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
33 #include "lib/northbound_cli.h"
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 #include "ospf6_spf.h"
43 #include "ospf6_top.h"
45 #include "ospf6_area.h"
46 #include "ospf6_interface.h"
47 #include "ospf6_neighbor.h"
48 #include "ospf6_asbr.h"
49 #include "ospf6_abr.h"
50 #include "ospf6_intra.h"
51 #include "ospf6_flood.h"
53 #include "ospf6_spf.h"
54 #include "ospf6_nssa.h"
57 DEFINE_MTYPE_STATIC(OSPF6D
, OSPF6_EXTERNAL_INFO
, "OSPF6 ext. info");
58 DEFINE_MTYPE_STATIC(OSPF6D
, OSPF6_DIST_ARGS
, "OSPF6 Distribute arguments");
59 DEFINE_MTYPE_STATIC(OSPF6D
, OSPF6_REDISTRIBUTE
, "OSPF6 Redistribute arguments");
61 static void ospf6_asbr_redistribute_set(int type
, vrf_id_t vrf_id
);
62 static void ospf6_asbr_redistribute_unset(struct ospf6
*ospf6
,
63 struct ospf6_redist
*red
, int type
);
65 #ifndef VTYSH_EXTRACT_PL
66 #include "ospf6d/ospf6_asbr_clippy.c"
69 unsigned char conf_debug_ospf6_asbr
= 0;
71 #define ZROUTE_NAME(x) zebra_route_string(x)
73 /* AS External LSA origination */
74 void ospf6_as_external_lsa_originate(struct ospf6_route
*route
,
77 char buffer
[OSPF6_MAX_LSASIZE
];
78 struct ospf6_lsa_header
*lsa_header
;
79 struct ospf6_lsa
*lsa
;
80 struct ospf6_external_info
*info
= route
->route_option
;
82 struct ospf6_as_external_lsa
*as_external_lsa
;
85 if (IS_OSPF6_DEBUG_ASBR
|| IS_OSPF6_DEBUG_ORIGINATE(AS_EXTERNAL
))
86 zlog_debug("Originate AS-External-LSA for %pFX",
90 memset(buffer
, 0, sizeof(buffer
));
91 lsa_header
= (struct ospf6_lsa_header
*)buffer
;
92 as_external_lsa
= (struct ospf6_as_external_lsa
93 *)((caddr_t
)lsa_header
94 + sizeof(struct ospf6_lsa_header
));
95 p
= (caddr_t
)((caddr_t
)as_external_lsa
96 + sizeof(struct ospf6_as_external_lsa
));
98 /* Fill AS-External-LSA */
100 if (route
->path
.metric_type
== 2)
101 SET_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_E
);
103 UNSET_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_E
);
105 /* forwarding address */
106 if (!IN6_IS_ADDR_UNSPECIFIED(&info
->forwarding
))
107 SET_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_F
);
109 UNSET_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_F
);
111 /* external route tag */
113 SET_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_T
);
115 UNSET_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_T
);
118 OSPF6_ASBR_METRIC_SET(as_external_lsa
, route
->path
.cost
);
121 as_external_lsa
->prefix
.prefix_length
= route
->prefix
.prefixlen
;
124 as_external_lsa
->prefix
.prefix_options
= route
->path
.prefix_options
;
126 /* don't use refer LS-type */
127 as_external_lsa
->prefix
.prefix_refer_lstype
= htons(0);
130 memcpy(p
, &route
->prefix
.u
.prefix6
,
131 OSPF6_PREFIX_SPACE(route
->prefix
.prefixlen
));
132 ospf6_prefix_apply_mask(&as_external_lsa
->prefix
);
133 p
+= OSPF6_PREFIX_SPACE(route
->prefix
.prefixlen
);
135 /* Forwarding address */
136 if (CHECK_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_F
)) {
137 memcpy(p
, &info
->forwarding
, sizeof(struct in6_addr
));
138 p
+= sizeof(struct in6_addr
);
141 /* External Route Tag */
142 if (CHECK_FLAG(as_external_lsa
->bits_metric
, OSPF6_ASBR_BIT_T
)) {
143 route_tag_t network_order
= htonl(info
->tag
);
145 memcpy(p
, &network_order
, sizeof(network_order
));
146 p
+= sizeof(network_order
);
149 /* Fill LSA Header */
151 lsa_header
->type
= htons(OSPF6_LSTYPE_AS_EXTERNAL
);
152 lsa_header
->id
= route
->path
.origin
.id
;
153 lsa_header
->adv_router
= ospf6
->router_id
;
155 ospf6_new_ls_seqnum(lsa_header
->type
, lsa_header
->id
,
156 lsa_header
->adv_router
, ospf6
->lsdb
);
157 lsa_header
->length
= htons((caddr_t
)p
- (caddr_t
)lsa_header
);
160 ospf6_lsa_checksum(lsa_header
);
163 lsa
= ospf6_lsa_create(lsa_header
);
166 ospf6_lsa_originate_process(lsa
, ospf6
);
169 int ospf6_orig_as_external_lsa(struct thread
*thread
)
171 struct ospf6_interface
*oi
;
172 struct ospf6_lsa
*lsa
;
173 uint32_t type
, adv_router
;
175 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
176 oi
->thread_as_extern_lsa
= NULL
;
178 if (oi
->state
== OSPF6_INTERFACE_DOWN
)
180 if (IS_AREA_NSSA(oi
->area
))
183 type
= htons(OSPF6_LSTYPE_AS_EXTERNAL
);
184 adv_router
= oi
->area
->ospf6
->router_id
;
185 for (ALL_LSDB_TYPED_ADVRTR(oi
->area
->ospf6
->lsdb
, type
, adv_router
,
187 if (IS_OSPF6_DEBUG_ASBR
)
189 "%s: Send update of AS-External LSA %s seq 0x%x",
191 ntohl(lsa
->header
->seqnum
));
193 ospf6_flood_interface(NULL
, lsa
, oi
);
199 static route_tag_t
ospf6_as_external_lsa_get_tag(struct ospf6_lsa
*lsa
)
201 struct ospf6_as_external_lsa
*external
;
202 ptrdiff_t tag_offset
;
203 route_tag_t network_order
;
208 external
= (struct ospf6_as_external_lsa
*)OSPF6_LSA_HEADER_END(
211 if (!CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_T
))
214 tag_offset
= sizeof(*external
)
215 + OSPF6_PREFIX_SPACE(external
->prefix
.prefix_length
);
216 if (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_F
))
217 tag_offset
+= sizeof(struct in6_addr
);
219 memcpy(&network_order
, (caddr_t
)external
+ tag_offset
,
220 sizeof(network_order
));
221 return ntohl(network_order
);
224 void ospf6_asbr_update_route_ecmp_path(struct ospf6_route
*old
,
225 struct ospf6_route
*route
,
228 struct ospf6_route
*old_route
, *next_route
;
229 struct ospf6_path
*ecmp_path
, *o_path
= NULL
;
230 struct listnode
*anode
, *anext
;
231 struct listnode
*nnode
, *rnode
, *rnext
;
232 struct ospf6_nexthop
*nh
, *rnh
;
233 bool route_found
= false;
235 /* check for old entry match with new route origin,
238 for (old_route
= old
; old_route
; old_route
= next_route
) {
239 bool route_updated
= false;
241 next_route
= old_route
->next
;
243 if (!ospf6_route_is_same(old_route
, route
)
244 || (old_route
->path
.type
!= route
->path
.type
))
247 /* Current and New route has same origin,
250 for (ALL_LIST_ELEMENTS(old_route
->paths
, anode
, anext
,
252 /* Check old route path and route has same
255 if (o_path
->area_id
!= route
->path
.area_id
256 || (memcmp(&(o_path
)->origin
, &(route
)->path
.origin
,
257 sizeof(struct ospf6_ls_origin
))
261 /* Cost is not same then delete current path */
262 if ((o_path
->cost
== route
->path
.cost
)
263 && (o_path
->u
.cost_e2
== route
->path
.u
.cost_e2
))
266 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
)) {
268 "%s: route %pFX cost old %u new %u is not same, replace route",
269 __func__
, &old_route
->prefix
, o_path
->cost
,
273 /* Remove selected current rout path's nh from
276 for (ALL_LIST_ELEMENTS_RO(o_path
->nh_list
, nnode
, nh
)) {
277 for (ALL_LIST_ELEMENTS(old_route
->nh_list
,
278 rnode
, rnext
, rnh
)) {
279 if (!ospf6_nexthop_is_same(rnh
, nh
))
281 listnode_delete(old_route
->nh_list
,
283 ospf6_nexthop_delete(rnh
);
287 listnode_delete(old_route
->paths
, o_path
);
288 ospf6_path_free(o_path
);
289 route_updated
= true;
291 /* Current route's path (adv_router info) is similar
292 * to route being added.
293 * Replace current route's path with paths list head.
294 * Update FIB with effective NHs.
296 if (listcount(old_route
->paths
)) {
297 for (ALL_LIST_ELEMENTS(old_route
->paths
,
298 anode
, anext
, o_path
)) {
299 ospf6_merge_nexthops(
303 /* Update RIB/FIB with effective
306 if (ospf6
->route_table
->hook_add
)
307 (*ospf6
->route_table
->hook_add
)(
310 if (old_route
->path
.origin
.id
311 == route
->path
.origin
.id
312 && old_route
->path
.origin
.adv_router
313 == route
->path
.origin
315 struct ospf6_path
*h_path
;
317 h_path
= (struct ospf6_path
*)
318 listgetdata(listhead(
320 old_route
->path
.origin
.type
=
322 old_route
->path
.origin
.id
=
324 old_route
->path
.origin
.adv_router
=
325 h_path
->origin
.adv_router
;
328 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
)) {
330 "%s: route %pFX old cost %u new cost %u, delete old entry.",
331 __func__
, &old_route
->prefix
,
332 old_route
->path
.cost
,
335 if (old
== old_route
)
337 ospf6_route_remove(old_route
,
346 for (old_route
= old
; old_route
; old_route
= old_route
->next
) {
348 /* Current and New Route prefix or route type
349 * is not same skip this current node.
351 if (!ospf6_route_is_same(old_route
, route
)
352 || (old_route
->path
.type
!= route
->path
.type
))
355 /* Old Route and New Route have Equal Cost, Merge NHs */
356 if ((old_route
->path
.cost
== route
->path
.cost
)
357 && (old_route
->path
.u
.cost_e2
== route
->path
.u
.cost_e2
)) {
359 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
)) {
361 "%s: old route %pFX path cost %u e2 %u",
362 __func__
, &old_route
->prefix
,
363 old_route
->path
.cost
,
364 old_route
->path
.u
.cost_e2
);
367 /* check if this path exists already in
368 * route->paths list, if so, replace nh_list
371 for (ALL_LIST_ELEMENTS_RO(old_route
->paths
, anode
,
373 if (o_path
->area_id
== route
->path
.area_id
374 && (memcmp(&(o_path
)->origin
,
375 &(route
)->path
.origin
,
376 sizeof(struct ospf6_ls_origin
))
380 /* If path is not found in old_route paths's list,
381 * add a new path to route paths list and merge
382 * nexthops in route->path->nh_list.
383 * Otherwise replace existing path's nh_list.
385 if (o_path
== NULL
) {
386 ecmp_path
= ospf6_path_dup(&route
->path
);
388 /* Add a nh_list to new ecmp path */
389 ospf6_copy_nexthops(ecmp_path
->nh_list
,
392 /* Add the new path to route's path list */
393 listnode_add_sort(old_route
->paths
, ecmp_path
);
395 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
)) {
397 "%s: route %pFX another path added with nh %u, effective paths %u nh %u",
398 __func__
, &route
->prefix
,
399 listcount(ecmp_path
->nh_list
),
400 old_route
->paths
? listcount(
403 listcount(old_route
->nh_list
));
406 list_delete_all_node(o_path
->nh_list
);
407 ospf6_copy_nexthops(o_path
->nh_list
,
411 /* Reset nexthop lists, rebuild from brouter table
412 * for each adv. router.
414 list_delete_all_node(old_route
->nh_list
);
416 for (ALL_LIST_ELEMENTS_RO(old_route
->paths
, anode
,
418 struct ospf6_route
*asbr_entry
;
420 asbr_entry
= ospf6_route_lookup(
422 ospf6
->brouter_table
);
423 if (asbr_entry
== NULL
) {
424 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
426 "%s: ls_prfix %pFX asbr_entry not found.",
431 ospf6_route_merge_nexthops(old_route
,
435 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
437 "%s: route %pFX with effective paths %u nh %u",
438 __func__
, &route
->prefix
,
440 ? listcount(old_route
->paths
)
443 ? listcount(old_route
->nh_list
)
447 if (ospf6
->route_table
->hook_add
)
448 (*ospf6
->route_table
->hook_add
)(old_route
);
450 /* Delete the new route its info added to existing
453 ospf6_route_delete(route
);
460 /* Add new route to existing node in ospf6 route table. */
461 ospf6_route_add(route
, ospf6
->route_table
);
465 /* Check if the forwarding address is local address */
466 static int ospf6_ase_forward_address_check(struct ospf6
*ospf6
,
467 struct in6_addr
*fwd_addr
)
469 struct listnode
*anode
, *node
, *cnode
;
470 struct ospf6_interface
*oi
;
471 struct ospf6_area
*oa
;
472 struct interface
*ifp
;
475 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, anode
, oa
)) {
476 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, node
, oi
)) {
477 if (!if_is_operative(oi
->interface
)
478 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
482 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, c
)) {
483 if (IPV6_ADDR_SAME(&c
->address
->u
.prefix6
,
493 void ospf6_asbr_lsa_add(struct ospf6_lsa
*lsa
)
495 struct ospf6_as_external_lsa
*external
;
496 struct prefix asbr_id
;
497 struct ospf6_route
*asbr_entry
, *route
, *old
= NULL
;
498 struct ospf6_path
*path
;
501 struct ospf6_area
*oa
= NULL
;
502 struct prefix fwd_addr
;
505 type
= ntohs(lsa
->header
->type
);
506 oa
= lsa
->lsdb
->data
;
508 external
= (struct ospf6_as_external_lsa
*)OSPF6_LSA_HEADER_END(
511 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
512 zlog_debug("Calculate AS-External route for %s", lsa
->name
);
514 ospf6
= ospf6_get_by_lsdb(lsa
);
516 if (lsa
->header
->adv_router
== ospf6
->router_id
) {
517 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
518 zlog_debug("Ignore self-originated AS-External-LSA");
522 if (OSPF6_ASBR_METRIC(external
) == OSPF_LS_INFINITY
) {
523 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
524 zlog_debug("Ignore LSA with LSInfinity Metric");
528 if (CHECK_FLAG(external
->prefix
.prefix_options
,
529 OSPF6_PREFIX_OPTION_NU
)) {
530 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
531 zlog_debug("Ignore LSA with NU bit set Metric");
535 ospf6_linkstate_prefix(lsa
->header
->adv_router
, htonl(0), &asbr_id
);
536 asbr_entry
= ospf6_route_lookup(&asbr_id
, ospf6
->brouter_table
);
537 if (asbr_entry
== NULL
) {
538 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
539 zlog_debug("ASBR entry not found: %pFX", &asbr_id
);
542 /* The router advertising external LSA can be ASBR or ABR */
543 if (!CHECK_FLAG(asbr_entry
->path
.router_bits
,
544 OSPF6_ROUTER_BIT_E
)) {
545 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
547 "External bit reset ASBR route entry : %pFX",
553 /* Check the forwarding address */
554 if (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_F
)) {
555 offset
= sizeof(*external
)
556 + OSPF6_PREFIX_SPACE(external
->prefix
.prefix_length
);
557 memset(&fwd_addr
, 0, sizeof(struct prefix
));
558 fwd_addr
.family
= AF_INET6
;
559 fwd_addr
.prefixlen
= IPV6_MAX_PREFIXLEN
;
560 memcpy(&fwd_addr
.u
.prefix6
, (caddr_t
)external
+ offset
,
561 sizeof(struct in6_addr
));
563 if (!IN6_IS_ADDR_UNSPECIFIED(&fwd_addr
.u
.prefix6
)) {
564 if (!ospf6_ase_forward_address_check(
565 ospf6
, &fwd_addr
.u
.prefix6
)) {
566 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
568 "Fwd address %pFX is local address",
573 /* Find the forwarding entry */
574 asbr_entry
= ospf6_route_lookup_bestmatch(
575 &fwd_addr
, ospf6
->route_table
);
576 if (asbr_entry
== NULL
) {
577 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
579 "Fwd address not found: %pFX",
586 route
= ospf6_route_create();
587 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
588 route
->prefix
.family
= AF_INET6
;
589 route
->prefix
.prefixlen
= external
->prefix
.prefix_length
;
590 ospf6_prefix_in6_addr(&route
->prefix
.u
.prefix6
, external
,
593 route
->path
.area_id
= asbr_entry
->path
.area_id
;
594 route
->path
.origin
.type
= lsa
->header
->type
;
595 route
->path
.origin
.id
= lsa
->header
->id
;
596 route
->path
.origin
.adv_router
= lsa
->header
->adv_router
;
597 route
->path
.prefix_options
= external
->prefix
.prefix_options
;
598 memcpy(&route
->path
.ls_prefix
, &asbr_id
, sizeof(struct prefix
));
600 if (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_E
)) {
601 route
->path
.type
= OSPF6_PATH_TYPE_EXTERNAL2
;
602 route
->path
.metric_type
= 2;
603 route
->path
.cost
= asbr_entry
->path
.cost
;
604 route
->path
.u
.cost_e2
= OSPF6_ASBR_METRIC(external
);
606 route
->path
.type
= OSPF6_PATH_TYPE_EXTERNAL1
;
607 route
->path
.metric_type
= 1;
609 asbr_entry
->path
.cost
+ OSPF6_ASBR_METRIC(external
);
610 route
->path
.u
.cost_e2
= 0;
613 route
->path
.tag
= ospf6_as_external_lsa_get_tag(lsa
);
615 ospf6_route_copy_nexthops(route
, asbr_entry
);
617 path
= ospf6_path_dup(&route
->path
);
618 ospf6_copy_nexthops(path
->nh_list
, asbr_entry
->nh_list
);
619 listnode_add_sort(route
->paths
, path
);
622 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
624 "%s: %s %u route add %pFX cost %u(%u) nh %u", __func__
,
625 (type
== OSPF6_LSTYPE_AS_EXTERNAL
) ? "AS-External"
627 (route
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL1
) ? 1 : 2,
628 &route
->prefix
, route
->path
.cost
, route
->path
.u
.cost_e2
,
629 listcount(route
->nh_list
));
631 if (type
== OSPF6_LSTYPE_AS_EXTERNAL
)
632 old
= ospf6_route_lookup(&route
->prefix
, ospf6
->route_table
);
633 else if (type
== OSPF6_LSTYPE_TYPE_7
)
634 old
= ospf6_route_lookup(&route
->prefix
, oa
->route_table
);
636 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
637 zlog_debug("%s: Adding new route", __func__
);
638 /* Add the new route to ospf6 instance route table. */
639 if (type
== OSPF6_LSTYPE_AS_EXTERNAL
)
640 ospf6_route_add(route
, ospf6
->route_table
);
641 /* Add the route to the area route table */
642 else if (type
== OSPF6_LSTYPE_TYPE_7
) {
643 ospf6_route_add(route
, oa
->route_table
);
647 * ECMP: Keep new equal preference path in current
648 * route's path list, update zebra with new effective
649 * list along with addition of ECMP path.
651 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
))
652 zlog_debug("%s : old route %pFX cost %u(%u) nh %u",
653 __func__
, &route
->prefix
, route
->path
.cost
,
654 route
->path
.u
.cost_e2
,
655 listcount(route
->nh_list
));
656 ospf6_asbr_update_route_ecmp_path(old
, route
, ospf6
);
660 void ospf6_asbr_lsa_remove(struct ospf6_lsa
*lsa
,
661 struct ospf6_route
*asbr_entry
)
663 struct ospf6_as_external_lsa
*external
;
664 struct prefix prefix
;
665 struct ospf6_route
*route
, *nroute
, *route_to_del
;
666 struct ospf6_area
*oa
= NULL
;
671 external
= (struct ospf6_as_external_lsa
*)OSPF6_LSA_HEADER_END(
674 if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL
) || (IS_OSPF6_DEBUG_NSSA
))
677 ospf6
= ospf6_get_by_lsdb(lsa
);
678 type
= ntohs(lsa
->header
->type
);
680 if (type
== OSPF6_LSTYPE_TYPE_7
) {
682 zlog_debug("%s: Withdraw Type 7 route for %s",
683 __func__
, lsa
->name
);
684 oa
= lsa
->lsdb
->data
;
687 zlog_debug("%s: Withdraw AS-External route for %s",
688 __func__
, lsa
->name
);
690 if (ospf6_check_and_set_router_abr(ospf6
))
691 oa
= ospf6
->backbone
;
693 oa
= listgetdata(listhead(ospf6
->area_list
));
698 zlog_debug("%s: Invalid area", __func__
);
702 if (lsa
->header
->adv_router
== oa
->ospf6
->router_id
) {
704 zlog_debug("Ignore self-originated AS-External-LSA");
708 route_to_del
= ospf6_route_create();
709 route_to_del
->type
= OSPF6_DEST_TYPE_NETWORK
;
710 route_to_del
->prefix
.family
= AF_INET6
;
711 route_to_del
->prefix
.prefixlen
= external
->prefix
.prefix_length
;
712 ospf6_prefix_in6_addr(&route_to_del
->prefix
.u
.prefix6
, external
,
715 route_to_del
->path
.origin
.type
= lsa
->header
->type
;
716 route_to_del
->path
.origin
.id
= lsa
->header
->id
;
717 route_to_del
->path
.origin
.adv_router
= lsa
->header
->adv_router
;
720 route_to_del
->path
.area_id
= asbr_entry
->path
.area_id
;
721 if (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_E
)) {
722 route_to_del
->path
.type
= OSPF6_PATH_TYPE_EXTERNAL2
;
723 route_to_del
->path
.metric_type
= 2;
724 route_to_del
->path
.cost
= asbr_entry
->path
.cost
;
725 route_to_del
->path
.u
.cost_e2
=
726 OSPF6_ASBR_METRIC(external
);
728 route_to_del
->path
.type
= OSPF6_PATH_TYPE_EXTERNAL1
;
729 route_to_del
->path
.metric_type
= 1;
730 route_to_del
->path
.cost
= asbr_entry
->path
.cost
731 + OSPF6_ASBR_METRIC(external
);
732 route_to_del
->path
.u
.cost_e2
= 0;
736 memset(&prefix
, 0, sizeof(struct prefix
));
737 prefix
.family
= AF_INET6
;
738 prefix
.prefixlen
= external
->prefix
.prefix_length
;
739 ospf6_prefix_in6_addr(&prefix
.u
.prefix6
, external
, &external
->prefix
);
741 if (type
== OSPF6_LSTYPE_TYPE_7
)
742 route
= ospf6_route_lookup(&prefix
, oa
->route_table
);
744 route
= ospf6_route_lookup(&prefix
, oa
->ospf6
->route_table
);
748 zlog_debug("AS-External route %pFX not found", &prefix
);
749 ospf6_route_delete(route_to_del
);
755 "%s: Current route %pFX cost %u e2 %u, route to del cost %u e2 %u",
756 __func__
, &prefix
, route
->path
.cost
, route
->path
.u
.cost_e2
,
757 route_to_del
->path
.cost
, route_to_del
->path
.u
.cost_e2
);
759 for (ospf6_route_lock(route
);
760 route
&& ospf6_route_is_prefix(&prefix
, route
); route
= nroute
) {
761 nroute
= ospf6_route_next(route
);
763 if (route
->type
!= OSPF6_DEST_TYPE_NETWORK
)
766 /* Route has multiple ECMP paths, remove matching
767 * path. Update current route's effective nh list
768 * after removal of one of the path.
770 if (listcount(route
->paths
) > 1) {
771 struct listnode
*anode
, *anext
;
772 struct listnode
*nnode
, *rnode
, *rnext
;
773 struct ospf6_nexthop
*nh
, *rnh
;
774 struct ospf6_path
*o_path
;
775 bool nh_updated
= false;
777 /* Iterate all paths of route to find maching with LSA
778 * remove from route path list. If route->path is same,
779 * replace from paths list.
781 for (ALL_LIST_ELEMENTS(route
->paths
, anode
, anext
,
783 if ((o_path
->origin
.type
!= lsa
->header
->type
)
784 || (o_path
->origin
.adv_router
785 != lsa
->header
->adv_router
)
786 || (o_path
->origin
.id
!= lsa
->header
->id
))
789 /* Compare LSA cost with current
793 && (o_path
->cost
!= route_to_del
->path
.cost
795 != route_to_del
->path
.u
797 if (IS_OSPF6_DEBUG_EXAMIN(
800 "%s: route %pFX to delete is not same, cost %u del cost %u. skip",
811 "%s: route %pFX path found with cost %u nh %u to remove.",
812 __func__
, &prefix
, route
->path
.cost
,
813 listcount(o_path
->nh_list
));
816 /* Remove found path's nh_list from
817 * the route's nh_list.
819 for (ALL_LIST_ELEMENTS_RO(o_path
->nh_list
,
821 for (ALL_LIST_ELEMENTS(route
->nh_list
,
824 if (!ospf6_nexthop_is_same(rnh
,
827 listnode_delete(route
->nh_list
,
829 ospf6_nexthop_delete(rnh
);
832 /* Delete the path from route's path list */
833 listnode_delete(route
->paths
, o_path
);
834 ospf6_path_free(o_path
);
839 /* Iterate all paths and merge nexthop,
840 * unlesss any of the nexthop similar to
841 * ones deleted as part of path deletion.
844 for (ALL_LIST_ELEMENTS(route
->paths
, anode
,
846 ospf6_merge_nexthops(route
->nh_list
,
852 "%s: AS-External %u route %pFX update paths %u nh %u",
855 == OSPF6_PATH_TYPE_EXTERNAL1
)
858 &route
->prefix
, listcount(route
->paths
),
859 route
->nh_list
? listcount(
864 if (listcount(route
->paths
)) {
865 /* Update RIB/FIB with effective
868 if (oa
->ospf6
->route_table
->hook_add
)
869 (*oa
->ospf6
->route_table
872 /* route's primary path is similar
873 * to LSA, replace route's primary
874 * path with route's paths list head.
876 if ((route
->path
.origin
.id
==
878 (route
->path
.origin
.adv_router
879 == lsa
->header
->adv_router
)) {
880 struct ospf6_path
*h_path
;
882 h_path
= (struct ospf6_path
*)
884 listhead(route
->paths
));
885 route
->path
.origin
.type
=
887 route
->path
.origin
.id
=
889 route
->path
.origin
.adv_router
=
890 h_path
->origin
.adv_router
;
893 if (type
== OSPF6_LSTYPE_TYPE_7
)
895 route
, oa
->route_table
);
899 oa
->ospf6
->route_table
);
905 /* Compare LSA origin and cost with current route info.
906 * if any check fails skip del this route node.
909 && (!ospf6_route_is_same_origin(route
, route_to_del
)
910 || (route
->path
.type
!= route_to_del
->path
.type
)
911 || (route
->path
.cost
!= route_to_del
->path
.cost
)
912 || (route
->path
.u
.cost_e2
913 != route_to_del
->path
.u
.cost_e2
))) {
916 "%s: route %pFX to delete is not same, cost %u del cost %u. skip",
917 __func__
, &prefix
, route
->path
.cost
,
918 route_to_del
->path
.cost
);
923 if ((route
->path
.origin
.type
!= lsa
->header
->type
)
924 || (route
->path
.origin
.adv_router
925 != lsa
->header
->adv_router
)
926 || (route
->path
.origin
.id
!= lsa
->header
->id
))
931 "%s: AS-External %u route remove %pFX cost %u(%u) nh %u",
933 route
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL1
936 &route
->prefix
, route
->path
.cost
, route
->path
.u
.cost_e2
,
937 listcount(route
->nh_list
));
939 if (type
== OSPF6_LSTYPE_TYPE_7
)
940 ospf6_route_remove(route
, oa
->route_table
);
942 ospf6_route_remove(route
, oa
->ospf6
->route_table
);
945 ospf6_route_unlock(route
);
947 ospf6_route_delete(route_to_del
);
950 void ospf6_asbr_lsentry_add(struct ospf6_route
*asbr_entry
, struct ospf6
*ospf6
)
952 struct ospf6_lsa
*lsa
;
956 if (!CHECK_FLAG(asbr_entry
->flag
, OSPF6_ROUTE_BEST
)) {
958 inet_ntop(AF_INET
, &ADV_ROUTER_IN_PREFIX(&asbr_entry
->prefix
),
960 zlog_info("ignore non-best path: lsentry %s add", buf
);
964 type
= htons(OSPF6_LSTYPE_AS_EXTERNAL
);
965 router
= ospf6_linkstate_prefix_adv_router(&asbr_entry
->prefix
);
966 for (ALL_LSDB_TYPED_ADVRTR(ospf6
->lsdb
, type
, router
, lsa
)) {
967 if (!OSPF6_LSA_IS_MAXAGE(lsa
))
968 ospf6_asbr_lsa_add(lsa
);
972 void ospf6_asbr_lsentry_remove(struct ospf6_route
*asbr_entry
,
975 struct ospf6_lsa
*lsa
;
979 type
= htons(OSPF6_LSTYPE_AS_EXTERNAL
);
980 router
= ospf6_linkstate_prefix_adv_router(&asbr_entry
->prefix
);
981 for (ALL_LSDB_TYPED_ADVRTR(ospf6
->lsdb
, type
, router
, lsa
))
982 ospf6_asbr_lsa_remove(lsa
, asbr_entry
);
986 /* redistribute function */
987 static void ospf6_asbr_routemap_set(struct ospf6_redist
*red
,
990 if (ROUTEMAP_NAME(red
)) {
991 route_map_counter_decrement(ROUTEMAP(red
));
992 free(ROUTEMAP_NAME(red
));
995 ROUTEMAP_NAME(red
) = strdup(mapname
);
996 ROUTEMAP(red
) = route_map_lookup_by_name(mapname
);
997 route_map_counter_increment(ROUTEMAP(red
));
1000 static void ospf6_asbr_routemap_unset(struct ospf6_redist
*red
)
1002 if (ROUTEMAP_NAME(red
))
1003 free(ROUTEMAP_NAME(red
));
1005 route_map_counter_decrement(ROUTEMAP(red
));
1007 ROUTEMAP_NAME(red
) = NULL
;
1008 ROUTEMAP(red
) = NULL
;
1011 static int ospf6_asbr_routemap_update_timer(struct thread
*thread
)
1015 struct ospf6
*ospf6
;
1016 struct ospf6_redist
*red
;
1018 arg
= THREAD_ARG(thread
);
1019 ospf6
= (struct ospf6
*)arg
[0];
1020 arg_type
= (int)(intptr_t)arg
[1];
1022 ospf6
->t_distribute_update
= NULL
;
1024 red
= ospf6_redist_lookup(ospf6
, arg_type
, 0);
1026 if (red
&& ROUTEMAP_NAME(red
))
1027 ROUTEMAP(red
) = route_map_lookup_by_name(ROUTEMAP_NAME(red
));
1028 if (red
&& ROUTEMAP(red
)) {
1029 if (IS_OSPF6_DEBUG_ASBR
)
1030 zlog_debug("%s: route-map %s update, reset redist %s",
1031 __func__
, ROUTEMAP_NAME(red
),
1032 ZROUTE_NAME(arg_type
));
1034 ospf6_zebra_no_redistribute(arg_type
, ospf6
->vrf_id
);
1035 ospf6_zebra_redistribute(arg_type
, ospf6
->vrf_id
);
1038 XFREE(MTYPE_OSPF6_DIST_ARGS
, arg
);
1042 void ospf6_asbr_distribute_list_update(int type
, struct ospf6
*ospf6
)
1046 if (ospf6
->t_distribute_update
)
1049 args
= XCALLOC(MTYPE_OSPF6_DIST_ARGS
, sizeof(void *) * 2);
1052 args
[1] = (void *)((ptrdiff_t)type
);
1054 if (IS_OSPF6_DEBUG_ASBR
)
1055 zlog_debug("%s: trigger redistribute %s reset thread", __func__
,
1058 ospf6
->t_distribute_update
= NULL
;
1059 thread_add_timer_msec(master
, ospf6_asbr_routemap_update_timer
, args
,
1060 OSPF_MIN_LS_INTERVAL
,
1061 &ospf6
->t_distribute_update
);
1064 void ospf6_asbr_routemap_update(const char *mapname
)
1067 struct listnode
*node
, *nnode
;
1068 struct ospf6
*ospf6
= NULL
;
1069 struct ospf6_redist
*red
;
1074 for (ALL_LIST_ELEMENTS(om6
->ospf6
, node
, nnode
, ospf6
)) {
1075 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
1076 red
= ospf6_redist_lookup(ospf6
, type
, 0);
1077 if (!red
|| (ROUTEMAP_NAME(red
) == NULL
))
1080 route_map_lookup_by_name(ROUTEMAP_NAME(red
));
1083 || strcmp(ROUTEMAP_NAME(red
), mapname
))
1085 if (ROUTEMAP(red
)) {
1086 if (IS_OSPF6_DEBUG_ASBR
)
1088 "%s: route-map %s update, reset redist %s",
1094 route_map_counter_increment(ROUTEMAP(red
));
1096 ospf6_asbr_distribute_list_update(type
, ospf6
);
1099 * if the mapname matches a
1100 * route-map on ospf6 but the
1101 * map doesn't exist, it is
1102 * being deleted. flush and then
1105 if (IS_OSPF6_DEBUG_ASBR
)
1107 "%s: route-map %s deleted, reset redist %s",
1112 ospf6_asbr_redistribute_unset(ospf6
, red
, type
);
1113 ospf6_asbr_routemap_set(red
, mapname
);
1114 ospf6_asbr_redistribute_set(
1115 type
, ospf6
->vrf_id
);
1121 static void ospf6_asbr_routemap_event(const char *name
)
1124 struct listnode
*node
, *nnode
;
1125 struct ospf6
*ospf6
;
1126 struct ospf6_redist
*red
;
1130 for (ALL_LIST_ELEMENTS(om6
->ospf6
, node
, nnode
, ospf6
)) {
1131 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
1132 red
= ospf6_redist_lookup(ospf6
, type
, 0);
1133 if (red
&& ROUTEMAP_NAME(red
)
1134 && (strcmp(ROUTEMAP_NAME(red
), name
) == 0))
1135 ospf6_asbr_distribute_list_update(type
, ospf6
);
1140 int ospf6_asbr_is_asbr(struct ospf6
*o
)
1142 return (o
->external_table
->count
|| IS_OSPF6_ASBR(o
));
1145 struct ospf6_redist
*ospf6_redist_lookup(struct ospf6
*ospf6
, int type
,
1146 unsigned short instance
)
1148 struct list
*red_list
;
1149 struct listnode
*node
;
1150 struct ospf6_redist
*red
;
1152 red_list
= ospf6
->redist
[type
];
1156 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
))
1157 if (red
->instance
== instance
)
1163 static struct ospf6_redist
*ospf6_redist_add(struct ospf6
*ospf6
, int type
,
1166 struct ospf6_redist
*red
;
1168 red
= ospf6_redist_lookup(ospf6
, type
, instance
);
1172 if (!ospf6
->redist
[type
])
1173 ospf6
->redist
[type
] = list_new();
1175 red
= XCALLOC(MTYPE_OSPF6_REDISTRIBUTE
, sizeof(struct ospf6_redist
));
1176 red
->instance
= instance
;
1177 ROUTEMAP_NAME(red
) = NULL
;
1178 ROUTEMAP(red
) = NULL
;
1180 listnode_add(ospf6
->redist
[type
], red
);
1181 ospf6
->redistribute
++;
1186 static void ospf6_redist_del(struct ospf6
*ospf6
, struct ospf6_redist
*red
,
1190 listnode_delete(ospf6
->redist
[type
], red
);
1191 if (!ospf6
->redist
[type
]->count
) {
1192 list_delete(&ospf6
->redist
[type
]);
1194 XFREE(MTYPE_OSPF6_REDISTRIBUTE
, red
);
1195 ospf6
->redistribute
--;
1199 /*Set the status of the ospf instance to ASBR based on the status parameter,
1200 * rechedule SPF calculation, originate router LSA*/
1201 void ospf6_asbr_status_update(struct ospf6
*ospf6
, int status
)
1203 struct listnode
*lnode
, *lnnode
;
1204 struct ospf6_area
*oa
;
1206 zlog_info("ASBR[%s:Status:%d]: Update", ospf6
->name
, status
);
1209 if (IS_OSPF6_ASBR(ospf6
)) {
1210 zlog_info("ASBR[%s:Status:%d]: Already ASBR",
1211 ospf6
->name
, status
);
1214 SET_FLAG(ospf6
->flag
, OSPF6_FLAG_ASBR
);
1216 if (!IS_OSPF6_ASBR(ospf6
)) {
1217 zlog_info("ASBR[%s:Status:%d]: Already non ASBR",
1218 ospf6
->name
, status
);
1221 UNSET_FLAG(ospf6
->flag
, OSPF6_FLAG_ASBR
);
1224 /* Transition from/to status ASBR, schedule timer. */
1225 ospf6_spf_schedule(ospf6
, OSPF6_SPF_FLAGS_ASBR_STATUS_CHANGE
);
1227 /* Reoriginate router LSA for all areas */
1228 for (ALL_LIST_ELEMENTS(ospf6
->area_list
, lnode
, lnnode
, oa
))
1229 OSPF6_ROUTER_LSA_SCHEDULE(oa
);
1232 static void ospf6_asbr_redistribute_set(int type
, vrf_id_t vrf_id
)
1234 struct ospf6
*ospf6
= NULL
;
1235 ospf6_zebra_redistribute(type
, vrf_id
);
1237 ospf6
= ospf6_lookup_by_vrf_id(vrf_id
);
1242 ospf6_asbr_status_update(ospf6
, ++ospf6
->redist_count
);
1245 static void ospf6_asbr_redistribute_unset(struct ospf6
*ospf6
,
1246 struct ospf6_redist
*red
, int type
)
1248 struct ospf6_route
*route
;
1249 struct ospf6_external_info
*info
;
1251 ospf6_zebra_no_redistribute(type
, ospf6
->vrf_id
);
1253 for (route
= ospf6_route_head(ospf6
->external_table
); route
;
1254 route
= ospf6_route_next(route
)) {
1255 info
= route
->route_option
;
1256 if (info
->type
!= type
)
1259 ospf6_asbr_redistribute_remove(info
->type
, 0, &route
->prefix
,
1263 ospf6_asbr_routemap_unset(red
);
1264 zlog_debug("%s: redist_count %d", __func__
, ospf6
->redist_count
);
1265 ospf6_asbr_status_update(ospf6
, --ospf6
->redist_count
);
1268 /* When an area is unstubified, flood all the external LSAs in the area */
1269 void ospf6_asbr_send_externals_to_area(struct ospf6_area
*oa
)
1271 struct ospf6_lsa
*lsa
, *lsanext
;
1273 for (ALL_LSDB(oa
->ospf6
->lsdb
, lsa
, lsanext
)) {
1274 if (ntohs(lsa
->header
->type
) == OSPF6_LSTYPE_AS_EXTERNAL
) {
1275 if (IS_OSPF6_DEBUG_ASBR
)
1276 zlog_debug("%s: Flooding AS-External LSA %s",
1277 __func__
, lsa
->name
);
1279 ospf6_flood_area(NULL
, lsa
, oa
);
1284 /* When an area is stubified, remove all the external LSAs in the area */
1285 void ospf6_asbr_remove_externals_from_area(struct ospf6_area
*oa
)
1287 struct ospf6_lsa
*lsa
, *lsanext
;
1288 struct listnode
*node
, *nnode
;
1289 struct ospf6_area
*area
;
1290 struct ospf6
*ospf6
= oa
->ospf6
;
1291 const struct route_node
*iterend
;
1293 /* skip if router is in other non-stub areas */
1294 for (ALL_LIST_ELEMENTS(ospf6
->area_list
, node
, nnode
, area
))
1295 if (!IS_AREA_STUB(area
))
1298 /* if router is only in a stub area then purge AS-External LSAs */
1299 iterend
= ospf6_lsdb_head(ospf6
->lsdb
, 0, 0, 0, &lsa
);
1300 while (lsa
!= NULL
) {
1301 assert(lsa
->lock
> 1);
1302 lsanext
= ospf6_lsdb_next(iterend
, lsa
);
1303 if (ntohs(lsa
->header
->type
) == OSPF6_LSTYPE_AS_EXTERNAL
)
1304 ospf6_lsdb_remove(lsa
, ospf6
->lsdb
);
1309 void ospf6_asbr_redistribute_add(int type
, ifindex_t ifindex
,
1310 struct prefix
*prefix
,
1311 unsigned int nexthop_num
,
1312 struct in6_addr
*nexthop
, route_tag_t tag
,
1313 struct ospf6
*ospf6
)
1315 route_map_result_t ret
;
1316 struct listnode
*lnode
;
1317 struct ospf6_area
*oa
;
1318 struct ospf6_route troute
;
1319 struct ospf6_external_info tinfo
;
1320 struct ospf6_route
*route
, *match
;
1321 struct ospf6_external_info
*info
;
1322 struct prefix prefix_id
;
1323 struct route_node
*node
;
1325 struct ospf6_redist
*red
;
1327 red
= ospf6_redist_lookup(ospf6
, type
, 0);
1332 if ((type
!= DEFAULT_ROUTE
)
1333 && !ospf6_zebra_is_redistribute(type
, ospf6
->vrf_id
))
1336 memset(&troute
, 0, sizeof(troute
));
1337 memset(&tinfo
, 0, sizeof(tinfo
));
1339 if (IS_OSPF6_DEBUG_ASBR
)
1340 zlog_debug("Redistribute %pFX (%s)", prefix
, ZROUTE_NAME(type
));
1342 /* if route-map was specified but not found, do not advertise */
1343 if (ROUTEMAP_NAME(red
)) {
1344 if (ROUTEMAP(red
) == NULL
)
1345 ospf6_asbr_routemap_update(NULL
);
1346 if (ROUTEMAP(red
) == NULL
) {
1348 "route-map \"%s\" not found, suppress redistributing",
1349 ROUTEMAP_NAME(red
));
1354 /* apply route-map */
1355 if (ROUTEMAP(red
)) {
1356 troute
.route_option
= &tinfo
;
1357 tinfo
.ifindex
= ifindex
;
1360 ret
= route_map_apply(ROUTEMAP(red
), prefix
, &troute
);
1361 if (ret
== RMAP_DENYMATCH
) {
1362 if (IS_OSPF6_DEBUG_ASBR
)
1363 zlog_debug("Denied by route-map \"%s\"",
1364 ROUTEMAP_NAME(red
));
1365 ospf6_asbr_redistribute_remove(type
, ifindex
, prefix
,
1371 match
= ospf6_route_lookup(prefix
, ospf6
->external_table
);
1373 info
= match
->route_option
;
1374 /* copy result of route-map */
1375 if (ROUTEMAP(red
)) {
1376 if (troute
.path
.metric_type
)
1377 match
->path
.metric_type
=
1378 troute
.path
.metric_type
;
1379 if (troute
.path
.cost
)
1380 match
->path
.cost
= troute
.path
.cost
;
1381 if (!IN6_IS_ADDR_UNSPECIFIED(&tinfo
.forwarding
))
1382 memcpy(&info
->forwarding
, &tinfo
.forwarding
,
1383 sizeof(struct in6_addr
));
1384 info
->tag
= tinfo
.tag
;
1386 /* If there is no route-map, simply update the tag and
1389 match
->path
.metric_type
= metric_type(ospf6
, type
, 0);
1390 match
->path
.cost
= metric_value(ospf6
, type
, 0);
1396 if (nexthop_num
&& nexthop
)
1397 ospf6_route_add_nexthop(match
, ifindex
, nexthop
);
1399 ospf6_route_add_nexthop(match
, ifindex
, NULL
);
1401 /* create/update binding in external_id_table */
1402 prefix_id
.family
= AF_INET
;
1403 prefix_id
.prefixlen
= 32;
1404 prefix_id
.u
.prefix4
.s_addr
= htonl(info
->id
);
1405 node
= route_node_get(ospf6
->external_id_table
, &prefix_id
);
1408 if (IS_OSPF6_DEBUG_ASBR
) {
1409 inet_ntop(AF_INET
, &prefix_id
.u
.prefix4
, ibuf
,
1412 "Advertise as AS-External Id:%s prefix %pFX metric %u",
1413 ibuf
, prefix
, match
->path
.metric_type
);
1416 match
->path
.origin
.id
= htonl(info
->id
);
1417 ospf6_as_external_lsa_originate(match
, ospf6
);
1418 ospf6_asbr_status_update(ospf6
, ospf6
->redistribute
);
1419 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, lnode
, oa
)) {
1420 if (IS_AREA_NSSA(oa
))
1421 ospf6_nssa_lsa_originate(match
, oa
);
1427 /* create new entry */
1428 route
= ospf6_route_create();
1429 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
1430 prefix_copy(&route
->prefix
, prefix
);
1432 info
= (struct ospf6_external_info
*)XCALLOC(
1433 MTYPE_OSPF6_EXTERNAL_INFO
, sizeof(struct ospf6_external_info
));
1434 route
->route_option
= info
;
1435 info
->id
= ospf6
->external_id
++;
1437 /* copy result of route-map */
1438 if (ROUTEMAP(red
)) {
1439 if (troute
.path
.metric_type
)
1440 route
->path
.metric_type
= troute
.path
.metric_type
;
1441 if (troute
.path
.cost
)
1442 route
->path
.cost
= troute
.path
.cost
;
1443 if (!IN6_IS_ADDR_UNSPECIFIED(&tinfo
.forwarding
))
1444 memcpy(&info
->forwarding
, &tinfo
.forwarding
,
1445 sizeof(struct in6_addr
));
1446 info
->tag
= tinfo
.tag
;
1448 /* If there is no route-map, simply update the tag and metric
1451 route
->path
.metric_type
= metric_type(ospf6
, type
, 0);
1452 route
->path
.cost
= metric_value(ospf6
, type
, 0);
1457 if (nexthop_num
&& nexthop
)
1458 ospf6_route_add_nexthop(route
, ifindex
, nexthop
);
1460 ospf6_route_add_nexthop(route
, ifindex
, NULL
);
1462 /* create/update binding in external_id_table */
1463 prefix_id
.family
= AF_INET
;
1464 prefix_id
.prefixlen
= 32;
1465 prefix_id
.u
.prefix4
.s_addr
= htonl(info
->id
);
1466 node
= route_node_get(ospf6
->external_id_table
, &prefix_id
);
1469 route
= ospf6_route_add(route
, ospf6
->external_table
);
1470 route
->route_option
= info
;
1472 if (IS_OSPF6_DEBUG_ASBR
) {
1473 inet_ntop(AF_INET
, &prefix_id
.u
.prefix4
, ibuf
, sizeof(ibuf
));
1475 "Advertise as AS-External Id:%s prefix %pFX metric %u",
1476 ibuf
, prefix
, route
->path
.metric_type
);
1479 route
->path
.origin
.id
= htonl(info
->id
);
1480 ospf6_as_external_lsa_originate(route
, ospf6
);
1481 ospf6_asbr_status_update(ospf6
, ospf6
->redistribute
);
1482 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, lnode
, oa
)) {
1483 if (IS_AREA_NSSA(oa
))
1484 ospf6_nssa_lsa_originate(route
, oa
);
1488 void ospf6_asbr_redistribute_remove(int type
, ifindex_t ifindex
,
1489 struct prefix
*prefix
, struct ospf6
*ospf6
)
1491 struct ospf6_area
*oa
;
1492 struct ospf6_route
*match
;
1493 struct ospf6_external_info
*info
= NULL
;
1494 struct listnode
*lnode
;
1495 struct route_node
*node
;
1496 struct ospf6_lsa
*lsa
;
1497 struct prefix prefix_id
;
1500 match
= ospf6_route_lookup(prefix
, ospf6
->external_table
);
1501 if (match
== NULL
) {
1502 if (IS_OSPF6_DEBUG_ASBR
)
1503 zlog_debug("No such route %pFX to withdraw", prefix
);
1507 info
= match
->route_option
;
1510 if (info
->type
!= type
) {
1511 if (IS_OSPF6_DEBUG_ASBR
)
1512 zlog_debug("Original protocol mismatch: %pFX", prefix
);
1516 if (IS_OSPF6_DEBUG_ASBR
) {
1517 inet_ntop(AF_INET
, &prefix_id
.u
.prefix4
, ibuf
, sizeof(ibuf
));
1518 zlog_debug("Withdraw %pFX (AS-External Id:%s)", prefix
, ibuf
);
1521 lsa
= ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_AS_EXTERNAL
),
1522 htonl(info
->id
), ospf6
->router_id
, ospf6
->lsdb
);
1524 if (IS_OSPF6_DEBUG_ASBR
) {
1525 zlog_debug("withdraw type 5 LSA for route %pFX",
1528 ospf6_lsa_purge(lsa
);
1531 /* Delete the NSSA LSA */
1532 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, lnode
, oa
)) {
1533 lsa
= ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_TYPE_7
),
1534 htonl(info
->id
), ospf6
->router_id
,
1537 if (IS_OSPF6_DEBUG_ASBR
) {
1538 zlog_debug("withdraw type 7 LSA for route %pFX",
1541 ospf6_lsa_purge(lsa
);
1545 /* remove binding in external_id_table */
1546 prefix_id
.family
= AF_INET
;
1547 prefix_id
.prefixlen
= 32;
1548 prefix_id
.u
.prefix4
.s_addr
= htonl(info
->id
);
1549 node
= route_node_lookup(ospf6
->external_id_table
, &prefix_id
);
1552 route_unlock_node(node
); /* to free the lookup lock */
1553 route_unlock_node(node
); /* to free the original lock */
1555 ospf6_route_remove(match
, ospf6
->external_table
);
1556 XFREE(MTYPE_OSPF6_EXTERNAL_INFO
, info
);
1558 ospf6_asbr_status_update(ospf6
, ospf6
->redistribute
);
1561 DEFUN (ospf6_redistribute
,
1562 ospf6_redistribute_cmd
,
1563 "redistribute " FRR_REDIST_STR_OSPF6D
,
1565 FRR_REDIST_HELP_STR_OSPF6D
)
1568 struct ospf6_redist
*red
;
1570 VTY_DECLVAR_CONTEXT(ospf6
, ospf6
);
1572 char *proto
= argv
[argc
- 1]->text
;
1573 type
= proto_redistnum(AFI_IP6
, proto
);
1575 return CMD_WARNING_CONFIG_FAILED
;
1577 red
= ospf6_redist_add(ospf6
, type
, 0);
1581 ospf6_asbr_redistribute_unset(ospf6
, red
, type
);
1582 ospf6_asbr_redistribute_set(type
, ospf6
->vrf_id
);
1587 DEFUN (ospf6_redistribute_routemap
,
1588 ospf6_redistribute_routemap_cmd
,
1589 "redistribute " FRR_REDIST_STR_OSPF6D
" route-map WORD",
1591 FRR_REDIST_HELP_STR_OSPF6D
1592 "Route map reference\n"
1595 int idx_protocol
= 1;
1598 struct ospf6_redist
*red
;
1600 VTY_DECLVAR_CONTEXT(ospf6
, ospf6
);
1602 char *proto
= argv
[idx_protocol
]->text
;
1603 type
= proto_redistnum(AFI_IP6
, proto
);
1605 return CMD_WARNING_CONFIG_FAILED
;
1607 red
= ospf6_redist_add(ospf6
, type
, 0);
1611 ospf6_asbr_redistribute_unset(ospf6
, red
, type
);
1612 ospf6_asbr_routemap_set(red
, argv
[idx_word
]->arg
);
1613 ospf6_asbr_redistribute_set(type
, ospf6
->vrf_id
);
1618 DEFUN (no_ospf6_redistribute
,
1619 no_ospf6_redistribute_cmd
,
1620 "no redistribute " FRR_REDIST_STR_OSPF6D
" [route-map WORD]",
1623 FRR_REDIST_HELP_STR_OSPF6D
1624 "Route map reference\n"
1627 int idx_protocol
= 2;
1629 struct ospf6_redist
*red
;
1631 VTY_DECLVAR_CONTEXT(ospf6
, ospf6
);
1633 char *proto
= argv
[idx_protocol
]->text
;
1634 type
= proto_redistnum(AFI_IP6
, proto
);
1636 return CMD_WARNING_CONFIG_FAILED
;
1638 red
= ospf6_redist_lookup(ospf6
, type
, 0);
1642 ospf6_asbr_redistribute_unset(ospf6
, red
, type
);
1643 ospf6_redist_del(ospf6
, red
, type
);
1648 int ospf6_redistribute_config_write(struct vty
*vty
, struct ospf6
*ospf6
)
1651 struct ospf6_redist
*red
;
1653 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
1654 red
= ospf6_redist_lookup(ospf6
, type
, 0);
1657 if (type
== ZEBRA_ROUTE_OSPF6
)
1660 if (ROUTEMAP_NAME(red
))
1661 vty_out(vty
, " redistribute %s route-map %s\n",
1662 ZROUTE_NAME(type
), ROUTEMAP_NAME(red
));
1664 vty_out(vty
, " redistribute %s\n", ZROUTE_NAME(type
));
1670 static void ospf6_redistribute_show_config(struct vty
*vty
, struct ospf6
*ospf6
,
1671 json_object
*json_array
,
1672 json_object
*json
, bool use_json
)
1675 int nroute
[ZEBRA_ROUTE_MAX
];
1677 struct ospf6_route
*route
;
1678 struct ospf6_external_info
*info
;
1679 json_object
*json_route
;
1680 struct ospf6_redist
*red
;
1683 memset(nroute
, 0, sizeof(nroute
));
1684 for (route
= ospf6_route_head(ospf6
->external_table
); route
;
1685 route
= ospf6_route_next(route
)) {
1686 info
= route
->route_option
;
1687 nroute
[info
->type
]++;
1692 vty_out(vty
, "Redistributing External Routes from:\n");
1694 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
1696 red
= ospf6_redist_lookup(ospf6
, type
, 0);
1700 if (type
== ZEBRA_ROUTE_OSPF6
)
1704 json_route
= json_object_new_object();
1705 json_object_string_add(json_route
, "routeType",
1707 json_object_int_add(json_route
, "numberOfRoutes",
1709 json_object_boolean_add(json_route
,
1710 "routeMapNamePresent",
1711 ROUTEMAP_NAME(red
));
1714 if (ROUTEMAP_NAME(red
)) {
1716 json_object_string_add(json_route
,
1718 ROUTEMAP_NAME(red
));
1719 json_object_boolean_add(json_route
,
1724 " %d: %s with route-map \"%s\"%s\n",
1725 nroute
[type
], ZROUTE_NAME(type
),
1728 : " (not found !)"));
1731 vty_out(vty
, " %d: %s\n", nroute
[type
],
1736 json_object_array_add(json_array
, json_route
);
1739 json_object_object_add(json
, "redistributedRoutes", json_array
);
1740 json_object_int_add(json
, "totalRoutes", total
);
1742 vty_out(vty
, "Total %d routes\n", total
);
1745 static void ospf6_redistribute_default_set(struct ospf6
*ospf6
, int originate
)
1747 struct prefix_ipv6 p
= {};
1748 struct in6_addr nexthop
= {};
1749 int cur_originate
= ospf6
->default_originate
;
1751 p
.family
= AF_INET6
;
1754 ospf6
->default_originate
= originate
;
1756 switch (cur_originate
) {
1757 case DEFAULT_ORIGINATE_NONE
:
1759 case DEFAULT_ORIGINATE_ZEBRA
:
1760 zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
,
1761 zclient
, AFI_IP6
, ospf6
->vrf_id
);
1762 ospf6_asbr_redistribute_remove(DEFAULT_ROUTE
, 0,
1763 (struct prefix
*)&p
, ospf6
);
1766 case DEFAULT_ORIGINATE_ALWAYS
:
1767 ospf6_asbr_redistribute_remove(DEFAULT_ROUTE
, 0,
1768 (struct prefix
*)&p
, ospf6
);
1772 switch (originate
) {
1773 case DEFAULT_ORIGINATE_NONE
:
1775 case DEFAULT_ORIGINATE_ZEBRA
:
1776 zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_ADD
,
1777 zclient
, AFI_IP6
, ospf6
->vrf_id
);
1780 case DEFAULT_ORIGINATE_ALWAYS
:
1781 ospf6_asbr_redistribute_add(DEFAULT_ROUTE
, 0,
1782 (struct prefix
*)&p
, 0, &nexthop
, 0,
1788 /* Default Route originate. */
1789 DEFPY (ospf6_default_route_originate
,
1790 ospf6_default_route_originate_cmd
,
1791 "default-information originate [{always$always|metric (0-16777214)$mval|metric-type (1-2)$mtype|route-map WORD$rtmap}]",
1792 "Control distribution of default route\n"
1793 "Distribute a default route\n"
1794 "Always advertise default route\n"
1795 "OSPFv3 default metric\n"
1797 "OSPFv3 metric type for default routes\n"
1798 "Set OSPFv3 External Type 1/2 metrics\n"
1799 "Route map reference\n"
1800 "Pointer to route-map entries\n")
1802 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
1803 struct ospf6_redist
*red
;
1804 bool sameRtmap
= false;
1806 VTY_DECLVAR_CONTEXT(ospf6
, ospf6
);
1808 int cur_originate
= ospf6
->default_originate
;
1810 red
= ospf6_redist_add(ospf6
, DEFAULT_ROUTE
, 0);
1813 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
1815 if (mval_str
== NULL
)
1818 if (mtype_str
== NULL
)
1821 /* To check ,if user is providing same route map */
1822 if ((rtmap
== ROUTEMAP_NAME(red
))
1823 || (rtmap
&& ROUTEMAP_NAME(red
)
1824 && (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
1827 /* Don't allow if the same lsa is aleardy originated. */
1828 if ((sameRtmap
) && (red
->dmetric
.type
== mtype
)
1829 && (red
->dmetric
.value
== mval
)
1830 && (cur_originate
== default_originate
))
1833 /* Updating Metric details */
1834 red
->dmetric
.type
= mtype
;
1835 red
->dmetric
.value
= mval
;
1837 /* updating route map details */
1839 ospf6_asbr_routemap_set(red
, rtmap
);
1841 ospf6_asbr_routemap_unset(red
);
1843 ospf6_redistribute_default_set(ospf6
, default_originate
);
1847 DEFPY (no_ospf6_default_information_originate
,
1848 no_ospf6_default_information_originate_cmd
,
1849 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
1851 "Control distribution of default information\n"
1852 "Distribute a default route\n"
1853 "Always advertise default route\n"
1854 "OSPFv3 default metric\n"
1856 "OSPFv3 metric type for default routes\n"
1857 "Set OSPFv3 External Type 1/2 metrics\n"
1858 "Route map reference\n"
1859 "Pointer to route-map entries\n")
1861 struct ospf6_redist
*red
;
1863 VTY_DECLVAR_CONTEXT(ospf6
, ospf6
);
1865 red
= ospf6_redist_lookup(ospf6
, DEFAULT_ROUTE
, 0);
1869 ospf6_asbr_routemap_unset(red
);
1870 ospf6_redist_del(ospf6
, red
, DEFAULT_ROUTE
);
1872 ospf6_redistribute_default_set(ospf6
, DEFAULT_ORIGINATE_NONE
);
1876 /* Routemap Functions */
1877 static enum route_map_cmd_result_t
1878 ospf6_routemap_rule_match_address_prefixlist(void *rule
,
1879 const struct prefix
*prefix
,
1883 struct prefix_list
*plist
;
1885 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
1887 return RMAP_NOMATCH
;
1889 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
1894 ospf6_routemap_rule_match_address_prefixlist_compile(const char *arg
)
1896 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1899 static void ospf6_routemap_rule_match_address_prefixlist_free(void *rule
)
1901 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1904 static const struct route_map_rule_cmd
1905 ospf6_routemap_rule_match_address_prefixlist_cmd
= {
1906 "ipv6 address prefix-list",
1907 ospf6_routemap_rule_match_address_prefixlist
,
1908 ospf6_routemap_rule_match_address_prefixlist_compile
,
1909 ospf6_routemap_rule_match_address_prefixlist_free
,
1912 /* `match interface IFNAME' */
1913 /* Match function should return 1 if match is success else return
1915 static enum route_map_cmd_result_t
1916 ospf6_routemap_rule_match_interface(void *rule
, const struct prefix
*prefix
,
1919 struct interface
*ifp
;
1920 struct ospf6_external_info
*ei
;
1922 ei
= ((struct ospf6_route
*)object
)->route_option
;
1923 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1925 if (ifp
!= NULL
&& ei
->ifindex
== ifp
->ifindex
)
1928 return RMAP_NOMATCH
;
1931 /* Route map `interface' match statement. `arg' should be
1933 static void *ospf6_routemap_rule_match_interface_compile(const char *arg
)
1935 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1938 /* Free route map's compiled `interface' value. */
1939 static void ospf6_routemap_rule_match_interface_free(void *rule
)
1941 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1944 /* Route map commands for interface matching. */
1945 static const struct route_map_rule_cmd
1946 ospf6_routemap_rule_match_interface_cmd
= {
1948 ospf6_routemap_rule_match_interface
,
1949 ospf6_routemap_rule_match_interface_compile
,
1950 ospf6_routemap_rule_match_interface_free
1953 /* Match function for matching route tags */
1954 static enum route_map_cmd_result_t
1955 ospf6_routemap_rule_match_tag(void *rule
, const struct prefix
*p
, void *object
)
1957 route_tag_t
*tag
= rule
;
1958 struct ospf6_route
*route
= object
;
1959 struct ospf6_external_info
*info
= route
->route_option
;
1961 if (info
->tag
== *tag
)
1964 return RMAP_NOMATCH
;
1967 static const struct route_map_rule_cmd
1968 ospf6_routemap_rule_match_tag_cmd
= {
1970 ospf6_routemap_rule_match_tag
,
1971 route_map_rule_tag_compile
,
1972 route_map_rule_tag_free
,
1975 static enum route_map_cmd_result_t
1976 ospf6_routemap_rule_set_metric_type(void *rule
, const struct prefix
*prefix
,
1979 char *metric_type
= rule
;
1980 struct ospf6_route
*route
= object
;
1982 if (strcmp(metric_type
, "type-2") == 0)
1983 route
->path
.metric_type
= 2;
1985 route
->path
.metric_type
= 1;
1990 static void *ospf6_routemap_rule_set_metric_type_compile(const char *arg
)
1992 if (strcmp(arg
, "type-2") && strcmp(arg
, "type-1"))
1994 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1997 static void ospf6_routemap_rule_set_metric_type_free(void *rule
)
1999 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2002 static const struct route_map_rule_cmd
2003 ospf6_routemap_rule_set_metric_type_cmd
= {
2005 ospf6_routemap_rule_set_metric_type
,
2006 ospf6_routemap_rule_set_metric_type_compile
,
2007 ospf6_routemap_rule_set_metric_type_free
,
2010 static enum route_map_cmd_result_t
2011 ospf6_routemap_rule_set_metric(void *rule
, const struct prefix
*prefix
,
2014 char *metric
= rule
;
2015 struct ospf6_route
*route
= object
;
2017 route
->path
.cost
= atoi(metric
);
2021 static void *ospf6_routemap_rule_set_metric_compile(const char *arg
)
2025 metric
= strtoul(arg
, &endp
, 0);
2026 if (metric
> OSPF_LS_INFINITY
|| *endp
!= '\0')
2028 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2031 static void ospf6_routemap_rule_set_metric_free(void *rule
)
2033 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2036 static const struct route_map_rule_cmd
2037 ospf6_routemap_rule_set_metric_cmd
= {
2039 ospf6_routemap_rule_set_metric
,
2040 ospf6_routemap_rule_set_metric_compile
,
2041 ospf6_routemap_rule_set_metric_free
,
2044 static enum route_map_cmd_result_t
2045 ospf6_routemap_rule_set_forwarding(void *rule
, const struct prefix
*prefix
,
2048 char *forwarding
= rule
;
2049 struct ospf6_route
*route
= object
;
2050 struct ospf6_external_info
*info
= route
->route_option
;
2052 if (inet_pton(AF_INET6
, forwarding
, &info
->forwarding
) != 1) {
2053 memset(&info
->forwarding
, 0, sizeof(struct in6_addr
));
2060 static void *ospf6_routemap_rule_set_forwarding_compile(const char *arg
)
2063 if (inet_pton(AF_INET6
, arg
, &a
) != 1)
2065 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2068 static void ospf6_routemap_rule_set_forwarding_free(void *rule
)
2070 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2073 static const struct route_map_rule_cmd
2074 ospf6_routemap_rule_set_forwarding_cmd
= {
2075 "forwarding-address",
2076 ospf6_routemap_rule_set_forwarding
,
2077 ospf6_routemap_rule_set_forwarding_compile
,
2078 ospf6_routemap_rule_set_forwarding_free
,
2081 static enum route_map_cmd_result_t
2082 ospf6_routemap_rule_set_tag(void *rule
, const struct prefix
*p
, void *object
)
2084 route_tag_t
*tag
= rule
;
2085 struct ospf6_route
*route
= object
;
2086 struct ospf6_external_info
*info
= route
->route_option
;
2092 static const struct route_map_rule_cmd ospf6_routemap_rule_set_tag_cmd
= {
2094 ospf6_routemap_rule_set_tag
,
2095 route_map_rule_tag_compile
,
2096 route_map_rule_tag_free
,
2099 /* add "set metric-type" */
2100 DEFUN_YANG (ospf6_routemap_set_metric_type
, ospf6_routemap_set_metric_type_cmd
,
2101 "set metric-type <type-1|type-2>",
2104 "OSPF6 external type 1 metric\n"
2105 "OSPF6 external type 2 metric\n")
2107 char *ext
= argv
[2]->text
;
2110 "./set-action[action='frr-ospf-route-map:metric-type']";
2111 char xpath_value
[XPATH_MAXLEN
];
2113 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
2114 snprintf(xpath_value
, sizeof(xpath_value
),
2115 "%s/rmap-set-action/frr-ospf-route-map:metric-type", xpath
);
2116 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, ext
);
2117 return nb_cli_apply_changes(vty
, NULL
);
2120 /* delete "set metric-type" */
2121 DEFUN_YANG (ospf6_routemap_no_set_metric_type
, ospf6_routemap_no_set_metric_type_cmd
,
2122 "no set metric-type [<type-1|type-2>]",
2126 "OSPF6 external type 1 metric\n"
2127 "OSPF6 external type 2 metric\n")
2130 "./set-action[action='frr-ospf-route-map:metric-type']";
2132 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
2133 return nb_cli_apply_changes(vty
, NULL
);
2136 /* add "set forwarding-address" */
2137 DEFUN_YANG (ospf6_routemap_set_forwarding
, ospf6_routemap_set_forwarding_cmd
,
2138 "set forwarding-address X:X::X:X",
2140 "Forwarding Address\n"
2145 "./set-action[action='frr-ospf6-route-map:forwarding-address']";
2146 char xpath_value
[XPATH_MAXLEN
];
2148 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
2149 snprintf(xpath_value
, sizeof(xpath_value
),
2150 "%s/rmap-set-action/frr-ospf6-route-map:ipv6-address", xpath
);
2151 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
2152 argv
[idx_ipv6
]->arg
);
2153 return nb_cli_apply_changes(vty
, NULL
);
2156 /* delete "set forwarding-address" */
2157 DEFUN_YANG (ospf6_routemap_no_set_forwarding
, ospf6_routemap_no_set_forwarding_cmd
,
2158 "no set forwarding-address [X:X::X:X]",
2161 "Forwarding Address\n"
2165 "./set-action[action='frr-ospf6-route-map:forwarding-address']";
2167 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
2168 return nb_cli_apply_changes(vty
, NULL
);
2171 static void ospf6_routemap_init(void)
2175 route_map_add_hook(ospf6_asbr_routemap_update
);
2176 route_map_delete_hook(ospf6_asbr_routemap_update
);
2177 route_map_event_hook(ospf6_asbr_routemap_event
);
2179 route_map_set_metric_hook(generic_set_add
);
2180 route_map_no_set_metric_hook(generic_set_delete
);
2182 route_map_set_tag_hook(generic_set_add
);
2183 route_map_no_set_tag_hook(generic_set_delete
);
2185 route_map_match_tag_hook(generic_match_add
);
2186 route_map_no_match_tag_hook(generic_match_delete
);
2188 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
2189 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
2191 route_map_match_interface_hook(generic_match_add
);
2192 route_map_no_match_interface_hook(generic_match_delete
);
2194 route_map_install_match(
2195 &ospf6_routemap_rule_match_address_prefixlist_cmd
);
2196 route_map_install_match(&ospf6_routemap_rule_match_interface_cmd
);
2197 route_map_install_match(&ospf6_routemap_rule_match_tag_cmd
);
2199 route_map_install_set(&ospf6_routemap_rule_set_metric_type_cmd
);
2200 route_map_install_set(&ospf6_routemap_rule_set_metric_cmd
);
2201 route_map_install_set(&ospf6_routemap_rule_set_forwarding_cmd
);
2202 route_map_install_set(&ospf6_routemap_rule_set_tag_cmd
);
2204 /* ASE Metric Type (e.g. Type-1/Type-2) */
2205 install_element(RMAP_NODE
, &ospf6_routemap_set_metric_type_cmd
);
2206 install_element(RMAP_NODE
, &ospf6_routemap_no_set_metric_type_cmd
);
2209 install_element(RMAP_NODE
, &ospf6_routemap_set_forwarding_cmd
);
2210 install_element(RMAP_NODE
, &ospf6_routemap_no_set_forwarding_cmd
);
2214 /* Display functions */
2215 static char *ospf6_as_external_lsa_get_prefix_str(struct ospf6_lsa
*lsa
,
2216 char *buf
, int buflen
,
2219 struct ospf6_as_external_lsa
*external
;
2220 struct in6_addr in6
;
2221 int prefix_length
= 0;
2225 external
= (struct ospf6_as_external_lsa
*)OSPF6_LSA_HEADER_END(
2229 ospf6_prefix_in6_addr(&in6
, external
,
2231 prefix_length
= external
->prefix
.prefix_length
;
2233 in6
= *((struct in6_addr
2234 *)((caddr_t
)external
2236 ospf6_as_external_lsa
)
2237 + OSPF6_PREFIX_SPACE(
2242 inet_ntop(AF_INET6
, &in6
, buf
, buflen
);
2243 if (prefix_length
) {
2244 snprintf(tbuf
, sizeof(tbuf
), "/%d",
2246 strlcat(buf
, tbuf
, buflen
);
2253 static int ospf6_as_external_lsa_show(struct vty
*vty
, struct ospf6_lsa
*lsa
,
2254 json_object
*json_obj
, bool use_json
)
2256 struct ospf6_as_external_lsa
*external
;
2259 assert(lsa
->header
);
2260 external
= (struct ospf6_as_external_lsa
*)OSPF6_LSA_HEADER_END(
2264 snprintf(buf
, sizeof(buf
), "%c%c%c",
2265 (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_E
) ? 'E'
2267 (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_F
) ? 'F'
2269 (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_T
) ? 'T'
2273 json_object_string_add(json_obj
, "bits", buf
);
2274 json_object_int_add(json_obj
, "metric",
2275 (unsigned long)OSPF6_ASBR_METRIC(external
));
2276 ospf6_prefix_options_printbuf(external
->prefix
.prefix_options
,
2278 json_object_string_add(json_obj
, "prefixOptions", buf
);
2279 json_object_int_add(
2280 json_obj
, "referenceLsType",
2281 ntohs(external
->prefix
.prefix_refer_lstype
));
2282 json_object_string_add(json_obj
, "prefix",
2283 ospf6_as_external_lsa_get_prefix_str(
2284 lsa
, buf
, sizeof(buf
), 0));
2286 /* Forwarding-Address */
2287 json_object_boolean_add(
2288 json_obj
, "forwardingAddressPresent",
2289 CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_F
));
2290 if (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_F
))
2291 json_object_string_add(
2292 json_obj
, "forwardingAddress",
2293 ospf6_as_external_lsa_get_prefix_str(
2294 lsa
, buf
, sizeof(buf
), 1));
2297 json_object_boolean_add(
2298 json_obj
, "tagPresent",
2299 CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_T
));
2300 if (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_T
))
2301 json_object_int_add(json_obj
, "tag",
2302 ospf6_as_external_lsa_get_tag(lsa
));
2304 vty_out(vty
, " Bits: %s\n", buf
);
2305 vty_out(vty
, " Metric: %5lu\n",
2306 (unsigned long)OSPF6_ASBR_METRIC(external
));
2308 ospf6_prefix_options_printbuf(external
->prefix
.prefix_options
,
2310 vty_out(vty
, " Prefix Options: %s\n", buf
);
2312 vty_out(vty
, " Referenced LSType: %d\n",
2313 ntohs(external
->prefix
.prefix_refer_lstype
));
2315 vty_out(vty
, " Prefix: %s\n",
2316 ospf6_as_external_lsa_get_prefix_str(lsa
, buf
,
2319 /* Forwarding-Address */
2320 if (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_F
)) {
2321 vty_out(vty
, " Forwarding-Address: %s\n",
2322 ospf6_as_external_lsa_get_prefix_str(
2323 lsa
, buf
, sizeof(buf
), 1));
2327 if (CHECK_FLAG(external
->bits_metric
, OSPF6_ASBR_BIT_T
)) {
2328 vty_out(vty
, " Tag: %" ROUTE_TAG_PRI
"\n",
2329 ospf6_as_external_lsa_get_tag(lsa
));
2336 static void ospf6_asbr_external_route_show(struct vty
*vty
,
2337 struct ospf6_route
*route
,
2338 json_object
*json_array
,
2341 struct ospf6_external_info
*info
= route
->route_option
;
2342 char prefix
[PREFIX2STR_BUFFER
], id
[16], forwarding
[64];
2344 json_object
*json_route
;
2347 prefix2str(&route
->prefix
, prefix
, sizeof(prefix
));
2348 tmp_id
= ntohl(info
->id
);
2349 inet_ntop(AF_INET
, &tmp_id
, id
, sizeof(id
));
2350 if (!IN6_IS_ADDR_UNSPECIFIED(&info
->forwarding
))
2351 inet_ntop(AF_INET6
, &info
->forwarding
, forwarding
,
2352 sizeof(forwarding
));
2354 snprintf(forwarding
, sizeof(forwarding
), ":: (ifindex %d)",
2355 ospf6_route_get_first_nh_index(route
));
2358 json_route
= json_object_new_object();
2359 snprintf(route_type
, sizeof(route_type
), "%c",
2360 zebra_route_char(info
->type
));
2361 json_object_string_add(json_route
, "routeType", route_type
);
2362 json_object_string_add(json_route
, "destination", prefix
);
2363 json_object_string_add(json_route
, "id", id
);
2364 json_object_int_add(json_route
, "metricType",
2365 route
->path
.metric_type
);
2366 json_object_int_add(
2367 json_route
, "routeCost",
2368 (unsigned long)(route
->path
.metric_type
== 2
2369 ? route
->path
.u
.cost_e2
2370 : route
->path
.cost
));
2371 json_object_string_add(json_route
, "forwarding", forwarding
);
2373 json_object_array_add(json_array
, json_route
);
2376 vty_out(vty
, "%c %-32pFX %-15s type-%d %5lu %s\n",
2377 zebra_route_char(info
->type
), &route
->prefix
, id
,
2378 route
->path
.metric_type
,
2379 (unsigned long)(route
->path
.metric_type
== 2
2380 ? route
->path
.u
.cost_e2
2381 : route
->path
.cost
),
2385 DEFUN(show_ipv6_ospf6_redistribute
, show_ipv6_ospf6_redistribute_cmd
,
2386 "show ipv6 ospf6 [vrf <NAME|all>] redistribute [json]",
2387 SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR
2389 "redistributing External information\n" JSON_STR
)
2391 struct ospf6_route
*route
;
2392 struct ospf6
*ospf6
= NULL
;
2393 json_object
*json
= NULL
;
2394 bool uj
= use_json(argc
, argv
);
2395 struct listnode
*node
;
2396 const char *vrf_name
= NULL
;
2397 bool all_vrf
= false;
2400 json_object
*json_array_routes
= NULL
;
2401 json_object
*json_array_redistribute
= NULL
;
2403 OSPF6_CMD_CHECK_RUNNING();
2404 OSPF6_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
2407 json
= json_object_new_object();
2408 json_array_routes
= json_object_new_array();
2409 json_array_redistribute
= json_object_new_array();
2412 for (ALL_LIST_ELEMENTS_RO(om6
->ospf6
, node
, ospf6
)) {
2414 || ((ospf6
->name
== NULL
&& vrf_name
== NULL
)
2415 || (ospf6
->name
&& vrf_name
2416 && strcmp(ospf6
->name
, vrf_name
) == 0))) {
2417 ospf6_redistribute_show_config(
2418 vty
, ospf6
, json_array_redistribute
, json
, uj
);
2420 for (route
= ospf6_route_head(ospf6
->external_table
);
2421 route
; route
= ospf6_route_next(route
)) {
2422 ospf6_asbr_external_route_show(
2423 vty
, route
, json_array_routes
, uj
);
2427 json_object_object_add(json
, "routes",
2429 vty_out(vty
, "%s\n",
2430 json_object_to_json_string_ext(
2431 json
, JSON_C_TO_STRING_PRETTY
));
2432 json_object_free(json
);
2443 static struct ospf6_lsa_handler as_external_handler
= {
2444 .lh_type
= OSPF6_LSTYPE_AS_EXTERNAL
,
2445 .lh_name
= "AS-External",
2446 .lh_short_name
= "ASE",
2447 .lh_show
= ospf6_as_external_lsa_show
,
2448 .lh_get_prefix_str
= ospf6_as_external_lsa_get_prefix_str
,
2451 static struct ospf6_lsa_handler nssa_external_handler
= {
2452 .lh_type
= OSPF6_LSTYPE_TYPE_7
,
2454 .lh_short_name
= "Type7",
2455 .lh_show
= ospf6_as_external_lsa_show
,
2456 .lh_get_prefix_str
= ospf6_as_external_lsa_get_prefix_str
,
2459 void ospf6_asbr_init(void)
2461 ospf6_routemap_init();
2463 ospf6_install_lsa_handler(&as_external_handler
);
2464 ospf6_install_lsa_handler(&nssa_external_handler
);
2466 install_element(VIEW_NODE
, &show_ipv6_ospf6_redistribute_cmd
);
2468 install_element(OSPF6_NODE
, &ospf6_default_route_originate_cmd
);
2469 install_element(OSPF6_NODE
,
2470 &no_ospf6_default_information_originate_cmd
);
2471 install_element(OSPF6_NODE
, &ospf6_redistribute_cmd
);
2472 install_element(OSPF6_NODE
, &ospf6_redistribute_routemap_cmd
);
2473 install_element(OSPF6_NODE
, &no_ospf6_redistribute_cmd
);
2476 void ospf6_asbr_redistribute_reset(struct ospf6
*ospf6
)
2479 struct ospf6_redist
*red
;
2481 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
2482 red
= ospf6_redist_lookup(ospf6
, type
, 0);
2485 if (type
== ZEBRA_ROUTE_OSPF6
)
2487 ospf6_asbr_redistribute_unset(ospf6
, red
, type
);
2488 ospf6_redist_del(ospf6
, red
, type
);
2490 red
= ospf6_redist_lookup(ospf6
, DEFAULT_ROUTE
, 0);
2492 ospf6_asbr_routemap_unset(red
);
2493 ospf6_redist_del(ospf6
, red
, type
);
2494 ospf6_redistribute_default_set(ospf6
, DEFAULT_ORIGINATE_NONE
);
2498 void ospf6_asbr_terminate(void)
2500 /* Cleanup route maps */
2504 DEFUN (debug_ospf6_asbr
,
2505 debug_ospf6_asbr_cmd
,
2509 "Debug OSPFv3 ASBR function\n"
2512 OSPF6_DEBUG_ASBR_ON();
2516 DEFUN (no_debug_ospf6_asbr
,
2517 no_debug_ospf6_asbr_cmd
,
2518 "no debug ospf6 asbr",
2522 "Debug OSPFv3 ASBR function\n"
2525 OSPF6_DEBUG_ASBR_OFF();
2529 int config_write_ospf6_debug_asbr(struct vty
*vty
)
2531 if (IS_OSPF6_DEBUG_ASBR
)
2532 vty_out(vty
, "debug ospf6 asbr\n");
2536 int ospf6_distribute_config_write(struct vty
*vty
, struct ospf6
*ospf6
)
2538 struct ospf6_redist
*red
;
2541 /* default-route print. */
2542 if (ospf6
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
2543 vty_out(vty
, " default-information originate");
2544 if (ospf6
->default_originate
2545 == DEFAULT_ORIGINATE_ALWAYS
)
2546 vty_out(vty
, " always");
2548 red
= ospf6_redist_lookup(ospf6
, DEFAULT_ROUTE
, 0);
2550 if (red
->dmetric
.value
>= 0)
2551 vty_out(vty
, " metric %d",
2552 red
->dmetric
.value
);
2554 if (red
->dmetric
.type
>= 0)
2555 vty_out(vty
, " metric-type %d",
2558 if (ROUTEMAP_NAME(red
))
2559 vty_out(vty
, " route-map %s",
2560 ROUTEMAP_NAME(red
));
2569 void install_element_ospf6_debug_asbr(void)
2571 install_element(ENABLE_NODE
, &debug_ospf6_asbr_cmd
);
2572 install_element(ENABLE_NODE
, &no_debug_ospf6_asbr_cmd
);
2573 install_element(CONFIG_NODE
, &debug_ospf6_asbr_cmd
);
2574 install_element(CONFIG_NODE
, &no_debug_ospf6_asbr_cmd
);