X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=stest%2Fcommon.tcl;h=89045a5147b5fb46206385be1c0afb8ab25bff91;hb=5406775a50f7afb6df1c6c0820557d1a025973cc;hp=d6250c3b7b14df30ce86ba677d62407d1a1b9054;hpb=9a54ddbe3df3fbc7b63a9b92646293d5f31609e6;p=secnet.git diff --git a/stest/common.tcl b/stest/common.tcl index d6250c3..89045a5 100644 --- a/stest/common.tcl +++ b/stest/common.tcl @@ -25,6 +25,11 @@ set extra(inside) { } set extra(outside) {} +set privkey(inside) test-example/inside.privkeys/ +set privkey(outside) test-example/outside.privkeys/ + +proc sitesconf_hook {l} { return $l } + proc mkconf {location site} { global tmp global builddir @@ -32,6 +37,7 @@ proc mkconf {location site} { global ports global extra global netlinkfh + upvar #0 privkey($site) privkey set pipefp $tmp/$site.netlink foreach tr {t r} { file delete $pipefp.$tr @@ -54,6 +60,7 @@ exec cat " close $fakeuh set cfg " + hash sha1; netlink userv-ipif { name \"netlink\"; userv-path \"$fakeuf\"; @@ -77,8 +84,25 @@ exec cat } append cfg "; local-name \"test-example/$location/$site\"; - local-key rsa-private(\"$builddir/test-example/$site.key\"); " + switch -glob $privkey { + */ { + set sitesconf sites.conf + append cfg " + key-cache priv-cache({ + privkeys \"$builddir/${privkey}priv.\"; + }); +" + } + * { + set sitesconf sites-nonego.conf + append cfg " + local-key rsa-private(\"$builddir/$privkey\"); +" + } + } + set sitesconf $builddir/test-example/$sitesconf + append cfg $extra($site) append cfg " log logfile { @@ -96,13 +120,23 @@ exec cat transform eax-serpent { }, serpent256-cbc { }; } - set f [open $builddir/test-example/sites.conf r] + set pubkeys $tmp/$site.pubkeys + file delete -force $pubkeys + exec cp -rl $builddir/test-example/pubkeys $pubkeys + + set f [open $sitesconf r] + while {[gets $f l] >= 0} { + regsub {\"[^\"]*test-example/pubkeys/} $l "\"$pubkeys/" l + set l [sitesconf_hook $l] + append cfg $l "\n" + } set sites [read $f] close $f append cfg $sites append cfg { sites map(site,all-sites); } + return $cfg } @@ -112,7 +146,9 @@ proc spawn-secnet {location site} { global netlinkfh global env global pidmap + global readbuf upvar #0 pids($site) pid + set readbuf($site) {} set cf $tmp/$site.conf set ch [open $cf w] puts $ch [mkconf $location $site] @@ -123,7 +159,7 @@ proc spawn-secnet {location site} { foreach k [array names env] { switch -glob $k { SECNET_STEST_DIVERT_* - - SECNET_TEST_BUILDDIR { } + SECNET_TEST_BUILDDIR - OLD_SECNET_DIR { } *SECNET* - *PRELOAD* { puts -nonewline " $k=$env($k)" } } @@ -156,12 +192,37 @@ proc spawn-secnet {location site} { proc netlink-readable {location site} { global ok + upvar #0 readbuf($site) buf upvar #0 netlinkfh($site.r) fh - read $fh; # empty the buffer + while 1 { + set x [read $fh] + set h [hbytes raw2h $x] + if {![hbytes length $h]} return + append buf $h + #puts "READABLE $site buf=$buf" + while {[regexp {^((?:..)*?)c0(.*)$} $buf dummy now buf]} { + #puts "READABLE $site now=$now (buf=$buf)" + regsub -all {^((?:..)*?)dbdc} $now {\1c0} now + regsub -all {^((?:..)*?)dbdd} $now {\1db} now + puts "netlink-got-packet $location $site $now" + netlink-got-packet $location $site $now + } + } +} + +proc netlink-got-packet {location site data} { + if {![hbytes length $data]} return switch -exact $site { inside { - puts OK - finish 0 + switch -glob $data { + 45000054ed9d4000fe0166d9ac12e802ac12e80900* { + puts "OK $data" + finish 0 + } + * { + error "unexpected $site $data" + } + } } outside { error "inside rx'd!" @@ -217,6 +278,21 @@ proc finish {estatus} { exit $estatus } +proc reap {} { + global pidmap + #puts stderr REAPING + foreach pid [array names pidmap] { + set got [wait -nohang $pid] + if {![llength $got]} continue + set info $pidmap($pid) + unset pidmap($pid) + puts stderr "reaped $info: $got" + finish 1 + } +} + +signal -restart trap SIGCHLD { after idle reap } + proc udp-proxy {} { global socktmp udpsock set u $socktmp/udp