1 /* Redistribution Handler
2 * Copyright (C) 1998 Kunihiro Ishiguro
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 "srcdest_table.h"
35 #include "zebra/rib.h"
36 #include "zebra/zebra_router.h"
37 #include "zebra/zebra_ns.h"
38 #include "zebra/zebra_vrf.h"
39 #include "zebra/zebra_routemap.h"
40 #include "zebra/redistribute.h"
41 #include "zebra/debug.h"
42 #include "zebra/router-id.h"
43 #include "zebra/zapi_msg.h"
44 #include "zebra/zebra_vxlan.h"
45 #include "zebra/zebra_errors.h"
47 #define ZEBRA_PTM_SUPPORT
49 /* array holding redistribute info about table redistribution */
50 /* bit AFI is set if that AFI is redistributing routes from this table */
51 static int zebra_import_table_used
[AFI_MAX
][ZEBRA_KERNEL_TABLE_MAX
];
52 static uint32_t zebra_import_table_distance
[AFI_MAX
][ZEBRA_KERNEL_TABLE_MAX
];
54 int is_zebra_import_table_enabled(afi_t afi
, vrf_id_t vrf_id
, uint32_t table_id
)
57 * Make sure that what we are called with actualy makes sense
62 if (is_zebra_valid_kernel_table(table_id
) &&
63 table_id
< ZEBRA_KERNEL_TABLE_MAX
)
64 return zebra_import_table_used
[afi
][table_id
];
68 static void zebra_redistribute_default(struct zserv
*client
, vrf_id_t vrf_id
)
72 struct route_table
*table
;
73 struct route_node
*rn
;
74 struct route_entry
*newre
;
76 for (afi
= AFI_IP
; afi
<= AFI_IP6
; afi
++) {
78 if (!vrf_bitmap_check(client
->redist_default
[afi
], vrf_id
))
82 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, vrf_id
);
86 /* Lookup default route. */
87 memset(&p
, 0, sizeof(p
));
88 p
.family
= afi2family(afi
);
89 rn
= route_node_lookup(table
, &p
);
93 RNODE_FOREACH_RE (rn
, newre
) {
94 if (CHECK_FLAG(newre
->flags
, ZEBRA_FLAG_SELECTED
))
95 zsend_redistribute_route(
96 ZEBRA_REDISTRIBUTE_ROUTE_ADD
, client
,
100 route_unlock_node(rn
);
104 /* Redistribute routes. */
105 static void zebra_redistribute(struct zserv
*client
, int type
,
106 unsigned short instance
, vrf_id_t vrf_id
,
109 struct route_entry
*newre
;
110 struct route_table
*table
;
111 struct route_node
*rn
;
113 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, vrf_id
);
117 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
))
118 RNODE_FOREACH_RE (rn
, newre
) {
119 const struct prefix
*dst_p
, *src_p
;
121 srcdest_rnode_prefixes(rn
, &dst_p
, &src_p
);
123 if (IS_ZEBRA_DEBUG_RIB
)
125 "%s: client %s %pFX(%u) checking: selected=%d, type=%d, distance=%d, metric=%d zebra_check_addr=%d",
127 zebra_route_string(client
->proto
),
129 CHECK_FLAG(newre
->flags
,
130 ZEBRA_FLAG_SELECTED
),
131 newre
->type
, newre
->distance
,
132 newre
->metric
, zebra_check_addr(dst_p
));
134 if (!CHECK_FLAG(newre
->flags
, ZEBRA_FLAG_SELECTED
))
136 if ((type
!= ZEBRA_ROUTE_ALL
137 && (newre
->type
!= type
138 || newre
->instance
!= instance
)))
140 if (!zebra_check_addr(dst_p
))
143 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
144 client
, dst_p
, src_p
, newre
);
149 * Function to check if prefix is candidate for
152 static bool zebra_redistribute_check(const struct route_entry
*re
,
153 struct zserv
*client
,
154 const struct prefix
*p
, int afi
)
156 /* Process only if there is valid re */
160 /* If default route and redistributed */
161 if (is_default_prefix(p
)
162 && vrf_bitmap_check(client
->redist_default
[afi
], re
->vrf_id
))
165 /* If redistribute in enabled for zebra route all */
166 if (vrf_bitmap_check(client
->redist
[afi
][ZEBRA_ROUTE_ALL
], re
->vrf_id
))
170 * If multi-instance then check for route
171 * redistribution for given instance.
174 && redist_check_instance(&client
->mi_redist
[afi
][re
->type
],
178 /* If redistribution is enabled for give route type. */
179 if (vrf_bitmap_check(client
->redist
[afi
][re
->type
], re
->vrf_id
))
185 /* Either advertise a route for redistribution to registered clients or */
186 /* withdraw redistribution if add cannot be done for client */
187 void redistribute_update(const struct prefix
*p
, const struct prefix
*src_p
,
188 const struct route_entry
*re
,
189 const struct route_entry
*prev_re
)
191 struct listnode
*node
, *nnode
;
192 struct zserv
*client
;
195 if (IS_ZEBRA_DEBUG_RIB
)
197 "(%u:%u):%pFX: Redist update re %p (%s), old %p (%s)",
198 re
->vrf_id
, re
->table
, p
, re
,
199 zebra_route_string(re
->type
), prev_re
,
200 prev_re
? zebra_route_string(prev_re
->type
) : "None");
202 afi
= family2afi(p
->family
);
204 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
205 "%s: Unknown AFI/SAFI prefix received", __func__
);
208 if (!zebra_check_addr(p
)) {
209 if (IS_ZEBRA_DEBUG_RIB
)
210 zlog_debug("Redist update filter prefix %pFX", p
);
215 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
216 if (zebra_redistribute_check(re
, client
, p
, afi
)) {
217 if (IS_ZEBRA_DEBUG_RIB
) {
219 "%s: client %s %pFX(%u:%u), type=%d, distance=%d, metric=%d",
221 zebra_route_string(client
->proto
), p
,
222 re
->vrf_id
, re
->table
, re
->type
,
223 re
->distance
, re
->metric
);
225 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
226 client
, p
, src_p
, re
);
227 } else if (zebra_redistribute_check(prev_re
, client
, p
, afi
))
228 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
229 client
, p
, src_p
, prev_re
);
234 * During a route delete, where 'new_re' is NULL, redist a delete to all
235 * clients registered for the type of 'old_re'.
236 * During a route update, redist a delete to any clients who will not see
237 * an update when the new route is installed. There are cases when a client
238 * may have seen a redist for 'old_re', but will not see
239 * the redist for 'new_re'.
241 void redistribute_delete(const struct prefix
*p
, const struct prefix
*src_p
,
242 const struct route_entry
*old_re
,
243 const struct route_entry
*new_re
)
245 struct listnode
*node
, *nnode
;
246 struct zserv
*client
;
251 vrfid
= old_re
->vrf_id
;
253 vrfid
= new_re
->vrf_id
;
257 if (IS_ZEBRA_DEBUG_RIB
) {
258 zlog_debug("%u:%pFX: Redist del: re %p (%s), new re %p (%s)",
260 old_re
? zebra_route_string(old_re
->type
) : "None",
262 new_re
? zebra_route_string(new_re
->type
) : "None");
265 afi
= family2afi(p
->family
);
267 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
268 "%s: Unknown AFI/SAFI prefix received",
273 /* Skip invalid (e.g. linklocal) prefix */
274 if (!zebra_check_addr(p
)) {
275 if (IS_ZEBRA_DEBUG_RIB
) {
277 "%u:%pFX: Redist del old: skipping invalid prefix",
283 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
284 /* Do not send unsolicited messages to synchronous clients. */
285 if (client
->synchronous
)
288 * Skip this client if it will receive an update for the
291 if (zebra_redistribute_check(new_re
, client
, p
, afi
))
294 /* Send a delete for the 'old' re to any subscribed client. */
295 if (zebra_redistribute_check(old_re
, client
, p
, afi
))
296 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
297 client
, p
, src_p
, old_re
);
302 void zebra_redistribute_add(ZAPI_HANDLER_ARGS
)
306 unsigned short instance
;
308 STREAM_GETC(msg
, afi
);
309 STREAM_GETC(msg
, type
);
310 STREAM_GETW(msg
, instance
);
312 if (IS_ZEBRA_DEBUG_EVENT
)
314 "%s: client proto %s afi=%d, wants %s, vrf %s(%u), instance=%d",
315 __func__
, zebra_route_string(client
->proto
), afi
,
316 zebra_route_string(type
), VRF_LOGNAME(zvrf
->vrf
),
317 zvrf_id(zvrf
), instance
);
319 if (afi
== 0 || afi
>= AFI_MAX
) {
320 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
321 "%s: Specified afi %d does not exist", __func__
, afi
);
325 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
326 zlog_debug("%s: Specified Route Type %d does not exist",
332 if (!redist_check_instance(&client
->mi_redist
[afi
][type
],
334 redist_add_instance(&client
->mi_redist
[afi
][type
],
336 zebra_redistribute(client
, type
, instance
,
340 if (!vrf_bitmap_check(client
->redist
[afi
][type
],
342 if (IS_ZEBRA_DEBUG_EVENT
)
344 "%s: setting vrf %s(%u) redist bitmap",
345 __func__
, VRF_LOGNAME(zvrf
->vrf
),
347 vrf_bitmap_set(client
->redist
[afi
][type
],
349 zebra_redistribute(client
, type
, 0, zvrf_id(zvrf
), afi
);
357 void zebra_redistribute_delete(ZAPI_HANDLER_ARGS
)
361 unsigned short instance
;
363 STREAM_GETC(msg
, afi
);
364 STREAM_GETC(msg
, type
);
365 STREAM_GETW(msg
, instance
);
367 if (IS_ZEBRA_DEBUG_EVENT
)
369 "%s: client proto %s afi=%d, no longer wants %s, vrf %s(%u), instance=%d",
370 __func__
, zebra_route_string(client
->proto
), afi
,
371 zebra_route_string(type
), VRF_LOGNAME(zvrf
->vrf
),
372 zvrf_id(zvrf
), instance
);
375 if (afi
== 0 || afi
>= AFI_MAX
) {
376 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
377 "%s: Specified afi %d does not exist", __func__
, afi
);
381 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
382 zlog_debug("%s: Specified Route Type %d does not exist",
388 * NOTE: no need to withdraw the previously advertised routes. The
390 * themselves should keep track of the received routes from zebra and
391 * withdraw them when necessary.
394 redist_del_instance(&client
->mi_redist
[afi
][type
], instance
);
396 vrf_bitmap_unset(client
->redist
[afi
][type
], zvrf_id(zvrf
));
402 void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS
)
406 STREAM_GETC(msg
, afi
);
408 if (afi
== 0 || afi
>= AFI_MAX
) {
409 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
410 "%s: Specified afi %u does not exist", __func__
, afi
);
414 vrf_bitmap_set(client
->redist_default
[afi
], zvrf_id(zvrf
));
415 zebra_redistribute_default(client
, zvrf_id(zvrf
));
421 void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS
)
425 STREAM_GETC(msg
, afi
);
427 if (afi
== 0 || afi
>= AFI_MAX
) {
428 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
429 "%s: Specified afi %u does not exist", __func__
, afi
);
433 vrf_bitmap_unset(client
->redist_default
[afi
], zvrf_id(zvrf
));
439 /* Interface up information. */
440 void zebra_interface_up_update(struct interface
*ifp
)
442 struct listnode
*node
, *nnode
;
443 struct zserv
*client
;
445 if (IS_ZEBRA_DEBUG_EVENT
)
446 zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s(%u)",
447 ifp
->name
, ifp
->vrf_id
);
449 if (ifp
->ptm_status
|| !ifp
->ptm_enable
) {
450 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
,
452 /* Do not send unsolicited messages to synchronous
455 if (client
->synchronous
)
458 zsend_interface_update(ZEBRA_INTERFACE_UP
,
460 zsend_interface_link_params(client
, ifp
);
465 /* Interface down information. */
466 void zebra_interface_down_update(struct interface
*ifp
)
468 struct listnode
*node
, *nnode
;
469 struct zserv
*client
;
471 if (IS_ZEBRA_DEBUG_EVENT
)
472 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s(%u)",
473 ifp
->name
, ifp
->vrf_id
);
475 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
476 /* Do not send unsolicited messages to synchronous clients. */
477 if (client
->synchronous
)
480 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
484 /* Interface information update. */
485 void zebra_interface_add_update(struct interface
*ifp
)
487 struct listnode
*node
, *nnode
;
488 struct zserv
*client
;
490 if (IS_ZEBRA_DEBUG_EVENT
)
491 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s(%u)", ifp
->name
,
494 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
495 /* Do not send unsolicited messages to synchronous clients. */
496 if (client
->synchronous
)
500 zsend_interface_add(client
, ifp
);
501 zsend_interface_link_params(client
, ifp
);
505 void zebra_interface_delete_update(struct interface
*ifp
)
507 struct listnode
*node
, *nnode
;
508 struct zserv
*client
;
510 if (IS_ZEBRA_DEBUG_EVENT
)
511 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s(%u)",
512 ifp
->name
, ifp
->vrf_id
);
514 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
515 /* Do not send unsolicited messages to synchronous clients. */
516 if (client
->synchronous
)
520 zsend_interface_delete(client
, ifp
);
524 /* Interface address addition. */
525 void zebra_interface_address_add_update(struct interface
*ifp
,
526 struct connected
*ifc
)
528 struct listnode
*node
, *nnode
;
529 struct zserv
*client
;
532 if (IS_ZEBRA_DEBUG_EVENT
) {
535 "MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %pFX on %s(%u)",
536 p
, ifp
->name
, ifp
->vrf_id
);
539 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
))
541 EC_ZEBRA_ADVERTISING_UNUSABLE_ADDR
,
542 "advertising address to clients that is not yet usable.");
544 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 1);
546 router_id_add_address(ifc
);
548 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
549 /* Do not send unsolicited messages to synchronous clients. */
550 if (client
->synchronous
)
553 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
554 client
->connected_rt_add_cnt
++;
555 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_ADD
,
561 /* Interface address deletion. */
562 void zebra_interface_address_delete_update(struct interface
*ifp
,
563 struct connected
*ifc
)
565 struct listnode
*node
, *nnode
;
566 struct zserv
*client
;
569 if (IS_ZEBRA_DEBUG_EVENT
) {
572 "MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %pFX on %s(%u)",
573 p
, ifp
->name
, ifp
->vrf_id
);
576 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 0);
578 router_id_del_address(ifc
);
580 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
581 /* Do not send unsolicited messages to synchronous clients. */
582 if (client
->synchronous
)
585 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
586 client
->connected_rt_del_cnt
++;
587 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_DELETE
,
593 /* Interface VRF change. May need to delete from clients not interested in
594 * the new VRF. Note that this function is invoked *prior* to the VRF change.
596 void zebra_interface_vrf_update_del(struct interface
*ifp
, vrf_id_t new_vrf_id
)
598 struct listnode
*node
, *nnode
;
599 struct zserv
*client
;
601 if (IS_ZEBRA_DEBUG_EVENT
)
603 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/DEL %s VRF Id %u -> %u",
604 ifp
->name
, ifp
->vrf_id
, new_vrf_id
);
606 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
607 /* Do not send unsolicited messages to synchronous clients. */
608 if (client
->synchronous
)
611 /* Need to delete if the client is not interested in the new
613 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
615 zsend_interface_delete(client
, ifp
);
616 zsend_interface_vrf_update(client
, ifp
, new_vrf_id
);
620 /* Interface VRF change. This function is invoked *post* VRF change and sends an
621 * add to clients who are interested in the new VRF but not in the old VRF.
623 void zebra_interface_vrf_update_add(struct interface
*ifp
, vrf_id_t old_vrf_id
)
625 struct listnode
*node
, *nnode
;
626 struct zserv
*client
;
628 if (IS_ZEBRA_DEBUG_EVENT
)
630 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/ADD %s VRF Id %u -> %u",
631 ifp
->name
, old_vrf_id
, ifp
->vrf_id
);
633 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
634 /* Do not send unsolicited messages to synchronous clients. */
635 if (client
->synchronous
)
638 /* Need to add if the client is interested in the new VRF. */
640 zsend_interface_add(client
, ifp
);
641 zsend_interface_addresses(client
, ifp
);
645 int zebra_add_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
646 struct route_entry
*re
, const char *rmap_name
)
648 struct route_entry
*newre
;
649 struct route_entry
*same
;
651 struct nexthop_group
*ng
;
652 route_map_result_t ret
= RMAP_PERMITMATCH
;
655 afi
= family2afi(rn
->p
.family
);
657 ret
= zebra_import_table_route_map_check(
658 afi
, re
->type
, re
->instance
, &rn
->p
,
659 re
->nhe
->nhg
.nexthop
,
660 zvrf
->vrf
->vrf_id
, re
->tag
, rmap_name
);
662 if (ret
!= RMAP_PERMITMATCH
) {
663 UNSET_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
);
664 zebra_del_import_table_entry(zvrf
, rn
, re
);
668 prefix_copy(&p
, &rn
->p
);
670 RNODE_FOREACH_RE (rn
, same
) {
671 if (CHECK_FLAG(same
->status
, ROUTE_ENTRY_REMOVED
))
674 if (same
->type
== re
->type
&& same
->instance
== re
->instance
675 && same
->table
== re
->table
676 && same
->type
!= ZEBRA_ROUTE_CONNECT
)
681 UNSET_FLAG(same
->flags
, ZEBRA_FLAG_SELECTED
);
682 zebra_del_import_table_entry(zvrf
, rn
, same
);
685 newre
= XCALLOC(MTYPE_RE
, sizeof(struct route_entry
));
686 newre
->type
= ZEBRA_ROUTE_TABLE
;
687 newre
->distance
= zebra_import_table_distance
[afi
][re
->table
];
688 newre
->flags
= re
->flags
;
689 newre
->metric
= re
->metric
;
690 newre
->mtu
= re
->mtu
;
691 newre
->table
= zvrf
->table_id
;
692 newre
->uptime
= monotime(NULL
);
693 newre
->instance
= re
->table
;
695 ng
= nexthop_group_new();
696 copy_nexthops(&ng
->nexthop
, re
->nhe
->nhg
.nexthop
, NULL
);
698 rib_add_multipath(afi
, SAFI_UNICAST
, &p
, NULL
, newre
, ng
);
703 int zebra_del_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
704 struct route_entry
*re
)
709 afi
= family2afi(rn
->p
.family
);
710 prefix_copy(&p
, &rn
->p
);
712 rib_delete(afi
, SAFI_UNICAST
, zvrf
->vrf
->vrf_id
, ZEBRA_ROUTE_TABLE
,
713 re
->table
, re
->flags
, &p
, NULL
, re
->nhe
->nhg
.nexthop
,
714 re
->nhe_id
, zvrf
->table_id
, re
->metric
, re
->distance
,
720 /* Assuming no one calls this with the main routing table */
721 int zebra_import_table(afi_t afi
, vrf_id_t vrf_id
, uint32_t table_id
,
722 uint32_t distance
, const char *rmap_name
, int add
)
724 struct route_table
*table
;
725 struct route_entry
*re
;
726 struct route_node
*rn
;
727 struct zebra_vrf
*zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
729 if (!is_zebra_valid_kernel_table(table_id
)
730 || (table_id
== RT_TABLE_MAIN
))
736 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
, vrf_id
,
740 } else if (IS_ZEBRA_DEBUG_RIB
) {
741 zlog_debug("%s routes from table %d",
742 add
? "Importing" : "Unimporting", table_id
);
747 zebra_add_import_table_route_map(afi
, rmap_name
,
751 zebra_get_import_table_route_map(afi
, table_id
);
753 zebra_del_import_table_route_map(afi
, table_id
);
758 zebra_import_table_used
[afi
][table_id
] = 1;
759 zebra_import_table_distance
[afi
][table_id
] = distance
;
761 zebra_import_table_used
[afi
][table_id
] = 0;
762 zebra_import_table_distance
[afi
][table_id
] =
763 ZEBRA_TABLE_DISTANCE_DEFAULT
;
765 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
767 zebra_del_import_table_route_map(afi
, table_id
);
772 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
773 /* For each entry in the non-default routing table,
774 * add the entry in the main table
779 RNODE_FOREACH_RE (rn
, re
) {
780 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
788 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
789 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
))) {
791 zebra_add_import_table_entry(zvrf
, rn
, re
,
794 zebra_del_import_table_entry(zvrf
, rn
, re
);
800 int zebra_import_table_config(struct vty
*vty
, vrf_id_t vrf_id
)
805 char afi_str
[AFI_MAX
][10] = {"", "ip", "ipv6", "ethernet"};
806 const char *rmap_name
;
808 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
809 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
810 if (!is_zebra_import_table_enabled(afi
, vrf_id
, i
))
813 if (zebra_import_table_distance
[afi
][i
]
814 != ZEBRA_TABLE_DISTANCE_DEFAULT
) {
815 vty_out(vty
, "%s import-table %d distance %d",
817 zebra_import_table_distance
[afi
][i
]);
819 vty_out(vty
, "%s import-table %d", afi_str
[afi
],
823 rmap_name
= zebra_get_import_table_route_map(afi
, i
);
825 vty_out(vty
, " route-map %s", rmap_name
);
835 static void zebra_import_table_rm_update_vrf_afi(struct zebra_vrf
*zvrf
,
836 afi_t afi
, int table_id
,
839 struct route_table
*table
;
840 struct route_entry
*re
;
841 struct route_node
*rn
;
842 const char *rmap_name
;
844 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
845 if ((!rmap_name
) || (strcmp(rmap_name
, rmap
) != 0))
848 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
,
849 zvrf
->vrf
->vrf_id
, table_id
);
851 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
852 zlog_debug("%s: Table id=%d not found", __func__
,
857 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
859 * For each entry in the non-default routing table,
860 * add the entry in the main table
865 RNODE_FOREACH_RE (rn
, re
) {
866 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
874 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
875 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
)))
876 zebra_add_import_table_entry(zvrf
, rn
, re
, rmap_name
);
882 static void zebra_import_table_rm_update_vrf(struct zebra_vrf
*zvrf
,
888 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
889 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
890 if (!is_zebra_import_table_enabled(
891 afi
, zvrf
->vrf
->vrf_id
, i
))
894 zebra_import_table_rm_update_vrf_afi(zvrf
, afi
, i
,
900 void zebra_import_table_rm_update(const char *rmap
)
903 struct zebra_vrf
*zvrf
;
905 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
911 zebra_import_table_rm_update_vrf(zvrf
, rmap
);
915 /* Interface parameters update */
916 void zebra_interface_parameters_update(struct interface
*ifp
)
918 struct listnode
*node
, *nnode
;
919 struct zserv
*client
;
921 if (IS_ZEBRA_DEBUG_EVENT
)
922 zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s(%u)",
923 ifp
->name
, ifp
->vrf_id
);
925 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
926 /* Do not send unsolicited messages to synchronous clients. */
927 if (client
->synchronous
)
930 zsend_interface_link_params(client
, ifp
);