Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netinet Style, rename 'iph' -> 'ip', and reduce the diff...



details:   https://anonhg.NetBSD.org/src/rev/21172bf4d292
branches:  trunk
changeset: 320534:21172bf4d292
user:      maxv <maxv%NetBSD.org@localhost>
date:      Wed Jul 11 06:00:34 2018 +0000

description:
Style, rename 'iph' -> 'ip', and reduce the diff between
in_undefer_cksum_tcpudp and the last part of in_undefer_cksum.

diffstat:

 sys/netinet/in_offload.c |  56 +++++++++++++++++++++++------------------------
 sys/netinet/in_offload.h |  12 ++++------
 2 files changed, 32 insertions(+), 36 deletions(-)

diffs (160 lines):

diff -r 38a29872aba0 -r 21172bf4d292 sys/netinet/in_offload.c
--- a/sys/netinet/in_offload.c  Wed Jul 11 05:38:55 2018 +0000
+++ b/sys/netinet/in_offload.c  Wed Jul 11 06:00:34 2018 +0000
@@ -1,6 +1,6 @@
-/*     $NetBSD: in_offload.c,v 1.9 2018/07/11 05:38:55 maxv Exp $      */
+/*     $NetBSD: in_offload.c,v 1.10 2018/07/11 06:00:34 maxv Exp $     */
 
-/*-
+/*
  * Copyright (c)2005, 2006 YAMAMOTO Takashi,
  * All rights reserved.
  *
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_offload.c,v 1.9 2018/07/11 05:38:55 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_offload.c,v 1.10 2018/07/11 06:00:34 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/mbuf.h>
@@ -50,11 +50,9 @@
     struct rtentry *rt)
 {
        int mss;
-       int iphlen;
-       int thlen;
-       int hlen;
-       int len;
-       struct ip *iph;
+       int iphlen, thlen;
+       int hlen, len;
+       struct ip *ip;
        struct tcphdr *th;
        uint16_t ipid;
        uint32_t tcpseq;
@@ -68,21 +66,21 @@
        m->m_pkthdr.csum_flags = 0;
 
        len = m->m_pkthdr.len;
-       KASSERT(len >= sizeof(*iph) + sizeof(*th));
+       KASSERT(len >= sizeof(*ip) + sizeof(*th));
 
-       if (m->m_len < sizeof(*iph)) {
-               m = m_pullup(m, sizeof(*iph));
+       if (m->m_len < sizeof(*ip)) {
+               m = m_pullup(m, sizeof(*ip));
                if (m == NULL) {
                        error = ENOMEM;
                        goto quit;
                }
        }
-       iph = mtod(m, struct ip *);
-       iphlen = iph->ip_hl * 4;
-       KASSERT(iph->ip_v == IPVERSION);
-       KASSERT(iphlen >= sizeof(*iph));
-       KASSERT(iph->ip_p == IPPROTO_TCP);
-       ipid = ntohs(iph->ip_id);
+       ip = mtod(m, struct ip *);
+       iphlen = ip->ip_hl * 4;
+       KASSERT(ip->ip_v == IPVERSION);
+       KASSERT(iphlen >= sizeof(*ip));
+       KASSERT(ip->ip_p == IPPROTO_TCP);
+       ipid = ntohs(ip->ip_id);
 
        hlen = iphlen + sizeof(*th);
        if (m->m_len < hlen) {
@@ -132,14 +130,14 @@
                KASSERT(n->m_len >= hlen); /* XXX */
 
                n->m_pkthdr.len = hlen + mss;
-               iph = mtod(n, struct ip *);
-               KASSERT(iph->ip_v == IPVERSION);
-               iph->ip_len = htons(n->m_pkthdr.len);
-               iph->ip_id = htons(ipid);
+               ip = mtod(n, struct ip *);
+               KASSERT(ip->ip_v == IPVERSION);
+               ip->ip_len = htons(n->m_pkthdr.len);
+               ip->ip_id = htons(ipid);
                th = (void *)(mtod(n, char *) + iphlen);
                th->th_seq = htonl(tcpseq);
-               iph->ip_sum = 0;
-               iph->ip_sum = in_cksum(n, iphlen);
+               ip->ip_sum = 0;
+               ip->ip_sum = in_cksum(n, iphlen);
                th->th_sum = 0;
                th->th_sum = in4_cksum(n, IPPROTO_TCP, iphlen, thlen + mss);
 
@@ -224,7 +222,7 @@
                if (__predict_true(l4offset + sizeof(uint16_t) <= m->m_len)) {
                        *(uint16_t *)(mtod(m, char *) + l4offset) = csum;
                } else {
-                       m_copyback(m, l4offset, sizeof(csum), (void *) &csum);
+                       m_copyback(m, l4offset, sizeof(csum), (void *)&csum);
                }
        }
 
@@ -239,20 +237,20 @@
 in_undefer_cksum_tcpudp(struct mbuf *m)
 {
        struct ip *ip;
-       u_int16_t csum, offset;
+       uint16_t csum, offset;
 
        ip = mtod(m, struct ip *);
        offset = ip->ip_hl << 2;
+
        csum = in4_cksum(m, 0, offset, ntohs(ip->ip_len) - offset);
        if (csum == 0 && (m->m_pkthdr.csum_flags & M_CSUM_UDPv4) != 0)
                csum = 0xffff;
 
        offset += M_CSUM_DATA_IPv4_OFFSET(m->m_pkthdr.csum_data);
 
-       if ((offset + sizeof(u_int16_t)) > m->m_len) {
-               /* This happens when ip options were inserted */
+       if ((offset + sizeof(uint16_t)) <= m->m_len) {
+               *(uint16_t *)(mtod(m, char *) + offset) = csum;
+       } else {
                m_copyback(m, offset, sizeof(csum), (void *)&csum);
-       } else {
-               *(u_int16_t *)(mtod(m, char *) + offset) = csum;
        }
 }
diff -r 38a29872aba0 -r 21172bf4d292 sys/netinet/in_offload.h
--- a/sys/netinet/in_offload.h  Wed Jul 11 05:38:55 2018 +0000
+++ b/sys/netinet/in_offload.h  Wed Jul 11 06:00:34 2018 +0000
@@ -1,6 +1,6 @@
-/*     $NetBSD: in_offload.h,v 1.10 2018/07/11 05:38:55 maxv Exp $     */
+/*     $NetBSD: in_offload.h,v 1.11 2018/07/11 06:00:34 maxv Exp $     */
 
-/*-
+/*
  * Copyright (c)2005, 2006 YAMAMOTO Takashi,
  * All rights reserved.
  *
@@ -30,21 +30,19 @@
 #define        _NETINET_IN_OFFLOAD_H_
 
 /*
- * subroutines to do software-only equivalent of h/w offloading.
+ * Subroutines to do software-only equivalent of h/w offloading.
  */
-
 int ip_tso_output(struct ifnet *, struct mbuf *, const struct sockaddr *,
     struct rtentry *);
 void in_undefer_cksum(struct mbuf *, size_t, int);
 void in_undefer_cksum_tcpudp(struct mbuf *);
 
 /*
- * offloading related sysctl variables.
+ * Offloading-related sysctl variables.
  *
- * they are here because it violates protocol layering in unusual way.
+ * They are here because it violates protocol layering in unusual way.
  * ie. while they are TCP/UDP sysctls, they are used by IP layer.
  */
-
 extern int tcp_do_loopback_cksum; /* do TCP checksum on loopback? */
 extern int udp_do_loopback_cksum; /* do UDP checksum on loopback? */
 



Home | Main Index | Thread Index | Old Index