Skip to content

Commit

Permalink
[EVPN-MH] Added new APP_L2_NEXTHOP_GROUP_TABLE_NAME table in APPL_DB
Browse files Browse the repository at this point in the history
And support to register and de-register raw netlink msg

Signed-off-by: Kishore Kunal <[email protected]>
  • Loading branch information
kishorekunal01 committed Nov 15, 2024
1 parent 378e828 commit cfb5c77
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
37 changes: 36 additions & 1 deletion common/netdispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,45 @@ void NetDispatcher::unregisterMessageHandler(int nlmsg_type)
m_handlers.erase(it);
}

void NetDispatcher::registerRawMessageHandler(int nlmsg_type, NetMsg *callback)
{
if (m_rawhandlers.find(nlmsg_type) != m_rawhandlers.end())
throw "Trying to registered on already registerd netlink message";

m_rawhandlers[nlmsg_type] = callback;
}

void NetDispatcher::unregisterRawMessageHandler(int nlmsg_type)
{
auto it = m_rawhandlers.find(nlmsg_type);

if (it == m_rawhandlers.end())
throw "Trying to unregister non existing handler";

m_rawhandlers.erase(it);

}

void NetDispatcher::nlCallback(struct nl_object *obj, void *context)
{
NetMsg *callback = (NetMsg *)context;
callback->onMsg(nl_object_get_msgtype(obj), obj);
}

void NetDispatcher::onNetlinkMessageRaw(struct nl_msg *msg)
{
struct nlmsghdr *nlmsghdr = nlmsg_hdr(msg);
NetMsg *reg_callback = NULL;
auto callback = m_rawhandlers.find(nlmsghdr->nlmsg_type);

/* Drop not registered messages */
if (callback == m_rawhandlers.end())
return;

reg_callback = (NetMsg *)callback->second;
reg_callback->onMsgRaw(nlmsghdr);
}

NetMsg* NetDispatcher::getCallback(int nlmsg_type)
{
MUTEX;
Expand All @@ -61,7 +94,9 @@ void NetDispatcher::onNetlinkMessage(struct nl_msg *msg)

/* Drop not registered messages */
if (callback == nullptr)
{
onNetlinkMessageRaw(msg);
return;

}
nl_msg_parse(msg, NetDispatcher::nlCallback, (callback));
}
17 changes: 17 additions & 0 deletions common/netdispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,24 @@ namespace swss
*/
void registerMessageHandler(int nlmsg_type, NetMsg *callback);

/*
* Register callback class according to message-type.
*
* Throw exception if
*/
void registerRawMessageHandler(int nlmsg_type, NetMsg *callback);

void unregisterRawMessageHandler(int nlmsg_type);


/** Called by NetLink or FpmLink classes as indication of new packet arrival. */
void onNetlinkMessage(struct nl_msg *msg);

/*
* Called by NetLink or FpmLink classes as indication of new packet arrival
*/
void onNetlinkMessageRaw(struct nl_msg *msg);

/**
* Unregister callback according to message-type.
*
Expand All @@ -48,6 +63,8 @@ namespace swss

std::map<int, NetMsg*> m_handlers;

std::map<int, NetMsg * > m_rawhandlers;

/** Mutex protecting register, unregister and get callback methods. */
std::mutex m_mutex;
};
Expand Down
5 changes: 5 additions & 0 deletions common/netmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ namespace swss
public:
/* Called by NetDispatcher when netmsg matches filters */
virtual void onMsg(int nlmsg_type, struct nl_object *obj) = 0;

/* Called by NetDispatcher when raw msg is send for matches filters */
virtual void onMsgRaw(struct nlmsghdr *)
{
}
};
}
4 changes: 2 additions & 2 deletions common/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ namespace swss {
#define APP_NAPT_POOL_IP_TABLE_NAME "NAPT_POOL_IP_TABLE"
#define APP_NAT_DNAT_POOL_TABLE_NAME "NAT_DNAT_POOL_TABLE"

#define APP_VRRP_TABLE_NAME "VRRP_TABLE"

#define APP_STP_VLAN_TABLE_NAME "STP_VLAN_TABLE"
#define APP_STP_VLAN_PORT_TABLE_NAME "STP_VLAN_PORT_TABLE"
#define APP_STP_VLAN_INSTANCE_TABLE_NAME "STP_VLAN_INSTANCE_TABLE"
Expand All @@ -125,6 +123,8 @@ namespace swss {

#define APP_VNET_MONITOR_TABLE_NAME "VNET_MONITOR_TABLE"

#define APP_L2_NEXTHOP_GROUP_TABLE_NAME "L2_NEXTHOP_GROUP_TABLE"

/***** ASIC DATABASE *****/
#define ASIC_TEMPERATURE_INFO_TABLE_NAME "ASIC_TEMPERATURE_INFO"

Expand Down

0 comments on commit cfb5c77

Please sign in to comment.