Merge changes from Andrey Mazo:

Clean up Configure.in for autoheader
        Static declarations where sensible
        Check/handle no fork() for no-MMU client systems (eg blackfin)
This commit is contained in:
mtbishop 2013-07-07 19:54:20 +00:00
parent 34ee687c65
commit f3c3e13798
15 changed files with 192 additions and 120 deletions

View File

@ -1,3 +1,9 @@
-.-.-
patch23 - check for fork and work around lack (AM)
patch22 - static declarations where possible (AM)
patch21 - fix up configure.in for newer autoheader (AM)
3.0.3:
rfe2636157 - Delayed UDP connection (dv)
rfe2149137 - makefile ignores LDFLAGS (sbk)

View File

@ -159,3 +159,8 @@ Eugene Berdnikov
Sean MacLennan
Reduce connection chatter
Andrey Mazo <ahippo@sf>
Clean up Configure.in for autoheader
Static declarations where sensible
Check/handle no fork() for no-MMU client systems (eg blackfin)

22
auth.c
View File

@ -17,7 +17,7 @@
*/
/*
* $Id: auth.c,v 1.9.2.4 2009/04/24 09:15:33 mtbishop Exp $
* $Id: auth.c,v 1.9.2.5 2013/07/07 19:54:20 mtbishop Exp $
*/
/*
@ -62,12 +62,12 @@
#include <openssl/blowfish.h>
#include <openssl/rand.h>
void gen_chal(char *buf)
static void gen_chal(char *buf)
{
RAND_bytes(buf, VTUN_CHAL_SIZE);
}
void encrypt_chal(char *chal, char *pwd)
static void encrypt_chal(char *chal, char *pwd)
{
register int i;
BF_KEY key;
@ -78,7 +78,7 @@ void encrypt_chal(char *chal, char *pwd)
BF_ecb_encrypt(chal + i, chal + i, &key, BF_ENCRYPT);
}
void decrypt_chal(char *chal, char *pwd)
static void decrypt_chal(char *chal, char *pwd)
{
register int i;
BF_KEY key;
@ -91,7 +91,7 @@ void decrypt_chal(char *chal, char *pwd)
#else /* HAVE_SSL */
void encrypt_chal(char *chal, char *pwd)
static void encrypt_chal(char *chal, char *pwd)
{
char * xor_msk = pwd;
register int i, xor_len = strlen(xor_msk);
@ -100,13 +100,13 @@ void encrypt_chal(char *chal, char *pwd)
chal[i] ^= xor_msk[i%xor_len];
}
void inline decrypt_chal(char *chal, char *pwd)
static void inline decrypt_chal(char *chal, char *pwd)
{
encrypt_chal(chal, pwd);
}
/* Generate PSEUDO random challenge key. */
void gen_chal(char *buf)
static void gen_chal(char *buf)
{
register int i;
@ -123,7 +123,7 @@ void gen_chal(char *buf)
* C - compression, S - speed for shaper and so on.
*/
char *bf2cf(struct vtun_host *host)
static char *bf2cf(struct vtun_host *host)
{
static char str[20], *ptr = str;
@ -187,7 +187,7 @@ char *bf2cf(struct vtun_host *host)
FLAGS: <TuE1>
*/
int cf2bf(char *str, struct vtun_host *host)
static int cf2bf(char *str, struct vtun_host *host)
{
char *ptr, *p;
int s;
@ -277,7 +277,7 @@ int cf2bf(char *str, struct vtun_host *host)
* string format: <char_data>
*/
char *cl2cs(char *chal)
static char *cl2cs(char *chal)
{
static char str[VTUN_CHAL_SIZE*2+3], *chr="abcdefghijklmnop";
register char *ptr = str;
@ -295,7 +295,7 @@ char *cl2cs(char *chal)
return str;
}
int cs2cl(char *str, char *chal)
static int cs2cl(char *str, char *chal)
{
register char *ptr = str;
register int i;

View File

@ -2,12 +2,12 @@ dnl
dnl VTun - Virtual Tunnel over TCP/IP network.
dnl Copyright (C) 1998-2006 Maxim Krasnyansky <max_mk@yahoo.com>
dnl
dnl $Id: configure.in,v 1.19.2.2 2009/03/29 10:08:51 mtbishop Exp $
dnl $Id: configure.in,v 1.19.2.3 2013/07/07 19:54:28 mtbishop Exp $
dnl
dnl Process this file with autoconf to produce a configure script.
dnl
AC_INIT(lib.c)
AC_INIT(vtun, 3) dnl this needs to change via variables as in the tail
AC_CONFIG_HEADER(config.h)
dnl Shapper support
@ -110,10 +110,13 @@ dnl Check for librt
AC_SEARCH_LIBS(nanosleep, rt posix4)
dnl Check for setproctitle in libutil
AC_SEARCH_LIBS(setproctitle, util bsd, AC_DEFINE(HAVE_SETPROC_TITLE) )
AC_SEARCH_LIBS(setproctitle, util bsd, AC_DEFINE(HAVE_SETPROC_TITLE, [1], [Define to 1 if you have setproctitle() function]) )
dnl Check for fork() (fallback to vfork() on non-MMU systems)
AC_FUNC_FORK
if test "$SHAPER" = "yes"; then
AC_DEFINE(HAVE_SHAPER)
AC_DEFINE(HAVE_SHAPER, [1], [Define to 1 if you want to enable shaper module])
fi
if test "$ZLIB" = "yes"; then
@ -121,7 +124,7 @@ if test "$ZLIB" = "yes"; then
AC_CHECKING( for ZLIB Library and Header files ... )
AC_CHECK_LIB(z, deflate,
LIBS="$LIBS -lz"
AC_DEFINE(HAVE_ZLIB),
AC_DEFINE(HAVE_ZLIB, [1], [Define to 1 if you have zlib]),
AC_MSG_ERROR( Zlib library not found.)
)
fi
@ -148,7 +151,7 @@ if test "$LZO" = "yes"; then
AC_CHECK_LIB($I, lzo1x_decompress,
[
LIBS="$LIBS -l"$I
AC_DEFINE(HAVE_LZO)
AC_DEFINE(HAVE_LZO, [1], [Define to 1 if you have lzo])
havelzo=1
]
)
@ -180,8 +183,8 @@ if test "$SSL" = "yes"; then
AC_CHECK_LIB(crypto, BF_set_key,
[
LIBS="$LIBS -lcrypto"
AC_DEFINE(HAVE_SSL)
AC_DEFINE(HAVE_SSL_BLOWFISH)
AC_DEFINE(HAVE_SSL, [1], [Define to 1 if you have openssl])
AC_DEFINE(HAVE_SSL_BLOWFISH, [1], [Define to 1 if you have blowfish in openssl])
],
AC_MSG_ERROR( SSL library not found. )
),
@ -196,7 +199,7 @@ if test "$SSL" = "yes"; then
$SSL_HDR_DIR /usr/include/ssl /usr/include/openssl /usr/include /usr/local/include /usr/local/ssl/include /usr/include/crypto,
AC_CHECK_LIB(crypto, AES_set_encrypt_key,
[
AC_DEFINE(HAVE_SSL_AES)
AC_DEFINE(HAVE_SSL_AES, [1], [Define to 1 if you have AES in openssl])
],
AC_MSG_ERROR( AES library not found. )
),
@ -211,7 +214,7 @@ if test "$SSL" = "yes"; then
$SSL_HDR_DIR /usr/include/ssl /usr/include/openssl /usr/include /usr/local/include /usr/local/ssl/include /usr/include/crypto,
AC_CHECK_LIB(crypto, EVP_EncryptInit,
[
AC_DEFINE(HAVE_SSL_EVP)
AC_DEFINE(HAVE_SSL_EVP, [1], [Define to 1 if you have EVP in openssl])
],
AC_MSG_ERROR( EVP library not found. )
),
@ -220,7 +223,7 @@ if test "$SSL" = "yes"; then
fi
if test "$NATHACK" = "yes"; then
AC_DEFINE(ENABLE_NAT_HACK)
AC_DEFINE(ENABLE_NAT_HACK, [1], [Define to 1 if you want to enable Nat Hack code])
fi
if test "$SOCKS" = "yes"; then
@ -274,6 +277,6 @@ changequote(<,>)
REL=`echo 'BRANCH-3_X' | tr -d '$: \-' | sed 's/^[A-Za-z]*//' | sed 's/\_/\./'`
changequote([,])
AC_DEFINE_UNQUOTED(VTUN_VER, "$REL `date '+%m/%d/%Y'`")
AC_DEFINE_UNQUOTED(VTUN_VER, "$REL `date '+%m/%d/%Y'`", [Vtun version])
AC_OUTPUT(Makefile)

View File

@ -64,16 +64,16 @@
#define ENC_BUF_SIZE VTUN_FRAME_SIZE + 128
#define ENC_KEY_SIZE 16
BF_KEY key;
char * enc_buf;
char * dec_buf;
static BF_KEY key;
static char * enc_buf;
static char * dec_buf;
#define CIPHER_INIT 0
#define CIPHER_CODE 1
#define CIPHER_SEQUENCE 2
#define CIPHER_REQ_INIT 3
struct vtun_host *phost;
static struct vtun_host *phost;
extern int send_a_packet;
@ -81,27 +81,32 @@ extern int send_a_packet;
#define MAX_GIBBERISH 10
#define MIN_GIBBERISH 1
#define MAX_GIBBERISH_TIME 2
int gibberish;
time_t gib_time_start;
static int gibberish;
static time_t gib_time_start;
int cipher_enc_state;
int cipher_dec_state;
int cipher;
int blocksize;
int keysize;
int enc_init_first_time;
int dec_init_first_time;
unsigned long sequence_num;
char * pkey;
char * iv_buf;
static int cipher_enc_state;
static int cipher_dec_state;
static int cipher;
static int blocksize;
static int keysize;
static int enc_init_first_time;
static int dec_init_first_time;
static unsigned long sequence_num;
static char * pkey;
static char * iv_buf;
EVP_CIPHER_CTX ctx_enc; /* encrypt */
EVP_CIPHER_CTX ctx_dec; /* decrypt */
static EVP_CIPHER_CTX ctx_enc; /* encrypt */
static EVP_CIPHER_CTX ctx_dec; /* decrypt */
EVP_CIPHER_CTX ctx_enc_ecb; /* sideband ecb encrypt */
EVP_CIPHER_CTX ctx_dec_ecb; /* sideband ecb decrypt */
static EVP_CIPHER_CTX ctx_enc_ecb; /* sideband ecb encrypt */
static EVP_CIPHER_CTX ctx_dec_ecb; /* sideband ecb decrypt */
int prep_key(char **key, int size, struct vtun_host *host)
static int send_msg(int len, char *in, char **out);
static int recv_msg(int len, char *in, char **out);
static int send_ib_mesg(int *len, char **in);
static int recv_ib_mesg(int *len, char **in);
static int prep_key(char **key, int size, struct vtun_host *host)
{
int tmplen, halflen;
char *hashkey;
@ -136,12 +141,12 @@ int prep_key(char **key, int size, struct vtun_host *host)
return 0;
}
void free_key (char *key)
static void free_key (char *key)
{
free(key);
}
int alloc_encrypt(struct vtun_host *host)
static int alloc_encrypt(struct vtun_host *host)
{
int sb_init = 0;
int var_key = 0;
@ -282,7 +287,7 @@ int alloc_encrypt(struct vtun_host *host)
return 0;
}
int free_encrypt()
static int free_encrypt()
{
free_key(pkey); pkey = NULL;
@ -297,7 +302,7 @@ int free_encrypt()
return 0;
}
int encrypt_buf(int len, char *in, char **out)
static int encrypt_buf(int len, char *in, char **out)
{
register int pad, p, msg_len;
int outlen;
@ -326,7 +331,7 @@ int encrypt_buf(int len, char *in, char **out)
return outlen+msg_len;
}
int decrypt_buf(int len, char *in, char **out)
static int decrypt_buf(int len, char *in, char **out)
{
register int pad;
char *tmp_ptr, *in_ptr, *out_ptr = dec_buf;
@ -351,7 +356,7 @@ int decrypt_buf(int len, char *in, char **out)
return outlen - pad;
}
int cipher_enc_init(char * iv)
static int cipher_enc_init(char * iv)
{
int var_key = 0;
const EVP_CIPHER *cipher_type;
@ -442,7 +447,7 @@ int cipher_enc_init(char * iv)
return 0;
}
int cipher_dec_init(char * iv)
static int cipher_dec_init(char * iv)
{
int var_key = 0;
const EVP_CIPHER *cipher_type;
@ -532,7 +537,7 @@ int cipher_dec_init(char * iv)
return 0;
}
int send_msg(int len, char *in, char **out)
static int send_msg(int len, char *in, char **out)
{
char * iv; char * in_ptr;
int outlen;
@ -570,7 +575,7 @@ int send_msg(int len, char *in, char **out)
return len;
}
int recv_msg(int len, char *in, char **out)
static int recv_msg(int len, char *in, char **out)
{
char * iv; char * in_ptr;
int outlen;
@ -645,7 +650,7 @@ int recv_msg(int len, char *in, char **out)
}
/* Send In-Band Message */
int send_ib_mesg(int *len, char **in)
static int send_ib_mesg(int *len, char **in)
{
char *in_ptr = *in;
@ -684,7 +689,7 @@ int send_ib_mesg(int *len, char **in)
}
/* Receive In-Band Message */
int recv_ib_mesg(int *len, char **in)
static int recv_ib_mesg(int *len, char **in)
{
char *in_ptr = *in;
@ -747,7 +752,7 @@ struct lfd_mod lfd_encrypt = {
#else /* HAVE_SSL */
int no_encrypt(struct vtun_host *host)
static int no_encrypt(struct vtun_host *host)
{
vtun_syslog(LOG_INFO, "Encryption is not supported");
return -1;

View File

@ -17,7 +17,7 @@
*/
/*
* $Id: lfd_legacy_encrypt.c,v 1.1.4.2 2008/01/07 22:35:33 mtbishop Exp $
* $Id: lfd_legacy_encrypt.c,v 1.1.4.3 2013/07/07 19:54:41 mtbishop Exp $
* Code added wholesale temporarily from lfd_encrypt 1.2.2.8
*/
@ -61,10 +61,10 @@
#define ENC_BUF_SIZE VTUN_FRAME_SIZE + 16
#define ENC_KEY_SIZE 16
BF_KEY key;
char * enc_buf;
static BF_KEY key;
static char * enc_buf;
int alloc_legacy_encrypt(struct vtun_host *host)
static int alloc_legacy_encrypt(struct vtun_host *host)
{
if( !(enc_buf = lfd_alloc(ENC_BUF_SIZE)) ){
vtun_syslog(LOG_ERR,"Can't allocate buffer for legacy encryptor");
@ -77,13 +77,13 @@ int alloc_legacy_encrypt(struct vtun_host *host)
return 0;
}
int free_legacy_encrypt()
static int free_legacy_encrypt()
{
lfd_free(enc_buf); enc_buf = NULL;
return 0;
}
int legacy_encrypt_buf(int len, char *in, char **out)
static int legacy_encrypt_buf(int len, char *in, char **out)
{
register int pad, p;
register char *in_ptr = in, *out_ptr = enc_buf;
@ -105,7 +105,7 @@ int legacy_encrypt_buf(int len, char *in, char **out)
return len + 8;
}
int legacy_decrypt_buf(int len, char *in, char **out)
static int legacy_decrypt_buf(int len, char *in, char **out)
{
register int p;
@ -140,7 +140,7 @@ struct lfd_mod lfd_legacy_encrypt = {
#else /* HAVE_SSL */
int no_legacy_encrypt(struct vtun_host *host)
static int no_legacy_encrypt(struct vtun_host *host)
{
vtun_syslog(LOG_INFO, "Encryption is not supported");
return -1;

View File

@ -17,7 +17,7 @@
*/
/*
* $Id: lfd_lzo.c,v 1.5.2.5 2012/07/09 01:01:08 mtbishop Exp $
* $Id: lfd_lzo.c,v 1.5.2.6 2013/07/07 19:54:44 mtbishop Exp $
*/
/* LZO compression module */
@ -44,7 +44,7 @@ static lzo_voidp wmem;
static int zbuf_size = VTUN_FRAME_SIZE * VTUN_FRAME_SIZE / 64 + 16 + 3;
/* Pointer to compress function */
int (*lzo1x_compress)(const lzo_byte *src, lzo_uint src_len,
static int (*lzo1x_compress)(const lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uint *dst_len,
lzo_voidp wrkmem);
/*
@ -52,7 +52,7 @@ int (*lzo1x_compress)(const lzo_byte *src, lzo_uint src_len,
* Allocate the buffers.
*/
int alloc_lzo(struct vtun_host *host)
static int alloc_lzo(struct vtun_host *host)
{
int zlevel = host->zlevel ? host->zlevel : 1;
lzo_uint mem;
@ -91,7 +91,7 @@ int alloc_lzo(struct vtun_host *host)
* Free the buffer.
*/
int free_lzo()
static int free_lzo()
{
lfd_free(zbuf); zbuf = NULL;
lzo_free(wmem); wmem = NULL;
@ -102,7 +102,7 @@ int free_lzo()
* This functions _MUST_ consume all incoming bytes in one pass,
* that's why we expand buffer dynamicly.
*/
int comp_lzo(int len, char *in, char **out)
static int comp_lzo(int len, char *in, char **out)
{
lzo_uint zlen = 0;
int err;
@ -116,7 +116,7 @@ int comp_lzo(int len, char *in, char **out)
return zlen;
}
int decomp_lzo(int len, char *in, char **out)
static int decomp_lzo(int len, char *in, char **out)
{
lzo_uint zlen = 0;
int err;
@ -144,7 +144,7 @@ struct lfd_mod lfd_lzo = {
#else /* HAVE_LZO */
int no_lzo(struct vtun_host *host)
static int no_lzo(struct vtun_host *host)
{
vtun_syslog(LOG_INFO, "LZO compression is not supported");
return -1;

View File

@ -17,7 +17,7 @@
*/
/*
* $Id: lfd_shaper.c,v 1.7.2.2 2008/01/07 22:35:36 mtbishop Exp $
* $Id: lfd_shaper.c,v 1.7.2.3 2013/07/07 19:54:48 mtbishop Exp $
*/
#include "config.h"
@ -38,13 +38,13 @@
#ifdef HAVE_SHAPER
unsigned long bytes, max_speed;
struct timeval curr_time, last_time;
static unsigned long bytes, max_speed;
static struct timeval curr_time, last_time;
/*
* Initialization function.
*/
int shaper_init(struct vtun_host *host)
static int shaper_init(struct vtun_host *host)
{
/* Calculate max speed bytes/sec */
max_speed = host->spd_out / 8 * 1024;
@ -59,7 +59,7 @@ int shaper_init(struct vtun_host *host)
}
/* Shaper counter */
int shaper_counter(int len, char *in, char **out)
static int shaper_counter(int len, char *in, char **out)
{
/* Just count incoming bytes */
bytes += len;
@ -69,7 +69,7 @@ int shaper_counter(int len, char *in, char **out)
}
/* Convert tv struct to milisec */
unsigned long inline tv2ms(struct timeval tv)
static unsigned long inline tv2ms(struct timeval tv)
{
register unsigned long ms = (tv.tv_sec * 1000)+(tv.tv_usec / 1000);
return ms ? ms : 1;
@ -94,7 +94,7 @@ unsigned long inline tv2ms(struct timeval tv)
* higher than maximal speed stop accepting input
* until the speed become lower or equal to maximal.
*/
int shaper_avail(void)
static int shaper_avail(void)
{
static struct timeval tv;
register unsigned long speed;
@ -144,7 +144,7 @@ struct lfd_mod lfd_shaper = {
#else /* HAVE_SHAPER */
int no_shaper(struct vtun_host *host)
static int no_shaper(struct vtun_host *host)
{
vtun_syslog(LOG_INFO, "Traffic shaping is not supported");
return -1;

View File

@ -17,7 +17,7 @@
*/
/*
* $Id: lfd_zlib.c,v 1.5.2.2 2008/01/07 22:35:38 mtbishop Exp $
* $Id: lfd_zlib.c,v 1.5.2.3 2013/07/07 19:54:52 mtbishop Exp $
*/
/* ZLIB compression module */
@ -45,7 +45,7 @@ static int zbuf_size = VTUN_FRAME_SIZE + 200;
* Initialize compressor/decompressor.
* Allocate the buffer.
*/
int zlib_alloc(struct vtun_host *host)
static int zlib_alloc(struct vtun_host *host)
{
int zlevel = host->zlevel ? host->zlevel : 1;
@ -78,7 +78,7 @@ int zlib_alloc(struct vtun_host *host)
* Free the buffer.
*/
int zlib_free()
static int zlib_free()
{
deflateEnd(&zd);
inflateEnd(&zi);
@ -104,7 +104,7 @@ static int expand_zbuf(z_stream *zs, int len)
* That's why we expand buffer dynamically.
* Practice shows that buffer will not grow larger that 16K.
*/
int zlib_comp(int len, char *in, char **out)
static int zlib_comp(int len, char *in, char **out)
{
int oavail, olen = 0;
int err;
@ -133,7 +133,7 @@ int zlib_comp(int len, char *in, char **out)
return olen;
}
int zlib_decomp(int len, char *in, char **out)
static int zlib_decomp(int len, char *in, char **out)
{
int oavail = 0, olen = 0;
int err;
@ -175,7 +175,7 @@ struct lfd_mod lfd_zlib = {
#else /* HAVE_ZLIB */
int no_zlib(struct vtun_host *host)
static int no_zlib(struct vtun_host *host)
{
vtun_syslog(LOG_INFO, "ZLIB compression is not supported");
return -1;

17
lib.c
View File

@ -17,7 +17,7 @@
*/
/*
* $Id: lib.c,v 1.9.2.2 2008/01/07 22:35:40 mtbishop Exp $
* $Id: lib.c,v 1.9.2.3 2013/07/07 19:54:56 mtbishop Exp $
*/
#include "config.h"
@ -45,9 +45,9 @@ volatile sig_atomic_t __io_canceled = 0;
/* Functions to manipulate with program title */
extern char **environ;
char *title_start; /* start of the proc title space */
char *title_end; /* end of the proc title space */
int title_size;
static char *title_start; /* start of the proc title space */
static char *title_end; /* end of the proc title space */
static int title_size;
void init_title(int argc,char *argv[], char *envp[], char *name)
{
@ -148,7 +148,7 @@ int readn_t(int fd, void *buf, size_t count, time_t timeout)
* Substitutes opt in place off '%X'.
* Returns new string.
*/
char * subst_opt(char *str, struct vtun_sopt *opt)
static char * subst_opt(char *str, struct vtun_sopt *opt)
{
register int slen, olen, sp, np;
register char *optr, *nstr, *tmp;
@ -185,6 +185,9 @@ char * subst_opt(char *str, struct vtun_sopt *opt)
sprintf(buf,"%d",opt->rport);
optr=buf;
break;
case 'h':
optr=opt->host;
break;
default:
sp++;
continue;
@ -223,7 +226,7 @@ char * subst_opt(char *str, struct vtun_sopt *opt)
* ' ' - group arguments
* Modifies original string.
*/
void split_args(char *str, char **argv)
static void split_args(char *str, char **argv)
{
register int i = 0;
int mode = 0;
@ -276,6 +279,7 @@ void split_args(char *str, char **argv)
argv[i]=NULL;
}
#ifdef HAVE_WORKING_FORK
int run_cmd(void *d, void *opt)
{
struct vtun_cmd *cmd = d;
@ -324,6 +328,7 @@ int run_cmd(void *d, void *opt)
vtun_syslog(LOG_ERR,"Couldn't exec program %s", cmd->prog);
exit(1);
}
#endif
void free_sopt( struct vtun_sopt *opt )
{

4
lib.h
View File

@ -17,7 +17,7 @@
*/
/*
* $Id: lib.h,v 1.7.2.2 2008/01/07 22:35:41 mtbishop Exp $
* $Id: lib.h,v 1.7.2.3 2013/07/07 19:55:00 mtbishop Exp $
*/
#ifndef _VTUN_LIB_H
#define _VTUN_LIB_H
@ -46,7 +46,9 @@
int readn_t(int fd, void *buf, size_t count, time_t timeout);
int print_p(int f, const char *ftm, ...);
#ifdef HAVE_WORKING_FORK
int run_cmd(void *d, void *opt);
#endif
void free_sopt(struct vtun_sopt *opt);
/* IO cancelation */

View File

@ -17,7 +17,7 @@
*/
/*
* $Id: linkfd.c,v 1.13.2.5 2012/07/07 07:14:17 mtbishop Exp $
* $Id: linkfd.c,v 1.13.2.6 2013/07/07 19:55:06 mtbishop Exp $
*/
#include "config.h"
@ -56,14 +56,14 @@ int send_a_packet = 0;
/* Host we are working with.
* Used by signal handlers that's why it is global.
*/
struct vtun_host *lfd_host;
static struct vtun_host *lfd_host;
struct lfd_mod *lfd_mod_head = NULL, *lfd_mod_tail = NULL;
static struct lfd_mod *lfd_mod_head = NULL, *lfd_mod_tail = NULL;
/* Modules functions*/
/* Add module to the end of modules list */
void lfd_add_mod(struct lfd_mod *mod)
static void lfd_add_mod(struct lfd_mod *mod)
{
if( !lfd_mod_head ){
lfd_mod_head = lfd_mod_tail = mod;
@ -77,7 +77,7 @@ void lfd_add_mod(struct lfd_mod *mod)
}
/* Initialize and allocate each module */
int lfd_alloc_mod(struct vtun_host *host)
static int lfd_alloc_mod(struct vtun_host *host)
{
struct lfd_mod *mod = lfd_mod_head;
@ -91,7 +91,7 @@ int lfd_alloc_mod(struct vtun_host *host)
}
/* Free all modules */
int lfd_free_mod(void)
static int lfd_free_mod(void)
{
struct lfd_mod *mod = lfd_mod_head;
@ -105,7 +105,7 @@ int lfd_free_mod(void)
}
/* Run modules down (from head to tail) */
inline int lfd_run_down(int len, char *in, char **out)
static inline int lfd_run_down(int len, char *in, char **out)
{
register struct lfd_mod *mod;
@ -119,7 +119,7 @@ inline int lfd_run_down(int len, char *in, char **out)
}
/* Run modules up (from tail to head) */
inline int lfd_run_up(int len, char *in, char **out)
static inline int lfd_run_up(int len, char *in, char **out)
{
register struct lfd_mod *mod;
@ -133,7 +133,7 @@ inline int lfd_run_up(int len, char *in, char **out)
}
/* Check if modules are accepting the data(down) */
inline int lfd_check_down(void)
static inline int lfd_check_down(void)
{
register struct lfd_mod *mod;
int err = 1;
@ -145,7 +145,7 @@ inline int lfd_check_down(void)
}
/* Check if modules are accepting the data(up) */
inline int lfd_check_up(void)
static inline int lfd_check_up(void)
{
register struct lfd_mod *mod;
int err = 1;
@ -179,7 +179,7 @@ static void sig_hup(int sig)
static volatile sig_atomic_t ka_need_verify = 0;
static time_t stat_timer = 0, ka_timer = 0;
void sig_alarm(int sig)
static void sig_alarm(int sig)
{
static time_t tm_old, tm = 0;
static char stm[20];
@ -215,7 +215,7 @@ static void sig_usr1(int sig)
lfd_host->stat.comp_in = lfd_host->stat.comp_out = 0;
}
int lfd_linker(void)
static int lfd_linker(void)
{
int fd1 = lfd_host->rmt_fd;
int fd2 = lfd_host->loc_fd;

56
main.c
View File

@ -17,7 +17,7 @@
*/
/*
* $Id: main.c,v 1.9.2.5 2012/07/08 05:32:57 mtbishop Exp $
* $Id: main.c,v 1.9.2.6 2013/07/07 19:55:10 mtbishop Exp $
*/
#include "config.h"
@ -39,13 +39,20 @@
#include "lib.h"
#include "compat.h"
#define OPTSTRING "mif:P:L:t:npq"
#ifdef HAVE_WORKING_FORK
# define SERVOPT_STRING "s"
#else
# define SERVOPT_STRING ""
#endif
/* Global options for the server and client */
struct vtun_opts vtun;
struct vtun_host default_host;
void write_pid(void);
void reread_config(int sig);
void usage(void);
static void write_pid(void);
static void reread_config(int sig);
static void usage(void);
extern int optind,opterr,optopt;
extern char *optarg;
@ -55,13 +62,19 @@ int is_rmt_fd_connected=1;
int main(int argc, char *argv[], char *env[])
{
int svr, daemon, sock, dofork, fd, opt;
int svr, daemon, sock, fd, opt;
#if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK)
int dofork;
#endif
struct vtun_host *host = NULL;
struct sigaction sa;
char *hst;
/* Configure default settings */
svr = 0; daemon = 1; sock = 0; dofork = 1;
svr = 0; daemon = 1; sock = 0;
#if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK)
dofork = 1;
#endif
vtun.cfg_file = VTUN_CONFIG_FILE;
vtun.persist = -1;
@ -92,7 +105,7 @@ int main(int argc, char *argv[], char *env[])
/* Start logging to syslog and stderr */
openlog("vtund", LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON);
while( (opt=getopt(argc,argv,"misf:P:L:t:npq")) != EOF ){
while( (opt=getopt(argc,argv,OPTSTRING SERVOPT_STRING)) != EOF ){
switch(opt){
case 'm':
if (mlockall(MCL_CURRENT | MCL_FUTURE) < 0) {
@ -102,7 +115,9 @@ int main(int argc, char *argv[], char *env[])
break;
case 'i':
vtun.svr_type = VTUN_INETD;
#ifdef HAVE_WORKING_FORK
case 's':
#endif
svr = 1;
break;
case 'L':
@ -173,13 +188,20 @@ int main(int argc, char *argv[], char *env[])
break;
case VTUN_INETD:
sock = dup(0);
#if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK)
dofork = 0;
#endif
break;
}
if( daemon ){
#ifdef HAVE_WORKING_FORK
if( dofork && fork() )
exit(0);
#elif defined(HAVE_WORKING_VFORK)
if( dofork && vfork() )
exit(0);
#endif
/* Direct stdin,stdout,stderr to '/dev/null' */
fd = open("/dev/null", O_RDWR);
@ -200,8 +222,14 @@ int main(int argc, char *argv[], char *env[])
init_title(argc,argv,env,"vtund[s]: ");
if( vtun.svr_type == VTUN_STAND_ALONE )
if( vtun.svr_type == VTUN_STAND_ALONE ){
#ifdef HAVE_WORKING_FORK
write_pid();
#else
vtun_syslog(LOG_ERR,"Standalone server is not supported. Use -i");
exit(1);
#endif
}
server(sock);
} else {
@ -218,7 +246,7 @@ int main(int argc, char *argv[], char *env[])
* Very simple PID file creation function. Used by server.
* Overrides existing file.
*/
void write_pid(void)
static void write_pid(void)
{
FILE *f;
@ -231,7 +259,7 @@ void write_pid(void)
fclose(f);
}
void reread_config(int sig)
static void reread_config(int sig)
{
if( !read_config(vtun.cfg_file) ){
vtun_syslog(LOG_ERR,"No hosts defined");
@ -239,12 +267,16 @@ void reread_config(int sig)
}
}
void usage(void)
static void usage(void)
{
printf("VTun ver %s\n", VTUN_VER);
printf("Usage: \n");
printf(" Server:\n");
printf("\tvtund <-s> [-f file] [-P port] [-L local address]\n");
#ifdef HAVE_WORKING_FORK
printf("\tvtund <-s|-i> [-f file] [-P port] [-L local address]\n");
#else
printf("\tvtund <-i> [-f file] [-P port] [-L local address]\n");
#endif
printf(" Client:\n");
/* I don't think these work. I'm disabling the suggestion - bish 20050601*/
printf("\tvtund [-f file] " /* [-P port] [-L local address] */

View File

@ -17,7 +17,7 @@
*/
/*
* $Id: server.c,v 1.9.2.3 2012/07/09 01:01:08 mtbishop Exp $
* $Id: server.c,v 1.9.2.4 2013/07/07 19:55:14 mtbishop Exp $
*/
#include "config.h"
@ -58,7 +58,7 @@ static void sig_term(int sig)
server_term = VTUN_SIG_TERM;
}
void connection(int sock)
static void connection(int sock)
{
struct sockaddr_in my_addr, cl_addr;
struct vtun_host *host;
@ -111,7 +111,8 @@ void connection(int sock)
exit(0);
}
void listener(void)
#ifdef HAVE_WORKING_FORK
static void listener(void)
{
struct sigaction sa;
struct sockaddr_in my_addr, cl_addr;
@ -172,6 +173,7 @@ void listener(void)
}
}
}
#endif
void server(int sock)
{
@ -190,7 +192,11 @@ void server(int sock)
switch( vtun.svr_type ){
case VTUN_STAND_ALONE:
#ifdef HAVE_WORKING_FORK
listener();
#else
vtun_syslog(LOG_ERR,"Standalone server is not supported: fork() not available");
#endif
break;
case VTUN_INETD:
connection(sock);

View File

@ -17,7 +17,7 @@
*/
/*
* $Id: tunnel.c,v 1.14.2.2 2008/01/07 22:36:03 mtbishop Exp $
* $Id: tunnel.c,v 1.14.2.3 2013/07/07 19:55:17 mtbishop Exp $
*/
#include "config.h"
@ -147,6 +147,7 @@ int tunnel(struct vtun_host *host)
break;
}
#ifdef HAVE_WORKING_FORK
switch( (pid=fork()) ){
case -1:
vtun_syslog(LOG_ERR,"Couldn't fork()");
@ -187,6 +188,9 @@ int tunnel(struct vtun_host *host)
exit(0);
}
#else
vtun_syslog(LOG_ERR,"Couldn't run up commands: fork() not available");
#endif
switch( host->flags & VTUN_TYPE_MASK ){
case VTUN_TTY:
@ -222,8 +226,12 @@ int tunnel(struct vtun_host *host)
opt = linkfd(host);
#ifdef HAVE_WORKING_FORK
set_title("%s running down commands", host->host);
llist_trav(&host->down, run_cmd, &host->sopt);
#else
vtun_syslog(LOG_ERR,"Couldn't run down commands: fork() not available");
#endif
if(! ( host->persist == VTUN_PERSIST_KEEPIF ) ) {
set_title("%s closing", host->host);