Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prioritize find link info by permanent MAC address, with fallback to current address #749

Merged
Merged
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
28 changes: 20 additions & 8 deletions library/network_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,26 @@
if mac is not None:
mac = Util.mac_norm(mac)
for linkinfo in cls.link_infos(refresh).values():
if mac is not None and mac not in [
linkinfo.get("perm-address", None),
linkinfo.get("address", None),
]:
continue
if ifname is not None and ifname != linkinfo.get("ifname", None):
continue
return linkinfo
perm_address = linkinfo.get("perm-address", None)
current_address = linkinfo.get("address", None)

Check warning on line 230 in library/network_connections.py

View check run for this annotation

Codecov / codecov/patch

library/network_connections.py#L229-L230

Added lines #L229 - L230 were not covered by tests

# 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

Check warning on line 235 in library/network_connections.py

View check run for this annotation

Codecov / codecov/patch

library/network_connections.py#L233-L235

Added lines #L233 - L235 were not covered by tests

# 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

Check warning on line 240 in library/network_connections.py

View check run for this annotation

Codecov / codecov/patch

library/network_connections.py#L238-L240

Added lines #L238 - L240 were not covered by tests

if ifname is not None and ifname == linkinfo.get("ifname", None):
return linkinfo

Check warning on line 243 in library/network_connections.py

View check run for this annotation

Codecov / codecov/patch

library/network_connections.py#L242-L243

Added lines #L242 - L243 were not covered by tests

# Return fallback match by address if no perm-address match found
if "matched_by_address" in locals():
return matched_by_address

Check warning on line 247 in library/network_connections.py

View check run for this annotation

Codecov / codecov/patch

library/network_connections.py#L246-L247

Added lines #L246 - L247 were not covered by tests

return None


Expand Down
Loading