From b41dd2dcd54752c1deadcd57c5591c5ed88c9c88 Mon Sep 17 00:00:00 2001 From: den-kloot <1522975+den-kloot@users.noreply.github.com> Date: Sat, 14 Nov 2026 11:19:28 +0100 Subject: [PATCH] omamobile-modem-sit 0.3.42: a default route on a down link no longer keeps the cellular route away After a silent spell (the network dropped packet registration for four minutes) omamobile-sit-data removed the cellular default route as intended, but never put it back once the bearer carried traffic again: it only re-adds the route when nothing else leads out, and the USB gadget's fallback route (20-usb-gadget.network, ConfigureWithoutCarrier=yes, metric 2048) is always there, flagged linkdown without a cable. On a Pixel 9a with Wi-Fi off the phone stayed offline until a reboot. Routes on a down link now count as no other exit. The other device packages carry the same fallback route, so this changes two more things on every phone with the cable out, both decided from the same list: - The carrier's DNS. "cellular = routed and not others" was never true on mobile data without a cable and without Wi-Fi, because the USB route counted as another way out, so the carrier's DNS was never used there. Now it is, which is what the resolver was written for. - The return after a sleep (SleepHold, #791). With the USB route counted, the cellular route came back at once after every sleep, logged as "behind Wi-Fi" even with Wi-Fi off. Now it waits for a route that leads out, or the 10 s grace, as intended. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Claude Fable 5.2 --- .../omamobile-modem-sit/lib/data_network.py | 11 +++++++++- .../test/test_data_network.py | 21 ++++++++++++++++++- packages/omamobile-modem-sit/version | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/packages/omamobile-modem-sit/lib/data_network.py b/packages/omamobile-modem-sit/lib/data_network.py index 55c49c56d..39c8d0a16 100644 --- a/packages/omamobile-modem-sit/lib/data_network.py +++ b/packages/omamobile-modem-sit/lib/data_network.py @@ -76,6 +76,15 @@ def counters(stats): return link['rx']['bytes'], link['tx']['packets'] +def other_exits(routes, dev): + """The default routes that lead out other than through the bearer. One + whose link is down leads nowhere: the USB gadget's fallback route stays + configured without a cable, and counting it kept the cellular route from + coming back after a silent spell.""" + return [r for r in routes + if r.get('dev') != dev and 'linkdown' not in r.get('flags', ())] + + def looks_silent(routed, before, after): """The routed bearer sent packets but received nothing since the last check. Not proof: a few router solicitations get no answer on a live one.""" @@ -423,7 +432,7 @@ def watch(): nonlocal last, seen, check_at routes = json.loads(run('ip', '-j', 'route', 'show', 'default')) routed = any(r.get('dev') == dev for r in routes) - others = [r for r in routes if r.get('dev') != dev] + others = other_exits(routes, dev) if roaming_blocked(): if routed: run('ip', 'route', 'del', 'default', 'dev', dev, 'metric', '700') diff --git a/packages/omamobile-modem-sit/test/test_data_network.py b/packages/omamobile-modem-sit/test/test_data_network.py index 0c9895afc..696f035e8 100644 --- a/packages/omamobile-modem-sit/test/test_data_network.py +++ b/packages/omamobile-modem-sit/test/test_data_network.py @@ -6,7 +6,7 @@ import unittest from unittest.mock import patch import data_network -from data_network import Resolver, SleepHold, configuration, counters, guarded, looks_silent, sleep_signal +from data_network import Resolver, SleepHold, configuration, counters, guarded, looks_silent, other_exits, sleep_signal class ResolverTests(unittest.TestCase): def test_fallback_restoration_preserves_new_wifi_dns(self): @@ -76,6 +76,18 @@ def test_roaming_ends_the_wait(self): hold.cancel() self.assertFalse(hold.returns(others=True, now=301)) + def test_after_a_sleep_a_route_on_a_down_link_does_not_end_the_wait(self): + usb={'dst':'default','gateway':'172.16.42.2','dev':'usb0','metric':2048,'flags':['linkdown']} + wifi={'dst':'default','gateway':'192.168.178.1','dev':'wlp1s0','metric':600,'flags':[]} + hold = SleepHold(grace=10) + hold.announced(routed=True) + hold.over(now=100) + self.assertFalse(hold.returns(bool(other_exits([usb],'rmnet0')), now=101)) # the cable is out: wait the grace + self.assertTrue(hold.returns(bool(other_exits([usb,wifi],'rmnet0')), now=102)) # Wi-Fi is back + hold.announced(routed=True) + hold.over(now=200) + self.assertTrue(hold.returns(bool(other_exits([usb],'rmnet0')), now=210)) # no Wi-Fi: after the grace + def test_counters_read_ip_json(self): stats=[{'stats64':{'rx':{'bytes':0,'packets':0},'tx':{'bytes':900,'packets':12}}}] self.assertEqual(counters(stats),(0,12)) @@ -85,6 +97,13 @@ def test_receiving_idle_or_unrouted_is_not_silent(self): self.assertFalse(looks_silent(True,(100,10),(900,40))) self.assertFalse(looks_silent(True,(0,10),(0,10))) self.assertFalse(looks_silent(False,(0,10),(0,40))) + def test_a_route_on_a_down_link_is_no_other_exit(self): + usb={'dst':'default','gateway':'172.16.42.2','dev':'usb0','metric':2048,'flags':['linkdown']} + self.assertEqual(other_exits([usb],'rmnet0'),[]) + wifi={'dst':'default','gateway':'192.168.178.1','dev':'wlp1s0','metric':600,'flags':[]} + cell={'dst':'default','dev':'rmnet0','metric':700,'flags':[]} + self.assertEqual(other_exits([usb,wifi,cell],'rmnet0'),[wifi]) + self.assertEqual(other_exits([{'dst':'default','dev':'tun-home'}],'rmnet0'),[{'dst':'default','dev':'tun-home'}]) class WatchTests(unittest.TestCase): def test_a_stalled_or_failed_ip_is_retried(self): diff --git a/packages/omamobile-modem-sit/version b/packages/omamobile-modem-sit/version index b463c010a..0bdfd66f8 100644 --- a/packages/omamobile-modem-sit/version +++ b/packages/omamobile-modem-sit/version @@ -1 +1 @@ -0.3.41 +0.3.42