Deleted Added
sdiff udiff text old ( 105218 ) new ( 105586 )
full compact
1/*
2 * Copyright (c) 1982, 1986, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)ip_input.c 8.2 (Berkeley) 1/4/94
34 * $FreeBSD: head/sys/netinet/ip_input.c 105586 2002-10-20 22:52:07Z phk $
35 */
36
37#include "opt_bootp.h"
38#include "opt_ipfw.h"
39#include "opt_ipdn.h"
40#include "opt_ipdivert.h"
41#include "opt_ipfilter.h"
42#include "opt_ipstealth.h"
43#include "opt_ipsec.h"
44#include "opt_mac.h"

--- 283 unchanged lines hidden (view full) ---

328 }
329 }
330
331 KASSERT(m != NULL && (m->m_flags & M_PKTHDR) != 0,
332 ("ip_input: no HDR"));
333
334 if (args.rule) { /* dummynet already filtered us */
335 ip = mtod(m, struct ip *);
336 hlen = ip->ip_hl << 2;
337 goto iphack ;
338 }
339
340 ipstat.ips_total++;
341
342 if (m->m_pkthdr.len < sizeof(struct ip))
343 goto tooshort;
344
345 if (m->m_len < sizeof (struct ip) &&
346 (m = m_pullup(m, sizeof (struct ip))) == 0) {
347 ipstat.ips_toosmall++;
348 return;
349 }
350 ip = mtod(m, struct ip *);
351
352 if (ip->ip_v != IPVERSION) {
353 ipstat.ips_badvers++;
354 goto bad;
355 }
356
357 hlen = ip->ip_hl << 2;
358 if (hlen < sizeof(struct ip)) { /* minimum header length */
359 ipstat.ips_badhlen++;
360 goto bad;
361 }
362 if (hlen > m->m_len) {
363 if ((m = m_pullup(m, hlen)) == 0) {
364 ipstat.ips_badhlen++;
365 return;

--- 416 unchanged lines hidden (view full) ---

782 m->m_pkthdr.header = ip;
783 m = ip_reass(m,
784 &ipq[sum], fp, &divert_info, &args.divert_rule);
785 if (m == 0)
786 return;
787 ipstat.ips_reassembled++;
788 ip = mtod(m, struct ip *);
789 /* Get the header length of the reassembled packet */
790 hlen = ip->ip_hl << 2;
791#ifdef IPDIVERT
792 /* Restore original checksum before diverting packet */
793 if (divert_info != 0) {
794 ip->ip_len += hlen;
795 ip->ip_len = htons(ip->ip_len);
796 ip->ip_off = htons(ip->ip_off);
797 ip->ip_sum = 0;
798 if (hlen == sizeof(struct ip))

--- 149 unchanged lines hidden (view full) ---

948
949static struct mbuf *
950ip_reass(struct mbuf *m, struct ipqhead *head, struct ipq *fp,
951 u_int32_t *divinfo, u_int16_t *divert_rule)
952{
953 struct ip *ip = mtod(m, struct ip *);
954 register struct mbuf *p, *q, *nq;
955 struct mbuf *t;
956 int hlen = ip->ip_hl << 2;
957 int i, next;
958
959 /*
960 * Presence of header sizes in mbufs
961 * would confuse code below.
962 */
963 m->m_data += hlen;
964 m->m_len -= hlen;

--- 121 unchanged lines hidden (view full) ---

1086 if (p->m_flags & M_FRAG)
1087 return (0);
1088
1089 /*
1090 * Reassembly is complete. Make sure the packet is a sane size.
1091 */
1092 q = fp->ipq_frags;
1093 ip = GETIP(q);
1094 if (next + (ip->ip_hl << 2) > IP_MAXPACKET) {
1095 ipstat.ips_toolong++;
1096 ip_freef(head, fp);
1097 return (0);
1098 }
1099
1100 /*
1101 * Concatenate fragments.
1102 */

--- 31 unchanged lines hidden (view full) ---

1134 */
1135 ip->ip_len = next;
1136 ip->ip_src = fp->ipq_src;
1137 ip->ip_dst = fp->ipq_dst;
1138 TAILQ_REMOVE(head, fp, ipq_list);
1139 nipq--;
1140 (void) m_free(dtom(fp));
1141 ip_nfragpackets--;
1142 m->m_len += (ip->ip_hl << 2);
1143 m->m_data -= (ip->ip_hl << 2);
1144 /* some debugging cruft by sklower, below, will go away soon */
1145 if (m->m_flags & M_PKTHDR) /* XXX this should be done elsewhere */
1146 m_fixhdr(m);
1147 return (m);
1148
1149dropfrag:
1150#ifdef IPDIVERT
1151 *divinfo = 0;

--- 107 unchanged lines hidden (view full) ---

1259 struct in_ifaddr *ia;
1260 int opt, optlen, cnt, off, code, type = ICMP_PARAMPROB, forward = 0;
1261 struct in_addr *sin, dst;
1262 n_time ntime;
1263 struct sockaddr_in ipaddr = { sizeof(ipaddr), AF_INET };
1264
1265 dst = ip->ip_dst;
1266 cp = (u_char *)(ip + 1);
1267 cnt = (ip->ip_hl << 2) - sizeof (struct ip);
1268 for (; cnt > 0; cnt -= optlen, cp += optlen) {
1269 opt = cp[IPOPT_OPTVAL];
1270 if (opt == IPOPT_EOL)
1271 break;
1272 if (opt == IPOPT_NOP)
1273 optlen = 1;
1274 else {
1275 if (cnt < IPOPT_OLEN + sizeof(*cp)) {

--- 372 unchanged lines hidden (view full) ---

1648 register struct mbuf *m;
1649 struct mbuf *mopt;
1650{
1651 register int i;
1652 struct ip *ip = mtod(m, struct ip *);
1653 register caddr_t opts;
1654 int olen;
1655
1656 olen = (ip->ip_hl << 2) - sizeof (struct ip);
1657 opts = (caddr_t)(ip + 1);
1658 i = m->m_len - (sizeof (struct ip) + olen);
1659 bcopy(opts + olen, opts, (unsigned)i);
1660 m->m_len -= olen;
1661 if (m->m_flags & M_PKTHDR)
1662 m->m_pkthdr.len -= olen;
1663 ip->ip_v = IPVERSION;
1664 ip->ip_hl = sizeof(struct ip) >> 2;
1665}
1666
1667u_char inetctlerrmap[PRC_NCMDS] = {
1668 0, 0, 0, 0,
1669 0, EMSGSIZE, EHOSTDOWN, EHOSTUNREACH,
1670 EHOSTUNREACH, EHOSTUNREACH, ECONNREFUSED, ECONNREFUSED,
1671 EMSGSIZE, EHOSTUNREACH, 0, 0,
1672 0, 0, 0, 0,

--- 80 unchanged lines hidden (view full) ---

1753 * We don't use m_copy() because it might return a reference
1754 * to a shared cluster. Both this function and ip_output()
1755 * assume exclusive access to the IP header in `m', so any
1756 * data in a cluster may change before we reach icmp_error().
1757 */
1758 MGET(mcopy, M_DONTWAIT, m->m_type);
1759 if (mcopy != NULL) {
1760 M_COPY_PKTHDR(mcopy, m);
1761 mcopy->m_len = imin((ip->ip_hl << 2) + 8,
1762 (int)ip->ip_len);
1763 m_copydata(m, 0, mcopy->m_len, mtod(mcopy, caddr_t));
1764#ifdef MAC
1765 /*
1766 * XXXMAC: This will eventually become an explicit
1767 * labeling point.
1768 */
1769 mac_create_mbuf_from_mbuf(m, mcopy);

--- 338 unchanged lines hidden ---