summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2012-08-16 12:21:34 +0300
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-08-17 16:13:13 +0300
commit9b0851196880a79fbcca76616c27bb9d16ba94c7 (patch)
treeddcead0cc16a12b9f98b005fdc4f9f9c3b231b9c
parent4d33afaed53d7ca3fcc7522be526a09a5bef3a0a (diff)
downloadconnman-9b0851196880a79fbcca76616c27bb9d16ba94c7.tar.gz
connman-9b0851196880a79fbcca76616c27bb9d16ba94c7.tar.bz2
connman-9b0851196880a79fbcca76616c27bb9d16ba94c7.zip
inet: Clear IP addresses when interface is set down
Clear interface IPv4 address by setting it to 0.0.0.0. IPv6 addresses are cleared automatically when the IFF_DYNAMIC flag is set at the time the interface is brought down. By removing the IP address and netmask, netlink properly reports new addresses assigned by DHCPv4.
-rw-r--r--src/inet.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/inet.c b/src/inet.c
index 0c3109d1..75efc26e 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -294,7 +294,7 @@ int connman_inet_ifup(int index)
goto done;
}
- ifr.ifr_flags |= IFF_UP;
+ ifr.ifr_flags |= (IFF_UP|IFF_DYNAMIC);
if (ioctl(sk, SIOCSIFFLAGS, &ifr) < 0) {
err = -errno;
@@ -312,6 +312,7 @@ done:
int connman_inet_ifdown(int index)
{
struct ifreq ifr;
+ struct sockaddr_in *addr;
int sk, err;
sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
@@ -331,12 +332,17 @@ int connman_inet_ifdown(int index)
goto done;
}
+ addr = (struct sockaddr_in *)&ifr.ifr_addr;
+ addr->sin_family = AF_INET;
+ if (ioctl(sk, SIOCSIFADDR, &ifr) < 0)
+ connman_warn("Could not clear IPv4 address index %d", index);
+
if (!(ifr.ifr_flags & IFF_UP)) {
err = -EALREADY;
goto done;
}
- ifr.ifr_flags &= ~IFF_UP;
+ ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC;
if (ioctl(sk, SIOCSIFFLAGS, &ifr) < 0)
err = -errno;