ignore bogus (large) return values from read
[unix-history] / usr / src / sys / netinet / ip_icmp.c
index cb4ccb9..f545cd1 100644 (file)
@@ -1,21 +1,26 @@
-/*     ip_icmp.c       4.14    82/04/24        */
+/*     ip_icmp.c       4.27    83/02/10        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
-#include "../h/clock.h"
-#include "../net/in.h"
-#include "../net/in_systm.h"
-#include "../net/ip.h"
-#include "../net/ip_icmp.h"
+#include "../h/time.h"
+#include "../h/kernel.h"
+
+#include "../net/route.h"
+
+#include "../netinet/in.h"
+#include "../netinet/in_systm.h"
+#include "../netinet/ip.h"
+#include "../netinet/ip_icmp.h"
 
 /*
  * ICMP routines: error generation, receive packet processing, and
  * routines to turnaround packets back to the originator, and
  * host table maintenance routines.
  */
 
 /*
  * ICMP routines: error generation, receive packet processing, and
  * routines to turnaround packets back to the originator, and
  * host table maintenance routines.
  */
+int    icmpprintfs = 0;
 
 /*
  * Generate an error packet of type error
 
 /*
  * Generate an error packet of type error
@@ -29,20 +34,21 @@ icmp_error(oip, type, code)
        register struct icmp *icp;
        struct mbuf *m;
        struct ip *nip;
        register struct icmp *icp;
        struct mbuf *m;
        struct ip *nip;
-COUNT(ICMP_ERROR);
 
 
+       if (icmpprintfs)
+               printf("icmp_error(%x, %d, %d)\n", oip, type, code);
        /*
         * Make sure that the old IP packet had 8 bytes of data to return;
         * if not, don't bother.  Also don't EVER error if the old
         * packet protocol was ICMP.
         */
        /*
         * Make sure that the old IP packet had 8 bytes of data to return;
         * if not, don't bother.  Also don't EVER error if the old
         * packet protocol was ICMP.
         */
-       if (oip->ip_len - oiplen < 8 || oip->ip_p == IPPROTO_ICMP)
+       if (oip->ip_len < 8 || oip->ip_p == IPPROTO_ICMP)
                goto free;
 
        /*
         * First, formulate icmp message
         */
                goto free;
 
        /*
         * First, formulate icmp message
         */
-       m = m_get(M_DONTWAIT);
+       m = m_get(M_DONTWAIT, MT_HEADER);
        if (m == 0)
                goto free;
        m->m_len = oiplen + 8 + ICMP_MINLEN;
        if (m == 0)
                goto free;
        m->m_len = oiplen + 8 + ICMP_MINLEN;
@@ -56,6 +62,9 @@ COUNT(ICMP_ERROR);
        }
        icp->icmp_code = code;
        bcopy((caddr_t)oip, (caddr_t)&icp->icmp_ip, oiplen + 8);
        }
        icp->icmp_code = code;
        bcopy((caddr_t)oip, (caddr_t)&icp->icmp_ip, oiplen + 8);
+       nip = &icp->icmp_ip;
+       nip->ip_len += oiplen;
+       nip->ip_len = htons((u_short)nip->ip_len);
 
        /*
         * Now, copy old ip header in front of icmp
 
        /*
         * Now, copy old ip header in front of icmp
@@ -96,14 +105,16 @@ icmp_input(m)
 {
        register struct icmp *icp;
        register struct ip *ip = mtod(m, struct ip *);
 {
        register struct icmp *icp;
        register struct ip *ip = mtod(m, struct ip *);
-       int icmplen = ip->ip_len, hlen = ip->ip_hl << 2, i;
+       int icmplen = ip->ip_len, hlen = ip->ip_hl << 2;
+       int i, (*ctlfunc)(), type;
        extern u_char ip_protox[];
        extern u_char ip_protox[];
-COUNT(ICMP_INPUT);
 
        /*
         * Locate icmp structure in mbuf, and check
         * that not corrupted and of at least minimum length.
         */
 
        /*
         * Locate icmp structure in mbuf, and check
         * that not corrupted and of at least minimum length.
         */
+       if (icmpprintfs)
+               printf("icmp_input from %x, len %d\n", ip->ip_src, icmplen);
        if (icmplen < ICMP_MINLEN)
                goto free;
        m->m_len -= hlen;
        if (icmplen < ICMP_MINLEN)
                goto free;
        m->m_len -= hlen;
