summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2006-04-01 15:42:02 +0000
committerrwatson <rwatson@FreeBSD.org>2006-04-01 15:42:02 +0000
commit5479e5d69217e0a6876338fc7cde604067b679ca (patch)
tree7431f8c0d78c14bc446d524dcda6a00888732015
parent68ff3be0b395955e8feac72262824b90a155a710 (diff)
downloadFreeBSD-src-5479e5d69217e0a6876338fc7cde604067b679ca.zip
FreeBSD-src-5479e5d69217e0a6876338fc7cde604067b679ca.tar.gz
Chance protocol switch method pru_detach() so that it returns void
rather than an error. Detaches do not "fail", they other occur or the protocol flags SS_PROTOREF to take ownership of the socket. soclose() no longer looks at so_pcb to see if it's NULL, relying entirely on the protocol to decide whether it's time to free the socket or not using SS_PROTOREF. so_pcb is now entirely owned and managed by the protocol code. Likewise, no longer test so_pcb in other socket functions, such as soreceive(), which have no business digging into protocol internals. Protocol detach routines no longer try to free the socket on detach, this is performed in the socket code if the protocol permits it. In rts_detach(), no longer test for rp != NULL in detach, and likewise in other protocols that don't permit a NULL so_pcb, reduce the incidence of testing for it during detach. netinet and netinet6 are not fully updated to this change, which will be in an upcoming commit. In their current state they may leak memory or panic. MFC after: 3 months
-rw-r--r--sys/kern/uipc_sockbuf.c4
-rw-r--r--sys/kern/uipc_socket.c38
-rw-r--r--sys/kern/uipc_socket2.c4
-rw-r--r--sys/kern/uipc_usrreq.c3
-rw-r--r--sys/net/raw_cb.c7
-rw-r--r--sys/net/raw_usrreq.c5
-rw-r--r--sys/net/rtsock.c42
-rw-r--r--sys/netatalk/ddp_usrreq.c3
-rw-r--r--sys/netatm/atm_aal5.c10
-rw-r--r--sys/netatm/atm_socket.c17
-rw-r--r--sys/netatm/atm_usrreq.c2
-rw-r--r--sys/netatm/atm_var.h2
-rw-r--r--sys/netgraph/bluetooth/include/ng_btsocket_hci_raw.h2
-rw-r--r--sys/netgraph/bluetooth/include/ng_btsocket_l2cap.h4
-rw-r--r--sys/netgraph/bluetooth/include/ng_btsocket_rfcomm.h2
-rw-r--r--sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c13
-rw-r--r--sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c13
-rw-r--r--sys/netgraph/bluetooth/socket/ng_btsocket_l2cap_raw.c12
-rw-r--r--sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c10
-rw-r--r--sys/netgraph/ng_socket.c12
-rw-r--r--sys/netinet/ip_divert.c5
-rw-r--r--sys/netinet/raw_ip.c5
-rw-r--r--sys/netinet/tcp_usrreq.c6
-rw-r--r--sys/netinet/udp_usrreq.c6
-rw-r--r--sys/netinet6/raw_ip6.c3
-rw-r--r--sys/netinet6/udp6_usrreq.c7
-rw-r--r--sys/netipsec/keysock.c20
-rw-r--r--sys/netipx/ipx_usrreq.c5
-rw-r--r--sys/netipx/spx_usrreq.c5
-rw-r--r--sys/netkey/keysock.c21
-rw-r--r--sys/netnatm/natm.c5
-rw-r--r--sys/sys/protosw.h4
32 files changed, 114 insertions, 183 deletions
diff --git a/sys/kern/uipc_sockbuf.c b/sys/kern/uipc_sockbuf.c
index be9084b..4afe8c5 100644
--- a/sys/kern/uipc_sockbuf.c
+++ b/sys/kern/uipc_sockbuf.c
@@ -1335,10 +1335,10 @@ pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data,
return EOPNOTSUPP;
}
-int
+void
pru_detach_notsupp(struct socket *so)
{
- return EOPNOTSUPP;
+
}
int
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index 35bb147..dadb06d 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -387,13 +387,18 @@ solisten_proto(so, backlog)
/*
* Attempt to free a socket. This should really be sotryfree().
*
- * We free the socket if the protocol is no longer interested in the socket,
- * there's no file descriptor reference, and the refcount is 0. While the
- * calling macro sotryfree() tests the refcount, sofree() has to test it
- * again as it's possible to race with an accept()ing thread if the socket is
- * in an listen queue of a listen socket, as being in the listen queue
- * doesn't elevate the reference count. sofree() acquires the accept mutex
- * early for this test in order to avoid that race.
+ * sofree() will succeed if:
+ *
+ * - There are no outstanding file descriptor references or related consumers
+ * (so_count == 0).
+ *
+ * - The socket has been closed by user space, if ever open (SS_NOFDREF).
+ *
+ * - The protocol does not have an outstanding strong reference on the socket
+ * (SS_PROTOREF).
+ *
+ * Otherwise, it will quietly abort so that a future call to sofree(), when
+ * conditions are right, can succeed.
*/
void
sofree(so)
@@ -404,8 +409,8 @@ sofree(so)
ACCEPT_LOCK_ASSERT();
SOCK_LOCK_ASSERT(so);
- if (so->so_pcb != NULL || (so->so_state & SS_NOFDREF) == 0 ||
- so->so_count != 0 || (so->so_state & SS_PROTOREF)) {
+ if ((so->so_state & SS_NOFDREF) == 0 || so->so_count != 0 ||
+ (so->so_state & SS_PROTOREF)) {
SOCK_UNLOCK(so);
ACCEPT_UNLOCK();
return;
@@ -447,6 +452,7 @@ sofree(so)
so->so_qstate & SQ_COMP, so->so_qstate & SQ_INCOMP));
SOCK_UNLOCK(so);
ACCEPT_UNLOCK();
+
SOCKBUF_LOCK(&so->so_snd);
so->so_snd.sb_flags |= SB_NOINTR;
(void)sblock(&so->so_snd, M_WAITOK);
@@ -507,8 +513,6 @@ soclose(so)
}
ACCEPT_UNLOCK();
}
- if (so->so_pcb == NULL)
- goto discard;
if (so->so_state & SS_ISCONNECTED) {
if ((so->so_state & SS_ISDISCONNECTING) == 0) {
error = sodisconnect(so);
@@ -527,13 +531,9 @@ soclose(so)
}
}
}
+
drop:
- if (so->so_pcb != NULL) {
- int error2 = (*so->so_proto->pr_usrreqs->pru_detach)(so);
- if (error == 0)
- error = error2;
- }
-discard:
+ (*so->so_proto->pr_usrreqs->pru_detach)(so);
ACCEPT_LOCK();
SOCK_LOCK(so);
KASSERT((so->so_state & SS_NOFDREF) == 0, ("soclose: NOFDREF"));
@@ -1602,7 +1602,7 @@ dontblock:
* Notify the protocol that some data has been
* drained before blocking.
*/
- if (pr->pr_flags & PR_WANTRCVD && so->so_pcb != NULL) {
+ if (pr->pr_flags & PR_WANTRCVD) {
SOCKBUF_UNLOCK(&so->so_rcv);
(*pr->pr_usrreqs->pru_rcvd)(so, flags);
SOCKBUF_LOCK(&so->so_rcv);
@@ -1646,7 +1646,7 @@ dontblock:
* ACK will be generated on return to TCP.
*/
if (!(flags & MSG_SOCALLBCK) &&
- (pr->pr_flags & PR_WANTRCVD) && so->so_pcb) {
+ (pr->pr_flags & PR_WANTRCVD)) {
SOCKBUF_UNLOCK(&so->so_rcv);
(*pr->pr_usrreqs->pru_rcvd)(so, flags);
SOCKBUF_LOCK(&so->so_rcv);
diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c
index be9084b..4afe8c5 100644
--- a/sys/kern/uipc_socket2.c
+++ b/sys/kern/uipc_socket2.c
@@ -1335,10 +1335,10 @@ pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data,
return EOPNOTSUPP;
}
-int
+void
pru_detach_notsupp(struct socket *so)
{
- return EOPNOTSUPP;
+
}
int
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index f304311..956013a 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -228,7 +228,7 @@ uipc_connect2(struct socket *so1, struct socket *so2)
/* control is EOPNOTSUPP */
-static int
+static void
uipc_detach(struct socket *so)
{
struct unpcb *unp;
@@ -238,7 +238,6 @@ uipc_detach(struct socket *so)
UNP_LOCK();
unp_detach(unp);
UNP_UNLOCK_ASSERT();
- return (0);
}
static int
diff --git a/sys/net/raw_cb.c b/sys/net/raw_cb.c
index 31566d1..f45be72 100644
--- a/sys/net/raw_cb.c
+++ b/sys/net/raw_cb.c
@@ -98,10 +98,9 @@ raw_detach(rp)
{
struct socket *so = rp->rcb_socket;
- ACCEPT_LOCK();
- SOCK_LOCK(so);
- so->so_pcb = 0;
- sotryfree(so);
+ KASSERT(so->so_pcb == rp, ("raw_detach: so_pcb != rp"));
+
+ so->so_pcb = NULL;
mtx_lock(&rawcb_mtx);
LIST_REMOVE(rp, list);
mtx_unlock(&rawcb_mtx);
diff --git a/sys/net/raw_usrreq.c b/sys/net/raw_usrreq.c
index c6f1a7d..300dd91 100644
--- a/sys/net/raw_usrreq.c
+++ b/sys/net/raw_usrreq.c
@@ -178,16 +178,15 @@ raw_uconnect(struct socket *so, struct sockaddr *nam, struct thread *td)
/* pru_connect2 is EOPNOTSUPP */
/* pru_control is EOPNOTSUPP */
-static int
+static void
raw_udetach(struct socket *so)
{
struct rawcb *rp = sotorawcb(so);
if (rp == 0)
- return EINVAL;
+ return;
raw_detach(rp);
- return 0;
}
static int
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index ad64ef0..701662d 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -152,8 +152,8 @@ rts_attach(struct socket *so, int proto, struct thread *td)
struct rawcb *rp;
int s, error;
- if (sotorawcb(so) != NULL)
- return EISCONN; /* XXX panic? */
+ KASSERT(so->so_pcb == NULL, ("rts_attach: so_pcb != NULL"));
+
/* XXX */
MALLOC(rp, struct rawcb *, sizeof *rp, M_PCB, M_WAITOK | M_ZERO);
if (rp == NULL)
@@ -214,32 +214,28 @@ rts_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
/* pru_connect2 is EOPNOTSUPP */
/* pru_control is EOPNOTSUPP */
-static int
+static void
rts_detach(struct socket *so)
{
struct rawcb *rp = sotorawcb(so);
- int s, error;
- s = splnet();
- if (rp != NULL) {
- RTSOCK_LOCK();
- switch(rp->rcb_proto.sp_protocol) {
- case AF_INET:
- route_cb.ip_count--;
- break;
- case AF_INET6:
- route_cb.ip6_count--;
- break;
- case AF_IPX:
- route_cb.ipx_count--;
- break;
- }
- route_cb.any_count--;
- RTSOCK_UNLOCK();
+ KASSERT(rp != NULL, ("rts_detach: rp == NULL"));
+
+ RTSOCK_LOCK();
+ switch(rp->rcb_proto.sp_protocol) {
+ case AF_INET:
+ route_cb.ip_count--;
+ break;
+ case AF_INET6:
+ route_cb.ip6_count--;
+ break;
+ case AF_IPX:
+ route_cb.ipx_count--;
+ break;
}
- error = raw_usrreqs.pru_detach(so);
- splx(s);
- return error;
+ route_cb.any_count--;
+ RTSOCK_UNLOCK();
+ raw_usrreqs.pru_detach(so);
}
static int
diff --git a/sys/netatalk/ddp_usrreq.c b/sys/netatalk/ddp_usrreq.c
index a652ca2..00815c8 100644
--- a/sys/netatalk/ddp_usrreq.c
+++ b/sys/netatalk/ddp_usrreq.c
@@ -72,7 +72,7 @@ ddp_attach(struct socket *so, int proto, struct thread *td)
return (error);
}
-static int
+static void
ddp_detach(struct socket *so)
{
struct ddpcb *ddp;
@@ -84,7 +84,6 @@ ddp_detach(struct socket *so)
DDP_LOCK(ddp);
at_pcbdetach(so, ddp);
DDP_LIST_XUNLOCK();
- return (0);
}
static int
diff --git a/sys/netatm/atm_aal5.c b/sys/netatm/atm_aal5.c
index 2a5e1e3..f21ad798 100644
--- a/sys/netatm/atm_aal5.c
+++ b/sys/netatm/atm_aal5.c
@@ -66,7 +66,7 @@ u_long atm_aal5_recvspace = 64 * 1024; /* XXX */
* Local functions
*/
static int atm_aal5_attach(struct socket *, int, struct thread *td);
-static int atm_aal5_detach(struct socket *);
+static void atm_aal5_detach(struct socket *);
static int atm_aal5_bind(struct socket *, struct sockaddr *,
struct thread *td);
static int atm_aal5_listen(struct socket *, int backlog,
@@ -290,15 +290,15 @@ out:
* errno error processing request - reason indicated
*
*/
-static int
+static void
atm_aal5_detach(so)
struct socket *so;
{
- ATM_INTRO("detach");
+ ATM_INTRO_NOERR("detach");
- err = atm_sock_detach(so);
+ atm_sock_detach(so);
- ATM_OUTRO();
+ ATM_OUTRO_NOERR();
}
diff --git a/sys/netatm/atm_socket.c b/sys/netatm/atm_socket.c
index 2cdab95..d2aecf1 100644
--- a/sys/netatm/atm_socket.c
+++ b/sys/netatm/atm_socket.c
@@ -146,12 +146,8 @@ atm_sock_attach(so, send, recv)
* Arguments:
* so pointer to socket
*
- * Returns:
- * 0 detach successful
- * errno detach failed - reason indicated
- *
*/
-int
+void
atm_sock_detach(so)
struct socket *so;
{
@@ -160,8 +156,7 @@ atm_sock_detach(so)
/*
* Make sure we're still attached
*/
- if (atp == NULL)
- return (ENOTCONN);
+ KASSERT(atp != NULL, ("atm_sock_detach: atp == NULL"));
/*
* Terminate any (possibly pending) connection
@@ -170,17 +165,9 @@ atm_sock_detach(so)
(void) atm_sock_disconnect(so);
}
- /*
- * Break links and free control blocks
- */
- ACCEPT_LOCK();
- SOCK_LOCK(so);
so->so_pcb = NULL;
- sotryfree(so);
uma_zfree(atm_pcb_zone, atp);
-
- return (0);
}
diff --git a/sys/netatm/atm_usrreq.c b/sys/netatm/atm_usrreq.c
index db5a2ab..8facb95 100644
--- a/sys/netatm/atm_usrreq.c
+++ b/sys/netatm/atm_usrreq.c
@@ -70,7 +70,7 @@ struct pr_usrreqs atm_dgram_usrreqs = {
.pru_attach = atm_dgram_attach,
.pru_bind = atm_proto_notsupp2,
.pru_control = atm_dgram_control,
- .pru_detach = atm_proto_notsupp1,
+ .pru_detach = atm_proto_notsupp5,
.pru_disconnect = atm_proto_notsupp1,
.pru_peeraddr = atm_proto_notsupp3,
.pru_send = atm_proto_notsupp4,
diff --git a/sys/netatm/atm_var.h b/sys/netatm/atm_var.h
index 23e43192..788acc9 100644
--- a/sys/netatm/atm_var.h
+++ b/sys/netatm/atm_var.h
@@ -151,7 +151,7 @@ int atm_create_stack(Atm_connvc *, struct stack_list *,
/* atm_socket.c */
void atm_sock_init(void);
int atm_sock_attach(struct socket *, u_long, u_long);
-int atm_sock_detach(struct socket *);
+void atm_sock_detach(struct socket *);
int atm_sock_bind(struct socket *, struct sockaddr *);
int atm_sock_listen(struct socket *, Atm_endpoint *, int);
int atm_sock_connect(struct socket *, struct sockaddr *,
diff --git a/sys/netgraph/bluetooth/include/ng_btsocket_hci_raw.h b/sys/netgraph/bluetooth/include/ng_btsocket_hci_raw.h
index cd7c849..0f28377 100644
--- a/sys/netgraph/bluetooth/include/ng_btsocket_hci_raw.h
+++ b/sys/netgraph/bluetooth/include/ng_btsocket_hci_raw.h
@@ -75,7 +75,7 @@ int ng_btsocket_hci_raw_connect (struct socket *, struct sockaddr *,
int ng_btsocket_hci_raw_control (struct socket *, u_long, caddr_t,
struct ifnet *, struct thread *);
int ng_btsocket_hci_raw_ctloutput (struct socket *, struct sockopt *);
-int ng_btsocket_hci_raw_detach (struct socket *);
+void ng_btsocket_hci_raw_detach (struct socket *);
int ng_btsocket_hci_raw_disconnect (struct socket *);
int ng_btsocket_hci_raw_peeraddr (struct socket *, struct sockaddr **);
int ng_btsocket_hci_raw_send (struct socket *, int, struct mbuf *,
diff --git a/sys/netgraph/bluetooth/include/ng_btsocket_l2cap.h b/sys/netgraph/bluetooth/include/ng_btsocket_l2cap.h
index 2c6171a..a8523ab 100644
--- a/sys/netgraph/bluetooth/include/ng_btsocket_l2cap.h
+++ b/sys/netgraph/bluetooth/include/ng_btsocket_l2cap.h
@@ -100,7 +100,7 @@ int ng_btsocket_l2cap_raw_connect (struct socket *, struct sockaddr *,
struct thread *);
int ng_btsocket_l2cap_raw_control (struct socket *, u_long, caddr_t,
struct ifnet *, struct thread *);
-int ng_btsocket_l2cap_raw_detach (struct socket *);
+void ng_btsocket_l2cap_raw_detach (struct socket *);
int ng_btsocket_l2cap_raw_disconnect (struct socket *);
int ng_btsocket_l2cap_raw_peeraddr (struct socket *, struct sockaddr **);
int ng_btsocket_l2cap_raw_send (struct socket *, int, struct mbuf *,
@@ -193,7 +193,7 @@ int ng_btsocket_l2cap_connect (struct socket *, struct sockaddr *,
int ng_btsocket_l2cap_control (struct socket *, u_long, caddr_t,
struct ifnet *, struct thread *);
int ng_btsocket_l2cap_ctloutput (struct socket *, struct sockopt *);
-int ng_btsocket_l2cap_detach (struct socket *);
+void ng_btsocket_l2cap_detach (struct socket *);
int ng_btsocket_l2cap_disconnect (struct socket *);
int ng_btsocket_l2cap_listen (struct socket *, int, struct thread *);
int ng_btsocket_l2cap_peeraddr (struct socket *, struct sockaddr **);
diff --git a/sys/netgraph/bluetooth/include/ng_btsocket_rfcomm.h b/sys/netgraph/bluetooth/include/ng_btsocket_rfcomm.h
index 4b92cf8..1939964 100644
--- a/sys/netgraph/bluetooth/include/ng_btsocket_rfcomm.h
+++ b/sys/netgraph/bluetooth/include/ng_btsocket_rfcomm.h
@@ -324,7 +324,7 @@ int ng_btsocket_rfcomm_connect (struct socket *, struct sockaddr *,
int ng_btsocket_rfcomm_control (struct socket *, u_long, caddr_t,
struct ifnet *, struct thread *);
int ng_btsocket_rfcomm_ctloutput (struct socket *, struct sockopt *);
-int ng_btsocket_rfcomm_detach (struct socket *);
+void ng_btsocket_rfcomm_detach (struct socket *);
int ng_btsocket_rfcomm_disconnect (struct socket *);
int ng_btsocket_rfcomm_listen (struct socket *, int, struct thread *);
int ng_btsocket_rfcomm_peeraddr (struct socket *, struct sockaddr **);
diff --git a/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c b/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c
index d89bdaf..04bf426 100644
--- a/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c
+++ b/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c
@@ -1399,15 +1399,15 @@ ng_btsocket_hci_raw_ctloutput(struct socket *so, struct sockopt *sopt)
* Detach raw HCI socket
*/
-int
+void
ng_btsocket_hci_raw_detach(struct socket *so)
{
ng_btsocket_hci_raw_pcb_p pcb = so2hci_raw_pcb(so);
- if (pcb == NULL)
- return (EINVAL);
+ KASSERT(pcb != NULL, ("ng_btsocket_hci_raw_detach: pcb == NULL"));
+
if (ng_btsocket_hci_raw_node == NULL)
- return (EINVAL);
+ return;
mtx_lock(&ng_btsocket_hci_raw_sockets_mtx);
mtx_lock(&pcb->pcb_mtx);
@@ -1422,12 +1422,7 @@ ng_btsocket_hci_raw_detach(struct socket *so)
bzero(pcb, sizeof(*pcb));
FREE(pcb, M_NETGRAPH_BTSOCKET_HCI_RAW);
- ACCEPT_LOCK();
- SOCK_LOCK(so);
so->so_pcb = NULL;
- sotryfree(so);
-
- return (0);
} /* ng_btsocket_hci_raw_detach */
/*
diff --git a/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c b/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c
index 09b5d76..21d3766 100644
--- a/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c
+++ b/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c
@@ -2316,15 +2316,15 @@ ng_btsocket_l2cap_ctloutput(struct socket *so, struct sockopt *sopt)
* Detach and destroy socket
*/
-int
+void
ng_btsocket_l2cap_detach(struct socket *so)
{
ng_btsocket_l2cap_pcb_p pcb = so2l2cap_pcb(so);
- if (pcb == NULL)
- return (EINVAL);
+ KASSERT(pcb != NULL, ("ng_btsocket_l2cap_detach: pcb == NULL"));
+
if (ng_btsocket_l2cap_node == NULL)
- return (EINVAL);
+ return;
mtx_lock(&ng_btsocket_l2cap_sockets_mtx);
mtx_lock(&pcb->pcb_mtx);
@@ -2350,12 +2350,7 @@ ng_btsocket_l2cap_detach(struct socket *so)
FREE(pcb, M_NETGRAPH_BTSOCKET_L2CAP);
soisdisconnected(so);
- ACCEPT_LOCK();
- SOCK_LOCK(so);
so->so_pcb = NULL;
- sotryfree(so);
-
- return (0);
} /* ng_btsocket_l2cap_detach */
/*
diff --git a/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap_raw.c b/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap_raw.c
index 0fda1a1..85700f9 100644
--- a/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap_raw.c
+++ b/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap_raw.c
@@ -1094,15 +1094,14 @@ ng_btsocket_l2cap_raw_control(struct socket *so, u_long cmd, caddr_t data,
* Detach and destroy socket
*/
-int
+void
ng_btsocket_l2cap_raw_detach(struct socket *so)
{
ng_btsocket_l2cap_raw_pcb_p pcb = so2l2cap_raw_pcb(so);
- if (pcb == NULL)
- return (EINVAL);
+ KASSERT(pcb != NULL, ("nt_btsocket_l2cap_raw_detach: pcb == NULL"));
if (ng_btsocket_l2cap_raw_node == NULL)
- return (EINVAL);
+ return;
mtx_lock(&ng_btsocket_l2cap_raw_sockets_mtx);
mtx_lock(&pcb->pcb_mtx);
@@ -1117,12 +1116,7 @@ ng_btsocket_l2cap_raw_detach(struct socket *so)
bzero(pcb, sizeof(*pcb));
FREE(pcb, M_NETGRAPH_BTSOCKET_L2CAP_RAW);
- ACCEPT_LOCK();
- SOCK_LOCK(so);
so->so_pcb = NULL;
- sotryfree(so);
-
- return (0);
} /* ng_btsocket_l2cap_raw_detach */
/*
diff --git a/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c b/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c
index c921067..982705f 100644
--- a/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c
+++ b/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c
@@ -674,13 +674,12 @@ ng_btsocket_rfcomm_ctloutput(struct socket *so, struct sockopt *sopt)
* Detach and destroy socket
*/
-int
+void
ng_btsocket_rfcomm_detach(struct socket *so)
{
ng_btsocket_rfcomm_pcb_p pcb = so2rfcomm_pcb(so);
- if (pcb == NULL)
- return (EINVAL);
+ KASSERT(pcb != NULL, ("ng_btsocket_rfcomm_detach: pcb == NULL"));
mtx_lock(&pcb->pcb_mtx);
@@ -726,12 +725,7 @@ ng_btsocket_rfcomm_detach(struct socket *so)
FREE(pcb, M_NETGRAPH_BTSOCKET_RFCOMM);
soisdisconnected(so);
- ACCEPT_LOCK();
- SOCK_LOCK(so);
so->so_pcb = NULL;
- sotryfree(so);
-
- return (0);
} /* ng_btsocket_rfcomm_detach */
/*
diff --git a/sys/netgraph/ng_socket.c b/sys/netgraph/ng_socket.c
index 5ad1bd6..5641effd 100644
--- a/sys/netgraph/ng_socket.c
+++ b/sys/netgraph/ng_socket.c
@@ -185,15 +185,13 @@ ngc_attach(struct socket *so, int proto, struct thread *td)
return (ng_attach_cntl(so));
}
-static int
+static void
ngc_detach(struct socket *so)
{
struct ngpcb *const pcbp = sotongpcb(so);
- if (pcbp == NULL)
- return (EINVAL);
+ KASSERT(pcbp != NULL, ("ngc_detach: pcbp == NULL"));
ng_detach_common(pcbp, NG_CONTROL);
- return (0);
}
static int
@@ -395,15 +393,13 @@ ngd_attach(struct socket *so, int proto, struct thread *td)
return (ng_attach_data(so));
}
-static int
+static void
ngd_detach(struct socket *so)
{
struct ngpcb *const pcbp = sotongpcb(so);
- if (pcbp == NULL)
- return (EINVAL);
+ KASSERT(pcbp == NULL, ("ngd_detach: pcbp == NULL"));
ng_detach_common(pcbp, NG_DATA);
- return (0);
}
static int
diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c
index b3b1a7c..bb31630 100644
--- a/sys/netinet/ip_divert.c
+++ b/sys/netinet/ip_divert.c
@@ -424,7 +424,7 @@ div_attach(struct socket *so, int proto, struct thread *td)
return 0;
}
-static int
+static void
div_detach(struct socket *so)
{
struct inpcb *inp;
@@ -433,12 +433,11 @@ div_detach(struct socket *so)
inp = sotoinpcb(so);
if (inp == 0) {
INP_INFO_WUNLOCK(&divcbinfo);
- return EINVAL;
+ return;
}
INP_LOCK(inp);
in_pcbdetach(inp);
INP_INFO_WUNLOCK(&divcbinfo);
- return 0;
}
static int
diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c
index b39e693..b6cf708 100644
--- a/sys/netinet/raw_ip.c
+++ b/sys/netinet/raw_ip.c
@@ -635,7 +635,7 @@ rip_pcbdetach(struct socket *so, struct inpcb *inp)
in_pcbdetach(inp);
}
-static int
+static void
rip_detach(struct socket *so)
{
struct inpcb *inp;
@@ -645,12 +645,11 @@ rip_detach(struct socket *so)
if (inp == 0) {
/* XXX counter, printf */
INP_INFO_WUNLOCK(&ripcbinfo);
- return EINVAL;
+ return;
}
INP_LOCK(inp);
rip_pcbdetach(so, inp);
INP_INFO_WUNLOCK(&ripcbinfo);
- return 0;
}
static void
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index ff4bd47..902cab6 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -148,10 +148,9 @@ out:
* which may finish later; embryonic TCB's can just
* be discarded here.
*/
-static int
+static void
tcp_usr_detach(struct socket *so)
{
- int error = 0;
struct inpcb *inp;
struct tcpcb *tp;
TCPDEBUG0;
@@ -160,7 +159,7 @@ tcp_usr_detach(struct socket *so)
inp = sotoinpcb(so);
if (inp == NULL) {
INP_INFO_WUNLOCK(&tcbinfo);
- return error;
+ return;
}
INP_LOCK(inp);
tp = intotcpcb(inp);
@@ -171,7 +170,6 @@ tcp_usr_detach(struct socket *so)
if (tp)
INP_UNLOCK(inp);
INP_INFO_WUNLOCK(&tcbinfo);
- return error;
}
#define INI_NOLOCK 0
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index 69ba6fe..23d4301 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -125,7 +125,7 @@ SYSCTL_STRUCT(_net_inet_udp, UDPCTL_STATS, stats, CTLFLAG_RW,
static void udp_append(struct inpcb *last, struct ip *ip, struct mbuf *n,
int off, struct sockaddr_in *udp_in);
-static int udp_detach(struct socket *so);
+static void udp_detach(struct socket *so);
static int udp_output(struct inpcb *, struct mbuf *, struct sockaddr *,
struct mbuf *, struct thread *);
@@ -1027,7 +1027,7 @@ udp_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
return error;
}
-static int
+static void
udp_detach(struct socket *so)
{
struct inpcb *inp;
@@ -1036,12 +1036,10 @@ udp_detach(struct socket *so)
inp = sotoinpcb(so);
if (inp == 0) {
INP_INFO_WUNLOCK(&udbinfo);
- return EINVAL;
}
INP_LOCK(inp);
in_pcbdetach(inp);
INP_INFO_WUNLOCK(&udbinfo);
- return 0;
}
static int
diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c
index 8973fdc..5b6daac 100644
--- a/sys/netinet6/raw_ip6.c
+++ b/sys/netinet6/raw_ip6.c
@@ -591,7 +591,7 @@ rip6_attach(struct socket *so, int proto, struct thread *td)
return 0;
}
-static int
+static void
rip6_detach(struct socket *so)
{
struct inpcb *inp;
@@ -612,7 +612,6 @@ rip6_detach(struct socket *so)
INP_LOCK(inp);
in6_pcbdetach(inp);
INP_INFO_WUNLOCK(&ripcbinfo);
- return 0;
}
static void
diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c
index f58019e..19b894f 100644
--- a/sys/netinet6/udp6_usrreq.c
+++ b/sys/netinet6/udp6_usrreq.c
@@ -117,7 +117,7 @@
*/
extern struct protosw inetsw[];
-static int udp6_detach __P((struct socket *so));
+static void udp6_detach __P((struct socket *so));
int
udp6_input(mp, offp, proto)
@@ -665,7 +665,7 @@ out:
return error;
}
-static int
+static void
udp6_detach(struct socket *so)
{
struct inpcb *inp;
@@ -675,14 +675,13 @@ udp6_detach(struct socket *so)
inp = sotoinpcb(so);
if (inp == 0) {
INP_INFO_WUNLOCK(&udbinfo);
- return EINVAL;
+ return;
}
INP_LOCK(inp);
s = splnet();
in6_pcbdetach(inp);
splx(s);
INP_INFO_WUNLOCK(&udbinfo);
- return 0;
}
static int
diff --git a/sys/netipsec/keysock.c b/sys/netipsec/keysock.c
index 4c84ed9c..9d87b1f 100644
--- a/sys/netipsec/keysock.c
+++ b/sys/netipsec/keysock.c
@@ -456,24 +456,20 @@ key_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
* key_detach()
* derived from net/rtsock.c:rts_detach()
*/
-static int
+static void
key_detach(struct socket *so)
{
struct keycb *kp = (struct keycb *)sotorawcb(so);
int s, error;
- s = splnet();
- if (kp != 0) {
- if (kp->kp_raw.rcb_proto.sp_protocol
- == PF_KEY) /* XXX: AF_KEY */
- key_cb.key_count--;
- key_cb.any_count--;
+ KASSERT(kp != NULL, ("key_detach: kp == NULL"));
+ if (kp->kp_raw.rcb_proto.sp_protocol
+ == PF_KEY) /* XXX: AF_KEY */
+ key_cb.key_count--;
+ key_cb.any_count--;
- key_freereg(so);
- }
- error = raw_usrreqs.pru_detach(so);
- splx(s);
- return error;
+ key_freereg(so);
+ raw_usrreqs.pru_detach(so);
}
/*
diff --git a/sys/netipx/ipx_usrreq.c b/sys/netipx/ipx_usrreq.c
index b98d5a1..2125d04 100644
--- a/sys/netipx/ipx_usrreq.c
+++ b/sys/netipx/ipx_usrreq.c
@@ -80,7 +80,7 @@ static int ipx_attach(struct socket *so, int proto, struct thread *td);
static int ipx_bind(struct socket *so, struct sockaddr *nam, struct thread *td);
static int ipx_connect(struct socket *so, struct sockaddr *nam,
struct thread *td);
-static int ipx_detach(struct socket *so);
+static void ipx_detach(struct socket *so);
static int ipx_disconnect(struct socket *so);
static int ipx_send(struct socket *so, int flags, struct mbuf *m,
struct sockaddr *addr, struct mbuf *control,
@@ -505,7 +505,7 @@ out:
return (error);
}
-static int
+static void
ipx_detach(so)
struct socket *so;
{
@@ -517,7 +517,6 @@ ipx_detach(so)
ipx_pcbdetach(ipxp);
ipx_pcbfree(ipxp);
IPX_LIST_UNLOCK();
- return (0);
}
static int
diff --git a/sys/netipx/spx_usrreq.c b/sys/netipx/spx_usrreq.c
index 637ea19..d9a5639 100644
--- a/sys/netipx/spx_usrreq.c
+++ b/sys/netipx/spx_usrreq.c
@@ -103,7 +103,7 @@ static int spx_attach(struct socket *so, int proto, struct thread *td);
static int spx_bind(struct socket *so, struct sockaddr *nam, struct thread *td);
static int spx_connect(struct socket *so, struct sockaddr *nam,
struct thread *td);
-static int spx_detach(struct socket *so);
+static void spx_detach(struct socket *so);
static void spx_pcbdetach(struct ipxpcb *ipxp);
static int spx_usr_disconnect(struct socket *so);
static int spx_listen(struct socket *so, int backlog, struct thread *td);
@@ -1512,7 +1512,7 @@ spx_connect_end:
return (error);
}
-static int
+static void
spx_detach(struct socket *so)
{
struct ipxpcb *ipxp;
@@ -1534,7 +1534,6 @@ spx_detach(struct socket *so)
ipx_pcbdetach(ipxp);
ipx_pcbfree(ipxp);
IPX_LIST_UNLOCK();
- return (0);
}
/*
diff --git a/sys/netkey/keysock.c b/sys/netkey/keysock.c
index 7b57488..7eb7e0b 100644
--- a/sys/netkey/keysock.c
+++ b/sys/netkey/keysock.c
@@ -366,24 +366,17 @@ key_connect(struct socket *so, struct sockaddr *nam, struct thread *p)
* key_detach()
* derived from net/rtsock.c:rts_detach()
*/
-static int
+static void
key_detach(struct socket *so)
{
struct keycb *kp = (struct keycb *)sotorawcb(so);
- int s, error;
-
- s = splnet();
- if (kp != 0) {
- if (kp->kp_raw.rcb_proto.sp_protocol
- == PF_KEY) /* XXX: AF_KEY */
- key_cb.key_count--;
- key_cb.any_count--;
- key_freereg(so);
- }
- error = raw_usrreqs.pru_detach(so);
- splx(s);
- return error;
+ KASSERT(kp != NULL, ("key_detach: kp == NULL"));
+ if (kp->kp_raw.rcb_proto.sp_protocol == PF_KEY) /* XXX: AF_KEY */
+ key_cb.key_count--;
+ key_cb.any_count--;
+ key_freereg(so);
+ raw_usrreqs.pru_detach(so);
}
/*
diff --git a/sys/netnatm/natm.c b/sys/netnatm/natm.c
index 6b3b202..8b87694 100644
--- a/sys/netnatm/natm.c
+++ b/sys/netnatm/natm.c
@@ -74,7 +74,7 @@ struct mtx natm_mtx;
* user requests
*/
static int natm_usr_attach(struct socket *, int, d_thread_t *);
-static int natm_usr_detach(struct socket *);
+static void natm_usr_detach(struct socket *);
static int natm_usr_connect(struct socket *, struct sockaddr *, d_thread_t *);
static int natm_usr_disconnect(struct socket *);
static int natm_usr_shutdown(struct socket *);
@@ -111,7 +111,7 @@ out:
return (error);
}
-static int
+static void
natm_usr_detach(struct socket *so)
{
struct natmpcb *npcb;
@@ -122,7 +122,6 @@ natm_usr_detach(struct socket *so)
npcb_free(npcb, NPCB_DESTROY); /* drain */
so->so_pcb = NULL;
NATM_UNLOCK();
- return (0);
}
static int
diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h
index 5f39c69..760aa7e 100644
--- a/sys/sys/protosw.h
+++ b/sys/sys/protosw.h
@@ -206,7 +206,7 @@ struct pr_usrreqs {
int (*pru_connect2)(struct socket *so1, struct socket *so2);
int (*pru_control)(struct socket *so, u_long cmd, caddr_t data,
struct ifnet *ifp, struct thread *td);
- int (*pru_detach)(struct socket *so);
+ void (*pru_detach)(struct socket *so);
int (*pru_disconnect)(struct socket *so);
int (*pru_listen)(struct socket *so, int backlog,
struct thread *td);
@@ -256,7 +256,7 @@ int pru_connect_notsupp(struct socket *so, struct sockaddr *nam,
int pru_connect2_notsupp(struct socket *so1, struct socket *so2);
int pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data,
struct ifnet *ifp, struct thread *td);
-int pru_detach_notsupp(struct socket *so);
+void pru_detach_notsupp(struct socket *so);
int pru_disconnect_notsupp(struct socket *so);
int pru_listen_notsupp(struct socket *so, int backlog, struct thread *td);
int pru_peeraddr_notsupp(struct socket *so, struct sockaddr **nam);
OpenPOWER on IntegriCloud