Module Name:    src
Committed By:   tls
Date:           Sun Aug 10 06:56:41 UTC 2014

Modified Files:
        src/sys/netnatm [tls-earlyentropy]: natm.c natm.h natm_pcb.c
            natm_proto.c

Log Message:
Rebase.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.24.28.1 src/sys/netnatm/natm.c
cvs rdiff -u -r1.11 -r1.11.28.1 src/sys/netnatm/natm.h
cvs rdiff -u -r1.14 -r1.14.28.1 src/sys/netnatm/natm_pcb.c \
    src/sys/netnatm/natm_proto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netnatm/natm.c
diff -u src/sys/netnatm/natm.c:1.24 src/sys/netnatm/natm.c:1.24.28.1
--- src/sys/netnatm/natm.c:1.24	Wed Mar  9 22:06:42 2011
+++ src/sys/netnatm/natm.c	Sun Aug 10 06:56:41 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: natm.c,v 1.24 2011/03/09 22:06:42 dyoung Exp $	*/
+/*	$NetBSD: natm.c,v 1.24.28.1 2014/08/10 06:56:41 tls Exp $	*/
 
 /*
  * Copyright (c) 1996 Charles D. Cranor and Washington University.
@@ -30,14 +30,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: natm.c,v 1.24 2011/03/09 22:06:42 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: natm.c,v 1.24.28.1 2014/08/10 06:56:41 tls Exp $");
 
 #include <sys/param.h>
+#include <sys/kmem.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/domain.h>
 #include <sys/ioctl.h>
-#include <sys/proc.h>
 #include <sys/protosw.h>
 #include <sys/mbuf.h>
 #include <sys/socket.h>
@@ -46,7 +46,6 @@ __KERNEL_RCSID(0, "$NetBSD: natm.c,v 1.2
 #include <net/if.h>
 #include <net/if_atm.h>
 #include <net/netisr.h>
-#include <net/radix.h>
 #include <net/route.h>
 
 #include <netinet/in.h>
@@ -59,252 +58,421 @@ u_long natm5_recvspace = 16*1024;
 u_long natm0_sendspace = 16*1024;
 u_long natm0_recvspace = 16*1024;
 
-/*
- * user requests
- */
+static int
+natm_attach(struct socket *so, int proto)
+{
+	int error = 0;
+	struct natmpcb *npcb;
 
-int natm_usrreq(so, req, m, nam, control, l)
+	KASSERT(so->so_pcb == NULL);
+	sosetlock(so);
 
-struct socket *so;
-int req;
-struct mbuf *m, *nam, *control;
-struct lwp *l;
+	if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
+		if (proto == PROTO_NATMAAL5)
+			error = soreserve(so, natm5_sendspace, natm5_recvspace);
+		else
+			error = soreserve(so, natm0_sendspace, natm0_recvspace);
+		if (error)
+			return error;
+	}
+	npcb = npcb_alloc(true);
+	npcb->npcb_socket = so;
+	so->so_pcb = npcb;
+	return error;
+}
 
