feat: add Docker MTU apply support and docker-ordered persistence

https://chatgpt.com/share/69733e45-96ec-800f-9aad-0cac7306dedd
This commit is contained in:
2026-01-23 10:53:29 +01:00
parent f534d025d0
commit fc5dee4dc0
11 changed files with 432 additions and 101 deletions

View File

@@ -22,10 +22,18 @@ class TestCore(unittest.TestCase):
pmtu_policy="min",
apply_egress_mtu=True,
apply_wg_mtu=True,
apply_docker_mtu=False,
apply_all=False,
docker_if=None,
docker_no_user_bridges=False,
wg_if="wg0",
wg_overhead=80,
wg_min=1280,
set_wg_mtu=None,
persist=None,
uninstall=False,
print_mtu=None,
print_json=False,
)
# PMTU probes: 1452 and 1500 -> min policy => 1452, effective=min(base(1500),1452)=1452
@@ -40,6 +48,7 @@ class TestCore(unittest.TestCase):
patch("automtu.core.wg_is_active", return_value=False),
patch("automtu.core.wg_peer_endpoints", return_value=[]),
patch("automtu.core.default_route_uses_iface", return_value=False),
patch("automtu.core.detect_docker_ifaces", return_value=[]),
):
buf = io.StringIO()
with redirect_stdout(buf):
@@ -52,10 +61,66 @@ class TestCore(unittest.TestCase):
self.assertIn("Selected Path MTU (policy=min): 1452", s)
self.assertIn("Computed wg0 MTU: 1372", s)
# apply egress and wg are both true -> two calls in order
mock_set.assert_any_call("eth0", 1452, True)
mock_set.assert_any_call("wg0", 1372, True)
def test_run_automtu_apply_all_includes_docker_bridge(self) -> None:
args = SimpleNamespace(
dry_run=True,
egress_if="eth0",
prefer_wg_egress=False,
force_egress_mtu=None,
pmtu_target=None,
auto_pmtu_from_wg=False,
pmtu_min_payload=1200,
pmtu_max_payload=1472,
pmtu_timeout=1.0,
pmtu_policy="min",
apply_egress_mtu=False,
apply_wg_mtu=False,
apply_docker_mtu=False,
apply_all=True, # expands in core()
docker_if=None,
docker_no_user_bridges=False,
wg_if="wg0",
wg_overhead=80,
wg_min=1280,
set_wg_mtu=None,
persist=None,
uninstall=False,
print_mtu=None,
print_json=False,
)
with (
patch("automtu.core.require_root", return_value=None),
patch(
"automtu.core.iface_exists",
side_effect=lambda name: name in {"eth0", "wg0", "docker0", "br-abc"},
),
patch("automtu.core.read_iface_mtu", return_value=1500),
patch("automtu.core.set_iface_mtu") as mock_set,
patch("automtu.core.wg_is_active", return_value=True),
patch(
"automtu.core.detect_docker_ifaces", return_value=["docker0", "br-abc"]
),
):
buf = io.StringIO()
with redirect_stdout(buf):
rc = run_automtu(args)
self.assertEqual(rc, 0)
# egress applied
mock_set.assert_any_call("eth0", 1500, True)
# wg applied (1500-80=1420)
mock_set.assert_any_call("wg0", 1420, True)
# docker applied
mock_set.assert_any_call("docker0", 1500, True)
mock_set.assert_any_call("br-abc", 1500, True)
def test_run_automtu_does_not_apply_wg_without_flag(self) -> None:
args = SimpleNamespace(
dry_run=True,
@@ -70,10 +135,18 @@ class TestCore(unittest.TestCase):
pmtu_policy="min",
apply_egress_mtu=False,
apply_wg_mtu=False,
apply_docker_mtu=False,
apply_all=False,
docker_if=None,
docker_no_user_bridges=False,
wg_if="wg0",
wg_overhead=80,
wg_min=1280,
set_wg_mtu=None,
persist=None,
uninstall=False,
print_mtu=None,
print_json=False,
)
with (
@@ -81,6 +154,7 @@ class TestCore(unittest.TestCase):
patch("automtu.core.iface_exists", return_value=True),
patch("automtu.core.read_iface_mtu", return_value=1500),
patch("automtu.core.set_iface_mtu") as mock_set,
patch("automtu.core.detect_docker_ifaces", return_value=[]),
):
buf = io.StringIO()
with redirect_stdout(buf):