1313
1414#include " neighsync.h"
1515#include " warm_restart.h"
16+ #include < algorithm>
1617
1718using namespace std ;
1819using namespace swss ;
1920
20- NeighSync::NeighSync (RedisPipeline *pipelineAppDB, DBConnector *stateDb) :
21+ NeighSync::NeighSync (RedisPipeline *pipelineAppDB, DBConnector *stateDb, DBConnector *cfgDb ) :
2122 m_neighTable(pipelineAppDB, APP_NEIGH_TABLE_NAME ),
22- m_stateNeighRestoreTable(stateDb, STATE_NEIGH_RESTORE_TABLE_NAME )
23+ m_stateNeighRestoreTable(stateDb, STATE_NEIGH_RESTORE_TABLE_NAME ),
24+ m_cfgInterfaceTable(cfgDb, CFG_INTF_TABLE_NAME ),
25+ m_cfgLagInterfaceTable(cfgDb, CFG_LAG_INTF_TABLE_NAME ),
26+ m_cfgVlanInterfaceTable(cfgDb, CFG_VLAN_INTF_TABLE_NAME )
2327{
2428 m_AppRestartAssist = new AppRestartAssist (pipelineAppDB, " neighsyncd" , " swss" , DEFAULT_NEIGHSYNC_WARMSTART_TIMER );
2529 if (m_AppRestartAssist)
@@ -57,6 +61,7 @@ void NeighSync::onMsg(int nlmsg_type, struct nl_object *obj)
5761 struct rtnl_neigh *neigh = (struct rtnl_neigh *)obj;
5862 string key;
5963 string family;
64+ string intfName;
6065
6166 if ((nlmsg_type != RTM_NEWNEIGH ) && (nlmsg_type != RTM_GETNEIGH ) &&
6267 (nlmsg_type != RTM_DELNEIGH ))
@@ -70,12 +75,18 @@ void NeighSync::onMsg(int nlmsg_type, struct nl_object *obj)
7075 return ;
7176
7277 key+= LinkCache::getInstance ().ifindexToName (rtnl_neigh_get_ifindex (neigh));
78+ intfName = key;
7379 key+= " :" ;
7480
7581 nl_addr2str (rtnl_neigh_get_dst (neigh), ipStr, MAX_ADDR_SIZE );
76- /* Ignore IPv6 link-local addresses as neighbors */
82+ /* Ignore IPv6 link-local addresses as neighbors, if ipv6 link local mode is disabled */
7783 if (family == IPV6_NAME && IN6_IS_ADDR_LINKLOCAL (nl_addr_get_binary_addr (rtnl_neigh_get_dst (neigh))))
78- return ;
84+ {
85+ if (isLinkLocalEnabled (intfName) == false )
86+ {
87+ return ;
88+ }
89+ }
7990 /* Ignore IPv6 multicast link-local addresses as neighbors */
8091 if (family == IPV6_NAME && IN6_IS_ADDR_MC_LINKLOCAL (nl_addr_get_binary_addr (rtnl_neigh_get_dst (neigh))))
8192 return ;
@@ -124,3 +135,52 @@ void NeighSync::onMsg(int nlmsg_type, struct nl_object *obj)
124135 m_neighTable.set (key, fvVector);
125136 }
126137}
138+
139+ /* To check the ipv6 link local is enabled on a given port */
140+ bool NeighSync::isLinkLocalEnabled (const string &port)
141+ {
142+ vector<FieldValueTuple> values;
143+
144+ if (!port.compare (0 , strlen (" Vlan" ), " Vlan" ))
145+ {
146+ if (!m_cfgVlanInterfaceTable.get (port, values))
147+ {
148+ SWSS_LOG_INFO (" IPv6 Link local is not enabled on %s" , port.c_str ());
149+ return false ;
150+ }
151+ }
152+ else if (!port.compare (0 , strlen (" PortChannel" ), " PortChannel" ))
153+ {
154+ if (!m_cfgLagInterfaceTable.get (port, values))
155+ {
156+ SWSS_LOG_INFO (" IPv6 Link local is not enabled on %s" , port.c_str ());
157+ return false ;
158+ }
159+ }
160+ else if (!port.compare (0 , strlen (" Ethernet" ), " Ethernet" ))
161+ {
162+ if (!m_cfgInterfaceTable.get (port, values))
163+ {
164+ SWSS_LOG_INFO (" IPv6 Link local is not enabled on %s" , port.c_str ());
165+ return false ;
166+ }
167+ }
168+ else
169+ {
170+ SWSS_LOG_INFO (" IPv6 Link local is not supported for %s " , port.c_str ());
171+ return false ;
172+ }
173+
174+ auto it = std::find_if (values.begin (), values.end (), [](const FieldValueTuple& t){ return t.first == " ipv6_use_link_local_only" ;});
175+ if (it != values.end ())
176+ {
177+ if (it->second == " enable" )
178+ {
179+ SWSS_LOG_INFO (" IPv6 Link local is enabled on %s" , port.c_str ());
180+ return true ;
181+ }
182+ }
183+
184+ SWSS_LOG_INFO (" IPv6 Link local is not enabled on %s" , port.c_str ());
185+ return false ;
186+ }
0 commit comments