BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / netinet / ip_input.c
index e65694f..889e370 100644 (file)
@@ -2,22 +2,35 @@
  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution is only permitted until one year after the first shipment
- * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
- * binary forms are permitted provided that: (1) source distributions retain
- * this entire copyright notice and comment, and (2) distributions including
- * binaries display the following acknowledgement:  This product includes
- * software developed by the University of California, Berkeley and its
- * contributors'' in the documentation or other materials provided with the
- * distribution and in all advertising materials mentioning features or use
- * of this software.  Neither the name of the University nor the names of
- * its contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)ip_input.c  7.17 (Berkeley) 7/25/90
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)ip_input.c  7.19 (Berkeley) 5/25/91
  */
 
 #include "param.h"
  */
 
 #include "param.h"
 #endif
 int    ipforwarding = IPFORWARDING;
 int    ipsendredirects = IPSENDREDIRECTS;
 #endif
 int    ipforwarding = IPFORWARDING;
 int    ipsendredirects = IPSENDREDIRECTS;
-#ifdef DEBUG
+#ifdef DIAGNOSTIC
 int    ipprintfs = 0;
 #endif
 
 int    ipprintfs = 0;
 #endif
 
+extern struct domain inetdomain;
+extern struct protosw inetsw[];
 u_char ip_protox[IPPROTO_MAX];
 int    ipqmaxlen = IFQ_MAXLEN;
 struct in_ifaddr *in_ifaddr;                   /* first inet address */
 u_char ip_protox[IPPROTO_MAX];
 int    ipqmaxlen = IFQ_MAXLEN;
 struct in_ifaddr *in_ifaddr;                   /* first inet address */
@@ -453,6 +468,13 @@ insert:
        m = dtom(ip);
        m->m_len += (ip->ip_hl << 2);
        m->m_data -= (ip->ip_hl << 2);
        m = dtom(ip);
        m->m_len += (ip->ip_hl << 2);
        m->m_data -= (ip->ip_hl << 2);
+       /* some debugging cruft by sklower, below, will go away soon */
+       if (m->m_flags & M_PKTHDR) { /* XXX this should be done elsewhere */
+               register int plen = 0;
+               for (t = m; m; m = m->m_next)
+                       plen += m->m_len;
+               t->m_pkthdr.len = plen;
+       }
        return ((struct ip *)ip);
 
 dropfrag:
        return ((struct ip *)ip);
 
 dropfrag:
@@ -768,7 +790,7 @@ save_rte(option, dst)
        unsigned olen;
 
        olen = option[IPOPT_OLEN];
        unsigned olen;
 
        olen = option[IPOPT_OLEN];
-#ifdef DEBUG
+#ifdef DIAGNOSTIC
        if (ipprintfs)
                printf("save_rte: olen %d\n", olen);
 #endif
        if (ipprintfs)
                printf("save_rte: olen %d\n", olen);
 #endif
@@ -801,7 +823,7 @@ ip_srcroute()
        /* length is (nhops+1)*sizeof(addr) + sizeof(nop + srcrt header) */
        m->m_len = ip_nhops * sizeof(struct in_addr) + sizeof(struct in_addr) +
            OPTSIZ;
        /* length is (nhops+1)*sizeof(addr) + sizeof(nop + srcrt header) */
        m->m_len = ip_nhops * sizeof(struct in_addr) + sizeof(struct in_addr) +
            OPTSIZ;
-#ifdef DEBUG
+#ifdef DIAGNOSTIC
        if (ipprintfs)
                printf("ip_srcroute: nhops %d mlen %d", ip_nhops, m->m_len);
 #endif
        if (ipprintfs)
                printf("ip_srcroute: nhops %d mlen %d", ip_nhops, m->m_len);
 #endif
@@ -811,9 +833,9 @@ ip_srcroute()
         */
        p = &ip_srcrt.route[ip_nhops - 1];
        *(mtod(m, struct in_addr *)) = *p--;
         */
        p = &ip_srcrt.route[ip_nhops - 1];
        *(mtod(m, struct in_addr *)) = *p--;
-#ifdef DEBUG
+#ifdef DIAGNOSTIC
        if (ipprintfs)
        if (ipprintfs)
-               printf(" hops %X", ntohl(*mtod(m, struct in_addr *)));
+               printf(" hops %lx", ntohl(mtod(m, struct in_addr *)->s_addr));
 #endif
 
        /*
 #endif
 
        /*
@@ -831,9 +853,9 @@ ip_srcroute()
         * reversing the path (pointers are now aligned).
         */
        while (p >= ip_srcrt.route) {
         * reversing the path (pointers are now aligned).
         */
        while (p >= ip_srcrt.route) {
-#ifdef DEBUG
+#ifdef DIAGNOSTIC
                if (ipprintfs)
                if (ipprintfs)
-                       printf(" %X", ntohl(*q));
+                       printf(" %lx", ntohl(q->s_addr));
 #endif
                *q++ = *p--;
        }
 #endif
                *q++ = *p--;
        }
@@ -841,9 +863,9 @@ ip_srcroute()
         * Last hop goes to final destination.
         */
        *q = ip_srcrt.dst;
         * Last hop goes to final destination.
         */
        *q = ip_srcrt.dst;
-#ifdef DEBUG
+#ifdef DIAGNOSTIC
        if (ipprintfs)
        if (ipprintfs)
-               printf(" %X\n", ntohl(*q));
+               printf(" %lx\n", ntohl(q->s_addr));
 #endif
        return (m);
 }
 #endif
        return (m);
 }
@@ -909,7 +931,7 @@ ip_forward(m, srcrt)
        struct in_addr dest;
 
        dest.s_addr = 0;
        struct in_addr dest;
 
        dest.s_addr = 0;
-#ifdef DEBUG
+#ifdef DIAGNOSTIC
        if (ipprintfs)
                printf("forward: src %x dst %x ttl %x\n", ip->ip_src,
                        ip->ip_dst, ip->ip_ttl);
        if (ipprintfs)
                printf("forward: src %x dst %x ttl %x\n", ip->ip_src,
                        ip->ip_dst, ip->ip_ttl);
@@ -994,7 +1016,7 @@ ip_forward(m, srcrt)
                            code = ICMP_REDIRECT_HOST;
                    else
                            code = ICMP_REDIRECT_NET;
                            code = ICMP_REDIRECT_HOST;
                    else
                            code = ICMP_REDIRECT_NET;
-#ifdef DEBUG
+#ifdef DIAGNOSTIC
                    if (ipprintfs)
                        printf("redirect (%d) to %x\n", code, dest.s_addr);
 #endif
                    if (ipprintfs)
                        printf("redirect (%d) to %x\n", code, dest.s_addr);
 #endif