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_memory.h"
45 #include "zebra/zebra_vxlan.h"
46 #include "zebra/zebra_errors.h"
48 #define ZEBRA_PTM_SUPPORT
50 /* array holding redistribute info about table redistribution */
51 /* bit AFI is set if that AFI is redistributing routes from this table */
52 static int zebra_import_table_used
[AFI_MAX
][ZEBRA_KERNEL_TABLE_MAX
];
53 static uint32_t zebra_import_table_distance
[AFI_MAX
][ZEBRA_KERNEL_TABLE_MAX
];
55 int is_zebra_import_table_enabled(afi_t afi
, vrf_id_t vrf_id
, uint32_t table_id
)
58 * Make sure that what we are called with actualy makes sense
63 if (is_zebra_valid_kernel_table(table_id
) &&
64 table_id
< ZEBRA_KERNEL_TABLE_MAX
)
65 return zebra_import_table_used
[afi
][table_id
];
69 static void zebra_redistribute_default(struct zserv
*client
, vrf_id_t vrf_id
)
73 struct route_table
*table
;
74 struct route_node
*rn
;
75 struct route_entry
*newre
;
77 for (afi
= AFI_IP
; afi
<= AFI_IP6
; afi
++) {
79 if (!vrf_bitmap_check(client
->redist_default
[afi
], vrf_id
))
83 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, vrf_id
);
87 /* Lookup default route. */
88 memset(&p
, 0, sizeof(p
));
89 p
.family
= afi2family(afi
);
90 rn
= route_node_lookup(table
, &p
);
94 RNODE_FOREACH_RE (rn
, newre
) {
95 if (CHECK_FLAG(newre
->flags
, ZEBRA_FLAG_SELECTED
)
96 && newre
->distance
!= DISTANCE_INFINITY
)
97 zsend_redistribute_route(
98 ZEBRA_REDISTRIBUTE_ROUTE_ADD
, client
,
102 route_unlock_node(rn
);
106 /* Redistribute routes. */
107 static void zebra_redistribute(struct zserv
*client
, int type
,
108 unsigned short instance
, vrf_id_t vrf_id
,
111 struct route_entry
*newre
;
112 struct route_table
*table
;
113 struct route_node
*rn
;
115 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, vrf_id
);
119 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
))
120 RNODE_FOREACH_RE (rn
, newre
) {
121 const struct prefix
*dst_p
, *src_p
;
123 srcdest_rnode_prefixes(rn
, &dst_p
, &src_p
);
125 if (IS_ZEBRA_DEBUG_RIB
)
127 "%s: client %s %pFX(%u) checking: selected=%d, type=%d, distance=%d, metric=%d zebra_check_addr=%d",
129 zebra_route_string(client
->proto
),
131 CHECK_FLAG(newre
->flags
,
132 ZEBRA_FLAG_SELECTED
),
133 newre
->type
, newre
->distance
,
134 newre
->metric
, zebra_check_addr(dst_p
));
136 if (!CHECK_FLAG(newre
->flags
, ZEBRA_FLAG_SELECTED
))
138 if ((type
!= ZEBRA_ROUTE_ALL
139 && (newre
->type
!= type
140 || newre
->instance
!= instance
)))
142 if (newre
->distance
== DISTANCE_INFINITY
)
144 if (!zebra_check_addr(dst_p
))
147 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
148 client
, dst_p
, src_p
, newre
);
153 * Function to check if prefix is candidate for
156 static bool zebra_redistribute_check(const struct route_entry
*re
,
157 struct zserv
*client
,
158 const struct prefix
*p
, int afi
)
160 /* Process only if there is valid re */
164 /* If default route and redistributed */
165 if (is_default_prefix(p
)
166 && vrf_bitmap_check(client
->redist_default
[afi
], re
->vrf_id
))
169 /* If redistribute in enabled for zebra route all */
170 if (vrf_bitmap_check(client
->redist
[afi
][ZEBRA_ROUTE_ALL
], re
->vrf_id
))
174 * If multi-instance then check for route
175 * redistribution for given instance.
178 && redist_check_instance(&client
->mi_redist
[afi
][re
->type
],
182 /* If redistribution is enabled for give route type. */
183 if (vrf_bitmap_check(client
->redist
[afi
][re
->type
], re
->vrf_id
))
189 /* Either advertise a route for redistribution to registered clients or */
190 /* withdraw redistribution if add cannot be done for client */
191 void redistribute_update(const struct prefix
*p
, const struct prefix
*src_p
,
192 const struct route_entry
*re
,
193 const struct route_entry
*prev_re
)
195 struct listnode
*node
, *nnode
;
196 struct zserv
*client
;
199 if (IS_ZEBRA_DEBUG_RIB
)
201 "(%u:%u):%pFX: Redist update re %p (%s), old %p (%s)",
202 re
->vrf_id
, re
->table
, p
, re
,
203 zebra_route_string(re
->type
), prev_re
,
204 prev_re
? zebra_route_string(prev_re
->type
) : "None");
206 afi
= family2afi(p
->family
);
208 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
209 "%s: Unknown AFI/SAFI prefix received\n", __func__
);
212 if (!zebra_check_addr(p
)) {
213 if (IS_ZEBRA_DEBUG_RIB
)
214 zlog_debug("Redist update filter prefix %pFX", p
);
219 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
220 if (zebra_redistribute_check(re
, client
, p
, afi
)) {
221 if (IS_ZEBRA_DEBUG_RIB
) {
223 "%s: client %s %pFX(%u:%u), type=%d, distance=%d, metric=%d",
225 zebra_route_string(client
->proto
), p
,
226 re
->vrf_id
, re
->table
, re
->type
,
227 re
->distance
, re
->metric
);
229 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
230 client
, p
, src_p
, re
);
231 } else if (zebra_redistribute_check(prev_re
, client
, p
, afi
))
232 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
233 client
, p
, src_p
, prev_re
);
238 * During a route delete, where 'new_re' is NULL, redist a delete to all
239 * clients registered for the type of 'old_re'.
240 * During a route update, redist a delete to any clients who will not see
241 * an update when the new route is installed. There are cases when a client
242 * may have seen a redist for 'old_re', but will not see
243 * the redist for 'new_re'.
245 void redistribute_delete(const struct prefix
*p
, const struct prefix
*src_p
,
246 const struct route_entry
*old_re
,
247 const struct route_entry
*new_re
)
249 struct listnode
*node
, *nnode
;
250 struct zserv
*client
;
255 vrfid
= old_re
->vrf_id
;
257 vrfid
= new_re
->vrf_id
;
261 if (IS_ZEBRA_DEBUG_RIB
) {
262 zlog_debug("%u:%pFX: Redist del: re %p (%s), new re %p (%s)",
264 old_re
? zebra_route_string(old_re
->type
) : "None",
266 new_re
? zebra_route_string(new_re
->type
) : "None");
269 /* Add DISTANCE_INFINITY check. */
270 if (old_re
&& (old_re
->distance
== DISTANCE_INFINITY
)) {
271 if (IS_ZEBRA_DEBUG_RIB
)
272 zlog_debug(" Skipping due to Infinite Distance");
276 afi
= family2afi(p
->family
);
278 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
279 "%s: Unknown AFI/SAFI prefix received\n",
284 /* Skip invalid (e.g. linklocal) prefix */
285 if (!zebra_check_addr(p
)) {
286 if (IS_ZEBRA_DEBUG_RIB
) {
288 "%u:%pFX: Redist del old: skipping invalid prefix",
294 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
295 /* Do not send unsolicited messages to synchronous clients. */
296 if (client
->synchronous
)
299 * Skip this client if it will receive an update for the
302 if (zebra_redistribute_check(new_re
, client
, p
, afi
))
305 /* Send a delete for the 'old' re to any subscribed client. */
306 if (zebra_redistribute_check(old_re
, client
, p
, afi
))
307 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
308 client
, p
, src_p
, old_re
);
313 void zebra_redistribute_add(ZAPI_HANDLER_ARGS
)
317 unsigned short instance
;
319 STREAM_GETC(msg
, afi
);
320 STREAM_GETC(msg
, type
);
321 STREAM_GETW(msg
, instance
);
323 if (IS_ZEBRA_DEBUG_EVENT
)
325 "%s: client proto %s afi=%d, wants %s, vrf %s(%u), instance=%d",
326 __func__
, zebra_route_string(client
->proto
), afi
,
327 zebra_route_string(type
), VRF_LOGNAME(zvrf
->vrf
),
328 zvrf_id(zvrf
), instance
);
330 if (afi
== 0 || afi
>= AFI_MAX
) {
331 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
332 "%s: Specified afi %d does not exist", __func__
, afi
);
336 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
337 zlog_debug("%s: Specified Route Type %d does not exist",
343 if (!redist_check_instance(&client
->mi_redist
[afi
][type
],
345 redist_add_instance(&client
->mi_redist
[afi
][type
],
347 zebra_redistribute(client
, type
, instance
,
351 if (!vrf_bitmap_check(client
->redist
[afi
][type
],
353 if (IS_ZEBRA_DEBUG_EVENT
)
355 "%s: setting vrf %s(%u) redist bitmap",
356 __func__
, VRF_LOGNAME(zvrf
->vrf
),
358 vrf_bitmap_set(client
->redist
[afi
][type
],
360 zebra_redistribute(client
, type
, 0, zvrf_id(zvrf
), afi
);
368 void zebra_redistribute_delete(ZAPI_HANDLER_ARGS
)
372 unsigned short instance
;
374 STREAM_GETC(msg
, afi
);
375 STREAM_GETC(msg
, type
);
376 STREAM_GETW(msg
, instance
);
378 if (afi
== 0 || afi
>= AFI_MAX
) {
379 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
380 "%s: Specified afi %d does not exist", __func__
, afi
);
384 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
385 zlog_debug("%s: Specified Route Type %d does not exist",
391 * NOTE: no need to withdraw the previously advertised routes. The
393 * themselves should keep track of the received routes from zebra and
394 * withdraw them when necessary.
397 redist_del_instance(&client
->mi_redist
[afi
][type
], instance
);
399 vrf_bitmap_unset(client
->redist
[afi
][type
], zvrf_id(zvrf
));
405 void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS
)
409 STREAM_GETC(msg
, afi
);
411 if (afi
== 0 || afi
>= AFI_MAX
) {
412 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
413 "%s: Specified afi %u does not exist", __func__
, afi
);
417 vrf_bitmap_set(client
->redist_default
[afi
], zvrf_id(zvrf
));
418 zebra_redistribute_default(client
, zvrf_id(zvrf
));
424 void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS
)
428 STREAM_GETC(msg
, afi
);
430 if (afi
== 0 || afi
>= AFI_MAX
) {
431 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
432 "%s: Specified afi %u does not exist", __func__
, afi
);
436 vrf_bitmap_unset(client
->redist_default
[afi
], zvrf_id(zvrf
));
442 /* Interface up information. */
443 void zebra_interface_up_update(struct interface
*ifp
)
445 struct listnode
*node
, *nnode
;
446 struct zserv
*client
;
448 if (IS_ZEBRA_DEBUG_EVENT
)
449 zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s(%u)",
450 ifp
->name
, ifp
->vrf_id
);
452 if (ifp
->ptm_status
|| !ifp
->ptm_enable
) {
453 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
,
455 /* Do not send unsolicited messages to synchronous
458 if (client
->synchronous
)
461 zsend_interface_update(ZEBRA_INTERFACE_UP
,
463 zsend_interface_link_params(client
, ifp
);
468 /* Interface down information. */
469 void zebra_interface_down_update(struct interface
*ifp
)
471 struct listnode
*node
, *nnode
;
472 struct zserv
*client
;
474 if (IS_ZEBRA_DEBUG_EVENT
)
475 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s(%u)",
476 ifp
->name
, ifp
->vrf_id
);
478 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
479 /* Do not send unsolicited messages to synchronous clients. */
480 if (client
->synchronous
)
483 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
487 /* Interface information update. */
488 void zebra_interface_add_update(struct interface
*ifp
)
490 struct listnode
*node
, *nnode
;
491 struct zserv
*client
;
493 if (IS_ZEBRA_DEBUG_EVENT
)
494 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s(%u)", ifp
->name
,
497 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
498 /* Do not send unsolicited messages to synchronous clients. */
499 if (client
->synchronous
)
503 zsend_interface_add(client
, ifp
);
504 zsend_interface_link_params(client
, ifp
);
508 void zebra_interface_delete_update(struct interface
*ifp
)
510 struct listnode
*node
, *nnode
;
511 struct zserv
*client
;
513 if (IS_ZEBRA_DEBUG_EVENT
)
514 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s(%u)",
515 ifp
->name
, ifp
->vrf_id
);
517 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
518 /* Do not send unsolicited messages to synchronous clients. */
519 if (client
->synchronous
)
523 zsend_interface_delete(client
, ifp
);
527 /* Interface address addition. */
528 void zebra_interface_address_add_update(struct interface
*ifp
,
529 struct connected
*ifc
)
531 struct listnode
*node
, *nnode
;
532 struct zserv
*client
;
535 if (IS_ZEBRA_DEBUG_EVENT
) {
538 "MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %pFX on %s(%u)",
539 p
, ifp
->name
, ifp
->vrf_id
);
542 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
))
544 EC_ZEBRA_ADVERTISING_UNUSABLE_ADDR
,
545 "WARNING: advertising address to clients that is not yet usable.");
547 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 1);
549 router_id_add_address(ifc
);
551 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
552 /* Do not send unsolicited messages to synchronous clients. */
553 if (client
->synchronous
)
556 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
557 client
->connected_rt_add_cnt
++;
558 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_ADD
,
564 /* Interface address deletion. */
565 void zebra_interface_address_delete_update(struct interface
*ifp
,
566 struct connected
*ifc
)
568 struct listnode
*node
, *nnode
;
569 struct zserv
*client
;
572 if (IS_ZEBRA_DEBUG_EVENT
) {
575 "MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %pFX on %s(%u)",
576 p
, ifp
->name
, ifp
->vrf_id
);
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_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_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
= XCALLOC(MTYPE_RE
, sizeof(struct route_entry
));
689 newre
->type
= ZEBRA_ROUTE_TABLE
;
690 newre
->distance
= zebra_import_table_distance
[afi
][re
->table
];
691 newre
->flags
= re
->flags
;
692 newre
->metric
= re
->metric
;
693 newre
->mtu
= re
->mtu
;
694 newre
->table
= zvrf
->table_id
;
695 newre
->uptime
= monotime(NULL
);
696 newre
->instance
= re
->table
;
698 ng
= nexthop_group_new();
699 copy_nexthops(&ng
->nexthop
, re
->nhe
->nhg
.nexthop
, NULL
);
701 rib_add_multipath(afi
, SAFI_UNICAST
, &p
, NULL
, newre
, ng
);
706 int zebra_del_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
707 struct route_entry
*re
)
712 afi
= family2afi(rn
->p
.family
);
713 prefix_copy(&p
, &rn
->p
);
715 rib_delete(afi
, SAFI_UNICAST
, zvrf
->vrf
->vrf_id
, ZEBRA_ROUTE_TABLE
,
716 re
->table
, re
->flags
, &p
, NULL
, re
->nhe
->nhg
.nexthop
,
717 re
->nhe_id
, zvrf
->table_id
, re
->metric
, re
->distance
,
723 /* Assuming no one calls this with the main routing table */
724 int zebra_import_table(afi_t afi
, vrf_id_t vrf_id
, uint32_t table_id
,
725 uint32_t distance
, const char *rmap_name
, int add
)
727 struct route_table
*table
;
728 struct route_entry
*re
;
729 struct route_node
*rn
;
730 struct zebra_vrf
*zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
732 if (!is_zebra_valid_kernel_table(table_id
)
733 || (table_id
== RT_TABLE_MAIN
))
739 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
, vrf_id
,
743 } else if (IS_ZEBRA_DEBUG_RIB
) {
744 zlog_debug("%s routes from table %d",
745 add
? "Importing" : "Unimporting", table_id
);
750 zebra_add_import_table_route_map(afi
, rmap_name
,
754 zebra_get_import_table_route_map(afi
, table_id
);
756 zebra_del_import_table_route_map(afi
, table_id
);
761 zebra_import_table_used
[afi
][table_id
] = 1;
762 zebra_import_table_distance
[afi
][table_id
] = distance
;
764 zebra_import_table_used
[afi
][table_id
] = 0;
765 zebra_import_table_distance
[afi
][table_id
] =
766 ZEBRA_TABLE_DISTANCE_DEFAULT
;
768 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
770 zebra_del_import_table_route_map(afi
, table_id
);
775 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
776 /* For each entry in the non-default routing table,
777 * add the entry in the main table
782 RNODE_FOREACH_RE (rn
, re
) {
783 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
791 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
792 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
))) {
794 zebra_add_import_table_entry(zvrf
, rn
, re
,
797 zebra_del_import_table_entry(zvrf
, rn
, re
);
803 int zebra_import_table_config(struct vty
*vty
, vrf_id_t vrf_id
)
808 char afi_str
[AFI_MAX
][10] = {"", "ip", "ipv6", "ethernet"};
809 const char *rmap_name
;
811 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
812 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
813 if (!is_zebra_import_table_enabled(afi
, vrf_id
, i
))
816 if (zebra_import_table_distance
[afi
][i
]
817 != ZEBRA_TABLE_DISTANCE_DEFAULT
) {
818 vty_out(vty
, "%s import-table %d distance %d",
820 zebra_import_table_distance
[afi
][i
]);
822 vty_out(vty
, "%s import-table %d", afi_str
[afi
],
826 rmap_name
= zebra_get_import_table_route_map(afi
, i
);
828 vty_out(vty
, " route-map %s", rmap_name
);
838 static void zebra_import_table_rm_update_vrf_afi(struct zebra_vrf
*zvrf
,
839 afi_t afi
, int table_id
,
842 struct route_table
*table
;
843 struct route_entry
*re
;
844 struct route_node
*rn
;
845 const char *rmap_name
;
847 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
848 if ((!rmap_name
) || (strcmp(rmap_name
, rmap
) != 0))
851 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
,
852 zvrf
->vrf
->vrf_id
, table_id
);
854 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
855 zlog_debug("%s: Table id=%d not found", __func__
,
860 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
862 * For each entry in the non-default routing table,
863 * add the entry in the main table
868 RNODE_FOREACH_RE (rn
, re
) {
869 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
877 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
878 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
)))
879 zebra_add_import_table_entry(zvrf
, rn
, re
, rmap_name
);
885 static void zebra_import_table_rm_update_vrf(struct zebra_vrf
*zvrf
,
891 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
892 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
893 if (!is_zebra_import_table_enabled(
894 afi
, zvrf
->vrf
->vrf_id
, i
))
897 zebra_import_table_rm_update_vrf_afi(zvrf
, afi
, i
,
903 void zebra_import_table_rm_update(const char *rmap
)
906 struct zebra_vrf
*zvrf
;
908 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
914 zebra_import_table_rm_update_vrf(zvrf
, rmap
);
918 /* Interface parameters update */
919 void zebra_interface_parameters_update(struct interface
*ifp
)
921 struct listnode
*node
, *nnode
;
922 struct zserv
*client
;
924 if (IS_ZEBRA_DEBUG_EVENT
)
925 zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s(%u)",
926 ifp
->name
, ifp
->vrf_id
);
928 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
929 /* Do not send unsolicited messages to synchronous clients. */
930 if (client
->synchronous
)
933 zsend_interface_link_params(client
, ifp
);