Deleted Added
full compact
ip_input.c (122334) ip_input.c (122702)
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 122334 2003-11-08 23:36:32Z sam $
34 * $FreeBSD: head/sys/netinet/ip_input.c 122702 2003-11-14 21:02:22Z andre $
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"

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

355
356/*
357 * Ip input routine. Checksum and byte swap header. If fragmented
358 * try to reassemble. Process options. Pass to next level.
359 */
360void
361ip_input(struct mbuf *m)
362{
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"

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

355
356/*
357 * Ip input routine. Checksum and byte swap header. If fragmented
358 * try to reassemble. Process options. Pass to next level.
359 */
360void
361ip_input(struct mbuf *m)
362{
363 struct ip *ip;
363 struct ip *ip = NULL;
364 struct ipq *fp;
365 struct in_ifaddr *ia = NULL;
366 struct ifaddr *ifa;
364 struct ipq *fp;
365 struct in_ifaddr *ia = NULL;
366 struct ifaddr *ifa;
367 int i, hlen, checkif;
367 int i, checkif, hlen = 0;
368 int ours = 0;
368 u_short sum;
369 struct in_addr pkt_dst;
370 u_int32_t divert_info = 0; /* packet divert/tee info */
371 struct ip_fw_args args;
372 struct route cro; /* copy of cached route */
373 int srcrt = 0; /* forward by ``src routing'' */
374#ifdef PFIL_HOOKS
375 struct in_addr odst; /* original dst address */

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

382#endif /* FAST_IPSEC */
383
384 args.eh = NULL;
385 args.oif = NULL;
386 args.rule = NULL;
387 args.divert_rule = 0; /* divert cookie */
388 args.next_hop = NULL;
389
369 u_short sum;
370 struct in_addr pkt_dst;
371 u_int32_t divert_info = 0; /* packet divert/tee info */
372 struct ip_fw_args args;
373 struct route cro; /* copy of cached route */
374 int srcrt = 0; /* forward by ``src routing'' */
375#ifdef PFIL_HOOKS
376 struct in_addr odst; /* original dst address */

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

383#endif /* FAST_IPSEC */
384
385 args.eh = NULL;
386 args.oif = NULL;
387 args.rule = NULL;
388 args.divert_rule = 0; /* divert cookie */
389 args.next_hop = NULL;
390
390 /* Grab info from MT_TAG mbufs prepended to the chain. */
391 for (; m && m->m_type == MT_TAG; m = m->m_next) {
391 /*
392 * Grab info from MT_TAG mbufs prepended to the chain.
393 *
394 * XXX: This is ugly. These pseudo mbuf prepend tags should really
395 * be real m_tags. Before these have always been allocated on the
396 * callers stack, so we didn't have to free them. Now with
397 * ip_fastforward they are true mbufs and we have to free them
398 * otherwise we have a leak. Must rewrite ipfw to use m_tags.
399 */
400 for (; m && m->m_type == MT_TAG;) {
401 struct mbuf *m0;
402
392 switch(m->_m_tag_id) {
393 default:
394 printf("ip_input: unrecognised MT_TAG tag %d\n",
395 m->_m_tag_id);
396 break;
397
398 case PACKET_TAG_DUMMYNET:
399 args.rule = ((struct dn_pkt *)m)->rule;
400 break;
401
402 case PACKET_TAG_DIVERT:
403 args.divert_rule = (intptr_t)m->m_hdr.mh_data & 0xffff;
404 break;
405
406 case PACKET_TAG_IPFORWARD:
407 args.next_hop = (struct sockaddr_in *)m->m_hdr.mh_data;
408 break;
403 switch(m->_m_tag_id) {
404 default:
405 printf("ip_input: unrecognised MT_TAG tag %d\n",
406 m->_m_tag_id);
407 break;
408
409 case PACKET_TAG_DUMMYNET:
410 args.rule = ((struct dn_pkt *)m)->rule;
411 break;
412
413 case PACKET_TAG_DIVERT:
414 args.divert_rule = (intptr_t)m->m_hdr.mh_data & 0xffff;
415 break;
416
417 case PACKET_TAG_IPFORWARD:
418 args.next_hop = (struct sockaddr_in *)m->m_hdr.mh_data;
419 break;
420
421 case PACKET_TAG_IPFASTFWD_OURS:
422 ours = 1;
423 break;
409 }
424 }
425
426 m0 = m;
427 m = m->m_next;
428 /* XXX: This is set by ip_fastforward */
429 if (m0->m_nextpkt == (struct mbuf *)1)
430 m_free(m0);
410 }
411
412 M_ASSERTPKTHDR(m);
413
431 }
432
433 M_ASSERTPKTHDR(m);
434
435 if (ours) /* ip_fastforward firewall changed dest to local */
436 goto ours;
437
414 if (args.rule) { /* dummynet already filtered us */
415 ip = mtod(m, struct ip *);
416 hlen = ip->ip_hl << 2;
417 goto iphack ;
418 }
419
420 ipstat.ips_total++;
421

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

1345 while (nipq > maxnipq && !TAILQ_EMPTY(&ipq[i])) {
1346 ipstat.ips_fragdropped +=
1347 TAILQ_FIRST(&ipq[i])->ipq_nfrags;
1348 ip_freef(&ipq[i], TAILQ_FIRST(&ipq[i]));
1349 }
1350 }
1351 }
1352 IPQ_UNLOCK();
438 if (args.rule) { /* dummynet already filtered us */
439 ip = mtod(m, struct ip *);
440 hlen = ip->ip_hl << 2;
441 goto iphack ;
442 }
443
444 ipstat.ips_total++;
445

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

1369 while (nipq > maxnipq && !TAILQ_EMPTY(&ipq[i])) {
1370 ipstat.ips_fragdropped +=
1371 TAILQ_FIRST(&ipq[i])->ipq_nfrags;
1372 ip_freef(&ipq[i], TAILQ_FIRST(&ipq[i]));
1373 }
1374 }
1375 }
1376 IPQ_UNLOCK();
1353 ipflow_slowtimo();
1354 splx(s);
1355}
1356
1357/*
1358 * Drain off all datagram fragments.
1359 */
1360void
1361ip_drain()

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

1975 RTCACHE_UPDATE(ro);
1976 if (error)
1977 ipstat.ips_cantforward++;
1978 else {
1979 ipstat.ips_forward++;
1980 if (type)
1981 ipstat.ips_redirectsent++;
1982 else {
1377 splx(s);
1378}
1379
1380/*
1381 * Drain off all datagram fragments.
1382 */
1383void
1384ip_drain()

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

1998 RTCACHE_UPDATE(ro);
1999 if (error)
2000 ipstat.ips_cantforward++;
2001 else {
2002 ipstat.ips_forward++;
2003 if (type)
2004 ipstat.ips_redirectsent++;
2005 else {
1983 if (mcopy) {
1984 ipflow_create(ro, mcopy);
2006 if (mcopy)
1985 m_freem(mcopy);
2007 m_freem(mcopy);
1986 }
1987 return;
1988 }
1989 }
1990 if (mcopy == NULL)
1991 return;
1992 destifp = NULL;
1993
1994 switch (error) {

--- 307 unchanged lines hidden ---
2008 return;
2009 }
2010 }
2011 if (mcopy == NULL)
2012 return;
2013 destifp = NULL;
2014
2015 switch (error) {

--- 307 unchanged lines hidden ---