]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: IPv6 session flapping with MP_REACH_NLRI and 0.0.0.0 in NEXT_HOP attribute
authornikos <nikos@apstra.com>
Thu, 9 May 2019 07:02:16 +0000 (00:02 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 20 Sep 2019 17:10:14 +0000 (13:10 -0400)
This is causing interop issues with vendors. According to the RFC,
receiver should ignore the NEXT_HOP attribute with MP_REACH_NLRI
present.

Signed-off-by: nikos <ntriantafillis@gmail.com>
bgpd/bgp_attr.c
bgpd/bgp_attr.h
bgpd/bgp_packet.c

index 2d8138976108b1b5e4f408405db1307f5793e2dd..cbfa166cf36620daa333b3a39d9375c7df7c12d3 100644 (file)
@@ -1256,6 +1256,32 @@ static int bgp_attr_as4_path(struct bgp_attr_parser_args *args,
        return BGP_ATTR_PARSE_PROCEED;
 }
 
+/*
+ * Check that the nexthop attribute is valid.
+ */
+bgp_attr_parse_ret_t
+bgp_attr_nexthop_valid(struct peer *peer, struct attr *attr)
+{
+       in_addr_t nexthop_h;
+
+       nexthop_h = ntohl(attr->nexthop.s_addr);
+       if ((IPV4_NET0(nexthop_h) || IPV4_NET127(nexthop_h)
+            || IPV4_CLASS_DE(nexthop_h))
+           && !BGP_DEBUG(allow_martians, ALLOW_MARTIANS)) {
+               char buf[INET_ADDRSTRLEN];
+
+               inet_ntop(AF_INET, &attr->nexthop.s_addr, buf,
+                         INET_ADDRSTRLEN);
+               flog_err(EC_BGP_ATTR_MARTIAN_NH, "Martian nexthop %s",
+                        buf);
+               bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
+                               BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP);
+               return BGP_ATTR_PARSE_ERROR;
+       }
+
+       return BGP_ATTR_PARSE_PROCEED;
+}
+
 /* Nexthop attribute. */
 static bgp_attr_parse_ret_t bgp_attr_nexthop(struct bgp_attr_parser_args *args)
 {
@@ -2671,21 +2697,7 @@ bgp_attr_parse_ret_t bgp_attr_parse(struct peer *peer, struct attr *attr,
         */
        if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP))
            && !CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI))) {
-
-               in_addr_t nexthop_h;
-
-               nexthop_h = ntohl(attr->nexthop.s_addr);
-               if ((IPV4_NET0(nexthop_h) || IPV4_NET127(nexthop_h)
-                    || IPV4_CLASS_DE(nexthop_h))
-                   && !BGP_DEBUG(allow_martians, ALLOW_MARTIANS)) {
-                       char buf[INET_ADDRSTRLEN];
-
-                       inet_ntop(AF_INET, &attr->nexthop.s_addr, buf,
-                                 INET_ADDRSTRLEN);
-                       flog_err(EC_BGP_ATTR_MARTIAN_NH, "Martian nexthop %s",
-                                buf);
-                       bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
-                                       BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP);
+               if (bgp_attr_nexthop_valid(peer, attr) < 0) {
                        return BGP_ATTR_PARSE_ERROR;
                }
        }
index 6d5c647b21c296f4d794f03cc2c398350f295ad6..f6b23a36bd6e054d912a74726d7c71c0edd26a03 100644 (file)
@@ -344,6 +344,9 @@ extern void bgp_packet_mpunreach_prefix(struct stream *s, struct prefix *p,
                                        uint32_t, int, uint32_t, struct attr *);
 extern void bgp_packet_mpunreach_end(struct stream *s, size_t attrlen_pnt);
 
+extern bgp_attr_parse_ret_t bgp_attr_nexthop_valid(struct peer *peer,
+                                                  struct attr *attr);
+
 static inline int bgp_rmap_nhop_changed(uint32_t out_rmap_flags,
                                        uint32_t in_rmap_flags)
 {
index 130e06a6cf1ba887531db13fee05b445dc501391..b5934fb56e220a67359c29430c08b48a54581e3a 100644 (file)
@@ -1533,6 +1533,17 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size)
                nlris[NLRI_UPDATE].nlri = stream_pnt(s);
                nlris[NLRI_UPDATE].length = update_len;
                stream_forward_getp(s, update_len);
+
+               if (CHECK_FLAG(attr.flag, ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI))) {
+                       /*
+                        * We skipped nexthop attribute validation earlier so
+                        * validate the nexthop now.
+                        */
+                       if (bgp_attr_nexthop_valid(peer, &attr) < 0) {
+                               bgp_attr_unintern_sub(&attr);
+                               return BGP_Stop;
+                       }
+               }
        }
 
        if (BGP_DEBUG(update, UPDATE_IN))