diff options
| author | Viacheslav Hletenko <v.gletenko@vyos.io> | 2025-07-16 12:34:28 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-16 12:34:28 +0300 |
| commit | 115fe85c726f85b8171e17f128ba204bdde34a57 (patch) | |
| tree | 751ba0214ac420c0d1a5427fbf064b64178badf9 | |
| parent | a1b5b365b9116fcf8a9a70714ccc449a1a5a6cc8 (diff) | |
| parent | 71e08a18125071c6bcc26b6dd61cdbdd92b4d65b (diff) | |
| download | vyos-1x-115fe85c726f85b8171e17f128ba204bdde34a57.tar.gz vyos-1x-115fe85c726f85b8171e17f128ba204bdde34a57.zip | |
Merge pull request #4605 from MattKobayashi/T7625
T7625: load-balancing: prune limit key if not configured
| -rwxr-xr-x | smoketest/scripts/cli/test_load-balancing_wan.py | 23 | ||||
| -rwxr-xr-x | src/helpers/vyos-load-balancer.py | 5 |
2 files changed, 27 insertions, 1 deletions
diff --git a/smoketest/scripts/cli/test_load-balancing_wan.py b/smoketest/scripts/cli/test_load-balancing_wan.py index 88a6f0ad7..937cc3b76 100755 --- a/smoketest/scripts/cli/test_load-balancing_wan.py +++ b/smoketest/scripts/cli/test_load-balancing_wan.py @@ -164,7 +164,7 @@ class TestLoadBalancingWan(VyOSUnitTestSHIM.TestCase): mangle_prerouting = """table ip vyos_wanloadbalance { chain wlb_mangle_prerouting { type filter hook prerouting priority mangle; policy accept; - iifname "veth3" ip saddr 198.51.100.0/24 ct state new limit rate 5/second burst 5 packets counter numgen random mod 11 vmap { 0 : jump wlb_mangle_isp_veth1, 1-10 : jump wlb_mangle_isp_veth2 } + iifname "veth3" ip saddr 198.51.100.0/24 ct state new counter numgen random mod 11 vmap { 0 : jump wlb_mangle_isp_veth1, 1-10 : jump wlb_mangle_isp_veth2 } iifname "veth3" ip saddr 198.51.100.0/24 counter meta mark set ct mark } }""" @@ -234,6 +234,27 @@ class TestLoadBalancingWan(VyOSUnitTestSHIM.TestCase): tmp = cmd('sudo nft -s list chain ip vyos_wanloadbalance wlb_nat_postrouting') self.assertEqual(tmp, nat_wanloadbalance) + # Set limit configuration + mangle_prerouting_limit = """table ip vyos_wanloadbalance { + chain wlb_mangle_prerouting { + type filter hook prerouting priority mangle; policy accept; + iifname "veth3" ip saddr 198.51.100.0/24 ct state new limit rate 10/second burst 10 packets counter numgen random mod 11 vmap { 0 : jump wlb_mangle_isp_veth1, 1-10 : jump wlb_mangle_isp_veth2 } + iifname "veth3" ip saddr 198.51.100.0/24 counter meta mark set ct mark + } +}""" + + self.cli_set(base_path + ['wan', 'rule', '10', 'limit', 'rate', '10']) + self.cli_set(base_path + ['wan', 'rule', '10', 'limit', 'burst', '10']) + + # Commit changes + self.cli_commit() + + time.sleep(5) + + # Check prerouting mangle chain + tmp = cmd('sudo nft -s list chain ip vyos_wanloadbalance wlb_mangle_prerouting') + self.assertEqual(tmp, mangle_prerouting_limit) + # 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 850c5142e..6b260bf2c 100755 --- a/src/helpers/vyos-load-balancer.py +++ b/src/helpers/vyos-load-balancer.py @@ -160,6 +160,11 @@ def get_config(): lb = conf.get_config_dict(base, key_mangling=('-', '_'), get_first_key=True, with_recursive_defaults=True) + # prune limit key if not set by user + for rule in lb.get('rule', []): + if lb.from_defaults(['rule', rule, 'limit']): + del lb['rule'][rule]['limit'] + lb['test_defaults'] = get_defaults(base + ['interface-health', 'A', 'test', 'B'], get_first_key=True) return lb |
