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 struct zebra_vrf
*zvrf
;
158 /* Process only if there is valid re */
162 zvrf
= vrf_info_lookup(re
->vrf_id
);
163 if (re
->vrf_id
== VRF_DEFAULT
&& zvrf
->table_id
!= re
->table
)
166 /* If default route and redistributed */
167 if (is_default_prefix(p
)
168 && vrf_bitmap_check(client
->redist_default
[afi
], re
->vrf_id
))
171 /* If redistribute in enabled for zebra route all */
172 if (vrf_bitmap_check(client
->redist
[afi
][ZEBRA_ROUTE_ALL
], re
->vrf_id
))
176 * If multi-instance then check for route
177 * redistribution for given instance.
180 && redist_check_instance(&client
->mi_redist
[afi
][re
->type
],
184 /* If redistribution is enabled for give route type. */
185 if (vrf_bitmap_check(client
->redist
[afi
][re
->type
], re
->vrf_id
))
191 /* Either advertise a route for redistribution to registered clients or */
192 /* withdraw redistribution if add cannot be done for client */
193 void redistribute_update(const struct prefix
*p
, const struct prefix
*src_p
,
194 const struct route_entry
*re
,
195 const struct route_entry
*prev_re
)
197 struct listnode
*node
, *nnode
;
198 struct zserv
*client
;
201 if (IS_ZEBRA_DEBUG_RIB
)
203 "(%u:%u):%pFX: Redist update re %p (%s), old %p (%s)",
204 re
->vrf_id
, re
->table
, p
, re
,
205 zebra_route_string(re
->type
), prev_re
,
206 prev_re
? zebra_route_string(prev_re
->type
) : "None");
208 afi
= family2afi(p
->family
);
210 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
211 "%s: Unknown AFI/SAFI prefix received", __func__
);
214 if (!zebra_check_addr(p
)) {
215 if (IS_ZEBRA_DEBUG_RIB
)
216 zlog_debug("Redist update filter prefix %pFX", p
);
221 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
222 if (zebra_redistribute_check(re
, client
, p
, afi
)) {
223 if (IS_ZEBRA_DEBUG_RIB
) {
225 "%s: client %s %pFX(%u:%u), type=%d, distance=%d, metric=%d",
227 zebra_route_string(client
->proto
), p
,
228 re
->vrf_id
, re
->table
, re
->type
,
229 re
->distance
, re
->metric
);
231 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
232 client
, p
, src_p
, re
);
233 } else if (zebra_redistribute_check(prev_re
, client
, p
, afi
))
234 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
235 client
, p
, src_p
, prev_re
);
240 * During a route delete, where 'new_re' is NULL, redist a delete to all
241 * clients registered for the type of 'old_re'.
242 * During a route update, redist a delete to any clients who will not see
243 * an update when the new route is installed. There are cases when a client
244 * may have seen a redist for 'old_re', but will not see
245 * the redist for 'new_re'.
247 void redistribute_delete(const struct prefix
*p
, const struct prefix
*src_p
,
248 const struct route_entry
*old_re
,
249 const struct route_entry
*new_re
)
251 struct listnode
*node
, *nnode
;
252 struct zserv
*client
;
257 vrfid
= old_re
->vrf_id
;
259 vrfid
= new_re
->vrf_id
;
263 if (IS_ZEBRA_DEBUG_RIB
) {
264 zlog_debug("%u:%pFX: Redist del: re %p (%s), new re %p (%s)",
266 old_re
? zebra_route_string(old_re
->type
) : "None",
268 new_re
? zebra_route_string(new_re
->type
) : "None");
271 afi
= family2afi(p
->family
);
273 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
274 "%s: Unknown AFI/SAFI prefix received",
279 /* Skip invalid (e.g. linklocal) prefix */
280 if (!zebra_check_addr(p
)) {
281 if (IS_ZEBRA_DEBUG_RIB
) {
283 "%u:%pFX: Redist del old: skipping invalid prefix",
289 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
290 /* Do not send unsolicited messages to synchronous clients. */
291 if (client
->synchronous
)
294 * Skip this client if it will receive an update for the
297 if (zebra_redistribute_check(new_re
, client
, p
, afi
))
300 /* Send a delete for the 'old' re to any subscribed client. */
301 if (zebra_redistribute_check(old_re
, client
, p
, afi
))
302 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
303 client
, p
, src_p
, old_re
);
308 void zebra_redistribute_add(ZAPI_HANDLER_ARGS
)
312 unsigned short instance
;
314 STREAM_GETC(msg
, afi
);
315 STREAM_GETC(msg
, type
);
316 STREAM_GETW(msg
, instance
);
318 if (IS_ZEBRA_DEBUG_EVENT
)
320 "%s: client proto %s afi=%d, wants %s, vrf %s(%u), instance=%d",
321 __func__
, zebra_route_string(client
->proto
), afi
,
322 zebra_route_string(type
), VRF_LOGNAME(zvrf
->vrf
),
323 zvrf_id(zvrf
), instance
);
325 if (afi
== 0 || afi
>= AFI_MAX
) {
326 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
327 "%s: Specified afi %d does not exist", __func__
, afi
);
331 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
332 zlog_debug("%s: Specified Route Type %d does not exist",
338 if (!redist_check_instance(&client
->mi_redist
[afi
][type
],
340 redist_add_instance(&client
->mi_redist
[afi
][type
],
342 zebra_redistribute(client
, type
, instance
,
346 if (!vrf_bitmap_check(client
->redist
[afi
][type
],
348 if (IS_ZEBRA_DEBUG_EVENT
)
350 "%s: setting vrf %s(%u) redist bitmap",
351 __func__
, VRF_LOGNAME(zvrf
->vrf
),
353 vrf_bitmap_set(client
->redist
[afi
][type
],
355 zebra_redistribute(client
, type
, 0, zvrf_id(zvrf
), afi
);
363 void zebra_redistribute_delete(ZAPI_HANDLER_ARGS
)
367 unsigned short instance
;
369 STREAM_GETC(msg
, afi
);
370 STREAM_GETC(msg
, type
);
371 STREAM_GETW(msg
, instance
);
373 if (IS_ZEBRA_DEBUG_EVENT
)
375 "%s: client proto %s afi=%d, no longer wants %s, vrf %s(%u), instance=%d",
376 __func__
, zebra_route_string(client
->proto
), afi
,
377 zebra_route_string(type
), VRF_LOGNAME(zvrf
->vrf
),
378 zvrf_id(zvrf
), instance
);
381 if (afi
== 0 || afi
>= AFI_MAX
) {
382 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
383 "%s: Specified afi %d does not exist", __func__
, afi
);
387 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
388 zlog_debug("%s: Specified Route Type %d does not exist",
394 * NOTE: no need to withdraw the previously advertised routes. The
396 * themselves should keep track of the received routes from zebra and
397 * withdraw them when necessary.
400 redist_del_instance(&client
->mi_redist
[afi
][type
], instance
);
402 vrf_bitmap_unset(client
->redist
[afi
][type
], zvrf_id(zvrf
));
408 void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS
)
412 STREAM_GETC(msg
, afi
);
414 if (afi
== 0 || afi
>= AFI_MAX
) {
415 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
416 "%s: Specified afi %u does not exist", __func__
, afi
);
420 vrf_bitmap_set(client
->redist_default
[afi
], zvrf_id(zvrf
));
421 zebra_redistribute_default(client
, zvrf_id(zvrf
));
427 void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS
)
431 STREAM_GETC(msg
, afi
);
433 if (afi
== 0 || afi
>= AFI_MAX
) {
434 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
435 "%s: Specified afi %u does not exist", __func__
, afi
);
439 vrf_bitmap_unset(client
->redist_default
[afi
], zvrf_id(zvrf
));
445 /* Interface up information. */
446 void zebra_interface_up_update(struct interface
*ifp
)
448 struct listnode
*node
, *nnode
;
449 struct zserv
*client
;
451 if (IS_ZEBRA_DEBUG_EVENT
)
452 zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s(%u)",
453 ifp
->name
, ifp
->vrf_id
);
455 if (ifp
->ptm_status
|| !ifp
->ptm_enable
) {
456 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
,
458 /* Do not send unsolicited messages to synchronous
461 if (client
->synchronous
)
464 zsend_interface_update(ZEBRA_INTERFACE_UP
,
466 zsend_interface_link_params(client
, ifp
);
471 /* Interface down information. */
472 void zebra_interface_down_update(struct interface
*ifp
)
474 struct listnode
*node
, *nnode
;
475 struct zserv
*client
;
477 if (IS_ZEBRA_DEBUG_EVENT
)
478 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s(%u)",
479 ifp
->name
, ifp
->vrf_id
);
481 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
482 /* Do not send unsolicited messages to synchronous clients. */
483 if (client
->synchronous
)
486 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
490 /* Interface information update. */
491 void zebra_interface_add_update(struct interface
*ifp
)
493 struct listnode
*node
, *nnode
;
494 struct zserv
*client
;
496 if (IS_ZEBRA_DEBUG_EVENT
)
497 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s(%u)", ifp
->name
,
500 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
501 /* Do not send unsolicited messages to synchronous clients. */
502 if (client
->synchronous
)
506 zsend_interface_add(client
, ifp
);
507 zsend_interface_link_params(client
, ifp
);
511 void zebra_interface_delete_update(struct interface
*ifp
)
513 struct listnode
*node
, *nnode
;
514 struct zserv
*client
;
516 if (IS_ZEBRA_DEBUG_EVENT
)
517 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s(%u)",
518 ifp
->name
, ifp
->vrf_id
);
520 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
521 /* Do not send unsolicited messages to synchronous clients. */
522 if (client
->synchronous
)
526 zsend_interface_delete(client
, ifp
);
530 /* Interface address addition. */
531 void zebra_interface_address_add_update(struct interface
*ifp
,
532 struct connected
*ifc
)
534 struct listnode
*node
, *nnode
;
535 struct zserv
*client
;
538 if (IS_ZEBRA_DEBUG_EVENT
) {
541 "MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %pFX on %s(%u)",
542 p
, ifp
->name
, ifp
->vrf_id
);
545 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
))
547 EC_ZEBRA_ADVERTISING_UNUSABLE_ADDR
,
548 "advertising address to clients that is not yet usable.");
550 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 1);
552 router_id_add_address(ifc
);
554 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
555 /* Do not send unsolicited messages to synchronous clients. */
556 if (client
->synchronous
)
559 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
560 client
->connected_rt_add_cnt
++;
561 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_ADD
,
567 /* Interface address deletion. */
568 void zebra_interface_address_delete_update(struct interface
*ifp
,
569 struct connected
*ifc
)
571 struct listnode
*node
, *nnode
;
572 struct zserv
*client
;
575 if (IS_ZEBRA_DEBUG_EVENT
) {
578 "MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %pFX on %s(%u)",
579 p
, ifp
->name
, ifp
->vrf_id
);
582 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 0);
584 router_id_del_address(ifc
);
586 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
587 /* Do not send unsolicited messages to synchronous clients. */
588 if (client
->synchronous
)
591 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
592 client
->connected_rt_del_cnt
++;
593 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_DELETE
,
599 /* Interface VRF change. May need to delete from clients not interested in
600 * the new VRF. Note that this function is invoked *prior* to the VRF change.
602 void zebra_interface_vrf_update_del(struct interface
*ifp
, vrf_id_t new_vrf_id
)
604 struct listnode
*node
, *nnode
;
605 struct zserv
*client
;
607 if (IS_ZEBRA_DEBUG_EVENT
)
609 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/DEL %s VRF Id %u -> %u",
610 ifp
->name
, ifp
->vrf_id
, new_vrf_id
);
612 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
613 /* Do not send unsolicited messages to synchronous clients. */
614 if (client
->synchronous
)
617 /* Need to delete if the client is not interested in the new
619 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
621 zsend_interface_delete(client
, ifp
);
622 zsend_interface_vrf_update(client
, ifp
, new_vrf_id
);
626 /* Interface VRF change. This function is invoked *post* VRF change and sends an
627 * add to clients who are interested in the new VRF but not in the old VRF.
629 void zebra_interface_vrf_update_add(struct interface
*ifp
, vrf_id_t old_vrf_id
)
631 struct listnode
*node
, *nnode
;
632 struct zserv
*client
;
634 if (IS_ZEBRA_DEBUG_EVENT
)
636 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/ADD %s VRF Id %u -> %u",
637 ifp
->name
, old_vrf_id
, ifp
->vrf_id
);
639 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
640 /* Do not send unsolicited messages to synchronous clients. */
641 if (client
->synchronous
)
644 /* Need to add if the client is interested in the new VRF. */
646 zsend_interface_add(client
, ifp
);
647 zsend_interface_addresses(client
, ifp
);
651 int zebra_add_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
652 struct route_entry
*re
, const char *rmap_name
)
654 struct route_entry
*newre
;
655 struct route_entry
*same
;
657 struct nexthop_group
*ng
;
658 route_map_result_t ret
= RMAP_PERMITMATCH
;
661 afi
= family2afi(rn
->p
.family
);
663 ret
= zebra_import_table_route_map_check(
664 afi
, re
->type
, re
->instance
, &rn
->p
,
665 re
->nhe
->nhg
.nexthop
,
666 zvrf
->vrf
->vrf_id
, re
->tag
, rmap_name
);
668 if (ret
!= RMAP_PERMITMATCH
) {
669 UNSET_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
);
670 zebra_del_import_table_entry(zvrf
, rn
, re
);
674 prefix_copy(&p
, &rn
->p
);
676 RNODE_FOREACH_RE (rn
, same
) {
677 if (CHECK_FLAG(same
->status
, ROUTE_ENTRY_REMOVED
))
680 if (same
->type
== re
->type
&& same
->instance
== re
->instance
681 && same
->table
== re
->table
682 && same
->type
!= ZEBRA_ROUTE_CONNECT
)
687 UNSET_FLAG(same
->flags
, ZEBRA_FLAG_SELECTED
);
688 zebra_del_import_table_entry(zvrf
, rn
, same
);
691 newre
= XCALLOC(MTYPE_RE
, sizeof(struct route_entry
));
692 newre
->type
= ZEBRA_ROUTE_TABLE
;
693 newre
->distance
= zebra_import_table_distance
[afi
][re
->table
];
694 newre
->flags
= re
->flags
;
695 newre
->metric
= re
->metric
;
696 newre
->mtu
= re
->mtu
;
697 newre
->table
= zvrf
->table_id
;
698 newre
->uptime
= monotime(NULL
);
699 newre
->instance
= re
->table
;
701 ng
= nexthop_group_new();
702 copy_nexthops(&ng
->nexthop
, re
->nhe
->nhg
.nexthop
, NULL
);
704 rib_add_multipath(afi
, SAFI_UNICAST
, &p
, NULL
, newre
, ng
);
709 int zebra_del_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
710 struct route_entry
*re
)
715 afi
= family2afi(rn
->p
.family
);
716 prefix_copy(&p
, &rn
->p
);
718 rib_delete(afi
, SAFI_UNICAST
, zvrf
->vrf
->vrf_id
, ZEBRA_ROUTE_TABLE
,
719 re
->table
, re
->flags
, &p
, NULL
, re
->nhe
->nhg
.nexthop
,
720 re
->nhe_id
, zvrf
->table_id
, re
->metric
, re
->distance
,
726 /* Assuming no one calls this with the main routing table */
727 int zebra_import_table(afi_t afi
, vrf_id_t vrf_id
, uint32_t table_id
,
728 uint32_t distance
, const char *rmap_name
, int add
)
730 struct route_table
*table
;
731 struct route_entry
*re
;
732 struct route_node
*rn
;
733 struct zebra_vrf
*zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
735 if (!is_zebra_valid_kernel_table(table_id
)
736 || (table_id
== RT_TABLE_MAIN
))
742 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
, vrf_id
,
746 } else if (IS_ZEBRA_DEBUG_RIB
) {
747 zlog_debug("%s routes from table %d",
748 add
? "Importing" : "Unimporting", table_id
);
753 zebra_add_import_table_route_map(afi
, rmap_name
,
757 zebra_get_import_table_route_map(afi
, table_id
);
759 zebra_del_import_table_route_map(afi
, table_id
);
764 zebra_import_table_used
[afi
][table_id
] = 1;
765 zebra_import_table_distance
[afi
][table_id
] = distance
;
767 zebra_import_table_used
[afi
][table_id
] = 0;
768 zebra_import_table_distance
[afi
][table_id
] =
769 ZEBRA_TABLE_DISTANCE_DEFAULT
;
771 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
773 zebra_del_import_table_route_map(afi
, table_id
);
778 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
779 /* For each entry in the non-default routing table,
780 * add the entry in the main table
785 RNODE_FOREACH_RE (rn
, re
) {
786 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
794 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
795 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
))) {
797 zebra_add_import_table_entry(zvrf
, rn
, re
,
800 zebra_del_import_table_entry(zvrf
, rn
, re
);
806 int zebra_import_table_config(struct vty
*vty
, vrf_id_t vrf_id
)
811 char afi_str
[AFI_MAX
][10] = {"", "ip", "ipv6", "ethernet"};
812 const char *rmap_name
;
814 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
815 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
816 if (!is_zebra_import_table_enabled(afi
, vrf_id
, i
))
819 if (zebra_import_table_distance
[afi
][i
]
820 != ZEBRA_TABLE_DISTANCE_DEFAULT
) {
821 vty_out(vty
, "%s import-table %d distance %d",
823 zebra_import_table_distance
[afi
][i
]);
825 vty_out(vty
, "%s import-table %d", afi_str
[afi
],
829 rmap_name
= zebra_get_import_table_route_map(afi
, i
);
831 vty_out(vty
, " route-map %s", rmap_name
);
841 static void zebra_import_table_rm_update_vrf_afi(struct zebra_vrf
*zvrf
,
842 afi_t afi
, int table_id
,
845 struct route_table
*table
;
846 struct route_entry
*re
;
847 struct route_node
*rn
;
848 const char *rmap_name
;
850 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
851 if ((!rmap_name
) || (strcmp(rmap_name
, rmap
) != 0))
854 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
,
855 zvrf
->vrf
->vrf_id
, table_id
);
857 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
858 zlog_debug("%s: Table id=%d not found", __func__
,
863 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
865 * For each entry in the non-default routing table,
866 * add the entry in the main table
871 RNODE_FOREACH_RE (rn
, re
) {
872 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
880 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
881 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
)))
882 zebra_add_import_table_entry(zvrf
, rn
, re
, rmap_name
);
888 static void zebra_import_table_rm_update_vrf(struct zebra_vrf
*zvrf
,
894 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
895 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
896 if (!is_zebra_import_table_enabled(
897 afi
, zvrf
->vrf
->vrf_id
, i
))
900 zebra_import_table_rm_update_vrf_afi(zvrf
, afi
, i
,
906 void zebra_import_table_rm_update(const char *rmap
)
909 struct zebra_vrf
*zvrf
;
911 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
917 zebra_import_table_rm_update_vrf(zvrf
, rmap
);
921 /* Interface parameters update */
922 void zebra_interface_parameters_update(struct interface
*ifp
)
924 struct listnode
*node
, *nnode
;
925 struct zserv
*client
;
927 if (IS_ZEBRA_DEBUG_EVENT
)
928 zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s(%u)",
929 ifp
->name
, ifp
->vrf_id
);
931 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
932 /* Do not send unsolicited messages to synchronous clients. */
933 if (client
->synchronous
)
936 zsend_interface_link_params(client
, ifp
);