blob: f09e9d22cc2bb9a90d59abc61055687e0e26a416 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
hasso508e53e2004-05-18 18:57:06 +00002 * Copyright (C) 2003 Yasuhiro Ohara
paul718e3742002-12-13 20:15:29 +00003 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
hasso508e53e2004-05-18 18:57:06 +000022#include <zebra.h>
23
24#include "log.h"
25#include "vty.h"
26#include "command.h"
27#include "prefix.h"
28#include "stream.h"
29#include "zclient.h"
30#include "memory.h"
31
hasso508e53e2004-05-18 18:57:06 +000032#include "ospf6_proto.h"
33#include "ospf6_top.h"
paul718e3742002-12-13 20:15:29 +000034#include "ospf6_interface.h"
hasso508e53e2004-05-18 18:57:06 +000035#include "ospf6_route.h"
36#include "ospf6_lsa.h"
hasso049207c2004-08-04 20:02:13 +000037#include "ospf6_lsdb.h"
paul718e3742002-12-13 20:15:29 +000038#include "ospf6_asbr.h"
hasso508e53e2004-05-18 18:57:06 +000039#include "ospf6_zebra.h"
hasso049207c2004-08-04 20:02:13 +000040#include "ospf6d.h"
paul718e3742002-12-13 20:15:29 +000041
hasso508e53e2004-05-18 18:57:06 +000042unsigned char conf_debug_ospf6_zebra = 0;
paul718e3742002-12-13 20:15:29 +000043
44/* information about zebra. */
45struct zclient *zclient = NULL;
46
hasso18a6dce2004-10-03 18:18:34 +000047struct in_addr router_id_zebra;
48
49/* Router-id update message from zebra. */
Paul Jakma6ac29a52008-08-15 13:45:30 +010050static int
hasso18a6dce2004-10-03 18:18:34 +000051ospf6_router_id_update_zebra (int command, struct zclient *zclient,
52 zebra_size_t length)
53{
54 struct prefix router_id;
55 struct ospf6 *o = ospf6;
56
57 zebra_router_id_update_read(zclient->ibuf,&router_id);
58 router_id_zebra = router_id.u.prefix4;
59
jardinc1ba9e82005-03-02 22:43:26 +000060 if (o == NULL)
61 return 0;
62
hasso18a6dce2004-10-03 18:18:34 +000063 if (o->router_id == 0)
64 o->router_id = (u_int32_t) router_id_zebra.s_addr;
65
66 return 0;
67}
68
paul718e3742002-12-13 20:15:29 +000069/* redistribute function */
70void
71ospf6_zebra_redistribute (int type)
72{
paul718e3742002-12-13 20:15:29 +000073 if (zclient->redist[type])
74 return;
paul718e3742002-12-13 20:15:29 +000075 zclient->redist[type] = 1;
paul718e3742002-12-13 20:15:29 +000076 if (zclient->sock > 0)
ajs634f9ea2005-04-11 15:51:40 +000077 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
paul718e3742002-12-13 20:15:29 +000078}
79
80void
81ospf6_zebra_no_redistribute (int type)
82{
hasso508e53e2004-05-18 18:57:06 +000083 if (! zclient->redist[type])
paul718e3742002-12-13 20:15:29 +000084 return;
paul718e3742002-12-13 20:15:29 +000085 zclient->redist[type] = 0;
paul718e3742002-12-13 20:15:29 +000086 if (zclient->sock > 0)
ajs634f9ea2005-04-11 15:51:40 +000087 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type);
paul718e3742002-12-13 20:15:29 +000088}
89
paul718e3742002-12-13 20:15:29 +000090/* Inteface addition message from zebra. */
Paul Jakma6ac29a52008-08-15 13:45:30 +010091static int
paul718e3742002-12-13 20:15:29 +000092ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length)
93{
94 struct interface *ifp;
95
96 ifp = zebra_interface_add_read (zclient->ibuf);
hasso508e53e2004-05-18 18:57:06 +000097 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +000098 zlog_debug ("Zebra Interface add: %s index %d mtu %d",
99 ifp->name, ifp->ifindex, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000100 ospf6_interface_if_add (ifp);
paul718e3742002-12-13 20:15:29 +0000101 return 0;
102}
103
Paul Jakma6ac29a52008-08-15 13:45:30 +0100104static int
paul718e3742002-12-13 20:15:29 +0000105ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length)
106{
hasso508e53e2004-05-18 18:57:06 +0000107 struct interface *ifp;
paul718e3742002-12-13 20:15:29 +0000108
ajsd2fc8892005-04-02 18:38:43 +0000109 if (!(ifp = zebra_interface_state_read(zclient->ibuf)))
110 return 0;
111
112 if (if_is_up (ifp))
113 zlog_warn ("Zebra: got delete of %s, but interface is still up", ifp->name);
114
hasso508e53e2004-05-18 18:57:06 +0000115 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000116 zlog_debug ("Zebra Interface delete: %s index %d mtu %d",
117 ifp->name, ifp->ifindex, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000118
ajsd2fc8892005-04-02 18:38:43 +0000119#if 0
120 /* Why is this commented out? */
paul718e3742002-12-13 20:15:29 +0000121 ospf6_interface_if_del (ifp);
hasso508e53e2004-05-18 18:57:06 +0000122#endif /*0*/
ajsd2fc8892005-04-02 18:38:43 +0000123
124 ifp->ifindex = IFINDEX_INTERNAL;
paul718e3742002-12-13 20:15:29 +0000125 return 0;
126}
127
Paul Jakma6ac29a52008-08-15 13:45:30 +0100128static int
paul718e3742002-12-13 20:15:29 +0000129ospf6_zebra_if_state_update (int command, struct zclient *zclient,
130 zebra_size_t length)
131{
132 struct interface *ifp;
133
134 ifp = zebra_interface_state_read (zclient->ibuf);
Ingo Flaschberger57c4f4f2011-04-04 11:17:45 +0100135 if (ifp == NULL)
136 return 0;
137
hasso508e53e2004-05-18 18:57:06 +0000138 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000139 zlog_debug ("Zebra Interface state change: "
Stephen Hemminger30d20592009-07-28 11:58:51 +0100140 "%s index %d flags %llx metric %d mtu %d",
141 ifp->name, ifp->ifindex, (unsigned long long)ifp->flags,
142 ifp->metric, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000143
144 ospf6_interface_state_update (ifp);
145 return 0;
146}
147
Paul Jakma6ac29a52008-08-15 13:45:30 +0100148static int
paul718e3742002-12-13 20:15:29 +0000149ospf6_zebra_if_address_update_add (int command, struct zclient *zclient,
hasso508e53e2004-05-18 18:57:06 +0000150 zebra_size_t length)
paul718e3742002-12-13 20:15:29 +0000151{
152 struct connected *c;
153 char buf[128];
154
paul0a589352004-05-08 11:48:26 +0000155 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000156 if (c == NULL)
157 return 0;
158
hasso508e53e2004-05-18 18:57:06 +0000159 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000160 zlog_debug ("Zebra Interface address add: %s %5s %s/%d",
161 c->ifp->name, prefix_family_str (c->address),
162 inet_ntop (c->address->family, &c->address->u.prefix,
163 buf, sizeof (buf)), c->address->prefixlen);
paul718e3742002-12-13 20:15:29 +0000164
165 if (c->address->family == AF_INET6)
hasso508e53e2004-05-18 18:57:06 +0000166 ospf6_interface_connected_route_update (c->ifp);
paul718e3742002-12-13 20:15:29 +0000167
168 return 0;
169}
170
Paul Jakma6ac29a52008-08-15 13:45:30 +0100171static int
paul718e3742002-12-13 20:15:29 +0000172ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient,
173 zebra_size_t length)
174{
175 struct connected *c;
176 char buf[128];
177
paul0a589352004-05-08 11:48:26 +0000178 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000179 if (c == NULL)
180 return 0;
181
hasso508e53e2004-05-18 18:57:06 +0000182 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000183 zlog_debug ("Zebra Interface address delete: %s %5s %s/%d",
184 c->ifp->name, prefix_family_str (c->address),
185 inet_ntop (c->address->family, &c->address->u.prefix,
186 buf, sizeof (buf)), c->address->prefixlen);
paul718e3742002-12-13 20:15:29 +0000187
188 if (c->address->family == AF_INET6)
hasso508e53e2004-05-18 18:57:06 +0000189 ospf6_interface_connected_route_update (c->ifp);
paul718e3742002-12-13 20:15:29 +0000190
191 return 0;
192}
193
Paul Jakma6ac29a52008-08-15 13:45:30 +0100194static int
paul718e3742002-12-13 20:15:29 +0000195ospf6_zebra_read_ipv6 (int command, struct zclient *zclient,
196 zebra_size_t length)
197{
198 struct stream *s;
199 struct zapi_ipv6 api;
200 unsigned long ifindex;
201 struct prefix_ipv6 p;
202 struct in6_addr *nexthop;
paul718e3742002-12-13 20:15:29 +0000203
204 s = zclient->ibuf;
205 ifindex = 0;
206 nexthop = NULL;
207 memset (&api, 0, sizeof (api));
208
209 /* Type, flags, message. */
210 api.type = stream_getc (s);
211 api.flags = stream_getc (s);
212 api.message = stream_getc (s);
213
214 /* IPv6 prefix. */
215 memset (&p, 0, sizeof (struct prefix_ipv6));
216 p.family = AF_INET6;
217 p.prefixlen = stream_getc (s);
218 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
219
220 /* Nexthop, ifindex, distance, metric. */
221 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
222 {
223 api.nexthop_num = stream_getc (s);
224 nexthop = (struct in6_addr *)
225 malloc (api.nexthop_num * sizeof (struct in6_addr));
226 stream_get (nexthop, s, api.nexthop_num * sizeof (struct in6_addr));
227 }
228 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
229 {
230 api.ifindex_num = stream_getc (s);
231 ifindex = stream_getl (s);
232 }
233 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
234 api.distance = stream_getc (s);
235 else
236 api.distance = 0;
237 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
238 api.metric = stream_getl (s);
239 else
240 api.metric = 0;
241
hasso508e53e2004-05-18 18:57:06 +0000242 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
paul718e3742002-12-13 20:15:29 +0000243 {
hasso508e53e2004-05-18 18:57:06 +0000244 char prefixstr[128], nexthopstr[128];
paul718e3742002-12-13 20:15:29 +0000245 prefix2str ((struct prefix *)&p, prefixstr, sizeof (prefixstr));
hasso508e53e2004-05-18 18:57:06 +0000246 if (nexthop)
247 inet_ntop (AF_INET6, nexthop, nexthopstr, sizeof (nexthopstr));
paul718e3742002-12-13 20:15:29 +0000248 else
hasso508e53e2004-05-18 18:57:06 +0000249 snprintf (nexthopstr, sizeof (nexthopstr), "::");
250
hassoc6487d62004-12-24 06:00:11 +0000251 zlog_debug ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld",
252 (command == ZEBRA_IPV6_ROUTE_ADD ? "add" : "delete"),
ajsf52d13c2005-10-01 17:38:06 +0000253 zebra_route_string(api.type), prefixstr, nexthopstr, ifindex);
paul718e3742002-12-13 20:15:29 +0000254 }
255
256 if (command == ZEBRA_IPV6_ROUTE_ADD)
hasso508e53e2004-05-18 18:57:06 +0000257 ospf6_asbr_redistribute_add (api.type, ifindex, (struct prefix *) &p,
258 api.nexthop_num, nexthop);
paul718e3742002-12-13 20:15:29 +0000259 else
hasso508e53e2004-05-18 18:57:06 +0000260 ospf6_asbr_redistribute_remove (api.type, ifindex, (struct prefix *) &p);
paul718e3742002-12-13 20:15:29 +0000261
262 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
263 free (nexthop);
264
265 return 0;
266}
267
hasso508e53e2004-05-18 18:57:06 +0000268
269
paul718e3742002-12-13 20:15:29 +0000270
271DEFUN (show_zebra,
272 show_zebra_cmd,
273 "show zebra",
274 SHOW_STR
275 "Zebra information\n")
276{
277 int i;
hasso508e53e2004-05-18 18:57:06 +0000278 if (zclient == NULL)
279 {
hasso049207c2004-08-04 20:02:13 +0000280 vty_out (vty, "Not connected to zebra%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000281 return CMD_SUCCESS;
282 }
paul718e3742002-12-13 20:15:29 +0000283
hasso049207c2004-08-04 20:02:13 +0000284 vty_out (vty, "Zebra Infomation%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000285 vty_out (vty, " enable: %d fail: %d%s",
hasso049207c2004-08-04 20:02:13 +0000286 zclient->enable, zclient->fail, VNL);
paul718e3742002-12-13 20:15:29 +0000287 vty_out (vty, " redistribute default: %d%s", zclient->redist_default,
hasso049207c2004-08-04 20:02:13 +0000288 VNL);
hasso508e53e2004-05-18 18:57:06 +0000289 vty_out (vty, " redistribute:");
paul718e3742002-12-13 20:15:29 +0000290 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
hasso508e53e2004-05-18 18:57:06 +0000291 {
292 if (zclient->redist[i])
ajsf52d13c2005-10-01 17:38:06 +0000293 vty_out (vty, " %s", zebra_route_string(i));
hasso508e53e2004-05-18 18:57:06 +0000294 }
hasso049207c2004-08-04 20:02:13 +0000295 vty_out (vty, "%s", VNL);
paul718e3742002-12-13 20:15:29 +0000296 return CMD_SUCCESS;
297}
298
299DEFUN (router_zebra,
300 router_zebra_cmd,
301 "router zebra",
302 "Enable a routing process\n"
303 "Make connection to zebra daemon\n")
304{
paul718e3742002-12-13 20:15:29 +0000305 vty->node = ZEBRA_NODE;
306 zclient->enable = 1;
307 zclient_start (zclient);
308 return CMD_SUCCESS;
309}
310
311DEFUN (no_router_zebra,
312 no_router_zebra_cmd,
313 "no router zebra",
314 NO_STR
315 "Configure routing process\n"
316 "Disable connection to zebra daemon\n")
317{
paul718e3742002-12-13 20:15:29 +0000318 zclient->enable = 0;
319 zclient_stop (zclient);
320 return CMD_SUCCESS;
321}
322
323/* Zebra configuration write function. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100324static int
hasso508e53e2004-05-18 18:57:06 +0000325config_write_ospf6_zebra (struct vty *vty)
paul718e3742002-12-13 20:15:29 +0000326{
327 if (! zclient->enable)
328 {
hasso049207c2004-08-04 20:02:13 +0000329 vty_out (vty, "no router zebra%s", VNL);
330 vty_out (vty, "!%s", VNL);
paul718e3742002-12-13 20:15:29 +0000331 }
332 else if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
333 {
hasso049207c2004-08-04 20:02:13 +0000334 vty_out (vty, "router zebra%s", VNL);
335 vty_out (vty, " no redistribute ospf6%s", VNL);
336 vty_out (vty, "!%s", VNL);
paul718e3742002-12-13 20:15:29 +0000337 }
338 return 0;
339}
340
341/* Zebra node structure. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800342static struct cmd_node zebra_node =
paul718e3742002-12-13 20:15:29 +0000343{
344 ZEBRA_NODE,
345 "%s(config-zebra)# ",
paul718e3742002-12-13 20:15:29 +0000346};
347
348#define ADD 0
hasso508e53e2004-05-18 18:57:06 +0000349#define REM 1
paul718e3742002-12-13 20:15:29 +0000350static void
hasso508e53e2004-05-18 18:57:06 +0000351ospf6_zebra_route_update (int type, struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000352{
paul718e3742002-12-13 20:15:29 +0000353 struct zapi_ipv6 api;
ajsd2fc8892005-04-02 18:38:43 +0000354 char buf[64];
hasso508e53e2004-05-18 18:57:06 +0000355 int nhcount;
paul718e3742002-12-13 20:15:29 +0000356 struct in6_addr **nexthops;
357 unsigned int *ifindexes;
paul718e3742002-12-13 20:15:29 +0000358 int i, ret = 0;
hasso508e53e2004-05-18 18:57:06 +0000359 struct prefix_ipv6 *dest;
paul718e3742002-12-13 20:15:29 +0000360
hasso508e53e2004-05-18 18:57:06 +0000361 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
paul718e3742002-12-13 20:15:29 +0000362 {
hasso508e53e2004-05-18 18:57:06 +0000363 prefix2str (&request->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000364 zlog_debug ("Send %s route: %s",
365 (type == REM ? "remove" : "add"), buf);
paul718e3742002-12-13 20:15:29 +0000366 }
367
368 if (zclient->sock < 0)
369 {
hasso508e53e2004-05-18 18:57:06 +0000370 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000371 zlog_debug (" Not connected to Zebra");
paul718e3742002-12-13 20:15:29 +0000372 return;
373 }
374
375 if (request->path.origin.adv_router == ospf6->router_id &&
376 (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
377 request->path.type == OSPF6_PATH_TYPE_EXTERNAL2))
378 {
hasso508e53e2004-05-18 18:57:06 +0000379 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000380 zlog_debug (" Ignore self-originated external route");
paul718e3742002-12-13 20:15:29 +0000381 return;
382 }
383
hasso508e53e2004-05-18 18:57:06 +0000384 /* If removing is the best path and if there's another path,
385 treat this request as add the secondary path */
386 if (type == REM && ospf6_route_is_best (request) &&
387 request->next && ospf6_route_is_same (request, request->next))
388 {
389 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000390 zlog_debug (" Best-path removal resulted Sencondary addition");
hasso508e53e2004-05-18 18:57:06 +0000391 type = ADD;
392 request = request->next;
393 }
394
395 /* Only the best path will be sent to zebra. */
396 if (! ospf6_route_is_best (request))
paul718e3742002-12-13 20:15:29 +0000397 {
398 /* this is not preferred best route, ignore */
hasso508e53e2004-05-18 18:57:06 +0000399 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000400 zlog_debug (" Ignore non-best route");
paul718e3742002-12-13 20:15:29 +0000401 return;
402 }
403
hasso508e53e2004-05-18 18:57:06 +0000404 nhcount = 0;
405 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
406 if (ospf6_nexthop_is_set (&request->nexthop[i]))
407 nhcount++;
paul718e3742002-12-13 20:15:29 +0000408
hasso508e53e2004-05-18 18:57:06 +0000409 if (nhcount == 0)
paul718e3742002-12-13 20:15:29 +0000410 {
hasso508e53e2004-05-18 18:57:06 +0000411 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000412 zlog_debug (" No nexthop, ignore");
paul718e3742002-12-13 20:15:29 +0000413 return;
414 }
415
416 /* allocate memory for nexthop_list */
417 nexthops = XCALLOC (MTYPE_OSPF6_OTHER,
hasso508e53e2004-05-18 18:57:06 +0000418 nhcount * sizeof (struct in6_addr *));
419 if (nexthops == NULL)
paul718e3742002-12-13 20:15:29 +0000420 {
hasso508e53e2004-05-18 18:57:06 +0000421 zlog_warn ("Can't send route to zebra: malloc failed");
paul718e3742002-12-13 20:15:29 +0000422 return;
423 }
424
425 /* allocate memory for ifindex_list */
426 ifindexes = XCALLOC (MTYPE_OSPF6_OTHER,
hasso508e53e2004-05-18 18:57:06 +0000427 nhcount * sizeof (unsigned int));
428 if (ifindexes == NULL)
paul718e3742002-12-13 20:15:29 +0000429 {
hasso508e53e2004-05-18 18:57:06 +0000430 zlog_warn ("Can't send route to zebra: malloc failed");
paul718e3742002-12-13 20:15:29 +0000431 XFREE (MTYPE_OSPF6_OTHER, nexthops);
432 return;
433 }
434
hasso508e53e2004-05-18 18:57:06 +0000435 for (i = 0; i < nhcount; i++)
paul718e3742002-12-13 20:15:29 +0000436 {
hasso508e53e2004-05-18 18:57:06 +0000437 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
ajsd2fc8892005-04-02 18:38:43 +0000438 {
439 char ifname[IFNAMSIZ];
440 inet_ntop (AF_INET6, &request->nexthop[i].address,
441 buf, sizeof (buf));
442 if (!if_indextoname(request->nexthop[i].ifindex, ifname))
443 strlcpy(ifname, "unknown", sizeof(ifname));
444 zlog_debug (" nexthop: %s%%%.*s(%d)", buf, IFNAMSIZ, ifname,
hassoc6487d62004-12-24 06:00:11 +0000445 request->nexthop[i].ifindex);
ajsd2fc8892005-04-02 18:38:43 +0000446 }
hasso508e53e2004-05-18 18:57:06 +0000447 nexthops[i] = &request->nexthop[i].address;
448 ifindexes[i] = request->nexthop[i].ifindex;
paul718e3742002-12-13 20:15:29 +0000449 }
450
451 api.type = ZEBRA_ROUTE_OSPF6;
452 api.flags = 0;
453 api.message = 0;
Denis Ovsienkob4e45f62011-12-05 16:35:14 +0400454 api.safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +0000455 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
hasso508e53e2004-05-18 18:57:06 +0000456 api.nexthop_num = nhcount;
paul718e3742002-12-13 20:15:29 +0000457 api.nexthop = nexthops;
hasso508e53e2004-05-18 18:57:06 +0000458 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
459 api.ifindex_num = nhcount;
paul718e3742002-12-13 20:15:29 +0000460 api.ifindex = ifindexes;
hasso508e53e2004-05-18 18:57:06 +0000461 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
462 api.metric = (request->path.metric_type == 2 ?
463 request->path.cost_e2 : request->path.cost);
paul718e3742002-12-13 20:15:29 +0000464
hasso508e53e2004-05-18 18:57:06 +0000465 dest = (struct prefix_ipv6 *) &request->prefix;
466 if (type == REM)
467 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api);
paul718e3742002-12-13 20:15:29 +0000468 else
hasso508e53e2004-05-18 18:57:06 +0000469 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api);
paul718e3742002-12-13 20:15:29 +0000470
471 if (ret < 0)
hasso508e53e2004-05-18 18:57:06 +0000472 zlog_err ("zapi_ipv6_route() %s failed: %s",
ajs6099b3b2004-11-20 02:06:59 +0000473 (type == REM ? "delete" : "add"), safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000474
paul718e3742002-12-13 20:15:29 +0000475 XFREE (MTYPE_OSPF6_OTHER, nexthops);
476 XFREE (MTYPE_OSPF6_OTHER, ifindexes);
477
478 return;
479}
480
481void
hasso508e53e2004-05-18 18:57:06 +0000482ospf6_zebra_route_update_add (struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000483{
hasso508e53e2004-05-18 18:57:06 +0000484 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
485 {
486 ospf6->route_table->hook_add = NULL;
487 ospf6->route_table->hook_remove = NULL;
488 return;
489 }
paul718e3742002-12-13 20:15:29 +0000490 ospf6_zebra_route_update (ADD, request);
491}
492
493void
hasso508e53e2004-05-18 18:57:06 +0000494ospf6_zebra_route_update_remove (struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000495{
hasso508e53e2004-05-18 18:57:06 +0000496 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
paul718e3742002-12-13 20:15:29 +0000497 {
hasso508e53e2004-05-18 18:57:06 +0000498 ospf6->route_table->hook_add = NULL;
499 ospf6->route_table->hook_remove = NULL;
500 return;
paul718e3742002-12-13 20:15:29 +0000501 }
hasso508e53e2004-05-18 18:57:06 +0000502 ospf6_zebra_route_update (REM, request);
paul718e3742002-12-13 20:15:29 +0000503}
504
paul718e3742002-12-13 20:15:29 +0000505DEFUN (redistribute_ospf6,
506 redistribute_ospf6_cmd,
507 "redistribute ospf6",
508 "Redistribute control\n"
509 "OSPF6 route\n")
510{
hasso508e53e2004-05-18 18:57:06 +0000511 struct ospf6_route *route;
512
513 if (zclient->redist[ZEBRA_ROUTE_OSPF6])
514 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000515
516 zclient->redist[ZEBRA_ROUTE_OSPF6] = 1;
517
hasso508e53e2004-05-18 18:57:06 +0000518 if (ospf6 == NULL)
519 return CMD_SUCCESS;
520
521 /* send ospf6 route to zebra route table */
522 for (route = ospf6_route_head (ospf6->route_table); route;
523 route = ospf6_route_next (route))
524 ospf6_zebra_route_update_add (route);
525
526 ospf6->route_table->hook_add = ospf6_zebra_route_update_add;
527 ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove;
paul718e3742002-12-13 20:15:29 +0000528
529 return CMD_SUCCESS;
530}
531
532DEFUN (no_redistribute_ospf6,
533 no_redistribute_ospf6_cmd,
534 "no redistribute ospf6",
535 NO_STR
536 "Redistribute control\n"
537 "OSPF6 route\n")
538{
hasso508e53e2004-05-18 18:57:06 +0000539 struct ospf6_route *route;
540
541 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
542 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000543
544 zclient->redist[ZEBRA_ROUTE_OSPF6] = 0;
545
hasso508e53e2004-05-18 18:57:06 +0000546 if (ospf6 == NULL)
paul718e3742002-12-13 20:15:29 +0000547 return CMD_SUCCESS;
548
hasso508e53e2004-05-18 18:57:06 +0000549 ospf6->route_table->hook_add = NULL;
550 ospf6->route_table->hook_remove = NULL;
paul718e3742002-12-13 20:15:29 +0000551
hasso508e53e2004-05-18 18:57:06 +0000552 /* withdraw ospf6 route from zebra route table */
553 for (route = ospf6_route_head (ospf6->route_table); route;
554 route = ospf6_route_next (route))
555 ospf6_zebra_route_update_remove (route);
paul718e3742002-12-13 20:15:29 +0000556
557 return CMD_SUCCESS;
558}
559
560void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100561ospf6_zebra_init (void)
paul718e3742002-12-13 20:15:29 +0000562{
563 /* Allocate zebra structure. */
564 zclient = zclient_new ();
565 zclient_init (zclient, ZEBRA_ROUTE_OSPF6);
hasso18a6dce2004-10-03 18:18:34 +0000566 zclient->router_id_update = ospf6_router_id_update_zebra;
paul718e3742002-12-13 20:15:29 +0000567 zclient->interface_add = ospf6_zebra_if_add;
568 zclient->interface_delete = ospf6_zebra_if_del;
569 zclient->interface_up = ospf6_zebra_if_state_update;
570 zclient->interface_down = ospf6_zebra_if_state_update;
571 zclient->interface_address_add = ospf6_zebra_if_address_update_add;
572 zclient->interface_address_delete = ospf6_zebra_if_address_update_delete;
573 zclient->ipv4_route_add = NULL;
574 zclient->ipv4_route_delete = NULL;
575 zclient->ipv6_route_add = ospf6_zebra_read_ipv6;
576 zclient->ipv6_route_delete = ospf6_zebra_read_ipv6;
577
578 /* redistribute connected route by default */
579 /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
580
581 /* Install zebra node. */
hasso508e53e2004-05-18 18:57:06 +0000582 install_node (&zebra_node, config_write_ospf6_zebra);
paul718e3742002-12-13 20:15:29 +0000583
584 /* Install command element for zebra node. */
585 install_element (VIEW_NODE, &show_zebra_cmd);
586 install_element (ENABLE_NODE, &show_zebra_cmd);
587 install_element (CONFIG_NODE, &router_zebra_cmd);
588 install_element (CONFIG_NODE, &no_router_zebra_cmd);
hasso508e53e2004-05-18 18:57:06 +0000589
paul718e3742002-12-13 20:15:29 +0000590 install_default (ZEBRA_NODE);
591 install_element (ZEBRA_NODE, &redistribute_ospf6_cmd);
592 install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd);
593
paul718e3742002-12-13 20:15:29 +0000594 return;
595}
596
hasso508e53e2004-05-18 18:57:06 +0000597/* Debug */
598
599DEFUN (debug_ospf6_zebra_sendrecv,
600 debug_ospf6_zebra_sendrecv_cmd,
601 "debug ospf6 zebra (send|recv)",
602 DEBUG_STR
603 OSPF6_STR
604 "Debug connection between zebra\n"
605 "Debug Sending zebra\n"
606 "Debug Receiving zebra\n"
607 )
paul718e3742002-12-13 20:15:29 +0000608{
hasso508e53e2004-05-18 18:57:06 +0000609 unsigned char level = 0;
610
611 if (argc)
612 {
613 if (! strncmp (argv[0], "s", 1))
614 level = OSPF6_DEBUG_ZEBRA_SEND;
615 else if (! strncmp (argv[0], "r", 1))
616 level = OSPF6_DEBUG_ZEBRA_RECV;
617 }
618 else
619 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
620
621 OSPF6_DEBUG_ZEBRA_ON (level);
622 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000623}
624
hasso508e53e2004-05-18 18:57:06 +0000625ALIAS (debug_ospf6_zebra_sendrecv,
626 debug_ospf6_zebra_cmd,
627 "debug ospf6 zebra",
628 DEBUG_STR
629 OSPF6_STR
630 "Debug connection between zebra\n"
Paul Jakma6ac29a52008-08-15 13:45:30 +0100631 )
hasso508e53e2004-05-18 18:57:06 +0000632
633
634DEFUN (no_debug_ospf6_zebra_sendrecv,
635 no_debug_ospf6_zebra_sendrecv_cmd,
636 "no debug ospf6 zebra (send|recv)",
637 NO_STR
638 DEBUG_STR
639 OSPF6_STR
640 "Debug connection between zebra\n"
641 "Debug Sending zebra\n"
642 "Debug Receiving zebra\n"
643 )
644{
645 unsigned char level = 0;
646
647 if (argc)
648 {
649 if (! strncmp (argv[0], "s", 1))
650 level = OSPF6_DEBUG_ZEBRA_SEND;
651 else if (! strncmp (argv[0], "r", 1))
652 level = OSPF6_DEBUG_ZEBRA_RECV;
653 }
654 else
655 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
656
657 OSPF6_DEBUG_ZEBRA_OFF (level);
658 return CMD_SUCCESS;
659}
660
661ALIAS (no_debug_ospf6_zebra_sendrecv,
662 no_debug_ospf6_zebra_cmd,
663 "no debug ospf6 zebra",
664 NO_STR
665 DEBUG_STR
666 OSPF6_STR
667 "Debug connection between zebra\n"
Paul Jakma6ac29a52008-08-15 13:45:30 +0100668 )
hasso508e53e2004-05-18 18:57:06 +0000669
670int
671config_write_ospf6_debug_zebra (struct vty *vty)
672{
673 if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV))
hasso049207c2004-08-04 20:02:13 +0000674 vty_out (vty, "debug ospf6 zebra%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000675 else
676 {
677 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hasso049207c2004-08-04 20:02:13 +0000678 vty_out (vty, "debug ospf6 zebra send%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000679 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hasso049207c2004-08-04 20:02:13 +0000680 vty_out (vty, "debug ospf6 zebra recv%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000681 }
682 return 0;
683}
684
685void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100686install_element_ospf6_debug_zebra (void)
hasso508e53e2004-05-18 18:57:06 +0000687{
688 install_element (ENABLE_NODE, &debug_ospf6_zebra_cmd);
689 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_cmd);
690 install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd);
691 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
692 install_element (CONFIG_NODE, &debug_ospf6_zebra_cmd);
693 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_cmd);
694 install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd);
695 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
696}
697
698