inet: Clear IP addresses when interface is set down
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 16 Aug 2012 09:21:34 +0000 (12:21 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Fri, 17 Aug 2012 13:13:13 +0000 (16:13 +0300)
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.

src/inet.c

index 0c3109d1f7ef7cfe521f112305bd61890a9e6d8c..75efc26ec75b65fdfe4ed82adfd2fa0bd0ea8a56 100644 (file)
@@ -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;