Skip to content

Commit 58655bc

Browse files
q2vendavem330
authored andcommitted
tcp: Rearrange tests in inet_csk_bind_conflict().
The following patch adds code in the !inet_use_bhash2_on_bind(sk) case in inet_csk_bind_conflict(). To avoid adding nest and make the change cleaner, this patch rearranges tests in inet_csk_bind_conflict(). Signed-off-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 822fb91 commit 58655bc

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

net/ipv4/inet_connection_sock.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -242,42 +242,40 @@ static int inet_csk_bind_conflict(const struct sock *sk,
242242
const struct inet_bind2_bucket *tb2, /* may be null */
243243
bool relax, bool reuseport_ok)
244244
{
245-
bool reuseport_cb_ok;
246-
struct sock_reuseport *reuseport_cb;
247245
kuid_t uid = sock_i_uid((struct sock *)sk);
246+
struct sock_reuseport *reuseport_cb;
247+
bool reuseport_cb_ok;
248+
struct sock *sk2;
248249

249250
rcu_read_lock();
250251
reuseport_cb = rcu_dereference(sk->sk_reuseport_cb);
251252
/* paired with WRITE_ONCE() in __reuseport_(add|detach)_closed_sock */
252253
reuseport_cb_ok = !reuseport_cb || READ_ONCE(reuseport_cb->num_closed_socks);
253254
rcu_read_unlock();
254255

255-
/*
256-
* Unlike other sk lookup places we do not check
256+
/* Conflicts with an existing IPV6_ADDR_ANY (if ipv6) or INADDR_ANY (if
257+
* ipv4) should have been checked already. We need to do these two
258+
* checks separately because their spinlocks have to be acquired/released
259+
* independently of each other, to prevent possible deadlocks
260+
*/
261+
if (inet_use_bhash2_on_bind(sk))
262+
return tb2 && inet_bhash2_conflict(sk, tb2, uid, relax,
263+
reuseport_cb_ok, reuseport_ok);
264+
265+
/* Unlike other sk lookup places we do not check
257266
* for sk_net here, since _all_ the socks listed
258267
* in tb->owners and tb2->owners list belong
259268
* to the same net - the one this bucket belongs to.
260269
*/
270+
sk_for_each_bound(sk2, &tb->owners) {
271+
if (!inet_bind_conflict(sk, sk2, uid, relax, reuseport_cb_ok, reuseport_ok))
272+
continue;
261273

262-
if (!inet_use_bhash2_on_bind(sk)) {
263-
struct sock *sk2;
264-
265-
sk_for_each_bound(sk2, &tb->owners)
266-
if (inet_bind_conflict(sk, sk2, uid, relax,
267-
reuseport_cb_ok, reuseport_ok) &&
268-
inet_rcv_saddr_equal(sk, sk2, true))
269-
return true;
270-
271-
return false;
274+
if (inet_rcv_saddr_equal(sk, sk2, true))
275+
return true;
272276
}
273277

274-
/* Conflicts with an existing IPV6_ADDR_ANY (if ipv6) or INADDR_ANY (if
275-
* ipv4) should have been checked already. We need to do these two
276-
* checks separately because their spinlocks have to be acquired/released
277-
* independently of each other, to prevent possible deadlocks
278-
*/
279-
return tb2 && inet_bhash2_conflict(sk, tb2, uid, relax, reuseport_cb_ok,
280-
reuseport_ok);
278+
return false;
281279
}
282280

283281
/* Determine if there is a bind conflict with an existing IPV6_ADDR_ANY (if ipv6) or

0 commit comments

Comments
 (0)