From: Donald Sharp Date: Mon, 6 May 2019 22:03:39 +0000 (-0400) Subject: zebra: Remove basic duplicated function X-Git-Tag: base_7.2~338^2~2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=8ab39b7f1c9003096eb4c701db52f84948d07cb1;p=matthieu%2Ffrr.git zebra: Remove basic duplicated function Combine the zebra_vrf_other_route_table and zebra_vrf_table_with_table_id functions into 1 function. Since they are basically the same thing. Signed-off-by: Donald Sharp --- diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 0071e001c6..d2bebb0e29 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -653,7 +653,8 @@ int zebra_import_table(afi_t afi, uint32_t table_id, uint32_t distance, if (afi >= AFI_MAX) return (-1); - table = zebra_vrf_other_route_table(afi, table_id, VRF_DEFAULT); + table = zebra_vrf_table_with_table_id(afi, SAFI_UNICAST, + table_id, VRF_DEFAULT); if (table == NULL) { return 0; } else if (IS_ZEBRA_DEBUG_RIB) { @@ -767,8 +768,8 @@ void zebra_import_table_rm_update(const char *rmap) rmap_name = zebra_get_import_table_route_map(afi, i); if ((!rmap_name) || (strcmp(rmap_name, rmap) != 0)) continue; - table = zebra_vrf_other_route_table(afi, i, - VRF_DEFAULT); + table = zebra_vrf_table_with_table_id(afi, SAFI_UNICAST, + i, VRF_DEFAULT); for (rn = route_top(table); rn; rn = route_next(rn)) { /* For each entry in the non-default * routing table, diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index 315d5b4905..38f8adeae7 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -320,27 +320,18 @@ struct route_table *zebra_vrf_table_with_table_id(afi_t afi, safi_t safi, vrf_id_t vrf_id, uint32_t table_id) { - struct route_table *table = NULL; + struct zebra_vrf *zvrf = vrf_info_lookup(vrf_id); + + if (!zvrf) + return NULL; if (afi >= AFI_MAX || safi >= SAFI_MAX) return NULL; - if (vrf_id == VRF_DEFAULT) { - if (table_id == RT_TABLE_MAIN) - table = zebra_vrf_table(afi, safi, vrf_id); - else - table = zebra_vrf_other_route_table(afi, table_id, - vrf_id); - } else if (vrf_is_backend_netns()) { - if (table_id == RT_TABLE_MAIN) - table = zebra_vrf_table(afi, safi, vrf_id); - else - table = zebra_vrf_other_route_table(afi, table_id, - vrf_id); - } else - table = zebra_vrf_table(afi, safi, vrf_id); + if (table_id == zvrf->table_id) + return zebra_vrf_table(afi, safi, vrf_id); - return table; + return zebra_router_get_table(zvrf, table_id, afi, safi); } void zebra_rtable_node_cleanup(struct route_table *table, @@ -438,32 +429,6 @@ struct route_table *zebra_vrf_table(afi_t afi, safi_t safi, vrf_id_t vrf_id) return zvrf->table[afi][safi]; } -struct route_table *zebra_vrf_other_route_table(afi_t afi, uint32_t table_id, - vrf_id_t vrf_id) -{ - struct zebra_vrf *zvrf; - - zvrf = vrf_info_lookup(vrf_id); - if (!zvrf) - return NULL; - - if (afi >= AFI_MAX) - return NULL; - - if (table_id != RT_TABLE_MAIN) { - if (zvrf->table_id == RT_TABLE_MAIN) { - /* this VRF use default table - * so in all cases, it does not use specific table - * so it is possible to configure tables in this VRF - */ - return zebra_router_get_table(zvrf, table_id, afi, - SAFI_UNICAST); - } - } - - return zvrf->table[afi][SAFI_UNICAST]; -} - static int vrf_config_write(struct vty *vty) { struct vrf *vrf; diff --git a/zebra/zebra_vrf.h b/zebra/zebra_vrf.h index c7a64d300a..49887f1b67 100644 --- a/zebra/zebra_vrf.h +++ b/zebra/zebra_vrf.h @@ -202,8 +202,6 @@ extern struct zebra_vrf *zebra_vrf_lookup_by_name(const char *); extern struct zebra_vrf *zebra_vrf_alloc(void); extern struct route_table *zebra_vrf_table(afi_t, safi_t, vrf_id_t); -extern struct route_table * -zebra_vrf_other_route_table(afi_t afi, uint32_t table_id, vrf_id_t vrf_id); extern int zebra_vrf_has_config(struct zebra_vrf *zvrf); extern void zebra_vrf_init(void);