Source-Changes-HG archive

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

[src/trunk]: src/sys avoid swapping endian of ip_len and ip_off on mbuf, to m...



details:   https://anonhg.NetBSD.org/src/rev/199ecc4602b5
branches:  trunk
changeset: 535293:199ecc4602b5
user:      itojun <itojun%NetBSD.org@localhost>
date:      Wed Aug 14 00:23:27 2002 +0000

description:
avoid swapping endian of ip_len and ip_off on mbuf, to meet with M_LEADINGSPACE
optimization made last year.  should solve PR 17867 and 10195.

IP_HDRINCL behavior of raw ip socket is kept unchanged.  we may want to
provide IP_HDRINCL variant that does not swap endian.

diffstat:

 sys/net/if_gre.c            |   7 +--
 sys/net/if_stf.c            |   6 +-
 sys/netinet/igmp.c          |  14 ++++---
 sys/netinet/in_gif.c        |   6 +-
 sys/netinet/ip_frag.c       |   8 ++--
 sys/netinet/ip_gre.c        |   7 +--
 sys/netinet/ip_icmp.c       |  44 +++++++++++++------------
 sys/netinet/ip_input.c      |  76 ++++++++++++++++++++++++--------------------
 sys/netinet/ip_mroute.c     |  17 ++++-----
 sys/netinet/ip_output.c     |  50 ++++++++++-------------------
 sys/netinet/raw_ip.c        |  20 +++++++----
 sys/netinet/tcp_input.c     |   8 ++--
 sys/netinet/tcp_output.c    |   6 +-
 sys/netinet/tcp_subr.c      |   6 +-
 sys/netinet/udp_usrreq.c    |  16 +++++----
 sys/netinet6/ah_input.c     |  10 ++--
 sys/netinet6/esp_input.c    |   6 +-
 sys/netinet6/ipcomp_input.c |   6 +-
 sys/netinet6/ipsec.c        |   9 ++--
 sys/netinet6/udp6_output.c  |   8 +--
 sys/netiso/if_eon.c         |  17 +++++++--
 sys/netiso/tp_inet.c        |  11 ++++-
 sys/netns/ns_ip.c           |  16 +++++---
 23 files changed, 194 insertions(+), 180 deletions(-)

diffs (truncated from 1272 to 300 lines):

diff -r 89ddff9cd034 -r 199ecc4602b5 sys/net/if_gre.c
--- a/sys/net/if_gre.c  Tue Aug 13 22:43:52 2002 +0000
+++ b/sys/net/if_gre.c  Wed Aug 14 00:23:27 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_gre.c,v 1.41 2002/08/12 05:22:57 itojun Exp $ */
+/*     $NetBSD: if_gre.c,v 1.42 2002/08/14 00:23:27 itojun Exp $ */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.41 2002/08/12 05:22:57 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.42 2002/08/14 00:23:27 itojun Exp $");
 
 #include "opt_inet.h"
 #include "opt_ns.h"
@@ -274,8 +274,7 @@
                        }
                        ip = mtod(m, struct ip *);
                        memcpy((caddr_t)(ip + 1), &mob_h, (unsigned)msiz);
