chiark / gitweb /
stest: Allow SECNET_STEST_DIVERT_*='i <some stuff>'
[secnet.git] / stest / common.tcl
index bc00d22297ff0e9f2e2f0d0cdf902874e10c1544..7ebe9d2babab83b8b00954d46a5a508c896aa019 100644 (file)
@@ -28,6 +28,8 @@ set extra(outside) {}
 set privkey(inside) test-example/inside.privkeys/
 set privkey(outside) test-example/outside.privkeys/
 
+set initiator inside
+
 proc sitesconf_hook {l} { return $l }
 
 proc oldsecnet {site} {
@@ -97,6 +99,12 @@ exec cat
                key-cache priv-cache({
                    privkeys \"$builddir/${privkey}priv.\";
                 });
+"
+       }
+       {load-private *} {
+           set sitesconf sites-nonego.conf
+           append cfg "
+               local-key load-private(\"[lindex $privkey 1]\",\"$builddir/[lindex $privkey 2]\");
 "
        }
        * {
@@ -178,19 +186,26 @@ proc spawn-secnet {location site} {
            *PRELOAD* { puts -nonewline " $k=$env($k)" }
        }
     }
-    puts " $argl"
     if {[info exists env($divertk)]} {
        switch -glob $env($divertk) {
-           i {
+           i - {i *} {
+               regsub {^i} $env($divertk) {} divert_prefix
+               puts "$divert_prefix $argl"
                puts -nonewline "run ^ command, hit return "
                flush stdout
                gets stdin
                set argl {}
            }
            0 - "" {
+               puts " $argl"
            }
-           * {
+           /* - ./* {
+               puts " $argl"
                set argl [split $env($divertk)]
+               puts "... $argl"
+           }
+           * {
+               error "$divertk not understood"
            }
        }
     }
@@ -225,9 +240,10 @@ proc netlink-readable {location site} {
 }
 
 proc netlink-got-packet {location site data} {
+    global initiator
     if {![hbytes length $data]} return 
-    switch -exact $site {
-       inside {
+    switch -exact $site!$initiator {
+       inside!inside - outside!outside {
            switch -glob $data {
                45000054ed9d4000fe0166d9ac12e802ac12e80900* {
                    puts "OK $data"
@@ -238,8 +254,8 @@ proc netlink-got-packet {location site data} {
                }
            }
        }
-       outside {
-           error "inside rx'd!"
+       default {
+           error "$site rx'd! (initiator $initiator)"
        }
     }
 }
@@ -261,6 +277,7 @@ $message
 
 proc sendpkt {} {
     global netlinkfh
+    global initiator
     set p {
         4500 0054 ed9d 4000 4001 24da ac12 e809
         ac12 e802 0800 1de4 2d96 0001 f1d4 a05d
@@ -269,7 +286,7 @@ proc sendpkt {} {
         2425 2627 2829 2a2b 2c2d 2e2f 3031 3233
         3435 3637
     }
-    puts -nonewline $netlinkfh(inside.t) \
+    puts -nonewline $netlinkfh($initiator.t) \
        [hbytes h2raw c0[join $p ""]c0]
 }
 
@@ -339,14 +356,20 @@ 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
+}
+
 proc test-kex {} {
     udp-proxy
     spawn-secnet in inside
     spawn-secnet out outside
 
-    after 500 sendpkt
-    after 1000 sendpkt
-    after 5000 timed-out
+    adj-after 500 sendpkt
+    adj-after 1000 sendpkt
+    adj-after 5000 timed-out
 
     vwait ok
 }