@@ -120,6 +131,9 @@ COUNT(ICMP_INPUT);
        /*
         * Message type specific processing.
         */
        /*
         * Message type specific processing.
         */
+       if (icmpprintfs)
+               printf("icmp_input, type %d code %d\n", icp->icmp_type,
+                       icp->icmp_code);
        switch (i = icp->icmp_type) {
 
        case ICMP_UNREACH:
        switch (i = icp->icmp_type) {
 
        case ICMP_UNREACH:
@@ -131,10 +145,14 @@ COUNT(ICMP_INPUT);
                 * Problem with previous datagram; advise
                 * higher level routines.
                 */
                 * Problem with previous datagram; advise
                 * higher level routines.
                 */
+               icp->icmp_ip.ip_len = ntohs((u_short)icp->icmp_ip.ip_len);
                if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN(icp))
                        goto free;
                if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN(icp))
                        goto free;
-               (*protosw[ip_protox[ip->ip_p]].pr_ctlinput)
-                       (icmpmap[i] + icp->icmp_code, (caddr_t)icp);
+               if (icmpprintfs)
+                       printf("deliver to protocol %d\n", icp->icmp_ip.ip_p);
+               type = i == ICMP_PARAMPROB ? 0 : icp->icmp_code;
+               if (ctlfunc = inetsw[ip_protox[icp->icmp_ip.ip_p]].pr_ctlinput)
+                       (*ctlfunc)(icmpmap[i] + type, (caddr_t)icp);
                goto free;
 
        case ICMP_ECHO:
                goto free;
 
        case ICMP_ECHO:
@@ -169,6 +187,7 @@ COUNT(ICMP_INPUT);
        }
 reflect:
        icmp_reflect(ip);
        }
 reflect:
        icmp_reflect(ip);
+       return;
 free:
        m_freem(dtom(ip));
 }
 free:
        m_freem(dtom(ip));
 }
@@ -181,7 +200,6 @@ icmp_reflect(ip)
        struct ip *ip;
 {
        struct in_addr t;
        struct ip *ip;
 {
        struct in_addr t;
-COUNT(ICMP_REFLECT);
 
        t = ip->ip_dst;
        ip->ip_dst = ip->ip_src;
 
        t = ip->ip_dst;
        ip->ip_dst = ip->ip_src;
@@ -189,8 +207,6 @@ COUNT(ICMP_REFLECT);
        icmp_send(ip);
 }
 
        icmp_send(ip);
 }
 
-int    generateicmpmsgs = 0;
-
 /*
  * Send an icmp packet back to the ip level,
  * after supplying a checksum.
 /*
  * Send an icmp packet back to the ip level,
  * after supplying a checksum.
@@ -198,19 +214,20 @@ int       generateicmpmsgs = 0;
 icmp_send(ip)
        struct ip *ip;
 {
 icmp_send(ip)
        struct ip *ip;
 {
-       register int hlen = ip->ip_hl << 2;
+       register int hlen;
        register struct icmp *icp;
        register struct icmp *icp;
-       register struct mbuf *m = dtom(ip);
+       register struct mbuf *m;
 
 
-COUNT(ICMP_SEND);
-       if (!generateicmpmsgs)
-               return;
+       m = dtom(ip);
+       hlen = ip->ip_hl << 2;
        icp = mtod(m, struct icmp *);
        icp->icmp_cksum = 0;
        icp->icmp_cksum = in_cksum(m, ip->ip_len - hlen);
        m->m_off -= hlen;
        m->m_len += hlen;
        icp = mtod(m, struct icmp *);
        icp->icmp_cksum = 0;
        icp->icmp_cksum = in_cksum(m, ip->ip_len - hlen);
        m->m_off -= hlen;
        m->m_len += hlen;
-       (void) ip_output(m, 0, 0, 0);
+       if (icmpprintfs)
+               printf("icmp_send dst %x src %x\n", ip->ip_dst, ip->ip_src);
+       (void) ip_output(m, (struct mbuf *)0, (struct route *)0, 0);
 }
 
 n_time
 }
 
 n_time
@@ -219,8 +236,7 @@ iptime()
        int s = spl6();
        u_long t;
 
        int s = spl6();
        u_long t;
 
-COUNT(IPTIME);
-       t = (time % SECDAY) * 1000 + lbolt * hz;
+       t = (time.tv_sec % (24*60*60)) * 1000 + time.tv_usec / 1000;
        splx(s);
        return (htonl(t));
 }
        splx(s);
        return (htonl(t));
 }