From: marko Date: Mon, 11 Jul 2005 16:37:59 +0000 (+0000) Subject: Add IPv6 address syntax checking X-Git-Url: https://git.entuzijast.net/?a=commitdiff_plain;h=b9b53dd3acb30755117dc59f057a70452368f820;p=imunes.git Add IPv6 address syntax checking Bug found by: Submitted by: Requested by: Reviewed by: Approved by: Obtained from: --- diff --git a/editor.tcl b/editor.tcl index 9fbda2d..a1dfe0a 100755 --- a/editor.tcl +++ b/editor.tcl @@ -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