In bgpd we do not follow the RFC8050 encoding for RIB_GENERIC_ADDPATH.
Mainly because it does not fit the way the code works and also because the
only other BGP implementation that seems to care about RIB_GENERIC_ADDPATH
does it the same way.

Because of this it makes no sense to parse RIB_GENERIC_ADDPATH strictly
per RFC8050 but instead parse it the way it is implemented.

While there cleanup some unused variables.
-- 
:wq Claudio

Index: mrtparser.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpctl/mrtparser.c,v
retrieving revision 1.15
diff -u -p -r1.15 mrtparser.c
--- mrtparser.c 27 Jul 2021 07:42:37 -0000      1.15
+++ mrtparser.c 22 Sep 2021 10:22:54 -0000
@@ -103,10 +103,8 @@ mrt_parse(int fd, struct mrt_parser *p, 
        struct mrt_bgp_state    *s;
        struct mrt_bgp_msg      *m;
        void                    *msg;
-       int                      addpath;
 
        while ((msg = mrt_read_msg(fd, &h))) {
-               addpath = 0;
                switch (ntohs(h.type)) {
                case MSG_NULL:
                case MSG_START:
@@ -376,7 +374,7 @@ mrt_parse_v2_rib(struct mrt_hdr *hdr, vo
        u_int32_t       snum, path_id = 0;
        u_int16_t       cnt, i, afi;
        u_int8_t        safi, aid;
-       int             ret, addpath = 0;
+       int             ret;
 
        if (len < sizeof(snum) + 1)
                return NULL;
@@ -417,6 +415,11 @@ mrt_parse_v2_rib(struct mrt_hdr *hdr, vo
                        goto fail;
                break;
        case MRT_DUMP_V2_RIB_GENERIC_ADDPATH:
+               /*
+                * RFC8050 handling for add-path has special handling for
+                * RIB_GENERIC_ADDPATH but nobody implements it that way.
+                * So just use the same way as for the other _ADDPATH types.
+                */
                r->add_path = 1;
                /* FALLTHROUGH */
        case MRT_DUMP_V2_RIB_GENERIC:
@@ -434,16 +437,6 @@ mrt_parse_v2_rib(struct mrt_hdr *hdr, vo
                if ((aid = mrt_afi2aid(afi, safi, verbose)) == AID_UNSPEC)
                        goto fail;
                
-               /* RFC8050 handling for add-path */
-               if (r->add_path) {
-                       if (len < sizeof(path_id))
-                               goto fail;
-                       memcpy(&path_id, b, sizeof(path_id));
-                       b += sizeof(path_id);
-                       len -= sizeof(path_id);
-                       path_id = ntohl(path_id);
-               }
-
                /* prefix */
                ret = mrt_extract_prefix(b, len, aid, &r->prefix,
                    &r->prefixlen, verbose);
@@ -487,12 +480,9 @@ mrt_parse_v2_rib(struct mrt_hdr *hdr, vo
                len -= sizeof(otm);
                entries[i].originated = ntohl(otm);
 
-               /* RFC8050 handling for add-path */
-               if (r->add_path &&
-                   ntohs(hdr->subtype) != MRT_DUMP_V2_RIB_GENERIC_ADDPATH) {
+               if (r->add_path) {
                        if (len < sizeof(path_id) + sizeof(alen))
                                goto fail;
-                       addpath = 0;
                        memcpy(&path_id, b, sizeof(path_id));
                        b += sizeof(path_id);
                        len -= sizeof(path_id);

Reply via email to