]> git.proxmox.com Git - mirror_frr.git/blob - zebra/redistribute.c
Merge pull request #1075 from donaldsharp/rip_metric
[mirror_frr.git] / zebra / redistribute.c
1 /* Redistribution Handler
2 * Copyright (C) 1998 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
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
9 * later version.
10 *
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.
15 *
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
19 */
20
21 #include <zebra.h>
22
23 #include "vector.h"
24 #include "vty.h"
25 #include "command.h"
26 #include "prefix.h"
27 #include "table.h"
28 #include "stream.h"
29 #include "zclient.h"
30 #include "linklist.h"
31 #include "log.h"
32 #include "vrf.h"
33 #include "srcdest_table.h"
34
35 #include "zebra/rib.h"
36 #include "zebra/zserv.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/zebra_memory.h"
44 #include "zebra/zebra_vxlan.h"
45
46 #define ZEBRA_PTM_SUPPORT
47
48 /* array holding redistribute info about table redistribution */
49 /* bit AFI is set if that AFI is redistributing routes from this table */
50 static int zebra_import_table_used[AFI_MAX][ZEBRA_KERNEL_TABLE_MAX];
51 static u_int32_t zebra_import_table_distance[AFI_MAX][ZEBRA_KERNEL_TABLE_MAX];
52
53 int is_zebra_import_table_enabled(afi_t afi, u_int32_t table_id)
54 {
55 /*
56 * Make sure that what we are called with actualy makes sense
57 */
58 if (afi == AFI_MAX)
59 return 0;
60
61 if (is_zebra_valid_kernel_table(table_id))
62 return zebra_import_table_used[afi][table_id];
63 return 0;
64 }
65
66 static void zebra_redistribute_default(struct zserv *client, vrf_id_t vrf_id)
67 {
68 int afi;
69 struct prefix p;
70 struct route_table *table;
71 struct route_node *rn;
72 struct route_entry *newre;
73
74 for (afi = AFI_IP; afi <= AFI_IP6; afi++) {
75 /* Lookup table. */
76 table = zebra_vrf_table(afi, SAFI_UNICAST, vrf_id);
77 if (!table)
78 continue;
79
80 /* Lookup default route. */
81 memset(&p, 0, sizeof(p));
82 p.family = afi2family(afi);
83 rn = route_node_lookup(table, &p);
84 if (!rn)
85 continue;
86
87 RNODE_FOREACH_RE(rn, newre)
88 if (CHECK_FLAG(newre->flags, ZEBRA_FLAG_SELECTED)
89 && newre->distance != DISTANCE_INFINITY)
90 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD,
91 client, &rn->p, NULL, newre);
92
93 route_unlock_node(rn);
94 }
95 }
96
97 /* Redistribute routes. */
98 static void zebra_redistribute(struct zserv *client, int type, u_short instance,
99 vrf_id_t vrf_id, int afi)
100 {
101 struct route_entry *newre;
102 struct route_table *table;
103 struct route_node *rn;
104
105 table = zebra_vrf_table(afi, SAFI_UNICAST, vrf_id);
106 if (!table)
107 return;
108
109 for (rn = route_top(table); rn; rn = srcdest_route_next(rn))
110 RNODE_FOREACH_RE(rn, newre)
111 {
112 struct prefix *dst_p, *src_p;
113 srcdest_rnode_prefixes(rn, &dst_p, &src_p);
114
115 if (IS_ZEBRA_DEBUG_EVENT)
116 zlog_debug(
117 "%s: checking: selected=%d, type=%d, distance=%d, "
118 "zebra_check_addr=%d",
119 __func__,
120 CHECK_FLAG(newre->flags,
121 ZEBRA_FLAG_SELECTED),
122 newre->type, newre->distance,
123 zebra_check_addr(dst_p));
124
125 if (!CHECK_FLAG(newre->flags, ZEBRA_FLAG_SELECTED))
126 continue;
127 if ((type != ZEBRA_ROUTE_ALL
128 && (newre->type != type
129 || newre->instance != instance)))
130 continue;
131 if (newre->distance == DISTANCE_INFINITY)
132 continue;
133 if (!zebra_check_addr(dst_p))
134 continue;
135
136 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD,
137 client, dst_p, src_p, newre);
138 }
139 }
140
141 /* Either advertise a route for redistribution to registered clients or */
142 /* withdraw redistribution if add cannot be done for client */
143 void redistribute_update(struct prefix *p, struct prefix *src_p,
144 struct route_entry *re, struct route_entry *prev_re)
145 {
146 struct listnode *node, *nnode;
147 struct zserv *client;
148 int send_redistribute;
149 int afi;
150 char buf[INET6_ADDRSTRLEN];
151
152 if (IS_ZEBRA_DEBUG_RIB) {
153 inet_ntop(p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN);
154 zlog_debug(
155 "%u:%s/%d: Redist update re %p (type %d), old %p (type %d)",
156 re->vrf_id, buf, p->prefixlen, re, re->type, prev_re,
157 prev_re ? prev_re->type : -1);
158 }
159
160 afi = family2afi(p->family);
161 if (!afi) {
162 zlog_warn("%s: Unknown AFI/SAFI prefix received\n",
163 __FUNCTION__);
164 return;
165 }
166
167 for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client)) {
168 send_redistribute = 0;
169
170 if (is_default_prefix(p)
171 && vrf_bitmap_check(client->redist_default, re->vrf_id))
172 send_redistribute = 1;
173 else if (vrf_bitmap_check(client->redist[afi][ZEBRA_ROUTE_ALL],
174 re->vrf_id))
175 send_redistribute = 1;
176 else if (re->instance
177 && redist_check_instance(
178 &client->mi_redist[afi][re->type],
179 re->instance))
180 send_redistribute = 1;
181 else if (vrf_bitmap_check(client->redist[afi][re->type],
182 re->vrf_id))
183 send_redistribute = 1;
184
185 if (send_redistribute) {
186 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD,
187 client, p, src_p, re);
188 } else if (prev_re
189 && ((re->instance
190 && redist_check_instance(
191 &client->mi_redist[afi]
192 [prev_re->type],
193 re->instance))
194 || vrf_bitmap_check(
195 client->redist[afi][prev_re->type],
196 re->vrf_id))) {
197 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL,
198 client, p, src_p, prev_re);
199 }
200 }
201 }
202
203 void redistribute_delete(struct prefix *p, struct prefix *src_p,
204 struct route_entry *re)
205 {
206 struct listnode *node, *nnode;
207 struct zserv *client;
208 char buf[INET6_ADDRSTRLEN];
209 int afi;
210
211 if (IS_ZEBRA_DEBUG_RIB) {
212 inet_ntop(p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN);
213 zlog_debug("%u:%s/%d: Redist delete re %p (type %d)",
214 re->vrf_id, buf, p->prefixlen, re, re->type);
215 }
216
217 /* Add DISTANCE_INFINITY check. */
218 if (re->distance == DISTANCE_INFINITY)
219 return;
220
221 afi = family2afi(p->family);
222 if (!afi) {
223 zlog_warn("%s: Unknown AFI/SAFI prefix received\n",
224 __FUNCTION__);
225 return;
226 }
227
228 for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client)) {
229 if ((is_default_prefix(p)
230 && vrf_bitmap_check(client->redist_default, re->vrf_id))
231 || vrf_bitmap_check(client->redist[afi][ZEBRA_ROUTE_ALL],
232 re->vrf_id)
233 || (re->instance
234 && redist_check_instance(
235 &client->mi_redist[afi][re->type],
236 re->instance))
237 || vrf_bitmap_check(client->redist[afi][re->type],
238 re->vrf_id)) {
239 zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL,
240 client, p, src_p, re);
241 }
242 }
243 }
244
245 void zebra_redistribute_add(int command, struct zserv *client, int length,
246 struct zebra_vrf *zvrf)
247 {
248 afi_t afi;
249 int type;
250 u_short instance;
251
252 afi = stream_getc(client->ibuf);
253 type = stream_getc(client->ibuf);
254 instance = stream_getw(client->ibuf);
255
256 if (type == 0 || type >= ZEBRA_ROUTE_MAX)
257 return;
258
259 if (instance) {
260 if (!redist_check_instance(&client->mi_redist[afi][type],
261 instance)) {
262 redist_add_instance(&client->mi_redist[afi][type],
263 instance);
264 zebra_redistribute(client, type, instance,
265 zvrf_id(zvrf), afi);
266 }
267 } else {
268 if (!vrf_bitmap_check(client->redist[afi][type],
269 zvrf_id(zvrf))) {
270 vrf_bitmap_set(client->redist[afi][type],
271 zvrf_id(zvrf));
272 zebra_redistribute(client, type, 0, zvrf_id(zvrf), afi);
273 }
274 }
275 }
276
277 void zebra_redistribute_delete(int command, struct zserv *client, int length,
278 struct zebra_vrf *zvrf)
279 {
280 afi_t afi;
281 int type;
282 u_short instance;
283
284 afi = stream_getc(client->ibuf);
285 type = stream_getc(client->ibuf);
286 instance = stream_getw(client->ibuf);
287
288 if (type == 0 || type >= ZEBRA_ROUTE_MAX)
289 return;
290
291 /*
292 * NOTE: no need to withdraw the previously advertised routes. The
293 * clients
294 * themselves should keep track of the received routes from zebra and
295 * withdraw them when necessary.
296 */
297 if (instance)
298 redist_del_instance(&client->mi_redist[afi][type], instance);
299 else
300 vrf_bitmap_unset(client->redist[afi][type], zvrf_id(zvrf));
301 }
302
303 void zebra_redistribute_default_add(int command, struct zserv *client,
304 int length, struct zebra_vrf *zvrf)
305 {
306 vrf_bitmap_set(client->redist_default, zvrf_id(zvrf));
307 zebra_redistribute_default(client, zvrf_id(zvrf));
308 }
309
310 void zebra_redistribute_default_delete(int command, struct zserv *client,
311 int length, struct zebra_vrf *zvrf)
312 {
313 vrf_bitmap_unset(client->redist_default, zvrf_id(zvrf));
314 }
315
316 /* Interface up information. */
317 void zebra_interface_up_update(struct interface *ifp)
318 {
319 struct listnode *node, *nnode;
320 struct zserv *client;
321
322 if (IS_ZEBRA_DEBUG_EVENT)
323 zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s", ifp->name);
324
325 if (ifp->ptm_status || !ifp->ptm_enable) {
326 for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client))
327 if (client->ifinfo) {
328 zsend_interface_update(ZEBRA_INTERFACE_UP,
329 client, ifp);
330 zsend_interface_link_params(client, ifp);
331 }
332 }
333 }
334
335 /* Interface down information. */
336 void zebra_interface_down_update(struct interface *ifp)
337 {
338 struct listnode *node, *nnode;
339 struct zserv *client;
340
341 if (IS_ZEBRA_DEBUG_EVENT)
342 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s", ifp->name);
343
344 for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client)) {
345 zsend_interface_update(ZEBRA_INTERFACE_DOWN, client, ifp);
346 }
347 }
348
349 /* Interface information update. */
350 void zebra_interface_add_update(struct interface *ifp)
351 {
352 struct listnode *node, *nnode;
353 struct zserv *client;
354
355 if (IS_ZEBRA_DEBUG_EVENT)
356 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s[%d]", ifp->name,
357 ifp->vrf_id);
358
359 for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client))
360 if (client->ifinfo) {
361 client->ifadd_cnt++;
362 zsend_interface_add(client, ifp);
363 zsend_interface_link_params(client, ifp);
364 }
365 }
366
367 void zebra_interface_delete_update(struct interface *ifp)
368 {
369 struct listnode *node, *nnode;
370 struct zserv *client;
371
372 if (IS_ZEBRA_DEBUG_EVENT)
373 zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s", ifp->name);
374
375 for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client)) {
376 client->ifdel_cnt++;
377 zsend_interface_delete(client, ifp);
378 }
379 }
380
381 /* Interface address addition. */
382 void zebra_interface_address_add_update(struct interface *ifp,
383 struct connected *ifc)
384 {
385 struct listnode *node, *nnode;
386 struct zserv *client;
387 struct prefix *p;
388
389 if (IS_ZEBRA_DEBUG_EVENT) {
390 char buf[PREFIX_STRLEN];
391
392 p = ifc->address;
393 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s on %s",
394 prefix2str(p, buf, sizeof(buf)), ifc->ifp->name);
395 }
396
397 if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
398 zlog_warn(
399 "WARNING: advertising address to clients that is not yet usable.");
400
401 zebra_vxlan_add_del_gw_macip(ifp, ifc->address, 1);
402
403 router_id_add_address(ifc);
404
405 for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client))
406 if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) {
407 client->connected_rt_add_cnt++;
408 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_ADD,
409 client, ifp, ifc);
410 }
411 }
412
413 /* Interface address deletion. */
414 void zebra_interface_address_delete_update(struct interface *ifp,
415 struct connected *ifc)
416 {
417 struct listnode *node, *nnode;
418 struct zserv *client;
419 struct prefix *p;
420
421 if (IS_ZEBRA_DEBUG_EVENT) {
422 char buf[PREFIX_STRLEN];
423
424 p = ifc->address;
425 zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s on %s",
426 prefix2str(p, buf, sizeof(buf)), ifc->ifp->name);
427 }
428
429 zebra_vxlan_add_del_gw_macip(ifp, ifc->address, 0);
430
431 router_id_del_address(ifc);
432
433 for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client))
434 if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) {
435 client->connected_rt_del_cnt++;
436 zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_DELETE,
437 client, ifp, ifc);
438 }
439 }
440
441 /* Interface VRF change. May need to delete from clients not interested in
442 * the new VRF. Note that this function is invoked *prior* to the VRF change.
443 */
444 void zebra_interface_vrf_update_del(struct interface *ifp, vrf_id_t new_vrf_id)
445 {
446 struct listnode *node, *nnode;
447 struct zserv *client;
448
449 if (IS_ZEBRA_DEBUG_EVENT)
450 zlog_debug(
451 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/DEL %s VRF Id %u -> %u",
452 ifp->name, ifp->vrf_id, new_vrf_id);
453
454 for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client)) {
455 /* Need to delete if the client is not interested in the new
456 * VRF. */
457 zsend_interface_update(ZEBRA_INTERFACE_DOWN, client, ifp);
458 client->ifdel_cnt++;
459 zsend_interface_delete(client, ifp);
460 zsend_interface_vrf_update(client, ifp, new_vrf_id);
461 }
462 }
463
464 /* Interface VRF change. This function is invoked *post* VRF change and sends an
465 * add to clients who are interested in the new VRF but not in the old VRF.
466 */
467 void zebra_interface_vrf_update_add(struct interface *ifp, vrf_id_t old_vrf_id)
468 {
469 struct listnode *node, *nnode;
470 struct zserv *client;
471
472 if (IS_ZEBRA_DEBUG_EVENT)
473 zlog_debug(
474 "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/ADD %s VRF Id %u -> %u",
475 ifp->name, old_vrf_id, ifp->vrf_id);
476
477 for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client)) {
478 /* Need to add if the client is interested in the new VRF. */
479 client->ifadd_cnt++;
480 zsend_interface_add(client, ifp);
481 zsend_interface_addresses(client, ifp);
482 }
483 }
484
485 int zebra_add_import_table_entry(struct route_node *rn, struct route_entry *re,
486 const char *rmap_name)
487 {
488 struct route_entry *newre;
489 struct route_entry *same;
490 struct prefix p;
491 route_map_result_t ret = RMAP_MATCH;
492 afi_t afi;
493
494 afi = family2afi(rn->p.family);
495 if (rmap_name)
496 ret = zebra_import_table_route_map_check(
497 afi, re->type, &rn->p, re->nexthop, re->vrf_id,
498 re->tag, rmap_name);
499
500 if (ret != RMAP_MATCH) {
501 zebra_del_import_table_entry(rn, re);
502 return 0;
503 }
504
505 prefix_copy(&p, &rn->p);
506
507 RNODE_FOREACH_RE(rn, same)
508 {
509 if (CHECK_FLAG(same->status,
510 ROUTE_ENTRY_REMOVED))
511 continue;
512
513 if (same->type == re->type
514 && same->instance == re->instance
515 && same->table == re->table
516 && same->type != ZEBRA_ROUTE_CONNECT)
517 break;
518 }
519
520 if (same)
521 zebra_del_import_table_entry(rn, same);
522
523 if (re->nexthop_num == 1) {
524 rib_add(afi, SAFI_UNICAST, re->vrf_id,
525 ZEBRA_ROUTE_TABLE, re->table, 0, &p,
526 NULL, re->nexthop,
527 zebrad.rtm_table_default, re->metric,
528 re->mtu,
529 zebra_import_table_distance[afi]
530 [re->table]);
531 } else if (re->nexthop_num > 1) {
532 newre = XCALLOC(MTYPE_RE,
533 sizeof(struct route_entry));
534 newre->type = ZEBRA_ROUTE_TABLE;
535 newre->distance =
536 zebra_import_table_distance[afi][re->table];
537 newre->flags = re->flags;
538 newre->metric = re->metric;
539 newre->mtu = re->mtu;
540 newre->table = zebrad.rtm_table_default;
541 newre->nexthop_num = 0;
542 newre->uptime = time(NULL);
543 newre->instance = re->table;
544 route_entry_copy_nexthops(newre, re->nexthop);
545
546 rib_add_multipath(afi, SAFI_UNICAST, &p,
547 NULL, newre);
548 }
549 return 0;
550 }
551
552 int zebra_del_import_table_entry(struct route_node *rn, struct route_entry *re)
553 {
554 struct prefix p;
555 afi_t afi;
556
557 afi = family2afi(rn->p.family);
558 prefix_copy(&p, &rn->p);
559
560 rib_delete(afi, SAFI_UNICAST, re->vrf_id, ZEBRA_ROUTE_TABLE,
561 re->table, re->flags, &p, NULL, NULL,
562 zebrad.rtm_table_default, re->metric);
563
564 return 0;
565 }
566
567 /* Assuming no one calls this with the main routing table */
568 int zebra_import_table(afi_t afi, u_int32_t table_id, u_int32_t distance,
569 const char *rmap_name, int add)
570 {
571 struct route_table *table;
572 struct route_entry *re;
573 struct route_node *rn;
574
575 if (!is_zebra_valid_kernel_table(table_id)
576 || ((table_id == RT_TABLE_MAIN)
577 || (table_id == zebrad.rtm_table_default)))
578 return (-1);
579
580 if (afi >= AFI_MAX)
581 return (-1);
582
583 table = zebra_vrf_other_route_table(afi, table_id, VRF_DEFAULT);
584 if (table == NULL) {
585 return 0;
586 } else if (IS_ZEBRA_DEBUG_RIB) {
587 zlog_debug("%s routes from table %d",
588 add ? "Importing" : "Unimporting", table_id);
589 }
590
591 if (add) {
592 if (rmap_name)
593 zebra_add_import_table_route_map(afi, rmap_name,
594 table_id);
595 else {
596 rmap_name =
597 zebra_get_import_table_route_map(afi, table_id);
598 if (rmap_name)
599 zebra_del_import_table_route_map(afi, table_id);
600 }
601
602 zebra_import_table_used[afi][table_id] = 1;
603 zebra_import_table_distance[afi][table_id] = distance;
604 } else {
605 zebra_import_table_used[afi][table_id] = 0;
606 zebra_import_table_distance[afi][table_id] =
607 ZEBRA_TABLE_DISTANCE_DEFAULT;
608
609 rmap_name = zebra_get_import_table_route_map(afi, table_id);
610 if (rmap_name)
611 zebra_del_import_table_route_map(afi, table_id);
612 }
613
614 for (rn = route_top(table); rn; rn = route_next(rn)) {
615 /* For each entry in the non-default routing table,
616 * add the entry in the main table
617 */
618 if (!rn->info)
619 continue;
620
621 RNODE_FOREACH_RE(rn, re)
622 {
623 if (CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED))
624 continue;
625 break;
626 }
627
628 if (!re)
629 continue;
630
631 if (((afi == AFI_IP) && (rn->p.family == AF_INET))
632 || ((afi == AFI_IP6) && (rn->p.family == AF_INET6))) {
633 if (add)
634 zebra_add_import_table_entry(rn, re, rmap_name);
635 else
636 zebra_del_import_table_entry(rn, re);
637 }
638 }
639 return 0;
640 }
641
642 int zebra_import_table_config(struct vty *vty)
643 {
644 int i;
645 afi_t afi;
646 int write = 0;
647 char afi_str[AFI_MAX][10] = {"", "ip", "ipv6", "ethernet"};
648 const char *rmap_name;
649
650 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
651 for (i = 1; i < ZEBRA_KERNEL_TABLE_MAX; i++) {
652 if (!is_zebra_import_table_enabled(afi, i))
653 continue;
654
655 if (zebra_import_table_distance[afi][i]
656 != ZEBRA_TABLE_DISTANCE_DEFAULT) {
657 vty_out(vty,
658 "%s import-table %d distance %d",
659 afi_str[afi], i,
660 zebra_import_table_distance[afi][i]);
661 } else {
662 vty_out(vty, "%s import-table %d",
663 afi_str[afi], i);
664 }
665
666 rmap_name = zebra_get_import_table_route_map(afi, i);
667 if (rmap_name)
668 vty_out(vty, " route-map %s",
669 rmap_name);
670
671 vty_out(vty, "\n");
672 write = 1;
673 }
674 }
675
676 return write;
677 }
678
679 void zebra_import_table_rm_update()
680 {
681 afi_t afi;
682 int i;
683 struct route_table *table;
684 struct route_entry *re;
685 struct route_node *rn;
686 const char *rmap_name;
687
688 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
689 for (i = 1; i < ZEBRA_KERNEL_TABLE_MAX; i++) {
690 if (!is_zebra_import_table_enabled(afi, i))
691 continue;
692
693 rmap_name = zebra_get_import_table_route_map(afi, i);
694 if (!rmap_name)
695 return;
696
697 table = zebra_vrf_other_route_table(afi,
698 i,
699 VRF_DEFAULT);
700 for (rn = route_top(table); rn;
701 rn = route_next(rn)) {
702 /* For each entry in the non-default
703 * routing table,
704 * add the entry in the main table
705 */
706 if (!rn->info)
707 continue;
708
709 RNODE_FOREACH_RE(rn, re)
710 {
711 if (CHECK_FLAG(
712 re->status,
713 ROUTE_ENTRY_REMOVED))
714 continue;
715 break;
716 }
717
718 if (!re)
719 continue;
720
721 if (((afi == AFI_IP)
722 && (rn->p.family == AF_INET))
723 || ((afi == AFI_IP6)
724 && (rn->p.family == AF_INET6)))
725 zebra_add_import_table_entry(
726 rn, re, rmap_name);
727 }
728 }
729 }
730
731 return;
732 }
733
734 /* Interface parameters update */
735 void zebra_interface_parameters_update(struct interface *ifp)
736 {
737 struct listnode *node, *nnode;
738 struct zserv *client;
739
740 if (IS_ZEBRA_DEBUG_EVENT)
741 zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s",
742 ifp->name);
743
744 for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client))
745 if (client->ifinfo)
746 zsend_interface_link_params(client, ifp);
747 }