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
;
122 char buf
[PREFIX_STRLEN
];
124 srcdest_rnode_prefixes(rn
, &dst_p
, &src_p
);
126 if (IS_ZEBRA_DEBUG_RIB
)
128 "%s: client %s %s(%u) checking: selected=%d, type=%d, distance=%d, metric=%d zebra_check_addr=%d",
130 zebra_route_string(client
->proto
),
131 prefix2str(dst_p
, buf
, sizeof(buf
)),
132 vrf_id
, CHECK_FLAG(newre
->flags
,
133 ZEBRA_FLAG_SELECTED
),
134 newre
->type
, newre
->distance
,
135 newre
->metric
, zebra_check_addr(dst_p
));
137 if (!CHECK_FLAG(newre
->flags
, ZEBRA_FLAG_SELECTED
))
139 if ((type
!= ZEBRA_ROUTE_ALL
140 && (newre
->type
!= type
141 || newre
->instance
!= instance
)))
143 if (newre
->distance
== DISTANCE_INFINITY
)
145 if (!zebra_check_addr(dst_p
))
148 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
149 client
, dst_p
, src_p
, newre
);
154 * Function to check if prefix is candidate for
157 static bool zebra_redistribute_check(const struct route_entry
*re
,
158 struct zserv
*client
,
159 const struct prefix
*p
, int afi
)
161 /* Process only if there is valid re */
165 /* If default route and redistributed */
166 if (is_default_prefix(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 && redist_check_instance(&client
->mi_redist
[afi
][re
->type
],
183 /* If redistribution is enabled for give route type. */
184 if (vrf_bitmap_check(client
->redist
[afi
][re
->type
], re
->vrf_id
))
190 /* Either advertise a route for redistribution to registered clients or */
191 /* withdraw redistribution if add cannot be done for client */
192 void redistribute_update(const struct prefix
*p
, const struct prefix
*src_p
,
193 const struct route_entry
*re
,
194 const struct route_entry
*prev_re
)
196 struct listnode
*node
, *nnode
;
197 struct zserv
*client
;
199 char buf
[PREFIX_STRLEN
];
201 if (IS_ZEBRA_DEBUG_RIB
) {
203 "%u:%s: Redist update re %p (%s), old %p (%s)",
204 re
->vrf_id
, prefix2str(p
, buf
, sizeof(buf
)),
205 re
, zebra_route_string(re
->type
), prev_re
,
206 prev_re
? zebra_route_string(prev_re
->type
) : "None");
209 afi
= family2afi(p
->family
);
211 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
212 "%s: Unknown AFI/SAFI prefix received\n", __func__
);
215 if (!zebra_check_addr(p
)) {
216 if (IS_ZEBRA_DEBUG_RIB
)
217 zlog_debug("Redist update filter prefix %s",
218 prefix2str(p
, buf
, sizeof(buf
)));
223 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
224 if (zebra_redistribute_check(re
, client
, p
, afi
)) {
225 if (IS_ZEBRA_DEBUG_RIB
) {
227 "%s: client %s %s(%u), type=%d, distance=%d, metric=%d",
229 zebra_route_string(client
->proto
),
230 prefix2str(p
, buf
, sizeof(buf
)),
231 re
->vrf_id
, re
->type
,
232 re
->distance
, re
->metric
);
234 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
235 client
, p
, src_p
, re
);
236 } else if (zebra_redistribute_check(prev_re
, client
, p
, afi
))
237 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
238 client
, p
, src_p
, prev_re
);
243 * During a route delete, where 'new_re' is NULL, redist a delete to all
244 * clients registered for the type of 'old_re'.
245 * During a route update, redist a delete to any clients who will not see
246 * an update when the new route is installed. There are cases when a client
247 * may have seen a redist for 'old_re', but will not see
248 * the redist for 'new_re'.
250 void redistribute_delete(const struct prefix
*p
, const struct prefix
*src_p
,
251 const struct route_entry
*old_re
,
252 const struct route_entry
*new_re
)
254 struct listnode
*node
, *nnode
;
255 struct zserv
*client
;
257 char buf
[PREFIX_STRLEN
];
261 vrfid
= old_re
->vrf_id
;
263 vrfid
= new_re
->vrf_id
;
267 if (IS_ZEBRA_DEBUG_RIB
) {
269 "%u:%s: Redist del: re %p (%s), new re %p (%s)",
270 vrfid
, prefix2str(p
, buf
, sizeof(buf
)),
272 old_re
? zebra_route_string(old_re
->type
) : "None",
274 new_re
? zebra_route_string(new_re
->type
) : "None");
277 /* Add DISTANCE_INFINITY check. */
278 if (old_re
&& (old_re
->distance
== DISTANCE_INFINITY
)) {
279 if (IS_ZEBRA_DEBUG_RIB
)
280 zlog_debug(" Skipping due to Infinite Distance");
284 afi
= family2afi(p
->family
);
286 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
287 "%s: Unknown AFI/SAFI prefix received\n",
292 /* Skip invalid (e.g. linklocal) prefix */
293 if (!zebra_check_addr(p
)) {
294 if (IS_ZEBRA_DEBUG_RIB
) {
296 "%u:%s: Redist del old: skipping invalid prefix",
297 vrfid
, prefix2str(p
, buf
, sizeof(buf
)));
302 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
303 /* Do not send unsolicited messages to synchronous clients. */
304 if (client
->synchronous
)
307 * Skip this client if it will receive an update for the
310 if (zebra_redistribute_check(new_re
, client
, p
, afi
))
313 /* Send a delete for the 'old' re to any subscribed client. */
314 if (zebra_redistribute_check(old_re
, client
, p
, afi
))
315 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
316 client
, p
, src_p
, old_re
);
321 void zebra_redistribute_add(ZAPI_HANDLER_ARGS
)
325 unsigned short instance
;
327 STREAM_GETC(msg
, afi
);
328 STREAM_GETC(msg
, type
);
329 STREAM_GETW(msg
, instance
);
331 if (IS_ZEBRA_DEBUG_EVENT
)
333 "%s: client proto %s afi=%d, wants %s, vrf %s(%u), instance=%d",
334 __func__
, zebra_route_string(client
->proto
), afi
,
335 zebra_route_string(type
), VRF_LOGNAME(zvrf
->vrf
),
336 zvrf_id(zvrf
), instance
);
338 if (afi
== 0 || afi
>= AFI_MAX
) {
339 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
340 "%s: Specified afi %d does not exist", __func__
, afi
);
344 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
345 zlog_debug("%s: Specified Route Type %d does not exist",
351 if (!redist_check_instance(&client
->mi_redist
[afi
][type
],
353 redist_add_instance(&client
->mi_redist
[afi
][type
],
355 zebra_redistribute(client
, type
, instance
,
359 if (!vrf_bitmap_check(client
->redist
[afi
][type
],
361 if (IS_ZEBRA_DEBUG_EVENT
)
363 "%s: setting vrf %s(%u) redist bitmap",
364 __func__
, VRF_LOGNAME(zvrf
->vrf
),
366 vrf_bitmap_set(client
->redist
[afi
][type
],
368 zebra_redistribute(client
, type
, 0, zvrf_id(zvrf
), afi
);
376 void zebra_redistribute_delete(ZAPI_HANDLER_ARGS
)
380 unsigned short instance
;
382 STREAM_GETC(msg
, afi
);
383 STREAM_GETC(msg
, type
);
384 STREAM_GETW(msg
, instance
);
386 if (afi
== 0 || afi
>= AFI_MAX
) {
387 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
388 "%s: Specified afi %d does not exist", __func__
, afi
);
392 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
393 zlog_debug("%s: Specified Route Type %d does not exist",
399 * NOTE: no need to withdraw the previously advertised routes. The
401 * themselves should keep track of the received routes from zebra and
402 * withdraw them when necessary.
405 redist_del_instance(&client
->mi_redist
[afi
][type
], instance
);
407 vrf_bitmap_unset(client
->redist
[afi
][type
], zvrf_id(zvrf
));
413 void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS
)
417 STREAM_GETC(msg
, afi
);
419 if (afi
== 0 || afi
>= AFI_MAX
) {
420 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
421 "%s: Specified afi %u does not exist", __func__
, afi
);
425 vrf_bitmap_set(client
->redist_default
[afi
], zvrf_id(zvrf
));
426 zebra_redistribute_default(client
, zvrf_id(zvrf
));
432 void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS
)
436 STREAM_GETC(msg
, afi
);
438 if (afi
== 0 || afi
>= AFI_MAX
) {
439 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
440 "%s: Specified afi %u does not exist", __func__
, afi
);
444 vrf_bitmap_unset(client
->redist_default
[afi
], zvrf_id(zvrf
));
450 /* Interface up information. */
451 void zebra_interface_up_update(struct interface
*ifp
)
453 struct listnode
*node
, *nnode
;
454 struct zserv
*client
;
456 if (IS_ZEBRA_DEBUG_EVENT
)
457 zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s(%u)",
458 ifp
->name
, ifp
->vrf_id
);
460 if (ifp
->ptm_status
|| !ifp
->ptm_enable
) {
461 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
,
463 /* Do not send unsolicited messages to synchronous
466 if (client
->synchronous
)
469 zsend_interface_update(ZEBRA_INTERFACE_UP
,
471 zsend_interface_link_params(client
, ifp
);
476 /* Interface down information. */
477 void zebra_interface_down_update(struct interface
*ifp
)
479 struct listnode
*node
, *nnode
;
480 struct zserv
*client
;
482 if (IS_ZEBRA_DEBUG_EVENT
)
483 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s(%u)",
484 ifp
->name
, ifp
->vrf_id
);
486 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
487 /* Do not send unsolicited messages to synchronous clients. */
488 if (client
->synchronous
)
491 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
495 /* Interface information update. */
496 void zebra_interface_add_update(struct interface
*ifp
)
498 struct listnode
*node
, *nnode
;
499 struct zserv
*client
;
501 if (IS_ZEBRA_DEBUG_EVENT
)
502 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s(%u)", ifp
->name
,
505 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
506 /* Do not send unsolicited messages to synchronous clients. */
507 if (client
->synchronous
)
511 zsend_interface_add(client
, ifp
);
512 zsend_interface_link_params(client
, ifp
);
516 void zebra_interface_delete_update(struct interface
*ifp
)
518 struct listnode
*node
, *nnode
;
519 struct zserv
*client
;
521 if (IS_ZEBRA_DEBUG_EVENT
)
522 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s(%u)",
523 ifp
->name
, ifp
->vrf_id
);
525 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
526 /* Do not send unsolicited messages to synchronous clients. */
527 if (client
->synchronous
)
531 zsend_interface_delete(client
, ifp
);
535 /* Interface address addition. */
536 void zebra_interface_address_add_update(struct interface
*ifp
,
537 struct connected
*ifc
)
539 struct listnode
*node
, *nnode
;
540 struct zserv
*client
;
543 if (IS_ZEBRA_DEBUG_EVENT
) {
544 char buf
[PREFIX_STRLEN
];
547 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s on %s(%u)",
548 prefix2str(p
, buf
, sizeof(buf
)), ifp
->name
,
552 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
))
554 EC_ZEBRA_ADVERTISING_UNUSABLE_ADDR
,
555 "WARNING: advertising address to clients that is not yet usable.");
557 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 1);
559 router_id_add_address(ifc
);
561 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
562 /* Do not send unsolicited messages to synchronous clients. */
563 if (client
->synchronous
)
566 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
567 client
->connected_rt_add_cnt
++;
568 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_ADD
,
574 /* Interface address deletion. */
575 void zebra_interface_address_delete_update(struct interface
*ifp
,
576 struct connected
*ifc
)
578 struct listnode
*node
, *nnode
;
579 struct zserv
*client
;
582 if (IS_ZEBRA_DEBUG_EVENT
) {
583 char buf
[PREFIX_STRLEN
];
586 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s on %s(%u)",
587 prefix2str(p
, buf
, sizeof(buf
)),
588 ifp
->name
, ifp
->vrf_id
);
591 zebra_vxlan_add_del_gw_macip(ifp
, ifc
->address
, 0);
593 router_id_del_address(ifc
);
595 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
596 /* Do not send unsolicited messages to synchronous clients. */
597 if (client
->synchronous
)
600 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
601 client
->connected_rt_del_cnt
++;
602 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_DELETE
,
608 /* Interface VRF change. May need to delete from clients not interested in
609 * the new VRF. Note that this function is invoked *prior* to the VRF change.
611 void zebra_interface_vrf_update_del(struct interface
*ifp
, vrf_id_t new_vrf_id
)
613 struct listnode
*node
, *nnode
;
614 struct zserv
*client
;
616 if (IS_ZEBRA_DEBUG_EVENT
)
618 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/DEL %s VRF Id %u -> %u",
619 ifp
->name
, ifp
->vrf_id
, new_vrf_id
);
621 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
622 /* Do not send unsolicited messages to synchronous clients. */
623 if (client
->synchronous
)
626 /* Need to delete if the client is not interested in the new
628 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
630 zsend_interface_delete(client
, ifp
);
631 zsend_interface_vrf_update(client
, ifp
, new_vrf_id
);
635 /* Interface VRF change. This function is invoked *post* VRF change and sends an
636 * add to clients who are interested in the new VRF but not in the old VRF.
638 void zebra_interface_vrf_update_add(struct interface
*ifp
, vrf_id_t old_vrf_id
)
640 struct listnode
*node
, *nnode
;
641 struct zserv
*client
;
643 if (IS_ZEBRA_DEBUG_EVENT
)
645 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/ADD %s VRF Id %u -> %u",
646 ifp
->name
, old_vrf_id
, ifp
->vrf_id
);
648 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
649 /* Do not send unsolicited messages to synchronous clients. */
650 if (client
->synchronous
)
653 /* Need to add if the client is interested in the new VRF. */
655 zsend_interface_add(client
, ifp
);
656 zsend_interface_addresses(client
, ifp
);
660 int zebra_add_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
661 struct route_entry
*re
, const char *rmap_name
)
663 struct route_entry
*newre
;
664 struct route_entry
*same
;
666 struct nexthop_group
*ng
;
667 route_map_result_t ret
= RMAP_PERMITMATCH
;
670 afi
= family2afi(rn
->p
.family
);
672 ret
= zebra_import_table_route_map_check(
673 afi
, re
->type
, re
->instance
, &rn
->p
,
674 re
->nhe
->nhg
.nexthop
,
675 zvrf
->vrf
->vrf_id
, re
->tag
, rmap_name
);
677 if (ret
!= RMAP_PERMITMATCH
) {
678 UNSET_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
);
679 zebra_del_import_table_entry(zvrf
, rn
, re
);
683 prefix_copy(&p
, &rn
->p
);
685 RNODE_FOREACH_RE (rn
, same
) {
686 if (CHECK_FLAG(same
->status
, ROUTE_ENTRY_REMOVED
))
689 if (same
->type
== re
->type
&& same
->instance
== re
->instance
690 && same
->table
== re
->table
691 && same
->type
!= ZEBRA_ROUTE_CONNECT
)
696 UNSET_FLAG(same
->flags
, ZEBRA_FLAG_SELECTED
);
697 zebra_del_import_table_entry(zvrf
, rn
, same
);
700 newre
= XCALLOC(MTYPE_RE
, sizeof(struct route_entry
));
701 newre
->type
= ZEBRA_ROUTE_TABLE
;
702 newre
->distance
= zebra_import_table_distance
[afi
][re
->table
];
703 newre
->flags
= re
->flags
;
704 newre
->metric
= re
->metric
;
705 newre
->mtu
= re
->mtu
;
706 newre
->table
= zvrf
->table_id
;
707 newre
->uptime
= monotime(NULL
);
708 newre
->instance
= re
->table
;
710 ng
= nexthop_group_new();
711 copy_nexthops(&ng
->nexthop
, re
->nhe
->nhg
.nexthop
, NULL
);
713 rib_add_multipath(afi
, SAFI_UNICAST
, &p
, NULL
, newre
, ng
);
718 int zebra_del_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
719 struct route_entry
*re
)
724 afi
= family2afi(rn
->p
.family
);
725 prefix_copy(&p
, &rn
->p
);
727 rib_delete(afi
, SAFI_UNICAST
, zvrf
->vrf
->vrf_id
, ZEBRA_ROUTE_TABLE
,
728 re
->table
, re
->flags
, &p
, NULL
, re
->nhe
->nhg
.nexthop
,
729 re
->nhe_id
, zvrf
->table_id
, re
->metric
, re
->distance
,
735 /* Assuming no one calls this with the main routing table */
736 int zebra_import_table(afi_t afi
, vrf_id_t vrf_id
, uint32_t table_id
,
737 uint32_t distance
, const char *rmap_name
, int add
)
739 struct route_table
*table
;
740 struct route_entry
*re
;
741 struct route_node
*rn
;
742 struct zebra_vrf
*zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
744 if (!is_zebra_valid_kernel_table(table_id
)
745 || (table_id
== RT_TABLE_MAIN
))
751 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
, vrf_id
,
755 } else if (IS_ZEBRA_DEBUG_RIB
) {
756 zlog_debug("%s routes from table %d",
757 add
? "Importing" : "Unimporting", table_id
);
762 zebra_add_import_table_route_map(afi
, rmap_name
,
766 zebra_get_import_table_route_map(afi
, table_id
);
768 zebra_del_import_table_route_map(afi
, table_id
);
773 zebra_import_table_used
[afi
][table_id
] = 1;
774 zebra_import_table_distance
[afi
][table_id
] = distance
;
776 zebra_import_table_used
[afi
][table_id
] = 0;
777 zebra_import_table_distance
[afi
][table_id
] =
778 ZEBRA_TABLE_DISTANCE_DEFAULT
;
780 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
782 zebra_del_import_table_route_map(afi
, table_id
);
787 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
788 /* For each entry in the non-default routing table,
789 * add the entry in the main table
794 RNODE_FOREACH_RE (rn
, re
) {
795 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
803 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
804 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
))) {
806 zebra_add_import_table_entry(zvrf
, rn
, re
,
809 zebra_del_import_table_entry(zvrf
, rn
, re
);
815 int zebra_import_table_config(struct vty
*vty
, vrf_id_t vrf_id
)
820 char afi_str
[AFI_MAX
][10] = {"", "ip", "ipv6", "ethernet"};
821 const char *rmap_name
;
823 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
824 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
825 if (!is_zebra_import_table_enabled(afi
, vrf_id
, i
))
828 if (zebra_import_table_distance
[afi
][i
]
829 != ZEBRA_TABLE_DISTANCE_DEFAULT
) {
830 vty_out(vty
, "%s import-table %d distance %d",
832 zebra_import_table_distance
[afi
][i
]);
834 vty_out(vty
, "%s import-table %d", afi_str
[afi
],
838 rmap_name
= zebra_get_import_table_route_map(afi
, i
);
840 vty_out(vty
, " route-map %s", rmap_name
);
850 static void zebra_import_table_rm_update_vrf_afi(struct zebra_vrf
*zvrf
,
851 afi_t afi
, int table_id
,
854 struct route_table
*table
;
855 struct route_entry
*re
;
856 struct route_node
*rn
;
857 const char *rmap_name
;
859 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
860 if ((!rmap_name
) || (strcmp(rmap_name
, rmap
) != 0))
863 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
,
864 zvrf
->vrf
->vrf_id
, table_id
);
866 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
867 zlog_debug("%s: Table id=%d not found", __func__
,
872 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
874 * For each entry in the non-default routing table,
875 * add the entry in the main table
880 RNODE_FOREACH_RE (rn
, re
) {
881 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
889 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
890 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
)))
891 zebra_add_import_table_entry(zvrf
, rn
, re
, rmap_name
);
897 static void zebra_import_table_rm_update_vrf(struct zebra_vrf
*zvrf
,
903 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
904 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
905 if (!is_zebra_import_table_enabled(
906 afi
, zvrf
->vrf
->vrf_id
, i
))
909 zebra_import_table_rm_update_vrf_afi(zvrf
, afi
, i
,
915 void zebra_import_table_rm_update(const char *rmap
)
918 struct zebra_vrf
*zvrf
;
920 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
926 zebra_import_table_rm_update_vrf(zvrf
, rmap
);
930 /* Interface parameters update */
931 void zebra_interface_parameters_update(struct interface
*ifp
)
933 struct listnode
*node
, *nnode
;
934 struct zserv
*client
;
936 if (IS_ZEBRA_DEBUG_EVENT
)
937 zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s(%u)",
938 ifp
->name
, ifp
->vrf_id
);
940 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
941 /* Do not send unsolicited messages to synchronous clients. */
942 if (client
->synchronous
)
945 zsend_interface_link_params(client
, ifp
);