]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Use nd_ types in the IPv6 structures.
authorGuy Harris <[email protected]>
Tue, 12 Dec 2017 03:38:35 +0000 (19:38 -0800)
committerGuy Harris <[email protected]>
Tue, 12 Dec 2017 03:38:35 +0000 (19:38 -0800)
And add the EXTRACT_U_1() calls as needed.

Change some other EXTRACT_ calls that no longer need an & operator.

ip6.h
print-icmp6.c
print-ip6.c
print-ip6opts.c
print-pgm.c
print-rt6.c
print-tcp.c
print-udp.c

diff --git a/ip6.h b/ip6.h
index 9a24ef143c8e8cacb273c02c06cb052d4b8b44d3..35f12e42764b8de3285f16c13f3102b810d2b1e6 100644 (file)
--- a/ip6.h
+++ b/ip6.h
 struct ip6_hdr {
        union {
                struct ip6_hdrctl {
-                       uint32_t ip6_un1_flow;  /* 20 bits of flow-ID */
-                       uint16_t ip6_un1_plen;  /* payload length */
-                       uint8_t  ip6_un1_nxt;   /* next header */
-                       uint8_t  ip6_un1_hlim;  /* hop limit */
+                       nd_uint32_t ip6_un1_flow;       /* 20 bits of flow-ID */
+                       nd_uint16_t ip6_un1_plen;       /* payload length */
+                       nd_uint8_t  ip6_un1_nxt;        /* next header */
+                       nd_uint8_t  ip6_un1_hlim;       /* hop limit */
                } ip6_un1;
-               uint8_t ip6_un2_vfc;    /* 4 bits version, top 4 bits class */
+               nd_uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
        } ip6_ctlun;
        struct in6_addr ip6_src;        /* source address */
        struct in6_addr ip6_dst;        /* destination address */
 } UNALIGNED;
 
 #define ip6_vfc                ip6_ctlun.ip6_un2_vfc
-#define IP6_VERSION(ip6_hdr)   (((ip6_hdr)->ip6_vfc & 0xf0) >> 4)
+#define IP6_VERSION(ip6_hdr)   ((EXTRACT_U_1((ip6_hdr)->ip6_vfc) & 0xf0) >> 4)
 #define ip6_flow       ip6_ctlun.ip6_un1.ip6_un1_flow
 #define ip6_plen       ip6_ctlun.ip6_un1.ip6_un1_plen
 #define ip6_nxt                ip6_ctlun.ip6_un1.ip6_un1_nxt
