MCLALLOC must be called at splimp
[unix-history] / usr / src / sys / net / raw_usrreq.c
index 3c83a9d..cff9e6c 100644 (file)
@@ -1,18 +1,25 @@
-/*     raw_usrreq.c    4.17    82/06/20        */
-
-#include "../h/param.h"
-#include "../h/mbuf.h"
-#include "../h/protosw.h"
-#include "../h/socket.h"
-#include "../h/socketvar.h"
-#include "../h/mtpr.h"
-#include "../net/in.h"
-#include "../net/in_systm.h"
-#include "../net/if.h"
-#include "../net/raw_cb.h"
-#include <errno.h>
-
-int    rawqmaxlen = IFQ_MAXLEN;
+/*
+ * Copyright (c) 1980, 1986 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)raw_usrreq.c        7.1 (Berkeley) %G%
+ */
+
+#include "param.h"
+#include "mbuf.h"
+#include "domain.h"
+#include "protosw.h"
+#include "socket.h"
+#include "socketvar.h"
+#include "errno.h"
+
+#include "if.h"
+#include "route.h"
+#include "netisr.h"
+#include "raw_cb.h"
+
+#include "../vax/mtpr.h"
 
 /*
  * Initialize raw connection block q.
 
 /*
  * Initialize raw connection block q.
@@ -39,13 +46,12 @@ raw_input(m0, proto, src, dst)
        /*
         * Rip off an mbuf for a generic header.
         */
        /*
         * Rip off an mbuf for a generic header.
         */
-       m = m_get(M_DONTWAIT);
+       m = m_get(M_DONTWAIT, MT_HEADER);
        if (m == 0) {
                m_freem(m0);
                return;
        }
        m->m_next = m0;
        if (m == 0) {
                m_freem(m0);
                return;
        }
        m->m_next = m0;
-       m->m_off = MMINOFF;
        m->m_len = sizeof(struct raw_header);
        rh = mtod(m, struct raw_header *);
        rh->raw_dst = *dst;
        m->m_len = sizeof(struct raw_header);
        rh = mtod(m, struct raw_header *);
        rh->raw_dst = *dst;
@@ -78,7 +84,6 @@ rawintr()
        int s;
        struct mbuf *m;
        register struct rawcb *rp;
        int s;
        struct mbuf *m;
        register struct rawcb *rp;
-       register struct protosw *lproto;
        register struct raw_header *rh;
        struct socket *last;
 
        register struct raw_header *rh;
        struct socket *last;
 
@@ -91,11 +96,10 @@ next:
        rh = mtod(m, struct raw_header *);
        last = 0;
        for (rp = rawcb.rcb_next; rp != &rawcb; rp = rp->rcb_next) {
        rh = mtod(m, struct raw_header *);
        last = 0;
        for (rp = rawcb.rcb_next; rp != &rawcb; rp = rp->rcb_next) {
-               lproto = rp->rcb_socket->so_proto;
-               if (lproto->pr_family != rh->raw_proto.sp_family)
+               if (rp->rcb_proto.sp_family != rh->raw_proto.sp_family)
                        continue;
                        continue;
-               if (lproto->pr_protocol &&
-                   lproto->pr_protocol != rh->raw_proto.sp_protocol)
+               if (rp->rcb_proto.sp_protocol  &&
+                   rp->rcb_proto.sp_protocol != rh->raw_proto.sp_protocol)
                        continue;
                /*
                 * We assume the lower level routines have
                        continue;
                /*
                 * We assume the lower level routines have
@@ -112,52 +116,59 @@ next:
                        continue;
                if (last) {
                        struct mbuf *n;
                        continue;
                if (last) {
                        struct mbuf *n;
-                       if (n = m_copy(m->m_next, 0, (int)M_COPYALL))
-                               goto nospace;
-                       if (sbappendaddr(&last->so_rcv, &rh->raw_src, n)==0) {
-                               /* should notify about lost packet */
-                               m_freem(n);
-                               goto nospace;
+                       if (n = m_copy(m->m_next, 0, (int)M_COPYALL)) {
+                               if (sbappendaddr(&last->so_rcv, &rh->raw_src,
+                                   n, (struct mbuf *)0) == 0)
+                                       /* should notify about lost packet */
+                                       m_freem(n);
+                               else
+                                       sorwakeup(last);
                        }
                        }
-                       sorwakeup(last);
                }
                }
