Skip to content

Commit b09bde5

Browse files
edumazetdavem330
authored andcommitted
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: 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>
1 parent cafbe18 commit b09bde5

File tree

9 files changed

+16
-18
lines changed

9 files changed

+16
-18
lines changed

include/net/inet_sock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ struct inet_sock {
231231
__u8 mc_ttl;
232232
__u8 pmtudisc;
233233
__u8 is_icsk:1,
234-
mc_loop:1,
235234
transparent:1,
236235
mc_all:1,
237236
nodefrag:1;
@@ -271,6 +270,7 @@ enum {
271270
INET_FLAGS_RECVERR_RFC4884 = 10,
272271
INET_FLAGS_FREEBIND = 11,
273272
INET_FLAGS_HDRINCL = 12,
273+
INET_FLAGS_MC_LOOP = 13,
274274
};
275275

276276
/* cmsg flags for inet */

net/core/sock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ bool sk_mc_loop(struct sock *sk)
767767
return true;
768768
switch (sk->sk_family) {
769769
case AF_INET:
770-
return inet_sk(sk)->mc_loop;
770+
return inet_test_bit(MC_LOOP, sk);
771771
#if IS_ENABLED(CONFIG_IPV6)
772772
case AF_INET6:
773773
return inet6_sk(sk)->mc_loop;

net/ipv4/af_inet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static int inet_create(struct net *net, struct socket *sock, int protocol,
356356
sk->sk_txrehash = READ_ONCE(net->core.sysctl_txrehash);
357357

358358
inet->uc_ttl = -1;
359-
inet->mc_loop = 1;
359+
inet_set_bit(MC_LOOP, sk);
360360
inet->mc_ttl = 1;
361361
inet->mc_all = 1;
362362
inet->mc_index = 0;

net/ipv4/inet_diag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
186186
inet_sockopt.is_icsk = inet->is_icsk;
187187
inet_sockopt.freebind = inet_test_bit(FREEBIND, sk);
188188
inet_sockopt.hdrincl = inet_test_bit(HDRINCL, sk);
189-
inet_sockopt.mc_loop = inet->mc_loop;
189+
inet_sockopt.mc_loop = inet_test_bit(MC_LOOP, sk);
190190
inet_sockopt.transparent = inet->transparent;
191191
inet_sockopt.mc_all = inet->mc_all;
192192
inet_sockopt.nodefrag = inet->nodefrag;

net/ipv4/ip_sockglue.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,11 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
993993
return -ENOPROTOOPT;
994994
inet_assign_bit(HDRINCL, sk, val);
995995
return 0;
996+
case IP_MULTICAST_LOOP:
997+
if (optlen < 1)
998+
return -EINVAL;
999+
inet_assign_bit(MC_LOOP, sk, val);
1000+
return 0;
9961001
}
9971002

9981003
err = 0;
@@ -1083,11 +1088,6 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
10831088
goto e_inval;
10841089
inet->mc_ttl = val;
10851090
break;
1086-
case IP_MULTICAST_LOOP:
1087-
if (optlen < 1)
1088-
goto e_inval;
1089-
inet->mc_loop = !!val;
1090-
break;
10911091
case IP_UNICAST_IF:
10921092
{
10931093
struct net_device *dev = NULL;
@@ -1579,6 +1579,9 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
15791579
case IP_HDRINCL:
15801580
val = inet_test_bit(HDRINCL, sk);
15811581
goto copyval;
1582+
case IP_MULTICAST_LOOP:
1583+
val = inet_test_bit(MC_LOOP, sk);
1584+
goto copyval;
15821585
}
15831586

15841587
if (needs_rtnl)
@@ -1653,9 +1656,6 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
16531656
case IP_MULTICAST_TTL:
16541657
val = inet->mc_ttl;
16551658
break;
1656-
case IP_MULTICAST_LOOP:
1657-
val = inet->mc_loop;
1658-
break;
16591659
case IP_UNICAST_IF:
16601660
val = (__force int)htonl((__u32) inet->uc_index);
16611661
break;

net/ipv4/udp_tunnel_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void setup_udp_tunnel_sock(struct net *net, struct socket *sock,
6363
struct sock *sk = sock->sk;
6464

6565
/* Disable multicast loopback */
66-
inet_sk(sk)->mc_loop = 0;
66+
inet_clear_bit(MC_LOOP, sk);
6767

6868
/* Enable CHECKSUM_UNNECESSARY to CHECKSUM_COMPLETE conversion */
6969
inet_inc_convert_csum(sk);

net/ipv6/af_inet6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol,
229229
*/
230230
inet->uc_ttl = -1;
231231

232-
inet->mc_loop = 1;
232+
inet_set_bit(MC_LOOP, sk);
233233
inet->mc_ttl = 1;
234234
inet->mc_index = 0;
235235
RCU_INIT_POINTER(inet->mc_list, NULL);

net/netfilter/ipvs/ip_vs_sync.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,11 +1297,9 @@ static void set_sock_size(struct sock *sk, int mode, int val)
12971297
*/
12981298
static void set_mcast_loop(struct sock *sk, u_char loop)
12991299
{
1300-
struct inet_sock *inet = inet_sk(sk);
1301-
13021300
/* setsockopt(sock, SOL_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)); */
13031301
lock_sock(sk);
1304-
inet->mc_loop = loop ? 1 : 0;
1302+
inet_assign_bit(MC_LOOP, sk, loop);
13051303
#ifdef CONFIG_IP_VS_IPV6
13061304
if (sk->sk_family == AF_INET6) {
13071305
struct ipv6_pinfo *np = inet6_sk(sk);

net/sctp/socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9482,7 +9482,7 @@ void sctp_copy_sock(struct sock *newsk, struct sock *sk,
94829482
newinet->inet_id = get_random_u16();
94839483

94849484
newinet->uc_ttl = inet->uc_ttl;
9485-
newinet->mc_loop = 1;
9485+
inet_set_bit(MC_LOOP, newsk);
94869486
newinet->mc_ttl = 1;
94879487
newinet->mc_index = 0;
94889488
newinet->mc_list = NULL;

0 commit comments

Comments
 (0)