summaryrefslogtreecommitdiffstats
path: root/net/ipv4/ip_sockglue.c
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2021-10-25 18:48:24 +0200
committerJakub Kicinski <kuba@kernel.org>2021-10-26 03:02:14 +0200
commit020e71a3cf7f50c0f2c54cf2444067b76fe6d785 (patch)
tree34f7f3b49927f2807a6a72bd488328484a728e00 /net/ipv4/ip_sockglue.c
parentipv4: annotate data races arount inet->min_ttl (diff)
downloadlinux-020e71a3cf7f50c0f2c54cf2444067b76fe6d785.tar.xz
linux-020e71a3cf7f50c0f2c54cf2444067b76fe6d785.zip
ipv4: guard IP_MINTTL with a static key
RFC 5082 IP_MINTTL option is rarely used on hosts. Add a static key to remove from TCP fast path useless code, and potential cache line miss to fetch inet_sk(sk)->min_ttl Note that once ip4_min_ttl static key has been enabled, it stays enabled until next boot. Signed-off-by: Eric Dumazet <edumazet@google.com> Acked-by: Soheil Hassas Yeganeh <soheil@google.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/ipv4/ip_sockglue.c')
-rw-r--r--net/ipv4/ip_sockglue.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index d5487c858067..38d29b175ca6 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -886,6 +886,8 @@ static int compat_ip_mcast_join_leave(struct sock *sk, int optname,
return ip_mc_leave_group(sk, &mreq);
}
+DEFINE_STATIC_KEY_FALSE(ip4_min_ttl);
+
static int do_ip_setsockopt(struct sock *sk, int level, int optname,
sockptr_t optval, unsigned int optlen)
{
@@ -1352,6 +1354,10 @@ static int do_ip_setsockopt(struct sock *sk, int level, int optname,
goto e_inval;
if (val < 0 || val > 255)
goto e_inval;
+
+ if (val)
+ static_branch_enable(&ip4_min_ttl);
+
/* tcp_v4_err() and tcp_v4_rcv() might read min_ttl
* while we are changint it.
*/