iproute2: ip-monitor: Properly track interface names
ip-monitor does not currently update interface names for tracked ids,
even if they change on the system. This causes route messages to print
with the wrong interface name, making them indistinguishable from each
other on dynamic interfaces that all start as `eth0` on the system.
We need this to support USB connectivity on SmartNICs that use a USB
NCSI path.
Tested: Booted a machine with USB interfaces that rename to verify that the names are properly tracked now. Old images have a 100% reproduction rate of this issue.
Fusion-Link: https://fusion2.corp.google.com/7d1a7a23-0878-3d5c-a126-82ef2bd7ce8e (platform11)
Fusion-Link: https://fusion2.corp.google.com/fcdb0235-156e-3088-8f26-c02891f10d59 (platform11-emr)
Fusion-Link: https://fusion2.corp.google.com/01dec9b3-ebb3-3316-ad1a-d7da08a96494 (platform15)
Fusion-Link: https://fusion2.corp.google.com/d0617ef2-6d9f-3446-b173-7027a63cef6a (platform17)
Fusion-Link: https://fusion2.corp.google.com/f1cd0acd-bb90-3654-a3cb-c1a9e3b24c28 (platform5)
Google-Bug-Id: 428743767
Change-Id: If6b0864dfc2bf0107e34ddaa541ad34f16ab8abc
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/recipes-connectivity/iproute2/files/0001-lib-ll_map-Update-name-when-changed.patch b/recipes-connectivity/iproute2/files/0001-lib-ll_map-Update-name-when-changed.patch
new file mode 100644
index 0000000..56673ea
--- /dev/null
+++ b/recipes-connectivity/iproute2/files/0001-lib-ll_map-Update-name-when-changed.patch
@@ -0,0 +1,80 @@
+From d46e4d052195e61e2641a9639b968945105c85d4 Mon Sep 17 00:00:00 2001
+From: "William A. Kennington III" <william@wkennington.com>
+Date: Thu, 31 Jul 2025 14:55:45 -0700
+Subject: [PATCH 1/2] lib/ll_map: Update name when changed
+
+On systems with a predictable naming scheme, our interfaces always first
+come up with the incremental kernel name prior to being renamed. If we
+have multiple links that come up at different times, they will usually
+use overlapping names when first seen. The predictable name is then set
+shorlty after. When using ip-monitor, all routes will then end up
+printing with this same first name (usually best seen with eth0). In
+these instances the routes cannot have their interfaces distinguished,
+as they are printed with a stale name.
+
+Consider the following example while running `ip-monitor`
+```
+$ sudo ip link add dummy1 type dummy
+$ sudo ip link set dummy1 name dummy2
+$ sudo ip link set dummy2 addr 00:00:00:00:00:02
+$ sudo ip link add dummy1 type dummy
+$ sudo ip link set dummy1 addr 00:00:00:00:00:01
+$ sudo ip link set dummy2 up
+$ sudo ip link set dummy1 up
+```
+We currently see the following, notice the address and route lines
+```
+20: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
+ link/ether 82:49:17:d4:21:88 brd ff:ff:ff:ff:ff:ff
+20: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
+ link/ether 86:61:a6:69:1d:7b brd ff:ff:ff:ff:ff:ff
+20: dummy2: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
+ link/ether 86:61:a6:69:1d:7b brd ff:ff:ff:ff:ff:ff
+20: dummy2: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
+ link/ether 00:00:00:00:00:02 brd ff:ff:ff:ff:ff:ff
+21: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
+ link/ether d6:f6:da:e5:d7:7c brd ff:ff:ff:ff:ff:ff
+21: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
+ link/ether 86:61:a6:69:1d:7b brd ff:ff:ff:ff:ff:ff
+21: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
+ link/ether 00:00:00:00:00:01 brd ff:ff:ff:ff:ff:ff
+20: dummy2: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
+ link/ether 00:00:00:00:00:02 brd ff:ff:ff:ff:ff:ff
+multicast ff00::/8 dev dummy1 table local proto kernel metric 256 pref medium
+fe80::/64 dev dummy1 proto kernel metric 256 pref medium
+20: dummy1 inet6 fe80::200:ff:fe00:2/64 scope link proto kernel_ll
+ valid_lft forever preferred_lft forever
+local fe80::200:ff:fe00:2 dev dummy1 table local proto kernel metric 0 pref medium
+21: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
+ link/ether 00:00:00:00:00:01 brd ff:ff:ff:ff:ff:ff
+multicast ff00::/8 dev dummy1 table local proto kernel metric 256 pref medium
+fe80::/64 dev dummy1 proto kernel metric 256 pref medium
+21: dummy1 inet6 fe80::200:ff:fe00:1/64 scope link proto kernel_ll
+ valid_lft forever preferred_lft forever
+local fe80::200:ff:fe00:1 dev dummy1 table local proto kernel metric 0 pref medium
+```
+
+Upstream-Status: Pending
+Signed-off-by: William A. Kennington III <william@wkennington.com>
+---
+ lib/ll_map.c | 3 +--
+ 1 file changed, 1 insertion(+), 2 deletions(-)
+
+diff --git a/lib/ll_map.c b/lib/ll_map.c
+index 8970c20f..431946f5 100644
+--- a/lib/ll_map.c
++++ b/lib/ll_map.c
+@@ -118,9 +118,8 @@ static void ll_entry_update(struct ll_cache *im, struct ifinfomsg *ifi,
+ {
+ unsigned int h;
+
++ strcpy(im->name, ifname);
+ im->flags = ifi->ifi_flags;
+- if (!strcmp(im->name, ifname))
+- return;
+ hlist_del(&im->name_hash);
+ h = namehash(ifname) & (IDXMAP_SIZE - 1);
+ hlist_add_head(&im->name_hash, &name_head[h]);
+--
+2.50.1.565.gc32cd1483b-goog
+
diff --git a/recipes-connectivity/iproute2/files/0002-ip-monitor-Always-monitor-links.patch b/recipes-connectivity/iproute2/files/0002-ip-monitor-Always-monitor-links.patch
new file mode 100644
index 0000000..5bd82b8
--- /dev/null
+++ b/recipes-connectivity/iproute2/files/0002-ip-monitor-Always-monitor-links.patch
@@ -0,0 +1,54 @@
+From 0b1b8103a015d3e30e85eb0183797caa2c2e1e85 Mon Sep 17 00:00:00 2001
+From: "William A. Kennington III" <william@wkennington.com>
+Date: Thu, 31 Jul 2025 14:55:52 -0700
+Subject: [PATCH 2/2] ip-monitor: Always monitor links
+
+We need to watch link changes even if we don't actively print them.
+Otherwise, route changes will not print the correct link name.
+
+Upstream-Status: Pending
+Signed-off-by: William A. Kennington III <william@wkennington.com>
+---
+ ip/ipmonitor.c | 11 ++++++++---
+ 1 file changed, 8 insertions(+), 3 deletions(-)
+
+diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c
+index 9b055264..556e4856 100644
+--- a/ip/ipmonitor.c
++++ b/ip/ipmonitor.c
+@@ -22,6 +22,7 @@
+ static void usage(void) __attribute__((noreturn));
+ static int prefix_banner;
+ int listen_all_nsid;
++int print_link;
+
+ static void usage(void)
+ {
+@@ -96,8 +97,10 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,
+ case RTM_NEWLINK:
+ case RTM_DELLINK:
+ ll_remember_index(n, NULL);
+- print_headers(fp, "[LINK]", ctrl);
+- print_linkinfo(n, arg);
++ if (print_link) {
++ print_headers(fp, "[LINK]", ctrl);
++ print_linkinfo(n, arg);
++ }
+ return 0;
+
+ case RTM_NEWADDR:
+@@ -254,8 +257,10 @@ int do_ipmonitor(int argc, char **argv)
+ if (!lmask)
+ lmask = IPMON_L_ALL;
+
++ /* Always monitor links for renaming */
++ groups |= nl_mgrp(RTNLGRP_LINK);
+ if (lmask & IPMON_LLINK)
+- groups |= nl_mgrp(RTNLGRP_LINK);
++ print_link = true;
+ if (lmask & IPMON_LADDR) {
+ if (!preferred_family || preferred_family == AF_INET)
+ groups |= nl_mgrp(RTNLGRP_IPV4_IFADDR);
+--
+2.50.1.565.gc32cd1483b-goog
+
diff --git a/recipes-connectivity/iproute2/iproute2_%.bbappend b/recipes-connectivity/iproute2/iproute2_%.bbappend
new file mode 100644
index 0000000..524fecd
--- /dev/null
+++ b/recipes-connectivity/iproute2/iproute2_%.bbappend
@@ -0,0 +1,5 @@
+FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
+SRC_URI:append = " \
+ file://0001-lib-ll_map-Update-name-when-changed.patch \
+ file://0002-ip-monitor-Always-monitor-links.patch \
+ "