Skip to content

Commit e58e415

Browse files
David Aherndavem330
authored andcommitted
net: Enable support for VRF with ipv4 multicast
Enable support for IPv4 multicast: - similar to unicast the flow struct is updated to L3 master device if relevant prior to calling fib_rules_lookup. The table id is saved to the lookup arg so the rule action for ipmr can return the table associated with the device. - ip_mr_forward needs to check for master device mismatch as well since the skb->dev is set to it - allow multicast address on VRF device for Rx by checking for the daddr in the VRF device as well as the original ingress device - on Tx need to drop to __mkroute_output when FIB lookup fails for multicast destination address. - if CONFIG_IP_MROUTE_MULTIPLE_TABLES is enabled VRF driver creates IPMR FIB rules on first device create similar to FIB rules. In addition the VRF driver does not divert IPv4 multicast packets: it breaks on Tx since the fib lookup fails on the mcast address. With this patch, ipmr forwarding and local rx/tx work. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1c85175 commit e58e415

File tree

3 files changed

+56
-21
lines changed

3 files changed

+56
-21
lines changed

drivers/net/vrf.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,6 @@ static netdev_tx_t vrf_process_v4_outbound(struct sk_buff *skb,
272272
if (IS_ERR(rt))
273273
goto err;
274274

275-
if (rt->rt_type != RTN_UNICAST && rt->rt_type != RTN_LOCAL) {
276-
ip_rt_put(rt);
277-
goto err;
278-
}
279-
280275
skb_dst_drop(skb);
281276

282277
/* if dst.dev is loopback or the VRF device again this is locally
@@ -611,6 +606,10 @@ static struct sk_buff *vrf_ip_out(struct net_device *vrf_dev,
611606
struct dst_entry *dst = NULL;
612607
struct rtable *rth;
613608

609+
/* don't divert multicast */
610+
if (ipv4_is_multicast(ip_hdr(skb)->daddr))
611+
return skb;
612+
614613
rcu_read_lock();
615614

616615
rth = rcu_dereference(vrf->rth);
@@ -999,6 +998,9 @@ static struct sk_buff *vrf_ip_rcv(struct net_device *vrf_dev,
999998
skb->skb_iif = vrf_dev->ifindex;
1000999
IPCB(skb)->flags |= IPSKB_L3SLAVE;
10011000

1001+
if (ipv4_is_multicast(ip_hdr(skb)->daddr))
1002+
goto out;
1003+
10021004
/* loopback traffic; do not push through packet taps again.
10031005
* Reset pkt_type for upper layers to process skb
10041006
*/
@@ -1162,8 +1164,19 @@ static int vrf_add_fib_rules(const struct net_device *dev)
11621164
if (err < 0)
11631165
goto ipv6_err;
11641166

1167+
#if IS_ENABLED(CONFIG_IP_MROUTE_MULTIPLE_TABLES)
1168+
err = vrf_fib_rule(dev, RTNL_FAMILY_IPMR, true);
1169+
if (err < 0)
1170+
goto ipmr_err;
1171+
#endif
1172+
11651173
return 0;
11661174

1175+
#if IS_ENABLED(CONFIG_IP_MROUTE_MULTIPLE_TABLES)
1176+
ipmr_err:
1177+
vrf_fib_rule(dev, AF_INET6, false);
1178+
#endif
1179+
11671180
ipv6_err:
11681181
vrf_fib_rule(dev, AF_INET, false);
11691182

net/ipv4/ipmr.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ static int ipmr_fib_lookup(struct net *net, struct flowi4 *flp4,
137137
.flags = FIB_LOOKUP_NOREF,
138138
};
139139

140+
/* update flow if oif or iif point to device enslaved to l3mdev */
141+
l3mdev_update_flow(net, flowi4_to_flowi(flp4));
142+
140143
err = fib_rules_lookup(net->ipv4.mr_rules_ops,
141144
flowi4_to_flowi(flp4), 0, &arg);
142145
if (err < 0)
@@ -163,7 +166,9 @@ static int ipmr_rule_action(struct fib_rule *rule, struct flowi *flp,
163166
return -EINVAL;
164167
}
165168

166-
mrt = ipmr_get_table(rule->fr_net, rule->table);
169+
arg->table = fib_rule_get_table(rule, arg);
170+
171+
mrt = ipmr_get_table(rule->fr_net, arg->table);
167172
if (!mrt)
168173
return -EAGAIN;
169174
res->mrt = mrt;
@@ -1809,6 +1814,12 @@ static void ip_mr_forward(struct net *net, struct mr_table *mrt,
18091814

18101815
/* Wrong interface: drop packet and (maybe) send PIM assert. */
18111816
if (mrt->vif_table[vif].dev != skb->dev) {
1817+
struct net_device *mdev;
1818+
1819+
mdev = l3mdev_master_dev_rcu(mrt->vif_table[vif].dev);
1820+
if (mdev == skb->dev)
1821+
goto forward;
1822+
18121823
if (rt_is_output_route(skb_rtable(skb))) {
18131824
/* It is our own packet, looped back.
18141825
* Very complicated situation...

net/ipv4/route.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,25 +1980,35 @@ int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,
19801980
*/
19811981
if (ipv4_is_multicast(daddr)) {
19821982
struct in_device *in_dev = __in_dev_get_rcu(dev);
1983+
int our = 0;
19831984

1984-
if (in_dev) {
1985-
int our = ip_check_mc_rcu(in_dev, daddr, saddr,
1986-
ip_hdr(skb)->protocol);
1987-
if (our
1985+
if (in_dev)
1986+
our = ip_check_mc_rcu(in_dev, daddr, saddr,
1987+
ip_hdr(skb)->protocol);
1988+
1989+
/* check l3 master if no match yet */
1990+
if ((!in_dev || !our) && netif_is_l3_slave(dev)) {
1991+
struct in_device *l3_in_dev;
1992+
1993+
l3_in_dev = __in_dev_get_rcu(skb->dev);
1994+
if (l3_in_dev)
1995+
our = ip_check_mc_rcu(l3_in_dev, daddr, saddr,
1996+
ip_hdr(skb)->protocol);
1997+
}
1998+
1999+
res = -EINVAL;
2000+
if (our
19882001
#ifdef CONFIG_IP_MROUTE
1989-
||
1990-
(!ipv4_is_local_multicast(daddr) &&
1991-
IN_DEV_MFORWARD(in_dev))
2002+
||
2003+
(!ipv4_is_local_multicast(daddr) &&
2004+
IN_DEV_MFORWARD(in_dev))
19922005
#endif
1993-
) {
1994-
int res = ip_route_input_mc(skb, daddr, saddr,
1995-
tos, dev, our);
1996-
rcu_read_unlock();
1997-
return res;
1998-
}
2006+
) {
2007+
res = ip_route_input_mc(skb, daddr, saddr,
2008+
tos, dev, our);
19992009
}
20002010
rcu_read_unlock();
2001-
return -EINVAL;
2011+
return res;
20022012
}
20032013
res = ip_route_input_slow(skb, daddr, saddr, tos, dev);
20042014
rcu_read_unlock();
@@ -2266,7 +2276,8 @@ struct rtable *__ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
22662276
res.fi = NULL;
22672277
res.table = NULL;
22682278
if (fl4->flowi4_oif &&
2269-
!netif_index_is_l3_master(net, fl4->flowi4_oif)) {
2279+
(ipv4_is_multicast(fl4->daddr) ||
2280+
!netif_index_is_l3_master(net, fl4->flowi4_oif))) {
22702281
/* Apparently, routing tables are wrong. Assume,
22712282
that the destination is on link.
22722283

0 commit comments

Comments
 (0)