From 501a4c7fd2ce8af909e553894ee3f1956e29a91c Mon Sep 17 00:00:00 2001
From: Stephen Hemminger <shemminger@vyatta.com>
Date: Thu, 19 Jan 2012 19:04:24 -0800
Subject: Enforce length restriction on interface description

Bug 7730
Kernel limit on interface description (ifalias) is 256 characters.
---
 templates/interfaces/bonding/node.tag/description/node.def            | 4 ++++
 .../interfaces/bonding/node.tag/vif/node.tag/description/node.def     | 4 ++++
 .../node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def  | 4 ++++
 .../node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def  | 4 ++++
 templates/interfaces/bridge/node.tag/description/node.def             | 4 ++++
 templates/interfaces/ethernet/node.tag/description/node.def           | 4 ++++
 .../interfaces/ethernet/node.tag/vif/node.tag/description/node.def    | 4 ++++
 .../node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def  | 4 ++++
 .../node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def  | 4 ++++
 templates/interfaces/loopback/node.tag/description/node.def           | 4 ++++
 templates/interfaces/pseudo-ethernet/node.tag/description/node.def    | 4 ++++
 .../pseudo-ethernet/node.tag/vif/node.tag/description/node.def        | 4 ++++
 templates/interfaces/tunnel/node.tag/description/node.def             | 4 ++++
 13 files changed, 52 insertions(+)

diff --git a/templates/interfaces/bonding/node.tag/description/node.def b/templates/interfaces/bonding/node.tag/description/node.def
index e4807d2f..c6d2789d 100644
--- a/templates/interfaces/bonding/node.tag/description/node.def
+++ b/templates/interfaces/bonding/node.tag/description/node.def
@@ -1,4 +1,8 @@
 type: txt
 help: Description
+
+syntax:expression: pattern $VAR(@) "^.{1,256}$" \
+	; "interface description is too long (limit 256 characters)"
+
 update: sudo sh -c "echo \"$VAR(@)\" >/sys/class/net/$VAR(../@)/ifalias"
 delete: sudo sh -c "echo '' >/sys/class/net/$VAR(../@)/ifalias"
diff --git a/templates/interfaces/bonding/node.tag/vif/node.tag/description/node.def b/templates/interfaces/bonding/node.tag/vif/node.tag/description/node.def
index ce6c5fd0..a0b29f05 100644
--- a/templates/interfaces/bonding/node.tag/vif/node.tag/description/node.def
+++ b/templates/interfaces/bonding/node.tag/vif/node.tag/description/node.def
@@ -1,4 +1,8 @@
 type: txt
 help: Description
+
+syntax:expression: pattern $VAR(@) "^.{1,256}$" \
+	; "interface description is too long (limit 256 characters)"
+
 update: sudo sh -c "echo \"$VAR(@)\" >/sys/class/net/$VAR(../../@).$VAR(../@)/ifalias"
 delete: sudo sh -c "echo '' >/sys/class/net/$VAR(../../@).$VAR(../@)/ifalias"
diff --git a/templates/interfaces/bonding/node.tag/vif/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def b/templates/interfaces/bonding/node.tag/vif/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def
index 7d3ab379..a0f78074 100644
--- a/templates/interfaces/bonding/node.tag/vif/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def
+++ b/templates/interfaces/bonding/node.tag/vif/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def
@@ -1,5 +1,9 @@
 priority: 820 # after vrrp
 type: txt
+
+syntax:expression: pattern $VAR(@) "^.{1,256}$" \
+	; "interface description is too long (limit 256 characters)"
+
 help: Description for this interface
 update: sudo sh -c "echo \"$VAR(@)\" >/sys/class/net/$VAR(../../../../../@).$VAR(../../../../@)v$VAR(../../@)/ifalias"
 delete: sudo sh -c "echo '' >/sys/class/net/$VAR(../../../../../@).$VAR(../../../../@)v$VAR(../../@)/ifalias"
