Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F161618819
D55970.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D55970.id.diff
View Options
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -727,22 +727,27 @@
KASSERT(sin == NULL || sin->sin_len == sizeof(struct sockaddr_in),
("%s: invalid address length for %p", __func__, sin));
INP_WLOCK_ASSERT(inp);
- INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo);
if (inp->inp_lport != 0 || inp->inp_laddr.s_addr != INADDR_ANY)
return (EINVAL);
anonport = sin == NULL || sin->sin_port == 0;
+
+ INP_HASH_WLOCK(inp->inp_pcbinfo);
error = in_pcbbind_setup(inp, sin, &inp->inp_laddr.s_addr,
&inp->inp_lport, flags, cred);
- if (error)
+ if (error) {
+ INP_HASH_WUNLOCK(inp->inp_pcbinfo);
return (error);
+ }
if (__predict_false((error = in_pcbinshash(inp)) != 0)) {
+ INP_HASH_WUNLOCK(inp->inp_pcbinfo);
MPASS(inp->inp_socket->so_options & SO_REUSEPORT_LB);
inp->inp_laddr.s_addr = INADDR_ANY;
inp->inp_lport = 0;
inp->inp_flags &= ~INP_BOUNDFIB;
return (error);
}
+ INP_HASH_WUNLOCK(inp->inp_pcbinfo);
if (anonport)
inp->inp_flags |= INP_ANONPORT;
return (0);
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -256,10 +256,8 @@
error = EAFNOSUPPORT;
goto out;
}
- INP_HASH_WLOCK(&V_tcbinfo);
error = in_pcbbind(inp, sinp, V_tcp_bind_all_fibs ? 0 : INPBIND_FIB,
td->td_ucred);
- INP_HASH_WUNLOCK(&V_tcbinfo);
out:
tcp_bblog_pru(tp, PRU_BIND, error);
TCP_PROBE2(debug__user, tp, PRU_BIND);
@@ -305,7 +303,6 @@
goto out;
}
- INP_HASH_WLOCK(&V_tcbinfo);
inp->inp_vflag &= ~INP_IPV4;
inp->inp_vflag |= INP_IPV6;
#ifdef INET
@@ -318,20 +315,17 @@
in6_sin6_2_sin(&sin, sin6);
if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
error = EAFNOSUPPORT;
- INP_HASH_WUNLOCK(&V_tcbinfo);
goto out;
}
inp->inp_vflag |= INP_IPV4;
inp->inp_vflag &= ~INP_IPV6;
error = in_pcbbind(inp, &sin, 0, td->td_ucred);
- INP_HASH_WUNLOCK(&V_tcbinfo);
goto out;
}
}
#endif
error = in6_pcbbind(inp, sin6, V_tcp_bind_all_fibs ? 0 : INPBIND_FIB,
td->td_ucred);
- INP_HASH_WUNLOCK(&V_tcbinfo);
out:
if (error != 0)
inp->inp_vflag = vflagsav;
@@ -368,10 +362,8 @@
goto out;
}
if (inp->inp_lport == 0) {
- INP_HASH_WLOCK(&V_tcbinfo);
error = in_pcbbind(inp, NULL,
V_tcp_bind_all_fibs ? 0 : INPBIND_FIB, td->td_ucred);
- INP_HASH_WUNLOCK(&V_tcbinfo);
}
if (error == 0) {
tcp_state_change(tp, TCPS_LISTEN);
@@ -426,7 +418,6 @@
SOCK_UNLOCK(so);
goto out;
}
- INP_HASH_WLOCK(&V_tcbinfo);
if (inp->inp_lport == 0) {
inp->inp_vflag &= ~INP_IPV4;
if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
@@ -434,7 +425,6 @@
error = in6_pcbbind(inp, NULL,
V_tcp_bind_all_fibs ? 0 : INPBIND_FIB, td->td_ucred);
}
- INP_HASH_WUNLOCK(&V_tcbinfo);
if (error == 0) {
tcp_state_change(tp, TCPS_LISTEN);
solisten_proto(so, backlog);
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -1356,10 +1356,8 @@
.sin_len = sizeof(struct sockaddr_in),
};
- INP_HASH_WLOCK(pcbinfo);
error = in_pcbbind(inp, &wild, V_udp_bind_all_fibs ?
0 : INPBIND_FIB, td->td_ucred);
- INP_HASH_WUNLOCK(pcbinfo);
if (error)
goto release;
lport = inp->inp_lport;
@@ -1599,11 +1597,9 @@
udp_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
{
struct inpcb *inp;
- struct inpcbinfo *pcbinfo;
struct sockaddr_in *sinp;
int error;
- pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("udp_bind: inp == NULL"));
@@ -1622,10 +1618,8 @@
return (EINVAL);
INP_WLOCK(inp);
- INP_HASH_WLOCK(pcbinfo);
error = in_pcbbind(inp, sinp, V_udp_bind_all_fibs ? 0 : INPBIND_FIB,
td->td_ucred);
- INP_HASH_WUNLOCK(pcbinfo);
INP_WUNLOCK(inp);
return (error);
}
diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c
--- a/sys/netinet6/in6_pcb.c
+++ b/sys/netinet6/in6_pcb.c
@@ -297,7 +297,6 @@
int error, fib, lookupflags, sooptions;
INP_WLOCK_ASSERT(inp);
- INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo);
if (inp->inp_lport || !IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
return (EINVAL);
@@ -310,6 +309,7 @@
if ((error = prison_local_ip6(cred, &inp->in6p_laddr,
((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0))) != 0)
return (error);
+ INP_HASH_WLOCK(inp->inp_pcbinfo);
} else {
KASSERT(sin6->sin6_family == AF_INET6,
("%s: invalid address family for %p", __func__, sin6));
@@ -326,11 +326,14 @@
fib = (flags & INPBIND_FIB) != 0 ? inp->inp_inc.inc_fibnum :
RT_ALL_FIBS;
+ INP_HASH_WLOCK(inp->inp_pcbinfo);
/* See if this address/port combo is available. */
- error = in6_pcbbind_avail(inp, sin6, fib, sooptions, lookupflags,
- cred);
- if (error != 0)
+ error = in6_pcbbind_avail(inp, sin6, fib, sooptions,
+ lookupflags, cred);
+ if (error != 0) {
+ INP_HASH_WUNLOCK(inp->inp_pcbinfo);
return (error);
+ }
lport = sin6->sin6_port;
inp->in6p_laddr = sin6->sin6_addr;
@@ -339,6 +342,7 @@
inp->inp_flags |= INP_BOUNDFIB;
if (lport == 0) {
if ((error = in6_pcbsetport(&inp->in6p_laddr, inp, cred)) != 0) {
+ INP_HASH_WUNLOCK(inp->inp_pcbinfo);
/* Undo an address bind that may have occurred. */
inp->inp_flags &= ~INP_BOUNDFIB;
inp->in6p_laddr = in6addr_any;
@@ -347,12 +351,15 @@
} else {
inp->inp_lport = lport;
if (in_pcbinshash(inp) != 0) {
+ INP_HASH_WUNLOCK(inp->inp_pcbinfo);
inp->inp_flags &= ~INP_BOUNDFIB;
inp->in6p_laddr = in6addr_any;
inp->inp_lport = 0;
return (EAGAIN);
}
}
+ INP_HASH_WUNLOCK(inp->inp_pcbinfo);
+
return (0);
}
diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c
--- a/sys/netinet6/udp6_usrreq.c
+++ b/sys/netinet6/udp6_usrreq.c
@@ -1046,11 +1046,9 @@
{
struct sockaddr_in6 *sin6_p;
struct inpcb *inp;
- struct inpcbinfo *pcbinfo;
int error;
u_char vflagsav;
- pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("udp6_bind: inp == NULL"));
@@ -1062,7 +1060,6 @@
sin6_p = (struct sockaddr_in6 *)nam;
INP_WLOCK(inp);
- INP_HASH_WLOCK(pcbinfo);
vflagsav = inp->inp_vflag;
inp->inp_vflag &= ~INP_IPV4;
inp->inp_vflag |= INP_IPV6;
@@ -1091,7 +1088,6 @@
#endif
if (error != 0)
inp->inp_vflag = vflagsav;
- INP_HASH_WUNLOCK(pcbinfo);
INP_WUNLOCK(inp);
return (error);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jul 6, 8:45 AM (4 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34681077
Default Alt Text
D55970.id.diff (6 KB)
Attached To
Mode
D55970: inpcb: make in_pcbbind() acquire the hash lock internally
Attached
Detach File
Event Timeline
Log In to Comment