-nospace:
                last = rp->rcb_socket;
        }
        if (last) {
                last = rp->rcb_socket;
        }
        if (last) {
-               m = m_free(m);          /* header */
-               if (sbappendaddr(&last->so_rcv, &rh->raw_src, m) == 0)
-                       goto drop;
-               sorwakeup(last);
-               goto next;
-       }
-drop:
-       m_freem(m);
+               if (sbappendaddr(&last->so_rcv, &rh->raw_src,
+                   m->m_next, (struct mbuf *)0) == 0)
+                       m_freem(m->m_next);
+               else
+                       sorwakeup(last);
+               (void) m_free(m);               /* header */
+       } else
+               m_freem(m);
        goto next;
 }
 
        goto next;
 }
 
+/*ARGSUSED*/
 raw_ctlinput(cmd, arg)
        int cmd;
 raw_ctlinput(cmd, arg)
        int cmd;
-       caddr_t arg;
+       struct sockaddr *arg;
 {
 
        if (cmd < 0 || cmd > PRC_NCMDS)
                return;
 {
 
        if (cmd < 0 || cmd > PRC_NCMDS)
                return;
+       /* INCOMPLETE */
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
-raw_usrreq(so, req, m, addr)
+raw_usrreq(so, req, m, nam, rights)
        struct socket *so;
        int req;
        struct socket *so;
        int req;
-       struct mbuf *m;
-       caddr_t addr;
+       struct mbuf *m, *nam, *rights;
 {
        register struct rawcb *rp = sotorawcb(so);
 {
        register struct rawcb *rp = sotorawcb(so);
-       int error = 0;
-
-       if (rp == 0 && req != PRU_ATTACH)
-               return (EINVAL);
+       register int error = 0;
 
 
+       if (req == PRU_CONTROL)
+               return (EOPNOTSUPP);
+       if (rights && rights->m_len) {
+               error = EOPNOTSUPP;
+               goto release;
+       }
+       if (rp == 0 && req != PRU_ATTACH) {
+               error = EINVAL;
+               goto release;
+       }
        switch (req) {
 
        /*
        switch (req) {
 
        /*
@@ -166,11 +177,15 @@ raw_usrreq(so, req, m, addr)
         * the appropriate raw interface routine.
         */
        case PRU_ATTACH:
         * the appropriate raw interface routine.
         */
        case PRU_ATTACH:
-               if ((so->so_state & SS_PRIV) == 0)
-                       return (EACCES);
-               if (rp)
-                       return (EINVAL);
-               error = raw_attach(so, (struct sockaddr *)addr);
+               if ((so->so_state & SS_PRIV) == 0) {
+                       error = EACCES;
+                       break;
+               }
+               if (rp) {
+                       error = EINVAL;
+                       break;
+               }
+               error = raw_attach(so, (int)nam);
                break;
 
        /*
                break;
 
        /*
@@ -178,8 +193,10 @@ raw_usrreq(so, req, m, addr)
         * Flush data or not depending on the options.
         */
        case PRU_DETACH:
         * Flush data or not depending on the options.
         */
        case PRU_DETACH:
-               if (rp == 0)
-                       return (ENOTCONN);
+               if (rp == 0) {
+                       error = ENOTCONN;
+                       break;
+               }
                raw_detach(rp);
                break;
 
                raw_detach(rp);
                break;
 
@@ -190,15 +207,31 @@ raw_usrreq(so, req, m, addr)
         * nothing else around it should go to). 
         */
        case PRU_CONNECT:
         * nothing else around it should go to). 
         */
        case PRU_CONNECT:
-               if (rp->rcb_flags & RAW_FADDR)
-                       return (EISCONN);
-               raw_connaddr(rp, (struct sockaddr *)addr);
+               if (rp->rcb_flags & RAW_FADDR) {
+                       error = EISCONN;
+                       break;
+               }
+               raw_connaddr(rp, nam);
                soisconnected(so);
                break;
 
                soisconnected(so);
                break;
 
+       case PRU_CONNECT2:
+               error = EOPNOTSUPP;
+               goto release;
+
+       case PRU_BIND:
+               if (rp->rcb_flags & RAW_LADDR) {
+                       error = EINVAL;                 /* XXX */
+                       break;
+               }
+               error = raw_bind(so, nam);
+               break;
+
        case PRU_DISCONNECT:
        case PRU_DISCONNECT:
-               if ((rp->rcb_flags & RAW_FADDR) == 0)
-                       return (ENOTCONN);
+               if ((rp->rcb_flags & RAW_FADDR) == 0) {
+                       error = ENOTCONN;
+                       break;
+               }
                raw_disconnect(rp);
                soisdisconnected(so);
                break;
                raw_disconnect(rp);
                soisdisconnected(so);
                break;
@@ -215,14 +248,19 @@ raw_usrreq(so, req, m, addr)
         * routine handles any massaging necessary.
         */
        case PRU_SEND:
         * routine handles any massaging necessary.
         */
        case PRU_SEND:
-               if (addr) {
-                       if (rp->rcb_flags & RAW_FADDR)
-                               return (EISCONN);
-                       raw_connaddr(rp, (struct sockaddr *)addr);
-               } else if ((rp->rcb_flags & RAW_FADDR) == 0)
-                       return (ENOTCONN);
+               if (nam) {
+                       if (rp->rcb_flags & RAW_FADDR) {
+                               error = EISCONN;
+                               break;
+                       }
+                       raw_connaddr(rp, nam);
+               } else if ((rp->rcb_flags & RAW_FADDR) == 0) {
+                       error = ENOTCONN;
+                       break;
+               }
                error = (*so->so_proto->pr_output)(m, so);
                error = (*so->so_proto->pr_output)(m, so);
-               if (addr)
+               m = NULL;
+               if (nam)
                        rp->rcb_flags &= ~RAW_FADDR;
                break;
 
                        rp->rcb_flags &= ~RAW_FADDR;
                break;
 
@@ -232,24 +270,42 @@ raw_usrreq(so, req, m, addr)
                soisdisconnected(so);
                break;
 
                soisdisconnected(so);
                break;
 
+       case PRU_SENSE:
+               /*
+                * stat: don't bother with a blocksize.
+                */
+               return (0);
+
        /*
         * Not supported.
         */
        /*
         * Not supported.
         */
-       case PRU_ACCEPT:
-       case PRU_RCVD:
-       case PRU_CONTROL:
-       case PRU_SENSE:
        case PRU_RCVOOB:
        case PRU_RCVOOB:
+       case PRU_RCVD:
+               return(EOPNOTSUPP);
+
+       case PRU_LISTEN:
+       case PRU_ACCEPT:
        case PRU_SENDOOB:
                error = EOPNOTSUPP;
                break;
 
        case PRU_SOCKADDR:
        case PRU_SENDOOB:
                error = EOPNOTSUPP;
                break;
 
        case PRU_SOCKADDR:
-               bcopy(addr, (caddr_t)&rp->rcb_laddr, sizeof (struct sockaddr));
+               bcopy((caddr_t)&rp->rcb_laddr, mtod(nam, caddr_t),
+                   sizeof (struct sockaddr));
+               nam->m_len = sizeof (struct sockaddr);
+               break;
+
+       case PRU_PEERADDR:
+               bcopy((caddr_t)&rp->rcb_faddr, mtod(nam, caddr_t),
+                   sizeof (struct sockaddr));
+               nam->m_len = sizeof (struct sockaddr);
                break;
 
        default:
                panic("raw_usrreq");
        }
                break;
 
        default:
                panic("raw_usrreq");
        }
+release:
+       if (m != NULL)
+               m_freem(m);
        return (error);
 }
        return (error);
 }