}
for (i=0; i<conf->num_savednics; i++) {
struct saved_nic *s = &conf->saved_nics[i];
- if (lxc_netdev_move_by_index(s->ifindex, 1))
+ if (lxc_netdev_move_by_index(s->ifindex, 1, NULL))
WARN("Error moving nic index:%d back to host netns",
s->ifindex);
}
if (!netdev->ifindex)
continue;
- err = lxc_netdev_move_by_index(netdev->ifindex, pid);
+ err = lxc_netdev_move_by_index(netdev->ifindex, pid, NULL);
if (err) {
ERROR("failed to move '%s' to the container : %s",
netdev->link, strerror(-err));
if (my_iflist) {
for (tmpif = my_iflist; tmpif; tmpif = tmpif->mi_next) {
- if (lxc_netdev_move_by_name(tmpif->mi_ifname, pid) < 0)
+ if (lxc_netdev_move_by_name(tmpif->mi_ifname, pid, NULL) < 0)
fprintf(stderr,"Could not move interface %s into container %d: %s\n", tmpif->mi_ifname, pid, strerror(errno));
}
}
}
/* pass veth2 to target netns */
- ret = lxc_netdev_move_by_name(veth2buf, pid);
+ ret = lxc_netdev_move_by_name(veth2buf, pid, NULL);
if (ret < 0) {
fprintf(stderr, "Error moving %s to netns %d\n", veth2buf, pid);
goto out_del;
struct rtmsg rt;
};
-int lxc_netdev_move_by_index(int ifindex, pid_t pid)
+int lxc_netdev_move_by_index(int ifindex, pid_t pid, const char* ifname)
{
struct nl_handler nlh;
struct nlmsg *nlmsg = NULL;
if (nla_put_u32(nlmsg, IFLA_NET_NS_PID, pid))
goto out;
+ if (ifname != NULL) {
+ if (nla_put_string(nlmsg, IFLA_IFNAME, ifname))
+ goto out;
+ }
+
err = netlink_transaction(&nlh, nlmsg, nlmsg);
out:
netlink_close(&nlh);
return err;
}
-int lxc_netdev_move_by_name(const char *ifname, pid_t pid)
+int lxc_netdev_move_by_name(const char *ifname, pid_t pid, const char* newname)
{
int index;
if (!index)
return -EINVAL;
- return lxc_netdev_move_by_index(index, pid);
+ return lxc_netdev_move_by_index(index, pid, newname);
}
int lxc_netdev_delete_by_index(int ifindex)
/*
* Move a device between namespaces
*/
-extern int lxc_netdev_move_by_index(int ifindex, pid_t pid);
-extern int lxc_netdev_move_by_name(const char *ifname, pid_t pid);
+extern int lxc_netdev_move_by_index(int ifindex, pid_t pid, const char* ifname);
+extern int lxc_netdev_move_by_name(const char *ifname, pid_t pid, const char* newname);
/*
* Delete a network device