Deleted Added
full compact
ip_input.c (105218) ip_input.c (105586)
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
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 105218 2002-10-16 09:01:48Z guido $
34 * $FreeBSD: head/sys/netinet/ip_input.c 105586 2002-10-20 22:52:07Z phk $
35 */
36
35 */
36
37#define _IP_VHL
38
39#include "opt_bootp.h"
40#include "opt_ipfw.h"
41#include "opt_ipdn.h"
42#include "opt_ipdivert.h"
43#include "opt_ipfilter.h"
44#include "opt_ipstealth.h"
45#include "opt_ipsec.h"
46#include "opt_mac.h"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

--- 338 unchanged lines hidden ---
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 ---