diff options
author | Brad Smith <brad@cvs.openbsd.org> | 2006-01-12 15:06:13 +0000 |
---|---|---|
committer | Brad Smith <brad@cvs.openbsd.org> | 2006-01-12 15:06:13 +0000 |
commit | 89ea3802de539e5fbf173ab41da10f5f3239e559 (patch) | |
tree | b4db396ac5ec5a7e0294e4d228a458964ba71632 /sys | |
parent | 9d8e9330a35dbb4f9da9024018086d07a642d0fe (diff) |
- add a missing htons() to the receive checksum routine to fix
checksumming on little endian systems.
- only set the Ok flag in the checksum routine.
Checksumming fix from: Pyun YongHyeon <pyunyh at gmail dot com>
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/sparc/dev/hme.c | 20 | ||||
-rw-r--r-- | sys/dev/ic/hme.c | 22 |
2 files changed, 16 insertions, 26 deletions
diff --git a/sys/arch/sparc/dev/hme.c b/sys/arch/sparc/dev/hme.c index de6b75ace63..fe77ee65139 100644 --- a/sys/arch/sparc/dev/hme.c +++ b/sys/arch/sparc/dev/hme.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hme.c,v 1.50 2005/11/09 06:14:50 brad Exp $ */ +/* $OpenBSD: hme.c,v 1.51 2006/01/12 15:06:12 brad Exp $ */ /* * Copyright (c) 1998 Jason L. Wright (jason@thought.net) @@ -102,7 +102,7 @@ int hme_tint(struct hme_softc *); int hme_mint(struct hme_softc *, u_int32_t); int hme_eint(struct hme_softc *, u_int32_t); -/* TCP/UDP checksum offloading support */ +/* TCP/UDP checksum offload support */ void hme_rxcksum(struct mbuf *, u_int32_t); void hme_reset_rx(struct hme_softc *); @@ -749,7 +749,7 @@ hme_rxcksum(struct mbuf *m, u_int32_t flags) struct ip *ip; struct udphdr *uh; int32_t hlen, len, pktlen; - u_int16_t cksum, flag_bad, flag_ok, *opts; + u_int16_t cksum, *opts; u_int32_t temp32; union pseudoh { struct hdr { @@ -787,8 +787,6 @@ hme_rxcksum(struct mbuf *m, u_int32_t flags) case IPPROTO_TCP: if (pktlen < (hlen + sizeof(struct tcphdr))) return; - flag_ok = M_TCP_CSUM_IN_OK; - flag_bad = M_TCP_CSUM_IN_BAD; break; case IPPROTO_UDP: if (pktlen < (hlen + sizeof(struct udphdr))) @@ -796,14 +794,12 @@ hme_rxcksum(struct mbuf *m, u_int32_t flags) uh = (struct udphdr *)((caddr_t)ip + hlen); if (uh->uh_sum == 0) return; /* no checksum */ - flag_ok = M_UDP_CSUM_IN_OK; - flag_bad = M_UDP_CSUM_IN_BAD; break; default: return; } - cksum = ~(flags & HME_RXD_CSUM); + cksum = htons(~(flags & HME_RXD_CSUM)); /* cksum fixup for IP options */ len = hlen - sizeof(struct ip); if (len > 0) { @@ -826,10 +822,10 @@ hme_rxcksum(struct mbuf *m, u_int32_t flags) temp32 = (temp32 >> 16) + (temp32 & 65535); temp32 += (temp32 >> 16); cksum = ~temp32; - if (cksum != 0) - m->m_pkthdr.csum_flags |= flag_bad; - else - m->m_pkthdr.csum_flags |= flag_ok; + if (cksum == 0) { + m->m_pkthdr.csum_flags |= + M_TCP_CSUM_IN_OK | M_UDP_CSUM_IN_OK; + } } int diff --git a/sys/dev/ic/hme.c b/sys/dev/ic/hme.c index b4a2f078df0..6b73d056cfe 100644 --- a/sys/dev/ic/hme.c +++ b/sys/dev/ic/hme.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hme.c,v 1.40 2005/12/16 06:08:13 brad Exp $ */ +/* $OpenBSD: hme.c,v 1.41 2006/01/12 15:06:12 brad Exp $ */ /* $NetBSD: hme.c,v 1.21 2001/07/07 15:59:37 thorpej Exp $ */ /*- @@ -114,7 +114,7 @@ void hme_mediastatus(struct ifnet *, struct ifmediareq *); int hme_eint(struct hme_softc *, u_int); int hme_rint(struct hme_softc *); int hme_tint(struct hme_softc *); -/* TCP/UDP checksum offloading support */ +/* TCP/UDP checksum offload support */ void hme_rxcksum(struct mbuf *, u_int32_t); void @@ -752,7 +752,7 @@ hme_rxcksum(struct mbuf *m, u_int32_t flags) struct ip *ip; struct udphdr *uh; int32_t hlen, len, pktlen; - u_int16_t cksum, flag_bad, flag_ok, *opts; + u_int16_t cksum, *opts; u_int32_t temp32; union pseudoh { struct hdr { @@ -790,8 +790,6 @@ hme_rxcksum(struct mbuf *m, u_int32_t flags) case IPPROTO_TCP: if (pktlen < (hlen + sizeof(struct tcphdr))) return; - flag_ok = M_TCP_CSUM_IN_OK; - flag_bad = M_TCP_CSUM_IN_BAD; break; case IPPROTO_UDP: if (pktlen < (hlen + sizeof(struct udphdr))) @@ -799,14 +797,12 @@ hme_rxcksum(struct mbuf *m, u_int32_t flags) uh = (struct udphdr *)((caddr_t)ip + hlen); if (uh->uh_sum == 0) return; /* no checksum */ - flag_ok = M_UDP_CSUM_IN_OK; - flag_bad = M_UDP_CSUM_IN_BAD; break; default: return; } - cksum = ~(flags & HME_XD_RXCKSUM); + cksum = htons(~(flags & HME_XD_RXCKSUM)); /* cksum fixup for IP options */ len = hlen - sizeof(struct ip); if (len > 0) { @@ -829,10 +825,10 @@ hme_rxcksum(struct mbuf *m, u_int32_t flags) temp32 = (temp32 >> 16) + (temp32 & 65535); temp32 += (temp32 >> 16); cksum = ~temp32; - if (cksum != 0) - m->m_pkthdr.csum_flags |= flag_bad; - else - m->m_pkthdr.csum_flags |= flag_ok; + if (cksum == 0) { + m->m_pkthdr.csum_flags |= + M_TCP_CSUM_IN_OK | M_UDP_CSUM_IN_OK; + } } /* @@ -879,9 +875,7 @@ hme_rint(sc) } ifp->if_ipackets++; -#if 0 hme_rxcksum(m, flags); -#endif #if NBPFILTER > 0 if (ifp->if_bpf) |