X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/blobdiff_plain/53a941d3f97a50964587c6e9533b1e43e74a57a8..91ac51aa6d078ba287972988fc9cca6593bfbe8f:/proxy/tripe-mitm.c diff --git a/proxy/tripe-mitm.c b/proxy/tripe-mitm.c index 7394aaaa..eb1c7fd2 100644 --- a/proxy/tripe-mitm.c +++ b/proxy/tripe-mitm.c @@ -67,6 +67,8 @@ #include #include +#include "util.h" + /*----- Data structures ---------------------------------------------------*/ typedef struct peer { @@ -255,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]); @@ -265,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 { @@ -377,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) @@ -407,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); + IGNORE(write(f->p_to->sf.fd, buf, sz)); } static void addsend(filter *f, unsigned ac, char **av) @@ -424,6 +456,7 @@ const struct filtab { { "send", addsend }, { "fork", addfork }, { "delay", adddelay }, + { "drop", adddrop }, { "corrupt", addcorrupt }, { 0, 0 } }; @@ -631,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); }