diff options
author | tanimura <tanimura@FreeBSD.org> | 2002-05-20 05:41:09 +0000 |
---|---|---|
committer | tanimura <tanimura@FreeBSD.org> | 2002-05-20 05:41:09 +0000 |
commit | 92d8381dd544a8237b3fd68c4e7fce9bd0903fb2 (patch) | |
tree | 2465ddbcecac65f96c5c6d5cef1a4fe3f1ac03f8 /sys/netns/ns_pcb.c | |
parent | 969293170b27461145f69a538d5abd15fea34ba1 (diff) | |
download | FreeBSD-src-92d8381dd544a8237b3fd68c4e7fce9bd0903fb2.zip FreeBSD-src-92d8381dd544a8237b3fd68c4e7fce9bd0903fb2.tar.gz |
Lock down a socket, milestone 1.
o Add a mutex (sb_mtx) to struct sockbuf. This protects the data in a
socket buffer. The mutex in the receive buffer also protects the data
in struct socket.
o Determine the lock strategy for each members in struct socket.
o Lock down the following members:
- so_count
- so_options
- so_linger
- so_state
o Remove *_locked() socket APIs. Make the following socket APIs
touching the members above now require a locked socket:
- sodisconnect()
- soisconnected()
- soisconnecting()
- soisdisconnected()
- soisdisconnecting()
- sofree()
- soref()
- sorele()
- sorwakeup()
- sotryfree()
- sowakeup()
- sowwakeup()
Reviewed by: alfred
Diffstat (limited to 'sys/netns/ns_pcb.c')
-rw-r--r-- | sys/netns/ns_pcb.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/sys/netns/ns_pcb.c b/sys/netns/ns_pcb.c index 01301c0..9e06710 100644 --- a/sys/netns/ns_pcb.c +++ b/sys/netns/ns_pcb.c @@ -94,9 +94,13 @@ ns_pcbbind(nsp, nam) if (lport) { u_short aport = ntohs(lport); + SOCK_LOCK(so); if (aport < NSPORT_RESERVED && - (nsp->nsp_socket->so_state & SS_PRIV) == 0) + (nsp->nsp_socket->so_state & SS_PRIV) == 0) { + SOCK_UNLOCK(so); return (EACCES); + } + SOCK_UNLOCK(so); if (ns_pcblookup(&zerons_addr, lport, 0)) return (EADDRINUSE); } @@ -148,8 +152,12 @@ ns_pcbconnect(nsp, nam) */ ro = &nsp->nsp_route; dst = &satons_addr(ro->ro_dst); - if (nsp->nsp_socket->so_options & SO_DONTROUTE) + SOCK_LOCK(nsp->nsp_socket); + if (nsp->nsp_socket->so_options & SO_DONTROUTE) { + SOCK_UNLOCK(nsp->nsp_socket); goto flush; + } + SOCK_UNLOCK(nsp->nsp_socket); if (!ns_neteq(nsp->nsp_lastdst, sns->sns_addr)) goto flush; if (!ns_hosteq(nsp->nsp_lastdst, sns->sns_addr)) { @@ -165,16 +173,19 @@ ns_pcbconnect(nsp, nam) } }/* else cached route is ok; do nothing */ nsp->nsp_lastdst = sns->sns_addr; + SOCK_LOCK(nsp->nsp_socket); if ((nsp->nsp_socket->so_options & SO_DONTROUTE) == 0 && /*XXX*/ (ro->ro_rt == (struct rtentry *)0 || ro->ro_rt->rt_ifp == (struct ifnet *)0)) { + SOCK_UNLOCK(nsp->nsp_socket); /* No route yet, so try to acquire one */ ro->ro_dst.sa_family = AF_NS; ro->ro_dst.sa_len = sizeof(ro->ro_dst); *dst = sns->sns_addr; dst->x_port = 0; rtalloc(ro); - } + } else + SOCK_UNLOCK(nsp->nsp_socket); if (ns_neteqnn(nsp->nsp_laddr.x_net, ns_zeronet)) { /* * If route is known or can be allocated now, @@ -222,8 +233,12 @@ ns_pcbdisconnect(nsp) { nsp->nsp_faddr = zerons_addr; - if (nsp->nsp_socket->so_state & SS_NOFDREF) + SOCK_LOCK(so); + if (nsp->nsp_socket->so_state & SS_NOFDREF) { + SOCK_UNLOCK(so); ns_pcbdetach(nsp); + } else + SOCK_UNLOCK(so); } ns_pcbdetach(nsp) @@ -232,6 +247,7 @@ ns_pcbdetach(nsp) struct socket *so = nsp->nsp_socket; so->so_pcb = 0; + SOCK_LOCK(so); sotryfree(so); if (nsp->nsp_route.ro_rt) rtfree(nsp->nsp_route.ro_rt); |