]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Merge branch 'master' into master 630/head
authorGuy Harris <[email protected]>
Sat, 16 Dec 2017 06:34:42 +0000 (22:34 -0800)
committerGitHub <[email protected]>
Sat, 16 Dec 2017 06:34:42 +0000 (22:34 -0800)
1  2 
print-bgp.c
tests/TESTLIST

diff --cc print-bgp.c
index fe83922ddb8b178463854838637931ee9aeaba89,bfb94df66c27dd98f78d8aa0a3cbe82561ee4d9b..443581de648c013d74bafe9625483d5ce4a2f409
@@@ -2586,71 -2517,44 +2608,76 @@@ static voi
  bgp_update_print(netdissect_options *ndo,
                   const u_char *dat, int length)
  {
-       struct bgp bgp;
+       const struct bgp *bgp_header;
        const u_char *p;
        int withdrawn_routes_len;
 +        char buf[MAXHOSTNAMELEN + 100];
 +        int wpfx;
        int len;
        int i;
 +        int add_path;
 +        int path_id;
  
-       ND_TCHECK2(dat[0], BGP_SIZE);
+       ND_TCHECK_LEN(dat, BGP_SIZE);
        if (length < BGP_SIZE)
                goto trunc;
-       memcpy(&bgp, dat, BGP_SIZE);
-       p = dat + BGP_SIZE;     /*XXX*/
+       bgp_header = (const struct bgp *)dat;
+       p = dat + BGP_SIZE;
        length -= BGP_SIZE;
  
        /* Unfeasible routes */
-       ND_TCHECK2(p[0], 2);
+       ND_TCHECK_2(p);
        if (length < 2)
                goto trunc;
-       withdrawn_routes_len = EXTRACT_16BITS(p);
+       withdrawn_routes_len = EXTRACT_BE_U_2(p);
        p += 2;
        length -= 2;
 -      if (withdrawn_routes_len) {
 +      if (withdrawn_routes_len > 1) {
-               ND_TCHECK2(p[0], withdrawn_routes_len);
+               /*
+                * Without keeping state from the original NLRI message,
+                * it's not possible to tell if this a v4 or v6 route,
+                * so only try to decode it if we're not v6 enabled.
 -               */
++         */
+               ND_TCHECK_LEN(p, withdrawn_routes_len);
                if (length < withdrawn_routes_len)
                        goto trunc;
 -              ND_PRINT((ndo, "\n\t  Withdrawn routes: %d bytes", withdrawn_routes_len));
 -              p += withdrawn_routes_len;
 -              length -= withdrawn_routes_len;
 -      }
 +
 +                ND_PRINT((ndo, "\n\t  Withdrawn routes:"));
 +                add_path = check_add_path(p, withdrawn_routes_len, 32);
 +                while(withdrawn_routes_len > 0) {
 +                        if (add_path) {
 +                                path_id = EXTRACT_32BITS(p);
 +                                p += 4;
 +                                length -= 4;
 +                                withdrawn_routes_len -= 4;
 +                        }
 +                        wpfx = decode_prefix4(ndo, p, withdrawn_routes_len, buf, sizeof(buf));
 +                        if (wpfx == -1) {
 +                                ND_PRINT((ndo, "\n\t    (illegal prefix length)"));
 +                                break;
 +                        } else if (wpfx == -2)
 +                                goto trunc;
 +                        else if (wpfx == -3)
 +                                goto trunc; /* bytes left, but not enough */
 +                        else {
 +                                ND_PRINT((ndo, "\n\t    %s", buf));
 +                                if (add_path) {
 +                                    ND_PRINT((ndo, "   Path Id: %d", path_id));
 +                                }
 +                                p += wpfx;
 +                                length -= wpfx;
 +                                withdrawn_routes_len -= wpfx;
 +                        }
 +                }
 +      } else {
 +                p += withdrawn_routes_len;
 +                length -= withdrawn_routes_len;
 +        }
  
-       ND_TCHECK2(p[0], 2);
+       ND_TCHECK_2(p);
        if (length < 2)
                goto trunc;
-       len = EXTRACT_16BITS(p);
+       len = EXTRACT_BE_U_2(p);
        p += 2;
        length -= 2;
  
diff --cc tests/TESTLIST
Simple merge