]> git.entuzijast.net Git - imunes.git/commitdiff
Add IPv6 address syntax checking
authormarko <marko>
Mon, 11 Jul 2005 16:37:59 +0000 (16:37 +0000)
committermarko <marko>
Mon, 11 Jul 2005 16:37:59 +0000 (16:37 +0000)
Bug found by:
Submitted by:
Requested by:
Reviewed by:
Approved by:
Obtained from:

editor.tcl

index 9fbda2dad297e9007e24bc07f8c100b1aa4e465a..a1dfe0a7fc91ac2616f7e7fe2af0e1b51777d9b8 100755 (executable)
@@ -435,6 +435,7 @@ proc chooseIfName { lnode1 lnode2 } {
            if { [nodeType $lnode2] == "router" || \
                [nodeType $lnode2] == "frswitch" } {
                return ser
+               return eth
            } else {
                return eth
            }
@@ -1339,6 +1340,9 @@ proc checkIPv4Addr { str } {
 
 
 proc checkIPv4Net { str } {
+    if { $str == "" } {
+       return 1
+    }
     if { ![checkIPv4Addr [lindex [split $str /] 0]]} {
        return 0
     }
@@ -1350,6 +1354,57 @@ proc checkIPv4Net { str } {
 }
 
 
+proc checkIPv6Addr { str } {
+    set doublec false
+    set wordlist [split $str :]
+    set wordcnt [expr [llength $wordlist] - 1]
+    if { $wordcnt > 7 } {
+       return 0
+    }
+    if { [lindex $wordlist 0] == "" } {
+       set wordlist [lreplace $wordlist 0 0 0]
+    }
+    if { [lindex $wordlist $wordcnt] == "" } {
+       set wordlist [lreplace $wordlist $wordcnt $wordcnt 0]
+    }
+    for { set i 0 } { $i <= $wordcnt } { incr i } {
+       set word [lindex $wordlist $i]
+       if { $word == "" } {
+           if { $doublec == "true" } {
+               return 0
+           }
+           set doublec true
+       }
+       if { [string length $word] > 4 } {
+           if { $i == $wordcnt } {
+               return [checkIPv4Addr $word]
+           } else {
+               return 0
+           }
+       }
+       if { [string is xdigit $word] == 0 } {
+           return 0
+       }
+    }
+    return 1
+}
+
+
+proc checkIPv6Net { str } {
+    if { $str == "" } {
+       return 1
+    }
+    if { ![checkIPv6Addr [lindex [split $str /] 0]]} {
+       return 0
+    }
+    set net [lindex [split $str /] 1]
+    if { [string length [string trim $net]] != [string length $net] } {
+       return 0
+    }
+    return [checkIntRange $net 0 128]
+}
+
+
 proc focusAndFlash {W {count 9}} {
     global badentry
 
@@ -1538,10 +1593,8 @@ proc popupConfigDialog { c } {
                            -validate focus -invcmd "focusAndFlash %W"
                        $wi.if$ifc.cfg.ipv6.addrv insert 0 \
                            [getIfcIPv6addr $target $ifc]
-if { 0 } {
                        $wi.if$ifc.cfg.ipv6.addrv configure \
-                           -vcmd {checkIPv4Net %P}
-}
+                           -vcmd {checkIPv6Net %P}
                        pack $wi.if$ifc.cfg.ipv6.addrl \
                            $wi.if$ifc.cfg.ipv6.addrv -side left
                        pack $wi.if$ifc.cfg.ipv6 -side top -anchor w