From: marko Date: Tue, 12 Jul 2005 13:16:17 +0000 (+0000) Subject: Static route refactoring: X-Git-Url: https://git.entuzijast.net/?a=commitdiff_plain;h=717ef98710c77910e17785ffaa8eda3d148b7f83;p=imunes.git Static route refactoring: * both IPv4 and IPv6 static routes can be specified / mixed; * syntax checking on route entries performed when applying changes, invalid route entries are silently discarded; * an integer metric value can be optionally specified with each route (currently usefull only with XORP). Bug found by: Submitted by: Requested by: Reviewed by: Approved by: Obtained from: --- diff --git a/editor.tcl b/editor.tcl index 1b9f4eb..d82952c 100755 --- a/editor.tcl +++ b/editor.tcl @@ -1585,7 +1585,8 @@ proc popupConfigDialog { c } { # # Static routes # - set routes [getStatIPv4routes $target] + set routes [concat [getStatIPv4routes $target] \ + [getStatIPv6routes $target]] labelframe $wi.statrt -padx 4 -pady 4 label $wi.statrt.label -text "Static routes:" pack $wi.statrt.label -side top -anchor w @@ -1596,8 +1597,8 @@ proc popupConfigDialog { c } { if { $h < 2 } { set h 2 } - text $wi.statrt.cfg.text -bg white \ - -width 36 -height $h -takefocus 0 + text $wi.statrt.cfg.text -font arial -bg white \ + -width 40 -height $h -takefocus 0 foreach route $routes { $wi.statrt.cfg.text insert end "$route " } @@ -1873,7 +1874,6 @@ proc popupConfigApply { wi object_type target close phase } { } if {[lsearch {router pc host} [nodeType $target]] >= 0} { - set ifconfchanged 0 foreach ifc [ifcList $target] { # # Operational state @@ -1885,7 +1885,6 @@ proc popupConfigApply { wi object_type target close phase } { setIfcOperState $target $ifc $ifoperstate updateIfcLabel $target [peerByIfc $target $ifc] set changed 1 - set ifconfchanged 1 } # @@ -1897,7 +1896,6 @@ proc popupConfigApply { wi object_type target close phase } { setIfcIPv4addr $target $ifc $ipaddr updateIfcLabel $target [peerByIfc $target $ifc] set changed 1 - set ifconfchanged 1 } set ipaddr [$wi.if$ifc.cfg.ipv6.addrv get] set oldipaddr [getIfcIPv6addr $target $ifc] @@ -1905,7 +1903,6 @@ proc popupConfigApply { wi object_type target close phase } { setIfcIPv6addr $target $ifc $ipaddr updateIfcLabel $target [peerByIfc $target $ifc] set changed 1 - set ifconfchanged 1 } set mtu [$wi.if$ifc.cfg.ipv4.mtuv get] @@ -1917,21 +1914,51 @@ proc popupConfigApply { wi object_type target close phase } { } - set oldstatrtes [getStatIPv4routes $target] - set newstatrtes {} + set oldIPv4statrtes [lsort [getStatIPv4routes $target]] + set oldIPv6statrtes [lsort [getStatIPv6routes $target]] + set newIPv4statrtes {} + set newIPv6statrtes {} set i 1 while { 1 } { set text [$wi.statrt.cfg.text get $i.0 $i.end] - set text [string trim $text] - if { $text == "" } { + set rtentry [lrange [split [string trim $text]] 0 2] + if { $rtentry == "" } { + break + } + set dst [lindex $rtentry 0] + set gw [lindex $rtentry 1] + set metric [lindex $rtentry 2] + if { [string is integer $metric] != 1 || \ + $metric > 65535 } { + break + } + if { [checkIPv4Net $dst] == 1 } { + if { [checkIPv4Addr $gw] == 1 } { + lappend newIPv4statrtes \ + [string trim "$dst $gw $metric"] + } else { + break + } + } elseif { [checkIPv6Net $dst] == 1 } { + if { [checkIPv6Addr $gw] == 1 } { + lappend newIPv6statrtes \ + [string trim "$dst $gw $metric"] + } else { + break + } + } else { break } - lappend newstatrtes $text incr i } - if { [lsort $oldstatrtes] != [lsort $newstatrtes] || \ - $ifconfchanged == 1} { - setStatIPv4routes $target $newstatrtes + set newIPv4statrtes [lsort $newIPv4statrtes] + if { $oldIPv4statrtes != $newIPv4statrtes } { + setStatIPv4routes $target $newIPv4statrtes + set changed 1 + } + set newIPv6statrtes [lsort $newIPv6statrtes] + if { $oldIPv6statrtes != $newIPv6statrtes } { + setStatIPv6routes $target $newIPv6statrtes set changed 1 } diff --git a/host.tcl b/host.tcl index c3a25c6..174ae64 100755 --- a/host.tcl +++ b/host.tcl @@ -54,7 +54,10 @@ proc $MODULE.cfggen { node } { lappend cfg "" foreach statrte [getStatIPv4routes $node] { - lappend cfg "route add $statrte" + lappend cfg "route add -inet $statrte" + } + foreach statrte [getStatIPv6routes $node] { + lappend cfg "route add -inet6 $statrte" } lappend cfg "portmap" diff --git a/pc.tcl b/pc.tcl index 236b55c..2b2b282 100755 --- a/pc.tcl +++ b/pc.tcl @@ -55,7 +55,10 @@ proc $MODULE.cfggen { node } { lappend cfg "" foreach statrte [getStatIPv4routes $node] { - lappend cfg "route add $statrte" + lappend cfg "route add -inet $statrte" + } + foreach statrte [getStatIPv6routes $node] { + lappend cfg "route add -inet6 $statrte" } return $cfg diff --git a/quagga.tcl b/quagga.tcl index 82e580e..36a4959 100755 --- a/quagga.tcl +++ b/quagga.tcl @@ -71,6 +71,9 @@ proc $MODULE.cfggen { node } { foreach statrte [getStatIPv4routes $node] { lappend cfg "ip route $statrte" } + foreach statrte [getStatIPv6routes $node] { + lappend cfg "ipv6 route $statrte" + } return $cfg } diff --git a/static.tcl b/static.tcl index a948592..9db3efb 100755 --- a/static.tcl +++ b/static.tcl @@ -55,7 +55,10 @@ proc $MODULE.cfggen { node } { lappend cfg "" foreach statrte [getStatIPv4routes $node] { - lappend cfg "route add $statrte" + lappend cfg "route add -inet $statrte" + } + foreach statrte [getStatIPv6routes $node] { + lappend cfg "route add -inet6 $statrte" } return $cfg diff --git a/xorp.tcl b/xorp.tcl index 4614f01..8f7807b 100755 --- a/xorp.tcl +++ b/xorp.tcl @@ -70,22 +70,35 @@ proc $MODULE.cfggen { node } { lappend cfg "}" lappend cfg "" - set statrtes [getStatIPv4routes $node] - if { $statrtes != "" } { - lappend cfg "protocols {" - lappend cfg " static {" - foreach rte $statrtes { - set dest [lindex $rte 0] - set gw [lindex $rte 1] - lappend cfg " route4 $dest {" - lappend cfg " next-hop: $gw" - lappend cfg " metric: 0" - lappend cfg " }" + lappend cfg "protocols {" + lappend cfg " static {" + foreach rte [getStatIPv4routes $node] { + set dest [lindex $rte 0] + set gw [lindex $rte 1] + set metric [lindex $rte 2] + if { $metric == "" } { + set metric 0 } - lappend cfg " }" - lappend cfg "}" - lappend cfg "" + lappend cfg " route4 $dest {" + lappend cfg " next-hop: $gw" + lappend cfg " metric: $metric" + lappend cfg " }" } + foreach rte [getStatIPv6routes $node] { + set dest [lindex $rte 0] + set gw [lindex $rte 1] + set metric [lindex $rte 2] + if { $metric == "" } { + set metric 0 + } + lappend cfg " route6 $dest {" + lappend cfg " next-hop: $gw" + lappend cfg " metric: $metric" + lappend cfg " }" + } + lappend cfg " }" + lappend cfg "}" + lappend cfg "" if { [netconfFetchSection $node "router rip"] != "" } { lappend cfg "protocols {"