new copyright notice
[unix-history] / usr / src / sys / netns / ns_error.c
index 695d628..2ca2dd1 100644 (file)
@@ -1,19 +1,15 @@
 /*
 /*
- * Copyright (c) 1984, 1985, 1986, 1987 Regents of the University of California.
+ * Copyright (c) 1984, 1988 Regents of the University of California.
  * All rights reserved.
  *
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that this notice is preserved and that due credit is given
- * to the University of California at Berkeley. The name of the University
- * may not be used to endorse or promote products derived from this
- * software without specific prior written permission. This software
- * is provided ``as is'' without express or implied warranty.
+ * %sccs.include.redist.c%
  *
  *
- *      @(#)ns_error.c 7.4 (Berkeley) %G%
+ *     @(#)ns_error.c  7.8 (Berkeley) %G%
  */
 
 #include "param.h"
 #include "systm.h"
  */
 
 #include "param.h"
 #include "systm.h"
+#include "malloc.h"
 #include "mbuf.h"
 #include "protosw.h"
 #include "socket.h"
 #include "mbuf.h"
 #include "protosw.h"
 #include "socket.h"
 int    ns_errprintfs = 0;
 #endif
 
 int    ns_errprintfs = 0;
 #endif
 
+ns_err_x(c)
+{
+       register u_short *w, *lim, *base = ns_errstat.ns_es_codes;
+       u_short x = c;
+
+       /*
+        * zero is a legit error code, handle specially
+        */
+       if (x == 0)
+               return (0);
+       lim = base + NS_ERR_MAX - 1;
+       for (w = base + 1; w < lim; w++) {
+               if (*w == 0)
+                       *w = x;
+               if (*w == x)
+                       break;
+       }
+       return (w - base);
+}
+
 /*
  * Generate an error packet of type error
  * in response to bad packet.
 /*
  * Generate an error packet of type error
  * in response to bad packet.
@@ -59,9 +75,9 @@ ns_error(om, type, param)
         * and nobody was there, just echo it.
         * (Yes, this is a wart!)
         */
         * and nobody was there, just echo it.
         * (Yes, this is a wart!)
         */
-       if (type==NS_ERR_NOSOCK &&
-           oip->idp_dna.x_port==htons(2) &&
-           (type = ns_echo(oip)==0))
+       if (type == NS_ERR_NOSOCK &&
+           oip->idp_dna.x_port == htons(2) &&
+           (type = ns_echo(om))==0)
                return;
 
 #ifdef NS_ERRPRINTFS
                return;
 
 #ifdef NS_ERRPRINTFS
@@ -72,7 +88,7 @@ ns_error(om, type, param)
         * Don't Generate error packets in response to multicasts.
         */
        if (oip->idp_dna.x_host.c_host[0] & 1)
         * Don't Generate error packets in response to multicasts.
         */
        if (oip->idp_dna.x_host.c_host[0] & 1)
-               goto free;
+               goto freeit;
 
        ns_errstat.ns_es_error++;
        /*
 
        ns_errstat.ns_es_error++;
        /*
@@ -82,21 +98,21 @@ ns_error(om, type, param)
         */
        if (oip->idp_len < sizeof(struct idp)) {
                ns_errstat.ns_es_oldshort++;
         */
        if (oip->idp_len < sizeof(struct idp)) {
                ns_errstat.ns_es_oldshort++;
-               goto free;
+               goto freeit;
        }
        if (oip->idp_pt == NSPROTO_ERROR) {
                ns_errstat.ns_es_oldns_err++;
        }
        if (oip->idp_pt == NSPROTO_ERROR) {
                ns_errstat.ns_es_oldns_err++;
-               goto free;
+               goto freeit;
        }
 
        /*
         * First, formulate ns_err message
         */
        }
 
        /*
         * First, formulate ns_err message
         */
-       m = m_get(M_DONTWAIT, MT_HEADER);
+       m = m_gethdr(M_DONTWAIT, MT_HEADER);
        if (m == NULL)
        if (m == NULL)
-               goto free;
+               goto freeit;
        m->m_len = sizeof(*ep);
        m->m_len = sizeof(*ep);
-       m->m_off = MMAXOFF - m->m_len;
+       MH_ALIGN(m, m->m_len);
        ep = mtod(m, struct ns_epidp *);
        if ((u_int)type > NS_ERR_TOO_BIG)
                panic("ns_err_error");
        ep = mtod(m, struct ns_epidp *);
        if ((u_int)type > NS_ERR_TOO_BIG)
                panic("ns_err_error");
@@ -113,13 +129,13 @@ ns_error(om, type, param)
        nip->idp_sna = oip->idp_dna;
        if (idpcksum) {
                nip->idp_sum = 0;
        nip->idp_sna = oip->idp_dna;
        if (idpcksum) {
                nip->idp_sum = 0;
-               nip->idp_sum = ns_cksum(dtom(nip), sizeof(*ep));
+               nip->idp_sum = ns_cksum(m, sizeof(*ep));
        } else 
                nip->idp_sum = 0xffff;
        } else 
                nip->idp_sum = 0xffff;
-       (void) ns_output(dtom(nip), (struct route *)0, 0);
+       (void) ns_output(m, (struct route *)0, 0);
 
 
-free:
-       m_freem(dtom(oip));
+freeit:
+       m_freem(om);
 }
 
 ns_printhost(p)
 }
 
 ns_printhost(p)
@@ -159,7 +175,7 @@ ns_err_input(m)
        }
 #endif
        i = sizeof (struct ns_epidp);
        }
 #endif
        i = sizeof (struct ns_epidp);
-       if ((m->m_off > MMAXOFF || m->m_len < i) &&
+       if (((m->m_flags & M_EXT) || m->m_len < i) &&
                (m = m_pullup(m, i)) == 0)  {
                ns_errstat.ns_es_tooshort++;
                return;
                (m = m_pullup(m, i)) == 0)  {
                ns_errstat.ns_es_tooshort++;
                return;
@@ -227,15 +243,15 @@ ns_err_input(m)
                        idp_ctlinput(code, (caddr_t)ep);
                }
                
                        idp_ctlinput(code, (caddr_t)ep);
                }
                
-               goto free;
+               goto freeit;
 
        default:
        badcode:
                ns_errstat.ns_es_badcode++;
 
        default:
        badcode:
                ns_errstat.ns_es_badcode++;
-               goto free;
+               goto freeit;
 
        }
 
        }
-free:
+freeit:
        m_freem(m);
 }
 
        m_freem(m);
 }
 
@@ -252,10 +268,10 @@ nstime()
 }
 #endif
 
 }
 #endif
 
-ns_echo(idp)
-register struct idp *idp;
+ns_echo(m)
+struct mbuf *m;
 {
 {
-       struct mbuf *m = dtom(idp);
+       register struct idp *idp = mtod(m, struct idp *);
        register struct echo {
            struct idp  ec_idp;
            u_short             ec_op; /* Operation, 1 = request, 2 = reply */
        register struct echo {
            struct idp  ec_idp;
            u_short             ec_op; /* Operation, 1 = request, 2 = reply */