inet: move inet->bind_address_no_port to inet->inet_flags

IP_BIND_ADDRESS_NO_PORT 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>
This commit is contained in:
Eric Dumazet 2023-08-16 08:15:44 +00:00 коммит произвёл David S. Miller
Родитель f04b8d3478
Коммит ca571e2eb7
5 изменённых файлов: 11 добавлений и 11 удалений

Просмотреть файл

@ -229,8 +229,7 @@ struct inet_sock {
__u8 min_ttl; __u8 min_ttl;
__u8 mc_ttl; __u8 mc_ttl;
__u8 pmtudisc; __u8 pmtudisc;
__u8 bind_address_no_port:1, __u8 defer_connect:1; /* Indicates that fastopen_connect is set
defer_connect:1; /* Indicates that fastopen_connect is set
* and cookie exists so we defer connect * and cookie exists so we defer connect
* until first data frame is written * until first data frame is written
*/ */
@ -270,6 +269,7 @@ enum {
INET_FLAGS_TRANSPARENT = 15, INET_FLAGS_TRANSPARENT = 15,
INET_FLAGS_IS_ICSK = 16, INET_FLAGS_IS_ICSK = 16,
INET_FLAGS_NODEFRAG = 17, INET_FLAGS_NODEFRAG = 17,
INET_FLAGS_BIND_ADDRESS_NO_PORT = 18,
}; };
/* cmsg flags for inet */ /* cmsg flags for inet */

Просмотреть файл

@ -529,7 +529,7 @@ int __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
inet->inet_saddr = 0; /* Use device */ inet->inet_saddr = 0; /* Use device */
/* Make sure we are allowed to bind here. */ /* Make sure we are allowed to bind here. */
if (snum || !(inet->bind_address_no_port || if (snum || !(inet_test_bit(BIND_ADDRESS_NO_PORT, sk) ||
(flags & BIND_FORCE_ADDRESS_NO_PORT))) { (flags & BIND_FORCE_ADDRESS_NO_PORT))) {
err = sk->sk_prot->get_port(sk, snum); err = sk->sk_prot->get_port(sk, snum);
if (err) { if (err) {

Просмотреть файл

@ -190,7 +190,7 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
inet_sockopt.transparent = inet_test_bit(TRANSPARENT, sk); inet_sockopt.transparent = inet_test_bit(TRANSPARENT, sk);
inet_sockopt.mc_all = inet_test_bit(MC_ALL, sk); inet_sockopt.mc_all = inet_test_bit(MC_ALL, sk);
inet_sockopt.nodefrag = inet_test_bit(NODEFRAG, sk); inet_sockopt.nodefrag = inet_test_bit(NODEFRAG, sk);
inet_sockopt.bind_address_no_port = inet->bind_address_no_port; inet_sockopt.bind_address_no_port = inet_test_bit(BIND_ADDRESS_NO_PORT, sk);
inet_sockopt.recverr_rfc4884 = inet_test_bit(RECVERR_RFC4884, sk); inet_sockopt.recverr_rfc4884 = inet_test_bit(RECVERR_RFC4884, sk);
inet_sockopt.defer_connect = inet->defer_connect; inet_sockopt.defer_connect = inet->defer_connect;
if (nla_put(skb, INET_DIAG_SOCKOPT, sizeof(inet_sockopt), if (nla_put(skb, INET_DIAG_SOCKOPT, sizeof(inet_sockopt),

Просмотреть файл

@ -1020,6 +1020,9 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
return -ENOPROTOOPT; return -ENOPROTOOPT;
inet_assign_bit(NODEFRAG, sk, val); inet_assign_bit(NODEFRAG, sk, val);
return 0; return 0;
case IP_BIND_ADDRESS_NO_PORT:
inet_assign_bit(BIND_ADDRESS_NO_PORT, sk, val);
return 0;
} }
err = 0; err = 0;
@ -1084,9 +1087,6 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
goto e_inval; goto e_inval;
inet->uc_ttl = val; inet->uc_ttl = val;
break; break;
case IP_BIND_ADDRESS_NO_PORT:
inet->bind_address_no_port = val ? 1 : 0;
break;
case IP_MTU_DISCOVER: case IP_MTU_DISCOVER:
if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_OMIT) if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_OMIT)
goto e_inval; goto e_inval;
@ -1587,6 +1587,9 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
case IP_NODEFRAG: case IP_NODEFRAG:
val = inet_test_bit(NODEFRAG, sk); val = inet_test_bit(NODEFRAG, sk);
goto copyval; goto copyval;
case IP_BIND_ADDRESS_NO_PORT:
val = inet_test_bit(BIND_ADDRESS_NO_PORT, sk);
goto copyval;
} }
if (needs_rtnl) if (needs_rtnl)
@ -1634,9 +1637,6 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
inet->uc_ttl); inet->uc_ttl);
break; break;
} }
case IP_BIND_ADDRESS_NO_PORT:
val = inet->bind_address_no_port;
break;
case IP_MTU_DISCOVER: case IP_MTU_DISCOVER:
val = inet->pmtudisc; val = inet->pmtudisc;
break; break;

Просмотреть файл

@ -399,7 +399,7 @@ static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
sk->sk_ipv6only = 1; sk->sk_ipv6only = 1;
/* Make sure we are allowed to bind here. */ /* Make sure we are allowed to bind here. */
if (snum || !(inet->bind_address_no_port || if (snum || !(inet_test_bit(BIND_ADDRESS_NO_PORT, sk) ||
(flags & BIND_FORCE_ADDRESS_NO_PORT))) { (flags & BIND_FORCE_ADDRESS_NO_PORT))) {
err = sk->sk_prot->get_port(sk, snum); err = sk->sk_prot->get_port(sk, snum);
if (err) { if (err) {