From 9b0851196880a79fbcca76616c27bb9d16ba94c7 Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Thu, 16 Aug 2012 12:21:34 +0300 Subject: 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. --- src/inet.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/inet.c') 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; -- cgit v1.2.3