diff options
author | rwatson <rwatson@FreeBSD.org> | 2006-07-21 17:11:15 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2006-07-21 17:11:15 +0000 |
commit | 720efebbba89f0ed3381913203af601ee17ba25f (patch) | |
tree | c584d49beb0289bc5110816075b0f48383df5bfd /sys/netipx | |
parent | ec82ec19cb2d1e5f72d91c4479b80a91ec859f6e (diff) | |
download | FreeBSD-src-720efebbba89f0ed3381913203af601ee17ba25f.zip FreeBSD-src-720efebbba89f0ed3381913203af601ee17ba25f.tar.gz |
Change semantics of socket close and detach. Add a new protocol switch
function, pru_close, to notify protocols that the file descriptor or
other consumer of a socket is closing the socket. pru_abort is now a
notification of close also, and no longer detaches. pru_detach is no
longer used to notify of close, and will be called during socket
tear-down by sofree() when all references to a socket evaporate after
an earlier call to abort or close the socket. This means detach is now
an unconditional teardown of a socket, whereas previously sockets could
persist after detach of the protocol retained a reference.
This faciliates sharing mutexes between layers of the network stack as
the mutex is required during the checking and removal of references at
the head of sofree(). With this change, pru_detach can now assume that
the mutex will no longer be required by the socket layer after
completion, whereas before this was not necessarily true.
Reviewed by: gnn
Diffstat (limited to 'sys/netipx')
-rw-r--r-- | sys/netipx/ipx_usrreq.c | 21 | ||||
-rw-r--r-- | sys/netipx/spx_usrreq.c | 37 |
2 files changed, 43 insertions, 15 deletions
diff --git a/sys/netipx/ipx_usrreq.c b/sys/netipx/ipx_usrreq.c index 489014a..84de629 100644 --- a/sys/netipx/ipx_usrreq.c +++ b/sys/netipx/ipx_usrreq.c @@ -88,6 +88,7 @@ static int ipx_send(struct socket *so, int flags, struct mbuf *m, static int ipx_shutdown(struct socket *so); static int ripx_attach(struct socket *so, int proto, struct thread *td); static int ipx_output(struct ipxpcb *ipxp, struct mbuf *m0); +static void ipx_usr_close(struct socket *so); struct pr_usrreqs ipx_usrreqs = { .pru_abort = ipx_usr_abort, @@ -101,6 +102,7 @@ struct pr_usrreqs ipx_usrreqs = { .pru_send = ipx_send, .pru_shutdown = ipx_shutdown, .pru_sockaddr = ipx_sockaddr, + .pru_close = ipx_usr_close, }; struct pr_usrreqs ripx_usrreqs = { @@ -115,6 +117,7 @@ struct pr_usrreqs ripx_usrreqs = { .pru_send = ipx_send, .pru_shutdown = ipx_shutdown, .pru_sockaddr = ipx_sockaddr, + .pru_close = ipx_usr_close, }; /* @@ -432,14 +435,8 @@ static void ipx_usr_abort(so) struct socket *so; { - struct ipxpcb *ipxp = sotoipxpcb(so); - KASSERT(ipxp != NULL, ("ipx_usr_abort: ipxp == NULL")); - IPX_LIST_LOCK(); - IPX_LOCK(ipxp); - ipx_pcbdetach(ipxp); - ipx_pcbfree(ipxp); - IPX_LIST_UNLOCK(); + /* XXXRW: Possibly ipx_disconnect() here? */ soisdisconnected(so); } @@ -482,6 +479,15 @@ ipx_bind(so, nam, td) return (error); } +static void +ipx_usr_close(so) + struct socket *so; +{ + + /* XXXRW: Possibly ipx_disconnect() here? */ + soisdisconnected(so); +} + static int ipx_connect(so, nam, td) struct socket *so; @@ -513,6 +519,7 @@ ipx_detach(so) { struct ipxpcb *ipxp = sotoipxpcb(so); + /* XXXRW: Should assert detached. */ KASSERT(ipxp != NULL, ("ipx_detach: ipxp == NULL")); IPX_LIST_LOCK(); IPX_LOCK(ipxp); diff --git a/sys/netipx/spx_usrreq.c b/sys/netipx/spx_usrreq.c index d9a5639..9400df2 100644 --- a/sys/netipx/spx_usrreq.c +++ b/sys/netipx/spx_usrreq.c @@ -101,6 +101,7 @@ static void spx_usr_abort(struct socket *so); static int spx_accept(struct socket *so, struct sockaddr **nam); 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 void spx_usr_close(struct socket *so); static int spx_connect(struct socket *so, struct sockaddr *nam, struct thread *td); static void spx_detach(struct socket *so); @@ -131,6 +132,7 @@ struct pr_usrreqs spx_usrreqs = { .pru_send = spx_send, .pru_shutdown = spx_shutdown, .pru_sockaddr = ipx_sockaddr, + .pru_close = spx_usr_close, }; struct pr_usrreqs spx_usrreq_sps = { @@ -149,6 +151,7 @@ struct pr_usrreqs spx_usrreq_sps = { .pru_send = spx_send, .pru_shutdown = spx_shutdown, .pru_sockaddr = ipx_sockaddr, + .pru_close = spx_usr_close, }; void @@ -1320,9 +1323,7 @@ spx_usr_abort(struct socket *so) IPX_LIST_LOCK(); IPX_LOCK(ipxp); spx_drop(cb, ECONNABORTED); - spx_pcbdetach(ipxp); - ipx_pcbdetach(ipxp); - ipx_pcbfree(ipxp); + IPX_UNLOCK(ipxp); IPX_LIST_UNLOCK(); } @@ -1459,6 +1460,28 @@ out: return (error); } +static void +spx_usr_close(struct socket *so) +{ + struct ipxpcb *ipxp; + struct spxpcb *cb; + + ipxp = sotoipxpcb(so); + KASSERT(ipxp != NULL, ("spx_usr_close: ipxp == NULL")); + + cb = ipxtospxpcb(ipxp); + KASSERT(cb != NULL, ("spx_usr_close: cb == NULL")); + + IPX_LIST_LOCK(); + IPX_LOCK(ipxp); + if (cb->s_state > TCPS_LISTEN) + spx_disconnect(cb); + else + spx_close(cb); + IPX_UNLOCK(ipxp); + IPX_LIST_UNLOCK(); +} + /* * Initiate connection to peer. Enter SYN_SENT state, and mark socket as * connecting. Start keep-alive timer, setup prototype header, send initial @@ -1518,6 +1541,9 @@ spx_detach(struct socket *so) struct ipxpcb *ipxp; struct spxpcb *cb; + /* + * XXXRW: Should assert appropriately detached. + */ ipxp = sotoipxpcb(so); KASSERT(ipxp != NULL, ("spx_detach: ipxp == NULL")); @@ -1526,12 +1552,7 @@ spx_detach(struct socket *so) IPX_LIST_LOCK(); IPX_LOCK(ipxp); - if (cb->s_state > TCPS_LISTEN) - spx_disconnect(cb); - else - spx_close(cb); spx_pcbdetach(ipxp); - ipx_pcbdetach(ipxp); ipx_pcbfree(ipxp); IPX_LIST_UNLOCK(); } |