summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorAdam Smith <adamsmith@yzguy.io>2026-10-08 01:20:09 +0000
committerChristian Breunig <christian@breunig.cc>2026-11-07 22:19:52 +0100
commit9babe4468dec43d2df20488bacd3877d77c42b35 (patch)
tree5e2b7e9114411a9e5a17efdecbd83a68bcf087b6 /src/tests
parentd6902e6423ec78b5b99d96b6427ebee771ea6c38 (diff)
downloadvyos-1x-9babe4468dec43d2df20488bacd3877d77c42b35.tar.gz
vyos-1x-9babe4468dec43d2df20488bacd3877d77c42b35.zip
wwan: T9388: apply a static bearer's address/gateway/DNS directly
QMI raw-ip modems get their address, gateway and DNS from ModemManager as a "static" bearer instead of over a DHCP(v6) or Router Advertisement exchange, so "address dhcp", "address dhcpv6" and "ipv6 address autoconf" never produced a usable config and only worked for IPv4 by accident. Check the interface's connected bearer first. If its method for the family is static, apply it directly; if it is dhcp, or there is no bearer yet, fall through to the existing DHCP(v6) client / kernel SLAAC unchanged. - Address and DNS are applied from the bearer. DNS is registered with vyos-hostsd under the same dhcp-<if>/dhcpv6-<if> tags a real client uses. A DHCP(v6) client which was started while the bearer was still missing, including one which keeps restarting, is stopped before the settings are applied. - The default route is rendered into FRR as a tag 210 static route, the same way a DHCP one is. WWANIf records the gateway of the bearer in /run/vyos-wwan, which the new get_wwan_router() filter reads, and a new block in staticd.frr.j2 fed by get_wwan_interfaces() renders the IPv4 and IPv6 default routes. Distance, no-default-route and VRFs behave as for DHCP, also for an interface without "address dhcp". frrender notices a gateway change, and WWANIf reconciles FRR with vyos-frr-render.py whenever the recorded gateway changes, the way the dhclient lease hook does, so op-mode reconnect is covered as well. The state is written atomically, as the renderer reads it concurrently. - The address installed from the bearer is recorded in /run/vyos-wwan too. It is removed on reconnect, when the family is no longer configured and when the interface goes away, and nothing else on the interface is ever touched. - vyos-netlinkd applies the bearer again after it re-dials a lost session, as the new session can come back with a different address or gateway. A DHCP client used to pick that up on its own. What a previous session left behind is dropped for a family the new one does not supply, the configured DHCP(v6) client or SLAAC is started for it as a commit would, and an incomplete result is retried on the following reconcile passes for a while. - The bearer is picked by its connected status rather than bearers[0], and its config is polled briefly with wait_for() until it is no longer missing or a placeholder, since it can be populated slightly after the bearer reports connected.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/test_utils_wwan.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/tests/test_utils_wwan.py b/src/tests/test_utils_wwan.py
index 1114745ea..dd53bd5d0 100644
--- a/src/tests/test_utils_wwan.py
+++ b/src/tests/test_utils_wwan.py
@@ -12,8 +12,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import os
+import stat
+import tempfile
from unittest import TestCase
+from unittest.mock import patch
+from vyos.utils import wwan
from vyos.utils.wwan import connect_options
autoconf = {'address': {'autoconf': {}}}
@@ -48,3 +53,51 @@ class TestUtilsWWAN(TestCase):
connect_options(config),
'ip-type=ipv4,apn=internet,user=user,password=secret',
)
+
+
+class TestUtilsWWANBearerState(TestCase):
+ def setUp(self):
+ tmp = tempfile.TemporaryDirectory()
+ self.addCleanup(tmp.cleanup)
+ patcher = patch.object(wwan, 'bearer_state_dir', tmp.name)
+ patcher.start()
+ self.addCleanup(patcher.stop)
+
+ def test_nothing_recorded(self):
+ self.assertIsNone(wwan.get_bearer_router('wwan0', 'ipv4'))
+ self.assertIsNone(wwan.get_bearer_address('wwan0', 'ipv6'))
+
+ def test_round_trip_per_interface_and_family(self):
+ wwan.set_bearer_router('wwan0', 'ipv4', '192.0.2.1')
+ wwan.set_bearer_router('wwan0', 'ipv6', '2001:db8::1')
+ wwan.set_bearer_address('wwan0', 'ipv4', '192.0.2.2/30')
+ wwan.set_bearer_router('wwan1', 'ipv4', '198.51.100.1')
+
+ self.assertEqual(wwan.get_bearer_router('wwan0', 'ipv4'), '192.0.2.1')
+ self.assertEqual(wwan.get_bearer_router('wwan0', 'ipv6'), '2001:db8::1')
+ self.assertEqual(wwan.get_bearer_address('wwan0', 'ipv4'), '192.0.2.2/30')
+ self.assertEqual(wwan.get_bearer_router('wwan1', 'ipv4'), '198.51.100.1')
+ # the router and the address of a family are kept apart
+ self.assertIsNone(wwan.get_bearer_address('wwan0', 'ipv6'))
+
+ def test_empty_value_forgets(self):
+ wwan.set_bearer_router('wwan0', 'ipv4', '192.0.2.1')
+ wwan.set_bearer_router('wwan0', 'ipv4', None)
+ self.assertIsNone(wwan.get_bearer_router('wwan0', 'ipv4'))
+ # forgetting something that was never recorded is not an error
+ wwan.set_bearer_address('wwan0', 'ipv6', None)
+
+ def test_write_is_atomic(self):
+ wwan.set_bearer_router('wwan0', 'ipv4', '192.0.2.1')
+ # a failure while replacing leaves the old value in place and no
+ # temporary file behind
+ with patch.object(wwan.os, 'replace', side_effect=OSError):
+ with self.assertRaises(OSError):
+ wwan.set_bearer_router('wwan0', 'ipv4', '198.51.100.1')
+ self.assertEqual(wwan.get_bearer_router('wwan0', 'ipv4'), '192.0.2.1')
+ self.assertEqual(os.listdir(wwan.bearer_state_dir), ['wwan0.ipv4-router'])
+
+ def test_state_file_is_readable_by_others(self):
+ wwan.set_bearer_address('wwan0', 'ipv4', '192.0.2.2/30')
+ path = os.path.join(wwan.bearer_state_dir, 'wwan0.ipv4-address')
+ self.assertEqual(stat.S_IMODE(os.stat(path).st_mode), 0o644)