@@ -109,21 +109,21 @@ struct ip6_hdr {
  */
 
 struct ip6_ext {
-       uint8_t ip6e_nxt;
-       uint8_t ip6e_len;
+       nd_uint8_t ip6e_nxt;
+       nd_uint8_t ip6e_len;
 } UNALIGNED;
 
 /* Hop-by-Hop options header */
 struct ip6_hbh {
-       uint8_t ip6h_nxt;       /* next header */
-       uint8_t ip6h_len;       /* length in units of 8 octets */
+       nd_uint8_t ip6h_nxt;    /* next header */
+       nd_uint8_t ip6h_len;    /* length in units of 8 octets */
        /* followed by options */
 } UNALIGNED;
 
 /* Destination options header */
 struct ip6_dest {
-       uint8_t ip6d_nxt;       /* next header */
-       uint8_t ip6d_len;       /* length in units of 8 octets */
+       nd_uint8_t ip6d_nxt;    /* next header */
+       nd_uint8_t ip6d_len;    /* length in units of 8 octets */
        /* followed by options */
 } UNALIGNED;
 
@@ -165,10 +165,10 @@ struct ip6_dest {
 
 /* Routing header */
 struct ip6_rthdr {
-       uint8_t  ip6r_nxt;      /* next header */
-       uint8_t  ip6r_len;      /* length in units of 8 octets */
-       uint8_t  ip6r_type;     /* routing type */
-       uint8_t  ip6r_segleft;  /* segments left */
+       nd_uint8_t  ip6r_nxt;           /* next header */
+       nd_uint8_t  ip6r_len;           /* length in units of 8 octets */
+       nd_uint8_t  ip6r_type;          /* routing type */
+       nd_uint8_t  ip6r_segleft;       /* segments left */
        /* followed by routing type specific data */
 } UNALIGNED;
 
@@ -188,10 +188,10 @@ struct ip6_rthdr0 {
 
 /* Fragment header */
 struct ip6_frag {
-       uint8_t  ip6f_nxt;              /* next header */
-       uint8_t  ip6f_reserved; /* reserved field */
-       uint16_t ip6f_offlg;            /* offset, reserved, and flag */
-       uint32_t ip6f_ident;            /* identification */
+       nd_uint8_t  ip6f_nxt;           /* next header */
+       nd_uint8_t  ip6f_reserved;      /* reserved field */
+       nd_uint16_t ip6f_offlg;         /* offset, reserved, and flag */
+       nd_uint32_t ip6f_ident;         /* identification */
 } UNALIGNED;
 
 #define IP6F_OFF_MASK          0xfff8  /* mask out offset from ip6f_offlg */
index 594c9153bfc80697c29c74072cd22eca000195d1..2fd9d1b4e5940a0d944fdc114f67ccc5f0b4130e 100644 (file)
@@ -875,7 +875,7 @@ icmp6_print(netdissect_options *ndo,
        const struct ip6_hdr *ip;
        const struct ip6_hdr *oip;
        const struct udphdr *ouh;
-       int dport;
+       u_int dport;
        const u_char *ep;
        u_int prot;
 
@@ -935,7 +935,7 @@ icmp6_print(netdissect_options *ndo,
                            == NULL)
                                goto trunc;
 
-                       dport = EXTRACT_BE_U_2(&ouh->uh_dport);
+                       dport = EXTRACT_BE_U_2(ouh->uh_dport);
                        switch (prot) {
                        case IPPROTO_TCP:
                                ND_PRINT((ndo,", %s tcp port %s",
@@ -948,9 +948,9 @@ icmp6_print(netdissect_options *ndo,
                                           udpport_string(ndo, dport)));
                                break;
                        default:
-                               ND_PRINT((ndo,", %s protocol %d port %d unreachable",
+                               ND_PRINT((ndo,", %s protocol %u port %u unreachable",
                                        ip6addr_string(ndo, &oip->ip6_dst),
-                                          oip->ip6_nxt, dport));
+                                          prot, dport));
                                break;
                        }
                        break;
@@ -1179,7 +1179,7 @@ get_upperlayer(netdissect_options *ndo, const u_char *bp, u_int *prot)
        if (!ND_TTEST(ip6->ip6_nxt))
                return NULL;
 
-       nh = ip6->ip6_nxt;
+       nh = EXTRACT_U_1(ip6->ip6_nxt);
        hlen = sizeof(struct ip6_hdr);
 
        while (bp < ep) {
@@ -1203,8 +1203,8 @@ get_upperlayer(netdissect_options *ndo, const u_char *bp, u_int *prot)
                        hbh = (const struct ip6_hbh *)bp;
                        if (!ND_TTEST(hbh->ip6h_len))
                                return(NULL);
-                       nh = hbh->ip6h_nxt;
-                       hlen = (hbh->ip6h_len + 1) << 3;
+                       nh = EXTRACT_U_1(hbh->ip6h_nxt);
+                       hlen = (EXTRACT_U_1(hbh->ip6h_len) + 1) << 3;
                        break;
 
                case IPPROTO_FRAGMENT: /* this should be odd, but try anyway */
@@ -1212,9 +1212,9 @@ get_upperlayer(netdissect_options *ndo, const u_char *bp, u_int *prot)
                        if (!ND_TTEST(fragh->ip6f_offlg))
                                return(NULL);
                        /* fragments with non-zero offset are meaningless */
-                       if ((EXTRACT_BE_U_2(&fragh->ip6f_offlg) & IP6F_OFF_MASK) != 0)
+                       if ((EXTRACT_BE_U_2(fragh->ip6f_offlg) & IP6F_OFF_MASK) != 0)
                                return(NULL);
-                       nh = fragh->ip6f_nxt;
+                       nh = EXTRACT_U_1(fragh->ip6f_nxt);
                        hlen = sizeof(struct ip6_frag);
                        break;
 
index bdc79f9cadf0dfb90e65b112a388ed18caab665b..3b63639e865cc3edf240bca7a3bfa5aa25ce8008 100644 (file)
@@ -58,7 +58,7 @@ ip6_finddst(netdissect_options *ndo, struct in6_addr *dst,
 
        cp = (const u_char *)ip6;
        advance = sizeof(struct ip6_hdr);
-       nh = ip6->ip6_nxt;
+       nh = EXTRACT_U_1(ip6->ip6_nxt);
        dst_addr = (const void *)&ip6->ip6_dst;
 
        while (cp < ndo->ndo_snapend) {
@@ -98,8 +98,8 @@ ip6_finddst(netdissect_options *ndo, struct in6_addr *dst,
                         */
                        dp = (const struct ip6_rthdr *)cp;
                        ND_TCHECK(*dp);
-                       len = dp->ip6r_len;
-                       switch (dp->ip6r_type) {
+                       len = EXTRACT_U_1(dp->ip6r_len);
+                       switch (EXTRACT_U_1(dp->ip6r_type)) {
 
                        case IPV6_RTHDR_TYPE_0:
                        case IPV6_RTHDR_TYPE_2:         /* Mobile IPv6 ID-20 */
@@ -172,11 +172,13 @@ nextproto6_cksum(netdissect_options *ndo,
                 uint8_t        ph_nxt;
         } ph;
         struct cksum_vec vec[2];
+        u_int nh;
 
         /* pseudo-header */
         memset(&ph, 0, sizeof(ph));
         UNALIGNED_MEMCPY(&ph.ph_src, &ip6->ip6_src, sizeof (struct in6_addr));
-        switch (ip6->ip6_nxt) {
+        nh = EXTRACT_U_1(ip6->ip6_nxt);
+        switch (nh) {
 
         case IPPROTO_HOPOPTS:
         case IPPROTO_DSTOPTS:
@@ -239,14 +241,15 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
           return;
        }
 
-       payload_len = EXTRACT_BE_U_2(&ip6->ip6_plen);
+       payload_len = EXTRACT_BE_U_2(ip6->ip6_plen);
        len = payload_len + sizeof(struct ip6_hdr);
        if (length < len)
                ND_PRINT((ndo, "truncated-ip6 - %u bytes missing!",
                        len - length));
 
+        nh = EXTRACT_U_1(ip6->ip6_nxt);
         if (ndo->ndo_vflag) {
-            flow = EXTRACT_BE_U_4(&ip6->ip6_flow);
+            flow = EXTRACT_BE_U_4(ip6->ip6_flow);
             ND_PRINT((ndo, "("));
 #if 0
             /* rfc1883 */
@@ -263,9 +266,9 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
 #endif
 
             ND_PRINT((ndo, "hlim %u, next-header %s (%u) payload length: %u) ",
-                         ip6->ip6_hlim,
-                         tok2str(ipproto_values,"unknown",ip6->ip6_nxt),
-                         ip6->ip6_nxt,
+                         EXTRACT_U_1(ip6->ip6_hlim),
+                         tok2str(ipproto_values,"unknown",nh),
+                         nh,
                          payload_len));
         }
 
@@ -278,7 +281,6 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
 
        cp = (const u_char *)ip6;
        advance = sizeof(struct ip6_hdr);
-       nh = ip6->ip6_nxt;
        while (cp < ndo->ndo_snapend && advance > 0) {
                if (len < (u_int)advance)
                        goto trunc;
index 41b292e722eebbd6c0ca91fb2cfdec9596ad20d8..95e52e4bb9ec95c96eccc3414a14ee671079c264 100644 (file)
@@ -177,7 +177,7 @@ hbhopt_print(netdissect_options *ndo, register const u_char *bp)
     u_int hbhlen = 0;
 
     ND_TCHECK(dp->ip6h_len);
-    hbhlen = (dp->ip6h_len + 1) << 3;
+    hbhlen = (EXTRACT_U_1(dp->ip6h_len) + 1) << 3;
     ND_TCHECK_LEN(dp, hbhlen);
     ND_PRINT((ndo, "HBH "));
     if (ndo->ndo_vflag)
@@ -197,7 +197,7 @@ dstopt_print(netdissect_options *ndo, register const u_char *bp)
     u_int dstoptlen = 0;
 
     ND_TCHECK(dp->ip6d_len);
-    dstoptlen = (dp->ip6d_len + 1) << 3;
+    dstoptlen = (EXTRACT_U_1(dp->ip6d_len) + 1) << 3;
     ND_TCHECK_LEN(dp, dstoptlen);
     ND_PRINT((ndo, "DSTOPT "));
     if (ndo->ndo_vflag) {
index 16735f5d6be0952937fd014a0129eb2b76cd9b24..04b654ef23ef0a6e54d569b7badb6a925b44d623 100644 (file)
@@ -181,7 +181,7 @@ pgm_print(netdissect_options *ndo,
        dport = EXTRACT_BE_U_2(&pgm->pgm_dport);
 
        if (ip6) {
-               if (ip6->ip6_nxt == IPPROTO_PGM) {
+               if (EXTRACT_U_1(ip6->ip6_nxt) == IPPROTO_PGM) {
                        ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                ip6addr_string(ndo, &ip6->ip6_src),
                                tcpport_string(ndo, sport),
index 31da35ea972033c097050b05b22ab4987f8b9b06..66c417586a9b1fd636b0e0902d1d1ec30488e050 100644 (file)
@@ -41,7 +41,7 @@ rt6_print(netdissect_options *ndo, register const u_char *bp, const u_char *bp2
        register const struct ip6_rthdr *dp;
        register const struct ip6_rthdr0 *dp0;
        register const u_char *ep;
-       int i, len;
+       u_int i, len, type;
        register const struct in6_addr *addr;
 
        dp = (const struct ip6_rthdr *)bp;
@@ -51,12 +51,13 @@ rt6_print(netdissect_options *ndo, register const u_char *bp, const u_char *bp2
 
        ND_TCHECK(dp->ip6r_segleft);
 
-       len = dp->ip6r_len;
-       ND_PRINT((ndo, "srcrt (len=%d", dp->ip6r_len)); /*)*/
-       ND_PRINT((ndo, ", type=%d", dp->ip6r_type));
-       ND_PRINT((ndo, ", segleft=%d", dp->ip6r_segleft));
+       len = EXTRACT_U_1(dp->ip6r_len);
+       ND_PRINT((ndo, "srcrt (len=%u", len));  /*)*/
+       type = EXTRACT_U_1(dp->ip6r_type);
+       ND_PRINT((ndo, ", type=%u", type));
+       ND_PRINT((ndo, ", segleft=%u", EXTRACT_U_1(dp->ip6r_segleft)));
 
-       switch (dp->ip6r_type) {
+       switch (type) {
        case IPV6_RTHDR_TYPE_0:
        case IPV6_RTHDR_TYPE_2:                 /* Mobile IPv6 ID-20 */
                dp0 = (const struct ip6_rthdr0 *)dp;
index 91d8212e931f04414bcd9bdad61821011fc37b16..70af9b613e60a82bcacae9767f2a74f4b622cea4 100644 (file)
@@ -187,11 +187,11 @@ tcp_print(netdissect_options *ndo,
                 return;
         }
 
-        sport = EXTRACT_BE_U_2(&tp->th_sport);
-        dport = EXTRACT_BE_U_2(&tp->th_dport);
+        sport = EXTRACT_BE_U_2(tp->th_sport);
+        dport = EXTRACT_BE_U_2(tp->th_dport);
 
         if (ip6) {
-                if (ip6->ip6_nxt == IPPROTO_TCP) {
+                if (EXTRACT_U_1(ip6->ip6_nxt) == IPPROTO_TCP) {
                         ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                      ip6addr_string(ndo, &ip6->ip6_src),
                                      tcpport_string(ndo, sport),
@@ -224,10 +224,10 @@ tcp_print(netdissect_options *ndo,
                 return;
         }
 
-        seq = EXTRACT_BE_U_4(&tp->th_seq);
-        ack = EXTRACT_BE_U_4(&tp->th_ack);
-        win = EXTRACT_BE_U_2(&tp->th_win);
-        urp = EXTRACT_BE_U_2(&tp->th_urp);
+        seq = EXTRACT_BE_U_4(tp->th_seq);
+        ack = EXTRACT_BE_U_4(tp->th_ack);
+        win = EXTRACT_BE_U_2(tp->th_win);
+        urp = EXTRACT_BE_U_2(tp->th_urp);
 
         if (ndo->ndo_qflag) {
                 ND_PRINT((ndo, "tcp %d", length - hlen));
@@ -372,7 +372,7 @@ tcp_print(netdissect_options *ndo,
                 if (IP_V(ip) == 4) {
                         if (ND_TTEST2(tp->th_sport, length)) {
                                 sum = tcp_cksum(ndo, ip, tp, length);
-                                tcp_sum = EXTRACT_BE_U_2(&tp->th_sum);
+                                tcp_sum = EXTRACT_BE_U_2(tp->th_sum);
 
                                 ND_PRINT((ndo, ", cksum 0x%04x", tcp_sum));
                                 if (sum != 0)
@@ -384,7 +384,7 @@ tcp_print(netdissect_options *ndo,
                 } else if (IP_V(ip) == 6 && ip6->ip6_plen) {
                         if (ND_TTEST2(tp->th_sport, length)) {
                                 sum = tcp6_cksum(ndo, ip6, tp, length);
-                                tcp_sum = EXTRACT_BE_U_2(&tp->th_sum);
+                                tcp_sum = EXTRACT_BE_U_2(tp->th_sum);
 
                                 ND_PRINT((ndo, ", cksum 0x%04x", tcp_sum));
                                 if (sum != 0)
@@ -871,14 +871,14 @@ tcp_verify_signature(netdissect_options *ndo,
                 MD5_Update(&ctx, (const char *)&ip->ip_dst, sizeof(ip->ip_dst));
                 MD5_Update(&ctx, (const char *)&zero_proto, sizeof(zero_proto));
                 MD5_Update(&ctx, (const char *)&ip->ip_p, sizeof(ip->ip_p));
-                tlen = EXTRACT_BE_U_2(&ip->ip_len) - IP_HL(ip) * 4;
+                tlen = EXTRACT_BE_U_2(ip->ip_len) - IP_HL(ip) * 4;
                 tlen = htons(tlen);
                 MD5_Update(&ctx, (const char *)&tlen, sizeof(tlen));
         } else if (IP_V(ip) == 6) {
                 ip6 = (const struct ip6_hdr *)ip;
                 MD5_Update(&ctx, (const char *)&ip6->ip6_src, sizeof(ip6->ip6_src));
                 MD5_Update(&ctx, (const char *)&ip6->ip6_dst, sizeof(ip6->ip6_dst));
-                len32 = htonl(EXTRACT_BE_U_2(&ip6->ip6_plen));
+                len32 = htonl(EXTRACT_BE_U_2(ip6->ip6_plen));
                 MD5_Update(&ctx, (const char *)&len32, sizeof(len32));
                 nxt = 0;
                 MD5_Update(&ctx, (const char *)&nxt, sizeof(nxt));
index b4fcec9424dbbdc18dd89aaad8ef4cc81f211f8a..c58339e99d3067da884f377f7a2a5130be78c2cc 100644 (file)
@@ -324,7 +324,7 @@ udpipaddr_print(netdissect_options *ndo, const struct ip *ip, int sport, int dpo
                ip6 = NULL;
 
        if (ip6) {
-               if (ip6->ip6_nxt == IPPROTO_UDP) {
+               if (EXTRACT_U_1(ip6->ip6_nxt) == IPPROTO_UDP) {
                        if (sport == -1) {
                                ND_PRINT((ndo, "%s > %s: ",
                                        ip6addr_string(ndo, &ip6->ip6_src),