rename physical device to the original name

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
Daniel Lezcano 2011-03-07 02:08:47 +01:00 committed by Daniel Lezcano
parent b84f58b9fb
commit d472214b83
3 changed files with 31 additions and 35 deletions

View File

@ -1218,7 +1218,7 @@ static int setup_netdev(struct lxc_netdev *netdev)
/* empty network namespace */
if (!netdev->ifindex) {
if (netdev->flags & IFF_UP) {
err = lxc_device_up("lo");
err = lxc_netdev_up("lo");
if (err) {
ERROR("failed to set the loopback up : %s",
strerror(-err));
@ -1284,7 +1284,7 @@ static int setup_netdev(struct lxc_netdev *netdev)
if (netdev->flags & IFF_UP) {
int err;
err = lxc_device_up(current_ifname);
err = lxc_netdev_up(current_ifname);
if (err) {
ERROR("failed to set '%s' up : %s", current_ifname,
strerror(-err));
@ -1292,7 +1292,7 @@ static int setup_netdev(struct lxc_netdev *netdev)
}
/* the network is up, make the loopback up too */
err = lxc_device_up("lo");
err = lxc_netdev_up("lo");
if (err) {
ERROR("failed to set the loopback up : %s",
strerror(-err));
@ -1381,9 +1381,9 @@ static int instanciate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
}
if (netdev->mtu) {
err = lxc_device_set_mtu(veth1, atoi(netdev->mtu));
err = lxc_netdev_set_mtu(veth1, atoi(netdev->mtu));
if (!err)
err = lxc_device_set_mtu(veth2, atoi(netdev->mtu));
err = lxc_netdev_set_mtu(veth2, atoi(netdev->mtu));
if (err) {
ERROR("failed to set mtu '%s' for %s-%s : %s",
netdev->mtu, veth1, veth2, strerror(-err));
@ -1406,7 +1406,7 @@ static int instanciate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
goto out_delete;
}
err = lxc_device_up(veth1);
err = lxc_netdev_up(veth1);
if (err) {
ERROR("failed to set %s up : %s", veth1, strerror(-err));
goto out_delete;
@ -1578,8 +1578,16 @@ void lxc_delete_network(struct lxc_list *network)
lxc_list_for_each(iterator, network) {
netdev = iterator->elem;
if (netdev->ifindex > 0 && netdev->type != LXC_NET_PHYS)
lxc_netdev_delete_by_index(netdev->ifindex);
if (netdev->ifindex == 0)
continue;
/* Recent kernels already delete the virtual devices */
if (netdev->type != LXC_NET_PHYS)
continue;
if (lxc_netdev_rename_by_index(netdev->ifindex, netdev->link))
WARN("failed to rename to the initial name the netdev '%s'",
netdev->link);
}
}
@ -1597,7 +1605,7 @@ int lxc_assign_network(struct lxc_list *network, pid_t pid)
if (!netdev->ifindex)
continue;
err = lxc_device_move(netdev->ifindex, pid);
err = lxc_netdev_move_by_index(netdev->ifindex, pid);
if (err) {
ERROR("failed to move '%s' to the container : %s",
netdev->link, strerror(-err));

View File

@ -89,7 +89,7 @@ struct ip_req {
struct ifaddrmsg ifa;
};
int lxc_device_move(int ifindex, pid_t pid)
int lxc_netdev_move_by_index(int ifindex, pid_t pid)
{
struct nl_handler nlh;
struct nlmsg *nlmsg = NULL;
@ -225,7 +225,7 @@ int lxc_netdev_rename_by_name(const char *oldname, const char *newname)
return lxc_netdev_rename_by_index(index, newname);
}
static int device_set_flag(const char *name, int flag)
static int netdev_set_flag(const char *name, int flag)
{
struct nl_handler nlh;
struct nlmsg *nlmsg = NULL, *answer = NULL;
@ -272,7 +272,7 @@ out:
return err;
}
int lxc_device_set_mtu(const char *name, int mtu)
int lxc_netdev_set_mtu(const char *name, int mtu)
{
struct nl_handler nlh;
struct nlmsg *nlmsg = NULL, *answer = NULL;
@ -320,14 +320,14 @@ out:
return err;
}
int lxc_device_up(const char *name)
int lxc_netdev_up(const char *name)
{
return device_set_flag(name, IFF_UP);
return netdev_set_flag(name, IFF_UP);
}
int lxc_device_down(const char *name)
int lxc_netdev_down(const char *name)
{
return device_set_flag(name, 0);
return netdev_set_flag(name, 0);
}
int lxc_veth_create(const char *name1, const char *name2)
@ -743,7 +743,7 @@ int lxc_ipv4_addr_add(int ifindex, struct in_addr *addr,
/*
* There is a lxc_bridge_attach, but no need of a bridge detach
* as automatically done by kernel when device deleted.
* as automatically done by kernel when a netdev is deleted.
*/
int lxc_bridge_attach(const char *bridge, const char *ifname)
{

View File

@ -31,7 +31,7 @@ extern int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr);
/*
* Move a device between namespaces
*/
extern int lxc_device_move(int ifindex, pid_t pid);
extern int lxc_netdev_move_by_index(int ifindex, pid_t pid);
/*
* Delete a network device
@ -46,33 +46,21 @@ extern int lxc_netdev_rename_by_name(const char *oldname, const char *newname);
extern int lxc_netdev_rename_by_index(int ifindex, const char *newname);
/*
* Set the device network up
* Set the device network up or down
*/
extern int lxc_device_up(const char *name);
/*
* Set the device network down
*/
extern int lxc_device_down(const char *name);
extern int lxc_netdev_up(const char *name);
extern int lxc_netdev_down(const char *name);
/*
* Change the mtu size for the specified device
*/
extern int lxc_device_set_mtu(const char *name, int mtu);
extern int lxc_netdev_set_mtu(const char *name, int mtu);
/*
* Create a veth network device
* Create a virtual network devices
*/
extern int lxc_veth_create(const char *name1, const char *name2);
/*
* Create a macvlan network device
*/
extern int lxc_macvlan_create(const char *master, const char *name, int mode);
/*
* Create a vlan network device
*/
extern int lxc_vlan_create(const char *master, const char *name, ushort vid);
/*