Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 707d4f2e authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Define enum class for NetlinkEvent actions."

parents 72af28c2 e4f39408
Loading
Loading
Loading
Loading
+18 −14
Original line number Diff line number Diff line
@@ -21,25 +21,29 @@
#define NL_PARAMS_MAX 32

class NetlinkEvent {
public:
    enum class Action {
        kUnknown = 0,
        kAdd = 1,
        kRemove = 2,
        kChange = 3,
        kLinkUp = 4,
        kLinkDown = 5,
        kAddressUpdated = 6,
        kAddressRemoved = 7,
        kRdnss = 8,
        kRouteUpdated = 9,
        kRouteRemoved = 10,
    };

private:
    int  mSeq;
    char *mPath;
    int  mAction;
    Action mAction;
    char *mSubsystem;
    char *mParams[NL_PARAMS_MAX];

public:
    const static int NlActionUnknown;
    const static int NlActionAdd;
    const static int NlActionRemove;
    const static int NlActionChange;
    const static int NlActionLinkDown;
    const static int NlActionLinkUp;
    const static int NlActionAddressUpdated;
    const static int NlActionAddressRemoved;
    const static int NlActionRdnss;
    const static int NlActionRouteUpdated;
    const static int NlActionRouteRemoved;

    NetlinkEvent();
    virtual ~NetlinkEvent();

@@ -47,7 +51,7 @@ public:
    const char *findParam(const char *paramName);

    const char *getSubsystem() { return mSubsystem; }
    int getAction() { return mAction; }
    Action getAction() { return mAction; }

    void dump();

+13 −25
Original line number Diff line number Diff line
@@ -47,20 +47,8 @@ const int LOCAL_NFLOG_PACKET = NFNL_SUBSYS_ULOG << 8 | NFULNL_MSG_PACKET;
#include <netlink/handlers.h>
#include <netlink/msg.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;
const int NetlinkEvent::NlActionAddressUpdated = 6;
const int NetlinkEvent::NlActionAddressRemoved = 7;
const int NetlinkEvent::NlActionRdnss = 8;
const int NetlinkEvent::NlActionRouteUpdated = 9;
const int NetlinkEvent::NlActionRouteRemoved = 10;

NetlinkEvent::NetlinkEvent() {
    mAction = NlActionUnknown;
    mAction = Action::kUnknown;
    memset(mParams, 0, sizeof(mParams));
    mPath = NULL;
    mSubsystem = NULL;
@@ -154,8 +142,8 @@ bool NetlinkEvent::parseIfInfoMessage(const struct nlmsghdr *nh) {
        switch(rta->rta_type) {
            case IFLA_IFNAME:
                asprintf(&mParams[0], "INTERFACE=%s", (char *) RTA_DATA(rta));
                mAction = (ifi->ifi_flags & IFF_LOWER_UP) ?  NlActionLinkUp :
                                                             NlActionLinkDown;
                mAction = (ifi->ifi_flags & IFF_LOWER_UP) ? Action::kLinkUp :
                                                            Action::kLinkDown;
                mSubsystem = strdup("net");
                return true;
        }
@@ -244,8 +232,8 @@ bool NetlinkEvent::parseIfAddrMessage(const struct nlmsghdr *nh) {
    }

    // Fill in netlink event information.
    mAction = (type == RTM_NEWADDR) ? NlActionAddressUpdated :
                                      NlActionAddressRemoved;
    mAction = (type == RTM_NEWADDR) ? Action::kAddressUpdated :
                                      Action::kAddressRemoved;
    mSubsystem = strdup("net");
    asprintf(&mParams[0], "ADDRESS=%s/%d", addrstr,
             ifaddr->ifa_prefixlen);
@@ -276,7 +264,7 @@ bool NetlinkEvent::parseUlogPacketMessage(const struct nlmsghdr *nh) {
    asprintf(&mParams[0], "ALERT_NAME=%s", pm->prefix);
    asprintf(&mParams[1], "INTERFACE=%s", devname);
    mSubsystem = strdup("qlog");
    mAction = NlActionChange;
    mAction = Action::kChange;
    return true;
}

@@ -311,7 +299,7 @@ bool NetlinkEvent::parseNfPacketMessage(struct nlmsghdr *nh) {
    asprintf(&mParams[0], "UID=%d", uid);
    mParams[1] = hex;
    mSubsystem = strdup("strict");
    mAction = NlActionChange;
    mAction = Action::kChange;
    return true;
}

@@ -397,8 +385,8 @@ bool NetlinkEvent::parseRtMessage(const struct nlmsghdr *nh) {
        return false;

    // Fill in netlink event information.
    mAction = (type == RTM_NEWROUTE) ? NlActionRouteUpdated :
                                       NlActionRouteRemoved;
    mAction = (type == RTM_NEWROUTE) ? Action::kRouteUpdated :
                                       Action::kRouteRemoved;
    mSubsystem = strdup("net");
    asprintf(&mParams[0], "ROUTE=%s/%d", dst, prefixLength);
    asprintf(&mParams[1], "GATEWAY=%s", (*gw) ? gw : "");
@@ -497,7 +485,7 @@ bool NetlinkEvent::parseNdUserOptMessage(const struct nlmsghdr *nh) {
        }
        buf[pos] = '\0';

        mAction = NlActionRdnss;
        mAction = Action::kRdnss;
        mSubsystem = strdup("net");
        asprintf(&mParams[0], "INTERFACE=%s", ifname);
        asprintf(&mParams[1], "LIFETIME=%u", lifetime);
@@ -617,11 +605,11 @@ bool NetlinkEvent::parseAsciiNetlinkMessage(char *buffer, int size) {
            const char* a;
            if ((a = HAS_CONST_PREFIX(s, end, "ACTION=")) != NULL) {
                if (!strcmp(a, "add"))
                    mAction = NlActionAdd;
                    mAction = Action::kAdd;
                else if (!strcmp(a, "remove"))
                    mAction = NlActionRemove;
                    mAction = Action::kRemove;
                else if (!strcmp(a, "change"))
                    mAction = NlActionChange;
                    mAction = Action::kChange;
            } else if ((a = HAS_CONST_PREFIX(s, end, "SEQNUM=")) != NULL) {
                mSeq = atoi(a);
            } else if ((a = HAS_CONST_PREFIX(s, end, "SUBSYSTEM=")) != NULL) {