Skip to content

Commit de036b2

Browse files
authored
Merge pull request #1283 from kernelkit/probe-fixes
Fix chassis MAC fallbak detection
2 parents 9386f00 + a98cb58 commit de036b2

File tree

1 file changed

+16
-34
lines changed
  • board/common/rootfs/usr/libexec/infix/init.d

1 file changed

+16
-34
lines changed

board/common/rootfs/usr/libexec/infix/init.d/00-probe

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
32
import importlib.machinery
43
import json
54
import os
@@ -359,49 +358,32 @@ def vpd_inject(out, vpds):
359358

360359

361360
def fallback_base_mac():
362-
"""Find MAC address of first suitable non-loopback interface.
363-
364-
Prefers real (globally unique) MACs over locally administered ones.
365-
Prioritizes interface types: eth* > wan > wifi* > others.
366-
"""
361+
"""Find lowest valid MAC address from all interfaces."""
367362
base_path = '/sys/class/net'
368-
interfaces = []
363+
macs = []
369364

370365
for iface in os.listdir(base_path):
371-
if iface == 'lo':
372-
continue
373366
try:
374-
# pylint: disable=invalid-name
375367
fn = os.path.join(base_path, iface, 'address')
376368
with open(fn, 'r', encoding='ascii') as f:
377369
mac = f.read().strip()
378370

379-
# Check if locally administered (bit 1 of first octet is set)
380-
first_byte = int(mac.split(':')[0], 16)
381-
is_local = bool(first_byte & 0x02)
382-
383-
# Prefer: eth* > wan > wifi* > others, then real MACs > local MACs
384-
priority = 0
385-
if iface.startswith('eth'):
386-
priority = 400
387-
elif iface == 'wan':
388-
priority = 300
389-
elif iface.startswith('wifi'):
390-
priority = 200
391-
else:
392-
priority = 100
393-
394-
# Real MACs get +100 bonus
395-
if not is_local:
396-
priority += 100
397-
398-
interfaces.append((priority, iface, mac))
399-
except FileNotFoundError:
371+
# Skip invalid/empty/unset MAC addresses
372+
if not mac or len(mac) < 17 or mac == '00:00:00:00:00:00':
373+
continue
374+
375+
# Validate MAC address format
376+
parts = mac.split(':')
377+
if len(parts) != 6:
378+
continue
379+
380+
macs.append(mac)
381+
except (FileNotFoundError, ValueError):
400382
continue
401383

402-
if interfaces:
403-
interfaces.sort(reverse=True) # Highest priority first
404-
return interfaces[0][2] # Return MAC
384+
if macs:
385+
macs.sort()
386+
return macs[0]
405387

406388
return None
407389

0 commit comments

Comments
 (0)