diff options
author | rwatson <rwatson@FreeBSD.org> | 2006-04-01 16:20:54 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2006-04-01 16:20:54 +0000 |
commit | a7c2bca553bef1485f864043c190482cc9c6fdd4 (patch) | |
tree | 60c6d1ae13c348075601004daade9dd8338f72a3 /sys/netinet/udp_usrreq.c | |
parent | 71cc03392bbc78f93765e5550fc35f98c373df04 (diff) | |
download | FreeBSD-src-a7c2bca553bef1485f864043c190482cc9c6fdd4.zip FreeBSD-src-a7c2bca553bef1485f864043c190482cc9c6fdd4.tar.gz |
Update in_pcb-derived basic socket types following changes to
pru_abort(), pru_detach(), and in_pcbdetach():
- Universally support and enforce the invariant that so_pcb is
never NULL, converting dozens of unnecessary NULL checks into
assertions, and eliminating dozens of unnecessary error handling
cases in protocol code.
- In some cases, eliminate unnecessary pcbinfo locking, as it is no
longer required to ensure so_pcb != NULL. For example, in protocol
shutdown methods, and in raw IP send.
- Abort and detach protocol switch methods no longer return failures,
nor attempt to free sockets, as the socket layer does this.
- Invoke in_pcbfree() after in_pcbdetach() in order to free the
detached in_pcb structure for a socket.
MFC after: 3 months
Diffstat (limited to 'sys/netinet/udp_usrreq.c')
-rw-r--r-- | sys/netinet/udp_usrreq.c | 51 |
1 files changed, 16 insertions, 35 deletions
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 23d4301..e00892d 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -934,15 +934,13 @@ udp_abort(struct socket *so) { struct inpcb *inp; - INP_INFO_WLOCK(&udbinfo); inp = sotoinpcb(so); - if (inp == 0) { - INP_INFO_WUNLOCK(&udbinfo); - return; /* ??? possible? panic instead? */ - } + KASSERT(inp != NULL, ("udp_abort: inp == NULL")); + INP_INFO_WLOCK(&udbinfo); INP_LOCK(inp); soisdisconnected(so); in_pcbdetach(inp); + in_pcbfree(inp); INP_INFO_WUNLOCK(&udbinfo); } @@ -952,12 +950,9 @@ udp_attach(struct socket *so, int proto, struct thread *td) struct inpcb *inp; int error; - INP_INFO_WLOCK(&udbinfo); inp = sotoinpcb(so); - if (inp != 0) { - INP_INFO_WUNLOCK(&udbinfo); - return EINVAL; - } + KASSERT(inp == NULL, ("udp_attach: inp != NULL")); + INP_INFO_WLOCK(&udbinfo); error = soreserve(so, udp_sendspace, udp_recvspace); if (error) { INP_INFO_WUNLOCK(&udbinfo); @@ -984,12 +979,9 @@ udp_bind(struct socket *so, struct sockaddr *nam, struct thread *td) struct inpcb *inp; int error; - INP_INFO_WLOCK(&udbinfo); inp = sotoinpcb(so); - if (inp == 0) { - INP_INFO_WUNLOCK(&udbinfo); - return EINVAL; - } + KASSERT(inp != NULL, ("udp_bind: inp == NULL")); + INP_INFO_WLOCK(&udbinfo); INP_LOCK(inp); error = in_pcbbind(inp, nam, td->td_ucred); INP_UNLOCK(inp); @@ -1004,12 +996,9 @@ udp_connect(struct socket *so, struct sockaddr *nam, struct thread *td) int error; struct sockaddr_in *sin; - INP_INFO_WLOCK(&udbinfo); inp = sotoinpcb(so); - if (inp == 0) { - INP_INFO_WUNLOCK(&udbinfo); - return EINVAL; - } + KASSERT(inp != NULL, ("udp_connect: inp == NULL")); + INP_INFO_WLOCK(&udbinfo); INP_LOCK(inp); if (inp->inp_faddr.s_addr != INADDR_ANY) { INP_UNLOCK(inp); @@ -1032,13 +1021,12 @@ udp_detach(struct socket *so) { struct inpcb *inp; - INP_INFO_WLOCK(&udbinfo); inp = sotoinpcb(so); - if (inp == 0) { - INP_INFO_WUNLOCK(&udbinfo); - } + KASSERT(inp != NULL, ("udp_detach: inp == NULL")); + INP_INFO_WLOCK(&udbinfo); INP_LOCK(inp); in_pcbdetach(inp); + in_pcbfree(inp); INP_INFO_WUNLOCK(&udbinfo); } @@ -1047,12 +1035,9 @@ udp_disconnect(struct socket *so) { struct inpcb *inp; - INP_INFO_WLOCK(&udbinfo); inp = sotoinpcb(so); - if (inp == 0) { - INP_INFO_WUNLOCK(&udbinfo); - return EINVAL; - } + KASSERT(inp != NULL, ("udp_disconnect: inp == NULL")); + INP_INFO_WLOCK(&udbinfo); INP_LOCK(inp); if (inp->inp_faddr.s_addr == INADDR_ANY) { INP_INFO_WUNLOCK(&udbinfo); @@ -1075,6 +1060,7 @@ udp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, struct inpcb *inp; inp = sotoinpcb(so); + KASSERT(inp != NULL, ("udp_send: inp == NULL")); return udp_output(inp, m, addr, control, td); } @@ -1083,14 +1069,9 @@ udp_shutdown(struct socket *so) { struct inpcb *inp; - INP_INFO_RLOCK(&udbinfo); inp = sotoinpcb(so); - if (inp == 0) { - INP_INFO_RUNLOCK(&udbinfo); - return EINVAL; - } + KASSERT(inp != NULL, ("udp_shutdown: inp == NULL")); INP_LOCK(inp); - INP_INFO_RUNLOCK(&udbinfo); socantsendmore(so); INP_UNLOCK(inp); return 0; |