diff --git a/templates/interfaces/bonding/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def b/templates/interfaces/bonding/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def
index 75400c58..df48a57b 100644
--- a/templates/interfaces/bonding/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def
+++ b/templates/interfaces/bonding/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def
@@ -1,5 +1,9 @@
 priority: 820 # after vrrp
 type: txt
+
+syntax:expression: pattern $VAR(@) "^.{1,256}$" \
+	; "interface description is too long (limit 256 characters)"
+
 help: Description for this interface
 update: sudo sh -c "echo \"$VAR(@)\" >/sys/class/net/$VAR(../../../../@)v$VAR(../../@)/ifalias"
 delete: sudo sh -c "echo '' >/sys/class/net/$VAR(../../../../@)v$VAR(../../@)/ifalias"
diff --git a/templates/interfaces/bridge/node.tag/description/node.def b/templates/interfaces/bridge/node.tag/description/node.def
index e4807d2f..c6d2789d 100644
--- a/templates/interfaces/bridge/node.tag/description/node.def
+++ b/templates/interfaces/bridge/node.tag/description/node.def
@@ -1,4 +1,8 @@
 type: txt
 help: Description
+
+syntax:expression: pattern $VAR(@) "^.{1,256}$" \
+	; "interface description is too long (limit 256 characters)"
+
 update: sudo sh -c "echo \"$VAR(@)\" >/sys/class/net/$VAR(../@)/ifalias"
 delete: sudo sh -c "echo '' >/sys/class/net/$VAR(../@)/ifalias"
diff --git a/templates/interfaces/ethernet/node.tag/description/node.def b/templates/interfaces/ethernet/node.tag/description/node.def
index e4807d2f..c6d2789d 100644
--- a/templates/interfaces/ethernet/node.tag/description/node.def
+++ b/templates/interfaces/ethernet/node.tag/description/node.def
@@ -1,4 +1,8 @@
 type: txt
 help: Description
+
+syntax:expression: pattern $VAR(@) "^.{1,256}$" \
+	; "interface description is too long (limit 256 characters)"
+
 update: sudo sh -c "echo \"$VAR(@)\" >/sys/class/net/$VAR(../@)/ifalias"
 delete: sudo sh -c "echo '' >/sys/class/net/$VAR(../@)/ifalias"
diff --git a/templates/interfaces/ethernet/node.tag/vif/node.tag/description/node.def b/templates/interfaces/ethernet/node.tag/vif/node.tag/description/node.def
index ce6c5fd0..a0b29f05 100644
--- a/templates/interfaces/ethernet/node.tag/vif/node.tag/description/node.def
+++ b/templates/interfaces/ethernet/node.tag/vif/node.tag/description/node.def
@@ -1,4 +1,8 @@
 type: txt
 help: Description
+
+syntax:expression: pattern $VAR(@) "^.{1,256}$" \
+	; "interface description is too long (limit 256 characters)"
+
 update: sudo sh -c "echo \"$VAR(@)\" >/sys/class/net/$VAR(../../@).$VAR(../@)/ifalias"
 delete: sudo sh -c "echo '' >/sys/class/net/$VAR(../../@).$VAR(../@)/ifalias"
diff --git a/templates/interfaces/ethernet/node.tag/vif/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def b/templates/interfaces/ethernet/node.tag/vif/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def
index 7d3ab379..a0f78074 100644
--- a/templates/interfaces/ethernet/node.tag/vif/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def
+++ b/templates/interfaces/ethernet/node.tag/vif/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def
@@ -1,5 +1,9 @@
 priority: 820 # after vrrp
 type: txt
+
+syntax:expression: pattern $VAR(@) "^.{1,256}$" \
+	; "interface description is too long (limit 256 characters)"
+
 help: Description for this interface
 update: sudo sh -c "echo \"$VAR(@)\" >/sys/class/net/$VAR(../../../../../@).$VAR(../../../../@)v$VAR(../../@)/ifalias"
 delete: sudo sh -c "echo '' >/sys/class/net/$VAR(../../../../../@).$VAR(../../../../@)v$VAR(../../@)/ifalias"
