chiark / gitweb /
build, debian: Add a suffix to the main TrIPE-specific manpages.
[tripe] / proxy / tripe-mitm.c
index 107362eed6bfb1ca1488cd03e6ddd088316f903f..a9f84914cf0a9a7e1690030ad4e0ec2906b2bf7c 100644 (file)
@@ -1,13 +1,11 @@
 /* -*-c-*-
- *
- * $Id$
  *
  * An evil proxy for TrIPE
  *
  * (c) 2001 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of Trivial IP Encryption (TrIPE).
  *
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * TrIPE is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with TrIPE; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -69,6 +67,8 @@
 #include <catacomb/rand.h>
 #include <catacomb/rc4.h>
 
+#include "util.h"
+
 /*----- Data structures ---------------------------------------------------*/
 
 typedef struct peer {
@@ -257,7 +257,7 @@ static void addcorrupt(filter *f, unsigned ac, char **av)
 {
   corrupt *c;
   if (ac > 1)
-    die(1, "syntax: filt:corrupt[:PCORRUPT]");
+    die(1, "syntax: filt:corrupt[:P-CORRUPT]");
   c = CREATE(corrupt);
   if (ac > 0)
     c->p_corrupt = atoi(av[0]);
@@ -267,6 +267,36 @@ static void addcorrupt(filter *f, unsigned ac, char **av)
   f->func = docorrupt;
 }
 
+/*----- Drop filter -------------------------------------------------------*/
+
+typedef struct drop {
+  unsigned p_drop;
+} drop;
+
+static void dodrop(filter *f, const octet *buf, size_t sz)
+{
+  drop *d = f->state;
+
+  if (!RND(d->p_drop))
+    puts("drop packet");
+  else
+    PASS(f->next, buf, sz);
+}
+
+static void adddrop(filter *f, unsigned ac, char **av)
+{
+  drop *d;
+  if (ac > 1)
+    die(1, "syntax: filt:drop[:P-DROP]");
+  d = CREATE(drop);
+  if (ac > 0)
+    d->p_drop = atoi(av[0]);
+  else
+    d->p_drop = 5;
+  f->state = d;
+  f->func = dodrop;
+}
+
 /*----- Delay filter ------------------------------------------------------*/
 
 typedef struct delaynode {
@@ -379,7 +409,7 @@ static void adddelay(filter *f, unsigned ac, char **av)
   unsigned i;
 
   if (ac < 1 || ac > 3)
-    die(1, "syntax: filt:delay:QLEN[:MILLIS:PREPLAY]");
+    die(1, "syntax: filt:delay:QLEN[:MILLIS:P-REPLAY]");
   d = CREATE(delay);
   d->max = atoi(av[0]);
   if (ac > 1)
@@ -409,7 +439,7 @@ static void adddelay(filter *f, unsigned ac, char **av)
 static void dosend(filter *f, const octet *buf, size_t sz)
 {
   printf("send to `%s'\n", f->p_to->name);
-  write(f->p_to->sf.fd, buf, sz);
+  DISCARD(write(f->p_to->sf.fd, buf, sz));
 }
 
 static void addsend(filter *f, unsigned ac, char **av)
@@ -426,6 +456,7 @@ const struct filtab {
   { "send",    addsend },
   { "fork",    addfork },
   { "delay",   adddelay },
+  { "drop",    adddrop },
   { "corrupt", addcorrupt },
   { 0,         0 }
 };
@@ -483,7 +514,7 @@ static void floodtimer(struct timeval *tv, void *vv)
   PASS(f->p->f, buf, sz);
   setflood(f);
 }
-  
+
 static void setflood(flood *f)
 {
   struct timeval tv;
@@ -633,6 +664,7 @@ Filters:\n\
   send\n\
   fork:TAG\n\
   delay:QLEN[:MILLIS:P-REPLAY]\n\
+  drop[:P-DROP]\n\
   corrupt[:P-CORRUPT]\n",
        fp);
 }