2 * Copyright (C) 2003 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
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
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.
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.
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"
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"
51 unsigned char conf_debug_ospf6_asbr
= 0;
53 #define ZROUTE_NAME(x) zebra_route_string(x)
55 /* AS External LSA origination */
57 ospf6_as_external_lsa_originate (struct ospf6_route
*route
)
59 char buffer
[OSPF6_MAX_LSASIZE
];
60 struct ospf6_lsa_header
*lsa_header
;
61 struct ospf6_lsa
*old
, *lsa
;
62 struct ospf6_external_info
*info
= route
->route_option
;
64 struct ospf6_as_external_lsa
*as_external_lsa
;
68 /* find previous LSA */
69 old
= ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL
),
70 route
->path
.origin
.id
, ospf6
->router_id
,
73 if (IS_OSPF6_DEBUG_ASBR
|| IS_OSPF6_DEBUG_ORIGINATE (AS_EXTERNAL
))
75 prefix2str (&route
->prefix
, buf
, sizeof (buf
));
76 zlog_debug ("Originate AS-External-LSA for %s", buf
);
80 memset (buffer
, 0, sizeof (buffer
));
81 lsa_header
= (struct ospf6_lsa_header
*) buffer
;
82 as_external_lsa
= (struct ospf6_as_external_lsa
*)
83 ((caddr_t
) lsa_header
+ sizeof (struct ospf6_lsa_header
));
85 ((caddr_t
) as_external_lsa
+ sizeof (struct ospf6_as_external_lsa
));
87 /* Fill AS-External-LSA */
89 if (route
->path
.metric_type
== 2)
90 SET_FLAG (as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_E
);
92 UNSET_FLAG (as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_E
);
94 /* forwarding address */
95 if (! IN6_IS_ADDR_UNSPECIFIED (&info
->forwarding
))
96 SET_FLAG (as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_F
);
98 UNSET_FLAG (as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_F
);
100 /* external route tag */
101 UNSET_FLAG (as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_T
);
104 OSPF6_ASBR_METRIC_SET (as_external_lsa
, route
->path
.cost
);
107 as_external_lsa
->prefix
.prefix_length
= route
->prefix
.prefixlen
;
110 as_external_lsa
->prefix
.prefix_options
= route
->path
.prefix_options
;
112 /* don't use refer LS-type */
113 as_external_lsa
->prefix
.prefix_refer_lstype
= htons (0);
116 memcpy (p
, &route
->prefix
.u
.prefix6
,
117 OSPF6_PREFIX_SPACE (route
->prefix
.prefixlen
));
118 ospf6_prefix_apply_mask (&as_external_lsa
->prefix
);
119 p
+= OSPF6_PREFIX_SPACE (route
->prefix
.prefixlen
);
121 /* Forwarding address */
122 if (CHECK_FLAG (as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_F
))
124 memcpy (p
, &info
->forwarding
, sizeof (struct in6_addr
));
125 p
+= sizeof (struct in6_addr
);
128 /* External Route Tag */
129 if (CHECK_FLAG (as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_T
))
134 /* Fill LSA Header */
136 lsa_header
->type
= htons (OSPF6_LSTYPE_AS_EXTERNAL
);
137 lsa_header
->id
= route
->path
.origin
.id
;
138 lsa_header
->adv_router
= ospf6
->router_id
;
140 ospf6_new_ls_seqnum (lsa_header
->type
, lsa_header
->id
,
141 lsa_header
->adv_router
, ospf6
->lsdb
);
142 lsa_header
->length
= htons ((caddr_t
) p
- (caddr_t
) lsa_header
);
145 ospf6_lsa_checksum (lsa_header
);
148 lsa
= ospf6_lsa_create (lsa_header
);
151 ospf6_lsa_originate_process (lsa
, ospf6
);
156 ospf6_asbr_lsa_add (struct ospf6_lsa
*lsa
)
158 struct ospf6_as_external_lsa
*external
;
159 struct prefix asbr_id
;
160 struct ospf6_route
*asbr_entry
, *route
;
164 external
= (struct ospf6_as_external_lsa
*)
165 OSPF6_LSA_HEADER_END (lsa
->header
);
167 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL
))
168 zlog_debug ("Calculate AS-External route for %s", lsa
->name
);
170 if (lsa
->header
->adv_router
== ospf6
->router_id
)
172 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL
))
173 zlog_debug ("Ignore self-originated AS-External-LSA");
177 if (OSPF6_ASBR_METRIC (external
) == LS_INFINITY
)
179 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL
))
180 zlog_debug ("Ignore LSA with LSInfinity Metric");
184 ospf6_linkstate_prefix (lsa
->header
->adv_router
, htonl (0), &asbr_id
);
185 asbr_entry
= ospf6_route_lookup (&asbr_id
, ospf6
->brouter_table
);
186 if (asbr_entry
== NULL
||
187 ! CHECK_FLAG (asbr_entry
->path
.router_bits
, OSPF6_ROUTER_BIT_E
))
189 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL
))
191 prefix2str (&asbr_id
, buf
, sizeof (buf
));
192 zlog_debug ("ASBR entry not found: %s", buf
);
197 route
= ospf6_route_create ();
198 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
199 route
->prefix
.family
= AF_INET6
;
200 route
->prefix
.prefixlen
= external
->prefix
.prefix_length
;
201 ospf6_prefix_in6_addr (&route
->prefix
.u
.prefix6
, &external
->prefix
);
203 route
->path
.area_id
= asbr_entry
->path
.area_id
;
204 route
->path
.origin
.type
= lsa
->header
->type
;
205 route
->path
.origin
.id
= lsa
->header
->id
;
206 route
->path
.origin
.adv_router
= lsa
->header
->adv_router
;
208 route
->path
.prefix_options
= external
->prefix
.prefix_options
;
209 if (CHECK_FLAG (external
->bits_metric
, OSPF6_ASBR_BIT_E
))
211 route
->path
.type
= OSPF6_PATH_TYPE_EXTERNAL2
;
212 route
->path
.metric_type
= 2;
213 route
->path
.cost
= asbr_entry
->path
.cost
;
214 route
->path
.cost_e2
= OSPF6_ASBR_METRIC (external
);
218 route
->path
.type
= OSPF6_PATH_TYPE_EXTERNAL1
;
219 route
->path
.metric_type
= 1;
220 route
->path
.cost
= asbr_entry
->path
.cost
+ OSPF6_ASBR_METRIC (external
);
221 route
->path
.cost_e2
= 0;
224 for (i
= 0; i
< OSPF6_MULTI_PATH_LIMIT
; i
++)
225 ospf6_nexthop_copy (&route
->nexthop
[i
], &asbr_entry
->nexthop
[i
]);
227 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL
))
229 prefix2str (&route
->prefix
, buf
, sizeof (buf
));
230 zlog_debug ("AS-External route add: %s", buf
);
233 ospf6_route_add (route
, ospf6
->route_table
);
237 ospf6_asbr_lsa_remove (struct ospf6_lsa
*lsa
)
239 struct ospf6_as_external_lsa
*external
;
240 struct prefix prefix
;
241 struct ospf6_route
*route
;
244 external
= (struct ospf6_as_external_lsa
*)
245 OSPF6_LSA_HEADER_END (lsa
->header
);
247 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL
))
248 zlog_debug ("Withdraw AS-External route for %s", lsa
->name
);
250 if (lsa
->header
->adv_router
== ospf6
->router_id
)
252 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL
))
253 zlog_debug ("Ignore self-originated AS-External-LSA");
257 memset (&prefix
, 0, sizeof (struct prefix
));
258 prefix
.family
= AF_INET6
;
259 prefix
.prefixlen
= external
->prefix
.prefix_length
;
260 ospf6_prefix_in6_addr (&prefix
.u
.prefix6
, &external
->prefix
);
262 route
= ospf6_route_lookup (&prefix
, ospf6
->route_table
);
265 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL
))
267 prefix2str (&prefix
, buf
, sizeof (buf
));
268 zlog_debug ("AS-External route %s not found", buf
);
273 for (ospf6_route_lock (route
);
274 route
&& ospf6_route_is_prefix (&prefix
, route
);
275 route
= ospf6_route_next (route
))
277 if (route
->type
!= OSPF6_DEST_TYPE_NETWORK
)
279 if (route
->path
.origin
.type
!= lsa
->header
->type
)
281 if (route
->path
.origin
.id
!= lsa
->header
->id
)
283 if (route
->path
.origin
.adv_router
!= lsa
->header
->adv_router
)
286 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL
))
288 prefix2str (&route
->prefix
, buf
, sizeof (buf
));
289 zlog_debug ("AS-External route remove: %s", buf
);
291 ospf6_route_remove (route
, ospf6
->route_table
);
296 ospf6_asbr_lsentry_add (struct ospf6_route
*asbr_entry
)
298 struct ospf6_lsa
*lsa
;
302 if (! CHECK_FLAG (asbr_entry
->flag
, OSPF6_ROUTE_BEST
))
305 inet_ntop (AF_INET
, &ADV_ROUTER_IN_PREFIX (&asbr_entry
->prefix
),
307 zlog_info ("ignore non-best path: lsentry %s add", buf
);
311 type
= htons (OSPF6_LSTYPE_AS_EXTERNAL
);
312 router
= ospf6_linkstate_prefix_adv_router (&asbr_entry
->prefix
);
313 for (lsa
= ospf6_lsdb_type_router_head (type
, router
, ospf6
->lsdb
); lsa
;
314 lsa
= ospf6_lsdb_type_router_next (type
, router
, lsa
))
316 if (! OSPF6_LSA_IS_MAXAGE (lsa
))
317 ospf6_asbr_lsa_add (lsa
);
322 ospf6_asbr_lsentry_remove (struct ospf6_route
*asbr_entry
)
324 struct ospf6_lsa
*lsa
;
328 type
= htons (OSPF6_LSTYPE_AS_EXTERNAL
);
329 router
= ospf6_linkstate_prefix_adv_router (&asbr_entry
->prefix
);
330 for (lsa
= ospf6_lsdb_type_router_head (type
, router
, ospf6
->lsdb
);
331 lsa
; lsa
= ospf6_lsdb_type_router_next (type
, router
, lsa
))
332 ospf6_asbr_lsa_remove (lsa
);
337 /* redistribute function */
340 ospf6_asbr_routemap_set (int type
, const char *mapname
)
342 if (ospf6
->rmap
[type
].name
)
343 free (ospf6
->rmap
[type
].name
);
344 ospf6
->rmap
[type
].name
= strdup (mapname
);
345 ospf6
->rmap
[type
].map
= route_map_lookup_by_name (mapname
);
349 ospf6_asbr_routemap_unset (int type
)
351 if (ospf6
->rmap
[type
].name
)
352 free (ospf6
->rmap
[type
].name
);
353 ospf6
->rmap
[type
].name
= NULL
;
354 ospf6
->rmap
[type
].map
= NULL
;
358 ospf6_asbr_routemap_update (const char *mapname
)
365 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
367 if (ospf6
->rmap
[type
].name
)
368 ospf6
->rmap
[type
].map
=
369 route_map_lookup_by_name (ospf6
->rmap
[type
].name
);
371 ospf6
->rmap
[type
].map
= NULL
;
376 ospf6_asbr_is_asbr (struct ospf6
*o
)
378 return o
->external_table
->count
;
382 ospf6_asbr_redistribute_set (int type
)
384 ospf6_zebra_redistribute (type
);
388 ospf6_asbr_redistribute_unset (int type
)
390 struct ospf6_route
*route
;
391 struct ospf6_external_info
*info
;
393 ospf6_zebra_no_redistribute (type
);
395 for (route
= ospf6_route_head (ospf6
->external_table
); route
;
396 route
= ospf6_route_next (route
))
398 info
= route
->route_option
;
399 if (info
->type
!= type
)
402 ospf6_asbr_redistribute_remove (info
->type
, route
->nexthop
[0].ifindex
,
408 ospf6_asbr_redistribute_add (int type
, int ifindex
, struct prefix
*prefix
,
409 u_int nexthop_num
, struct in6_addr
*nexthop
)
412 struct ospf6_route troute
;
413 struct ospf6_external_info tinfo
;
414 struct ospf6_route
*route
, *match
;
415 struct ospf6_external_info
*info
;
416 struct prefix prefix_id
;
417 struct route_node
*node
;
418 char pbuf
[64], ibuf
[16];
419 struct listnode
*lnode
, *lnnode
;
420 struct ospf6_area
*oa
;
422 if (! ospf6_zebra_is_redistribute (type
))
425 if (IS_OSPF6_DEBUG_ASBR
)
427 prefix2str (prefix
, pbuf
, sizeof (pbuf
));
428 zlog_debug ("Redistribute %s (%s)", pbuf
, ZROUTE_NAME (type
));
431 /* if route-map was specified but not found, do not advertise */
432 if (ospf6
->rmap
[type
].name
)
434 if (ospf6
->rmap
[type
].map
== NULL
)
435 ospf6_asbr_routemap_update (NULL
);
436 if (ospf6
->rmap
[type
].map
== NULL
)
438 zlog_warn ("route-map \"%s\" not found, suppress redistributing",
439 ospf6
->rmap
[type
].name
);
444 /* apply route-map */
445 if (ospf6
->rmap
[type
].map
)
447 memset (&troute
, 0, sizeof (troute
));
448 memset (&tinfo
, 0, sizeof (tinfo
));
449 troute
.route_option
= &tinfo
;
451 ret
= route_map_apply (ospf6
->rmap
[type
].map
, prefix
,
452 RMAP_OSPF6
, &troute
);
453 if (ret
== RMAP_DENYMATCH
)
455 if (IS_OSPF6_DEBUG_ASBR
)
456 zlog_debug ("Denied by route-map \"%s\"", ospf6
->rmap
[type
].name
);
461 match
= ospf6_route_lookup (prefix
, ospf6
->external_table
);
464 info
= match
->route_option
;
466 /* copy result of route-map */
467 if (ospf6
->rmap
[type
].map
)
469 if (troute
.path
.metric_type
)
470 match
->path
.metric_type
= troute
.path
.metric_type
;
471 if (troute
.path
.cost
)
472 match
->path
.cost
= troute
.path
.cost
;
473 if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo
.forwarding
))
474 memcpy (&info
->forwarding
, &tinfo
.forwarding
,
475 sizeof (struct in6_addr
));
479 match
->nexthop
[0].ifindex
= ifindex
;
480 if (nexthop_num
&& nexthop
)
481 memcpy (&match
->nexthop
[0].address
, nexthop
, sizeof (struct in6_addr
));
483 /* create/update binding in external_id_table */
484 prefix_id
.family
= AF_INET
;
485 prefix_id
.prefixlen
= 32;
486 prefix_id
.u
.prefix4
.s_addr
= htonl (info
->id
);
487 node
= route_node_get (ospf6
->external_id_table
, &prefix_id
);
490 if (IS_OSPF6_DEBUG_ASBR
)
492 inet_ntop (AF_INET
, &prefix_id
.u
.prefix4
, ibuf
, sizeof (ibuf
));
493 zlog_debug ("Advertise as AS-External Id:%s", ibuf
);
496 match
->path
.origin
.id
= htonl (info
->id
);
497 ospf6_as_external_lsa_originate (match
);
501 /* create new entry */
502 route
= ospf6_route_create ();
503 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
504 memcpy (&route
->prefix
, prefix
, sizeof (struct prefix
));
506 info
= (struct ospf6_external_info
*)
507 XCALLOC (MTYPE_OSPF6_EXTERNAL_INFO
, sizeof (struct ospf6_external_info
));
508 route
->route_option
= info
;
509 info
->id
= ospf6
->external_id
++;
511 /* copy result of route-map */
512 if (ospf6
->rmap
[type
].map
)
514 if (troute
.path
.metric_type
)
515 route
->path
.metric_type
= troute
.path
.metric_type
;
516 if (troute
.path
.cost
)
517 route
->path
.cost
= troute
.path
.cost
;
518 if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo
.forwarding
))
519 memcpy (&info
->forwarding
, &tinfo
.forwarding
,
520 sizeof (struct in6_addr
));
524 route
->nexthop
[0].ifindex
= ifindex
;
525 if (nexthop_num
&& nexthop
)
526 memcpy (&route
->nexthop
[0].address
, nexthop
, sizeof (struct in6_addr
));
528 /* create/update binding in external_id_table */
529 prefix_id
.family
= AF_INET
;
530 prefix_id
.prefixlen
= 32;
531 prefix_id
.u
.prefix4
.s_addr
= htonl (info
->id
);
532 node
= route_node_get (ospf6
->external_id_table
, &prefix_id
);
535 route
= ospf6_route_add (route
, ospf6
->external_table
);
536 route
->route_option
= info
;
538 if (IS_OSPF6_DEBUG_ASBR
)
540 inet_ntop (AF_INET
, &prefix_id
.u
.prefix4
, ibuf
, sizeof (ibuf
));
541 zlog_debug ("Advertise as AS-External Id:%s", ibuf
);
544 route
->path
.origin
.id
= htonl (info
->id
);
545 ospf6_as_external_lsa_originate (route
);
547 /* Router-Bit (ASBR Flag) may have to be updated */
548 for (ALL_LIST_ELEMENTS (ospf6
->area_list
, lnode
, lnnode
, oa
))
549 OSPF6_ROUTER_LSA_SCHEDULE (oa
);
553 ospf6_asbr_redistribute_remove (int type
, int ifindex
, struct prefix
*prefix
)
555 struct ospf6_route
*match
;
556 struct ospf6_external_info
*info
= NULL
;
557 struct route_node
*node
;
558 struct ospf6_lsa
*lsa
;
559 struct prefix prefix_id
;
560 char pbuf
[64], ibuf
[16];
561 struct listnode
*lnode
, *lnnode
;
562 struct ospf6_area
*oa
;
564 match
= ospf6_route_lookup (prefix
, ospf6
->external_table
);
567 if (IS_OSPF6_DEBUG_ASBR
)
569 prefix2str (prefix
, pbuf
, sizeof (pbuf
));
570 zlog_debug ("No such route %s to withdraw", pbuf
);
575 info
= match
->route_option
;
578 if (info
->type
!= type
)
580 if (IS_OSPF6_DEBUG_ASBR
)
582 prefix2str (prefix
, pbuf
, sizeof (pbuf
));
583 zlog_debug ("Original protocol mismatch: %s", pbuf
);
588 if (IS_OSPF6_DEBUG_ASBR
)
590 prefix2str (prefix
, pbuf
, sizeof (pbuf
));
591 inet_ntop (AF_INET
, &prefix_id
.u
.prefix4
, ibuf
, sizeof (ibuf
));
592 zlog_debug ("Withdraw %s (AS-External Id:%s)", pbuf
, ibuf
);
595 lsa
= ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL
),
596 htonl (info
->id
), ospf6
->router_id
, ospf6
->lsdb
);
598 ospf6_lsa_purge (lsa
);
600 /* remove binding in external_id_table */
601 prefix_id
.family
= AF_INET
;
602 prefix_id
.prefixlen
= 32;
603 prefix_id
.u
.prefix4
.s_addr
= htonl (info
->id
);
604 node
= route_node_lookup (ospf6
->external_id_table
, &prefix_id
);
607 route_unlock_node (node
);
609 ospf6_route_remove (match
, ospf6
->external_table
);
610 XFREE (MTYPE_OSPF6_EXTERNAL_INFO
, info
);
612 /* Router-Bit (ASBR Flag) may have to be updated */
613 for (ALL_LIST_ELEMENTS (ospf6
->area_list
, lnode
, lnnode
, oa
))
614 OSPF6_ROUTER_LSA_SCHEDULE (oa
);
617 DEFUN (ospf6_redistribute
,
618 ospf6_redistribute_cmd
,
619 "redistribute (static|kernel|connected|ripng|bgp)",
630 if (strncmp (argv
[0], "sta", 3) == 0)
631 type
= ZEBRA_ROUTE_STATIC
;
632 else if (strncmp (argv
[0], "ker", 3) == 0)
633 type
= ZEBRA_ROUTE_KERNEL
;
634 else if (strncmp (argv
[0], "con", 3) == 0)
635 type
= ZEBRA_ROUTE_CONNECT
;
636 else if (strncmp (argv
[0], "rip", 3) == 0)
637 type
= ZEBRA_ROUTE_RIPNG
;
638 else if (strncmp (argv
[0], "bgp", 3) == 0)
639 type
= ZEBRA_ROUTE_BGP
;
641 ospf6_asbr_redistribute_unset (type
);
642 ospf6_asbr_routemap_unset (type
);
643 ospf6_asbr_redistribute_set (type
);
647 DEFUN (ospf6_redistribute_routemap
,
648 ospf6_redistribute_routemap_cmd
,
649 "redistribute (static|kernel|connected|ripng|bgp) route-map WORD",
656 "Route map reference\n"
662 if (strncmp (argv
[0], "sta", 3) == 0)
663 type
= ZEBRA_ROUTE_STATIC
;
664 else if (strncmp (argv
[0], "ker", 3) == 0)
665 type
= ZEBRA_ROUTE_KERNEL
;
666 else if (strncmp (argv
[0], "con", 3) == 0)
667 type
= ZEBRA_ROUTE_CONNECT
;
668 else if (strncmp (argv
[0], "rip", 3) == 0)
669 type
= ZEBRA_ROUTE_RIPNG
;
670 else if (strncmp (argv
[0], "bgp", 3) == 0)
671 type
= ZEBRA_ROUTE_BGP
;
673 ospf6_asbr_redistribute_unset (type
);
674 ospf6_asbr_routemap_set (type
, argv
[1]);
675 ospf6_asbr_redistribute_set (type
);
679 DEFUN (no_ospf6_redistribute
,
680 no_ospf6_redistribute_cmd
,
681 "no redistribute (static|kernel|connected|ripng|bgp)",
693 if (strncmp (argv
[0], "sta", 3) == 0)
694 type
= ZEBRA_ROUTE_STATIC
;
695 else if (strncmp (argv
[0], "ker", 3) == 0)
696 type
= ZEBRA_ROUTE_KERNEL
;
697 else if (strncmp (argv
[0], "con", 3) == 0)
698 type
= ZEBRA_ROUTE_CONNECT
;
699 else if (strncmp (argv
[0], "rip", 3) == 0)
700 type
= ZEBRA_ROUTE_RIPNG
;
701 else if (strncmp (argv
[0], "bgp", 3) == 0)
702 type
= ZEBRA_ROUTE_BGP
;
704 ospf6_asbr_redistribute_unset (type
);
705 ospf6_asbr_routemap_unset (type
);
711 ospf6_redistribute_config_write (struct vty
*vty
)
715 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
717 if (type
== ZEBRA_ROUTE_OSPF6
)
719 if (! ospf6_zebra_is_redistribute (type
))
722 if (ospf6
->rmap
[type
].name
)
723 vty_out (vty
, " redistribute %s route-map %s%s",
724 ZROUTE_NAME (type
), ospf6
->rmap
[type
].name
, VNL
);
726 vty_out (vty
, " redistribute %s%s",
727 ZROUTE_NAME (type
), VNL
);
734 ospf6_redistribute_show_config (struct vty
*vty
)
737 int nroute
[ZEBRA_ROUTE_MAX
];
739 struct ospf6_route
*route
;
740 struct ospf6_external_info
*info
;
743 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
745 for (route
= ospf6_route_head (ospf6
->external_table
); route
;
746 route
= ospf6_route_next (route
))
748 info
= route
->route_option
;
749 nroute
[info
->type
]++;
753 vty_out (vty
, "Redistributing External Routes from:%s", VNL
);
754 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
756 if (type
== ZEBRA_ROUTE_OSPF6
)
758 if (! ospf6_zebra_is_redistribute (type
))
761 if (ospf6
->rmap
[type
].name
)
762 vty_out (vty
, " %d: %s with route-map \"%s\"%s%s", nroute
[type
],
763 ZROUTE_NAME (type
), ospf6
->rmap
[type
].name
,
764 (ospf6
->rmap
[type
].map
? "" : " (not found !)"),
767 vty_out (vty
, " %d: %s%s", nroute
[type
],
768 ZROUTE_NAME (type
), VNL
);
770 vty_out (vty
, "Total %d routes%s", total
, VNL
);
775 /* Routemap Functions */
776 static route_map_result_t
777 ospf6_routemap_rule_match_address_prefixlist (void *rule
,
778 struct prefix
*prefix
,
779 route_map_object_t type
,
782 struct prefix_list
*plist
;
784 if (type
!= RMAP_OSPF6
)
787 plist
= prefix_list_lookup (AFI_IP6
, (char *) rule
);
791 return (prefix_list_apply (plist
, prefix
) == PREFIX_DENY
?
792 RMAP_NOMATCH
: RMAP_MATCH
);
796 ospf6_routemap_rule_match_address_prefixlist_compile (const char *arg
)
798 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
802 ospf6_routemap_rule_match_address_prefixlist_free (void *rule
)
804 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
807 struct route_map_rule_cmd
808 ospf6_routemap_rule_match_address_prefixlist_cmd
=
810 "ipv6 address prefix-list",
811 ospf6_routemap_rule_match_address_prefixlist
,
812 ospf6_routemap_rule_match_address_prefixlist_compile
,
813 ospf6_routemap_rule_match_address_prefixlist_free
,
816 static route_map_result_t
817 ospf6_routemap_rule_set_metric_type (void *rule
, struct prefix
*prefix
,
818 route_map_object_t type
, void *object
)
820 char *metric_type
= rule
;
821 struct ospf6_route
*route
= object
;
823 if (type
!= RMAP_OSPF6
)
826 if (strcmp (metric_type
, "type-2") == 0)
827 route
->path
.metric_type
= 2;
829 route
->path
.metric_type
= 1;
835 ospf6_routemap_rule_set_metric_type_compile (const char *arg
)
837 if (strcmp (arg
, "type-2") && strcmp (arg
, "type-1"))
839 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
843 ospf6_routemap_rule_set_metric_type_free (void *rule
)
845 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
848 struct route_map_rule_cmd
849 ospf6_routemap_rule_set_metric_type_cmd
=
852 ospf6_routemap_rule_set_metric_type
,
853 ospf6_routemap_rule_set_metric_type_compile
,
854 ospf6_routemap_rule_set_metric_type_free
,
857 static route_map_result_t
858 ospf6_routemap_rule_set_metric (void *rule
, struct prefix
*prefix
,
859 route_map_object_t type
, void *object
)
862 struct ospf6_route
*route
= object
;
864 if (type
!= RMAP_OSPF6
)
867 route
->path
.cost
= atoi (metric
);
872 ospf6_routemap_rule_set_metric_compile (const char *arg
)
876 metric
= strtoul (arg
, &endp
, 0);
877 if (metric
> LS_INFINITY
|| *endp
!= '\0')
879 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
883 ospf6_routemap_rule_set_metric_free (void *rule
)
885 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
888 struct route_map_rule_cmd
889 ospf6_routemap_rule_set_metric_cmd
=
892 ospf6_routemap_rule_set_metric
,
893 ospf6_routemap_rule_set_metric_compile
,
894 ospf6_routemap_rule_set_metric_free
,
897 static route_map_result_t
898 ospf6_routemap_rule_set_forwarding (void *rule
, struct prefix
*prefix
,
899 route_map_object_t type
, void *object
)
901 char *forwarding
= rule
;
902 struct ospf6_route
*route
= object
;
903 struct ospf6_external_info
*info
= route
->route_option
;
905 if (type
!= RMAP_OSPF6
)
908 if (inet_pton (AF_INET6
, forwarding
, &info
->forwarding
) != 1)
910 memset (&info
->forwarding
, 0, sizeof (struct in6_addr
));
918 ospf6_routemap_rule_set_forwarding_compile (const char *arg
)
921 if (inet_pton (AF_INET6
, arg
, &a
) != 1)
923 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
927 ospf6_routemap_rule_set_forwarding_free (void *rule
)
929 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
932 struct route_map_rule_cmd
933 ospf6_routemap_rule_set_forwarding_cmd
=
935 "forwarding-address",
936 ospf6_routemap_rule_set_forwarding
,
937 ospf6_routemap_rule_set_forwarding_compile
,
938 ospf6_routemap_rule_set_forwarding_free
,
942 route_map_command_status (struct vty
*vty
, int ret
)
949 case RMAP_RULE_MISSING
:
950 vty_out (vty
, "Can't find rule.%s", VNL
);
952 case RMAP_COMPILE_ERROR
:
953 vty_out (vty
, "Argument is malformed.%s", VNL
);
956 vty_out (vty
, "route-map add set failed.%s", VNL
);
962 /* add "match address" */
963 DEFUN (ospf6_routemap_match_address_prefixlist
,
964 ospf6_routemap_match_address_prefixlist_cmd
,
965 "match ipv6 address prefix-list WORD",
968 "Match address of route\n"
969 "Match entries of prefix-lists\n"
970 "IPv6 prefix-list name\n")
972 int ret
= route_map_add_match ((struct route_map_index
*) vty
->index
,
973 "ipv6 address prefix-list", argv
[0]);
974 return route_map_command_status (vty
, ret
);
977 /* delete "match address" */
978 DEFUN (ospf6_routemap_no_match_address_prefixlist
,
979 ospf6_routemap_no_match_address_prefixlist_cmd
,
980 "no match ipv6 address prefix-list WORD",
984 "Match address of route\n"
985 "Match entries of prefix-lists\n"
986 "IPv6 prefix-list name\n")
988 int ret
= route_map_delete_match ((struct route_map_index
*) vty
->index
,
989 "ipv6 address prefix-list", argv
[0]);
990 return route_map_command_status (vty
, ret
);
993 /* add "set metric-type" */
994 DEFUN (ospf6_routemap_set_metric_type
,
995 ospf6_routemap_set_metric_type_cmd
,
996 "set metric-type (type-1|type-2)",
999 "OSPF6 external type 1 metric\n"
1000 "OSPF6 external type 2 metric\n")
1002 int ret
= route_map_add_set ((struct route_map_index
*) vty
->index
,
1003 "metric-type", argv
[0]);
1004 return route_map_command_status (vty
, ret
);
1007 /* delete "set metric-type" */
1008 DEFUN (ospf6_routemap_no_set_metric_type
,
1009 ospf6_routemap_no_set_metric_type_cmd
,
1010 "no set metric-type (type-1|type-2)",
1014 "OSPF6 external type 1 metric\n"
1015 "OSPF6 external type 2 metric\n")
1017 int ret
= route_map_delete_set ((struct route_map_index
*) vty
->index
,
1018 "metric-type", argv
[0]);
1019 return route_map_command_status (vty
, ret
);
1022 /* add "set metric" */
1025 "set metric <0-4294967295>",
1030 int ret
= route_map_add_set ((struct route_map_index
*) vty
->index
,
1032 return route_map_command_status (vty
, ret
);
1035 /* delete "set metric" */
1036 DEFUN (no_set_metric
,
1038 "no set metric <0-4294967295>",
1044 int ret
= route_map_delete_set ((struct route_map_index
*) vty
->index
,
1046 return route_map_command_status (vty
, ret
);
1049 /* add "set forwarding-address" */
1050 DEFUN (ospf6_routemap_set_forwarding
,
1051 ospf6_routemap_set_forwarding_cmd
,
1052 "set forwarding-address X:X::X:X",
1054 "Forwarding Address\n"
1057 int ret
= route_map_add_set ((struct route_map_index
*) vty
->index
,
1058 "forwarding-address", argv
[0]);
1059 return route_map_command_status (vty
, ret
);
1062 /* delete "set forwarding-address" */
1063 DEFUN (ospf6_routemap_no_set_forwarding
,
1064 ospf6_routemap_no_set_forwarding_cmd
,
1065 "no set forwarding-address X:X::X:X",
1068 "Forwarding Address\n"
1071 int ret
= route_map_delete_set ((struct route_map_index
*) vty
->index
,
1072 "forwarding-address", argv
[0]);
1073 return route_map_command_status (vty
, ret
);
1077 ospf6_routemap_init (void)
1080 route_map_init_vty ();
1081 route_map_add_hook (ospf6_asbr_routemap_update
);
1082 route_map_delete_hook (ospf6_asbr_routemap_update
);
1084 route_map_install_match (&ospf6_routemap_rule_match_address_prefixlist_cmd
);
1085 route_map_install_set (&ospf6_routemap_rule_set_metric_type_cmd
);
1086 route_map_install_set (&ospf6_routemap_rule_set_metric_cmd
);
1087 route_map_install_set (&ospf6_routemap_rule_set_forwarding_cmd
);
1089 /* Match address prefix-list */
1090 install_element (RMAP_NODE
, &ospf6_routemap_match_address_prefixlist_cmd
);
1091 install_element (RMAP_NODE
, &ospf6_routemap_no_match_address_prefixlist_cmd
);
1093 /* ASE Metric Type (e.g. Type-1/Type-2) */
1094 install_element (RMAP_NODE
, &ospf6_routemap_set_metric_type_cmd
);
1095 install_element (RMAP_NODE
, &ospf6_routemap_no_set_metric_type_cmd
);
1098 install_element (RMAP_NODE
, &set_metric_cmd
);
1099 install_element (RMAP_NODE
, &no_set_metric_cmd
);
1102 install_element (RMAP_NODE
, &ospf6_routemap_set_forwarding_cmd
);
1103 install_element (RMAP_NODE
, &ospf6_routemap_no_set_forwarding_cmd
);
1107 /* Display functions */
1109 ospf6_as_external_lsa_show (struct vty
*vty
, struct ospf6_lsa
*lsa
)
1111 struct ospf6_as_external_lsa
*external
;
1113 struct in6_addr in6
, *forwarding
;
1115 assert (lsa
->header
);
1116 external
= (struct ospf6_as_external_lsa
*)
1117 OSPF6_LSA_HEADER_END (lsa
->header
);
1120 snprintf (buf
, sizeof (buf
), "%c%c%c",
1121 (CHECK_FLAG (external
->bits_metric
, OSPF6_ASBR_BIT_E
) ? 'E' : '-'),
1122 (CHECK_FLAG (external
->bits_metric
, OSPF6_ASBR_BIT_F
) ? 'F' : '-'),
1123 (CHECK_FLAG (external
->bits_metric
, OSPF6_ASBR_BIT_T
) ? 'T' : '-'));
1125 vty_out (vty
, " Bits: %s%s", buf
, VNL
);
1126 vty_out (vty
, " Metric: %5lu%s", (u_long
) OSPF6_ASBR_METRIC (external
),
1129 ospf6_prefix_options_printbuf (external
->prefix
.prefix_options
,
1131 vty_out (vty
, " Prefix Options: %s%s", buf
,
1134 vty_out (vty
, " Referenced LSType: %d%s",
1135 ntohs (external
->prefix
.prefix_refer_lstype
),
1138 ospf6_prefix_in6_addr (&in6
, &external
->prefix
);
1139 inet_ntop (AF_INET6
, &in6
, buf
, sizeof (buf
));
1140 vty_out (vty
, " Prefix: %s/%d%s", buf
,
1141 external
->prefix
.prefix_length
, VNL
);
1143 /* Forwarding-Address */
1144 if (CHECK_FLAG (external
->bits_metric
, OSPF6_ASBR_BIT_F
))
1146 forwarding
= (struct in6_addr
*)
1147 ((caddr_t
) external
+ sizeof (struct ospf6_as_external_lsa
) +
1148 OSPF6_PREFIX_SPACE (external
->prefix
.prefix_length
));
1149 inet_ntop (AF_INET6
, forwarding
, buf
, sizeof (buf
));
1150 vty_out (vty
, " Forwarding-Address: %s%s", buf
, VNL
);
1157 ospf6_asbr_external_route_show (struct vty
*vty
, struct ospf6_route
*route
)
1159 struct ospf6_external_info
*info
= route
->route_option
;
1160 char prefix
[64], id
[16], forwarding
[64];
1163 prefix2str (&route
->prefix
, prefix
, sizeof (prefix
));
1164 tmp_id
= ntohl (info
->id
);
1165 inet_ntop (AF_INET
, &tmp_id
, id
, sizeof (id
));
1166 if (! IN6_IS_ADDR_UNSPECIFIED (&info
->forwarding
))
1167 inet_ntop (AF_INET6
, &info
->forwarding
, forwarding
, sizeof (forwarding
));
1169 snprintf (forwarding
, sizeof (forwarding
), ":: (ifindex %d)",
1170 route
->nexthop
[0].ifindex
);
1172 vty_out (vty
, "%c %-32s %-15s type-%d %5lu %s%s",
1173 zebra_route_char(info
->type
),
1174 prefix
, id
, route
->path
.metric_type
,
1175 (u_long
) (route
->path
.metric_type
== 2 ?
1176 route
->path
.cost_e2
: route
->path
.cost
),
1180 DEFUN (show_ipv6_ospf6_redistribute
,
1181 show_ipv6_ospf6_redistribute_cmd
,
1182 "show ipv6 ospf6 redistribute",
1186 "redistributing External information\n"
1189 struct ospf6_route
*route
;
1191 ospf6_redistribute_show_config (vty
);
1193 for (route
= ospf6_route_head (ospf6
->external_table
); route
;
1194 route
= ospf6_route_next (route
))
1195 ospf6_asbr_external_route_show (vty
, route
);
1200 struct ospf6_lsa_handler as_external_handler
=
1202 OSPF6_LSTYPE_AS_EXTERNAL
,
1204 ospf6_as_external_lsa_show
1208 ospf6_asbr_init (void)
1210 ospf6_routemap_init ();
1212 ospf6_install_lsa_handler (&as_external_handler
);
1214 install_element (VIEW_NODE
, &show_ipv6_ospf6_redistribute_cmd
);
1215 install_element (ENABLE_NODE
, &show_ipv6_ospf6_redistribute_cmd
);
1217 install_element (OSPF6_NODE
, &ospf6_redistribute_cmd
);
1218 install_element (OSPF6_NODE
, &ospf6_redistribute_routemap_cmd
);
1219 install_element (OSPF6_NODE
, &no_ospf6_redistribute_cmd
);
1223 DEFUN (debug_ospf6_asbr
,
1224 debug_ospf6_asbr_cmd
,
1228 "Debug OSPFv3 ASBR function\n"
1231 OSPF6_DEBUG_ASBR_ON ();
1235 DEFUN (no_debug_ospf6_asbr
,
1236 no_debug_ospf6_asbr_cmd
,
1237 "no debug ospf6 asbr",
1241 "Debug OSPFv3 ASBR function\n"
1244 OSPF6_DEBUG_ASBR_OFF ();
1249 config_write_ospf6_debug_asbr (struct vty
*vty
)
1251 if (IS_OSPF6_DEBUG_ASBR
)
1252 vty_out (vty
, "debug ospf6 asbr%s", VNL
);
1257 install_element_ospf6_debug_asbr ()
1259 install_element (ENABLE_NODE
, &debug_ospf6_asbr_cmd
);
1260 install_element (ENABLE_NODE
, &no_debug_ospf6_asbr_cmd
);
1261 install_element (CONFIG_NODE
, &debug_ospf6_asbr_cmd
);
1262 install_element (CONFIG_NODE
, &no_debug_ospf6_asbr_cmd
);