-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
75 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,54 @@ | ||
#ifndef __NETDISPATCHER__ | ||
#define __NETDISPATCHER__ | ||
|
||
#include <netlink/netlink.h> | ||
#include <netlink/cache.h> | ||
#include <netlink/utils.h> | ||
#include <netlink/data.h> | ||
#include <netlink/route/rtnl.h> | ||
|
||
#include <map> | ||
#include <mutex> | ||
#pragma once | ||
|
||
#include "netmsg.h" | ||
|
||
namespace swss { | ||
#include <netlink/msg.h> | ||
|
||
class NetDispatcher { | ||
public: | ||
#include <map> | ||
#include <mutex> | ||
|
||
/* | ||
* Get singlton instance*/ | ||
static NetDispatcher& getInstance(); | ||
namespace swss | ||
{ | ||
class NetDispatcher | ||
{ | ||
public: | ||
|
||
/* | ||
* Register callback class according to message-type. | ||
* | ||
* Throw exception if callback is already registered. | ||
*/ | ||
void registerMessageHandler(int nlmsg_type, NetMsg *callback); | ||
/** Get singlton instance. */ | ||
static NetDispatcher& getInstance(); | ||
|
||
/* | ||
* Called by NetLink or FpmLink classes as indication of new packet arrival | ||
*/ | ||
void onNetlinkMessage(struct nl_msg *msg); | ||
/** | ||
* Register callback class according to message-type. | ||
* | ||
* Throw exception if callback is already registered. | ||
*/ | ||
void registerMessageHandler(int nlmsg_type, NetMsg *callback); | ||
|
||
/* | ||
* Unregister callback according to message-type. | ||
* | ||
* Throw exception if callback is not registered. | ||
*/ | ||
void unregisterMessageHandler(int nlmsg_type); | ||
/** Called by NetLink or FpmLink classes as indication of new packet arrival. */ | ||
void onNetlinkMessage(struct nl_msg *msg); | ||
|
||
private: | ||
/** | ||
* Unregister callback according to message-type. | ||
* | ||
* Throw exception if callback is not registered. | ||
*/ | ||
void unregisterMessageHandler(int nlmsg_type); | ||
|
||
NetDispatcher() = default; | ||
private: | ||
|
||
NetDispatcher(const NetDispatcher&) = delete; | ||
NetDispatcher() = default; | ||
|
||
NetMsg* getCallback(int nlmsg_type); | ||
NetDispatcher(const NetDispatcher&) = delete; | ||
|
||
private: | ||
NetMsg* getCallback(int nlmsg_type); | ||
|
||
/* nl_msg_parse callback API */ | ||
static void nlCallback(struct nl_object *obj, void *context); | ||
private: | ||
|
||
std::map<int, NetMsg*> m_handlers; | ||
/** nl_msg_parse callback API */ | ||
static void nlCallback(struct nl_object *obj, void *context); | ||
|
||
/* | ||
* Mutex protecting register, unregister and get callback methods. | ||
*/ | ||
std::mutex m_mutex; | ||
}; | ||
std::map<int, NetMsg*> m_handlers; | ||
|
||
/** Mutex protecting register, unregister and get callback methods. */ | ||
std::mutex m_mutex; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
#ifndef __NETLINK__ | ||
#define __NETLINK__ | ||
#pragma once | ||
|
||
#include <linux/netlink.h> | ||
#include <linux/rtnetlink.h> | ||
#include "selectable.h" | ||
|
||
namespace swss { | ||
#include <netlink/netlink.h> | ||
#include <netlink/route/rtnl.h> | ||
|
||
class NetLink : public Selectable { | ||
public: | ||
NetLink(int pri = 0); | ||
~NetLink() override; | ||
namespace swss | ||
{ | ||
class NetLink : | ||
public Selectable | ||
{ | ||
public: | ||
|
||
void registerGroup(int rtnlGroup); | ||
void dumpRequest(int rtmGetCommand); | ||
NetLink(int pri = 0); | ||
virtual ~NetLink(); | ||
|
||
int getFd() override; | ||
uint64_t readData() override; | ||
void registerGroup(int rtnlGroup); | ||
void dumpRequest(int rtmGetCommand); | ||
|
||
private: | ||
static int onNetlinkMsg(struct nl_msg *msg, void *arg); | ||
int getFd() override; | ||
uint64_t readData() override; | ||
|
||
nl_sock *m_socket; | ||
}; | ||
private: | ||
|
||
} | ||
static int onNetlinkMsg(struct nl_msg *msg, void *arg); | ||
|
||
#endif | ||
struct nl_sock *m_socket; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
#ifndef __NETMSG__ | ||
#define __NETMSG__ | ||
#pragma once | ||
|
||
#include <netlink/netlink.h> | ||
#include <netlink/cache.h> | ||
#include <netlink/utils.h> | ||
#include <netlink/data.h> | ||
#include <netlink/route/rtnl.h> | ||
|
||
namespace swss { | ||
|
||
class NetMsg { | ||
public: | ||
/* Called by NetDispatcher when netmsg matches filters */ | ||
virtual void onMsg(int nlmsg_type, struct nl_object *obj) = 0; | ||
}; | ||
|
||
namespace swss | ||
{ | ||
class NetMsg | ||
{ | ||
public: | ||
/* Called by NetDispatcher when netmsg matches filters */ | ||
virtual void onMsg(int nlmsg_type, struct nl_object *obj) = 0; | ||
}; | ||
} | ||
|
||
#endif |