Skip to content

Commit 05d5f82

Browse files
committed
ctlplane: handle interface renaming
When a grout interface is renamed, rename its control plane counterpart. Signed-off-by: Robin Jarry <rjarry@redhat.com> Reviewed-by: Christophe Fontaine <cfontain@redhat.com>
1 parent 08ebd15 commit 05d5f82

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

modules/infra/control/ctlplane.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,18 @@ static void cp_set_speed(struct iface *iface) {
383383
}
384384

385385
static void cp_update(struct iface *iface) {
386+
char current_name[IFNAMSIZ];
386387
struct rte_ether_addr mac;
387388
struct ifreq ifr = {0};
388389
int ioctl_sock;
389390

391+
if (iface->cp_id > 0) {
392+
if (if_indextoname(iface->cp_id, current_name) != NULL
393+
&& strcmp(current_name, iface->name) != 0) {
394+
netlink_link_set_name(iface->cp_id, iface->name);
395+
}
396+
}
397+
390398
if ((ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
391399
LOG(ERR, "socket(SOCK_DGRAM): %s", strerror(errno));
392400
goto err;

modules/infra/control/gr_netlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
int netlink_link_set_admin_state(const char *ifname, bool up);
1111
int netlink_link_set_master(const char *ifname, const char *master_ifname);
12+
int netlink_link_set_name(uint32_t ifindex, const char *ifname);
1213
int netlink_link_add_vrf(const char *vrf_name, uint32_t table_id);
1314
int netlink_link_del_iface(const char *ifname);
1415
int netlink_add_route(const char *ifname, uint32_t table);

modules/infra/control/netlink.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,25 @@ int netlink_set_ifalias(const char *ifname, const char *ifalias) {
328328
return netlink_send_req(nlh);
329329
}
330330

331+
int netlink_link_set_name(uint32_t ifindex, const char *ifname) {
332+
char buf[NLMSG_SPACE(sizeof(struct ifinfomsg) + NLA_SPACE(IFNAMSIZ))];
333+
struct ifinfomsg *ifm;
334+
struct nlmsghdr *nlh;
335+
336+
memset(buf, 0, sizeof(buf));
337+
nlh = mnl_nlmsg_put_header(buf);
338+
nlh->nlmsg_type = RTM_SETLINK;
339+
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
340+
341+
ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(*ifm));
342+
ifm->ifi_family = AF_UNSPEC;
343+
ifm->ifi_index = ifindex;
344+
345+
mnl_attr_put_strz(nlh, IFLA_IFNAME, ifname);
346+
347+
return netlink_send_req(nlh);
348+
}
349+
331350
static void netlink_init(struct event_base *) {
332351
nl_sock = mnl_socket_open(NETLINK_ROUTE);
333352
if (!nl_sock)

0 commit comments

Comments
 (0)