diff --git a/Credits b/Credits new file mode 100644 index 0000000..5fea99c --- /dev/null +++ b/Credits @@ -0,0 +1,144 @@ +vtrunkd (c) 2015-2016 Vrayo Systems Ltd. team (http://vrayo.com) + +Author of vtrunkd core algorithm is Andrew Gryaznov +with help of Andrey Kuznetsov + +Author of the original vtun package is Maxim Krasnyansky . + +A lot of thanks to the following people for their suggestions and +contributions (original vtun): + +Gayaneh Krasnyanskaya(Max's Wife) + Initial Web site creation. And a lot of other help :))) + +Alex Korenkov + Testing, bug reports. + +Shukhrat Zakhidov + Testing, bug reports, suggestions. + +Dag Wieers + Initial RPM packager specification file. + RedHat startup script. + Several bug reports. + SOCKS support suggestions. + +Ted Rolle + Spelling fixes. + +Craig Sanders + Debian startup script. + +Catalin Ciocoiu + Reported compilation problems. + +Timur Danyarhojaev + Added client source address option. + +Andreas Kainz + RPM package improvements. + +Chris Todd + Idea of challenge based authentication. + Initial BlowFish encryption code. + Suggestions. + +Garet Krampe + A lot of great ideas. Mailing list. + Web site mirror. + +Denis Zapolsky + Testing. + +Vadim Zaliva + Solaris patches. Suggestions. + +Hurricane Floyd + Max had several vacations. + Bishop had no power or water, and was able + to experience the Third World. + :))))))))))))))))))) + +James B. MacLean + Client persist mode fix. Suggestions. + +Paul + Stress tests, bug reports, suggestions. + +Maksim Yevenkin + TAP driver for FreeBSD. + +Anthon Walters + Web site mirror. Testing. Initial FAQ. + +Ryan Defelice + OpenBSD package maintainer. Provided OpenBSD server for + development and testing + +Alexander Bergolth + Initial multiple connection handling and host lock functionalities. + Improvements and fixes of source address option. Incorrect error + handling fix. Ideas. Suggestions. + +Hubert Feyrer + NetBSD package. + +Hiroharu Tamaru + Updated FreeBSD 4.0 TUN driver support. + +Terry Donaldson + Provided Solaris 8.0 server for development and testing. + +Daniel Podlejski + TUN/TAP driver modifications for 2.3.99-pre5 kernel. + +Michael Tokarev + File descriptors and memory leaks fix. + Tons of other bug fixes and patches. Suggestions. Ideas. + +Xavier + European web site mirror. + +Chris Snell + Mailing list archives. + +Robert Stone + Security enhancements. Suggestions. Ideas. + Encryption and other subsystems rework for 3.X. + +Steinar H. Gunderson + Tons of stability fixes and problem reports. + Ideas and suggestions. + +Yan Seiner + Testing. Bug reports. Suggestions. + +James Yonan + Encryption and other fixes. Suggestions. + +Greg Olszewski + Config parser and other fixes. Suggestions. + +Kevin P. Fleming + Makefile and config parser enhancement. + Other minor fixes and suggestions. + +Robert R. Wal + Added support for iproute command. + +Willems Luc + Initial SuSE packaging. Testing. + +Nickolai Zeldovich + mlockall() support to prevent VM collapse. + +Dale Fountain + Added multiple cipher support. + Added multiple cipher modes support. + Added support for different sized keys. + Re-sync ciphers when using non-ECB modes over a UDP connection. + Fixed Bug#908824 (persist=keep not re-applying routes) + +Alan Grow + Added a Listening Address/Interface (rfe936523) + Cleaned up the code around that portion of the config. diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..26291b0 --- /dev/null +++ b/INSTALL @@ -0,0 +1,10 @@ +System requirements: + +- Linux. Kernel 2.6.25+ recommended +- Additional software: + bison + flex + zlib-dev + liblzo-dev + libssl-dev + diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 0000000..a7055b8 --- /dev/null +++ b/Makefile.in @@ -0,0 +1,137 @@ +# +# vtrunkd - Virtual Tunnel Trunking over TCP/IP network. +# +# Copyright (C) 2011-2016 Vrayo Systems Ltd. team +# +# Vtrunkd has been derived from VTUN package by Maxim Krasnyansky. +# vtun Copyright (C) 1998-2000 Maxim Krasnyansky +# +# This program 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. +# +# Makefile.in,v 1.6.2.4.2.1 2006/11/16 04:03:44 mtbishop Exp +# + +VERSION=\"$(shell git describe --abbrev=4 --dirty --always)\" +CC = @CC@ +CFLAGS = @CFLAGS@ @CPPFLAGS@ -W +LDFLAGS = @LIBS@ -lm + +YACC = @YACC@ +YACCFLAGS = -d + +LEX = @LEX@ +LEXFLAGS = -t + +INSTALL = @INSTALL@ +INSTALL_OWNER = -o root -g 0 + +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +SBIN_DIR = @sbindir@ +MAN_DIR = @mandir@ +ETC_DIR = @sysconfdir@ +VAR_DIR = @localstatedir@ + +PID_FILE = ${VAR_DIR}/run/vtrunkd.pid +CFG_FILE = ${ETC_DIR}/vtrunkd.conf +STAT_DIR = ${VAR_DIR}/log/vtrunkd +LOCK_DIR = ${VAR_DIR}/lock/vtrunkd + +DEFS = -DVTUN_CONFIG_FILE=\"$(CFG_FILE)\" -DVTUN_PID_FILE=\"$(PID_FILE)\" \ + -DVTUN_STAT_DIR=\"$(STAT_DIR)\" -DVTUN_LOCK_DIR=\"$(LOCK_DIR)\" \ + -DVERSION_NUMBER=$(VERSION) + +OBJS = main.o cfg_file.tab.o cfg_file.lex.o server.o client.o lib.o \ + frame_llist.o llist.o auth.o tunnel.o lock.o netlib.o \ + tun_dev.o tap_dev.o pty_dev.o pipe_dev.o \ + tcp_proto.o udp_proto.o log.o \ + linkfd.o lfd_shaper.o lfd_zlib.o lfd_lzo.o lfd_encrypt.o speed_algo.o timer.o packet_code.o udp_states.o pid.o + +CONFIGURE_FILES = Makefile config.status config.cache config.h config.log + +%.o: %.c vtun.h lib.h log.h + $(CC) $(CFLAGS) $(DEFS) -c $< + +all: vtrunkd vshm_start_debug get_cong_status + +vtrunkd: $(OBJS) + $(CC) $(CFLAGS) -o vtrunkd $(OBJS) $(FSSOBJS) $(LFD_OBJS) $(LDFLAGS) + +vshm_start_debug: $(OBJS) + $(CC) $(CFLAGS) -o vshm_debug_enable vshm_start_debug.c $(LDFLAGS) + +get_cong_status: $(OBJS) + $(CC) $(CFLAGS) -o get_cong_status get_cong_status.c $(LDFLAGS) + +cfg_file.tab.c: cfg_file.y cfg_kwords.h config.h + $(YACC) $(YACCFLAGS) -b cfg_file cfg_file.y + +cfg_file.lex.c: cfg_file.l cfg_kwords.h config.h + $(LEX) $(LEXFLAGS) cfg_file.l > cfg_file.lex.c + +depend: + makedepend -- $(CFLAGS) -- *.c + +clean: + rm -f core cfg_file.tab.* cfg_file.lex.* *.o *~ *.bak vtrunkd vshm_debug_enable get_cong_status + +distclean: clean + rm -f $(CONFIGURE_FILES) + rm -f `cat vtun.drivers` + +install_man: + $(INSTALL) -d -m 755 $(INSTALL_OWNER) $(DESTDIR)$(MAN_DIR)/man8 + $(INSTALL) -m 644 $(INSTALL_OWNER) vtrunkd.8 $(DESTDIR)$(MAN_DIR)/man8 + $(INSTALL) -d -m 755 $(INSTALL_OWNER) $(DESTDIR)$(MAN_DIR)/man5 + $(INSTALL) -m 644 $(INSTALL_OWNER) vtrunkd.conf.5 $(DESTDIR)$(MAN_DIR)/man5 + rm -f $(DESTDIR)$(MAN_DIR)/man8/vtrunkd.8 + ln -s vtrunkd.8 $(DESTDIR)$(MAN_DIR)/man8/vtrunkd.8 + +install_config: + $(INSTALL) -d -m 755 $(INSTALL_OWNER) $(DESTDIR)$(ETC_DIR) + if [ ! -f $(ETC_DIR)/vtrunkd.conf ]; then \ + $(INSTALL) -m 600 $(INSTALL_OWNER) vtrunkd.conf $(DESTDIR)$(ETC_DIR)/; \ + fi + #if [ ! -f $(ETC_DIR)/vtrunkd-srv.test.conf ]; then \ + # $(INSTALL) -m 600 $(INSTALL_OWNER) test/vtrunkd-srv.test.conf $(DESTDIR)$(ETC_DIR)/; \ + #fi + #if [ ! -f $(ETC_DIR)/vtrunkd-cli.test.conf ]; then \ + # $(INSTALL) -m 600 $(INSTALL_OWNER) test/vtrunkd-cli.test.conf $(DESTDIR)$(ETC_DIR)/; \ + #fi +install_scripts: + #if [ ! -f $(prefix)/cli.sh ]; then \ + # $(INSTALL) -m 755 $(INSTALL_OWNER) test/cli.sh $(DESTDIR)$(prefix)/; \ + #fi + #if [ ! -f $(prefix)/srv.sh ]; then \ + # $(INSTALL) -m 755 $(INSTALL_OWNER) test/srv.sh $(DESTDIR)$(prefix)/; \ + #fi + + +install: vtrunkd install_config install_man install_scripts + $(INSTALL) -d -m 755 $(INSTALL_OWNER) $(DESTDIR)$(VAR_DIR)/run + $(INSTALL) -d -m 755 $(INSTALL_OWNER) $(DESTDIR)$(STAT_DIR) + $(INSTALL) -d -m 755 $(INSTALL_OWNER) $(DESTDIR)$(LOCK_DIR) + $(INSTALL) -d -m 755 $(INSTALL_OWNER) $(DESTDIR)$(SBIN_DIR) + $(INSTALL) -m 755 $(INSTALL_OWNER) vtrunkd $(DESTDIR)$(SBIN_DIR)/ + +# DO NOT DELETE THIS LINE -- make depend depends on it. +remove: remove_config remove_start_bin remove_docs + +remove_config: + rm -f $(DESTDIR)$(ETC_DIR)/vtrunkd* +remove_start_bin: + rm -f $(DESTDIR)$(prefix)/srv.sh + rm -f $(DESTDIR)$(prefix)/cli.sh + rm -f $(DESTDIR)$(prefix)/sbin/vtrunkd +remove_docs: + rm -f $(DESTDIR)$(MAN_DIR)/man5/vtrunkd.conf.5 + rm -f $(DESTDIR)$(MAN_DIR)/man8/vtrunkd.8 diff --git a/README b/README new file mode 100644 index 0000000..dd275a7 --- /dev/null +++ b/README @@ -0,0 +1,45 @@ +vtrunkd - universal network link bonding and multichannel VPN. +Copyright (C) 2011-2016 Vrayo Systems Ltd. team + +Vtrunkd is a Linux VPN daemon used to combine several connection paths +into one aggregated channel. Features latency, reordering and jitter +management, behaviour analysis optimizations for encapsulated protocols, +bufferbloat control, packet redundancy, and multiple cpu cores utilization. +Up to 30 heterogenous links bonding supported. Used for live streaming, +LTE/3G/Wi-Fi link bonding. 32/64-bit, x86, MIPS and ARM supported. +Supports python plug-ins for new algorithms implementation. + +Based on original package vtun - Copyright (C) 1998-2004 +Maxim Krasnyansky + +This product includes software developed by the OpenSSL Project +for use in the OpenSSL Toolkit. (http://www.openssl.org/). +Copyright (c) 1998-2004 The OpenSSL Project. All rights reserved. + +Compilation and Installation: + +In order to compile VTun you need several software packages. +Required packages: + - Good C compiler (gcc, egcs, etc) + - GNU Make (make) + - GNU libtool (libtool) + - Lexical Analyzer (flex, lex) + - YACC (yacc, bison, byacc) + - Universal TUN/TAP driver http://vtun.sourceforge.net/tun + +On ubuntu, run: + $ sudo apt-get install build-essential flex bison + +To configure run: + ./configure + +To compile and install run: + make install + +If you have any suggestions, ideas, wishes send them to +Andrew Gryaznov + ag@vrayo.com, + https://www.linkedin.com/in/grandrew + +vtrunkd and vtrunkd algorithm (C) Andrew Gryaznov +Vtun (c) Maxim Krasnyansky diff --git a/aclocal.m4 b/aclocal.m4 new file mode 100644 index 0000000..3df2901 --- /dev/null +++ b/aclocal.m4 @@ -0,0 +1,71 @@ +dnl Test files +AC_DEFUN( AC_TEST_FILES, +[ + ac_file_found=yes + for f in $1; do + if test ! -f $2/$f; then + ac_file_found=no + break; + fi + done + + if test "$ac_file_found" = "yes" ; then + ifelse([$3], , :,[$3]) + else + ifelse([$4], , :,[$4]) + fi +]) + +dnl Search for headers, add path to CPPFLAGS if found +AC_DEFUN( AC_SEARCH_HEADERS, +[ + AC_MSG_CHECKING("for $1") + ac_hdr_found=no + for p in $2; do + if test -n "$p"; then + dir="$p" + else + dir="/usr/include" + fi + AC_TEST_FILES($1, $dir, + [ + ac_hdr_found=yes + break + ] + ) + done + if test "$ac_hdr_found" = "yes" ; then + if test -n "$p"; then + CPPFLAGS="$CPPFLAGS -I$p" + fi + AC_MSG_RESULT( [($dir) yes] ) + ifelse([$3], , :,[$3]) + else + AC_MSG_RESULT("no") + ifelse([$4], , :,[$4]) + fi +]) + + +dnl Create links to all files($1) in the directory($2) +AC_DEFUN( AC_LINK_DIR, +[ + for i in $1; do + if test -f $2/$i -a ! -f $i; then + AC_MSG_RESULT(linking $2/$i to $i) + ln -f -s $2/$i $i + fi + done +]) + +dnl Create driver and protocol links +dnl $1 - drivers list, $2 - os dir +AC_DEFUN( AC_LINK_DRV, +[ + AC_MSG_RESULT( creating driver and protocol links ... ) + + if test "$2" != ""; then + AC_LINK_DIR($1, $2) + fi + AC_LINK_DIR($1, generic) +]) diff --git a/auth.c b/auth.c new file mode 100644 index 0000000..ed49630 --- /dev/null +++ b/auth.c @@ -0,0 +1,427 @@ +/* + vtrunkd - Virtual Tunnel Trunking over TCP/IP network. + + Copyright (C) 2011-2016 Vrayo Systems Ltd. team + + Vtrunkd has been derived from VTUN package by Maxim Krasnyansky. + vtun Copyright (C) 1998-2000 Maxim Krasnyansky + + This program 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. + */ + +/* + * auth.c,v 1.2.2.7.2.3 2006/11/16 04:02:33 mtbishop Exp + */ + +/* + * Challenge based authentication. + * Thanx to Chris Todd for the good idea. + * + * Jim Yonan, 05/24/2001 + * gen_chal rewrite to use better random number generator + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_NETINET_IN_H +#include +#endif + +#ifdef HAVE_NETINET_TCP_H +#include +#endif + +#ifdef HAVE_ARPA_INET_H +#include +#endif + +#include "vtun.h" +#include "lib.h" +#include "lock.h" +#include "auth.h" + +/* Encryption and Decryption of the challenge key */ +#ifdef HAVE_SSL + +#include +#include +#include + +void gen_chal(char *buf) +{ + RAND_bytes(buf, VTUN_CHAL_SIZE); +} + +void encrypt_chal(char *chal, char *pwd) +{ + register int i; + BF_KEY key; + + BF_set_key(&key, 16, MD5(pwd,strlen(pwd),NULL)); + + for(i=0; i < VTUN_CHAL_SIZE; i += 8 ) + BF_ecb_encrypt(chal + i, chal + i, &key, BF_ENCRYPT); +} + +void decrypt_chal(char *chal, char *pwd) +{ + register int i; + BF_KEY key; + + BF_set_key(&key, 16, MD5(pwd,strlen(pwd),NULL)); + + for(i=0; i < VTUN_CHAL_SIZE; i += 8 ) + BF_ecb_encrypt(chal + i, chal + i, &key, BF_DECRYPT); +} + +#else /* HAVE_SSL */ + +void encrypt_chal(char *chal, char *pwd) +{ + char * xor_msk = pwd; + register int i, xor_len = strlen(xor_msk); + + for(i=0; i < VTUN_CHAL_SIZE; i++) + chal[i] ^= xor_msk[i%xor_len]; +} + +void decrypt_chal(char *chal, char *pwd) +{ + encrypt_chal(chal, pwd); +} + +/* Generate PSEUDO random challenge key. */ +void gen_chal(char *buf) +{ + register int i; + + srand(time(NULL)); + + for(i=0; i < VTUN_CHAL_SIZE; i++) + buf[i] = (unsigned int)(255.0 * rand()/RAND_MAX); +} +#endif /* HAVE_SSL */ + +/* + * Functions to convert binary flags to character string. + * string format: + * C - compression, S - speed for shaper and so on. + */ + +char *bf2cf(struct vtun_host *host) +{ + static char str[20], *ptr = str; + + *(ptr++) = '<'; + + switch( host->flags & VTUN_PROT_MASK ){ + case VTUN_TCP: + *(ptr++) = 'T'; + break; + + case VTUN_UDP: + *(ptr++) = 'U'; + break; + } + + switch( host->flags & VTUN_TYPE_MASK ){ + case VTUN_TTY: + *(ptr++) = 't'; + break; + + case VTUN_PIPE: + *(ptr++) = 'p'; + break; + + case VTUN_ETHER: + *(ptr++) = 'e'; + break; + + case VTUN_TUN: + *(ptr++) = 'u'; + break; + } + + if( (host->flags & VTUN_SHAPE) /* && host->spd_in */) + ptr += sprintf(ptr,"S%d",host->spd_in); + + if( host->flags & VTUN_ZLIB ) + ptr += sprintf(ptr,"C%d", host->zlevel); + + if( host->flags & VTUN_LZO ) + ptr += sprintf(ptr,"L%d", host->zlevel); + + if( host->flags & VTUN_KEEP_ALIVE ) + *(ptr++) = 'K'; + + if( host->flags & VTUN_ENCRYPT ) + ptr += sprintf(ptr,"E%d", host->cipher); + + strcat(ptr,">"); + + return str; +} + +/* return 1 on success, otherwise 0 */ + +int cf2bf(char *str, struct vtun_host *host) +{ + char *ptr, *p; + int s; + + if( (ptr = strchr(str,'<')) ){ + ptr++; + while(*ptr){ + switch(*ptr++){ + case 't': + host->flags |= VTUN_TTY; + break; + case 'p': + host->flags |= VTUN_PIPE; + break; + case 'e': + host->flags |= VTUN_ETHER; + break; + case 'u': + host->flags |= VTUN_TUN; + break; + case 'U': + host->flags &= ~VTUN_PROT_MASK; + host->flags |= VTUN_UDP; + break; + case 'T': + host->flags &= ~VTUN_PROT_MASK; + host->flags |= VTUN_TCP; + break; + case 'K': + host->flags |= VTUN_KEEP_ALIVE; + break; + case 'C': + if((s = strtol(ptr,&p,10)) == ERANGE || ptr == p) + return 0; + host->flags |= VTUN_ZLIB; + host->zlevel = s; + ptr = p; + break; + case 'L': + if((s = strtol(ptr,&p,10)) == ERANGE || ptr == p) + return 0; + host->flags |= VTUN_LZO; + host->zlevel = s; + ptr = p; + break; + case 'E': + if((s = strtol(ptr,&p,10)) == ERANGE || ptr == p) + return 0; + host->flags |= VTUN_ENCRYPT; + host->cipher = s; + ptr = p; + break; + case 'S': + if((s = strtol(ptr,&p,10)) == ERANGE || ptr == p) + return 0; + if( s ){ + host->flags |= VTUN_SHAPE; + host->spd_out = s; + } + ptr = p; + break; + case '>': + return 1; + default: + return 0; + } + } + } + return 0; +} + +/* + * Functions to convert binary key data to character string. + * string format: + */ + +char *cl2cs(char *chal) +{ + static char str[VTUN_CHAL_SIZE*2+3], *chr="abcdefghijklmnop"; + register char *ptr = str; + register int i; + + *(ptr++) = '<'; + for(i=0; i> 4) ]; + *(ptr++) = chr[ (chal[i] & 0x0f) ]; + } + + *(ptr++) = '>'; + *ptr = '\0'; + + return str; +} + +int cs2cl(char *str, char *chal) +{ + register char *ptr = str; + register int i; + + if( !(ptr = strchr(str,'<')) ) + return 0; + ptr++; + if( !strtok(ptr,">") || strlen(ptr) != VTUN_CHAL_SIZE*2 ) + return 0; + + for(i=0; i 0 ){ + *reason = D_OTHER; + buf[sizeof(buf)-1]='\0'; + strtok(buf,"\r\n"); + + if( !(str1=strtok(buf," :")) ) { + *reason = D_NOSHAKE1; + break; + } + if( !(str2=strtok(NULL," :")) ) { + *reason = D_NOSHAKE2; + break; + } + + switch( stage ){ + case ST_HOST: + if( !strcmp(str1,"HOST") ){ + host = strdup(str2); + + gen_chal(chal_req); + print_p(fd,"OK CHAL: %s\n", cl2cs(chal_req)); + + stage = ST_CHAL; + continue; + } + *reason = D_ST_CHAL; + break; + case ST_CHAL: + if( !strcmp(str1,"CHAL") ){ + if( !cs2cl(str2,chal_res) ) { + *reason = D_CHAL; + break; + } + + if( !(h = find_host(host)) ) { + *reason = D_NOHOST; + break; + } + + decrypt_chal(chal_res, h->passwd); + + if( !memcmp(chal_req, chal_res, VTUN_CHAL_SIZE) ){ + /* Auth successeful. */ + + /* Lock host */ + if( lock_host(h) < 0 ){ + /* Multiple connections are denied */ + h = NULL; + *reason = D_NOMULT; + break; + } + print_p(fd,"OK FLAGS: %s\n", bf2cf(h)); + } else + h = NULL; + } + break; + } + break; + } + + if( host ) + free(host); + + if( !h ) + print_p(fd,"ERR\n"); + + return h; +} + +/* Authentication (Client side) */ +int auth_client(int fd, struct vtun_host *host, int * reason) +{ + char buf[VTUN_MESG_SIZE], chal[VTUN_CHAL_SIZE]; + int stage, success=0 ; + + stage = ST_INIT; + *reason = D_NOREAD; + while( readn_t(fd, buf, VTUN_MESG_SIZE, vtun.timeout) > 0 ){ + *reason = D_OTHER; + buf[sizeof(buf)-1]='\0'; + switch( stage ){ + case ST_INIT: + if (!strncmp(buf, "VTRUNKD", 7)) { + stage = ST_HOST; + print_p(fd,"HOST: %s\n",host->host); + continue; + } + *reason = D_GREET; + break; + + case ST_HOST: + if( !strncmp(buf,"OK",2) && cs2cl(buf,chal)){ + stage = ST_CHAL; + + encrypt_chal(chal,host->passwd); + print_p(fd,"CHAL: %s\n", cl2cs(chal)); + + continue; + } + *reason = D_CHAL; + break; + + case ST_CHAL: + if( !strncmp(buf,"OK",2) && cf2bf(buf,host) ) + success = 1; + else *reason = D_PWD; + break; + } + break; + } + + return success; +} diff --git a/auth.h b/auth.h new file mode 100644 index 0000000..7bc128e --- /dev/null +++ b/auth.h @@ -0,0 +1,32 @@ +/* + vtrunkd - Virtual Tunnel Trunking over TCP/IP network. + + Copyright (C) 2011-2016 Vrayo Systems Ltd. team + + Vtrunkd has been derived from VTUN package by Maxim Krasnyansky. + vtun Copyright (C) 1998-2000 Maxim Krasnyansky + + This program 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. + */ + +/* + * auth.h,v 1.1.1.2.6.1 2006/11/16 04:02:36 mtbishop Exp + */ + +#define VTUN_CHAL_SIZE 16 + +#define ST_INIT 0 +#define ST_HOST 1 +#define ST_CHAL 2 + +struct vtun_host * auth_server(int fd, int * reason); +int auth_client(int fd, struct vtun_host *host, int * reason); + diff --git a/cfg_file.l b/cfg_file.l new file mode 100644 index 0000000..affc60e --- /dev/null +++ b/cfg_file.l @@ -0,0 +1,196 @@ +%{ +/* + vtrunkd - Virtual Tunnel Trunking over TCP/IP network. + + Copyright (C) 2011-2016 Vrayo Systems Ltd. team + + Vtrunkd has been derived from VTUN package by Maxim Krasnyansky. + vtun Copyright (C) 1998-2000 Maxim Krasnyansky + + This program 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. + */ + +/* + * cfg_file.l,v 1.1.1.2.2.1.2.2 2006/11/16 04:02:39 mtbishop Exp + */ + +#include "config.h" + +#include + +#include "vtun.h" + +#include "cfg_file.tab.h" +#include "cfg_kwords.h" + +/* static buffer for strings */ +char str_buf[255]; + +int find_keyword(struct kword *kw, char *str); + +#define ECHO {;} +#define YY_DECL int yylex(void) + +/* Push and pop parser state */ +static int stack[16]; +static int ptr = 0; + +#define PUSH_STATE() \ + do { \ + if( ptr == 16 ){ \ + yyerror("To many pushes to parser's state stack"); \ + return K_ERROR; \ + } \ + stack[ptr++] = YY_START; \ + } while(0) + +#define POP_STATE() \ + do { \ + if( !ptr ){ \ + yyerror("To many pops from parser's state stack"); \ + return K_ERROR; \ + } \ + BEGIN(stack[--ptr]); \ + } while(0) + +int cfg_error(const char *ftm, ...); + +int yyerror(char *str); +%} + +num [0-9]+ +dnum {num}:{num} +word [A-Za-z0-9\-\_+=\!\$\#\%\&\*\^\@@\\\~\.]+ +wordnm {word}:{num} +kword [A-Za-z0-9\_\-]+ +comment \#.*\n +fname [A-Za-z0-9\_\.\-]+ +path (\/{fname})+ +string \".*\" + +%x OPTION PARAM + +%% +<*>[ \t] ; /* Skip spaces and tabs (All stages) */ + +<*>\n { lineno++; } /* (All stages) */ + +{comment} { lineno++; } /* Skip comments */ + +{kword} { + int kw = find_keyword(cfg_keyword,yytext); + if( kw != -1 ) + return kw; + + /* Keyword not found, means host definition. */ + yylval.str = yytext; + return K_HOST; + } + +{word} { + yylval.str = yytext; + return K_ERROR; + } + +<*>\{ { + PUSH_STATE(); + BEGIN(OPTION); + return *yytext; + } +<*>\} { + POP_STATE(); + return *yytext; + } + +