diff --git a/templates/interfaces/ethernet/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def b/templates/interfaces/ethernet/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def
index 75400c58..df48a57b 100644
--- a/templates/interfaces/ethernet/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def
+++ b/templates/interfaces/ethernet/node.tag/vrrp/vrrp-group/node.tag/interface/description/node.def
@@ -1,5 +1,9 @@
 priority: 820 # after vrrp
 type: txt
+
+syntax:expression: pattern $VAR(@) "^.{1,256}$" \
+	; "interface description is too long (limit 256 characters)"
+
 help: Description for this interface
 update: sudo sh -c "echo \"$VAR(@)\" >/sys/class/net/$VAR(../../../../@)v$VAR(../../@)/ifalias"
 delete: sudo sh -c "echo '' >/sys/class/net/$VAR(../../../../@)v$VAR(../../@)/ifalias"
diff --git a/templates/interfaces/loopback/node.tag/description/node.def b/templates/interfaces/loopback/node.tag/description/node.def
index e4807d2f..c6d2789d 100644
--- a/templates/interfaces/loopback/node.tag/description/node.def
+++ b/templates/interfaces/loopback/node.tag/description/node.def
@@ -1,4 +1,8 @@
 type: txt
 help: Description
+
+syntax:expression: pattern $VAR(@) "^.{1,256}$" \
+	; "interface description is too long (limit 256 characters)"
+
 update: sudo sh -c "echo \"$VAR(@)\" >/sys/class/net/$VAR(../@)/ifalias"
 delete: sudo sh -c "echo '' >/sys/class/net/$VAR(../@)/ifalias"
diff --git a/templates/interfaces/pseudo-ethernet/node.tag/description/node.def b/templates/interfaces/pseudo-ethernet/node.tag/description/node.def
index e2a1534b..e57584a8 100644
--- a/templates/interfaces/pseudo-ethernet/node.tag/description/node.def
+++ b/templates/interfaces/pseudo-ethernet/node.tag/description/node.def
@@ -1,4 +1,8 @@
 type: txt
 help: Description for this interface
+
+syntax:expression: pattern $VAR(@) "^.{1,256}$" \
+	; "interface description is too long (limit 256 characters)"
+
 update: sudo sh -c "echo \"$VAR(@)\" >/sys/class/net/$VAR(../@)/ifalias"
 delete: sudo sh -c "echo '' >/sys/class/net/$VAR(../@)/ifalias"
diff --git a/templates/interfaces/pseudo-ethernet/node.tag/vif/node.tag/description/node.def b/templates/interfaces/pseudo-ethernet/node.tag/vif/node.tag/description/node.def
index ce6c5fd0..a0b29f05 100644
--- a/templates/interfaces/pseudo-ethernet/node.tag/vif/node.tag/description/node.def
+++ b/templates/interfaces/pseudo-ethernet/node.tag/vif/node.tag/description/node.def
@@ -1,4 +1,8 @@
 type: txt
 help: Description
+
+syntax:expression: pattern $VAR(@) "^.{1,256}$" \
+	; "interface description is too long (limit 256 characters)"
+
 update: sudo sh -c "echo \"$VAR(@)\" >/sys/class/net/$VAR(../../@).$VAR(../@)/ifalias"
 delete: sudo sh -c "echo '' >/sys/class/net/$VAR(../../@).$VAR(../@)/ifalias"
diff --git a/templates/interfaces/tunnel/node.tag/description/node.def b/templates/interfaces/tunnel/node.tag/description/node.def
index e4807d2f..c6d2789d 100644
--- a/templates/interfaces/tunnel/node.tag/description/node.def
+++ b/templates/interfaces/tunnel/node.tag/description/node.def
@@ -1,4 +1,8 @@
 type: txt
 help: Description
+
+syntax:expression: pattern $VAR(@) "^.{1,256}$" \
+	; "interface description is too long (limit 256 characters)"
+
 update: sudo sh -c "echo \"$VAR(@)\" >/sys/class/net/$VAR(../@)/ifalias"
 delete: sudo sh -c "echo '' >/sys/class/net/$VAR(../@)/ifalias"
-- 
cgit v1.2.3