Skip to content

Commit

Permalink
inet: move inet->nodefrag to inet->inet_flags
Browse files Browse the repository at this point in the history
IP_NODEFRAG socket option can now be set/read
without locking the socket.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Aug 16, 2023
1 parent b1c0356 commit f04b8d3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/net/inet_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ static int inet_create(struct net *net, struct socket *sock, int 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;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/inet_diag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 8 additions & 10 deletions net/ipv4/ip_sockglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/netfilter/nf_defrag_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions net/netfilter/ipvs/ip_vs_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit f04b8d3

Please sign in to comment.