Skip to content

Commit a46182b

Browse files
Kevin Cernekeedavem330
Kevin Cernekee
authored andcommitted
net: igmp: Use correct source address on IGMPv3 reports
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. Signed-off-by: Kevin Cernekee <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c545a94 commit a46182b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

net/ipv4/igmp.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
#include <linux/rtnetlink.h>
9090
#include <linux/times.h>
9191
#include <linux/pkt_sched.h>
92+
#include <linux/byteorder/generic.h>
9293

9394
#include <net/net_namespace.h>
9495
#include <net/arp.h>
@@ -321,6 +322,23 @@ igmp_scount(struct ip_mc_list *pmc, int type, int gdeleted, int sdeleted)
321322
return scount;
322323
}
323324

325+
/* source address selection per RFC 3376 section 4.2.13 */
326+
static __be32 igmpv3_get_srcaddr(struct net_device *dev,
327+
const struct flowi4 *fl4)
328+
{
329+
struct in_device *in_dev = __in_dev_get_rcu(dev);
330+
331+
if (!in_dev)
332+
return htonl(INADDR_ANY);
333+
334+
for_ifa(in_dev) {
335+
if (inet_ifa_match(fl4->saddr, ifa))
336+
return fl4->saddr;
337+
} endfor_ifa(in_dev);
338+
339+
return htonl(INADDR_ANY);
340+
}
341+
324342
static struct sk_buff *igmpv3_newpack(struct net_device *dev, unsigned int mtu)
325343
{
326344
struct sk_buff *skb;
@@ -368,7 +386,7 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, unsigned int mtu)
368386
pip->frag_off = htons(IP_DF);
369387
pip->ttl = 1;
370388
pip->daddr = fl4.daddr;
371-
pip->saddr = fl4.saddr;
389+
pip->saddr = igmpv3_get_srcaddr(dev, &fl4);
372390
pip->protocol = IPPROTO_IGMP;
373391
pip->tot_len = 0; /* filled in later */
374392
ip_select_ident(net, skb, NULL);

0 commit comments

Comments
 (0)