Commit e2baad9e authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

tcp: connect() from bound sockets can be faster

__inet_hash_connect() does not use its third argument (port_offset)
if socket was already bound to a source port.

No need to perform useless but expensive md5 computations.
Reported-by: default avatarCrestez Dan Leonard <cdleonard@gmail.com>
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5a7e4b48
...@@ -394,9 +394,10 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row, ...@@ -394,9 +394,10 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
} }
static inline u32 inet_sk_port_offset(const struct sock *sk) static u32 inet_sk_port_offset(const struct sock *sk)
{ {
const struct inet_sock *inet = inet_sk(sk); const struct inet_sock *inet = inet_sk(sk);
return secure_ipv4_port_ephemeral(inet->inet_rcv_saddr, return secure_ipv4_port_ephemeral(inet->inet_rcv_saddr,
inet->inet_daddr, inet->inet_daddr,
inet->inet_dport); inet->inet_dport);
...@@ -600,7 +601,11 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row, ...@@ -600,7 +601,11 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
int inet_hash_connect(struct inet_timewait_death_row *death_row, int inet_hash_connect(struct inet_timewait_death_row *death_row,
struct sock *sk) struct sock *sk)
{ {
return __inet_hash_connect(death_row, sk, inet_sk_port_offset(sk), u32 port_offset = 0;
if (!inet_sk(sk)->inet_num)
port_offset = inet_sk_port_offset(sk);
return __inet_hash_connect(death_row, sk, port_offset,
__inet_check_established); __inet_check_established);
} }
EXPORT_SYMBOL_GPL(inet_hash_connect); EXPORT_SYMBOL_GPL(inet_hash_connect);
......
...@@ -257,7 +257,7 @@ static int __inet6_check_established(struct inet_timewait_death_row *death_row, ...@@ -257,7 +257,7 @@ static int __inet6_check_established(struct inet_timewait_death_row *death_row,
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
} }
static inline u32 inet6_sk_port_offset(const struct sock *sk) static u32 inet6_sk_port_offset(const struct sock *sk)
{ {
const struct inet_sock *inet = inet_sk(sk); const struct inet_sock *inet = inet_sk(sk);
...@@ -269,7 +269,11 @@ static inline u32 inet6_sk_port_offset(const struct sock *sk) ...@@ -269,7 +269,11 @@ static inline u32 inet6_sk_port_offset(const struct sock *sk)
int inet6_hash_connect(struct inet_timewait_death_row *death_row, int inet6_hash_connect(struct inet_timewait_death_row *death_row,
struct sock *sk) struct sock *sk)
{ {
return __inet_hash_connect(death_row, sk, inet6_sk_port_offset(sk), u32 port_offset = 0;
if (!inet_sk(sk)->inet_num)
port_offset = inet6_sk_port_offset(sk);
return __inet_hash_connect(death_row, sk, port_offset,
__inet6_check_established); __inet6_check_established);
} }
EXPORT_SYMBOL_GPL(inet6_hash_connect); EXPORT_SYMBOL_GPL(inet6_hash_connect);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment