diff options
author | Seigo Tanimura <tanimura@FreeBSD.org> | 2002-05-20 05:41:09 +0000 |
---|---|---|
committer | Seigo Tanimura <tanimura@FreeBSD.org> | 2002-05-20 05:41:09 +0000 |
commit | 243917fe3b5e36464ab72473e872da9acd44aa1c (patch) | |
tree | 2465ddbcecac65f96c5c6d5cef1a4fe3f1ac03f8 /sys/netinet6/raw_ip6.c | |
parent | e21fb30dcef1a691eee2732bcf9070c8dc8009de (diff) | |
download | src-243917fe3b5e36464ab72473e872da9acd44aa1c.tar.gz src-243917fe3b5e36464ab72473e872da9acd44aa1c.zip |
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
Notes
Notes:
svn path=/head/; revision=96972
Diffstat (limited to 'sys/netinet6/raw_ip6.c')
-rw-r--r-- | sys/netinet6/raw_ip6.c | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 2dcec0cf880f..5fbd7c9f630d 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -182,9 +182,16 @@ rip6_input(mp, offp, proto) } else #endif /*IPSEC*/ if (n) { - if (last->in6p_flags & IN6P_CONTROLOPTS || - last->in6p_socket->so_options & SO_TIMESTAMP) + if (last->in6p_flags & IN6P_CONTROLOPTS) ip6_savecontrol(last, &opts, ip6, n); + else { + SOCK_LOCK(last->in6p_socket); + if (last->in6p_socket->so_options & SO_TIMESTAMP) { + SOCK_UNLOCK(last->in6p_socket); + ip6_savecontrol(last, &opts, ip6, n); + } else + SOCK_UNLOCK(last->in6p_socket); + } /* strip intermediate headers */ m_adj(n, *offp); if (sbappendaddr(&last->in6p_socket->so_rcv, @@ -194,8 +201,11 @@ rip6_input(mp, offp, proto) if (opts) m_freem(opts); rip6stat.rip6s_fullsock++; - } else + } else { + SOCK_LOCK(last->in6p_socket); sorwakeup(last->in6p_socket); + SOCK_UNLOCK(last->in6p_socket); + } opts = NULL; } } @@ -213,9 +223,16 @@ rip6_input(mp, offp, proto) } else #endif /*IPSEC*/ if (last) { - if (last->in6p_flags & IN6P_CONTROLOPTS || - last->in6p_socket->so_options & SO_TIMESTAMP) + if (last->in6p_flags & IN6P_CONTROLOPTS) ip6_savecontrol(last, &opts, ip6, m); + else { + SOCK_LOCK(last->in6p_socket); + if (last->in6p_socket->so_options & SO_TIMESTAMP) { + SOCK_UNLOCK(last->in6p_socket); + ip6_savecontrol(last, &opts, ip6, m); + } else + SOCK_UNLOCK(last->in6p_socket); + } /* strip intermediate headers */ m_adj(m, *offp); if (sbappendaddr(&last->in6p_socket->so_rcv, @@ -224,8 +241,11 @@ rip6_input(mp, offp, proto) if (opts) m_freem(opts); rip6stat.rip6s_fullsock++; - } else + } else { + SOCK_LOCK(last->in6p_socket); sorwakeup(last->in6p_socket); + SOCK_UNLOCK(last->in6p_socket); + } } else { rip6stat.rip6s_nosock++; if (m->m_flags & M_MCAST) @@ -591,7 +611,9 @@ rip6_detach(struct socket *so) static int rip6_abort(struct socket *so) { + SOCK_LOCK(so); soisdisconnected(so); + SOCK_UNLOCK(so); return rip6_detach(so); } @@ -600,8 +622,12 @@ rip6_disconnect(struct socket *so) { struct inpcb *inp = sotoinpcb(so); - if ((so->so_state & SS_ISCONNECTED) == 0) + SOCK_LOCK(so); + if ((so->so_state & SS_ISCONNECTED) == 0) { + SOCK_UNLOCK(so); return ENOTCONN; + } + SOCK_UNLOCK(so); inp->in6p_faddr = in6addr_any; return rip6_abort(so); } @@ -669,7 +695,9 @@ rip6_connect(struct socket *so, struct sockaddr *nam, struct thread *td) return (error ? error : EADDRNOTAVAIL); inp->in6p_laddr = *in6a; inp->in6p_faddr = addr->sin6_addr; + SOCK_LOCK(so); soisconnected(so); + SOCK_UNLOCK(so); return 0; } @@ -689,7 +717,9 @@ rip6_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, struct sockaddr_in6 *dst; /* always copy sockaddr to avoid overwrites */ + SOCK_LOCK(so); if (so->so_state & SS_ISCONNECTED) { + SOCK_UNLOCK(so); if (nam) { m_freem(m); return EISCONN; @@ -702,6 +732,7 @@ rip6_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, sizeof(struct in6_addr)); dst = &tmp; } else { + SOCK_UNLOCK(so); if (nam == NULL) { m_freem(m); return ENOTCONN; |