* luci/libs/uvl:
authorJo-Philipp Wich <jow@openwrt.org>
Thu, 4 Sep 2008 23:39:55 +0000 (23:39 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Thu, 4 Sep 2008 23:39:55 +0000 (23:39 +0000)
- implement port and portrange datatypes
- fix datatype of port ranges in firewall scheme

libs/uvl/luasrc/uvl/datatypes.lua
libs/uvl/root/lib/uci/schema/default/firewall

index 60377e2..e6a4c16 100644 (file)
@@ -83,6 +83,20 @@ function ip6prefix( val )
        return ( val and val >= 0 and val <= 128 )
 end
 
        return ( val and val >= 0 and val <= 128 )
 end
 
+function port( val )
+       val = tonumber(val)
+       return ( val and val >= 1 and val <= 65535 )
+end
+
+function portrange( val )
+       local p1, p2 = val:match("^(%d+)%-(%d+)$")
+       if p1 and p2 and port(p1) and port(p2) then
+               return true
+       else
+               return port(val)
+       end
+end
+
 function macaddr( val )
        if val and val:match(
                "^[a-fA-F0-9]+:[a-fA-F0-9]+:[a-fA-F0-9]+:" ..
 function macaddr( val )
        if val and val:match(
                "^[a-fA-F0-9]+:[a-fA-F0-9]+:[a-fA-F0-9]+:" ..
index e421b11..fc58705 100644 (file)
@@ -121,7 +121,7 @@ config variable
        option name     'src_port'
        option title    'Source port'
        option section  'firewall.rule'
        option name     'src_port'
        option title    'Source port'
        option section  'firewall.rule'
-       option datatype 'uint'
+       option datatype 'portrange'
 
 config variable
        option name     'src_mac'
 
 config variable
        option name     'src_mac'
@@ -145,7 +145,7 @@ config variable
        option name     'dest_port'
        option title    'Destination port'
        option section  'firewall.rule'
        option name     'dest_port'
        option title    'Destination port'
        option section  'firewall.rule'
-       option datatype 'uint'
+       option datatype 'portrange'
 
 config variable
        option name     'proto'
 
 config variable
        option name     'proto'
@@ -183,13 +183,13 @@ config variable
        option name     'src_port'
        option title    'Source port'
        option section  'firewall.redirect'
        option name     'src_port'
        option title    'Source port'
        option section  'firewall.redirect'
-       option datatype 'uint'
+       option datatype 'portrange'
 
 config variable
        option name     'src_dport'
        option title    'Source destination port'
        option section  'firewall.redirect'
 
 config variable
        option name     'src_dport'
        option title    'Source destination port'
        option section  'firewall.redirect'
-       option datatype 'uint'
+       option datatype 'portrange'
 
 config variable
        option name     'src_mac'
 
 config variable
        option name     'src_mac'
@@ -213,7 +213,7 @@ config variable
        option name     'dest_port'
        option title    'Destination port'
        option section  'firewall.redirect'
        option name     'dest_port'
        option title    'Destination port'
        option section  'firewall.redirect'
-       option datatype 'uint'
+       option datatype 'portrange'
 
 config variable
        option name     'proto'
 
 config variable
        option name     'proto'