netdev->link : "eth%d";
/* rename the interface name */
- err = lxc_device_rename(ifname, netdev->name);
+ err = lxc_netdev_rename_by_name(ifname, netdev->name);
if (err) {
ERROR("failed to rename %s->%s : %s", ifname, netdev->name,
strerror(-err));
return 0;
out_delete:
- lxc_device_delete(veth1);
+ lxc_netdev_delete_by_name(veth1);
return -1;
}
netdev->ifindex = if_nametoindex(peer);
if (!netdev->ifindex) {
ERROR("failed to retrieve the index for %s", peer);
- lxc_device_delete(peer);
+ lxc_netdev_delete_by_name(peer);
return -1;
}
netdev->ifindex = if_nametoindex(peer);
if (!netdev->ifindex) {
ERROR("failed to retrieve the ifindex for %s", peer);
- lxc_device_delete(peer);
+ lxc_netdev_delete_by_name(peer);
return -1;
}
lxc_list_for_each(iterator, network) {
netdev = iterator->elem;
if (netdev->ifindex > 0 && netdev->type != LXC_NET_PHYS)
- lxc_device_delete_index(netdev->ifindex);
+ lxc_netdev_delete_by_index(netdev->ifindex);
}
}
return err;
}
-int lxc_device_delete(const char *name)
+int lxc_netdev_delete_by_index(int ifindex)
{
struct nl_handler nlh;
struct nlmsg *nlmsg = NULL, *answer = NULL;
struct link_req *link_req;
- int index, len, err;
+ int err;
err = netlink_open(&nlh, NETLINK_ROUTE);
if (err)
return err;
- err = -EINVAL;
- len = strlen(name);
- if (len == 1 || len > IFNAMSIZ)
- goto out;
-
err = -ENOMEM;
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
if (!nlmsg)
if (!answer)
goto out;
- err = -EINVAL;
- index = if_nametoindex(name);
- if (!index)
- goto out;
-
link_req = (struct link_req *)nlmsg;
link_req->ifinfomsg.ifi_family = AF_UNSPEC;
- link_req->ifinfomsg.ifi_index = index;
+ link_req->ifinfomsg.ifi_index = ifindex;
nlmsg->nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
nlmsg->nlmsghdr.nlmsg_flags = NLM_F_ACK|NLM_F_REQUEST;
nlmsg->nlmsghdr.nlmsg_type = RTM_DELLINK;
- if (nla_put_string(nlmsg, IFLA_IFNAME, name))
- goto out;
-
err = netlink_transaction(&nlh, nlmsg, answer);
out:
netlink_close(&nlh);
return err;
}
-int lxc_device_delete_index(int ifindex)
+int lxc_netdev_delete_by_name(const char *name)
+{
+ int index;
+
+ index = if_nametoindex(name);
+ if (!index)
+ return -EINVAL;
+
+ return lxc_netdev_delete_by_index(index);
+}
+
+int lxc_netdev_rename_by_index(int ifindex, const char *newname)
{
struct nl_handler nlh;
struct nlmsg *nlmsg = NULL, *answer = NULL;
struct link_req *link_req;
- int err;
+ int len, err;
err = netlink_open(&nlh, NETLINK_ROUTE);
if (err)
return err;
+ len = strlen(newname);
+ if (len == 1 || len > IFNAMSIZ)
+ goto out;
+
err = -ENOMEM;
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
if (!nlmsg)
link_req->ifinfomsg.ifi_index = ifindex;
nlmsg->nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
nlmsg->nlmsghdr.nlmsg_flags = NLM_F_ACK|NLM_F_REQUEST;
- nlmsg->nlmsghdr.nlmsg_type = RTM_DELLINK;
+ nlmsg->nlmsghdr.nlmsg_type = RTM_NEWLINK;
+
+ if (nla_put_string(nlmsg, IFLA_IFNAME, newname))
+ goto out;
err = netlink_transaction(&nlh, nlmsg, answer);
out:
return err;
}
+int lxc_netdev_rename_by_name(const char *oldname, const char *newname)
+{
+ int len, index;
+
+ len = strlen(oldname);
+ if (len == 1 || len > IFNAMSIZ)
+ return -EINVAL;
+
+ index = if_nametoindex(oldname);
+ if (!index)
+ return -EINVAL;
+
+ return lxc_netdev_rename_by_index(index, newname);
+}
+
static int device_set_flag(const char *name, int flag)
{
struct nl_handler nlh;
return device_set_flag(name, 0);
}
-int lxc_device_rename(const char *oldname, const char *newname)
-{
- struct nl_handler nlh;
- struct nlmsg *nlmsg = NULL, *answer = NULL;
- struct link_req *link_req;
- int index, len, err;
-
- err = netlink_open(&nlh, NETLINK_ROUTE);
- if (err)
- return err;
-
- err = -EINVAL;
- len = strlen(oldname);
- if (len == 1 || len > IFNAMSIZ)
- goto out;
-
- len = strlen(newname);
- if (len == 1 || len > IFNAMSIZ)
- goto out;
-
- err = -ENOMEM;
- nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
- if (!nlmsg)
- goto out;
-
- answer = nlmsg_alloc(NLMSG_GOOD_SIZE);
- if (!answer)
- goto out;
-
- err = -EINVAL;
- index = if_nametoindex(oldname);
- if (!index)
- goto out;
-
- link_req = (struct link_req *)nlmsg;
- link_req->ifinfomsg.ifi_family = AF_UNSPEC;
- link_req->ifinfomsg.ifi_index = index;
- nlmsg->nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
- nlmsg->nlmsghdr.nlmsg_flags = NLM_F_ACK|NLM_F_REQUEST;
- nlmsg->nlmsghdr.nlmsg_type = RTM_NEWLINK;
-
- if (nla_put_string(nlmsg, IFLA_IFNAME, newname))
- goto out;
-
- err = netlink_transaction(&nlh, nlmsg, answer);
-out:
- netlink_close(&nlh);
- nlmsg_free(answer);
- nlmsg_free(nlmsg);
- return err;
-}
-
int lxc_veth_create(const char *name1, const char *name2)
{
struct nl_handler nlh;
/*
* Delete a network device
*/
-extern int lxc_device_delete(const char *name);
+extern int lxc_netdev_delete_by_name(const char *name);
+extern int lxc_netdev_delete_by_index(int ifindex);
/*
- * Delete a network device by the index
+ * Change the device name
*/
-extern int lxc_device_delete_index(int ifindex);
+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
*/
extern int lxc_device_down(const char *name);
-/*
- * Change the device name
- */
-extern int lxc_device_rename(const char *oldname, const char *newname);
-
/*
* Change the mtu size for the specified device
*/