chiark / gitweb /
Print "still open" messages. userv-utils-0-1-finger-mergeup-1
authorian <ian>
Fri, 9 Jun 2000 20:27:14 +0000 (20:27 +0000)
committerian <ian>
Fri, 9 Jun 2000 20:27:14 +0000 (20:27 +0000)
ipif/forwarder.c
ipif/udptunnel

index 6179eaa..793ad24 100644 (file)
@@ -6,7 +6,7 @@
  *  udptunnel-forwarder <optchars>
  *                      <public-local-fd> <private-in-fd> <private-out-fd>
  *                      <encdec-keys-fd>
- *                      <mtu> <keepalive> <timeout>
+ *                      <mtu> <keepalive> <timeout> <reannounce>
  *                      <public-remote-addr> [<public-remote-port>]
  *                      |<mech1> [<mech1-params> ...]
  *                      |<mech2> [<mech2-params> ...]
@@ -75,7 +75,7 @@ static struct utsname uname_result;
 
 static const char *opt_chars;
 static int public_local_fd, private_in_fd, private_out_fd;
-static int mtu2, keepalive, timeout;
+static int mtu2, keepalive, timeout, reannounce;
 static int public_remote_specd;
 static struct sockaddr_in public_remote;
 static int encdec_keys_fd, encdec_keys_write, crypto_debug;
@@ -178,6 +178,8 @@ static const struct mechanism *find_mech(const char *name) {
 
 static void inbound(void) {
   static int any_recvd;
+  static time_t nextreann;
+  static unsigned long npackets, nbytes;
   
   struct sockaddr_in this_saddr;
   int r, i, different, this_saddrlen;
@@ -219,6 +221,8 @@ static void inbound(void) {
     cdebugbuf(i, "decode", &buf_in, 3,0);
   }
 
+  npackets++;
+  nbytes += buf_in.size;
   alarm(timeout);
 
   different= (!public_remote_specd ||
@@ -245,8 +249,22 @@ static void inbound(void) {
 
     diag("tunnel open");
 
+  } else if (reannounce && now() >= nextreann) {
+
+    fprintf(stderr, "%s: tunnel still open: received %lu packets, %lu bytes\n",
+           programid, npackets, nbytes);
+
+  } else {
+
+    goto no_set_reann; /* only reset this if we don't print a message. */
+
   }
 
+  if (reannounce)
+    nextreann= now() + reannounce;
+  
+no_set_reann:
+
   any_recvd= 1;
 
   if (!buf_in.size || *buf_in.start != 0300) {
@@ -345,6 +363,7 @@ int main(int argc, const char *const *const argv_in) {
   mtu2= getarg_ulong() * 2;
   keepalive= getarg_ulong();
   timeout= getarg_ulong();
+  reannounce= getarg_ulong();
   
   arg= getarg_string();
   if (*arg) {
index 720517b..09595d1 100755 (executable)
@@ -19,7 +19,7 @@
 #            <public-local-addr>,<public-local-port>
 #            <public-remote-addr>,<public-remote-port>
 #            <private-local-addr>,<private-remote-addr>,<mtu>,<proto>
-#            <keepalive>,<timeout>
+#            <keepalive>,<timeout>[,<reannounce>]
 #            <extra-nets-for-local-cmd> <extra-nets-for-remote-cmd>
 #          [ <remote-command> [<remote-args> ...] ]
 #
@@ -41,7 +41,7 @@
 #                     <public-remote-addr'>,<public-remote-port'>
 #                     <public-local-addr'>,<public-local-port'>
 #                     <private-remote-addr>,<private-local-addr>,<mtu>,<proto>
-#                     <keepalive>,<timeout>
+#                     <keepalive>,<timeout>[,<reannounce>]
 #                     <extra-nets-for-remote-cmd> <extra-nets-for-local-cmd>
 #
 
@@ -227,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;
 
@@ -269,7 +277,7 @@ if (@ARGV) {
            "$rad,$rpd",
            $masq ? 'Wait,Wait' : $las eq 'Any' ? "Wait,$lpd" : $lapd,
            "$rva,$lva,$mtu,$proto",
-           "$keepalive,$timeout",
+           $ka_to_ra,
            $rexn, $lexn);
     debug("remote command @rcmd");
 
@@ -361,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.");