From: Guillaume Boutry <[email protected]>
Renaming a watched link to an unwatched name leaves its old name
mapped to the same ifindex.
Remove mappings for the reported ifindex before checking the new
name. Extend the monitor test to rename the link away and back.
Fixes: 2257c01f579d ("controller: Add host-if-monitor to track (Linux)
interface indices.")
Assisted-by: GPT-6.2 Sol, Codex
Signed-off-by: Guillaume Boutry <[email protected]>
---
controller/host-if-monitor.c | 13 +++++++++++++
tests/system-ovn-netlink.at | 15 +++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/controller/host-if-monitor.c b/controller/host-if-monitor.c
index 65110d2a3..7ddf6e455 100644
--- a/controller/host-if-monitor.c
+++ b/controller/host-if-monitor.c
@@ -137,6 +137,19 @@ if_notifier_cb(const struct rtnetlink_change *change, void
*aux OVS_UNUSED)
return;
}
+ /* A rename reports the new name, which might not be watched. Remove
+ * mappings for the same index before considering the current name. */
+ if (change->nlmsg_type == RTM_NEWLINK) {
+ struct simap_node *node;
+ SIMAP_FOR_EACH_SAFE (node, &monitor.ifname_to_ifindex) {
+ if (node->data == change->if_index
+ && strcmp(node->name, change->ifname)) {
+ simap_delete(&monitor.ifname_to_ifindex, node);
+ monitor.changes_detected = true;
+ }
+ }
+ }
+
switch (change->nlmsg_type) {
case RTM_NEWLINK:
if ((change->ifi_flags & IFF_UP)
diff --git a/tests/system-ovn-netlink.at b/tests/system-ovn-netlink.at
index d47982b6e..3dcf20649 100644
--- a/tests/system-ovn-netlink.at
+++ b/tests/system-ovn-netlink.at
@@ -367,6 +367,21 @@ AT_CHECK_UNQUOTED([netlink_if_index lo-test], [0], [dnl
$if_index
])
+dnl A rename to an unwatched name must invalidate the old mapping.
+on_exit 'if ip link show lo-renamed >/dev/null 2>&1; then ip link del
lo-renamed; fi'
+AT_CHECK([ovstest test-ovn-netlink host-if-monitor lo-test \
+ 'ip link set lo-test down && ip link set lo-test name lo-renamed' \
+ true], [0], [dnl
+0
+])
+
+dnl Renaming an interface into the watched name must learn its index.
+AT_CHECK_UNQUOTED([ovstest test-ovn-netlink host-if-monitor lo-test \
+ 'ip link set lo-renamed name lo-test && ip link set lo-test up' \
+ true], [0], [dnl
+$if_index
+])
+
dnl Should NOT notify if an interface whose name is not monitored by OVN
dnl is added.
check ip link del lo-test
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev