Commit e187013a authored by Akhmat Karakotov's avatar Akhmat Karakotov Committed by David S. Miller

txhash: Make rethinking txhash behavior configurable via sysctl

Add a per ns sysctl that controls the txhash rethink behavior:
net.core.txrehash. When enabled, the same behavior is retained,
when disabled, rethink is not performed. Sysctl is enabled by default.
Signed-off-by: default avatarAkhmat Karakotov <hmukos@yandex-team.ru>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 678dfd52
...@@ -10,6 +10,7 @@ struct netns_core { ...@@ -10,6 +10,7 @@ struct netns_core {
struct ctl_table_header *sysctl_hdr; struct ctl_table_header *sysctl_hdr;
int sysctl_somaxconn; int sysctl_somaxconn;
u8 sysctl_txrehash;
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
struct prot_inuse __percpu *prot_inuse; struct prot_inuse __percpu *prot_inuse;
......
...@@ -587,6 +587,18 @@ static inline bool sk_user_data_is_nocopy(const struct sock *sk) ...@@ -587,6 +587,18 @@ static inline bool sk_user_data_is_nocopy(const struct sock *sk)
__tmp | SK_USER_DATA_NOCOPY); \ __tmp | SK_USER_DATA_NOCOPY); \
}) })
static inline
struct net *sock_net(const struct sock *sk)
{
return read_pnet(&sk->sk_net);
}
static inline
void sock_net_set(struct sock *sk, struct net *net)
{
write_pnet(&sk->sk_net, net);
}
/* /*
* SK_CAN_REUSE and SK_NO_REUSE on a socket mean that the socket is OK * SK_CAN_REUSE and SK_NO_REUSE on a socket mean that the socket is OK
* or not whether his port will be reused by someone else. SK_FORCE_REUSE * or not whether his port will be reused by someone else. SK_FORCE_REUSE
...@@ -2054,10 +2066,18 @@ static inline void sk_set_txhash(struct sock *sk) ...@@ -2054,10 +2066,18 @@ static inline void sk_set_txhash(struct sock *sk)
static inline bool sk_rethink_txhash(struct sock *sk) static inline bool sk_rethink_txhash(struct sock *sk)
{ {
if (sk->sk_txhash) { u8 rehash;
if (!sk->sk_txhash)
return false;
rehash = READ_ONCE(sock_net(sk)->core.sysctl_txrehash);
if (rehash) {
sk_set_txhash(sk); sk_set_txhash(sk);
return true; return true;
} }
return false; return false;
} }
...@@ -2704,18 +2724,6 @@ static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb) ...@@ -2704,18 +2724,6 @@ static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb)
__kfree_skb(skb); __kfree_skb(skb);
} }
static inline
struct net *sock_net(const struct sock *sk)
{
return read_pnet(&sk->sk_net);
}
static inline
void sock_net_set(struct sock *sk, struct net *net)
{
write_pnet(&sk->sk_net, net);
}
static inline bool static inline bool
skb_sk_is_prefetched(struct sk_buff *skb) skb_sk_is_prefetched(struct sk_buff *skb)
{ {
......
...@@ -31,4 +31,7 @@ struct __kernel_sockaddr_storage { ...@@ -31,4 +31,7 @@ struct __kernel_sockaddr_storage {
#define SOCK_BUF_LOCK_MASK (SOCK_SNDBUF_LOCK | SOCK_RCVBUF_LOCK) #define SOCK_BUF_LOCK_MASK (SOCK_SNDBUF_LOCK | SOCK_RCVBUF_LOCK)
#define SOCK_TXREHASH_DISABLED 0
#define SOCK_TXREHASH_ENABLED 1
#endif /* _UAPI_LINUX_SOCKET_H */ #endif /* _UAPI_LINUX_SOCKET_H */
...@@ -364,6 +364,8 @@ static __net_init int setup_net(struct net *net, struct user_namespace *user_ns) ...@@ -364,6 +364,8 @@ static __net_init int setup_net(struct net *net, struct user_namespace *user_ns)
static int __net_init net_defaults_init_net(struct net *net) static int __net_init net_defaults_init_net(struct net *net)
{ {
net->core.sysctl_somaxconn = SOMAXCONN; net->core.sysctl_somaxconn = SOMAXCONN;
net->core.sysctl_txrehash = SOCK_TXREHASH_ENABLED;
return 0; return 0;
} }
......
...@@ -593,6 +593,15 @@ static struct ctl_table netns_core_table[] = { ...@@ -593,6 +593,15 @@ static struct ctl_table netns_core_table[] = {
.extra1 = SYSCTL_ZERO, .extra1 = SYSCTL_ZERO,
.proc_handler = proc_dointvec_minmax .proc_handler = proc_dointvec_minmax
}, },
{
.procname = "txrehash",
.data = &init_net.core.sysctl_txrehash,
.maxlen = sizeof(u8),
.mode = 0644,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
.proc_handler = proc_dou8vec_minmax,
},
{ } { }
}; };
...@@ -611,7 +620,7 @@ __setup("fb_tunnels=", fb_tunnels_only_for_init_net_sysctl_setup); ...@@ -611,7 +620,7 @@ __setup("fb_tunnels=", fb_tunnels_only_for_init_net_sysctl_setup);
static __net_init int sysctl_core_net_init(struct net *net) static __net_init int sysctl_core_net_init(struct net *net)
{ {
struct ctl_table *tbl; struct ctl_table *tbl, *tmp;
tbl = netns_core_table; tbl = netns_core_table;
if (!net_eq(net, &init_net)) { if (!net_eq(net, &init_net)) {
...@@ -619,7 +628,8 @@ static __net_init int sysctl_core_net_init(struct net *net) ...@@ -619,7 +628,8 @@ static __net_init int sysctl_core_net_init(struct net *net)
if (tbl == NULL) if (tbl == NULL)
goto err_dup; goto err_dup;
tbl[0].data = &net->core.sysctl_somaxconn; for (tmp = tbl; tmp->procname; tmp++)
tmp->data += (char *)net - (char *)&init_net;
/* Don't export any sysctls to unprivileged users */ /* Don't export any sysctls to unprivileged users */
if (net->user_ns != &init_user_ns) { if (net->user_ns != &init_user_ns) {
......
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