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.
This commit is contained in:
itojun 2002-08-14 00:23:27 +00:00
parent f5435ff138
commit c00fa8dfd9
23 changed files with 195 additions and 181 deletions

View File

@ -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 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
}
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);

View File

@ -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 @@ stf_output(ifp, m, dst, rt)
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

View File

@ -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 @@ igmp_input(m, va_alist)
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 @@ igmp_input(m, va_alist)
* 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 @@ igmp_input(m, va_alist)
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 @@ igmp_sendpkt(inm, type)
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;

View File

@ -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 @@ in_gif_output(ifp, family, m)
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

View File

@ -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 @@ extern struct timeout ipfr_slowtimer_ch;
#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 @@ ipfr_t *table[];
/*
* 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 @@ ipfr_t *table[];
* 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;

View File

@ -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 @@ gre_mobile_input(m, va_alist)
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;

View File

@ -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 @@ icmp_error(n, type, code, dest, destifp)
*/
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 @@ icmp_error(n, type, code, dest, destifp)
/*
* 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 @@ icmp_error(n, type, code, dest, destifp)
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 @@ icmp_error(n, type, code, dest, destifp)
/* 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 @@ icmp_input(m, va_alist)
* 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 @@ icmp_input(m, va_alist)
}
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 @@ icmp_reflect(m)
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 @@ icmp_reflect(m)
}
}
/* if it was not addressed to us, but the route doesn't go out
the source interface, pick an address on the source
interface. This can happen when routing is asymmetric, or
when the incoming packet was encapsulated */
/*
* if it was not addressed to us, but the route doesn't go out
* the source interface, pick an address on the source
* interface. This can happen when routing is asymmetric, or
* when the incoming packet was encapsulated
*/
if (sin == (struct sockaddr_in *)0) {
TAILQ_FOREACH(ifa, &m->m_pkthdr.rcvif->if_addrlist, ifa_list) {
if (ifa->ifa_addr->sa_family != AF_INET)
@ -821,7 +823,7 @@ icmp_reflect(m)
* Now strip out original options by copying rest of first
* mbuf's data back, and adjust the IP length.
*/
ip->ip_len -= optlen;
ip->ip_len = htons(ntohs(ip->ip_len) - optlen);
ip->ip_hl = sizeof(struct ip) >> 2;
m->m_len -= optlen;
if (m->m_flags & M_PKTHDR)
@ -855,7 +857,7 @@ icmp_send(m, opts)
m->m_len -= hlen;
icp = mtod(m, struct icmp *);
icp->icmp_cksum = 0;
icp->icmp_cksum = in_cksum(m, ip->ip_len - hlen);
icp->icmp_cksum = in_cksum(m, ntohs(ip->ip_len) - hlen);
m->m_data -= hlen;
m->m_len += hlen;
#ifdef ICMPPRINTFS
@ -991,7 +993,7 @@ icmp_mtudisc(icp, faddr)
if (mtu == 0) {
int i = 0;
mtu = icp->icmp_ip.ip_len; /* NTOHS happened in deliver: */
mtu = ntohs(icp->icmp_ip.ip_len);
/* Some 4.2BSD-based routers incorrectly adjust the ip_len */
if (mtu > rt->rt_rmx.rmx_mtu && rt->rt_rmx.rmx_mtu != 0)
mtu -= (icp->icmp_ip.ip_hl << 2);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_input.c,v 1.154 2002/06/30 22:40:34 thorpej Exp $ */
/* $NetBSD: ip_input.c,v 1.155 2002/08/14 00:23:31 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -102,7 +102,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.154 2002/06/30 22:40:34 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.155 2002/08/14 00:23:31 itojun Exp $");
#include "opt_gateway.h"
#include "opt_pfil_hooks.h"
@ -571,12 +571,6 @@ ip_input(struct mbuf *m)
}
#endif
/*
* Convert fields to host representation.
*/
NTOHS(ip->ip_len);
NTOHS(ip->ip_off);
/*
* Process options and, if not destined for us,
* ship it on. ip_dooptions returns 1 when an
@ -722,7 +716,15 @@ ours:
* if the packet was previously fragmented,
* but it's not worth the time; just let them time out.)
*/
if (ip->ip_off & ~(IP_DF|IP_RF)) {
if (ip->ip_off & ~htons(IP_DF|IP_RF)) {
if (M_READONLY(m)) {
if ((m = m_pullup(m, hlen)) == NULL) {
ipstat.ips_toosmall++;
goto bad;
}
ip = mtod(m, struct ip *);
}
/*
* Look for queue of fragments
* of this datagram.
@ -742,27 +744,28 @@ found:
* set ipqe_mff if more fragments are expected,
* convert offset of this to bytes.
*/
ip->ip_len -= hlen;
mff = (ip->ip_off & IP_MF) != 0;
ip->ip_len = htons(ntohs(ip->ip_len) - hlen);
mff = (ip->ip_off & htons(IP_MF)) != 0;
if (mff) {
/*
* Make sure that fragments have a data length
* that's a non-zero multiple of 8 bytes.
*/
if (ip->ip_len == 0 || (ip->ip_len & 0x7) != 0) {
if (ntohs(ip->ip_len) == 0 ||
(ntohs(ip->ip_len) & 0x7) != 0) {
ipstat.ips_badfrags++;
IPQ_UNLOCK();
goto bad;
}
}
ip->ip_off <<= 3;
ip->ip_off = htons((ntohs(ip->ip_off) & IP_OFFMASK) << 3);
/*
* If datagram marked as having more fragments
* or if this is not the first fragment,
* attempt reassembly; if it succeeds, proceed.
*/
if (mff || ip->ip_off) {
if (mff || ip->ip_off != htons(0)) {
ipstat.ips_fragments++;
ipqe = pool_get(&ipqent_pool, PR_NOWAIT);
if (ipqe == NULL) {
@ -781,7 +784,7 @@ found:
ipstat.ips_reassembled++;
ip = mtod(m, struct ip *);
hlen = ip->ip_hl << 2;
ip->ip_len += hlen;
ip->ip_len = htons(ntohs(ip->ip_len) + hlen);
} else
if (fp)
ip_freef(fp);
@ -806,7 +809,7 @@ found:
*/
#if IFA_STATS
if (ia && ip)
ia->ia_ifa.ifa_data.ifad_inbytes += ip->ip_len;
ia->ia_ifa.ifa_data.ifad_inbytes += ntohs(ip->ip_len);
#endif
ipstat.ips_delivered++;
{
@ -886,7 +889,7 @@ ip_reass(ipqe, fp)
*/
for (p = NULL, q = TAILQ_FIRST(&fp->ipq_fragq); q != NULL;
p = q, q = TAILQ_NEXT(q, ipqe_q))
if (q->ipqe_ip->ip_off > ipqe->ipqe_ip->ip_off)
if (ntohs(q->ipqe_ip->ip_off) > ntohs(ipqe->ipqe_ip->ip_off))
break;
/*
@ -895,14 +898,16 @@ ip_reass(ipqe, fp)
* segment. If it provides all of our data, drop us.
*/
if (p != NULL) {
i = p->ipqe_ip->ip_off + p->ipqe_ip->ip_len -
ipqe->ipqe_ip->ip_off;
i = ntohs(p->ipqe_ip->ip_off) + ntohs(p->ipqe_ip->ip_len) -
ntohs(ipqe->ipqe_ip->ip_off);
if (i > 0) {
if (i >= ipqe->ipqe_ip->ip_len)
if (i >= ntohs(ipqe->ipqe_ip->ip_len))
goto dropfrag;
m_adj(ipqe->ipqe_m, i);
ipqe->ipqe_ip->ip_off += i;
ipqe->ipqe_ip->ip_len -= i;
ipqe->ipqe_ip->ip_off =
htons(ntohs(ipqe->ipqe_ip->ip_off) + i);
ipqe->ipqe_ip->ip_len =
htons(ntohs(ipqe->ipqe_ip->ip_len) - i);
}
}
@ -910,13 +915,16 @@ ip_reass(ipqe, fp)
* While we overlap succeeding segments trim them or,
* if they are completely covered, dequeue them.
*/
for (; q != NULL && ipqe->ipqe_ip->ip_off + ipqe->ipqe_ip->ip_len >
q->ipqe_ip->ip_off; q = nq) {
i = (ipqe->ipqe_ip->ip_off + ipqe->ipqe_ip->ip_len) -
q->ipqe_ip->ip_off;
if (i < q->ipqe_ip->ip_len) {
q->ipqe_ip->ip_len -= i;
q->ipqe_ip->ip_off += i;
for (; q != NULL &&
ntohs(ipqe->ipqe_ip->ip_off) + ntohs(ipqe->ipqe_ip->ip_len) >
ntohs(q->ipqe_ip->ip_off); q = nq) {
i = (ntohs(ipqe->ipqe_ip->ip_off) +
ntohs(ipqe->ipqe_ip->ip_len)) - ntohs(q->ipqe_ip->ip_off);
if (i < ntohs(q->ipqe_ip->ip_len)) {
q->ipqe_ip->ip_len =
htons(ntohs(q->ipqe_ip->ip_len) - i);
q->ipqe_ip->ip_off =
htons(ntohs(q->ipqe_ip->ip_off) + i);
m_adj(q->ipqe_m, i);
break;
}
@ -939,9 +947,9 @@ insert:
next = 0;
for (p = NULL, q = TAILQ_FIRST(&fp->ipq_fragq); q != NULL;
p = q, q = TAILQ_NEXT(q, ipqe_q)) {
if (q->ipqe_ip->ip_off != next)
if (ntohs(q->ipqe_ip->ip_off) != next)
return (0);
next += q->ipqe_ip->ip_len;
next += ntohs(q->ipqe_ip->ip_len);
}
if (p->ipqe_mff)
return (0);
@ -976,7 +984,7 @@ insert:
* dequeue and discard fragment reassembly header.
* Make header visible.
*/
ip->ip_len = next;
ip->ip_len = htons(next);
ip->ip_src = fp->ipq_src;
ip->ip_dst = fp->ipq_dst;
LIST_REMOVE(fp, ipq_q);
@ -1459,7 +1467,7 @@ ip_stripoptions(m, mopt)
m->m_len -= olen;
if (m->m_flags & M_PKTHDR)
m->m_pkthdr.len -= olen;
ip->ip_len -= olen;
ip->ip_len = htons(ntohs(ip->ip_len) - olen);
ip->ip_hl = sizeof (struct ip) >> 2;
}
@ -1549,7 +1557,7 @@ ip_forward(m, srcrt)
* we need to generate an ICMP message to the src.
* Pullup to avoid sharing mbuf cluster between m and mcopy.
*/
mcopy = m_copym(m, 0, imin((int)ip->ip_len, 68), M_DONTWAIT);
mcopy = m_copym(m, 0, imin(ntohs(ip->ip_len), 68), M_DONTWAIT);
if (mcopy)
mcopy = m_pullup(mcopy, ip->ip_hl << 2);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_mroute.c,v 1.61 2002/07/31 04:07:20 itojun Exp $ */
/* $NetBSD: ip_mroute.c,v 1.62 2002/08/14 00:23:31 itojun Exp $ */
/*
* Copyright (c) 1989 Stephen Deering
@ -54,7 +54,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.61 2002/07/31 04:07:20 itojun Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.62 2002/08/14 00:23:31 itojun Exp $");
#include "opt_ipsec.h"
@ -1444,7 +1444,8 @@ phyint_send(ip, vifp, m)
if (vifp->v_rate_limit <= 0)
tbf_send_packet(vifp, mb_copy);
else
tbf_control(vifp, mb_copy, mtod(mb_copy, struct ip *), ip->ip_len);
tbf_control(vifp, mb_copy, mtod(mb_copy, struct ip *),
ntohs(ip->ip_len));
}
static void
@ -1455,7 +1456,7 @@ encap_send(ip, vifp, m)
{
struct mbuf *mb_copy;
struct ip *ip_copy;
int i, len = ip->ip_len + sizeof(multicast_encap_iphdr);
int i, len = ntohs(ip->ip_len) + sizeof(multicast_encap_iphdr);
/*
* copy the old packet & pullup it's IP header into the
@ -1486,7 +1487,7 @@ encap_send(ip, vifp, m)
ip_copy = mtod(mb_copy, struct ip *);
*ip_copy = multicast_encap_iphdr;
ip_copy->ip_id = htons(ip_id++);
ip_copy->ip_len = len;
ip_copy->ip_len = htons(len);
ip_copy->ip_src = vifp->v_lcl_addr;
ip_copy->ip_dst = vifp->v_rmt_addr;
@ -1495,8 +1496,6 @@ encap_send(ip, vifp, m)
*/
ip = (struct ip *)((caddr_t)ip_copy + sizeof(multicast_encap_iphdr));
--ip->ip_ttl;
HTONS(ip->ip_len);
HTONS(ip->ip_off);
ip->ip_sum = 0;
mb_copy->m_data += sizeof(multicast_encap_iphdr);
ip->ip_sum = in_cksum(mb_copy, ip->ip_hl << 2);
@ -1505,7 +1504,7 @@ encap_send(ip, vifp, m)
if (vifp->v_rate_limit <= 0)
tbf_send_packet(vifp, mb_copy);
else
tbf_control(vifp, mb_copy, ip, ip_copy->ip_len);
tbf_control(vifp, mb_copy, ip, ntohs(ip_copy->ip_len));
}
/*
@ -1695,7 +1694,7 @@ tbf_process_q(vifp)
for (m = vifp->tbf_q;
m != 0;
m = vifp->tbf_q) {
len = mtod(m, struct ip *)->ip_len;
len = ntohs(mtod(m, struct ip *)->ip_len);
/* determine if the packet can be sent */
if (len <= vifp->tbf_n_tok) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_output.c,v 1.99 2002/06/24 08:11:30 itojun Exp $ */
/* $NetBSD: ip_output.c,v 1.100 2002/08/14 00:23:32 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -102,7 +102,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.99 2002/06/24 08:11:30 itojun Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.100 2002/08/14 00:23:32 itojun Exp $");
#include "opt_pfil_hooks.h"
#include "opt_ipsec.h"
@ -216,7 +216,7 @@ ip_output(m0, va_alist)
*/
if ((flags & (IP_FORWARDING|IP_RAWOUTPUT)) == 0) {
ip->ip_v = IPVERSION;
ip->ip_off = 0;
ip->ip_off = htons(0);
ip->ip_id = htons(ip_id++);
ip->ip_hl = hlen >> 2;
ipstat.ips_localout++;
@ -425,7 +425,7 @@ ip_output(m0, va_alist)
goto bad;
}
/* don't allow broadcast messages to be fragmented */
if ((u_int16_t)ip->ip_len > ifp->if_mtu) {
if (ntohs(ip->ip_len) > ifp->if_mtu) {
error = EMSGSIZE;
goto bad;
}
@ -440,16 +440,10 @@ sendit:
*/
if ((flags & IP_MTUDISC) != 0 && ro->ro_rt != NULL &&
(ro->ro_rt->rt_rmx.rmx_locks & RTV_MTU) == 0)
ip->ip_off |= IP_DF;
ip->ip_off |= htons(IP_DF);
/*
* Remember the current ip_len and ip_off, and swap them into
* network order.
*/
ip_len = ip->ip_len;
HTONS(ip->ip_len);
HTONS(ip->ip_off);
/* Remember the current ip_len */
ip_len = ntohs(ip->ip_len);
#ifdef IPSEC
/* get SP for this packet */
@ -657,15 +651,8 @@ skip_ipsec:
/*
* Too large for interface; fragment if possible.
* Must be able to put at least 8 bytes per fragment.
*
* Note we swap ip_len and ip_off into host order to make
* the logic below a little simpler.
*/
NTOHS(ip->ip_len);
NTOHS(ip->ip_off);
if (ip->ip_off & IP_DF) {
if (ntohs(ip->ip_off) & IP_DF) {
if (flags & IP_RETURNMTU)
*mtu_p = mtu;
error = EMSGSIZE;
@ -690,7 +677,7 @@ skip_ipsec:
*/
m0 = m;
mhlen = sizeof (struct ip);
for (off = hlen + len; off < (u_int16_t)ip->ip_len; off += len) {
for (off = hlen + len; off < ntohs(ip->ip_len); off += len) {
MGETHDR(m, M_DONTWAIT, MT_HEADER);
if (m == 0) {
error = ENOBUFS;
@ -712,10 +699,11 @@ skip_ipsec:
mhip->ip_off = ((off - hlen) >> 3) + (ip->ip_off & ~IP_MF);
if (ip->ip_off & IP_MF)
mhip->ip_off |= IP_MF;
if (off + len >= (u_int16_t)ip->ip_len)
len = (u_int16_t)ip->ip_len - off;
if (off + len >= ntohs(ip->ip_len))
len = ntohs(ip->ip_len) - off;
else
mhip->ip_off |= IP_MF;
HTONS(mhip->ip_off);
mhip->ip_len = htons((u_int16_t)(len + mhlen));
m->m_next = m_copy(m0, off, len);
if (m->m_next == 0) {
@ -725,7 +713,6 @@ skip_ipsec:
}
m->m_pkthdr.len = mhlen + len;
m->m_pkthdr.rcvif = (struct ifnet *)0;
HTONS(mhip->ip_off);
mhip->ip_sum = 0;
mhip->ip_sum = in_cksum(m, mhlen);
ipstat.ips_ofragments++;
@ -736,11 +723,10 @@ skip_ipsec:
* and updating header, then send each fragment (in order).
*/
m = m0;
m_adj(m, hlen + firstlen - (u_int16_t)ip->ip_len);
m_adj(m, hlen + firstlen - ntohs(ip->ip_len));
m->m_pkthdr.len = hlen + firstlen;
ip->ip_len = htons((u_int16_t)m->m_pkthdr.len);
ip->ip_off |= IP_MF;
HTONS(ip->ip_off);
ip->ip_off |= htons(IP_MF);
ip->ip_sum = 0;
ip->ip_sum = in_cksum(m, hlen);
sendorfree:
@ -764,7 +750,7 @@ sendorfree:
INADDR_TO_IA(ip->ip_src, ia);
if (ia) {
ia->ia_ifa.ifa_data.ifad_outbytes +=
ntohs(ip->ip_len);
ntohs(ip->ip_len);
}
#endif
#ifdef IPSEC
@ -862,7 +848,7 @@ ip_insertoptions(m, opt, phlen)
unsigned optlen;
optlen = opt->m_len - sizeof(p->ipopt_dst);
if (optlen + (u_int16_t)ip->ip_len > IP_MAXPACKET)
if (optlen + ntohs(ip->ip_len) > IP_MAXPACKET)
return (m); /* XXX should fail */
if (!in_nullhost(p->ipopt_dst))
ip->ip_dst = p->ipopt_dst;
@ -888,7 +874,7 @@ ip_insertoptions(m, opt, phlen)
ip = mtod(m, struct ip *);
bcopy((caddr_t)p->ipopt_list, (caddr_t)(ip + 1), (unsigned)optlen);
*phlen = sizeof(struct ip) + optlen;
ip->ip_len += optlen;
ip->ip_len = htons(ntohs(ip->ip_len) + optlen);
return (m);
}
@ -1655,8 +1641,6 @@ ip_mloopback(ifp, m, dst)
* than the interface's MTU. Can this possibly matter?
*/
ip = mtod(copym, struct ip *);
HTONS(ip->ip_len);
HTONS(ip->ip_off);
if (copym->m_pkthdr.csum_flags & (M_CSUM_TCPv4|M_CSUM_UDPv4)) {
in_delayed_cksum(copym);

View File

@ -1,4 +1,4 @@
/* $NetBSD: raw_ip.c,v 1.61 2002/06/09 16:33:43 itojun Exp $ */
/* $NetBSD: raw_ip.c,v 1.62 2002/08/14 00:23:33 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -65,7 +65,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.61 2002/06/09 16:33:43 itojun Exp $");
__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.62 2002/08/14 00:23:33 itojun Exp $");
#include "opt_ipsec.h"
#include "opt_mrouting.h"
@ -163,9 +163,11 @@ rip_input(m, va_alist)
/*
* XXX Compatibility: programs using raw IP expect ip_len
* XXX to have the header length subtracted.
* XXX to have the header length subtracted, and in host order.
* XXX ip_off is also expected to be host order.
*/
ip->ip_len -= ip->ip_hl << 2;
ip->ip_len = ntohs(ip->ip_len) - (ip->ip_hl << 2);
NTOHS(ip->ip_off);
CIRCLEQ_FOREACH(inp, &rawcbtable.inpt_queue, inp_queue) {
if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != proto)
@ -335,9 +337,9 @@ rip_output(m, va_alist)
M_PREPEND(m, sizeof(struct ip), M_WAIT);
ip = mtod(m, struct ip *);
ip->ip_tos = 0;
ip->ip_off = 0;
ip->ip_off = htons(0);
ip->ip_p = inp->inp_ip.ip_p;
ip->ip_len = m->m_pkthdr.len;
ip->ip_len = htons(m->m_pkthdr.len);
ip->ip_src = inp->inp_laddr;
ip->ip_dst = inp->inp_faddr;
ip->ip_ttl = MAXTTL;
@ -348,10 +350,13 @@ rip_output(m, va_alist)
return (EMSGSIZE);
}
ip = mtod(m, struct ip *);
/* XXX userland passes ip_len and ip_off in host order */
if (m->m_pkthdr.len != ip->ip_len) {
m_freem(m);
return (EINVAL);
}
HTONS(ip->ip_len);
HTONS(ip->ip_off);
if (ip->ip_id == 0)
ip->ip_id = htons(ip_id++);
opts = NULL;
@ -365,7 +370,8 @@ rip_output(m, va_alist)
return ENOBUFS;
}
#endif /*IPSEC*/
return (ip_output(m, opts, &inp->inp_route, flags, inp->inp_moptions, &inp->inp_errormtu));
return (ip_output(m, opts, &inp->inp_route, flags, inp->inp_moptions,
&inp->inp_errormtu));
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcp_input.c,v 1.149 2002/07/18 03:23:01 wrstuden Exp $ */
/* $NetBSD: tcp_input.c,v 1.150 2002/08/14 00:23:33 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -152,7 +152,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.149 2002/07/18 03:23:01 wrstuden Exp $");
__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.150 2002/08/14 00:23:33 itojun Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@ -853,7 +853,7 @@ tcp_input(m, va_alist)
}
#endif
/* We do the checksum after PCB lookup... */
len = ip->ip_len;
len = ntohs(ip->ip_len);
tlen = len - toff;
break;
#endif
@ -3746,7 +3746,7 @@ syn_cache_respond(sc, m)
switch (sc->sc_src.sa.sa_family) {
#ifdef INET
case AF_INET:
ip->ip_len = tlen;
ip->ip_len = htons(tlen);
ip->ip_ttl = ip_defttl;
/* XXX tos? */
break;

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcp_output.c,v 1.83 2002/06/13 16:31:05 thorpej Exp $ */
/* $NetBSD: tcp_output.c,v 1.84 2002/08/14 00:23:34 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -142,7 +142,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.83 2002/06/13 16:31:05 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.84 2002/08/14 00:23:34 itojun Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@ -1073,7 +1073,7 @@ send:
switch (af) {
#ifdef INET
case AF_INET:
ip->ip_len = m->m_pkthdr.len;
ip->ip_len = htons(m->m_pkthdr.len);
if (tp->t_inpcb) {
ip->ip_ttl = tp->t_inpcb->inp_ip.ip_ttl;
ip->ip_tos = tp->t_inpcb->inp_ip.ip_tos;

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcp_subr.c,v 1.132 2002/07/01 20:51:25 itojun Exp $ */
/* $NetBSD: tcp_subr.c,v 1.133 2002/08/14 00:23:35 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -102,7 +102,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.132 2002/07/01 20:51:25 itojun Exp $");
__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.133 2002/08/14 00:23:35 itojun Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@ -761,7 +761,7 @@ tcp_respond(tp, template, m, th0, ack, seq, flags)
th->th_sum = 0;
th->th_sum = in_cksum(m, hlen + tlen);
ip->ip_len = hlen + tlen; /*will be flipped on output*/
ip->ip_len = htons(hlen + tlen);
ip->ip_ttl = ip_defttl;
break;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: udp_usrreq.c,v 1.95 2002/06/30 22:40:37 thorpej Exp $ */
/* $NetBSD: udp_usrreq.c,v 1.96 2002/08/14 00:23:36 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -65,7 +65,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.95 2002/06/30 22:40:37 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.96 2002/08/14 00:23:36 itojun Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@ -216,6 +216,7 @@ udp_input(m, va_alist)
int iphlen, proto;
int len;
int n;
u_int16_t ip_len;
va_start(ap, m);
iphlen = va_arg(ap, int);
@ -272,13 +273,14 @@ udp_input(m, va_alist)
* Make mbuf data length reflect UDP length.
* If not enough data to reflect UDP length, drop.
*/
ip_len = ntohs(ip->ip_len);
len = ntohs((u_int16_t)uh->uh_ulen);
if (ip->ip_len != iphlen + len) {
if (ip->ip_len < iphlen + len || len < sizeof(struct udphdr)) {
if (ip_len != iphlen + len) {
if (ip_len < iphlen + len || len < sizeof(struct udphdr)) {
udpstat.udps_badlen++;
goto bad;
}
m_adj(m, iphlen + len - ip->ip_len);
m_adj(m, iphlen + len - ip_len);
}
/*
@ -892,7 +894,7 @@ udp_output(m, va_alist)
* Compute the packet length of the IP header, and
* punt if the length looks bogus.
*/
if ((len + sizeof(struct udpiphdr)) > IP_MAXPACKET) {
if (len + sizeof(struct udpiphdr) > IP_MAXPACKET) {
error = EMSGSIZE;
goto release;
}
@ -924,7 +926,7 @@ udp_output(m, va_alist)
m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum);
} else
ui->ui_sum = 0;
((struct ip *)ui)->ip_len = sizeof (struct udpiphdr) + len;
((struct ip *)ui)->ip_len = htons(sizeof (struct udpiphdr) + len);
((struct ip *)ui)->ip_ttl = inp->inp_ip.ip_ttl; /* XXX */
((struct ip *)ui)->ip_tos = inp->inp_ip.ip_tos; /* XXX */
udpstat.udps_opackets++;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ah_input.c,v 1.34 2002/06/09 14:43:10 itojun Exp $ */
/* $NetBSD: ah_input.c,v 1.35 2002/08/14 00:23:37 itojun Exp $ */
/* $KAME: ah_input.c,v 1.64 2001/09/04 08:43:19 itojun Exp $ */
/*
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ah_input.c,v 1.34 2002/06/09 14:43:10 itojun Exp $");
__KERNEL_RCSID(0, "$NetBSD: ah_input.c,v 1.35 2002/08/14 00:23:37 itojun Exp $");
#include "opt_inet.h"
@ -82,7 +82,7 @@ __KERNEL_RCSID(0, "$NetBSD: ah_input.c,v 1.34 2002/06/09 14:43:10 itojun Exp $")
#include <net/net_osdep.h>
#define IPLEN_FLIPPED
/*#define IPLEN_FLIPPED*/
#ifdef INET
void
@ -275,7 +275,7 @@ ah4_input(m, va_alist)
*/
{
#if 1
#if 0
/*
* some of IP header fields are flipped to the host endian.
* convert them back to network endian. VERY stupid.
@ -288,7 +288,7 @@ ah4_input(m, va_alist)
goto fail;
}
ipsecstat.in_ahhist[sav->alg_auth]++;
#if 1
#if 0
/*
* flip them back.
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: esp_input.c,v 1.22 2002/06/08 20:06:44 itojun Exp $ */
/* $NetBSD: esp_input.c,v 1.23 2002/08/14 00:23:38 itojun Exp $ */
/* $KAME: esp_input.c,v 1.60 2001/09/04 08:43:19 itojun Exp $ */
/*
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: esp_input.c,v 1.22 2002/06/08 20:06:44 itojun Exp $");
__KERNEL_RCSID(0, "$NetBSD: esp_input.c,v 1.23 2002/08/14 00:23:38 itojun Exp $");
#include "opt_inet.h"
@ -82,7 +82,7 @@ __KERNEL_RCSID(0, "$NetBSD: esp_input.c,v 1.22 2002/06/08 20:06:44 itojun Exp $"
#include <net/net_osdep.h>
#define IPLEN_FLIPPED
/*#define IPLEN_FLIPPED*/
#define ESPMAXLEN \
(sizeof(struct esp) < sizeof(struct newesp) \

View File

@ -1,4 +1,4 @@
/* $NetBSD: ipcomp_input.c,v 1.18 2001/11/13 00:57:03 lukem Exp $ */
/* $NetBSD: ipcomp_input.c,v 1.19 2002/08/14 00:23:38 itojun Exp $ */
/* $KAME: ipcomp_input.c,v 1.29 2001/09/04 08:43:19 itojun Exp $ */
/*
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ipcomp_input.c,v 1.18 2001/11/13 00:57:03 lukem Exp $");
__KERNEL_RCSID(0, "$NetBSD: ipcomp_input.c,v 1.19 2002/08/14 00:23:38 itojun Exp $");
#include "opt_inet.h"
@ -78,7 +78,7 @@ __KERNEL_RCSID(0, "$NetBSD: ipcomp_input.c,v 1.18 2001/11/13 00:57:03 lukem Exp
#include <net/net_osdep.h>
#define IPLEN_FLIPPED
/*#define IPLEN_FLIPPED*/
#ifdef INET
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: ipsec.c,v 1.64 2002/08/01 05:17:47 itojun Exp $ */
/* $NetBSD: ipsec.c,v 1.65 2002/08/14 00:23:39 itojun Exp $ */
/* $KAME: ipsec.c,v 1.136 2002/05/19 00:36:39 itojun Exp $ */
/*
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.64 2002/08/01 05:17:47 itojun Exp $");
__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.65 2002/08/14 00:23:39 itojun Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@ -894,8 +894,7 @@ ipsec4_get_ulp(m, spidx, needport)
((struct sockaddr_in *)&spidx->dst)->sin_port = IPSEC_PORT_ANY;
m_copydata(m, 0, sizeof(ip), (caddr_t)&ip);
/* ip_input() flips it into host endian XXX need more checking */
if (ip.ip_off & (IP_MF | IP_OFFMASK))
if (ip.ip_off & htons(IP_MF | IP_OFFMASK))
return;
nxt = ip.ip_p;
@ -2087,7 +2086,7 @@ ipsec4_encapsulate(m, sav)
ip->ip_len = htons(plen + sizeof(struct ip));
else {
ipseclog((LOG_ERR, "IPv4 ipsec: size exceeds limit: "
"leave ip_len as is (invalid packet)\n"));
"leave ip_len as is (invalid packet)\n"));
}
ip->ip_id = htons(ip_id++);
bcopy(&((struct sockaddr_in *)&sav->sah->saidx.src)->sin_addr,

View File

@ -1,4 +1,4 @@
/* $NetBSD: udp6_output.c,v 1.7 2002/06/08 20:06:45 itojun Exp $ */
/* $NetBSD: udp6_output.c,v 1.8 2002/08/14 00:23:40 itojun Exp $ */
/* $KAME: udp6_output.c,v 1.43 2001/10/15 09:19:52 itojun Exp $ */
/*
@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: udp6_output.c,v 1.7 2002/06/08 20:06:45 itojun Exp $");
__KERNEL_RCSID(0, "$NetBSD: udp6_output.c,v 1.8 2002/08/14 00:23:40 itojun Exp $");
#include "opt_ipsec.h"
#include "opt_inet.h"
@ -382,12 +382,10 @@ udp6_output(in6p, m, addr6, control, p)
if (udp6->uh_sum == 0)
udp6->uh_sum = 0xffff;
ip->ip_len = hlen + plen;
ip->ip_len = htons(hlen + plen);
ip->ip_ttl = in6_selecthlim(in6p, NULL); /* XXX */
ip->ip_tos = 0; /* XXX */
ip->ip_len = hlen + plen; /* XXX */
udpstat.udps_opackets++;
#ifdef IPSEC
(void)ipsec_setsocket(m, NULL); /* XXX */

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_eon.c,v 1.37 2002/07/29 22:54:38 itojun Exp $ */
/* $NetBSD: if_eon.c,v 1.38 2002/08/14 00:23:40 itojun Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -71,7 +71,7 @@ SOFTWARE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_eon.c,v 1.37 2002/07/29 22:54:38 itojun Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_eon.c,v 1.38 2002/08/14 00:23:40 itojun Exp $");
#include "opt_eon.h"
@ -425,15 +425,22 @@ einval:
send:
/* put an eon_hdr in the buffer, prepended by an ip header */
datalen = m->m_pkthdr.len + EONIPLEN;
MGETHDR(mh, M_DONTWAIT, MT_HEADER);
if (mh == (struct mbuf *) 0)
if (datalen > IP_MAXPACKET) {
error = EMSGSIZE;
goto flush;
}
MGETHDR(mh, M_DONTWAIT, MT_HEADER);
if (mh == (struct mbuf *) 0) {
error = ENOBUFS;
goto flush;
}
mh->m_next = m;
m = mh;
MH_ALIGN(m, sizeof(struct eon_iphdr));
m->m_len = sizeof(struct eon_iphdr);
ifp->if_obytes +=
(ei->ei_ip.ip_len = (u_short) (m->m_pkthdr.len = datalen));
m->m_pkthdr.len = datalen;
ei->ei_ip.ip_len = htons(datalen);
ifp->if_obytes += datalen;
*mtod(m, struct eon_iphdr *) = *ei;
#ifdef ARGO_DEBUG

View File

@ -1,4 +1,4 @@
/* $NetBSD: tp_inet.c,v 1.21 2001/11/13 01:10:50 lukem Exp $ */
/* $NetBSD: tp_inet.c,v 1.22 2002/08/14 00:23:41 itojun Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -77,7 +77,7 @@ SOFTWARE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tp_inet.c,v 1.21 2001/11/13 01:10:50 lukem Exp $");
__KERNEL_RCSID(0, "$NetBSD: tp_inet.c,v 1.22 2002/08/14 00:23:41 itojun Exp $");
#include "opt_inet.h"
#include "opt_iso.h"
@ -467,7 +467,12 @@ tpip_output_dg(m0, va_alist)
bzero((caddr_t) ip, sizeof *ip);
ip->ip_p = IPPROTO_TP;
m->m_pkthdr.len = ip->ip_len = sizeof(struct ip) + datalen;
if (sizeof(struct ip) + datalen > IP_MAXPACKET) {
error = EMSGSIZE;
goto bad;
}
m->m_pkthdr.len = sizeof(struct ip) + datalen;
ip->ip_len = htons(sizeof(struct ip) + datalen);
ip->ip_ttl = MAXTTL;
/*
* don't know why you need to set ttl; overlay doesn't even make this

View File

@ -1,4 +1,4 @@
/* $NetBSD: ns_ip.c,v 1.29 2001/11/13 01:08:11 lukem Exp $ */
/* $NetBSD: ns_ip.c,v 1.30 2002/08/14 00:23:42 itojun Exp $ */
/*
* Copyright (c) 1984, 1985, 1986, 1987, 1993
@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ns_ip.c,v 1.29 2001/11/13 01:08:11 lukem Exp $");
__KERNEL_RCSID(0, "$NetBSD: ns_ip.c,v 1.30 2002/08/14 00:23:42 itojun Exp $");
#include "opt_ns.h" /* options NSIP, needed by ns_if.h */
@ -239,8 +239,8 @@ idpip_input(va_alist)
idp = mtod(m, struct idp *);
len = ntohs(idp->idp_len);
if (len & 1) len++; /* Preserve Garbage Byte */
if (ip->ip_len != len) {
if (len > ip->ip_len) {
if (ntohs(ip->ip_len) != len) {
if (len > ntohs(ip->ip_len)) {
nsipif.if_ierrors++;
if (nsip_badlen) m_freem(nsip_badlen);
nsip_badlen = m;
@ -323,13 +323,17 @@ nsipoutput(ifp, m, dst, rt)
ip->ip_p = IPPROTO_IDP;
ip->ip_src = ifn->ifen_src;
ip->ip_dst = ifn->ifen_dst;
ip->ip_len = (u_int16_t)len + sizeof (struct ip);
if (len + sizeof (struct ip) > IP_MAXPACKET) {
m_freem(m);
return (EMSGSIZE);
}
ip->ip_len = htons(len + sizeof (struct ip));
ip->ip_ttl = MAXTTL;
/*
* Output final datagram.
*/
error = (ip_output(m, (struct mbuf *)0, ro, SO_BROADCAST, NULL));
error = ip_output(m, (struct mbuf *)0, ro, SO_BROADCAST, NULL);
if (error) {
ifn->ifen_ifnet.if_oerrors++;
ifn->ifen_ifnet.if_ierrors = error;