-                       NTOHS(ip->ip_len);
-                       ip->ip_len += msiz;
+                       ip->ip_len = htons(ntohs(ip->ip_len) + msiz);
                } else {  /* AF_INET */
                        IF_DROP(&ifp->if_snd);
                        m_freem(m);
diff -r 89ddff9cd034 -r 199ecc4602b5 sys/net/if_stf.c
--- a/sys/net/if_stf.c  Tue Aug 13 22:43:52 2002 +0000
+++ b/sys/net/if_stf.c  Wed Aug 14 00:23:27 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_stf.c,v 1.28 2002/08/06 04:58:57 itojun Exp $       */
+/*     $NetBSD: if_stf.c,v 1.29 2002/08/14 00:23:28 itojun Exp $       */
 /*     $KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $ */
 
 /*
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.28 2002/08/06 04:58:57 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.29 2002/08/14 00:23:28 itojun Exp $");
 
 #include "opt_inet.h"
 
@@ -434,7 +434,7 @@
        bcopy(in4, &ip->ip_dst, sizeof(ip->ip_dst));
        ip->ip_p = IPPROTO_IPV6;
        ip->ip_ttl = ip_gif_ttl;        /*XXX*/
-       ip->ip_len = m->m_pkthdr.len;   /*host order*/
+       ip->ip_len = htons(m->m_pkthdr.len);
        if (ifp->if_flags & IFF_LINK1)
                ip_ecn_ingress(ECN_ALLOWED, &ip->ip_tos, &tos);
        else
diff -r 89ddff9cd034 -r 199ecc4602b5 sys/netinet/igmp.c
--- a/sys/netinet/igmp.c        Tue Aug 13 22:43:52 2002 +0000
+++ b/sys/netinet/igmp.c        Wed Aug 14 00:23:27 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: igmp.c,v 1.30 2002/06/30 22:40:33 thorpej Exp $        */
+/*     $NetBSD: igmp.c,v 1.31 2002/08/14 00:23:29 itojun Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.30 2002/06/30 22:40:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.31 2002/08/14 00:23:29 itojun Exp $");
 
 #include "opt_mrouting.h"
 
@@ -148,6 +148,7 @@
        struct in_ifaddr *ia;
        int timer;
        va_list ap;
+       u_int16_t ip_len;
 
        va_start(ap, m);
        iphlen = va_arg(ap, int);
@@ -160,7 +161,8 @@
         * Validate lengths
         */
        minlen = iphlen + IGMP_MINLEN;
-       if (ip->ip_len < minlen) {
+       ip_len = ntohs(ip->ip_len);
+       if (ip_len < minlen) {
                ++igmpstat.igps_rcv_tooshort;
                m_freem(m);
                return;
@@ -181,7 +183,7 @@
        m->m_len -= iphlen;
        igmp = mtod(m, struct igmp *);
        /* No need to assert alignment here. */
-       if (in_cksum(m, ip->ip_len - iphlen)) {
+       if (in_cksum(m, ip_len - iphlen)) {
                ++igmpstat.igps_rcv_badsum;
                m_freem(m);
                return;
@@ -526,8 +528,8 @@
 
        ip = mtod(m, struct ip *);
        ip->ip_tos = 0;
-       ip->ip_len = sizeof(struct ip) + IGMP_MINLEN;
-       ip->ip_off = 0;
+       ip->ip_len = htons(sizeof(struct ip) + IGMP_MINLEN);
+       ip->ip_off = htons(0);
        ip->ip_p = IPPROTO_IGMP;
        ip->ip_src = zeroin_addr;
        ip->ip_dst = inm->inm_addr;
diff -r 89ddff9cd034 -r 199ecc4602b5 sys/netinet/in_gif.c
--- a/sys/netinet/in_gif.c      Tue Aug 13 22:43:52 2002 +0000
+++ b/sys/netinet/in_gif.c      Wed Aug 14 00:23:27 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_gif.c,v 1.28 2002/07/14 21:09:17 itojun Exp $       */
+/*     $NetBSD: in_gif.c,v 1.29 2002/08/14 00:23:29 itojun Exp $       */
 /*     $KAME: in_gif.c,v 1.66 2001/07/29 04:46:09 itojun Exp $ */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.28 2002/07/14 21:09:17 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.29 2002/08/14 00:23:29 itojun Exp $");
 
 #include "opt_inet.h"
 #include "opt_iso.h"
@@ -170,7 +170,7 @@
        iphdr.ip_p = proto;
        /* version will be set in ip_output() */
        iphdr.ip_ttl = ip_gif_ttl;
-       iphdr.ip_len = m->m_pkthdr.len + sizeof(struct ip);
+       iphdr.ip_len = htons(m->m_pkthdr.len + sizeof(struct ip));
        if (ifp->if_flags & IFF_LINK1)
                ip_ecn_ingress(ECN_ALLOWED, &iphdr.ip_tos, &tos);
        else
diff -r 89ddff9cd034 -r 199ecc4602b5 sys/netinet/ip_frag.c
--- a/sys/netinet/ip_frag.c     Tue Aug 13 22:43:52 2002 +0000
+++ b/sys/netinet/ip_frag.c     Wed Aug 14 00:23:27 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_frag.c,v 1.31 2002/06/09 16:33:40 itojun Exp $      */
+/*     $NetBSD: ip_frag.c,v 1.32 2002/08/14 00:23:29 itojun Exp $      */
 
 /*
  * Copyright (C) 1993-2001 by Darren Reed.
@@ -93,7 +93,7 @@
 #if !defined(lint)
 #if defined(__NetBSD__)
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_frag.c,v 1.31 2002/06/09 16:33:40 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_frag.c,v 1.32 2002/08/14 00:23:29 itojun Exp $");
 #else
 static const char sccsid[] = "@(#)ip_frag.c    1.11 3/24/96 (C) 1993-2000 Darren Reed";
 static const char rcsid[] = "@(#)Id: ip_frag.c,v 2.10.2.21 2002/04/10 04:56:10 darrenr Exp";
@@ -217,7 +217,7 @@
        /*
         * Compute the offset of the expected start of the next packet.
         */
-       off = ip->ip_off & IP_OFFMASK;
+       off = ntohs(ip->ip_off) & IP_OFFMASK;
        if (!off)
                fra->ipfr_seen0 = 1;
        fra->ipfr_off = off + (fin->fin_dlen >> 3);
@@ -351,7 +351,7 @@
                         * last (in order), shrink expiration time.
                         */
                        if (off == f->ipfr_off) {
-                               if (!(ip->ip_off & IP_MF))
+                               if (!(ip->ip_off & htons(IP_MF)))
                                        f->ipfr_ttl = 1;
                                else
                                        f->ipfr_off = atoff;
diff -r 89ddff9cd034 -r 199ecc4602b5 sys/netinet/ip_gre.c
--- a/sys/netinet/ip_gre.c      Tue Aug 13 22:43:52 2002 +0000
+++ b/sys/netinet/ip_gre.c      Wed Aug 14 00:23:27 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_gre.c,v 1.20 2002/08/10 05:40:54 itojun Exp $ */
+/*     $NetBSD: ip_gre.c,v 1.21 2002/08/14 00:23:30 itojun Exp $ */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_gre.c,v 1.20 2002/08/10 05:40:54 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_gre.c,v 1.21 2002/08/14 00:23:30 itojun Exp $");
 
 #include "gre.h"
 #if NGRE > 0
@@ -297,8 +297,7 @@
        memmove(ip + (ip->ip_hl << 2), ip + (ip->ip_hl << 2) + msiz,
                m->m_len - msiz - (ip->ip_hl << 2));
        m->m_len -= msiz;
-       ip->ip_len -= msiz;
-       HTONS(ip->ip_len);
+       ip->ip_len = htons(ntohs(ip->ip_len) - msiz);
        m->m_pkthdr.len -= msiz;
 
        ip->ip_sum = 0;
diff -r 89ddff9cd034 -r 199ecc4602b5 sys/netinet/ip_icmp.c
--- a/sys/netinet/ip_icmp.c     Tue Aug 13 22:43:52 2002 +0000
+++ b/sys/netinet/ip_icmp.c     Wed Aug 14 00:23:27 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_icmp.c,v 1.69 2002/06/30 22:40:34 thorpej Exp $     */
+/*     $NetBSD: ip_icmp.c,v 1.70 2002/08/14 00:23:30 itojun Exp $      */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -105,7 +105,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.69 2002/06/30 22:40:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.70 2002/08/14 00:23:30 itojun Exp $");
 
 #include "opt_ipsec.h"
 
@@ -248,7 +248,7 @@
         */
        if (n->m_flags & M_DECRYPTED)
                goto freeit;
-       if (oip->ip_off &~ (IP_MF|IP_DF))
+       if (oip->ip_off &~ htons(IP_MF|IP_DF))
                goto freeit;
        if (oip->ip_p == IPPROTO_ICMP && type != ICMP_REDIRECT &&
          n->m_len >= oiplen + ICMP_MINLEN &&
@@ -271,7 +271,8 @@
        /*
         * Now, formulate icmp message
         */
-       icmplen = oiplen + min(icmpreturndatabytes, oip->ip_len - oiplen);
+       icmplen = oiplen + min(icmpreturndatabytes,
+           ntohs(oip->ip_len) - oiplen);
        /*
         * Defend against mbuf chains shorter than oip->ip_len:
         */
@@ -328,8 +329,6 @@
                        icp->icmp_nextmtu = htons(destifp->if_mtu);
        }
 
-       HTONS(oip->ip_off);
-       HTONS(oip->ip_len);
        icp->icmp_code = code;
        m_copydata(n, 0, icmplen, (caddr_t)&icp->icmp_ip);
        nip = &icp->icmp_ip;
@@ -348,9 +347,9 @@
        /* ip_v set in ip_output */
        nip->ip_hl = sizeof(struct ip) >> 2;
        nip->ip_tos = 0;
-       nip->ip_len = m->m_len;
+       nip->ip_len = htons(m->m_len);
        /* ip_id set in ip_output */
-       nip->ip_off = 0;
+       nip->ip_off = htons(0);
        /* ip_ttl set in icmp_reflect */
        nip->ip_p = IPPROTO_ICMP;
        nip->ip_src = oip->ip_src;
@@ -399,7 +398,7 @@
         * Locate icmp structure in mbuf, and check
         * that not corrupted and of at least minimum length.
         */
-       icmplen = ip->ip_len - hlen;
+       icmplen = ntohs(ip->ip_len) - hlen;
 #ifdef ICMPPRINTFS
        if (icmpprintfs)
                printf("icmp_input from %x to %x, len %d\n",
@@ -502,7 +501,6 @@
                }
                if (IN_MULTICAST(icp->icmp_ip.ip_dst.s_addr))
                        goto badcode;
-               NTOHS(icp->icmp_ip.ip_len);
 #ifdef ICMPPRINTFS
                if (icmpprintfs)
                        printf("deliver to protocol %d\n", icp->icmp_ip.ip_p);
@@ -687,10 +685,12 @@
 
        icmpdst.sin_addr = t;
 
-       /* if the packet is addressed somewhere else, compute the
-          source address for packets routed back to the source, and
-          use that, if it's an address on the interface which
-          received the packet */
+       /*
+        * if the packet is addressed somewhere else, compute the
+        * source address for packets routed back to the source, and
+        * use that, if it's an address on the interface which
+        * received the packet
+        */
        if (sin == (struct sockaddr_in *)0) {
                struct sockaddr_in sin_dst;
                struct route icmproute;
@@ -720,10 +720,12 @@
                }
        }
 
-       /* if it was not addressed to us, but the route doesn't go out
-          the source interface, pick an address on the source



Home | Main Index | Thread Index | Old Index