chiark / gitweb /
changelog: start 0.6.8
[secnet.git] / stest / common.tcl
index 5895568b9a32ef7fdc8f3d6bdbc2d8beddc10c85..3c3bc1c0bbbccd2421b47fa6593e771587c111dc 100644 (file)
@@ -1,3 +1,8 @@
+# This file is part of secnet.
+# See LICENCE and this file CREDITS for full list of copyright holders.
+# SPDX-License-Identifier: GPL-3.0-or-later
+# There is NO WARRANTY.
+
 source test-common.tcl
 
 package require Tclx
@@ -19,6 +24,11 @@ set netlink(outside) {
 set ports(inside) {16913 16910}
 set ports(outside) 16900
 
+set defnet_v4 198.51.100
+set defnet_v6 2001:db8:ff00
+set defaddr_v4 ${defnet_v4}.1
+set defaddr_v6 ${defnet_v6}::1
+
 set extra(inside) {
     local-mobile True;
     mtu-target 1260;
@@ -44,6 +54,7 @@ proc mkconf {location site} {
     global ports
     global extra
     global netlinkfh
+    global defaddr_v4 defaddr_v6
     upvar #0 privkey($site) privkey
     set pipefp $tmp/$site.netlink
     foreach tr {t r} {
@@ -83,7 +94,7 @@ exec cat
        append cfg "$delim
            udp {
                 port $port;
-                address \"::1\", \"127.0.0.1\";
+                address \"$defaddr_v6\", \"$defaddr_v4\";
                buffer sysbuffer(4096);
            }
        "
@@ -145,6 +156,8 @@ exec cat
     set f [open $sitesconf r]
     while {[gets $f l] >= 0} {
        regsub {\"[^\"]*test-example/pubkeys/} $l "\"$pubkeys/" l
+       regsub -all {\"\[127\.0\.0\.1\]\"} $l "\"\[$defaddr_v4\]\"" l
+       regsub -all {\"\[::1]\"}           $l "\"\[$defaddr_v6\]\"" l
        set l [sitesconf_hook $l]
        append cfg $l "\n"
     }
@@ -177,29 +190,39 @@ proc spawn-secnet {location site} {
     }
     set argl [list $secnet -dvnc $cf]
     set divertk SECNET_STEST_DIVERT_$site
-    puts -nonewline "spawn"
+    set spawn_info "spawn:"
     foreach k [array names env] {
        switch -glob $k {
            SECNET_STEST_DIVERT_* -
            SECNET_TEST_BUILDDIR - OLD_SECNET_DIR { }
            *SECNET* -
-           *PRELOAD* { puts -nonewline " $k=$env($k)" }
+           *PRELOAD* { append spawn_info " $k=$env($k)" }
        }
     }
-    puts " $argl"
     if {[info exists env($divertk)]} {
-       switch -glob $env($divertk) {
-           i {
-               puts -nonewline "run ^ command, hit return "
-               flush stdout
-               gets stdin
-               set argl {}
-           }
-           0 - "" {
-           }
-           * {
-               set argl [split $env($divertk)]
-           }
+       set divert $env($divertk)
+    } else {
+       set divert {}
+    }
+    switch -glob $divert {
+       i - {i *} {
+           regsub {^i} $divert {} divert_prefix
+           puts "$spawn_info $divert_prefix $argl"
+           puts -nonewline "run ^ command, hit return "
+           flush stdout
+           gets stdin
+           set argl {}
+       }
+       0 - "" {
+           puts "$spawn_info $argl"
+       }
+       /* - ./* {
+           puts "$spawn_info $argl"
+           set argl [split $divert]
+           puts "... $argl"
+       }
+       * {
+           error "$divertk not understood"
        }
     }
     if {[llength $argl]} { 
@@ -350,6 +373,8 @@ proc udp-relay {data src sock args} {
 }
 
 proc adj-after {timeout args} {
+    upvar #0 env(SECNET_STEST_TIMEOUT_MUL) mul
+    if {[info exists mul]} { set timeout [expr {$timeout * $mul}] }
     eval after $timeout $args
 }