aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@aristanetworks.com>2009-11-08 03:53:51 -0500
committerDavid S. Miller <davem@davemloft.net>2009-11-08 03:53:51 -0500
commit81adee47dfb608df3ad0b91d230fb3cef75f0060 (patch)
treee9d7a41872f84c1395e21915e5f92c05ab872e69 /drivers
parentf7a3a1d8affe563846fc17f0e7c0cc1500190c57 (diff)
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')
-rw-r--r--drivers/net/can/dev.c2
-rw-r--r--drivers/net/macvlan.c4
-rw-r--r--drivers/net/veth.c15
3 files changed, 15 insertions, 6 deletions
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index c3db111d2ff5..5fe34d64ca2a 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -674,7 +674,7 @@ nla_put_failure:
674 return -EMSGSIZE; 674 return -EMSGSIZE;
675} 675}
676 676
677static int can_newlink(struct net_device *dev, 677static int can_newlink(struct net *src_net, struct net_device *dev,
678 struct nlattr *tb[], struct nlattr *data[]) 678 struct nlattr *tb[], struct nlattr *data[])
679{ 679{
680 return -EOPNOTSUPP; 680 return -EOPNOTSUPP;
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 20b7707f38ef..d7dba3f6f763 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -504,7 +504,7 @@ static int macvlan_get_tx_queues(struct net *net,
504 return 0; 504 return 0;
505} 505}
506 506
507static int macvlan_newlink(struct net_device *dev, 507static int macvlan_newlink(struct net *src_net, struct net_device *dev,
508 struct nlattr *tb[], struct nlattr *data[]) 508 struct nlattr *tb[], struct nlattr *data[])
509{ 509{
510 struct macvlan_dev *vlan = netdev_priv(dev); 510 struct macvlan_dev *vlan = netdev_priv(dev);
@@ -515,7 +515,7 @@ static int macvlan_newlink(struct net_device *dev,
515 if (!tb[IFLA_LINK]) 515 if (!tb[IFLA_LINK])
516 return -EINVAL; 516 return -EINVAL;
517 517
518 lowerdev = __dev_get_by_index(dev_net(dev), nla_get_u32(tb[IFLA_LINK])); 518 lowerdev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
519 if (lowerdev == NULL) 519 if (lowerdev == NULL)
520 return -ENODEV; 520 return -ENODEV;
521 521
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[])
340 340
341static struct rtnl_link_ops veth_link_ops; 341static struct rtnl_link_ops veth_link_ops;
342 342
343static int veth_newlink(struct net_device *dev, 343static int veth_newlink(struct net *src_net, struct net_device *dev,
344 struct nlattr *tb[], struct nlattr *data[]) 344 struct nlattr *tb[], struct nlattr *data[])
345{ 345{
346 int err; 346 int err;
@@ -348,6 +348,7 @@ static int veth_newlink(struct net_device *dev,
348 struct veth_priv *priv; 348 struct veth_priv *priv;
349 char ifname[IFNAMSIZ]; 349 char ifname[IFNAMSIZ];
350 struct nlattr *peer_tb[IFLA_MAX + 1], **tbp; 350 struct nlattr *peer_tb[IFLA_MAX + 1], **tbp;
351 struct net *net;
351 352
352 /* 353 /*
353 * create and register peer first 354 * create and register peer first
@@ -380,14 +381,22 @@ static int veth_newlink(struct net_device *dev,
380 else 381 else
381 snprintf(ifname, IFNAMSIZ, DRV_NAME "%%d"); 382 snprintf(ifname, IFNAMSIZ, DRV_NAME "%%d");
382 383
383 peer = rtnl_create_link(dev_net(dev), ifname, &veth_link_ops, tbp); 384 net = rtnl_link_get_net(src_net, tbp);
384 if (IS_ERR(peer)) 385 if (IS_ERR(net))
386 return PTR_ERR(net);
387
388 peer = rtnl_create_link(src_net, net, ifname, &veth_link_ops, tbp);
389 if (IS_ERR(peer)) {
390 put_net(net);
385 return PTR_ERR(peer); 391 return PTR_ERR(peer);
392 }
386 393
387 if (tbp[IFLA_ADDRESS] == NULL) 394 if (tbp[IFLA_ADDRESS] == NULL)
388 random_ether_addr(peer->dev_addr); 395 random_ether_addr(peer->dev_addr);
389 396
390 err = register_netdevice(peer); 397 err = register_netdevice(peer);
398 put_net(net);
399 net = NULL;
391 if (err < 0) 400 if (err < 0)
392 goto err_register_peer; 401 goto err_register_peer;
393 402