summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python/vyos/configverify.py21
-rwxr-xr-xsrc/conf_mode/protocols_ospf.py2
-rwxr-xr-xsrc/conf_mode/protocols_ospfv3.py14
3 files changed, 37 insertions, 0 deletions
diff --git a/python/vyos/configverify.py b/python/vyos/configverify.py
index bcaec55be..de88310e8 100644
--- a/python/vyos/configverify.py
+++ b/python/vyos/configverify.py
@@ -307,3 +307,24 @@ def verify_diffie_hellman_length(file, min_keysize):
return False
+def verify_route_maps(config):
+ """
+ Common helper function used by routing protocol implementations to perform
+ recurring validation if the specified route-map for either zebra to kernel
+ installation exists (this is the top-level route_map key) or when a route
+ is redistributed with a route-map that it exists!
+ """
+ if 'route_map' in config:
+ route_map = config['route_map']
+ # Check if the specified route-map exists, if not error out
+ if dict_search(f'policy.route_map.{route_map}', config) == None:
+ raise ConfigError(f'Specified route-map "{route_map}" does not exist!')
+
+ if 'redistribute' in config:
+ for protocol, protocol_config in config['redistribute'].items():
+ if 'route_map' in protocol_config:
+ route_map = protocol_config['route_map']
+ # Check if the specified route-map exists, if not error out
+ if dict_search(f'policy.route_map.{route_map}', config) == None:
+ raise ConfigError(f'Redistribution route-map "{route_map}" ' \
+ f'for "{protocol}" does not exist!')
diff --git a/src/conf_mode/protocols_ospf.py b/src/conf_mode/protocols_ospf.py
index f43929b46..9842d26cd 100755
--- a/src/conf_mode/protocols_ospf.py
+++ b/src/conf_mode/protocols_ospf.py
@@ -20,6 +20,7 @@ from sys import exit
from vyos.config import Config
from vyos.configdict import dict_merge
+from vyos.configverify import verify_route_maps
from vyos.template import render
from vyos.template import render_to_string
from vyos.util import call
@@ -99,6 +100,7 @@ def verify(ospf):
if not ospf:
return None
+ verify_route_maps(ospf)
return None
def generate(ospf):
diff --git a/src/conf_mode/protocols_ospfv3.py b/src/conf_mode/protocols_ospfv3.py
index f514641ef..2fb600056 100755
--- a/src/conf_mode/protocols_ospfv3.py
+++ b/src/conf_mode/protocols_ospfv3.py
@@ -20,6 +20,7 @@ from sys import exit
from vyos.config import Config
from vyos.configdict import dict_merge
+from vyos.configverify import verify_route_maps
from vyos.template import render
from vyos.template import render_to_string
from vyos.util import call
@@ -48,12 +49,25 @@ def get_config(config=None):
conf = Config()
base = ['protocols', 'ospfv3']
ospfv3 = conf.get_config_dict(base, key_mangling=('-', '_'), get_first_key=True)
+
+ # Bail out early if configuration tree does not exist
+ if not conf.exists(base):
+ return ospfv3
+
+ # We also need some additional information from the config, prefix-lists
+ # and route-maps for instance. They will be used in verify()
+ base = ['policy']
+ tmp = conf.get_config_dict(base, key_mangling=('-', '_'))
+ # Merge policy dict into OSPF dict
+ ospfv3 = dict_merge(tmp, ospfv3)
+
return ospfv3
def verify(ospfv3):
if not ospfv3:
return None
+ verify_route_maps(ospfv3)
return None
def generate(ospfv3):