Skip to content

Commit 5226b6a

Browse files
Mike Manningdavem330
authored andcommitted
ipv6: handling of multicast packets received in VRF
If the skb for multicast packets marked as enslaved to a VRF are received, then the secondary device index should be used to obtain the real device. And verify the multicast address against the enslaved rather than the l3mdev device. Signed-off-by: Dewi Morgan <[email protected]> Signed-off-by: Mike Manning <[email protected]> Reviewed-by: David Ahern <[email protected]> Tested-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d839a0e commit 5226b6a

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

net/ipv6/ip6_input.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ static int ip6_input_finish(struct net *net, struct sock *sk, struct sk_buff *sk
359359
}
360360
} else if (ipprot->flags & INET6_PROTO_FINAL) {
361361
const struct ipv6hdr *hdr;
362+
int sdif = inet6_sdif(skb);
363+
struct net_device *dev;
362364

363365
/* Only do this once for first final protocol */
364366
have_final = true;
@@ -371,9 +373,19 @@ static int ip6_input_finish(struct net *net, struct sock *sk, struct sk_buff *sk
371373
skb_postpull_rcsum(skb, skb_network_header(skb),
372374
skb_network_header_len(skb));
373375
hdr = ipv6_hdr(skb);
376+
377+
/* skb->dev passed may be master dev for vrfs. */
378+
if (sdif) {
379+
dev = dev_get_by_index_rcu(net, sdif);
380+
if (!dev)
381+
goto discard;
382+
} else {
383+
dev = skb->dev;
384+
}
385+
374386
if (ipv6_addr_is_multicast(&hdr->daddr) &&
375-
!ipv6_chk_mcast_addr(skb->dev, &hdr->daddr,
376-
&hdr->saddr) &&
387+
!ipv6_chk_mcast_addr(dev, &hdr->daddr,
388+
&hdr->saddr) &&
377389
!ipv6_is_mld(skb, nexthdr, skb_network_header_len(skb)))
378390
goto discard;
379391
}
@@ -432,15 +444,32 @@ EXPORT_SYMBOL_GPL(ip6_input);
432444

433445
int ip6_mc_input(struct sk_buff *skb)
434446
{
447+
int sdif = inet6_sdif(skb);
435448
const struct ipv6hdr *hdr;
449+
struct net_device *dev;
436450
bool deliver;
437451

438452
__IP6_UPD_PO_STATS(dev_net(skb_dst(skb)->dev),
439453
__in6_dev_get_safely(skb->dev), IPSTATS_MIB_INMCAST,
440454
skb->len);
441455

456+
/* skb->dev passed may be master dev for vrfs. */
457+
if (sdif) {
458+
rcu_read_lock();
459+
dev = dev_get_by_index_rcu(dev_net(skb->dev), sdif);
460+
if (!dev) {
461+
rcu_read_unlock();
462+
kfree_skb(skb);
463+
return -ENODEV;
464+
}
465+
} else {
466+
dev = skb->dev;
467+
}
468+
442469
hdr = ipv6_hdr(skb);
443-
deliver = ipv6_chk_mcast_addr(skb->dev, &hdr->daddr, NULL);
470+
deliver = ipv6_chk_mcast_addr(dev, &hdr->daddr, NULL);
471+
if (sdif)
472+
rcu_read_unlock();
444473

445474
#ifdef CONFIG_IPV6_MROUTE
446475
/*

0 commit comments

Comments
 (0)