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 if (IS_ZEBRA_DEBUG_RIB
)
121 "%s: client %s %pRN(%u:%u) checking: selected=%d, type=%d, distance=%d, metric=%d zebra_check_addr=%d",
123 zebra_route_string(client
->proto
), rn
,
124 vrf_id
, newre
->instance
,
125 !!CHECK_FLAG(newre
->flags
,
126 ZEBRA_FLAG_SELECTED
),
127 newre
->type
, newre
->distance
,
129 zebra_check_addr(&rn
->p
));
131 if (!CHECK_FLAG(newre
->flags
, ZEBRA_FLAG_SELECTED
))
133 if ((type
!= ZEBRA_ROUTE_ALL
134 && (newre
->type
!= type
135 || newre
->instance
!= instance
)))
137 if (!zebra_check_addr(&rn
->p
))
140 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
146 * Function to check if prefix is candidate for
149 static bool zebra_redistribute_check(const struct route_node
*rn
,
150 const struct route_entry
*re
,
151 struct zserv
*client
)
153 struct zebra_vrf
*zvrf
;
156 /* Process only if there is valid re */
160 afi
= family2afi(rn
->p
.family
);
161 zvrf
= vrf_info_lookup(re
->vrf_id
);
162 if (re
->vrf_id
== VRF_DEFAULT
&& zvrf
->table_id
!= re
->table
)
165 /* If default route and redistributed */
166 if (is_default_prefix(&rn
->p
) &&
167 vrf_bitmap_check(client
->redist_default
[afi
], re
->vrf_id
))
170 /* If redistribute in enabled for zebra route all */
171 if (vrf_bitmap_check(client
->redist
[afi
][ZEBRA_ROUTE_ALL
], re
->vrf_id
))
175 * If multi-instance then check for route
176 * redistribution for given instance.
179 if (redist_check_instance(&client
->mi_redist
[afi
][re
->type
],
186 /* If redistribution is enabled for give route type. */
187 if (vrf_bitmap_check(client
->redist
[afi
][re
->type
], re
->vrf_id
))
193 /* Either advertise a route for redistribution to registered clients or */
194 /* withdraw redistribution if add cannot be done for client */
195 void redistribute_update(const struct route_node
*rn
,
196 const struct route_entry
*re
,
197 const struct route_entry
*prev_re
)
199 struct listnode
*node
, *nnode
;
200 struct zserv
*client
;
202 if (IS_ZEBRA_DEBUG_RIB
)
204 "(%u:%u):%pRN(%u): Redist update re %p (%s), old %p (%s)",
205 re
->vrf_id
, re
->table
, rn
, re
->instance
, re
,
206 zebra_route_string(re
->type
), prev_re
,
207 prev_re
? zebra_route_string(prev_re
->type
) : "None");
209 if (!zebra_check_addr(&rn
->p
)) {
210 if (IS_ZEBRA_DEBUG_RIB
)
211 zlog_debug("Redist update filter prefix %pRN", rn
);
216 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
217 if (zebra_redistribute_check(rn
, re
, client
)) {
218 if (IS_ZEBRA_DEBUG_RIB
) {
220 "%s: client %s %pRN(%u:%u), type=%d, distance=%d, metric=%d",
222 zebra_route_string(client
->proto
), rn
,
223 re
->vrf_id
, re
->table
, re
->type
,
224 re
->distance
, re
->metric
);
226 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
228 } else if (zebra_redistribute_check(rn
, prev_re
, client
))
229 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
230 client
, rn
, prev_re
);
235 * During a route delete, where 'new_re' is NULL, redist a delete to all
236 * clients registered for the type of 'old_re'.
237 * During a route update, redist a delete to any clients who will not see
238 * an update when the new route is installed. There are cases when a client
239 * may have seen a redist for 'old_re', but will not see
240 * the redist for 'new_re'.
242 void redistribute_delete(const struct route_node
*rn
,
243 const struct route_entry
*old_re
,
244 const struct route_entry
*new_re
)
246 struct listnode
*node
, *nnode
;
247 struct zserv
*client
;
251 vrfid
= old_re
->vrf_id
;
253 vrfid
= new_re
->vrf_id
;
257 if (IS_ZEBRA_DEBUG_RIB
) {
258 uint8_t old_inst
, new_inst
;
261 old_inst
= new_inst
= 0;
264 old_inst
= old_re
->instance
;
265 table
= old_re
->table
;
268 new_inst
= new_re
->instance
;
269 table
= new_re
->table
;
273 "%u:%u%pRN: Redist del: re %p (%u:%s), new re %p (%u:%s)",
274 vrfid
, table
, rn
, old_re
, old_inst
,
275 old_re
? zebra_route_string(old_re
->type
) : "None",
277 new_re
? zebra_route_string(new_re
->type
) : "None");
280 /* Skip invalid (e.g. linklocal) prefix */
281 if (!zebra_check_addr(&rn
->p
)) {
282 if (IS_ZEBRA_DEBUG_RIB
) {
284 "%u:%pRN: Redist del old: skipping invalid prefix",
290 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
291 /* Do not send unsolicited messages to synchronous clients. */
292 if (client
->synchronous
)
295 * Skip this client if it will receive an update for the
298 if (zebra_redistribute_check(rn
, new_re
, client
))
301 /* Send a delete for the 'old' re to any subscribed client. */
302 if (zebra_redistribute_check(rn
, old_re
, client
))
303 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
309 void zebra_redistribute_add(ZAPI_HANDLER_ARGS
)
313 unsigned short instance
;
315 STREAM_GETC(msg
, afi
);
316 STREAM_GETC(msg
, type
);
317 STREAM_GETW(msg
, instance
);
319 if (IS_ZEBRA_DEBUG_EVENT
)
321 "%s: client proto %s afi=%d, wants %s, vrf %s(%u), instance=%d",
322 __func__
, zebra_route_string(client
->proto
), afi
,
323 zebra_route_string(type
), VRF_LOGNAME(zvrf
->vrf
),
324 zvrf_id(zvrf
), instance
);
326 if (afi
== 0 || afi
>= AFI_MAX
) {
327 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
328 "%s: Specified afi %d does not exist", __func__
, afi
);
332 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
333 zlog_debug("%s: Specified Route Type %d does not exist",
339 if (!redist_check_instance(&client
->mi_redist
[afi
][type
],
341 redist_add_instance(&client
->mi_redist
[afi
][type
],
343 zebra_redistribute(client
, type
, instance
,
347 if (!vrf_bitmap_check(client
->redist
[afi
][type
],
349 if (IS_ZEBRA_DEBUG_EVENT
)
351 "%s: setting vrf %s(%u) redist bitmap",
352 __func__
, VRF_LOGNAME(zvrf
->vrf
),
354 vrf_bitmap_set(client
->redist
[afi
][type
],
356 zebra_redistribute(client
, type
, 0, zvrf_id(zvrf
), afi
);
364 void zebra_redistribute_delete(ZAPI_HANDLER_ARGS
)
368 unsigned short instance
;
370 STREAM_GETC(msg
, afi
);
371 STREAM_GETC(msg
, type
);
372 STREAM_GETW(msg
, instance
);
374 if (IS_ZEBRA_DEBUG_EVENT
)
376 "%s: client proto %s afi=%d, no longer wants %s, vrf %s(%u), instance=%d",
377 __func__
, zebra_route_string(client
->proto
), afi
,
378 zebra_route_string(type
), VRF_LOGNAME(zvrf
->vrf
),
379 zvrf_id(zvrf
), instance
);
382 if (afi
== 0 || afi
>= AFI_MAX
) {
383 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
384 "%s: Specified afi %d does not exist", __func__
, afi
);
388 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
389 zlog_debug("%s: Specified Route Type %d does not exist",
395 * NOTE: no need to withdraw the previously advertised routes. The
397 * themselves should keep track of the received routes from zebra and
398 * withdraw them when necessary.
401 redist_del_instance(&client
->mi_redist
[afi
][type
], instance
);
403 vrf_bitmap_unset(client
->redist
[afi
][type
], zvrf_id(zvrf
));
409 void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS
)
413 STREAM_GETC(msg
, afi
);
415 if (afi
== 0 || afi
>= AFI_MAX
) {
416 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
417 "%s: Specified afi %u does not exist", __func__
, afi
);
421 vrf_bitmap_set(client
->redist_default
[afi
], zvrf_id(zvrf
));
422 zebra_redistribute_default(client
, zvrf_id(zvrf
));
428 void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS
)
432 STREAM_GETC(msg
, afi
);
434 if (afi
== 0 || afi
>= AFI_MAX
) {
435 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
436 "%s: Specified afi %u does not exist", __func__
, afi
);
440 vrf_bitmap_unset(client
->redist_default
[afi
], zvrf_id(zvrf
));
446 /* Interface up information. */
447 void zebra_interface_up_update(struct interface
*ifp
)
449 struct listnode
*node
, *nnode
;
450 struct zserv
*client
;
452 if (IS_ZEBRA_DEBUG_EVENT
)
453 zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s vrf %s(%u)",
454 ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
);
456 if (ifp
->ptm_status
|| !ifp
->ptm_enable
) {
457 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
,
459 /* Do not send unsolicited messages to synchronous
462 if (client
->synchronous
)
465 zsend_interface_update(ZEBRA_INTERFACE_UP
,
467 zsend_interface_link_params(client
, ifp
);
472 /* Interface down information. */
473 void zebra_interface_down_update(struct interface
*ifp
)
475 struct listnode
*node
, *nnode
;
476 struct zserv
*client
;
478 if (IS_ZEBRA_DEBUG_EVENT
)
479 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s vrf %s(%u)",
480 ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
);
482 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
483 /* Do not send unsolicited messages to synchronous clients. */
484 if (client
->synchronous
)
487 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
491 /* Interface information update. */
492 void zebra_interface_add_update(struct interface
*ifp
)
494 struct listnode
*node
, *nnode
;
495 struct zserv
*client
;
497 if (IS_ZEBRA_DEBUG_EVENT
)
498 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s vrf %s(%u)",
499 ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
);
501 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
502 /* Do not send unsolicited messages to synchronous clients. */
503 if (client
->synchronous
)
507 zsend_interface_add(client
, ifp
);
508 zsend_interface_link_params(client
, ifp
);
512 void zebra_interface_delete_update(struct interface
*ifp
)
514 struct listnode
*node
, *nnode
;
515 struct zserv
*client
;
517 if (IS_ZEBRA_DEBUG_EVENT
)
518 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s vrf %s(%u)",
519 ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
);
521 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
522 /* Do not send unsolicited messages to synchronous clients. */
523 if (client
->synchronous
)
527 zsend_interface_delete(client
, ifp
);
531 /* Interface address addition. */
532 void zebra_interface_address_add_update(struct interface
*ifp
,
533 struct connected
*ifc
)
535 struct listnode
*node
, *nnode
;
536 struct zserv
*client
;
538 if (IS_ZEBRA_DEBUG_EVENT
)
540 "MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %pFX on %s vrf %s(%u)",
541 ifc
->address
, ifp
->name
, ifp
->vrf
->name
,
544 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
))
546 EC_ZEBRA_ADVERTISING_UNUSABLE_ADDR
,
547 "advertising address to clients that is not yet usable.");
549 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 1);
551 router_id_add_address(ifc
);
553 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
554 /* Do not send unsolicited messages to synchronous clients. */
555 if (client
->synchronous
)
558 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
559 client
->connected_rt_add_cnt
++;
560 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_ADD
,
566 /* Interface address deletion. */
567 void zebra_interface_address_delete_update(struct interface
*ifp
,
568 struct connected
*ifc
)
570 struct listnode
*node
, *nnode
;
571 struct zserv
*client
;
573 if (IS_ZEBRA_DEBUG_EVENT
)
575 "MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %pFX on %s vrf %s(%u)",
576 ifc
->address
, ifp
->name
, ifp
->vrf
->name
,
579 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 0);
581 router_id_del_address(ifc
);
583 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
584 /* Do not send unsolicited messages to synchronous clients. */
585 if (client
->synchronous
)
588 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
589 client
->connected_rt_del_cnt
++;
590 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_DELETE
,
596 /* Interface VRF change. May need to delete from clients not interested in
597 * the new VRF. Note that this function is invoked *prior* to the VRF change.
599 void zebra_interface_vrf_update_del(struct interface
*ifp
, vrf_id_t new_vrf_id
)
601 struct listnode
*node
, *nnode
;
602 struct zserv
*client
;
604 if (IS_ZEBRA_DEBUG_EVENT
)
606 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/DEL %s VRF Id %u -> %u",
607 ifp
->name
, ifp
->vrf
->vrf_id
, new_vrf_id
);
609 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
610 /* Do not send unsolicited messages to synchronous clients. */
611 if (client
->synchronous
)
614 /* Need to delete if the client is not interested in the new
616 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
618 zsend_interface_delete(client
, ifp
);
619 zsend_interface_vrf_update(client
, ifp
, new_vrf_id
);
623 /* Interface VRF change. This function is invoked *post* VRF change and sends an
624 * add to clients who are interested in the new VRF but not in the old VRF.
626 void zebra_interface_vrf_update_add(struct interface
*ifp
, vrf_id_t old_vrf_id
)
628 struct listnode
*node
, *nnode
;
629 struct zserv
*client
;
631 if (IS_ZEBRA_DEBUG_EVENT
)
633 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/ADD %s VRF Id %u -> %u",
634 ifp
->name
, old_vrf_id
, ifp
->vrf
->vrf_id
);
636 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
637 /* Do not send unsolicited messages to synchronous clients. */
638 if (client
->synchronous
)
641 /* Need to add if the client is interested in the new VRF. */
643 zsend_interface_add(client
, ifp
);
644 zsend_interface_addresses(client
, ifp
);
648 int zebra_add_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
649 struct route_entry
*re
, const char *rmap_name
)
651 struct route_entry
*newre
;
652 struct route_entry
*same
;
654 struct nexthop_group
*ng
;
655 route_map_result_t ret
= RMAP_PERMITMATCH
;
658 afi
= family2afi(rn
->p
.family
);
660 ret
= zebra_import_table_route_map_check(
661 afi
, re
->type
, re
->instance
, &rn
->p
,
662 re
->nhe
->nhg
.nexthop
,
663 zvrf
->vrf
->vrf_id
, re
->tag
, rmap_name
);
665 if (ret
!= RMAP_PERMITMATCH
) {
666 UNSET_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
);
667 zebra_del_import_table_entry(zvrf
, rn
, re
);
671 prefix_copy(&p
, &rn
->p
);
673 RNODE_FOREACH_RE (rn
, same
) {
674 if (CHECK_FLAG(same
->status
, ROUTE_ENTRY_REMOVED
))
677 if (same
->type
== re
->type
&& same
->instance
== re
->instance
678 && same
->table
== re
->table
679 && same
->type
!= ZEBRA_ROUTE_CONNECT
)
684 UNSET_FLAG(same
->flags
, ZEBRA_FLAG_SELECTED
);
685 zebra_del_import_table_entry(zvrf
, rn
, same
);
688 newre
= zebra_rib_route_entry_new(
689 0, ZEBRA_ROUTE_TABLE
, re
->table
, re
->flags
, re
->nhe_id
,
690 zvrf
->table_id
, re
->metric
, re
->mtu
,
691 zebra_import_table_distance
[afi
][re
->table
], re
->tag
);
693 ng
= nexthop_group_new();
694 copy_nexthops(&ng
->nexthop
, re
->nhe
->nhg
.nexthop
, NULL
);
696 rib_add_multipath(afi
, SAFI_UNICAST
, &p
, NULL
, newre
, ng
, false);
701 int zebra_del_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
702 struct route_entry
*re
)
707 afi
= family2afi(rn
->p
.family
);
708 prefix_copy(&p
, &rn
->p
);
710 rib_delete(afi
, SAFI_UNICAST
, zvrf
->vrf
->vrf_id
, ZEBRA_ROUTE_TABLE
,
711 re
->table
, re
->flags
, &p
, NULL
, re
->nhe
->nhg
.nexthop
,
712 re
->nhe_id
, zvrf
->table_id
, re
->metric
, re
->distance
,
718 /* Assuming no one calls this with the main routing table */
719 int zebra_import_table(afi_t afi
, vrf_id_t vrf_id
, uint32_t table_id
,
720 uint32_t distance
, const char *rmap_name
, int add
)
722 struct route_table
*table
;
723 struct route_entry
*re
;
724 struct route_node
*rn
;
725 struct zebra_vrf
*zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
727 if (!is_zebra_valid_kernel_table(table_id
)
728 || (table_id
== RT_TABLE_MAIN
))
734 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
, vrf_id
,
738 } else if (IS_ZEBRA_DEBUG_RIB
) {
739 zlog_debug("%s routes from table %d",
740 add
? "Importing" : "Unimporting", table_id
);
745 zebra_add_import_table_route_map(afi
, rmap_name
,
749 zebra_get_import_table_route_map(afi
, table_id
);
751 zebra_del_import_table_route_map(afi
, table_id
);
756 zebra_import_table_used
[afi
][table_id
] = 1;
757 zebra_import_table_distance
[afi
][table_id
] = distance
;
759 zebra_import_table_used
[afi
][table_id
] = 0;
760 zebra_import_table_distance
[afi
][table_id
] =
761 ZEBRA_TABLE_DISTANCE_DEFAULT
;
763 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
765 zebra_del_import_table_route_map(afi
, table_id
);
770 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
771 /* For each entry in the non-default routing table,
772 * add the entry in the main table
777 RNODE_FOREACH_RE (rn
, re
) {
778 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
786 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
787 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
))) {
789 zebra_add_import_table_entry(zvrf
, rn
, re
,
792 zebra_del_import_table_entry(zvrf
, rn
, re
);
798 int zebra_import_table_config(struct vty
*vty
, vrf_id_t vrf_id
)
803 char afi_str
[AFI_MAX
][10] = {"", "ip", "ipv6", "ethernet"};
804 const char *rmap_name
;
806 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
807 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
808 if (!is_zebra_import_table_enabled(afi
, vrf_id
, i
))
811 if (zebra_import_table_distance
[afi
][i
]
812 != ZEBRA_TABLE_DISTANCE_DEFAULT
) {
813 vty_out(vty
, "%s import-table %d distance %d",
815 zebra_import_table_distance
[afi
][i
]);
817 vty_out(vty
, "%s import-table %d", afi_str
[afi
],
821 rmap_name
= zebra_get_import_table_route_map(afi
, i
);
823 vty_out(vty
, " route-map %s", rmap_name
);
833 static void zebra_import_table_rm_update_vrf_afi(struct zebra_vrf
*zvrf
,
834 afi_t afi
, int table_id
,
837 struct route_table
*table
;
838 struct route_entry
*re
;
839 struct route_node
*rn
;
840 const char *rmap_name
;
842 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
843 if ((!rmap_name
) || (strcmp(rmap_name
, rmap
) != 0))
846 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
,
847 zvrf
->vrf
->vrf_id
, table_id
);
849 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
850 zlog_debug("%s: Table id=%d not found", __func__
,
855 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
857 * For each entry in the non-default routing table,
858 * add the entry in the main table
863 RNODE_FOREACH_RE (rn
, re
) {
864 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
872 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
873 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
)))
874 zebra_add_import_table_entry(zvrf
, rn
, re
, rmap_name
);
880 static void zebra_import_table_rm_update_vrf(struct zebra_vrf
*zvrf
,
886 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
887 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
888 if (!is_zebra_import_table_enabled(
889 afi
, zvrf
->vrf
->vrf_id
, i
))
892 zebra_import_table_rm_update_vrf_afi(zvrf
, afi
, i
,
898 void zebra_import_table_rm_update(const char *rmap
)
901 struct zebra_vrf
*zvrf
;
903 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
909 zebra_import_table_rm_update_vrf(zvrf
, rmap
);
913 /* Interface parameters update */
914 void zebra_interface_parameters_update(struct interface
*ifp
)
916 struct listnode
*node
, *nnode
;
917 struct zserv
*client
;
919 if (IS_ZEBRA_DEBUG_EVENT
)
920 zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s vrf %s(%u)",
921 ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
);
923 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
924 /* Do not send unsolicited messages to synchronous clients. */
925 if (client
->synchronous
)
928 zsend_interface_link_params(client
, ifp
);