Skip to content

Commit

Permalink
tcp: Remove unnecessary conditions in inet_csk_bind_conflict().
Browse files Browse the repository at this point in the history
When we get an ephemeral port, the relax is false, so the SO_REUSEADDR
conditions may be evaluated twice. We do not need to check the conditions
again.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Kuniyuki Iwashima authored and David S. Miller committed Mar 12, 2020
1 parent af91fd7 commit 16f6c25
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions net/ipv4/inet_connection_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,15 @@ static int inet_csk_bind_conflict(const struct sock *sk,
(!sk->sk_bound_dev_if ||
!sk2->sk_bound_dev_if ||
sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
if ((!reuse || !sk2->sk_reuse ||
sk2->sk_state == TCP_LISTEN) &&
(!reuseport || !sk2->sk_reuseport ||
rcu_access_pointer(sk->sk_reuseport_cb) ||
(sk2->sk_state != TCP_TIME_WAIT &&
!uid_eq(uid, sock_i_uid(sk2))))) {
if (inet_rcv_saddr_equal(sk, sk2, true))
break;
}
if (!relax && reuse && sk2->sk_reuse &&
if (reuse && sk2->sk_reuse &&
sk2->sk_state != TCP_LISTEN) {
if (!relax &&
inet_rcv_saddr_equal(sk, sk2, true))
break;
} else if (!reuseport || !sk2->sk_reuseport ||
rcu_access_pointer(sk->sk_reuseport_cb) ||
(sk2->sk_state != TCP_TIME_WAIT &&
!uid_eq(uid, sock_i_uid(sk2)))) {
if (inet_rcv_saddr_equal(sk, sk2, true))
break;
}
Expand Down

0 comments on commit 16f6c25

Please sign in to comment.