net: flow: Add l3mdev flow update
authorDavid Ahern <dsa@cumulusnetworks.com>
Sat, 10 Sep 2016 19:09:52 +0000 (12:09 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sun, 11 Sep 2016 06:12:51 +0000 (23:12 -0700)
Add l3mdev hook to set FLOWI_FLAG_SKIP_NH_OIF flag and update oif/iif
in flow struct if its oif or iif points to a device enslaved to an L3
Master device. Only 1 needs to be converted to match the l3mdev FIB
rule. This moves the flow adjustment for l3mdev to a single point
catching all lookups. It is redundant for existing hooks (those are
removed in later patches) but is needed for missed lookups such as
PMTU updates.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/l3mdev.h
net/ipv4/fib_rules.c
net/ipv6/fib6_rules.c
net/l3mdev/l3mdev.c

index e90095091aa0d11a409f8936569a30f30d98e8b1..81e175e80537214e5d2ac74fec8fca1bd49ef95d 100644 (file)
@@ -49,6 +49,8 @@ struct l3mdev_ops {
 int l3mdev_fib_rule_match(struct net *net, struct flowi *fl,
                          struct fib_lookup_arg *arg);
 
+void l3mdev_update_flow(struct net *net, struct flowi *fl);
+
 int l3mdev_master_ifindex_rcu(const struct net_device *dev);
 static inline int l3mdev_master_ifindex(struct net_device *dev)
 {
@@ -290,6 +292,10 @@ int l3mdev_fib_rule_match(struct net *net, struct flowi *fl,
 {
        return 1;
 }
+static inline
+void l3mdev_update_flow(struct net *net, struct flowi *fl)
+{
+}
 #endif
 
 #endif /* _NET_L3MDEV_H_ */
index 6e9ea69e5f751bd39d0cebb26b3b0b0e73877913..770bebed6b28823d0490627711c1e1986729474f 100644 (file)
@@ -56,6 +56,9 @@ int __fib_lookup(struct net *net, struct flowi4 *flp,
        };
        int err;
 
+       /* update flow if oif or iif point to device enslaved to l3mdev */
+       l3mdev_update_flow(net, flowi4_to_flowi(flp));
+
        err = fib_rules_lookup(net->ipv4.rules_ops, flowi4_to_flowi(flp), 0, &arg);
 #ifdef CONFIG_IP_ROUTE_CLASSID
        if (arg.rule)
index 5857c1fc8b6721f2a2b5c83c4a231d561ad132b5..eea23b57c6a5a000aec234cc9bf6f9411d98001f 100644 (file)
@@ -38,6 +38,9 @@ struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
                .flags = FIB_LOOKUP_NOREF,
        };
 
+       /* update flow if oif or iif point to device enslaved to l3mdev */
+       l3mdev_update_flow(net, flowi6_to_flowi(fl6));
+
        fib_rules_lookup(net->ipv6.fib6_rules_ops,
                         flowi6_to_flowi(fl6), flags, &arg);
 
index c4a1c3e84e12670ad80c8606608a41fca1e5974e..43610e5acc4e6c848599a768d84126db89fb327c 100644 (file)
@@ -222,3 +222,38 @@ out:
 
        return rc;
 }
+
+void l3mdev_update_flow(struct net *net, struct flowi *fl)
+{
+       struct net_device *dev;
+       int ifindex;
+
+       rcu_read_lock();
+
+       if (fl->flowi_oif) {
+               dev = dev_get_by_index_rcu(net, fl->flowi_oif);
+               if (dev) {
+                       ifindex = l3mdev_master_ifindex_rcu(dev);
+                       if (ifindex) {
+                               fl->flowi_oif = ifindex;
+                               fl->flowi_flags |= FLOWI_FLAG_SKIP_NH_OIF;
+                               goto out;
+                       }
+               }
+       }
+
+       if (fl->flowi_iif) {
+               dev = dev_get_by_index_rcu(net, fl->flowi_iif);
+               if (dev) {
+                       ifindex = l3mdev_master_ifindex_rcu(dev);
+                       if (ifindex) {
+                               fl->flowi_iif = ifindex;
+                               fl->flowi_flags |= FLOWI_FLAG_SKIP_NH_OIF;
+                       }
+               }
+       }
+
+out:
+       rcu_read_unlock();
+}
+EXPORT_SYMBOL_GPL(l3mdev_update_flow);