]> git.proxmox.com Git - mirror_lxc.git/commitdiff
lxc: remove perror call in nl.c (V2)
authorMichel Normand <normand@fr.ibm.com>
Thu, 29 Apr 2010 08:03:59 +0000 (10:03 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 29 Apr 2010 08:03:59 +0000 (10:03 +0200)
There is only one such perror call, so remove it in nl.c

In this same patch, verify that all functions of nl.c and network.c
are reporting a -errno value in case of error;
value that is reported in lxc log by the callers in conf.c

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/conf.c
src/lxc/network.c
src/lxc/nl.c

index 7747afc113f859194563e9c8984352930a21723a..b27a11d14ea91ea6b1abb039316aa1f1b32c3426 100644 (file)
@@ -914,8 +914,10 @@ static int setup_hw_addr(char *hwaddr, const char *ifname)
        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;
        }
 
@@ -942,13 +944,17 @@ static int setup_ipv4_addr(struct lxc_list *ip, int ifindex)
 {
        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;
                }
        }
@@ -960,14 +966,19 @@ static int setup_ipv6_addr(struct lxc_list *ip, int ifindex)
 {
        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;
@@ -977,12 +988,15 @@ static int setup_netdev(struct lxc_netdev *netdev)
 {
        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;
@@ -1001,8 +1015,10 @@ static int setup_netdev(struct lxc_netdev *netdev)
                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;
        }
 
@@ -1040,14 +1056,20 @@ static int setup_netdev(struct lxc_netdev *netdev)
 
        /* 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;
                }
        }
@@ -1106,6 +1128,7 @@ static int instanciate_veth(struct lxc_netdev *netdev)
 {
        char veth1buf[IFNAMSIZ], *veth1;
        char veth2[IFNAMSIZ];
+       int err;
 
        if (netdev->priv.veth_attr.pair)
                veth1 = netdev->priv.veth_attr.pair;
@@ -1123,24 +1146,31 @@ static int instanciate_veth(struct lxc_netdev *netdev)
                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);
@@ -1150,8 +1180,10 @@ static int instanciate_veth(struct lxc_netdev *netdev)
        }
 
        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;
                }
        }
@@ -1169,6 +1201,7 @@ 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");
@@ -1184,10 +1217,11 @@ static int instanciate_macvlan(struct lxc_netdev *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;
        }
 
@@ -1208,6 +1242,7 @@ static int instanciate_macvlan(struct lxc_netdev *netdev)
 static int instanciate_vlan(struct lxc_netdev *netdev)
 {
        char peer[IFNAMSIZ];
+       int err;
 
        if (!netdev->link) {
                ERROR("no link specified for vlan netdev");
@@ -1216,9 +1251,10 @@ static int instanciate_vlan(struct lxc_netdev *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;
        }
 
@@ -1292,6 +1328,7 @@ int lxc_assign_network(struct lxc_list *network, pid_t pid)
 {
        struct lxc_list *iterator;
        struct lxc_netdev *netdev;
+       int err;
 
        lxc_list_for_each(iterator, network) {
 
@@ -1301,9 +1338,10 @@ int lxc_assign_network(struct lxc_list *network, pid_t pid)
                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;
                }
 
index b678ee24a8fa7735082eee44dc80ad723ec47f99..f8cb8a465c05962814c9c3a971db2568b7b94c62 100644 (file)
@@ -94,11 +94,13 @@ int lxc_device_move(int ifindex, pid_t pid)
        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;
@@ -113,10 +115,7 @@ int lxc_device_move(int ifindex, pid_t pid)
        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);
@@ -128,15 +127,18 @@ int lxc_device_delete(const char *name)
        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;
@@ -145,6 +147,7 @@ int lxc_device_delete(const char *name)
        if (!answer)
                goto out;
 
+       err = -EINVAL;
        index = if_nametoindex(name);
        if (!index)
                goto out;
@@ -159,10 +162,7 @@ int lxc_device_delete(const char *name)
        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);
@@ -175,11 +175,13 @@ 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;
+       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;
@@ -195,10 +197,7 @@ int lxc_device_delete_index(int ifindex)
        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);
@@ -211,15 +210,18 @@ static int device_set_flag(const char *name, int flag)
        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;
@@ -228,6 +230,7 @@ static int device_set_flag(const char *name, int flag)
        if (!answer)
                goto out;
 
+       err = -EINVAL;
        index = if_nametoindex(name);
        if (!index)
                goto out;
@@ -242,10 +245,6 @@ static int device_set_flag(const char *name, int flag)
        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);
@@ -258,15 +257,18 @@ int lxc_device_set_mtu(const char *name, int mtu)
        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;
@@ -275,6 +277,7 @@ int lxc_device_set_mtu(const char *name, int mtu)
        if (!answer)
                goto out;
 
+       err = -EINVAL;
        index = if_nametoindex(name);
        if (!index)
                goto out;
@@ -290,10 +293,6 @@ int lxc_device_set_mtu(const char *name, int mtu)
                goto out;
 
        err = netlink_transaction(&nlh, nlmsg, answer);
-       if (err < 0)
-               goto out;
-
-       err = 0;
 out:
        netlink_close(&nlh);
        nlmsg_free(nlmsg);
@@ -316,11 +315,13 @@ 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 = -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;
@@ -329,6 +330,7 @@ int lxc_device_rename(const char *oldname, const char *newname)
        if (len == 1 || len > IFNAMSIZ)
                goto out;
 
+       err = -ENOMEM;
        nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
        if (!nlmsg)
                goto out;
@@ -337,6 +339,7 @@ int lxc_device_rename(const char *oldname, const char *newname)
        if (!answer)
                goto out;
 
+       err = -EINVAL;
        index = if_nametoindex(oldname);
        if (!index)
                goto out;
@@ -351,10 +354,7 @@ int lxc_device_rename(const char *oldname, const char *newname)
        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);
@@ -368,11 +368,13 @@ int lxc_veth_create(const char *name1, const char *name2)
        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;
@@ -381,6 +383,7 @@ int lxc_veth_create(const char *name1, const char *name2)
        if (len == 1 || len > IFNAMSIZ)
                goto out;
 
+       err = -ENOMEM;
        nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
        if (!nlmsg)
                goto out;
@@ -396,6 +399,7 @@ int lxc_veth_create(const char *name1, const char *name2)
                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;
@@ -425,10 +429,7 @@ int lxc_veth_create(const char *name1, const char *name2)
        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);
@@ -443,11 +444,13 @@ int lxc_vlan_create(const char *master, const char *name, ushort vlanid)
        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;
@@ -456,6 +459,7 @@ int lxc_vlan_create(const char *master, const char *name, ushort vlanid)
        if (len == 1 || len > IFNAMSIZ)
                goto err3;
 
+       err = -ENOMEM;
        nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
        if (!nlmsg)
                goto err3;
@@ -464,6 +468,7 @@ int lxc_vlan_create(const char *master, const char *name, ushort vlanid)
        if (!answer)
                goto err2;
 
+       err = -EINVAL;
        lindex = if_nametoindex(master);
        if (!lindex)
                goto err1;
@@ -499,10 +504,7 @@ int lxc_vlan_create(const char *master, const char *name, ushort vlanid)
        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:
@@ -518,11 +520,13 @@ int lxc_macvlan_create(const char *master, const char *name, int mode)
        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;
@@ -531,6 +535,7 @@ int lxc_macvlan_create(const char *master, const char *name, int mode)
        if (len == 1 || len > IFNAMSIZ)
                goto out;
 
+       err = -ENOMEM;
        nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
        if (!nlmsg)
                goto out;
@@ -539,6 +544,7 @@ int lxc_macvlan_create(const char *master, const char *name, int mode)
        if (!answer)
                goto out;
 
+       err = -EINVAL;
        index = if_nametoindex(master);
        if (!index)
                goto out;
@@ -576,10 +582,7 @@ int lxc_macvlan_create(const char *master, const char *name, int mode)
        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);
@@ -607,7 +610,7 @@ static int ip_forward_set(const char *ifname, int family, int flag)
        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);
@@ -630,7 +633,7 @@ static int neigh_proxy_set(const char *ifname, int family, int flag)
        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,
@@ -669,7 +672,7 @@ int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr)
        else if (c >= 'A' && c <= 'F')
            val = c - 'A' + 10;
        else {
-           return -1;
+           return -EINVAL;
        }
        val <<= 4;
        c = *macaddr;
@@ -682,7 +685,7 @@ int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr)
        else if (c == ':' || c == 0)
            val >>= 4;
        else {
-           return -1;
+           return -EINVAL;
        }
        if (c != 0)
            macaddr++;
@@ -702,14 +705,16 @@ int lxc_ip_addr_add(int family, int ifindex, void *addr, int prefix)
        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;
@@ -728,6 +733,7 @@ int lxc_ip_addr_add(int family, int ifindex, void *addr, int prefix)
         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;
 
@@ -739,10 +745,7 @@ int lxc_ip_addr_add(int family, int ifindex, void *addr, int prefix)
 /*                                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);
@@ -757,20 +760,22 @@ static int bridge_add_del_interface(const char *bridge,
        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;
 }
index b5d3dd0f46b6bf0e68249f61d2904c7f2a11e85f..fdaf07e66597800799521db389891b0e20bdb79d 100644 (file)
@@ -195,7 +195,6 @@ extern int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg)
 extern int netlink_transaction(struct nl_handler *handler, 
                               struct nlmsg *request, struct nlmsg *answer)
 {
-
        int ret;
 
        ret = netlink_send(handler, request);
@@ -208,10 +207,7 @@ extern int netlink_transaction(struct nl_handler *handler,
 
        if (answer->nlmsghdr.nlmsg_type == NLMSG_ERROR) {
                struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(answer);
-               errno = -err->error;
-               if (errno)
-                       perror("Error configuring kernel");
-               return -errno;
+               return err->error;
        }
        
        return 0;