+static void
+natm_detach(struct socket *so)
 {
-  int error = 0, s, s2;
+	struct natmpcb *npcb = (struct natmpcb *)so->so_pcb;
+
+	/*
+	 * we turn on 'drain' *before* we sofree.
+	 */
+
+	npcb_free(npcb, NPCB_DESTROY);	/* drain */
+	so->so_pcb = NULL;
+	/* sofree drops the lock */
+	sofree(so);
+	mutex_enter(softnet_lock);
+}
+
+static int
+natm_accept(struct socket *so, struct mbuf *nam)
+{
+	KASSERT(solocked(so));
+
+	return EOPNOTSUPP;
+}
+
+static int
+natm_bind(struct socket *so, struct mbuf *nam, struct lwp *l)
+{
+	KASSERT(solocked(so));
+
+	return EOPNOTSUPP;
+}
+
+static int
+natm_listen(struct socket *so, struct lwp *l)
+{
+	KASSERT(solocked(so));
+
+	return EOPNOTSUPP;
+}
+
+static int
+natm_connect(struct socket *so, struct mbuf *nam, struct lwp *l)
+{
+	int error = 0, s2;
+	struct natmpcb *npcb;
+	struct sockaddr_natm *snatm;
+	struct atm_pseudoioctl api;
+	struct atm_pseudohdr *aph;
+	struct ifnet *ifp;
+	int proto = so->so_proto->pr_protocol;
+
+	KASSERT(solocked(so));
+
+	/*
+	 * validate nam and npcb
+	 */
+
+	if (nam->m_len != sizeof(*snatm))
+		return EINVAL;
+	snatm = mtod(nam, struct sockaddr_natm *);
+	if (snatm->snatm_len != sizeof(*snatm) ||
+	    (npcb->npcb_flags & NPCB_FREE) == 0)
+		return EINVAL;
+	if (snatm->snatm_family != AF_NATM)
+		return EAFNOSUPPORT;
+
+	snatm->snatm_if[IFNAMSIZ-1] = '\0';  /* XXX ensure null termination
+						since ifunit() uses strcmp */
+
+	/*
+	 * convert interface string to ifp, validate.
+	 */
+
+	ifp = ifunit(snatm->snatm_if);
+	if (ifp == NULL || (ifp->if_flags & IFF_RUNNING) == 0) {
+		return ENXIO;
+	}
+	if (ifp->if_output != atm_output) {
+		return EAFNOSUPPORT;
+	}
+
+	/*
+	 * register us with the NATM PCB layer
+	 */
+
+	if (npcb_add(npcb, ifp, snatm->snatm_vci, snatm->snatm_vpi) != npcb)
+		return EADDRINUSE;
+
+	/*
+	 * enable rx
+	 */
+
+	ATM_PH_FLAGS(&api.aph) = (proto == PROTO_NATMAAL5) ? ATM_PH_AAL5 : 0;
+	ATM_PH_VPI(&api.aph) = npcb->npcb_vpi;
+	ATM_PH_SETVCI(&api.aph, npcb->npcb_vci);
+	api.rxhand = npcb;
+	s2 = splnet();
+	if (ifp->if_ioctl(ifp, SIOCATMENA, &api) != 0) {
+		splx(s2);
+		npcb_free(npcb, NPCB_REMOVE);
+		return EIO;
+	}
+	splx(s2);
+
+	soisconnected(so);
+	return error;
+}
+
+static int
+natm_connect2(struct socket *so, struct socket *so2)
+{
+	KASSERT(solocked(so));
+
+	return EOPNOTSUPP;
+}
+
+static int
+natm_disconnect(struct socket *so)
+{
+	struct natmpcb *npcb = (struct natmpcb *)so->so_pcb;
+
+	KASSERT(solocked(so));
+	KASSERT(npcb != NULL);
+
+	if ((npcb->npcb_flags & NPCB_CONNECTED) == 0) {
+		printf("natm: disconnected check\n");
+		return EIO;
+	}
+	ifp = npcb->npcb_ifp;
+
+	/*
+	 * disable rx
+	 */
+	ATM_PH_FLAGS(&api.aph) = ATM_PH_AAL5;
+	ATM_PH_VPI(&api.aph) = npcb->npcb_vpi;
+	ATM_PH_SETVCI(&api.aph, npcb->npcb_vci);
+	api.rxhand = npcb;
+
+	s2 = splnet();
+	ifp->if_ioctl(ifp, SIOCATMDIS, &api);
+	splx(s);
+
+	npcb_free(npcb, NPCB_REMOVE);
+	soisdisconnected(so);
+	return 0;
+}
+
+static int
+natm_shutdown(struct socket *so)
+{
+	int s;
+
+	KASSERT(solocked(so));
+
+	s = splsoftnet();
+	socantsendmore(so);
+	splx(s);
+
+	return 0;
+}
+
+static int
+natm_abort(struct socket *so)
+{
+	KASSERT(solocked(so));
+
+	return EOPNOTSUPP;
+}
+
+static int
+natm_ioctl(struct socket *so, u_long cmd, void *nam, struct ifnet *ifp)
+{
+  int error = 0, s;
   struct natmpcb *npcb;
-  struct sockaddr_natm *snatm;
-  struct atm_pseudoioctl api;
-  struct atm_pseudohdr *aph;
   struct atm_rawioctl ario;
-  struct ifnet *ifp;
-  int proto = so->so_proto->pr_protocol;
 
   s = SPLSOFTNET();
 
   npcb = (struct natmpcb *) so->so_pcb;
 
-  if (npcb == NULL && req != PRU_ATTACH) {
-    error = EINVAL;
+  /*
+   * raw atm ioctl.   comes in as a SIOCRAWATM.   we convert it to
+   * SIOCXRAWATM and pass it to the driver.
+   */
+  if (cmd == SIOCRAWATM) {
+    if (npcb->npcb_ifp == NULL) {
+      error = ENOTCONN;
+      goto done;
+    }
+    ario.npcb = npcb;
+    ario.rawvalue = *((int *)nam);
+    error = npcb->npcb_ifp->if_ioctl(npcb->npcb_ifp, SIOCXRAWATM, &ario);
+    if (!error) {
+      if (ario.rawvalue)
+	npcb->npcb_flags |= NPCB_RAW;
+      else
+	npcb->npcb_flags &= ~(NPCB_RAW);
+    }
+
     goto done;
   }
 
+  error = EOPNOTSUPP;
 
-  switch (req) {
-    case PRU_ATTACH:			/* attach protocol to up */
+done:
+  splx(s);
+  return(error);
+}
 
-      if (npcb) {
-	error = EISCONN;
-	break;
-      }
-
-      if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
-	if (proto == PROTO_NATMAAL5)
-          error = soreserve(so, natm5_sendspace, natm5_recvspace);
-	else
-          error = soreserve(so, natm0_sendspace, natm0_recvspace);
-        if (error)
-          break;
-      }
+static int
+natm_stat(struct socket *so, struct stat *ub)
+{
+  KASSERT(solocked(so));
 
-      so->so_pcb = (void *) (npcb = npcb_alloc(M_WAITOK));
-      npcb->npcb_socket = so;
+  return 0;
+}
 
-      break;
+static int
+natm_peeraddr(struct socket *so, struct mbuf *nam)
+{
+  struct natmpcb *npcb = (struct natmpcb *) so->so_pcb;
+  struct sockaddr_natm *snatm;
 
-    case PRU_DETACH:			/* detach protocol from up */
+  KASSERT(solocked(so));
+  KASSERT(pcb != NULL);
+  KASSERT(nam != NULL);
+
+  snatm = mtod(nam, struct sockaddr_natm *);
+  memset(snatm, 0, sizeof(*snatm));
+  nam->m_len = snatm->snatm_len = sizeof(*snatm);
+  snatm->snatm_family = AF_NATM;
+  memcpy(snatm->snatm_if, npcb->npcb_ifp->if_xname, sizeof(snatm->snatm_if));
+  snatm->snatm_vci = npcb->npcb_vci;
+  snatm->snatm_vpi = npcb->npcb_vpi;
+  return 0;
+}
 
-      /*
-       * we turn on 'drain' *before* we sofree.
-       */
-
-      npcb_free(npcb, NPCB_DESTROY);	/* drain */
-      so->so_pcb = NULL;
-      /* sofree drops the lock */
-      sofree(so);
-      mutex_enter(softnet_lock);
+static int
+natm_sockaddr(struct socket *so, struct mbuf *nam)
+{
+	KASSERT(solocked(so));
 
-      break;
+	return EOPNOTSUPP;
+}
 
-    case PRU_CONNECT:			/* establish connection to peer */
+static int
+natm_rcvd(struct socket *so, int flags, struct lwp *l)
+{
+	KASSERT(solocked(so));
 
-      /*
-       * validate nam and npcb
-       */
-
-      if (nam->m_len != sizeof(*snatm)) {
-        error = EINVAL;
-	break;
-      }
-      snatm = mtod(nam, struct sockaddr_natm *);
-      if (snatm->snatm_len != sizeof(*snatm) ||
-		(npcb->npcb_flags & NPCB_FREE) == 0) {
-	error = EINVAL;
-	break;
-      }
-      if (snatm->snatm_family != AF_NATM) {
-	error = EAFNOSUPPORT;
-	break;
-      }
+	return EOPNOTSUPP;
+}
 
-      snatm->snatm_if[IFNAMSIZ-1] = '\0';  /* XXX ensure null termination
-						since ifunit() uses strcmp */
+static int
+natm_recvoob(struct socket *so, struct mbuf *m, int flags)
+{
+	KASSERT(solocked(so));
 
-      /*
-       * convert interface string to ifp, validate.
-       */
-
-      ifp = ifunit(snatm->snatm_if);
-      if (ifp == NULL || (ifp->if_flags & IFF_RUNNING) == 0) {
-	error = ENXIO;
-	break;
-      }
-      if (ifp->if_output != atm_output) {
-	error = EAFNOSUPPORT;
-	break;
-      }
-
-
-      /*
-       * register us with the NATM PCB layer
-       */
-
-      if (npcb_add(npcb, ifp, snatm->snatm_vci, snatm->snatm_vpi) != npcb) {
-        error = EADDRINUSE;
-        break;
-      }
-
-      /*
-       * enable rx
-       */
-
-      ATM_PH_FLAGS(&api.aph) = (proto == PROTO_NATMAAL5) ? ATM_PH_AAL5 : 0;
-      ATM_PH_VPI(&api.aph) = npcb->npcb_vpi;
-      ATM_PH_SETVCI(&api.aph, npcb->npcb_vci);
-      api.rxhand = npcb;
-      s2 = splnet();
-      if (ifp->if_ioctl(ifp, SIOCATMENA, &api) != 0) {
-	splx(s2);
-	npcb_free(npcb, NPCB_REMOVE);
-        error = EIO;
-	break;
-      }
-      splx(s2);
+	return EOPNOTSUPP;
+}
 
-      soisconnected(so);
+static int
+natm_send(struct socket *so, struct mbuf *m, struct mbuf *nam,
+    struct mbuf *control)
+{
+	struct natmpcb *npcb = (struct natmpcb *) so->so_pcb;
+	struct atm_pseudohdr *aph;
 
-      break;
+	KASSERT(solocked(so));
+	KASSERT(pcb != NULL);
+	KASSERT(m != NULL);
+
+	if (control && control->m_len) {
+		m_freem(control);
+		m_freem(m);
+		return EINVAL;
+	}
 
-    case PRU_DISCONNECT:		/* disconnect from peer */
+	/*
+	 * send the data.   we must put an atm_pseudohdr on first
+	 */
+	s = SPLSOFTNET();
+	M_PREPEND(m, sizeof(*aph), M_WAITOK);
+	if (m == NULL) {
+		error = ENOBUFS;
+		break;
+	}
+	aph = mtod(m, struct atm_pseudohdr *);
+	ATM_PH_VPI(aph) = npcb->npcb_vpi;
+	ATM_PH_SETVCI(aph, npcb->npcb_vci);
+	ATM_PH_FLAGS(aph) = (proto == PROTO_NATMAAL5) ? ATM_PH_AAL5 : 0;
+	error = atm_output(npcb->npcb_ifp, m, NULL, NULL);
+	splx(s);
 
-      if ((npcb->npcb_flags & NPCB_CONNECTED) == 0) {
-        printf("natm: disconnected check\n");
-        error = EIO;
-	break;
-      }
-      ifp = npcb->npcb_ifp;
-
-      /*
-       * disable rx
-       */
-
-      ATM_PH_FLAGS(&api.aph) = ATM_PH_AAL5;
-      ATM_PH_VPI(&api.aph) = npcb->npcb_vpi;
-      ATM_PH_SETVCI(&api.aph, npcb->npcb_vci);
-      api.rxhand = npcb;
-      s2 = splnet();
-      ifp->if_ioctl(ifp, SIOCATMDIS, &api);
-      splx(s);
+	return error;
+}
 
-      npcb_free(npcb, NPCB_REMOVE);
-      soisdisconnected(so);
+static int
+natm_send(struct socket *so, struct mbuf *m, struct mbuf *nam,
+    struct mbuf *control, struct lwp *l)
+{
+	struct natmpcb *npcb = (struct natmpcb *) so->so_pcb;
+	struct atm_pseudohdr *aph;
 
-      break;
+	KASSERT(solocked(so));
+	KASSERT(pcb != NULL);
+	KASSERT(m != NULL);
+
+	if (control && control->m_len) {
+		m_freem(control);
+		m_freem(m);
+		return EINVAL;
+	}
 
-    case PRU_SHUTDOWN:			/* won't send any more data */
-      socantsendmore(so);
-      break;
+	/*
+	 * send the data.   we must put an atm_pseudohdr on first
+	 */
+	s = SPLSOFTNET();
+	M_PREPEND(m, sizeof(*aph), M_WAITOK);
+	if (m == NULL) {
+		error = ENOBUFS;
+		break;
+	}
+	aph = mtod(m, struct atm_pseudohdr *);
+	ATM_PH_VPI(aph) = npcb->npcb_vpi;
+	ATM_PH_SETVCI(aph, npcb->npcb_vci);
+	ATM_PH_FLAGS(aph) = (proto == PROTO_NATMAAL5) ? ATM_PH_AAL5 : 0;
+	error = atm_output(npcb->npcb_ifp, m, NULL, NULL);
+	splx(s);
 
-    case PRU_SEND:			/* send this data */
-      if (control && control->m_len) {
-	m_freem(control);
-	m_freem(m);
-	error = EINVAL;
-	break;
-      }
-
-      /*
-       * send the data.   we must put an atm_pseudohdr on first
-       */
-
-      M_PREPEND(m, sizeof(*aph), M_WAITOK);
-      if (m == NULL) {
-        error = ENOBUFS;
-	break;
-      }
-      aph = mtod(m, struct atm_pseudohdr *);
-      ATM_PH_VPI(aph) = npcb->npcb_vpi;
-      ATM_PH_SETVCI(aph, npcb->npcb_vci);
-      ATM_PH_FLAGS(aph) = (proto == PROTO_NATMAAL5) ? ATM_PH_AAL5 : 0;
+	return error;
+}
 
-      error = atm_output(npcb->npcb_ifp, m, NULL, NULL);
+static int
+natm_sendoob(struct socket *so, struct mbuf *m, struct mbuf *control)
+{
+	KASSERT(solocked(so));
 
-      break;
+	return EOPNOTSUPP;
+}
 
-    case PRU_SENSE:			/* return status into m */
-      /* return zero? */
-      break;
+static int
+natm_purgeif(struct socket *so, struct ifnet *ifp)
+{
 
-    case PRU_PEERADDR:			/* fetch peer's address */
-      snatm = mtod(nam, struct sockaddr_natm *);
-      memset(snatm, 0, sizeof(*snatm));
-      nam->m_len = snatm->snatm_len = sizeof(*snatm);
-      snatm->snatm_family = AF_NATM;
-      memcpy(snatm->snatm_if, npcb->npcb_ifp->if_xname, sizeof(snatm->snatm_if));
-      snatm->snatm_vci = npcb->npcb_vci;
-      snatm->snatm_vpi = npcb->npcb_vpi;
-      break;
+	return EOPNOTSUPP;
+}
 
-    case PRU_CONTROL:			/* control operations on protocol */
-      /*
-       * raw atm ioctl.   comes in as a SIOCRAWATM.   we convert it to
-       * SIOCXRAWATM and pass it to the driver.
-       */
-      if ((u_long)m == SIOCRAWATM) {
-        if (npcb->npcb_ifp == NULL) {
-          error = ENOTCONN;
-          break;
-        }
-        ario.npcb = npcb;
-        ario.rawvalue = *((int *)nam);
-        error = npcb->npcb_ifp->if_ioctl(npcb->npcb_ifp, SIOCXRAWATM, &ario);
-	if (!error) {
-          if (ario.rawvalue)
-	    npcb->npcb_flags |= NPCB_RAW;
-	  else
-	    npcb->npcb_flags &= ~(NPCB_RAW);
-	}
+/*
+ * user requests
+ */
 
-        break;
-      }
+static int
+natm_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
+    struct mbuf *control, struct lwp *l)
+{
+  int error = 0, s, s2;
+  struct natmpcb *npcb;
+  struct sockaddr_natm *snatm;
+  struct atm_pseudoioctl api;
+  struct atm_pseudohdr *aph;
+  struct ifnet *ifp;
+  int proto = so->so_proto->pr_protocol;
 
-      error = EOPNOTSUPP;
-      break;
+  KASSERT(req != PRU_ATTACH);
+  KASSERT(req != PRU_DETACH);
+  KASSERT(req != PRU_ACCEPT);
+  KASSERT(req != PRU_BIND);
+  KASSERT(req != PRU_LISTEN);
+  KASSERT(req != PRU_CONNECT);
+  KASSERT(req != PRU_CONNECT2);
+  KASSERT(req != PRU_DISCONNECT);
+  KASSERT(req != PRU_SHUTDOWN);
+  KASSERT(req != PRU_ABORT);
+  KASSERT(req != PRU_CONTROL);
+  KASSERT(req != PRU_SENSE);
+  KASSERT(req != PRU_PEERADDR);
+  KASSERT(req != PRU_SOCKADDR);
+  KASSERT(req != PRU_RCVD);
+  KASSERT(req != PRU_RCVOOB);
+  KASSERT(req != PRU_SEND);
+  KASSERT(req != PRU_SENDOOB);
+  KASSERT(req != PRU_PURGEIF);
 
-    case PRU_BIND:			/* bind socket to address */
-    case PRU_LISTEN:			/* listen for connection */
-    case PRU_ACCEPT:			/* accept connection from peer */
-    case PRU_CONNECT2:			/* connect two sockets */
-    case PRU_ABORT:			/* abort (fast DISCONNECT, DETATCH) */
-					/* (only happens if LISTEN socket) */
-    case PRU_RCVD:			/* have taken data; more room now */
+  if (so->so_pcb == NULL)
+	return EINVAL;
+
+  switch (req) {
     case PRU_FASTTIMO:			/* 200ms timeout */
     case PRU_SLOWTIMO:			/* 500ms timeout */
-    case PRU_RCVOOB:			/* retrieve out of band data */
-    case PRU_SENDOOB:			/* send out of band data */
     case PRU_PROTORCV:			/* receive from below */
     case PRU_PROTOSEND:			/* send to below */
-    case PRU_SOCKADDR:			/* fetch socket's address */
 #ifdef DIAGNOSTIC
       printf("natm: PRU #%d unsupported\n", req);
 #endif
@@ -315,8 +483,7 @@ struct lwp *l;
   }
 
 done:
-  splx(s);
-  return(error);
+  return error;
 }
 
 /*
@@ -361,7 +528,7 @@ next:
   if (npcb->npcb_flags & NPCB_DRAIN) {
     m_freem(m);
     if (npcb->npcb_inq == 0)
-      free(npcb, M_PCB);			/* done! */
+      kmem_intr_free(npcb, sizeof(*npcb));
     goto next;
   }
 
