13
13
14
14
#include " neighsync.h"
15
15
#include " warm_restart.h"
16
+ #include < algorithm>
16
17
17
18
using namespace std ;
18
19
using namespace swss ;
19
20
20
- NeighSync::NeighSync (RedisPipeline *pipelineAppDB, DBConnector *stateDb) :
21
+ NeighSync::NeighSync (RedisPipeline *pipelineAppDB, DBConnector *stateDb, DBConnector *cfgDb ) :
21
22
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)
23
27
{
24
28
m_AppRestartAssist = new AppRestartAssist (pipelineAppDB, " neighsyncd" , " swss" , DEFAULT_NEIGHSYNC_WARMSTART_TIMER);
25
29
if (m_AppRestartAssist)
@@ -57,6 +61,7 @@ void NeighSync::onMsg(int nlmsg_type, struct nl_object *obj)
57
61
struct rtnl_neigh *neigh = (struct rtnl_neigh *)obj;
58
62
string key;
59
63
string family;
64
+ string intfName;
60
65
61
66
if ((nlmsg_type != RTM_NEWNEIGH) && (nlmsg_type != RTM_GETNEIGH) &&
62
67
(nlmsg_type != RTM_DELNEIGH))
@@ -70,12 +75,18 @@ void NeighSync::onMsg(int nlmsg_type, struct nl_object *obj)
70
75
return ;
71
76
72
77
key+= LinkCache::getInstance ().ifindexToName (rtnl_neigh_get_ifindex (neigh));
78
+ intfName = key;
73
79
key+= " :" ;
74
80
75
81
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 */
77
83
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
+ }
79
90
/* Ignore IPv6 multicast link-local addresses as neighbors */
80
91
if (family == IPV6_NAME && IN6_IS_ADDR_MC_LINKLOCAL (nl_addr_get_binary_addr (rtnl_neigh_get_dst (neigh))))
81
92
return ;
@@ -124,3 +135,52 @@ void NeighSync::onMsg(int nlmsg_type, struct nl_object *obj)
124
135
m_neighTable.set (key, fvVector);
125
136
}
126
137
}
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