chiark / gitweb /
tripe-admin manpage: Generate a command and message summary.
[tripe] / tripe.c
diff --git a/tripe.c b/tripe.c
index 180177ee66450b8876ff63f3b9fe064017a616d3..be37617a1e57204778fc93f87e2c11cd63fba284 100644 (file)
--- a/tripe.c
+++ b/tripe.c
@@ -51,7 +51,7 @@ static sel_timer it;
  * Use:                Called periodically to do housekeeping tasks.
  */
 
-void interval(struct timeval *tv, void *v)
+static void interval(struct timeval *tv, void *v)
 {
   struct timeval tvv;
   T( trace(T_PEER, "peer: interval timer"); )
@@ -62,6 +62,23 @@ void interval(struct timeval *tv, void *v)
   sel_addtimer(&sel, &it, &tvv, interval, v);
 }
 
+/* --- @mystrieq@ --- *
+ *
+ * Arguments:  @const char *x, *y@ = two strings
+ *
+ * Returns:    True if @x@ and @y are equal, up to case.
+ */
+
+int mystrieq(const char *x, const char *y)
+{
+  for (;;) {
+    if (!*x && !*y) return (1);
+    if (tolower((unsigned char)*x) != tolower((unsigned char)*y))
+      return (0);
+    x++; y++;
+  }
+}
+
 /* --- @main@ --- *
  *
  * Arguments:  @int argc@ = number of command line arguments
@@ -74,7 +91,7 @@ void interval(struct timeval *tv, void *v)
 
 static void usage(FILE *fp)
 {
-  pquis(fp, "Usage: $ [-D] [-d DIR] [-b ADDR] [-p PORT]\n\
+  pquis(fp, "Usage: $ [-D] [-d DIR] [-b ADDR] [-p PORT] [-n TUNNEL]\n\
        [-U USER] [-G GROUP] [-a SOCKET] [-T TRACE-OPTS]\n\
        [-k PRIV-KEYRING] [-K PUB-KEYRING] [-t KEY-TAG]\n");
 }
@@ -95,12 +112,13 @@ Options:\n\
 -h, --help             Display this help text.\n\
 -v, --version          Display version number.\n\
 -u, --usage            Display pointless usage message.\n\
-    --tunnel           Display IP tunnelling technique and exit.\n\
+    --tunnels          Display IP tunnel drivers and exit.\n\
 \n\
 -D, --daemon           Run in the background.\n\
 -d, --directory=DIR    Switch to directory DIR [default " CONFIGDIR "].\n\
 -b, --bind-address=ADDR        Bind UDP socket to this IP ADDR.\n\
 -p, --port=PORT                Select UDP port to listen to.\n\
+-n, --tunnel=TUNNEL    Seelect default tunnel driver.\n\
 -U, --setuid=USER      Set uid to USER after initialization.\n\
 -G, --setgid=GROUP     Set gid to GROUP after initialization.\n\
 -k, --priv-keyring=FILE        Get private key from FILE.\n\
@@ -123,6 +141,9 @@ int main(int argc, char *argv[])
   unsigned port = 0;
   struct in_addr baddr = { INADDR_ANY };
   unsigned f = 0;
+  int i;
+  int selerr = 0;
+  struct timeval tv;
   uid_t u = -1;
   gid_t g = -1;
 
@@ -134,12 +155,14 @@ int main(int argc, char *argv[])
 
   if ((p = getenv("TRIPEDIR")) != 0)
     dir = p;
+  tun_default = tunnels[0];
 
   for (;;) {
     static const struct option opts[] = {
       { "help",                0,              0,      'h' },
       { "version",     0,              0,      'v' },
       { "usage",       0,              0,      'u' },
+      { "tunnels",     0,              0,      '0' },
 
       { "daemon",      0,              0,      'D' },
       { "uid",         OPTF_ARGREQ,    0,      'U' },
@@ -147,6 +170,7 @@ int main(int argc, char *argv[])
       { "gid",         OPTF_ARGREQ,    0,      'G' },
       { "setgid",      OPTF_ARGREQ,    0,      'G' },
       { "bind-address",        OPTF_ARGREQ,    0,      'b' },
+      { "tunnel",      OPTF_ARGREQ,    0,      'n' },
       { "port",                OPTF_ARGREQ,    0,      'p' },
       { "directory",   OPTF_ARGREQ,    0,      'd' },
       { "priv-keyring",        OPTF_ARGREQ,    0,      'k' },
@@ -157,12 +181,11 @@ int main(int argc, char *argv[])
       { "trace",       OPTF_ARGREQ,    0,      'T' },
 #endif
 
-      { "tunnel",      0,              0,      '0' },
       { 0,             0,              0,      0 }
     };
 
-    int i = mdwopt(argc, argv, "hvuDU:G:b:p:d:k:K:t:a:" T("T:"),
-                  opts, 0, 0, 0);
+    i = mdwopt(argc, argv, "hvuDU:G:b:p:d:k:K:t:a:" T("T:"),
+              opts, 0, 0, 0);
     if (i < 0)
       break;
     switch (i) {
@@ -225,6 +248,16 @@ int main(int argc, char *argv[])
          die(EXIT_FAILURE, "bad port number %lu", i);
        port = i;
       } break;
+      case 'n': {
+       int i;
+       for (i = 0;; i++) {
+         if (!tunnels[i])
+           die(EXIT_FAILURE, "unknown tunnel `%s'", optarg);
+         if (mystrieq(optarg, tunnels[i]->name))
+           break;
+       }
+       tun_default = tunnels[i];
+      } break;
       case 'd':
        dir = optarg;
        break;
@@ -247,9 +280,9 @@ int main(int argc, char *argv[])
        break;
 #endif
       case '0': {
-       static const char *tun[] =
-         { "notdef", "unet", "bsd", "linux", "slip" };
-       puts(tun[TUN_TYPE]);
+       int i;
+       for (i = 0; tunnels[i]; i++)
+         puts(tunnels[i]->name);
        exit(0);
       } break;
       default:
@@ -273,7 +306,8 @@ int main(int argc, char *argv[])
   rand_noisesrc(RAND_GLOBAL, &noise_source);
   rand_seed(RAND_GLOBAL, MAXHASHSZ);
   signal(SIGPIPE, SIG_IGN);
-  tun_init();
+  for (i = 0; tunnels[i]; i++)
+    tunnels[i]->init();
   p_init(baddr, port);
   if (!(f & f_daemon)) {
 #ifndef NTRACE
@@ -302,25 +336,19 @@ int main(int argc, char *argv[])
     a_daemon();
   }
 
-  {
-    struct timeval tv;
-    tv.tv_sec = time(0) + T_INTERVAL;
-    tv.tv_usec = 0;
-    sel_addtimer(&sel, &it, &tv, interval, 0);
-  }
+  tv.tv_sec = time(0) + T_INTERVAL;
+  tv.tv_usec = 0;
+  sel_addtimer(&sel, &it, &tv, interval, 0);
 
-  {
-    int selerr = 0;
-    for (;;) {
-      if (!sel_select(&sel))
-        selerr = 0;
-      else if (errno != EINTR && errno != EAGAIN) {
-       a_warn("SERVER select-error -- %s", strerror(errno));
-       selerr++;
-       if (selerr > 8) {
-         a_warn("ABORT repeated-select-errors");
-         abort();
-       }
+  for (;;) {
+    if (!sel_select(&sel))
+      selerr = 0;
+    else if (errno != EINTR && errno != EAGAIN) {
+      a_warn("SERVER", "select-error", "?ERRNO", A_END);
+      selerr++;
+      if (selerr > 8) {
+       a_warn("ABORT", "repeated-select-errors", A_END);
+       abort();
       }
     }
   }