diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2013-08-02 05:57:47 +0900 |
---|---|---|
committer | Lorenzo Colitti <lorenzo@google.com> | 2013-08-09 12:43:30 +0900 |
commit | 9b3cd7635caf5948d7d4b11f8f588c9d2811d58e (patch) | |
tree | fdc03f022842627cf1fd9ba767044f555ed9a1e0 | |
parent | 979f54172af12d04fbcf07703b1db1891fa39d4c (diff) | |
download | netd-9b3cd7635caf5948d7d4b11f8f588c9d2811d58e.tar.gz |
Make netd track and notify IP address changes.
Subscribe netd's netlink socket to listen to IPv4 and IPv6
address changes (and ND opts, which we'll need for IPv6 DNS
later), and make NetlinkHandler notify the system of address
changes.
Bug: 10232006
Change-Id: Ib9dfd58635dce389980d8ee9529a17661a02320a
-rw-r--r-- | NetlinkHandler.cpp | 24 | ||||
-rw-r--r-- | NetlinkHandler.h | 2 | ||||
-rw-r--r-- | NetlinkManager.cpp | 6 | ||||
-rw-r--r-- | ResponseCode.h | 1 |
4 files changed, 31 insertions, 2 deletions
diff --git a/NetlinkHandler.cpp b/NetlinkHandler.cpp index 6621a9aa..753b92b3 100644 --- a/NetlinkHandler.cpp +++ b/NetlinkHandler.cpp @@ -52,7 +52,7 @@ void NetlinkHandler::onEvent(NetlinkEvent *evt) { return; } - if (!strcmp(subsys, "net")) { + if (!strcmp(subsys, "interface")) { int action = evt->getAction(); const char *iface = evt->findParam("INTERFACE"); @@ -69,6 +69,16 @@ void NetlinkHandler::onEvent(NetlinkEvent *evt) { notifyInterfaceLinkChanged(iface, false); } + } else if (!strcmp(subsys, "address")) { + const char *address = evt->findParam("ADDRESS"); + const char *iface = evt->findParam("IFACE"); + const char *flags = evt->findParam("FLAGS"); + const char *scope = evt->findParam("SCOPE"); + + if (iface && flags && scope) { + notifyAddressChanged(evt->getAction(), address, iface, flags, scope); + } + } else if (!strcmp(subsys, "qlog")) { const char *alertName = evt->findParam("ALERT_NAME"); const char *iface = evt->findParam("INTERFACE"); @@ -145,3 +155,15 @@ void NetlinkHandler::notifyInterfaceClassActivity(const char *name, mNm->getBroadcaster()->sendBroadcast( ResponseCode::InterfaceClassActivity, msg, false); } + +void NetlinkHandler::notifyAddressChanged(int action, const char *addr, + const char *iface, const char *flags, + const char *scope) { + char msg[255]; + snprintf(msg, sizeof(msg), "Address %s %s %s %s %s", + (action == NetlinkEvent::NlActionAdd) ? "updated" : "removed", + addr, iface, flags, scope); + + mNm->getBroadcaster()->sendBroadcast(ResponseCode::InterfaceAddressChange, + msg, false); +} diff --git a/NetlinkHandler.h b/NetlinkHandler.h index 50bfaceb..0cbf3392 100644 --- a/NetlinkHandler.h +++ b/NetlinkHandler.h @@ -39,5 +39,7 @@ protected: void notifyInterfaceLinkChanged(const char *name, bool isUp); void notifyQuotaLimitReached(const char *name, const char *iface); void notifyInterfaceClassActivity(const char *name, bool isActive); + void notifyAddressChanged(int action, const char *addr, const char *iface, + const char *flags, const char *scope); }; #endif diff --git a/NetlinkManager.cpp b/NetlinkManager.cpp index 8e2bc691..32578a1d 100644 --- a/NetlinkManager.cpp +++ b/NetlinkManager.cpp @@ -101,7 +101,11 @@ int NetlinkManager::start() { return -1; } - if ((mRouteHandler = setupSocket(&mRouteSock, NETLINK_ROUTE, RTMGRP_LINK, + if ((mRouteHandler = setupSocket(&mRouteSock, NETLINK_ROUTE, + RTMGRP_LINK | + RTMGRP_IPV4_IFADDR | + RTMGRP_IPV6_IFADDR | + (1 << (RTNLGRP_ND_USEROPT - 1)), NetlinkListener::NETLINK_FORMAT_BINARY)) == NULL) { return -1; } diff --git a/ResponseCode.h b/ResponseCode.h index c5792c78..46b842d6 100644 --- a/ResponseCode.h +++ b/ResponseCode.h @@ -75,5 +75,6 @@ public: static const int ServiceGetAddrInfoFailed = 611; static const int ServiceGetAddrInfoSuccess = 612; static const int InterfaceClassActivity = 613; + static const int InterfaceAddressChange = 614; }; #endif |