summaryrefslogtreecommitdiffstats
path: root/sys/net
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 /sys/net
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
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/raw_cb.c7
-rw-r--r--sys/net/raw_usrreq.c5
-rw-r--r--sys/net/rtsock.c42
3 files changed, 24 insertions, 30 deletions
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
OpenPOWER on IntegriCloud