9
9
#include " dbconnector.h"
10
10
#include " producerstatetable.h"
11
11
#include " tokenize.h"
12
+ #include " exec.h"
12
13
13
14
#include " linkcache.h"
14
15
#include " portsyncd/linksync.h"
@@ -28,6 +29,13 @@ const string LAG_PREFIX = "PortChannel";
28
29
extern set<string> g_portSet;
29
30
extern bool g_init;
30
31
32
+ struct if_nameindex
33
+ {
34
+ unsigned int if_index;
35
+ char *if_name;
36
+ };
37
+ extern " C" { extern struct if_nameindex *if_nameindex (void ) __THROW; }
38
+
31
39
LinkSync::LinkSync (DBConnector *appl_db, DBConnector *state_db) :
32
40
m_portTableProducer(appl_db, APP_PORT_TABLE_NAME),
33
41
m_portTable(appl_db, APP_PORT_TABLE_NAME),
@@ -49,6 +57,38 @@ LinkSync::LinkSync(DBConnector *appl_db, DBConnector *state_db) :
49
57
}
50
58
}
51
59
}
60
+
61
+ struct if_nameindex *if_ni, *idx_p;
62
+ if_ni = if_nameindex ();
63
+ if (if_ni == NULL )
64
+ {
65
+ return ;
66
+ }
67
+
68
+ for (idx_p = if_ni; ! (idx_p->if_index == 0 && idx_p->if_name == NULL ); idx_p++)
69
+ {
70
+ string key = idx_p->if_name ;
71
+ if (key.compare (0 , INTFS_PREFIX.length (), INTFS_PREFIX))
72
+ {
73
+ continue ;
74
+ }
75
+
76
+ m_ifindexOldNameMap[idx_p->if_index ] = key;
77
+
78
+ /* Bring down the existing kernel interfaces */
79
+ string cmd, res;
80
+ SWSS_LOG_INFO (" Bring down old interface %s(%d)" , key.c_str (), idx_p->if_index );
81
+ cmd = " ip link set " + key + " down" ;
82
+ try
83
+ {
84
+ swss::exec (cmd, res);
85
+ }
86
+ catch (...)
87
+ {
88
+ /* Ignore error in this flow ; */
89
+ SWSS_LOG_WARN (" Failed to bring down old interface %s(%d)" , key.c_str (), idx_p->if_index );
90
+ }
91
+ }
52
92
}
53
93
54
94
void LinkSync::onMsg (int nlmsg_type, struct nl_object *obj)
@@ -99,29 +139,15 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
99
139
/* In the event of swss restart, it is possible to get netlink messages during bridge
100
140
* delete, interface delete etc which are part of cleanup. These netlink messages for
101
141
* the front-panel interface must not be published or it will update the statedb with
102
- * old interface info and result in subsequent failures. A new interface creation shall
103
- * not have master or admin status iff_up. So if the first netlink message comes with these
104
- * values set, it is considered to be happening during a cleanup process.
105
- * Fix to ignore this and any further messages for this ifindex
142
+ * old interface info and result in subsequent failures. Ingore all netlink messages
143
+ * coming from old interfaces.
106
144
*/
107
145
108
- static std::map<unsigned int , std::string> m_ifindexOldNameMap;
109
- if (m_ifindexNameMap.find (ifindex) == m_ifindexNameMap.end ())
146
+ if (m_ifindexOldNameMap.find (ifindex) != m_ifindexOldNameMap.end ())
110
147
{
111
- if (master)
112
- {
113
- m_ifindexOldNameMap[ifindex] = key;
114
- SWSS_LOG_INFO (" nlmsg type:%d Ignoring for %d, master %d" , nlmsg_type, ifindex, master);
115
- return ;
116
- }
117
- else if (m_ifindexOldNameMap.find (ifindex) != m_ifindexOldNameMap.end ())
118
- {
119
- if (m_ifindexOldNameMap[ifindex] == key)
120
- {
121
- SWSS_LOG_INFO (" nlmsg type:%d Ignoring message for old interface %d" , nlmsg_type, ifindex);
122
- return ;
123
- }
124
- }
148
+ SWSS_LOG_INFO (" nlmsg type:%d Ignoring message for old interface %s(%d)" ,
149
+ nlmsg_type, key.c_str (), ifindex);
150
+ return ;
125
151
}
126
152
127
153
/* Insert or update the ifindex to key map */
@@ -153,6 +179,7 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
153
179
vector<FieldValueTuple> vector;
154
180
vector.push_back (tuple);
155
181
m_statePortTable.set (key, vector);
182
+ SWSS_LOG_INFO (" Publish %s(ok) to state db" , key.c_str ());
156
183
}
157
184
158
185
m_portTableProducer.set (key, fvVector);
0 commit comments