summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshish Sharma <ashishsharma@google.com>2012-04-10 19:47:09 -0700
committerAshish Sharma <ashishsharma@google.com>2012-04-12 12:08:04 -0700
commit6337b88ce4438d224819e9b381ddaf2873bbfdda (patch)
treebfce7f0b46cada23461c2283084428d11e25704f
parentb146ae64bda6f82b390323b6586b4f37b981572b (diff)
downloadnetd-6337b88ce4438d224819e9b381ddaf2873bbfdda.tar.gz
netd: Add support for interface idletimer netlink notifications.
Change-Id: Ifda5b8ecf68533eea42b133dbe0a581b4401ab11
-rw-r--r--NetlinkHandler.cpp20
-rw-r--r--NetlinkHandler.h1
-rw-r--r--NetlinkManager.cpp21
-rw-r--r--NetlinkManager.h5
-rw-r--r--ResponseCode.h2
5 files changed, 48 insertions, 1 deletions
diff --git a/NetlinkHandler.cpp b/NetlinkHandler.cpp
index 954a4781..a4f039ce 100644
--- a/NetlinkHandler.cpp
+++ b/NetlinkHandler.cpp
@@ -72,8 +72,16 @@ void NetlinkHandler::onEvent(NetlinkEvent *evt) {
const char *alertName = evt->findParam("ALERT_NAME");
const char *iface = evt->findParam("INTERFACE");
notifyQuotaLimitReached(alertName, iface);
- }
+ } else if (!strcmp(subsys, "idletimer")) {
+ int action = evt->getAction();
+ const char *iface = evt->findParam("INTERFACE");
+ if (action == evt->NlActionIfaceActive) {
+ notifyInterfaceActivity(iface, true);
+ } else if (action == evt->NlActionIfaceIdle) {
+ notifyInterfaceActivity(iface, false);
+ }
+ }
}
void NetlinkHandler::notifyInterfaceAdded(const char *name) {
@@ -117,3 +125,13 @@ void NetlinkHandler::notifyQuotaLimitReached(const char *name, const char *iface
mNm->getBroadcaster()->sendBroadcast(ResponseCode::BandwidthControl,
msg, false);
}
+
+void NetlinkHandler::notifyInterfaceActivity(const char *name, bool isActive) {
+ char msg[255];
+
+ snprintf(msg, sizeof(msg), "Iface %s %s", isActive ? "active" : "idle", name);
+
+ mNm->getBroadcaster()->sendBroadcast(isActive ? ResponseCode::InterfaceActive
+ : ResponseCode::InterfaceIdle,
+ msg, false);
+}
diff --git a/NetlinkHandler.h b/NetlinkHandler.h
index 9466ca6c..fe829346 100644
--- a/NetlinkHandler.h
+++ b/NetlinkHandler.h
@@ -38,5 +38,6 @@ protected:
void notifyInterfaceChanged(const char *name, bool isUp);
void notifyInterfaceLinkChanged(const char *name, bool isUp);
void notifyQuotaLimitReached(const char *name, const char *iface);
+ void notifyInterfaceActivity(const char *name, bool isActive);
};
#endif
diff --git a/NetlinkManager.cpp b/NetlinkManager.cpp
index 73e55999..2d8a4de1 100644
--- a/NetlinkManager.cpp
+++ b/NetlinkManager.cpp
@@ -34,6 +34,7 @@
#include "NetlinkHandler.h"
const int NetlinkManager::NFLOG_QUOTA_GROUP = 1;
+const int NetlinkManager::IDLETIMER_GROUP = 1;
NetlinkManager *NetlinkManager::sInstance = NULL;
@@ -111,6 +112,12 @@ int NetlinkManager::start() {
ALOGE("Unable to open quota2 logging socket");
// TODO: return -1 once the emulator gets a new kernel.
}
+
+ if ((mIfaceIdleTimerHandler = setupSocket(&mIfaceIdleTimerSock, NETLINK_IDLETIMER,
+ IDLETIMER_GROUP, NetlinkListener::NETLINK_FORMAT_BINARY)) == NULL) {
+ // TODO: switch back to using NETLINK_NFLOG with a custom type.
+ ALOGE("Unable to open iface idletimer socket");
+ }
return 0;
}
@@ -151,5 +158,19 @@ int NetlinkManager::stop() {
close(mQuotaSock);
mQuotaSock = -1;
}
+
+ if (mIfaceIdleTimerHandler) {
+ if (mIfaceIdleTimerHandler->stop()) {
+ ALOGE("Unable to stop iface IDLETIMER NetlinkHandler: %s", strerror(errno));
+ status = -1;
+ }
+
+ delete mIfaceIdleTimerHandler;
+ mIfaceIdleTimerHandler = NULL;
+
+ close(mIfaceIdleTimerSock);
+ mIfaceIdleTimerSock = -1;
+ }
+
return status;
}
diff --git a/NetlinkManager.h b/NetlinkManager.h
index c8f55070..6515ea4c 100644
--- a/NetlinkManager.h
+++ b/NetlinkManager.h
@@ -32,9 +32,11 @@ private:
NetlinkHandler *mUeventHandler;
NetlinkHandler *mRouteHandler;
NetlinkHandler *mQuotaHandler;
+ NetlinkHandler *mIfaceIdleTimerHandler;
int mUeventSock;
int mRouteSock;
int mQuotaSock;
+ int mIfaceIdleTimerSock;
public:
virtual ~NetlinkManager();
@@ -50,6 +52,9 @@ public:
/* This is the nflog group arg that the xt_quota2 neftiler will use. */
static const int NFLOG_QUOTA_GROUP;
+ /* This is the group that the xt_IDLETIMER netfilter will use. */
+ static const int IDLETIMER_GROUP;
+
private:
NetlinkManager();
NetlinkHandler* setupSocket(int *sock, int netlinkFamily, int groups,
diff --git a/ResponseCode.h b/ResponseCode.h
index 04a66448..07c2be36 100644
--- a/ResponseCode.h
+++ b/ResponseCode.h
@@ -59,5 +59,7 @@ public:
// 600 series - Unsolicited broadcasts
static const int InterfaceChange = 600;
static const int BandwidthControl = 601;
+ static const int InterfaceActive = 602;
+ static const int InterfaceIdle = 603;
};
#endif