From 3d9dbdbe8b0a2c44049975da3cdbdaead67c8567 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 30 Jul 2018 10:46:00 -0400 Subject: [PATCH] bgpd: Abstract bgp_connected_ref retrieving/setting from info pointer The bgp_connected_ref 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 --- bgpd/bgp_nexthop.c | 26 ++++++++++++++------------ bgpd/bgp_table.h | 13 +++++++++++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 76bfa73fee..e092313d7d 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -278,14 +278,14 @@ void bgp_connected_add(struct bgp *bgp, struct connected *ifc) rn = bgp_node_get(bgp->connected_table[AFI_IP], (struct prefix *)&p); - if (rn->info) { - bc = rn->info; + bc = bgp_connected_get_node_info(rn); + if (bc) bc->refcnt++; - } else { + else { bc = XCALLOC(MTYPE_BGP_CONN, sizeof(struct bgp_connected_ref)); bc->refcnt = 1; - rn->info = bc; + bgp_connected_set_node_info(rn, bc); } for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { @@ -310,14 +310,15 @@ void bgp_connected_add(struct bgp *bgp, struct connected *ifc) rn = bgp_node_get(bgp->connected_table[AFI_IP6], (struct prefix *)&p); - if (rn->info) { - bc = rn->info; + + bc = bgp_connected_get_node_info(rn); + if (bc) bc->refcnt++; - } else { + else { bc = XCALLOC(MTYPE_BGP_CONN, sizeof(struct bgp_connected_ref)); bc->refcnt = 1; - rn->info = bc; + bgp_connected_set_node_info(rn, bc); } } } @@ -354,11 +355,11 @@ void bgp_connected_delete(struct bgp *bgp, struct connected *ifc) if (!rn) return; - bc = rn->info; + bc = bgp_connected_get_node_info(rn); bc->refcnt--; if (bc->refcnt == 0) { XFREE(MTYPE_BGP_CONN, bc); - rn->info = NULL; + bgp_connected_set_node_info(rn, NULL); } bgp_unlock_node(rn); bgp_unlock_node(rn); @@ -368,15 +369,16 @@ static void bgp_connected_cleanup(struct route_table *table, struct route_node *rn) { struct bgp_connected_ref *bc; + struct bgp_node *bn = bgp_node_from_rnode(rn); - bc = rn->info; + bc = bgp_connected_get_node_info(bn); if (!bc) return; bc->refcnt--; if (bc->refcnt == 0) { XFREE(MTYPE_BGP_CONN, bc); - rn->info = NULL; + bgp_connected_set_node_info(bn, NULL); } } diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index e7206cf4e8..f60265b51b 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -347,4 +347,17 @@ static inline void bgp_static_set_node_info(struct bgp_node *node, { node->info = bgp_static; } + +static inline struct bgp_connected_ref * +bgp_connected_get_node_info(struct bgp_node *node) +{ + return node->info; +} + +static inline void bgp_connected_set_node_info(struct bgp_node *node, + struct bgp_connected_ref *bc) +{ + node->info = bc; +} + #endif /* _QUAGGA_BGP_TABLE_H */ -- 2.39.5