From: Donald Sharp Date: Mon, 30 Jul 2018 14:29:28 +0000 (-0400) Subject: bgpd: Abstract distance retrieving/setting from info pointer X-Git-Tag: frr-7.1-dev~340^2~3 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=ca2e160d7dca2621260ddf03e2e07e4c8c4495af;p=matthieu%2Ffrr.git bgpd: Abstract distance retrieving/setting from info pointer The bgp_distance data is stored as a void pointer in `struct bgp_node`. Abstract retrieval of this data and setting of this data into functions so that in the future we can move around what is stored in bgp_node. Signed-off-by: Donald Sharp --- diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 29c68dc6fa..42028fda48 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -10771,12 +10771,12 @@ static int bgp_distance_set(struct vty *vty, const char *distance_str, /* Get BGP distance node. */ rn = bgp_node_get(bgp_distance_table[afi][safi], (struct prefix *)&p); - if (rn->info) { - bdistance = rn->info; + bdistance = bgp_distance_get_node(rn); + if (bdistance) bgp_unlock_node(rn); - } else { + else { bdistance = bgp_distance_new(); - rn->info = bdistance; + bgp_distance_set_node(rn, bdistance); } /* Set distance value. */ @@ -10821,7 +10821,7 @@ static int bgp_distance_unset(struct vty *vty, const char *distance_str, return CMD_WARNING_CONFIG_FAILED; } - bdistance = rn->info; + bdistance = bgp_distance_get_node(rn); distance = atoi(distance_str); if (bdistance->distance != distance) { @@ -10860,7 +10860,7 @@ uint8_t bgp_distance_apply(struct prefix *p, struct bgp_info *rinfo, afi_t afi, sockunion2hostprefix(&peer->su, &q); rn = bgp_node_match(bgp_distance_table[afi][safi], &q); if (rn) { - bdistance = rn->info; + bdistance = bgp_distance_get_node(rn); bgp_unlock_node(rn); if (bdistance->access_list) { @@ -11511,8 +11511,9 @@ void bgp_config_write_distance(struct vty *vty, struct bgp *bgp, afi_t afi, } for (rn = bgp_table_top(bgp_distance_table[afi][safi]); rn; - rn = bgp_route_next(rn)) - if ((bdistance = rn->info) != NULL) { + rn = bgp_route_next(rn)) { + bdistance = bgp_distance_get_node(rn); + if (bdistance != NULL) { char buf[PREFIX_STRLEN]; vty_out(vty, " distance %d %s %s\n", @@ -11521,6 +11522,7 @@ void bgp_config_write_distance(struct vty *vty, struct bgp *bgp, afi_t afi, bdistance->access_list ? bdistance->access_list : ""); } + } } /* Allocate routing table structure and install commands. */ diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index fc1942db5a..6c52d27a82 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -326,4 +326,15 @@ static inline void bgp_aggregate_set_node_info(struct bgp_node *node, node->info = aggregate; } +static inline struct bgp_distance *bgp_distance_get_node(struct bgp_node *node) +{ + return node->info; +} + +static inline void bgp_distance_set_node(struct bgp_node *node, + struct bgp_distance *distance) +{ + node->info = distance; +} + #endif /* _QUAGGA_BGP_TABLE_H */