X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/3fe0fc3a60fc3f29ee40b8474192a585a5eeaaa0..db11df9356902bc290083a54e895cdca5f7bf1e3:/proxy/tripe-mitm.c?ds=sidebyside
diff --git a/proxy/tripe-mitm.c b/proxy/tripe-mitm.c
index 3686b7ba..bd57306d 100644
--- a/proxy/tripe-mitm.c
+++ b/proxy/tripe-mitm.c
@@ -9,19 +9,18 @@
*
* This file is part of Trivial IP Encryption (TrIPE).
*
- * TrIPE is free software; you can redistribute it and/or modify
- * 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 free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 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.
+ * 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.
+ * along with TrIPE. If not, see .
*/
/*----- Header files ------------------------------------------------------*/
@@ -67,11 +66,12 @@
#include
#include
+#include "util.h"
+
/*----- Data structures ---------------------------------------------------*/
typedef struct peer {
sel_file sf;
- dh_pub kpub;
const char *name;
struct filter *f;
} peer;
@@ -116,26 +116,20 @@ static void dopacket(int fd, unsigned mode, void *vv)
static void addpeer(unsigned ac, char **av)
{
- key_packstruct kps[DH_PUBFETCHSZ];
- key_packdef *kp;
struct hostent *h;
struct sockaddr_in sin;
int len = PKBUFSZ;
peer *p;
int fd;
- int e;
if (ac != 4)
die(1, "syntax: peer:NAME:PORT:ADDR:PORT");
if (npeer >= 2)
die(1, "enough peers already");
+ if (!key_bytag(&keys, av[0]))
+ die(1, "no key named `%s'", av[0]);
p = &peers[npeer++];
p->name = xstrdup(av[0]);
- kp = key_fetchinit(dh_pubfetch, kps, &p->kpub);
- e = key_fetchbyname(kp, &keys, av[0]);
- key_fetchdone(kp);
- if (e)
- die(1, "key_fetch `%s': %s", av[0], key_strerror(e));
if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
die(1, "socket: %s", strerror(errno));
fdflags(fd, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC);
@@ -255,7 +249,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 +259,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 +401,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)
@@ -406,10 +430,8 @@ static void adddelay(filter *f, unsigned ac, char **av)
static void dosend(filter *f, const octet *buf, size_t sz)
{
- int hunoz;
-
printf("send to `%s'\n", f->p_to->name);
- hunoz = 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 +448,7 @@ const struct filtab {
{ "send", addsend },
{ "fork", addfork },
{ "delay", adddelay },
+ { "drop", adddrop },
{ "corrupt", addcorrupt },
{ 0, 0 }
};
@@ -633,6 +656,7 @@ Filters:\n\
send\n\
fork:TAG\n\
delay:QLEN[:MILLIS:P-REPLAY]\n\
+ drop[:P-DROP]\n\
corrupt[:P-CORRUPT]\n",
fp);
}
@@ -690,8 +714,10 @@ int main(int argc, char *argv[])
parse(argv[i]);
if (npeer != 2)
die(1, "need two peers");
- for (;;)
- sel_select(&sel);
+ for (;;) {
+ if (sel_select(&sel) && errno != EINTR)
+ die(1, "select failed: %s", strerror(errno));
+ }
#undef f_bogus
}