Skip to content

Commit 115fe85

Browse files
authored
Merge pull request #4605 from MattKobayashi/T7625
T7625: load-balancing: prune limit key if not configured
2 parents a1b5b36 + 71e08a1 commit 115fe85

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

smoketest/scripts/cli/test_load-balancing_wan.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def test_check_chains(self):
164164
mangle_prerouting = """table ip vyos_wanloadbalance {
165165
chain wlb_mangle_prerouting {
166166
type filter hook prerouting priority mangle; policy accept;
167-
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 }
167+
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 }
168168
iifname "veth3" ip saddr 198.51.100.0/24 counter meta mark set ct mark
169169
}
170170
}"""
@@ -234,6 +234,27 @@ def test_check_chains(self):
234234
tmp = cmd('sudo nft -s list chain ip vyos_wanloadbalance wlb_nat_postrouting')
235235
self.assertEqual(tmp, nat_wanloadbalance)
236236

237+
# Set limit configuration
238+
mangle_prerouting_limit = """table ip vyos_wanloadbalance {
239+
chain wlb_mangle_prerouting {
240+
type filter hook prerouting priority mangle; policy accept;
241+
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 }
242+
iifname "veth3" ip saddr 198.51.100.0/24 counter meta mark set ct mark
243+
}
244+
}"""
245+
246+
self.cli_set(base_path + ['wan', 'rule', '10', 'limit', 'rate', '10'])
247+
self.cli_set(base_path + ['wan', 'rule', '10', 'limit', 'burst', '10'])
248+
249+
# Commit changes
250+
self.cli_commit()
251+
252+
time.sleep(5)
253+
254+
# Check prerouting mangle chain
255+
tmp = cmd('sudo nft -s list chain ip vyos_wanloadbalance wlb_mangle_prerouting')
256+
self.assertEqual(tmp, mangle_prerouting_limit)
257+
237258
# Delete veth interfaces and netns
238259
for iface in [iface1, iface2, iface3]:
239260
call(f'sudo ip link del dev {iface}')

src/helpers/vyos-load-balancer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ def get_config():
160160
lb = conf.get_config_dict(base, key_mangling=('-', '_'),
161161
get_first_key=True, with_recursive_defaults=True)
162162

163+
# prune limit key if not set by user
164+
for rule in lb.get('rule', []):
165+
if lb.from_defaults(['rule', rule, 'limit']):
166+
del lb['rule'][rule]['limit']
167+
163168
lb['test_defaults'] = get_defaults(base + ['interface-health', 'A', 'test', 'B'], get_first_key=True)
164169

165170
return lb

0 commit comments

Comments
 (0)