Skip to content

Commit ca571e2

Browse files
edumazetdavem330
authored andcommitted
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 <[email protected]> Acked-by: Soheil Hassas Yeganeh <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f04b8d3 commit ca571e2

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

include/net/inet_sock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ struct inet_sock {
229229
__u8 min_ttl;
230230
__u8 mc_ttl;
231231
__u8 pmtudisc;
232-
__u8 bind_address_no_port:1,
233-
defer_connect:1; /* Indicates that fastopen_connect is set
232+
__u8 defer_connect:1; /* Indicates that fastopen_connect is set
234233
* and cookie exists so we defer connect
235234
* until first data frame is written
236235
*/
@@ -270,6 +269,7 @@ enum {
270269
INET_FLAGS_TRANSPARENT = 15,
271270
INET_FLAGS_IS_ICSK = 16,
272271
INET_FLAGS_NODEFRAG = 17,
272+
INET_FLAGS_BIND_ADDRESS_NO_PORT = 18,
273273
};
274274

275275
/* cmsg flags for inet */

net/ipv4/af_inet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ int __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
529529
inet->inet_saddr = 0; /* Use device */
530530

531531
/* Make sure we are allowed to bind here. */
532-
if (snum || !(inet->bind_address_no_port ||
532+
if (snum || !(inet_test_bit(BIND_ADDRESS_NO_PORT, sk) ||
533533
(flags & BIND_FORCE_ADDRESS_NO_PORT))) {
534534
err = sk->sk_prot->get_port(sk, snum);
535535
if (err) {

net/ipv4/inet_diag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
190190
inet_sockopt.transparent = inet_test_bit(TRANSPARENT, sk);
191191
inet_sockopt.mc_all = inet_test_bit(MC_ALL, sk);
192192
inet_sockopt.nodefrag = inet_test_bit(NODEFRAG, sk);
193-
inet_sockopt.bind_address_no_port = inet->bind_address_no_port;
193+
inet_sockopt.bind_address_no_port = inet_test_bit(BIND_ADDRESS_NO_PORT, sk);
194194
inet_sockopt.recverr_rfc4884 = inet_test_bit(RECVERR_RFC4884, sk);
195195
inet_sockopt.defer_connect = inet->defer_connect;
196196
if (nla_put(skb, INET_DIAG_SOCKOPT, sizeof(inet_sockopt),

net/ipv4/ip_sockglue.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,9 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
10201020
return -ENOPROTOOPT;
10211021
inet_assign_bit(NODEFRAG, sk, val);
10221022
return 0;
1023+
case IP_BIND_ADDRESS_NO_PORT:
1024+
inet_assign_bit(BIND_ADDRESS_NO_PORT, sk, val);
1025+
return 0;
10231026
}
10241027

10251028
err = 0;
@@ -1084,9 +1087,6 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
10841087
goto e_inval;
10851088
inet->uc_ttl = val;
10861089
break;
1087-
case IP_BIND_ADDRESS_NO_PORT:
1088-
inet->bind_address_no_port = val ? 1 : 0;
1089-
break;
10901090
case IP_MTU_DISCOVER:
10911091
if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_OMIT)
10921092
goto e_inval;
@@ -1587,6 +1587,9 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
15871587
case IP_NODEFRAG:
15881588
val = inet_test_bit(NODEFRAG, sk);
15891589
goto copyval;
1590+
case IP_BIND_ADDRESS_NO_PORT:
1591+
val = inet_test_bit(BIND_ADDRESS_NO_PORT, sk);
1592+
goto copyval;
15901593
}
15911594

15921595
if (needs_rtnl)
@@ -1634,9 +1637,6 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
16341637
inet->uc_ttl);
16351638
break;
16361639
}
1637-
case IP_BIND_ADDRESS_NO_PORT:
1638-
val = inet->bind_address_no_port;
1639-
break;
16401640
case IP_MTU_DISCOVER:
16411641
val = inet->pmtudisc;
16421642
break;

net/ipv6/af_inet6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
399399
sk->sk_ipv6only = 1;
400400

401401
/* Make sure we are allowed to bind here. */
402-
if (snum || !(inet->bind_address_no_port ||
402+
if (snum || !(inet_test_bit(BIND_ADDRESS_NO_PORT, sk) ||
403403
(flags & BIND_FORCE_ADDRESS_NO_PORT))) {
404404
err = sk->sk_prot->get_port(sk, snum);
405405
if (err) {

0 commit comments

Comments
 (0)