summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-05-26 08:11:55 +0200
committerGitHub <noreply@github.com>2026-05-26 08:11:55 +0200
commit9534f4202e4430b4a58caa28603e5594178fd745 (patch)
treecac0d3076244ada474801d939a394e27c9de4a33
parent7b19c149d4edd39bfe441f1d38d602c707fa7ae2 (diff)
parent33ac35a45b813ab408c7ce0ccb511608a637fc68 (diff)
downloadvyos-1x-9534f4202e4430b4a58caa28603e5594178fd745.tar.gz
vyos-1x-9534f4202e4430b4a58caa28603e5594178fd745.zip
Merge pull request #5119 from AppMana/T8480
wan: T8480: add suppress_prefixlength ip rules for internal routing
-rw-r--r--interface-definitions/load-balancing_wan.xml.in6
-rwxr-xr-xsmoketest/scripts/cli/test_load-balancing_wan.py17
-rwxr-xr-xsrc/helpers/vyos-load-balancer.py24
3 files changed, 46 insertions, 1 deletions
diff --git a/interface-definitions/load-balancing_wan.xml.in b/interface-definitions/load-balancing_wan.xml.in
index 24be00111..17bd3aaf3 100644
--- a/interface-definitions/load-balancing_wan.xml.in
+++ b/interface-definitions/load-balancing_wan.xml.in
@@ -29,6 +29,12 @@
<valueless/>
</properties>
</leafNode>
+ <leafNode name="only-default-route">
+ <properties>
+ <help>Prefer specific routes in the main routing table over WAN load balancing</help>
+ <valueless/>
+ </properties>
+ </leafNode>
<leafNode name="hook">
<properties>
<help>Script to be executed on interface status change</help>
diff --git a/smoketest/scripts/cli/test_load-balancing_wan.py b/smoketest/scripts/cli/test_load-balancing_wan.py
index 3b956a12e..1692b8760 100755
--- a/smoketest/scripts/cli/test_load-balancing_wan.py
+++ b/smoketest/scripts/cli/test_load-balancing_wan.py
@@ -138,6 +138,23 @@ class TestLoadBalancingWan(VyOSUnitTestSHIM.TestCase):
tmp = cmd('sudo ip route show table 202')
self.assertEqual(tmp, original)
+ tmp = cmd('sudo ip rule show')
+ self.assertIn('from all fwmark 0xc9 lookup 201', tmp)
+ self.assertIn('from all fwmark 0xca lookup 202', tmp)
+ self.assertNotIn('fwmark 0xc9 lookup main suppress_prefixlength 0', tmp)
+ self.assertNotIn('fwmark 0xca lookup main suppress_prefixlength 0', tmp)
+
+ self.cli_set(base_path + ['wan', 'only-default-route'])
+ self.cli_commit()
+
+ time.sleep(5)
+
+ tmp = cmd('sudo ip rule show')
+ self.assertIn('from all fwmark 0xc9 lookup main suppress_prefixlength 0', tmp)
+ self.assertIn('from all fwmark 0xc9 lookup 201', tmp)
+ self.assertIn('from all fwmark 0xca lookup main suppress_prefixlength 0', tmp)
+ self.assertIn('from all fwmark 0xca lookup 202', tmp)
+
# Delete veth interfaces and netns
for iface in [iface1, iface2, iface3]:
call(f'sudo ip link del dev {iface}')
diff --git a/src/helpers/vyos-load-balancer.py b/src/helpers/vyos-load-balancer.py
index 4417c04d5..127ce05e5 100755
--- a/src/helpers/vyos-load-balancer.py
+++ b/src/helpers/vyos-load-balancer.py
@@ -204,7 +204,17 @@ def cleanup(lb):
index = 1
for ifname, health_conf in lb['interface_health'].items():
table_num = lb['mark_offset'] + index
+ suppress_prio = lb['mark_offset'] + index
+ table_prio = suppress_prio + 100
run(f'ip route del table {table_num} default')
+ run(
+ f'ip rule del fwmark {hex(table_num)} table main '
+ f'suppress_prefixlength 0 priority {suppress_prio}'
+ )
+ run(
+ f'ip rule del fwmark {hex(table_num)} table {table_num} '
+ f'priority {table_prio}'
+ )
run(f'ip rule del fwmark {hex(table_num)} table {table_num}')
index += 1
@@ -263,7 +273,19 @@ if __name__ == '__main__':
else:
run(f'ip route replace table {table_num} default dev {ifname} via {health_conf["nexthop"]}')
- run(f'ip rule add fwmark {hex(table_num)} table {table_num}')
+ suppress_prio = lb['mark_offset'] + index
+ table_prio = suppress_prio + 100
+ if 'only_default_route' in lb:
+ run(
+ f'ip rule add fwmark {hex(table_num)} table main '
+ f'suppress_prefixlength 0 priority {suppress_prio}'
+ )
+ run(
+ f'ip rule add fwmark {hex(table_num)} table {table_num} '
+ f'priority {table_prio}'
+ )
+ else:
+ run(f'ip rule add fwmark {hex(table_num)} table {table_num}')
index += 1