]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
BGP: Handle case where capabilites are not used
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Fri, 15 Mar 2019 19:57:26 +0000 (20:57 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Fri, 15 Mar 2019 19:57:26 +0000 (20:57 +0100)
If peer does not announce capabilities at all, or when we have
capabilities disabled, handle that as implicit IPv4 unicast.

proto/bgp/bgp.c
proto/bgp/bgp.h
proto/bgp/packets.c

index 1c6bbf238381b682d2286a890a98d3d239baa0d8..6a6205f57e6abc6dccb0638b521938c47e5d69bd 100644 (file)
@@ -487,6 +487,7 @@ bgp_conn_enter_openconfirm_state(struct bgp_conn *conn)
 }
 
 static const struct bgp_af_caps dummy_af_caps = { };
+static const struct bgp_af_caps basic_af_caps = { .ready = 1 };
 
 void
 bgp_conn_enter_established_state(struct bgp_conn *conn)
@@ -530,6 +531,13 @@ bgp_conn_enter_established_state(struct bgp_conn *conn)
     const struct bgp_af_caps *loc = bgp_find_af_caps(local, c->afi);
     const struct bgp_af_caps *rem = bgp_find_af_caps(peer,  c->afi);
 
+    /* Use default if capabilities were not announced */
+    if (!local->length && (c->afi == BGP_AF_IPV4))
+      loc = &basic_af_caps;
+
+    if (!peer->length && (c->afi == BGP_AF_IPV4))
+      rem = &basic_af_caps;
+
     /* Ignore AFIs that were not announced in multiprotocol capability */
     if (!loc || !loc->ready)
       loc = &dummy_af_caps;
index 8e7fe15e91632437fed53adf2b219e9ca9563534..5e3b1e3f1d32497c9d4d5b4e165cbd6523b92bfb 100644 (file)
@@ -192,6 +192,7 @@ struct bgp_caps {
   u16 gr_time;                         /* Graceful restart time in seconds */
 
   u16 af_count;                                /* Number of af_data items */
+  u16 length;                          /* Length of capabilities in OPEN msg */
 
   struct bgp_af_caps af_data[0];       /* Per-AF capability data */
 };
index a0f8d9178462a0c4452008a76275b45bab0a5bf8..5c3c4c6793ee43569d26567b70fd9cf32e405387 100644 (file)
@@ -237,6 +237,7 @@ bgp_write_capabilities(struct bgp_conn *conn, byte *buf)
   struct bgp_af_caps *ac;
   uint any_ext_next_hop = 0;
   uint any_add_path = 0;
+  byte *buf_head = buf;
   byte *data;
 
   /* Prepare bgp_caps structure */
@@ -384,6 +385,8 @@ bgp_write_capabilities(struct bgp_conn *conn, byte *buf)
     *buf++ = 0;                        /* Capability data length */
   }
 
+  caps->length = buf - buf_head;
+
   return buf;
 }
 
@@ -395,6 +398,8 @@ bgp_read_capabilities(struct bgp_conn *conn, struct bgp_caps *caps, byte *pos, i
   int i, cl;
   u32 af;
 
+  caps->length += len;
+
   while (len > 0)
   {
     if (len < 2 || len < (2 + pos[1]))