@@ -1903,6 +1903,23 @@ int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,
}
EXPORT_SYMBOL(ip_route_input_noref);
+/* if out device is enslaved to a VRF device update dst to
+ * send through it
+ */
+static void rt_use_vrf_dev(struct rtable *rth, struct net_device *dev_out)
+{
+#if IS_ENABLED(CONFIG_NET_VRF)
+ int ifindex = vrf_master_dev_ifindex(dev_out);
+ struct net_device *mdev;
+
+ mdev = dev_get_by_index(dev_net(dev_out), ifindex);
+ if (mdev) {
+ dev_put(rth->dst.dev);
+ rth->dst.dev = mdev;
+ }
+#endif
+}
+
/* called with rcu_read_lock() */
static struct rtable *__mkroute_output(const struct fib_result *res,
const struct flowi4 *fl4, int orig_oif,
@@ -2008,6 +2025,7 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
}
rt_set_nexthop(rth, fl4->daddr, res, fnhe, fi, type, 0);
+ rt_use_vrf_dev(rth, dev_out);
return rth;
}