Deleted Added
full compact
ip_input.c (67609) ip_input.c (67620)
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 67609 2000-10-26 12:18:13Z ru $
34 * $FreeBSD: head/sys/netinet/ip_input.c 67620 2000-10-26 13:14:48Z ru $
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"

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

249 * try to reassemble. Process options. Pass to next level.
250 */
251void
252ip_input(struct mbuf *m)
253{
254 struct ip *ip;
255 struct ipq *fp;
256 struct in_ifaddr *ia = NULL;
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"

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

249 * try to reassemble. Process options. Pass to next level.
250 */
251void
252ip_input(struct mbuf *m)
253{
254 struct ip *ip;
255 struct ipq *fp;
256 struct in_ifaddr *ia = NULL;
257 int i, hlen, mff;
257 int i, hlen;
258 u_short sum;
259 u_int16_t divert_cookie; /* firewall cookie */
260#ifdef IPDIVERT
261 u_int32_t divert_info = 0; /* packet divert/tee info */
262#endif
263 struct ip_fw_chain *rule = NULL;
264#ifdef PFIL_HOOKS
265 struct packet_filter_hook *pfh;

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

593
594 /*
595 * If offset or IP_MF are set, must reassemble.
596 * Otherwise, nothing need be done.
597 * (We could look in the reassembly queue to see
598 * if the packet was previously fragmented,
599 * but it's not worth the time; just let them time out.)
600 */
258 u_short sum;
259 u_int16_t divert_cookie; /* firewall cookie */
260#ifdef IPDIVERT
261 u_int32_t divert_info = 0; /* packet divert/tee info */
262#endif
263 struct ip_fw_chain *rule = NULL;
264#ifdef PFIL_HOOKS
265 struct packet_filter_hook *pfh;

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

593
594 /*
595 * If offset or IP_MF are set, must reassemble.
596 * Otherwise, nothing need be done.
597 * (We could look in the reassembly queue to see
598 * if the packet was previously fragmented,
599 * but it's not worth the time; just let them time out.)
600 */
601 if (ip->ip_off & (IP_MF | IP_OFFMASK | IP_RF)) {
601 if (ip->ip_off & (IP_MF | IP_OFFMASK)) {
602
602
603#if 0 /*
604 * Reassembly should be able to treat a mbuf cluster, for later
605 * operation of contiguous protocol headers on the cluster. (KAME)
606 */
607 if (m->m_flags & M_EXT) { /* XXX */
608 if ((m = m_pullup(m, hlen)) == 0) {
609 ipstat.ips_toosmall++;
610#ifdef IPFIREWALL_FORWARD
611 ip_fw_fwd_addr = NULL;
612#endif
613 return;
614 }
615 ip = mtod(m, struct ip *);
616 }
617#endif
618 sum = IPREASS_HASH(ip->ip_src.s_addr, ip->ip_id);
619 /*
620 * Look for queue of fragments
621 * of this datagram.
622 */
623 for (fp = ipq[sum].next; fp != &ipq[sum]; fp = fp->next)
624 if (ip->ip_id == fp->ipq_id &&
625 ip->ip_src.s_addr == fp->ipq_src.s_addr &&

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

643 }
644 }
645 } else
646 ip_freef(ipq[sum].prev);
647 }
648found:
649 /*
650 * Adjust ip_len to not reflect header,
603 sum = IPREASS_HASH(ip->ip_src.s_addr, ip->ip_id);
604 /*
605 * Look for queue of fragments
606 * of this datagram.
607 */
608 for (fp = ipq[sum].next; fp != &ipq[sum]; fp = fp->next)
609 if (ip->ip_id == fp->ipq_id &&
610 ip->ip_src.s_addr == fp->ipq_src.s_addr &&

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

628 }
629 }
630 } else
631 ip_freef(ipq[sum].prev);
632 }
633found:
634 /*
635 * Adjust ip_len to not reflect header,
651 * set ip_mff if more fragments are expected,
652 * convert offset of this to bytes.
653 */
654 ip->ip_len -= hlen;
636 * convert offset of this to bytes.
637 */
638 ip->ip_len -= hlen;
655 mff = (ip->ip_off & IP_MF) != 0;
656 if (mff) {
639 if (ip->ip_off & IP_MF) {
657 /*
658 * Make sure that fragments have a data length
659 * that's a non-zero multiple of 8 bytes.
660 */
661 if (ip->ip_len == 0 || (ip->ip_len & 0x7) != 0) {
662 ipstat.ips_toosmall++; /* XXX */
663 goto bad;
664 }
665 m->m_flags |= M_FRAG;
666 }
667 ip->ip_off <<= 3;
668
669 /*
640 /*
641 * Make sure that fragments have a data length
642 * that's a non-zero multiple of 8 bytes.
643 */
644 if (ip->ip_len == 0 || (ip->ip_len & 0x7) != 0) {
645 ipstat.ips_toosmall++; /* XXX */
646 goto bad;
647 }
648 m->m_flags |= M_FRAG;
649 }
650 ip->ip_off <<= 3;
651
652 /*
670 * If datagram marked as having more fragments
671 * or if this is not the first fragment,
672 * attempt reassembly; if it succeeds, proceed.
653 * Attempt reassembly; if it succeeds, proceed.
673 */
654 */
674 if (mff || ip->ip_off) {
675 ipstat.ips_fragments++;
676 m->m_pkthdr.header = ip;
655 ipstat.ips_fragments++;
656 m->m_pkthdr.header = ip;
677#ifdef IPDIVERT
657#ifdef IPDIVERT
678 m = ip_reass(m,
679 fp, &ipq[sum], &divert_info, &divert_cookie);
658 m = ip_reass(m,
659 fp, &ipq[sum], &divert_info, &divert_cookie);
680#else
660#else
681 m = ip_reass(m, fp, &ipq[sum]);
661 m = ip_reass(m, fp, &ipq[sum]);
682#endif
662#endif
683 if (m == 0) {
663 if (m == 0) {
684#ifdef IPFIREWALL_FORWARD
664#ifdef IPFIREWALL_FORWARD
685 ip_fw_fwd_addr = NULL;
665 ip_fw_fwd_addr = NULL;
686#endif
666#endif
687 return;
688 }
689 ipstat.ips_reassembled++;
690 ip = mtod(m, struct ip *);
691 /* Get the header length of the reassembled packet */
692 hlen = IP_VHL_HL(ip->ip_vhl) << 2;
667 return;
668 }
669 ipstat.ips_reassembled++;
670 ip = mtod(m, struct ip *);
671 /* Get the header length of the reassembled packet */
672 hlen = IP_VHL_HL(ip->ip_vhl) << 2;
693#ifdef IPDIVERT
673#ifdef IPDIVERT
694 /* Restore original checksum before diverting packet */
695 if (divert_info != 0) {
696 ip->ip_len += hlen;
697 HTONS(ip->ip_len);
698 HTONS(ip->ip_off);
699 ip->ip_sum = 0;
700 ip->ip_sum = in_cksum_hdr(ip);
701 NTOHS(ip->ip_off);
702 NTOHS(ip->ip_len);
703 ip->ip_len -= hlen;
704 }
674 /* Restore original checksum before diverting packet */
675 if (divert_info != 0) {
676 ip->ip_len += hlen;
677 HTONS(ip->ip_len);
678 HTONS(ip->ip_off);
679 ip->ip_sum = 0;
680 ip->ip_sum = in_cksum_hdr(ip);
681 NTOHS(ip->ip_off);
682 NTOHS(ip->ip_len);
683 ip->ip_len -= hlen;
684 }
705#endif
685#endif
706 } else
707 if (fp)
708 ip_freef(fp);
709 } else
710 ip->ip_len -= hlen;
711
712#ifdef IPDIVERT
713 /*
714 * Divert or tee packet to the divert protocol if required.
715 *
716 * If divert_info is zero then cookie should be too, so we shouldn't

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

799 register struct ipq *fp;
800 struct ipq *where;
801#ifdef IPDIVERT
802 u_int32_t *divinfo;
803 u_int16_t *divcookie;
804#endif
805{
806 struct ip *ip = mtod(m, struct ip *);
686 } else
687 ip->ip_len -= hlen;
688
689#ifdef IPDIVERT
690 /*
691 * Divert or tee packet to the divert protocol if required.
692 *
693 * If divert_info is zero then cookie should be too, so we shouldn't

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

776 register struct ipq *fp;
777 struct ipq *where;
778#ifdef IPDIVERT
779 u_int32_t *divinfo;
780 u_int16_t *divcookie;
781#endif
782{
783 struct ip *ip = mtod(m, struct ip *);
807 register struct mbuf *p = 0, *q, *nq;
784 register struct mbuf *p, *q, *nq;
808 struct mbuf *t;
809 int hlen = IP_VHL_HL(ip->ip_vhl) << 2;
810 int i, next;
811
812 /*
813 * Presence of header sizes in mbufs
814 * would confuse code below.
815 */

--- 981 unchanged lines hidden ---
785 struct mbuf *t;
786 int hlen = IP_VHL_HL(ip->ip_vhl) << 2;
787 int i, next;
788
789 /*
790 * Presence of header sizes in mbufs
791 * would confuse code below.
792 */

--- 981 unchanged lines hidden ---