date and time created 81/11/29 22:20:02 by wnj
[unix-history] / usr / src / sys / netinet / ip_input.c
index a6d3e42..b4fc9cc 100644 (file)
@@ -1,4 +1,4 @@
-/* ip_input.c 1.17 81/11/23 */
+/* ip_input.c 1.20 81/11/29 */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -6,11 +6,10 @@
 #include "../h/mbuf.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
 #include "../h/mbuf.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
-#include "../net/inet.h"
-#include "../net/inet_systm.h"
+#include "../net/in.h"
+#include "../net/in_systm.h"
 #include "../net/if.h"
 #include "../net/if.h"
-#include "../net/imp.h"
-#include "../net/ip.h"                 /* belongs before inet.h */
+#include "../net/ip.h"                 /* belongs before in.h */
 #include "../net/ip_var.h"
 #include "../net/ip_icmp.h"
 #include "../net/tcp.h"
 #include "../net/ip_var.h"
 #include "../net/ip_icmp.h"
 #include "../net/tcp.h"
@@ -51,27 +50,35 @@ struct      ip *ip_reass();
  * try to reassamble.  If complete and fragment queue exists, discard.
  * Process options.  Pass to next level.
  */
  * try to reassamble.  If complete and fragment queue exists, discard.
  * Process options.  Pass to next level.
  */
-ip_input(m0)
-       struct mbuf *m0;
+ipintr()
 {
        register struct ip *ip;
 {
        register struct ip *ip;
-       register struct mbuf *m = m0;
+       register struct mbuf *m;
+       struct mbuf *m0;
        register int i;
        register struct ipq *fp;
        register int i;
        register struct ipq *fp;
-       int hlen;
+       int hlen, s;
 
 
-COUNT(IP_INPUT);
+COUNT(IPINTR);
+next:
        /*
        /*
-        * Check header and byteswap.
+        * Get next datagram off input queue and get IP header
+        * in first mbuf.
         */
         */
-       printf("ip_input\n");
+       s = splimp();
+       IF_DEQUEUE(&ipintrq, m);
+       splx(s);
+       if (m == 0)
+               return;
+       if (m->m_len < sizeof (struct ip) &&
+           m_pullup(m, sizeof (struct ip)) == 0)
+               goto bad;
        ip = mtod(m, struct ip *);
        ip = mtod(m, struct ip *);
-       if ((hlen = ip->ip_hl << 2) > m->m_len) {
-               printf("ip hdr ovflo\n");
+       if ((hlen = ip->ip_hl << 2) > m->m_len &&
+           m_pullup(m, hlen) == 0)
                goto bad;
                goto bad;
-       }
        if (ipcksum)
        if (ipcksum)
-               if ((ip->ip_sum = inet_cksum(m, hlen)) != 0xffff) {
+               if ((ip->ip_sum = in_cksum(m, hlen)) != 0xffff) {
                        printf("ip_sum %x\n", ip->ip_sum);
                        ipstat.ips_badsum++;
                        goto bad;
                        printf("ip_sum %x\n", ip->ip_sum);
                        ipstat.ips_badsum++;
                        goto bad;
@@ -90,20 +97,13 @@ COUNT(IP_INPUT);
         * Trim mbufs if longer than we expect.
         * Drop packet if shorter than we expect.
         */
         * Trim mbufs if longer than we expect.
         * Drop packet if shorter than we expect.
         */
-       printf("ip_input: %d:", ip->ip_len);
        i = 0;
        i = 0;
-       for (; m != NULL; m = m->m_next) {
+       for (m0 = m; m != NULL; m = m->m_next)
                i += m->m_len;
                i += m->m_len;
-               printf(" %d", m->m_len);
-       }
-       printf("\n");
        m = m0;
        if (i != ip->ip_len) {
        m = m0;
        if (i != ip->ip_len) {
-               if (i < ip->ip_len) {
-                       printf("ip_input: short packet\n");
+               if (i < ip->ip_len)
                        goto bad;
                        goto bad;
-               }
-               printf("m_adj %d\n", ip->ip_len - i);
                m_adj(m, ip->ip_len - i);
        }
 
                m_adj(m, ip->ip_len - i);
        }
 
@@ -113,14 +113,14 @@ COUNT(IP_INPUT);
         */
        if (hlen > sizeof (struct ip))
                ip_dooptions(ip);
         */
        if (hlen > sizeof (struct ip))
                ip_dooptions(ip);
-       if (ip->ip_dst.s_addr != n_lhost.s_addr &&
+       if (ifnet && ip->ip_dst.s_addr != ifnet->if_addr.s_addr &&
            if_ifwithaddr(ip->ip_dst) == 0) {
                if (--ip->ip_ttl == 0) {
                        icmp_error(ip, ICMP_TIMXCEED, 0);
            if_ifwithaddr(ip->ip_dst) == 0) {
                if (--ip->ip_ttl == 0) {
                        icmp_error(ip, ICMP_TIMXCEED, 0);
-                       return;
+                       goto next;
                }
                }
-               ip_output(dtom(ip));
-               return;
+               (void) ip_output(dtom(ip), (struct mbuf *)0);
+               goto next;
        }
 
        /*
        }
 
        /*
@@ -155,7 +155,7 @@ found:
        if (((struct ipasfrag *)ip)->ipf_mff || ip->ip_off) {
                ip = ip_reass((struct ipasfrag *)ip, fp);
                if (ip == 0)
        if (((struct ipasfrag *)ip)->ipf_mff || ip->ip_off) {
                ip = ip_reass((struct ipasfrag *)ip, fp);
                if (ip == 0)
-                       return;
+                       goto next;
                hlen = ip->ip_hl << 2;
                m = dtom(ip);
        } else
                hlen = ip->ip_hl << 2;
                m = dtom(ip);
        } else
@@ -166,9 +166,10 @@ found:
         * Switch out to protocol's input routine.
         */
        (*protosw[ip_protox[ip->ip_p]].pr_input)(m);
         * Switch out to protocol's input routine.
         */
        (*protosw[ip_protox[ip->ip_p]].pr_input)(m);
-       return;
+       goto next;
 bad:
        m_freem(m);
 bad:
        m_freem(m);
+       goto next;
 }
 
 /*
 }
 
 /*