summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-03-24 21:01:37 +0100
committerChristian Breunig <christian@breunig.cc>2024-03-24 21:01:37 +0100
commitc6d8d9c012da1a7566eec2dff70385457f073e64 (patch)
tree151278c3a201927c71f4fd3caa26a1474b2b1a53
parentafaf715194a922c92f6ff6058abc0e4b9ff570d4 (diff)
downloadvyos-1x-c6d8d9c012da1a7566eec2dff70385457f073e64.tar.gz
vyos-1x-c6d8d9c012da1a7566eec2dff70385457f073e64.zip
ospf: T6066: can not define the same network in different areas
Users can not (FRR fails) commit the same network belonging to different OSPF areas. Add verify() check to prevent this.
-rwxr-xr-xsmoketest/scripts/cli/test_protocols_ospf.py20
-rwxr-xr-xsrc/conf_mode/protocols_ospf.py7
2 files changed, 27 insertions, 0 deletions
diff --git a/smoketest/scripts/cli/test_protocols_ospf.py b/smoketest/scripts/cli/test_protocols_ospf.py
index 82fb96754..1b9cc50fe 100755
--- a/smoketest/scripts/cli/test_protocols_ospf.py
+++ b/smoketest/scripts/cli/test_protocols_ospf.py
@@ -540,5 +540,25 @@ class TestProtocolsOSPF(VyOSUnitTestSHIM.TestCase):
for router_id in router_ids:
self.assertIn(f' graceful-restart helper enable {router_id}', frrconfig)
+ def test_ospf_17_duplicate_area_network(self):
+ area0 = '0'
+ area1 = '1'
+ network = '10.0.0.0/8'
+
+ self.cli_set(base_path + ['area', area0, 'network', network])
+
+ # we can not have the same network defined on two areas
+ self.cli_set(base_path + ['area', area1, 'network', network])
+ with self.assertRaises(ConfigSessionError):
+ self.cli_commit()
+ self.cli_delete(base_path + ['area', area0])
+
+ self.cli_commit()
+
+ # Verify FRR ospfd configuration
+ frrconfig = self.getFRRconfig('router ospf', daemon=PROCESS_NAME)
+ self.assertIn(f'router ospf', frrconfig)
+ self.assertIn(f' network {network} area {area1}', frrconfig)
+
if __name__ == '__main__':
unittest.main(verbosity=2)
diff --git a/src/conf_mode/protocols_ospf.py b/src/conf_mode/protocols_ospf.py
index 695842795..6fffe7e0d 100755
--- a/src/conf_mode/protocols_ospf.py
+++ b/src/conf_mode/protocols_ospf.py
@@ -127,6 +127,7 @@ def verify(ospf):
# Validate if configured Access-list exists
if 'area' in ospf:
+ networks = []
for area, area_config in ospf['area'].items():
if 'import_list' in area_config:
acl_import = area_config['import_list']
@@ -135,6 +136,12 @@ def verify(ospf):
acl_export = area_config['export_list']
if acl_export: verify_access_list(acl_export, ospf)
+ if 'network' in area_config:
+ for network in area_config['network']:
+ if network in networks:
+ raise ConfigError(f'Network "{network}" already defined in different area!')
+ networks.append(network)
+
if 'interface' in ospf:
for interface, interface_config in ospf['interface'].items():
verify_interface_exists(interface)