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