Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract IFLA_LINKINFO processing to a function #168

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 64 additions & 38 deletions switchlink/switchlink_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,67 @@ static void process_info_lag_member_data_attr(
}
}

/*
* Routine Description:
* Processes the IFLA_LINKINFO attribute.
*
* Arguments:
* [in] attr - netlink attribute
* [inout] attrs - link attributes
* [out] link_type - link type
* [out] slave_link_type - slave link type
* [out] create_lag_member - flag to create LAG member
*
* Return Values:
* void
*/
static void process_linkinfo_attr(const struct nlattr* attr,
struct link_attrs* attrs,
switchlink_link_type_t* link_type,
switchlink_link_type_t* slave_link_type,
bool* create_lag_member) {
const struct nlattr *linkinfo, *infodata, *infoslavedata;
int linkinfo_attr_type;
int attrlen = nla_len(attr);

// IFLA_LINKINFO is a container type
nla_for_each_nested(linkinfo, attr, attrlen) {
linkinfo_attr_type = nla_type(linkinfo);
switch (linkinfo_attr_type) {
case IFLA_INFO_KIND:
*link_type = get_link_type(nla_get_string(linkinfo));
break;
case IFLA_INFO_DATA:
// IFLA_INFO_DATA is a container type
if (*link_type == SWITCHLINK_LINK_TYPE_VXLAN) {
nla_for_each_nested(infodata, linkinfo, attrlen) {
process_info_data_attr(infodata, attrs);
}
} else if (*link_type == SWITCHLINK_LINK_TYPE_BOND) {
nla_for_each_nested(infodata, linkinfo, attrlen) {
process_info_lag_data_attr(infodata, attrs);
}
}
break;
case IFLA_INFO_SLAVE_KIND:
*slave_link_type = get_link_type(nla_get_string(linkinfo));
break;
case IFLA_INFO_SLAVE_DATA:
if (*slave_link_type == SWITCHLINK_LINK_TYPE_BOND) {
#ifdef LAG_OPTION
*create_lag_member = true;
#endif
nla_for_each_nested(infoslavedata, linkinfo, attrlen) {
process_info_lag_member_data_attr(infoslavedata, attrs);
}
}
break;
default:
break;
}
}
}

/*
* Routine Description:
* Processes netlink link messages.
Expand All @@ -209,11 +270,10 @@ static void process_info_lag_member_data_attr(
*/
void switchlink_process_link_msg(const struct nlmsghdr* nlmsg, int msgtype) {
int hdrlen, attrlen;
const struct nlattr *attr, *linkinfo, *infodata, *infoslavedata;
const struct nlattr* attr;
const struct ifinfomsg* ifmsg;
switchlink_link_type_t link_type = SWITCHLINK_LINK_TYPE_NONE;
switchlink_link_type_t slave_link_type = SWITCHLINK_LINK_TYPE_NONE;
int linkinfo_attr_type;

switchlink_db_interface_info_t intf_info = {0};
struct link_attrs attrs = {0};
Expand Down Expand Up @@ -247,42 +307,8 @@ void switchlink_process_link_msg(const struct nlmsghdr* nlmsg, int msgtype) {
krnlmon_log_debug("IFLA Operstate: %d\n", attrs.oper_state);
break;
case IFLA_LINKINFO:
// IFLA_LINKINFO is a container type
nla_for_each_nested(linkinfo, attr, attrlen) {
linkinfo_attr_type = nla_type(linkinfo);
switch (linkinfo_attr_type) {
case IFLA_INFO_KIND:
link_type = get_link_type(nla_get_string(linkinfo));
break;
case IFLA_INFO_DATA:
// IFLA_INFO_DATA is a container type
if (link_type == SWITCHLINK_LINK_TYPE_VXLAN) {
nla_for_each_nested(infodata, linkinfo, attrlen) {
process_info_data_attr(infodata, &attrs);
}
} else if (link_type == SWITCHLINK_LINK_TYPE_BOND) {
nla_for_each_nested(infodata, linkinfo, attrlen) {
process_info_lag_data_attr(infodata, &attrs);
}
}
break;
case IFLA_INFO_SLAVE_KIND:
slave_link_type = get_link_type(nla_get_string(linkinfo));
break;
case IFLA_INFO_SLAVE_DATA:
if (slave_link_type == SWITCHLINK_LINK_TYPE_BOND) {
#ifdef LAG_OPTION
create_lag_member = true;
#endif
nla_for_each_nested(infoslavedata, linkinfo, attrlen) {
process_info_lag_member_data_attr(infoslavedata, &attrs);
}
}
break;
default:
break;
}
}
process_linkinfo_attr(attr, &attrs, &link_type, &slave_link_type,
&create_lag_member);
break;
case IFLA_ADDRESS:
// IFLA_ADDRESS for kind "sit" is 4 octets
Expand Down