@@ -196,6 +196,67 @@ static void process_info_lag_member_data_attr(
196
196
}
197
197
}
198
198
199
+ /*
200
+ * Routine Description:
201
+ * Processes the IFLA_LINKINFO attribute.
202
+ *
203
+ * Arguments:
204
+ * [in] attr - netlink attribute
205
+ * [inout] attrs - link attributes
206
+ * [out] link_type - link type
207
+ * [out] slave_link_type - slave link type
208
+ * [out] create_lag_member - flag to create LAG member
209
+ *
210
+ * Return Values:
211
+ * void
212
+ */
213
+ static void process_linkinfo_attr (const struct nlattr * attr ,
214
+ struct link_attrs * attrs ,
215
+ switchlink_link_type_t * link_type ,
216
+ switchlink_link_type_t * slave_link_type ,
217
+ bool * create_lag_member ) {
218
+ const struct nlattr * linkinfo , * infodata , * infoslavedata ;
219
+ int linkinfo_attr_type ;
220
+ int attrlen = nla_len (attr );
221
+
222
+ // IFLA_LINKINFO is a container type
223
+ nla_for_each_nested (linkinfo , attr , attrlen ) {
224
+ linkinfo_attr_type = nla_type (linkinfo );
225
+ switch (linkinfo_attr_type ) {
226
+ case IFLA_INFO_KIND :
227
+ * link_type = get_link_type (nla_get_string (linkinfo ));
228
+ break ;
229
+ case IFLA_INFO_DATA :
230
+ // IFLA_INFO_DATA is a container type
231
+ if (* link_type == SWITCHLINK_LINK_TYPE_VXLAN ) {
232
+ nla_for_each_nested (infodata , linkinfo , attrlen ) {
233
+ process_info_data_attr (infodata , attrs );
234
+ }
235
+ } else if (* link_type == SWITCHLINK_LINK_TYPE_BOND ) {
236
+ nla_for_each_nested (infodata , linkinfo , attrlen ) {
237
+ process_info_lag_data_attr (infodata , attrs );
238
+ }
239
+ }
240
+ break ;
241
+ case IFLA_INFO_SLAVE_KIND :
242
+ * slave_link_type = get_link_type (nla_get_string (linkinfo ));
243
+ break ;
244
+ case IFLA_INFO_SLAVE_DATA :
245
+ if (* slave_link_type == SWITCHLINK_LINK_TYPE_BOND ) {
246
+ #ifdef LAG_OPTION
247
+ * create_lag_member = true;
248
+ #endif
249
+ nla_for_each_nested (infoslavedata , linkinfo , attrlen ) {
250
+ process_info_lag_member_data_attr (infoslavedata , attrs );
251
+ }
252
+ }
253
+ break ;
254
+ default :
255
+ break ;
256
+ }
257
+ }
258
+ }
259
+
199
260
/*
200
261
* Routine Description:
201
262
* Processes netlink link messages.
@@ -209,11 +270,10 @@ static void process_info_lag_member_data_attr(
209
270
*/
210
271
void switchlink_process_link_msg (const struct nlmsghdr * nlmsg , int msgtype ) {
211
272
int hdrlen , attrlen ;
212
- const struct nlattr * attr , * linkinfo , * infodata , * infoslavedata ;
273
+ const struct nlattr * attr ;
213
274
const struct ifinfomsg * ifmsg ;
214
275
switchlink_link_type_t link_type = SWITCHLINK_LINK_TYPE_NONE ;
215
276
switchlink_link_type_t slave_link_type = SWITCHLINK_LINK_TYPE_NONE ;
216
- int linkinfo_attr_type ;
217
277
218
278
switchlink_db_interface_info_t intf_info = {0 };
219
279
struct link_attrs attrs = {0 };
@@ -247,42 +307,8 @@ void switchlink_process_link_msg(const struct nlmsghdr* nlmsg, int msgtype) {
247
307
krnlmon_log_debug ("IFLA Operstate: %d\n" , attrs .oper_state );
248
308
break ;
249
309
case IFLA_LINKINFO :
250
- // IFLA_LINKINFO is a container type
251
- nla_for_each_nested (linkinfo , attr , attrlen ) {
252
- linkinfo_attr_type = nla_type (linkinfo );
253
- switch (linkinfo_attr_type ) {
254
- case IFLA_INFO_KIND :
255
- link_type = get_link_type (nla_get_string (linkinfo ));
256
- break ;
257
- case IFLA_INFO_DATA :
258
- // IFLA_INFO_DATA is a container type
259
- if (link_type == SWITCHLINK_LINK_TYPE_VXLAN ) {
260
- nla_for_each_nested (infodata , linkinfo , attrlen ) {
261
- process_info_data_attr (infodata , & attrs );
262
- }
263
- } else if (link_type == SWITCHLINK_LINK_TYPE_BOND ) {
264
- nla_for_each_nested (infodata , linkinfo , attrlen ) {
265
- process_info_lag_data_attr (infodata , & attrs );
266
- }
267
- }
268
- break ;
269
- case IFLA_INFO_SLAVE_KIND :
270
- slave_link_type = get_link_type (nla_get_string (linkinfo ));
271
- break ;
272
- case IFLA_INFO_SLAVE_DATA :
273
- if (slave_link_type == SWITCHLINK_LINK_TYPE_BOND ) {
274
- #ifdef LAG_OPTION
275
- create_lag_member = true;
276
- #endif
277
- nla_for_each_nested (infoslavedata , linkinfo , attrlen ) {
278
- process_info_lag_member_data_attr (infoslavedata , & attrs );
279
- }
280
- }
281
- break ;
282
- default :
283
- break ;
284
- }
285
- }
310
+ process_linkinfo_attr (attr , & attrs , & link_type , & slave_link_type ,
311
+ & create_lag_member );
286
312
break ;
287
313
case IFLA_ADDRESS :
288
314
// IFLA_ADDRESS for kind "sit" is 4 octets
0 commit comments