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 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, vrf_id
);
83 /* Lookup default route. */
84 memset(&p
, 0, sizeof(p
));
85 p
.family
= afi2family(afi
);
86 rn
= route_node_lookup(table
, &p
);
90 RNODE_FOREACH_RE (rn
, newre
) {
91 if (CHECK_FLAG(newre
->flags
, ZEBRA_FLAG_SELECTED
)
92 && newre
->distance
!= DISTANCE_INFINITY
)
93 zsend_redistribute_route(
94 ZEBRA_REDISTRIBUTE_ROUTE_ADD
, client
,
98 route_unlock_node(rn
);
102 /* Redistribute routes. */
103 static void zebra_redistribute(struct zserv
*client
, int type
,
104 unsigned short instance
, vrf_id_t vrf_id
,
107 struct route_entry
*newre
;
108 struct route_table
*table
;
109 struct route_node
*rn
;
111 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, vrf_id
);
115 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
))
116 RNODE_FOREACH_RE (rn
, newre
) {
117 const struct prefix
*dst_p
, *src_p
;
118 char buf
[PREFIX_STRLEN
];
120 srcdest_rnode_prefixes(rn
, &dst_p
, &src_p
);
122 if (IS_ZEBRA_DEBUG_RIB
)
124 "%s: client %s %s(%u) checking: selected=%d, type=%d, distance=%d, metric=%d zebra_check_addr=%d",
126 zebra_route_string(client
->proto
),
127 prefix2str(dst_p
, buf
, sizeof(buf
)),
128 vrf_id
, CHECK_FLAG(newre
->flags
,
129 ZEBRA_FLAG_SELECTED
),
130 newre
->type
, newre
->distance
,
131 newre
->metric
, zebra_check_addr(dst_p
));
133 if (!CHECK_FLAG(newre
->flags
, ZEBRA_FLAG_SELECTED
))
135 if ((type
!= ZEBRA_ROUTE_ALL
136 && (newre
->type
!= type
137 || newre
->instance
!= instance
)))
139 if (newre
->distance
== DISTANCE_INFINITY
)
141 if (!zebra_check_addr(dst_p
))
144 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
145 client
, dst_p
, src_p
, newre
);
149 /* Either advertise a route for redistribution to registered clients or */
150 /* withdraw redistribution if add cannot be done for client */
151 void redistribute_update(const struct prefix
*p
, const struct prefix
*src_p
,
152 const struct route_entry
*re
,
153 const struct route_entry
*prev_re
)
155 struct listnode
*node
, *nnode
;
156 struct zserv
*client
;
157 int send_redistribute
;
159 char buf
[PREFIX_STRLEN
];
161 if (IS_ZEBRA_DEBUG_RIB
) {
163 "%u:%s: Redist update re %p (%s), old %p (%s)",
164 re
->vrf_id
, prefix2str(p
, buf
, sizeof(buf
)),
165 re
, zebra_route_string(re
->type
), prev_re
,
166 prev_re
? zebra_route_string(prev_re
->type
) : "None");
169 afi
= family2afi(p
->family
);
171 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
172 "%s: Unknown AFI/SAFI prefix received\n",
176 if (!zebra_check_addr(p
)) {
177 if (IS_ZEBRA_DEBUG_RIB
)
178 zlog_debug("Redist update filter prefix %s",
179 prefix2str(p
, buf
, sizeof(buf
)));
184 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
185 send_redistribute
= 0;
187 if (is_default_prefix(p
)
188 && vrf_bitmap_check(client
->redist_default
[afi
],
190 send_redistribute
= 1;
191 else if (vrf_bitmap_check(client
->redist
[afi
][ZEBRA_ROUTE_ALL
],
193 send_redistribute
= 1;
194 else if (re
->instance
195 && redist_check_instance(
196 &client
->mi_redist
[afi
][re
->type
],
198 send_redistribute
= 1;
199 else if (vrf_bitmap_check(client
->redist
[afi
][re
->type
],
201 send_redistribute
= 1;
203 if (send_redistribute
) {
204 if (IS_ZEBRA_DEBUG_RIB
) {
206 "%s: client %s %s(%u), type=%d, distance=%d, metric=%d",
208 zebra_route_string(client
->proto
),
209 prefix2str(p
, buf
, sizeof(buf
)),
210 re
->vrf_id
, re
->type
,
211 re
->distance
, re
->metric
);
213 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
214 client
, p
, src_p
, re
);
217 && redist_check_instance(
218 &client
->mi_redist
[afi
]
222 client
->redist
[afi
][prev_re
->type
],
224 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
225 client
, p
, src_p
, prev_re
);
231 * During a route delete, where 'new_re' is NULL, redist a delete to all
232 * clients registered for the type of 'old_re'.
233 * During a route update, redist a delete to any clients who will not see
234 * an update when the new route is installed. There are cases when a client
235 * may have seen a redist for 'old_re', but will not see
236 * the redist for 'new_re'.
238 void redistribute_delete(const struct prefix
*p
, const struct prefix
*src_p
,
239 const struct route_entry
*old_re
,
240 const struct route_entry
*new_re
)
242 struct listnode
*node
, *nnode
;
243 struct zserv
*client
;
245 char buf
[PREFIX_STRLEN
];
249 vrfid
= old_re
->vrf_id
;
251 vrfid
= new_re
->vrf_id
;
255 if (IS_ZEBRA_DEBUG_RIB
) {
257 "%u:%s: Redist del: re %p (%s), new re %p (%s)",
258 vrfid
, prefix2str(p
, buf
, sizeof(buf
)),
260 old_re
? zebra_route_string(old_re
->type
) : "None",
262 new_re
? zebra_route_string(new_re
->type
) : "None");
265 /* Add DISTANCE_INFINITY check. */
266 if (old_re
&& (old_re
->distance
== DISTANCE_INFINITY
)) {
267 if (IS_ZEBRA_DEBUG_RIB
)
268 zlog_debug("\tSkipping due to Infinite Distance");
272 afi
= family2afi(p
->family
);
274 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
275 "%s: Unknown AFI/SAFI prefix received\n",
280 /* Skip invalid (e.g. linklocal) prefix */
281 if (!zebra_check_addr(p
)) {
282 if (IS_ZEBRA_DEBUG_RIB
) {
284 "%u:%s: Redist del old: skipping invalid prefix",
285 vrfid
, prefix2str(p
, buf
, sizeof(buf
)));
290 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
292 /* Skip this client if it will receive an update for the
295 if (is_default_prefix(p
)
296 && vrf_bitmap_check(client
->redist_default
[afi
],
299 else if (vrf_bitmap_check(
300 client
->redist
[afi
][ZEBRA_ROUTE_ALL
],
303 else if (new_re
->instance
304 && redist_check_instance(
305 &client
->mi_redist
[afi
][new_re
->type
],
308 else if (vrf_bitmap_check(
309 client
->redist
[afi
][new_re
->type
],
314 /* Send a delete for the 'old' re to any subscribed client. */
316 && (vrf_bitmap_check(client
->redist
[afi
][ZEBRA_ROUTE_ALL
],
319 && redist_check_instance(
320 &client
->mi_redist
[afi
][old_re
->type
],
322 || vrf_bitmap_check(client
->redist
[afi
][old_re
->type
],
324 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
325 client
, p
, src_p
, old_re
);
330 void zebra_redistribute_add(ZAPI_HANDLER_ARGS
)
334 unsigned short instance
;
336 STREAM_GETC(msg
, afi
);
337 STREAM_GETC(msg
, type
);
338 STREAM_GETW(msg
, instance
);
340 if (IS_ZEBRA_DEBUG_EVENT
)
342 "%s: client proto %s afi=%d, wants %s, vrf %u, instance=%d",
343 __func__
, zebra_route_string(client
->proto
), afi
,
344 zebra_route_string(type
), zvrf_id(zvrf
), instance
);
346 if (afi
== 0 || afi
>= AFI_MAX
) {
347 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
348 "%s: Specified afi %d does not exist",
349 __PRETTY_FUNCTION__
, afi
);
353 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
354 zlog_debug("%s: Specified Route Type %d does not exist",
355 __PRETTY_FUNCTION__
, type
);
360 if (!redist_check_instance(&client
->mi_redist
[afi
][type
],
362 redist_add_instance(&client
->mi_redist
[afi
][type
],
364 zebra_redistribute(client
, type
, instance
,
368 if (!vrf_bitmap_check(client
->redist
[afi
][type
],
370 if (IS_ZEBRA_DEBUG_EVENT
)
371 zlog_debug("%s: setting vrf %u redist bitmap",
372 __func__
, zvrf_id(zvrf
));
373 vrf_bitmap_set(client
->redist
[afi
][type
],
375 zebra_redistribute(client
, type
, 0, zvrf_id(zvrf
), afi
);
383 void zebra_redistribute_delete(ZAPI_HANDLER_ARGS
)
387 unsigned short instance
;
389 STREAM_GETC(msg
, afi
);
390 STREAM_GETC(msg
, type
);
391 STREAM_GETW(msg
, instance
);
393 if (afi
== 0 || afi
>= AFI_MAX
) {
394 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
395 "%s: Specified afi %d does not exist",
396 __PRETTY_FUNCTION__
, afi
);
400 if (type
== 0 || type
>= ZEBRA_ROUTE_MAX
) {
401 zlog_debug("%s: Specified Route Type %d does not exist",
402 __PRETTY_FUNCTION__
, type
);
407 * NOTE: no need to withdraw the previously advertised routes. The
409 * themselves should keep track of the received routes from zebra and
410 * withdraw them when necessary.
413 redist_del_instance(&client
->mi_redist
[afi
][type
], instance
);
415 vrf_bitmap_unset(client
->redist
[afi
][type
], zvrf_id(zvrf
));
421 void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS
)
425 STREAM_GETC(msg
, afi
);
427 if (afi
== 0 || afi
>= AFI_MAX
) {
428 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
429 "%s: Specified afi %u does not exist",
430 __PRETTY_FUNCTION__
, afi
);
434 vrf_bitmap_set(client
->redist_default
[afi
], zvrf_id(zvrf
));
435 zebra_redistribute_default(client
, zvrf_id(zvrf
));
441 void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS
)
445 STREAM_GETC(msg
, afi
);
447 if (afi
== 0 || afi
>= AFI_MAX
) {
448 flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF
,
449 "%s: Specified afi %u does not exist",
450 __PRETTY_FUNCTION__
, afi
);
454 vrf_bitmap_unset(client
->redist_default
[afi
], zvrf_id(zvrf
));
460 /* Interface up information. */
461 void zebra_interface_up_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_UP %s(%u)",
468 ifp
->name
, ifp
->vrf_id
);
470 if (ifp
->ptm_status
|| !ifp
->ptm_enable
) {
471 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
,
473 zsend_interface_update(ZEBRA_INTERFACE_UP
,
475 zsend_interface_link_params(client
, ifp
);
480 /* Interface down information. */
481 void zebra_interface_down_update(struct interface
*ifp
)
483 struct listnode
*node
, *nnode
;
484 struct zserv
*client
;
486 if (IS_ZEBRA_DEBUG_EVENT
)
487 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s(%u)",
488 ifp
->name
, ifp
->vrf_id
);
490 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
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
)) {
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(%u)",
519 ifp
->name
, ifp
->vrf_id
);
521 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
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
) {
536 char buf
[PREFIX_STRLEN
];
539 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s on %s(%u)",
540 prefix2str(p
, buf
, sizeof(buf
)), ifp
->name
,
544 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
))
546 EC_ZEBRA_ADVERTISING_UNUSABLE_ADDR
,
547 "WARNING: 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 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
555 client
->connected_rt_add_cnt
++;
556 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_ADD
,
561 /* Interface address deletion. */
562 void zebra_interface_address_delete_update(struct interface
*ifp
,
563 struct connected
*ifc
)
565 struct listnode
*node
, *nnode
;
566 struct zserv
*client
;
569 if (IS_ZEBRA_DEBUG_EVENT
) {
570 char buf
[PREFIX_STRLEN
];
573 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s on %s(%u)",
574 prefix2str(p
, buf
, sizeof(buf
)),
575 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 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
)) {
584 client
->connected_rt_del_cnt
++;
585 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_DELETE
,
590 /* Interface VRF change. May need to delete from clients not interested in
591 * the new VRF. Note that this function is invoked *prior* to the VRF change.
593 void zebra_interface_vrf_update_del(struct interface
*ifp
, vrf_id_t new_vrf_id
)
595 struct listnode
*node
, *nnode
;
596 struct zserv
*client
;
598 if (IS_ZEBRA_DEBUG_EVENT
)
600 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/DEL %s VRF Id %u -> %u",
601 ifp
->name
, ifp
->vrf_id
, new_vrf_id
);
603 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
604 /* Need to delete if the client is not interested in the new
606 zsend_interface_update(ZEBRA_INTERFACE_DOWN
, client
, ifp
);
608 zsend_interface_delete(client
, ifp
);
609 zsend_interface_vrf_update(client
, ifp
, new_vrf_id
);
613 /* Interface VRF change. This function is invoked *post* VRF change and sends an
614 * add to clients who are interested in the new VRF but not in the old VRF.
616 void zebra_interface_vrf_update_add(struct interface
*ifp
, vrf_id_t old_vrf_id
)
618 struct listnode
*node
, *nnode
;
619 struct zserv
*client
;
621 if (IS_ZEBRA_DEBUG_EVENT
)
623 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/ADD %s VRF Id %u -> %u",
624 ifp
->name
, old_vrf_id
, ifp
->vrf_id
);
626 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
)) {
627 /* Need to add if the client is interested in the new VRF. */
629 zsend_interface_add(client
, ifp
);
630 zsend_interface_addresses(client
, ifp
);
634 int zebra_add_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
635 struct route_entry
*re
, const char *rmap_name
)
637 struct route_entry
*newre
;
638 struct route_entry
*same
;
640 struct nexthop_group
*ng
;
641 route_map_result_t ret
= RMAP_PERMITMATCH
;
644 afi
= family2afi(rn
->p
.family
);
646 ret
= zebra_import_table_route_map_check(
647 afi
, re
->type
, re
->instance
, &rn
->p
,
648 re
->nhe
->nhg
->nexthop
,
649 zvrf
->vrf
->vrf_id
, re
->tag
, rmap_name
);
651 if (ret
!= RMAP_PERMITMATCH
) {
652 UNSET_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
);
653 zebra_del_import_table_entry(zvrf
, rn
, re
);
657 prefix_copy(&p
, &rn
->p
);
659 RNODE_FOREACH_RE (rn
, same
) {
660 if (CHECK_FLAG(same
->status
, ROUTE_ENTRY_REMOVED
))
663 if (same
->type
== re
->type
&& same
->instance
== re
->instance
664 && same
->table
== re
->table
665 && same
->type
!= ZEBRA_ROUTE_CONNECT
)
670 UNSET_FLAG(same
->flags
, ZEBRA_FLAG_SELECTED
);
671 zebra_del_import_table_entry(zvrf
, rn
, same
);
674 newre
= XCALLOC(MTYPE_RE
, sizeof(struct route_entry
));
675 newre
->type
= ZEBRA_ROUTE_TABLE
;
676 newre
->distance
= zebra_import_table_distance
[afi
][re
->table
];
677 newre
->flags
= re
->flags
;
678 newre
->metric
= re
->metric
;
679 newre
->mtu
= re
->mtu
;
680 newre
->table
= zvrf
->table_id
;
681 newre
->uptime
= monotime(NULL
);
682 newre
->instance
= re
->table
;
684 ng
= nexthop_group_new();
685 copy_nexthops(&ng
->nexthop
, re
->nhe
->nhg
->nexthop
, NULL
);
687 rib_add_multipath(afi
, SAFI_UNICAST
, &p
, NULL
, newre
, ng
);
692 int zebra_del_import_table_entry(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
693 struct route_entry
*re
)
698 afi
= family2afi(rn
->p
.family
);
699 prefix_copy(&p
, &rn
->p
);
701 rib_delete(afi
, SAFI_UNICAST
, zvrf
->vrf
->vrf_id
, ZEBRA_ROUTE_TABLE
,
702 re
->table
, re
->flags
, &p
, NULL
, re
->nhe
->nhg
->nexthop
,
703 re
->nhe_id
, zvrf
->table_id
, re
->metric
, re
->distance
,
709 /* Assuming no one calls this with the main routing table */
710 int zebra_import_table(afi_t afi
, vrf_id_t vrf_id
, uint32_t table_id
,
711 uint32_t distance
, const char *rmap_name
, int add
)
713 struct route_table
*table
;
714 struct route_entry
*re
;
715 struct route_node
*rn
;
716 struct zebra_vrf
*zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
718 if (!is_zebra_valid_kernel_table(table_id
)
719 || (table_id
== RT_TABLE_MAIN
))
725 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
, vrf_id
,
729 } else if (IS_ZEBRA_DEBUG_RIB
) {
730 zlog_debug("%s routes from table %d",
731 add
? "Importing" : "Unimporting", table_id
);
736 zebra_add_import_table_route_map(afi
, rmap_name
,
740 zebra_get_import_table_route_map(afi
, table_id
);
742 zebra_del_import_table_route_map(afi
, table_id
);
747 zebra_import_table_used
[afi
][table_id
] = 1;
748 zebra_import_table_distance
[afi
][table_id
] = distance
;
750 zebra_import_table_used
[afi
][table_id
] = 0;
751 zebra_import_table_distance
[afi
][table_id
] =
752 ZEBRA_TABLE_DISTANCE_DEFAULT
;
754 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
756 zebra_del_import_table_route_map(afi
, table_id
);
761 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
762 /* For each entry in the non-default routing table,
763 * add the entry in the main table
768 RNODE_FOREACH_RE (rn
, re
) {
769 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
777 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
778 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
))) {
780 zebra_add_import_table_entry(zvrf
, rn
, re
,
783 zebra_del_import_table_entry(zvrf
, rn
, re
);
789 int zebra_import_table_config(struct vty
*vty
, vrf_id_t vrf_id
)
794 char afi_str
[AFI_MAX
][10] = {"", "ip", "ipv6", "ethernet"};
795 const char *rmap_name
;
797 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
798 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
799 if (!is_zebra_import_table_enabled(afi
, vrf_id
, i
))
802 if (zebra_import_table_distance
[afi
][i
]
803 != ZEBRA_TABLE_DISTANCE_DEFAULT
) {
804 vty_out(vty
, "%s import-table %d distance %d",
806 zebra_import_table_distance
[afi
][i
]);
808 vty_out(vty
, "%s import-table %d", afi_str
[afi
],
812 rmap_name
= zebra_get_import_table_route_map(afi
, i
);
814 vty_out(vty
, " route-map %s", rmap_name
);
824 static void zebra_import_table_rm_update_vrf_afi(struct zebra_vrf
*zvrf
,
825 afi_t afi
, int table_id
,
828 struct route_table
*table
;
829 struct route_entry
*re
;
830 struct route_node
*rn
;
831 const char *rmap_name
;
833 rmap_name
= zebra_get_import_table_route_map(afi
, table_id
);
834 if ((!rmap_name
) || (strcmp(rmap_name
, rmap
) != 0))
837 table
= zebra_vrf_get_table_with_table_id(afi
, SAFI_UNICAST
,
838 zvrf
->vrf
->vrf_id
, table_id
);
840 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
841 zlog_debug("%s: Table id=%d not found", __func__
,
846 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
848 * For each entry in the non-default routing table,
849 * add the entry in the main table
854 RNODE_FOREACH_RE (rn
, re
) {
855 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
863 if (((afi
== AFI_IP
) && (rn
->p
.family
== AF_INET
))
864 || ((afi
== AFI_IP6
) && (rn
->p
.family
== AF_INET6
)))
865 zebra_add_import_table_entry(zvrf
, rn
, re
, rmap_name
);
871 static void zebra_import_table_rm_update_vrf(struct zebra_vrf
*zvrf
,
877 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
878 for (i
= 1; i
< ZEBRA_KERNEL_TABLE_MAX
; i
++) {
879 if (!is_zebra_import_table_enabled(
880 afi
, zvrf
->vrf
->vrf_id
, i
))
883 zebra_import_table_rm_update_vrf_afi(zvrf
, afi
, i
,
889 void zebra_import_table_rm_update(const char *rmap
)
892 struct zebra_vrf
*zvrf
;
894 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
900 zebra_import_table_rm_update_vrf(zvrf
, rmap
);
904 /* Interface parameters update */
905 void zebra_interface_parameters_update(struct interface
*ifp
)
907 struct listnode
*node
, *nnode
;
908 struct zserv
*client
;
910 if (IS_ZEBRA_DEBUG_EVENT
)
911 zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s(%u)",
912 ifp
->name
, ifp
->vrf_id
);
914 for (ALL_LIST_ELEMENTS(zrouter
.client_list
, node
, nnode
, client
))
915 zsend_interface_link_params(client
, ifp
);