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 (IS_ZEBRA_DEBUG_EVENT
)
341 zlog_debug("%s: setting vrf %s(%u) redist bitmap",
342 __func__
, VRF_LOGNAME(zvrf
->vrf
),
344 vrf_bitmap_set(client
->redist
[afi
][type
], zvrf_id(zvrf
));
345 zebra_redistribute(client
, type
, 0, zvrf_id(zvrf
), afi
);
352 void zebra_redistribute_delete(ZAPI_HANDLER_ARGS
)
356 unsigned short instance
;
358 STREAM_GETC(msg
, afi
);
359 STREAM_GETC(msg
, type
);
360 STREAM_GETW(msg
, instance
);
362 if (IS_ZEBRA_DEBUG_EVENT
)
364 "%s: client proto %s afi=%d, no longer wants %s, vrf %s(%u), instance=%d",
365 __func__
, zebra_route_string(client
->proto
), afi
,
366 zebra_route_string(type
), VRF_LOGNAME(zvrf
->vrf
),
367 zvrf_id(zvrf
), instance
);
370 if (afi
== 0 || afi
>= AFI_MAX
) {
371 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
372 "%s: Specified afi %d does not exist", __func__
, afi
);
376 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
377 zlog_debug("%s: Specified Route Type %d does not exist",
383 * NOTE: no need to withdraw the previously advertised routes. The
385 * themselves should keep track of the received routes from zebra and
386 * withdraw them when necessary.
389 redist_del_instance(&client
->mi_redist
[afi
][type
], instance
);
391 vrf_bitmap_unset(client
->redist
[afi
][type
], zvrf_id(zvrf
));
397 void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS
)
401 STREAM_GETC(msg
, afi
);
403 if (afi
== 0 || afi
>= AFI_MAX
) {
404 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
405 "%s: Specified afi %u does not exist", __func__
, afi
);
409 vrf_bitmap_set(client
->redist_default
[afi
], zvrf_id(zvrf
));
410 zebra_redistribute_default(client
, zvrf_id(zvrf
));
416 void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS
)
420 STREAM_GETC(msg
, afi
);
422 if (afi
== 0 || afi
>= AFI_MAX
) {
423 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
424 "%s: Specified afi %u does not exist", __func__
, afi
);
428 vrf_bitmap_unset(client
->redist_default
[afi
], zvrf_id(zvrf
));
434 /* Interface up information. */
435 void zebra_interface_up_update(struct interface
*ifp
)
437 struct listnode
*node
, *nnode
;
438 struct zserv
*client
;
440 if (IS_ZEBRA_DEBUG_EVENT
)
441 zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s(%u)",
442 ifp
->name
, ifp
->vrf_id
);
444 if (ifp
->ptm_status
|| !ifp
->ptm_enable
) {
445 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
,
447 /* Do not send unsolicited messages to synchronous
450 if (client
->synchronous
)
453 zsend_interface_update(ZEBRA_INTERFACE_UP
,
455 zsend_interface_link_params(client
, ifp
);
460 /* Interface down information. */
461 void zebra_interface_down_update(struct interface
*ifp
)
463 struct listnode
*node
, *nnode
;
464 struct zserv
*client
;
466 if (IS_ZEBRA_DEBUG_EVENT
)
467 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s(%u)",
468 ifp
->name
, ifp
->vrf_id
);
470 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
471 /* Do not send unsolicited messages to synchronous clients. */
472 if (client
->synchronous
)
475 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
479 /* Interface information update. */
480 void zebra_interface_add_update(struct interface
*ifp
)
482 struct listnode
*node
, *nnode
;
483 struct zserv
*client
;
485 if (IS_ZEBRA_DEBUG_EVENT
)
486 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s(%u)", ifp
->name
,
489 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
490 /* Do not send unsolicited messages to synchronous clients. */
491 if (client
->synchronous
)
495 zsend_interface_add(client
, ifp
);
496 zsend_interface_link_params(client
, ifp
);
500 void zebra_interface_delete_update(struct interface
*ifp
)
502 struct listnode
*node
, *nnode
;
503 struct zserv
*client
;
505 if (IS_ZEBRA_DEBUG_EVENT
)
506 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s(%u)",
507 ifp
->name
, ifp
->vrf_id
);
509 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
510 /* Do not send unsolicited messages to synchronous clients. */
511 if (client
->synchronous
)
515 zsend_interface_delete(client
, ifp
);
519 /* Interface address addition. */
520 void zebra_interface_address_add_update(struct interface
*ifp
,
521 struct connected
*ifc
)
523 struct listnode
*node
, *nnode
;
524 struct zserv
*client
;
527 if (IS_ZEBRA_DEBUG_EVENT
) {
530 "MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %pFX on %s(%u)",
531 p
, ifp
->name
, ifp
->vrf_id
);
534 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
))
536 EC_ZEBRA_ADVERTISING_UNUSABLE_ADDR
,
537 "advertising address to clients that is not yet usable.");
539 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 1);
541 router_id_add_address(ifc
);
543 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
544 /* Do not send unsolicited messages to synchronous clients. */
545 if (client
->synchronous
)
548 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
549 client
->connected_rt_add_cnt
++;
550 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_ADD
,
556 /* Interface address deletion. */
557 void zebra_interface_address_delete_update(struct interface
*ifp
,
558 struct connected
*ifc
)
560 struct listnode
*node
, *nnode
;
561 struct zserv
*client
;
564 if (IS_ZEBRA_DEBUG_EVENT
) {
567 "MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %pFX on %s(%u)",
568 p
, ifp
->name
, ifp
->vrf_id
);
571 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 0);
573 router_id_del_address(ifc
);
575 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
576 /* Do not send unsolicited messages to synchronous clients. */
577 if (client
->synchronous
)
580 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
581 client
->connected_rt_del_cnt
++;
582 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_DELETE
,
588 /* Interface VRF change. May need to delete from clients not interested in
589 * the new VRF. Note that this function is invoked *prior* to the VRF change.
591 void zebra_interface_vrf_update_del(struct interface
*ifp
, vrf_id_t new_vrf_id
)
593 struct listnode
*node
, *nnode
;
594 struct zserv
*client
;
596 if (IS_ZEBRA_DEBUG_EVENT
)
598 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/DEL %s VRF Id %u -> %u",
599 ifp
->name
, ifp
->vrf_id
, new_vrf_id
);
601 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
602 /* Do not send unsolicited messages to synchronous clients. */
603 if (client
->synchronous
)
606 /* Need to delete if the client is not interested in the new
608 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
610 zsend_interface_delete(client
, ifp
);
611 zsend_interface_vrf_update(client
, ifp
, new_vrf_id
);
615 /* Interface VRF change. This function is invoked *post* VRF change and sends an
616 * add to clients who are interested in the new VRF but not in the old VRF.
618 void zebra_interface_vrf_update_add(struct interface
*ifp
, vrf_id_t old_vrf_id
)
620 struct listnode
*node
, *nnode
;
621 struct zserv
*client
;
623 if (IS_ZEBRA_DEBUG_EVENT
)
625 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/ADD %s VRF Id %u -> %u",
626 ifp
->name
, old_vrf_id
, ifp
->vrf_id
);
628 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
629 /* Do not send unsolicited messages to synchronous clients. */
630 if (client
->synchronous
)
633 /* Need to add if the client is interested in the new VRF. */
635 zsend_interface_add(client
, ifp
);
636 zsend_interface_addresses(client
, ifp
);
640 int zebra_add_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
641 struct route_entry
*re
, const char *rmap_name
)
643 struct route_entry
*newre
;
644 struct route_entry
*same
;
646 struct nexthop_group
*ng
;
647 route_map_result_t ret
= RMAP_PERMITMATCH
;
650 afi
= family2afi(rn
->p
.family
);
652 ret
= zebra_import_table_route_map_check(
653 afi
, re
->type
, re
->instance
, &rn
->p
,
654 re
->nhe
->nhg
.nexthop
,
655 zvrf
->vrf
->vrf_id
, re
->tag
, rmap_name
);
657 if (ret
!= RMAP_PERMITMATCH
) {
658 UNSET_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
);
659 zebra_del_import_table_entry(zvrf
, rn
, re
);
663 prefix_copy(&p
, &rn
->p
);
665 RNODE_FOREACH_RE (rn
, same
) {
666 if (CHECK_FLAG(same
->status
, ROUTE_ENTRY_REMOVED
))
669 if (same
->type
== re
->type
&& same
->instance
== re
->instance
670 && same
->table
== re
->table
671 && same
->type
!= ZEBRA_ROUTE_CONNECT
)
676 UNSET_FLAG(same
->flags
, ZEBRA_FLAG_SELECTED
);
677 zebra_del_import_table_entry(zvrf
, rn
, same
);
680 newre
= XCALLOC(MTYPE_RE
, sizeof(struct route_entry
));
681 newre
->type
= ZEBRA_ROUTE_TABLE
;
682 newre
->distance
= zebra_import_table_distance
[afi
][re
->table
];
683 newre
->flags
= re
->flags
;
684 newre
->metric
= re
->metric
;
685 newre
->mtu
= re
->mtu
;
686 newre
->table
= zvrf
->table_id
;
687 newre
->uptime
= monotime(NULL
);
688 newre
->instance
= re
->table
;
690 ng
= nexthop_group_new();
691 copy_nexthops(&ng
->nexthop
, re
->nhe
->nhg
.nexthop
, NULL
);
693 rib_add_multipath(afi
, SAFI_UNICAST
, &p
, NULL
, newre
, ng
);
698 int zebra_del_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
699 struct route_entry
*re
)
704 afi
= family2afi(rn
->p
.family
);
705 prefix_copy(&p
, &rn
->p
);
707 rib_delete(afi
, SAFI_UNICAST
, zvrf
->vrf
->vrf_id
, ZEBRA_ROUTE_TABLE
,
708 re
->table
, re
->flags
, &p
, NULL
, re
->nhe
->nhg
.nexthop
,
709 re
->nhe_id
, zvrf
->table_id
, re
->metric
, re
->distance
,
715 /* Assuming no one calls this with the main routing table */
716 int zebra_import_table(afi_t afi
, vrf_id_t vrf_id
, uint32_t table_id
,
717 uint32_t distance
, const char *rmap_name
, int add
)
719 struct route_table
*table
;
720 struct route_entry
*re
;
721 struct route_node
*rn
;
722 struct zebra_vrf
*zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
724 if (!is_zebra_valid_kernel_table(table_id
)
725 || (table_id
== RT_TABLE_MAIN
))
731 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
, vrf_id
,
735 } else if (IS_ZEBRA_DEBUG_RIB
) {
736 zlog_debug("%s routes from table %d",
737 add
? "Importing" : "Unimporting", table_id
);
742 zebra_add_import_table_route_map(afi
, rmap_name
,
746 zebra_get_import_table_route_map(afi
, table_id
);
748 zebra_del_import_table_route_map(afi
, table_id
);
753 zebra_import_table_used
[afi
][table_id
] = 1;
754 zebra_import_table_distance
[afi
][table_id
] = distance
;
756 zebra_import_table_used
[afi
][table_id
] = 0;
757 zebra_import_table_distance
[afi
][table_id
] =
758 ZEBRA_TABLE_DISTANCE_DEFAULT
;
760 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
762 zebra_del_import_table_route_map(afi
, table_id
);
767 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
768 /* For each entry in the non-default routing table,
769 * add the entry in the main table
774 RNODE_FOREACH_RE (rn
, re
) {
775 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
783 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
784 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
))) {
786 zebra_add_import_table_entry(zvrf
, rn
, re
,
789 zebra_del_import_table_entry(zvrf
, rn
, re
);
795 int zebra_import_table_config(struct vty
*vty
, vrf_id_t vrf_id
)
800 char afi_str
[AFI_MAX
][10] = {"", "ip", "ipv6", "ethernet"};
801 const char *rmap_name
;
803 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
804 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
805 if (!is_zebra_import_table_enabled(afi
, vrf_id
, i
))
808 if (zebra_import_table_distance
[afi
][i
]
809 != ZEBRA_TABLE_DISTANCE_DEFAULT
) {
810 vty_out(vty
, "%s import-table %d distance %d",
812 zebra_import_table_distance
[afi
][i
]);
814 vty_out(vty
, "%s import-table %d", afi_str
[afi
],
818 rmap_name
= zebra_get_import_table_route_map(afi
, i
);
820 vty_out(vty
, " route-map %s", rmap_name
);
830 static void zebra_import_table_rm_update_vrf_afi(struct zebra_vrf
*zvrf
,
831 afi_t afi
, int table_id
,
834 struct route_table
*table
;
835 struct route_entry
*re
;
836 struct route_node
*rn
;
837 const char *rmap_name
;
839 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
840 if ((!rmap_name
) || (strcmp(rmap_name
, rmap
) != 0))
843 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
,
844 zvrf
->vrf
->vrf_id
, table_id
);
846 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
847 zlog_debug("%s: Table id=%d not found", __func__
,
852 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
854 * For each entry in the non-default routing table,
855 * add the entry in the main table
860 RNODE_FOREACH_RE (rn
, re
) {
861 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
869 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
870 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
)))
871 zebra_add_import_table_entry(zvrf
, rn
, re
, rmap_name
);
877 static void zebra_import_table_rm_update_vrf(struct zebra_vrf
*zvrf
,
883 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
884 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
885 if (!is_zebra_import_table_enabled(
886 afi
, zvrf
->vrf
->vrf_id
, i
))
889 zebra_import_table_rm_update_vrf_afi(zvrf
, afi
, i
,
895 void zebra_import_table_rm_update(const char *rmap
)
898 struct zebra_vrf
*zvrf
;
900 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
906 zebra_import_table_rm_update_vrf(zvrf
, rmap
);
910 /* Interface parameters update */
911 void zebra_interface_parameters_update(struct interface
*ifp
)
913 struct listnode
*node
, *nnode
;
914 struct zserv
*client
;
916 if (IS_ZEBRA_DEBUG_EVENT
)
917 zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s(%u)",
918 ifp
->name
, ifp
->vrf_id
);
920 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
921 /* Do not send unsolicited messages to synchronous clients. */
922 if (client
->synchronous
)
925 zsend_interface_link_params(client
, ifp
);