linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] add IPV6_MULTICAST_ALL sockopt
@ 2018-09-10  8:27 Andre Naujoks
  2018-09-10  8:27 ` [PATCH 1/1] ipv6: Add sockopt IPV6_MULTICAST_ALL analogue to IP_MULTICAST_ALL Andre Naujoks
  0 siblings, 1 reply; 5+ messages in thread
From: Andre Naujoks @ 2018-09-10  8:27 UTC (permalink / raw)
  To: netdev, linux-kernel, davem, kuznet, yoshfuji; +Cc: Andre Naujoks

The patch applies to the current net-next tree.

I tried to keep the impact of this to a minimum and to replicate the
behaviour of IP_MULTICAST_ALL.

Andre Naujoks (1):
  ipv6: Add sockopt IPV6_MULTICAST_ALL analogue to IP_MULTICAST_ALL

 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(-)

-- 
2.19.0.rc2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/1] ipv6: Add sockopt IPV6_MULTICAST_ALL analogue to IP_MULTICAST_ALL
  2018-09-10  8:27 [PATCH 0/1] add IPV6_MULTICAST_ALL sockopt Andre Naujoks
@ 2018-09-10  8:27 ` Andre Naujoks
  2018-09-10  9:07   ` Maciej Żenczykowski
  2018-09-13 15:17   ` David Miller
  0 siblings, 2 replies; 5+ messages in thread
From: Andre Naujoks @ 2018-09-10  8:27 UTC (permalink / raw)
  To: netdev, linux-kernel, davem, kuznet, yoshfuji,
	Greg Kroah-Hartman, Erik Kline, Thomas Gleixner,
	Maciej Żenczykowski, Shaohua Li, Andre Naujoks,
	Kate Stewart, Philippe Ombredanne

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>
---
 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 9a4261e50272..77ef8478234f 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 c0cac9cc3a28..381ce38940ae 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -674,6 +674,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:
 	{
@@ -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;
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index 4ae54aaca373..6895e1dc0b03 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -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;
-- 
2.19.0.rc2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] ipv6: Add sockopt IPV6_MULTICAST_ALL analogue to IP_MULTICAST_ALL
  2018-09-10  8:27 ` [PATCH 1/1] ipv6: Add sockopt IPV6_MULTICAST_ALL analogue to IP_MULTICAST_ALL Andre Naujoks
@ 2018-09-10  9:07   ` Maciej Żenczykowski
  2018-09-10  9:30     ` Andre Naujoks
  2018-09-13 15:17   ` David Miller
  1 sibling, 1 reply; 5+ messages in thread
From: Maciej Żenczykowski @ 2018-09-10  9:07 UTC (permalink / raw)
  To: Andre Naujoks
  Cc: Linux NetDev, Kernel hackers, David S. Miller, kuznet,
	Hideaki YOSHIFUJI, Greg Kroah-Hartman, Erik Kline,
	Thomas Gleixner, Shaohua Li, Kate Stewart, Philippe Ombredanne

Any reason not to use the same bit that is used by ipv4?
(as in add the setsockopt/getsockopt but just toggle the v4 bit)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] ipv6: Add sockopt IPV6_MULTICAST_ALL analogue to IP_MULTICAST_ALL
  2018-09-10  9:07   ` Maciej Żenczykowski
@ 2018-09-10  9:30     ` Andre Naujoks
  0 siblings, 0 replies; 5+ messages in thread
From: Andre Naujoks @ 2018-09-10  9:30 UTC (permalink / raw)
  To: Maciej Żenczykowski
  Cc: Linux NetDev, Kernel hackers, David S. Miller, kuznet,
	Hideaki YOSHIFUJI, Greg Kroah-Hartman, Erik Kline,
	Thomas Gleixner, Shaohua Li, Kate Stewart, Philippe Ombredanne

On 9/10/18 11:07 AM, Maciej Żenczykowski wrote:
> Any reason not to use the same bit that is used by ipv4?
> (as in add the setsockopt/getsockopt but just toggle the v4 bit)
> 

I wanted to keep the current behavior for an ipv6 socket as is. I think
user space api/behavioral changes are frowned upon!?

Currently the bit is settable for an ipv6 socket and changes the
handling for ipv4 multicasts for that socket. If I had just added the
socket option and set the v4 bit, you would get maybe unexpected
behavior from that, if you used it for ipv4 multicasts.

Another approach I tried, was to just honor the v4 bit in v6 context,
like this:

diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index 4ae54aaca373..af1659327d46 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -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 inet_sk(sk)->mc_all;
 	}
 	read_lock(&mc->sflock);
 	psl = mc->sflist;


But that has the same problem of changing current behavior in a possibly
unexpected way.

Regards
  Andre

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] ipv6: Add sockopt IPV6_MULTICAST_ALL analogue to IP_MULTICAST_ALL
  2018-09-10  8:27 ` [PATCH 1/1] ipv6: Add sockopt IPV6_MULTICAST_ALL analogue to IP_MULTICAST_ALL Andre Naujoks
  2018-09-10  9:07   ` Maciej Żenczykowski
@ 2018-09-13 15:17   ` David Miller
  1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2018-09-13 15:17 UTC (permalink / raw)
  To: nautsch2
  Cc: netdev, linux-kernel, kuznet, yoshfuji, gregkh, ek, tglx, maze,
	shli, kstewart, pombredanne

From: Andre Naujoks <nautsch2@gmail.com>
Date: Mon, 10 Sep 2018 10:27:15 +0200

> 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>

Applied to net-next, thank you.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-09-13 15:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-10  8:27 [PATCH 0/1] add IPV6_MULTICAST_ALL sockopt Andre Naujoks
2018-09-10  8:27 ` [PATCH 1/1] ipv6: Add sockopt IPV6_MULTICAST_ALL analogue to IP_MULTICAST_ALL Andre Naujoks
2018-09-10  9:07   ` Maciej Żenczykowski
2018-09-10  9:30     ` Andre Naujoks
2018-09-13 15:17   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).