From f04b8d3478a3a63f17d8dc0dc6da16a828b48df0 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Wed, 16 Aug 2023 08:15:43 +0000 Subject: [PATCH] inet: move inet->nodefrag to inet->inet_flags IP_NODEFRAG socket option can now be set/read without locking the socket. Signed-off-by: Eric Dumazet Acked-by: Soheil Hassas Yeganeh Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- include/net/inet_sock.h | 2 +- net/ipv4/af_inet.c | 2 +- net/ipv4/inet_diag.c | 2 +- net/ipv4/ip_sockglue.c | 18 ++++++++---------- net/ipv4/netfilter/nf_defrag_ipv4.c | 2 +- net/netfilter/ipvs/ip_vs_core.c | 4 ++-- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index 38f7fc1c4dac..0e6e1b017efb 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h @@ -229,7 +229,6 @@ struct inet_sock { __u8 min_ttl; __u8 mc_ttl; __u8 pmtudisc; - __u8 nodefrag:1; __u8 bind_address_no_port:1, defer_connect:1; /* Indicates that fastopen_connect is set * and cookie exists so we defer connect @@ -270,6 +269,7 @@ enum { INET_FLAGS_MC_ALL = 14, INET_FLAGS_TRANSPARENT = 15, INET_FLAGS_IS_ICSK = 16, + INET_FLAGS_NODEFRAG = 17, }; /* cmsg flags for inet */ diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 0f46b71f8a98..2fb9948b5230 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -333,7 +333,7 @@ lookup_protocol: inet = inet_sk(sk); inet_assign_bit(IS_ICSK, sk, INET_PROTOSW_ICSK & answer_flags); - inet->nodefrag = 0; + inet_clear_bit(NODEFRAG, sk); if (SOCK_RAW == sock->type) { inet->inet_num = protocol; diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c index ada198fc1a92..39606caad484 100644 --- a/net/ipv4/inet_diag.c +++ b/net/ipv4/inet_diag.c @@ -189,7 +189,7 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb, inet_sockopt.mc_loop = inet_test_bit(MC_LOOP, sk); inet_sockopt.transparent = inet_test_bit(TRANSPARENT, sk); inet_sockopt.mc_all = inet_test_bit(MC_ALL, sk); - inet_sockopt.nodefrag = inet->nodefrag; + inet_sockopt.nodefrag = inet_test_bit(NODEFRAG, sk); inet_sockopt.bind_address_no_port = inet->bind_address_no_port; inet_sockopt.recverr_rfc4884 = inet_test_bit(RECVERR_RFC4884, sk); inet_sockopt.defer_connect = inet->defer_connect; diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index dac471ed067b..ec946c13ea20 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -1015,6 +1015,11 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname, goto e_inval; inet_assign_bit(TRANSPARENT, sk, val); return 0; + case IP_NODEFRAG: + if (sk->sk_type != SOCK_RAW) + return -ENOPROTOOPT; + inet_assign_bit(NODEFRAG, sk, val); + return 0; } err = 0; @@ -1079,13 +1084,6 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname, goto e_inval; inet->uc_ttl = val; break; - case IP_NODEFRAG: - if (sk->sk_type != SOCK_RAW) { - err = -ENOPROTOOPT; - break; - } - inet->nodefrag = val ? 1 : 0; - break; case IP_BIND_ADDRESS_NO_PORT: inet->bind_address_no_port = val ? 1 : 0; break; @@ -1586,6 +1584,9 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname, case IP_TRANSPARENT: val = inet_test_bit(TRANSPARENT, sk); goto copyval; + case IP_NODEFRAG: + val = inet_test_bit(NODEFRAG, sk); + goto copyval; } if (needs_rtnl) @@ -1633,9 +1634,6 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname, inet->uc_ttl); break; } - case IP_NODEFRAG: - val = inet->nodefrag; - break; case IP_BIND_ADDRESS_NO_PORT: val = inet->bind_address_no_port; break; diff --git a/net/ipv4/netfilter/nf_defrag_ipv4.c b/net/ipv4/netfilter/nf_defrag_ipv4.c index a9ba7de092c4..265b39bc435b 100644 --- a/net/ipv4/netfilter/nf_defrag_ipv4.c +++ b/net/ipv4/netfilter/nf_defrag_ipv4.c @@ -66,7 +66,7 @@ static unsigned int ipv4_conntrack_defrag(void *priv, struct sock *sk = skb->sk; if (sk && sk_fullsock(sk) && (sk->sk_family == PF_INET) && - inet_sk(sk)->nodefrag) + inet_test_bit(NODEFRAG, sk)) return NF_ACCEPT; #if IS_ENABLED(CONFIG_NF_CONNTRACK) diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c index cb83ca506c5c..3230506ae3ff 100644 --- a/net/netfilter/ipvs/ip_vs_core.c +++ b/net/netfilter/ipvs/ip_vs_core.c @@ -1346,7 +1346,7 @@ ip_vs_out_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *stat if (unlikely(sk && hooknum == NF_INET_LOCAL_OUT && af == AF_INET)) { - if (sk->sk_family == PF_INET && inet_sk(sk)->nodefrag) + if (sk->sk_family == PF_INET && inet_test_bit(NODEFRAG, sk)) return NF_ACCEPT; } @@ -1946,7 +1946,7 @@ ip_vs_in_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state if (unlikely(sk && hooknum == NF_INET_LOCAL_OUT && af == AF_INET)) { - if (sk->sk_family == PF_INET && inet_sk(sk)->nodefrag) + if (sk->sk_family == PF_INET && inet_test_bit(NODEFRAG, sk)) return NF_ACCEPT; }