125
int lxc_device_delete(const char *name)
127
struct nl_handler nlh;
128
struct nlmsg *nlmsg = NULL, *answer = NULL;
129
struct link_req *link_req;
132
err = netlink_open(&nlh, NETLINK_ROUTE);
138
if (len == 1 || len > IFNAMSIZ)
142
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
146
answer = nlmsg_alloc(NLMSG_GOOD_SIZE);
151
index = if_nametoindex(name);
155
link_req = (struct link_req *)nlmsg;
156
link_req->ifinfomsg.ifi_family = AF_UNSPEC;
157
link_req->ifinfomsg.ifi_index = index;
158
nlmsg->nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
159
nlmsg->nlmsghdr.nlmsg_flags = NLM_F_ACK|NLM_F_REQUEST;
160
nlmsg->nlmsghdr.nlmsg_type = RTM_DELLINK;
162
if (nla_put_string(nlmsg, IFLA_IFNAME, name))
165
err = netlink_transaction(&nlh, nlmsg, answer);
173
int lxc_device_delete_index(int ifindex)
125
int lxc_netdev_delete_by_index(int ifindex)
175
127
struct nl_handler nlh;
176
128
struct nlmsg *nlmsg = NULL, *answer = NULL;
208
static int device_set_flag(const char *name, int flag)
160
int lxc_netdev_delete_by_name(const char *name)
164
index = if_nametoindex(name);
168
return lxc_netdev_delete_by_index(index);
171
int lxc_netdev_rename_by_index(int ifindex, const char *newname)
173
struct nl_handler nlh;
174
struct nlmsg *nlmsg = NULL, *answer = NULL;
175
struct link_req *link_req;
178
err = netlink_open(&nlh, NETLINK_ROUTE);
182
len = strlen(newname);
183
if (len == 1 || len > IFNAMSIZ)
187
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
191
answer = nlmsg_alloc(NLMSG_GOOD_SIZE);
195
link_req = (struct link_req *)nlmsg;
196
link_req->ifinfomsg.ifi_family = AF_UNSPEC;
197
link_req->ifinfomsg.ifi_index = ifindex;
198
nlmsg->nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
199
nlmsg->nlmsghdr.nlmsg_flags = NLM_F_ACK|NLM_F_REQUEST;
200
nlmsg->nlmsghdr.nlmsg_type = RTM_NEWLINK;
202
if (nla_put_string(nlmsg, IFLA_IFNAME, newname))
205
err = netlink_transaction(&nlh, nlmsg, answer);
213
int lxc_netdev_rename_by_name(const char *oldname, const char *newname)
217
len = strlen(oldname);
218
if (len == 1 || len > IFNAMSIZ)
221
index = if_nametoindex(oldname);
225
return lxc_netdev_rename_by_index(index, newname);
228
static int netdev_set_flag(const char *name, int flag)
210
230
struct nl_handler nlh;
211
231
struct nlmsg *nlmsg = NULL, *answer = NULL;
255
int lxc_device_set_mtu(const char *name, int mtu)
275
int lxc_netdev_set_mtu(const char *name, int mtu)
257
277
struct nl_handler nlh;
258
278
struct nlmsg *nlmsg = NULL, *answer = NULL;
303
int lxc_device_up(const char *name)
305
return device_set_flag(name, IFF_UP);
308
int lxc_device_down(const char *name)
310
return device_set_flag(name, 0);
313
int lxc_device_rename(const char *oldname, const char *newname)
315
struct nl_handler nlh;
316
struct nlmsg *nlmsg = NULL, *answer = NULL;
317
struct link_req *link_req;
320
err = netlink_open(&nlh, NETLINK_ROUTE);
325
len = strlen(oldname);
326
if (len == 1 || len > IFNAMSIZ)
329
len = strlen(newname);
330
if (len == 1 || len > IFNAMSIZ)
334
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
338
answer = nlmsg_alloc(NLMSG_GOOD_SIZE);
343
index = if_nametoindex(oldname);
347
link_req = (struct link_req *)nlmsg;
348
link_req->ifinfomsg.ifi_family = AF_UNSPEC;
349
link_req->ifinfomsg.ifi_index = index;
350
nlmsg->nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
351
nlmsg->nlmsghdr.nlmsg_flags = NLM_F_ACK|NLM_F_REQUEST;
352
nlmsg->nlmsghdr.nlmsg_type = RTM_NEWLINK;
354
if (nla_put_string(nlmsg, IFLA_IFNAME, newname))
357
err = netlink_transaction(&nlh, nlmsg, answer);
323
int lxc_netdev_up(const char *name)
325
return netdev_set_flag(name, IFF_UP);
328
int lxc_netdev_down(const char *name)
330
return netdev_set_flag(name, 0);
365
333
int lxc_veth_create(const char *name1, const char *name2)
777
745
* There is a lxc_bridge_attach, but no need of a bridge detach
778
* as automatically done by kernel when device deleted.
746
* as automatically done by kernel when a netdev is deleted.
780
748
int lxc_bridge_attach(const char *bridge, const char *ifname)