Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions modules/infra/control/ctlplane.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,18 @@ static void cp_set_speed(struct iface *iface) {
}

static void cp_update(struct iface *iface) {
char current_name[IFNAMSIZ];
struct rte_ether_addr mac;
struct ifreq ifr = {0};
int ioctl_sock;

if (iface->cp_id > 0) {
if (if_indextoname(iface->cp_id, current_name) != NULL
&& strcmp(current_name, iface->name) != 0) {
netlink_link_set_name(iface->cp_id, iface->name);
}
Comment on lines +391 to +395
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Handle rename failure.

The return value from netlink_link_set_name is not checked. If the rename fails, the code continues silently, potentially causing a mismatch between iface->name and the actual kernel interface name. This could lead to subsequent ioctl operations failing or operating on the wrong interface.

Apply this diff to add error handling:

 	if (iface->cp_id > 0) {
 		if (if_indextoname(iface->cp_id, current_name) != NULL
 		    && strcmp(current_name, iface->name) != 0) {
-			netlink_link_set_name(iface->cp_id, iface->name);
+			if (netlink_link_set_name(iface->cp_id, iface->name) < 0) {
+				LOG(ERR, "netlink_link_set_name(%u, %s): %s",
+				    iface->cp_id, iface->name, strerror(errno));
+			}
 		}
 	}
🤖 Prompt for AI Agents
In modules/infra/control/ctlplane.c around lines 391-395, the call to
netlink_link_set_name lacks error handling; check its return value and if it
indicates failure, log the error (include errno/strerror(errno) or the
function's error string) and prevent further operations on the wrong interface —
for example, clear iface->cp_id or return an error from the enclosing function
so subsequent ioctl calls are not made against a mismatched kernel name. Ensure
the log message includes iface->cp_id and iface->name for context.

}

if ((ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
LOG(ERR, "socket(SOCK_DGRAM): %s", strerror(errno));
goto err;
Expand Down
1 change: 1 addition & 0 deletions modules/infra/control/gr_netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

int netlink_link_set_admin_state(const char *ifname, bool up);
int netlink_link_set_master(const char *ifname, const char *master_ifname);
int netlink_link_set_name(uint32_t ifindex, const char *ifname);
int netlink_link_add_vrf(const char *vrf_name, uint32_t table_id);
int netlink_link_del_iface(const char *ifname);
int netlink_add_route(const char *ifname, uint32_t table);
Expand Down
19 changes: 19 additions & 0 deletions modules/infra/control/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,25 @@ int netlink_set_ifalias(const char *ifname, const char *ifalias) {
return netlink_send_req(nlh);
}

int netlink_link_set_name(uint32_t ifindex, const char *ifname) {
char buf[NLMSG_SPACE(sizeof(struct ifinfomsg) + NLA_SPACE(IFNAMSIZ))];
struct ifinfomsg *ifm;
struct nlmsghdr *nlh;

memset(buf, 0, sizeof(buf));
nlh = mnl_nlmsg_put_header(buf);
nlh->nlmsg_type = RTM_SETLINK;
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;

ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(*ifm));
ifm->ifi_family = AF_UNSPEC;
ifm->ifi_index = ifindex;

mnl_attr_put_strz(nlh, IFLA_IFNAME, ifname);

return netlink_send_req(nlh);
}

static void netlink_init(struct event_base *) {
nl_sock = mnl_socket_open(NETLINK_ROUTE);
if (!nl_sock)
Expand Down