mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-11 13:12:28 +00:00
bgpd: Abstract bgp_nexthop_cache retrieving/setting from info pointer
The bgp_nexthop_cache 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 <sharpd@cumulusnetworks.com>
This commit is contained in:
parent
3d9dbdbe8b
commit
14315f2d69
@ -80,12 +80,14 @@ static void bgp_nexthop_cache_reset(struct bgp_table *table)
|
|||||||
struct bgp_node *rn;
|
struct bgp_node *rn;
|
||||||
struct bgp_nexthop_cache *bnc;
|
struct bgp_nexthop_cache *bnc;
|
||||||
|
|
||||||
for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn))
|
for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) {
|
||||||
if ((bnc = rn->info) != NULL) {
|
bnc = bgp_nexthop_get_node_info(rn);
|
||||||
|
if (bnc != NULL) {
|
||||||
bnc_free(bnc);
|
bnc_free(bnc);
|
||||||
rn->info = NULL;
|
bgp_nexthop_set_node_info(rn, NULL);
|
||||||
bgp_unlock_node(rn);
|
bgp_unlock_node(rn);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *bgp_tip_hash_alloc(void *p)
|
static void *bgp_tip_hash_alloc(void *p)
|
||||||
@ -530,35 +532,35 @@ static void bgp_show_nexthops(struct vty *vty, struct bgp *bgp, int detail)
|
|||||||
|
|
||||||
for (rn = bgp_table_top(bgp->nexthop_cache_table[afi]); rn;
|
for (rn = bgp_table_top(bgp->nexthop_cache_table[afi]); rn;
|
||||||
rn = bgp_route_next(rn)) {
|
rn = bgp_route_next(rn)) {
|
||||||
if ((bnc = rn->info) != NULL) {
|
bnc = bgp_nexthop_get_node_info(rn);
|
||||||
if (CHECK_FLAG(bnc->flags, BGP_NEXTHOP_VALID)) {
|
if (!bnc)
|
||||||
vty_out(vty,
|
continue;
|
||||||
" %s valid [IGP metric %d], #paths %d\n",
|
|
||||||
inet_ntop(rn->p.family,
|
|
||||||
&rn->p.u.prefix, buf,
|
|
||||||
sizeof(buf)),
|
|
||||||
bnc->metric, bnc->path_count);
|
|
||||||
|
|
||||||
if (!detail)
|
if (CHECK_FLAG(bnc->flags, BGP_NEXTHOP_VALID)) {
|
||||||
continue;
|
vty_out(vty,
|
||||||
|
" %s valid [IGP metric %d], #paths %d\n",
|
||||||
|
inet_ntop(rn->p.family,
|
||||||
|
&rn->p.u.prefix, buf,
|
||||||
|
sizeof(buf)),
|
||||||
|
bnc->metric, bnc->path_count);
|
||||||
|
|
||||||
bgp_show_nexthops_detail(vty, bgp, bnc);
|
if (!detail)
|
||||||
|
continue;
|
||||||
|
|
||||||
} else {
|
bgp_show_nexthops_detail(vty, bgp, bnc);
|
||||||
vty_out(vty, " %s invalid\n",
|
|
||||||
inet_ntop(rn->p.family,
|
} else {
|
||||||
&rn->p.u.prefix, buf,
|
vty_out(vty, " %s invalid\n",
|
||||||
sizeof(buf)));
|
inet_ntop(rn->p.family,
|
||||||
if (CHECK_FLAG(bnc->flags,
|
&rn->p.u.prefix, buf,
|
||||||
BGP_NEXTHOP_CONNECTED))
|
sizeof(buf)));
|
||||||
vty_out(vty,
|
if (CHECK_FLAG(bnc->flags,
|
||||||
" Must be Connected\n");
|
BGP_NEXTHOP_CONNECTED))
|
||||||
|
vty_out(vty, " Must be Connected\n");
|
||||||
}
|
}
|
||||||
tbuf = time(NULL)
|
tbuf = time(NULL) - (bgp_clock() - bnc->last_update);
|
||||||
- (bgp_clock() - bnc->last_update);
|
vty_out(vty, " Last update: %s", ctime(&tbuf));
|
||||||
vty_out(vty, " Last update: %s", ctime(&tbuf));
|
vty_out(vty, "\n");
|
||||||
vty_out(vty, "\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ static void bgp_unlink_nexthop_check(struct bgp_nexthop_cache *bnc)
|
|||||||
}
|
}
|
||||||
unregister_zebra_rnh(bnc,
|
unregister_zebra_rnh(bnc,
|
||||||
CHECK_FLAG(bnc->flags, BGP_STATIC_ROUTE));
|
CHECK_FLAG(bnc->flags, BGP_STATIC_ROUTE));
|
||||||
bnc->node->info = NULL;
|
bgp_nexthop_set_node_info(bnc->node, NULL);
|
||||||
bgp_unlock_node(bnc->node);
|
bgp_unlock_node(bnc->node);
|
||||||
bnc->node = NULL;
|
bnc->node = NULL;
|
||||||
bnc_free(bnc);
|
bnc_free(bnc);
|
||||||
@ -128,11 +128,10 @@ void bgp_unlink_nexthop_by_peer(struct peer *peer)
|
|||||||
|
|
||||||
rn = bgp_node_get(peer->bgp->nexthop_cache_table[afi], &p);
|
rn = bgp_node_get(peer->bgp->nexthop_cache_table[afi], &p);
|
||||||
|
|
||||||
if (!rn->info)
|
bnc = bgp_nexthop_get_node_info(rn);
|
||||||
|
if (!bnc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bnc = rn->info;
|
|
||||||
|
|
||||||
/* cleanup the peer reference */
|
/* cleanup the peer reference */
|
||||||
bnc->nht_info = NULL;
|
bnc->nht_info = NULL;
|
||||||
|
|
||||||
@ -191,9 +190,10 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop,
|
|||||||
else
|
else
|
||||||
rn = bgp_node_get(bgp_nexthop->nexthop_cache_table[afi], &p);
|
rn = bgp_node_get(bgp_nexthop->nexthop_cache_table[afi], &p);
|
||||||
|
|
||||||
if (!rn->info) {
|
bnc = bgp_nexthop_get_node_info(rn);
|
||||||
|
if (!bnc) {
|
||||||
bnc = bnc_new();
|
bnc = bnc_new();
|
||||||
rn->info = bnc;
|
bgp_nexthop_set_node_info(rn, bnc);
|
||||||
bnc->node = rn;
|
bnc->node = rn;
|
||||||
bnc->bgp = bgp_nexthop;
|
bnc->bgp = bgp_nexthop;
|
||||||
bgp_lock_node(rn);
|
bgp_lock_node(rn);
|
||||||
@ -205,7 +205,6 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bnc = rn->info;
|
|
||||||
bgp_unlock_node(rn);
|
bgp_unlock_node(rn);
|
||||||
if (is_bgp_static_route) {
|
if (is_bgp_static_route) {
|
||||||
SET_FLAG(bnc->flags, BGP_STATIC_ROUTE);
|
SET_FLAG(bnc->flags, BGP_STATIC_ROUTE);
|
||||||
@ -297,16 +296,21 @@ void bgp_delete_connected_nexthop(afi_t afi, struct peer *peer)
|
|||||||
|
|
||||||
rn = bgp_node_lookup(
|
rn = bgp_node_lookup(
|
||||||
peer->bgp->nexthop_cache_table[family2afi(p.family)], &p);
|
peer->bgp->nexthop_cache_table[family2afi(p.family)], &p);
|
||||||
if (!rn || !rn->info) {
|
if (!rn) {
|
||||||
if (BGP_DEBUG(nht, NHT))
|
if (BGP_DEBUG(nht, NHT))
|
||||||
zlog_debug("Cannot find connected NHT node for peer %s",
|
zlog_debug("Cannot find connected NHT node for peer %s",
|
||||||
peer->host);
|
peer->host);
|
||||||
if (rn)
|
|
||||||
bgp_unlock_node(rn);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bnc = rn->info;
|
bnc = bgp_nexthop_get_node_info(rn);
|
||||||
|
if (!bnc) {
|
||||||
|
if (BGP_DEBUG(nht, NHT))
|
||||||
|
zlog_debug("Cannot find connected NHT node for peer %s on route_node as expected",
|
||||||
|
peer->host);
|
||||||
|
bgp_unlock_node(rn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
bgp_unlock_node(rn);
|
bgp_unlock_node(rn);
|
||||||
|
|
||||||
if (bnc->nht_info != peer) {
|
if (bnc->nht_info != peer) {
|
||||||
@ -324,7 +328,7 @@ void bgp_delete_connected_nexthop(afi_t afi, struct peer *peer)
|
|||||||
zlog_debug("Freeing connected NHT node %p for peer %s",
|
zlog_debug("Freeing connected NHT node %p for peer %s",
|
||||||
bnc, peer->host);
|
bnc, peer->host);
|
||||||
unregister_zebra_rnh(bnc, 0);
|
unregister_zebra_rnh(bnc, 0);
|
||||||
bnc->node->info = NULL;
|
bgp_nexthop_set_node_info(bnc->node, NULL);
|
||||||
bgp_unlock_node(bnc->node);
|
bgp_unlock_node(bnc->node);
|
||||||
bnc_free(bnc);
|
bnc_free(bnc);
|
||||||
}
|
}
|
||||||
@ -367,19 +371,29 @@ void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id)
|
|||||||
bgp->import_check_table[family2afi(nhr.prefix.family)],
|
bgp->import_check_table[family2afi(nhr.prefix.family)],
|
||||||
&nhr.prefix);
|
&nhr.prefix);
|
||||||
|
|
||||||
if (!rn || !rn->info) {
|
if (!rn) {
|
||||||
if (BGP_DEBUG(nht, NHT)) {
|
if (BGP_DEBUG(nht, NHT)) {
|
||||||
char buf[PREFIX2STR_BUFFER];
|
char buf[PREFIX2STR_BUFFER];
|
||||||
prefix2str(&nhr.prefix, buf, sizeof(buf));
|
prefix2str(&nhr.prefix, buf, sizeof(buf));
|
||||||
zlog_debug("parse nexthop update(%s): rn not found",
|
zlog_debug("parse nexthop update(%s): rn not found",
|
||||||
buf);
|
buf);
|
||||||
}
|
}
|
||||||
if (rn)
|
|
||||||
bgp_unlock_node(rn);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bnc = rn->info;
|
bnc = bgp_nexthop_get_node_info(rn);
|
||||||
|
if (!bnc) {
|
||||||
|
if (BGP_DEBUG(nht, NHT)) {
|
||||||
|
char buf[PREFIX2STR_BUFFER];
|
||||||
|
|
||||||
|
prefix2str(&nhr.prefix, buf, sizeof(buf));
|
||||||
|
zlog_debug("parse nexthop update(%s): bnc node info not found",
|
||||||
|
buf);
|
||||||
|
}
|
||||||
|
bgp_unlock_node(rn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bgp_unlock_node(rn);
|
bgp_unlock_node(rn);
|
||||||
bnc->last_update = bgp_clock();
|
bnc->last_update = bgp_clock();
|
||||||
bnc->change_flags = 0;
|
bnc->change_flags = 0;
|
||||||
@ -487,7 +501,7 @@ void bgp_cleanup_nexthops(struct bgp *bgp)
|
|||||||
|
|
||||||
for (rn = bgp_table_top(bgp->nexthop_cache_table[afi]); rn;
|
for (rn = bgp_table_top(bgp->nexthop_cache_table[afi]); rn;
|
||||||
rn = bgp_route_next(rn)) {
|
rn = bgp_route_next(rn)) {
|
||||||
bnc = rn->info;
|
bnc = bgp_nexthop_get_node_info(rn);
|
||||||
if (!bnc)
|
if (!bnc)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -360,4 +360,16 @@ static inline void bgp_connected_set_node_info(struct bgp_node *node,
|
|||||||
node->info = bc;
|
node->info = bc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct bgp_nexthop_cache *
|
||||||
|
bgp_nexthop_get_node_info(struct bgp_node *node)
|
||||||
|
{
|
||||||
|
return node->info;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void bgp_nexthop_set_node_info(struct bgp_node *node,
|
||||||
|
struct bgp_nexthop_cache *bnc)
|
||||||
|
{
|
||||||
|
node->info = bnc;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _QUAGGA_BGP_TABLE_H */
|
#endif /* _QUAGGA_BGP_TABLE_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user