1*6338Ssam /* ip_input.c 1.35 82/03/28 */ 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" 16*6338Ssam #include "../net/route.h" 174495Swnj 18*6338Ssam #define IPTTLDEC 5 /* doesn't belong here */ 19*6338Ssam 204898Swnj u_char ip_protox[IPPROTO_MAX]; 216210Swnj int ipqmaxlen = IFQ_MAXLEN; 22*6338Ssam struct ifnet *ifinet; /* first inet interface */ 234898Swnj 244801Swnj /* 255172Swnj * IP initialization: fill in IP protocol switch table. 265161Swnj * All protocols not implemented in kernel go to raw IP protocol handler. 274801Swnj */ 284801Swnj ip_init() 294801Swnj { 304898Swnj register struct protosw *pr; 314898Swnj register int i; 324495Swnj 334951Swnj COUNT(IP_INIT); 344898Swnj pr = pffindproto(PF_INET, IPPROTO_RAW); 354898Swnj if (pr == 0) 364898Swnj panic("ip_init"); 374898Swnj for (i = 0; i < IPPROTO_MAX; i++) 384898Swnj ip_protox[i] = pr - protosw; 394898Swnj for (pr = protosw; pr <= protoswLAST; pr++) 404898Swnj if (pr->pr_family == PF_INET && 414898Swnj pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) 424898Swnj ip_protox[pr->pr_protocol] = pr - protosw; 434801Swnj ipq.next = ipq.prev = &ipq; 444801Swnj ip_id = time & 0xffff; 456210Swnj ipintrq.ifq_maxlen = ipqmaxlen; 46*6338Ssam ifinet = if_ifwithaf(AF_INET); 474801Swnj } 484801Swnj 494898Swnj u_char ipcksum = 1; 504640Swnj struct ip *ip_reass(); 51*6338Ssam int ipforwarding = 0; 52*6338Ssam struct sockaddr_in ipaddr = { AF_INET }; 534640Swnj 544640Swnj /* 554640Swnj * Ip input routine. Checksum and byte swap header. If fragmented 564640Swnj * try to reassamble. If complete and fragment queue exists, discard. 574640Swnj * Process options. Pass to next level. 584640Swnj */ 595084Swnj ipintr() 604495Swnj { 614923Swnj register struct ip *ip; 625084Swnj register struct mbuf *m; 635217Swnj struct mbuf *m0, *mopt; 644640Swnj register int i; 654495Swnj register struct ipq *fp; 665084Swnj int hlen, s; 674495Swnj 685084Swnj COUNT(IPINTR); 695084Swnj next: 704640Swnj /* 715084Swnj * Get next datagram off input queue and get IP header 725084Swnj * in first mbuf. 734640Swnj */ 745084Swnj s = splimp(); 755084Swnj IF_DEQUEUE(&ipintrq, m); 765084Swnj splx(s); 775218Swnj if (m == 0) 785084Swnj return; 795306Sroot if ((m->m_off > MMAXOFF || m->m_len < sizeof (struct ip)) && 805306Sroot (m = m_pullup(m, sizeof (struct ip))) == 0) 815306Sroot return; 824640Swnj ip = mtod(m, struct ip *); 835161Swnj if ((hlen = ip->ip_hl << 2) > m->m_len) { 845306Sroot if ((m = m_pullup(m, hlen)) == 0) 855306Sroot return; 865161Swnj ip = mtod(m, struct ip *); 875161Swnj } 884951Swnj if (ipcksum) 895217Swnj if (ip->ip_sum = in_cksum(m, hlen)) { 905161Swnj printf("ip_sum %x\n", ip->ip_sum); /* XXX */ 914951Swnj ipstat.ips_badsum++; 924951Swnj goto bad; 934495Swnj } 944951Swnj 955217Swnj #if vax 964951Swnj /* 974951Swnj * Convert fields to host representation. 984951Swnj */ 994907Swnj ip->ip_len = ntohs((u_short)ip->ip_len); 1004640Swnj ip->ip_id = ntohs(ip->ip_id); 1014951Swnj ip->ip_off = ntohs((u_short)ip->ip_off); 1025217Swnj #endif 1034495Swnj 1044543Swnj /* 1054640Swnj * Check that the amount of data in the buffers 1064640Swnj * is as at least much as the IP header would have us expect. 1074640Swnj * Trim mbufs if longer than we expect. 1084640Swnj * Drop packet if shorter than we expect. 1094543Swnj */ 1104640Swnj i = 0; 1115161Swnj m0 = m; 1126088Sroot for (; m != NULL; m = m->m_next) { 1136088Sroot if (m->m_free) panic("ipinput already free"); 1144495Swnj i += m->m_len; 1156088Sroot } 1164640Swnj m = m0; 1174640Swnj if (i != ip->ip_len) { 1185161Swnj if (i < ip->ip_len) { 1195161Swnj ipstat.ips_tooshort++; 1204951Swnj goto bad; 1215161Swnj } 1224640Swnj m_adj(m, ip->ip_len - i); 1234495Swnj } 1244495Swnj 1254640Swnj /* 1264640Swnj * Process options and, if not destined for us, 1274640Swnj * ship it on. 1284640Swnj */ 1294543Swnj if (hlen > sizeof (struct ip)) 1304907Swnj ip_dooptions(ip); 1316210Swnj 132*6338Ssam /* 133*6338Ssam * Fast check on the first interface in the list. 134*6338Ssam */ 135*6338Ssam if (ifinet) { 136*6338Ssam struct sockaddr_in *sin; 137*6338Ssam 138*6338Ssam sin = (struct sockaddr_in *)&ifinet->if_addr; 139*6338Ssam if (sin->sin_addr.s_addr == ip->ip_dst.s_addr) 140*6338Ssam goto ours; 141*6338Ssam } 142*6338Ssam ipaddr.sin_addr = ip->ip_dst; 143*6338Ssam if (if_ifwithaddr((struct sockaddr *)&ipaddr) == 0) { 144*6338Ssam register struct rtentry *rt; 145*6338Ssam 146*6338Ssam printf("forward: dst %x ttl %x\n", ip->ip_dst, ip->ip_ttl); 147*6338Ssam if (ipforwarding == 0) 148*6338Ssam goto bad; 149*6338Ssam if (ip->ip_ttl < IPTTLDEC) { 1504907Swnj icmp_error(ip, ICMP_TIMXCEED, 0); 1515084Swnj goto next; 1524495Swnj } 153*6338Ssam ip->ip_ttl -= IPTTLDEC; 1545217Swnj mopt = m_get(M_DONTWAIT); 1555217Swnj if (mopt == 0) 1565217Swnj goto bad; 1575217Swnj ip_stripoptions(ip, mopt); 158*6338Ssam 159*6338Ssam /* 160*6338Ssam * Check the routing table in case we should 161*6338Ssam * munge the src address before it gets passed on. 162*6338Ssam */ 163*6338Ssam ipaddr.sin_addr = ip->ip_src; 164*6338Ssam rt = reroute(&ipaddr); 165*6338Ssam if (rt && (rt->rt_flags & RTF_MUNGE)) { 166*6338Ssam struct sockaddr_in *sin; 167*6338Ssam 168*6338Ssam sin = (struct sockaddr_in *)&rt->rt_dst; 169*6338Ssam ip->ip_src = sin->sin_addr; 170*6338Ssam } 1716210Swnj /* 0 here means no directed broadcast */ 172*6338Ssam (void) ip_output(m0, mopt, 0, 0); 1735084Swnj goto next; 1744543Swnj } 1754495Swnj 176*6338Ssam ours: 1774640Swnj /* 1784640Swnj * Look for queue of fragments 1794640Swnj * of this datagram. 1804640Swnj */ 1814640Swnj for (fp = ipq.next; fp != &ipq; fp = fp->next) 1824640Swnj if (ip->ip_id == fp->ipq_id && 1834640Swnj ip->ip_src.s_addr == fp->ipq_src.s_addr && 1844640Swnj ip->ip_dst.s_addr == fp->ipq_dst.s_addr && 1854640Swnj ip->ip_p == fp->ipq_p) 1864640Swnj goto found; 1874640Swnj fp = 0; 1884640Swnj found: 1894495Swnj 1904640Swnj /* 1914640Swnj * Adjust ip_len to not reflect header, 1924640Swnj * set ip_mff if more fragments are expected, 1934640Swnj * convert offset of this to bytes. 1944640Swnj */ 1954640Swnj ip->ip_len -= hlen; 1964898Swnj ((struct ipasfrag *)ip)->ipf_mff = 0; 1974640Swnj if (ip->ip_off & IP_MF) 1984898Swnj ((struct ipasfrag *)ip)->ipf_mff = 1; 1994640Swnj ip->ip_off <<= 3; 2004495Swnj 2014640Swnj /* 2024640Swnj * If datagram marked as having more fragments 2034640Swnj * or if this is not the first fragment, 2044640Swnj * attempt reassembly; if it succeeds, proceed. 2054640Swnj */ 2064898Swnj if (((struct ipasfrag *)ip)->ipf_mff || ip->ip_off) { 2074898Swnj ip = ip_reass((struct ipasfrag *)ip, fp); 2084640Swnj if (ip == 0) 2095084Swnj goto next; 2104640Swnj hlen = ip->ip_hl << 2; 2114640Swnj m = dtom(ip); 2124640Swnj } else 2134640Swnj if (fp) 2144640Swnj (void) ip_freef(fp); 2154951Swnj 2164951Swnj /* 2174951Swnj * Switch out to protocol's input routine. 2184951Swnj */ 2194898Swnj (*protosw[ip_protox[ip->ip_p]].pr_input)(m); 2205084Swnj goto next; 2214951Swnj bad: 2224951Swnj m_freem(m); 2235084Swnj goto next; 2244640Swnj } 2254495Swnj 2264640Swnj /* 2274640Swnj * Take incoming datagram fragment and try to 2284951Swnj * reassemble it into whole datagram. If a chain for 2294640Swnj * reassembly of this datagram already exists, then it 2304640Swnj * is given as fp; otherwise have to make a chain. 2314640Swnj */ 2324640Swnj struct ip * 2334640Swnj ip_reass(ip, fp) 2344898Swnj register struct ipasfrag *ip; 2354640Swnj register struct ipq *fp; 2364640Swnj { 2374640Swnj register struct mbuf *m = dtom(ip); 2384898Swnj register struct ipasfrag *q; 2394640Swnj struct mbuf *t; 2404640Swnj int hlen = ip->ip_hl << 2; 2414640Swnj int i, next; 2424951Swnj COUNT(IP_REASS); 2434543Swnj 2444640Swnj /* 2454640Swnj * Presence of header sizes in mbufs 2464640Swnj * would confuse code below. 2474640Swnj */ 2484640Swnj m->m_off += hlen; 2494640Swnj m->m_len -= hlen; 2504495Swnj 2514640Swnj /* 2524640Swnj * If first fragment to arrive, create a reassembly queue. 2534640Swnj */ 2544640Swnj if (fp == 0) { 2555851Sroot if ((t = m_get(M_WAIT)) == NULL) 2564640Swnj goto dropfrag; 2574640Swnj t->m_off = MMINOFF; 2584640Swnj fp = mtod(t, struct ipq *); 2594640Swnj insque(fp, &ipq); 2604640Swnj fp->ipq_ttl = IPFRAGTTL; 2614640Swnj fp->ipq_p = ip->ip_p; 2624640Swnj fp->ipq_id = ip->ip_id; 2634898Swnj fp->ipq_next = fp->ipq_prev = (struct ipasfrag *)fp; 2644898Swnj fp->ipq_src = ((struct ip *)ip)->ip_src; 2654898Swnj fp->ipq_dst = ((struct ip *)ip)->ip_dst; 2665161Swnj q = (struct ipasfrag *)fp; 2675161Swnj goto insert; 2684640Swnj } 2694495Swnj 2704640Swnj /* 2714640Swnj * Find a segment which begins after this one does. 2724640Swnj */ 2734898Swnj for (q = fp->ipq_next; q != (struct ipasfrag *)fp; q = q->ipf_next) 2744640Swnj if (q->ip_off > ip->ip_off) 2754640Swnj break; 2764495Swnj 2774640Swnj /* 2784640Swnj * If there is a preceding segment, it may provide some of 2794640Swnj * our data already. If so, drop the data from the incoming 2804640Swnj * segment. If it provides all of our data, drop us. 2814640Swnj */ 2824898Swnj if (q->ipf_prev != (struct ipasfrag *)fp) { 2834898Swnj i = q->ipf_prev->ip_off + q->ipf_prev->ip_len - ip->ip_off; 2844640Swnj if (i > 0) { 2854640Swnj if (i >= ip->ip_len) 2864640Swnj goto dropfrag; 2874640Swnj m_adj(dtom(ip), i); 2884640Swnj ip->ip_off += i; 2894640Swnj ip->ip_len -= i; 2904640Swnj } 2914640Swnj } 2924543Swnj 2934640Swnj /* 2944640Swnj * While we overlap succeeding segments trim them or, 2954640Swnj * if they are completely covered, dequeue them. 2964640Swnj */ 2974898Swnj while (q != (struct ipasfrag *)fp && ip->ip_off + ip->ip_len > q->ip_off) { 2984640Swnj i = (ip->ip_off + ip->ip_len) - q->ip_off; 2994640Swnj if (i < q->ip_len) { 3004640Swnj q->ip_len -= i; 3016256Sroot q->ip_off += i; 3024640Swnj m_adj(dtom(q), i); 3034640Swnj break; 3044495Swnj } 3054898Swnj q = q->ipf_next; 3064898Swnj m_freem(dtom(q->ipf_prev)); 3074898Swnj ip_deq(q->ipf_prev); 3084543Swnj } 3094495Swnj 3105161Swnj insert: 3114640Swnj /* 3124640Swnj * Stick new segment in its place; 3134640Swnj * check for complete reassembly. 3144640Swnj */ 3154898Swnj ip_enq(ip, q->ipf_prev); 3164640Swnj next = 0; 3174898Swnj for (q = fp->ipq_next; q != (struct ipasfrag *)fp; q = q->ipf_next) { 3184640Swnj if (q->ip_off != next) 3194640Swnj return (0); 3204640Swnj next += q->ip_len; 3214640Swnj } 3224898Swnj if (q->ipf_prev->ipf_mff) 3234640Swnj return (0); 3244495Swnj 3254640Swnj /* 3264640Swnj * Reassembly is complete; concatenate fragments. 3274640Swnj */ 3284640Swnj q = fp->ipq_next; 3294640Swnj m = dtom(q); 3304640Swnj t = m->m_next; 3314640Swnj m->m_next = 0; 3324640Swnj m_cat(m, t); 3336298Swnj q = q->ipf_next; 3346298Swnj while (q != (struct ipasfrag *)fp) { 3356298Swnj t = dtom(q); 3366298Swnj q = q->ipf_next; 3376298Swnj m_cat(m, t); 3386298Swnj } 3394495Swnj 3404640Swnj /* 3414640Swnj * Create header for new ip packet by 3424640Swnj * modifying header of first packet; 3434640Swnj * dequeue and discard fragment reassembly header. 3444640Swnj * Make header visible. 3454640Swnj */ 3464640Swnj ip = fp->ipq_next; 3474640Swnj ip->ip_len = next; 3484898Swnj ((struct ip *)ip)->ip_src = fp->ipq_src; 3494898Swnj ((struct ip *)ip)->ip_dst = fp->ipq_dst; 3504640Swnj remque(fp); 3514907Swnj (void) m_free(dtom(fp)); 3524640Swnj m = dtom(ip); 3534898Swnj m->m_len += sizeof (struct ipasfrag); 3544898Swnj m->m_off -= sizeof (struct ipasfrag); 3554898Swnj return ((struct ip *)ip); 3564495Swnj 3574640Swnj dropfrag: 3584640Swnj m_freem(m); 3594640Swnj return (0); 3604495Swnj } 3614495Swnj 3624640Swnj /* 3634640Swnj * Free a fragment reassembly header and all 3644640Swnj * associated datagrams. 3654640Swnj */ 3664640Swnj struct ipq * 3674640Swnj ip_freef(fp) 3684640Swnj struct ipq *fp; 3694495Swnj { 3704898Swnj register struct ipasfrag *q; 3714640Swnj struct mbuf *m; 3724951Swnj COUNT(IP_FREEF); 3734495Swnj 3744898Swnj for (q = fp->ipq_next; q != (struct ipasfrag *)fp; q = q->ipf_next) 3754640Swnj m_freem(dtom(q)); 3764640Swnj m = dtom(fp); 3774640Swnj fp = fp->next; 3784640Swnj remque(fp->prev); 3794907Swnj (void) m_free(m); 3804640Swnj return (fp); 3814495Swnj } 3824495Swnj 3834640Swnj /* 3844640Swnj * Put an ip fragment on a reassembly chain. 3854640Swnj * Like insque, but pointers in middle of structure. 3864640Swnj */ 3874640Swnj ip_enq(p, prev) 3884898Swnj register struct ipasfrag *p, *prev; 3894495Swnj { 3904951Swnj 3914640Swnj COUNT(IP_ENQ); 3924898Swnj p->ipf_prev = prev; 3934898Swnj p->ipf_next = prev->ipf_next; 3944898Swnj prev->ipf_next->ipf_prev = p; 3954898Swnj prev->ipf_next = p; 3964495Swnj } 3974495Swnj 3984640Swnj /* 3994640Swnj * To ip_enq as remque is to insque. 4004640Swnj */ 4014640Swnj ip_deq(p) 4024898Swnj register struct ipasfrag *p; 4034640Swnj { 4044951Swnj 4054640Swnj COUNT(IP_DEQ); 4064898Swnj p->ipf_prev->ipf_next = p->ipf_next; 4074898Swnj p->ipf_next->ipf_prev = p->ipf_prev; 4084495Swnj } 4094495Swnj 4104640Swnj /* 4114640Swnj * IP timer processing; 4124640Swnj * if a timer expires on a reassembly 4134640Swnj * queue, discard it. 4144640Swnj */ 4154801Swnj ip_slowtimo() 4164495Swnj { 4174495Swnj register struct ipq *fp; 4184640Swnj int s = splnet(); 4194951Swnj 4204801Swnj COUNT(IP_SLOWTIMO); 4215243Sroot fp = ipq.next; 4225243Sroot if (fp == 0) { 4235243Sroot splx(s); 4245243Sroot return; 4255243Sroot } 4265243Sroot while (fp != &ipq) 4274640Swnj if (--fp->ipq_ttl == 0) 4284640Swnj fp = ip_freef(fp); 4294640Swnj else 4304640Swnj fp = fp->next; 4314640Swnj splx(s); 4324495Swnj } 4334495Swnj 4344951Swnj /* 4354951Swnj * Drain off all datagram fragments. 4364951Swnj */ 4374801Swnj ip_drain() 4384801Swnj { 4394801Swnj 4404951Swnj COUNT(IP_DRAIN); 4414951Swnj while (ipq.next != &ipq) 4424951Swnj (void) ip_freef(ipq.next); 4434801Swnj } 4444923Swnj 4454640Swnj /* 4464640Swnj * Do option processing on a datagram, 4474640Swnj * possibly discarding it if bad options 4484640Swnj * are encountered. 4494640Swnj */ 4504640Swnj ip_dooptions(ip) 4514640Swnj struct ip *ip; 4524495Swnj { 4534640Swnj register u_char *cp; 4544907Swnj int opt, optlen, cnt; 4554923Swnj struct in_addr *sin; 4564801Swnj register struct ip_timestamp *ipt; 4574951Swnj register struct ifnet *ifp; 4584951Swnj struct in_addr t; 4594495Swnj 4604951Swnj COUNT(IP_DOOPTIONS); 4614640Swnj cp = (u_char *)(ip + 1); 4624640Swnj cnt = (ip->ip_hl << 2) - sizeof (struct ip); 4634640Swnj for (; cnt > 0; cnt -= optlen, cp += optlen) { 4644640Swnj opt = cp[0]; 4654640Swnj if (opt == IPOPT_EOL) 4664640Swnj break; 4674640Swnj if (opt == IPOPT_NOP) 4684640Swnj optlen = 1; 4694640Swnj else 4704640Swnj optlen = cp[1]; 4714640Swnj switch (opt) { 4724495Swnj 4734640Swnj default: 4744640Swnj break; 4754495Swnj 4764951Swnj /* 4774951Swnj * Source routing with record. 4784951Swnj * Find interface with current destination address. 4794951Swnj * If none on this machine then drop if strictly routed, 4804951Swnj * or do nothing if loosely routed. 4814951Swnj * Record interface address and bring up next address 4824951Swnj * component. If strictly routed make sure next 4834951Swnj * address on directly accessible net. 4844951Swnj */ 4854640Swnj case IPOPT_LSRR: 4864801Swnj if (cp[2] < 4 || cp[2] > optlen - (sizeof (long) - 1)) 4874640Swnj break; 4884923Swnj sin = (struct in_addr *)(cp + cp[2]); 489*6338Ssam ipaddr.sin_addr = *sin; 490*6338Ssam ifp = if_ifwithaddr((struct sockaddr *)&ipaddr); 4914951Swnj if (ifp == 0) { 4924951Swnj if (opt == IPOPT_SSRR) 4934951Swnj goto bad; 4944951Swnj break; 4954640Swnj } 4964951Swnj t = ip->ip_dst; ip->ip_dst = *sin; *sin = t; 4974951Swnj cp[2] += 4; 4984951Swnj if (cp[2] > optlen - (sizeof (long) - 1)) 4994951Swnj break; 5004951Swnj ip->ip_dst = sin[1]; 501*6338Ssam if (opt == IPOPT_SSRR && 502*6338Ssam if_ifonnetof(ip->ip_dst.s_net) == 0) 5034951Swnj goto bad; 5044640Swnj break; 5054495Swnj 5064640Swnj case IPOPT_TS: 5074801Swnj ipt = (struct ip_timestamp *)cp; 5084801Swnj if (ipt->ipt_len < 5) 5094640Swnj goto bad; 5104801Swnj if (ipt->ipt_ptr > ipt->ipt_len - sizeof (long)) { 5114801Swnj if (++ipt->ipt_oflw == 0) 5124640Swnj goto bad; 5134495Swnj break; 5144640Swnj } 5154923Swnj sin = (struct in_addr *)(cp+cp[2]); 5164801Swnj switch (ipt->ipt_flg) { 5174495Swnj 5184640Swnj case IPOPT_TS_TSONLY: 5194640Swnj break; 5204640Swnj 5214640Swnj case IPOPT_TS_TSANDADDR: 5224801Swnj if (ipt->ipt_ptr + 8 > ipt->ipt_len) 5234640Swnj goto bad; 524*6338Ssam if (ifinet == 0) 525*6338Ssam goto bad; /* ??? */ 526*6338Ssam *sin++ = ((struct sockaddr_in *)&ifinet->if_addr)->sin_addr; 5274640Swnj break; 5284640Swnj 5294640Swnj case IPOPT_TS_PRESPEC: 530*6338Ssam ipaddr.sin_addr = *sin; 531*6338Ssam if (if_ifwithaddr((struct sockaddr *)&ipaddr) == 0) 5324951Swnj continue; 5334801Swnj if (ipt->ipt_ptr + 8 > ipt->ipt_len) 5344640Swnj goto bad; 5354801Swnj ipt->ipt_ptr += 4; 5364640Swnj break; 5374640Swnj 5384495Swnj default: 5394640Swnj goto bad; 5404495Swnj } 5414923Swnj *(n_time *)sin = iptime(); 5424801Swnj ipt->ipt_ptr += 4; 5434640Swnj } 5444495Swnj } 5454907Swnj return; 5464640Swnj bad: 5474640Swnj /* SHOULD FORCE ICMP MESSAGE */ 5484907Swnj return; 5494495Swnj } 5504495Swnj 5514640Swnj /* 5524951Swnj * Strip out IP options, at higher 5534951Swnj * level protocol in the kernel. 5544951Swnj * Second argument is buffer to which options 5554951Swnj * will be moved, and return value is their length. 5564640Swnj */ 5575217Swnj ip_stripoptions(ip, mopt) 5584640Swnj struct ip *ip; 5595217Swnj struct mbuf *mopt; 5604495Swnj { 5614640Swnj register int i; 5624640Swnj register struct mbuf *m; 5634640Swnj int olen; 5644951Swnj COUNT(IP_STRIPOPTIONS); 5654640Swnj 5664640Swnj olen = (ip->ip_hl<<2) - sizeof (struct ip); 5674951Swnj m = dtom(ip); 5684951Swnj ip++; 5695217Swnj if (mopt) { 5705217Swnj mopt->m_len = olen; 5715217Swnj mopt->m_off = MMINOFF; 5725217Swnj bcopy((caddr_t)ip, mtod(m, caddr_t), (unsigned)olen); 5735217Swnj } 5744640Swnj i = m->m_len - (sizeof (struct ip) + olen); 5754907Swnj bcopy((caddr_t)ip+olen, (caddr_t)ip, (unsigned)i); 5765243Sroot m->m_len -= olen; 5774495Swnj } 578