install correct aliases file
[unix-history] / usr / src / sys / net / raw_usrreq.c
index b456437..c6a94e9 100644 (file)
@@ -1,17 +1,36 @@
-/*     raw_usrreq.c    4.26    83/05/27        */
+/*
+ * Copyright (c) 1980, 1986 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, 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'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *     @(#)raw_usrreq.c        7.4 (Berkeley) %G%
+ */
 
 
-#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 "../machine/mtpr.h"
 
 /*
  * Initialize raw connection block q.
 
 /*
  * Initialize raw connection block q.
@@ -76,7 +95,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 +107,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 +127,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 +170,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;
@@ -174,13 +190,13 @@ raw_usrreq(so, req, m, nam, rights)
        case PRU_ATTACH:
                if ((so->so_state & SS_PRIV) == 0) {
                        error = EACCES;
        case PRU_ATTACH:
                if ((so->so_state & SS_PRIV) == 0) {
                        error = EACCES;
-                       goto release;
+                       break;
                }
                if (rp) {
                        error = EINVAL;
                }
                if (rp) {
                        error = EINVAL;
-                       goto release;
+                       break;
                }
                }
-               error = raw_attach(so);
+               error = raw_attach(so, (int)nam);
                break;
 
        /*
                break;
 
        /*
@@ -190,7 +206,7 @@ raw_usrreq(so, req, m, nam, rights)
        case PRU_DETACH:
                if (rp == 0) {
                        error = ENOTCONN;
        case PRU_DETACH:
                if (rp == 0) {
                        error = ENOTCONN;
-                       goto release;
+                       break;
                }
                raw_detach(rp);
                break;
                }
                raw_detach(rp);
                break;
@@ -204,16 +220,20 @@ raw_usrreq(so, req, m, nam, rights)
        case PRU_CONNECT:
                if (rp->rcb_flags & RAW_FADDR) {
                        error = EISCONN;
        case PRU_CONNECT:
                if (rp->rcb_flags & RAW_FADDR) {
                        error = EISCONN;
-                       goto release;
+                       break;
                }
                raw_connaddr(rp, nam);
                soisconnected(so);
                break;
 
                }
                raw_connaddr(rp, nam);
                soisconnected(so);
                break;
 
+       case PRU_CONNECT2:
+               error = EOPNOTSUPP;
+               goto release;
+
        case PRU_BIND:
                if (rp->rcb_flags & RAW_LADDR) {
                        error = EINVAL;                 /* XXX */
        case PRU_BIND:
                if (rp->rcb_flags & RAW_LADDR) {
                        error = EINVAL;                 /* XXX */
-                       goto release;
+                       break;
                }
                error = raw_bind(so, nam);
                break;
                }
                error = raw_bind(so, nam);
                break;
@@ -221,7 +241,7 @@ raw_usrreq(so, req, m, nam, rights)
        case PRU_DISCONNECT:
                if ((rp->rcb_flags & RAW_FADDR) == 0) {
                        error = ENOTCONN;
        case PRU_DISCONNECT:
                if ((rp->rcb_flags & RAW_FADDR) == 0) {
                        error = ENOTCONN;
-                       goto release;
+                       break;
                }
                raw_disconnect(rp);
                soisdisconnected(so);
                }
                raw_disconnect(rp);
                soisdisconnected(so);
@@ -242,12 +262,12 @@ raw_usrreq(so, req, m, nam, rights)
                if (nam) {
                        if (rp->rcb_flags & RAW_FADDR) {
                                error = EISCONN;
                if (nam) {
                        if (rp->rcb_flags & RAW_FADDR) {
                                error = EISCONN;
-                               goto release;
+                               break;
                        }
                        raw_connaddr(rp, nam);
                } else if ((rp->rcb_flags & RAW_FADDR) == 0) {
                        error = ENOTCONN;
                        }
                        raw_connaddr(rp, nam);
                } else if ((rp->rcb_flags & RAW_FADDR) == 0) {
                        error = ENOTCONN;
-                       goto release;
+                       break;
                }
                error = (*so->so_proto->pr_output)(m, so);
                m = NULL;
                }
                error = (*so->so_proto->pr_output)(m, so);
                m = NULL;
@@ -261,14 +281,21 @@ raw_usrreq(so, req, m, nam, rights)
                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_SENDOOB:
                error = EOPNOTSUPP;
                break;
@@ -279,6 +306,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");
        }