Tolerate RTM_DELADDR messages from deleted interfaces.
When an interface is deleted (which can happen, for example, to
the tun interfaces used for VPN and 464xlat), the kernel sends
RTM_DELADDR messages for all its IP addresses.
Currently we ignore these because we cannot fetch the interface
name. Instead, pass them up with an empty interface name so that
NetlinkHandler can do something useful for them, such as destroy
connections on the IP addresses that are being deleted.
Bug: 26976388
Change-Id: I2ced7e389228f9d665d0a87d97bd3452c8c0c98b
diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp
index 23dcd62..739fad7 100644
--- a/libsysutils/src/NetlinkEvent.cpp
+++ b/libsysutils/src/NetlinkEvent.cpp
@@ -159,7 +159,7 @@
struct ifaddrmsg *ifaddr = (struct ifaddrmsg *) NLMSG_DATA(nh);
struct ifa_cacheinfo *cacheinfo = NULL;
char addrstr[INET6_ADDRSTRLEN] = "";
- char ifname[IFNAMSIZ];
+ char ifname[IFNAMSIZ] = "";
if (!checkRtNetlinkLength(nh, sizeof(*ifaddr)))
return false;
@@ -207,8 +207,7 @@
// Find the interface name.
if (!if_indextoname(ifaddr->ifa_index, ifname)) {
- SLOGE("Unknown ifindex %d in %s", ifaddr->ifa_index, msgtype);
- return false;
+ SLOGD("Unknown ifindex %d in %s", ifaddr->ifa_index, msgtype);
}
} else if (rta->rta_type == IFA_CACHEINFO) {
@@ -235,8 +234,7 @@
mAction = (type == RTM_NEWADDR) ? Action::kAddressUpdated :
Action::kAddressRemoved;
mSubsystem = strdup("net");
- asprintf(&mParams[0], "ADDRESS=%s/%d", addrstr,
- ifaddr->ifa_prefixlen);
+ asprintf(&mParams[0], "ADDRESS=%s/%d", addrstr, ifaddr->ifa_prefixlen);
asprintf(&mParams[1], "INTERFACE=%s", ifname);
asprintf(&mParams[2], "FLAGS=%u", ifaddr->ifa_flags);
asprintf(&mParams[3], "SCOPE=%u", ifaddr->ifa_scope);