ignore bogus (large) return values from read
[unix-history] / usr / src / sys / netinet / ip_icmp.c
index 705526b..f545cd1 100644 (file)
@@ -1,17 +1,20 @@
-/*     ip_icmp.c       4.18    82/09/12        */
+/*     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 "../net/in.h"
-#include "../net/in_systm.h"
-#include "../net/ip.h"
-#include "../net/ip_icmp.h"
-#include <time.h>
+#include "../h/time.h"
 #include "../h/kernel.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
 /*
  * ICMP routines: error generation, receive packet processing, and
  * routines to turnaround packets back to the originator, and
@@ -45,7 +48,7 @@ icmp_error(oip, type, code)
        /*
         * First, formulate icmp message
         */
        /*
         * 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;
@@ -61,9 +64,7 @@ icmp_error(oip, type, code)
        bcopy((caddr_t)oip, (caddr_t)&icp->icmp_ip, oiplen + 8);
        nip = &icp->icmp_ip;
        nip->ip_len += oiplen;
        bcopy((caddr_t)oip, (caddr_t)&icp->icmp_ip, oiplen + 8);
        nip = &icp->icmp_ip;
        nip->ip_len += oiplen;
-#if vax || pdp11
        nip->ip_len = htons((u_short)nip->ip_len);
        nip->ip_len = htons((u_short)nip->ip_len);
-#endif
 
        /*
         * Now, copy old ip header in front of icmp
 
        /*
         * Now, copy old ip header in front of icmp
@@ -104,7 +105,8 @@ 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, (*ctlfunc)();
+       int icmplen = ip->ip_len, hlen = ip->ip_hl << 2;
+       int i, (*ctlfunc)(), type;
        extern u_char ip_protox[];
 
        /*
        extern u_char ip_protox[];
 
        /*
@@ -143,15 +145,14 @@ icmp_input(m)
                 * Problem with previous datagram; advise
                 * higher level routines.
                 */
                 * Problem with previous datagram; advise
                 * higher level routines.
                 */
-#if vax || pdp11
-               icp->icmp_ip.ip_len = ntohs(icp->icmp_ip.ip_len);
-#endif
+               icp->icmp_ip.ip_len = ntohs((u_short)icp->icmp_ip.ip_len);
                if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN(icp))
                        goto free;
                if (icmpprintfs)
                        printf("deliver to protocol %d\n", icp->icmp_ip.ip_p);
                if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN(icp))
                        goto free;
                if (icmpprintfs)
                        printf("deliver to protocol %d\n", icp->icmp_ip.ip_p);
-               if (ctlfunc = protosw[ip_protox[icp->icmp_ip.ip_p]].pr_ctlinput)
-                       (*ctlfunc)(icmpmap[i] + icp->icmp_code, (caddr_t)icp);
+               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:
@@ -186,6 +187,7 @@ icmp_input(m)
        }
 reflect:
        icmp_reflect(ip);
        }
 reflect:
        icmp_reflect(ip);
+       return;
 free:
        m_freem(dtom(ip));
 }
 free:
        m_freem(dtom(ip));
 }
@@ -205,8 +207,6 @@ icmp_reflect(ip)
        icmp_send(ip);
 }
 
        icmp_send(ip);
 }
 
-int    generateicmpmsgs = 1;
-
 /*
  * 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.
@@ -214,12 +214,12 @@ int       generateicmpmsgs = 1;
 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;
 
 
-       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);
        icp = mtod(m, struct icmp *);
        icp->icmp_cksum = 0;
        icp->icmp_cksum = in_cksum(m, ip->ip_len - hlen);
@@ -227,7 +227,7 @@ icmp_send(ip)
        m->m_len += hlen;
        if (icmpprintfs)
                printf("icmp_send dst %x src %x\n", ip->ip_dst, ip->ip_src);
        m->m_len += hlen;
        if (icmpprintfs)
                printf("icmp_send dst %x src %x\n", ip->ip_dst, ip->ip_src);
-       (void) ip_output(m, 0, 0, 0);
+       (void) ip_output(m, (struct mbuf *)0, (struct route *)0, 0);
 }
 
 n_time
 }
 
 n_time