diff options
author | Lawrence Teo <lteo@cvs.openbsd.org> | 2013-06-05 02:25:06 +0000 |
---|---|---|
committer | Lawrence Teo <lteo@cvs.openbsd.org> | 2013-06-05 02:25:06 +0000 |
commit | 90edb487a57327280a2e55947d2b1e5b50701d1f (patch) | |
tree | 6003209d81b3d12d655e2ca894c66fb4a1e926b6 /sys | |
parent | 69d45c9634312598b247320e7af351d0e396664f (diff) |
Calculate ICMP checksums with in4_cksum() which lets us get rid of the
clunky m_data/m_len dance needed by in_cksum().
Tested on amd64, hppa, i386, loongson, macppc, sgi, and sparc64.
Thanks to blambert@, bluhm@, and henning@ for help and feedback;
abieber@ for testing this diff independently on macppc; krw@ for access
to his hppa, sgi, and sparc64 test systems at t2k13; nick@ for helping
me figure out Ken's hppa so that I can test this diff. :)
ok blambert bluhm henning mikeb
Diffstat (limited to 'sys')
-rw-r--r-- | sys/netinet/ip_icmp.c | 18 | ||||
-rw-r--r-- | sys/netinet/ip_output.c | 11 |
2 files changed, 9 insertions, 20 deletions
diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 1680ac52816..baef294334c 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_icmp.c,v 1.99 2013/05/03 09:35:20 mpi Exp $ */ +/* $OpenBSD: ip_icmp.c,v 1.100 2013/06/05 02:25:05 lteo Exp $ */ /* $NetBSD: ip_icmp.c,v 1.19 1996/02/13 23:42:22 christos Exp $ */ /* @@ -347,16 +347,12 @@ icmp_input(struct mbuf *m, ...) return; } ip = mtod(m, struct ip *); - m->m_len -= hlen; - m->m_data += hlen; - icp = mtod(m, struct icmp *); - if (in_cksum(m, icmplen)) { + if (in4_cksum(m, 0, hlen, icmplen)) { icmpstat.icps_checksum++; goto freeit; } - m->m_len += hlen; - m->m_data -= hlen; + icp = (struct icmp *)(mtod(m, caddr_t) + hlen); #ifdef ICMPPRINTFS /* * Message type specific processing. @@ -807,13 +803,9 @@ icmp_send(struct mbuf *m, struct mbuf *opts) struct icmp *icp; hlen = ip->ip_hl << 2; - m->m_data += hlen; - m->m_len -= hlen; - icp = mtod(m, struct icmp *); + icp = (struct icmp *)(mtod(m, caddr_t) + hlen); icp->icmp_cksum = 0; - icp->icmp_cksum = in_cksum(m, ntohs(ip->ip_len) - hlen); - m->m_data -= hlen; - m->m_len += hlen; + icp->icmp_cksum = in4_cksum(m, 0, hlen, ntohs(ip->ip_len) - hlen); #ifdef ICMPPRINTFS if (icmpprintfs) { char buf[4 * sizeof("123")]; diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 00c2e21957c..099f71ffc05 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_output.c,v 1.239 2013/04/24 12:34:15 mpi Exp $ */ +/* $OpenBSD: ip_output.c,v 1.240 2013/06/05 02:25:05 lteo Exp $ */ /* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */ /* @@ -2126,13 +2126,10 @@ in_proto_cksum_out(struct mbuf *m, struct ifnet *ifp) struct icmp *icp; hlen = ip->ip_hl << 2; - m->m_data += hlen; - m->m_len -= hlen; - icp = mtod(m, struct icmp *); + icp = (struct icmp *)(mtod(m, caddr_t) + hlen); icp->icmp_cksum = 0; - icp->icmp_cksum = in_cksum(m, ntohs(ip->ip_len) - hlen); - m->m_data -= hlen; - m->m_len += hlen; + icp->icmp_cksum = in4_cksum(m, 0, hlen, + ntohs(ip->ip_len) - hlen); m->m_pkthdr.csum_flags &= ~M_ICMP_CSUM_OUT; /* Clear */ } } |