@@ -396,3 +563,48 @@ m->m_pkthdr.rcvif = NULL;	/* null it out
 
   goto next;
 }
+
+PR_WRAP_USRREQS(natm)
+#define	natm_attach	natm_attach_wrapper
+#define	natm_detach	natm_detach_wrapper
+#define	natm_accept	natm_accept_wrapper
+#define	natm_bind	natm_bind_wrapper
+#define	natm_listen	natm_listen_wrapper
+#define	natm_connect	natm_connect_wrapper
+#define	natm_connect2	natm_connect2_wrapper
+#define	natm_disconnect	natm_disconnect_wrapper
+#define	natm_shutdown	natm_shutdown_wrapper
+#define	natm_abort	natm_abort_wrapper
+#define	natm_ioctl	natm_ioctl_wrapper
+#define	natm_stat	natm_stat_wrapper
+#define	natm_peeraddr	natm_peeraddr_wrapper
+#define	natm_sockaddr	natm_sockaddr_wrapper
+#define	natm_rcvd	natm_rcvd_wrapper
+#define	natm_recvoob	natm_recvoob_wrapper
+#define	natm_send	natm_send_wrapper
+#define	natm_sendoob	natm_sendoob_wrapper
+#define	natm_purgeif	natm_purgeif_wrapper
+#define	natm_usrreq	natm_usrreq_wrapper
+
+const struct pr_usrreqs natm_usrreqs = {
+	.pr_attach	= natm_attach,
+	.pr_detach	= natm_detach,
+	.pr_accept	= natm_accept,
+	.pr_bind	= natm_bind,
+	.pr_listen	= natm_listen,
+	.pr_connect	= natm_connect,
+	.pr_connect2	= natm_connect2,
+	.pr_disconnect	= natm_disconnect,
+	.pr_shutdown	= natm_shutdown,
+	.pr_abort	= natm_abort,
+	.pr_ioctl	= natm_ioctl,
+	.pr_stat	= natm_stat,
+	.pr_peeraddr	= natm_peeraddr,
+	.pr_sockaddr	= natm_sockaddr,
+	.pr_rcvd	= natm_rcvd,
+	.pr_recvoob	= natm_recvoob,
+	.pr_send	= natm_send,
+	.pr_sendoob	= natm_sendoob,
+	.pr_purgeif	= natm_purgeif,
+	.pr_generic	= natm_usrreq,
+};

Index: src/sys/netnatm/natm.h
diff -u src/sys/netnatm/natm.h:1.11 src/sys/netnatm/natm.h:1.11.28.1
--- src/sys/netnatm/natm.h:1.11	Tue Feb  1 19:40:24 2011
+++ src/sys/netnatm/natm.h	Sun Aug 10 06:56:41 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: natm.h,v 1.11 2011/02/01 19:40:24 chuck Exp $	*/
+/*	$NetBSD: natm.h,v 1.11.28.1 2014/08/10 06:56:41 tls Exp $	*/
 
 /*
  * Copyright (c) 1996 Charles D. Cranor and Washington University.
@@ -119,6 +119,8 @@ extern	u_int natm_sookcnt,
 		natm_sookbytes;		/* account of ok */
 #endif
 
