summaryrefslogtreecommitdiffstats
path: root/sys/netinet6
diff options
context:
space:
mode:
authortanimura <tanimura@FreeBSD.org>2002-05-31 11:52:35 +0000
committertanimura <tanimura@FreeBSD.org>2002-05-31 11:52:35 +0000
commite6fa9b9e922913444c2e6b2b58bf3de5eaed868d (patch)
tree9d5f24794525313566896ab89aa860515db344a6 /sys/netinet6
parent1ea6cbb8c29088e04528460633798a6c131ca1ba (diff)
downloadFreeBSD-src-e6fa9b9e922913444c2e6b2b58bf3de5eaed868d.zip
FreeBSD-src-e6fa9b9e922913444c2e6b2b58bf3de5eaed868d.tar.gz
Back out my lats commit of locking down a socket, it conflicts with hsu's work.
Requested by: hsu
Diffstat (limited to 'sys/netinet6')
-rw-r--r--sys/netinet6/icmp6.c10
-rw-r--r--sys/netinet6/in6_pcb.c68
-rw-r--r--sys/netinet6/in6_src.c2
-rw-r--r--sys/netinet6/ip6_input.c5
-rw-r--r--sys/netinet6/ip6_mroute.c2
-rw-r--r--sys/netinet6/raw_ip6.c45
-rw-r--r--sys/netinet6/udp6_usrreq.c57
7 files changed, 38 insertions, 151 deletions
diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c
index f9994c6..38332b2 100644
--- a/sys/netinet6/icmp6.c
+++ b/sys/netinet6/icmp6.c
@@ -1941,11 +1941,8 @@ icmp6_rip6_input(mp, off)
if (opts) {
m_freem(opts);
}
- } else {
- SOCK_LOCK(last->in6p_socket);
+ } else
sorwakeup(last->in6p_socket);
- SOCK_UNLOCK(last->in6p_socket);
- }
opts = NULL;
}
}
@@ -1961,11 +1958,8 @@ icmp6_rip6_input(mp, off)
m_freem(m);
if (opts)
m_freem(opts);
- } else {
- SOCK_LOCK(last->in6p_socket);
+ } else
sorwakeup(last->in6p_socket);
- SOCK_UNLOCK(last->in6p_socket);
- }
} else {
m_freem(m);
ip6stat.ip6s_delivered--;
diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c
index ab37249..09a5c29 100644
--- a/sys/netinet6/in6_pcb.c
+++ b/sys/netinet6/in6_pcb.c
@@ -124,19 +124,14 @@ in6_pcbbind(inp, nam, td)
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)NULL;
struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
u_short lport = 0;
- int wild = 0, reuseport;
+ int wild = 0, reuseport = (so->so_options & SO_REUSEPORT);
- SOCK_LOCK(so);
- reuseport = (so->so_options & SO_REUSEPORT);
- SOCK_UNLOCK(so);
if (!in6_ifaddr) /* XXX broken! */
return (EADDRNOTAVAIL);
if (inp->inp_lport || !IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
return(EINVAL);
- SOCK_LOCK(so);
if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT)) == 0)
wild = 1;
- SOCK_UNLOCK(so);
if (nam) {
sin6 = (struct sockaddr_in6 *)nam;
if (nam->sa_len != sizeof(*sin6))
@@ -162,10 +157,8 @@ in6_pcbbind(inp, nam, td)
* and a multicast address is bound on both
* new and duplicated sockets.
*/
- SOCK_LOCK(so);
if (so->so_options & SO_REUSEADDR)
reuseport = SO_REUSEADDR|SO_REUSEPORT;
- SOCK_UNLOCK(so);
} else if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
struct ifaddr *ia = NULL;
@@ -197,19 +190,14 @@ in6_pcbbind(inp, nam, td)
t = in6_pcblookup_local(pcbinfo,
&sin6->sin6_addr, lport,
INPLOOKUP_WILDCARD);
- if (t != NULL) {
- SOCK_LOCK(t->inp_socket);
- if ((!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) ||
- !IN6_IS_ADDR_UNSPECIFIED(&t->in6p_laddr) ||
- (t->inp_socket->so_options &
- SO_REUSEPORT) == 0) &&
- (so->so_cred->cr_uid !=
- t->inp_socket->so_cred->cr_uid)) {
- SOCK_UNLOCK(t->inp_socket);
- return (EADDRINUSE);
- }
- SOCK_UNLOCK(t->inp_socket);
- }
+ if (t &&
+ (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) ||
+ !IN6_IS_ADDR_UNSPECIFIED(&t->in6p_laddr) ||
+ (t->inp_socket->so_options &
+ SO_REUSEPORT) == 0) &&
+ (so->so_cred->cr_uid !=
+ t->inp_socket->so_cred->cr_uid))
+ return (EADDRINUSE);
if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0 &&
IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
struct sockaddr_in sin;
@@ -230,14 +218,8 @@ in6_pcbbind(inp, nam, td)
}
t = in6_pcblookup_local(pcbinfo, &sin6->sin6_addr,
lport, wild);
- if (t != NULL) {
- SOCK_LOCK(t->inp_socket);
- if ((reuseport & t->inp_socket->so_options) == 0) {
- SOCK_UNLOCK(t->inp_socket);
- return(EADDRINUSE);
- }
- SOCK_UNLOCK(t->inp_socket);
- }
+ if (t && (reuseport & t->inp_socket->so_options) == 0)
+ return(EADDRINUSE);
if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0 &&
IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
struct sockaddr_in sin;
@@ -245,19 +227,14 @@ in6_pcbbind(inp, nam, td)
in6_sin6_2_sin(&sin, sin6);
t = in_pcblookup_local(pcbinfo, sin.sin_addr,
lport, wild);
- if (t != NULL) {
- SOCK_LOCK(t->inp_socket);
- if ((reuseport & t->inp_socket->so_options)
- == 0 &&
- (ntohl(t->inp_laddr.s_addr)
- != INADDR_ANY ||
- INP_SOCKAF(so) ==
- INP_SOCKAF(t->inp_socket))) {
- SOCK_UNLOCK(t->inp_socket);
- return (EADDRINUSE);
- }
- SOCK_UNLOCK(t->inp_socket);
- }
+ if (t &&
+ (reuseport & t->inp_socket->so_options)
+ == 0 &&
+ (ntohl(t->inp_laddr.s_addr)
+ != INADDR_ANY ||
+ INP_SOCKAF(so) ==
+ INP_SOCKAF(t->inp_socket)))
+ return (EADDRINUSE);
}
}
inp->in6p_laddr = sin6->sin6_addr;
@@ -612,12 +589,8 @@ in6_pcbdisconnect(inp)
/* clear flowinfo - draft-itojun-ipv6-flowlabel-api-00 */
inp->in6p_flowinfo &= ~IPV6_FLOWLABEL_MASK;
in_pcbrehash(inp);
- SOCK_LOCK(inp->inp_socket);
- if (inp->inp_socket->so_state & SS_NOFDREF) {
- SOCK_UNLOCK(inp->inp_socket);
+ if (inp->inp_socket->so_state & SS_NOFDREF)
in6_pcbdetach(inp);
- } else
- SOCK_UNLOCK(inp->inp_socket);
}
void
@@ -634,7 +607,6 @@ in6_pcbdetach(inp)
inp->inp_gencnt = ++ipi->ipi_gencnt;
in_pcbremlists(inp);
sotoinpcb(so) = 0;
- SOCK_LOCK(so);
sotryfree(so);
if (inp->in6p_options)
diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c
index 910e66d..3dd2212 100644
--- a/sys/netinet6/in6_src.c
+++ b/sys/netinet6/in6_src.c
@@ -338,11 +338,9 @@ in6_pcbsetport(laddr, inp, td)
int count, error = 0, wild = 0;
struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
- SOCK_LOCK(so);
/* XXX: this is redundant when called from in6_pcbbind */
if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT)) == 0)
wild = INPLOOKUP_WILDCARD;
- SOCK_UNLOCK(so);
inp->inp_flags |= INP_ANONPORT;
diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c
index f237cdf..16df5bb 100644
--- a/sys/netinet6/ip6_input.c
+++ b/sys/netinet6/ip6_input.c
@@ -1147,19 +1147,16 @@ ip6_savecontrol(in6p, mp, ip6, m)
privileged++;
#ifdef SO_TIMESTAMP
- SOCK_LOCK(in6p->in6p_socket);
if ((in6p->in6p_socket->so_options & SO_TIMESTAMP) != 0) {
struct timeval tv;
- SOCK_UNLOCK(in6p->in6p_socket);
microtime(&tv);
*mp = sbcreatecontrol((caddr_t) &tv, sizeof(tv),
SCM_TIMESTAMP, SOL_SOCKET);
if (*mp) {
mp = &(*mp)->m_next;
}
- } else
- SOCK_UNLOCK(in6p->in6p_socket);
+ }
#endif
/* RFC 2292 sec. 5 */
diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c
index 513e307..9af7e81 100644
--- a/sys/netinet6/ip6_mroute.c
+++ b/sys/netinet6/ip6_mroute.c
@@ -892,9 +892,7 @@ socket_send(s, mm, src)
if (sbappendaddr(&s->so_rcv,
(struct sockaddr *)src,
mm, (struct mbuf *)0) != 0) {
- SOCK_LOCK(s);
sorwakeup(s);
- SOCK_UNLOCK(s);
return 0;
}
}
diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c
index 5fbd7c9..2dcec0c 100644
--- a/sys/netinet6/raw_ip6.c
+++ b/sys/netinet6/raw_ip6.c
@@ -182,16 +182,9 @@ rip6_input(mp, offp, proto)
} else
#endif /*IPSEC*/
if (n) {
- if (last->in6p_flags & IN6P_CONTROLOPTS)
+ if (last->in6p_flags & IN6P_CONTROLOPTS ||
+ last->in6p_socket->so_options & SO_TIMESTAMP)
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,
@@ -201,11 +194,8 @@ rip6_input(mp, offp, proto)
if (opts)
m_freem(opts);
rip6stat.rip6s_fullsock++;
- } else {
- SOCK_LOCK(last->in6p_socket);
+ } else
sorwakeup(last->in6p_socket);
- SOCK_UNLOCK(last->in6p_socket);
- }
opts = NULL;
}
}
@@ -223,16 +213,9 @@ rip6_input(mp, offp, proto)
} else
#endif /*IPSEC*/
if (last) {
- if (last->in6p_flags & IN6P_CONTROLOPTS)
+ if (last->in6p_flags & IN6P_CONTROLOPTS ||
+ last->in6p_socket->so_options & SO_TIMESTAMP)
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,
@@ -241,11 +224,8 @@ rip6_input(mp, offp, proto)
if (opts)
m_freem(opts);
rip6stat.rip6s_fullsock++;
- } else {
- SOCK_LOCK(last->in6p_socket);
+ } else
sorwakeup(last->in6p_socket);
- SOCK_UNLOCK(last->in6p_socket);
- }
} else {
rip6stat.rip6s_nosock++;
if (m->m_flags & M_MCAST)
@@ -611,9 +591,7 @@ rip6_detach(struct socket *so)
static int
rip6_abort(struct socket *so)
{
- SOCK_LOCK(so);
soisdisconnected(so);
- SOCK_UNLOCK(so);
return rip6_detach(so);
}
@@ -622,12 +600,8 @@ rip6_disconnect(struct socket *so)
{
struct inpcb *inp = sotoinpcb(so);
- SOCK_LOCK(so);
- if ((so->so_state & SS_ISCONNECTED) == 0) {
- SOCK_UNLOCK(so);
+ if ((so->so_state & SS_ISCONNECTED) == 0)
return ENOTCONN;
- }
- SOCK_UNLOCK(so);
inp->in6p_faddr = in6addr_any;
return rip6_abort(so);
}
@@ -695,9 +669,7 @@ 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;
}
@@ -717,9 +689,7 @@ 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;
@@ -732,7 +702,6 @@ 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;
diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c
index 0e58be5..20913e6 100644
--- a/sys/netinet6/udp6_usrreq.c
+++ b/sys/netinet6/udp6_usrreq.c
@@ -269,18 +269,10 @@ udp6_input(mp, offp, proto)
* and m_copy() will copy M_PKTHDR
* only if offset is 0.
*/
- if (last->in6p_flags & IN6P_CONTROLOPTS)
+ if (last->in6p_flags & IN6P_CONTROLOPTS
+ || last->in6p_socket->so_options & SO_TIMESTAMP)
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);
- }
m_adj(n, off + sizeof(struct udphdr));
if (sbappendaddr(&last->in6p_socket->so_rcv,
@@ -290,11 +282,8 @@ udp6_input(mp, offp, proto)
if (opts)
m_freem(opts);
udpstat.udps_fullsock++;
- } else {
- SOCK_LOCK(last->in6p_socket);
+ } else
sorwakeup(last->in6p_socket);
- SOCK_UNLOCK(last->in6p_socket);
- }
opts = NULL;
}
}
@@ -307,13 +296,9 @@ udp6_input(mp, offp, proto)
* port. It assumes that an application will never
* clear these options after setting them.
*/
- SOCK_LOCK(last->in6p_socket);
if ((last->in6p_socket->so_options &
- (SO_REUSEPORT|SO_REUSEADDR)) == 0) {
- SOCK_UNLOCK(last->in6p_socket);
+ (SO_REUSEPORT|SO_REUSEADDR)) == 0)
break;
- } else
- SOCK_UNLOCK(last->in6p_socket);
}
if (last == NULL) {
@@ -335,16 +320,9 @@ udp6_input(mp, offp, proto)
goto bad;
}
#endif /* IPSEC */
- if (last->in6p_flags & IN6P_CONTROLOPTS)
+ if (last->in6p_flags & IN6P_CONTROLOPTS
+ || last->in6p_socket->so_options & SO_TIMESTAMP)
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);
- }
m_adj(m, off + sizeof(struct udphdr));
if (sbappendaddr(&last->in6p_socket->so_rcv,
@@ -353,9 +331,7 @@ udp6_input(mp, offp, proto)
udpstat.udps_fullsock++;
goto bad;
}
- SOCK_LOCK(last->in6p_socket);
sorwakeup(last->in6p_socket);
- SOCK_UNLOCK(last->in6p_socket);
return IPPROTO_DONE;
}
/*
@@ -399,16 +375,9 @@ udp6_input(mp, offp, proto)
*/
init_sin6(&udp_in6, m); /* general init */
udp_in6.sin6_port = uh->uh_sport;
- if (in6p->in6p_flags & IN6P_CONTROLOPTS)
+ if (in6p->in6p_flags & IN6P_CONTROLOPTS
+ || in6p->in6p_socket->so_options & SO_TIMESTAMP)
ip6_savecontrol(in6p, &opts, ip6, m);
- else {
- SOCK_LOCK(in6p->in6p_socket);
- if (in6p->in6p_socket->so_options & SO_TIMESTAMP) {
- SOCK_UNLOCK(in6p->in6p_socket);
- ip6_savecontrol(in6p, &opts, ip6, m);
- } else
- SOCK_UNLOCK(in6p->in6p_socket);
- }
m_adj(m, off + sizeof(struct udphdr));
if (sbappendaddr(&in6p->in6p_socket->so_rcv,
(struct sockaddr *)&udp_in6,
@@ -416,9 +385,7 @@ udp6_input(mp, offp, proto)
udpstat.udps_fullsock++;
goto bad;
}
- SOCK_LOCK(in6p->in6p_socket);
sorwakeup(in6p->in6p_socket);
- SOCK_UNLOCK(in6p->in6p_socket);
return IPPROTO_DONE;
bad:
if (m)
@@ -542,9 +509,7 @@ udp6_abort(struct socket *so)
inp = sotoinpcb(so);
if (inp == 0)
return EINVAL; /* ??? possible? panic instead? */
- SOCK_LOCK(so);
soisdisconnected(so);
- SOCK_UNLOCK(so);
s = splnet();
in6_pcbdetach(inp);
splx(s);
@@ -649,9 +614,7 @@ udp6_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
if (error == 0) {
inp->inp_vflag |= INP_IPV4;
inp->inp_vflag &= ~INP_IPV6;
- SOCK_LOCK(so);
soisconnected(so);
- SOCK_UNLOCK(so);
}
return error;
}
@@ -666,9 +629,7 @@ udp6_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
inp->inp_vflag &= ~INP_IPV4;
inp->inp_vflag |= INP_IPV6;
}
- SOCK_LOCK(so);
soisconnected(so);
- SOCK_UNLOCK(so);
}
return error;
}
@@ -712,9 +673,7 @@ udp6_disconnect(struct socket *so)
in6_pcbdisconnect(inp);
inp->in6p_laddr = in6addr_any;
splx(s);
- SOCK_LOCK(so);
so->so_state &= ~SS_ISCONNECTED; /* XXX */
- SOCK_UNLOCK(so);
return 0;
}
OpenPOWER on IntegriCloud