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 && newre
->distance
!= DISTANCE_INFINITY
)
96 zsend_redistribute_route(
97 ZEBRA_REDISTRIBUTE_ROUTE_ADD
, client
,
101 route_unlock_node(rn
);
105 /* Redistribute routes. */
106 static void zebra_redistribute(struct zserv
*client
, int type
,
107 unsigned short instance
, vrf_id_t vrf_id
,
110 struct route_entry
*newre
;
111 struct route_table
*table
;
112 struct route_node
*rn
;
114 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, vrf_id
);
118 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
))
119 RNODE_FOREACH_RE (rn
, newre
) {
120 const struct prefix
*dst_p
, *src_p
;
122 srcdest_rnode_prefixes(rn
, &dst_p
, &src_p
);
124 if (IS_ZEBRA_DEBUG_RIB
)
126 "%s: client %s %pFX(%u) checking: selected=%d, type=%d, distance=%d, metric=%d zebra_check_addr=%d",
128 zebra_route_string(client
->proto
),
130 CHECK_FLAG(newre
->flags
,
131 ZEBRA_FLAG_SELECTED
),
132 newre
->type
, newre
->distance
,
133 newre
->metric
, zebra_check_addr(dst_p
));
135 if (!CHECK_FLAG(newre
->flags
, ZEBRA_FLAG_SELECTED
))
137 if ((type
!= ZEBRA_ROUTE_ALL
138 && (newre
->type
!= type
139 || newre
->instance
!= instance
)))
141 if (newre
->distance
== DISTANCE_INFINITY
)
143 if (!zebra_check_addr(dst_p
))
146 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
147 client
, dst_p
, src_p
, newre
);
152 * Function to check if prefix is candidate for
155 static bool zebra_redistribute_check(const struct route_entry
*re
,
156 struct zserv
*client
,
157 const struct prefix
*p
, int afi
)
159 /* Process only if there is valid re */
163 /* If default route and redistributed */
164 if (is_default_prefix(p
)
165 && vrf_bitmap_check(client
->redist_default
[afi
], re
->vrf_id
))
168 /* If redistribute in enabled for zebra route all */
169 if (vrf_bitmap_check(client
->redist
[afi
][ZEBRA_ROUTE_ALL
], re
->vrf_id
))
173 * If multi-instance then check for route
174 * redistribution for given instance.
177 && redist_check_instance(&client
->mi_redist
[afi
][re
->type
],
181 /* If redistribution is enabled for give route type. */
182 if (vrf_bitmap_check(client
->redist
[afi
][re
->type
], re
->vrf_id
))
188 /* Either advertise a route for redistribution to registered clients or */
189 /* withdraw redistribution if add cannot be done for client */
190 void redistribute_update(const struct prefix
*p
, const struct prefix
*src_p
,
191 const struct route_entry
*re
,
192 const struct route_entry
*prev_re
)
194 struct listnode
*node
, *nnode
;
195 struct zserv
*client
;
198 if (IS_ZEBRA_DEBUG_RIB
)
200 "(%u:%u):%pFX: Redist update re %p (%s), old %p (%s)",
201 re
->vrf_id
, re
->table
, p
, re
,
202 zebra_route_string(re
->type
), prev_re
,
203 prev_re
? zebra_route_string(prev_re
->type
) : "None");
205 afi
= family2afi(p
->family
);
207 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
208 "%s: Unknown AFI/SAFI prefix received", __func__
);
211 if (!zebra_check_addr(p
)) {
212 if (IS_ZEBRA_DEBUG_RIB
)
213 zlog_debug("Redist update filter prefix %pFX", p
);
218 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
219 if (zebra_redistribute_check(re
, client
, p
, afi
)) {
220 if (IS_ZEBRA_DEBUG_RIB
) {
222 "%s: client %s %pFX(%u:%u), type=%d, distance=%d, metric=%d",
224 zebra_route_string(client
->proto
), p
,
225 re
->vrf_id
, re
->table
, re
->type
,
226 re
->distance
, re
->metric
);
228 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
229 client
, p
, src_p
, re
);
230 } else if (zebra_redistribute_check(prev_re
, client
, p
, afi
))
231 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
232 client
, p
, src_p
, prev_re
);
237 * During a route delete, where 'new_re' is NULL, redist a delete to all
238 * clients registered for the type of 'old_re'.
239 * During a route update, redist a delete to any clients who will not see
240 * an update when the new route is installed. There are cases when a client
241 * may have seen a redist for 'old_re', but will not see
242 * the redist for 'new_re'.
244 void redistribute_delete(const struct prefix
*p
, const struct prefix
*src_p
,
245 const struct route_entry
*old_re
,
246 const struct route_entry
*new_re
)
248 struct listnode
*node
, *nnode
;
249 struct zserv
*client
;
254 vrfid
= old_re
->vrf_id
;
256 vrfid
= new_re
->vrf_id
;
260 if (IS_ZEBRA_DEBUG_RIB
) {
261 zlog_debug("%u:%pFX: Redist del: re %p (%s), new re %p (%s)",
263 old_re
? zebra_route_string(old_re
->type
) : "None",
265 new_re
? zebra_route_string(new_re
->type
) : "None");
268 /* Add DISTANCE_INFINITY check. */
269 if (old_re
&& (old_re
->distance
== DISTANCE_INFINITY
)) {
270 if (IS_ZEBRA_DEBUG_RIB
)
271 zlog_debug(" Skipping due to Infinite Distance");
275 afi
= family2afi(p
->family
);
277 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
278 "%s: Unknown AFI/SAFI prefix received",
283 /* Skip invalid (e.g. linklocal) prefix */
284 if (!zebra_check_addr(p
)) {
285 if (IS_ZEBRA_DEBUG_RIB
) {
287 "%u:%pFX: Redist del old: skipping invalid prefix",
293 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
294 /* Do not send unsolicited messages to synchronous clients. */
295 if (client
->synchronous
)
298 * Skip this client if it will receive an update for the
301 if (zebra_redistribute_check(new_re
, client
, p
, afi
))
304 /* Send a delete for the 'old' re to any subscribed client. */
305 if (zebra_redistribute_check(old_re
, client
, p
, afi
))
306 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
307 client
, p
, src_p
, old_re
);
312 void zebra_redistribute_add(ZAPI_HANDLER_ARGS
)
316 unsigned short instance
;
318 STREAM_GETC(msg
, afi
);
319 STREAM_GETC(msg
, type
);
320 STREAM_GETW(msg
, instance
);
322 if (IS_ZEBRA_DEBUG_EVENT
)
324 "%s: client proto %s afi=%d, wants %s, vrf %s(%u), instance=%d",
325 __func__
, zebra_route_string(client
->proto
), afi
,
326 zebra_route_string(type
), VRF_LOGNAME(zvrf
->vrf
),
327 zvrf_id(zvrf
), instance
);
329 if (afi
== 0 || afi
>= AFI_MAX
) {
330 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
331 "%s: Specified afi %d does not exist", __func__
, afi
);
335 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
336 zlog_debug("%s: Specified Route Type %d does not exist",
342 if (!redist_check_instance(&client
->mi_redist
[afi
][type
],
344 redist_add_instance(&client
->mi_redist
[afi
][type
],
346 zebra_redistribute(client
, type
, instance
,
350 if (!vrf_bitmap_check(client
->redist
[afi
][type
],
352 if (IS_ZEBRA_DEBUG_EVENT
)
354 "%s: setting vrf %s(%u) redist bitmap",
355 __func__
, VRF_LOGNAME(zvrf
->vrf
),
357 vrf_bitmap_set(client
->redist
[afi
][type
],
359 zebra_redistribute(client
, type
, 0, zvrf_id(zvrf
), afi
);
367 void zebra_redistribute_delete(ZAPI_HANDLER_ARGS
)
371 unsigned short instance
;
373 STREAM_GETC(msg
, afi
);
374 STREAM_GETC(msg
, type
);
375 STREAM_GETW(msg
, instance
);
377 if (afi
== 0 || afi
>= AFI_MAX
) {
378 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
379 "%s: Specified afi %d does not exist", __func__
, afi
);
383 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
384 zlog_debug("%s: Specified Route Type %d does not exist",
390 * NOTE: no need to withdraw the previously advertised routes. The
392 * themselves should keep track of the received routes from zebra and
393 * withdraw them when necessary.
396 redist_del_instance(&client
->mi_redist
[afi
][type
], instance
);
398 vrf_bitmap_unset(client
->redist
[afi
][type
], zvrf_id(zvrf
));
404 void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS
)
408 STREAM_GETC(msg
, afi
);
410 if (afi
== 0 || afi
>= AFI_MAX
) {
411 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
412 "%s: Specified afi %u does not exist", __func__
, afi
);
416 vrf_bitmap_set(client
->redist_default
[afi
], zvrf_id(zvrf
));
417 zebra_redistribute_default(client
, zvrf_id(zvrf
));
423 void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS
)
427 STREAM_GETC(msg
, afi
);
429 if (afi
== 0 || afi
>= AFI_MAX
) {
430 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
431 "%s: Specified afi %u does not exist", __func__
, afi
);
435 vrf_bitmap_unset(client
->redist_default
[afi
], zvrf_id(zvrf
));
441 /* Interface up information. */
442 void zebra_interface_up_update(struct interface
*ifp
)
444 struct listnode
*node
, *nnode
;
445 struct zserv
*client
;
447 if (IS_ZEBRA_DEBUG_EVENT
)
448 zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s(%u)",
449 ifp
->name
, ifp
->vrf_id
);
451 if (ifp
->ptm_status
|| !ifp
->ptm_enable
) {
452 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
,
454 /* Do not send unsolicited messages to synchronous
457 if (client
->synchronous
)
460 zsend_interface_update(ZEBRA_INTERFACE_UP
,
462 zsend_interface_link_params(client
, ifp
);
467 /* Interface down information. */
468 void zebra_interface_down_update(struct interface
*ifp
)
470 struct listnode
*node
, *nnode
;
471 struct zserv
*client
;
473 if (IS_ZEBRA_DEBUG_EVENT
)
474 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s(%u)",
475 ifp
->name
, ifp
->vrf_id
);
477 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
478 /* Do not send unsolicited messages to synchronous clients. */
479 if (client
->synchronous
)
482 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
486 /* Interface information update. */
487 void zebra_interface_add_update(struct interface
*ifp
)
489 struct listnode
*node
, *nnode
;
490 struct zserv
*client
;
492 if (IS_ZEBRA_DEBUG_EVENT
)
493 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s(%u)", ifp
->name
,
496 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
497 /* Do not send unsolicited messages to synchronous clients. */
498 if (client
->synchronous
)
502 zsend_interface_add(client
, ifp
);
503 zsend_interface_link_params(client
, ifp
);
507 void zebra_interface_delete_update(struct interface
*ifp
)
509 struct listnode
*node
, *nnode
;
510 struct zserv
*client
;
512 if (IS_ZEBRA_DEBUG_EVENT
)
513 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s(%u)",
514 ifp
->name
, ifp
->vrf_id
);
516 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
517 /* Do not send unsolicited messages to synchronous clients. */
518 if (client
->synchronous
)
522 zsend_interface_delete(client
, ifp
);
526 /* Interface address addition. */
527 void zebra_interface_address_add_update(struct interface
*ifp
,
528 struct connected
*ifc
)
530 struct listnode
*node
, *nnode
;
531 struct zserv
*client
;
534 if (IS_ZEBRA_DEBUG_EVENT
) {
537 "MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %pFX on %s(%u)",
538 p
, ifp
->name
, ifp
->vrf_id
);
541 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
))
543 EC_ZEBRA_ADVERTISING_UNUSABLE_ADDR
,
544 "advertising address to clients that is not yet usable.");
546 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 1);
548 router_id_add_address(ifc
);
550 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
551 /* Do not send unsolicited messages to synchronous clients. */
552 if (client
->synchronous
)
555 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
556 client
->connected_rt_add_cnt
++;
557 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_ADD
,
563 /* Interface address deletion. */
564 void zebra_interface_address_delete_update(struct interface
*ifp
,
565 struct connected
*ifc
)
567 struct listnode
*node
, *nnode
;
568 struct zserv
*client
;
571 if (IS_ZEBRA_DEBUG_EVENT
) {
574 "MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %pFX on %s(%u)",
575 p
, ifp
->name
, ifp
->vrf_id
);
578 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 0);
580 router_id_del_address(ifc
);
582 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
583 /* Do not send unsolicited messages to synchronous clients. */
584 if (client
->synchronous
)
587 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
588 client
->connected_rt_del_cnt
++;
589 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_DELETE
,
595 /* Interface VRF change. May need to delete from clients not interested in
596 * the new VRF. Note that this function is invoked *prior* to the VRF change.
598 void zebra_interface_vrf_update_del(struct interface
*ifp
, vrf_id_t new_vrf_id
)
600 struct listnode
*node
, *nnode
;
601 struct zserv
*client
;
603 if (IS_ZEBRA_DEBUG_EVENT
)
605 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/DEL %s VRF Id %u -> %u",
606 ifp
->name
, ifp
->vrf_id
, new_vrf_id
);
608 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
609 /* Do not send unsolicited messages to synchronous clients. */
610 if (client
->synchronous
)
613 /* Need to delete if the client is not interested in the new
615 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
617 zsend_interface_delete(client
, ifp
);
618 zsend_interface_vrf_update(client
, ifp
, new_vrf_id
);
622 /* Interface VRF change. This function is invoked *post* VRF change and sends an
623 * add to clients who are interested in the new VRF but not in the old VRF.
625 void zebra_interface_vrf_update_add(struct interface
*ifp
, vrf_id_t old_vrf_id
)
627 struct listnode
*node
, *nnode
;
628 struct zserv
*client
;
630 if (IS_ZEBRA_DEBUG_EVENT
)
632 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/ADD %s VRF Id %u -> %u",
633 ifp
->name
, old_vrf_id
, ifp
->vrf_id
);
635 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
636 /* Do not send unsolicited messages to synchronous clients. */
637 if (client
->synchronous
)
640 /* Need to add if the client is interested in the new VRF. */
642 zsend_interface_add(client
, ifp
);
643 zsend_interface_addresses(client
, ifp
);
647 int zebra_add_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
648 struct route_entry
*re
, const char *rmap_name
)
650 struct route_entry
*newre
;
651 struct route_entry
*same
;
653 struct nexthop_group
*ng
;
654 route_map_result_t ret
= RMAP_PERMITMATCH
;
657 afi
= family2afi(rn
->p
.family
);
659 ret
= zebra_import_table_route_map_check(
660 afi
, re
->type
, re
->instance
, &rn
->p
,
661 re
->nhe
->nhg
.nexthop
,
662 zvrf
->vrf
->vrf_id
, re
->tag
, rmap_name
);
664 if (ret
!= RMAP_PERMITMATCH
) {
665 UNSET_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
);
666 zebra_del_import_table_entry(zvrf
, rn
, re
);
670 prefix_copy(&p
, &rn
->p
);
672 RNODE_FOREACH_RE (rn
, same
) {
673 if (CHECK_FLAG(same
->status
, ROUTE_ENTRY_REMOVED
))
676 if (same
->type
== re
->type
&& same
->instance
== re
->instance
677 && same
->table
== re
->table
678 && same
->type
!= ZEBRA_ROUTE_CONNECT
)
683 UNSET_FLAG(same
->flags
, ZEBRA_FLAG_SELECTED
);
684 zebra_del_import_table_entry(zvrf
, rn
, same
);
687 newre
= XCALLOC(MTYPE_RE
, sizeof(struct route_entry
));
688 newre
->type
= ZEBRA_ROUTE_TABLE
;
689 newre
->distance
= zebra_import_table_distance
[afi
][re
->table
];
690 newre
->flags
= re
->flags
;
691 newre
->metric
= re
->metric
;
692 newre
->mtu
= re
->mtu
;
693 newre
->table
= zvrf
->table_id
;
694 newre
->uptime
= monotime(NULL
);
695 newre
->instance
= re
->table
;
697 ng
= nexthop_group_new();
698 copy_nexthops(&ng
->nexthop
, re
->nhe
->nhg
.nexthop
, NULL
);
700 rib_add_multipath(afi
, SAFI_UNICAST
, &p
, NULL
, newre
, ng
);
705 int zebra_del_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
706 struct route_entry
*re
)
711 afi
= family2afi(rn
->p
.family
);
712 prefix_copy(&p
, &rn
->p
);
714 rib_delete(afi
, SAFI_UNICAST
, zvrf
->vrf
->vrf_id
, ZEBRA_ROUTE_TABLE
,
715 re
->table
, re
->flags
, &p
, NULL
, re
->nhe
->nhg
.nexthop
,
716 re
->nhe_id
, zvrf
->table_id
, re
->metric
, re
->distance
,
722 /* Assuming no one calls this with the main routing table */
723 int zebra_import_table(afi_t afi
, vrf_id_t vrf_id
, uint32_t table_id
,
724 uint32_t distance
, const char *rmap_name
, int add
)
726 struct route_table
*table
;
727 struct route_entry
*re
;
728 struct route_node
*rn
;
729 struct zebra_vrf
*zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
731 if (!is_zebra_valid_kernel_table(table_id
)
732 || (table_id
== RT_TABLE_MAIN
))
738 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
, vrf_id
,
742 } else if (IS_ZEBRA_DEBUG_RIB
) {
743 zlog_debug("%s routes from table %d",
744 add
? "Importing" : "Unimporting", table_id
);
749 zebra_add_import_table_route_map(afi
, rmap_name
,
753 zebra_get_import_table_route_map(afi
, table_id
);
755 zebra_del_import_table_route_map(afi
, table_id
);
760 zebra_import_table_used
[afi
][table_id
] = 1;
761 zebra_import_table_distance
[afi
][table_id
] = distance
;
763 zebra_import_table_used
[afi
][table_id
] = 0;
764 zebra_import_table_distance
[afi
][table_id
] =
765 ZEBRA_TABLE_DISTANCE_DEFAULT
;
767 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
769 zebra_del_import_table_route_map(afi
, table_id
);
774 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
775 /* For each entry in the non-default routing table,
776 * add the entry in the main table
781 RNODE_FOREACH_RE (rn
, re
) {
782 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
790 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
791 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
))) {
793 zebra_add_import_table_entry(zvrf
, rn
, re
,
796 zebra_del_import_table_entry(zvrf
, rn
, re
);
802 int zebra_import_table_config(struct vty
*vty
, vrf_id_t vrf_id
)
807 char afi_str
[AFI_MAX
][10] = {"", "ip", "ipv6", "ethernet"};
808 const char *rmap_name
;
810 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
811 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
812 if (!is_zebra_import_table_enabled(afi
, vrf_id
, i
))
815 if (zebra_import_table_distance
[afi
][i
]
816 != ZEBRA_TABLE_DISTANCE_DEFAULT
) {
817 vty_out(vty
, "%s import-table %d distance %d",
819 zebra_import_table_distance
[afi
][i
]);
821 vty_out(vty
, "%s import-table %d", afi_str
[afi
],
825 rmap_name
= zebra_get_import_table_route_map(afi
, i
);
827 vty_out(vty
, " route-map %s", rmap_name
);
837 static void zebra_import_table_rm_update_vrf_afi(struct zebra_vrf
*zvrf
,
838 afi_t afi
, int table_id
,
841 struct route_table
*table
;
842 struct route_entry
*re
;
843 struct route_node
*rn
;
844 const char *rmap_name
;
846 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
847 if ((!rmap_name
) || (strcmp(rmap_name
, rmap
) != 0))
850 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
,
851 zvrf
->vrf
->vrf_id
, table_id
);
853 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
854 zlog_debug("%s: Table id=%d not found", __func__
,
859 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
861 * For each entry in the non-default routing table,
862 * add the entry in the main table
867 RNODE_FOREACH_RE (rn
, re
) {
868 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
876 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
877 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
)))
878 zebra_add_import_table_entry(zvrf
, rn
, re
, rmap_name
);
884 static void zebra_import_table_rm_update_vrf(struct zebra_vrf
*zvrf
,
890 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
891 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
892 if (!is_zebra_import_table_enabled(
893 afi
, zvrf
->vrf
->vrf_id
, i
))
896 zebra_import_table_rm_update_vrf_afi(zvrf
, afi
, i
,
902 void zebra_import_table_rm_update(const char *rmap
)
905 struct zebra_vrf
*zvrf
;
907 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
913 zebra_import_table_rm_update_vrf(zvrf
, rmap
);
917 /* Interface parameters update */
918 void zebra_interface_parameters_update(struct interface
*ifp
)
920 struct listnode
*node
, *nnode
;
921 struct zserv
*client
;
923 if (IS_ZEBRA_DEBUG_EVENT
)
924 zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s(%u)",
925 ifp
->name
, ifp
->vrf_id
);
927 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
928 /* Do not send unsolicited messages to synchronous clients. */
929 if (client
->synchronous
)
932 zsend_interface_link_params(client
, ifp
);