]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_zebra.c
quagga: Allow compile time determination of v6 RR semantics
[mirror_frr.git] / ospf6d / ospf6_zebra.c
1 /*
2 * Copyright (C) 2003 Yasuhiro Ohara
3 *
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
22 #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
32 #include "ospf6_proto.h"
33 #include "ospf6_top.h"
34 #include "ospf6_interface.h"
35 #include "ospf6_route.h"
36 #include "ospf6_lsa.h"
37 #include "ospf6_lsdb.h"
38 #include "ospf6_asbr.h"
39 #include "ospf6_zebra.h"
40 #include "ospf6d.h"
41
42 unsigned char conf_debug_ospf6_zebra = 0;
43
44 /* information about zebra. */
45 struct zclient *zclient = NULL;
46
47 struct in_addr router_id_zebra;
48
49 /* Router-id update message from zebra. */
50 static int
51 ospf6_router_id_update_zebra (int command, struct zclient *zclient,
52 zebra_size_t length, vrf_id_t vrf_id)
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
60 if (o == NULL)
61 return 0;
62
63 if (o->router_id == 0)
64 o->router_id = (u_int32_t) router_id_zebra.s_addr;
65
66 return 0;
67 }
68
69 /* redistribute function */
70 void
71 ospf6_zebra_redistribute (int type)
72 {
73 if (vrf_bitmap_check (zclient->redist[AFI_IP6][type], VRF_DEFAULT))
74 return;
75 vrf_bitmap_set (zclient->redist[AFI_IP6][type], VRF_DEFAULT);
76
77 if (zclient->sock > 0)
78 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0,
79 VRF_DEFAULT);
80 }
81
82 void
83 ospf6_zebra_no_redistribute (int type)
84 {
85 if (!vrf_bitmap_check (zclient->redist[AFI_IP6][type], VRF_DEFAULT))
86 return;
87 vrf_bitmap_unset (zclient->redist[AFI_IP6][type], VRF_DEFAULT);
88 if (zclient->sock > 0)
89 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP6, type,
90 0, VRF_DEFAULT);
91 }
92
93 /* Inteface addition message from zebra. */
94 static int
95 ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length,
96 vrf_id_t vrf_id)
97 {
98 struct interface *ifp;
99
100 ifp = zebra_interface_add_read (zclient->ibuf, vrf_id);
101 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
102 zlog_debug ("Zebra Interface add: %s index %d mtu %d",
103 ifp->name, ifp->ifindex, ifp->mtu6);
104 ospf6_interface_if_add (ifp);
105 return 0;
106 }
107
108 static int
109 ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length,
110 vrf_id_t vrf_id)
111 {
112 struct interface *ifp;
113
114 if (!(ifp = zebra_interface_state_read (zclient->ibuf, vrf_id)))
115 return 0;
116
117 if (if_is_up (ifp))
118 zlog_warn ("Zebra: got delete of %s, but interface is still up", ifp->name);
119
120 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
121 zlog_debug ("Zebra Interface delete: %s index %d mtu %d",
122 ifp->name, ifp->ifindex, ifp->mtu6);
123
124 #if 0
125 /* XXX: ospf6_interface_if_del is not the right way to handle this,
126 * because among other thinkable issues, it will also clear all
127 * settings as they are contained in the struct ospf6_interface. */
128 ospf6_interface_if_del (ifp);
129 #endif /*0*/
130
131 ifp->ifindex = IFINDEX_DELETED;
132 return 0;
133 }
134
135 static int
136 ospf6_zebra_if_state_update (int command, struct zclient *zclient,
137 zebra_size_t length, vrf_id_t vrf_id)
138 {
139 struct interface *ifp;
140
141 ifp = zebra_interface_state_read (zclient->ibuf, vrf_id);
142 if (ifp == NULL)
143 return 0;
144
145 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
146 zlog_debug ("Zebra Interface state change: "
147 "%s index %d flags %llx metric %d mtu %d bandwidth %d",
148 ifp->name, ifp->ifindex, (unsigned long long)ifp->flags,
149 ifp->metric, ifp->mtu6, ifp->bandwidth);
150
151 ospf6_interface_state_update (ifp);
152 return 0;
153 }
154
155 static int
156 ospf6_zebra_if_address_update_add (int command, struct zclient *zclient,
157 zebra_size_t length, vrf_id_t vrf_id)
158 {
159 struct connected *c;
160 char buf[128];
161
162 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, zclient->ibuf,
163 vrf_id);
164 if (c == NULL)
165 return 0;
166
167 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
168 zlog_debug ("Zebra Interface address add: %s %5s %s/%d",
169 c->ifp->name, prefix_family_str (c->address),
170 inet_ntop (c->address->family, &c->address->u.prefix,
171 buf, sizeof (buf)), c->address->prefixlen);
172
173 if (c->address->family == AF_INET6)
174 {
175 ospf6_interface_state_update (c->ifp);
176 ospf6_interface_connected_route_update (c->ifp);
177 }
178 return 0;
179 }
180
181 static int
182 ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient,
183 zebra_size_t length, vrf_id_t vrf_id)
184 {
185 struct connected *c;
186 char buf[128];
187
188 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf,
189 vrf_id);
190 if (c == NULL)
191 return 0;
192
193 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
194 zlog_debug ("Zebra Interface address delete: %s %5s %s/%d",
195 c->ifp->name, prefix_family_str (c->address),
196 inet_ntop (c->address->family, &c->address->u.prefix,
197 buf, sizeof (buf)), c->address->prefixlen);
198
199 if (c->address->family == AF_INET6)
200 {
201 ospf6_interface_connected_route_update (c->ifp);
202 ospf6_interface_state_update (c->ifp);
203 }
204
205 return 0;
206 }
207
208 static int
209 ospf6_zebra_read_ipv6 (int command, struct zclient *zclient,
210 zebra_size_t length, vrf_id_t vrf_id)
211 {
212 struct stream *s;
213 struct zapi_ipv6 api;
214 unsigned long ifindex;
215 struct prefix_ipv6 p;
216 struct in6_addr *nexthop;
217
218 if (ospf6 == NULL)
219 return 0;
220
221 s = zclient->ibuf;
222 ifindex = 0;
223 nexthop = NULL;
224 memset (&api, 0, sizeof (api));
225
226 /* Type, flags, message. */
227 api.type = stream_getc (s);
228 api.instance = stream_getw (s);
229 api.flags = stream_getc (s);
230 api.message = stream_getc (s);
231
232 /* IPv6 prefix. */
233 memset (&p, 0, sizeof (struct prefix_ipv6));
234 p.family = AF_INET6;
235 p.prefixlen = stream_getc (s);
236 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
237
238 /* Nexthop, ifindex, distance, metric. */
239 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
240 {
241 api.nexthop_num = stream_getc (s);
242 nexthop = (struct in6_addr *)
243 malloc (api.nexthop_num * sizeof (struct in6_addr));
244 stream_get (nexthop, s, api.nexthop_num * sizeof (struct in6_addr));
245 }
246 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
247 {
248 api.ifindex_num = stream_getc (s);
249 ifindex = stream_getl (s);
250 }
251 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
252 api.distance = stream_getc (s);
253 else
254 api.distance = 0;
255 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
256 api.metric = stream_getl (s);
257 else
258 api.metric = 0;
259
260 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
261 {
262 char prefixstr[PREFIX2STR_BUFFER], nexthopstr[128];
263 prefix2str ((struct prefix *)&p, prefixstr, sizeof (prefixstr));
264 if (nexthop)
265 inet_ntop (AF_INET6, nexthop, nexthopstr, sizeof (nexthopstr));
266 else
267 snprintf (nexthopstr, sizeof (nexthopstr), "::");
268
269 zlog_debug ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld",
270 (command == ZEBRA_IPV6_ROUTE_ADD ? "add" : "delete"),
271 zebra_route_string(api.type), prefixstr, nexthopstr, ifindex);
272 }
273
274 if (command == ZEBRA_REDISTRIBUTE_IPV6_ADD)
275 ospf6_asbr_redistribute_add (api.type, ifindex, (struct prefix *) &p,
276 api.nexthop_num, nexthop);
277 else
278 ospf6_asbr_redistribute_remove (api.type, ifindex, (struct prefix *) &p);
279
280 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
281 free (nexthop);
282
283 return 0;
284 }
285
286
287
288
289 DEFUN (show_zebra,
290 show_zebra_cmd,
291 "show zebra",
292 SHOW_STR
293 "Zebra information\n")
294 {
295 int i;
296 if (zclient == NULL)
297 {
298 vty_out (vty, "Not connected to zebra%s", VNL);
299 return CMD_SUCCESS;
300 }
301
302 vty_out (vty, "Zebra Infomation%s", VNL);
303 vty_out (vty, " enable: %d fail: %d%s",
304 zclient->enable, zclient->fail, VNL);
305 vty_out (vty, " redistribute default: %d%s",
306 vrf_bitmap_check (zclient->default_information, VRF_DEFAULT),
307 VNL);
308 vty_out (vty, " redistribute:");
309 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
310 {
311 if (vrf_bitmap_check (zclient->redist[AFI_IP6][i], VRF_DEFAULT))
312 vty_out (vty, " %s", zebra_route_string(i));
313 }
314 vty_out (vty, "%s", VNL);
315 return CMD_SUCCESS;
316 }
317
318 DEFUN (router_zebra,
319 router_zebra_cmd,
320 "router zebra",
321 "Enable a routing process\n"
322 "Make connection to zebra daemon\n")
323 {
324 vty->node = ZEBRA_NODE;
325 zclient->enable = 1;
326 zclient_start (zclient);
327 return CMD_SUCCESS;
328 }
329
330 DEFUN (no_router_zebra,
331 no_router_zebra_cmd,
332 "no router zebra",
333 NO_STR
334 "Configure routing process\n"
335 "Disable connection to zebra daemon\n")
336 {
337 zclient->enable = 0;
338 zclient_stop (zclient);
339 return CMD_SUCCESS;
340 }
341
342 /* Zebra configuration write function. */
343 static int
344 config_write_ospf6_zebra (struct vty *vty)
345 {
346 if (! zclient->enable)
347 {
348 vty_out (vty, "no router zebra%s", VNL);
349 vty_out (vty, "!%s", VNL);
350 }
351 else if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6],
352 VRF_DEFAULT))
353 {
354 vty_out (vty, "router zebra%s", VNL);
355 vty_out (vty, " no redistribute ospf6%s", VNL);
356 vty_out (vty, "!%s", VNL);
357 }
358 return 0;
359 }
360
361 /* Zebra node structure. */
362 static struct cmd_node zebra_node =
363 {
364 ZEBRA_NODE,
365 "%s(config-zebra)# ",
366 };
367
368 #define ADD 0
369 #define REM 1
370 static void
371 ospf6_zebra_route_update (int type, struct ospf6_route *request)
372 {
373 struct zapi_ipv6 api;
374 char buf[PREFIX2STR_BUFFER];
375 int nhcount;
376 struct in6_addr **nexthops;
377 unsigned int *ifindexes;
378 int ret = 0;
379 struct prefix_ipv6 *dest;
380
381 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
382 {
383 prefix2str (&request->prefix, buf, sizeof (buf));
384 zlog_debug ("Send %s route: %s",
385 (type == REM ? "remove" : "add"), buf);
386 }
387
388 if (zclient->sock < 0)
389 {
390 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
391 zlog_debug (" Not connected to Zebra");
392 return;
393 }
394
395 if (request->path.origin.adv_router == ospf6->router_id &&
396 (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
397 request->path.type == OSPF6_PATH_TYPE_EXTERNAL2))
398 {
399 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
400 zlog_debug (" Ignore self-originated external route");
401 return;
402 }
403
404 /* If removing is the best path and if there's another path,
405 treat this request as add the secondary path */
406 if (type == REM && ospf6_route_is_best (request) &&
407 request->next && ospf6_route_is_same (request, request->next))
408 {
409 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
410 zlog_debug (" Best-path removal resulted Sencondary addition");
411 type = ADD;
412 request = request->next;
413 }
414
415 /* Only the best path will be sent to zebra. */
416 if (! ospf6_route_is_best (request))
417 {
418 /* this is not preferred best route, ignore */
419 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
420 zlog_debug (" Ignore non-best route");
421 return;
422 }
423
424 nhcount = ospf6_route_num_nexthops (request);
425 if (nhcount == 0)
426 {
427 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
428 zlog_debug (" No nexthop, ignore");
429 return;
430 }
431
432 /* allocate memory for nexthop_list */
433 nexthops = XCALLOC (MTYPE_OSPF6_OTHER,
434 nhcount * sizeof (struct in6_addr *));
435 if (nexthops == NULL)
436 {
437 zlog_warn ("Can't send route to zebra: malloc failed");
438 return;
439 }
440
441 /* allocate memory for ifindex_list */
442 ifindexes = XCALLOC (MTYPE_OSPF6_OTHER,
443 nhcount * sizeof (unsigned int));
444 if (ifindexes == NULL)
445 {
446 zlog_warn ("Can't send route to zebra: malloc failed");
447 XFREE (MTYPE_OSPF6_OTHER, nexthops);
448 return;
449 }
450
451 ospf6_route_zebra_copy_nexthops (request, ifindexes, nexthops, nhcount);
452
453 api.vrf_id = VRF_DEFAULT;
454 api.type = ZEBRA_ROUTE_OSPF6;
455 api.instance = 0;
456 api.flags = 0;
457 api.message = 0;
458 api.safi = SAFI_UNICAST;
459 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
460 api.nexthop_num = nhcount;
461 api.nexthop = nexthops;
462 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
463 api.ifindex_num = nhcount;
464 api.ifindex = ifindexes;
465 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
466 api.metric = (request->path.metric_type == 2 ?
467 request->path.u.cost_e2 : request->path.cost);
468
469 dest = (struct prefix_ipv6 *) &request->prefix;
470 if (type == REM)
471 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api);
472 else
473 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api);
474
475 if (ret < 0)
476 zlog_err ("zapi_ipv6_route() %s failed: %s",
477 (type == REM ? "delete" : "add"), safe_strerror (errno));
478
479 XFREE (MTYPE_OSPF6_OTHER, nexthops);
480 XFREE (MTYPE_OSPF6_OTHER, ifindexes);
481
482 return;
483 }
484
485 void
486 ospf6_zebra_route_update_add (struct ospf6_route *request)
487 {
488 if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6],
489 VRF_DEFAULT))
490 {
491 ospf6->route_table->hook_add = NULL;
492 ospf6->route_table->hook_remove = NULL;
493 return;
494 }
495 ospf6_zebra_route_update (ADD, request);
496 }
497
498 void
499 ospf6_zebra_route_update_remove (struct ospf6_route *request)
500 {
501 if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6],
502 VRF_DEFAULT))
503 {
504 ospf6->route_table->hook_add = NULL;
505 ospf6->route_table->hook_remove = NULL;
506 return;
507 }
508 ospf6_zebra_route_update (REM, request);
509 }
510
511 void
512 ospf6_zebra_add_discard (struct ospf6_route *request)
513 {
514 struct zapi_ipv6 api;
515 char buf[INET6_ADDRSTRLEN];
516 struct prefix_ipv6 *dest;
517
518 if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6],
519 VRF_DEFAULT))
520 {
521 if (!CHECK_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED))
522 {
523 api.vrf_id = VRF_DEFAULT;
524 api.type = ZEBRA_ROUTE_OSPF6;
525 api.flags = ZEBRA_FLAG_BLACKHOLE;
526 api.instance = 0;
527 api.message = 0;
528 api.safi = SAFI_UNICAST;
529 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
530 api.nexthop_num = 0;
531 api.ifindex_num = 0;
532
533 dest = (struct prefix_ipv6 *) &request->prefix;
534
535 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api);
536
537 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
538 zlog_debug ("Zebra: Route add discard %s/%d",
539 inet_ntop (AF_INET6, &dest->prefix,
540 buf, INET6_ADDRSTRLEN),
541 dest->prefixlen);
542 SET_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED);
543 }
544 else
545 {
546 dest = (struct prefix_ipv6 *) &request->prefix;
547
548 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
549 zlog_debug ("Zebra: Blackhole route present already %s/%d",
550 inet_ntop (AF_INET6, &dest->prefix,
551 buf, INET6_ADDRSTRLEN),
552 dest->prefixlen);
553 }
554 }
555 }
556
557 void
558 ospf6_zebra_delete_discard (struct ospf6_route *request)
559 {
560 struct zapi_ipv6 api;
561 char buf[INET6_ADDRSTRLEN];
562 struct prefix_ipv6 *dest;
563
564 if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
565 {
566 if (CHECK_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED))
567 {
568 api.vrf_id = VRF_DEFAULT;
569 api.type = ZEBRA_ROUTE_OSPF6;
570 api.flags = ZEBRA_FLAG_BLACKHOLE;
571 api.instance = 0;
572 api.message = 0;
573 api.safi = SAFI_UNICAST;
574 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
575 api.nexthop_num = 0;
576 api.ifindex_num = 0;
577
578 dest = (struct prefix_ipv6 *) &request->prefix;
579
580 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api);
581
582 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
583 zlog_debug ("Zebra: Route delete discard %s/%d",
584 inet_ntop (AF_INET6, &dest->prefix, buf,
585 INET6_ADDRSTRLEN), dest->prefixlen);
586 UNSET_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED);
587 }
588 else
589 {
590 dest = (struct prefix_ipv6 *) &request->prefix;
591 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
592 zlog_debug ("Zebra: Blackhole route already deleted %s/%d",
593 inet_ntop (AF_INET6, &dest->prefix, buf,
594 INET6_ADDRSTRLEN), dest->prefixlen);
595 }
596 }
597 }
598
599 DEFUN (redistribute_ospf6,
600 redistribute_ospf6_cmd,
601 "redistribute ospf6",
602 "Redistribute control\n"
603 "OSPF6 route\n")
604 {
605 struct ospf6_route *route;
606
607 if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
608 return CMD_SUCCESS;
609
610 vrf_bitmap_set (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT);
611
612 if (ospf6 == NULL)
613 return CMD_SUCCESS;
614
615 /* send ospf6 route to zebra route table */
616 for (route = ospf6_route_head (ospf6->route_table); route;
617 route = ospf6_route_next (route))
618 ospf6_zebra_route_update_add (route);
619
620 ospf6->route_table->hook_add = ospf6_zebra_route_update_add;
621 ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove;
622
623 return CMD_SUCCESS;
624 }
625
626 DEFUN (no_redistribute_ospf6,
627 no_redistribute_ospf6_cmd,
628 "no redistribute ospf6",
629 NO_STR
630 "Redistribute control\n"
631 "OSPF6 route\n")
632 {
633 struct ospf6_route *route;
634
635 if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
636 return CMD_SUCCESS;
637
638 vrf_bitmap_unset (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT);
639
640 if (ospf6 == NULL)
641 return CMD_SUCCESS;
642
643 ospf6->route_table->hook_add = NULL;
644 ospf6->route_table->hook_remove = NULL;
645
646 /* withdraw ospf6 route from zebra route table */
647 for (route = ospf6_route_head (ospf6->route_table); route;
648 route = ospf6_route_next (route))
649 ospf6_zebra_route_update_remove (route);
650
651 return CMD_SUCCESS;
652 }
653
654 static void
655 ospf6_zebra_connected (struct zclient *zclient)
656 {
657 zclient_send_reg_requests (zclient, VRF_DEFAULT);
658 }
659
660 void
661 ospf6_zebra_init (struct thread_master *master)
662 {
663 /* Allocate zebra structure. */
664 zclient = zclient_new(master);
665 zclient_init (zclient, ZEBRA_ROUTE_OSPF6, 0);
666 zclient->zebra_connected = ospf6_zebra_connected;
667 zclient->router_id_update = ospf6_router_id_update_zebra;
668 zclient->interface_add = ospf6_zebra_if_add;
669 zclient->interface_delete = ospf6_zebra_if_del;
670 zclient->interface_up = ospf6_zebra_if_state_update;
671 zclient->interface_down = ospf6_zebra_if_state_update;
672 zclient->interface_address_add = ospf6_zebra_if_address_update_add;
673 zclient->interface_address_delete = ospf6_zebra_if_address_update_delete;
674 zclient->ipv4_route_add = NULL;
675 zclient->ipv4_route_delete = NULL;
676 zclient->redistribute_route_ipv4_add = NULL;
677 zclient->redistribute_route_ipv4_del = NULL;
678 zclient->ipv6_route_add = ospf6_zebra_read_ipv6;
679 zclient->ipv6_route_delete = ospf6_zebra_read_ipv6;
680 zclient->redistribute_route_ipv6_add = ospf6_zebra_read_ipv6;
681 zclient->redistribute_route_ipv6_del = ospf6_zebra_read_ipv6;
682
683 /* redistribute connected route by default */
684 /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
685
686 /* Install zebra node. */
687 install_node (&zebra_node, config_write_ospf6_zebra);
688
689 /* Install command element for zebra node. */
690 install_element (VIEW_NODE, &show_zebra_cmd);
691 install_element (ENABLE_NODE, &show_zebra_cmd);
692 install_element (CONFIG_NODE, &router_zebra_cmd);
693 install_element (CONFIG_NODE, &no_router_zebra_cmd);
694
695 install_default (ZEBRA_NODE);
696 install_element (ZEBRA_NODE, &redistribute_ospf6_cmd);
697 install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd);
698
699 return;
700 }
701
702 /* Debug */
703
704 DEFUN (debug_ospf6_zebra_sendrecv,
705 debug_ospf6_zebra_sendrecv_cmd,
706 "debug ospf6 zebra (send|recv)",
707 DEBUG_STR
708 OSPF6_STR
709 "Debug connection between zebra\n"
710 "Debug Sending zebra\n"
711 "Debug Receiving zebra\n"
712 )
713 {
714 unsigned char level = 0;
715
716 if (argc)
717 {
718 if (! strncmp (argv[0], "s", 1))
719 level = OSPF6_DEBUG_ZEBRA_SEND;
720 else if (! strncmp (argv[0], "r", 1))
721 level = OSPF6_DEBUG_ZEBRA_RECV;
722 }
723 else
724 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
725
726 OSPF6_DEBUG_ZEBRA_ON (level);
727 return CMD_SUCCESS;
728 }
729
730 ALIAS (debug_ospf6_zebra_sendrecv,
731 debug_ospf6_zebra_cmd,
732 "debug ospf6 zebra",
733 DEBUG_STR
734 OSPF6_STR
735 "Debug connection between zebra\n"
736 )
737
738
739 DEFUN (no_debug_ospf6_zebra_sendrecv,
740 no_debug_ospf6_zebra_sendrecv_cmd,
741 "no debug ospf6 zebra (send|recv)",
742 NO_STR
743 DEBUG_STR
744 OSPF6_STR
745 "Debug connection between zebra\n"
746 "Debug Sending zebra\n"
747 "Debug Receiving zebra\n"
748 )
749 {
750 unsigned char level = 0;
751
752 if (argc)
753 {
754 if (! strncmp (argv[0], "s", 1))
755 level = OSPF6_DEBUG_ZEBRA_SEND;
756 else if (! strncmp (argv[0], "r", 1))
757 level = OSPF6_DEBUG_ZEBRA_RECV;
758 }
759 else
760 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
761
762 OSPF6_DEBUG_ZEBRA_OFF (level);
763 return CMD_SUCCESS;
764 }
765
766 ALIAS (no_debug_ospf6_zebra_sendrecv,
767 no_debug_ospf6_zebra_cmd,
768 "no debug ospf6 zebra",
769 NO_STR
770 DEBUG_STR
771 OSPF6_STR
772 "Debug connection between zebra\n"
773 )
774
775 int
776 config_write_ospf6_debug_zebra (struct vty *vty)
777 {
778 if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV))
779 vty_out (vty, "debug ospf6 zebra%s", VNL);
780 else
781 {
782 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
783 vty_out (vty, "debug ospf6 zebra send%s", VNL);
784 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
785 vty_out (vty, "debug ospf6 zebra recv%s", VNL);
786 }
787 return 0;
788 }
789
790 void
791 install_element_ospf6_debug_zebra (void)
792 {
793 install_element (ENABLE_NODE, &debug_ospf6_zebra_cmd);
794 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_cmd);
795 install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd);
796 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
797 install_element (CONFIG_NODE, &debug_ospf6_zebra_cmd);
798 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_cmd);
799 install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd);
800 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
801 }
802
803