From: Donald Sharp Date: Fri, 16 Mar 2018 04:02:56 +0000 (-0400) Subject: zebra: Read in on startup arbitrary tables X-Git-Tag: frr-5.0-dev~138^2~2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=95a29032bca3d41ff6870561e76111a7f9aac626;p=mirror%2Ffrr.git zebra: Read in on startup arbitrary tables When we receive an arbitrary table over the netlink bus save it for later perusal and sweep any routes that we may have created from an earlier run. The current redistribute code is limited to ZEBRA_KERNEL_TABLE_MAX. I left this alone for the moment because I believe it needs to be converted to a RB tree instead of a flat array. Which is more work for the future. Additionally this proposed change might necessitate some cli changes or rethinks. Signed-off-by: Donald Sharp --- diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 3a66aea45f..89c17b069a 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -58,7 +58,8 @@ int is_zebra_import_table_enabled(afi_t afi, u_int32_t table_id) if (afi == AFI_MAX) return 0; - if (is_zebra_valid_kernel_table(table_id)) + if (is_zebra_valid_kernel_table(table_id) && + table_id < ZEBRA_KERNEL_TABLE_MAX) return zebra_import_table_used[afi][table_id]; return 0; } diff --git a/zebra/rib.h b/zebra/rib.h index b5d8c6e8eb..44e0a9ce40 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -326,6 +326,7 @@ extern struct route_entry *rib_lookup_ipv4(struct prefix_ipv4 *, vrf_id_t); extern void rib_update(vrf_id_t, rib_update_event_t); extern void rib_weed_tables(void); extern void rib_sweep_route(void); +extern void rib_sweep_table(struct route_table *); extern void rib_close_table(struct route_table *); extern void rib_init(void); extern unsigned long rib_score_proto(u_char proto, u_short instance); diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c index 2c7b85e614..29c179245b 100644 --- a/zebra/zebra_ns.c +++ b/zebra/zebra_ns.c @@ -177,6 +177,17 @@ unsigned long zebra_ns_score_proto(u_char proto, u_short instance) return cnt; } +void zebra_ns_sweep_route(void) +{ + struct zebra_ns_table *znst; + struct zebra_ns *zns; + + zns = zebra_ns_lookup(NS_DEFAULT); + + RB_FOREACH (znst, zebra_ns_table_head, &zns->ns_tables) + rib_sweep_table(znst->table); +} + struct route_table *zebra_ns_get_table(struct zebra_ns *zns, struct zebra_vrf *zvrf, uint32_t tableid, afi_t afi) diff --git a/zebra/zebra_ns.h b/zebra/zebra_ns.h index f6b8f5f9b3..6655e5c019 100644 --- a/zebra/zebra_ns.h +++ b/zebra/zebra_ns.h @@ -92,4 +92,5 @@ extern struct route_table *zebra_ns_get_table(struct zebra_ns *zns, int zebra_ns_config_write(struct vty *vty, struct ns *ns); unsigned long zebra_ns_score_proto(u_char proto, u_short instance); +void zebra_ns_sweep_route(void); #endif diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 35c74daea5..73b20320ad 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -139,9 +139,6 @@ uint8_t route_distance(int type) int is_zebra_valid_kernel_table(u_int32_t table_id) { - if ((table_id > ZEBRA_KERNEL_TABLE_MAX)) - return 0; - #ifdef linux if ((table_id == RT_TABLE_UNSPEC) || (table_id == RT_TABLE_LOCAL) || (table_id == RT_TABLE_COMPAT)) @@ -2739,7 +2736,7 @@ void rib_weed_tables(void) } /* Delete self installed routes after zebra is relaunched. */ -static void rib_sweep_table(struct route_table *table) +void rib_sweep_table(struct route_table *table) { struct route_node *rn; struct route_entry *re; @@ -2800,6 +2797,8 @@ void rib_sweep_route(void) rib_sweep_table(zvrf->table[AFI_IP][SAFI_UNICAST]); rib_sweep_table(zvrf->table[AFI_IP6][SAFI_UNICAST]); } + + zebra_ns_sweep_route(); } /* Remove specific by protocol routes from 'table'. */