summaryrefslogtreecommitdiff
path: root/drivers/net/veth.c
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@aristanetworks.com>2009-11-08 11:53:51 +0300
committerDavid S. Miller <davem@davemloft.net>2009-11-08 11:53:51 +0300
commit81adee47dfb608df3ad0b91d230fb3cef75f0060 (patch)
treee9d7a41872f84c1395e21915e5f92c05ab872e69 /drivers/net/veth.c
parentf7a3a1d8affe563846fc17f0e7c0cc1500190c57 (diff)
downloadlinux-81adee47dfb608df3ad0b91d230fb3cef75f0060.tar.xz
net: Support specifying the network namespace upon device creation.
There is no good reason to not support userspace specifying the network namespace during device creation, and it makes it easier to create a network device and pass it to a child network namespace with a well known name. We have to be careful to ensure that the target network namespace for the new device exists through the life of the call. To keep that logic clear I have factored out the network namespace grabbing logic into rtnl_link_get_net. In addtion we need to continue to pass the source network namespace to the rtnl_link_ops.newlink method so that we can find the base device source network namespace. Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com> Acked-by: Eric Dumazet <eric.dumazet@gmail.com>
Diffstat (limited to 'drivers/net/veth.c')
-rw-r--r--drivers/net/veth.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 9bed694cd215..2d657f2314cb 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -340,7 +340,7 @@ static int veth_validate(struct nlattr *tb[], struct nlattr *data[])
static struct rtnl_link_ops veth_link_ops;
-static int veth_newlink(struct net_device *dev,
+static int veth_newlink(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[])
{
int err;
@@ -348,6 +348,7 @@ static int veth_newlink(struct net_device *dev,
struct veth_priv *priv;
char ifname[IFNAMSIZ];
struct nlattr *peer_tb[IFLA_MAX + 1], **tbp;
+ struct net *net;
/*
* create and register peer first
@@ -380,14 +381,22 @@ static int veth_newlink(struct net_device *dev,
else
snprintf(ifname, IFNAMSIZ, DRV_NAME "%%d");
- peer = rtnl_create_link(dev_net(dev), ifname, &veth_link_ops, tbp);
- if (IS_ERR(peer))
+ net = rtnl_link_get_net(src_net, tbp);
+ if (IS_ERR(net))
+ return PTR_ERR(net);
+
+ peer = rtnl_create_link(src_net, net, ifname, &veth_link_ops, tbp);
+ if (IS_ERR(peer)) {
+ put_net(net);
return PTR_ERR(peer);
+ }
if (tbp[IFLA_ADDRESS] == NULL)
random_ether_addr(peer->dev_addr);
err = register_netdevice(peer);
+ put_net(net);
+ net = NULL;
if (err < 0)
goto err_register_peer;