]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Use nextproto6_cksum() for XXX-over-IPv6 checksums.
authorGuy Harris <[email protected]>
Fri, 17 Jun 2011 07:51:47 +0000 (00:51 -0700)
committerGuy Harris <[email protected]>
Fri, 17 Jun 2011 07:51:47 +0000 (00:51 -0700)
Get rid of duplicated checksums with IPv6 pseudo-headers.

ip6.h
netdissect.h
print-dccp.c
print-icmp6.c
print-ip6.c
print-tcp.c
print-udp.c

diff --git a/ip6.h b/ip6.h
index c54b5b2e69eaa5b78e4c79f36374aeb8f2450d79..12c87ad29291ca0868bf361d99214e0ecbbb069e 100644 (file)
--- a/ip6.h
+++ b/ip6.h
@@ -187,6 +187,6 @@ struct ip6_frag {
 #define IP6F_MORE_FRAG         0x0001  /* more-fragments flag */
 
 /* in print-ip6.c */
-extern int nextproto6_cksum(const struct ip6_hdr *, const u_short *, u_int, u_int);
+extern int nextproto6_cksum(const struct ip6_hdr *, const u_int8_t *, u_int, u_int);
 
 #endif /* not _NETINET_IP6_H_ */
index 0c829e62c83ca4113da19092e80865fb17a343c8..5363988f569242b837ae942e727b8402d9c2befb 100644 (file)
@@ -461,7 +461,7 @@ extern u_int ieee802_15_4_if_print(netdissect_options *,const struct pcap_pkthdr
 extern void ip6_print(netdissect_options *,const u_char *, u_int);
 #if 0
 extern void ip6_opt_print(netdissect_options *,const u_char *, int);
-extern int nextproto6_cksum(const struct ip6_hdr *, const u_short *, u_int, u_int);
+extern int nextproto6_cksum(const struct ip6_hdr *, const u_int8_t *, u_int, u_int);
 extern int hbhopt_print(netdissect_options *,const u_char *);
 extern int dstopt_print(netdissect_options *,const u_char *);
 extern int frag6_print(netdissect_options *,const u_char *,
index 460c43a0511ad1cc8137bfcdc72b9a39b2100845..96aa7ab270c13fe97275d15d24f6e1a3528038ec 100644 (file)
@@ -103,28 +103,8 @@ static int dccp_cksum(const struct ip *ip,
 #ifdef INET6
 static int dccp6_cksum(const struct ip6_hdr *ip6, const struct dccp_hdr *dh, u_int len)
 {
-       int cov = dccp_csum_coverage(dh, len);
-       struct {
-               struct in6_addr ph_src;
-               struct in6_addr ph_dst;
-               u_int32_t   ph_len;
-               u_int8_t    ph_zero[3];
-               u_int8_t    ph_nxt;
-       } ph;
-       struct cksum_vec vec[2];
-
-       /* pseudo-header */
-       memset(&ph, 0, sizeof(ph));
-       ph.ph_src = ip6->ip6_src;
-       ph.ph_dst = ip6->ip6_dst;
-       ph.ph_len = htonl(len);
-       ph.ph_nxt = IPPROTO_DCCP;
-
-       vec[0].ptr = (const u_int8_t *)(void *)&ph;
-       vec[0].len = sizeof(ph);
-       vec[1].ptr = (const u_int8_t *)(void *)dh;
-       vec[1].len = cov;
-       return in_cksum(vec, 2);
+       return nextproto6_cksum(ip6, (const u_int8_t *)(void *)dh,
+           dccp_csum_coverage(dh, len), IPPROTO_DCCP);
 }
 #endif
 
index c8c06386f555e4fe362a7acc6d10dca102c6455d..be362bbf1dddbc2427cacb1a3182b513391e1ef4 100644 (file)
@@ -197,44 +197,8 @@ print_lladdr(const u_int8_t *p, size_t l)
 static int icmp6_cksum(const struct ip6_hdr *ip6, const struct icmp6_hdr *icp,
        u_int len)
 {
-       size_t i;
-       register const u_int16_t *sp;
-       u_int32_t sum;
-       union {
-               struct {
-                       struct in6_addr ph_src;
-                       struct in6_addr ph_dst;
-                       u_int32_t       ph_len;
-                       u_int8_t        ph_zero[3];
-                       u_int8_t        ph_nxt;
-               } ph;
-               u_int16_t pa[20];
-       } phu;
-
-       /* pseudo-header */
-       memset(&phu, 0, sizeof(phu));
-       phu.ph.ph_src = ip6->ip6_src;
-       phu.ph.ph_dst = ip6->ip6_dst;
-       phu.ph.ph_len = htonl(len);
-       phu.ph.ph_nxt = IPPROTO_ICMPV6;
-
-       sum = 0;
-       for (i = 0; i < sizeof(phu.pa) / sizeof(phu.pa[0]); i++)
-               sum += phu.pa[i];
-
-       sp = (const u_int16_t *)icp;
-
-       for (i = 0; i < (len & ~1); i += 2)
-               sum += *sp++;
-
-       if (len & 1)
-               sum += htons((*(const u_int8_t *)sp) << 8);
-
-       while (sum > 0xffff)
-               sum = (sum & 0xffff) + (sum >> 16);
-       sum = ~sum & 0xffff;
-
-       return (sum);
+       return (nextproto6_cksum(ip6, (const u_int8_t *)(void *)icp, len,
+           IPPROTO_ICMPV6));
 }
 
 enum ND_RPL_CODE {
index fad1a9a2d3a4bfa8fb0d13155da0ec932532a241..f5e62441ea9ee7c305f32c0189921a5a4e523366 100644 (file)
@@ -48,7 +48,7 @@ static const char rcsid[] _U_ =
  * Compute a V6-style checksum by building a pseudoheader.
  */
 int
-nextproto6_cksum(const struct ip6_hdr *ip6, const u_short *data,
+nextproto6_cksum(const struct ip6_hdr *ip6, const u_int8_t *data,
                 u_int len, u_int next_proto)
 {
         struct {
@@ -69,7 +69,7 @@ nextproto6_cksum(const struct ip6_hdr *ip6, const u_short *data,
 
         vec[0].ptr = (const u_int8_t *)(void *)&ph;
         vec[0].len = sizeof(ph);
-        vec[1].ptr = (const u_int8_t *)(void *)data;
+        vec[1].ptr = data;
         vec[1].len = len;
 
         return in_cksum(vec, 2);
@@ -225,7 +225,7 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
                    }
 
                case IPPROTO_PIM:
-                       pim_print(cp, len, nextproto6_cksum(ip6, (u_short *)cp, len,
+                       pim_print(cp, len, nextproto6_cksum(ip6, cp, len,
                                                            IPPROTO_PIM));
                        return;
 
index 24025e5958c705c3503a80b3c391111da5a45738..82840419181cf9d0ab6d7a48b6ef777e743f1fd9 100644 (file)
@@ -432,7 +432,7 @@ tcp_print(register const u_char *bp, register u_int length,
 #ifdef INET6
                 else if (IP_V(ip) == 6 && ip6->ip6_plen) {
                         if (TTEST2(tp->th_sport, length)) {
-                                sum = nextproto6_cksum(ip6, (u_short *)tp, length, IPPROTO_TCP);
+                                sum = nextproto6_cksum(ip6, (const u_int8_t *)tp, length, IPPROTO_TCP);
                                 tcp_sum = EXTRACT_16BITS(&tp->th_sum);
 
                                 (void)printf(", cksum 0x%04x", tcp_sum);
index 32a7e8afce5af127f59bd02fad1d4f32690fb5f0..02a1e6ec5f46bb285a2cc21893a9bd7ba2f3b1f2 100644 (file)
@@ -316,27 +316,8 @@ static int udp_cksum(register const struct ip *ip,
 static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up,
        u_int len)
 {
-       struct {
-               struct in6_addr ph_src;
-               struct in6_addr ph_dst;
-               u_int32_t       ph_len;
-               u_int8_t        ph_zero[3];
-               u_int8_t        ph_nxt;
-       } ph;
-       struct cksum_vec vec[2];
-
-       /* pseudo-header */
-       memset(&ph, 0, sizeof(ph));
-       ph.ph_src = ip6->ip6_src;
-       ph.ph_dst = ip6->ip6_dst;
-       ph.ph_len = htonl(len);
-       ph.ph_nxt = IPPROTO_UDP;
-
-       vec[0].ptr = (const u_int8_t *)(void *)&ph;
-       vec[0].len = sizeof(ph);
-       vec[1].ptr = (const u_int8_t *)(void *)up;
-       vec[1].len = len;
-       return (in_cksum(vec, 2));
+       return (nextproto6_cksum(ip6, (const u_int8_t *)(void *)up, len,
+           IPPROTO_UDP));
 }
 #endif