summaryrefslogtreecommitdiff
path: root/src/inet.c
diff options
context:
space:
mode:
authorForest Bond <forest.bond@rapidrollout.com>2013-01-07 14:24:55 (GMT)
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-01-08 13:02:05 (GMT)
commita479b35af65063550c553327689fe5604a7e3e10 (patch)
treeb48c3f34d8a6009110803be0e3e3aba4f033ba64 /src/inet.c
parente03a01d3182d555d3d2c27494256821c9eb4ed81 (diff)
downloadconnman-a479b35af65063550c553327689fe5604a7e3e10.zip
connman-a479b35af65063550c553327689fe5604a7e3e10.tar.gz
connman-a479b35af65063550c553327689fe5604a7e3e10.tar.bz2
inet: Fix error handling when bridging interfaces
Functions that add and remove interfaces to and from bridges now return an appropriate error code.
Diffstat (limited to 'src/inet.c')
-rw-r--r--src/inet.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/inet.c b/src/inet.c
index c360f56..0027fe6 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -1183,59 +1183,63 @@ connman_bool_t connman_inet_compare_subnet(int index, const char *host)
int connman_inet_remove_from_bridge(int index, const char *bridge)
{
struct ifreq ifr;
- int sk, err;
+ int sk, err = 0;
if (bridge == NULL)
return -EINVAL;
sk = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
- if (sk < 0)
- return sk;
+ if (sk < 0) {
+ err = -errno;
+ goto out;
+ }
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, bridge, IFNAMSIZ - 1);
ifr.ifr_ifindex = index;
- err = ioctl(sk, SIOCBRDELIF, &ifr);
+ if (ioctl(sk, SIOCBRDELIF, &ifr) < 0)
+ err = -errno;
close(sk);
- if (err < 0) {
+out:
+ if (err < 0)
connman_error("Remove interface from bridge error %s",
- strerror(errno));
- return err;
- }
+ strerror(-err));
- return 0;
+ return err;
}
int connman_inet_add_to_bridge(int index, const char *bridge)
{
struct ifreq ifr;
- int sk, err;
+ int sk, err = 0;
if (bridge == NULL)
return -EINVAL;
sk = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
- if (sk < 0)
- return sk;
+ if (sk < 0) {
+ err = -errno;
+ goto out;
+ }
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, bridge, IFNAMSIZ - 1);
ifr.ifr_ifindex = index;
- err = ioctl(sk, SIOCBRADDIF, &ifr);
+ if (ioctl(sk, SIOCBRADDIF, &ifr) < 0)
+ err = -errno;
close(sk);
- if (err < 0) {
+out:
+ if (err < 0)
connman_error("Add interface to bridge error %s",
- strerror(errno));
- return err;
- }
+ strerror(-err));
- return 0;
+ return err;
}
int connman_inet_set_mtu(int index, int mtu)