summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2026-03-02 08:26:30 +0000
committerGitHub <noreply@github.com>2026-03-02 08:26:30 +0000
commit4292d2b893f429003b70e8f1cb74986a5f12cf47 (patch)
tree392dd6258ad55abdf3166774c688a14ce04fdba6
parent3e448bd51685688bdae6ec698a3923cfdeb83689 (diff)
parentda2349c0eaca742dffa5e271d0d53937ecec9f8f (diff)
downloadvyos-1x-4292d2b893f429003b70e8f1cb74986a5f12cf47.tar.gz
vyos-1x-4292d2b893f429003b70e8f1cb74986a5f12cf47.zip
Merge pull request #5018 from c-po/vrf
vrf: T8320: only allow alpha numerical characters, - and _ as VRF name
-rw-r--r--interface-definitions/include/constraint/vrf.xml.i2
-rwxr-xr-xsrc/validators/vrf-name7
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):