From 57a49ac2a518fb64a678521bcf2ee386c5b5527d Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 3 Feb 2016 16:05:32 +0000 Subject: [PATCH] initial commit --- Credits | 144 + INSTALL | 10 + Makefile.in | 137 + README | 45 + aclocal.m4 | 71 + auth.c | 427 + auth.h | 32 + cfg_file.l | 196 + cfg_file.y | 775 ++ cfg_kwords.h | 132 + client.c | 284 + compat.h | 34 + config.guess | 1308 +++ config.h.in | 74 + config.sub | 1417 +++ configure | 6352 +++++++++++++ configure.in | 214 + const.h | 52 + defines.h | 14 + driver.h | 61 + frame_llist.c | 126 + frame_llist.h | 67 + generic/pipe_dev.c | 55 + generic/pty_dev.c | 97 + generic/tap_dev.c | 75 + generic/tcp_proto.c | 121 + generic/tun_dev.c | 75 + generic/udp_proto.c | 149 + install-sh | 238 + lfd_encrypt.c | 763 ++ lfd_lzo.c | 161 + lfd_shaper.c | 153 + lfd_zlib.c | 191 + lib.c | 432 + lib.h | 130 + linkfd.c | 8552 ++++++++++++++++++ linkfd.h | 110 + linux/tap_dev.c | 29 + linux/tun_dev.c | 133 + llist.c | 103 + llist.h | 48 + lock.c | 178 + lock.h | 32 + log.c | 303 + log.h | 31 + main.c | 342 + net_structs.h | 30 + netlib.c | 291 + netlib.h | 44 + netlink_socket_info.c | 374 + netlink_socket_info.h | 34 + packages/openwrt/Makefile | 68 + packages/os-jessie/Dockerfile | 5 + packages/os-jessie/debian/changelog | 5 + packages/os-jessie/debian/compat | 1 + packages/os-jessie/debian/control | 15 + packages/os-jessie/debian/copyright | 60 + packages/os-jessie/debian/docs | 4 + packages/os-jessie/debian/files | 1 + packages/os-jessie/debian/init.d.ex | 166 + packages/os-jessie/debian/logrotate | 7 + packages/os-jessie/debian/postinst.ex | 39 + packages/os-jessie/debian/postrm.ex | 37 + packages/os-jessie/debian/rules | 32 + packages/os-jessie/debian/source/format | 1 + packages/os-jessie/debian/vtrunkd2.substvars | 2 + packages/os-jessie/sources.list | 8 + packages/os-trusty/Dockerfile | 4 + packages/os-trusty/debian/changelog | 5 + packages/os-trusty/debian/compat | 1 + packages/os-trusty/debian/control | 15 + packages/os-trusty/debian/copyright | 60 + packages/os-trusty/debian/docs | 4 + packages/os-trusty/debian/files | 1 + packages/os-trusty/debian/init.d.ex | 166 + packages/os-trusty/debian/logrotate | 7 + packages/os-trusty/debian/postinst.ex | 39 + packages/os-trusty/debian/postrm.ex | 37 + packages/os-trusty/debian/rules | 32 + packages/os-trusty/debian/source/format | 1 + packages/os-trusty/debian/vtrunkd2.substvars | 2 + packages/os-vivid/Dockerfile | 5 + packages/os-vivid/debian/changelog | 5 + packages/os-vivid/debian/compat | 1 + packages/os-vivid/debian/control | 15 + packages/os-vivid/debian/copyright | 60 + packages/os-vivid/debian/docs | 4 + packages/os-vivid/debian/files | 1 + packages/os-vivid/debian/init.d.ex | 166 + packages/os-vivid/debian/logrotate | 7 + packages/os-vivid/debian/postinst.ex | 39 + packages/os-vivid/debian/postrm.ex | 37 + packages/os-vivid/debian/rules | 32 + packages/os-vivid/debian/source/format | 1 + packages/os-vivid/debian/vtrunkd2.substvars | 2 + packages/os-vivid/sources.list | 8 + packages/os-wheezy/Dockerfile | 5 + packages/os-wheezy/debian/changelog | 5 + packages/os-wheezy/debian/compat | 1 + packages/os-wheezy/debian/control | 15 + packages/os-wheezy/debian/copyright | 60 + packages/os-wheezy/debian/docs | 4 + packages/os-wheezy/debian/files | 1 + packages/os-wheezy/debian/init.d.ex | 166 + packages/os-wheezy/debian/logrotate | 7 + packages/os-wheezy/debian/postinst.ex | 39 + packages/os-wheezy/debian/postrm.ex | 37 + packages/os-wheezy/debian/rules | 28 + packages/os-wheezy/debian/source/format | 1 + packages/os-wheezy/debian/vtrunkd2.substvars | 2 + packages/os-wheezy/sources.list | 8 + packages/os-wily/Dockerfile | 5 + packages/os-wily/debian/changelog | 5 + packages/os-wily/debian/compat | 1 + packages/os-wily/debian/control | 15 + packages/os-wily/debian/copyright | 60 + packages/os-wily/debian/docs | 4 + packages/os-wily/debian/files | 1 + packages/os-wily/debian/init.d.ex | 166 + packages/os-wily/debian/logrotate | 7 + packages/os-wily/debian/postinst.ex | 39 + packages/os-wily/debian/postrm.ex | 37 + packages/os-wily/debian/rules | 32 + packages/os-wily/debian/source/format | 1 + packages/os-wily/debian/vtrunkd2.substvars | 2 + packages/os-wily/sources.list | 8 + packet_code.c | 203 + packet_code.h | 50 + pid.c | 29 + pid.h | 22 + pre-commit | 6 + scripts/reroute | 63 + scripts/rmtree.sh | 15 + scripts/vtund-start.conf | 33 + scripts/vtund.rc.debian | 61 + scripts/vtund.rc.red_hat | 44 + scripts/vtund.rc.suse | 108 + scripts/vtund.rc.suse.config | 4 + scripts/vtund.xinetd | 13 + server.c | 298 + speed_algo.c | 79 + speed_algo.h | 30 + svr4/tap_dev.c | 144 + svr4/tun_dev.c | 177 + test/lossed.c | 85 + timer.c | 51 + timer.h | 30 + tunnel.c | 893 ++ udp_states.c | 102 + udp_states.h | 27 + v_struct.h | 526 ++ version.h | 1 + vtrunkd.8 | 183 + vtrunkd.conf | 325 + vtrunkd.conf.5 | 290 + vtrunkd_client.conf | 72 + vtun.drivers | 6 + vtun.h | 438 + vtun_socks.h | 47 + 159 files changed, 31671 insertions(+) create mode 100644 Credits create mode 100644 INSTALL create mode 100644 Makefile.in create mode 100644 README create mode 100644 aclocal.m4 create mode 100644 auth.c create mode 100644 auth.h create mode 100644 cfg_file.l create mode 100644 cfg_file.y create mode 100644 cfg_kwords.h create mode 100644 client.c create mode 100644 compat.h create mode 100755 config.guess create mode 100644 config.h.in create mode 100755 config.sub create mode 100755 configure create mode 100644 configure.in create mode 100644 const.h create mode 100644 defines.h create mode 100644 driver.h create mode 100644 frame_llist.c create mode 100644 frame_llist.h create mode 100644 generic/pipe_dev.c create mode 100644 generic/pty_dev.c create mode 100644 generic/tap_dev.c create mode 100644 generic/tcp_proto.c create mode 100644 generic/tun_dev.c create mode 100644 generic/udp_proto.c create mode 100755 install-sh create mode 100644 lfd_encrypt.c create mode 100644 lfd_lzo.c create mode 100644 lfd_shaper.c create mode 100644 lfd_zlib.c create mode 100644 lib.c create mode 100644 lib.h create mode 100644 linkfd.c create mode 100644 linkfd.h create mode 100644 linux/tap_dev.c create mode 100644 linux/tun_dev.c create mode 100644 llist.c create mode 100644 llist.h create mode 100644 lock.c create mode 100644 lock.h create mode 100644 log.c create mode 100644 log.h create mode 100644 main.c create mode 100644 net_structs.h create mode 100644 netlib.c create mode 100644 netlib.h create mode 100644 netlink_socket_info.c create mode 100644 netlink_socket_info.h create mode 100644 packages/openwrt/Makefile create mode 100644 packages/os-jessie/Dockerfile create mode 100644 packages/os-jessie/debian/changelog create mode 100644 packages/os-jessie/debian/compat create mode 100644 packages/os-jessie/debian/control create mode 100644 packages/os-jessie/debian/copyright create mode 100644 packages/os-jessie/debian/docs create mode 100644 packages/os-jessie/debian/files create mode 100644 packages/os-jessie/debian/init.d.ex create mode 100644 packages/os-jessie/debian/logrotate create mode 100644 packages/os-jessie/debian/postinst.ex create mode 100644 packages/os-jessie/debian/postrm.ex create mode 100755 packages/os-jessie/debian/rules create mode 100644 packages/os-jessie/debian/source/format create mode 100644 packages/os-jessie/debian/vtrunkd2.substvars create mode 100644 packages/os-jessie/sources.list create mode 100644 packages/os-trusty/Dockerfile create mode 100644 packages/os-trusty/debian/changelog create mode 100644 packages/os-trusty/debian/compat create mode 100644 packages/os-trusty/debian/control create mode 100644 packages/os-trusty/debian/copyright create mode 100644 packages/os-trusty/debian/docs create mode 100644 packages/os-trusty/debian/files create mode 100644 packages/os-trusty/debian/init.d.ex create mode 100644 packages/os-trusty/debian/logrotate create mode 100644 packages/os-trusty/debian/postinst.ex create mode 100644 packages/os-trusty/debian/postrm.ex create mode 100755 packages/os-trusty/debian/rules create mode 100644 packages/os-trusty/debian/source/format create mode 100644 packages/os-trusty/debian/vtrunkd2.substvars create mode 100644 packages/os-vivid/Dockerfile create mode 100644 packages/os-vivid/debian/changelog create mode 100644 packages/os-vivid/debian/compat create mode 100644 packages/os-vivid/debian/control create mode 100644 packages/os-vivid/debian/copyright create mode 100644 packages/os-vivid/debian/docs create mode 100644 packages/os-vivid/debian/files create mode 100644 packages/os-vivid/debian/init.d.ex create mode 100644 packages/os-vivid/debian/logrotate create mode 100644 packages/os-vivid/debian/postinst.ex create mode 100644 packages/os-vivid/debian/postrm.ex create mode 100755 packages/os-vivid/debian/rules create mode 100644 packages/os-vivid/debian/source/format create mode 100644 packages/os-vivid/debian/vtrunkd2.substvars create mode 100644 packages/os-vivid/sources.list create mode 100644 packages/os-wheezy/Dockerfile create mode 100644 packages/os-wheezy/debian/changelog create mode 100644 packages/os-wheezy/debian/compat create mode 100644 packages/os-wheezy/debian/control create mode 100644 packages/os-wheezy/debian/copyright create mode 100644 packages/os-wheezy/debian/docs create mode 100644 packages/os-wheezy/debian/files create mode 100644 packages/os-wheezy/debian/init.d.ex create mode 100644 packages/os-wheezy/debian/logrotate create mode 100644 packages/os-wheezy/debian/postinst.ex create mode 100644 packages/os-wheezy/debian/postrm.ex create mode 100755 packages/os-wheezy/debian/rules create mode 100644 packages/os-wheezy/debian/source/format create mode 100644 packages/os-wheezy/debian/vtrunkd2.substvars create mode 100644 packages/os-wheezy/sources.list create mode 100644 packages/os-wily/Dockerfile create mode 100644 packages/os-wily/debian/changelog create mode 100644 packages/os-wily/debian/compat create mode 100644 packages/os-wily/debian/control create mode 100644 packages/os-wily/debian/copyright create mode 100644 packages/os-wily/debian/docs create mode 100644 packages/os-wily/debian/files create mode 100644 packages/os-wily/debian/init.d.ex create mode 100644 packages/os-wily/debian/logrotate create mode 100644 packages/os-wily/debian/postinst.ex create mode 100644 packages/os-wily/debian/postrm.ex create mode 100755 packages/os-wily/debian/rules create mode 100644 packages/os-wily/debian/source/format create mode 100644 packages/os-wily/debian/vtrunkd2.substvars create mode 100644 packages/os-wily/sources.list create mode 100644 packet_code.c create mode 100644 packet_code.h create mode 100644 pid.c create mode 100644 pid.h create mode 100755 pre-commit create mode 100755 scripts/reroute create mode 100755 scripts/rmtree.sh create mode 100644 scripts/vtund-start.conf create mode 100644 scripts/vtund.rc.debian create mode 100644 scripts/vtund.rc.red_hat create mode 100644 scripts/vtund.rc.suse create mode 100755 scripts/vtund.rc.suse.config create mode 100644 scripts/vtund.xinetd create mode 100644 server.c create mode 100644 speed_algo.c create mode 100644 speed_algo.h create mode 100644 svr4/tap_dev.c create mode 100644 svr4/tun_dev.c create mode 100644 test/lossed.c create mode 100644 timer.c create mode 100644 timer.h create mode 100644 tunnel.c create mode 100644 udp_states.c create mode 100644 udp_states.h create mode 100644 v_struct.h create mode 100644 version.h create mode 100644 vtrunkd.8 create mode 100644 vtrunkd.conf create mode 100644 vtrunkd.conf.5 create mode 100644 vtrunkd_client.conf create mode 100644 vtun.drivers create mode 100644 vtun.h create mode 100644 vtun_socks.h 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; + } + +