net: Add support for l3mdev ops to VRF driver
authorDavid Ahern <dsa@cumulusnetworks.com>
Wed, 30 Sep 2015 03:07:12 +0000 (20:07 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 30 Sep 2015 03:40:33 +0000 (20:40 -0700)
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/Kconfig
drivers/net/vrf.c

index d18eb607bee66ab1f586059a44de4fefd94352da..b9ebd0d18a522db0da8603f5cb401c40d5645386 100644 (file)
@@ -299,6 +299,7 @@ config NLMON
 config NET_VRF
        tristate "Virtual Routing and Forwarding (Lite)"
        depends on IP_MULTIPLE_TABLES && IPV6_MULTIPLE_TABLES
+       depends on NET_L3_MASTER_DEV
        ---help---
          This option enables the support for mapping interfaces into VRF's. The
          support enables VRF devices.
index 2d7418e0b908becdfce54bab2addbc7ce3dc1586..72f1892ebad0380f76ba84fbcaeba673860e3c78 100644 (file)
@@ -35,6 +35,7 @@
 #include <net/route.h>
 #include <net/addrconf.h>
 #include <net/vrf.h>
+#include <net/l3mdev.h>
 
 #define DRV_NAME       "vrf"
 #define DRV_VERSION    "1.0"
@@ -529,6 +530,33 @@ static const struct net_device_ops vrf_netdev_ops = {
        .ndo_del_slave          = vrf_del_slave,
 };
 
+static u32 vrf_fib_table(const struct net_device *dev)
+{
+       struct net_vrf *vrf = netdev_priv(dev);
+
+       return vrf->tb_id;
+}
+
+static struct rtable *vrf_get_rtable(const struct net_device *dev,
+                                    const struct flowi4 *fl4)
+{
+       struct rtable *rth = NULL;
+
+       if (!(fl4->flowi4_flags & FLOWI_FLAG_VRFSRC)) {
+               struct net_vrf *vrf = netdev_priv(dev);
+
+               rth = vrf->rth;
+               atomic_inc(&rth->dst.__refcnt);
+       }
+
+       return rth;
+}
+
+static const struct l3mdev_ops vrf_l3mdev_ops = {
+       .l3mdev_fib_table       = vrf_fib_table,
+       .l3mdev_get_rtable      = vrf_get_rtable,
+};
+
 static void vrf_get_drvinfo(struct net_device *dev,
                            struct ethtool_drvinfo *info)
 {
@@ -546,6 +574,7 @@ static void vrf_setup(struct net_device *dev)
 
        /* Initialize the device structure. */
        dev->netdev_ops = &vrf_netdev_ops;
+       dev->l3mdev_ops = &vrf_l3mdev_ops;
        dev->ethtool_ops = &vrf_ethtool_ops;
        dev->destructor = free_netdev;