mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-01 11:40:22 +00:00
delete network devices by index
Add a function to delete the network device by its index. Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
parent
6a3111b87e
commit
b9a5bb586c
@ -170,6 +170,42 @@ out:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lxc_device_delete_index(int ifindex)
|
||||||
|
{
|
||||||
|
struct nl_handler nlh;
|
||||||
|
struct nlmsg *nlmsg = NULL, *answer = NULL;
|
||||||
|
struct link_req *link_req;
|
||||||
|
int err = -1;
|
||||||
|
|
||||||
|
if (netlink_open(&nlh, NETLINK_ROUTE))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!nlmsg)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
answer = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!answer)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
link_req = (struct link_req *)nlmsg;
|
||||||
|
link_req->ifinfomsg.ifi_family = AF_UNSPEC;
|
||||||
|
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 (netlink_transaction(&nlh, nlmsg, answer))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
netlink_close(&nlh);
|
||||||
|
nlmsg_free(answer);
|
||||||
|
nlmsg_free(nlmsg);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
static int device_set_flag(const char *name, int flag)
|
static int device_set_flag(const char *name, int flag)
|
||||||
{
|
{
|
||||||
struct nl_handler nlh;
|
struct nl_handler nlh;
|
||||||
|
@ -38,6 +38,11 @@ extern int lxc_device_move(int ifindex, pid_t pid);
|
|||||||
*/
|
*/
|
||||||
extern int lxc_device_delete(const char *name);
|
extern int lxc_device_delete(const char *name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Delete a network device by the index
|
||||||
|
*/
|
||||||
|
extern int lxc_device_delete_index(int ifindex);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the device network up
|
* Set the device network up
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user