buy back from patch 2972369 (debian 339364)

This commit is contained in:
mtbishop 2012-07-07 07:14:17 +00:00
parent 868b4f7745
commit 408c943518
9 changed files with 86 additions and 54 deletions

View File

@ -3,7 +3,12 @@
rfe2149137 - makefile ignores LDFLAGS (sbk) rfe2149137 - makefile ignores LDFLAGS (sbk)
rfe2405993 - mem leak in config parser (frY) rfe2405993 - mem leak in config parser (frY)
rfe1685781 - vtun3 server should offer vtun2-compatible encryption (if) rfe1685781 - vtun3 server should offer vtun2-compatible encryption (if)
rfe3540779 - Parallel make Makefile.in race condition (pb) pat3540779 - Parallel make Makefile.in race condition (pb)
pat2972369 - link timeout in UDP mode (Eugene Berdnikov - deb339364)
Minor fixes in lfd_lzo.c to ensure correct type casting
Add description of "keepalive timeout:count;" syntax
to man page and vtund.conf sample.
Remove doubled if(send_a_file){...} block in linkfd.c.
3.0.2: 3.0.2:
rfe1685781 - vtun3 client should parse vtun2 server encr directives (hch) rfe1685781 - vtun3 client should parse vtun2 server encr directives (hch)

View File

@ -152,3 +152,7 @@ Dragos Vingarzan <dragos.vingarzan@gmail.com>
Sergey Popov (Pinkbyte) <@pinkbyte.ru> Sergey Popov (Pinkbyte) <@pinkbyte.ru>
Parallel make Makefile.in race condition (rfe3540779) Parallel make Makefile.in race condition (rfe3540779)
Eugene Berdnikov
Link timeout in UDP mode (deb339364)
Types cleanup

View File

@ -18,7 +18,7 @@
*/ */
/* /*
* $Id: cfg_file.y,v 1.8.2.4 2010/04/14 08:48:09 mtbishop Exp $ * $Id: cfg_file.y,v 1.8.2.5 2012/07/07 07:14:17 mtbishop Exp $
*/ */
#include "config.h" #include "config.h"
@ -377,7 +377,7 @@ keepalive:
if( yylval.dnum.num1 ){ if( yylval.dnum.num1 ){
parse_host->flags |= VTUN_KEEP_ALIVE; parse_host->flags |= VTUN_KEEP_ALIVE;
parse_host->ka_interval = yylval.dnum.num1; parse_host->ka_interval = yylval.dnum.num1;
parse_host->ka_failure = yylval.dnum.num2; parse_host->ka_maxfail = yylval.dnum.num2;
} }
} }

View File

