Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: add an option to set the inactivity timeout interval #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions man/iodine.8
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ iodine, iodined \- tunnel IPv4 over DNS
.I 0|1
.B ] [-I
.I interval
.B ] [-o
.I interval
.B ]
.B [
.I nameserver
Expand Down Expand Up @@ -236,8 +238,10 @@ There are some DNS relays with very small timeouts,
notably dnsadvantage.com (ultradns), that will give
SERVFAIL errors even with \-I1; data will still get trough,
and these errors can be ignored.
Maximum useful value is 59, since iodined will close a client's
connection after 60 seconds of inactivity.
Maximum useful value is less than specified in \-o.
.TP
.B -o interval
Inactivity timeout interval. Defaults to 60 seconds.
.SS Server Options:
.TP
.B -c
Expand Down
13 changes: 10 additions & 3 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ static unsigned short do_qtype = T_UNSET;
static enum connection conn;

static int selecttimeout; /* RFC says timeout minimum 5sec */
static int inactivitytimeout;
static int lazymode;
static long send_ping_soon;
static time_t lastdownstreamtime;
Expand Down Expand Up @@ -211,6 +212,12 @@ client_set_selecttimeout(int select_timeout)
selecttimeout = select_timeout;
}

void
client_set_inactivitytimeout(int inactivity_timeout)
{
inactivitytimeout = inactivity_timeout;
}

void
client_set_lazymode(int lazy_mode)
{
Expand Down Expand Up @@ -847,7 +854,7 @@ tunnel_dns(int tun_fd, int dns_fd)
}

if (read == 5 && !strncmp("BADIP", buf, 5)) {
warnx("BADIP: Server rejected sender IP address (maybe iodined -c will help), or server kicked us due to timeout. Will exit if no downstream data is received in 60 seconds.");
warnx("BADIP: Server rejected sender IP address (maybe iodined -c will help), or server kicked us due to timeout. Will exit if no downstream data is received in %d seconds.", inactivitytimeout);
return -1; /* nothing done */
}

Expand Down Expand Up @@ -1117,8 +1124,8 @@ client_tunnel(int tun_fd, int dns_fd)

i = select(MAX(tun_fd, dns_fd) + 1, &fds, NULL, NULL, &tv);

if (lastdownstreamtime + 60 < time(NULL)) {
warnx("No downstream data received in 60 seconds, shutting down.");
if (lastdownstreamtime + inactivitytimeout < time(NULL)) {
warnx("No downstream data received in %d seconds, shutting down.", inactivitytimeout);
running = 0;
}

Expand Down
1 change: 1 addition & 0 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ int client_set_qtype(char *qtype);
char *client_get_qtype(void);
void client_set_downenc(char *encoding);
void client_set_selecttimeout(int select_timeout);
void client_set_inactivitytimeout(int inactivity_timeout);
void client_set_lazymode(int lazy_mode);
void client_set_hostname_maxlen(int i);

Expand Down
13 changes: 11 additions & 2 deletions src/iodine.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ static void help(FILE *stream, bool verbose)
" -t dir to chroot to directory dir\n"
" -d device to set tunnel device name\n"
" -z context, to apply specified SELinux context after initialization\n"
" -F pidfile to write pid to a file\n\n"
" -F pidfile to write pid to a file\n"
" -o inactivity timeout interval\n\n"
"nameserver is the IP number/hostname of the relaying nameserver. If absent,\n"
" /etc/resolv.conf is used\n"
"topdomain is the FQDN that is delegated to the tunnel endpoint.\n");
Expand Down Expand Up @@ -143,6 +144,7 @@ int main(int argc, char **argv)
int raw_mode;
int lazymode;
int selecttimeout;
int inactivitytimeout;
int hostname_maxlen;
#ifdef OPENBSD
int rtable = 0;
Expand Down Expand Up @@ -172,6 +174,7 @@ int main(int argc, char **argv)
raw_mode = 1;
lazymode = 1;
selecttimeout = 4;
inactivitytimeout = 60;
hostname_maxlen = 0xFF;
nameserv_family = AF_UNSPEC;

Expand All @@ -190,7 +193,7 @@ int main(int argc, char **argv)
__progname++;
#endif

while ((choice = getopt(argc, argv, "46vfhru:t:d:R:P:m:M:F:T:O:L:I:")) != -1) {
while ((choice = getopt(argc, argv, "46vfhru:t:d:R:P:m:M:F:T:O:L:I:o:")) != -1) {
switch(choice) {
case '4':
nameserv_family = AF_INET;
Expand Down Expand Up @@ -271,6 +274,11 @@ int main(int argc, char **argv)
if (selecttimeout < 1)
selecttimeout = 1;
break;
case 'o':
inactivitytimeout = atoi(optarg);
if (inactivitytimeout < 1)
inactivitytimeout = 1;
break;
default:
usage();
/* NOTREACHED */
Expand Down Expand Up @@ -322,6 +330,7 @@ int main(int argc, char **argv)
}

client_set_selecttimeout(selecttimeout);
client_set_inactivitytimeout(inactivitytimeout);
client_set_lazymode(lazymode);
client_set_topdomain(topdomain);
client_set_hostname_maxlen(hostname_maxlen);
Expand Down