diff options
-rwxr-xr-x | smoketest/scripts/cli/test_policy.py | 52 | ||||
-rwxr-xr-x | src/conf_mode/policy-local-route.py | 16 |
2 files changed, 50 insertions, 18 deletions
diff --git a/smoketest/scripts/cli/test_policy.py b/smoketest/scripts/cli/test_policy.py index a636a8097..ab63cbcf7 100755 --- a/smoketest/scripts/cli/test_policy.py +++ b/smoketest/scripts/cli/test_policy.py @@ -902,8 +902,6 @@ class TestPolicy(VyOSUnitTestSHIM.TestCase): self.cli_commit() - # Check generated configuration - # Expected values original = """ 102: from 2001:db8:1338::/126 iif lo lookup 150 102: from 2001:db8:1339::/126 iif lo lookup 150 @@ -1047,10 +1045,7 @@ class TestPolicy(VyOSUnitTestSHIM.TestCase): 101: from all fwmark 0x18 lookup 154 """ tmp = cmd('ip rule show prio 101') - original = original.split() - tmp = tmp.split() - - self.assertEqual(tmp, original) + self.assertEqual(sort_ip(tmp), sort_ip(original)) # Test set table for sources with fwmark def test_fwmark_sources_table_id(self): @@ -1072,10 +1067,7 @@ class TestPolicy(VyOSUnitTestSHIM.TestCase): 100: from 203.0.113.12 fwmark 0x17 lookup 150 """ tmp = cmd('ip rule show prio 100') - original = original.split() - tmp = tmp.split() - - self.assertEqual(tmp, original) + self.assertEqual(sort_ip(tmp), sort_ip(original)) # Test remove fwmark for sources with fwmark def test_source_fwmk_remove(self): @@ -1097,10 +1089,7 @@ class TestPolicy(VyOSUnitTestSHIM.TestCase): 100: from 203.0.113.11 to 203.0.113.0/24 fwmark 0x17 lookup 150 """ tmp = cmd('ip rule show prio 100') - original = original.split() - tmp = tmp.split() - - self.assertEqual(tmp, original) + self.assertEqual(sort_ip(tmp), sort_ip(original)) self.cli_delete(path + ['rule', rule, 'source', src]) self.cli_commit() @@ -1109,9 +1098,38 @@ class TestPolicy(VyOSUnitTestSHIM.TestCase): 100: from all to 203.0.113.0/24 fwmark 0x17 lookup 150 """ tmp = cmd('ip rule show prio 100') - original = original.split() - tmp = tmp.split() - self.assertEqual(tmp, original) + self.assertEqual(sort_ip(tmp), sort_ip(original)) + + # Test change table for sources with fwmark + def test_source_change_table(self): + path = base_path + ['local-route'] + + src = '203.0.113.11' + dst = '203.0.113.0/24' + fwmk = '23' + rule = '100' + table = '150' + self.cli_set(path + ['rule', rule, 'set', 'table', table]) + self.cli_set(path + ['rule', rule, 'source', src]) + self.cli_set(path + ['rule', rule, 'destination', dst]) + self.cli_set(path + ['rule', rule, 'fwmark', fwmk]) + + self.cli_commit() + + original = """ + 100: from 203.0.113.11 to 203.0.113.0/24 fwmark 0x17 lookup 150 + """ + tmp = cmd('ip rule show prio 100') + self.assertEqual(sort_ip(tmp), sort_ip(original)) + + self.cli_set(path + ['rule', rule, 'set', 'table', '151']) + self.cli_commit() + + original = """ + 100: from 203.0.113.11 to 203.0.113.0/24 fwmark 0x17 lookup 151 + """ + tmp = cmd('ip rule show prio 100') + self.assertEqual(sort_ip(tmp), sort_ip(original)) def sort_ip(output): o = '\n'.join([' '.join(line.strip().split()) for line in output.strip().splitlines()]) diff --git a/src/conf_mode/policy-local-route.py b/src/conf_mode/policy-local-route.py index c32463d04..8a92bbc76 100755 --- a/src/conf_mode/policy-local-route.py +++ b/src/conf_mode/policy-local-route.py @@ -54,6 +54,7 @@ def get_config(config=None): fwmk = leaf_node_changed(conf, base_rule + [rule, 'fwmark']) iif = leaf_node_changed(conf, base_rule + [rule, 'inbound-interface']) dst = leaf_node_changed(conf, base_rule + [rule, 'destination']) + table = leaf_node_changed(conf, base_rule + [rule, 'set', 'table']) rule_def = {} if src: rule_def = dict_merge({'source' : src}, rule_def) @@ -63,6 +64,8 @@ def get_config(config=None): rule_def = dict_merge({'inbound_interface' : iif}, rule_def) if dst: rule_def = dict_merge({'destination' : dst}, rule_def) + if table: + rule_def = dict_merge({'table' : table}, rule_def) dict = dict_merge({dict_id : {rule : rule_def}}, dict) pbr.update(dict) @@ -78,6 +81,7 @@ def get_config(config=None): fwmk = leaf_node_changed(conf, base_rule + [rule, 'fwmark']) iif = leaf_node_changed(conf, base_rule + [rule, 'inbound-interface']) dst = leaf_node_changed(conf, base_rule + [rule, 'destination']) + table = leaf_node_changed(conf, base_rule + [rule, 'set', 'table']) # keep track of changes in configuration # otherwise we might remove an existing node although nothing else has changed changed = False @@ -119,6 +123,13 @@ def get_config(config=None): changed = True if len(dst) > 0: rule_def = dict_merge({'destination' : dst}, rule_def) + if table is None: + if 'set' in rule_config and 'table' in rule_config['set']: + rule_def = dict_merge({'table': [rule_config['set']['table']]}, rule_def) + else: + changed = True + if len(table) > 0: + rule_def = dict_merge({'table' : table}, rule_def) if changed: dict = dict_merge({dict_id : {rule : rule_def}}, dict) pbr.update(dict) @@ -179,7 +190,10 @@ def apply(pbr): rule_config['inbound_interface'] = rule_config['inbound_interface'] if 'inbound_interface' in rule_config else [''] for iif in rule_config['inbound_interface']: f_iif = '' if iif == '' else f' iif {iif} ' - call(f'ip{v6} rule del prio {rule} {f_src}{f_dst}{f_fwmk}{f_iif}') + rule_config['table'] = rule_config['table'] if 'table' in rule_config else [''] + for table in rule_config['table']: + f_table = '' if table == '' else f' lookup {table} ' + call(f'ip{v6} rule del prio {rule} {f_src}{f_dst}{f_fwmk}{f_iif}{f_table}') # Generate new config for route in ['local_route', 'local_route6']: |