properly free mbuf space
[unix-history] / usr / src / sys / netinet / ip_icmp.c
index 830f8d8..8cf82fd 100644 (file)
@@ -1,12 +1,12 @@
-/*     ip_icmp.c       4.7     81/11/23        */
+/*     ip_icmp.c       4.13    82/04/07        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
 #include "../h/protosw.h"
 #include "../h/clock.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
 #include "../h/protosw.h"
 #include "../h/clock.h"
-#include "../net/inet.h"
-#include "../net/inet_systm.h"
+#include "../net/in.h"
+#include "../net/in_systm.h"
 #include "../net/ip.h"
 #include "../net/ip_icmp.h"
 
 #include "../net/ip.h"
 #include "../net/ip_icmp.h"
 
@@ -27,6 +27,7 @@ icmp_error(oip, type, code)
        struct icmp *icp = (struct icmp *)((int)oip + oiplen);
        struct mbuf *m;
        struct ip *nip;
        struct icmp *icp = (struct icmp *)((int)oip + oiplen);
        struct mbuf *m;
        struct ip *nip;
+COUNT(ICMP_ERROR);
 
        /*
         * Make sure that the old IP packet had 8 bytes of data to return;
 
        /*
         * Make sure that the old IP packet had 8 bytes of data to return;
@@ -41,7 +42,7 @@ icmp_error(oip, type, code)
         * of the mbuf, followed by the old IP header and 8 bytes
         * of its data.
         */
         * of the mbuf, followed by the old IP header and 8 bytes
         * of its data.
         */
-       m = m_get(0);
+       m = m_get(M_DONTWAIT);
        if (m == 0)
                goto free;
        m->m_off = MMAXOFF - (oiplen + 8);
        if (m == 0)
                goto free;
        m->m_off = MMAXOFF - (oiplen + 8);
@@ -63,10 +64,10 @@ icmp_error(oip, type, code)
        *nip = *oip;
        icmp_reflect(nip);
 
        *nip = *oip;
        icmp_reflect(nip);
 
+free:
        /*
         * Discard mbufs of original datagram
         */
        /*
         * Discard mbufs of original datagram
         */
-free:
        m_freem(dtom(oip));
 }
 
        m_freem(dtom(oip));
 }
 
@@ -81,6 +82,8 @@ icmp_input(m)
        int hlen = ip->ip_hl << 2;
        int icmplen = ip->ip_len - hlen;
        int i;
        int hlen = ip->ip_hl << 2;
        int icmplen = ip->ip_len - hlen;
        int i;
+       extern u_char ip_protox[];
+COUNT(ICMP_INPUT);
 
        /*
         * Locate icmp structure in mbuf, and check
 
        /*
         * Locate icmp structure in mbuf, and check
@@ -92,7 +95,7 @@ icmp_input(m)
        icp = (struct icmp *)mtod(m, struct icmp *);
        i = icp->icmp_cksum;
        icp->icmp_cksum = 0;
        icp = (struct icmp *)mtod(m, struct icmp *);
        i = icp->icmp_cksum;
        icp->icmp_cksum = 0;
-       if (i != inet_cksum(m, icmplen) || icmplen < ICMP_MINLEN)
+       if (i != in_cksum(m, icmplen) || icmplen < ICMP_MINLEN)
                goto free;
 
        /*
                goto free;
 
        /*
@@ -111,7 +114,7 @@ icmp_input(m)
                 */
                if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN(icp))
                        goto free;
                 */
                if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN(icp))
                        goto free;
-               icmp_ctlinput(ip);
+               (*protosw[ip_protox[ip->ip_p]].pr_ctlinput)(m);
                goto free;
 
        case ICMP_ECHO:
                goto free;
 
        case ICMP_ECHO:
@@ -154,6 +157,7 @@ icmp_reflect(ip)
        struct ip *ip;
 {
        struct in_addr t;
        struct ip *ip;
 {
        struct in_addr t;
+COUNT(ICMP_REFLECT);
 
        t = ip->ip_src; ip->ip_dst = ip->ip_src; ip->ip_src = t;
        /*
 
        t = ip->ip_src; ip->ip_dst = ip->ip_src; ip->ip_src = t;
        /*
@@ -170,24 +174,17 @@ icmp_reflect(ip)
 icmp_send(ip)
        struct ip *ip;
 {
 icmp_send(ip)
        struct ip *ip;
 {
-       struct icmp *icp = 0;                                   /* XXX */
+COUNT(ICMP_SEND);
 
 
-       icp->icmp_cksum = 0;
-       icp->icmp_cksum = inet_cksum(dtom(ip), 0);              /* XXX */
-       ip->ip_ttl = MAXTTL;
-       ip_output(dtom(ip));
+       m_freem(dtom(ip));
 }
 
 }
 
-/*
- * Advise a higher level protocol of a problem reported by
- * a gateway or another host.
- */
-icmp_ctlinput(ip)
-       struct ip *ip;
+icmp_ctlinput(m)
+       struct mbuf *m;
 {
 {
-       extern u_char ip_protox[];              /* XXX */
+COUNT(ICMP_CTLINPUT);
 
 
-       (*protosw[ip_protox[ip->ip_p]].pr_ctlinput)(ip);
+       m_freem(m);
 }
 
 /*
 }
 
 /*
@@ -199,11 +196,13 @@ icmp_gotreply(icp)
        struct icmp *icp;
 {
 
        struct icmp *icp;
 {
 
+COUNT(ICMP_GOTREPLY);
 }
 
 icmp_drain()
 {
 
 }
 
 icmp_drain()
 {
 
+COUNT(ICMP_DRAIN);
 }
 
 n_time
 }
 
 n_time
@@ -212,6 +211,7 @@ iptime()
        int s = spl6();
        u_long t;
 
        int s = spl6();
        u_long t;
 
+COUNT(IPTIME);
        t = (time % SECDAY) * 1000 + lbolt * hz;
        splx(s);
        return (htonl(t));
        t = (time % SECDAY) * 1000 + lbolt * hz;
        splx(s);
        return (htonl(t));