chiark / gitweb /
git-daemon: add Makefile and documentation.
[userv-utils.git] / ipif / forwarder.c
index f901f78deb4eb38d0f3840d497a07c06123f0674..66f869080117af064b4b80ed00921b34aabfbb8c 100644 (file)
@@ -1,12 +1,12 @@
 /*
- * Encrypting tunnel for userv-ipif tunnels, actual implementation
+ * Encrypting tunnel for userv-ipif tunnels, actual core implementation
  */
 /*
  * usage:
  *  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> ...]
@@ -24,7 +24,7 @@
  * writer to reader first, then keys for packets from reader to
  * writer.
  *
- * Every must be numeric.  There is very little argument checking.
+ * Every addr or port must be numeric.  There is very little argument checking.
  *
  * Exit status:
  *  SIGALARM   timed out
@@ -35,7 +35,8 @@
  *      16     bad trouble
  */
 /*
- * Copyright (C) 2000 Ian Jackson
+ * Copyright (C) 2000,2003 Ian Jackson
+ * This file is part of ipif, part of userv-utils
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by
@@ -75,7 +76,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 +179,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;
@@ -212,11 +215,15 @@ static void inbound(void) {
       if (*emsg)
        fprintf(stderr, "%s: bad packet: %s: %s\n",
                programid, mechs[i]->name, emsg);
+      else
+       cdebug(i,"silently discarded");
       return;
     }
     cdebugbuf(i, "decode", &buf_in, 3,0);
   }
 
+  npackets++;
+  nbytes += buf_in.size;
   alarm(timeout);
 
   different= (!public_remote_specd ||
@@ -243,8 +250,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) {
@@ -343,6 +364,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) {