]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_asbr.c
Merge branch 'dev/osr/vty_index'
[mirror_frr.git] / ospf6d / ospf6_asbr.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 "memory.h"
26 #include "prefix.h"
27 #include "command.h"
28 #include "vty.h"
29 #include "routemap.h"
30 #include "table.h"
31 #include "plist.h"
32 #include "thread.h"
33 #include "linklist.h"
34
35 #include "ospf6_proto.h"
36 #include "ospf6_lsa.h"
37 #include "ospf6_lsdb.h"
38 #include "ospf6_route.h"
39 #include "ospf6_zebra.h"
40 #include "ospf6_message.h"
41
42 #include "ospf6_top.h"
43 #include "ospf6_area.h"
44 #include "ospf6_interface.h"
45 #include "ospf6_neighbor.h"
46 #include "ospf6_asbr.h"
47 #include "ospf6_intra.h"
48 #include "ospf6_flood.h"
49 #include "ospf6d.h"
50
51 unsigned char conf_debug_ospf6_asbr = 0;
52
53 #define ZROUTE_NAME(x) zebra_route_string(x)
54
55 /* AS External LSA origination */
56 static void
57 ospf6_as_external_lsa_originate (struct ospf6_route *route)
58 {
59 char buffer[OSPF6_MAX_LSASIZE];
60 struct ospf6_lsa_header *lsa_header;
61 struct ospf6_lsa *lsa;
62 struct ospf6_external_info *info = route->route_option;
63
64 struct ospf6_as_external_lsa *as_external_lsa;
65 char buf[PREFIX2STR_BUFFER];
66 caddr_t p;
67
68 if (IS_OSPF6_DEBUG_ASBR || IS_OSPF6_DEBUG_ORIGINATE (AS_EXTERNAL))
69 {
70 prefix2str (&route->prefix, buf, sizeof (buf));
71 zlog_debug ("Originate AS-External-LSA for %s", buf);
72 }
73
74 /* prepare buffer */
75 memset (buffer, 0, sizeof (buffer));
76 lsa_header = (struct ospf6_lsa_header *) buffer;
77 as_external_lsa = (struct ospf6_as_external_lsa *)
78 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
79 p = (caddr_t)
80 ((caddr_t) as_external_lsa + sizeof (struct ospf6_as_external_lsa));
81
82 /* Fill AS-External-LSA */
83 /* Metric type */
84 if (route->path.metric_type == 2)
85 SET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E);
86 else
87 UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E);
88
89 /* forwarding address */
90 if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding))
91 SET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F);
92 else
93 UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F);
94
95 /* external route tag */
96 if (info->tag)
97 SET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T);
98 else
99 UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T);
100
101 /* Set metric */
102 OSPF6_ASBR_METRIC_SET (as_external_lsa, route->path.cost);
103
104 /* prefixlen */
105 as_external_lsa->prefix.prefix_length = route->prefix.prefixlen;
106
107 /* PrefixOptions */
108 as_external_lsa->prefix.prefix_options = route->path.prefix_options;
109
110 /* don't use refer LS-type */
111 as_external_lsa->prefix.prefix_refer_lstype = htons (0);
112
113 /* set Prefix */
114 memcpy (p, &route->prefix.u.prefix6,
115 OSPF6_PREFIX_SPACE (route->prefix.prefixlen));
116 ospf6_prefix_apply_mask (&as_external_lsa->prefix);
117 p += OSPF6_PREFIX_SPACE (route->prefix.prefixlen);
118
119 /* Forwarding address */
120 if (CHECK_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F))
121 {
122 memcpy (p, &info->forwarding, sizeof (struct in6_addr));
123 p += sizeof (struct in6_addr);
124 }
125
126 /* External Route Tag */
127 if (CHECK_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T))
128 {
129 route_tag_t network_order = htonl(info->tag);
130
131 memcpy (p, &network_order, sizeof(network_order));
132 p += sizeof(network_order);
133 }
134
135 /* Fill LSA Header */
136 lsa_header->age = 0;
137 lsa_header->type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
138 lsa_header->id = route->path.origin.id;
139 lsa_header->adv_router = ospf6->router_id;
140 lsa_header->seqnum =
141 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
142 lsa_header->adv_router, ospf6->lsdb);
143 lsa_header->length = htons ((caddr_t) p - (caddr_t) lsa_header);
144
145 /* LSA checksum */
146 ospf6_lsa_checksum (lsa_header);
147
148 /* create LSA */
149 lsa = ospf6_lsa_create (lsa_header);
150
151 /* Originate */
152 ospf6_lsa_originate_process (lsa, ospf6);
153 }
154
155 static route_tag_t
156 ospf6_as_external_lsa_get_tag (struct ospf6_lsa *lsa)
157 {
158 struct ospf6_as_external_lsa *external;
159 ptrdiff_t tag_offset;
160 route_tag_t network_order;
161
162 if (!lsa)
163 return 0;
164
165 external = (struct ospf6_as_external_lsa *)
166 OSPF6_LSA_HEADER_END (lsa->header);
167
168 if (!CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_T))
169 return 0;
170
171 tag_offset = sizeof(*external) + OSPF6_PREFIX_SPACE(external->prefix.prefix_length);
172 if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F))
173 tag_offset += sizeof(struct in6_addr);
174
175 memcpy(&network_order, (caddr_t)external + tag_offset, sizeof(network_order));
176 return ntohl(network_order);
177 }
178
179 void
180 ospf6_asbr_lsa_add (struct ospf6_lsa *lsa)
181 {
182 struct ospf6_as_external_lsa *external;
183 struct prefix asbr_id;
184 struct ospf6_route *asbr_entry, *route;
185 char buf[PREFIX2STR_BUFFER];
186
187 external = (struct ospf6_as_external_lsa *)
188 OSPF6_LSA_HEADER_END (lsa->header);
189
190 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
191 zlog_debug ("Calculate AS-External route for %s", lsa->name);
192
193 if (lsa->header->adv_router == ospf6->router_id)
194 {
195 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
196 zlog_debug ("Ignore self-originated AS-External-LSA");
197 return;
198 }
199
200 if (OSPF6_ASBR_METRIC (external) == OSPF_LS_INFINITY)
201 {
202 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
203 zlog_debug ("Ignore LSA with LSInfinity Metric");
204 return;
205 }
206
207 if (CHECK_FLAG(external->prefix.prefix_options, OSPF6_PREFIX_OPTION_NU))
208 {
209 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
210 zlog_debug ("Ignore LSA with NU bit set Metric");
211 return;
212 }
213
214 ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &asbr_id);
215 asbr_entry = ospf6_route_lookup (&asbr_id, ospf6->brouter_table);
216 if (asbr_entry == NULL ||
217 ! CHECK_FLAG (asbr_entry->path.router_bits, OSPF6_ROUTER_BIT_E))
218 {
219 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
220 {
221 prefix2str (&asbr_id, buf, sizeof (buf));
222 zlog_debug ("ASBR entry not found: %s", buf);
223 }
224 return;
225 }
226
227 route = ospf6_route_create ();
228 route->type = OSPF6_DEST_TYPE_NETWORK;
229 route->prefix.family = AF_INET6;
230 route->prefix.prefixlen = external->prefix.prefix_length;
231 ospf6_prefix_in6_addr (&route->prefix.u.prefix6, &external->prefix);
232
233 route->path.area_id = asbr_entry->path.area_id;
234 route->path.origin.type = lsa->header->type;
235 route->path.origin.id = lsa->header->id;
236 route->path.origin.adv_router = lsa->header->adv_router;
237
238 route->path.prefix_options = external->prefix.prefix_options;
239 if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E))
240 {
241 route->path.type = OSPF6_PATH_TYPE_EXTERNAL2;
242 route->path.metric_type = 2;
243 route->path.cost = asbr_entry->path.cost;
244 route->path.u.cost_e2 = OSPF6_ASBR_METRIC (external);
245 }
246 else
247 {
248 route->path.type = OSPF6_PATH_TYPE_EXTERNAL1;
249 route->path.metric_type = 1;
250 route->path.cost = asbr_entry->path.cost + OSPF6_ASBR_METRIC (external);
251 route->path.u.cost_e2 = 0;
252 }
253
254 route->path.tag = ospf6_as_external_lsa_get_tag (lsa);
255
256 ospf6_route_copy_nexthops (route, asbr_entry);
257
258 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
259 {
260 prefix2str (&route->prefix, buf, sizeof (buf));
261 zlog_debug ("AS-External route add: %s", buf);
262 }
263
264 ospf6_route_add (route, ospf6->route_table);
265 }
266
267 void
268 ospf6_asbr_lsa_remove (struct ospf6_lsa *lsa)
269 {
270 struct ospf6_as_external_lsa *external;
271 struct prefix prefix;
272 struct ospf6_route *route, *nroute;
273 char buf[PREFIX2STR_BUFFER];
274
275 external = (struct ospf6_as_external_lsa *)
276 OSPF6_LSA_HEADER_END (lsa->header);
277
278 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
279 zlog_debug ("Withdraw AS-External route for %s", lsa->name);
280
281 if (lsa->header->adv_router == ospf6->router_id)
282 {
283 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
284 zlog_debug ("Ignore self-originated AS-External-LSA");
285 return;
286 }
287
288 memset (&prefix, 0, sizeof (struct prefix));
289 prefix.family = AF_INET6;
290 prefix.prefixlen = external->prefix.prefix_length;
291 ospf6_prefix_in6_addr (&prefix.u.prefix6, &external->prefix);
292
293 route = ospf6_route_lookup (&prefix, ospf6->route_table);
294 if (route == NULL)
295 {
296 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
297 {
298 prefix2str (&prefix, buf, sizeof (buf));
299 zlog_debug ("AS-External route %s not found", buf);
300 }
301 return;
302 }
303
304 for (ospf6_route_lock (route);
305 route && ospf6_route_is_prefix (&prefix, route);
306 route = nroute)
307 {
308 nroute = ospf6_route_next (route);
309 if (route->type != OSPF6_DEST_TYPE_NETWORK)
310 continue;
311 if (route->path.origin.type != lsa->header->type)
312 continue;
313 if (route->path.origin.id != lsa->header->id)
314 continue;
315 if (route->path.origin.adv_router != lsa->header->adv_router)
316 continue;
317
318 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
319 {
320 prefix2str (&route->prefix, buf, sizeof (buf));
321 zlog_debug ("AS-External route remove: %s", buf);
322 }
323 ospf6_route_remove (route, ospf6->route_table);
324 }
325 if (route != NULL)
326 ospf6_route_unlock (route);
327 }
328
329 void
330 ospf6_asbr_lsentry_add (struct ospf6_route *asbr_entry)
331 {
332 struct ospf6_lsa *lsa;
333 u_int16_t type;
334 u_int32_t router;
335
336 if (! CHECK_FLAG (asbr_entry->flag, OSPF6_ROUTE_BEST))
337 {
338 char buf[16];
339 inet_ntop (AF_INET, &ADV_ROUTER_IN_PREFIX (&asbr_entry->prefix),
340 buf, sizeof (buf));
341 zlog_info ("ignore non-best path: lsentry %s add", buf);
342 return;
343 }
344
345 type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
346 router = ospf6_linkstate_prefix_adv_router (&asbr_entry->prefix);
347 for (lsa = ospf6_lsdb_type_router_head (type, router, ospf6->lsdb); lsa;
348 lsa = ospf6_lsdb_type_router_next (type, router, lsa))
349 {
350 if (! OSPF6_LSA_IS_MAXAGE (lsa))
351 ospf6_asbr_lsa_add (lsa);
352 }
353 }
354
355 void
356 ospf6_asbr_lsentry_remove (struct ospf6_route *asbr_entry)
357 {
358 struct ospf6_lsa *lsa;
359 u_int16_t type;
360 u_int32_t router;
361
362 type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
363 router = ospf6_linkstate_prefix_adv_router (&asbr_entry->prefix);
364 for (lsa = ospf6_lsdb_type_router_head (type, router, ospf6->lsdb);
365 lsa; lsa = ospf6_lsdb_type_router_next (type, router, lsa))
366 ospf6_asbr_lsa_remove (lsa);
367 }
368
369
370
371 /* redistribute function */
372
373 static void
374 ospf6_asbr_routemap_set (int type, const char *mapname)
375 {
376 if (ospf6->rmap[type].name)
377 free (ospf6->rmap[type].name);
378 ospf6->rmap[type].name = strdup (mapname);
379 ospf6->rmap[type].map = route_map_lookup_by_name (mapname);
380 }
381
382 static void
383 ospf6_asbr_routemap_unset (int type)
384 {
385 if (ospf6->rmap[type].name)
386 free (ospf6->rmap[type].name);
387 ospf6->rmap[type].name = NULL;
388 ospf6->rmap[type].map = NULL;
389 }
390
391 static void
392 ospf6_asbr_routemap_update (const char *mapname)
393 {
394 int type;
395
396 if (ospf6 == NULL)
397 return;
398
399 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
400 {
401 if (ospf6->rmap[type].name)
402 ospf6->rmap[type].map =
403 route_map_lookup_by_name (ospf6->rmap[type].name);
404 else
405 ospf6->rmap[type].map = NULL;
406 }
407 }
408
409 int
410 ospf6_asbr_is_asbr (struct ospf6 *o)
411 {
412 return o->external_table->count;
413 }
414
415 static void
416 ospf6_asbr_redistribute_set (int type)
417 {
418 ospf6_zebra_redistribute (type);
419 }
420
421 static void
422 ospf6_asbr_redistribute_unset (int type)
423 {
424 struct ospf6_route *route;
425 struct ospf6_external_info *info;
426
427 ospf6_zebra_no_redistribute (type);
428
429 for (route = ospf6_route_head (ospf6->external_table); route;
430 route = ospf6_route_next (route))
431 {
432 info = route->route_option;
433 if (info->type != type)
434 continue;
435
436 ospf6_asbr_redistribute_remove (info->type, 0, &route->prefix);
437 }
438
439 ospf6_asbr_routemap_unset (type);
440 }
441
442 /* When an area is unstubified, flood all the external LSAs in the area */
443 void
444 ospf6_asbr_send_externals_to_area (struct ospf6_area *oa)
445 {
446 struct ospf6_lsa *lsa;
447
448 for (lsa = ospf6_lsdb_head (oa->ospf6->lsdb); lsa;
449 lsa = ospf6_lsdb_next (lsa))
450 {
451 if (ntohs (lsa->header->type) == OSPF6_LSTYPE_AS_EXTERNAL)
452 {
453 zlog_debug ("%s: Flooding AS-External LSA %s\n", __func__, lsa->name);
454 ospf6_flood_area (NULL, lsa, oa);
455 }
456 }
457 }
458
459 void
460 ospf6_asbr_redistribute_add (int type, ifindex_t ifindex, struct prefix *prefix,
461 u_int nexthop_num, struct in6_addr *nexthop, route_tag_t tag)
462 {
463 int ret;
464 struct ospf6_route troute;
465 struct ospf6_external_info tinfo;
466 struct ospf6_route *route, *match;
467 struct ospf6_external_info *info;
468 struct prefix prefix_id;
469 struct route_node *node;
470 char pbuf[PREFIX2STR_BUFFER], ibuf[16];
471 struct listnode *lnode, *lnnode;
472 struct ospf6_area *oa;
473
474 if (! ospf6_zebra_is_redistribute (type))
475 return;
476
477 if (IS_OSPF6_DEBUG_ASBR)
478 {
479 prefix2str (prefix, pbuf, sizeof (pbuf));
480 zlog_debug ("Redistribute %s (%s)", pbuf, ZROUTE_NAME (type));
481 }
482
483 /* if route-map was specified but not found, do not advertise */
484 if (ospf6->rmap[type].name)
485 {
486 if (ospf6->rmap[type].map == NULL)
487 ospf6_asbr_routemap_update (NULL);
488 if (ospf6->rmap[type].map == NULL)
489 {
490 zlog_warn ("route-map \"%s\" not found, suppress redistributing",
491 ospf6->rmap[type].name);
492 return;
493 }
494 }
495
496 /* apply route-map */
497 if (ospf6->rmap[type].map)
498 {
499 memset (&troute, 0, sizeof (troute));
500 memset (&tinfo, 0, sizeof (tinfo));
501 troute.route_option = &tinfo;
502 tinfo.ifindex = ifindex;
503 tinfo.tag = tag;
504
505 ret = route_map_apply (ospf6->rmap[type].map, prefix,
506 RMAP_OSPF6, &troute);
507 if (ret == RMAP_DENYMATCH)
508 {
509 if (IS_OSPF6_DEBUG_ASBR)
510 zlog_debug ("Denied by route-map \"%s\"", ospf6->rmap[type].name);
511 return;
512 }
513 }
514
515 match = ospf6_route_lookup (prefix, ospf6->external_table);
516 if (match)
517 {
518 info = match->route_option;
519
520 /* copy result of route-map */
521 if (ospf6->rmap[type].map)
522 {
523 if (troute.path.metric_type)
524 match->path.metric_type = troute.path.metric_type;
525 if (troute.path.cost)
526 match->path.cost = troute.path.cost;
527 if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo.forwarding))
528 memcpy (&info->forwarding, &tinfo.forwarding,
529 sizeof (struct in6_addr));
530 info->tag = tinfo.tag;
531 }
532 else
533 {
534 /* If there is no route-map, simply update the tag */
535 info->tag = tag;
536 }
537
538 info->type = type;
539
540 if (nexthop_num && nexthop)
541 ospf6_route_add_nexthop (match, ifindex, nexthop);
542 else
543 ospf6_route_add_nexthop (match, ifindex, NULL);
544
545 /* create/update binding in external_id_table */
546 prefix_id.family = AF_INET;
547 prefix_id.prefixlen = 32;
548 prefix_id.u.prefix4.s_addr = htonl (info->id);
549 node = route_node_get (ospf6->external_id_table, &prefix_id);
550 node->info = match;
551
552 if (IS_OSPF6_DEBUG_ASBR)
553 {
554 inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
555 zlog_debug ("Advertise as AS-External Id:%s", ibuf);
556 }
557
558 match->path.origin.id = htonl (info->id);
559 ospf6_as_external_lsa_originate (match);
560 return;
561 }
562
563 /* create new entry */
564 route = ospf6_route_create ();
565 route->type = OSPF6_DEST_TYPE_NETWORK;
566 memcpy (&route->prefix, prefix, sizeof (struct prefix));
567
568 info = (struct ospf6_external_info *)
569 XCALLOC (MTYPE_OSPF6_EXTERNAL_INFO, sizeof (struct ospf6_external_info));
570 route->route_option = info;
571 info->id = ospf6->external_id++;
572
573 /* copy result of route-map */
574 if (ospf6->rmap[type].map)
575 {
576 if (troute.path.metric_type)
577 route->path.metric_type = troute.path.metric_type;
578 if (troute.path.cost)
579 route->path.cost = troute.path.cost;
580 if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo.forwarding))
581 memcpy (&info->forwarding, &tinfo.forwarding,
582 sizeof (struct in6_addr));
583 info->tag = tinfo.tag;
584 }
585 else
586 {
587 /* If there is no route-map, simply set the tag */
588 info->tag = tag;
589 }
590
591 info->type = type;
592 if (nexthop_num && nexthop)
593 ospf6_route_add_nexthop (route, ifindex, nexthop);
594 else
595 ospf6_route_add_nexthop (route, ifindex, NULL);
596
597 /* create/update binding in external_id_table */
598 prefix_id.family = AF_INET;
599 prefix_id.prefixlen = 32;
600 prefix_id.u.prefix4.s_addr = htonl (info->id);
601 node = route_node_get (ospf6->external_id_table, &prefix_id);
602 node->info = route;
603
604 route = ospf6_route_add (route, ospf6->external_table);
605 route->route_option = info;
606
607 if (IS_OSPF6_DEBUG_ASBR)
608 {
609 inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
610 zlog_debug ("Advertise as AS-External Id:%s", ibuf);
611 }
612
613 route->path.origin.id = htonl (info->id);
614 ospf6_as_external_lsa_originate (route);
615
616 /* Router-Bit (ASBR Flag) may have to be updated */
617 for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa))
618 OSPF6_ROUTER_LSA_SCHEDULE (oa);
619 }
620
621 void
622 ospf6_asbr_redistribute_remove (int type, ifindex_t ifindex,
623 struct prefix *prefix)
624 {
625 struct ospf6_route *match;
626 struct ospf6_external_info *info = NULL;
627 struct route_node *node;
628 struct ospf6_lsa *lsa;
629 struct prefix prefix_id;
630 char pbuf[PREFIX2STR_BUFFER], ibuf[16];
631 struct listnode *lnode, *lnnode;
632 struct ospf6_area *oa;
633
634 match = ospf6_route_lookup (prefix, ospf6->external_table);
635 if (match == NULL)
636 {
637 if (IS_OSPF6_DEBUG_ASBR)
638 {
639 prefix2str (prefix, pbuf, sizeof (pbuf));
640 zlog_debug ("No such route %s to withdraw", pbuf);
641 }
642 return;
643 }
644
645 info = match->route_option;
646 assert (info);
647
648 if (info->type != type)
649 {
650 if (IS_OSPF6_DEBUG_ASBR)
651 {
652 prefix2str (prefix, pbuf, sizeof (pbuf));
653 zlog_debug ("Original protocol mismatch: %s", pbuf);
654 }
655 return;
656 }
657
658 if (IS_OSPF6_DEBUG_ASBR)
659 {
660 prefix2str (prefix, pbuf, sizeof (pbuf));
661 inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
662 zlog_debug ("Withdraw %s (AS-External Id:%s)", pbuf, ibuf);
663 }
664
665 lsa = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL),
666 htonl (info->id), ospf6->router_id, ospf6->lsdb);
667 if (lsa)
668 ospf6_lsa_purge (lsa);
669
670 /* remove binding in external_id_table */
671 prefix_id.family = AF_INET;
672 prefix_id.prefixlen = 32;
673 prefix_id.u.prefix4.s_addr = htonl (info->id);
674 node = route_node_lookup (ospf6->external_id_table, &prefix_id);
675 assert (node);
676 node->info = NULL;
677 route_unlock_node (node);
678
679 ospf6_route_remove (match, ospf6->external_table);
680 XFREE (MTYPE_OSPF6_EXTERNAL_INFO, info);
681
682 /* Router-Bit (ASBR Flag) may have to be updated */
683 for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa))
684 OSPF6_ROUTER_LSA_SCHEDULE (oa);
685 }
686
687 DEFUN (ospf6_redistribute,
688 ospf6_redistribute_cmd,
689 "redistribute <kernel|connected|static|ripng|isis|bgp|table>",
690 "Redistribute\n"
691 QUAGGA_REDIST_HELP_STR_OSPF6D)
692 {
693 int type;
694
695 type = proto_redistnum(AFI_IP6, argv[2]->arg);
696 if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
697 return CMD_WARNING;
698
699 ospf6_asbr_redistribute_unset (type);
700 ospf6_asbr_redistribute_set (type);
701 return CMD_SUCCESS;
702 }
703
704 DEFUN (ospf6_redistribute_routemap,
705 ospf6_redistribute_routemap_cmd,
706 "redistribute <kernel|connected|static|ripng|isis|bgp|table> route-map WORD",
707 "Redistribute\n"
708 QUAGGA_REDIST_HELP_STR_OSPF6D
709 "Route map reference\n"
710 "Route map name\n")
711 {
712 int idx_protocol = 1;
713 int idx_word = 3;
714 int type;
715
716 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->arg);
717 if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
718 return CMD_WARNING;
719
720 ospf6_asbr_redistribute_unset (type);
721 ospf6_asbr_routemap_set (type, argv[idx_word]->arg);
722 ospf6_asbr_redistribute_set (type);
723 return CMD_SUCCESS;
724 }
725
726 DEFUN (no_ospf6_redistribute,
727 no_ospf6_redistribute_cmd,
728 "no redistribute <kernel|connected|static|ripng|isis|bgp|table> [route-map WORD]",
729 NO_STR
730 "Redistribute\n"
731 QUAGGA_REDIST_HELP_STR_OSPF6D
732 "Route map reference\n"
733 "Route map name\n")
734 {
735 int idx_protocol = 2;
736 int type;
737
738 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
739 if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
740 return CMD_WARNING;
741
742 ospf6_asbr_redistribute_unset (type);
743
744 return CMD_SUCCESS;
745 }
746
747
748 int
749 ospf6_redistribute_config_write (struct vty *vty)
750 {
751 int type;
752
753 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
754 {
755 if (type == ZEBRA_ROUTE_OSPF6)
756 continue;
757 if (! ospf6_zebra_is_redistribute (type))
758 continue;
759
760 if (ospf6->rmap[type].name)
761 vty_out (vty, " redistribute %s route-map %s%s",
762 ZROUTE_NAME (type), ospf6->rmap[type].name, VNL);
763 else
764 vty_out (vty, " redistribute %s%s",
765 ZROUTE_NAME (type), VNL);
766 }
767
768 return 0;
769 }
770
771 static void
772 ospf6_redistribute_show_config (struct vty *vty)
773 {
774 int type;
775 int nroute[ZEBRA_ROUTE_MAX];
776 int total;
777 struct ospf6_route *route;
778 struct ospf6_external_info *info;
779
780 total = 0;
781 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
782 nroute[type] = 0;
783 for (route = ospf6_route_head (ospf6->external_table); route;
784 route = ospf6_route_next (route))
785 {
786 info = route->route_option;
787 nroute[info->type]++;
788 total++;
789 }
790
791 vty_out (vty, "Redistributing External Routes from:%s", VNL);
792 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
793 {
794 if (type == ZEBRA_ROUTE_OSPF6)
795 continue;
796 if (! ospf6_zebra_is_redistribute (type))
797 continue;
798
799 if (ospf6->rmap[type].name)
800 vty_out (vty, " %d: %s with route-map \"%s\"%s%s", nroute[type],
801 ZROUTE_NAME (type), ospf6->rmap[type].name,
802 (ospf6->rmap[type].map ? "" : " (not found !)"),
803 VNL);
804 else
805 vty_out (vty, " %d: %s%s", nroute[type],
806 ZROUTE_NAME (type), VNL);
807 }
808 vty_out (vty, "Total %d routes%s", total, VNL);
809 }
810
811
812
813 /* Routemap Functions */
814 static route_map_result_t
815 ospf6_routemap_rule_match_address_prefixlist (void *rule,
816 struct prefix *prefix,
817 route_map_object_t type,
818 void *object)
819 {
820 struct prefix_list *plist;
821
822 if (type != RMAP_OSPF6)
823 return RMAP_NOMATCH;
824
825 plist = prefix_list_lookup (AFI_IP6, (char *) rule);
826 if (plist == NULL)
827 return RMAP_NOMATCH;
828
829 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
830 RMAP_NOMATCH : RMAP_MATCH);
831 }
832
833 static void *
834 ospf6_routemap_rule_match_address_prefixlist_compile (const char *arg)
835 {
836 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
837 }
838
839 static void
840 ospf6_routemap_rule_match_address_prefixlist_free (void *rule)
841 {
842 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
843 }
844
845 struct route_map_rule_cmd
846 ospf6_routemap_rule_match_address_prefixlist_cmd =
847 {
848 "ipv6 address prefix-list",
849 ospf6_routemap_rule_match_address_prefixlist,
850 ospf6_routemap_rule_match_address_prefixlist_compile,
851 ospf6_routemap_rule_match_address_prefixlist_free,
852 };
853
854 /* `match interface IFNAME' */
855 /* Match function should return 1 if match is success else return
856 zero. */
857 static route_map_result_t
858 ospf6_routemap_rule_match_interface (void *rule, struct prefix *prefix,
859 route_map_object_t type, void *object)
860 {
861 struct interface *ifp;
862 struct ospf6_external_info *ei;
863
864 if (type == RMAP_OSPF6)
865 {
866 ei = ((struct ospf6_route *) object)->route_option;
867 ifp = if_lookup_by_name ((char *)rule);
868
869 if (ifp != NULL
870 && ei->ifindex == ifp->ifindex)
871 return RMAP_MATCH;
872 }
873
874 return RMAP_NOMATCH;
875 }
876
877 /* Route map `interface' match statement. `arg' should be
878 interface name. */
879 static void *
880 ospf6_routemap_rule_match_interface_compile (const char *arg)
881 {
882 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
883 }
884
885 /* Free route map's compiled `interface' value. */
886 static void
887 ospf6_routemap_rule_match_interface_free (void *rule)
888 {
889 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
890 }
891
892 /* Route map commands for interface matching. */
893 struct route_map_rule_cmd
894 ospf6_routemap_rule_match_interface_cmd =
895 {
896 "interface",
897 ospf6_routemap_rule_match_interface,
898 ospf6_routemap_rule_match_interface_compile,
899 ospf6_routemap_rule_match_interface_free
900 };
901
902 /* Match function for matching route tags */
903 static route_map_result_t
904 ospf6_routemap_rule_match_tag (void *rule, struct prefix *prefix,
905 route_map_object_t type, void *object)
906 {
907 route_tag_t *tag = rule;
908 struct ospf6_route *route = object;
909 struct ospf6_external_info *info = route->route_option;
910
911 if (type == RMAP_OSPF6 && info->tag == *tag)
912 return RMAP_MATCH;
913
914 return RMAP_NOMATCH;
915 }
916
917 static struct route_map_rule_cmd
918 ospf6_routemap_rule_match_tag_cmd =
919 {
920 "tag",
921 ospf6_routemap_rule_match_tag,
922 route_map_rule_tag_compile,
923 route_map_rule_tag_free,
924 };
925
926 static route_map_result_t
927 ospf6_routemap_rule_set_metric_type (void *rule, struct prefix *prefix,
928 route_map_object_t type, void *object)
929 {
930 char *metric_type = rule;
931 struct ospf6_route *route = object;
932
933 if (type != RMAP_OSPF6)
934 return RMAP_OKAY;
935
936 if (strcmp (metric_type, "type-2") == 0)
937 route->path.metric_type = 2;
938 else
939 route->path.metric_type = 1;
940
941 return RMAP_OKAY;
942 }
943
944 static void *
945 ospf6_routemap_rule_set_metric_type_compile (const char *arg)
946 {
947 if (strcmp (arg, "type-2") && strcmp (arg, "type-1"))
948 return NULL;
949 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
950 }
951
952 static void
953 ospf6_routemap_rule_set_metric_type_free (void *rule)
954 {
955 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
956 }
957
958 struct route_map_rule_cmd
959 ospf6_routemap_rule_set_metric_type_cmd =
960 {
961 "metric-type",
962 ospf6_routemap_rule_set_metric_type,
963 ospf6_routemap_rule_set_metric_type_compile,
964 ospf6_routemap_rule_set_metric_type_free,
965 };
966
967 static route_map_result_t
968 ospf6_routemap_rule_set_metric (void *rule, struct prefix *prefix,
969 route_map_object_t type, void *object)
970 {
971 char *metric = rule;
972 struct ospf6_route *route = object;
973
974 if (type != RMAP_OSPF6)
975 return RMAP_OKAY;
976
977 route->path.cost = atoi (metric);
978 return RMAP_OKAY;
979 }
980
981 static void *
982 ospf6_routemap_rule_set_metric_compile (const char *arg)
983 {
984 u_int32_t metric;
985 char *endp;
986 metric = strtoul (arg, &endp, 0);
987 if (metric > OSPF_LS_INFINITY || *endp != '\0')
988 return NULL;
989 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
990 }
991
992 static void
993 ospf6_routemap_rule_set_metric_free (void *rule)
994 {
995 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
996 }
997
998 struct route_map_rule_cmd
999 ospf6_routemap_rule_set_metric_cmd =
1000 {
1001 "metric",
1002 ospf6_routemap_rule_set_metric,
1003 ospf6_routemap_rule_set_metric_compile,
1004 ospf6_routemap_rule_set_metric_free,
1005 };
1006
1007 static route_map_result_t
1008 ospf6_routemap_rule_set_forwarding (void *rule, struct prefix *prefix,
1009 route_map_object_t type, void *object)
1010 {
1011 char *forwarding = rule;
1012 struct ospf6_route *route = object;
1013 struct ospf6_external_info *info = route->route_option;
1014
1015 if (type != RMAP_OSPF6)
1016 return RMAP_OKAY;
1017
1018 if (inet_pton (AF_INET6, forwarding, &info->forwarding) != 1)
1019 {
1020 memset (&info->forwarding, 0, sizeof (struct in6_addr));
1021 return RMAP_ERROR;
1022 }
1023
1024 return RMAP_OKAY;
1025 }
1026
1027 static void *
1028 ospf6_routemap_rule_set_forwarding_compile (const char *arg)
1029 {
1030 struct in6_addr a;
1031 if (inet_pton (AF_INET6, arg, &a) != 1)
1032 return NULL;
1033 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1034 }
1035
1036 static void
1037 ospf6_routemap_rule_set_forwarding_free (void *rule)
1038 {
1039 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1040 }
1041
1042 struct route_map_rule_cmd
1043 ospf6_routemap_rule_set_forwarding_cmd =
1044 {
1045 "forwarding-address",
1046 ospf6_routemap_rule_set_forwarding,
1047 ospf6_routemap_rule_set_forwarding_compile,
1048 ospf6_routemap_rule_set_forwarding_free,
1049 };
1050
1051 static route_map_result_t
1052 ospf6_routemap_rule_set_tag (void *rule, struct prefix *prefix,
1053 route_map_object_t type, void *object)
1054 {
1055 route_tag_t *tag = rule;
1056 struct ospf6_route *route = object;
1057 struct ospf6_external_info *info = route->route_option;
1058
1059 if (type != RMAP_OSPF6)
1060 return RMAP_OKAY;
1061
1062 info->tag = *tag;
1063 return RMAP_OKAY;
1064 }
1065
1066 static struct route_map_rule_cmd
1067 ospf6_routemap_rule_set_tag_cmd =
1068 {
1069 "tag",
1070 ospf6_routemap_rule_set_tag,
1071 route_map_rule_tag_compile,
1072 route_map_rule_tag_free,
1073 };
1074
1075 static int
1076 route_map_command_status (struct vty *vty, int ret)
1077 {
1078 if (! ret)
1079 return CMD_SUCCESS;
1080
1081 switch (ret)
1082 {
1083 case RMAP_RULE_MISSING:
1084 vty_out (vty, "OSPF6 Can't find rule.%s", VNL);
1085 break;
1086 case RMAP_COMPILE_ERROR:
1087 vty_out (vty, "OSPF6 Argument is malformed.%s", VNL);
1088 break;
1089 default:
1090 vty_out (vty, "OSPF6 route-map add set failed.%s", VNL);
1091 break;
1092 }
1093 return CMD_WARNING;
1094 }
1095
1096 /* add "match address" */
1097 DEFUN (ospf6_routemap_match_address_prefixlist,
1098 ospf6_routemap_match_address_prefixlist_cmd,
1099 "match ipv6 address prefix-list WORD",
1100 "Match values\n"
1101 IPV6_STR
1102 "Match address of route\n"
1103 "Match entries of prefix-lists\n"
1104 "IPv6 prefix-list name\n")
1105 {
1106 VTY_DECLVAR_CONTEXT(route_map_index, route_map_index);
1107 int idx_word = 4;
1108 int ret = route_map_add_match (route_map_index,
1109 "ipv6 address prefix-list", argv[idx_word]->arg);
1110 return route_map_command_status (vty, ret);
1111 }
1112
1113 /* delete "match address" */
1114 DEFUN (ospf6_routemap_no_match_address_prefixlist,
1115 ospf6_routemap_no_match_address_prefixlist_cmd,
1116 "no match ipv6 address prefix-list WORD",
1117 NO_STR
1118 "Match values\n"
1119 IPV6_STR
1120 "Match address of route\n"
1121 "Match entries of prefix-lists\n"
1122 "IPv6 prefix-list name\n")
1123 {
1124 VTY_DECLVAR_CONTEXT(route_map_index, route_map_index);
1125 int idx_word = 5;
1126 int ret = route_map_delete_match (route_map_index,
1127 "ipv6 address prefix-list", argv[idx_word]->arg);
1128 return route_map_command_status (vty, ret);
1129 }
1130
1131 /* "match interface" */
1132 DEFUN (ospf6_routemap_match_interface,
1133 ospf6_routemap_match_interface_cmd,
1134 "match interface WORD",
1135 MATCH_STR
1136 "Match first hop interface of route\n"
1137 "Interface name\n")
1138 {
1139 VTY_DECLVAR_CONTEXT(route_map_index, route_map_index);
1140 int idx_word = 2;
1141 return route_map_add_match (route_map_index,
1142 "interface", argv[idx_word]->arg);
1143 }
1144
1145 /* "no match interface WORD" */
1146 DEFUN (ospf6_routemap_no_match_interface,
1147 ospf6_routemap_no_match_interface_cmd,
1148 "no match interface [WORD]",
1149 NO_STR
1150 MATCH_STR
1151 "Match first hop interface of route\n"
1152 "Interface name\n")
1153 {
1154 VTY_DECLVAR_CONTEXT(route_map_index, route_map_index);
1155 int idx_word = 3;
1156 int ret;
1157
1158 if (argc == 4)
1159 ret = route_map_delete_match (route_map_index,
1160 "interface", argv[idx_word]->arg);
1161 else
1162 ret = route_map_delete_match (route_map_index,
1163 "interface", NULL);
1164 return route_map_command_status (vty, ret);
1165 }
1166
1167 /* add "set metric-type" */
1168 DEFUN (ospf6_routemap_set_metric_type,
1169 ospf6_routemap_set_metric_type_cmd,
1170 "set metric-type <type-1|type-2>",
1171 "Set value\n"
1172 "Type of metric\n"
1173 "OSPF6 external type 1 metric\n"
1174 "OSPF6 external type 2 metric\n")
1175 {
1176 VTY_DECLVAR_CONTEXT(route_map_index, route_map_index);
1177 int idx_external = 2;
1178 int ret = route_map_add_set (route_map_index,
1179 "metric-type", argv[idx_external]->arg);
1180 return route_map_command_status (vty, ret);
1181 }
1182
1183 /* delete "set metric-type" */
1184 DEFUN (ospf6_routemap_no_set_metric_type,
1185 ospf6_routemap_no_set_metric_type_cmd,
1186 "no set metric-type <type-1|type-2>",
1187 NO_STR
1188 "Set value\n"
1189 "Type of metric\n"
1190 "OSPF6 external type 1 metric\n"
1191 "OSPF6 external type 2 metric\n")
1192 {
1193 VTY_DECLVAR_CONTEXT(route_map_index, route_map_index);
1194 int idx_external = 3;
1195 int ret = route_map_delete_set (route_map_index,
1196 "metric-type", argv[idx_external]->arg);
1197 return route_map_command_status (vty, ret);
1198 }
1199
1200 /* add "set forwarding-address" */
1201 DEFUN (ospf6_routemap_set_forwarding,
1202 ospf6_routemap_set_forwarding_cmd,
1203 "set forwarding-address X:X::X:X",
1204 "Set value\n"
1205 "Forwarding Address\n"
1206 "IPv6 Address\n")
1207 {
1208 VTY_DECLVAR_CONTEXT(route_map_index, route_map_index);
1209 int idx_ipv6 = 2;
1210 int ret = route_map_add_set (route_map_index,
1211 "forwarding-address", argv[idx_ipv6]->arg);
1212 return route_map_command_status (vty, ret);
1213 }
1214
1215 /* delete "set forwarding-address" */
1216 DEFUN (ospf6_routemap_no_set_forwarding,
1217 ospf6_routemap_no_set_forwarding_cmd,
1218 "no set forwarding-address X:X::X:X",
1219 NO_STR
1220 "Set value\n"
1221 "Forwarding Address\n"
1222 "IPv6 Address\n")
1223 {
1224 VTY_DECLVAR_CONTEXT(route_map_index, route_map_index);
1225 int idx_ipv6 = 3;
1226 int ret = route_map_delete_set (route_map_index,
1227 "forwarding-address", argv[idx_ipv6]->arg);
1228 return route_map_command_status (vty, ret);
1229 }
1230
1231 /* add "set tag" */
1232 DEFUN (ospf6_routemap_set_tag,
1233 ospf6_routemap_set_tag_cmd,
1234 "set tag (1-4294967295)",
1235 "Set value\n"
1236 "Tag value for routing protocol\n"
1237 "Tag value\n")
1238 {
1239 VTY_DECLVAR_CONTEXT(route_map_index, route_map_index);
1240 int ret = route_map_add_set (route_map_index,
1241 "tag", argv[2]->arg);
1242 return route_map_command_status (vty, ret);
1243 }
1244
1245 /* delete "set tag" */
1246 DEFUN (ospf6_routemap_no_set_tag,
1247 ospf6_routemap_no_set_tag_cmd,
1248 "no set tag [(1-4294967295)]",
1249 NO_STR
1250 "Set value\n"
1251 "Tag value for routing protocol\n"
1252 "Tag value\n")
1253 {
1254 char *tag = (argc == 4) ? argv[3]->arg : NULL;
1255 VTY_DECLVAR_CONTEXT (route_map_index, index);
1256 int ret = route_map_delete_set (index, "tag", tag);
1257 return route_map_command_status (vty, ret);
1258 }
1259
1260 static void
1261 ospf6_routemap_init (void)
1262 {
1263 route_map_init ();
1264
1265 route_map_add_hook (ospf6_asbr_routemap_update);
1266 route_map_delete_hook (ospf6_asbr_routemap_update);
1267
1268 route_map_set_metric_hook (generic_set_add);
1269 route_map_no_set_metric_hook (generic_set_delete);
1270
1271 route_map_install_match (&ospf6_routemap_rule_match_address_prefixlist_cmd);
1272 route_map_install_match (&ospf6_routemap_rule_match_interface_cmd);
1273 route_map_install_match (&ospf6_routemap_rule_match_tag_cmd);
1274
1275 route_map_install_set (&ospf6_routemap_rule_set_metric_type_cmd);
1276 route_map_install_set (&ospf6_routemap_rule_set_metric_cmd);
1277 route_map_install_set (&ospf6_routemap_rule_set_forwarding_cmd);
1278 route_map_install_set (&ospf6_routemap_rule_set_tag_cmd);
1279
1280 /* Match address prefix-list */
1281 install_element (RMAP_NODE, &ospf6_routemap_match_address_prefixlist_cmd);
1282 install_element (RMAP_NODE, &ospf6_routemap_no_match_address_prefixlist_cmd);
1283
1284 /* Match interface */
1285 install_element (RMAP_NODE, &ospf6_routemap_match_interface_cmd);
1286 install_element (RMAP_NODE, &ospf6_routemap_no_match_interface_cmd);
1287
1288 /* ASE Metric Type (e.g. Type-1/Type-2) */
1289 install_element (RMAP_NODE, &ospf6_routemap_set_metric_type_cmd);
1290 install_element (RMAP_NODE, &ospf6_routemap_no_set_metric_type_cmd);
1291
1292 /* ASE Metric */
1293 install_element (RMAP_NODE, &ospf6_routemap_set_forwarding_cmd);
1294 install_element (RMAP_NODE, &ospf6_routemap_no_set_forwarding_cmd);
1295
1296 /* Tag */
1297 install_element (RMAP_NODE, &ospf6_routemap_set_tag_cmd);
1298 install_element (RMAP_NODE, &ospf6_routemap_no_set_tag_cmd);
1299 }
1300
1301
1302 /* Display functions */
1303 static char *
1304 ospf6_as_external_lsa_get_prefix_str (struct ospf6_lsa *lsa, char *buf,
1305 int buflen, int pos)
1306 {
1307 struct ospf6_as_external_lsa *external;
1308 struct in6_addr in6;
1309 int prefix_length = 0;
1310
1311 if (lsa)
1312 {
1313 external = (struct ospf6_as_external_lsa *)
1314 OSPF6_LSA_HEADER_END (lsa->header);
1315
1316 if (pos == 0)
1317 {
1318 ospf6_prefix_in6_addr (&in6, &external->prefix);
1319 prefix_length = external->prefix.prefix_length;
1320 }
1321 else {
1322 in6 = *((struct in6_addr *)
1323 ((caddr_t) external + sizeof (struct ospf6_as_external_lsa) +
1324 OSPF6_PREFIX_SPACE (external->prefix.prefix_length)));
1325 }
1326 if (buf)
1327 {
1328 inet_ntop (AF_INET6, &in6, buf, buflen);
1329 if (prefix_length)
1330 sprintf (&buf[strlen(buf)], "/%d", prefix_length);
1331 }
1332 }
1333 return (buf);
1334 }
1335
1336 static int
1337 ospf6_as_external_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
1338 {
1339 struct ospf6_as_external_lsa *external;
1340 char buf[64];
1341
1342 assert (lsa->header);
1343 external = (struct ospf6_as_external_lsa *)
1344 OSPF6_LSA_HEADER_END (lsa->header);
1345
1346 /* bits */
1347 snprintf (buf, sizeof (buf), "%c%c%c",
1348 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E) ? 'E' : '-'),
1349 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F) ? 'F' : '-'),
1350 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_T) ? 'T' : '-'));
1351
1352 vty_out (vty, " Bits: %s%s", buf, VNL);
1353 vty_out (vty, " Metric: %5lu%s", (u_long) OSPF6_ASBR_METRIC (external),
1354 VNL);
1355
1356 ospf6_prefix_options_printbuf (external->prefix.prefix_options,
1357 buf, sizeof (buf));
1358 vty_out (vty, " Prefix Options: %s%s", buf,
1359 VNL);
1360
1361 vty_out (vty, " Referenced LSType: %d%s",
1362 ntohs (external->prefix.prefix_refer_lstype),
1363 VNL);
1364
1365 vty_out (vty, " Prefix: %s%s",
1366 ospf6_as_external_lsa_get_prefix_str (lsa, buf, sizeof(buf), 0), VNL);
1367
1368 /* Forwarding-Address */
1369 if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F))
1370 {
1371 vty_out (vty, " Forwarding-Address: %s%s",
1372 ospf6_as_external_lsa_get_prefix_str (lsa, buf, sizeof(buf), 1),
1373 VNL);
1374 }
1375
1376 /* Tag */
1377 if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_T))
1378 {
1379 vty_out (vty, " Tag: %"ROUTE_TAG_PRI"%s",
1380 ospf6_as_external_lsa_get_tag (lsa), VNL);
1381 }
1382
1383 return 0;
1384 }
1385
1386 static void
1387 ospf6_asbr_external_route_show (struct vty *vty, struct ospf6_route *route)
1388 {
1389 struct ospf6_external_info *info = route->route_option;
1390 char prefix[PREFIX2STR_BUFFER], id[16], forwarding[64];
1391 u_int32_t tmp_id;
1392
1393 prefix2str (&route->prefix, prefix, sizeof (prefix));
1394 tmp_id = ntohl (info->id);
1395 inet_ntop (AF_INET, &tmp_id, id, sizeof (id));
1396 if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding))
1397 inet_ntop (AF_INET6, &info->forwarding, forwarding, sizeof (forwarding));
1398 else
1399 snprintf (forwarding, sizeof (forwarding), ":: (ifindex %d)",
1400 ospf6_route_get_first_nh_index (route));
1401
1402 vty_out (vty, "%c %-32s %-15s type-%d %5lu %s%s",
1403 zebra_route_char(info->type),
1404 prefix, id, route->path.metric_type,
1405 (u_long) (route->path.metric_type == 2 ?
1406 route->path.u.cost_e2 : route->path.cost),
1407 forwarding, VNL);
1408 }
1409
1410 DEFUN (show_ipv6_ospf6_redistribute,
1411 show_ipv6_ospf6_redistribute_cmd,
1412 "show ipv6 ospf6 redistribute",
1413 SHOW_STR
1414 IP6_STR
1415 OSPF6_STR
1416 "redistributing External information\n"
1417 )
1418 {
1419 struct ospf6_route *route;
1420
1421 OSPF6_CMD_CHECK_RUNNING ();
1422
1423 ospf6_redistribute_show_config (vty);
1424
1425 for (route = ospf6_route_head (ospf6->external_table); route;
1426 route = ospf6_route_next (route))
1427 ospf6_asbr_external_route_show (vty, route);
1428
1429 return CMD_SUCCESS;
1430 }
1431
1432 struct ospf6_lsa_handler as_external_handler =
1433 {
1434 OSPF6_LSTYPE_AS_EXTERNAL,
1435 "AS-External",
1436 "ASE",
1437 ospf6_as_external_lsa_show,
1438 ospf6_as_external_lsa_get_prefix_str
1439 };
1440
1441 void
1442 ospf6_asbr_init (void)
1443 {
1444 ospf6_routemap_init ();
1445
1446 ospf6_install_lsa_handler (&as_external_handler);
1447
1448 install_element (VIEW_NODE, &show_ipv6_ospf6_redistribute_cmd);
1449
1450 install_element (OSPF6_NODE, &ospf6_redistribute_cmd);
1451 install_element (OSPF6_NODE, &ospf6_redistribute_routemap_cmd);
1452 install_element (OSPF6_NODE, &no_ospf6_redistribute_cmd);
1453 }
1454
1455 void
1456 ospf6_asbr_redistribute_reset (void)
1457 {
1458 int type;
1459
1460 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
1461 {
1462 if (type == ZEBRA_ROUTE_OSPF6)
1463 continue;
1464 if (ospf6_zebra_is_redistribute (type))
1465 ospf6_asbr_redistribute_unset(type);
1466 }
1467 }
1468
1469 void
1470 ospf6_asbr_terminate (void)
1471 {
1472 route_map_finish ();
1473 }
1474
1475 DEFUN (debug_ospf6_asbr,
1476 debug_ospf6_asbr_cmd,
1477 "debug ospf6 asbr",
1478 DEBUG_STR
1479 OSPF6_STR
1480 "Debug OSPFv3 ASBR function\n"
1481 )
1482 {
1483 OSPF6_DEBUG_ASBR_ON ();
1484 return CMD_SUCCESS;
1485 }
1486
1487 DEFUN (no_debug_ospf6_asbr,
1488 no_debug_ospf6_asbr_cmd,
1489 "no debug ospf6 asbr",
1490 NO_STR
1491 DEBUG_STR
1492 OSPF6_STR
1493 "Debug OSPFv3 ASBR function\n"
1494 )
1495 {
1496 OSPF6_DEBUG_ASBR_OFF ();
1497 return CMD_SUCCESS;
1498 }
1499
1500 int
1501 config_write_ospf6_debug_asbr (struct vty *vty)
1502 {
1503 if (IS_OSPF6_DEBUG_ASBR)
1504 vty_out (vty, "debug ospf6 asbr%s", VNL);
1505 return 0;
1506 }
1507
1508 void
1509 install_element_ospf6_debug_asbr ()
1510 {
1511 install_element (ENABLE_NODE, &debug_ospf6_asbr_cmd);
1512 install_element (ENABLE_NODE, &no_debug_ospf6_asbr_cmd);
1513 install_element (CONFIG_NODE, &debug_ospf6_asbr_cmd);
1514 install_element (CONFIG_NODE, &no_debug_ospf6_asbr_cmd);
1515 }