From: Quentin Young Date: Tue, 3 Dec 2019 20:48:27 +0000 (-0500) Subject: bgpd: more attribute parsing cleanup & paranoia X-Git-Tag: base_7.3~90^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=5e0e9c09f6c609d8d1548054c04360ba3a390acf;p=matthieu%2Ffrr.git bgpd: more attribute parsing cleanup & paranoia * Move VNC interning to the appropriate spot * Use existing bgp_attr_flush_encap to free encap sets * Assert that refcounts are correct before exiting to keep the demons contained in their fiery prison Signed-off-by: Quentin Young --- diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 5233211b47..88663bf30d 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -2796,12 +2796,6 @@ bgp_attr_parse_ret_t bgp_attr_parse(struct peer *peer, struct attr *attr, goto done; } - /* - * The "rest" of the code does nothing with as4_aggregator. - * there is no memory attached specifically which is not part - * of the attr. - * so ignoring just means do nothing. - */ /* * Finally do the checks on the aspath we did not do yet * because we waited for a potentially synthesized aspath. @@ -2811,15 +2805,10 @@ bgp_attr_parse_ret_t bgp_attr_parse(struct peer *peer, struct attr *attr, if (ret != BGP_ATTR_PARSE_PROCEED) goto done; } -#if ENABLE_BGP_VNC - if (attr->vnc_subtlvs) - attr->vnc_subtlvs = - encap_intern(attr->vnc_subtlvs, VNC_SUBTLV_TYPE); -#endif ret = BGP_ATTR_PARSE_PROCEED; - done: + /* * At this stage, we have done all fiddling with as4, and the * resulting info is in attr->aggregator resp. attr->aspath so @@ -2842,7 +2831,29 @@ done: if (attr->encap_subtlvs) attr->encap_subtlvs = encap_intern(attr->encap_subtlvs, ENCAP_SUBTLV_TYPE); - } +#if ENABLE_BGP_VNC + if (attr->vnc_subtlvs) + attr->vnc_subtlvs = encap_intern(attr->vnc_subtlvs, + VNC_SUBTLV_TYPE); +#endif + } else { + if (attr->transit) { + transit_free(attr->transit); + attr->transit = NULL; + } + + bgp_attr_flush_encap(attr); + }; + + /* Sanity checks */ + if (attr->transit) + assert(attr->transit->refcnt > 0); + if (attr->encap_subtlvs) + assert(attr->encap_subtlvs->refcnt > 0); +#if ENABLE_BGP_VNC + if (attr->vnc_subtlvs) + assert(attr->vnc_subtlvs->refcnt > 0); +#endif return ret; }