Skip to content

Commit c11204c

Browse files
yydcooldavem330
authored andcommitted
txhash: fix sk->sk_txrehash default
This code fix a bug that sk->sk_txrehash gets its default enable value from sysctl_txrehash only when the socket is a TCP listener. We should have sysctl_txrehash to set the default sk->sk_txrehash, no matter TCP, nor listerner/connector. Tested by following packetdrill: 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 +0 socket(..., SOCK_DGRAM, IPPROTO_UDP) = 4 // SO_TXREHASH == 74, default to sysctl_txrehash == 1 +0 getsockopt(3, SOL_SOCKET, 74, [1], [4]) = 0 +0 getsockopt(4, SOL_SOCKET, 74, [1], [4]) = 0 Fixes: 2685924 ("txhash: Add socket option to control TX hash rethink behavior") Signed-off-by: Kevin Yang <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c966153 commit c11204c

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

net/core/sock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,8 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
15311531
ret = -EINVAL;
15321532
break;
15331533
}
1534+
if ((u8)val == SOCK_TXREHASH_DEFAULT)
1535+
val = READ_ONCE(sock_net(sk)->core.sysctl_txrehash);
15341536
/* Paired with READ_ONCE() in tcp_rtx_synack() */
15351537
WRITE_ONCE(sk->sk_txrehash, (u8)val);
15361538
break;
@@ -3451,7 +3453,6 @@ void sock_init_data(struct socket *sock, struct sock *sk)
34513453
sk->sk_pacing_rate = ~0UL;
34523454
WRITE_ONCE(sk->sk_pacing_shift, 10);
34533455
sk->sk_incoming_cpu = -1;
3454-
sk->sk_txrehash = SOCK_TXREHASH_DEFAULT;
34553456

34563457
sk_rx_queue_clear(sk);
34573458
/*

net/ipv4/af_inet.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ static int inet_create(struct net *net, struct socket *sock, int protocol,
347347
sk->sk_destruct = inet_sock_destruct;
348348
sk->sk_protocol = protocol;
349349
sk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
350+
sk->sk_txrehash = READ_ONCE(net->core.sysctl_txrehash);
350351

351352
inet->uc_ttl = -1;
352353
inet->mc_loop = 1;

net/ipv4/inet_connection_sock.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,9 +1225,6 @@ int inet_csk_listen_start(struct sock *sk)
12251225
sk->sk_ack_backlog = 0;
12261226
inet_csk_delack_init(sk);
12271227

1228-
if (sk->sk_txrehash == SOCK_TXREHASH_DEFAULT)
1229-
sk->sk_txrehash = READ_ONCE(sock_net(sk)->core.sysctl_txrehash);
1230-
12311228
/* There is race window here: we announce ourselves listening,
12321229
* but this transition is still not validated by get_port().
12331230
* It is OK, because this socket enters to hash table only

net/ipv6/af_inet6.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol,
222222
np->pmtudisc = IPV6_PMTUDISC_WANT;
223223
np->repflow = net->ipv6.sysctl.flowlabel_reflect & FLOWLABEL_REFLECT_ESTABLISHED;
224224
sk->sk_ipv6only = net->ipv6.sysctl.bindv6only;
225+
sk->sk_txrehash = READ_ONCE(net->core.sysctl_txrehash);
225226

226227
/* Init the ipv4 part of the socket since we can have sockets
227228
* using v6 API for ipv4.

0 commit comments

Comments
 (0)