From d747b97dbd29b4b6d34bb03a7ece533b26b1d49c Mon Sep 17 00:00:00 2001 From: Kishore Kunal Date: Thu, 14 Nov 2024 12:42:27 -0800 Subject: [PATCH] [EVPN-MH] Added new APP_L2_NEXTHOP_GROUP_TABLE_NAME table in APPL_DB And support to register and de-register raw netlink msg Signed-off-by: Kishore Kunal --- common/netdispatcher.cpp | 37 ++++++++++++++++++++++++++++++++++++- common/netdispatcher.h | 17 +++++++++++++++++ common/netmsg.h | 5 +++++ common/schema.h | 2 ++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/common/netdispatcher.cpp b/common/netdispatcher.cpp index e7f8878a..352939c0 100644 --- a/common/netdispatcher.cpp +++ b/common/netdispatcher.cpp @@ -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; @@ -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)); } diff --git a/common/netdispatcher.h b/common/netdispatcher.h index 4a7e9fad..be1ddae3 100644 --- a/common/netdispatcher.h +++ b/common/netdispatcher.h @@ -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. * @@ -48,6 +63,8 @@ namespace swss std::map m_handlers; + std::map m_rawhandlers; + /** Mutex protecting register, unregister and get callback methods. */ std::mutex m_mutex; }; diff --git a/common/netmsg.h b/common/netmsg.h index 5cdeae03..dda5bd8a 100644 --- a/common/netmsg.h +++ b/common/netmsg.h @@ -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 *) + { + } }; } diff --git a/common/schema.h b/common/schema.h index e616f128..36bb9b1b 100644 --- a/common/schema.h +++ b/common/schema.h @@ -125,6 +125,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"