From 5e5e5e9a733d9427064f6fb0a72df9769f634d92 Mon Sep 17 00:00:00 2001 From: Chenbo Feng Date: Fri, 2 Mar 2018 01:32:53 -0800 Subject: [PATCH] Include iface index in the netlink event The TrafficController inside netd also get notified when the interface on device added or removed, and it need both ifaceName and ifaceIndex information from Netlink event. Add the ifaceIndex in the event can avoid the TrafficController to run if_nametoindex again when receive the event. Bug: 30950746 Bug: 73137611 Test: new interface show up in bpf interface map. Change-Id: Ia3b4aeb8eff345ce7cf03ccec88f0893cfe125c0 --- libsysutils/src/NetlinkEvent.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp index 7f92904f2..35a30639b 100644 --- a/libsysutils/src/NetlinkEvent.cpp +++ b/libsysutils/src/NetlinkEvent.cpp @@ -137,6 +137,12 @@ bool NetlinkEvent::parseIfInfoMessage(const struct nlmsghdr *nh) { switch(rta->rta_type) { case IFLA_IFNAME: asprintf(&mParams[0], "INTERFACE=%s", (char *) RTA_DATA(rta)); + // We can get the interface change information from sysfs update + // already. But in case we missed those message when devices start. + // We do a update again when received a kLinkUp event. To make + // the message consistent, use IFINDEX here as well since sysfs + // uses IFINDEX. + asprintf(&mParams[1], "IFINDEX=%d", ifi->ifi_index); mAction = (ifi->ifi_flags & IFF_LOWER_UP) ? Action::kLinkUp : Action::kLinkDown; mSubsystem = strdup("net");