Notify network observers of route changes.
This reverts commit 20d3f5e856a38ef22851e32d7f9b6a7cd02eb459.
Bug: 9180552
Change-Id: I004448e2f0c731f6ca2c6d3535dc4dd51a622293
diff --git a/server/NetlinkHandler.cpp b/server/NetlinkHandler.cpp
index 4f421c5..d1dbf7d 100644
--- a/server/NetlinkHandler.cpp
+++ b/server/NetlinkHandler.cpp
@@ -29,6 +29,9 @@
#include "NetlinkManager.h"
#include "ResponseCode.h"
+static const char *kUpdated = "updated";
+static const char *kRemoved = "removed";
+
NetlinkHandler::NetlinkHandler(NetlinkManager *nm, int listenerSocket,
int format) :
NetlinkListener(listenerSocket, format) {
@@ -82,6 +85,14 @@
if (lifetime && servers) {
notifyInterfaceDnsServers(iface, lifetime, servers);
}
+ } else if (action == evt->NlActionRouteUpdated ||
+ action == evt->NlActionRouteRemoved) {
+ const char *route = evt->findParam("ROUTE");
+ const char *gateway = evt->findParam("GATEWAY");
+ const char *iface = evt->findParam("INTERFACE");
+ if (route && (gateway || iface)) {
+ notifyRouteChange(action, route, gateway, iface);
+ }
}
} else if (!strcmp(subsys, "qlog")) {
@@ -154,8 +165,8 @@
const char *scope) {
notify(ResponseCode::InterfaceAddressChange,
"Address %s %s %s %s %s",
- (action == NetlinkEvent::NlActionAddressUpdated) ?
- "updated" : "removed", addr, iface, flags, scope);
+ (action == NetlinkEvent::NlActionAddressUpdated) ? kUpdated : kRemoved,
+ addr, iface, flags, scope);
}
void NetlinkHandler::notifyInterfaceDnsServers(const char *iface,
@@ -164,3 +175,15 @@
notify(ResponseCode::InterfaceDnsInfo, "DnsInfo servers %s %s %s",
iface, lifetime, servers);
}
+
+void NetlinkHandler::notifyRouteChange(int action, const char *route,
+ const char *gateway, const char *iface) {
+ notify(ResponseCode::RouteChange,
+ "Route %s %s%s%s%s%s",
+ (action == NetlinkEvent::NlActionRouteUpdated) ? kUpdated : kRemoved,
+ route,
+ *gateway ? " via " : "",
+ gateway,
+ *iface ? " dev " : "",
+ iface);
+}
diff --git a/server/NetlinkHandler.h b/server/NetlinkHandler.h
index a5c5b6b..83baa2b 100644
--- a/server/NetlinkHandler.h
+++ b/server/NetlinkHandler.h
@@ -45,6 +45,6 @@
const char *flags, const char *scope);
void notifyInterfaceDnsServers(const char *iface, const char *lifetime,
const char *servers);
-
+ void notifyRouteChange(int action, const char *route, const char *gateway, const char *iface);
};
#endif
diff --git a/server/NetlinkManager.cpp b/server/NetlinkManager.cpp
index 32578a1..1d731ac 100644
--- a/server/NetlinkManager.cpp
+++ b/server/NetlinkManager.cpp
@@ -105,6 +105,7 @@
RTMGRP_LINK |
RTMGRP_IPV4_IFADDR |
RTMGRP_IPV6_IFADDR |
+ RTMGRP_IPV6_ROUTE |
(1 << (RTNLGRP_ND_USEROPT - 1)),
NetlinkListener::NETLINK_FORMAT_BINARY)) == NULL) {
return -1;
diff --git a/server/ResponseCode.h b/server/ResponseCode.h
index d8fafbb..054939d 100644
--- a/server/ResponseCode.h
+++ b/server/ResponseCode.h
@@ -77,5 +77,6 @@
static const int InterfaceClassActivity = 613;
static const int InterfaceAddressChange = 614;
static const int InterfaceDnsInfo = 615;
+ static const int RouteChange = 616;
};
#endif