]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: more attribute parsing cleanup & paranoia
authorQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 3 Dec 2019 20:48:27 +0000 (15:48 -0500)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 16 Jan 2020 19:36:52 +0000 (14:36 -0500)
* 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 <qlyoung@cumulusnetworks.com>
bgpd/bgp_attr.c

index c7bdab35d2abd9691518316290e0fc6b4041042d..2e83f7d0517f41ccaaf4cadf4e55d6cbda7382f4 100644 (file)
@@ -2770,12 +2770,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.
@@ -2785,15 +2779,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
@@ -2816,7 +2805,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;
 }