From f6bdc08004a24ac6c8cc90e0cab89e89d9739824 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 30 May 2018 17:47:48 -0400 Subject: [PATCH] bgpd: Cleanup some duplicated code We have 2 code paths that were duplicating a bunch of code for the deletion of connected prefixes. This simplifies the code path and makes the code look a bit cleaner. I did not touch the _add path because the v4 if statement had some code I did not have time to look into. Future project. Signed-off-by: Donald Sharp --- bgpd/bgp_nexthop.c | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 3700778c73..0cb9bc7e2b 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -326,35 +326,21 @@ void bgp_connected_delete(struct bgp *bgp, struct connected *ifc) { struct prefix p; struct prefix *addr; - struct bgp_node *rn; + struct bgp_node *rn = NULL; struct bgp_connected_ref *bc; addr = ifc->address; p = *(CONNECTED_PREFIX(ifc)); + apply_mask(&p); if (addr->family == AF_INET) { - apply_mask_ipv4((struct prefix_ipv4 *)&p); - if (prefix_ipv4_any((struct prefix_ipv4 *)&p)) return; bgp_address_del(bgp, addr); rn = bgp_node_lookup(bgp->connected_table[AFI_IP], &p); - if (!rn) - return; - - bc = rn->info; - bc->refcnt--; - if (bc->refcnt == 0) { - XFREE(MTYPE_BGP_CONN, bc); - rn->info = NULL; - } - bgp_unlock_node(rn); - bgp_unlock_node(rn); } else if (addr->family == AF_INET6) { - apply_mask_ipv6((struct prefix_ipv6 *)&p); - if (IN6_IS_ADDR_UNSPECIFIED(&p.u.prefix6)) return; @@ -363,18 +349,19 @@ void bgp_connected_delete(struct bgp *bgp, struct connected *ifc) rn = bgp_node_lookup(bgp->connected_table[AFI_IP6], (struct prefix *)&p); - if (!rn) - return; + } - bc = rn->info; - bc->refcnt--; - if (bc->refcnt == 0) { - XFREE(MTYPE_BGP_CONN, bc); - rn->info = NULL; - } - bgp_unlock_node(rn); - bgp_unlock_node(rn); + if (!rn) + return; + + bc = rn->info; + bc->refcnt--; + if (bc->refcnt == 0) { + XFREE(MTYPE_BGP_CONN, bc); + rn->info = NULL; } + bgp_unlock_node(rn); + bgp_unlock_node(rn); } int bgp_nexthop_self(struct bgp *bgp, struct in_addr nh_addr) -- 2.39.5