From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <simon.horman@corigine.com>,
Soheil Hassas Yeganeh <soheil@google.com>,
netdev@vger.kernel.org, eric.dumazet@gmail.com,
Eric Dumazet <edumazet@google.com>
Subject: [PATCH v2 net-next 12/15] inet: move inet->bind_address_no_port to inet->inet_flags
Date: Fri, 11 Aug 2023 07:36:18 +0000 [thread overview]
Message-ID: <20230811073621.2874702-13-edumazet@google.com> (raw)
In-Reply-To: <20230811073621.2874702-1-edumazet@google.com>
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>
---
include/net/inet_sock.h | 4 ++--
net/ipv4/af_inet.c | 2 +-
net/ipv4/inet_diag.c | 2 +-
net/ipv4/ip_sockglue.c | 12 ++++++------
net/ipv6/af_inet6.c | 2 +-
5 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
index 0e6e1b017efb1f738be1682448675ecece43c1f7..5eca2e70cbb2c16d26caa7f219ae53fe066ea3bd 100644
--- a/include/net/inet_sock.h
+++ b/include/net/inet_sock.h
@@ -229,8 +229,7 @@ struct inet_sock {
__u8 min_ttl;
__u8 mc_ttl;
__u8 pmtudisc;
- __u8 bind_address_no_port:1,
- defer_connect:1; /* Indicates that fastopen_connect is set
+ __u8 defer_connect:1; /* Indicates that fastopen_connect is set
* and cookie exists so we defer connect
* until first data frame is written
*/
@@ -270,6 +269,7 @@ enum {
INET_FLAGS_TRANSPARENT = 15,
INET_FLAGS_IS_ICSK = 16,
INET_FLAGS_NODEFRAG = 17,
+ INET_FLAGS_BIND_ADDRESS_NO_PORT = 18,
};
/* cmsg flags for inet */
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index f684310c8f24ca08170f39ec955d20209566d7c5..c591f04eb6a9fc3b7b37a4b93b826a35488b9b50 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -519,7 +519,7 @@ int __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
inet->inet_saddr = 0; /* Use device */
/* 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))) {
err = sk->sk_prot->get_port(sk, snum);
if (err) {
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 39606caad484a99a78beae399e38e56584f23f28..128966dea5540caaa94f6b87db4d3960d177caac 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -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.mc_all = inet_test_bit(MC_ALL, 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.defer_connect = inet->defer_connect;
if (nla_put(skb, INET_DIAG_SOCKOPT, sizeof(inet_sockopt),
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index ec946c13ea206dde3c5634d6dcd07aab7090cad8..cfa65a0b0900f2f77bfd800f105ea079e2afff7c 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -1020,6 +1020,9 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
return -ENOPROTOOPT;
inet_assign_bit(NODEFRAG, sk, val);
return 0;
+ case IP_BIND_ADDRESS_NO_PORT:
+ inet_assign_bit(BIND_ADDRESS_NO_PORT, sk, val);
+ return 0;
}
err = 0;
@@ -1084,9 +1087,6 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
goto e_inval;
inet->uc_ttl = val;
break;
- case IP_BIND_ADDRESS_NO_PORT:
- inet->bind_address_no_port = val ? 1 : 0;
- break;
case IP_MTU_DISCOVER:
if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_OMIT)
goto e_inval;
@@ -1587,6 +1587,9 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
case IP_NODEFRAG:
val = inet_test_bit(NODEFRAG, sk);
goto copyval;
+ case IP_BIND_ADDRESS_NO_PORT:
+ val = inet_test_bit(BIND_ADDRESS_NO_PORT, sk);
+ goto copyval;
}
if (needs_rtnl)
@@ -1634,9 +1637,6 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
inet->uc_ttl);
break;
}
- case IP_BIND_ADDRESS_NO_PORT:
- val = inet->bind_address_no_port;
- break;
case IP_MTU_DISCOVER:
val = inet->pmtudisc;
break;
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index fea7918ad6ef351afc6bfb45d54aae8d658d4b55..37af30fefeca317a6fa1a32db84b6ee3500301a9 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -399,7 +399,7 @@ static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
sk->sk_ipv6only = 1;
/* 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))) {
err = sk->sk_prot->get_port(sk, snum);
if (err) {
--
2.41.0.640.ga95def55d0-goog
next prev parent reply other threads:[~2023-08-11 7:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-11 7:36 [PATCH v2 net-next 00/15] inet: socket lock and data-races avoidance Eric Dumazet
2023-08-11 7:36 ` [PATCH v2 net-next 01/15] inet: introduce inet->inet_flags Eric Dumazet
2023-08-11 7:36 ` [PATCH v2 net-next 02/15] inet: set/get simple options locklessly Eric Dumazet
2023-08-11 7:36 ` [PATCH v2 net-next 03/15] inet: move inet->recverr to inet->inet_flags Eric Dumazet
2023-08-11 7:36 ` [PATCH v2 net-next 04/15] inet: move inet->recverr_rfc4884 " Eric Dumazet
2023-08-11 7:36 ` [PATCH v2 net-next 05/15] inet: move inet->freebind " Eric Dumazet
2023-08-11 7:36 ` [PATCH v2 net-next 06/15] inet: move inet->hdrincl " Eric Dumazet
2023-08-11 7:36 ` [PATCH v2 net-next 07/15] inet: move inet->mc_loop to inet->inet_frags Eric Dumazet
2023-08-11 14:10 ` kernel test robot
2023-08-11 15:48 ` Eric Dumazet
2023-08-11 7:36 ` [PATCH v2 net-next 08/15] inet: move inet->mc_all " Eric Dumazet
2023-08-11 7:36 ` [PATCH v2 net-next 09/15] inet: move inet->transparent to inet->inet_flags Eric Dumazet
2023-08-11 7:36 ` [PATCH v2 net-next 10/15] inet: move inet->is_icsk " Eric Dumazet
2023-08-11 7:36 ` [PATCH v2 net-next 11/15] inet: move inet->nodefrag " Eric Dumazet
2023-08-11 7:36 ` Eric Dumazet [this message]
2023-08-11 7:36 ` [PATCH v2 net-next 13/15] inet: move inet->defer_connect " Eric Dumazet
2023-08-11 7:36 ` [PATCH v2 net-next 14/15] inet: implement lockless IP_TTL Eric Dumazet
2023-08-11 7:36 ` [PATCH v2 net-next 15/15] inet: implement lockless IP_MINTTL Eric Dumazet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230811073621.2874702-13-edumazet@google.com \
--to=edumazet@google.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=simon.horman@corigine.com \
--cc=soheil@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).