diff options
author | Wink Saville <wink@google.com> | 2011-01-09 12:22:57 -0800 |
---|---|---|
committer | Wink Saville <wink@google.com> | 2011-01-09 12:22:57 -0800 |
commit | 1d504eeb50d980c222572629383bb76315f32ca0 (patch) | |
tree | ddeb70bf6d5bdf41aadd5a6db4915f188907ecf6 | |
parent | 9315c4bed6783869463e580a19c5b82faf9c3964 (diff) | |
download | system_core-1d504eeb50d980c222572629383bb76315f32ca0.zip system_core-1d504eeb50d980c222572629383bb76315f32ca0.tar.gz system_core-1d504eeb50d980c222572629383bb76315f32ca0.tar.bz2 |
Revert "Add NETLINK_ROUTE processing to the netlink client code, so that Ethernet"
This reverts commit 8418ac8ba59bd140b5a2432c99501cc79debdefc.
-rw-r--r-- | include/sysutils/NetlinkEvent.h | 8 | ||||
-rw-r--r-- | include/sysutils/NetlinkListener.h | 6 | ||||
-rw-r--r-- | libsysutils/src/NetlinkEvent.cpp | 67 | ||||
-rw-r--r-- | libsysutils/src/NetlinkListener.cpp | 12 |
4 files changed, 8 insertions, 85 deletions
diff --git a/include/sysutils/NetlinkEvent.h b/include/sysutils/NetlinkEvent.h index 1ee9849..b329b09 100644 --- a/include/sysutils/NetlinkEvent.h +++ b/include/sysutils/NetlinkEvent.h @@ -30,23 +30,17 @@ public: const static int NlActionAdd; const static int NlActionRemove; const static int NlActionChange; - const static int NlActionLinkDown; - const static int NlActionLinkUp; NetlinkEvent(); virtual ~NetlinkEvent(); - bool decode(char *buffer, int size, int format); + bool decode(char *buffer, int size); const char *findParam(const char *paramName); const char *getSubsystem() { return mSubsystem; } int getAction() { return mAction; } void dump(); - - protected: - bool parseBinaryNetlinkMessage(char *buffer, int size); - bool parseAsciiNetlinkMessage(char *buffer, int size); }; #endif diff --git a/include/sysutils/NetlinkListener.h b/include/sysutils/NetlinkListener.h index 1cf5f9f..2880046 100644 --- a/include/sysutils/NetlinkListener.h +++ b/include/sysutils/NetlinkListener.h @@ -22,13 +22,9 @@ class NetlinkEvent; class NetlinkListener : public SocketListener { char mBuffer[64 * 1024]; - int mFormat; public: - static const int NETLINK_FORMAT_ASCII = 0; - static const int NETLINK_FORMAT_BINARY = 1; - - NetlinkListener(int socket, int format); + NetlinkListener(int socket); virtual ~NetlinkListener() {} protected: diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp index 2e3143d..86c1f42 100644 --- a/libsysutils/src/NetlinkEvent.cpp +++ b/libsysutils/src/NetlinkEvent.cpp @@ -19,20 +19,12 @@ #define LOG_TAG "NetlinkEvent" #include <cutils/log.h> -#include <sysutils/NetlinkListener.h> #include <sysutils/NetlinkEvent.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <linux/rtnetlink.h> -#include <linux/if.h> - const int NetlinkEvent::NlActionUnknown = 0; const int NetlinkEvent::NlActionAdd = 1; const int NetlinkEvent::NlActionRemove = 2; const int NetlinkEvent::NlActionChange = 3; -const int NetlinkEvent::NlActionLinkUp = 4; -const int NetlinkEvent::NlActionLinkDown = 5; NetlinkEvent::NetlinkEvent() { mAction = NlActionUnknown; @@ -64,56 +56,7 @@ void NetlinkEvent::dump() { } } -/* - * Parse an binary message from a NETLINK_ROUTE netlink socket. - */ -bool NetlinkEvent::parseBinaryNetlinkMessage(char *buffer, int size) { - size_t sz = size; - struct nlmsghdr *nh = (struct nlmsghdr *) buffer; - - while (NLMSG_OK(nh, sz) && (nh->nlmsg_type != NLMSG_DONE)) { - if (nh->nlmsg_type == RTM_NEWLINK) { - int len = nh->nlmsg_len - sizeof(*nh); - struct ifinfomsg *ifi; - - if (sizeof(*ifi) <= (size_t) len) { - ifi = (ifinfomsg *)NLMSG_DATA(nh); - - if ((ifi->ifi_flags & IFF_LOOPBACK) == 0) { - struct rtattr *rta = (struct rtattr *) - ((char *) ifi + NLMSG_ALIGN(sizeof(*ifi))); - len = NLMSG_PAYLOAD(nh, sizeof(*ifi)); - - while(RTA_OK(rta, len)) { - switch(rta->rta_type) { - case IFLA_IFNAME: - char buffer[16 + IFNAMSIZ]; - snprintf(buffer, sizeof(buffer), "INTERFACE=%s", - (char *) RTA_DATA(rta)); - mParams[0] = strdup(buffer); - mAction = (ifi->ifi_flags & IFF_LOWER_UP) ? - NlActionLinkUp : NlActionLinkDown; - mSubsystem = strdup("net"); - break; - } - - rta = RTA_NEXT(rta, len); - } - } - } - } - - nh = NLMSG_NEXT(nh, size); - } - - return true; -} - -/* - * Parse an ASCII-formatted message from a NETLINK_KOBJECT_UEVENT - * netlink socket. - */ -bool NetlinkEvent::parseAsciiNetlinkMessage(char *buffer, int size) { +bool NetlinkEvent::decode(char *buffer, int size) { char *s = buffer; char *end; int param_idx = 0; @@ -149,14 +92,6 @@ bool NetlinkEvent::parseAsciiNetlinkMessage(char *buffer, int size) { return true; } -bool NetlinkEvent::decode(char *buffer, int size, int format) { - if (format == NetlinkListener::NETLINK_FORMAT_BINARY) { - return parseBinaryNetlinkMessage(buffer, size); - } else { - return parseAsciiNetlinkMessage(buffer, size); - } -} - const char *NetlinkEvent::findParam(const char *paramName) { size_t len = strlen(paramName); for (int i = 0; mParams[i] && i < NL_PARAMS_MAX; ++i) { diff --git a/libsysutils/src/NetlinkListener.cpp b/libsysutils/src/NetlinkListener.cpp index 8361120..e2a354e 100644 --- a/libsysutils/src/NetlinkListener.cpp +++ b/libsysutils/src/NetlinkListener.cpp @@ -25,9 +25,8 @@ #include <sysutils/NetlinkListener.h> #include <sysutils/NetlinkEvent.h> -NetlinkListener::NetlinkListener(int socket, int format) : +NetlinkListener::NetlinkListener(int socket) : SocketListener(socket, false) { - mFormat = format; } bool NetlinkListener::onDataAvailable(SocketClient *cli) @@ -41,14 +40,13 @@ bool NetlinkListener::onDataAvailable(SocketClient *cli) } NetlinkEvent *evt = new NetlinkEvent(); - int err = evt->decode(mBuffer, count, mFormat); - - if (!err) { + if (!evt->decode(mBuffer, count)) { SLOGE("Error decoding NetlinkEvent"); - } else { - onEvent(evt); + goto out; } + onEvent(evt); +out: delete evt; return true; } |