San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #ifndef _NETLINKEVENT_H |
| 17 | #define _NETLINKEVENT_H |
| 18 | |
Mike J. Chen | 17260b1 | 2011-06-23 15:00:30 -0700 | [diff] [blame] | 19 | #include <sysutils/NetlinkListener.h> |
| 20 | |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 21 | #define NL_PARAMS_MAX 32 |
| 22 | |
| 23 | class NetlinkEvent { |
Jeff Sharkey | e4f3940 | 2015-03-13 13:27:33 -0700 | [diff] [blame] | 24 | public: |
| 25 | enum class Action { |
| 26 | kUnknown = 0, |
| 27 | kAdd = 1, |
| 28 | kRemove = 2, |
| 29 | kChange = 3, |
| 30 | kLinkUp = 4, |
| 31 | kLinkDown = 5, |
| 32 | kAddressUpdated = 6, |
| 33 | kAddressRemoved = 7, |
| 34 | kRdnss = 8, |
| 35 | kRouteUpdated = 9, |
| 36 | kRouteRemoved = 10, |
| 37 | }; |
| 38 | |
| 39 | private: |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 40 | int mSeq; |
| 41 | char *mPath; |
Jeff Sharkey | e4f3940 | 2015-03-13 13:27:33 -0700 | [diff] [blame] | 42 | Action mAction; |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 43 | char *mSubsystem; |
| 44 | char *mParams[NL_PARAMS_MAX]; |
| 45 | |
| 46 | public: |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 47 | NetlinkEvent(); |
| 48 | virtual ~NetlinkEvent(); |
| 49 | |
Mike J. Chen | 17260b1 | 2011-06-23 15:00:30 -0700 | [diff] [blame] | 50 | bool decode(char *buffer, int size, int format = NetlinkListener::NETLINK_FORMAT_ASCII); |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 51 | const char *findParam(const char *paramName); |
| 52 | |
| 53 | const char *getSubsystem() { return mSubsystem; } |
Jeff Sharkey | e4f3940 | 2015-03-13 13:27:33 -0700 | [diff] [blame] | 54 | Action getAction() { return mAction; } |
San Mehat | d674413 | 2009-12-24 07:17:09 -0800 | [diff] [blame] | 55 | |
| 56 | void dump(); |
Mike J. Chen | ec16b9d | 2011-06-23 14:55:28 -0700 | [diff] [blame] | 57 | |
| 58 | protected: |
| 59 | bool parseBinaryNetlinkMessage(char *buffer, int size); |
| 60 | bool parseAsciiNetlinkMessage(char *buffer, int size); |
Lorenzo Colitti | 9b34293 | 2014-06-19 13:16:04 +0900 | [diff] [blame] | 61 | bool parseIfInfoMessage(const struct nlmsghdr *nh); |
| 62 | bool parseIfAddrMessage(const struct nlmsghdr *nh); |
| 63 | bool parseUlogPacketMessage(const struct nlmsghdr *nh); |
Jeff Sharkey | 9a20e67 | 2014-10-30 14:51:59 -0700 | [diff] [blame] | 64 | bool parseNfPacketMessage(struct nlmsghdr *nh); |
Lorenzo Colitti | d7ff7ea | 2014-06-11 17:37:12 +0900 | [diff] [blame] | 65 | bool parseRtMessage(const struct nlmsghdr *nh); |
Lorenzo Colitti | 9b34293 | 2014-06-19 13:16:04 +0900 | [diff] [blame] | 66 | bool parseNdUserOptMessage(const struct nlmsghdr *nh); |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | #endif |