Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/netinet ip_undefer_csum:
details: https://anonhg.NetBSD.org/src/rev/94572d4dceb6
branches: trunk
changeset: 764495:94572d4dceb6
user: yamt <yamt%NetBSD.org@localhost>
date: Mon Apr 25 22:11:31 2011 +0000
description:
ip_undefer_csum:
- don't forget ntohs.
- don't add hdrlen twice for l4 header offset.
- use M_CSUM_DATA_IPv4_IPHL instead of extracting it from ip header.
- simplify code.
- KNF.
diffstat:
sys/netinet/in_offload.c | 30 ++++++++++++++++--------------
1 files changed, 16 insertions(+), 14 deletions(-)
diffs (75 lines):
diff -r 3e72c613a0bf -r 94572d4dceb6 sys/netinet/in_offload.c
--- a/sys/netinet/in_offload.c Mon Apr 25 22:09:29 2011 +0000
+++ b/sys/netinet/in_offload.c Mon Apr 25 22:11:31 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: in_offload.c,v 1.4 2011/04/14 15:53:36 yamt Exp $ */
+/* $NetBSD: in_offload.c,v 1.5 2011/04/25 22:11:31 yamt Exp $ */
/*-
* Copyright (c)2005, 2006 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_offload.c,v 1.4 2011/04/14 15:53:36 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_offload.c,v 1.5 2011/04/25 22:11:31 yamt Exp $");
#include <sys/param.h>
#include <sys/mbuf.h>
@@ -203,42 +203,44 @@
void
ip_undefer_csum(struct mbuf *m, size_t hdrlen, int csum_flags)
{
- KASSERT(m->m_flags & M_PKTHDR);
- KASSERT((m->m_pkthdr.csum_flags & csum_flags) == csum_flags);
+ const size_t iphdrlen = M_CSUM_DATA_IPv4_IPHL(m->m_pkthdr.csum_data);
uint16_t csum;
uint16_t ip_len;
uint16_t *csump;
- size_t iphdrlen;
+
+ KASSERT(m->m_flags & M_PKTHDR);
+ KASSERT((m->m_pkthdr.csum_flags & csum_flags) == csum_flags);
if (__predict_true(hdrlen + sizeof(struct ip) <= m->m_len)) {
struct ip *ip = (struct ip *)(mtod(m, uint8_t *) + hdrlen);
+
ip_len = ip->ip_len;
- iphdrlen = ip->ip_hl << 2;
csump = &ip->ip_sum;
} else {
- uint8_t ip_vhl;
- const size_t ip_len_offset = hdrlen + offsetof(struct ip, ip_len);
- m_copydata(m, hdrlen, sizeof(ip_vhl), &ip_vhl);
+ const size_t ip_len_offset =
+ hdrlen + offsetof(struct ip, ip_len);
+
m_copydata(m, ip_len_offset, sizeof(ip_len), &ip_len);
- iphdrlen = (ip_vhl & 0x0f) << 2;
csump = NULL;
}
+ ip_len = ntohs(ip_len);
if (csum_flags & M_CSUM_IPv4) {
- const size_t offset = hdrlen + offsetof(struct ip, ip_sum);
csum = in4_cksum(m, 0, hdrlen, iphdrlen);
if (csump != NULL) {
*csump = csum;
} else {
+ const size_t offset = hdrlen +
+ offsetof(struct ip, ip_sum);
+
m_copyback(m, offset, sizeof(uint16_t), &csum);
}
}
if (csum_flags & (M_CSUM_UDPv4|M_CSUM_TCPv4)) {
- size_t l4offset = hdrlen
- + M_CSUM_DATA_IPv4_IPHL(m->m_pkthdr.csum_data);
+ size_t l4offset = hdrlen + iphdrlen;
- csum = in4_cksum(m, 0, hdrlen + l4offset, ip_len - l4offset);
+ csum = in4_cksum(m, 0, l4offset, ip_len - l4offset - hdrlen);
if (csum == 0 && (csum_flags & M_CSUM_UDPv4) != 0)
csum = 0xffff;
Home |
Main Index |
Thread Index |
Old Index