struct ifreq ifr;
int ret, fd;
- if (lxc_convert_mac(hwaddr, &sockaddr)) {
- ERROR("conversion has failed");
+ ret = lxc_convert_mac(hwaddr, &sockaddr);
+ if (ret) {
+ ERROR("mac address '%s' conversion failed : %s",
+ hwaddr, strerror(-ret));
return -1;
}
{
struct lxc_list *iterator;
struct lxc_inetdev *inetdev;
+ int err;
lxc_list_for_each(iterator, ip) {
inetdev = iterator->elem;
- if (lxc_ip_addr_add(AF_INET, ifindex,
- &inetdev->addr, inetdev->prefix)) {
+ err = lxc_ip_addr_add(AF_INET, ifindex,
+ &inetdev->addr, inetdev->prefix);
+ if (err) {
+ ERROR("failed to setup_ipv4_addr ifindex %d : %s",
+ ifindex, strerror(-err));
return -1;
}
}
{
struct lxc_list *iterator;
struct lxc_inet6dev *inet6dev;
+ int err;
lxc_list_for_each(iterator, ip) {
inet6dev = iterator->elem;
- if (lxc_ip_addr_add(AF_INET6, ifindex,
- & inet6dev->addr, inet6dev->prefix))
+ err = lxc_ip_addr_add(AF_INET6, ifindex,
+ &inet6dev->addr, inet6dev->prefix);
+ if (err) {
+ ERROR("failed to setup_ipv6_addr ifindex %d : %s",
+ ifindex, strerror(-err));
return -1;
+ }
}
return 0;
{
char ifname[IFNAMSIZ];
char *current_ifname = ifname;
+ int err;
/* empty network namespace */
if (!netdev->ifindex) {
if (netdev->flags | IFF_UP) {
- if (lxc_device_up("lo")) {
- ERROR("failed to set the loopback up");
+ err = lxc_device_up("lo");
+ if (err) {
+ ERROR("failed to set the loopback up : %s",
+ strerror(-err));
return -1;
}
return 0;
netdev->name = "eth%d";
/* rename the interface name */
- if (lxc_device_rename(ifname, netdev->name)) {
- ERROR("failed to rename %s->%s", ifname, netdev->name);
+ err = lxc_device_rename(ifname, netdev->name);
+ if (err) {
+ ERROR("failed to rename %s->%s : %s", ifname, netdev->name,
+ strerror(-err));
return -1;
}
/* set the network device up */
if (netdev->flags | IFF_UP) {
- if (lxc_device_up(current_ifname)) {
- ERROR("failed to set '%s' up", current_ifname);
+ int err;
+
+ err = lxc_device_up(current_ifname);
+ if (err) {
+ ERROR("failed to set '%s' up : %s", current_ifname,
+ strerror(-err));
return -1;
}
/* the network is up, make the loopback up too */
- if (lxc_device_up("lo")) {
- ERROR("failed to set the loopback up");
+ err = lxc_device_up("lo");
+ if (err) {
+ ERROR("failed to set the loopback up : %s",
+ strerror(-err));
return -1;
}
}
{
char veth1buf[IFNAMSIZ], *veth1;
char veth2[IFNAMSIZ];
+ int err;
if (netdev->priv.veth_attr.pair)
veth1 = netdev->priv.veth_attr.pair;
return -1;
}
- if (lxc_veth_create(veth1, veth2)) {
- ERROR("failed to create %s-%s", veth1, veth2);
+ err = lxc_veth_create(veth1, veth2);
+ if (err) {
+ ERROR("failed to create %s-%s : %s", veth1, veth2,
+ strerror(-err));
return -1;
}
if (netdev->mtu) {
- if (lxc_device_set_mtu(veth1, atoi(netdev->mtu)) ||
- lxc_device_set_mtu(veth2, atoi(netdev->mtu))) {
- ERROR("failed to set mtu '%s' for %s-%s",
- netdev->mtu, veth1, veth2);
+ err = lxc_device_set_mtu(veth1, atoi(netdev->mtu));
+ if (!err)
+ err = lxc_device_set_mtu(veth2, atoi(netdev->mtu));
+ if (err) {
+ ERROR("failed to set mtu '%s' for %s-%s : %s",
+ netdev->mtu, veth1, veth2, strerror(-err));
goto out_delete;
}
}
- if (netdev->link && lxc_bridge_attach(netdev->link, veth1)) {
- ERROR("failed to attach '%s' to the bridge '%s'",
- veth1, netdev->link);
- goto out_delete;
+ if (netdev->link) {
+ err = lxc_bridge_attach(netdev->link, veth1);
+ if (err) {
+ ERROR("failed to attach '%s' to the bridge '%s' : %s",
+ veth1, netdev->link, strerror(-err));
+ goto out_delete;
+ }
}
netdev->ifindex = if_nametoindex(veth2);
}
if (netdev->flags & IFF_UP) {
- if (lxc_device_up(veth1)) {
- ERROR("failed to set %s up", veth1);
+ err = lxc_device_up(veth1);
+ if (err) {
+ ERROR("failed to set %s up : %s", veth1,
+ strerror(-err));
goto out_delete;
}
}
static int instanciate_macvlan(struct lxc_netdev *netdev)
{
char peer[IFNAMSIZ];
+ int err;
if (!netdev->link) {
ERROR("no link specified for macvlan netdev");
return -1;
}
- if (lxc_macvlan_create(netdev->link, peer,
- netdev->priv.macvlan_attr.mode)) {
- ERROR("failed to create macvlan interface '%s' on '%s'",
- peer, netdev->link);
+ err = lxc_macvlan_create(netdev->link, peer,
+ netdev->priv.macvlan_attr.mode);
+ if (err) {
+ ERROR("failed to create macvlan interface '%s' on '%s' : %s",
+ peer, netdev->link, strerror(-err));
return -1;
}
static int instanciate_vlan(struct lxc_netdev *netdev)
{
char peer[IFNAMSIZ];
+ int err;
if (!netdev->link) {
ERROR("no link specified for vlan netdev");
snprintf(peer, sizeof(peer), "vlan%d", netdev->priv.vlan_attr.vid);
- if (lxc_vlan_create(netdev->link, peer, netdev->priv.vlan_attr.vid)) {
- ERROR("failed to create vlan interface '%s' on '%s'",
- peer, netdev->link);
+ err = lxc_vlan_create(netdev->link, peer, netdev->priv.vlan_attr.vid);
+ if (err) {
+ ERROR("failed to create vlan interface '%s' on '%s' : %s",
+ peer, netdev->link, strerror(-err));
return -1;
}
{
struct lxc_list *iterator;
struct lxc_netdev *netdev;
+ int err;
lxc_list_for_each(iterator, network) {
if (!netdev->ifindex)
continue;
- if (lxc_device_move(netdev->ifindex, pid)) {
- ERROR("failed to move '%s' to the container",
- netdev->link);
+ err = lxc_device_move(netdev->ifindex, pid);
+ if (err) {
+ ERROR("failed to move '%s' to the container : %s",
+ netdev->link, strerror(-err));
return -1;
}
struct nl_handler nlh;
struct nlmsg *nlmsg = NULL;
struct link_req *link_req;
- int err = -1;
+ int err;
- if (netlink_open(&nlh, NETLINK_ROUTE))
- return -1;
+ err = netlink_open(&nlh, NETLINK_ROUTE);
+ if (err)
+ return err;
+ err = -ENOMEM;
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
if (!nlmsg)
goto out;
if (nla_put_u32(nlmsg, IFLA_NET_NS_PID, pid))
goto out;
- if (netlink_transaction(&nlh, nlmsg, nlmsg))
- goto out;
-
- err = 0;
+ err = netlink_transaction(&nlh, nlmsg, nlmsg);
out:
netlink_close(&nlh);
nlmsg_free(nlmsg);
struct nl_handler nlh;
struct nlmsg *nlmsg = NULL, *answer = NULL;
struct link_req *link_req;
- int index, len, err = -1;
+ int index, len, err;
- if (netlink_open(&nlh, NETLINK_ROUTE))
- return -1;
+ 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)
goto out;
if (!answer)
goto out;
+ err = -EINVAL;
index = if_nametoindex(name);
if (!index)
goto out;
if (nla_put_string(nlmsg, IFLA_IFNAME, name))
goto out;
- if (netlink_transaction(&nlh, nlmsg, answer))
- goto out;
-
- err = 0;
+ err = netlink_transaction(&nlh, nlmsg, answer);
out:
netlink_close(&nlh);
nlmsg_free(answer);
struct nl_handler nlh;
struct nlmsg *nlmsg = NULL, *answer = NULL;
struct link_req *link_req;
- int err = -1;
+ int err;
- if (netlink_open(&nlh, NETLINK_ROUTE))
- return -1;
+ err = netlink_open(&nlh, NETLINK_ROUTE);
+ if (err)
+ return err;
+ err = -ENOMEM;
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
if (!nlmsg)
goto out;
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;
+ err = netlink_transaction(&nlh, nlmsg, answer);
out:
netlink_close(&nlh);
nlmsg_free(answer);
struct nl_handler nlh;
struct nlmsg *nlmsg = NULL, *answer = NULL;
struct link_req *link_req;
- int index, len, err = -1;
+ int index, len, err;
- if (netlink_open(&nlh, NETLINK_ROUTE))
- return -1;
+ 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)
goto out;
if (!answer)
goto out;
+ err = -EINVAL;
index = if_nametoindex(name);
if (!index)
goto out;
nlmsg->nlmsghdr.nlmsg_type = RTM_NEWLINK;
err = netlink_transaction(&nlh, nlmsg, answer);
- if (err < 0)
- goto out;
-
- err = 0;
out:
netlink_close(&nlh);
nlmsg_free(nlmsg);
struct nl_handler nlh;
struct nlmsg *nlmsg = NULL, *answer = NULL;
struct link_req *link_req;
- int index, len, err = -1;
+ int index, len, err;
- if (netlink_open(&nlh, NETLINK_ROUTE))
- return -1;
+ 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)
goto out;
if (!answer)
goto out;
+ err = -EINVAL;
index = if_nametoindex(name);
if (!index)
goto out;
goto out;
err = netlink_transaction(&nlh, nlmsg, answer);
- if (err < 0)
- goto out;
-
- err = 0;
out:
netlink_close(&nlh);
nlmsg_free(nlmsg);
struct nl_handler nlh;
struct nlmsg *nlmsg = NULL, *answer = NULL;
struct link_req *link_req;
- int index, len, err = -1;
+ int index, len, err;
- if (netlink_open(&nlh, NETLINK_ROUTE))
- return -1;
+ err = netlink_open(&nlh, NETLINK_ROUTE);
+ if (err)
+ return err;
+ err = -EINVAL;
len = strlen(oldname);
if (len == 1 || len > IFNAMSIZ)
goto out;
if (len == 1 || len > IFNAMSIZ)
goto out;
+ err = -ENOMEM;
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
if (!nlmsg)
goto out;
if (!answer)
goto out;
+ err = -EINVAL;
index = if_nametoindex(oldname);
if (!index)
goto out;
if (nla_put_string(nlmsg, IFLA_IFNAME, newname))
goto out;
- if (netlink_transaction(&nlh, nlmsg, answer))
- goto out;
-
- err = 0;
+ err = netlink_transaction(&nlh, nlmsg, answer);
out:
netlink_close(&nlh);
nlmsg_free(answer);
struct nlmsg *nlmsg = NULL, *answer = NULL;
struct link_req *link_req;
struct rtattr *nest1, *nest2, *nest3;
- int len, err = -1;
+ int len, err;
- if (netlink_open(&nlh, NETLINK_ROUTE))
- return -1;
+ err = netlink_open(&nlh, NETLINK_ROUTE);
+ if (err)
+ return err;
+ err = -EINVAL;
len = strlen(name1);
if (len == 1 || len > IFNAMSIZ)
goto out;
if (len == 1 || len > IFNAMSIZ)
goto out;
+ err = -ENOMEM;
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
if (!nlmsg)
goto out;
NLM_F_REQUEST|NLM_F_CREATE|NLM_F_EXCL|NLM_F_ACK;
nlmsg->nlmsghdr.nlmsg_type = RTM_NEWLINK;
+ err = -EINVAL;
nest1 = nla_begin_nested(nlmsg, IFLA_LINKINFO);
if (!nest1)
goto out;
if (nla_put_string(nlmsg, IFLA_IFNAME, name1))
goto out;
- if (netlink_transaction(&nlh, nlmsg, answer))
- goto out;
-
- err = 0;
+ err = netlink_transaction(&nlh, nlmsg, answer);
out:
netlink_close(&nlh);
nlmsg_free(answer);
struct nlmsg *nlmsg = NULL, *answer = NULL;
struct link_req *link_req;
struct rtattr *nest, *nest2;
- int lindex, len, err = -1;
+ int lindex, len, err;
- if (netlink_open(&nlh, NETLINK_ROUTE))
- return -1;
+ err = netlink_open(&nlh, NETLINK_ROUTE);
+ if (err)
+ return err;
+ err = -EINVAL;
len = strlen(master);
if (len == 1 || len > IFNAMSIZ)
goto err3;
if (len == 1 || len > IFNAMSIZ)
goto err3;
+ err = -ENOMEM;
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
if (!nlmsg)
goto err3;
if (!answer)
goto err2;
+ err = -EINVAL;
lindex = if_nametoindex(master);
if (!lindex)
goto err1;
if (nla_put_string(nlmsg, IFLA_IFNAME, name))
goto err1;
- if (netlink_transaction(&nlh, nlmsg, answer))
- goto err1;
-
- err = 0;
+ err = netlink_transaction(&nlh, nlmsg, answer);
err1:
nlmsg_free(answer);
err2:
struct nlmsg *nlmsg = NULL, *answer = NULL;
struct link_req *link_req;
struct rtattr *nest, *nest2;
- int index, len, err = -1;
+ int index, len, err;
- if (netlink_open(&nlh, NETLINK_ROUTE))
- return -1;
+ err = netlink_open(&nlh, NETLINK_ROUTE);
+ if (err)
+ return err;
+ err = -EINVAL;
len = strlen(master);
if (len == 1 || len > IFNAMSIZ)
goto out;
if (len == 1 || len > IFNAMSIZ)
goto out;
+ err = -ENOMEM;
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
if (!nlmsg)
goto out;
if (!answer)
goto out;
+ err = -EINVAL;
index = if_nametoindex(master);
if (!index)
goto out;
if (nla_put_string(nlmsg, IFLA_IFNAME, name))
goto out;
- if (netlink_transaction(&nlh, nlmsg, answer))
- goto out;
-
- err = 0;
+ err = netlink_transaction(&nlh, nlmsg, answer);
out:
netlink_close(&nlh);
nlmsg_free(answer);
char path[MAXPATHLEN];
if (family != AF_INET && family != AF_INET6)
- return -1;
+ return -EINVAL;
snprintf(path, MAXPATHLEN, "/proc/sys/net/%s/conf/%s/forwarding",
family == AF_INET?"ipv4":"ipv6" , ifname);
char path[MAXPATHLEN];
if (family != AF_INET && family != AF_INET6)
- return -1;
+ return -EINVAL;
sprintf(path, "/proc/sys/net/%s/conf/%s/%s",
family == AF_INET?"ipv4":"ipv6" , ifname,
else if (c >= 'A' && c <= 'F')
val = c - 'A' + 10;
else {
- return -1;
+ return -EINVAL;
}
val <<= 4;
c = *macaddr;
else if (c == ':' || c == 0)
val >>= 4;
else {
- return -1;
+ return -EINVAL;
}
if (c != 0)
macaddr++;
struct nlmsg *nlmsg = NULL, *answer = NULL;
struct ip_req *ip_req;
int addrlen;
- int err = -1;
+ int err;
addrlen = family == AF_INET ? sizeof(struct in_addr) :
sizeof(struct in6_addr);
- if (netlink_open(&nlh, NETLINK_ROUTE))
- return -1;
+ err = netlink_open(&nlh, NETLINK_ROUTE);
+ if (err)
+ return err;
+ err = -ENOMEM;
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
if (!nlmsg)
goto out;
ip_req->ifa.ifa_family = family;
ip_req->ifa.ifa_scope = 0;
+ err = -EINVAL;
if (nla_put_buffer(nlmsg, IFA_LOCAL, addr, addrlen))
goto out;
/* sizeof(in_bcast))) */
/* goto out; */
- if (netlink_transaction(&nlh, nlmsg, answer))
- goto out;
-
- err = 0;
+ err = netlink_transaction(&nlh, nlmsg, answer);
out:
netlink_close(&nlh);
nlmsg_free(answer);
struct ifreq ifr;
if (strlen(ifname) > IFNAMSIZ)
- return -1;
+ return -EINVAL;
index = if_nametoindex(ifname);
if (!index)
- return -1;
+ return -EINVAL;
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0)
- return -1;
+ return -errno;
strncpy(ifr.ifr_name, bridge, IFNAMSIZ);
ifr.ifr_ifindex = index;
err = ioctl(fd, detach?SIOCBRDELIF:SIOCBRADDIF, &ifr);
close(fd);
+ if (err)
+ err = -errno;
return err;
}