ipv6: Add sockopt IPV6_MULTICAST_ALL analogue to IP_MULTICAST_ALL
authorAndre Naujoks <nautsch2@gmail.com>
Mon, 10 Sep 2018 08:27:15 +0000 (10:27 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 13 Sep 2018 15:17:27 +0000 (08:17 -0700)
The socket option will be enabled by default to ensure current behaviour
is not changed. This is the same for the IPv4 version.

A socket bound to in6addr_any and a specific port will receive all traffic
on that port. Analogue to IP_MULTICAST_ALL, disable this behaviour, if
one or more multicast groups were joined (using said socket) and only
pass on multicast traffic from groups, which were explicitly joined via
this socket.

Without this option disabled a socket (system even) joined to multiple
multicast groups is very hard to get right. Filtering by destination
address has to take place in user space to avoid receiving multicast
traffic from other multicast groups, which might have traffic on the same
port.

The extension of the IP_MULTICAST_ALL socketoption to just apply to ipv6,
too, is not done to avoid changing the behaviour of current applications.

Signed-off-by: Andre Naujoks <nautsch2@gmail.com>
Acked-By: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/ipv6.h
include/uapi/linux/in6.h
net/ipv6/af_inet6.c
net/ipv6/ipv6_sockglue.c
net/ipv6/mcast.c

index 8415bf1a9776245b810c8f92fa16c98eb038a45f..495e834c1367ddc9e680f56d0cc66f4055fd1f6e 100644 (file)
@@ -274,7 +274,8 @@ struct ipv6_pinfo {
                                                 */
                                dontfrag:1,
                                autoflowlabel:1,
-                               autoflowlabel_set:1;
+                               autoflowlabel_set:1,
+                               mc_all:1;
        __u8                    min_hopcount;
        __u8                    tclass;
        __be32                  rcv_flowinfo;
index ed291e55f024f14e8ae257d913d1cf13705ffc2d..71d82fe15b034db9ffc2127c1474cc8d0ef9c9d7 100644 (file)
@@ -177,6 +177,7 @@ struct in6_flowlabel_req {
 #define IPV6_V6ONLY            26
 #define IPV6_JOIN_ANYCAST      27
 #define IPV6_LEAVE_ANYCAST     28
+#define IPV6_MULTICAST_ALL     29
 
 /* IPV6_MTU_DISCOVER values */
 #define IPV6_PMTUDISC_DONT             0
index 9a4261e502727005b3ea5e26795afd747533ee9e..77ef8478234f668b5c42a16c74062e9e98392dfb 100644 (file)
@@ -209,6 +209,7 @@ lookup_protocol:
        np->hop_limit   = -1;
        np->mcast_hops  = IPV6_DEFAULT_MCASTHOPS;
        np->mc_loop     = 1;
+       np->mc_all      = 1;
        np->pmtudisc    = IPV6_PMTUDISC_WANT;
        np->repflow     = net->ipv6.sysctl.flowlabel_reflect;
        sk->sk_ipv6only = net->ipv6.sysctl.bindv6only;
index c0cac9cc3a28190beee2f0313477048f84a0bf16..381ce38940aee2deb7e9725ff7f2aa35bc3ba12b 100644 (file)
@@ -674,6 +674,13 @@ done:
                        retv = ipv6_sock_ac_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr);
                break;
        }
+       case IPV6_MULTICAST_ALL:
+               if (optlen < sizeof(int))
+                       goto e_inval;
+               np->mc_all = valbool;
+               retv = 0;
+               break;
+
        case MCAST_JOIN_GROUP:
        case MCAST_LEAVE_GROUP:
        {
@@ -1266,6 +1273,10 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
                val = np->mcast_oif;
                break;
 
+       case IPV6_MULTICAST_ALL:
+               val = np->mc_all;
+               break;
+
        case IPV6_UNICAST_IF:
                val = (__force int)htonl((__u32) np->ucast_oif);
                break;
index 4ae54aaca3736d168cceb0cefd254727486f8048..6895e1dc0b03b358a0bd77140b7a7b555893e5a8 100644 (file)
@@ -636,7 +636,7 @@ bool inet6_mc_check(struct sock *sk, const struct in6_addr *mc_addr,
        }
        if (!mc) {
                rcu_read_unlock();
-               return true;
+               return np->mc_all;
        }
        read_lock(&mc->sflock);
        psl = mc->sflist;