ipv6: make IPV6_FREEBIND and IPV6_TRANSPARENT lockless
Subsystems (3)
cover ipv6: make IPV6_FREEBIND and IPV6_TRANSPARENT lockless
From: Xuanqiang Luo <[email protected]>
Move both IPv6 setters to the lockless setsockopt path.
Patch 1 handles IPV6_FREEBIND.
Patch 2 handles IPV6_TRANSPARENT.
Xuanqiang Luo (2):
ipv6: make IPV6_FREEBIND setsockopt lockless
ipv6: make IPV6_TRANSPARENT setsockopt lockless
net/ipv6/ipv6_sockglue.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-)
base-commit: 348ea4642f56ab3dc93621c8e3ab0ccd0e5f1782
Signature · 1 line
2.43.0
PATCH 1/2 ipv6: make IPV6_FREEBIND setsockopt lockless
From: Xuanqiang Luo <[email protected]>
IPV6_FREEBIND still takes the socket lock despite using inet_assign_bit() to update the flag shared with IP_FREEBIND. IPv6 TCP and UDP sockets can already update this flag without the lock through SOL_IP/IP_FREEBIND.
Move IPV6_FREEBIND to the lockless setsockopt path.
--- net/ipv6/ipv6_sockglue.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
net/ipv6/ipv6_sockglue.c +6 -8
@@ -398,6 +398,12 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname,/* Handle options that can be set without locking the socket. */ switch (optname) { +case IPV6_FREEBIND : +if (optlen <sizeof (int )) +return -EINVAL ; +/* Shared with IP_FREEBIND. */ +inet_assign_bit (FREEBIND , sk, valbool); +return 0 ;case IPV6_UNICAST_HOPS :if (optlen <sizeof (int ))return -EINVAL ;
@@ -679,14 +685,6 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname, retv =0 ;break ; -case IPV6_FREEBIND : -if (optlen <sizeof (int )) - goto e_inval; -/* we also don't have a separate freebind bit for IPV6 */ -inet_assign_bit (FREEBIND , sk, valbool); - retv =0 ; -break ; -case IPV6_RECVORIGDSTADDR :if (optlen <sizeof (int )) goto e_inval;
Signature · 1 line
2.43.0
PATCH 2/2 ipv6: make IPV6_TRANSPARENT setsockopt lockless
In reply to Xuanqiang LuoFrom: Xuanqiang Luo <[email protected]>
IPV6_TRANSPARENT still takes the socket lock despite using inet_assign_bit() to update the flag shared with IP_TRANSPARENT. IPv6 TCP and UDP sockets can already update this flag without the lock through SOL_IP/IP_TRANSPARENT.
Move IPV6_TRANSPARENT to the lockless setsockopt path.
--- net/ipv6/ipv6_sockglue.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
net/ipv6/ipv6_sockglue.c +9 -13
@@ -404,6 +404,15 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname,/* Shared with IP_FREEBIND. */ inet_assign_bit (FREEBIND , sk, valbool);return 0 ; +case IPV6_TRANSPARENT : +if (valbool && !sockopt_ns_capable (net->user_ns,CAP_NET_RAW ) && + !sockopt_ns_capable (net->user_ns,CAP_NET_ADMIN )) +return -EPERM ; +if (optlen <sizeof (int )) +return -EINVAL ; +/* Shared with IP_TRANSPARENT. */ +inet_assign_bit (TRANSPARENT , sk, valbool); +return 0 ;case IPV6_UNICAST_HOPS :if (optlen <sizeof (int ))return -EINVAL ;
@@ -672,19 +681,6 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname, retv =0 ;break ; -case IPV6_TRANSPARENT : -if (valbool && !sockopt_ns_capable (net->user_ns,CAP_NET_RAW ) && - !sockopt_ns_capable (net->user_ns,CAP_NET_ADMIN )) { - retv = -EPERM ; -break ; - } -if (optlen <sizeof (int )) - goto e_inval; -/* we don't have a separate transparent bit for IPV6 we use the one in the IPv4 socket */ -inet_assign_bit (TRANSPARENT , sk, valbool); - retv =0 ; -break ; -case IPV6_RECVORIGDSTADDR :if (optlen <sizeof (int )) goto e_inval;
Signature · 1 line
2.43.0
Quoted 9 lines · Xuanqiang Luo
From: Xuanqiang Luo <[email protected]>
Move both IPv6 setters to the lockless setsockopt path.
Patch 1 handles
IPV6_FREEBIND.Patch 2 handles
IPV6_TRANSPARENT.
The changes are fine, they simply align IPv6 with what IP_FREEBIND and IP_TRANSPARENT have been doing in ip_sockglue.c already.
However, both patches touch the same switch() in the same function and do exactly the same thing. Please squash them into a single patch in v2, no cover letter needed then.
Thanks!
pw-bot: cr