@ -17,7 +17,7 @@
*/ */
/* /*
* $Id: lfd_lzo.c,v 1.5.2.3 2008/01/07 22:35:35 mtbishop Exp $ * $Id: lfd_lzo.c,v 1.5.2.4 2012/07/07 07:14:17 mtbishop Exp $
*/ */
/* LZO compression module */ /* LZO compression module */
@ -35,6 +35,7 @@
#ifdef HAVE_LZO #ifdef HAVE_LZO
#include "lzoutil.h"
#include "lzo1x.h" #include "lzo1x.h"
#include "lzoutil.h" #include "lzoutil.h"
@ -54,7 +55,7 @@ int (*lzo1x_compress)(const lzo_byte *src, lzo_uint src_len,
int alloc_lzo(struct vtun_host *host) int alloc_lzo(struct vtun_host *host)
{ {
int zlevel = host->zlevel ? host->zlevel : 1; int zlevel = host->zlevel ? host->zlevel : 1;
int mem; lzo_uint mem;
switch( zlevel ){ switch( zlevel ){
case 9: case 9:

View File

@ -17,7 +17,7 @@
*/ */
/* /*
* $Id: linkfd.c,v 1.13.2.4 2009/03/29 10:08:54 mtbishop Exp $ * $Id: linkfd.c,v 1.13.2.5 2012/07/07 07:14:17 mtbishop Exp $
*/ */
#include "config.h" #include "config.h"
@ -175,20 +175,38 @@ static void sig_hup(int sig)
linker_term = VTUN_SIG_HUP; linker_term = VTUN_SIG_HUP;
} }
/* Statistic dump */ /* Statistic dump and keep-alive monitor */
static volatile sig_atomic_t ka_need_verify = 0;
static time_t stat_timer = 0, ka_timer = 0;
void sig_alarm(int sig) void sig_alarm(int sig)
{ {
static time_t tm; static time_t tm_old, tm = 0;
static char stm[20]; static char stm[20];
tm_old = tm;
tm = time(NULL); tm = time(NULL);
strftime(stm, sizeof(stm)-1, "%b %d %H:%M:%S", localtime(&tm));
fprintf(lfd_host->stat.file,"%s %lu %lu %lu %lu\n", stm, if( (lfd_host->flags & VTUN_KEEP_ALIVE) && (ka_timer -= tm-tm_old) <= 0){
lfd_host->stat.byte_in, lfd_host->stat.byte_out, ka_need_verify = 1;
lfd_host->stat.comp_in, lfd_host->stat.comp_out); ka_timer = lfd_host->ka_interval
+ 1; /* We have to complete select() on idle */
alarm(VTUN_STAT_IVAL); }
}
if( (lfd_host->flags & VTUN_STAT) && (stat_timer -= tm-tm_old) <= 0){
strftime(stm, sizeof(stm)-1, "%b %d %H:%M:%S", localtime(&tm));
fprintf(lfd_host->stat.file,"%s %lu %lu %lu %lu\n", stm,
lfd_host->stat.byte_in, lfd_host->stat.byte_out,
lfd_host->stat.comp_in, lfd_host->stat.comp_out);
stat_timer = VTUN_STAT_IVAL;
}
if ( ka_timer*stat_timer ){
alarm( (ka_timer < stat_timer) ? ka_timer : stat_timer );
} else {
alarm( (ka_timer) ? ka_timer : stat_timer );
}
}
static void sig_usr1(int sig) static void sig_usr1(int sig)
{ {
@ -238,6 +256,21 @@ int lfd_linker(void)
else else
continue; continue;
} }
if( ka_need_verify ){
if( idle > lfd_host->ka_maxfail ){
vtun_syslog(LOG_INFO,"Session %s network timeout", lfd_host->host);
break;
}
if (idle++ > 0) { /* No input frames, check connection with ECHO */
if( proto_write(fd1, buf, VTUN_ECHO_REQ) < 0 ){
vtun_syslog(LOG_ERR,"Failed to send ECHO_REQ");
break;
}
}
ka_need_verify = 0;
}
if (send_a_packet) if (send_a_packet)
{ {
send_a_packet = 0; send_a_packet = 0;
@ -249,35 +282,11 @@ int lfd_linker(void)
break; break;
lfd_host->stat.comp_out += tmplen; lfd_host->stat.comp_out += tmplen;
} }
if( !len ){
if (send_a_packet)
{
send_a_packet = 0;
tmplen = 1;
lfd_host->stat.byte_out += tmplen;
if( (tmplen=lfd_run_down(tmplen,buf,&out)) == -1 )
break;
if( tmplen && proto_write(fd1, out, tmplen) < 0 )
break;
lfd_host->stat.comp_out += tmplen;
}
/* We are idle, lets check connection */
if( lfd_host->flags & VTUN_KEEP_ALIVE ){
if( ++idle > lfd_host->ka_failure ){
vtun_syslog(LOG_INFO,"Session %s network timeout", lfd_host->host);
break;
}
/* Send ECHO request */
if( proto_write(fd1, buf, VTUN_ECHO_REQ) < 0 )
break;
}
continue;
}
/* Read frames from network(fd1), decode and pass them to /* Read frames from network(fd1), decode and pass them to
* the local device (fd2) */ * the local device (fd2) */
if( FD_ISSET(fd1, &fdset) && lfd_check_up() ){ if( FD_ISSET(fd1, &fdset) && lfd_check_up() ){
idle = 0; idle = 0; ka_need_verify = 0;
if( (len=proto_read(fd1, buf)) <= 0 ) if( (len=proto_read(fd1, buf)) <= 0 )
break; break;
@ -296,7 +305,7 @@ int lfd_linker(void)
continue; continue;
} }
if( fl==VTUN_ECHO_REP ){ if( fl==VTUN_ECHO_REP ){
/* Just ignore ECHO reply */ /* Just ignore ECHO reply, ka_need_verify==0 already */
continue; continue;
} }
if( fl==VTUN_CONN_CLOSE ){ if( fl==VTUN_CONN_CLOSE ){
@ -388,6 +397,15 @@ int linkfd(struct vtun_host *host)
sa.sa_handler=sig_hup; sa.sa_handler=sig_hup;
sigaction(SIGHUP,&sa,&sa_oldhup); sigaction(SIGHUP,&sa,&sa_oldhup);
/* Initialize keep-alive timer */
if( host->flags & (VTUN_STAT|VTUN_KEEP_ALIVE) ){
sa.sa_handler=sig_alarm;
sigaction(SIGALRM,&sa,NULL);
alarm( (host->ka_interval < VTUN_STAT_IVAL) ?
host->ka_interval : VTUN_STAT_IVAL );
}
/* Initialize statstic dumps */ /* Initialize statstic dumps */
if( host->flags & VTUN_STAT ){ if( host->flags & VTUN_STAT ){
char file[40]; char file[40];
@ -400,7 +418,6 @@ int linkfd(struct vtun_host *host)
sprintf(file,"%s/%.20s", VTUN_STAT_DIR, host->host); sprintf(file,"%s/%.20s", VTUN_STAT_DIR, host->host);
if( (host->stat.file=fopen(file, "a")) ){ if( (host->stat.file=fopen(file, "a")) ){
setvbuf(host->stat.file, NULL, _IOLBF, 0); setvbuf(host->stat.file, NULL, _IOLBF, 0);
alarm(VTUN_STAT_IVAL);
} else } else
vtun_syslog(LOG_ERR, "Can't open stats file %s", file); vtun_syslog(LOG_ERR, "Can't open stats file %s", file);
} }
@ -409,7 +426,7 @@ int linkfd(struct vtun_host *host)
lfd_linker(); lfd_linker();
if( host->flags & VTUN_STAT ){ if( host->flags & (VTUN_STAT|VTUN_KEEP_ALIVE) ){
alarm(0); alarm(0);
if (host->stat.file) if (host->stat.file)
fclose(host->stat.file); fclose(host->stat.file);

4
main.c
View File

@ -17,7 +17,7 @@
*/ */
/* /*
* $Id: main.c,v 1.9.2.3 2009/03/29 10:08:57 mtbishop Exp $ * $Id: main.c,v 1.9.2.4 2012/07/07 07:14:17 mtbishop Exp $
*/ */
#include "config.h" #include "config.h"
@ -86,7 +86,7 @@ int main(int argc, char *argv[], char *env[])
default_host.multi = VTUN_MULTI_ALLOW; default_host.multi = VTUN_MULTI_ALLOW;
default_host.timeout = VTUN_CONNECT_TIMEOUT; default_host.timeout = VTUN_CONNECT_TIMEOUT;
default_host.ka_interval = 30; default_host.ka_interval = 30;
default_host.ka_failure = 4; default_host.ka_maxfail = 4;
default_host.loc_fd = default_host.rmt_fd = -1; default_host.loc_fd = default_host.rmt_fd = -1;
/* Start logging to syslog and stderr */ /* Start logging to syslog and stderr */

4
vtun.h
View File

@ -17,7 +17,7 @@
*/ */
/* /*
* $Id: vtun.h,v 1.12.2.4 2009/03/29 10:09:11 mtbishop Exp $ * $Id: vtun.h,v 1.12.2.5 2012/07/07 07:14:17 mtbishop Exp $
*/ */
#ifndef _VTUN_H #ifndef _VTUN_H
@ -107,7 +107,7 @@ struct vtun_host {
/* Keep Alive */ /* Keep Alive */
int ka_interval; int ka_interval;
int ka_failure; int ka_maxfail;
/* Source address */ /* Source address */
struct vtun_addr src_addr; struct vtun_addr src_addr;

View File

@ -6,7 +6,7 @@
# Ted Rolle <ted@acacia.datacomm.com> # Ted Rolle <ted@acacia.datacomm.com>
# #
# Configuration file example # Configuration file example
# $Id: vtund.conf,v 1.4.2.4 2009/04/24 09:15:38 mtbishop Exp $ # $Id: vtund.conf,v 1.4.2.5 2012/07/07 07:14:17 mtbishop Exp $
# #
# #
# Lines which begin with '#' are comments # Lines which begin with '#' are comments
@ -130,6 +130,10 @@
# keepalive - Enable 'yes' or disable 'no' connection # keepalive - Enable 'yes' or disable 'no' connection
# keep-alive. Ignored by the client. # keep-alive. Ignored by the client.
# #
# May be in the form 'interval:count', where 'interval' is the
# period of connection checks and 'count' is the maximum number
# of retries. 'yes' is equivalent to '30:4'.
#
# ----------- # -----------
# timeout - Connect timeout. # timeout - Connect timeout.
# #

View File

@ -1,5 +1,5 @@
.\" Manual page for vtund.conf .\" Manual page for vtund.conf
.\" $Id: vtund.conf.5,v 1.4.2.3 2009/04/24 09:15:41 mtbishop Exp $ .\" $Id: vtund.conf.5,v 1.4.2.4 2012/07/07 07:14:17 mtbishop Exp $
.TH VTUND.CONF 5 .TH VTUND.CONF 5
.SH NAME .SH NAME
@ -237,10 +237,11 @@ AES cipher, 256 bit key, mode OFB
.RE .RE
.IP .IP
This option is ignored by the client. This option is ignored by the client.
.IP \fBkeepalive\ \fByes\fR|\fBno\fR|\fIinterval\fB:\fIcount\fR
.IP \fBkeepalive\ \fByes\fR|\fBno\fR enable or disable connection keep-alive. Time \fIinterval\fR is a period
enable or disable connection keep-alive. between connection checks, in seconds, and \fIcount\fR is the maximum number
This option is ignored by the client. of retries (\fByes\fR = \fI30\fB:\fI4\fR).
This option is ignored by the server.
.IP \fBstat\ \fByes\fR|\fBno\fR .IP \fBstat\ \fByes\fR|\fBno\fR
enable or disable statistics. If enabled \fBvtund\fR(8) will log enable or disable statistics. If enabled \fBvtund\fR(8) will log
statistic counters to /var/log/vtund/session_X every 5 minutes. statistic counters to /var/log/vtund/session_X every 5 minutes.