X-Git-Url: https://git.distorted.org.uk/~mdw/userv-utils/blobdiff_plain/8f1bfa81e24978ace26d94f63abc1436fe685fe4..7729298ad653ba4e0b10bacc9f27d210b4eaf4e7:/ipif/udptunnel diff --git a/ipif/udptunnel b/ipif/udptunnel index 5b64b2b..09595d1 100755 --- a/ipif/udptunnel +++ b/ipif/udptunnel @@ -19,8 +19,8 @@ # , # , # ,,, -# , -# +# ,[,] +# # [ [ ...] ] # # proto may be slip or cslip @@ -41,8 +41,8 @@ # , # , # ,,, -# , -# +# ,[,] +# # # If it was given Print for , this command's first @@ -67,12 +67,13 @@ # # (-m not specified) (-m specified) # actual addr/port that addr/port `Wait' -# `Wait' the chosen address `Wait' # `Print' the chosen address `Wait' +# `Any' `Wait' for addr, `Wait' +# chosen port for port # # udptunnel will userv ipif locally, as # userv root ipif ,,, -# +# # or, if -l was given, userv root ipif is replaced with the argument(s) # following -l option(s) until `.'. # @@ -170,8 +171,6 @@ sub arg_value ($$) { return shift @ARGV; } -$|=1; - @lcmd= (); @encryption= (); $masq= 0; @@ -228,8 +227,16 @@ m/^([.0-9]+),([.0-9]+),(\d+),(slip|cslip)$/ ($lva,$rva,$mtu,$proto) = ($1,$2,$3,$4); $_= shift @ARGV; -m/^(\d+),(\d+)$/ or quit("keepalive,timeout missing or bad syntax"); -($keepalive,$timeout)= ($1,$2); +if (m/^(\d+),(\d+)$/) { + ($keepalive,$timeout,$reannounce)= ($1+0,$2+0,0); + $ka_to_ra= "$keepalive,$timeout"; +} elsif (m/^(\d+),(\d+),(\d+)$/) { + ($keepalive,$timeout,$reannounce)= ($1+0,$2+0,$3); + "$keepalive,$timeout", + $ka_to_ra= "$keepalive,$timeout,$reannounce"; +} else { + quit("keepalive,timeout missing or bad syntax"); +} $keepalive && ($timeout > $keepalive*2) or quit("timeout must be < 2*keepalive") if $timeout; @@ -268,15 +275,14 @@ if (@ARGV) { @rcmd= (@ARGV, @remoteopts, "$rad,$rpd", - $masq ? 'Wait,Wait' : $lapd, + $masq ? 'Wait,Wait' : $las eq 'Any' ? "Wait,$lpd" : $lapd, "$rva,$lva,$mtu,$proto", - "$keepalive,$timeout", + $ka_to_ra, $rexn, $lexn); debug("remote command @rcmd"); if ($rapcmd) { pipe(RAPREAD,RCMDREADSUB) or fail("pipe"); - select(RCMDREADSUB); $|=1; select(STDOUT); } pipe(RCMDWRITESUB,DUMPKEYS) or fail("pipe"); defined($c_rcmd= fork) or fail("fork for remote"); @@ -295,30 +301,33 @@ if (@ARGV) { if ($rapcmd) { close RCMDREADSUB if $rapcmd; - $!=0; $_= ; $e="$!"; + $_= ''; + while (!m/\n/) { + $!=0; + defined($nread= sysread(RAPREAD,$_,1,length)) + or fail("read from remote command"); + if (!$nread) { + close DUMPKEYS; + close RAPREAD; + waitpid $c_rcmd,0 or fail("wait for remote command"); + quit($? ? "remote command failed (code $?)" : + "no details received from remote"); + } + } + chomp; + m/^([.0-9]+)\,(\d+)$/ or quit("invalid details from remote end: \`$_'"); + ($rar,$rpr) = ($1,$2); + $ra= conv_host_addr($rar); + $rp= conv_port_number($rpr); defined($c_catremdebug= fork) or fail("fork for cat remote debug"); if (!$c_catremdebug) { open(STDIN,"<&RAPREAD") or fail("redirect remote debug"); - close RAPREAD; close DUMPKEYS; close L; exec "cat"; fail("execute cat"); } close RAPREAD; - - if (!length) { - close DUMPKEYS; - waitpid $c_rcmd,0 or fail("wait for remote command"); - quit($? ? "remote command failed (code $?)" : - $e ? "read error from remote command: $e" : - "no details received from remote"); - } - chomp; - m/^([.0-9]+)\,(\d+)$/ or quit("invalid details from remote end: \`$_'"); - ($rar,$rpr) = ($1,$2); - $ra= conv_host_addr($rar); - $rp= conv_port_number($rpr); } } elsif ($dump) { open DUMPKEYS, ">&STDOUT" or fail("reopen stdout for key material"); @@ -360,7 +369,7 @@ $xfwdopts.= 'w' if $dump; @fcmd= ($fcmd, $xfwdopts, fileno(L), fileno(DW), fileno(UR), fileno(DUMPKEYS), - $mtu, $keepalive, $timeout, + $mtu, $keepalive, $timeout, $reannounce, @rapf, @encryption); debug("forwarding command @fcmd.");