1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Redistribution Handler
3 * Copyright (C) 1998 Kunihiro Ishiguro
18 #include "srcdest_table.h"
20 #include "zebra/rib.h"
21 #include "zebra/zebra_router.h"
22 #include "zebra/zebra_ns.h"
23 #include "zebra/zebra_vrf.h"
24 #include "zebra/zebra_routemap.h"
25 #include "zebra/redistribute.h"
26 #include "zebra/debug.h"
27 #include "zebra/router-id.h"
28 #include "zebra/zapi_msg.h"
29 #include "zebra/zebra_vxlan.h"
30 #include "zebra/zebra_errors.h"
32 #define ZEBRA_PTM_SUPPORT
34 /* array holding redistribute info about table redistribution */
35 /* bit AFI is set if that AFI is redistributing routes from this table */
36 static int zebra_import_table_used
[AFI_MAX
][ZEBRA_KERNEL_TABLE_MAX
];
37 static uint32_t zebra_import_table_distance
[AFI_MAX
][ZEBRA_KERNEL_TABLE_MAX
];
39 int is_zebra_import_table_enabled(afi_t afi
, vrf_id_t vrf_id
, uint32_t table_id
)
42 * Make sure that what we are called with actualy makes sense
47 if (is_zebra_valid_kernel_table(table_id
) &&
48 table_id
< ZEBRA_KERNEL_TABLE_MAX
)
49 return zebra_import_table_used
[afi
][table_id
];
53 static void zebra_redistribute_default(struct zserv
*client
, vrf_id_t vrf_id
)
57 struct route_table
*table
;
58 struct route_node
*rn
;
59 struct route_entry
*newre
;
61 for (afi
= AFI_IP
; afi
<= AFI_IP6
; afi
++) {
63 if (!vrf_bitmap_check(client
->redist_default
[afi
], vrf_id
))
67 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, vrf_id
);
71 /* Lookup default route. */
72 memset(&p
, 0, sizeof(p
));
73 p
.family
= afi2family(afi
);
74 rn
= route_node_lookup(table
, &p
);
78 RNODE_FOREACH_RE (rn
, newre
) {
79 if (CHECK_FLAG(newre
->flags
, ZEBRA_FLAG_SELECTED
))
80 zsend_redistribute_route(
81 ZEBRA_REDISTRIBUTE_ROUTE_ADD
, client
,
85 route_unlock_node(rn
);
89 /* Redistribute routes. */
90 static void zebra_redistribute(struct zserv
*client
, int type
,
91 unsigned short instance
, vrf_id_t vrf_id
,
94 struct route_entry
*newre
;
95 struct route_table
*table
;
96 struct route_node
*rn
;
98 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, vrf_id
);
102 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
))
103 RNODE_FOREACH_RE (rn
, newre
) {
104 if (IS_ZEBRA_DEBUG_RIB
)
106 "%s: client %s %pRN(%u:%u) checking: selected=%d, type=%s, instance=%u, distance=%d, metric=%d zebra_check_addr=%d",
108 zebra_route_string(client
->proto
), rn
,
109 vrf_id
, newre
->instance
,
110 !!CHECK_FLAG(newre
->flags
,
111 ZEBRA_FLAG_SELECTED
),
112 zebra_route_string(newre
->type
),
116 zebra_check_addr(&rn
->p
));
118 if (!CHECK_FLAG(newre
->flags
, ZEBRA_FLAG_SELECTED
))
120 if ((type
!= ZEBRA_ROUTE_ALL
121 && (newre
->type
!= type
122 || newre
->instance
!= instance
)))
124 if (!zebra_check_addr(&rn
->p
))
127 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
133 * Function to check if prefix is candidate for
136 static bool zebra_redistribute_check(const struct route_node
*rn
,
137 const struct route_entry
*re
,
138 struct zserv
*client
)
140 struct zebra_vrf
*zvrf
;
143 /* Process only if there is valid re */
147 afi
= family2afi(rn
->p
.family
);
148 zvrf
= zebra_vrf_lookup_by_id(re
->vrf_id
);
149 if (re
->vrf_id
== VRF_DEFAULT
&& zvrf
->table_id
!= re
->table
)
152 /* If default route and redistributed */
153 if (is_default_prefix(&rn
->p
) &&
154 vrf_bitmap_check(client
->redist_default
[afi
], re
->vrf_id
))
157 /* If redistribute in enabled for zebra route all */
158 if (vrf_bitmap_check(client
->redist
[afi
][ZEBRA_ROUTE_ALL
], re
->vrf_id
))
162 * If multi-instance then check for route
163 * redistribution for given instance.
166 if (redist_check_instance(&client
->mi_redist
[afi
][re
->type
],
173 /* If redistribution is enabled for give route type. */
174 if (vrf_bitmap_check(client
->redist
[afi
][re
->type
], re
->vrf_id
))
180 /* Either advertise a route for redistribution to registered clients or */
181 /* withdraw redistribution if add cannot be done for client */
182 void redistribute_update(const struct route_node
*rn
,
183 const struct route_entry
*re
,
184 const struct route_entry
*prev_re
)
186 struct listnode
*node
, *nnode
;
187 struct zserv
*client
;
189 if (IS_ZEBRA_DEBUG_RIB
)
191 "(%u:%u):%pRN(%u): Redist update re %p (%s), old %p (%s)",
192 re
->vrf_id
, re
->table
, rn
, re
->instance
, re
,
193 zebra_route_string(re
->type
), prev_re
,
194 prev_re
? zebra_route_string(prev_re
->type
) : "None");
196 if (!zebra_check_addr(&rn
->p
)) {
197 if (IS_ZEBRA_DEBUG_RIB
)
198 zlog_debug("Redist update filter prefix %pRN", rn
);
203 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
204 if (zebra_redistribute_check(rn
, re
, client
)) {
205 if (IS_ZEBRA_DEBUG_RIB
) {
207 "%s: client %s %pRN(%u:%u), type=%d, distance=%d, metric=%d",
209 zebra_route_string(client
->proto
), rn
,
210 re
->vrf_id
, re
->table
, re
->type
,
211 re
->distance
, re
->metric
);
213 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
215 } else if (zebra_redistribute_check(rn
, prev_re
, client
))
216 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
217 client
, rn
, prev_re
);
222 * During a route delete, where 'new_re' is NULL, redist a delete to all
223 * clients registered for the type of 'old_re'.
224 * During a route update, redist a delete to any clients who will not see
225 * an update when the new route is installed. There are cases when a client
226 * may have seen a redist for 'old_re', but will not see
227 * the redist for 'new_re'.
229 void redistribute_delete(const struct route_node
*rn
,
230 const struct route_entry
*old_re
,
231 const struct route_entry
*new_re
)
233 struct listnode
*node
, *nnode
;
234 struct zserv
*client
;
238 vrfid
= old_re
->vrf_id
;
240 vrfid
= new_re
->vrf_id
;
244 if (IS_ZEBRA_DEBUG_RIB
) {
245 uint8_t old_inst
, new_inst
;
248 old_inst
= new_inst
= 0;
251 old_inst
= old_re
->instance
;
252 table
= old_re
->table
;
255 new_inst
= new_re
->instance
;
256 table
= new_re
->table
;
260 "%u:%u%pRN: Redist del: re %p (%u:%s), new re %p (%u:%s)",
261 vrfid
, table
, rn
, old_re
, old_inst
,
262 old_re
? zebra_route_string(old_re
->type
) : "None",
264 new_re
? zebra_route_string(new_re
->type
) : "None");
267 /* Skip invalid (e.g. linklocal) prefix */
268 if (!zebra_check_addr(&rn
->p
)) {
269 if (IS_ZEBRA_DEBUG_RIB
) {
271 "%u:%pRN: Redist del old: skipping invalid prefix",
277 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
278 /* Do not send unsolicited messages to synchronous clients. */
279 if (client
->synchronous
)
282 * Skip this client if it will receive an update for the
285 if (zebra_redistribute_check(rn
, new_re
, client
))
288 /* Send a delete for the 'old' re to any subscribed client. */
289 if (zebra_redistribute_check(rn
, old_re
, client
))
290 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
296 void zebra_redistribute_add(ZAPI_HANDLER_ARGS
)
300 unsigned short instance
;
302 STREAM_GETC(msg
, afi
);
303 STREAM_GETC(msg
, type
);
304 STREAM_GETW(msg
, instance
);
306 if (IS_ZEBRA_DEBUG_EVENT
)
308 "%s: client proto %s afi=%d, wants %s, vrf %s(%u), instance=%d",
309 __func__
, zebra_route_string(client
->proto
), afi
,
310 zebra_route_string(type
), VRF_LOGNAME(zvrf
->vrf
),
311 zvrf_id(zvrf
), instance
);
313 if (afi
== 0 || afi
>= AFI_MAX
) {
314 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
315 "%s: Specified afi %d does not exist", __func__
, afi
);
319 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
320 zlog_debug("%s: Specified Route Type %d does not exist",
326 if (!redist_check_instance(&client
->mi_redist
[afi
][type
],
328 redist_add_instance(&client
->mi_redist
[afi
][type
],
330 zebra_redistribute(client
, type
, instance
,
334 if (!vrf_bitmap_check(client
->redist
[afi
][type
],
336 if (IS_ZEBRA_DEBUG_EVENT
)
338 "%s: setting vrf %s(%u) redist bitmap",
339 __func__
, VRF_LOGNAME(zvrf
->vrf
),
341 vrf_bitmap_set(client
->redist
[afi
][type
],
343 zebra_redistribute(client
, type
, 0, zvrf_id(zvrf
), afi
);
351 void zebra_redistribute_delete(ZAPI_HANDLER_ARGS
)
355 unsigned short instance
;
357 STREAM_GETC(msg
, afi
);
358 STREAM_GETC(msg
, type
);
359 STREAM_GETW(msg
, instance
);
361 if (IS_ZEBRA_DEBUG_EVENT
)
363 "%s: client proto %s afi=%d, no longer wants %s, vrf %s(%u), instance=%d",
364 __func__
, zebra_route_string(client
->proto
), afi
,
365 zebra_route_string(type
), VRF_LOGNAME(zvrf
->vrf
),
366 zvrf_id(zvrf
), instance
);
369 if (afi
== 0 || afi
>= AFI_MAX
) {
370 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
371 "%s: Specified afi %d does not exist", __func__
, afi
);
375 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
376 zlog_debug("%s: Specified Route Type %d does not exist",
382 * NOTE: no need to withdraw the previously advertised routes. The
384 * themselves should keep track of the received routes from zebra and
385 * withdraw them when necessary.
388 redist_del_instance(&client
->mi_redist
[afi
][type
], instance
);
390 vrf_bitmap_unset(client
->redist
[afi
][type
], zvrf_id(zvrf
));
396 void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS
)
400 STREAM_GETC(msg
, afi
);
402 if (afi
== 0 || afi
>= AFI_MAX
) {
403 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
404 "%s: Specified afi %u does not exist", __func__
, afi
);
408 vrf_bitmap_set(client
->redist_default
[afi
], zvrf_id(zvrf
));
409 zebra_redistribute_default(client
, zvrf_id(zvrf
));
415 void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS
)
419 STREAM_GETC(msg
, afi
);
421 if (afi
== 0 || afi
>= AFI_MAX
) {
422 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
423 "%s: Specified afi %u does not exist", __func__
, afi
);
427 vrf_bitmap_unset(client
->redist_default
[afi
], zvrf_id(zvrf
));
433 /* Interface up information. */
434 void zebra_interface_up_update(struct interface
*ifp
)
436 struct listnode
*node
, *nnode
;
437 struct zserv
*client
;
439 if (IS_ZEBRA_DEBUG_EVENT
)
440 zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s vrf %s(%u)",
441 ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
);
443 if (ifp
->ptm_status
|| !ifp
->ptm_enable
) {
444 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
,
446 /* Do not send unsolicited messages to synchronous
449 if (client
->synchronous
)
452 zsend_interface_update(ZEBRA_INTERFACE_UP
,
454 zsend_interface_link_params(client
, ifp
);
459 /* Interface down information. */
460 void zebra_interface_down_update(struct interface
*ifp
)
462 struct listnode
*node
, *nnode
;
463 struct zserv
*client
;
465 if (IS_ZEBRA_DEBUG_EVENT
)
466 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s vrf %s(%u)",
467 ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
);
469 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
470 /* Do not send unsolicited messages to synchronous clients. */
471 if (client
->synchronous
)
474 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
478 /* Interface information update. */
479 void zebra_interface_add_update(struct interface
*ifp
)
481 struct listnode
*node
, *nnode
;
482 struct zserv
*client
;
484 if (IS_ZEBRA_DEBUG_EVENT
)
485 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s vrf %s(%u)",
486 ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
);
488 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
489 /* Do not send unsolicited messages to synchronous clients. */
490 if (client
->synchronous
)
494 zsend_interface_add(client
, ifp
);
495 zsend_interface_link_params(client
, ifp
);
499 void zebra_interface_delete_update(struct interface
*ifp
)
501 struct listnode
*node
, *nnode
;
502 struct zserv
*client
;
504 if (IS_ZEBRA_DEBUG_EVENT
)
505 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s vrf %s(%u)",
506 ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
);
508 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
509 /* Do not send unsolicited messages to synchronous clients. */
510 if (client
->synchronous
)
514 zsend_interface_delete(client
, ifp
);
518 /* Interface address addition. */
519 void zebra_interface_address_add_update(struct interface
*ifp
,
520 struct connected
*ifc
)
522 struct listnode
*node
, *nnode
;
523 struct zserv
*client
;
525 if (IS_ZEBRA_DEBUG_EVENT
)
527 "MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %pFX on %s vrf %s(%u)",
528 ifc
->address
, ifp
->name
, ifp
->vrf
->name
,
531 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
))
533 EC_ZEBRA_ADVERTISING_UNUSABLE_ADDR
,
534 "advertising address to clients that is not yet usable.");
536 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 1);
538 router_id_add_address(ifc
);
540 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
541 /* Do not send unsolicited messages to synchronous clients. */
542 if (client
->synchronous
)
545 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
546 client
->connected_rt_add_cnt
++;
547 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_ADD
,
553 /* Interface address deletion. */
554 void zebra_interface_address_delete_update(struct interface
*ifp
,
555 struct connected
*ifc
)
557 struct listnode
*node
, *nnode
;
558 struct zserv
*client
;
560 if (IS_ZEBRA_DEBUG_EVENT
)
562 "MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %pFX on %s vrf %s(%u)",
563 ifc
->address
, ifp
->name
, ifp
->vrf
->name
,
566 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 0);
568 router_id_del_address(ifc
);
570 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
571 /* Do not send unsolicited messages to synchronous clients. */
572 if (client
->synchronous
)
575 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
576 client
->connected_rt_del_cnt
++;
577 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_DELETE
,
583 /* Interface VRF change. May need to delete from clients not interested in
584 * the new VRF. Note that this function is invoked *prior* to the VRF change.
586 void zebra_interface_vrf_update_del(struct interface
*ifp
, vrf_id_t new_vrf_id
)
588 struct listnode
*node
, *nnode
;
589 struct zserv
*client
;
591 if (IS_ZEBRA_DEBUG_EVENT
)
593 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/DEL %s VRF Id %u -> %u",
594 ifp
->name
, ifp
->vrf
->vrf_id
, new_vrf_id
);
596 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
597 /* Do not send unsolicited messages to synchronous clients. */
598 if (client
->synchronous
)
601 /* Need to delete if the client is not interested in the new
603 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
605 zsend_interface_delete(client
, ifp
);
606 zsend_interface_vrf_update(client
, ifp
, new_vrf_id
);
610 /* Interface VRF change. This function is invoked *post* VRF change and sends an
611 * add to clients who are interested in the new VRF but not in the old VRF.
613 void zebra_interface_vrf_update_add(struct interface
*ifp
, vrf_id_t old_vrf_id
)
615 struct listnode
*node
, *nnode
;
616 struct zserv
*client
;
618 if (IS_ZEBRA_DEBUG_EVENT
)
620 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/ADD %s VRF Id %u -> %u",
621 ifp
->name
, old_vrf_id
, ifp
->vrf
->vrf_id
);
623 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
624 /* Do not send unsolicited messages to synchronous clients. */
625 if (client
->synchronous
)
628 /* Need to add if the client is interested in the new VRF. */
630 zsend_interface_add(client
, ifp
);
631 zsend_interface_addresses(client
, ifp
);
635 int zebra_add_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
636 struct route_entry
*re
, const char *rmap_name
)
638 struct route_entry
*newre
;
639 struct route_entry
*same
;
641 struct nexthop_group
*ng
;
642 route_map_result_t ret
= RMAP_PERMITMATCH
;
645 afi
= family2afi(rn
->p
.family
);
647 ret
= zebra_import_table_route_map_check(
648 afi
, re
->type
, re
->instance
, &rn
->p
,
649 re
->nhe
->nhg
.nexthop
,
650 zvrf
->vrf
->vrf_id
, re
->tag
, rmap_name
);
652 if (ret
!= RMAP_PERMITMATCH
) {
653 UNSET_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
);
654 zebra_del_import_table_entry(zvrf
, rn
, re
);
658 prefix_copy(&p
, &rn
->p
);
660 RNODE_FOREACH_RE (rn
, same
) {
661 if (CHECK_FLAG(same
->status
, ROUTE_ENTRY_REMOVED
))
664 if (same
->type
== re
->type
&& same
->instance
== re
->instance
665 && same
->table
== re
->table
666 && same
->type
!= ZEBRA_ROUTE_CONNECT
)
671 UNSET_FLAG(same
->flags
, ZEBRA_FLAG_SELECTED
);
672 zebra_del_import_table_entry(zvrf
, rn
, same
);
675 newre
= zebra_rib_route_entry_new(
676 0, ZEBRA_ROUTE_TABLE
, re
->table
, re
->flags
, re
->nhe_id
,
677 zvrf
->table_id
, re
->metric
, re
->mtu
,
678 zebra_import_table_distance
[afi
][re
->table
], re
->tag
);
680 ng
= nexthop_group_new();
681 copy_nexthops(&ng
->nexthop
, re
->nhe
->nhg
.nexthop
, NULL
);
683 rib_add_multipath(afi
, SAFI_UNICAST
, &p
, NULL
, newre
, ng
, false);
688 int zebra_del_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
689 struct route_entry
*re
)
694 afi
= family2afi(rn
->p
.family
);
695 prefix_copy(&p
, &rn
->p
);
697 rib_delete(afi
, SAFI_UNICAST
, zvrf
->vrf
->vrf_id
, ZEBRA_ROUTE_TABLE
,
698 re
->table
, re
->flags
, &p
, NULL
, re
->nhe
->nhg
.nexthop
,
699 re
->nhe_id
, zvrf
->table_id
, re
->metric
, re
->distance
,
705 /* Assuming no one calls this with the main routing table */
706 int zebra_import_table(afi_t afi
, vrf_id_t vrf_id
, uint32_t table_id
,
707 uint32_t distance
, const char *rmap_name
, int add
)
709 struct route_table
*table
;
710 struct route_entry
*re
;
711 struct route_node
*rn
;
712 struct zebra_vrf
*zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
714 if (!is_zebra_valid_kernel_table(table_id
)
715 || (table_id
== RT_TABLE_MAIN
))
721 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
, vrf_id
,
725 } else if (IS_ZEBRA_DEBUG_RIB
) {
726 zlog_debug("%s routes from table %d",
727 add
? "Importing" : "Unimporting", table_id
);
732 zebra_add_import_table_route_map(afi
, rmap_name
,
736 zebra_get_import_table_route_map(afi
, table_id
);
738 zebra_del_import_table_route_map(afi
, table_id
);
743 zebra_import_table_used
[afi
][table_id
] = 1;
744 zebra_import_table_distance
[afi
][table_id
] = distance
;
746 zebra_import_table_used
[afi
][table_id
] = 0;
747 zebra_import_table_distance
[afi
][table_id
] =
748 ZEBRA_TABLE_DISTANCE_DEFAULT
;
750 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
752 zebra_del_import_table_route_map(afi
, table_id
);
757 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
758 /* For each entry in the non-default routing table,
759 * add the entry in the main table
764 RNODE_FOREACH_RE (rn
, re
) {
765 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
773 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
774 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
))) {
776 zebra_add_import_table_entry(zvrf
, rn
, re
,
779 zebra_del_import_table_entry(zvrf
, rn
, re
);
785 int zebra_import_table_config(struct vty
*vty
, vrf_id_t vrf_id
)
790 char afi_str
[AFI_MAX
][10] = {"", "ip", "ipv6", "ethernet"};
791 const char *rmap_name
;
793 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
794 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
795 if (!is_zebra_import_table_enabled(afi
, vrf_id
, i
))
798 if (zebra_import_table_distance
[afi
][i
]
799 != ZEBRA_TABLE_DISTANCE_DEFAULT
) {
800 vty_out(vty
, "%s import-table %d distance %d",
802 zebra_import_table_distance
[afi
][i
]);
804 vty_out(vty
, "%s import-table %d", afi_str
[afi
],
808 rmap_name
= zebra_get_import_table_route_map(afi
, i
);
810 vty_out(vty
, " route-map %s", rmap_name
);
820 static void zebra_import_table_rm_update_vrf_afi(struct zebra_vrf
*zvrf
,
821 afi_t afi
, int table_id
,
824 struct route_table
*table
;
825 struct route_entry
*re
;
826 struct route_node
*rn
;
827 const char *rmap_name
;
829 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
830 if ((!rmap_name
) || (strcmp(rmap_name
, rmap
) != 0))
833 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
,
834 zvrf
->vrf
->vrf_id
, table_id
);
836 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
837 zlog_debug("%s: Table id=%d not found", __func__
,
842 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
844 * For each entry in the non-default routing table,
845 * add the entry in the main table
850 RNODE_FOREACH_RE (rn
, re
) {
851 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
859 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
860 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
)))
861 zebra_add_import_table_entry(zvrf
, rn
, re
, rmap_name
);
867 static void zebra_import_table_rm_update_vrf(struct zebra_vrf
*zvrf
,
873 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
874 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
875 if (!is_zebra_import_table_enabled(
876 afi
, zvrf
->vrf
->vrf_id
, i
))
879 zebra_import_table_rm_update_vrf_afi(zvrf
, afi
, i
,
885 void zebra_import_table_rm_update(const char *rmap
)
888 struct zebra_vrf
*zvrf
;
890 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
896 zebra_import_table_rm_update_vrf(zvrf
, rmap
);
900 /* Interface parameters update */
901 void zebra_interface_parameters_update(struct interface
*ifp
)
903 struct listnode
*node
, *nnode
;
904 struct zserv
*client
;
906 if (IS_ZEBRA_DEBUG_EVENT
)
907 zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s vrf %s(%u)",
908 ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
);
910 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
911 /* Do not send unsolicited messages to synchronous clients. */
912 if (client
->synchronous
)
915 zsend_interface_link_params(client
, ifp
);