Notify network observers of route changes.

Bug: 9180552
Change-Id: Ic23025e4d7cb4e58ae59017777267ac45f00b434
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);
+}