BSD 4_3 release
[unix-history] / usr / src / sys / net / raw_usrreq.c
index 685e0a7..b619886 100644 (file)
@@ -1,15 +1,23 @@
-/*     raw_usrreq.c    4.28    83/06/14        */
+/*
+ * 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) 6/4/86
+ */
 
 
-#include "../h/param.h"
-#include "../h/mbuf.h"
-#include "../h/protosw.h"
-#include "../h/socket.h"
-#include "../h/socketvar.h"
-#include "../h/errno.h"
+#include "param.h"
+#include "mbuf.h"
+#include "domain.h"
+#include "protosw.h"
+#include "socket.h"
+#include "socketvar.h"
+#include "errno.h"
 
 
-#include "../net/if.h"
-#include "../net/netisr.h"
-#include "../net/raw_cb.h"
+#include "if.h"
+#include "route.h"
+#include "netisr.h"
+#include "raw_cb.h"
 
 #include "../vax/mtpr.h"
 
 
 #include "../vax/mtpr.h"
 
@@ -76,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;
 
@@ -89,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
@@ -110,36 +116,33 @@ next:
                        continue;
                if (last) {
                        struct mbuf *n;
                        continue;
                if (last) {
                        struct mbuf *n;
-                       if ((n = m_copy(m->m_next, 0, (int)M_COPYALL)) == 0)
-                               goto nospace;
-                       if (sbappendaddr(&last->so_rcv, &rh->raw_src,
-                           n, (struct mbuf *)0) == 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,
                if (sbappendaddr(&last->so_rcv, &rh->raw_src,
-                   m, (struct mbuf *)0) == 0)
-                       goto drop;
-               sorwakeup(last);
-               goto next;
-       }
-drop:
-       m_freem(m);
+                   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;
 }
 
 /*ARGSUSED*/
 raw_ctlinput(cmd, arg)
        int cmd;
        goto next;
 }
 
 /*ARGSUSED*/
 raw_ctlinput(cmd, arg)
        int cmd;
-       caddr_t arg;
+       struct sockaddr *arg;
 {
 
        if (cmd < 0 || cmd > PRC_NCMDS)
 {
 
        if (cmd < 0 || cmd > PRC_NCMDS)
@@ -156,6 +159,8 @@ raw_usrreq(so, req, m, nam, rights)
        register struct rawcb *rp = sotorawcb(so);
        register int error = 0;
 
        register struct rawcb *rp = sotorawcb(so);
        register int error = 0;
 
+       if (req == PRU_CONTROL)
+               return (EOPNOTSUPP);
        if (rights && rights->m_len) {
                error = EOPNOTSUPP;
                goto release;
        if (rights && rights->m_len) {
                error = EOPNOTSUPP;
                goto release;
@@ -180,7 +185,7 @@ raw_usrreq(so, req, m, nam, rights)
                        error = EINVAL;
                        break;
                }
                        error = EINVAL;
                        break;
                }
-               error = raw_attach(so);
+               error = raw_attach(so, (int)nam);
                break;
 
        /*
                break;
 
        /*
@@ -265,18 +270,21 @@ raw_usrreq(so, req, m, nam, rights)
                soisdisconnected(so);
                break;
 
                soisdisconnected(so);
                break;
 
-       case PRU_CONTROL:
-               m = NULL;
-               error = EOPNOTSUPP;
-               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_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_SENDOOB:
                error = EOPNOTSUPP;
                break;
@@ -287,6 +295,12 @@ raw_usrreq(so, req, m, nam, rights)
                nam->m_len = sizeof (struct sockaddr);
                break;
 
                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");
        }
        default:
                panic("raw_usrreq");
        }