net: igmp: Use correct source address on IGMPv3 reports
commit a46182b00290839fa3fa159d54fd3237bd8669f0 upstream. Closing a multicast socket after the final IPv4 address is deleted from an interface can generate a membership report that uses the source IP from a different interface. The following test script, run from an isolated netns, reproduces the issue: #!/bin/bash ip link add dummy0 type dummy ip link add dummy1 type dummy ip link set dummy0 up ip link set dummy1 up ip addr add 10.1.1.1/24 dev dummy0 ip addr add 192.168.99.99/24 dev dummy1 tcpdump -U -i dummy0 & socat EXEC:"sleep 2" \ UDP4-DATAGRAM:239.101.1.68:8889,ip-add-membership=239.0.1.68:10.1.1.1 & sleep 1 ip addr del 10.1.1.1/24 dev dummy0 sleep 5 kill %tcpdump RFC 3376 specifies that the report must be sent with a valid IP source address from the destination subnet, or from address 0.0.0.0. Add an extra check to make sure this is the case. Change-Id: I39d64ccedc8b11a4854f2ba8f5ff05fe9a2ea761 Signed-off-by: Kevin Cernekee <cernekee@chromium.org> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net> [bwh: Backported to 3.2: adjust context] Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
This commit is contained in:
parent
9b947a1549
commit
31b1159223
|
@ -88,6 +88,7 @@
|
|||
#include <linux/if_arp.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <linux/times.h>
|
||||
#include <linux/byteorder/generic.h>
|
||||
|
||||
#include <net/net_namespace.h>
|
||||
#include <net/arp.h>
|
||||
|
@ -298,6 +299,23 @@ igmp_scount(struct ip_mc_list *pmc, int type, int gdeleted, int sdeleted)
|
|||
return scount;
|
||||
}
|
||||
|
||||
/* source address selection per RFC 3376 section 4.2.13 */
|
||||
static __be32 igmpv3_get_srcaddr(struct net_device *dev,
|
||||
const struct flowi4 *fl4)
|
||||
{
|
||||
struct in_device *in_dev = __in_dev_get_rcu(dev);
|
||||
|
||||
if (!in_dev)
|
||||
return htonl(INADDR_ANY);
|
||||
|
||||
for_ifa(in_dev) {
|
||||
if (inet_ifa_match(fl4->saddr, ifa))
|
||||
return fl4->saddr;
|
||||
} endfor_ifa(in_dev);
|
||||
|
||||
return htonl(INADDR_ANY);
|
||||
}
|
||||
|
||||
#define igmp_skb_size(skb) (*(unsigned int *)((skb)->cb))
|
||||
|
||||
static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size)
|
||||
|
@ -345,7 +363,7 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size)
|
|||
pip->frag_off = htons(IP_DF);
|
||||
pip->ttl = 1;
|
||||
pip->daddr = fl4.daddr;
|
||||
pip->saddr = fl4.saddr;
|
||||
pip->saddr = igmpv3_get_srcaddr(dev, &fl4);
|
||||
pip->protocol = IPPROTO_IGMP;
|
||||
pip->tot_len = 0; /* filled in later */
|
||||
ip_select_ident(skb, NULL);
|
||||
|
|
Loading…
Reference in New Issue