Commit b09bde5c authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

inet: move inet->mc_loop to inet->inet_frags

IP_MULTICAST_LOOP socket option can now be set/read
without locking the socket.

v3: fix build bot error reported in ipvs set_mcast_loop()
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Acked-by: default avatarSoheil Hassas Yeganeh <soheil@google.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cafbe182
...@@ -231,7 +231,6 @@ struct inet_sock { ...@@ -231,7 +231,6 @@ struct inet_sock {
__u8 mc_ttl; __u8 mc_ttl;
__u8 pmtudisc; __u8 pmtudisc;
__u8 is_icsk:1, __u8 is_icsk:1,
mc_loop:1,
transparent:1, transparent:1,
mc_all:1, mc_all:1,
nodefrag:1; nodefrag:1;
...@@ -271,6 +270,7 @@ enum { ...@@ -271,6 +270,7 @@ enum {
INET_FLAGS_RECVERR_RFC4884 = 10, INET_FLAGS_RECVERR_RFC4884 = 10,
INET_FLAGS_FREEBIND = 11, INET_FLAGS_FREEBIND = 11,
INET_FLAGS_HDRINCL = 12, INET_FLAGS_HDRINCL = 12,
INET_FLAGS_MC_LOOP = 13,
}; };
/* cmsg flags for inet */ /* cmsg flags for inet */
......
...@@ -767,7 +767,7 @@ bool sk_mc_loop(struct sock *sk) ...@@ -767,7 +767,7 @@ bool sk_mc_loop(struct sock *sk)
return true; return true;
switch (sk->sk_family) { switch (sk->sk_family) {
case AF_INET: case AF_INET:
return inet_sk(sk)->mc_loop; return inet_test_bit(MC_LOOP, sk);
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
case AF_INET6: case AF_INET6:
return inet6_sk(sk)->mc_loop; return inet6_sk(sk)->mc_loop;
......
...@@ -356,7 +356,7 @@ static int inet_create(struct net *net, struct socket *sock, int protocol, ...@@ -356,7 +356,7 @@ static int inet_create(struct net *net, struct socket *sock, int protocol,
sk->sk_txrehash = READ_ONCE(net->core.sysctl_txrehash); sk->sk_txrehash = READ_ONCE(net->core.sysctl_txrehash);
inet->uc_ttl = -1; inet->uc_ttl = -1;
inet->mc_loop = 1; inet_set_bit(MC_LOOP, sk);
inet->mc_ttl = 1; inet->mc_ttl = 1;
inet->mc_all = 1; inet->mc_all = 1;
inet->mc_index = 0; inet->mc_index = 0;
......
...@@ -186,7 +186,7 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb, ...@@ -186,7 +186,7 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
inet_sockopt.is_icsk = inet->is_icsk; inet_sockopt.is_icsk = inet->is_icsk;
inet_sockopt.freebind = inet_test_bit(FREEBIND, sk); inet_sockopt.freebind = inet_test_bit(FREEBIND, sk);
inet_sockopt.hdrincl = inet_test_bit(HDRINCL, sk); inet_sockopt.hdrincl = inet_test_bit(HDRINCL, sk);
inet_sockopt.mc_loop = inet->mc_loop; inet_sockopt.mc_loop = inet_test_bit(MC_LOOP, sk);
inet_sockopt.transparent = inet->transparent; inet_sockopt.transparent = inet->transparent;
inet_sockopt.mc_all = inet->mc_all; inet_sockopt.mc_all = inet->mc_all;
inet_sockopt.nodefrag = inet->nodefrag; inet_sockopt.nodefrag = inet->nodefrag;
......
...@@ -993,6 +993,11 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname, ...@@ -993,6 +993,11 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
return -ENOPROTOOPT; return -ENOPROTOOPT;
inet_assign_bit(HDRINCL, sk, val); inet_assign_bit(HDRINCL, sk, val);
return 0; return 0;
case IP_MULTICAST_LOOP:
if (optlen < 1)
return -EINVAL;
inet_assign_bit(MC_LOOP, sk, val);
return 0;
} }
err = 0; err = 0;
...@@ -1083,11 +1088,6 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname, ...@@ -1083,11 +1088,6 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
goto e_inval; goto e_inval;
inet->mc_ttl = val; inet->mc_ttl = val;
break; break;
case IP_MULTICAST_LOOP:
if (optlen < 1)
goto e_inval;
inet->mc_loop = !!val;
break;
case IP_UNICAST_IF: case IP_UNICAST_IF:
{ {
struct net_device *dev = NULL; struct net_device *dev = NULL;
...@@ -1579,6 +1579,9 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname, ...@@ -1579,6 +1579,9 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
case IP_HDRINCL: case IP_HDRINCL:
val = inet_test_bit(HDRINCL, sk); val = inet_test_bit(HDRINCL, sk);
goto copyval; goto copyval;
case IP_MULTICAST_LOOP:
val = inet_test_bit(MC_LOOP, sk);
goto copyval;
} }
if (needs_rtnl) if (needs_rtnl)
...@@ -1653,9 +1656,6 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname, ...@@ -1653,9 +1656,6 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
case IP_MULTICAST_TTL: case IP_MULTICAST_TTL:
val = inet->mc_ttl; val = inet->mc_ttl;
break; break;
case IP_MULTICAST_LOOP:
val = inet->mc_loop;
break;
case IP_UNICAST_IF: case IP_UNICAST_IF:
val = (__force int)htonl((__u32) inet->uc_index); val = (__force int)htonl((__u32) inet->uc_index);
break; break;
......
...@@ -63,7 +63,7 @@ void setup_udp_tunnel_sock(struct net *net, struct socket *sock, ...@@ -63,7 +63,7 @@ void setup_udp_tunnel_sock(struct net *net, struct socket *sock,
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
/* Disable multicast loopback */ /* Disable multicast loopback */
inet_sk(sk)->mc_loop = 0; inet_clear_bit(MC_LOOP, sk);
/* Enable CHECKSUM_UNNECESSARY to CHECKSUM_COMPLETE conversion */ /* Enable CHECKSUM_UNNECESSARY to CHECKSUM_COMPLETE conversion */
inet_inc_convert_csum(sk); inet_inc_convert_csum(sk);
......
...@@ -229,7 +229,7 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol, ...@@ -229,7 +229,7 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol,
*/ */
inet->uc_ttl = -1; inet->uc_ttl = -1;
inet->mc_loop = 1; inet_set_bit(MC_LOOP, sk);
inet->mc_ttl = 1; inet->mc_ttl = 1;
inet->mc_index = 0; inet->mc_index = 0;
RCU_INIT_POINTER(inet->mc_list, NULL); RCU_INIT_POINTER(inet->mc_list, NULL);
......
...@@ -1297,11 +1297,9 @@ static void set_sock_size(struct sock *sk, int mode, int val) ...@@ -1297,11 +1297,9 @@ static void set_sock_size(struct sock *sk, int mode, int val)
*/ */
static void set_mcast_loop(struct sock *sk, u_char loop) static void set_mcast_loop(struct sock *sk, u_char loop)
{ {
struct inet_sock *inet = inet_sk(sk);
/* setsockopt(sock, SOL_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)); */ /* setsockopt(sock, SOL_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)); */
lock_sock(sk); lock_sock(sk);
inet->mc_loop = loop ? 1 : 0; inet_assign_bit(MC_LOOP, sk, loop);
#ifdef CONFIG_IP_VS_IPV6 #ifdef CONFIG_IP_VS_IPV6
if (sk->sk_family == AF_INET6) { if (sk->sk_family == AF_INET6) {
struct ipv6_pinfo *np = inet6_sk(sk); struct ipv6_pinfo *np = inet6_sk(sk);
......
...@@ -9482,7 +9482,7 @@ void sctp_copy_sock(struct sock *newsk, struct sock *sk, ...@@ -9482,7 +9482,7 @@ void sctp_copy_sock(struct sock *newsk, struct sock *sk,
newinet->inet_id = get_random_u16(); newinet->inet_id = get_random_u16();
newinet->uc_ttl = inet->uc_ttl; newinet->uc_ttl = inet->uc_ttl;
newinet->mc_loop = 1; inet_set_bit(MC_LOOP, newsk);
newinet->mc_ttl = 1; newinet->mc_ttl = 1;
newinet->mc_index = 0; newinet->mc_index = 0;
newinet->mc_list = NULL; newinet->mc_list = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment