X-Git-Url: https://git.distorted.org.uk/~mdw/userv-utils/blobdiff_plain/244a0e991c9286152f4e8c2252249088c5461c67..935da5a413575e01bc3273bb93b2efacbbe47759:/ipif/forwarder.c?ds=sidebyside diff --git a/ipif/forwarder.c b/ipif/forwarder.c index 0112d90..f901f78 100644 --- a/ipif/forwarder.c +++ b/ipif/forwarder.c @@ -1,14 +1,15 @@ /* * Encrypting tunnel for userv-ipif tunnels, actual implementation - * + */ +/* * usage: * udptunnel-forwarder * * * * [] - * ! [ ...] - * ! [ ...] + * | [ ...] + * | [ ...] * '' * * Remote addr may '' to mean wait to receive a packet and reply to @@ -19,6 +20,10 @@ * w means generate and write encdec keys, rather than reading them * K means do crypto debug (use with care!) * + * encdec keys datastream has keys for packets from key datastream + * writer to reader first, then keys for packets from reader to + * writer. + * * Every must be numeric. There is very little argument checking. * * Exit status: @@ -29,6 +34,23 @@ * 12 usage error * 16 bad trouble */ +/* + * Copyright (C) 2000 Ian Jackson + * + * This 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. + * + * This program 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 userv-utils; if not, write to the Free Software + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ #include #include @@ -71,8 +93,8 @@ static time_t nextsendka; static void cdebug(int mechno /*or -1*/, const char *msg) { if (!crypto_debug) return; - printf("%s: CRYPTO: %-20s %s\n", - programid, + printf("%-8.8s: CRYPTO: %-20s %s\n", + uname_result.nodename, mechno >= 0 ? mechs[mechno]->name : "", msg); } @@ -127,6 +149,7 @@ void random_key(void *ptr, size_t sz) { write_must(encdec_keys_fd,ptr,sz,"write keys datastream"); } else { read_must(encdec_keys_fd,ptr,sz,"read keys datastream"); + cdebughex(-1, "random_key", ptr, sz, 0,0,0); } } @@ -186,7 +209,9 @@ static void inbound(void) { for (i=n_mechs-1; i>=0; i--) { emsg= mechs[i]->decode(md_in[i],&buf_in); if (emsg) { - fprintf(stderr, "%s: bad packet: %s: %s\n", programid, mechs[i]->name, emsg); + if (*emsg) + fprintf(stderr, "%s: bad packet: %s: %s\n", + programid, mechs[i]->name, emsg); return; } cdebugbuf(i, "decode", &buf_in, 3,0); @@ -335,18 +360,26 @@ int main(int argc, const char *const *const argv_in) { maxprefix= 0; i= 0; while ((arg= *++argv)) { - arg_assert(*arg++ == '!'); + arg_assert(*arg++ == '|'); arg_assert(i <= MAXMECHS); mechs[i]= find_mech(arg); - cdebug(i,"encsetup"); + cdebug(i,"writer->reader setup"); argv_save= argv; - mechs[i]->encsetup(&md_in[i], &maxprefix, &maxsuffix); + + if (encdec_keys_write) + mechs[i]->encsetup(&md_out[i], &maxprefix, &maxsuffix); + else + mechs[i]->decsetup(&md_in[i]); argv_done= argv; argv= argv_save; - cdebug(i,"decsetup"); - mechs[i]->decsetup(&md_out[i]); + cdebug(i,"reader->writer setup"); + + if (encdec_keys_write) + mechs[i]->decsetup(&md_in[i]); + else + mechs[i]->encsetup(&md_out[i], &maxprefix, &maxsuffix); assert(argv == argv_done);