From: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
To: <davem@davemloft.net>, <kuznet@ms2.inr.ac.ru>,
<yoshfuji@linux-ipv6.org>, <edumazet@google.com>
Cc: <kuniyu@amazon.co.jp>, <kuni1840@gmail.com>,
<netdev@vger.kernel.org>, <osa-contribution-log@amazon.com>
Subject: [PATCH net-next 1/3] tcp: Remove unnecessary conditions in inet_csk_bind_conflict().
Date: Fri, 21 Feb 2020 00:20:18 +0900 [thread overview]
Message-ID: <20200220152020.13056-2-kuniyu@amazon.co.jp> (raw)
In-Reply-To: <20200220152020.13056-1-kuniyu@amazon.co.jp>
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>
---
net/ipv4/inet_connection_sock.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index a4db79b1b643..2e9549f49a82 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -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;
}
--
2.17.2 (Apple Git-113)
next prev parent reply other threads:[~2020-02-20 15:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-20 15:20 [PATCH net-next 0/3] Improve bind(addr, 0) behaviour Kuniyuki Iwashima
2020-02-20 15:20 ` Kuniyuki Iwashima [this message]
2020-02-20 15:20 ` [PATCH net-next 2/3] tcp: bind(addr, 0) remove the SO_REUSEADDR restriction when ephemeral ports are exhausted Kuniyuki Iwashima
2020-02-20 15:20 ` [PATCH net-next 3/3] tcp: Prevent port hijacking when " Kuniyuki Iwashima
2020-02-20 17:11 ` [PATCH net-next 0/3] Improve bind(addr, 0) behaviour David Laight
2020-02-21 10:01 ` Kuniyuki Iwashima
2020-02-21 10:46 ` David Laight
2020-02-20 19:58 ` Eric Dumazet
2020-02-21 20:35 ` [PATCH net-next 0/3] ImpArove " Kuniyuki Iwashima
2020-02-22 1:07 ` [PATCH net-next 0/3] Improve " Kuniyuki Iwashima
2020-02-23 21:06 ` Kuniyuki Iwashima
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200220152020.13056-2-kuniyu@amazon.co.jp \
--to=kuniyu@amazon.co.jp \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuni1840@gmail.com \
--cc=kuznet@ms2.inr.ac.ru \
--cc=netdev@vger.kernel.org \
--cc=osa-contribution-log@amazon.com \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.