fix: Remove MAC address matching from SysUtil.link_info_find()

The link_info_find() function previously allowed searching for links by
MAC address, but this introduced ambiguity and could cause false alarms
in certain cases (e.g. retrieving the link info by MAC might return the
link info that only matches the current MAC instead of the permanent
MAC). To ensure reliable behavior, this function should accept and match
the link info only by interface name.

To address the issues, the following changes were made:
- Removed MAC address matching logic to eliminate ambiguity.
- Simplified the function to only check ifname, making it more
  predictable.
- Updated all callers to adapt to this change, ensuring correctness.
- When a profile is tied to an interface via mac only, the validation of
  the existence of interface will now be delegated to NetworkManager
instead.

Resolves: https://issues.redhat.com/browse/RHEL-84197

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
This commit is contained in:
Wen Liang 2025-03-13 18:10:47 -04:00 committed by liangwen12year
parent 6a5ca9309e
commit cac2bbb43e
8 changed files with 207 additions and 34 deletions

View file

@ -222,31 +222,15 @@ class SysUtil:
return linkinfos
@classmethod
def link_info_find(cls, refresh=False, mac=None, ifname=None):
if mac is not None:
mac = Util.mac_norm(mac)
for linkinfo in cls.link_infos(refresh).values():
perm_address = linkinfo.get("perm-address", None)
current_address = linkinfo.get("address", None)
def link_info_find(cls, ifname):
result = None
# Match by perm-address (prioritized)
if mac is not None and perm_address not in [None, "00:00:00:00:00:00"]:
if mac == perm_address:
return linkinfo
for linkinfo in cls.link_infos().values():
if ifname == linkinfo["ifname"]:
result = linkinfo
break
# Fallback to match by address
if mac is not None and (perm_address in [None, "00:00:00:00:00:00"]):
if mac == current_address:
matched_by_address = linkinfo # Save for potential fallback
if ifname is not None and ifname == linkinfo.get("ifname", None):
return linkinfo
# Return fallback match by address if no perm-address match found
if "matched_by_address" in locals():
return matched_by_address
return None
return result
###############################################################################
@ -2155,18 +2139,8 @@ class Cmd(object):
# permanent MAC address.
li_mac = None
li_ifname = None
if connection["mac"]:
li_mac = SysUtil.link_info_find(mac=connection["mac"])
if not li_mac:
self.log_fatal(
idx,
"profile specifies mac '%s' but no such interface exists"
% (connection["mac"]),
)
if connection["interface_name"]:
li_ifname = SysUtil.link_info_find(
ifname=connection["interface_name"]
)
li_ifname = SysUtil.link_info_find(connection["interface_name"])
if not li_ifname:
if connection["type"] == "ethernet":
self.log_fatal(