]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Ignore handling NLRIs if we received MP_UNREACH_NLRI
authorDonatas Abraitis <donatas@opensourcerouting.org>
Sun, 29 Oct 2023 20:44:45 +0000 (22:44 +0200)
committerChristian Breunig <christian@breunig.cc>
Mon, 27 Nov 2023 18:43:51 +0000 (19:43 +0100)
If we receive MP_UNREACH_NLRI, we should stop handling remaining NLRIs if
no mandatory path attributes received.

In other words, if MP_UNREACH_NLRI received, the remaining NLRIs should be handled
as a new data, but without mandatory attributes, it's a malformed packet.

In normal case, this MUST not happen at all, but to avoid crashing bgpd, we MUST
handle that.

Reported-by: Iggy Frankovic <iggyfran@amazon.com>
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
Signed-off-by: Christian Breunig <christian@breunig.cc>
(cherry picked from commit c37119df45bbf4ef713bc10475af2ee06e12f3bf)

bgpd/bgp_attr.c
bgpd/bgp_attr.h
bgpd/bgp_packet.c

index 4bc28fe2374a4c17cffc8137e53df3834b5d0912..c51e5acb50ec517ea49dd0a022104c4d58222125 100644 (file)
@@ -2850,15 +2850,6 @@ static int bgp_attr_check(struct peer *peer, struct attr *attr)
        if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV) && !attr->flag)
                return BGP_ATTR_PARSE_PROCEED;
 
-       /* "An UPDATE message that contains the MP_UNREACH_NLRI is not required
-          to carry any other path attributes.", though if MP_REACH_NLRI or NLRI
-          are present, it should.  Check for any other attribute being present
-          instead.
-        */
-       if ((!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)) &&
-            CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI))))
-               return BGP_ATTR_PARSE_PROCEED;
-
        if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN)))
                type = BGP_ATTR_ORIGIN;
 
@@ -2877,6 +2868,16 @@ static int bgp_attr_check(struct peer *peer, struct attr *attr)
            && !CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)))
                type = BGP_ATTR_LOCAL_PREF;
 
+       /* An UPDATE message that contains the MP_UNREACH_NLRI is not required
+        * to carry any other path attributes. Though if MP_REACH_NLRI or NLRI
+        * are present, it should. Check for any other attribute being present
+        * instead.
+        */
+       if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)) &&
+           CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI)))
+               return type ? BGP_ATTR_PARSE_MISSING_MANDATORY
+                           : BGP_ATTR_PARSE_PROCEED;
+
        /* If any of the well-known mandatory attributes are not present
         * in an UPDATE message, then "treat-as-withdraw" MUST be used.
         */
index e6e953364bebe5d0c0d199e55054622b601accd1..cf9c681b0d6ac41065a96bfd72552431c8894983 100644 (file)
@@ -339,6 +339,7 @@ typedef enum {
           */
        BGP_ATTR_PARSE_ERROR_NOTIFYPLS = -3,
        BGP_ATTR_PARSE_EOR = -4,
+       BGP_ATTR_PARSE_MISSING_MANDATORY = -5,
 } bgp_attr_parse_ret_t;
 
 struct bpacket_attr_vec_arr;
index 2c8a375a55e228a01d1dc73d923a259528f06421..164e7ae721ac5dfdf7823c20adba1529fc95f336 100644 (file)
@@ -1625,7 +1625,12 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size)
        /* Network Layer Reachability Information. */
        update_len = end - stream_pnt(s);
 
-       if (update_len) {
+       /* If we received MP_UNREACH_NLRI attribute, but also NLRIs, then
+        * NLRIs should be handled as a new data. Though, if we received
+        * NLRIs without mandatory attributes, they should be ignored.
+        */
+       if (update_len && attribute_len &&
+           attr_parse_ret != BGP_ATTR_PARSE_MISSING_MANDATORY) {
                /* Set NLRI portion to structure. */
                nlris[NLRI_UPDATE].afi = AFI_IP;
                nlris[NLRI_UPDATE].safi = SAFI_UNICAST;