From a476fdb2466ea5ba1135588244286201fa5e3119 Mon Sep 17 00:00:00 2001 From: hellodword <46193371+hellodword@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:55:46 +0000 Subject: [PATCH] nixos/sing-box: test iproute2_table_index and iproute2_rule_index --- nixos/tests/sing-box.nix | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/nixos/tests/sing-box.nix b/nixos/tests/sing-box.nix index 4a56d12f5289..a8a287586af2 100644 --- a/nixos/tests/sing-box.nix +++ b/nixos/tests/sing-box.nix @@ -49,6 +49,8 @@ import ./make-test-python.nix ( "fd00::1/126" ]; auto_route = true; + iproute2_table_index = 2024; + iproute2_rule_index = 9001; route_address = [ "${hosts."${target_host}"}/32" ]; @@ -515,9 +517,14 @@ import ./make-test-python.nix ( with subtest("tun"): tun.wait_for_unit("sing-box.service") - tun.wait_for_unit("sys-devices-virtual-net-tun0.device") - tun.wait_until_succeeds("ip route get ${hosts."${target_host}"} | grep 'dev tun0'") - tun.succeed("ip addr show tun0") + tun.wait_for_unit("sys-devices-virtual-net-${tunInbound.interface_name}.device") + tun.wait_until_succeeds("ip route get ${hosts."${target_host}"} | grep 'dev ${tunInbound.interface_name}'") + tun.succeed("ip addr show ${tunInbound.interface_name}") + tun.succeed("ip route show table ${toString tunInbound.iproute2_table_index} | grep ${tunInbound.interface_name}") + assert ( + tun.succeed("ip rule list table ${toString tunInbound.iproute2_table_index} | sort | head -1 | awk -F: '{print $1}' | tr -d '\n'") + == "${toString tunInbound.iproute2_rule_index}" + ) test_curl(tun) with subtest("wireguard"): @@ -532,8 +539,8 @@ import ./make-test-python.nix ( with subtest("fakeip"): fakeip.wait_for_unit("sing-box.service") - fakeip.wait_for_unit("sys-devices-virtual-net-tun0.device") - fakeip.wait_until_succeeds("ip route get ${hosts."${target_host}"} | grep 'dev tun0'") + fakeip.wait_for_unit("sys-devices-virtual-net-${tunInbound.interface_name}.device") + fakeip.wait_until_succeeds("ip route get ${hosts."${target_host}"} | grep 'dev ${tunInbound.interface_name}'") fakeip.succeed("dig +short A ${target_host} @${target_host} | grep '^198.18.'") '';