diff options
| -rw-r--r-- | interface-definitions/include/constraint/vrf.xml.i | 2 | ||||
| -rwxr-xr-x | src/validators/vrf-name | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/interface-definitions/include/constraint/vrf.xml.i b/interface-definitions/include/constraint/vrf.xml.i index a1922bb6d..fa0518dad 100644 --- a/interface-definitions/include/constraint/vrf.xml.i +++ b/interface-definitions/include/constraint/vrf.xml.i @@ -2,5 +2,5 @@ <constraint> <validator name="vrf-name"/> </constraint> -<constraintErrorMessage>VRF instance name must be 15 characters or less and can not\nbe named as regular network interfaces.\nA name must starts from a letter.\n</constraintErrorMessage> +<constraintErrorMessage>VRF instance name must be 15 characters or less and can not be named as a\nregular network interfaces. VRF name must start with a letter.\n</constraintErrorMessage> <!-- include end --> diff --git a/src/validators/vrf-name b/src/validators/vrf-name index cc4be2510..b56ebd036 100755 --- a/src/validators/vrf-name +++ b/src/validators/vrf-name @@ -24,15 +24,22 @@ if __name__ == '__main__': vrf = argv[1] length = len(vrf) + # must not exceed Linux Kernel IFNAMSIZ definition if length not in range(1, 16): exit(1) + # allow only alpha numerical characters, - and _ + pattern = r'^[A-Za-z0-9_-]+$' + if not re.match(pattern, vrf): + exit(1) + # Treat loopback interface "lo" explicitly. Adding "lo" explicitly to the # following regex pattern would deny any VRF name starting with lo - thuse # local-vrf would be illegal - and that we do not want. if vrf == "lo": exit(1) + # VRF name must not conflict with local interface type prefix pattern = r'^(?!(bond|br|dum|eth|lan|eno|ens|enp|enx|gnv|ipoe|l2tp|l2tpeth|\ vtun|ppp|pppoe|peth|tun|vti|vxlan|wg|wlan|wwan|\d)\d*(\.\d+)?(v.+)?).*$' if not re.match(pattern, vrf): |
