chiark
/
gitweb
/
~ian
/
userv-utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ipif: "include" looks for the file in the directory where "include" appears
[userv-utils.git]
/
ipif
/
forwarder.c
diff --git
a/ipif/forwarder.c
b/ipif/forwarder.c
index 6179eaa0b94fc6e53f4753f274599c676960c562..d92fdd9294dc34842a0d4257895384937e996975 100644
(file)
--- a/
ipif/forwarder.c
+++ b/
ipif/forwarder.c
@@
-1,12
+1,12
@@
/*
/*
- * Encrypting tunnel for userv-ipif tunnels, actual implementation
+ * Encrypting tunnel for userv-ipif tunnels, actual
core
implementation
*/
/*
* usage:
* udptunnel-forwarder <optchars>
* <public-local-fd> <private-in-fd> <private-out-fd>
* <encdec-keys-fd>
*/
/*
* usage:
* udptunnel-forwarder <optchars>
* <public-local-fd> <private-in-fd> <private-out-fd>
* <encdec-keys-fd>
- * <mtu> <keepalive> <timeout>
+ * <mtu> <keepalive> <timeout>
<reannounce>
* <public-remote-addr> [<public-remote-port>]
* |<mech1> [<mech1-params> ...]
* |<mech2> [<mech2-params> ...]
* <public-remote-addr> [<public-remote-port>]
* |<mech1> [<mech1-params> ...]
* |<mech2> [<mech2-params> ...]
@@
-24,7
+24,7
@@
* writer to reader first, then keys for packets from reader to
* writer.
*
* writer to reader first, then keys for packets from reader to
* writer.
*
- * Every must be numeric. There is very little argument checking.
+ * Every
addr or port
must be numeric. There is very little argument checking.
*
* Exit status:
* SIGALARM timed out
*
* Exit status:
* SIGALARM timed out
@@
-35,11
+35,17
@@
* 16 bad trouble
*/
/*
* 16 bad trouble
*/
/*
- * Copyright (C) 2000 Ian Jackson
+ * This file is part of ipif, part of userv-utils
+ *
+ * Copyright 1996-2013 Ian Jackson <ijackson@chiark.greenend.org.uk>
+ * Copyright 1998 David Damerell <damerell@chiark.greenend.org.uk>
+ * Copyright 1999,2003
+ * Chancellor Masters and Scholars of the University of Cambridge
+ * Copyright 2010 Tony Finch <fanf@dotat.at>
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
*
* 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
+ * the Free Software Foundation; either version
3
of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
@@
-48,8
+54,7
@@
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* 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.
+ * along with userv-utils; if not, see http://www.gnu.org/licenses/.
*/
#include <sys/socket.h>
*/
#include <sys/socket.h>
@@
-75,7
+80,7
@@
static struct utsname uname_result;
static const char *opt_chars;
static int public_local_fd, private_in_fd, private_out_fd;
static const char *opt_chars;
static int public_local_fd, private_in_fd, private_out_fd;
-static int mtu2, keepalive, timeout;
+static int mtu2, keepalive, timeout
, reannounce
;
static int public_remote_specd;
static struct sockaddr_in public_remote;
static int encdec_keys_fd, encdec_keys_write, crypto_debug;
static int public_remote_specd;
static struct sockaddr_in public_remote;
static int encdec_keys_fd, encdec_keys_write, crypto_debug;
@@
-83,7
+88,7
@@
static int n_mechs;
static const struct mechanism *mechs[MAXMECHS];
static struct mechdata *md_in[MAXMECHS], *md_out[MAXMECHS];
static const struct mechanism *mechs[MAXMECHS];
static struct mechdata *md_in[MAXMECHS], *md_out[MAXMECHS];
-static
size_
t maxprefix, maxsuffix;
+static
in
t maxprefix, maxsuffix;
static struct buffer buf_in, buf_out;
static unsigned char *accum_buf;
static struct buffer buf_in, buf_out;
static unsigned char *accum_buf;
@@
-178,9
+183,12
@@
static const struct mechanism *find_mech(const char *name) {
static void inbound(void) {
static int any_recvd;
static void inbound(void) {
static int any_recvd;
+ static time_t nextreann;
+ static unsigned long npackets, nbytes;
struct sockaddr_in this_saddr;
struct sockaddr_in this_saddr;
- int r, i, different, this_saddrlen;
+ size_t this_saddrlen;
+ int r, i, different;
const char *emsg;
buf_in.start= buf_in.base+1;
const char *emsg;
buf_in.start= buf_in.base+1;
@@
-219,6
+227,8
@@
static void inbound(void) {
cdebugbuf(i, "decode", &buf_in, 3,0);
}
cdebugbuf(i, "decode", &buf_in, 3,0);
}
+ npackets++;
+ nbytes += buf_in.size;
alarm(timeout);
different= (!public_remote_specd ||
alarm(timeout);
different= (!public_remote_specd ||
@@
-245,8
+255,22
@@
static void inbound(void) {
diag("tunnel open");
diag("tunnel open");
+ } else if (reannounce && now() >= nextreann) {
+
+ fprintf(stderr, "%s: tunnel still open: received %lu packets, %lu bytes\n",
+ programid, npackets, nbytes);
+
+ } else {
+
+ goto no_set_reann; /* only reset this if we don't print a message. */
+
}
}
+ if (reannounce)
+ nextreann= now() + reannounce;
+
+no_set_reann:
+
any_recvd= 1;
if (!buf_in.size || *buf_in.start != 0300) {
any_recvd= 1;
if (!buf_in.size || *buf_in.start != 0300) {
@@
-345,6
+369,7
@@
int main(int argc, const char *const *const argv_in) {
mtu2= getarg_ulong() * 2;
keepalive= getarg_ulong();
timeout= getarg_ulong();
mtu2= getarg_ulong() * 2;
keepalive= getarg_ulong();
timeout= getarg_ulong();
+ reannounce= getarg_ulong();
arg= getarg_string();
if (*arg) {
arg= getarg_string();
if (*arg) {
@@
-409,7
+434,8
@@
int main(int argc, const char *const *const argv_in) {
if (keepalive) {
tnow= now();
if (keepalive) {
tnow= now();
- if (tnow >= nextsendka && public_remote_specd) sendpacket("\300",1);
+ if (tnow >= nextsendka && public_remote_specd)
+ sendpacket((unsigned char*)"\300",1);
polltimeout= (nextsendka - tnow)*1000;
} else {
polltimeout= -1;
polltimeout= (nextsendka - tnow)*1000;
} else {
polltimeout= -1;