feat(network): prioritize USB > Wi-Fi > 4G cellular routing

This commit is contained in:
shenlei
2026-11-18 10:09:18 +09:00
parent c1c3346f69
commit c9f216dec9
10 changed files with 84 additions and 21 deletions
+3 -1
View File
@@ -262,6 +262,7 @@ def build_nmcli_setup_commands(con_name=CONNECTION_NAME, apn='cmnet', ifname='*'
'gsm.auto-config', 'yes',
'connection.autoconnect', 'no',
'ipv4.route-metric', '700',
'ipv6.route-metric', '700',
'connection.interface-name', ifname if ifname != '*' else ''])
else:
cmd = ['nmcli', 'connection', 'add',
@@ -271,7 +272,8 @@ def build_nmcli_setup_commands(con_name=CONNECTION_NAME, apn='cmnet', ifname='*'
'apn', apn,
'gsm.auto-config', 'yes',
'connection.autoconnect', 'no',
'ipv4.route-metric', '700']
'ipv4.route-metric', '700',
'ipv6.route-metric', '700']
commands.append(cmd)
return commands
+19 -5
View File
@@ -234,9 +234,23 @@ def collect_telemetry(sys_path='/sys', proc_path='/proc', run=subprocess.run):
r_def = run(['ip', '-4', 'route', 'show', 'default'],
capture_output=True, text=True, timeout=0.8)
if r_def.returncode == 0 and r_def.stdout.strip():
parts = r_def.stdout.splitlines()[0].split()
if 'dev' in parts:
default_dev = parts[parts.index('dev') + 1]
best_metric = None
for line in r_def.stdout.splitlines():
parts = line.split()
if 'dev' not in parts:
continue
dev = parts[parts.index('dev') + 1]
metric = 0
if 'metric' in parts:
m_idx = parts.index('metric')
if m_idx + 1 < len(parts):
try:
metric = int(parts[m_idx + 1])
except ValueError:
metric = 0
if best_metric is None or metric < best_metric:
best_metric = metric
default_dev = dev
except (OSError, subprocess.SubprocessError):
pass
@@ -470,8 +484,8 @@ def render_dashboard_bgrx(telemetry, mode='status', width=1080, height=2280):
net = telemetry['network']
card(1100, 380, 'NETWORK & MESH ROUTING')
draw_text(buf, width, height, 92, 1175, f"DEFAULT : {net.get('default_dev') or 'none'}", scale=4, fg_px=COL_TEXT, bg_px=COL_CARD)
draw_text(buf, width, height, 92, 1245, f"WI-FI : {net.get('wlan0_ip') or 'disconnected'} (m 600)", scale=3, fg_px=COL_MUTED, bg_px=COL_CARD)
draw_text(buf, width, height, 92, 1295, f"USB NCM : {net.get('usb0_ip') or 'down'} ({'link' if net.get('usb0_carrier') else 'unplugged'})", scale=3, fg_px=COL_MUTED, bg_px=COL_CARD)
draw_text(buf, width, height, 92, 1245, f"USB NCM : {net.get('usb0_ip') or 'down'} ({'m 50' if net.get('usb0_carrier') else 'unplugged'})", scale=3, fg_px=COL_GREEN if net.get('default_dev') == 'usb0' else COL_MUTED, bg_px=COL_CARD)
draw_text(buf, width, height, 92, 1295, f"WI-FI : {net.get('wlan0_ip') or 'disconnected'} (m 200)", scale=3, fg_px=COL_GREEN if net.get('default_dev') == 'wlan0' else COL_MUTED, bg_px=COL_CARD)
draw_text(buf, width, height, 92, 1345, f"EASYTIER: {net.get('tun0_ip') or 'stopped'}", scale=3, fg_px=COL_GREEN if net.get('tun0_ip') else COL_MUTED, bg_px=COL_CARD)
# Card 4: Compute