+extern const struct pr_usrreqs natm_usrreqs;
+
 /* atm_rawioctl: kernel's version of SIOCRAWATM [for internal use only!] */
 struct atm_rawioctl {
   struct natmpcb *npcb;
@@ -129,18 +131,11 @@ struct atm_rawioctl {
 /* external functions */
 
 /* natm_pcb.c */
-struct	natmpcb *npcb_alloc(int);
+struct	natmpcb *npcb_alloc(bool);
 void	npcb_free(struct natmpcb *, int);
-struct	natmpcb *npcb_add(struct natmpcb *, struct ifnet *, int, int);
+struct	natmpcb *npcb_add(struct natmpcb *, struct ifnet *, u_int16_t, u_int8_t);
 
 /* natm.c */
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int	natm_usrreq(struct socket *, int, struct mbuf *,
-                             struct mbuf *, struct mbuf *, struct lwp *);
-#elif defined(__FreeBSD__)
-int	natm_usrreq(struct socket *, int, struct mbuf *,
-                             struct mbuf *, struct mbuf *);
-#endif
 int	natm0_sysctl(int *, u_int, void *, size_t *, void *, size_t);
 int	natm5_sysctl(int *, u_int, void *, size_t *, void *, size_t);
 void	natmintr(void);

Index: src/sys/netnatm/natm_pcb.c
diff -u src/sys/netnatm/natm_pcb.c:1.14 src/sys/netnatm/natm_pcb.c:1.14.28.1
--- src/sys/netnatm/natm_pcb.c:1.14	Tue Feb  1 19:40:24 2011
+++ src/sys/netnatm/natm_pcb.c	Sun Aug 10 06:56:41 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: natm_pcb.c,v 1.14 2011/02/01 19:40:24 chuck Exp $	*/
+/*	$NetBSD: natm_pcb.c,v 1.14.28.1 2014/08/10 06:56:41 tls Exp $	*/
 
 /*
  * Copyright (c) 1996 Charles D. Cranor and Washington University.
@@ -31,18 +31,18 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: natm_pcb.c,v 1.14 2011/02/01 19:40:24 chuck Exp $");
+__KERNEL_RCSID(0, "$NetBSD: natm_pcb.c,v 1.14.28.1 2014/08/10 06:56:41 tls Exp $");
 
 #include "opt_ddb.h"
 
 #include <sys/param.h>
+#include <sys/kmem.h>
 #include <sys/systm.h>
 #include <sys/queue.h>
 #include <sys/socket.h>
 #include <sys/protosw.h>
 #include <sys/domain.h>
 #include <sys/mbuf.h>
-#include <sys/malloc.h>
 
 #include <net/if.h>
 #include <net/radix.h>
@@ -56,21 +56,13 @@ __KERNEL_RCSID(0, "$NetBSD: natm_pcb.c,v
  * npcb_alloc: allocate a npcb [in the free state]
  */
 
-struct natmpcb *npcb_alloc(wait)
-
-int wait;
-
+struct natmpcb *
+npcb_alloc(bool wait)
 {
   struct natmpcb *npcb;
 
-  npcb = malloc(sizeof(*npcb), M_PCB, wait);
-
-#ifdef DIAGNOSTIC
-  if (wait == M_WAITOK && npcb == NULL) panic("npcb_alloc: malloc didn't wait");
-#endif
-
+  npcb = kmem_intr_zalloc(sizeof(*npcb), wait ? KM_SLEEP : KM_NOSLEEP);
   if (npcb) {
-    memset(npcb, 0, sizeof(*npcb));
     npcb->npcb_flags = NPCB_FREE;
   }
   return(npcb);
@@ -81,11 +73,8 @@ int wait;
  * npcb_free: free a npcb
  */
 
-void npcb_free(npcb, op)
-
-struct natmpcb *npcb;
-int op;
-
+void
+npcb_free(struct natmpcb *npcb, int op)
 {
   int s = splnet();
 
@@ -95,9 +84,9 @@ int op;
   }
   if (op == NPCB_DESTROY) {
     if (npcb->npcb_inq) {
-      npcb->npcb_flags = NPCB_DRAIN;	/* flag for distruction */
+      npcb->npcb_flags = NPCB_DRAIN;	/* flag for destruction */
     } else {
-      free(npcb, M_PCB);		/* kill it! */
+      kmem_intr_free(npcb, sizeof(*npcb));
     }
   }
 
@@ -110,13 +99,9 @@ int op;
  *   returns npcb if ok
  */
 
-struct natmpcb *npcb_add(npcb, ifp, vci, vpi)
-
-struct natmpcb *npcb;
-struct ifnet *ifp;
-u_int16_t vci;
-u_int8_t vpi;
-
+struct natmpcb *
+npcb_add(struct natmpcb *npcb, struct ifnet *ifp,
+	u_int16_t vci, u_int8_t vpi)
 {
   struct natmpcb *cpcb = NULL;		/* current pcb */
   int s = splnet();
@@ -146,7 +131,7 @@ u_int8_t vpi;
    */
 
   if (npcb == NULL) {
-    cpcb = npcb_alloc(M_NOWAIT);	/* could be called from lower half */
+    cpcb = npcb_alloc(false);	/* could be called from lower half */
     if (cpcb == NULL)
       goto done;			/* fail */
   } else {
Index: src/sys/netnatm/natm_proto.c
diff -u src/sys/netnatm/natm_proto.c:1.14 src/sys/netnatm/natm_proto.c:1.14.28.1
--- src/sys/netnatm/natm_proto.c:1.14	Tue Feb  1 19:40:24 2011
+++ src/sys/netnatm/natm_proto.c	Sun Aug 10 06:56:41 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: natm_proto.c,v 1.14 2011/02/01 19:40:24 chuck Exp $	*/
+/*	$NetBSD: natm_proto.c,v 1.14.28.1 2014/08/10 06:56:41 tls Exp $	*/
 
 /*
  * Copyright (c) 1996 Charles D. Cranor and Washington University.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: natm_proto.c,v 1.14 2011/02/01 19:40:24 chuck Exp $");
+__KERNEL_RCSID(0, "$NetBSD: natm_proto.c,v 1.14.28.1 2014/08/10 06:56:41 tls Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -42,7 +42,6 @@ __KERNEL_RCSID(0, "$NetBSD: natm_proto.c
 #include <sys/mbuf.h>
 
 #include <net/if.h>
-#include <net/radix.h>
 #include <net/route.h>
 
 #include <netinet/in.h>
@@ -57,10 +56,6 @@ struct npcblist natm_pcbs = LIST_HEAD_IN
 struct	ifqueue natmintrq;       	/* natm packet input queue */
 int	natmqmaxlen = IFQ_MAXLEN;	/* max # of packets on queue */
 
-PR_WRAP_USRREQ(natm_usrreq)
-
-#define	natm_usrreq	natm_usrreq_wrapper
-
 const struct protosw natmsw[] = {
 { .pr_type = SOCK_STREAM,
   .pr_domain = &natmdomain,
@@ -70,7 +65,7 @@ const struct protosw natmsw[] = {
   .pr_output = 0,
   .pr_ctlinput = 0,
   .pr_ctloutput = 0,
-  .pr_usrreq = natm_usrreq,
+  .pr_usrreqs = &natm_usrreq,
   .pr_init = 0,
   .pr_fasttimo = 0,
   .pr_slowtimo = 0,
@@ -84,7 +79,7 @@ const struct protosw natmsw[] = {
   .pr_output = 0,
   .pr_ctlinput = 0,
   .pr_ctloutput = 0,
-  .pr_usrreq = natm_usrreq,
+  .pr_usrreqs = &natm_usrreq,
   .pr_init = 0,
   .pr_fasttimo = 0,
   .pr_slowtimo = 0,
@@ -98,7 +93,7 @@ const struct protosw natmsw[] = {
   .pr_output = 0,
   .pr_ctlinput = 0,
   .pr_ctloutput = 0,
-  .pr_usrreq = natm_usrreq,
+  .pr_usrreqs = &natm_usrreqs,
   .pr_init = 0,
   .pr_fasttimo = 0,
   .pr_slowtimo = 0,

Reply via email to