]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: Add Support for rfc 8050 MRT add-path 8066/head
authorDavid Teach <dteach@routeviews.org>
Thu, 11 Feb 2021 20:44:00 +0000 (20:44 +0000)
committerdteach <dteach@uoreogn.edu>
Fri, 12 Feb 2021 00:51:41 +0000 (16:51 -0800)
 - Rfc 8050 adds support for BGP NLRI that carry path identifiers. this commit adds that support to FRR
 - Updated bgp_dump.h to include new sub-type values
 - Updated bgp_dump.c to check for add_path af_caps in the peer struct.
 - Updated bgp_dump.c to use the proper sub-type values upon detection of add-path af_caps
 - Updated bgp_dump.c to properly dump the path_id wen present.

Signed-off-by: David Teach <dteach@routeviews.org>
bgpd/bgp_dump.c
bgpd/bgp_dump.h

index 975bba93147b7d2b21918240523423fad964aa7e..944a5848ec9335c63f0a35ef06a1177b9d88bd19 100644 (file)
@@ -300,6 +300,13 @@ static void bgp_dump_routes_index_table(struct bgp *bgp)
        fflush(bgp_dump_routes.fp);
 }
 
+static int bgp_addpath_encode_rx(struct peer *peer, afi_t afi, safi_t safi)
+{
+
+       return (CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV)
+               && CHECK_FLAG(peer->af_cap[afi][safi],
+                             PEER_CAP_ADDPATH_AF_TX_RCV));
+}
 
 static struct bgp_path_info *
 bgp_dump_route_node_record(int afi, struct bgp_dest *dest,
@@ -308,16 +315,27 @@ bgp_dump_route_node_record(int afi, struct bgp_dest *dest,
        struct stream *obuf;
        size_t sizep;
        size_t endp;
+       int addpath_encoded;
        const struct prefix *p = bgp_dest_get_prefix(dest);
 
        obuf = bgp_dump_obuf;
        stream_reset(obuf);
 
+       addpath_encoded = bgp_addpath_encode_rx(path->peer, afi, SAFI_UNICAST);
+
        /* MRT header */
-       if (afi == AFI_IP)
+       if (afi == AFI_IP && addpath_encoded)
+               bgp_dump_header(obuf, MSG_TABLE_DUMP_V2,
+                               TABLE_DUMP_V2_RIB_IPV4_UNICAST_ADDPATH,
+                               BGP_DUMP_ROUTES);
+       else if (afi == AFI_IP)
                bgp_dump_header(obuf, MSG_TABLE_DUMP_V2,
                                TABLE_DUMP_V2_RIB_IPV4_UNICAST,
                                BGP_DUMP_ROUTES);
+       else if (afi == AFI_IP6 && addpath_encoded)
+               bgp_dump_header(obuf, MSG_TABLE_DUMP_V2,
+                               TABLE_DUMP_V2_RIB_IPV6_UNICAST_ADDPATH,
+                               BGP_DUMP_ROUTES);
        else if (afi == AFI_IP6)
                bgp_dump_header(obuf, MSG_TABLE_DUMP_V2,
                                TABLE_DUMP_V2_RIB_IPV6_UNICAST,
@@ -361,6 +379,11 @@ bgp_dump_route_node_record(int afi, struct bgp_dest *dest,
                /* Originated */
                stream_putl(obuf, time(NULL) - (bgp_clock() - path->uptime));
 
+               /*Path Identifier*/
+               if (addpath_encoded) {
+                       stream_putl(obuf, path->addpath_rx_id);
+               }
+
                /* Dump attribute. */
                /* Skip prefix & AFI/SAFI for MP_NLRI */
                bgp_dump_routes_attr(obuf, path->attr, p);
@@ -528,19 +551,32 @@ static void bgp_dump_packet_func(struct bgp_dump *bgp_dump, struct peer *peer,
                                 struct stream *packet)
 {
        struct stream *obuf;
-
+       int addpath_encoded = 0;
        /* If dump file pointer is disabled return immediately. */
        if (bgp_dump->fp == NULL)
                return;
+       if (peer->su.sa.sa_family == AF_INET) {
+               addpath_encoded =
+                       bgp_addpath_encode_rx(peer, AFI_IP, SAFI_UNICAST);
+       } else if (peer->su.sa.sa_family == AF_INET6) {
+               addpath_encoded =
+                       bgp_addpath_encode_rx(peer, AFI_IP6, SAFI_UNICAST);
+       }
 
        /* Make dump stream. */
        obuf = bgp_dump_obuf;
        stream_reset(obuf);
 
        /* Dump header and common part. */
-       if (CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV)) {
+       if (CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV) && addpath_encoded) {
+               bgp_dump_header(obuf, MSG_PROTOCOL_BGP4MP,
+                               BGP4MP_MESSAGE_AS4_ADDPATH, bgp_dump->type);
+       } else if (CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV)) {
                bgp_dump_header(obuf, MSG_PROTOCOL_BGP4MP, BGP4MP_MESSAGE_AS4,
                                bgp_dump->type);
+       } else if (addpath_encoded) {
+               bgp_dump_header(obuf, MSG_PROTOCOL_BGP4MP,
+                               BGP4MP_MESSAGE_ADDPATH, bgp_dump->type);
        } else {
                bgp_dump_header(obuf, MSG_PROTOCOL_BGP4MP, BGP4MP_MESSAGE,
                                bgp_dump->type);
index 86c80d481c17f0105f75ddc918cdf52fbbc6f38a..a8cbd8ed2c8f05669acbe0e3ed919691656b80e9 100644 (file)
 #define MSG_PROTOCOL_BGP4MP_ET 17
 
 /* subtype value */
-#define BGP4MP_STATE_CHANGE          0
-#define BGP4MP_MESSAGE               1
-#define BGP4MP_ENTRY                 2
-#define BGP4MP_SNAPSHOT              3
-#define BGP4MP_MESSAGE_AS4           4
-#define BGP4MP_STATE_CHANGE_AS4      5
+#define BGP4MP_STATE_CHANGE 0
+#define BGP4MP_MESSAGE 1
+#define BGP4MP_ENTRY 2
+#define BGP4MP_SNAPSHOT 3
+#define BGP4MP_MESSAGE_AS4 4
+#define BGP4MP_STATE_CHANGE_AS4 5
+#define BGP4MP_MESSAGE_ADDPATH 8
+#define BGP4MP_MESSAGE_AS4_ADDPATH 9
+#define BGP4MP_MESSAGE_LOCAL_ADDPATH 10
+#define BGP4MP_MESSAGE_AS4_LOCAL_ADDPATH 11
 
 #define BGP_DUMP_HEADER_SIZE 12
 #define BGP_DUMP_MSG_HEADER  40
 
-#define TABLE_DUMP_V2_PEER_INDEX_TABLE   1
-#define TABLE_DUMP_V2_RIB_IPV4_UNICAST   2
+#define TABLE_DUMP_V2_PEER_INDEX_TABLE 1
+#define TABLE_DUMP_V2_RIB_IPV4_UNICAST 2
 #define TABLE_DUMP_V2_RIB_IPV4_MULTICAST 3
-#define TABLE_DUMP_V2_RIB_IPV6_UNICAST   4
+#define TABLE_DUMP_V2_RIB_IPV6_UNICAST 4
 #define TABLE_DUMP_V2_RIB_IPV6_MULTICAST 5
-#define TABLE_DUMP_V2_RIB_GENERIC        6
+#define TABLE_DUMP_V2_RIB_IPV4_UNICAST_ADDPATH 8
+#define TABLE_DUMP_V2_RIB_IPV4_MULTICAST_ADDPATH 9
+#define TABLE_DUMP_V2_RIB_IPV6_UNICAST_ADDPATH 10
+#define TABLE_DUMP_V2_RIB_IPV6_MULTICAST_ADDPATH 11
+#define TABLE_DUMP_V2_RIB_GENERIC_ADDPATH 12
 
 #define TABLE_DUMP_V2_PEER_INDEX_TABLE_IP  0
 #define TABLE_DUMP_V2_PEER_INDEX_TABLE_IP6 1