Received: by 10.192.165.156 with SMTP id m28csp579396imm; Wed, 11 Apr 2018 04:09:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/GTlaBYyTk+MxD45q5XpMEUHrB/O5Vl5qMrdgc+uRKzq9uPSVDT0FHwbRMPVL3MgB/T95+ X-Received: by 2002:a17:902:6b07:: with SMTP id o7-v6mr4617821plk.136.1523444983776; Wed, 11 Apr 2018 04:09:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523444983; cv=none; d=google.com; s=arc-20160816; b=IoCqSrs56FG5Sw2ld7GFb8sUD/YlCyPY3qwOON6pCRVfSaqu7IRXqje6UjyGvAVwqe JhjjMXtBfci9oP/d9vzOxVbYhC2tm/Tcah7et7uYbpou+nhbWah1McXuiDbkb8GgZz8t ESiqkGvgjJHs9CLxJasgpsahpOj7mLg8dzhTYYdUTd0tP+kqTw/S3ggWFBImKP8cuyMl qhRuVqQqlRo66qDWnM6tSKwgRqFaT5aCzokWF3mtC7YfKGM+af4YAWrIaMRcmy/uJlO5 IJW0UaDLjnLIYB7r7Ynd4/Inrw7qReHYIlToNcwCpchd6X0gbKqBE1WgGCx4XeEhGVYU 6bMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:subject :from:to:dkim-signature:arc-authentication-results; bh=zuEyFsibXJc7YOP1A65vpobqYcepSYKKzuhg6X3jZnM=; b=BxLu1B6GaV1eMiGOfN2viwb31oGFewC6jtnyIQtghNfJYBD+9RiOwwGHN3kvuL0QwE SXcDpC4Hc+9LE2rtJeZJ/azrBa5cW/tYPzgAWbv91qotp0nstPxq7vcKeB+coZPzjR4A UsMtiWURVbJrNkk35Ij/PEfaeAogAd1N7vQ6VxdWf56IcX9UiM01JDsCU7cIqraX+2/I 8IZoLuavwc0k7hSBcEeJ5atrL0hh2ByxtsSxAieIsFSShZGUkc8lgyWNxVWRzY+Z0/+A J6gOVkTWy9+oUYtlOdnPS2A40O+c1x93bcqm19w0N8sBW8MXCzalphF7s7qSou7c+nhv T5qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HtLc+ddt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 2-v6si901882pla.436.2018.04.11.04.09.06; Wed, 11 Apr 2018 04:09:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HtLc+ddt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753043AbeDKLCy (ORCPT + 99 others); Wed, 11 Apr 2018 07:02:54 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:35816 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751729AbeDKLCw (ORCPT ); Wed, 11 Apr 2018 07:02:52 -0400 Received: by mail-wm0-f65.google.com with SMTP id r82so3051674wme.0; Wed, 11 Apr 2018 04:02:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=zuEyFsibXJc7YOP1A65vpobqYcepSYKKzuhg6X3jZnM=; b=HtLc+ddtd0MLjPkosFnpgQ64AQvXEH99YnWKfzmfHujOR1e0DqMPCfaQUqX04vFdyh vcSQhp5z0lQCPVq5BNkIWyxpXs3HXNkVASLHyDdoP2cHrQFEHIWKuFyR2EBZ+clS7cXW DsrwVDocRqULpowuIGBN0/KpT8oZmlmIWcS6CpGsclzdBRB+z3U/bwWdkoAPHCMt+aSm c3d2cAoX4AezzQIAOgv6CU062mdu0okl777ge3sIruuRL3OUrSO53uBzjoGXQecTj2g9 d4vyEynjgiCpGrH4+EA/J4GCiG5PiXn5vkrFtoH4j/Iwwyyg0O4ROb8VmiY/xAiHn4+d dqEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=zuEyFsibXJc7YOP1A65vpobqYcepSYKKzuhg6X3jZnM=; b=ZYb3sXbyqwS2TxEv4OTLE74MdDMYtqVn7DzOQF2ByF1SEi8ELzT0AHwe4g5a/YRuA0 zLJT2VrAV/wOV8iImS11u0T3GMAn9cl+7I/lYWBB7wsQ3TbKgCbYjK+I7Xp4J102dnvm LU4N43seHspxAuP8KnMgtfT1d80rjeK3AyOUz18UQc41swglz4t7NxA5IkbskhQgd6Tq Id9D/oElIxpAN6MwhvkWvNK1oErd7mFObE90xXrwRr9skw9RtffBFcRSwivfhZ0If/+2 eiBrpk5GHVQv0qkOohHWojZxiJp5m+5aHhwrjNYOQDN1930DUxdZYgSKltPn3O2V+Jx2 LbsA== X-Gm-Message-State: ALQs6tBlCYyIbxcBdq55j9TMH4DrTT3mAPLgsxtDD7U/nM2kWpdY9muo QdYi1PHLp313UNNvGfqbdlg3vN8u X-Received: by 10.28.36.3 with SMTP id k3mr2256185wmk.51.1523444570185; Wed, 11 Apr 2018 04:02:50 -0700 (PDT) Received: from ?IPv6:2003:ee:bc6:6300:edf1:3e20:c467:d2aa? (p200300EE0BC66300EDF13E20C467D2AA.dip0.t-ipconnect.de. [2003:ee:bc6:6300:edf1:3e20:c467:d2aa]) by smtp.gmail.com with ESMTPSA id q90sm1909765wrb.6.2018.04.11.04.02.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Apr 2018 04:02:49 -0700 (PDT) To: "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI , David Ahern , Greg Kroah-Hartman , Andre Naujoks , =?UTF-8?Q?Maciej_=c5=bbenczykowski?= , Shaohua Li , Paolo Abeni , Thomas Gleixner , Kate Stewart , Philippe Ombredanne , linux-kernel@vger.kernel.org, netdev@vger.kernel.org From: Andre Naujoks Subject: [RFC/PATCH] Add a socketoption IPV6_MULTICAST_ALL analogue to the IPV4 version Message-ID: Date: Wed, 11 Apr 2018 13:02:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi. I was running into a problem, when trying to join multiple multicast groups on a single socket and thus binding to the any-address on said socket. I received traffic from multicast groups, I did not join on that socket and was at first surprised by that. After reading some old e-mails/threads, which came to the conclusion "It is, as it is." (e.g https://marc.info/?l=linux-kernel&m=115815686626791&w=2), I discovered the IPv4 socketoption IP_MULTICAST_ALL, which, when disabled, does exactly what I would expect from a socket by default. I propose a socket option for IPv6, which does the same and has the same default as the IPv4 version. My first thought was, to just apply IP_MULTICAST_ALL to a ipv6 socket, but that would change the behavior of current applications and would probably be a big no-no. Regards Andre From 473653086c05a3de839c3504885053f6254c7bc5 Mon Sep 17 00:00:00 2001 From: Andre Naujoks Date: Wed, 11 Apr 2018 12:38:28 +0200 Subject: [PATCH] Add a socketoption IPV6_MULTICAST_ALL analogue to the IPV4 version 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 --- include/linux/ipv6.h | 3 ++- include/uapi/linux/in6.h | 1 + net/ipv6/af_inet6.c | 1 + net/ipv6/ipv6_sockglue.c | 11 +++++++++++ net/ipv6/mcast.c | 2 +- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h index 8415bf1a9776..495e834c1367 100644 --- a/include/linux/ipv6.h +++ b/include/linux/ipv6.h @@ -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; diff --git a/include/uapi/linux/in6.h b/include/uapi/linux/in6.h index ed291e55f024..71d82fe15b03 100644 --- a/include/uapi/linux/in6.h +++ b/include/uapi/linux/in6.h @@ -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 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index 8da0b513f188..7844cd9d2f10 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c @@ -209,6 +209,7 @@ static int inet6_create(struct net *net, struct socket *sock, int 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; diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c index 4d780c7f0130..b2bc1942a2ee 100644 --- a/net/ipv6/ipv6_sockglue.c +++ b/net/ipv6/ipv6_sockglue.c @@ -664,6 +664,13 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, 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: { @@ -1255,6 +1262,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; diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c index 793159d77d8a..623ad00eb3c2 100644 --- a/net/ipv6/mcast.c +++ b/net/ipv6/mcast.c @@ -622,7 +622,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; -- 2.17.0