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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "ospf6_proto.h"
35 #include "ospf6_lsa.h"
36 #include "ospf6_lsdb.h"
37 #include "ospf6_route.h"
38 #include "ospf6_zebra.h"
39 #include "ospf6_message.h"
41 #include "ospf6_top.h"
42 #include "ospf6_area.h"
43 #include "ospf6_interface.h"
44 #include "ospf6_neighbor.h"
45 #include "ospf6_asbr.h"
46 #include "ospf6_intra.h"
47 #include "ospf6_flood.h"
50 unsigned char conf_debug_ospf6_asbr
= 0;
52 #define ZROUTE_NAME(x) zebra_route_string(x)
54 /* AS External LSA origination */
55 static void ospf6_as_external_lsa_originate(struct ospf6_route
*route
)
57 char buffer
[OSPF6_MAX_LSASIZE
];
58 struct ospf6_lsa_header
*lsa_header
;
59 struct ospf6_lsa
*lsa
;
60 struct ospf6_external_info
*info
= route
->route_option
;
62 struct ospf6_as_external_lsa
*as_external_lsa
;
63 char buf
[PREFIX2STR_BUFFER
];
66 if (IS_OSPF6_DEBUG_ASBR
|| IS_OSPF6_DEBUG_ORIGINATE(AS_EXTERNAL
)) {
67 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
68 zlog_debug("Originate AS-External-LSA for %s", buf
);
72 memset(buffer
, 0, sizeof(buffer
));
73 lsa_header
= (struct ospf6_lsa_header
*)buffer
;
74 as_external_lsa
= (struct ospf6_as_external_lsa
75 *)((caddr_t
)lsa_header
76 + sizeof(struct ospf6_lsa_header
));
77 p
= (caddr_t
)((caddr_t
)as_external_lsa
78 + sizeof(struct ospf6_as_external_lsa
));
80 /* Fill AS-External-LSA */
82 if (route
->path
.metric_type
== 2)
83 SET_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_E
);
85 UNSET_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_E
);
87 /* forwarding address */
88 if (!IN6_IS_ADDR_UNSPECIFIED(&info
->forwarding
))
89 SET_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_F
);
91 UNSET_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_F
);
93 /* external route tag */
95 SET_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_T
);
97 UNSET_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_T
);
100 OSPF6_ASBR_METRIC_SET(as_external_lsa
, route
->path
.cost
);
103 as_external_lsa
->prefix
.prefix_length
= route
->prefix
.prefixlen
;
106 as_external_lsa
->prefix
.prefix_options
= route
->path
.prefix_options
;
108 /* don't use refer LS-type */
109 as_external_lsa
->prefix
.prefix_refer_lstype
= htons(0);
112 memcpy(p
, &route
->prefix
.u
.prefix6
,
113 OSPF6_PREFIX_SPACE(route
->prefix
.prefixlen
));
114 ospf6_prefix_apply_mask(&as_external_lsa
->prefix
);
115 p
+= OSPF6_PREFIX_SPACE(route
->prefix
.prefixlen
);
117 /* Forwarding address */
118 if (CHECK_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_F
)) {
119 memcpy(p
, &info
->forwarding
, sizeof(struct in6_addr
));
120 p
+= sizeof(struct in6_addr
);
123 /* External Route Tag */
124 if (CHECK_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_T
)) {
125 route_tag_t network_order
= htonl(info
->tag
);
127 memcpy(p
, &network_order
, sizeof(network_order
));
128 p
+= sizeof(network_order
);
131 /* Fill LSA Header */
133 lsa_header
->type
= htons(OSPF6_LSTYPE_AS_EXTERNAL
);
134 lsa_header
->id
= route
->path
.origin
.id
;
135 lsa_header
->adv_router
= ospf6
->router_id
;
137 ospf6_new_ls_seqnum(lsa_header
->type
, lsa_header
->id
,
138 lsa_header
->adv_router
, ospf6
->lsdb
);
139 lsa_header
->length
= htons((caddr_t
)p
- (caddr_t
)lsa_header
);
142 ospf6_lsa_checksum(lsa_header
);
145 lsa
= ospf6_lsa_create(lsa_header
);
148 ospf6_lsa_originate_process(lsa
, ospf6
);
151 int ospf6_orig_as_external_lsa(struct thread
*thread
)
153 struct ospf6_interface
*oi
;
154 struct ospf6_lsa
*lsa
;
155 uint32_t type
, adv_router
;
157 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
158 oi
->thread_as_extern_lsa
= NULL
;
160 if (oi
->state
== OSPF6_INTERFACE_DOWN
)
163 type
= htons(OSPF6_LSTYPE_AS_EXTERNAL
);
164 adv_router
= oi
->area
->ospf6
->router_id
;
165 for (ALL_LSDB_TYPED_ADVRTR(ospf6
->lsdb
, type
, adv_router
, lsa
)) {
166 if (IS_OSPF6_DEBUG_ASBR
)
167 zlog_debug("%s: Send update of AS-External LSA %s seq 0x%x",
168 __PRETTY_FUNCTION__
, lsa
->name
,
169 ntohl(lsa
->header
->seqnum
));
171 ospf6_flood_interface(NULL
, lsa
, oi
);
177 static route_tag_t
ospf6_as_external_lsa_get_tag(struct ospf6_lsa
*lsa
)
179 struct ospf6_as_external_lsa
*external
;
180 ptrdiff_t tag_offset
;
181 route_tag_t network_order
;
186 external
= (struct ospf6_as_external_lsa
*)OSPF6_LSA_HEADER_END(
189 if (!CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_T
))
192 tag_offset
= sizeof(*external
)
193 + OSPF6_PREFIX_SPACE(external
->prefix
.prefix_length
);
194 if (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_F
))
195 tag_offset
+= sizeof(struct in6_addr
);
197 memcpy(&network_order
, (caddr_t
)external
+ tag_offset
,
198 sizeof(network_order
));
199 return ntohl(network_order
);
202 void ospf6_asbr_update_route_ecmp_path(struct ospf6_route
*old
,
203 struct ospf6_route
*route
)
205 struct ospf6_route
*old_route
;
206 struct ospf6_path
*ecmp_path
, *o_path
= NULL
;
207 struct listnode
*anode
;
208 struct listnode
*nnode
, *rnode
, *rnext
;
209 struct ospf6_nexthop
*nh
, *rnh
;
210 char buf
[PREFIX2STR_BUFFER
];
211 bool route_found
= false;
213 for (old_route
= old
; old_route
; old_route
= old_route
->next
) {
214 if (ospf6_route_is_same(old_route
, route
) &&
215 (old_route
->path
.type
== route
->path
.type
) &&
216 (old_route
->path
.cost
== route
->path
.cost
) &&
217 (old_route
->path
.u
.cost_e2
== route
->path
.u
.cost_e2
)) {
219 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
)) {
220 prefix2str(&old_route
->prefix
, buf
,
222 zlog_debug("%s: old route %s path cost %u [%u]",
223 __PRETTY_FUNCTION__
, buf
,
224 old_route
->path
.cost
,
225 ospf6_route_is_same(old_route
,
229 /* check if this path exists already in
230 * route->paths list, if so, replace nh_list
233 for (ALL_LIST_ELEMENTS_RO(old_route
->paths
, anode
,
235 if ((o_path
->origin
.id
== route
->path
.origin
.id
)
236 && (o_path
->origin
.adv_router
==
237 route
->path
.origin
.adv_router
))
240 /* If path is not found in old_route paths's list,
241 * add a new path to route paths list and merge
242 * nexthops in route->path->nh_list.
243 * Otherwise replace existing path's nh_list.
245 if (o_path
== NULL
) {
246 ecmp_path
= ospf6_path_dup(&route
->path
);
248 /* Add a nh_list to new ecmp path */
249 ospf6_copy_nexthops(ecmp_path
->nh_list
,
251 /* Merge nexthop to existing route's nh_list */
252 ospf6_route_merge_nexthops(old_route
, route
);
255 if (ospf6
->route_table
->hook_add
)
256 (*ospf6
->route_table
->hook_add
)
259 /* Add the new path to route's path list */
260 listnode_add_sort(old_route
->paths
, ecmp_path
);
262 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
)) {
263 prefix2str(&route
->prefix
, buf
,
265 zlog_debug("%s: route %s another path added with nh %u, Paths %u",
266 __PRETTY_FUNCTION__
, buf
,
267 listcount(ecmp_path
->nh_list
),
269 listcount(old_route
->paths
)
273 for (ALL_LIST_ELEMENTS_RO(o_path
->nh_list
,
275 for (ALL_LIST_ELEMENTS(
277 rnode
, rnext
, rnh
)) {
278 if (!ospf6_nexthop_is_same(rnh
,
285 ospf6_nexthop_delete(rnh
);
288 list_delete_all_node(o_path
->nh_list
);
289 ospf6_copy_nexthops(o_path
->nh_list
,
292 /* Merge nexthop to existing route's nh_list */
293 ospf6_route_merge_nexthops(old_route
,
296 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
)) {
297 prefix2str(&route
->prefix
,
299 zlog_debug("%s: existing route %s with effective nh count %u",
300 __PRETTY_FUNCTION__
, buf
,
302 listcount(old_route
->nh_list
)
307 if (ospf6
->route_table
->hook_add
)
308 (*ospf6
->route_table
->hook_add
)
312 /* Delete the new route its info added to existing
315 ospf6_route_delete(route
);
321 /* Add new route to existing node in ospf6 route table. */
322 ospf6_route_add(route
, ospf6
->route_table
);
326 void ospf6_asbr_lsa_add(struct ospf6_lsa
*lsa
)
328 struct ospf6_as_external_lsa
*external
;
329 struct prefix asbr_id
;
330 struct ospf6_route
*asbr_entry
, *route
, *old
;
331 struct ospf6_path
*path
;
332 char buf
[PREFIX2STR_BUFFER
];
334 external
= (struct ospf6_as_external_lsa
*)OSPF6_LSA_HEADER_END(
337 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
338 zlog_debug("Calculate AS-External route for %s", lsa
->name
);
340 if (lsa
->header
->adv_router
== ospf6
->router_id
) {
341 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
342 zlog_debug("Ignore self-originated AS-External-LSA");
346 if (OSPF6_ASBR_METRIC(external
) == OSPF_LS_INFINITY
) {
347 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
348 zlog_debug("Ignore LSA with LSInfinity Metric");
352 if (CHECK_FLAG(external
->prefix
.prefix_options
,
353 OSPF6_PREFIX_OPTION_NU
)) {
354 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
355 zlog_debug("Ignore LSA with NU bit set Metric");
359 ospf6_linkstate_prefix(lsa
->header
->adv_router
, htonl(0), &asbr_id
);
360 asbr_entry
= ospf6_route_lookup(&asbr_id
, ospf6
->brouter_table
);
361 if (asbr_entry
== NULL
362 || !CHECK_FLAG(asbr_entry
->path
.router_bits
, OSPF6_ROUTER_BIT_E
)) {
363 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
)) {
364 prefix2str(&asbr_id
, buf
, sizeof(buf
));
365 zlog_debug("ASBR entry not found: %s", buf
);
370 route
= ospf6_route_create();
371 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
372 route
->prefix
.family
= AF_INET6
;
373 route
->prefix
.prefixlen
= external
->prefix
.prefix_length
;
374 ospf6_prefix_in6_addr(&route
->prefix
.u
.prefix6
, &external
->prefix
);
376 route
->path
.area_id
= asbr_entry
->path
.area_id
;
377 route
->path
.origin
.type
= lsa
->header
->type
;
378 route
->path
.origin
.id
= lsa
->header
->id
;
379 route
->path
.origin
.adv_router
= lsa
->header
->adv_router
;
381 route
->path
.prefix_options
= external
->prefix
.prefix_options
;
382 if (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_E
)) {
383 route
->path
.type
= OSPF6_PATH_TYPE_EXTERNAL2
;
384 route
->path
.metric_type
= 2;
385 route
->path
.cost
= asbr_entry
->path
.cost
;
386 route
->path
.u
.cost_e2
= OSPF6_ASBR_METRIC(external
);
388 route
->path
.type
= OSPF6_PATH_TYPE_EXTERNAL1
;
389 route
->path
.metric_type
= 1;
391 asbr_entry
->path
.cost
+ OSPF6_ASBR_METRIC(external
);
392 route
->path
.u
.cost_e2
= 0;
395 route
->path
.tag
= ospf6_as_external_lsa_get_tag(lsa
);
397 ospf6_route_copy_nexthops(route
, asbr_entry
);
399 path
= ospf6_path_dup(&route
->path
);
400 ospf6_copy_nexthops(path
->nh_list
, asbr_entry
->nh_list
);
401 listnode_add_sort(route
->paths
, path
);
404 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
)) {
405 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
406 zlog_debug("%s: AS-External %u route add %s cost %u(%u) nh %u",
408 (route
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL1
)
409 ? 1 : 2, buf
, route
->path
.cost
,
410 route
->path
.u
.cost_e2
,
411 listcount(route
->nh_list
));
414 old
= ospf6_route_lookup(&route
->prefix
, ospf6
->route_table
);
416 /* Add the new route to ospf6 instance route table. */
417 ospf6_route_add(route
, ospf6
->route_table
);
420 * ECMP: Keep new equal preference path in current
421 * route's path list, update zebra with new effective
422 * list along with addition of ECMP path.
424 ospf6_asbr_update_route_ecmp_path(old
, route
);
429 void ospf6_asbr_lsa_remove(struct ospf6_lsa
*lsa
)
431 struct ospf6_as_external_lsa
*external
;
432 struct prefix prefix
;
433 struct ospf6_route
*route
, *nroute
;
434 char buf
[PREFIX2STR_BUFFER
];
436 external
= (struct ospf6_as_external_lsa
*)OSPF6_LSA_HEADER_END(
439 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
440 zlog_debug("Withdraw AS-External route for %s", lsa
->name
);
442 if (lsa
->header
->adv_router
== ospf6
->router_id
) {
443 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
444 zlog_debug("Ignore self-originated AS-External-LSA");
448 memset(&prefix
, 0, sizeof(struct prefix
));
449 prefix
.family
= AF_INET6
;
450 prefix
.prefixlen
= external
->prefix
.prefix_length
;
451 ospf6_prefix_in6_addr(&prefix
.u
.prefix6
, &external
->prefix
);
453 route
= ospf6_route_lookup(&prefix
, ospf6
->route_table
);
455 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
)) {
456 prefix2str(&prefix
, buf
, sizeof(buf
));
457 zlog_debug("AS-External route %s not found", buf
);
462 for (ospf6_route_lock(route
);
463 route
&& ospf6_route_is_prefix(&prefix
, route
); route
= nroute
) {
464 nroute
= ospf6_route_next(route
);
465 if (route
->type
!= OSPF6_DEST_TYPE_NETWORK
)
468 /* Route has multiple ECMP paths remove,
469 * matching path and update effective route's nh list.
471 if (listcount(route
->paths
) > 1) {
472 struct listnode
*anode
, *anext
;
473 struct listnode
*nnode
, *rnode
, *rnext
;
474 struct ospf6_nexthop
*nh
, *rnh
;
475 struct ospf6_path
*o_path
;
476 bool nh_updated
= false;
478 /* Iterate all paths of route to find maching with LSA
479 * remove from route path list. If route->path is same,
480 * replace from paths list.
482 for (ALL_LIST_ELEMENTS(route
->paths
, anode
, anext
,
484 if (o_path
->origin
.type
!= lsa
->header
->type
)
486 if (o_path
->origin
.id
!= lsa
->header
->id
)
488 if (o_path
->origin
.adv_router
!=
489 lsa
->header
->adv_router
)
492 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
)) {
493 prefix2str(&prefix
, buf
, sizeof(buf
));
495 "%s: route %s path found with nh %u",
496 __PRETTY_FUNCTION__
, buf
,
497 listcount(o_path
->nh_list
));
500 /* Remove found path's nh_list from
501 * the route's nh_list.
503 for (ALL_LIST_ELEMENTS_RO(o_path
->nh_list
,
505 for (ALL_LIST_ELEMENTS(route
->nh_list
,
506 rnode
, rnext
, rnh
)) {
507 if (!ospf6_nexthop_is_same(rnh
,
510 listnode_delete(route
->nh_list
,
512 ospf6_nexthop_delete(rnh
);
515 /* Delete the path from route's path list */
516 listnode_delete(route
->paths
, o_path
);
517 ospf6_path_free(o_path
);
522 /* Iterate all paths and merge nexthop,
523 * unlesss any of the nexthop similar to
524 * ones deleted as part of path deletion.
527 for (ALL_LIST_ELEMENTS(route
->paths
, anode
,
529 ospf6_merge_nexthops(route
->nh_list
,
533 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
)) {
534 prefix2str(&route
->prefix
, buf
,
536 zlog_debug("%s: AS-External %u route %s update paths %u nh %u"
537 , __PRETTY_FUNCTION__
,
539 OSPF6_PATH_TYPE_EXTERNAL1
)
541 listcount(route
->paths
),
542 listcount(route
->nh_list
));
545 /* Update RIB/FIB w/ effective nh_list */
546 if (ospf6
->route_table
->hook_add
)
547 (*ospf6
->route_table
->hook_add
)(route
);
549 /* route's path is similar to lsa header,
550 * replace route's path with route's
553 if (route
->path
.origin
.id
== lsa
->header
->id
&&
554 route
->path
.origin
.adv_router
==
555 lsa
->header
->adv_router
) {
556 struct ospf6_path
*h_path
;
558 h_path
= (struct ospf6_path
*)
559 listgetdata(listhead(route
->paths
));
560 route
->path
.origin
.type
=
562 route
->path
.origin
.id
=
564 route
->path
.origin
.adv_router
=
565 h_path
->origin
.adv_router
;
571 if (route
->path
.origin
.type
!= lsa
->header
->type
)
573 if (route
->path
.origin
.id
!= lsa
->header
->id
)
575 if (route
->path
.origin
.adv_router
!=
576 lsa
->header
->adv_router
)
579 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
)) {
580 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
581 zlog_debug("%s: AS-External %u route remove %s cost %u(%u) nh %u",
583 route
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL1
584 ? 1 : 2, buf
, route
->path
.cost
,
585 route
->path
.u
.cost_e2
,
586 listcount(route
->nh_list
));
588 ospf6_route_remove(route
, ospf6
->route_table
);
591 ospf6_route_unlock(route
);
594 void ospf6_asbr_lsentry_add(struct ospf6_route
*asbr_entry
)
596 struct ospf6_lsa
*lsa
;
600 if (!CHECK_FLAG(asbr_entry
->flag
, OSPF6_ROUTE_BEST
)) {
602 inet_ntop(AF_INET
, &ADV_ROUTER_IN_PREFIX(&asbr_entry
->prefix
),
604 zlog_info("ignore non-best path: lsentry %s add", buf
);
608 type
= htons(OSPF6_LSTYPE_AS_EXTERNAL
);
609 router
= ospf6_linkstate_prefix_adv_router(&asbr_entry
->prefix
);
610 for (ALL_LSDB_TYPED_ADVRTR(ospf6
->lsdb
, type
, router
, lsa
)) {
611 if (!OSPF6_LSA_IS_MAXAGE(lsa
))
612 ospf6_asbr_lsa_add(lsa
);
616 void ospf6_asbr_lsentry_remove(struct ospf6_route
*asbr_entry
)
618 struct ospf6_lsa
*lsa
;
622 type
= htons(OSPF6_LSTYPE_AS_EXTERNAL
);
623 router
= ospf6_linkstate_prefix_adv_router(&asbr_entry
->prefix
);
624 for (ALL_LSDB_TYPED_ADVRTR(ospf6
->lsdb
, type
, router
, lsa
))
625 ospf6_asbr_lsa_remove(lsa
);
629 /* redistribute function */
631 static void ospf6_asbr_routemap_set(int type
, const char *mapname
)
633 if (ospf6
->rmap
[type
].name
)
634 free(ospf6
->rmap
[type
].name
);
635 ospf6
->rmap
[type
].name
= strdup(mapname
);
636 ospf6
->rmap
[type
].map
= route_map_lookup_by_name(mapname
);
639 static void ospf6_asbr_routemap_unset(int type
)
641 if (ospf6
->rmap
[type
].name
)
642 free(ospf6
->rmap
[type
].name
);
643 ospf6
->rmap
[type
].name
= NULL
;
644 ospf6
->rmap
[type
].map
= NULL
;
647 static int ospf6_asbr_routemap_update_timer(struct thread
*thread
)
652 arg
= THREAD_ARG(thread
);
653 arg_type
= (int)(intptr_t)arg
[1];
655 ospf6
->t_distribute_update
= NULL
;
657 if (ospf6
->rmap
[arg_type
].name
)
658 ospf6
->rmap
[arg_type
].map
= route_map_lookup_by_name(
659 ospf6
->rmap
[arg_type
].name
);
660 if (ospf6
->rmap
[arg_type
].map
) {
661 if (IS_OSPF6_DEBUG_ASBR
)
662 zlog_debug("%s: route-map %s update, reset redist %s",
664 ospf6
->rmap
[arg_type
].name
,
665 ZROUTE_NAME(arg_type
));
667 ospf6_zebra_no_redistribute(arg_type
);
668 ospf6_zebra_redistribute(arg_type
);
671 XFREE(MTYPE_OSPF6_DIST_ARGS
, arg
);
675 void ospf6_asbr_distribute_list_update(int type
)
679 if (ospf6
->t_distribute_update
)
682 args
= XCALLOC(MTYPE_OSPF6_DIST_ARGS
, sizeof(void *)*2);
685 args
[1] = (void *)((ptrdiff_t)type
);
687 if (IS_OSPF6_DEBUG_ASBR
)
688 zlog_debug("%s: trigger redistribute %s reset thread",
689 __PRETTY_FUNCTION__
, ZROUTE_NAME(type
));
691 ospf6
->t_distribute_update
= NULL
;
692 thread_add_timer_msec(master
, ospf6_asbr_routemap_update_timer
,
693 (void **)args
, OSPF_MIN_LS_INTERVAL
,
694 &ospf6
->t_distribute_update
);
697 static void ospf6_asbr_routemap_update(const char *mapname
)
704 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
705 if (ospf6
->rmap
[type
].name
) {
706 ospf6
->rmap
[type
].map
= route_map_lookup_by_name(
707 ospf6
->rmap
[type
].name
);
709 if (mapname
&& ospf6
->rmap
[type
].map
&&
710 (strcmp(ospf6
->rmap
[type
].name
, mapname
) == 0)) {
711 if (IS_OSPF6_DEBUG_ASBR
)
712 zlog_debug("%s: route-map %s update, reset redist %s",
713 __PRETTY_FUNCTION__
, mapname
,
715 ospf6_asbr_distribute_list_update(type
);
718 ospf6
->rmap
[type
].map
= NULL
;
722 static void ospf6_asbr_routemap_event(route_map_event_t event
, const char *name
)
728 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
729 if ((ospf6
->rmap
[type
].name
) &&
730 (strcmp(ospf6
->rmap
[type
].name
, name
) == 0)) {
731 ospf6_asbr_distribute_list_update(type
);
736 int ospf6_asbr_is_asbr(struct ospf6
*o
)
738 return o
->external_table
->count
;
741 static void ospf6_asbr_redistribute_set(int type
)
743 ospf6_zebra_redistribute(type
);
746 static void ospf6_asbr_redistribute_unset(int type
)
748 struct ospf6_route
*route
;
749 struct ospf6_external_info
*info
;
751 ospf6_zebra_no_redistribute(type
);
753 for (route
= ospf6_route_head(ospf6
->external_table
); route
;
754 route
= ospf6_route_next(route
)) {
755 info
= route
->route_option
;
756 if (info
->type
!= type
)
759 ospf6_asbr_redistribute_remove(info
->type
, 0, &route
->prefix
);
762 ospf6_asbr_routemap_unset(type
);
765 /* When an area is unstubified, flood all the external LSAs in the area */
766 void ospf6_asbr_send_externals_to_area(struct ospf6_area
*oa
)
768 struct ospf6_lsa
*lsa
;
770 for (ALL_LSDB(oa
->ospf6
->lsdb
, lsa
)) {
771 if (ntohs(lsa
->header
->type
) == OSPF6_LSTYPE_AS_EXTERNAL
) {
772 zlog_debug("%s: Flooding AS-External LSA %s\n",
773 __func__
, lsa
->name
);
774 ospf6_flood_area(NULL
, lsa
, oa
);
779 void ospf6_asbr_redistribute_add(int type
, ifindex_t ifindex
,
780 struct prefix
*prefix
, u_int nexthop_num
,
781 struct in6_addr
*nexthop
, route_tag_t tag
)
784 struct ospf6_route troute
;
785 struct ospf6_external_info tinfo
;
786 struct ospf6_route
*route
, *match
;
787 struct ospf6_external_info
*info
;
788 struct prefix prefix_id
;
789 struct route_node
*node
;
790 char pbuf
[PREFIX2STR_BUFFER
], ibuf
[16];
791 struct listnode
*lnode
, *lnnode
;
792 struct ospf6_area
*oa
;
794 if (!ospf6_zebra_is_redistribute(type
))
797 memset(&troute
, 0, sizeof(troute
));
798 memset(&tinfo
, 0, sizeof(tinfo
));
800 if (IS_OSPF6_DEBUG_ASBR
) {
801 prefix2str(prefix
, pbuf
, sizeof(pbuf
));
802 zlog_debug("Redistribute %s (%s)", pbuf
, ZROUTE_NAME(type
));
805 /* if route-map was specified but not found, do not advertise */
806 if (ospf6
->rmap
[type
].name
) {
807 if (ospf6
->rmap
[type
].map
== NULL
)
808 ospf6_asbr_routemap_update(NULL
);
809 if (ospf6
->rmap
[type
].map
== NULL
) {
811 "route-map \"%s\" not found, suppress redistributing",
812 ospf6
->rmap
[type
].name
);
817 /* apply route-map */
818 if (ospf6
->rmap
[type
].map
) {
819 troute
.route_option
= &tinfo
;
820 tinfo
.ifindex
= ifindex
;
823 ret
= route_map_apply(ospf6
->rmap
[type
].map
, prefix
, RMAP_OSPF6
,
825 if (ret
== RMAP_DENYMATCH
) {
826 if (IS_OSPF6_DEBUG_ASBR
)
827 zlog_debug("Denied by route-map \"%s\"",
828 ospf6
->rmap
[type
].name
);
833 match
= ospf6_route_lookup(prefix
, ospf6
->external_table
);
835 info
= match
->route_option
;
836 /* copy result of route-map */
837 if (ospf6
->rmap
[type
].map
) {
838 if (troute
.path
.metric_type
)
839 match
->path
.metric_type
=
840 troute
.path
.metric_type
;
841 if (troute
.path
.cost
)
842 match
->path
.cost
= troute
.path
.cost
;
843 if (!IN6_IS_ADDR_UNSPECIFIED(&tinfo
.forwarding
))
844 memcpy(&info
->forwarding
, &tinfo
.forwarding
,
845 sizeof(struct in6_addr
));
846 info
->tag
= tinfo
.tag
;
848 /* If there is no route-map, simply update the tag */
854 if (nexthop_num
&& nexthop
)
855 ospf6_route_add_nexthop(match
, ifindex
, nexthop
);
857 ospf6_route_add_nexthop(match
, ifindex
, NULL
);
859 /* create/update binding in external_id_table */
860 prefix_id
.family
= AF_INET
;
861 prefix_id
.prefixlen
= 32;
862 prefix_id
.u
.prefix4
.s_addr
= htonl(info
->id
);
863 node
= route_node_get(ospf6
->external_id_table
, &prefix_id
);
866 if (IS_OSPF6_DEBUG_ASBR
) {
867 inet_ntop(AF_INET
, &prefix_id
.u
.prefix4
, ibuf
,
869 prefix2str(prefix
, pbuf
, sizeof(pbuf
));
870 zlog_debug("Advertise as AS-External Id:%s prefix %s metric %u",
871 ibuf
, pbuf
, match
->path
.metric_type
);
874 match
->path
.origin
.id
= htonl(info
->id
);
875 ospf6_as_external_lsa_originate(match
);
879 /* create new entry */
880 route
= ospf6_route_create();
881 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
882 memcpy(&route
->prefix
, prefix
, sizeof(struct prefix
));
884 info
= (struct ospf6_external_info
*)XCALLOC(
885 MTYPE_OSPF6_EXTERNAL_INFO
, sizeof(struct ospf6_external_info
));
886 route
->route_option
= info
;
887 info
->id
= ospf6
->external_id
++;
889 /* copy result of route-map */
890 if (ospf6
->rmap
[type
].map
) {
891 if (troute
.path
.metric_type
)
892 route
->path
.metric_type
= troute
.path
.metric_type
;
893 if (troute
.path
.cost
)
894 route
->path
.cost
= troute
.path
.cost
;
895 if (!IN6_IS_ADDR_UNSPECIFIED(&tinfo
.forwarding
))
896 memcpy(&info
->forwarding
, &tinfo
.forwarding
,
897 sizeof(struct in6_addr
));
898 info
->tag
= tinfo
.tag
;
900 /* If there is no route-map, simply set the tag */
905 if (nexthop_num
&& nexthop
)
906 ospf6_route_add_nexthop(route
, ifindex
, nexthop
);
908 ospf6_route_add_nexthop(route
, ifindex
, NULL
);
910 /* create/update binding in external_id_table */
911 prefix_id
.family
= AF_INET
;
912 prefix_id
.prefixlen
= 32;
913 prefix_id
.u
.prefix4
.s_addr
= htonl(info
->id
);
914 node
= route_node_get(ospf6
->external_id_table
, &prefix_id
);
917 route
= ospf6_route_add(route
, ospf6
->external_table
);
918 route
->route_option
= info
;
920 if (IS_OSPF6_DEBUG_ASBR
) {
921 inet_ntop(AF_INET
, &prefix_id
.u
.prefix4
, ibuf
, sizeof(ibuf
));
922 prefix2str(prefix
, pbuf
, sizeof(pbuf
));
923 zlog_debug("Advertise as AS-External Id:%s prefix %s metric %u",
924 ibuf
, pbuf
, route
->path
.metric_type
);
927 route
->path
.origin
.id
= htonl(info
->id
);
928 ospf6_as_external_lsa_originate(route
);
930 /* Router-Bit (ASBR Flag) may have to be updated */
931 for (ALL_LIST_ELEMENTS(ospf6
->area_list
, lnode
, lnnode
, oa
))
932 OSPF6_ROUTER_LSA_SCHEDULE(oa
);
935 void ospf6_asbr_redistribute_remove(int type
, ifindex_t ifindex
,
936 struct prefix
*prefix
)
938 struct ospf6_route
*match
;
939 struct ospf6_external_info
*info
= NULL
;
940 struct route_node
*node
;
941 struct ospf6_lsa
*lsa
;
942 struct prefix prefix_id
;
943 char pbuf
[PREFIX2STR_BUFFER
], ibuf
[16];
944 struct listnode
*lnode
, *lnnode
;
945 struct ospf6_area
*oa
;
947 match
= ospf6_route_lookup(prefix
, ospf6
->external_table
);
949 if (IS_OSPF6_DEBUG_ASBR
) {
950 prefix2str(prefix
, pbuf
, sizeof(pbuf
));
951 zlog_debug("No such route %s to withdraw", pbuf
);
956 info
= match
->route_option
;
959 if (info
->type
!= type
) {
960 if (IS_OSPF6_DEBUG_ASBR
) {
961 prefix2str(prefix
, pbuf
, sizeof(pbuf
));
962 zlog_debug("Original protocol mismatch: %s", pbuf
);
967 if (IS_OSPF6_DEBUG_ASBR
) {
968 prefix2str(prefix
, pbuf
, sizeof(pbuf
));
969 inet_ntop(AF_INET
, &prefix_id
.u
.prefix4
, ibuf
, sizeof(ibuf
));
970 zlog_debug("Withdraw %s (AS-External Id:%s)", pbuf
, ibuf
);
973 lsa
= ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_AS_EXTERNAL
),
974 htonl(info
->id
), ospf6
->router_id
, ospf6
->lsdb
);
976 ospf6_lsa_purge(lsa
);
978 /* remove binding in external_id_table */
979 prefix_id
.family
= AF_INET
;
980 prefix_id
.prefixlen
= 32;
981 prefix_id
.u
.prefix4
.s_addr
= htonl(info
->id
);
982 node
= route_node_lookup(ospf6
->external_id_table
, &prefix_id
);
985 route_unlock_node(node
); /* to free the lookup lock */
986 route_unlock_node(node
); /* to free the original lock */
988 ospf6_route_remove(match
, ospf6
->external_table
);
989 XFREE(MTYPE_OSPF6_EXTERNAL_INFO
, info
);
991 /* Router-Bit (ASBR Flag) may have to be updated */
992 for (ALL_LIST_ELEMENTS(ospf6
->area_list
, lnode
, lnnode
, oa
))
993 OSPF6_ROUTER_LSA_SCHEDULE(oa
);
996 DEFUN (ospf6_redistribute
,
997 ospf6_redistribute_cmd
,
998 "redistribute " FRR_REDIST_STR_OSPF6D
,
1000 FRR_REDIST_HELP_STR_OSPF6D
)
1004 char *proto
= argv
[argc
- 1]->text
;
1005 type
= proto_redistnum(AFI_IP6
, proto
);
1007 return CMD_WARNING_CONFIG_FAILED
;
1009 ospf6_asbr_redistribute_unset(type
);
1010 ospf6_asbr_redistribute_set(type
);
1014 DEFUN (ospf6_redistribute_routemap
,
1015 ospf6_redistribute_routemap_cmd
,
1016 "redistribute " FRR_REDIST_STR_OSPF6D
" route-map WORD",
1018 FRR_REDIST_HELP_STR_OSPF6D
1019 "Route map reference\n"
1022 int idx_protocol
= 1;
1026 char *proto
= argv
[idx_protocol
]->text
;
1027 type
= proto_redistnum(AFI_IP6
, proto
);
1029 return CMD_WARNING_CONFIG_FAILED
;
1031 ospf6_asbr_redistribute_unset(type
);
1032 ospf6_asbr_routemap_set(type
, argv
[idx_word
]->arg
);
1033 ospf6_asbr_redistribute_set(type
);
1037 DEFUN (no_ospf6_redistribute
,
1038 no_ospf6_redistribute_cmd
,
1039 "no redistribute " FRR_REDIST_STR_OSPF6D
" [route-map WORD]",
1042 FRR_REDIST_HELP_STR_OSPF6D
1043 "Route map reference\n"
1046 int idx_protocol
= 2;
1049 char *proto
= argv
[idx_protocol
]->text
;
1050 type
= proto_redistnum(AFI_IP6
, proto
);
1052 return CMD_WARNING_CONFIG_FAILED
;
1054 ospf6_asbr_redistribute_unset(type
);
1059 int ospf6_redistribute_config_write(struct vty
*vty
)
1063 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
1064 if (type
== ZEBRA_ROUTE_OSPF6
)
1066 if (!ospf6_zebra_is_redistribute(type
))
1069 if (ospf6
->rmap
[type
].name
)
1070 vty_out(vty
, " redistribute %s route-map %s\n",
1071 ZROUTE_NAME(type
), ospf6
->rmap
[type
].name
);
1073 vty_out(vty
, " redistribute %s\n", ZROUTE_NAME(type
));
1079 static void ospf6_redistribute_show_config(struct vty
*vty
)
1082 int nroute
[ZEBRA_ROUTE_MAX
];
1084 struct ospf6_route
*route
;
1085 struct ospf6_external_info
*info
;
1088 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
1090 for (route
= ospf6_route_head(ospf6
->external_table
); route
;
1091 route
= ospf6_route_next(route
)) {
1092 info
= route
->route_option
;
1093 nroute
[info
->type
]++;
1097 vty_out(vty
, "Redistributing External Routes from:\n");
1098 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
1099 if (type
== ZEBRA_ROUTE_OSPF6
)
1101 if (!ospf6_zebra_is_redistribute(type
))
1104 if (ospf6
->rmap
[type
].name
)
1105 vty_out(vty
, " %d: %s with route-map \"%s\"%s\n",
1106 nroute
[type
], ZROUTE_NAME(type
),
1107 ospf6
->rmap
[type
].name
,
1108 (ospf6
->rmap
[type
].map
? ""
1109 : " (not found !)"));
1111 vty_out(vty
, " %d: %s\n", nroute
[type
],
1114 vty_out(vty
, "Total %d routes\n", total
);
1118 /* Routemap Functions */
1119 static route_map_result_t
1120 ospf6_routemap_rule_match_address_prefixlist(void *rule
, struct prefix
*prefix
,
1121 route_map_object_t type
,
1124 struct prefix_list
*plist
;
1126 if (type
!= RMAP_OSPF6
)
1127 return RMAP_NOMATCH
;
1129 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
1131 return RMAP_NOMATCH
;
1133 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
1138 ospf6_routemap_rule_match_address_prefixlist_compile(const char *arg
)
1140 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1143 static void ospf6_routemap_rule_match_address_prefixlist_free(void *rule
)
1145 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1148 struct route_map_rule_cmd ospf6_routemap_rule_match_address_prefixlist_cmd
= {
1149 "ipv6 address prefix-list",
1150 ospf6_routemap_rule_match_address_prefixlist
,
1151 ospf6_routemap_rule_match_address_prefixlist_compile
,
1152 ospf6_routemap_rule_match_address_prefixlist_free
,
1155 /* `match interface IFNAME' */
1156 /* Match function should return 1 if match is success else return
1158 static route_map_result_t
1159 ospf6_routemap_rule_match_interface(void *rule
, struct prefix
*prefix
,
1160 route_map_object_t type
, void *object
)
1162 struct interface
*ifp
;
1163 struct ospf6_external_info
*ei
;
1165 if (type
== RMAP_OSPF6
) {
1166 ei
= ((struct ospf6_route
*)object
)->route_option
;
1167 ifp
= if_lookup_by_name((char *)rule
, VRF_DEFAULT
);
1169 if (ifp
!= NULL
&& ei
->ifindex
== ifp
->ifindex
)
1173 return RMAP_NOMATCH
;
1176 /* Route map `interface' match statement. `arg' should be
1178 static void *ospf6_routemap_rule_match_interface_compile(const char *arg
)
1180 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1183 /* Free route map's compiled `interface' value. */
1184 static void ospf6_routemap_rule_match_interface_free(void *rule
)
1186 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1189 /* Route map commands for interface matching. */
1190 struct route_map_rule_cmd ospf6_routemap_rule_match_interface_cmd
= {
1191 "interface", ospf6_routemap_rule_match_interface
,
1192 ospf6_routemap_rule_match_interface_compile
,
1193 ospf6_routemap_rule_match_interface_free
};
1195 /* Match function for matching route tags */
1196 static route_map_result_t
ospf6_routemap_rule_match_tag(void *rule
,
1197 struct prefix
*prefix
,
1198 route_map_object_t type
,
1201 route_tag_t
*tag
= rule
;
1202 struct ospf6_route
*route
= object
;
1203 struct ospf6_external_info
*info
= route
->route_option
;
1205 if (type
== RMAP_OSPF6
&& info
->tag
== *tag
)
1208 return RMAP_NOMATCH
;
1211 static struct route_map_rule_cmd ospf6_routemap_rule_match_tag_cmd
= {
1212 "tag", ospf6_routemap_rule_match_tag
, route_map_rule_tag_compile
,
1213 route_map_rule_tag_free
,
1216 static route_map_result_t
1217 ospf6_routemap_rule_set_metric_type(void *rule
, struct prefix
*prefix
,
1218 route_map_object_t type
, void *object
)
1220 char *metric_type
= rule
;
1221 struct ospf6_route
*route
= object
;
1223 if (type
!= RMAP_OSPF6
)
1226 if (strcmp(metric_type
, "type-2") == 0)
1227 route
->path
.metric_type
= 2;
1229 route
->path
.metric_type
= 1;
1234 static void *ospf6_routemap_rule_set_metric_type_compile(const char *arg
)
1236 if (strcmp(arg
, "type-2") && strcmp(arg
, "type-1"))
1238 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1241 static void ospf6_routemap_rule_set_metric_type_free(void *rule
)
1243 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1246 struct route_map_rule_cmd ospf6_routemap_rule_set_metric_type_cmd
= {
1247 "metric-type", ospf6_routemap_rule_set_metric_type
,
1248 ospf6_routemap_rule_set_metric_type_compile
,
1249 ospf6_routemap_rule_set_metric_type_free
,
1252 static route_map_result_t
1253 ospf6_routemap_rule_set_metric(void *rule
, struct prefix
*prefix
,
1254 route_map_object_t type
, void *object
)
1256 char *metric
= rule
;
1257 struct ospf6_route
*route
= object
;
1259 if (type
!= RMAP_OSPF6
)
1262 route
->path
.cost
= atoi(metric
);
1266 static void *ospf6_routemap_rule_set_metric_compile(const char *arg
)
1270 metric
= strtoul(arg
, &endp
, 0);
1271 if (metric
> OSPF_LS_INFINITY
|| *endp
!= '\0')
1273 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1276 static void ospf6_routemap_rule_set_metric_free(void *rule
)
1278 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1281 struct route_map_rule_cmd ospf6_routemap_rule_set_metric_cmd
= {
1282 "metric", ospf6_routemap_rule_set_metric
,
1283 ospf6_routemap_rule_set_metric_compile
,
1284 ospf6_routemap_rule_set_metric_free
,
1287 static route_map_result_t
1288 ospf6_routemap_rule_set_forwarding(void *rule
, struct prefix
*prefix
,
1289 route_map_object_t type
, void *object
)
1291 char *forwarding
= rule
;
1292 struct ospf6_route
*route
= object
;
1293 struct ospf6_external_info
*info
= route
->route_option
;
1295 if (type
!= RMAP_OSPF6
)
1298 if (inet_pton(AF_INET6
, forwarding
, &info
->forwarding
) != 1) {
1299 memset(&info
->forwarding
, 0, sizeof(struct in6_addr
));
1306 static void *ospf6_routemap_rule_set_forwarding_compile(const char *arg
)
1309 if (inet_pton(AF_INET6
, arg
, &a
) != 1)
1311 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1314 static void ospf6_routemap_rule_set_forwarding_free(void *rule
)
1316 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1319 struct route_map_rule_cmd ospf6_routemap_rule_set_forwarding_cmd
= {
1320 "forwarding-address", ospf6_routemap_rule_set_forwarding
,
1321 ospf6_routemap_rule_set_forwarding_compile
,
1322 ospf6_routemap_rule_set_forwarding_free
,
1325 static route_map_result_t
ospf6_routemap_rule_set_tag(void *rule
,
1326 struct prefix
*prefix
,
1327 route_map_object_t type
,
1330 route_tag_t
*tag
= rule
;
1331 struct ospf6_route
*route
= object
;
1332 struct ospf6_external_info
*info
= route
->route_option
;
1334 if (type
!= RMAP_OSPF6
)
1341 static struct route_map_rule_cmd ospf6_routemap_rule_set_tag_cmd
= {
1342 "tag", ospf6_routemap_rule_set_tag
, route_map_rule_tag_compile
,
1343 route_map_rule_tag_free
,
1346 static int route_map_command_status(struct vty
*vty
, int ret
)
1349 case RMAP_RULE_MISSING
:
1350 vty_out(vty
, "OSPF6 Can't find rule.\n");
1351 return CMD_WARNING_CONFIG_FAILED
;
1353 case RMAP_COMPILE_ERROR
:
1354 vty_out(vty
, "OSPF6 Argument is malformed.\n");
1355 return CMD_WARNING_CONFIG_FAILED
;
1357 case RMAP_COMPILE_SUCCESS
:
1364 /* add "set metric-type" */
1365 DEFUN (ospf6_routemap_set_metric_type
,
1366 ospf6_routemap_set_metric_type_cmd
,
1367 "set metric-type <type-1|type-2>",
1370 "OSPF6 external type 1 metric\n"
1371 "OSPF6 external type 2 metric\n")
1373 VTY_DECLVAR_CONTEXT(route_map_index
, route_map_index
);
1374 int idx_external
= 2;
1375 int ret
= route_map_add_set(route_map_index
, "metric-type",
1376 argv
[idx_external
]->arg
);
1377 return route_map_command_status(vty
, ret
);
1380 /* delete "set metric-type" */
1381 DEFUN (ospf6_routemap_no_set_metric_type
,
1382 ospf6_routemap_no_set_metric_type_cmd
,
1383 "no set metric-type [<type-1|type-2>]",
1387 "OSPF6 external type 1 metric\n"
1388 "OSPF6 external type 2 metric\n")
1390 VTY_DECLVAR_CONTEXT(route_map_index
, route_map_index
);
1391 char *ext
= (argc
== 4) ? argv
[3]->text
: NULL
;
1392 int ret
= route_map_delete_set(route_map_index
, "metric-type", ext
);
1393 return route_map_command_status(vty
, ret
);
1396 /* add "set forwarding-address" */
1397 DEFUN (ospf6_routemap_set_forwarding
,
1398 ospf6_routemap_set_forwarding_cmd
,
1399 "set forwarding-address X:X::X:X",
1401 "Forwarding Address\n"
1404 VTY_DECLVAR_CONTEXT(route_map_index
, route_map_index
);
1406 int ret
= route_map_add_set(route_map_index
, "forwarding-address",
1407 argv
[idx_ipv6
]->arg
);
1408 return route_map_command_status(vty
, ret
);
1411 /* delete "set forwarding-address" */
1412 DEFUN (ospf6_routemap_no_set_forwarding
,
1413 ospf6_routemap_no_set_forwarding_cmd
,
1414 "no set forwarding-address X:X::X:X",
1417 "Forwarding Address\n"
1420 VTY_DECLVAR_CONTEXT(route_map_index
, route_map_index
);
1422 int ret
= route_map_delete_set(route_map_index
, "forwarding-address",
1423 argv
[idx_ipv6
]->arg
);
1424 return route_map_command_status(vty
, ret
);
1427 static void ospf6_routemap_init(void)
1431 route_map_add_hook(ospf6_asbr_routemap_update
);
1432 route_map_delete_hook(ospf6_asbr_routemap_update
);
1433 route_map_event_hook(ospf6_asbr_routemap_event
);
1435 route_map_set_metric_hook(generic_set_add
);
1436 route_map_no_set_metric_hook(generic_set_delete
);
1438 route_map_match_tag_hook(generic_match_add
);
1439 route_map_no_match_tag_hook(generic_match_delete
);
1441 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
1442 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
1444 route_map_match_interface_hook(generic_match_add
);
1445 route_map_no_match_interface_hook(generic_match_delete
);
1447 route_map_install_match(
1448 &ospf6_routemap_rule_match_address_prefixlist_cmd
);
1449 route_map_install_match(&ospf6_routemap_rule_match_interface_cmd
);
1450 route_map_install_match(&ospf6_routemap_rule_match_tag_cmd
);
1452 route_map_install_set(&ospf6_routemap_rule_set_metric_type_cmd
);
1453 route_map_install_set(&ospf6_routemap_rule_set_metric_cmd
);
1454 route_map_install_set(&ospf6_routemap_rule_set_forwarding_cmd
);
1455 route_map_install_set(&ospf6_routemap_rule_set_tag_cmd
);
1457 /* ASE Metric Type (e.g. Type-1/Type-2) */
1458 install_element(RMAP_NODE
, &ospf6_routemap_set_metric_type_cmd
);
1459 install_element(RMAP_NODE
, &ospf6_routemap_no_set_metric_type_cmd
);
1462 install_element(RMAP_NODE
, &ospf6_routemap_set_forwarding_cmd
);
1463 install_element(RMAP_NODE
, &ospf6_routemap_no_set_forwarding_cmd
);
1467 /* Display functions */
1468 static char *ospf6_as_external_lsa_get_prefix_str(struct ospf6_lsa
*lsa
,
1469 char *buf
, int buflen
,
1472 struct ospf6_as_external_lsa
*external
;
1473 struct in6_addr in6
;
1474 int prefix_length
= 0;
1477 external
= (struct ospf6_as_external_lsa
*)OSPF6_LSA_HEADER_END(
1481 ospf6_prefix_in6_addr(&in6
, &external
->prefix
);
1482 prefix_length
= external
->prefix
.prefix_length
;
1484 in6
= *((struct in6_addr
1485 *)((caddr_t
)external
1487 ospf6_as_external_lsa
)
1488 + OSPF6_PREFIX_SPACE(
1493 inet_ntop(AF_INET6
, &in6
, buf
, buflen
);
1495 sprintf(&buf
[strlen(buf
)], "/%d",
1502 static int ospf6_as_external_lsa_show(struct vty
*vty
, struct ospf6_lsa
*lsa
)
1504 struct ospf6_as_external_lsa
*external
;
1507 assert(lsa
->header
);
1508 external
= (struct ospf6_as_external_lsa
*)OSPF6_LSA_HEADER_END(
1512 snprintf(buf
, sizeof(buf
), "%c%c%c",
1513 (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_E
) ? 'E'
1515 (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_F
) ? 'F'
1517 (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_T
) ? 'T'
1520 vty_out(vty
, " Bits: %s\n", buf
);
1521 vty_out(vty
, " Metric: %5lu\n",
1522 (u_long
)OSPF6_ASBR_METRIC(external
));
1524 ospf6_prefix_options_printbuf(external
->prefix
.prefix_options
, buf
,
1526 vty_out(vty
, " Prefix Options: %s\n", buf
);
1528 vty_out(vty
, " Referenced LSType: %d\n",
1529 ntohs(external
->prefix
.prefix_refer_lstype
));
1531 vty_out(vty
, " Prefix: %s\n",
1532 ospf6_as_external_lsa_get_prefix_str(lsa
, buf
, sizeof(buf
), 0));
1534 /* Forwarding-Address */
1535 if (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_F
)) {
1536 vty_out(vty
, " Forwarding-Address: %s\n",
1537 ospf6_as_external_lsa_get_prefix_str(lsa
, buf
,
1542 if (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_T
)) {
1543 vty_out(vty
, " Tag: %" ROUTE_TAG_PRI
"\n",
1544 ospf6_as_external_lsa_get_tag(lsa
));
1550 static void ospf6_asbr_external_route_show(struct vty
*vty
,
1551 struct ospf6_route
*route
)
1553 struct ospf6_external_info
*info
= route
->route_option
;
1554 char prefix
[PREFIX2STR_BUFFER
], id
[16], forwarding
[64];
1557 prefix2str(&route
->prefix
, prefix
, sizeof(prefix
));
1558 tmp_id
= ntohl(info
->id
);
1559 inet_ntop(AF_INET
, &tmp_id
, id
, sizeof(id
));
1560 if (!IN6_IS_ADDR_UNSPECIFIED(&info
->forwarding
))
1561 inet_ntop(AF_INET6
, &info
->forwarding
, forwarding
,
1562 sizeof(forwarding
));
1564 snprintf(forwarding
, sizeof(forwarding
), ":: (ifindex %d)",
1565 ospf6_route_get_first_nh_index(route
));
1567 vty_out(vty
, "%c %-32s %-15s type-%d %5lu %s\n",
1568 zebra_route_char(info
->type
), prefix
, id
,
1569 route
->path
.metric_type
,
1570 (u_long
)(route
->path
.metric_type
== 2 ? route
->path
.u
.cost_e2
1571 : route
->path
.cost
),
1575 DEFUN (show_ipv6_ospf6_redistribute
,
1576 show_ipv6_ospf6_redistribute_cmd
,
1577 "show ipv6 ospf6 redistribute",
1581 "redistributing External information\n"
1584 struct ospf6_route
*route
;
1586 OSPF6_CMD_CHECK_RUNNING();
1588 ospf6_redistribute_show_config(vty
);
1590 for (route
= ospf6_route_head(ospf6
->external_table
); route
;
1591 route
= ospf6_route_next(route
))
1592 ospf6_asbr_external_route_show(vty
, route
);
1597 struct ospf6_lsa_handler as_external_handler
= {
1598 .lh_type
= OSPF6_LSTYPE_AS_EXTERNAL
,
1599 .lh_name
= "AS-External",
1600 .lh_short_name
= "ASE",
1601 .lh_show
= ospf6_as_external_lsa_show
,
1602 .lh_get_prefix_str
= ospf6_as_external_lsa_get_prefix_str
,
1606 void ospf6_asbr_init(void)
1608 ospf6_routemap_init();
1610 ospf6_install_lsa_handler(&as_external_handler
);
1612 install_element(VIEW_NODE
, &show_ipv6_ospf6_redistribute_cmd
);
1614 install_element(OSPF6_NODE
, &ospf6_redistribute_cmd
);
1615 install_element(OSPF6_NODE
, &ospf6_redistribute_routemap_cmd
);
1616 install_element(OSPF6_NODE
, &no_ospf6_redistribute_cmd
);
1619 void ospf6_asbr_redistribute_reset(void)
1623 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
1624 if (type
== ZEBRA_ROUTE_OSPF6
)
1626 if (ospf6_zebra_is_redistribute(type
))
1627 ospf6_asbr_redistribute_unset(type
);
1631 void ospf6_asbr_terminate(void)
1633 /* Cleanup route maps */
1634 route_map_add_hook(NULL
);
1635 route_map_delete_hook(NULL
);
1636 route_map_event_hook(NULL
);
1640 DEFUN (debug_ospf6_asbr
,
1641 debug_ospf6_asbr_cmd
,
1645 "Debug OSPFv3 ASBR function\n"
1648 OSPF6_DEBUG_ASBR_ON();
1652 DEFUN (no_debug_ospf6_asbr
,
1653 no_debug_ospf6_asbr_cmd
,
1654 "no debug ospf6 asbr",
1658 "Debug OSPFv3 ASBR function\n"
1661 OSPF6_DEBUG_ASBR_OFF();
1665 int config_write_ospf6_debug_asbr(struct vty
*vty
)
1667 if (IS_OSPF6_DEBUG_ASBR
)
1668 vty_out(vty
, "debug ospf6 asbr\n");
1672 void install_element_ospf6_debug_asbr()
1674 install_element(ENABLE_NODE
, &debug_ospf6_asbr_cmd
);
1675 install_element(ENABLE_NODE
, &no_debug_ospf6_asbr_cmd
);
1676 install_element(CONFIG_NODE
, &debug_ospf6_asbr_cmd
);
1677 install_element(CONFIG_NODE
, &no_debug_ospf6_asbr_cmd
);