xref: /csrg-svn/sys/netinet/ip_input.c (revision 6256)
1*6256Sroot /*	ip_input.c	1.33	82/03/19	*/
24571Swnj 
34495Swnj #include "../h/param.h"
44543Swnj #include "../h/systm.h"
54640Swnj #include "../h/clock.h"
64640Swnj #include "../h/mbuf.h"
74898Swnj #include "../h/protosw.h"
84923Swnj #include "../h/socket.h"
95084Swnj #include "../net/in.h"
105084Swnj #include "../net/in_systm.h"
114951Swnj #include "../net/if.h"
125084Swnj #include "../net/ip.h"			/* belongs before in.h */
134898Swnj #include "../net/ip_var.h"
144801Swnj #include "../net/ip_icmp.h"
154801Swnj #include "../net/tcp.h"
164495Swnj 
174898Swnj u_char	ip_protox[IPPROTO_MAX];
186210Swnj int	ipqmaxlen = IFQ_MAXLEN;
194898Swnj 
204801Swnj /*
215172Swnj  * IP initialization: fill in IP protocol switch table.
225161Swnj  * All protocols not implemented in kernel go to raw IP protocol handler.
234801Swnj  */
244801Swnj ip_init()
254801Swnj {
264898Swnj 	register struct protosw *pr;
274898Swnj 	register int i;
284495Swnj 
294951Swnj COUNT(IP_INIT);
304898Swnj 	pr = pffindproto(PF_INET, IPPROTO_RAW);
314898Swnj 	if (pr == 0)
324898Swnj 		panic("ip_init");
334898Swnj 	for (i = 0; i < IPPROTO_MAX; i++)
344898Swnj 		ip_protox[i] = pr - protosw;
354898Swnj 	for (pr = protosw; pr <= protoswLAST; pr++)
364898Swnj 		if (pr->pr_family == PF_INET &&
374898Swnj 		    pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW)
384898Swnj 			ip_protox[pr->pr_protocol] = pr - protosw;
394801Swnj 	ipq.next = ipq.prev = &ipq;
404801Swnj 	ip_id = time & 0xffff;
416210Swnj 	ipintrq.ifq_maxlen = ipqmaxlen;
424801Swnj }
434801Swnj 
444898Swnj u_char	ipcksum = 1;
454640Swnj struct	ip *ip_reass();
464640Swnj 
474640Swnj /*
484640Swnj  * Ip input routine.  Checksum and byte swap header.  If fragmented
494640Swnj  * try to reassamble.  If complete and fragment queue exists, discard.
504640Swnj  * Process options.  Pass to next level.
514640Swnj  */
525084Swnj ipintr()
534495Swnj {
544923Swnj 	register struct ip *ip;
555084Swnj 	register struct mbuf *m;
565217Swnj 	struct mbuf *m0, *mopt;
574640Swnj 	register int i;
584495Swnj 	register struct ipq *fp;
595084Swnj 	int hlen, s;
604495Swnj 
615084Swnj COUNT(IPINTR);
625084Swnj next:
634640Swnj 	/*
645084Swnj 	 * Get next datagram off input queue and get IP header
655084Swnj 	 * in first mbuf.
664640Swnj 	 */
675084Swnj 	s = splimp();
685084Swnj 	IF_DEQUEUE(&ipintrq, m);
695084Swnj 	splx(s);
705218Swnj 	if (m == 0)
715084Swnj 		return;
725306Sroot 	if ((m->m_off > MMAXOFF || m->m_len < sizeof (struct ip)) &&
735306Sroot 	    (m = m_pullup(m, sizeof (struct ip))) == 0)
745306Sroot 		return;
754640Swnj 	ip = mtod(m, struct ip *);
765161Swnj 	if ((hlen = ip->ip_hl << 2) > m->m_len) {
775306Sroot 		if ((m = m_pullup(m, hlen)) == 0)
785306Sroot 			return;
795161Swnj 		ip = mtod(m, struct ip *);
805161Swnj 	}
814951Swnj 	if (ipcksum)
825217Swnj 		if (ip->ip_sum = in_cksum(m, hlen)) {
835161Swnj 			printf("ip_sum %x\n", ip->ip_sum);	/* XXX */
844951Swnj 			ipstat.ips_badsum++;
854951Swnj 			goto bad;
864495Swnj 		}
874951Swnj 
885217Swnj #if vax
894951Swnj 	/*
904951Swnj 	 * Convert fields to host representation.
914951Swnj 	 */
924907Swnj 	ip->ip_len = ntohs((u_short)ip->ip_len);
934640Swnj 	ip->ip_id = ntohs(ip->ip_id);
944951Swnj 	ip->ip_off = ntohs((u_short)ip->ip_off);
955217Swnj #endif
964495Swnj 
974543Swnj 	/*
984640Swnj 	 * Check that the amount of data in the buffers
994640Swnj 	 * is as at least much as the IP header would have us expect.
1004640Swnj 	 * Trim mbufs if longer than we expect.
1014640Swnj 	 * Drop packet if shorter than we expect.
1024543Swnj 	 */
1034640Swnj 	i = 0;
1045161Swnj 	m0 = m;
1056088Sroot 	for (; m != NULL; m = m->m_next) {
1066088Sroot 		if (m->m_free) panic("ipinput already free");
1074495Swnj 		i += m->m_len;
1086088Sroot 	}
1094640Swnj 	m = m0;
1104640Swnj 	if (i != ip->ip_len) {
1115161Swnj 		if (i < ip->ip_len) {
1125161Swnj 			ipstat.ips_tooshort++;
1134951Swnj 			goto bad;
1145161Swnj 		}
1154640Swnj 		m_adj(m, ip->ip_len - i);
1164495Swnj 	}
1174495Swnj 
1184640Swnj 	/*
1194640Swnj 	 * Process options and, if not destined for us,
1204640Swnj 	 * ship it on.
1214640Swnj 	 */
1224543Swnj 	if (hlen > sizeof (struct ip))
1234907Swnj 		ip_dooptions(ip);
1245084Swnj 	if (ifnet && ip->ip_dst.s_addr != ifnet->if_addr.s_addr &&
1255045Swnj 	    if_ifwithaddr(ip->ip_dst) == 0) {
1266210Swnj 
1276210Swnj 		goto bad;
1286210Swnj #ifdef notdef
1296210Swnj 		printf("ip->ip_dst %x ip->ip_ttl %x\n",
1306210Swnj 		    ip->ip_dst, ip->ip_ttl);
1314640Swnj 		if (--ip->ip_ttl == 0) {
1324907Swnj 			icmp_error(ip, ICMP_TIMXCEED, 0);
1335084Swnj 			goto next;
1344495Swnj 		}
1355217Swnj 		mopt = m_get(M_DONTWAIT);
1365217Swnj 		if (mopt == 0)
1375217Swnj 			goto bad;
1385217Swnj 		ip_stripoptions(ip, mopt);
1396210Swnj 		/* 0 here means no directed broadcast */
1406210Swnj 		(void) ip_output(m0, mopt, 0);
1415084Swnj 		goto next;
1426210Swnj #endif
1434543Swnj 	}
1444495Swnj 
1454640Swnj 	/*
1464640Swnj 	 * Look for queue of fragments
1474640Swnj 	 * of this datagram.
1484640Swnj 	 */
1494640Swnj 	for (fp = ipq.next; fp != &ipq; fp = fp->next)
1504640Swnj 		if (ip->ip_id == fp->ipq_id &&
1514640Swnj 		    ip->ip_src.s_addr == fp->ipq_src.s_addr &&
1524640Swnj 		    ip->ip_dst.s_addr == fp->ipq_dst.s_addr &&
1534640Swnj 		    ip->ip_p == fp->ipq_p)
1544640Swnj 			goto found;
1554640Swnj 	fp = 0;
1564640Swnj found:
1574495Swnj 
1584640Swnj 	/*
1594640Swnj 	 * Adjust ip_len to not reflect header,
1604640Swnj 	 * set ip_mff if more fragments are expected,
1614640Swnj 	 * convert offset of this to bytes.
1624640Swnj 	 */
1634640Swnj 	ip->ip_len -= hlen;
1644898Swnj 	((struct ipasfrag *)ip)->ipf_mff = 0;
1654640Swnj 	if (ip->ip_off & IP_MF)
1664898Swnj 		((struct ipasfrag *)ip)->ipf_mff = 1;
1674640Swnj 	ip->ip_off <<= 3;
1684495Swnj 
1694640Swnj 	/*
1704640Swnj 	 * If datagram marked as having more fragments
1714640Swnj 	 * or if this is not the first fragment,
1724640Swnj 	 * attempt reassembly; if it succeeds, proceed.
1734640Swnj 	 */
1744898Swnj 	if (((struct ipasfrag *)ip)->ipf_mff || ip->ip_off) {
1754898Swnj 		ip = ip_reass((struct ipasfrag *)ip, fp);
1764640Swnj 		if (ip == 0)
1775084Swnj 			goto next;
1784640Swnj 		hlen = ip->ip_hl << 2;
1794640Swnj 		m = dtom(ip);
1804640Swnj 	} else
1814640Swnj 		if (fp)
1824640Swnj 			(void) ip_freef(fp);
1834951Swnj 
1844951Swnj 	/*
1854951Swnj 	 * Switch out to protocol's input routine.
1864951Swnj 	 */
1874898Swnj 	(*protosw[ip_protox[ip->ip_p]].pr_input)(m);
1885084Swnj 	goto next;
1894951Swnj bad:
1904951Swnj 	m_freem(m);
1915084Swnj 	goto next;
1924640Swnj }
1934495Swnj 
1944640Swnj /*
1954640Swnj  * Take incoming datagram fragment and try to
1964951Swnj  * reassemble it into whole datagram.  If a chain for
1974640Swnj  * reassembly of this datagram already exists, then it
1984640Swnj  * is given as fp; otherwise have to make a chain.
1994640Swnj  */
2004640Swnj struct ip *
2014640Swnj ip_reass(ip, fp)
2024898Swnj 	register struct ipasfrag *ip;
2034640Swnj 	register struct ipq *fp;
2044640Swnj {
2054640Swnj 	register struct mbuf *m = dtom(ip);
2064898Swnj 	register struct ipasfrag *q;
2074640Swnj 	struct mbuf *t;
2084640Swnj 	int hlen = ip->ip_hl << 2;
2094640Swnj 	int i, next;
2104951Swnj COUNT(IP_REASS);
2114543Swnj 
2124640Swnj 	/*
2134640Swnj 	 * Presence of header sizes in mbufs
2144640Swnj 	 * would confuse code below.
2154640Swnj 	 */
2164640Swnj 	m->m_off += hlen;
2174640Swnj 	m->m_len -= hlen;
2184495Swnj 
2194640Swnj 	/*
2204640Swnj 	 * If first fragment to arrive, create a reassembly queue.
2214640Swnj 	 */
2224640Swnj 	if (fp == 0) {
2235851Sroot 		if ((t = m_get(M_WAIT)) == NULL)
2244640Swnj 			goto dropfrag;
2254640Swnj 		t->m_off = MMINOFF;
2264640Swnj 		fp = mtod(t, struct ipq *);
2274640Swnj 		insque(fp, &ipq);
2284640Swnj 		fp->ipq_ttl = IPFRAGTTL;
2294640Swnj 		fp->ipq_p = ip->ip_p;
2304640Swnj 		fp->ipq_id = ip->ip_id;
2314898Swnj 		fp->ipq_next = fp->ipq_prev = (struct ipasfrag *)fp;
2324898Swnj 		fp->ipq_src = ((struct ip *)ip)->ip_src;
2334898Swnj 		fp->ipq_dst = ((struct ip *)ip)->ip_dst;
2345161Swnj 		q = (struct ipasfrag *)fp;
2355161Swnj 		goto insert;
2364640Swnj 	}
2374495Swnj 
2384640Swnj 	/*
2394640Swnj 	 * Find a segment which begins after this one does.
2404640Swnj 	 */
2414898Swnj 	for (q = fp->ipq_next; q != (struct ipasfrag *)fp; q = q->ipf_next)
2424640Swnj 		if (q->ip_off > ip->ip_off)
2434640Swnj 			break;
2444495Swnj 
2454640Swnj 	/*
2464640Swnj 	 * If there is a preceding segment, it may provide some of
2474640Swnj 	 * our data already.  If so, drop the data from the incoming
2484640Swnj 	 * segment.  If it provides all of our data, drop us.
2494640Swnj 	 */
2504898Swnj 	if (q->ipf_prev != (struct ipasfrag *)fp) {
2514898Swnj 		i = q->ipf_prev->ip_off + q->ipf_prev->ip_len - ip->ip_off;
2524640Swnj 		if (i > 0) {
2534640Swnj 			if (i >= ip->ip_len)
2544640Swnj 				goto dropfrag;
2554640Swnj 			m_adj(dtom(ip), i);
2564640Swnj 			ip->ip_off += i;
2574640Swnj 			ip->ip_len -= i;
2584640Swnj 		}
2594640Swnj 	}
2604543Swnj 
2614640Swnj 	/*
2624640Swnj 	 * While we overlap succeeding segments trim them or,
2634640Swnj 	 * if they are completely covered, dequeue them.
2644640Swnj 	 */
2654898Swnj 	while (q != (struct ipasfrag *)fp && ip->ip_off + ip->ip_len > q->ip_off) {
2664640Swnj 		i = (ip->ip_off + ip->ip_len) - q->ip_off;
2674640Swnj 		if (i < q->ip_len) {
2684640Swnj 			q->ip_len -= i;
269*6256Sroot 			q->ip_off += i;
2704640Swnj 			m_adj(dtom(q), i);
2714640Swnj 			break;
2724495Swnj 		}
2734898Swnj 		q = q->ipf_next;
2744898Swnj 		m_freem(dtom(q->ipf_prev));
2754898Swnj 		ip_deq(q->ipf_prev);
2764543Swnj 	}
2774495Swnj 
2785161Swnj insert:
2794640Swnj 	/*
2804640Swnj 	 * Stick new segment in its place;
2814640Swnj 	 * check for complete reassembly.
2824640Swnj 	 */
2834898Swnj 	ip_enq(ip, q->ipf_prev);
2844640Swnj 	next = 0;
2854898Swnj 	for (q = fp->ipq_next; q != (struct ipasfrag *)fp; q = q->ipf_next) {
2864640Swnj 		if (q->ip_off != next)
2874640Swnj 			return (0);
2884640Swnj 		next += q->ip_len;
2894640Swnj 	}
2904898Swnj 	if (q->ipf_prev->ipf_mff)
2914640Swnj 		return (0);
2924495Swnj 
2934640Swnj 	/*
2944640Swnj 	 * Reassembly is complete; concatenate fragments.
2954640Swnj 	 */
2964640Swnj 	q = fp->ipq_next;
2974640Swnj 	m = dtom(q);
2984640Swnj 	t = m->m_next;
2994640Swnj 	m->m_next = 0;
3004640Swnj 	m_cat(m, t);
3014898Swnj 	while ((q = q->ipf_next) != (struct ipasfrag *)fp)
3024640Swnj 		m_cat(m, dtom(q));
3034495Swnj 
3044640Swnj 	/*
3054640Swnj 	 * Create header for new ip packet by
3064640Swnj 	 * modifying header of first packet;
3074640Swnj 	 * dequeue and discard fragment reassembly header.
3084640Swnj 	 * Make header visible.
3094640Swnj 	 */
3104640Swnj 	ip = fp->ipq_next;
3114640Swnj 	ip->ip_len = next;
3124898Swnj 	((struct ip *)ip)->ip_src = fp->ipq_src;
3134898Swnj 	((struct ip *)ip)->ip_dst = fp->ipq_dst;
3144640Swnj 	remque(fp);
3154907Swnj 	(void) m_free(dtom(fp));
3164640Swnj 	m = dtom(ip);
3174898Swnj 	m->m_len += sizeof (struct ipasfrag);
3184898Swnj 	m->m_off -= sizeof (struct ipasfrag);
3194898Swnj 	return ((struct ip *)ip);
3204495Swnj 
3214640Swnj dropfrag:
3224640Swnj 	m_freem(m);
3234640Swnj 	return (0);
3244495Swnj }
3254495Swnj 
3264640Swnj /*
3274640Swnj  * Free a fragment reassembly header and all
3284640Swnj  * associated datagrams.
3294640Swnj  */
3304640Swnj struct ipq *
3314640Swnj ip_freef(fp)
3324640Swnj 	struct ipq *fp;
3334495Swnj {
3344898Swnj 	register struct ipasfrag *q;
3354640Swnj 	struct mbuf *m;
3364951Swnj COUNT(IP_FREEF);
3374495Swnj 
3384898Swnj 	for (q = fp->ipq_next; q != (struct ipasfrag *)fp; q = q->ipf_next)
3394640Swnj 		m_freem(dtom(q));
3404640Swnj 	m = dtom(fp);
3414640Swnj 	fp = fp->next;
3424640Swnj 	remque(fp->prev);
3434907Swnj 	(void) m_free(m);
3444640Swnj 	return (fp);
3454495Swnj }
3464495Swnj 
3474640Swnj /*
3484640Swnj  * Put an ip fragment on a reassembly chain.
3494640Swnj  * Like insque, but pointers in middle of structure.
3504640Swnj  */
3514640Swnj ip_enq(p, prev)
3524898Swnj 	register struct ipasfrag *p, *prev;
3534495Swnj {
3544951Swnj 
3554640Swnj COUNT(IP_ENQ);
3564898Swnj 	p->ipf_prev = prev;
3574898Swnj 	p->ipf_next = prev->ipf_next;
3584898Swnj 	prev->ipf_next->ipf_prev = p;
3594898Swnj 	prev->ipf_next = p;
3604495Swnj }
3614495Swnj 
3624640Swnj /*
3634640Swnj  * To ip_enq as remque is to insque.
3644640Swnj  */
3654640Swnj ip_deq(p)
3664898Swnj 	register struct ipasfrag *p;
3674640Swnj {
3684951Swnj 
3694640Swnj COUNT(IP_DEQ);
3704898Swnj 	p->ipf_prev->ipf_next = p->ipf_next;
3714898Swnj 	p->ipf_next->ipf_prev = p->ipf_prev;
3724495Swnj }
3734495Swnj 
3744640Swnj /*
3754640Swnj  * IP timer processing;
3764640Swnj  * if a timer expires on a reassembly
3774640Swnj  * queue, discard it.
3784640Swnj  */
3794801Swnj ip_slowtimo()
3804495Swnj {
3814495Swnj 	register struct ipq *fp;
3824640Swnj 	int s = splnet();
3834951Swnj 
3844801Swnj COUNT(IP_SLOWTIMO);
3855243Sroot 	fp = ipq.next;
3865243Sroot 	if (fp == 0) {
3875243Sroot 		splx(s);
3885243Sroot 		return;
3895243Sroot 	}
3905243Sroot 	while (fp != &ipq)
3914640Swnj 		if (--fp->ipq_ttl == 0)
3924640Swnj 			fp = ip_freef(fp);
3934640Swnj 		else
3944640Swnj 			fp = fp->next;
3954640Swnj 	splx(s);
3964495Swnj }
3974495Swnj 
3984951Swnj /*
3994951Swnj  * Drain off all datagram fragments.
4004951Swnj  */
4014801Swnj ip_drain()
4024801Swnj {
4034801Swnj 
4044951Swnj COUNT(IP_DRAIN);
4054951Swnj 	while (ipq.next != &ipq)
4064951Swnj 		(void) ip_freef(ipq.next);
4074801Swnj }
4084923Swnj 
4094640Swnj /*
4104640Swnj  * Do option processing on a datagram,
4114640Swnj  * possibly discarding it if bad options
4124640Swnj  * are encountered.
4134640Swnj  */
4144640Swnj ip_dooptions(ip)
4154640Swnj 	struct ip *ip;
4164495Swnj {
4174640Swnj 	register u_char *cp;
4184907Swnj 	int opt, optlen, cnt;
4194923Swnj 	struct in_addr *sin;
4204801Swnj 	register struct ip_timestamp *ipt;
4214951Swnj 	register struct ifnet *ifp;
4224951Swnj 	struct in_addr t;
4234495Swnj 
4244951Swnj COUNT(IP_DOOPTIONS);
4254640Swnj 	cp = (u_char *)(ip + 1);
4264640Swnj 	cnt = (ip->ip_hl << 2) - sizeof (struct ip);
4274640Swnj 	for (; cnt > 0; cnt -= optlen, cp += optlen) {
4284640Swnj 		opt = cp[0];
4294640Swnj 		if (opt == IPOPT_EOL)
4304640Swnj 			break;
4314640Swnj 		if (opt == IPOPT_NOP)
4324640Swnj 			optlen = 1;
4334640Swnj 		else
4344640Swnj 			optlen = cp[1];
4354640Swnj 		switch (opt) {
4364495Swnj 
4374640Swnj 		default:
4384640Swnj 			break;
4394495Swnj 
4404951Swnj 		/*
4414951Swnj 		 * Source routing with record.
4424951Swnj 		 * Find interface with current destination address.
4434951Swnj 		 * If none on this machine then drop if strictly routed,
4444951Swnj 		 * or do nothing if loosely routed.
4454951Swnj 		 * Record interface address and bring up next address
4464951Swnj 		 * component.  If strictly routed make sure next
4474951Swnj 		 * address on directly accessible net.
4484951Swnj 		 */
4494640Swnj 		case IPOPT_LSRR:
4504801Swnj 			if (cp[2] < 4 || cp[2] > optlen - (sizeof (long) - 1))
4514640Swnj 				break;
4524923Swnj 			sin = (struct in_addr *)(cp + cp[2]);
4534951Swnj 			ifp = if_ifwithaddr(*sin);
4544951Swnj 			if (ifp == 0) {
4554951Swnj 				if (opt == IPOPT_SSRR)
4564951Swnj 					goto bad;
4574951Swnj 				break;
4584640Swnj 			}
4594951Swnj 			t = ip->ip_dst; ip->ip_dst = *sin; *sin = t;
4604951Swnj 			cp[2] += 4;
4614951Swnj 			if (cp[2] > optlen - (sizeof (long) - 1))
4624951Swnj 				break;
4634951Swnj 			ip->ip_dst = sin[1];
4644951Swnj 			if (opt == IPOPT_SSRR && if_ifonnetof(ip->ip_dst)==0)
4654951Swnj 				goto bad;
4664640Swnj 			break;
4674495Swnj 
4684640Swnj 		case IPOPT_TS:
4694801Swnj 			ipt = (struct ip_timestamp *)cp;
4704801Swnj 			if (ipt->ipt_len < 5)
4714640Swnj 				goto bad;
4724801Swnj 			if (ipt->ipt_ptr > ipt->ipt_len - sizeof (long)) {
4734801Swnj 				if (++ipt->ipt_oflw == 0)
4744640Swnj 					goto bad;
4754495Swnj 				break;
4764640Swnj 			}
4774923Swnj 			sin = (struct in_addr *)(cp+cp[2]);
4784801Swnj 			switch (ipt->ipt_flg) {
4794495Swnj 
4804640Swnj 			case IPOPT_TS_TSONLY:
4814640Swnj 				break;
4824640Swnj 
4834640Swnj 			case IPOPT_TS_TSANDADDR:
4844801Swnj 				if (ipt->ipt_ptr + 8 > ipt->ipt_len)
4854640Swnj 					goto bad;
4864951Swnj 				/* stamp with ``first'' interface address */
4874951Swnj 				*sin++ = ifnet->if_addr;
4884640Swnj 				break;
4894640Swnj 
4904640Swnj 			case IPOPT_TS_PRESPEC:
4914951Swnj 				if (if_ifwithaddr(*sin) == 0)
4924951Swnj 					continue;
4934801Swnj 				if (ipt->ipt_ptr + 8 > ipt->ipt_len)
4944640Swnj 					goto bad;
4954801Swnj 				ipt->ipt_ptr += 4;
4964640Swnj 				break;
4974640Swnj 
4984495Swnj 			default:
4994640Swnj 				goto bad;
5004495Swnj 			}
5014923Swnj 			*(n_time *)sin = iptime();
5024801Swnj 			ipt->ipt_ptr += 4;
5034640Swnj 		}
5044495Swnj 	}
5054907Swnj 	return;
5064640Swnj bad:
5074640Swnj 	/* SHOULD FORCE ICMP MESSAGE */
5084907Swnj 	return;
5094495Swnj }
5104495Swnj 
5114640Swnj /*
5124951Swnj  * Strip out IP options, at higher
5134951Swnj  * level protocol in the kernel.
5144951Swnj  * Second argument is buffer to which options
5154951Swnj  * will be moved, and return value is their length.
5164640Swnj  */
5175217Swnj ip_stripoptions(ip, mopt)
5184640Swnj 	struct ip *ip;
5195217Swnj 	struct mbuf *mopt;
5204495Swnj {
5214640Swnj 	register int i;
5224640Swnj 	register struct mbuf *m;
5234640Swnj 	int olen;
5244951Swnj COUNT(IP_STRIPOPTIONS);
5254640Swnj 
5264640Swnj 	olen = (ip->ip_hl<<2) - sizeof (struct ip);
5274951Swnj 	m = dtom(ip);
5284951Swnj 	ip++;
5295217Swnj 	if (mopt) {
5305217Swnj 		mopt->m_len = olen;
5315217Swnj 		mopt->m_off = MMINOFF;
5325217Swnj 		bcopy((caddr_t)ip, mtod(m, caddr_t), (unsigned)olen);
5335217Swnj 	}
5344640Swnj 	i = m->m_len - (sizeof (struct ip) + olen);
5354907Swnj 	bcopy((caddr_t)ip+olen, (caddr_t)ip, (unsigned)i);
5365243Sroot 	m->m_len -= olen;
5374495Swnj }
538