Commit 097d3c95 authored by David Ahern's avatar David Ahern Committed by David S. Miller

net: vrf: Make add_fib_rules per network namespace flag

Commit 1aa6c4f6 ("net: vrf: Add l3mdev rules on first device create")
adds the l3mdev FIB rule the first time a VRF device is created. However,
it only creates the rule once and only in the namespace the first device
is created - which may not be init_net. Fix by using the net_generic
capability to make the add_fib_rules flag per network namespace.

Fixes: 1aa6c4f6 ("net: vrf: Add l3mdev rules on first device create")
Reported-by: default avatarPetr Machata <petrm@mellanox.com>
Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 78a5a93c
...@@ -36,12 +36,14 @@ ...@@ -36,12 +36,14 @@
#include <net/addrconf.h> #include <net/addrconf.h>
#include <net/l3mdev.h> #include <net/l3mdev.h>
#include <net/fib_rules.h> #include <net/fib_rules.h>
#include <net/netns/generic.h>
#define DRV_NAME "vrf" #define DRV_NAME "vrf"
#define DRV_VERSION "1.0" #define DRV_VERSION "1.0"
#define FIB_RULE_PREF 1000 /* default preference for FIB rules */ #define FIB_RULE_PREF 1000 /* default preference for FIB rules */
static bool add_fib_rules = true;
static unsigned int vrf_net_id;
struct net_vrf { struct net_vrf {
struct rtable __rcu *rth; struct rtable __rcu *rth;
...@@ -1394,6 +1396,8 @@ static int vrf_newlink(struct net *src_net, struct net_device *dev, ...@@ -1394,6 +1396,8 @@ static int vrf_newlink(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[]) struct nlattr *tb[], struct nlattr *data[])
{ {
struct net_vrf *vrf = netdev_priv(dev); struct net_vrf *vrf = netdev_priv(dev);
bool *add_fib_rules;
struct net *net;
int err; int err;
if (!data || !data[IFLA_VRF_TABLE]) if (!data || !data[IFLA_VRF_TABLE])
...@@ -1409,13 +1413,15 @@ static int vrf_newlink(struct net *src_net, struct net_device *dev, ...@@ -1409,13 +1413,15 @@ static int vrf_newlink(struct net *src_net, struct net_device *dev,
if (err) if (err)
goto out; goto out;
if (add_fib_rules) { net = dev_net(dev);
add_fib_rules = net_generic(net, vrf_net_id);
if (*add_fib_rules) {
err = vrf_add_fib_rules(dev); err = vrf_add_fib_rules(dev);
if (err) { if (err) {
unregister_netdevice(dev); unregister_netdevice(dev);
goto out; goto out;
} }
add_fib_rules = false; *add_fib_rules = false;
} }
out: out:
...@@ -1498,16 +1504,38 @@ static struct notifier_block vrf_notifier_block __read_mostly = { ...@@ -1498,16 +1504,38 @@ static struct notifier_block vrf_notifier_block __read_mostly = {
.notifier_call = vrf_device_event, .notifier_call = vrf_device_event,
}; };
/* Initialize per network namespace state */
static int __net_init vrf_netns_init(struct net *net)
{
bool *add_fib_rules = net_generic(net, vrf_net_id);
*add_fib_rules = true;
return 0;
}
static struct pernet_operations vrf_net_ops __net_initdata = {
.init = vrf_netns_init,
.id = &vrf_net_id,
.size = sizeof(bool),
};
static int __init vrf_init_module(void) static int __init vrf_init_module(void)
{ {
int rc; int rc;
register_netdevice_notifier(&vrf_notifier_block); register_netdevice_notifier(&vrf_notifier_block);
rc = rtnl_link_register(&vrf_link_ops); rc = register_pernet_subsys(&vrf_net_ops);
if (rc < 0) if (rc < 0)
goto error; goto error;
rc = rtnl_link_register(&vrf_link_ops);
if (rc < 0) {
unregister_pernet_subsys(&vrf_net_ops);
goto error;
}
return 0; return 0;
error: error:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment