From 30df5e95dbe585c6076d743d3771a42ad7c78590 Mon Sep 17 00:00:00 2001 From: Ivo Timmermans Date: Wed, 18 Oct 2000 20:12:10 +0000 Subject: [PATCH] Bring head revision up to date with cabal (try #3) --- AUTHORS | 2 - Makefile.am | 10 +- README | 21 +- THANKS | 18 +- TODO | 2 + acconfig.h | 10 + configure.in | 53 +- debian/changelog | 6 + debian/control | 4 +- debian/init.d | 7 +- debian/rules | 2 +- doc/Makefile.am | 6 +- doc/tinc.conf.5 | 129 +++-- doc/tinc.texi | 583 +++++++++++++++++----- lib/Makefile.am | 3 +- lib/utils.c | 54 +- lib/utils.h | 25 +- lib/xalloc.h | 2 + lib/xmalloc.c | 2 - po/POTFILES.in | 4 +- po/nl.po | 1053 ++++++++++++++++++++------------------- redhat/tinc.spec | 2 +- src/Makefile.am | 11 +- src/conf.c | 198 +++++--- src/conf.h | 62 ++- src/encr.c | 44 +- src/encr.h | 5 +- src/genauth.c | 97 ++-- src/net.c | 723 ++++++++++++++------------- src/net.h | 80 +-- src/netutl.c | 130 +---- src/netutl.h | 10 +- src/protocol.c | 1219 +++++++++++++++++++++++++++------------------- src/protocol.h | 91 ++-- src/tincd.c | 160 +++--- 35 files changed, 2826 insertions(+), 2002 deletions(-) diff --git a/AUTHORS b/AUTHORS index aa39942e..532543f4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -5,5 +5,3 @@ Ivo Timmermans These files are from other sources: * lib/pidfile.h and lib/pidfile.c are by Martin Schulze, taken from the syslog 1.3 sources. - * The files in cipher/blowfish/ are from the SSLeay package by - Eric Young. diff --git a/Makefile.am b/Makefile.am index 8ecab330..19ae3014 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = gnu -SUBDIRS = m4 intl lib cipher src doc po redhat debian +SUBDIRS = m4 intl lib src doc po redhat debian ACLOCAL_AMFLAGS = @@ -16,7 +16,7 @@ ChangeLog: rm -f ChangeLog rcs2log -u "zarq Ivo Timmermans itimmermans@bigfoot.com" \ -u "guus Guus Sliepen guus@sliepen.warande.net" | \ - sed -e 's,/home/CVS/tinc/cabal/,,g' > $@ + sed -e 's,/home/CVS/tinc/,,g' > $@ cvs-clean: maintainer-clean for f in $(CVS_CREATED) `find -name Makefile.in` ; do\ @@ -25,3 +25,9 @@ cvs-clean: maintainer-clean deb: dpkg-buildpackage -rfakeroot + +rpm: dist + cp $(distdir).tar.gz /usr/src/redhat/SOURCES/ + cp redhat/tinc.spec /usr/src/redhat/SOURCES/ + cd /usr/src/redhat/SOURCES/ + rpm -bi tinc.spec diff --git a/README b/README index 46deda8e..7c0fe125 100644 --- a/README +++ b/README @@ -4,17 +4,26 @@ Installation instructions may be found in the INSTALL file. tinc is Copyright (C) 1998,1999,2000 Ivo Timmermans , Guus Sliepen and others. For a complete list of authors see the AUTHORS file. -This product includes software developed by Eric Young (eay@mincom.oz.au) 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. See the file COPYING for more details. -This version of tinc relies on the GNU Multi-Precision Library -(gmp). This library is available from your nearest GNU mirror. Please -install this first even before trying to run configure. If you don't -do this, configure will (hopefully) mention it to you. + +Requirements +------------ + +Since 1.0pre3, we use OpenSSL for all cryptographic functions. So you +need to install this library first; grab it from +http://www.openssl.org/. We recommend version 0.9.5 or better. If +this library is not installed on you system, configure will fail. The +manual in doc/tinc.texi contains more detailed information on how to +install this library. + + +Features +-------- This version of tinc supports multiple virtual networks at once. To use this feature, you may supply a netname via the -n or --net @@ -29,7 +38,7 @@ In this version, MAC addresses are stripped off before encoding and sending a packet. When the packet reaches its destination, the MAC addresses are rebuilt again. They then have the form FE:FD:aa:bb:cc:dd. aa, bb, cc and dd are taken from the destination -and source IP address. +and source IP address. See the manual for more detailed information. tincd regenerates its encryption key pairs. It does this on the first activity after the keys have expired. This period is adjustable in the diff --git a/THANKS b/THANKS index 63d9221d..6116810a 100644 --- a/THANKS +++ b/THANKS @@ -2,19 +2,19 @@ I would like to thank * Hans Bayle (for making some useful coding suggestions and fixing a bug or two) + * Lubomír Bulej (for the Redhat system init script) + * Wessel Dankers (for the name `tinc' and various suggestions) * Mads Kiilerich (for finding some bugs and some errors in the documentation, and for making several suggestions to make it all - more userfriendly) - * James B. MacLean (for fixing several mission critical bugs, and for + more userfriendly, and the Redhat package) + * James MacLean (for fixing several mission critical bugs, and for giving me a few good ideas, and, most of all, for the wonderful testing and debugging) - * Cris van Pelt - * Robert van der Meulen - * Sander Smeenk - * Tijs van Bakel - * Wessel Dankers (for the name `tinc' and being a royal pain in the - ass (je hebt erom gevraagd)) + * Robert van der Meulen (early configuration code) + * Cris van Pelt (small fixes) + * Enrique Zanardi (for the Spanish translation) + * Matias Carrasco (for the Spanish translation of the manual) -for their help, support and ideas. Thank you guys! +for their help, support and ideas. Thank you guys! And especially Guus Sliepen, for starting this whole project... diff --git a/TODO b/TODO index 4ba698ad..4415e163 100644 --- a/TODO +++ b/TODO @@ -5,3 +5,5 @@ Things left to do to make cabal superstable: tree property. * Redundancy: multiple ConnectTo lines, if one fails others might be tried. + * Allow connects to hosts that use + nodirectdata. diff --git a/acconfig.h b/acconfig.h index 86a35ecb..f1d9ee74 100644 --- a/acconfig.h +++ b/acconfig.h @@ -43,3 +43,13 @@ # include # undef getopt #endif + + +/* Define to the location of the kernel sources */ +#undef CONFIG_TINC_KERNELDIR + +/* Define to 1 if tun/tap support is enabled and found */ +#undef HAVE_TUNTAP + +/* Define to the location of if_tun.h */ +#undef LINUX_IF_TUN_H diff --git a/configure.in b/configure.in index f18571bd..0d54bd51 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. -dnl $Id: configure.in,v 1.14 2000/06/25 15:42:40 zarq Exp $ +dnl $Id: configure.in,v 1.15 2000/10/18 20:12:06 zarq Exp $ AC_INIT(src/tincd.c) AM_INIT_AUTOMAKE(tinc, 1.0pre3) @@ -14,7 +14,7 @@ AM_ACLOCAL_INCLUDE(m4) # in the latter don't make it into the configure-time tests. AC_DEFINE([_GNU_SOURCE], [__USE_BSD]) -ALL_LINGUAS="nl" +ALL_LINGUAS="es nl" dnl Checks for programs. AC_PROG_CC @@ -33,8 +33,7 @@ dnl Checks for libraries. dnl Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS(fcntl.h limits.h sys/ioctl.h syslog.h unistd.h gmp.h gmp2/gmp.h \ -sys/time.h) +AC_CHECK_HEADERS(fcntl.h limits.h sys/ioctl.h syslog.h unistd.h sys/time.h linux/if_tun.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -53,32 +52,38 @@ jm_FUNC_REALLOC AM_GNU_GETTEXT -# Check for the GNU Multi Precision Library -libgmp=none -AC_CHECK_LIB(gmp, mpz_powm, [ - libgmp=gmp -]) -AC_CHECK_LIB(gmp2, mpz_powm, [ - libgmp=gmp2 -]) -AC_CHECK_LIB(gmp3, __gmpz_powm, [ - libgmp=gmp3 +AC_CHECK_LIB(dl, dlopen, [ + LIBS="$LIBS -ldl" ]) -AC_CHECK_LIB(gmp, __gmpz_powm, [ - libgmp=gmp + + +dnl Crypto stuff + +libcrypto=none +AC_CHECK_LIB(crypto, SHA1_version, [ + libcrypto=yes ]) -if test $libgmp = none; then - AC_MSG_ERROR(libgmp is not installed. Please grab it from your - nearest GNU mirror and install it (see README)) +if test $libcrypto = none; then + AC_MSG_ERROR(It seems like OpenSSL is not installed on this system.) else - LIBS="$LIBS -l$libgmp" + LIBS="$LIBS -lcrypto" fi -AC_CHECK_LIB(dl, dlopen, [ - LIBS="$LIBS -ldl" + +dnl Support for SunOS + +AC_CHECK_FUNC(socket, [], [ + AC_CHECK_LIB(socket, connect) ]) +AC_CHECK_FUNC(gethostbyname, [], [ + AC_CHECK_LIB(nsl, gethostbyname) +]) + + +dnl Check for TUN/TAP support in the kernel +tinc_TUNTAP -AC_OUTPUT([Makefile src/Makefile cipher/Makefile -cipher/blowfish/Makefile doc/Makefile intl/Makefile lib/Makefile +AC_OUTPUT([Makefile src/Makefile +doc/Makefile doc/es/Makefile intl/Makefile lib/Makefile m4/Makefile po/Makefile.in redhat/Makefile debian/Makefile]) diff --git a/debian/changelog b/debian/changelog index 6d158d2e..6c570df1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +tinc (1.0pre3-0.1) unstable; urgency=low + + * upgraded to upstream version 1.0pre3 + + -- Ivo Timmermans Sun, 25 Jun 2000 00:00:00 +0200 + tinc (1.0pre2-1) unstable; urgency=low * postinst creates a file /etc/tinc/nets.boot, containing all networks diff --git a/debian/control b/debian/control index cc18a908..c08c622b 100644 --- a/debian/control +++ b/debian/control @@ -3,11 +3,11 @@ Section: non-US/main Priority: optional Maintainer: Ivo Timmermans Standards-Version: 3.0.1 -Build-Depends: libc6-dev, libgmp2-dev +Build-Depends: libc6-dev, libssl095a-dev, autoconf (>= 2.12), automake, Package: tinc Architecture: i386 -Depends: ${shlibs:Depends}, libgmp2, perl5 +Depends: ${shlibs:Depends}, (libssl095a|libssl09), perl5 Description: Virtual Private Network daemon tinc is a daemon with which you can create a virtual private network (VPN). One daemon can handle multiple connections, so you can diff --git a/debian/init.d b/debian/init.d index 9067c546..1acbe4a1 100644 --- a/debian/init.d +++ b/debian/init.d @@ -1,7 +1,7 @@ #! /usr/bin/perl -w # # System startup script for tinc -# $Id: init.d,v 1.14 2000/06/01 20:21:27 guus Exp $ +# $Id: init.d,v 1.15 2000/10/18 20:12:06 zarq Exp $ # # Based on Lubomir Bulej's Redhat init script. # @@ -68,6 +68,7 @@ sub vpn_load { chomp($VPN); } elsif ( /^[ ]*VpnMask[ =]+([^ \#]+)/i ) { $VPNMASK=$1; + chomp($VPNMASK); } } if(!defined($DEV)) { @@ -108,10 +109,8 @@ sub vpn_load { if(!defined($VPNMASK)) { $VPNMASK = $MSK; + $VPNMASK = join(".", unpack('C4', $VPNMASK)); } - - $VPNMASK = pack('C4', split(/\./, $VPNMASK)); - $VPNMASK = join(".", unpack('C4', $VPNMASK)); $ADR = join(".", unpack('C4', $ADR)); $MSK = join(".", unpack('C4', $MSK)); diff --git a/debian/rules b/debian/rules index 34fcb9ba..397e998b 100644 --- a/debian/rules +++ b/debian/rules @@ -32,7 +32,7 @@ install: build dh_clean -k dh_installdirs - $(MAKE) install prefix=`pwd`/debian/tmp/usr + $(MAKE) install DESTDIR=`pwd`/debian/tmp mkdir -p `pwd`/debian/tmp/etc/tinc/example cp doc/tinc.conf.sample `pwd`/debian/tmp/etc/tinc/example/tinc.conf ln -s /usr/share/doc/tinc/README.Debian `pwd`/debian/tmp/etc/tinc/example/README diff --git a/doc/Makefile.am b/doc/Makefile.am index 09707ed6..9f3f7ebd 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,11 +1,13 @@ ## Process this file with automake to get Makefile.in +SUBDIRS = es + info_TEXINFOS = tinc.texi -dyn_MANS = tincd.8 +dyn_MANS = man_aux = $(dyn_MANS:.8=.x) -man_MANS = tinc.conf.5 genauth.8 $(dyn_MANS) +man_MANS = tincd.8 tinc.conf.5 genauth.8 $(dyn_MANS) PERL = @PERL@ HELP2MAN = help2man diff --git a/doc/tinc.conf.5 b/doc/tinc.conf.5 index bbe1091c..42d9cf28 100644 --- a/doc/tinc.conf.5 +++ b/doc/tinc.conf.5 @@ -59,67 +59,104 @@ one space character. .PP .SH "VARIABLES" .PP -Here are all valid variables, listed in alphabetical order: -.TP -\fBConnectPort = \fIport\fR -Connect to the upstream host (given with the \fBConnectTo\fR -directive) on port \fIport\fR. \fIport\fR may be given in decimal -(default), octal (when preceded by a single zero) or hexadecimal -(prefixed with \fB0x\fR). \fIport\fR is the port number for both the -UDP and the TCP (meta) connections. -.TP -\fBConnectTo = \fB(\fIIP address\fB|\fIhostname\fB)\fR -Specifies which host to connect to on startup. If the -\fBConnectPort\fR variable is omitted, then tinc will try to connect -to port 655. +Here are all valid variables, listed in alphabetical order. The default +value, required or optional is given between parentheses. +.TP +\fBConnectPort\fR = <\fIport\fR> (655) +Connect to the upstream host (given with the \fBConnectTo\fR directive) on +port \fIport\fR. port may be given in decimal (default), octal (when preceded +by a single zero) or hexadecimal (prefixed with 0x). \fIport\fR is the port +number for both the UDP and the TCP (meta) connections. +.TP +\fBConnectTo\fR = <\fIIP address|hostname\fR> (optional) +Specifies which host to connect to on startup. Multiple \fBConnectTo\fR variables +may be specified, if connecting to the first one fails then tinc will try +the next one, and so on. It is possible to specify hostnames for dynamic IP +addresses (like those given on dyndns.org), tinc will not cache the resolved +IP address. -If you don't specify a host with \fBConnectTo\fR, tinc won't connect -at all, and will instead just listen for incoming connections. Only -the initiator of a tinc VPN should need this. +If you don't specify a host with \fBConnectTo\fR, regardless of whether a +value for \fBConnectPort\fR is given, tinc won't connect at all, and will +instead just listen for incoming connections. +.TP +\fBHostnames\fR = <\fIyes|no\fR> (no) +This option selects whether IP addresses (both real and on the VPN) should +be resolved. Since DNS lookups are blocking, it might affect tinc's +efficiency, even stopping the daemon for a few seconds everytime it does +a lookup if your DNS server is not responding. + +This does not affect resolving hostnames to IP addresses from the configuration +file. +.TP +\fBIndirectData\fR = <\fIyes|no\fR> (no) +This option specifies whether other tinc daemons besides the one you +specified with \fBConnectTo\fR can make a direct connection to you. This is +especially useful if you are behind a firewall and it is impossible +to make a connection from the outside to your tinc daemon. Otherwise, +it is best to leave this option out or set it to no. .TP -\fBKeyExpire = \fIs\fR -The secret (and public) key expires after \fIs\fR seconds. The default -is 3600 seconds, or one hour. +\fBInterface\fR = <\fIdevice\fR> (optional) +If you have more than one network interface in your computer, tinc will by +default listen on all of them for incoming connections. It is possible to +bind tinc to a single interface like eth0 or ppp0 with this variable. +.TP +\fBInterfaceIP\fR = <\fIlocal address\fR> (optional) +If your computer has more than one IP address on a single interface (for example +if you are running virtual hosts), tinc will by default listen on all of them for +incoming connections. It is possible to bind tinc to a single IP address with +this variable. It is still possible to listen on several interfaces at the same +time though, if they share the same IP address. +.TP +\fBKeyExpire\fR = <\fIseconds\fR> (3600) +This option controls the time the encryption keys used to encrypt the data +are valid. It is common practice to change keys at regular intervals to +make it even harder for crackers, even though it is thought to be nearly +impossible to crack a single key. +.TP +\fBListenPort\fR = <\fIport\fR> (655) +Listen on local port \fIport\fR. The computer connecting to this daemon should +use this number as the argument for his \fBConnectPort\fR. +.TP +\fBMyOwnVPNIP\fR = <\fIlocal address[/maskbits]\fR> (required) +The \fIlocal address\fR is the number that the daemon will propagate to +other daemons on the network when it is identifying itself. Hence this +will be the file name of the passphrase file that the other end expects +to find the passphrase in. -If you make it shorter, a lot of time and bandwidth is spent -negotiating over the new keys. If you make it longer, you make -yourself more vulnerable to crackers, because they have more data to -work with. The best value depends on the speed of the link, and the -amount of data that goes over it. -.TP -\fBListenPort = \fIport\fR -Listen on local port \fIport\fR. The computer connecting to this -daemon should use this number as the argument for his -\fBConnectPort\fR. Again, the default is 655. -.TP -\fBMyOwnVPNIP = \fInetwork address\fR[\fB/\fImaskbits\fR] -The \fInetwork address\fR is the number that the daemon will propagate -to other daemons on the network when it is identifying itself. Hence -this will be the file name of the passphrase file that the other end -expects to find the passphrase in. +The local address is the IP address of the tap device, not the real IP +address of the host running tincd. Due to changes in recent kernels, it +is also necessary that you make the ethernet (also known as MAC) address +equal to the IP address (see the example). \fImaskbits\fR is the number of bits set to 1 in the netmask part. .TP -\fBMyVirtualIP = \fInetwork address\fR[\fB/\fImaskbits\fR] +\fBMyVirtualIP\fR = <\fIlocal address[/maskbits]> This is an alias for \fBMyOwnVPNIP\fR. .TP -\fBPassphrases = \fIdirectory\fR -The directory where tinc will look for passphrases when someone tries -to cennect. Please see the manpage for \fBgenauth\fR(8) for more -information about passphrases as used by tinc. +\fBPassphrases\fR = <\fIdirectory\fR> (/etc/tinc/NETNAME/passphrases) +The directory where tinc will look for passphrases when someone tries to +connect. Please see the manpage for genauth(8) for more information +about passphrases as used by tinc. .TP -\fBPingTimeout = \fInumber\fR -The number of seconds of inactivity that tinc will wait before sending -a probe to the other end. If that other end doesn't answer within that +\fBPingTimeout\fR = <\fIseconds\fR> (5) +The number of seconds of inactivity that tinc will wait before sending a +probe to the other end. If that other end doesn't answer within that same amount of seconds, the connection is terminated, and the others will be notified of this. .TP -\fBTapDevice = \fIdevice\fR +\fBTapDevice\fR = <\fIdevice\fR> (/dev/tap0) The ethertap device to use. Note that you can only use one device per daemon. The info pages of the tinc package contain more information -about configuring an ethertap device for linux. +about configuring an ethertap device for Linux. +.TP +\fBTCPonly\fR = <\fIyes|no\fR> (no, experimental) +If this variable is set to yes, then the packets are tunnelled over a TCP +connection instead of a UDP connection. This is especially useful for those +who want to run a tinc daemon from behind a masquerading firewall, or if +UDP packet routing is disabled somehow. This is experimental code, +try this at your own risk. .TP -\fBNetMask = \fImask\fR +\fBVpnMask\fR = <\fImask\fR> (optional) The mask that defines the scope of the entire VPN. This option is not used by the tinc daemon itself, but can be used by startup scripts to configure the ethertap devices correctly. diff --git a/doc/tinc.texi b/doc/tinc.texi index 10004234..50ff6616 100644 --- a/doc/tinc.texi +++ b/doc/tinc.texi @@ -1,4 +1,5 @@ \input texinfo @c -*-texinfo-*- +@c $Id: tinc.texi,v 1.9 2000/10/18 20:12:06 zarq Exp $ @c %**start of header @setfilename tinc.info @settitle tinc Manual @@ -12,40 +13,45 @@ This is the info manual for tinc, a Virtual Private Network daemon. -Copyright 1998,199,2000 Ivo Timmermans +Copyright @copyright{} 1998,199,2000 Ivo Timmermans +, Guus Sliepen and +Wessel Dankers . - Permission is granted to make and distribute verbatim - copies of this manual provided the copyright notice and - this permission notice are preserved on all copies. +$Id: tinc.texi,v 1.9 2000/10/18 20:12:06 zarq Exp $ - Permission is granted to copy and distribute modified - versions of this manual under the conditions for - verbatim copying, provided - that the entire resulting derived work is distributed - under the terms of a permission notice identical to this - one. +Permission is granted to make and distribute verbatim copies of this +manual provided the copyright notice and this permission notice are +preserved on all copies. + +Permission is granted to copy and distribute modified versions of this +manual under the conditions for verbatim copying, provided that the +entire resulting derived work is distributed under the terms of a +permission notice identical to this one. @end ifinfo @titlepage @title tinc Manual @subtitle Setting up a Virtual Private Network with tinc -@author Ivo Timmermans +@author Ivo Timmermans and Guus Sliepen @page @vskip 0pt plus 1filll -Copyright @copyright{} 1998,1999,2000 Ivo Timmermans +@cindex copyright +Copyright @copyright{} 1998,1999,2000 Ivo Timmermans +, Guus Sliepen and +Wessel Dankers . + +$Id: tinc.texi,v 1.9 2000/10/18 20:12:06 zarq Exp $ - Permission is granted to make and distribute verbatim - copies of this manual provided the copyright notice and - this permission notice are preserved on all copies. +Permission is granted to make and distribute verbatim copies of this +manual provided the copyright notice and this permission notice are +preserved on all copies. - Permission is granted to copy and distribute modified - versions of this manual under the conditions for - verbatim copying, provided - that the entire resulting derived work is distributed - under the terms of a permission notice identical to this - one. +Permission is granted to copy and distribute modified versions of this +manual under the conditions for verbatim copying, provided that the +entire resulting derived work is distributed under the terms of a +permission notice identical to this one. @end titlepage @@ -54,8 +60,8 @@ Copyright @copyright{} 1998,1999,2000 Ivo Timmermans @menu * Introduction:: Introduction -* Configuring a Linux system:: Before compiling tinc -* Installing tinc:: +* Installing tinc - preparations:: +* Installing tinc - installation:: * Configuring tinc:: * Running tinc:: * Technical information:: @@ -63,12 +69,14 @@ Copyright @copyright{} 1998,1999,2000 Ivo Timmermans * Concept Index:: All used terms explained @end menu + +@contents + @c ================================================================== -@node Introduction, Configuring a Linux system, Top, Top +@node Introduction, Installing tinc - preparations, Top, Top @chapter Introduction -@c straight from the www page - +@cindex tinc tinc is a Virtual Private Network (VPN) daemon that uses tunneling and encryption to create a secure private network between hosts on the Internet. @@ -86,12 +94,14 @@ process of tinc itself. @menu * VPNs:: Virtual Private Networks in general * tinc:: about tinc +* Supported platforms:: @end menu @c ================================================================== @node VPNs, tinc, Introduction, Introduction @section Virtual Private Networks +@cindex VPN A Virtual Private Network or VPN is a network that can only be accessed by a few elected computers that participate. This goal is achievable in more than just one way. @@ -100,7 +110,7 @@ more than just one way. Private networks can consist of a single stand-alone ethernet LAN. Or even two computers hooked up using a null-modem cable. In these cases, it is -obvious that the network is @emph{private}, noone can access it from the +obvious that the network is @emph{private}, no one can access it from the outside. But if your computers are linked to the internet, the network is not private anymore, unless one uses firewalls to block all private traffic. But then, there is no way to send private data to trusted @@ -131,9 +141,11 @@ that flows over the network. @c ================================================================== -@node tinc, , VPNs, Introduction +@node tinc, Supported platforms, VPNs, Introduction @section tinc +@cindex vpnd +@cindex ethertap I really don't quite remember what got us started, but it must have been Guus' idea. He wrote a simple implementation (about 50 lines of C) that used the @emph{ethertap} device that Linux knows of since somewhere @@ -158,23 +170,101 @@ available too. @c ================================================================== -@node Configuring a Linux system, Installing tinc, Introduction, Top -@chapter Configuring a Linux system +@node Supported platforms, , tinc, Introduction +@section Supported platforms -This chapter contains information on how a Linux system is configured -for the use of tinc. +tinc works on Linux, FreeBSD and Solaris. These are the three platforms +that are supported by the universial TUN/TAP device driver, so if +support for other operating systems is added to this driver, perhaps +tinc will run on them as well. Without this driver, tinc will most +likely compile and run, but it will not be able to send or receive data +packets. + +@c ================================================================== +@subsection Linux + +tinc was first written for Linux running on an intel x86 processor, so +this is the best supported platform. The protocol however, and actually +anything about tinc, has been rewritten to support random byte ordering +and arbitrary word length. So in theory it should run on other +processors that Linux runs on. Take care however, we haven't been able +to really test it yet. If you want to run tinc on another platform than +x86, and want to tell us how it went, please do so. + +tinc uses the ethertap device that is provided in the standard kernel +since version 2.1.60, so anything above that (2.2.x, 2.3.x, and the +2.4.0-testx (which is current at the time of this writing) kernel +versions) is able to support tinc. + + +@c ================================================================== +@subsection FreeBSD + +tinc on FreeBSD relies on the universial TUN/TAP driver for its data +acquisition from the kernel. Therefore, tinc suports the same platforms +as this driver. These are: FreeBSD 3.x, 4.x, 5.x. + + +@c ================================================================== +@subsection Solaris + +tinc on Solaris relies on the universial TUN/TAP driver for its data +acquisition from the kernel. Therefore, tinc suports the same platforms +as this driver. These are: Solaris, 2.1.x. + + +@c +@c +@c +@c +@c +@c +@c Preparing your system +@c +@c +@c +@c +@c + +@c ================================================================== +@node Installing tinc - preparations, Installing tinc - installation, Introduction, Top +@chapter Installing tinc: preparations + +This chapter contains information on how to prepare your system to +support tinc. @menu * Configuring the kernel:: -* Files Needed:: -* Setting up the devices:: +* Libraries:: @end menu @c ================================================================== -@node Configuring the kernel, Files Needed, Configuring a Linux system, Configuring a Linux system +@node Configuring the kernel, Libraries, Installing tinc - preparations, Installing tinc - preparations @section Configuring the kernel +If you are running Linux, chances are good that your kernel already +supports all the devices that tinc needs for proper operation. For +example, the standard kernel from Redhat Linux already has support for +ethertap and netlink compiled in. Debian users can use the modconf +utility to select the modules. If your Linux distribution supports this +method of selecting devices, look out for something called `ethertap', +and `netlink_dev'. You need both these devices. + +If you can install these devices in a similar manner, you may skip this +section. + +@menu +* Configuration of the Linux kernel:: +* Configuration of the FreeBSD kernel:: +* Configuration of the Solaris kernel:: +@end menu + + +@c ================================================================== +@node Configuration of the Linux kernel, Configuration of the FreeBSD kernel, Configuring the kernel, Configuring the kernel +@subsection Configuring the Linux kernel + Since this particular implementation only runs on 2.1 or higher Linux kernels, you should grab one (2.2 is current at this time). A 2.0 port is not really possible, unless someone tells me someone ported the @@ -185,9 +275,11 @@ new kernel, you should read the @uref{http://howto.linuxberg.com/LDP/HOWTO/Kernel-HOWTO.html, Kernel HOWTO} first. Do that now! -Here are the options you have to turn on/off when configuring a new +Here are the options you have to turn on when configuring a new kernel. +For kernel 2.2.x: + @example Code maturity level options [*] Prompt for development and/or incomplete code/drivers @@ -198,6 +290,19 @@ Network device support <*> Ethertap network tap @end example +For kernel 2.3.x and 2.4.x: + +@example +Code maturity level options +[*] Prompt for development and/or incomplete code/drivers +Networking options +[*] Kernel/User netlink socket +<*> Netlink device emulation +Network device support +<*> Universal TUN/TAP device driver support +@end example + + Any other options not mentioned here are not relevant to tinc. If you decide to build any of these as dynamic kernel modules, it's a good idea to add these lines to @file{/etc/modules.conf}. @@ -207,34 +312,179 @@ alias tap0 ethertap alias char-major-36 netlink_dev @end example +If you have a 2.4 kernel, you can also choose to use the `Ethertap +network tap' device. This is marked obsolete, because the universal +TUN/TAP driver is a newer implementation that is supposed to be used in +favor of ethertap. For tinc, it doesn't really matter which one you +choose; based on the device file name, tinc will make the right choice +about what protocol to use. + Finally, after having set up other options, build the kernel and boot -it. Unfortunately it's not possible to insert these modules in a running -kernel. +it. Unfortunately it's not possible to insert these modules in a +running kernel. + + +@c ================================================================== +@node Configuration of the FreeBSD kernel, Configuration of the Solaris kernel, Configuration of the Linux kernel, Configuring the kernel +@subsection Configuring the FreeBSD kernel + +This section will contain information on how to configure your FreeBSD +kernel to support the universal TUN/TAP device. For 5.0 and 4.1 +systems, this is included in the kernel configuration, for earlier +systems (4.0 and 3.x), you need to install the universal TUN/TAP driver +yourself. + +Unfortunately somebody still has to write the text. + + +@c ================================================================== +@node Configuration of the Solaris kernel, , Configuration of the FreeBSD kernel, Configuring the kernel +@subsection Configuring the Solaris kernel + +This section will contain information on how to configure your Solaris +kernel to support the universal TUN/TAP device. You need to install +this driver yourself. + +Unfortunately somebody still has to write the text. + + +@c ================================================================== +@node Libraries, , Configuring the kernel, Installing tinc - preparations +@section Libraries + +@cindex requirements +Before you can configure or build tinc, you need to have the OpenSSL +library installed on your system. If you try to configure tinc without +having installed it, configure will give you an error message, and stop. +@menu +* OpenSSL:: +@end menu + + +@c ================================================================== +@node OpenSSL, , Libraries, Libraries +@subsection OpenSSL + +@cindex OpenSSL +For all cryptography-related functions, tinc uses the functions provided +by the OpenSSL library. We recommend using version 0.9.5 or 0.9.6 of +this library. Other versions may also work, but we can guarantee +nothing. + +If this library is not installed, you wil get an error when configuring +tinc for build. Support for running tinc without having OpenSSL +installed @emph{may} be added in the future. + +You can use your operating system's package manager to install this if +available. Make sure you install the development AND runtime versions +of this package. + +If you have to install OpenSSL manually, you can get the source code +from @url{http://www.openssl.org/}. Instructions on how to configure, +build and install this package are included within the package. Please +make sure you build development and runtime libraries (which is the +default). + + +@c +@c +@c +@c Installing tinc +@c +@c +@c +@c @c ================================================================== -@node Files Needed, Setting up the devices, Configuring the kernel, Configuring a Linux system -@section Files Needed +@node Installing tinc - installation, Configuring tinc, Installing tinc - preparations, Top +@chapter Installing tinc: installation + +If you use Redhat or Debian, you may want to install one of the +precompiled packages for your system. These packages are equipped with +system startup scripts and sample configurations. + +If you don't run either of these systems, or you want to compile tinc +for yourself, you can use the source. The source is distributed under +the GNU General Public License (GPL). Download the source from the +@uref{http://tinc.nl.linux.org/download.html, download page}, which has +the checksums of these files listed; you may wish to check these with +md5sum before continuing. + +tinc comes in a handy autoconf/automake package, which you can just +treat the same as any other package. Which is just untar it, type +`configure' and then `make'. + +More detailed instructions are in the file @file{INSTALL}, which is +included in the source distribution. + +@menu +* Building tinc:: +* System files:: +* Interfaces:: +@end menu + + +@c ================================================================== +@node Building tinc, System files, Installing tinc - installation, Installing tinc - installation +@section Building tinc + +Detailed instructions on configuring the source and building tinc can be +found in the file called @file{INSTALL}. + + +@c ================================================================== +@node System files, Interfaces, Building tinc, Installing tinc - installation +@section System files + +Before you can run tinc, you + +@menu +* Device files:: +* Other files:: +@end menu + -@subsubheading Device files +@c ================================================================== +@node Device files, Other files, System files, System files +@subsection Device files First, you'll need the special device file(s) that form the interface between the kernel and the daemon. +The permissions for these files have to be such that only the super user +may read/write to this file. You'd want this, because otherwise +eavesdropping would become a bit too easy. This does, however, imply +that you'd have to run tincd as root. + +If you use the universal TUN/TAP driver, you have to create the +following device files (unless they already exist): + +@example +mknod -m 600 /dev/... c .. .. +chown 0.0 /dev/... +@end example + +If you want to have more devices, the device numbers will be .. .. ... + +If you use Linux, and you run the new 2.4 kernel using the devfs +filesystem, then the tap device will be automatically generated as +@file{/dev/netlink/tap0}. + +If you use Linux and have kernel 2.2.x, you have to make the ethertap +devices: + @example mknod -m 600 /dev/tap0 c 36 16 chown 0.0 /dev/tap0 @end example -The permissions now will be such that only the super user may read/write -to this file. You'd want this, because otherwise eavesdropping would -become a bit too easy. This does, however, imply that you'd have to run -tincd as root. +Any further ethertap devices have minor device number 16 through 31. -If you want to, you may also create more device files, which would be -numbered 0...15, with minor device numbers 16...31. They all should be -owned by root and have permission 600. +@c ================================================================== +@node Other files, , Device files, System files +@subsection Other files @subsubheading @file{/etc/networks} @@ -245,6 +495,9 @@ symbolic name. For example: myvpn 10.0.0.0 @end example +This has nothing to do with the MyVPNIP configuration variable that will be +discussed later, it is only to make the output of the route command more +legible. @subsubheading @file{/etc/services} @@ -260,15 +513,15 @@ tinc 655/udp TINC @c ================================================================== -@node Setting up the devices, , Files Needed, Configuring a Linux system -@section Setting up the devices +@node Interfaces, , System files, Installing tinc - installation +@section Interfaces Before you can start transmitting data over the tinc tunnel, you must set up the ethertap network devices. First, decide which IP addresses you want to have associated with these -devices, and what network mask they must have. You also need these -numbers when you are going to configure tinc itself. @xref{Configuring +devices, and what network mask they must have. You also need these +numbers when you are going to configure tinc itself. @xref{Configuring tinc}. It doesn't matter much which part you do first, setting up the network @@ -282,42 +535,52 @@ after me: ifconfig tap@emph{n} hw ether fe:fd:@emph{xx}:@emph{xx}:@emph{xx}:@emph{xx} @end example -The @emph{n} here is the number of the ethertap device you want to -use. It should be the same @emph{n} as the one you use for -@file{/dev/tap@emph{n}}. The @emph{xx}s are four hexadecimal numbers +The @emph{n} here is the number of the ethertap device you want to use. +It should be the same @emph{n} as the one you use for +@file{/dev/tap@emph{n}}. The @emph{xx}s are four hexadecimal numbers (0--ff). With previous versions of tincd, it didn't matter what they -were. But newer kernels require properly set up ethernet addresses. -In fact, the old behavior was wrong. It is required that the @emph{xx}s -match MyOwnVPNIP. +were. But newer kernels require properly set up ethernet addresses. In +fact, the old behavior was wrong. It is required that the @emph{xx}s +match the numbers of the IP address you will give to the tap device and +to the MyOwnVPNIP configuration (which will be discussed later). + +@cindex MAC address +@cindex hardware address +@strong{Tip}: for finding out what the MAC address of the tap interface +should be, you can use the following command: @example -ifconfig tap@emph{n} @emph{IP} netmask @emph{mask} +$ printf 'fe:fd:%02x:%02x:%02x:%02x' 10 1 54 1 +fe:fd:0a:01:36:01 @end example -This will activate the device with an IP address @emph{IP} with network -mask @emph{mask}. - +@cindex ifconfig +To activate the device, you have to assign an IP address to it. To set +an IP address @emph{IP} with network mask @emph{mask}, do the following: +@example +ifconfig tap@emph{n} @emph{xx}.@emph{xx}.@emph{xx}.@emph{xx} netmask @emph{mask} +@end example -@c ================================================================== -@node Installing tinc, Configuring tinc, Configuring a Linux system, Top -@chapter Installing tinc - -First download it. This is the -@uref{http://tinc.nl.linux.org/download.html, download -page}, which has the checksums of these files listed; you may wish to -check these with md5sum before continuing. +@cindex netmask +The netmask is the mask of the @emph{entire} VPN network, not just your +own subnet. It is the same netmask you will have to specify with the +VpnMask configuration variable. -tinc comes in a handy autoconf/automake package, which you can just -treat the same as any other package. Which is just untar it, type -`configure' and then `make'. -More detailed instructions are in the file @file{INSTALL}, which is -included in the source distribution. +@c +@c +@c +@c +@c Configuring tinc +@c +@c +@c +@c @c ================================================================== -@node Configuring tinc, Running tinc, Installing tinc, Top +@node Configuring tinc, Running tinc, Installing tinc - installation, Top @chapter Configuring tinc @menu @@ -327,7 +590,6 @@ included in the source distribution. * Example:: @end menu - @c ================================================================== @node Multiple networks, How connections work, Configuring tinc, Configuring tinc @section Multiple networks @@ -395,31 +657,67 @@ out, remember to replace it with at least one space character. @node Variables, , Configuration file, Configuration file @subsection Variables -Here are all valid variables, listed in alphabetical order: +Here are all valid variables, listed in alphabetical order. The default +value, required or optional is given between parentheses. @c straight from the manpage @table @asis -@item ConnectPort = port +@item ConnectPort = (655) Connect to the upstream host (given with the ConnectTo directive) on port port. port may be given in decimal (default), octal (when preceded by a single zero) or hexadecimal (prefixed with 0x). port is the port number for both the UDP and the TCP (meta) connections. -@item ConnectTo = (IP address|hostname) -Specifies which host to connect to on startup. If the ConnectPort -variable is omitted, then tinc will try to connect to port 655. +@item ConnectTo = (optional) +Specifies which host to connect to on startup. Multiple ConnectTo variables +may be specified, if connecting to the first one fails then tinc will try +the next one, and so on. It is possible to specify hostnames for dynamic IP +addresses (like those given on dyndns.org), tinc will not cache the resolved +IP address. If you don't specify a host with ConnectTo, regardless of whether a value for ConnectPort is given, tinc won't connect at all, and will -instead just listen for incoming connections. Only the initiator of a -tinc VPN should need this. - -@item ListenPort = port +instead just listen for incoming connections. + +@item Hostnames = (no) +This option selects whether IP addresses (both real and on the VPN) should +be resolved. Since DNS lookups are blocking, it might affect tinc's +efficiency, even stopping the daemon for a few seconds everytime it does +a lookup if your DNS server is not responding. + +This does not affect resolving hostnames to IP addresses from the configuration +file. + +@item IndirectData = (no) +This option specifies whether other tinc daemons besides the one you +specified with ConnectTo can make a direct connection to you. This is +especially useful if you are behind a firewall and it is impossible +to make a connection from the outside to your tinc daemon. Otherwise, +it is best to leave this option out or set it to no. + +@item Interface = (optional) +If you have more than one network interface in your computer, tinc will by +default listen on all of them for incoming connections. It is possible to +bind tinc to a single interface like eth0 or ppp0 with this variable. + +@item InterfaceIP = (optional) +If your computer has more than one IP address on a single interface (for example +if you are running virtual hosts), tinc will by default listen on all of them for +incoming connections. It is possible to bind tinc to a single IP address with +this variable. It is still possible to listen on several interfaces at the same +time though, if they share the same IP address. + +@item KeyExpire = (3600) +This option controls the time the encryption keys used to encrypt the data +are valid. It is common practice to change keys at regular intervals to +make it even harder for crackers, even though it is thought to be nearly +impossible to crack a single key. + +@item ListenPort = (655) Listen on local port port. The computer connecting to this daemon should -use this number as the argument for his ConnectPort. Again, the -default is 655. +use this number as the argument for his ConnectPort. -@item MyOwnVPNIP = local address[/maskbits] +@item MyOwnVPNIP = (required) The local address is the number that the daemon will propagate to other daemons on the network when it is identifying itself. Hence this will be the file name of the passphrase file that the other end expects @@ -432,36 +730,45 @@ equal to the IP address (see the example). maskbits is the number of bits set to 1 in the netmask part. -@item MyVirtualIP = local address[/maskbits] +@item MyVirtualIP = This is an alias for MyOwnVPNIP. -@item Passphrases = directory +@item Passphrases = (/etc/tinc/NETNAME/passphrases) The directory where tinc will look for passphrases when someone tries to connect. Please see the manpage for genauth(8) for more information about passphrases as used by tinc. -@item PingTimeout = number +@item PingTimeout = (5) The number of seconds of inactivity that tinc will wait before sending a probe to the other end. If that other end doesn't answer within that same amount of seconds, the connection is terminated, and the others will be notified of this. -@item TapDevice = device +@item TapDevice = (/dev/tap0) The ethertap device to use. Note that you can only use one device per daemon. The info pages of the tinc package contain more information about configuring an ethertap device for Linux. -@item VpnMask = mask +@item TCPonly = (no, experimental) +If this variable is set to yes, then the packets are tunnelled over a TCP +connection instead of a UDP connection. This is especially useful for those +who want to run a tinc daemon from behind a masquerading firewall, or if +UDP packet routing is disabled somehow. This is experimental code, +try this at your own risk. + +@item VpnMask = (optional) The mask that defines the scope of the entire VPN. This option is not used by the tinc daemon itself, but can be used by startup scripts to configure the ethertap devices correctly. @end table + @c ================================================================== @node Example, , Configuration file, Configuring tinc @section Example + Imagine the following situation. An A-based company wants to connect three branch offices in B, C and D using the internet. All four offices have a 24/7 connection to the internet. @@ -483,17 +790,19 @@ need to run tincd, but it must do a port forwarding of TCP&UDP on port 655 (unless otherwise configured). In this example, it is assumed that eth0 is the interface that points to -the inner LAN of the office. This could be the same as the interface -that leads to the internet. +the inner LAN of the office, although this could also be the same as the +interface that leads to the internet. The configuration of the real +interface is also shown as a comment, to give you an idea of how these +example host is set up. @subsubheading For A @emph{A} would be configured like this: @example +#ifconfig eth0 10.1.54.1 netmask 255.255.0.0 broadcast 10.1.255.255 ifconfig tap0 hw ether fe:fd:0a:01:36:01 ifconfig tap0 10.1.54.1 netmask 255.0.0.0 -ifconfig eth0 10.1.54.1 netmask 255.255.0.0 broadcast 10.1.255.255 @end example and in /etc/tinc/tinc.conf: @@ -507,9 +816,9 @@ VpnMask = 255.0.0.0 @subsubheading For B @example +#ifconfig eth0 10.2.43.8 netmask 255.255.0.0 broadcast 10.2.255.255 ifconfig tap0 hw ether fe:fd:0a:02:01:0c ifconfig tap0 10.2.1.12 netmask 255.0.0.0 -ifconfig eth0 10.2.43.8 netmask 255.255.0.0 broadcast 10.2.255.255 @end example and in /etc/tinc/tinc.conf: @@ -528,30 +837,33 @@ connect to this node. @subsubheading For C @example +#ifconfig eth0 10.3.69.254 netmask 255.255.0.0 broadcast 10.3.255.255 ifconfig tap0 hw ether fe:fd:0a:03:45:fe ifconfig tap0 10.3.69.254 netmask 255.0.0.0 -ifconfig eth0 10.3.69.254 netmask 255.255.0.0 broadcast 10.3.255.255 @end example and in /etc/tinc/A/tinc.conf: @example MyVirtualIP = 10.3.69.254/16 +TapDevice = /dev/tap1 ConnectTo = 1.2.3.4 ListenPort = 2000 VpnMask = 255.0.0.0 @end example C already has another daemon that runs on port 655, so they have to -reserve another port for tinc. They also use the netname to distinguish +reserve another port for tinc. It can connect to other tinc daemons on +the regular port though, so no ConnectPort variable is needed. +They also use the netname to distinguish between the two. tinc is started with `tincd -n A'. @subsubheading For D @example +#ifconfig tap0 10.4.3.32 netmask 255.255.0.0 broadcast 10.4.255.255 ifconfig tap0 hw ether fe:fd:0a:04:03:20 ifconfig tap0 10.4.3.32 netmask 255.0.0.0 -ifconfig tap0 10.4.3.32 netmask 255.255.0.0 broadcast 10.4.255.255 @end example and in /etc/tinc/tinc.conf: @@ -564,7 +876,8 @@ VpnMask=255.0.0.0 @end example D will be connecting to C, which has a tincd running for this network on -port 2000. Hence they need to put in a ConnectPort. +port 2000. Hence they need to put in a ConnectPort, but it doesn't need +to have a different ListenPort. @subsubheading Authentication @@ -572,17 +885,17 @@ A, B, C and D all generate a passphrase with genauth 2048, the output is stored in /etc/tinc/passphrases/local, except for C, where it should be /etc/tinc/A/passphrases/local. -A stores a copy of B's passphrase in /etc/tinc/passphrases/10.2.0.0 +A stores a copy of B's passphrase in /etc/tinc/passphrases/10.2.1.12 -A stores a copy of C's passphrase in /etc/tinc/passphrases/10.3.0.0 +A stores a copy of C's passphrase in /etc/tinc/passphrases/10.3.69.254 -B stores a copy of A's passphrase in /etc/tinc/passphrases/10.1.0.0 +B stores a copy of A's passphrase in /etc/tinc/passphrases/10.1.54.1 -C stores a copy of A's passphrase in /etc/tinc/A/passphrases/10.1.0.0 +C stores a copy of A's passphrase in /etc/tinc/A/passphrases/10.1.54.1 -C stores a copy of D's passphrase in /etc/tinc/A/passphrases/10.4.0.0 +C stores a copy of D's passphrase in /etc/tinc/A/passphrases/10.4.3.32 -D stores a copy of C's passphrase in /etc/tinc/passphrases/10.3.0.0 +D stores a copy of C's passphrase in /etc/tinc/passphrases/10.3.69.254 @subsubheading Starting @@ -810,16 +1123,47 @@ This chapter is a mixture of ideas, reasoning and explanation, please don't take it too serious. @menu +* Key Types:: * Key Management:: * Authentication:: * Protection:: @end menu +@c ================================================================== +@node Key Types, Key Management, Security, Security +@subsection Key Types +@c FIXME: check if I'm not talking nonsense + +There are several types of encryption keys. Tinc uses two of them, +symmetric private keypairs and public/private keypairs. + +Public/private keypairs are used in public key cryptography. It enables +someone to send out a public key with which other people can encrypt their +data. The encrypted data now can only be decrypted by the person who has +the private key that matches the public key. So, a public key only allows +@emph{other} people to send encrypted messages to you. This is very useful +in setting up private communications channels. Just send out your public key +and other people can talk to you in a secure way. But how can you know +the other person is who he says he is? + +For authentication itself tinc uses symmetric private keypairs, referred +to as a passphrase. The identity of each tinc daemon is defined by it's +passphrase (like you can be identified by your social security number). +Every tinc daemon that is allowed to connect to you has a copy of your +passphrase (hence symmetrical). + +It would also be possible to use public/private keypairs for authentication, +so that you could shout out your public key and don't need to keep it +secret (like the passphrase you would have to send to someone else). Also, +no one else has to know a private key from you. +Both forms have their pros and cons, and at the moment tinc just uses passphrases +(which are computationaly more efficient and perhaps in some way more +secure). @c ================================================================== -@node Key Management, Authentication, Security, Security +@node Key Management, Authentication, Key Types, Security @subsection Key Management -@c FIXME: recheck +@c FIXME change for the current protocol @cindex Diffie-Hellman You can't just send a private encryption key to your peer, because @@ -840,10 +1184,6 @@ mod p. This is then sent to B; while B computes g^b mod p, and transmits this to A, b being generated by B. Both a and b must be smaller than p-1. -These private keys are generated upon startup, and they are not changed -while the connection exists. A possible feature in the future is to -dynamically change the keys, every hour for example. - Both parties then calculate g^ab mod p = k. k is the new, shared, but still secret key. @@ -864,17 +1204,25 @@ system. We will let A transmit a passphrase that is also known to B encrypted with g^a, before A sends this to B. This way, B can check whether A is really A or just someone else. +B will never receive the real passphrase though, because it was +encrypted using public/private keypairs. This way there is no way an +imposter could steal A's passphrase. @cindex passphrase +@c ehrmz... but we only use 1024 bits passphrases ourselves? [guus] This passphrase should be 2304 bits for a symmetric encryption system. But since an asymmetric system is more secure, we could do with 2048 bits. This only holds if the passphrase is very random. These passphrases could be stored in a file that is non-readable by -anyone else but root; e.g. @file{/etc/vpn/passphrases}. +anyone else but root; e.g. @file{/etc/tinc/passphrases} with UID 0 +and permissions mode 700. -The only thing that needs to be taken care of is how A announces its -passphrase to B. +The only thing that needs to be taken care of is how A can securely send +a copy of it's passphrase to B if B doesn't have it yet. This could be +done via mail with PGP, but you should be really convinced of the +identity of the person who owns the email address you are sending this to. +Swapping floppy disks in real life might be the best way to do this! @c ================================================================== @@ -884,6 +1232,7 @@ passphrase to B. Now we have securely hidden our data. But a malicious cracker may still bother you by randomly altering the encrypted data he intercepts. +@c FIXME what the hell is this all about? remove? IT @c ================================================================== @node About us, Concept Index, Technical information, Top diff --git a/lib/Makefile.am b/lib/Makefile.am index 68312785..252eefc4 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,8 +1,9 @@ ## Process this file with automake to produce Makefile.in +# $Id: Makefile.am,v 1.3 2000/10/18 20:12:07 zarq Exp $ noinst_LIBRARIES = libvpn.a -INCLUDES = -I. -I$(top_builddir) +INCLUDES = -I. -I$(top_builddir) -I$(top_srcdir)/intl libvpn_a_SOURCES = xmalloc.c pidfile.c utils.c getopt.c getopt1.c diff --git a/lib/utils.c b/lib/utils.c index f42ee3ac..fc7abe4c 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -1,6 +1,7 @@ /* utils.c -- gathering of some stupid small functions - Copyright (C) 1999 Ivo Timmermans + Copyright (C) 1999,2000 Ivo Timmermans + 2000 Guus Sliepen 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 @@ -17,10 +18,57 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include +#include +#include + #include "config.h" #include +#include + +volatile int (cp_line[]) = {0, 0, 0, 0, 0, 0, 0, 0}; +volatile char (*cp_file[]) = {"?", "?", "?", "?", "?", "?", "?", "?"}; +volatile int cp_index = 0; + +char *hexadecimals = "0123456789ABCDEF"; + +int charhex2bin(char c) +{ + if(isdigit(c)) + return c - '0'; + else + return toupper(c) - 'A' + 10; +} + + +void hex2bin(char *src, char *dst, int length) +{ + int i; + for(i=0; i=0; i--) + { + dst[i*2+1] = hexadecimals[(unsigned char)src[i] & 15]; + dst[i*2] = hexadecimals[(unsigned char)src[i]>>4]; + } +} +char *cp_trace() +{ + syslog(LOG_DEBUG, "Checkpoint trace: %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d ...", + cp_file[(cp_index+7)%8], cp_line[(cp_index+7)%8], + cp_file[(cp_index+6)%8], cp_line[(cp_index+6)%8], + cp_file[(cp_index+5)%8], cp_line[(cp_index+5)%8], + cp_file[(cp_index+4)%8], cp_line[(cp_index+4)%8], + cp_file[(cp_index+3)%8], cp_line[(cp_index+3)%8], + cp_file[(cp_index+2)%8], cp_line[(cp_index+2)%8], + cp_file[(cp_index+1)%8], cp_line[(cp_index+1)%8], + cp_file[cp_index], cp_line[cp_index] + ); +} diff --git a/lib/utils.h b/lib/utils.h index ed6550dc..46465f36 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -1,6 +1,7 @@ /* utils.h -- header file for utils.c - Copyright (C) 1999 Ivo Timmermans + Copyright (C) 1999,2000 Ivo Timmermans + 2000 Guus Sliepen 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 @@ -20,11 +21,27 @@ #ifndef __TINC_UTILS_H__ #define __TINC_UTILS_H__ +#include + +enum { + DEBUG_CONNECTIONS = 0, + DEBUG_PROTOCOL, + DEBUG_STATUS, + DEBUG_ERROR, + DEBUG_META +}; + #define min(a,b) (((a)<(b))?(a):(b)) -#define cp { cp_line = __LINE__; cp_file = __FILE__; } +extern volatile int cp_line[]; +extern volatile char *cp_file[]; +extern volatile int cp_index; + +#define cp { cp_line[cp_index] = __LINE__; cp_file[cp_index] = __FILE__; cp_index++; cp_index %= 8; } +#define ecp { fprintf(stderr, "Explicit checkpoint in %s line %d\n", __FILE__, __LINE__); } -extern volatile int cp_line; -extern volatile char *cp_file; +extern void hex2bin(char *src, char *dst, int length); +extern void bin2hex(char *src, char *dst, int length); +extern char *cp_trace(void); #endif /* __TINC_UTILS_H__ */ diff --git a/lib/xalloc.h b/lib/xalloc.h index 3f8d7792..e77e6a57 100644 --- a/lib/xalloc.h +++ b/lib/xalloc.h @@ -1,3 +1,5 @@ +#include + #ifndef PARAMS # if defined PROTOTYPES || (defined __STDC__ && __STDC__) # define PARAMS(Args) Args diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 38fb571a..150b1aa7 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -87,8 +87,6 @@ xmalloc (n) size_t n; { void *p; - extern char*cp_file; - extern int cp_line; p = malloc (n); if (p == 0) diff --git a/po/POTFILES.in b/po/POTFILES.in index 976c6fd8..df8b507c 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -4,10 +4,12 @@ # Package source files lib/pidfile.c +lib/utils.c src/conf.c -src/encr.c src/genauth.c +src/meta.c src/net.c src/netutl.c src/protocol.c +src/subnet.c src/tincd.c diff --git a/po/nl.po b/po/nl.po index 8849299b..44e097f3 100644 --- a/po/nl.po +++ b/po/nl.po @@ -1,648 +1,708 @@ # Dutch messages for tinc -# Copyright (C) 1999, 2000 Free Software Foundation, Inc. +# Copyright (C) 1999, 2000 Ivo Timmermans, Guus Sliepen. # Ivo Timmermans , 1999, 2000. -# +# Guus Sliepen , 2000. msgid "" msgstr "" -"Project-Id-Version: tinc 1.0pre2\n" -"POT-Creation-Date: 2000-05-31 20:02+0200\n" +"Project-Id-Version: tinc 1.0pre3\n" +"POT-Creation-Date: 2000-10-15 02:53+0200\n" "PO-Revision-Date: 2000-05-31 20:14+02:00\n" -"Last-Translator: Ivo Timmermans \n" +"Last-Translator: Guus Sliepen \n" "Language-Team: Dutch \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=iso-8859-1\n" "Content-Transfer-Encoding: 8bit\n" -#: src/conf.c:158 +#: src/conf.c:164 #, c-format -msgid "%s: %d: Invalid variable name `%s'.\n" -msgstr "%s: %d: Ongeldige variabelenaam `%s'.\n" +msgid "Line %d too long while reading config file %s" +msgstr "Regel %d te lang tijdens het lezen van configuratie bestand %s" -#: src/conf.c:165 +#: src/conf.c:180 #, c-format -msgid "%s: %d: No value given for `%s'.\n" -msgstr "%s: %d: Geen waarde gegeven voor `%s'.\n" +msgid "Invalid variable name on line %d while reading config file %s" +msgstr "" +"Ongeldige naam voor variabele op regel %d tijdens het lezen van configuratie " +"bestand %s" -#: src/conf.c:173 +#: src/conf.c:187 #, c-format -msgid "%s: %d: Invalid value `%s' for variable `%s'.\n" -msgstr "%s: %d: Ongeldige waarde `%s' voor variabele `%s'.\n" +msgid "No value for variable on line %d while reading config file %s" +msgstr "" +"Geen waarde voor variabele op regel %d tijdens het lezen van configuratie " +"bestand %s" -#: src/conf.c:194 +#: src/conf.c:195 #, c-format -msgid "Could not open %s: %s\n" -msgstr "Kon %s niet openen: %s\n" +msgid "Invalid value for variable on line %d while reading config file %s" +msgstr "" +"Ongeldige waarde voor variabele op regel %d tijdens het lezen van " +"configuratie bestand %s" -#: src/encr.c:112 src/net.c:333 +#: src/genauth.c:78 #, c-format -msgid "Could not open %s: %m" -msgstr "Kon %s niet openen: %m" +msgid "Usage: %s bits\n" +msgstr "Gebruik: %s bits\n" -#: src/encr.c:119 +#: src/genauth.c:89 #, c-format -msgid "Illegal passphrase in %s; size would be %d" -msgstr "Ongeldig wachtwoord in %s; grootte zou %d zijn" +msgid "Illegal number: %s\n" +msgstr "Ongeldig nummer: %s\n" -#: src/encr.c:153 +#. Align to bytes for easy mallocing and reading +#: src/genauth.c:95 #, c-format -msgid "Generating %d bits keys." -msgstr "%d bits sleutel genereren." +msgid "Generating %d bits keys:\n" +msgstr "Bezig met genereren van een %d bits sleutel:\n" -#: src/encr.c:157 +#: src/genauth.c:99 +msgid "Done.\n" +msgstr "Klaar.\n" + +#: src/genauth.c:101 #, c-format -msgid "Opening /dev/urandom failed: %m" -msgstr "Openen van /dev/urandom mislukt: %m" +msgid "Public key: %s\n" +msgstr "Publieke sleutel: %s\n" -#: src/encr.c:222 +#: src/genauth.c:102 #, c-format -msgid "Encryption key set to %s" -msgstr "Sleutel ingesteld op %s" +msgid "Private key: %s\n" +msgstr "Privé sleutel: %s\n" -#: src/genauth.c:46 +#: src/meta.c:42 #, c-format -msgid "Usage: %s bits\n" -msgstr "Gebruik: %s bits\n" +msgid "Sending %d bytes of metadata to %s (%s): %s" +msgstr "Verzending %d bytes metadata naar %s (%s): %s" -#: src/genauth.c:55 +#: src/meta.c:57 #, c-format -msgid "Illegal number: %s\n" -msgstr "Ongeldig nummer: %s\n" +msgid "Sending meta data to %s (%s) failed: %m" +msgstr "Fout tijdens verzenden metadata naar %s (%s): %m" -#: src/genauth.c:60 +#: src/meta.c:85 src/net.c:773 #, c-format -msgid "Generating %d bits number" -msgstr "Genereren van %d bits nummer" +msgid "This is a bug: %s:%d: %d:%m %s (%s)" +msgstr "Dit is een programmeerfout: %s:%d: %d:%m %s (%s)" -#: src/genauth.c:65 -msgid "Opening /dev/urandom" -msgstr "Openen van /dev/urandom" +#: src/meta.c:91 +#, c-format +msgid "Metadata socket error for %s (%s): %s" +msgstr "Fout op metadata socket voor %s (%s): %s" -#: src/genauth.c:78 -msgid "File was empty!\n" -msgstr "Bestand was leeg!\n" +#: src/meta.c:110 +#, c-format +msgid "Connection closed by %s (%s)" +msgstr "Verbinding beëindigd door %s (%s)" -#: src/genauth.c:86 -msgid "" -": done.\n" -"The following line should be ENTIRELY copied into a passphrase file:\n" -msgstr "" -": klaar.\n" -"De volgende regel dient in zijn GEHEEL naar een wachtwoordbestand worden " -"gekopieerd:\n" +#: src/meta.c:114 +#, c-format +msgid "Metadata socket read error for %s (%s): %m" +msgstr "Fout op metadata socket voor %s (%s) tijdens lezen: %m" -#: src/genauth.c:98 -msgid ": done.\n" -msgstr ": klaar.\n" +#: src/meta.c:144 +#, c-format +msgid "Got request from %s (%s): %s" +msgstr "Kreeg verzoek van %s (%s): %s" + +#: src/meta.c:162 +#, c-format +msgid "Metadata read buffer overflow for %s (%s)" +msgstr "Metadata leesbuffer overvol voor %s (%s)" #: src/net.c:106 #, c-format -msgid "Sent %d bytes to %lx" -msgstr "%d bytes verzonden naar %lx" +msgid "Sending packet of %d bytes to %s (%s)" +msgstr "Verzending pakket van %d bytes naar %s (%s)" + +#: src/net.c:115 +#, c-format +msgid "Error sending packet to %s (%s): %m" +msgstr "Fout tijdens verzenden pakket naar %s (%s): %m" -#: src/net.c:110 +#: src/net.c:129 #, c-format -msgid "Error sending data: %m" -msgstr "Fout bij verzenden van gegevens: %m" +msgid "Receiving packet of %d bytes" +msgstr "Ontvangst pakket van %d bytes" -#: src/net.c:130 +#: src/net.c:142 #, c-format msgid "Can't write to tap device: %m" msgstr "Kan niet naar tap apparaat schrijven: %m" -#: src/net.c:149 +#: src/net.c:242 +msgid "Queue flushed" +msgstr "Wachtrij leeggemaakt" + +#: src/net.c:257 #, c-format -msgid "packet to queue: %d" -msgstr "pakket naar wachtrij: %d" +msgid "Flushing send queue for %s (%s)" +msgstr "Legen van verzend-wachtrij voor %s (%s)" -#: src/net.c:236 -msgid "queue flushed" -msgstr "wachtrij leeggemaakt" +#: src/net.c:265 +#, c-format +msgid "Flushing receive queue for %s (%s)" +msgstr "Legen van de ontvangst-wachtrij voor %s (%s)" + +#: src/net.c:283 +#, c-format +msgid "Trying to look up %d.%d.%d.%d in connection list failed!" +msgstr "Poging tot opzoeken %d.%d.%d.%d in verbindingslijst mislukte!" -#: src/net.c:251 -msgid "Flushing send queue for " -msgstr "Legen van verzend-wachtrij naar " +#: src/net.c:297 +#, c-format +msgid "Could not open UDP connection to %s (%s)" +msgstr "Kon geen UDP verbinding openen naar %s (%s)" -#: src/net.c:259 -msgid "Flushing receive queue for " -msgstr "Legen van de ontvangst-wachtrij voor " +#: src/net.c:305 +#, c-format +msgid "No valid key known yet for %s (%s), queueing packet" +msgstr "" +"Nog geen geldige sleutel bekend voor %s (%s), pakket wordt in de wachtrij " +"gezet" -#: src/net.c:277 -msgid "trying to look up " -msgstr "proberen op te zoeken van " +#: src/net.c:316 +#, c-format +msgid "%s (%s) is not ready, queueing packet" +msgstr "%s (%s) is niet gereed, pakket wordt in de wachtrij gezet" -#: src/net.c:277 -msgid " in connection list failed." -msgstr " in verbindingslijst mislukte." +#: src/net.c:344 +#, c-format +msgid "Could not open %s: %m" +msgstr "Kon %s niet openen: %m" -#: src/net.c:284 -msgid "There is no remote host I can send this packet to." -msgstr "Er is geen partner waar ik dit pakket naar kan sturen." +#: src/net.c:360 +#, c-format +msgid "%s is a new style tun/tap device" +msgstr "%s is een nieuwe stijl tun/tap apparaat" -#: src/net.c:308 -msgid " is not ready, queueing packet." -msgstr " is niet gereed, pakket wordt in de wachtrij gezet." +#: src/net.c:362 +msgid "tun/tap device will be left unconfigured" +msgstr "tun/tap apparaat wordt ongeconfigureerd gelaten" -#: src/net.c:354 +#: src/net.c:384 #, c-format msgid "Creating metasocket failed: %m" msgstr "Aanmaak van metasocket mislukt: %m" -#: src/net.c:360 src/net.c:409 +#: src/net.c:390 src/net.c:396 src/net.c:458 #, c-format msgid "setsockopt: %m" msgstr "setsockopt: %m" -#: src/net.c:367 src/net.c:416 src/net.c:468 +#: src/net.c:403 src/net.c:465 #, c-format msgid "fcntl: %m" msgstr "fcntl: %m" -#: src/net.c:378 +#: src/net.c:411 +#, c-format +msgid "Unable to bind listen socket to interface %s: %m" +msgstr "Kon luistersocket niet binden aan interface %s: %m" + +#: src/net.c:427 #, c-format msgid "Can't bind to port %hd/tcp: %m" msgstr "Kan niet aan poort %hd/tcp binden: %m" -#: src/net.c:384 +#: src/net.c:433 #, c-format msgid "listen: %m" msgstr "listen: %m" -#: src/net.c:403 src/net.c:451 +#: src/net.c:452 #, c-format msgid "Creating socket failed: %m" msgstr "Aanmaak socket mislukte: %m" -#: src/net.c:427 +#: src/net.c:476 #, c-format msgid "Can't bind to port %hd/udp: %m" msgstr "Kan niet aan poort %hd/udp binden: %m" -#: src/net.c:461 +#: src/net.c:493 #, c-format -msgid ":%d: %m" -msgstr ":%d: %m" +msgid "Trying to connect to %s" +msgstr "Poging tot verbinding met %s" -#: src/net.c:474 +#: src/net.c:503 #, c-format -msgid "Connected to %s:%hd" -msgstr "Verbonden met %s:%hd" - -#: src/net.c:495 -msgid "Could not set up a meta connection." -msgstr "Kon geen metaverbinding aangaan." +msgid "Creating socket for %s port %d failed: %m" +msgstr "Aanmaken socket voor %s poort %d mislukt: %m" -#: src/net.c:519 -msgid "No value for my VPN IP given" -msgstr "Geen waarde gegeven voor mijn VPN IP adres" +#: src/net.c:514 +#, c-format +msgid "%s port %hd: %m" +msgstr "%s poort %hd: %m" -#: src/net.c:533 -msgid "Unable to set up a listening socket" -msgstr "Kon geen luistersocket aanmaken" +#: src/net.c:521 +#, c-format +msgid "fcntl for %s port %d: %m" +msgstr "fcntl voor %s poort %d: %m" -#: src/net.c:539 -msgid "Unable to set up an incoming vpn data socket" -msgstr "Kon geen socket maken voor inkomend vpn verkeer" +#: src/net.c:527 +#, c-format +msgid "Connected to %s port %hd" +msgstr "Verbonden met %s poort %hd" -#: src/net.c:546 +#: src/net.c:547 #, c-format -msgid "Ready: listening on port %d." -msgstr "Gereed: luister op poort %d." +msgid "Error looking up `%s': %m" +msgstr "Fout bij het opzoeken van `%s': %m" -#: src/net.c:569 +#: src/net.c:557 #, c-format -msgid "Still failed to connect to other. Will retry in %d seconds." -msgstr "Wederom niet verbonden met de ander. Nieuwe poging over %d seconden." +msgid "Could not set up a meta connection to %s" +msgstr "Kon geen metaverbinding aangaan met %s" -#: src/net.c:602 -msgid "Try to re-establish outgoing connection in 5 minutes." -msgstr "Poging tot herstellen van uitgaande verbinding over 5 minuten." +#: src/net.c:586 +msgid "Name for tinc daemon required!" +msgstr "Naam voor tinc daemon verplicht!" -#: src/net.c:640 -msgid "Terminating." -msgstr "Beëindigen." +#: src/net.c:594 +msgid "Invalid name for myself!" +msgstr "Ongelige naam voor mijzelf!" -#: src/net.c:654 -msgid "Opening UDP socket to " -msgstr "Tijdens openen van UDP socket naar " +#: src/net.c:600 +msgid "Cannot open host configuration file for myself!" +msgstr "Kan host configuratie bestand voor mijzelf niet openen!" -#: src/net.c:659 -#, c-format -msgid "Creating data socket failed: %m" -msgstr "Aanmaak datasocket mislukt: %m" +#: src/net.c:619 +msgid "Unable to set up a listening socket!" +msgstr "Kon geen luistersocket aanmaken!" -#: src/net.c:669 -msgid "Connecting to " -msgstr "Verbinden naar " +#: src/net.c:625 +msgid "Unable to set up an incoming vpn data socket!" +msgstr "Kon geen socket maken voor inkomend vpn verkeer!" -#: src/net.c:669 +#: src/net.c:632 #, c-format -msgid ":%d failed: %m" -msgstr ":%d mislukt: %m" +msgid "Ready: listening on port %hd" +msgstr "Gereed: luisterend op poort %hd" -#: src/net.c:677 src/net.c:761 src/net.c:954 +#: src/net.c:660 #, c-format -msgid "This is a bug: %s:%d: %d:%m" -msgstr "Dit is een programmeerfout: %s:%d: %d:%m" +msgid "Still failed to connect to other, will retry in %d seconds" +msgstr "Wederom niet verbonden met de ander, nieuwe poging over %d seconden" -#: src/net.c:701 +#: src/net.c:698 #, c-format -msgid "Error: getpeername: %m" -msgstr "Fout: getpeername: %m" +msgid "Trying to re-establish outgoing connection in %d seconds" +msgstr "Poging tot herstellen van uitgaande verbinding over %d seconden" -#: src/net.c:713 -#, c-format -msgid "Connection from %s:%d" -msgstr "Verbinding van %s:%d" +#: src/net.c:736 +msgid "Terminating" +msgstr "Beëindigen" -#: src/net.c:766 +#: src/net.c:750 #, c-format -msgid "Incoming data socket error: %s" -msgstr "Fout op socket voor inkomend verkeer: %s" +msgid "Opening UDP socket to %s" +msgstr "Bezig met openen UDP socket naar %s" -#: src/net.c:774 +#: src/net.c:755 #, c-format -msgid "Receiving data failed: %m" -msgstr "Ontvangen van data mislukt: %m" - -#: src/net.c:787 -msgid "packet from " -msgstr "pakket van " +msgid "Creating UDP socket failed: %m" +msgstr "Aanmaak UDP socket mislukte: %m" -#: src/net.c:787 +#: src/net.c:765 #, c-format -msgid " (len %d)" -msgstr " (lengte %d)" - -#: src/net.c:791 -msgid "Got packet from unknown source " -msgstr "Pakket ontvangen met onbekende afzender " +msgid "Connecting to %s port %d failed: %m" +msgstr "Verbinding naar %s poort %d mislukt: %m" -#: src/net.c:825 +#: src/net.c:798 #, c-format -msgid "Closing connection with %s." -msgstr "Beëindigen verbinding met %s." - -#: src/net.c:841 -msgid "Try to re-establish outgoing connection in 5 seconds." -msgstr "Poging tot herstellen van uitgaande verbinding over 5 seconden." +msgid "Error: getpeername: %m" +msgstr "Fout: getpeername: %m" -#: src/net.c:893 +#: src/net.c:813 #, c-format -msgid "%s (" -msgstr "%s (" - -#: src/net.c:893 -msgid ") didn't respond to ping" -msgstr ") antwoordde niet op verzoeken" +msgid "Connection from %s port %d" +msgstr "Verbinding van %s poort %d" -#: src/net.c:924 +#: src/net.c:861 #, c-format -msgid "Accepting a new connection failed: %m" -msgstr "Aanname van nieuwe verbinding is mislukt: %m" - -#: src/net.c:932 -msgid "Closed attempted connection." -msgstr "Aangenomen verbinding verbroken." +msgid "This is a bug: %s:%d: %d:%m" +msgstr "Dit is een programmeerfout: %s:%d: %d:%m" -#: src/net.c:959 +#: src/net.c:867 #, c-format -msgid "Metadata socket error: %s" -msgstr "Fout op socket voor metaverkeer: %s" - -#: src/net.c:965 -msgid "Metadata read buffer overflow." -msgstr "Metadata ontvangstbuffer overloop." +msgid "Incoming data socket error: %s" +msgstr "Fout op socket voor inkomend verkeer: %s" -#: src/net.c:973 +#: src/net.c:873 #, c-format -msgid "Metadata socket read error: %m" -msgstr "Fout op socket voor metaverkeer: %m" +msgid "Receiving packet failed: %m" +msgstr "Ontvangst pakket mislukt: %m" -#: src/net.c:1000 +#: src/net.c:894 #, c-format -msgid "Unknown request: %s" -msgstr "Onbekend verzoek: %s" +msgid "Closing connection with %s (%s)" +msgstr "Beëindigen verbinding met %s (%s)" -#: src/net.c:1005 +#: src/net.c:937 +msgid "Trying to re-establish outgoing connection in 5 seconds" +msgstr "Poging tot herstellen van uitgaande verbinding over 5 seconden" + +#: src/net.c:967 #, c-format -msgid "Got request: %s" -msgstr "Ontving verzoek: %s" +msgid "%s (%s) didn't respond to PING" +msgstr "%s (%s) antwoordde niet op ping" -#: src/net.c:1009 -msgid "Error while processing request from " -msgstr "Fout tijdens afhandelen van verzoek van " +#: src/net.c:998 +#, c-format +msgid "Accepting a new connection failed: %m" +msgstr "Aanname van nieuwe verbinding is mislukt: %m" -#: src/net.c:1015 -msgid "Bogus data received." -msgstr "Onzinnige data ontvangen." +#: src/net.c:1006 +msgid "Closed attempted connection" +msgstr "Aangenomen verbinding verbroken" -#: src/net.c:1059 +#: src/net.c:1041 #, c-format -msgid "Outgoing data socket error: %s" -msgstr "Fout op socket voor uitgaand verkeer: %s" +msgid "Outgoing data socket error for %s (%s): %s" +msgstr "Fout op socket voor uitgaand verkeer voor %s (%s): %s" -#: src/net.c:1094 +#: src/net.c:1077 #, c-format msgid "Error while reading from tapdevice: %m" -msgstr "Fout tijdens lezen van tap-apparaatbestand: %m" +msgstr "Fout tijdens lezen van tap-apparaatbestand tijdens lezen: %m" -#: src/net.c:1104 +#: src/net.c:1087 #, c-format -msgid "Non-IP ethernet frame %04x from " -msgstr "Niet-IP ethernet pakket %04x van " +msgid "Non-IP ethernet frame %04x from %02x:%02x:%02x:%02x:%02x:%02x" +msgstr "Niet-IP ethernet pakket %04x van %02x:%02x:%02x:%02x:%02x:%02x" -#: src/net.c:1112 -msgid "Dropping short packet" -msgstr "Te kort pakket genegeerd" - -#: src/net.c:1120 +#: src/net.c:1094 #, c-format -msgid "An IP packet (%04x) for " -msgstr "Een IP pakket (%04x) voor " - -#: src/net.c:1120 -msgid " from " -msgstr " van " +msgid "Dropping short packet from %02x:%02x:%02x:%02x:%02x:%02x" +msgstr "Te kort pakket van %02x:%02x:%02x:%02x:%02x:%02x genegeerd" -#: src/net.c:1123 src/protocol.c:110 -msgid " to " -msgstr " naar " - -#: src/net.c:1158 +#: src/net.c:1133 #, c-format msgid "Error while waiting for input: %m" msgstr "Fout tijdens wachten op invoer: %m" -#: src/netutl.c:219 +#: src/netutl.c:115 #, c-format msgid "Error looking up `%s': %s\n" msgstr "Fout bij het opzoeken van `%s': %s\n" -#: src/netutl.c:243 -msgid "Connection list:" -msgstr "Verbindingslijst:" - -#: src/protocol.c:54 +#: src/protocol.c:80 #, c-format -msgid "Send ACK to %s" -msgstr "ACK zenden naar %s" +msgid "Output buffer overflow while sending %s to %s (%s)" +msgstr "Uitvoer buffer overvol tijdens zenden %s naar %s (%s)" -#: src/protocol.c:60 +#: src/protocol.c:87 #, c-format -msgid "send failed: %d:%d: %m" -msgstr "verzenden mislukte: %d:%d: %m" +msgid "Sending %s to %s (%s)" +msgstr "Verzending %s naar %s (%s)" -#: src/protocol.c:64 src/protocol.c:480 +#: src/protocol.c:101 #, c-format -msgid "Connection with %s activated." -msgstr "Verbinding met %s geactiveerd." +msgid "Unknown request from %s (%s)" +msgstr "Onbekend verzoek van %s (%s)" -#: src/protocol.c:73 -msgid "Send TERMREQ to " -msgstr "TERMREQ zenden naar " - -#: src/protocol.c:81 src/protocol.c:99 src/protocol.c:117 src/protocol.c:134 -#: src/protocol.c:148 src/protocol.c:166 src/protocol.c:184 src/protocol.c:212 -#: src/protocol.c:233 src/protocol.c:251 src/protocol.c:265 src/protocol.c:292 -#: src/protocol.c:322 src/protocol.c:656 src/protocol.c:754 +#: src/protocol.c:108 #, c-format -msgid "send failed: %s:%d: %m" -msgstr "verzenden mislukte: %s:%d: %m" - -#: src/protocol.c:92 -msgid "Send TIMEOUT to " -msgstr "TIMEOUT zenden naar " +msgid "Got %s from %s (%s)" +msgstr "Kreeg %s van %s (%s)" -#: src/protocol.c:110 -msgid "Sending delete host " -msgstr "Verzenden van verwijderingsverzoek van " +#: src/protocol.c:114 +#, c-format +msgid "Error while processing %s from %s (%s)" +msgstr "Fout tijdens afhandelen %s van %s (%s)" -#: src/protocol.c:128 -msgid "pinging " -msgstr "pingen van " +#: src/protocol.c:121 +#, c-format +msgid "Bogus data received from %s (%s)" +msgstr "Onzinnige data ontvangen van %s (%s)" -#: src/protocol.c:159 -msgid "Sending add host to " -msgstr "Verzenden van toevoegen van " +#: src/protocol.c:167 +#, c-format +msgid "Got bad ID from %s" +msgstr "Kreeg ongeldige ID van %s" -#: src/protocol.c:177 -msgid "Sending KEY_CHANGED to " -msgstr "KEY_CHANGED verzenden naar " +#: src/protocol.c:175 +#, c-format +msgid "Peer %s (%s) uses incompatible version %d" +msgstr "Ander %s (%s) gebruikt een niet-compatibel protocol versie %d" -#: src/protocol.c:205 -msgid "Send BASIC_INFO to " -msgstr "BASIC_INFO sturen naar " +#: src/protocol.c:184 +#, c-format +msgid "Peer %s uses invalid identity name" +msgstr "Ander %s gebruikt een ongeldige identiteitsnaam" -#: src/protocol.c:226 +#: src/protocol.c:192 #, c-format -msgid "Send PASSPHRASE %s to " -msgstr "PASSPHRASE %s sturen naar " +msgid "Peer %s had unknown identity (%s)" +msgstr "Ander %s heeft een onbekende identiteit (%s)" -#: src/protocol.c:244 +#: src/protocol.c:207 #, c-format -msgid "Send PUBLIC_KEY %s to " -msgstr "PUBLIC_KEY %s verzenden naar " +msgid "Uplink %s (%s) is already in our connection list" +msgstr "%s (%s) staat al in onze verbindingslijst" -#: src/protocol.c:279 -msgid "Attempting to send key request to " -msgstr "Poging tot verzenden van sleutelverzoek naar " +#: src/protocol.c:253 +#, c-format +msgid "Got bad CHALLENGE from %s (%s)" +msgstr "Kreeg ongeldige CHALLENGE van %s (%s)" -#: src/protocol.c:279 src/protocol.c:309 src/protocol.c:643 src/protocol.c:725 -#: src/protocol.c:741 src/protocol.c:781 -msgid ", which does not exist?" -msgstr ", die niet bestaat?" +#: src/protocol.c:261 +#, c-format +msgid "Intruder: wrong challenge length from %s (%s)" +msgstr "Indringer: verkeerde lengte voor uitdaging van %s (%s)" -#: src/protocol.c:285 -msgid "Sending out request for public key to " -msgstr "Verzoek om openbare sleutel verzenden naar " +#: src/protocol.c:287 +#, c-format +msgid "Trying to send CHAL_REPLY to %s (%s) without a valid CHALLENGE" +msgstr "Poging tot zenden CHAL_REPLY naar %s (%s) zonder een geldige CHALLENGE" -#: src/protocol.c:309 -msgid "Attempting to send key answer to " -msgstr "Poging tot verzenden van een sleutel naar " +#: src/protocol.c:318 +#, c-format +msgid "Got bad CHAL_REPLY from %s (%s)" +msgstr "Kreeg ongeldige CHAL_REPLY van %s (%s)" -#: src/protocol.c:315 -msgid "Sending public key to " -msgstr "Verzenden van openbare sleutel naar " +#: src/protocol.c:327 +#, c-format +msgid "Intruder: wrong challenge reply length from %s (%s)" +msgstr "Indringer: verkeerde lengte van antwoord op uitdaging van %s (%s)" -#: src/protocol.c:370 +#: src/protocol.c:344 #, c-format -msgid "got bad BASIC_INFO request: %s" -msgstr "Ongeldig BASIC_INFO verzoek ontvangen: %s" +msgid "Intruder: wrong challenge reply from %s (%s)" +msgstr "Indringer: verkeerd antwoord op de uitdaging van %s (%s)" -#: src/protocol.c:376 +#: src/protocol.c:386 #, c-format -msgid "Peer uses incompatible protocol version %d." -msgstr "De ander gebruikt een niet-compatibel protocol versie %d." +msgid "Removing old entry for %s at %s in favour of new connection from %s" +msgstr "" +"Verwijdering oude verbinding voor %s op %s in voordeel van nieuwe verbinding " +"van %s" -#: src/protocol.c:382 +#: src/protocol.c:398 #, c-format -msgid "got BASIC_INFO(%hd," -msgstr "BASIC_INFO(%hd," +msgid "Connection with %s (%s) activated" +msgstr "Verbinding met %s (%s) geactiveerd" -#: src/protocol.c:382 src/protocol.c:584 -msgid "," -msgstr "," +#: src/protocol.c:438 +#, c-format +msgid "Got bad ADD_SUBNET from %s (%s)" +msgstr "Kreeg ongeldige ADD_SUBNET van %s (%s)" -#: src/protocol.c:382 -msgid ")" -msgstr ") ontvangen" +#: src/protocol.c:447 +#, c-format +msgid "Got bad ADD_SUBNET from %s (%s): invalid identity name" +msgstr "Kreeg ongeldige ADD_SUBNET van %s (%s): ongeldige identiteitsnaam" -#: src/protocol.c:385 +#: src/protocol.c:456 #, c-format -msgid "Peer uses protocol version %d" -msgstr "De ander gebruikt protocol versie %d" +msgid "Got bad ADD_SUBNET from %s (%s): invalid subnet string" +msgstr "Kreeg ongeldige ADD_SUBNET van %s (%s): ongeldig subnet" -#: src/protocol.c:411 +#: src/protocol.c:467 #, c-format -msgid "got bad PASSPHRASE request: %s" -msgstr "Ongeldig PASSPHRASE verzoek ontvangen: %s" +msgid "Warning: got ADD_SUBNET from %s (%s) for ourself, restarting" +msgstr "Waarschuwing: kreeg ADD_SUBNET van %s (%s) voor onszelf, herstart" -#: src/protocol.c:417 -msgid "got PASSPHRASE" -msgstr "PASSPHRASE ontvangen" +#: src/protocol.c:478 +#, c-format +msgid "Got ADD_SUBNET for %s from %s (%s) which is not in our connection list" +msgstr "" +"Kreeg DEL_SUBNET voor %d.%d.%d.%d van %s (%s) die niet voorkomt in onze " +"verbindingslijst" -#: src/protocol.c:434 +#: src/protocol.c:506 #, c-format -msgid "got bad PUBLIC_KEY request: %s" -msgstr "Ongeldig PUBLIC_KEY verzoek ontvangen: %s" +msgid "Got bad DEL_SUBNET from %s (%s)" +msgstr "Kreeg ongeldige DEL_SUBNET van %s (%s)" -#: src/protocol.c:439 +#: src/protocol.c:515 #, c-format -msgid "got PUBLIC_KEY %s" -msgstr "PUBLIC_KEY %s verzoek ontvangen" +msgid "Got bad DEL_SUBNET from %s (%s): invalid identity name" +msgstr "Kreeg ongeldige DEL_SUBNET van %s (%s): ongeldige identiteitsnaam" -#. intruder! -#: src/protocol.c:444 -msgid "Intruder: passphrase does not match." -msgstr "Indringer: wachwoord komt niet overeen." +#: src/protocol.c:524 +#, c-format +msgid "Got bad DEL_SUBNET from %s (%s): invalid subnet string" +msgstr "Kreeg ongeldige DEL_SUBNET van %s (%s): ongeldige identiteitsnaam" -#: src/protocol.c:449 -msgid "Passphrase OK" -msgstr "Wachtwoord OK" +#: src/protocol.c:535 +#, c-format +msgid "Warning: got DEL_SUBNET from %s (%s) for ourself, restarting" +msgstr "Waarschuwing: kreeg DEL_SUBNET van %s (%s) voor onszelf, herstart" -#: src/protocol.c:477 -msgid "got ACK" -msgstr "ACK ontvangen" +#: src/protocol.c:546 +#, c-format +msgid "Got DEL_SUBNET for %s from %s (%s) which is not in our connection list" +msgstr "" +"Kreeg DEL_SUBNET voor %d.%d.%d.%d van %s (%s) die niet voorkomt in onze " +"verbindingslijst" -#: src/protocol.c:488 -msgid " wants to quit" -msgstr " wil beëindigen" +#: src/protocol.c:577 +#, c-format +msgid "Got bad ADD_HOST from %s (%s)" +msgstr "Kreeg ongeldige ADD_HOST van %s (%s)" -#: src/protocol.c:501 -msgid " says it's gotten a timeout from us" -msgstr " vindt dat wij te traag zijn" +#: src/protocol.c:585 +#, c-format +msgid "Got bad ADD_HOST from %s (%s): invalid identity name" +msgstr "Kreeg ongeldige ADD_HOST van %s (%s): ongeldige identiteitsnaam" -#: src/protocol.c:517 +#: src/protocol.c:594 #, c-format -msgid "got bad DEL_HOST request: %s" -msgstr "Ongeldig DEL_HOST verzoek ontvangen: %s" +msgid "Warning: got ADD_HOST from %s (%s) for ourself, restarting" +msgstr "Waarschuwing: kreeg ADD_HOST van %s (%s) voor onszelf, herstart" -#: src/protocol.c:522 -msgid "got DEL_HOST for " -msgstr "DEL_HOST ontvangen voor " +#: src/protocol.c:604 +#, c-format +msgid "Warning: got ADD_HOST from %s (%s) from ourself, restarting" +msgstr "Waarschuwing: kreeg ADD_HOST van %s (%s) van onszelf, herstart" -#: src/protocol.c:527 -msgid "Somebody wanted to delete " -msgstr "Iemand wilde " +#: src/protocol.c:614 +#, c-format +msgid "" +"Got ADD_HOST from %s (%s) with origin %s which is not in our connection list" +msgstr "" +"Kreeg ADD_HOST van %s (%s) met herkomst %s die niet in onze verbindingslijst " +"voorkomt" -#: src/protocol.c:527 -msgid " which does not exist?" -msgstr " verwijderen, die niet bestaat?" +#: src/protocol.c:633 +#, c-format +msgid "Got duplicate ADD_HOST for %s (%s) from %s (%s)" +msgstr "Kreeg een tweede ADD_HOST voor %s (%s) van %s (%s)" -#: src/protocol.c:545 -msgid "responding to ping from " -msgstr " antwoordde niet op verzoeken" +#: src/protocol.c:640 +#, c-format +msgid "Removing old entry for %s (%s)" +msgstr "Verwijdering oude verbinding voor %s (%s)" -#: src/protocol.c:559 -msgid "ok, got pong from " -msgstr "ok, pong ontvangen van " +#: src/protocol.c:683 +#, c-format +msgid "Got bad DEL_HOST from %s (%s)" +msgstr "Kreeg ongeldige DEL_HOST van %s (%s)" -#: src/protocol.c:577 +#: src/protocol.c:692 #, c-format -msgid "got bad ADD_HOST request: %s" -msgstr "Ongeldig ADD_HOST verzoek ontvangen: %s" +msgid "Got bad DEL_HOST from %s (%s): invalid identity name" +msgstr "Kreeg ongeldige DEL_HOST van %s (%s): ongeldige identiteitsnaam" -#: src/protocol.c:582 -msgid "Add host request from " -msgstr "Ontving verzoek tot toevoegen van " +#: src/protocol.c:701 +#, c-format +msgid "Warning: got DEL_HOST from %s (%s) for ourself, restarting" +msgstr "Waarschuwing: kreeg DEL_HOST van %s (%s) voor onszelf, herstart" -#: src/protocol.c:584 -msgid "got ADD_HOST(" -msgstr "ADD_HOST(" +#: src/protocol.c:712 +#, c-format +msgid "Warning: got DEL_HOST from %s (%s) from ourself, restarting" +msgstr "Waarschuwing: kreeg DEL_HOST van %s (%s) van onszelf, herstart" -#: src/protocol.c:584 +#: src/protocol.c:722 #, c-format -msgid ",%hd)" -msgstr ",%hd) ontvangen" +msgid "" +"Got DEL_HOST from %s (%s) with origin %s which is not in our connection list" +msgstr "" +"Kreeg DEL_HOST voor %s (%s) met herkomst %s die niet in onze " +"verbindingslijst voorkomt" -#: src/protocol.c:596 -msgid "Invalid add_host request from " -msgstr "Ontving ongeldig add_host verzoek van " +#: src/protocol.c:734 +#, c-format +msgid "Got DEL_HOST from %s (%s) for %s which is not in our connection list" +msgstr "" +"Kreeg DEL_HOST van %s (%s) voor %s die niet in onze verbindingslijst voorkomt" -#: src/protocol.c:625 +#: src/protocol.c:744 #, c-format -msgid "got bad request: %s" -msgstr "Ongeldig verzoek ontvangen: %s" +msgid "Got DEL_HOST from %s (%s) for %s which doesn't match" +msgstr "Kreeg DEL_HOST van %s (%s) voor %s wat niet overeenkomt" -#: src/protocol.c:630 -msgid "got REQ_KEY from " -msgstr "REQ_KEY ontvangen van " +#: src/protocol.c:776 +#, c-format +msgid "Got bad STATUS from %s (%s)" +msgstr "Kreeg ongeldige STATUS van %s (%s)" -#: src/protocol.c:630 src/protocol.c:714 -msgid " for " -msgstr " voor " +#: src/protocol.c:783 +#, c-format +msgid "Status message from %s (%s): %s: %s" +msgstr "Ontving statusbericht van %s (%s): %s: %s" -#: src/protocol.c:643 -msgid "Attempting to forward key request to " -msgstr "Poging tot doorsturen van sleutelaanvraag naar " +#: src/protocol.c:807 +#, c-format +msgid "Got bad ERROR from %s (%s)" +msgstr "Kreeg ongeldige ERROR van %s (%s)" -#: src/protocol.c:649 -msgid "Forwarding request for public key to " -msgstr "Doorsturen van openbare sleutel-aanvraag naar " +#: src/protocol.c:814 +#, c-format +msgid "Error message from %s (%s): %s: %s" +msgstr "Ontving foutmelding van %s (%s): %s: %s" -#: src/protocol.c:709 src/protocol.c:769 +#: src/protocol.c:892 #, c-format -msgid "got bad ANS_KEY request: %s" -msgstr "Ongeldig ANS_KEY verzoek ontvangen: %s" +msgid "Got bad KEY_CHANGED from %s (%s)" +msgstr "Kreeg ongeldige KEY_CHANGED van %s (%s)" -#: src/protocol.c:714 -msgid "got ANS_KEY from " -msgstr "ANS_KEY ontvangen van " +#: src/protocol.c:899 +#, c-format +msgid "" +"Got KEY_CHANGED from %s (%s) origin %s which does not exist in our " +"connection list" +msgstr "" +"Kreeg KEY_CHANGED van %s (%s) met herkomst %s die niet in onze " +"verbindingslijst voorkomt" -#: src/protocol.c:720 -msgid "Yeah! key arrived. Now do something with it." -msgstr "Hoi hoi! sleutel is binnen. Doe er nu iets leuks mee." +#: src/protocol.c:929 +#, c-format +msgid "Got bad REQ_KEY from %s (%s)" +msgstr "Kreeg ongeldige REQ_KEY van %s (%s)" -#: src/protocol.c:725 -msgid "Receiving key from " -msgstr "Sleutel ontvangen van " +#: src/protocol.c:936 +#, c-format +msgid "" +"Got REQ_KEY from %s (%s) origin %s which does not exist in our connection " +"list" +msgstr "" +"Kreeg REQ_KEY van %s (%s) herkomst %s die niet in onze verbindingslijst " +"voorkomt" -#: src/protocol.c:741 -msgid "Attempting to forward key to " -msgstr "Poging tot doorsturen van sleutel naar " +#: src/protocol.c:952 +#, c-format +msgid "" +"Got REQ_KEY from %s (%s) destination %s which does not exist in our " +"connection list" +msgstr "" +"Kreeg REQ_KEY van %s (%s) doel %s die niet in onze verbindingslijst voorkomt" -#: src/protocol.c:747 -msgid "Forwarding public key to " -msgstr "Doorsturen van openbare sleutel naar " +#: src/protocol.c:980 +#, c-format +msgid "Got bad ANS_KEY from %s (%s)" +msgstr "Kreeg ongeldige ANS_KEY van %s (%s)" -#: src/protocol.c:774 -msgid "got KEY_CHANGED from " -msgstr "KEY_CHANGED verzoek ontvangen " +#: src/protocol.c:987 +#, c-format +msgid "" +"Got ANS_KEY from %s (%s) origin %s which does not exist in our connection " +"list" +msgstr "" +"Kreeg ANS_KEY van %s (%s) met herkomst %s die niet in onze verbindingslijst " +"voorkomt" -#: src/protocol.c:781 -msgid "Got changed key from " -msgstr "Veranderde sleutel ontvangen van " +#: src/protocol.c:1003 +#, c-format +msgid "Got bad ANS_KEY from %s (%s) origin %s: invalid key" +msgstr "Kreeg ongeldige ANS_KEY van %s (%s) herkomst %s: ongeldige sleutel" -#: src/protocol.c:790 -msgid "Forwarding key invalidation request" -msgstr "Doorsturen van sleutelvervalaanvraag" +#: src/protocol.c:1016 +#, c-format +msgid "" +"Got ANS_KEY from %s (%s) destination %s which does not exist in our " +"connection list" +msgstr "" +"Kreeg ANS_KEY van %s (%s) doel %s die niet in onze verbindingslijst voorkomt" -#: src/tincd.c:95 +#: src/tincd.c:94 #, c-format msgid "Try `%s --help' for more information.\n" msgstr "Probeer `%s --help' voor meer informatie.\n" -#: src/tincd.c:98 +#: src/tincd.c:97 #, c-format msgid "" "Usage: %s [option]...\n" @@ -651,23 +711,23 @@ msgstr "" "Gebruik: %s [optie]...\n" "\n" -#: src/tincd.c:99 +#: src/tincd.c:98 msgid "" -" -c, --config=FILE Read configuration options from FILE.\n" +" -c, --config=DIR Read configuration options from DIR.\n" " -D, --no-detach Don't fork and detach.\n" " -d Increase debug level.\n" " -k, --kill Attempt to kill a running tincd and exit.\n" " -n, --net=NETNAME Connect to net NETNAME.\n" " -t, --timeout=TIMEOUT Seconds to wait before giving a timeout.\n" msgstr "" -" -c, --config=BESTAND Lees configuratie uit BESTAND.\n" +" -c, --config=MAP Lees configuratie uit MAP.\n" " -D, --no-detach Start geen nieuw proces.\n" " -d Verhoog debugniveau.\n" " -k, --kill Poging tot doden van lopende tincd en beëindig.\n" " -n, --net=NETNAAM Verbind met net NETNAAM.\n" " -t, --timeout=TIMEOUT Seconden wachten op timeout.\n" -#: src/tincd.c:105 +#: src/tincd.c:104 msgid "" " --help Display this help and exit.\n" " --version Output version information and exit.\n" @@ -677,138 +737,153 @@ msgstr "" " --version Geef versie informatie en beëindig.\n" "\n" -#: src/tincd.c:107 +#: src/tincd.c:106 msgid "Report bugs to tinc@nl.linux.org.\n" msgstr "" "Meld fouten in het programma aan tinc@nl.linux.org;\n" -"meld fouten in de vertaling aan vertaling@nl.linux.org.\n" +"Meld fouten in de vertaling aan vertaling@nl.linux.org.\n" -#: src/tincd.c:145 +#: src/tincd.c:144 #, c-format msgid "Invalid timeout value `%s'.\n" msgstr "Ongeldige timeout waarde `%s'.\n" -#: src/tincd.c:159 +#: src/tincd.c:158 #, c-format -msgid "Memory exhausted (last is %s:%d) (couldn't allocate %d bytes); exiting." +msgid "Memory exhausted (last is %s:%d) (couldn't allocate %d bytes), exiting." msgstr "" -"Geheugen is vol (laatste %s:%d) (kon geen %d bytes vrijmaken); beëindigen." +"Geheugen is vol (laatste %s:%d) (kon geen %d bytes vrijmaken), beëindigen." -#: src/tincd.c:214 +#: src/tincd.c:213 #, c-format -msgid "tincd %s (%s %s) starting, debug level %d." -msgstr "tincd %s (%s %s) gestart, debugniveau %d." +msgid "tincd %s (%s %s) starting, debug level %d" +msgstr "tincd %s (%s %s) gestart, debugniveau %d" -#: src/tincd.c:217 +#: src/tincd.c:216 #, c-format -msgid "tincd %s starting, debug level %d." -msgstr "tincd %s gestart, debugniveau %d." +msgid "tincd %s starting" +msgstr "tincd %s gestart" -#: src/tincd.c:232 +#: src/tincd.c:231 #, c-format -msgid "Total bytes written: tap %d, socket %d; bytes read: tap %d, socket %d." +msgid "Total bytes written: tap %d, socket %d; bytes read: tap %d, socket %d" msgstr "" "Totaal aantal bytes geschreven: tap %d, socket %d; bytes gelezen: top %d, " "socket %d." -#: src/tincd.c:250 +#: src/tincd.c:249 #, c-format msgid "A tincd is already running for net `%s' with pid %d.\n" msgstr "Een tincd voor net `%s' draait al met procesnummer %d.\n" -#: src/tincd.c:253 +#: src/tincd.c:252 #, c-format msgid "A tincd is already running with pid %d.\n" msgstr "Een tincd draait al met procesnummer %d.\n" -#: src/tincd.c:274 +#: src/tincd.c:273 #, c-format msgid "No other tincd is running for net `%s'.\n" msgstr "Geen andere tincd gevonden voor net `%s'.\n" -#: src/tincd.c:276 +#: src/tincd.c:275 msgid "No other tincd is running.\n" msgstr "Geen andere tincd gevonden.\n" -#: src/tincd.c:283 +#: src/tincd.c:282 msgid "Removing stale lock file.\n" msgstr "Ongebruikt vergrendelingsbestand verwijderd.\n" -#: src/tincd.c:339 +#. Do some intl stuff right now +#: src/tincd.c:325 +msgid "unknown" +msgstr "onbekend" + +#: src/tincd.c:331 #, c-format -msgid "%s version %s\n" -msgstr "%s versie %s\n" +msgid "%s version %s (built %s %s, protocol %d)\n" +msgstr "%s versie %s (gemaakt %s %s, protocol %d)\n" -#: src/tincd.c:340 +#: src/tincd.c:332 msgid "" -"Copyright (C) 1998,1999,2000 Ivo Timmermans and others,\n" -"see the AUTHORS file for a complete list.\n" +"Copyright (C) 1998,1999,2000 Ivo Timmermans, Guus Sliepen and others.\n" +"See the AUTHORS file for a complete list.\n" "\n" "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" "and you are welcome to redistribute it under certain conditions;\n" "see the file COPYING for details.\n" -"\n" msgstr "" -"Copyright (C) 1998,1999,2000 Ivo Timmermans en anderen,\n" -"zie het bestand AUTHORS voor een volledige lijst.\n" +"Copyright (C) 1998,1999,2000 Ivo Timmermans, Guus Sliepen en anderen.\n" +"Zie het bestand AUTHORS voor een volledige lijst.\n" "\n" "tinc wordt gedistribueerd ZONDER ENIGE GARANTIE. Dit is vrije " "programmatuur,\n" "en je bent welkom om het te distribueren onder bepaalde voorwaarden;\n" "zie het bestand COPYING voor details.\n" -"\n" -#: src/tincd.c:345 -msgid "" -"This product includes software developed by Eric Young (eay@mincom.oz.au)\n" +#: src/tincd.c:346 +msgid "You must be root to run this program. Sorry.\n" msgstr "" -"Dit produkt bevat programmatuur ontwikkeld door Eric Young " -"(eay@mincom.oz.au)\n" +"Je moet systeembeheerder zijn om dit programma te kunnen draaien. Sorry.\n" -#: src/tincd.c:355 -msgid "You must be root to run this program. sorry.\n" -msgstr "" -"Je moet systeembeheerder zijn om dit programma te kunnen draaien. sorry.\n" +#: src/tincd.c:377 +msgid "Unrecoverable error" +msgstr "Onherstelbare fout" + +#: src/tincd.c:382 +#, c-format +msgid "Restarting in %d seconds!" +msgstr "Herstart in %d seconden!" + +#: src/tincd.c:387 src/tincd.c:433 +msgid "Aieee! Not restarting." +msgstr "Waaah! Geen herstart." -#: src/tincd.c:390 +#: src/tincd.c:397 msgid "Got TERM signal" msgstr "Kreeg TERM signaal" -#: src/tincd.c:398 +#: src/tincd.c:405 msgid "Got QUIT signal" msgstr "Kreeg QUIT signaal" -#: src/tincd.c:405 +#: src/tincd.c:412 msgid "Got another SEGV signal: not restarting" msgstr "Kreeg nog een SEGV signaal: niet herstarten" -#: src/tincd.c:413 -#, c-format -msgid "Got SEGV signal after %s line %d. Trying to re-execute." -msgstr "Kreeg SEGV signaal na %s regel %d. Probeer opnieuw opstarten." +#: src/tincd.c:419 +msgid "Got SEGV signal" +msgstr "Kreeg SEGV signaal" -#: src/tincd.c:416 -msgid "Got SEGV signal; trying to re-execute." -msgstr "Kreeg SEGV signaal; probeer opnieuw opstarten." +#: src/tincd.c:424 +msgid "Trying to re-execute in 5 seconds..." +msgstr "Poging tot herstaren over 5 seconden..." -#: src/tincd.c:429 -msgid "Got HUP signal" -msgstr "Kreeg HUP signaal" +#: src/tincd.c:442 +msgid "Got HUP signal, rereading configuration and restarting" +msgstr "Kreeg HUP signaal, herlezen configuratie en herstarten" -#: src/tincd.c:439 -msgid "Got INT signal" -msgstr "Kreeg INT signaal" +#: src/tincd.c:450 +msgid "Got INT signal, exiting" +msgstr "Kreeg INT signaal, beëindigen" -#: src/tincd.c:453 -msgid "Forcing new key generation" -msgstr "Nieuwe sleutels geforceerd" +#: src/tincd.c:464 +msgid "Got USR2 signal, forcing new key generation" +msgstr "Kreeg USR2 signaal, nieuwe sleutels geforceerd" -#: src/tincd.c:461 +#: src/tincd.c:473 #, c-format -msgid "Got unexpected signal (%d) after %s line %d." -msgstr "Ontving onverwacht signaal (%d) na %s regel %d." +msgid "Got unexpected signal %d (%s)" +msgstr "Kreeg onverwacht signaal %d (%s)" -#: src/tincd.c:464 -#, c-format -msgid "Got unexpected signal (%d)." -msgstr "Ontving onverwacht signaal (%d)." +#~ msgid "Illegal passphrase in %s; size would be %d" +#~ msgstr "Ongeldig wachtwoord in %s; grootte zou %d zijn" + +#~ msgid "Generating %d bits keys" +#~ msgstr "%d bits sleutel genereren" + +#~ msgid "Opening /dev/urandom failed: %m" +#~ msgstr "Openen van /dev/urandom mislukt: %m" + +#~ msgid "Encryption key set to %s" +#~ msgstr "Sleutel ingesteld op %s" diff --git a/redhat/tinc.spec b/redhat/tinc.spec index eab43466..e5dfb76f 100644 --- a/redhat/tinc.spec +++ b/redhat/tinc.spec @@ -1,6 +1,6 @@ Summary: tinc Virtual Private Network daemon Name: tinc -Version: 1.0pre2 +Version: 1.0pre3 Release: 1 Copyright: GPL Group: System Environment/Daemons diff --git a/src/Makefile.am b/src/Makefile.am index 2cd0df4e..1ffe3d7b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,17 +1,18 @@ ## Produce this file with automake to get Makefile.in +# $Id: Makefile.am,v 1.5 2000/10/18 20:12:08 zarq Exp $ sbin_PROGRAMS = tincd genauth genauth_SOURCES = genauth.c -tincd_SOURCES = conf.c encr.c net.c netutl.c protocol.c tincd.c +tincd_SOURCES = conf.c connlist.c meta.c net.c netutl.c protocol.c subnet.c tincd.c -INCLUDES = -I$(top_builddir) -I$(top_srcdir)/cipher -I$(top_srcdir)/lib +INCLUDES = -I$(top_builddir) -I$(top_srcdir)/cipher -I$(top_srcdir)/lib -I$(top_srcdir)/intl -noinst_HEADERS = conf.h encr.h net.h netutl.h protocol.h +noinst_HEADERS = conf.h connlist.h meta.h net.h netutl.h protocol.h subnet.h -LIBS = @LIBS@ +LIBS = @LIBS@ @INTLLIBS@ -tincd_LDADD = $(top_builddir)/cipher/libcipher.la \ +tincd_LDADD = \ $(top_builddir)/lib/libvpn.a genauth_LDADD = $(top_builddir)/lib/libvpn.a diff --git a/src/conf.c b/src/conf.c index 35ca4d78..442e3960 100644 --- a/src/conf.c +++ b/src/conf.c @@ -19,52 +19,63 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: conf.c,v 1.9 2000/05/30 11:18:12 zarq Exp $ + $Id: conf.c,v 1.10 2000/10/18 20:12:08 zarq Exp $ */ -#include "config.h" - #include #include #include #include #include #include +#include #include #include "conf.h" #include "netutl.h" /* for strtoip */ +#include /* for cp */ +#include "config.h" +#include "connlist.h" #include "system.h" -config_t *config; +config_t *config = NULL; int debug_lvl = 0; int timeout = 0; /* seconds before timeout */ +char *confbase = NULL; /* directory in which all config files are */ +char *netname = NULL; /* name of the vpn network */ -typedef struct internal_config_t { - char *name; - enum which_t which; - int argtype; -} internal_config_t; +/* Will be set if HUP signal is received. It will be processed when it is safe. */ +int sighup = 0; /* These are all the possible configurable values */ static internal_config_t hazahaza[] = { - { "AllowConnect", allowconnect, TYPE_BOOL }, /* Is not used anywhere. Remove? */ - { "ConnectTo", upstreamip, TYPE_IP }, - { "ConnectPort", upstreamport, TYPE_INT }, - { "ListenPort", listenport, TYPE_INT }, - { "MyOwnVPNIP", myvpnip, TYPE_IP }, - { "MyVirtualIP", myvpnip, TYPE_IP }, /* an alias */ - { "Passphrases", passphrasesdir, TYPE_NAME }, +/* Main configuration file keywords */ + { "Name", tincname, TYPE_NAME }, + { "ConnectTo", connectto, TYPE_NAME }, { "PingTimeout", pingtimeout, TYPE_INT }, { "TapDevice", tapdevice, TYPE_NAME }, + { "TapSubnet", tapsubnet, TYPE_IP }, + { "PrivateKey", privatekey, TYPE_NAME }, { "KeyExpire", keyexpire, TYPE_INT }, - { "VpnMask", vpnmask, TYPE_IP }, { "Hostnames", resolve_dns, TYPE_BOOL }, + { "Interface", interface, TYPE_NAME }, + { "InterfaceIP", interfaceip, TYPE_IP }, +/* Host configuration file keywords */ + { "Address", address, TYPE_NAME }, + { "Port", port, TYPE_INT }, + { "PublicKey", publickey, TYPE_NAME }, + { "Subnet", subnet, TYPE_NAME }, + { "RestrictHosts", restricthosts, TYPE_BOOL }, + { "RestrictSubnets", restrictsubnets, TYPE_BOOL }, + { "RestrictAddress", restrictaddress, TYPE_BOOL }, + { "RestrictPort", restrictport, TYPE_BOOL }, + { "IndirectData", indirectdata, TYPE_BOOL }, + { "TCPonly", tcponly, TYPE_BOOL }, { NULL, 0, 0 } }; @@ -74,12 +85,12 @@ static internal_config_t hazahaza[] = { config_t * add_config_val(config_t **cfg, int argtype, char *val) { - config_t *p; + config_t *p, *r; char *q; - +cp p = (config_t*)xmalloc(sizeof(*p)); p->data.val = 0; - + switch(argtype) { case TYPE_INT: @@ -103,45 +114,56 @@ add_config_val(config_t **cfg, int argtype, char *val) p->data.val = 0; } + p->argtype = argtype; + if(p->data.val) { p->next = *cfg; *cfg = p; +cp return p; } - - free(p); - return NULL; + else + { + free(p); +cp + return NULL; + } } /* - Get variable from a section in a configfile. returns -1 on failure. + Parse a configuration file and put the results in the configuration tree + starting at *base. */ -int -readconfig(const char *fname, FILE *fp) +int read_config_file(config_t **base, const char *fname) { - char *line, *temp_buf; + int err = -1; + FILE *fp; + char line[MAXBUFSIZE]; /* There really should not be any line longer than this... */ char *p, *q; int i, lineno = 0; config_t *cfg; +cp + if((fp = fopen (fname, "r")) == NULL) + { + return -1; + } - line = (char *)xmalloc(80 * sizeof(char)); - temp_buf = (char *)xmalloc(80 * sizeof(char)); - for(;;) { - if(fgets(line, 80, fp) == NULL) - return 0; + if(fgets(line, MAXBUFSIZE, fp) == NULL) + { + err = 0; + break; + } + + lineno++; - while(!index(line, '\n')) + if(!index(line, '\n')) { - fgets(temp_buf, (strlen(line)+1) * 80, fp); - if(!temp_buf) - break; - strcat(line, temp_buf); - line = (char *)xrealloc(line, (strlen(line)+1) * sizeof(char)); + syslog(LOG_ERR, _("Line %d too long while reading config file %s"), lineno, fname); + break; } - lineno++; if((p = strtok(line, "\t\n\r =")) == NULL) continue; /* no tokens on this line */ @@ -155,66 +177,92 @@ readconfig(const char *fname, FILE *fp) if(!hazahaza[i].name) { - fprintf(stderr, _("%s: %d: Invalid variable name `%s'.\n"), - fname, lineno, p); - return -1; + syslog(LOG_ERR, _("Invalid variable name on line %d while reading config file %s"), + lineno, fname); + break; } if(((q = strtok(NULL, "\t\n\r =")) == NULL) || q[0] == '#') { - fprintf(stderr, _("%s: %d: No value given for `%s'.\n"), - fname, lineno, hazahaza[i].name); - return -1; + fprintf(stderr, _("No value for variable on line %d while reading config file %s"), + lineno, fname); + break; } - cfg = add_config_val(&config, hazahaza[i].argtype, q); + cfg = add_config_val(base, hazahaza[i].argtype, q); if(cfg == NULL) { - fprintf(stderr, _("%s: %d: Invalid value `%s' for variable `%s'.\n"), - fname, lineno, q, hazahaza[i].name); - return -1; + fprintf(stderr, _("Invalid value for variable on line %d while reading config file %s"), + lineno, fname); + break; } cfg->which = hazahaza[i].which; if(!config) config = cfg; } -} - -/* - wrapper function for readconfig -*/ -int -read_config_file(const char *fname) -{ - FILE *fp; - - if((fp = fopen (fname, "r")) == NULL) - { - fprintf(stderr, _("Could not open %s: %s\n"), fname, sys_errlist[errno]); - return 1; - } - - if(readconfig(fname, fp)) - return -1; fclose (fp); +cp + return err; +} - return 0; +int read_server_config() +{ + char *fname; + int x; +cp + asprintf(&fname, "%s/tinc.conf", confbase); + x = read_config_file(&config, fname); + free(fname); +cp + return x; } /* Look up the value of the config option type */ -const config_t * -get_config_val(which_t type) +const config_t *get_config_val(config_t *p, which_t type) { - config_t *p; +cp + for(; p != NULL; p = p->next) + if(p->which == type) + break; +cp + return p; +} - for(p = config; p != NULL; p = p->next) +/* + Support for multiple config lines. + Index is used to get a specific value, 0 being the first, 1 the second etc. +*/ +const config_t *get_next_config_val(config_t *p, which_t type, int index) +{ +cp + for(; p != NULL; p = p->next) if(p->which == type) - return p; + if(--index < 0) + break; +cp + return p; +} - /* Not found */ - return NULL; +/* + Remove the complete configuration tree. +*/ +void clear_config(config_t **base) +{ + config_t *p, *next; +cp + for(p = *base; p != NULL; p = next) + { + next = p->next; + if(p->data.ptr && (p->argtype == TYPE_NAME)) + { + free(p->data.ptr); + } + free(p); + } + *base = NULL; +cp } diff --git a/src/conf.h b/src/conf.h index de3d583c..13af26c0 100644 --- a/src/conf.h +++ b/src/conf.h @@ -17,43 +17,60 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: conf.h,v 1.6 2000/05/30 11:18:12 zarq Exp $ + $Id: conf.h,v 1.7 2000/10/18 20:12:08 zarq Exp $ */ #ifndef __TINC_CONF_H__ #define __TINC_CONF_H__ +#define MAXTIMEOUT 900 /* Maximum timeout value for retries. Should this be a configuration option? */ + typedef struct ip_mask_t { unsigned long ip; unsigned long mask; } ip_mask_t; -typedef union data_t { - unsigned long val; - void *ptr; - ip_mask_t *ip; -} data_t; - typedef enum which_t { - passphrasesdir = 1, - upstreamip, - upstreamport, - listenport, - myvpnip, - tapdevice, - allowconnect, + tincname = 1, + connectto, pingtimeout, + tapdevice, + tapsubnet, + privatekey, keyexpire, - vpnmask, - resolve_dns + resolve_dns, + interface, + interfaceip, + address, + port, + publickey, + subnet, + restricthosts, + restrictsubnets, + restrictaddress, + restrictport, + indirectdata, + tcponly, } which_t; typedef struct config_t { struct config_t *next; which_t which; - data_t data; + int argtype; + union data { + unsigned long val; + void *ptr; + ip_mask_t *ip; + struct config_t *next; /* For nested configs! */ + } data; } config_t; +typedef struct internal_config_t { + char *name; + enum which_t which; + int argtype; +} internal_config_t; + enum { stupid_false = 1, stupid_true @@ -69,9 +86,16 @@ enum { extern config_t *config; extern int debug_lvl; extern int timeout; +extern int upstreamindex; +extern int sighup; +extern char *confbase; +extern char *netname; extern config_t *add_config_val(config_t **, int, char *); -extern int read_config_file(const char *); -extern const config_t *get_config_val(which_t type); +extern int read_config_file(config_t **, const char *); +extern const config_t *get_config_val(config_t *, which_t type); +extern const config_t *get_next_config_val(config_t *, which_t type, int); +extern void clear_config(); +extern int read_server_config(void); #endif /* __TINC_CONF_H__ */ diff --git a/src/encr.c b/src/encr.c index 5753de23..8aae04b4 100644 --- a/src/encr.c +++ b/src/encr.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: encr.c,v 1.12 2000/05/31 18:23:06 zarq Exp $ + $Id: encr.c,v 1.13 2000/10/18 20:12:08 zarq Exp $ */ #include "config.h" @@ -61,8 +61,8 @@ int key_inited = 0, encryption_keylen; mpz_t my_private_key, my_public_key, generator, shared_prime; int my_key_expiry = (time_t)(-1); -static char* mypassphrase; -static int mypassphraselen; +char* mypassphrase; +int mypassphraselen; int char_hex_to_bin(int c) { @@ -98,18 +98,17 @@ int read_passphrase(char *which, char **out) cp if((cfg = get_config_val(passphrasesdir)) == NULL) { - filename = xmalloc(strlen(confbase)+13+strlen(which)); - sprintf(filename, "%spassphrases/%s", confbase, which); + asprintf(&filename, "%spassphrases/%s", confbase, which); } else { - filename = xmalloc(strlen(cfg->data.ptr)+2+strlen(which)); - sprintf(filename, "%s/%s", (char*)cfg->data.ptr, which); + asprintf(&filename, "%s/%s", (char*)cfg->data.ptr, which); } if((f = fopen(filename, "rb")) == NULL) { - syslog(LOG_ERR, _("Could not open %s: %m"), filename); + if(debug_lvl > 1) + syslog(LOG_ERR, _("Could not open %s: %m"), filename); return -1; } @@ -119,12 +118,14 @@ cp syslog(LOG_ERR, _("Illegal passphrase in %s; size would be %d"), filename, size); return -1; } - size >>= 2; /* bits->nibbles */ - pp = xmalloc(size+2); - fgets(pp, size+1, f); + + /* Hmz... hackish... strange +1 and +2 stuff... I really like more comments on those alignment thingies! */ + + pp = xmalloc(size/4 + 1); /* Allocate enough for fgets */ + fgets(pp, size/4 + 1, f); /* Read passhrase and reserve one byte for end-of-string */ fclose(f); - *out = xmalloc(size); + *out = xmalloc(size/8 + 2); /* Allocate enough bytes, +1 for rounding if bits%8 != 0, +1 for 2-byte alignment */ cp return str_hex_to_bin(*out, pp); } @@ -150,7 +151,8 @@ cp else my_key_expiry = (time_t)(time(NULL) + cfg->data.val); - syslog(LOG_NOTICE, _("Generating %d bits keys."), PRIVATE_KEY_BITS); + if(debug_lvl > 1) + syslog(LOG_NOTICE, _("Generating %d bits keys"), PRIVATE_KEY_BITS); if((f = fopen("/dev/urandom", "r")) == NULL) { @@ -266,7 +268,7 @@ int verify_passphrase(conn_list_t *cl, unsigned char *his_pubkey) mpz_t pk; unsigned char *out; BF_KEY bf_key; - char which[sizeof("123.123.123.123")+1]; + char *which; char *meuk; cp mpz_init_set_str(pk, his_pubkey, 36); @@ -280,7 +282,7 @@ cp if(key_inited) cipher_set_key(&encryption_key, encryption_keylen, text_key); - sprintf(which, IP_ADDR_S, IP_ADDR_V(cl->vpn_ip)); + asprintf(&which, IP_ADDR_S, IP_ADDR_V(cl->vpn_ip)); if((pplen = read_passphrase(which, &meuk)) < 0) return -1; @@ -335,12 +337,12 @@ cp /* We haven't received a key from this host (yet). */ continue; ek = make_shared_key(p->public_key->key); - free_key(p->key); - p->key = xmalloc(sizeof(*p->key)); - p->key->length = strlen(ek); - p->key->expiry = p->public_key->expiry; - p->key->key = xmalloc(strlen(ek) + 1); - strcpy(p->key->key, ek); + free_key(p->datakey); + p->datakey = xmalloc(sizeof(*p->datakey)); + p->datakey->length = strlen(ek); + p->datakey->expiry = p->public_key->expiry; + p->datakey->key = xmalloc(strlen(ek) + 1); + strcpy(p->datakey->key, ek); } cp } diff --git a/src/encr.h b/src/encr.h index 227c2c8c..e9bc67e4 100644 --- a/src/encr.h +++ b/src/encr.h @@ -15,6 +15,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id: encr.h,v 1.3 2000/10/18 20:12:08 zarq Exp $ */ #ifndef __TINC_ENCR_H__ @@ -30,9 +32,6 @@ extern int my_key_expiry; extern int security_init(void); -extern void do_bf_encrypt(vpn_packet_t *, real_packet_t *); -extern void do_bf_decrypt(real_packet_t *, vpn_packet_t *); - extern int send_portnumbers(int); extern void set_shared_key(char *); extern int send_passphrase(conn_list_t *); diff --git a/src/genauth.c b/src/genauth.c index 1d264576..4527b639 100644 --- a/src/genauth.c +++ b/src/genauth.c @@ -1,6 +1,7 @@ /* - genauth.c -- generate a random passphrase + genauth.c -- generate public/private keypairs Copyright (C) 1998,1999,2000 Ivo Timmermans + 2000 Guus Sliepen 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 @@ -16,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: genauth.c,v 1.7 2000/05/31 18:21:27 zarq Exp $ + $Id: genauth.c,v 1.8 2000/10/18 20:12:08 zarq Exp $ */ #include "config.h" @@ -24,20 +25,49 @@ #include #include #include +#include #include -#include "encr.h" - #include "system.h" -unsigned char initvec[] = { 0x22, 0x7b, 0xad, 0x55, 0x41, 0xf4, 0x3e, 0xf3 }; +#define RSA_PUBLIC_EXPONENT 65535 + +void indicator(int a, int b, void *p) +{ + switch(a) + { + case 0: + fprintf(stderr, "."); + break; + case 1: + fprintf(stderr, "+"); + break; + case 2: + fprintf(stderr, "-"); + break; + case 3: + switch(b) + { + case 0: + fprintf(stderr, " p\n"); + break; + case 1: + fprintf(stderr, " q\n"); + break; + default: + fprintf(stderr, "?"); + } + break; + default: + fprintf(stderr, "?"); + } +} int main(int argc, char **argv) { - FILE *fp; - int bits, c, i, bytes; - unsigned char *p; + int bits; + RSA *key; setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); @@ -51,54 +81,25 @@ int main(int argc, char **argv) if(!argv[1]) argv[1] = "1024"; - - if(!(bits = atol(argv[1]))) + + bits = atol(argv[1]); + + if(bits<32) { fprintf(stderr, _("Illegal number: %s\n"), argv[1]); return 1; } + + bits = ((bits - 1) | 7) + 1; /* Align to bytes for easy mallocing and reading */ - bits = ((bits - 1) | 63) + 1; - fprintf(stderr, _("Generating %d bits number"), bits); - bytes = bits >> 3; + fprintf(stderr, _("Generating %d bits keys:\n"), bits); - if((fp = fopen("/dev/urandom", "r")) == NULL) - { - perror(_("Opening /dev/urandom")); - return 1; - } + key = RSA_generate_key(bits, RSA_PUBLIC_EXPONENT, indicator, NULL); - p = xmalloc(bytes); + fprintf(stderr, _("Done.\n")); - setbuf(stdout, NULL); - for(i = 0; i < bytes; i++) - { - c = fgetc(fp); - if(feof(fp)) - { - puts(""); - fprintf(stderr, _("File was empty!\n")); - } - p[i] = c; - } - fclose(fp); - - if(isatty(1)) - { - fprintf(stderr, _(": done.\nThe following line should be ENTIRELY copied into a passphrase file:\n")); - printf("%d ", bits); - for(i = 0; i < bytes; i++) - printf("%02x", p[i]); - puts(""); - } - else - { - printf("%d ", bits); - for(i = 0; i < bytes; i++) - printf("%02x", p[i]); - puts(""); - fprintf(stderr, _(": done.\n")); - } + printf(_("Public key: %s\n"), BN_bn2hex(key->n)); + printf(_("Private key: %s\n"), BN_bn2hex(key->d)); return 0; } diff --git a/src/net.c b/src/net.c index 54e13232..16ab326c 100644 --- a/src/net.c +++ b/src/net.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.c,v 1.35 2000/05/31 18:23:05 zarq Exp $ + $Id: net.c,v 1.36 2000/10/18 20:12:08 zarq Exp $ */ #include "config.h" @@ -37,7 +37,11 @@ #include #include -#include +#ifdef HAVE_TUNTAP +#include +#include LINUX_IF_TUN_H +#endif + #include #include @@ -46,32 +50,29 @@ #include "net.h" #include "netutl.h" #include "protocol.h" +#include "meta.h" #include "system.h" int tap_fd = -1; - +int taptype = 0; int total_tap_in = 0; int total_tap_out = 0; int total_socket_in = 0; int total_socket_out = 0; +int upstreamindex = 0; static int seconds_till_retry; -/* The global list of existing connections */ -conn_list_t *conn_list = NULL; -conn_list_t *myself = NULL; +char *unknown = NULL; /* strip off the MAC adresses of an ethernet frame */ void strip_mac_addresses(vpn_packet_t *p) { - unsigned char tmp[MAXSIZE]; cp - memcpy(tmp, p->data, p->len); - p->len -= 12; - memcpy(p->data, &tmp[12], p->len); + memmove(p->data, p->data + 12, p->len -= 12); cp } @@ -80,59 +81,68 @@ cp */ void add_mac_addresses(vpn_packet_t *p) { - unsigned char tmp[MAXSIZE]; cp - memcpy(&tmp[12], p->data, p->len); + memcpy(p->data + 12, p->data, p->len); p->len += 12; - tmp[0] = tmp[6] = 0xfe; - tmp[1] = tmp[7] = 0xfd; - *((ip_t*)(&tmp[2])) = (ip_t)(htonl(myself->vpn_ip)); - *((ip_t*)(&tmp[8])) = *((ip_t*)(&tmp[26])); - memcpy(p->data, &tmp[0], p->len); + p->data[0] = p->data[6] = 0xfe; + p->data[1] = p->data[7] = 0xfd; + /* Really evil pointer stuff just below! */ + *((ip_t*)(&p->data[2])) = (ip_t)(htonl(myself->address)); + *((ip_t*)(&p->data[8])) = *((ip_t*)(&p->data[26])); cp } -int xsend(conn_list_t *cl, void *packet) +int xsend(conn_list_t *cl, vpn_packet_t *inpkt) { - int r; - real_packet_t rp; + vpn_packet_t outpkt; + int outlen, outpad; cp - do_encrypt((vpn_packet_t*)packet, &rp, cl->key); - rp.from = htonl(myself->vpn_ip); - rp.data.len = htons(rp.data.len); - rp.len = htons(rp.len); - + outpkt.len = inpkt->len; + EVP_EncryptInit(cl->cipher_pktctx, cl->cipher_pkttype, cl->cipher_pktkey, NULL); + EVP_EncryptUpdate(cl->cipher_pktctx, outpkt.data, &outlen, inpkt->data, inpkt->len); + EVP_EncryptFinal(cl->cipher_pktctx, outpkt.data + outlen, &outpad); + outlen += outpad; + if(debug_lvl > 3) - syslog(LOG_ERR, _("Sent %d bytes to %lx"), ntohs(rp.len), cl->vpn_ip); + syslog(LOG_ERR, _("Sending packet of %d bytes to %s (%s)"), + outlen, cl->name, cl->hostname); + + total_socket_out += outlen; + + cl->want_ping = 1; - if((r = send(cl->socket, (char*)&rp, ntohs(rp.len), 0)) < 0) + if((send(cl->socket, (char *) &(outpkt.len), outlen + 2, 0)) < 0) { - syslog(LOG_ERR, _("Error sending data: %m")); + syslog(LOG_ERR, _("Error sending packet to %s (%s): %m"), + cl->name, cl->hostname); return -1; } - - total_socket_out += r; - - cl->want_ping = 1; cp return 0; } -int xrecv(conn_list_t *cl, void *packet) +int xrecv(vpn_packet_t *inpkt) { - vpn_packet_t vp; - int lenin; + vpn_packet_t outpkt; + int outlen, outpad; cp - do_decrypt((real_packet_t*)packet, &vp, cl->key); - add_mac_addresses(&vp); - - if((lenin = write(tap_fd, &vp, vp.len + sizeof(vp.len))) < 0) + if(debug_lvl > 3) + syslog(LOG_ERR, _("Receiving packet of %d bytes"), + inpkt->len); + + outpkt.len = inpkt->len; + EVP_DecryptInit(myself->cipher_pktctx, myself->cipher_pkttype, myself->cipher_pktkey, NULL); + EVP_DecryptUpdate(myself->cipher_pktctx, outpkt.data, &outlen, inpkt->data, inpkt->len); + /* FIXME: grok DecryptFinal + EVP_DecryptFinal(myself->cipher_pktctx, outpkt.data + outlen, &outpad); + */ + + add_mac_addresses(&outpkt); + + if(write(tap_fd, outpkt.data, outpkt.len) < 0) syslog(LOG_ERR, _("Can't write to tap device: %m")); else - total_tap_out += lenin; - - cl->want_ping = 0; - cl->last_ping_time = time(NULL); + total_tap_out += outpkt.len; cp return 0; } @@ -145,9 +155,6 @@ void add_queue(packet_queue_t **q, void *packet, size_t s) { queue_element_t *e; cp - if(debug_lvl > 3) - syslog(LOG_DEBUG, _("packet to queue: %d"), s); - e = xmalloc(sizeof(*e)); e->packet = xmalloc(s); memcpy(e->packet, packet, s); @@ -233,7 +240,7 @@ cp } if(debug_lvl > 3) - syslog(LOG_DEBUG, _("queue flushed")); + syslog(LOG_DEBUG, _("Queue flushed")); cp } @@ -247,17 +254,17 @@ void flush_queues(conn_list_t *cl) cp if(cl->sq) { - if(debug_lvl > 1) - syslog(LOG_DEBUG, _("Flushing send queue for " IP_ADDR_S), - IP_ADDR_V(cl->vpn_ip)); + if(debug_lvl > 3) + syslog(LOG_DEBUG, _("Flushing send queue for %s (%s)"), + cl->name, cl->hostname); flush_queue(cl, &(cl->sq), xsend); } if(cl->rq) { - if(debug_lvl > 1) - syslog(LOG_DEBUG, _("Flushing receive queue for " IP_ADDR_S), - IP_ADDR_V(cl->vpn_ip)); + if(debug_lvl > 3) + syslog(LOG_DEBUG, _("Flushing receive queue for %s (%s)"), + cl->name, cl->hostname); flush_queue(cl, &(cl->rq), xrecv); } cp @@ -270,42 +277,46 @@ int send_packet(ip_t to, vpn_packet_t *packet) { conn_list_t *cl; cp - if((cl = lookup_conn(to)) == NULL) + if((cl = lookup_conn_list_ipv4(to)) == NULL) { - if(debug_lvl > 2) + if(debug_lvl > 3) { - syslog(LOG_NOTICE, _("trying to look up " IP_ADDR_S " in connection list failed."), + syslog(LOG_NOTICE, _("Trying to look up %d.%d.%d.%d in connection list failed!"), IP_ADDR_V(to)); } - for(cl = conn_list; cl != NULL && !cl->status.outgoing; cl = cl->next); - if(!cl) - { /* No open outgoing connection has been found. */ - if(debug_lvl > 2) - syslog(LOG_NOTICE, _("There is no remote host I can send this packet to.")); - return -1; - } - } - if(my_key_expiry <= time(NULL)) - regenerate_keys(); + return -1; + } + + /* If we ourselves have indirectdata flag set, we should send only to our uplink! */ + /* FIXME - check for indirection and reprogram it The Right Way(tm) this time. */ + if(!cl->status.dataopen) if(setup_vpn_connection(cl) < 0) - return -1; - + { + syslog(LOG_ERR, _("Could not open UDP connection to %s (%s)"), + cl->name, cl->hostname); + return -1; + } + if(!cl->status.validkey) { + if(debug_lvl > 3) + syslog(LOG_INFO, _("No valid key known yet for %s (%s), queueing packet"), + cl->name, cl->hostname); add_queue(&(cl->sq), packet, packet->len + 2); if(!cl->status.waitingforkey) - send_key_request(cl->vpn_ip); /* Keys should be sent to the host running the tincd */ + send_req_key(myself, cl); /* Keys should be sent to the host running the tincd */ return 0; } if(!cl->status.active) { + if(debug_lvl > 3) + syslog(LOG_INFO, _("%s (%s) is not ready, queueing packet"), + cl->name, cl->hostname); add_queue(&(cl->sq), packet, packet->len + 2); - if(debug_lvl > 1) - syslog(LOG_INFO, _(IP_ADDR_S " is not ready, queueing packet."), IP_ADDR_V(cl->vpn_ip)); return 0; /* We don't want to mess up, do we? */ } @@ -322,19 +333,49 @@ int setup_tap_fd(void) int nfd; const char *tapfname; config_t const *cfg; + +#ifdef HAVE_TUNTAP + struct ifreq ifr; +#endif cp - if((cfg = get_config_val(tapdevice)) == NULL) - tapfname = "/dev/tap0"; - else + if((cfg = get_config_val(config, tapdevice))) tapfname = cfg->data.ptr; - + else +#ifdef HAVE_TUNTAP + tapfname = "/dev/misc/net/tun"; +#else + tapfname = "/dev/tap0"; +#endif +cp if((nfd = open(tapfname, O_RDWR | O_NONBLOCK)) < 0) { syslog(LOG_ERR, _("Could not open %s: %m"), tapfname); return -1; } - +cp tap_fd = nfd; + + taptype = 0; + +#ifdef HAVE_TUNTAP + /* Ok now check if this is an old ethertap or a new tun/tap thingie */ + memset(&ifr, 0, sizeof(ifr)); +cp + ifr.ifr_flags = IFF_TAP | IFF_NO_PI; + if (netname) + strncpy(ifr.ifr_name, netname, IFNAMSIZ); +cp + if (!ioctl(tap_fd, TUNSETIFF, (void *) &ifr)) + { + syslog(LOG_INFO, _("%s is a new style tun/tap device"), tapfname); + taptype = 1; + if((cfg = get_config_val(config, tapsubnet)) == NULL) + syslog(LOG_INFO, _("tun/tap device will be left unconfigured")); + else + /* Setup inetaddr/netmask etc */; + } +#endif + cp return 0; } @@ -348,6 +389,7 @@ int setup_listen_meta_socket(int port) int nfd, flags; struct sockaddr_in a; const int one = 1; + config_t const *cfg; cp if((nfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { @@ -361,6 +403,12 @@ cp return -1; } + if(setsockopt(nfd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof(one))) + { + syslog(LOG_ERR, _("setsockopt: %m")); + return -1; + } + flags = fcntl(nfd, F_GETFL); if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) { @@ -368,10 +416,23 @@ cp return -1; } + if((cfg = get_config_val(config, interface))) + { + if(setsockopt(nfd, SOL_SOCKET, SO_KEEPALIVE, cfg->data.ptr, strlen(cfg->data.ptr))) + { + syslog(LOG_ERR, _("Unable to bind listen socket to interface %s: %m"), cfg->data.ptr); + return -1; + } + } + memset(&a, 0, sizeof(a)); a.sin_family = AF_INET; a.sin_port = htons(port); - a.sin_addr.s_addr = htonl(INADDR_ANY); + + if((cfg = get_config_val(config, interfaceip))) + a.sin_addr.s_addr = htonl(cfg->data.ip->ip); + else + a.sin_addr.s_addr = htonl(INADDR_ANY); if(bind(nfd, (struct sockaddr *)&a, sizeof(struct sockaddr))) { @@ -440,7 +501,10 @@ int setup_outgoing_meta_socket(conn_list_t *cl) struct sockaddr_in a; config_t const *cfg; cp - if((cfg = get_config_val(upstreamport)) == NULL) + if(debug_lvl > 0) + syslog(LOG_INFO, _("Trying to connect to %s"), cl->hostname); + + if((cfg = get_config_val(cl->config, port)) == NULL) cl->port = 655; else cl->port = cfg->data.val; @@ -448,30 +512,34 @@ cp cl->meta_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(cl->meta_socket == -1) { - syslog(LOG_ERR, _("Creating socket failed: %m")); + syslog(LOG_ERR, _("Creating socket for %s port %d failed: %m"), + cl->hostname, cl->port); return -1; } a.sin_family = AF_INET; a.sin_port = htons(cl->port); - a.sin_addr.s_addr = htonl(cl->real_ip); + a.sin_addr.s_addr = htonl(cl->address); if(connect(cl->meta_socket, (struct sockaddr *)&a, sizeof(a)) == -1) { - syslog(LOG_ERR, _(IP_ADDR_S ":%d: %m"), IP_ADDR_V(cl->real_ip), cl->port); + syslog(LOG_ERR, _("%s port %hd: %m"), cl->hostname, cl->port); return -1; } flags = fcntl(cl->meta_socket, F_GETFL); if(fcntl(cl->meta_socket, F_SETFL, flags | O_NONBLOCK) < 0) { - syslog(LOG_ERR, _("fcntl: %m")); + syslog(LOG_ERR, _("fcntl for %s port %d: %m"), + cl->hostname, cl->port); return -1; } - cl->hostname = hostlookup(htonl(cl->real_ip)); + if(debug_lvl > 0) + syslog(LOG_INFO, _("Connected to %s port %hd"), + cl->hostname, cl->port); - syslog(LOG_INFO, _("Connected to %s:%hd"), cl->hostname, cl->port); + cl->status.meta = 1; cp return 0; } @@ -483,24 +551,62 @@ cp an authentication sequence during which we will do just that. */ -int setup_outgoing_connection(ip_t ip) +int setup_outgoing_connection(char *name) { conn_list_t *ncn; + struct hostent *h; + config_t *cfg; cp + if(check_id(name)) + { + syslog(LOG_ERR, _("Invalid name for outgoing connection")); + return -1; + } + ncn = new_conn_list(); - ncn->real_ip = ip; + asprintf(&ncn->name, "%s", name); + + if(read_host_config(ncn)) + { + syslog(LOG_ERR, _("Error reading host configuration file for %s")); + free_conn_list(ncn); + return -1; + } + + if(!(cfg = get_config_val(ncn->config, address))) + { + syslog(LOG_ERR, _("No address specified for %s")); + free_conn_list(ncn); + return -1; + } + + if(!(h = gethostbyname(cfg->data.ptr))) + { + syslog(LOG_ERR, _("Error looking up `%s': %m"), cfg->data.ptr); + free_conn_list(ncn); + return -1; + } + ncn->address = ntohl(*((ip_t*)(h->h_addr_list[0]))); + ncn->hostname = hostlookup(htonl(ncn->address)); + if(setup_outgoing_meta_socket(ncn) < 0) { - syslog(LOG_ERR, _("Could not set up a meta connection.")); - free_conn_element(ncn); + syslog(LOG_ERR, _("Could not set up a meta connection to %s"), + ncn->hostname); + free_conn_list(ncn); return -1; } - ncn->status.meta = 1; ncn->status.outgoing = 1; - ncn->next = conn_list; - conn_list = ncn; + ncn->buffer = xmalloc(MAXBUFSIZE); + ncn->buflen = 0; + ncn->last_ping_time = time(NULL); + ncn->want_ping = 0; + + conn_list_add(ncn); + + send_id(ncn); cp return 0; } @@ -514,36 +620,59 @@ int setup_myself(void) cp myself = new_conn_list(); - if(!(cfg = get_config_val(myvpnip))) + asprintf(&myself->hostname, "MYSELF"); /* FIXME? Do hostlookup on ourselves? */ + myself->flags = 0; + myself->protocol_version = PROT_CURRENT; + + if(!(cfg = get_config_val(config, tincname))) /* Not acceptable */ { - syslog(LOG_ERR, _("No value for my VPN IP given")); + syslog(LOG_ERR, _("Name for tinc daemon required!")); return -1; } + else + asprintf(&myself->name, "%s", (char*)cfg->data.val); - myself->vpn_ip = cfg->data.ip->ip; - myself->vpn_mask = cfg->data.ip->mask; + if(check_id(myself->name)) + { + syslog(LOG_ERR, _("Invalid name for myself!")); + return -1; + } - if(!(cfg = get_config_val(listenport))) + if(read_host_config(myself)) + { + syslog(LOG_ERR, _("Cannot open host configuration file for myself!")); + return -1; + } + + if(!(cfg = get_config_val(myself->config, port))) myself->port = 655; else myself->port = cfg->data.val; + if((cfg = get_config_val(myself->config, indirectdata))) + if(cfg->data.val == stupid_true) + myself->flags |= EXPORTINDIRECTDATA; + + if((cfg = get_config_val(myself->config, tcponly))) + if(cfg->data.val == stupid_true) + myself->flags |= TCPONLY; + if((myself->meta_socket = setup_listen_meta_socket(myself->port)) < 0) { - syslog(LOG_ERR, _("Unable to set up a listening socket")); + syslog(LOG_ERR, _("Unable to set up a listening socket!")); return -1; } if((myself->socket = setup_vpn_in_socket(myself->port)) < 0) { - syslog(LOG_ERR, _("Unable to set up an incoming vpn data socket")); + syslog(LOG_ERR, _("Unable to set up an incoming vpn data socket!")); close(myself->meta_socket); return -1; } myself->status.active = 1; - syslog(LOG_NOTICE, _("Ready: listening on port %d."), myself->port); + syslog(LOG_NOTICE, _("Ready: listening on port %hd"), myself->port); cp return 0; } @@ -553,22 +682,30 @@ sigalrm_handler(int a) { config_t const *cfg; cp - cfg = get_config_val(upstreamip); + cfg = get_next_config_val(config, connectto, upstreamindex++); - if(!setup_outgoing_connection(cfg->data.ip->ip)) - { - signal(SIGALRM, SIG_IGN); - } - else + if(!upstreamindex && !cfg) + /* No upstream IP given, we're listen only. */ + return; + + while(cfg) { - signal(SIGALRM, sigalrm_handler); - seconds_till_retry += 5; - if(seconds_till_retry>300) /* Don't wait more than 5 minutes. */ - seconds_till_retry = 300; - alarm(seconds_till_retry); - syslog(LOG_ERR, _("Still failed to connect to other. Will retry in %d seconds."), - seconds_till_retry); + if(!setup_outgoing_connection(cfg->data.ptr)) /* function returns 0 when there are no problems */ + { + signal(SIGALRM, SIG_IGN); + return; + } + cfg = get_next_config_val(config, connectto, upstreamindex++); /* Or else we try the next ConnectTo line */ } + + signal(SIGALRM, sigalrm_handler); + upstreamindex = 0; + seconds_till_retry += 5; + if(seconds_till_retry > MAXTIMEOUT) /* Don't wait more than MAXTIMEOUT seconds. */ + seconds_till_retry = MAXTIMEOUT; + syslog(LOG_ERR, _("Still failed to connect to other, will retry in %d seconds"), + seconds_till_retry); + alarm(seconds_till_retry); cp } @@ -579,7 +716,7 @@ int setup_network_connections(void) { config_t const *cfg; cp - if((cfg = get_config_val(pingtimeout)) == NULL) + if((cfg = get_config_val(config, pingtimeout)) == NULL) timeout = 5; else timeout = cfg->data.val; @@ -590,17 +727,22 @@ cp if(setup_myself() < 0) return -1; - if((cfg = get_config_val(upstreamip)) == NULL) + if((cfg = get_next_config_val(config, connectto, upstreamindex++)) == NULL) /* No upstream IP given, we're listen only. */ return 0; - if(setup_outgoing_connection(cfg->data.ip->ip)) + while(cfg) { - signal(SIGALRM, sigalrm_handler); - seconds_till_retry = 300; - alarm(seconds_till_retry); - syslog(LOG_NOTICE, _("Try to re-establish outgoing connection in 5 minutes.")); + if(!setup_outgoing_connection(cfg->data.ptr)) /* function returns 0 when there are no problems */ + return 0; + cfg = get_next_config_val(config, connectto, upstreamindex++); /* Or else we try the next ConnectTo line */ } + + signal(SIGALRM, sigalrm_handler); + upstreamindex = 0; + seconds_till_retry = MAXTIMEOUT; + syslog(LOG_NOTICE, _("Trying to re-establish outgoing connection in %d seconds"), seconds_till_retry); + alarm(seconds_till_retry); cp return 0; } @@ -637,7 +779,7 @@ cp close(tap_fd); destroy_conn_list(); - syslog(LOG_NOTICE, _("Terminating.")); + syslog(LOG_NOTICE, _("Terminating")); cp return; } @@ -650,31 +792,32 @@ int setup_vpn_connection(conn_list_t *cl) int nfd, flags; struct sockaddr_in a; cp - if(debug_lvl > 1) - syslog(LOG_DEBUG, _("Opening UDP socket to " IP_ADDR_S), IP_ADDR_V(cl->real_ip)); + if(debug_lvl > 0) + syslog(LOG_DEBUG, _("Opening UDP socket to %s"), cl->hostname); nfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if(nfd == -1) { - syslog(LOG_ERR, _("Creating data socket failed: %m")); + syslog(LOG_ERR, _("Creating UDP socket failed: %m")); return -1; } a.sin_family = AF_INET; a.sin_port = htons(cl->port); - a.sin_addr.s_addr = htonl(cl->real_ip); + a.sin_addr.s_addr = htonl(cl->address); if(connect(nfd, (struct sockaddr *)&a, sizeof(a)) == -1) { - syslog(LOG_ERR, _("Connecting to " IP_ADDR_S ":%d failed: %m"), - IP_ADDR_V(cl->real_ip), cl->port); + syslog(LOG_ERR, _("Connecting to %s port %d failed: %m"), + cl->hostname, cl->port); return -1; } flags = fcntl(nfd, F_GETFL); if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) { - syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%m"), __FILE__, __LINE__, nfd); + syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%m %s (%s)"), __FILE__, __LINE__, nfd, + cl->name, cl->hostname); return -1; } @@ -702,21 +845,21 @@ cp return NULL; } + p->name = unknown; + p->address = ntohl(ci.sin_addr.s_addr); p->hostname = hostlookup(ci.sin_addr.s_addr); - p->real_ip = ntohl(ci.sin_addr.s_addr); p->meta_socket = sfd; p->status.meta = 1; + p->buffer = xmalloc(MAXBUFSIZE); p->buflen = 0; p->last_ping_time = time(NULL); p->want_ping = 0; - syslog(LOG_NOTICE, _("Connection from %s:%d"), p->hostname, htons(ci.sin_port)); + if(debug_lvl > 0) + syslog(LOG_NOTICE, _("Connection from %s port %d"), + p->hostname, htons(ci.sin_port)); - if(send_basic_info(p) < 0) - { - free(p); - return NULL; - } + p->allow_request = ID; cp return p; } @@ -749,64 +892,32 @@ cp udp socket and write it to the ethertap device after being decrypted */ -int handle_incoming_vpn_data(conn_list_t *cl) +int handle_incoming_vpn_data() { - real_packet_t rp; + vpn_packet_t pkt; int lenin; int x, l = sizeof(x); - conn_list_t *f; cp - if(getsockopt(cl->socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0) + if(getsockopt(myself->socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0) { - syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%m"), __FILE__, __LINE__, cl->socket); + syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%m"), + __FILE__, __LINE__, myself->socket); return -1; } if(x) { - syslog(LOG_ERR, _("Incoming data socket error: %s"), sys_errlist[x]); + syslog(LOG_ERR, _("Incoming data socket error: %s"), strerror(x)); return -1; } - rp.len = -1; - lenin = recvfrom(cl->socket, &rp, MTU, 0, NULL, NULL); - if(lenin <= 0) + if(recvfrom(myself->socket, (char *) &(pkt.len), MTU, 0, NULL, NULL) <= 0) { - syslog(LOG_ERR, _("Receiving data failed: %m")); + syslog(LOG_ERR, _("Receiving packet failed: %m")); return -1; } - total_socket_in += lenin; - rp.data.len = ntohs(rp.data.len); - rp.len = ntohs(rp.len); - rp.from = ntohl(rp.from); - - if(rp.len >= 0) - { - f = lookup_conn(rp.from); - if(debug_lvl > 3) - syslog(LOG_DEBUG, _("packet from " IP_ADDR_S " (len %d)"), - IP_ADDR_V(rp.from), rp.len); - if(!f) - { - syslog(LOG_ERR, _("Got packet from unknown source " IP_ADDR_S), - IP_ADDR_V(rp.from)); - return -1; - } - - if(f->status.validkey) - xrecv(f, &rp); - else - { - add_queue(&(f->rq), &rp, rp.len); - if(!cl->status.waitingforkey) - send_key_request(rp.from); - } - - if(my_key_expiry <= time(NULL)) - regenerate_keys(); - } cp - return 0; + return xrecv(&pkt); } /* @@ -815,54 +926,58 @@ cp */ void terminate_connection(conn_list_t *cl) { - conn_list_t *p, *q; + conn_list_t *p; cp if(cl->status.remove) return; if(debug_lvl > 0) - syslog(LOG_NOTICE, _("Closing connection with %s."), cl->hostname); - - if(cl->status.timeout) - send_timeout(cl); - else if(!cl->status.termreq) - send_termreq(cl); - - close(cl->socket); + syslog(LOG_NOTICE, _("Closing connection with %s (%s)"), + cl->name, cl->hostname); + + if(cl->socket) + close(cl->socket); if(cl->status.meta) close(cl->meta_socket); - if(cl->status.outgoing) - { - signal(SIGALRM, sigalrm_handler); - seconds_till_retry = 5; - alarm(seconds_till_retry); - syslog(LOG_NOTICE, _("Try to re-establish outgoing connection in 5 seconds.")); - } - - cl->status.active = 0; cl->status.remove = 1; + /* If this cl isn't active, don't send any DEL_HOSTs. */ + +/* FIXME: reprogram this. + if(cl->status.active) + notify_others(cl,NULL,send_del_host); +*/ + cp /* Find all connections that were lost because they were behind cl (the connection that was dropped). */ - for(p = conn_list; p != NULL; p = p->next) - if(p->nexthop == cl) + if(cl->status.meta) + for(p = conn_list; p != NULL; p = p->next) { - p->status.active = 0; - p->status.remove = 1; + if((p->nexthop == cl) && (p != cl)) + { + if(cl->status.active && p->status.active) +/* FIXME: reprogram this + notify_others(p,cl,send_del_host); +*/; + if(cl->socket) + close(cl->socket); + p->status.active = 0; + p->status.remove = 1; + } } - -cp - /* Then send a notification about all these connections to all hosts - that are still connected to us. */ - for(p = conn_list; p != NULL; p = p->next) - if(!p->status.remove && p->status.meta) - for(q = conn_list; q != NULL; q = q->next) - if(q->status.remove) - send_del_host(p, q); - + + cl->status.active = 0; + + if(cl->status.outgoing) + { + signal(SIGALRM, sigalrm_handler); + seconds_till_retry = 5; + alarm(seconds_till_retry); + syslog(LOG_NOTICE, _("Trying to re-establish outgoing connection in 5 seconds")); + } cp } @@ -890,8 +1005,9 @@ cp { if(p->status.pinged && !p->status.got_pong) { - syslog(LOG_INFO, _("%s (" IP_ADDR_S ") didn't respond to ping"), - p->hostname, IP_ADDR_V(p->vpn_ip)); + if(debug_lvl > 1) + syslog(LOG_INFO, _("%s (%s) didn't respond to PING"), + p->name, p->hostname); p->status.timeout = 1; terminate_connection(p); } @@ -913,23 +1029,23 @@ cp accept a new tcp connect and create a new connection */ -int handle_new_meta_connection(conn_list_t *cl) +int handle_new_meta_connection() { conn_list_t *ncn; struct sockaddr client; int nfd, len = sizeof(client); cp - if((nfd = accept(cl->meta_socket, &client, &len)) < 0) + if((nfd = accept(myself->meta_socket, &client, &len)) < 0) { syslog(LOG_ERR, _("Accepting a new connection failed: %m")); return -1; } - if((ncn = create_new_connection(nfd)) == NULL) + if(!(ncn = create_new_connection(nfd))) { shutdown(nfd, 2); close(nfd); - syslog(LOG_NOTICE, _("Closed attempted connection.")); + syslog(LOG_NOTICE, _("Closed attempted connection")); return 0; } @@ -940,98 +1056,6 @@ cp return 0; } -/* - dispatch any incoming meta requests -*/ -int handle_incoming_meta_data(conn_list_t *cl) -{ - int x, l = sizeof(x); - int request, oldlen, i; - int lenin = 0; -cp - if(getsockopt(cl->meta_socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0) - { - syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%m"), __FILE__, __LINE__, cl->meta_socket); - return -1; - } - if(x) - { - syslog(LOG_ERR, _("Metadata socket error: %s"), sys_errlist[x]); - return -1; - } - - if(cl->buflen >= MAXBUFSIZE) - { - syslog(LOG_ERR, _("Metadata read buffer overflow.")); - return -1; - } - - lenin = read(cl->meta_socket, cl->buffer, MAXBUFSIZE-cl->buflen); - - if(lenin<=0) - { - syslog(LOG_ERR, _("Metadata socket read error: %m")); - return -1; - } - - oldlen = cl->buflen; - cl->buflen += lenin; - - for(;;) - { - cl->reqlen = 0; - - for(i = oldlen; i < cl->buflen; i++) - { - if(cl->buffer[i] == '\n') - { - cl->buffer[i] = 0; /* replace end-of-line by end-of-string so we can use sscanf */ - cl->reqlen = i + 1; - break; - } - } - - if(cl->reqlen) - { - if(sscanf(cl->buffer, "%d", &request) == 1) - { - if((request < 0) || (request > 255) || (request_handlers[request] == NULL)) - { - syslog(LOG_ERR, _("Unknown request: %s"), cl->buffer); - return -1; - } - - if(debug_lvl > 3) - syslog(LOG_DEBUG, _("Got request: %s"), cl->buffer); - - if(request_handlers[request](cl)) /* Something went wrong. Probably scriptkiddies. Terminate. */ - { - syslog(LOG_ERR, _("Error while processing request from " IP_ADDR_S), IP_ADDR_V(cl->real_ip)); - return -1; - } - } - else - { - syslog(LOG_ERR, _("Bogus data received.")); - return -1; - } - - cl->buflen -= cl->reqlen; - memmove(cl->buffer, cl->buffer + cl->reqlen, cl->buflen); - oldlen = 0; - } - else - { - break; - } - } - - cl->last_ping_time = time(NULL); - cl->want_ping = 0; -cp - return 0; -} - /* check all connections to see if anything happened on their sockets @@ -1056,14 +1080,15 @@ cp I've once got here when it said `No route to host'. */ getsockopt(p->socket, SOL_SOCKET, SO_ERROR, &x, &l); - syslog(LOG_ERR, _("Outgoing data socket error: %s"), sys_errlist[x]); + syslog(LOG_ERR, _("Outgoing data socket error for %s (%s): %s"), + p->name, p->hostname, strerror(x)); terminate_connection(p); return; } if(p->status.meta) if(FD_ISSET(p->meta_socket, f)) - if(handle_incoming_meta_data(p) < 0) + if(receive_meta(p) < 0) { terminate_connection(p); return; @@ -1071,10 +1096,10 @@ cp } if(FD_ISSET(myself->socket, f)) - handle_incoming_vpn_data(myself); + handle_incoming_vpn_data(); if(FD_ISSET(myself->meta_socket, f)) - handle_new_meta_connection(myself); + handle_new_meta_connection(); cp } @@ -1089,10 +1114,24 @@ void handle_tap_input(void) int ether_type, lenin; cp memset(&vp, 0, sizeof(vp)); - if((lenin = read(tap_fd, &vp, MTU)) <= 0) + + if(taptype = 1) { - syslog(LOG_ERR, _("Error while reading from tapdevice: %m")); - return; + if((lenin = read(tap_fd, vp.data, MTU)) <= 0) + { + syslog(LOG_ERR, _("Error while reading from tapdevice: %m")); + return; + } + vp.len = lenin; + } + else + { + if((lenin = read(tap_fd, &vp, MTU)) <= 0) + { + syslog(LOG_ERR, _("Error while reading from tapdevice: %m")); + return; + } + vp.len = lenin - 2; } total_tap_in += lenin; @@ -1100,33 +1139,21 @@ cp ether_type = ntohs(*((unsigned short*)(&vp.data[12]))); if(ether_type != 0x0800) { - if(debug_lvl > 0) - syslog(LOG_INFO, _("Non-IP ethernet frame %04x from " MAC_ADDR_S), - ether_type, MAC_ADDR_V(vp.data[6])); + if(debug_lvl > 3) + syslog(LOG_INFO, _("Non-IP ethernet frame %04x from %02x:%02x:%02x:%02x:%02x:%02x"), ether_type, MAC_ADDR_V(vp.data[6])); return; } if(lenin < 32) { - if(debug_lvl > 0) - syslog(LOG_INFO, _("Dropping short packet")); + if(debug_lvl > 3) + syslog(LOG_INFO, _("Dropping short packet from %02x:%02x:%02x:%02x:%02x:%02x"), MAC_ADDR_V(vp.data[6])); return; } from = ntohl(*((unsigned long*)(&vp.data[26]))); to = ntohl(*((unsigned long*)(&vp.data[30]))); - if(debug_lvl > 3) - syslog(LOG_DEBUG, _("An IP packet (%04x) for " IP_ADDR_S " from " IP_ADDR_S), - ether_type, IP_ADDR_V(to), IP_ADDR_V(from)); - if(debug_lvl > 4) - syslog(LOG_DEBUG, _(MAC_ADDR_S " to " MAC_ADDR_S), - MAC_ADDR_V(vp.data[0]), MAC_ADDR_V(vp.data[6])); - - vp.len = (length_t)lenin - 2; - - strip_mac_addresses(&vp); - send_packet(to, &vp); cp } @@ -1153,10 +1180,30 @@ cp if((r = select(FD_SETSIZE, &fset, NULL, NULL, &tv)) < 0) { - if(errno == EINTR) /* because of alarm */ - continue; - syslog(LOG_ERR, _("Error while waiting for input: %m")); - return; + if(errno != EINTR) /* because of alarm */ + { + syslog(LOG_ERR, _("Error while waiting for input: %m")); + return; + } + } + + if(sighup) + { + sighup = 0; +/* FIXME: reprogram this. + if(debug_lvl > 1) + syslog(LOG_INFO, _("Rereading configuration file")); + close_network_connections(); + clear_config(); + if(read_config_file(&config, configfilename)) + { + syslog(LOG_ERR, _("Unable to reread configuration file, exiting")); + exit(0); + } + sleep(5); + setup_network_connections(); +*/ + continue; } if(last_ping_check + timeout < time(NULL)) @@ -1164,14 +1211,16 @@ cp { check_dead_connections(); last_ping_check = time(NULL); - continue; } - check_network_activity(&fset); + if(r > 0) + { + check_network_activity(&fset); - /* local tap data */ - if(FD_ISSET(tap_fd, &fset)) - handle_tap_input(); + /* local tap data */ + if(FD_ISSET(tap_fd, &fset)) + handle_tap_input(); + } } cp } diff --git a/src/net.h b/src/net.h index 3dfc3a56..05915361 100644 --- a/src/net.h +++ b/src/net.h @@ -15,6 +15,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id: net.h,v 1.10 2000/10/18 20:12:09 zarq Exp $ */ #ifndef __TINC_NET_H__ @@ -23,7 +25,6 @@ #include #include "config.h" -#include "conf.h" #define MAXSIZE 1700 /* should be a bit more than the MTU for the tapdevice */ #define MTU 1600 @@ -43,9 +44,29 @@ ((unsigned char*)&(x))[1],((unsigned char*)&(x))[0] #endif -#define MAXBUFSIZE 2048 /* Probably way too much, but it must fit every possible request. */ +#define MAXBUFSIZE 4096 /* Probably way too much, but it must fit every possible request. */ + +/* flags */ +#define INDIRECTDATA 0x0001 /* Used to indicate that this host has to be reached indirect */ +#define EXPORTINDIRECTDATA 0x0002 /* Used to indicate uplink that it has to tell others to do INDIRECTDATA */ +#define TCPONLY 0x0004 /* Tells sender to send packets over TCP instead of UDP (for firewalls) */ + +typedef struct mac_t +{ + unsigned char x[6]; +} mac_t; + +typedef unsigned long ipv4_t; + +typedef ipv4_t ip_t; /* alias for ipv4_t */ + +typedef struct ipv6_t +{ + unsigned short x[8]; +} ipv6_t; + +typedef unsigned short port_t; -typedef unsigned long ip_t; typedef short length_t; typedef struct vpn_packet_t { @@ -53,12 +74,6 @@ typedef struct vpn_packet_t { unsigned char data[MAXSIZE]; } vpn_packet_t; -typedef struct real_packet_t { - length_t len; /* the length of the entire packet */ - ip_t from; /* where the packet came from */ - vpn_packet_t data; /* encrypted vpn_packet_t */ -} real_packet_t; - typedef struct passphrase_t { unsigned short len; unsigned char *phrase; @@ -76,9 +91,15 @@ typedef struct status_bits_t { int validkey:1; /* 1 if we currently have a valid key for him */ int waitingforkey:1; /* 1 if we already sent out a request */ int dataopen:1; /* 1 if we have a valid UDP connection open */ - int unused:22; + int encryptout:1; /* 1 if we can encrypt outgoing traffic */ + int decryptin:1; /* 1 if we have to decrypt incoming traffic */ + int unused:18; } status_bits_t; +typedef struct option_bits_t { + int unused:32; +} option_bits_t; + typedef struct queue_element_t { void *packet; struct queue_element_t *prev; @@ -96,31 +117,6 @@ typedef struct enc_key_t { time_t expiry; } enc_key_t; -typedef struct conn_list_t { - ip_t vpn_ip; /* his vpn ip */ - ip_t vpn_mask; /* his vpn network address */ - ip_t real_ip; /* his real (internet) ip */ - char *hostname; /* the hostname of its real ip */ - short unsigned int port; /* his portnumber */ - int socket; /* our udp vpn socket */ - int meta_socket; /* our tcp meta socket */ - int protocol_version; /* used protocol */ - status_bits_t status; /* status info */ - passphrase_t *pp; /* encoded passphrase */ - packet_queue_t *sq; /* pending outgoing packets */ - packet_queue_t *rq; /* pending incoming packets (they have no - valid key to be decrypted with) */ - enc_key_t *public_key; /* the other party's public key */ - enc_key_t *key; /* encrypt with this key */ - char buffer[MAXBUFSIZE+1]; /* metadata input buffer */ - int buflen; /* bytes read into buffer */ - int reqlen; /* length of first request in buffer */ - time_t last_ping_time; /* last time we saw some activity from the other end */ - int want_ping; /* 0 if there's no need to check for activity */ - struct conn_list_t *nexthop; /* nearest meta-hop in this direction */ - struct conn_list_t *next; /* after all, it's a list of connections */ -} conn_list_t; - extern int tap_fd; extern int total_tap_in; @@ -128,15 +124,23 @@ extern int total_tap_out; extern int total_socket_in; extern int total_socket_out; -extern conn_list_t *conn_list; -extern conn_list_t *myself; +extern char *unknown; + +extern char *request_name[256]; +extern char *status_text[10]; + +#include "connlist.h" /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */ +extern int str2opt(const char *); +extern char *opt2str(int); extern int send_packet(ip_t, vpn_packet_t *); extern int setup_network_connections(void); extern void close_network_connections(void); extern void main_loop(void); extern int setup_vpn_connection(conn_list_t *); extern void terminate_connection(conn_list_t *); -extern void flush_queues(conn_list_t*); +extern void flush_queues(conn_list_t *); +extern int xrecv(vpn_packet_t *); +extern void add_queue(packet_queue_t **, void *, size_t); #endif /* __TINC_NET_H__ */ diff --git a/src/netutl.c b/src/netutl.c index c75bea27..f9424442 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: netutl.c,v 1.12 2000/05/31 18:23:06 zarq Exp $ + $Id: netutl.c,v 1.13 2000/10/18 20:12:09 zarq Exp $ */ #include "config.h" @@ -33,6 +33,7 @@ #include #include +#include "errno.h" #include "conf.h" #include "encr.h" #include "net.h" @@ -40,25 +41,6 @@ #include "system.h" -/* - look for a connection associated with the given vpn ip, - return its connection structure. - Skips connections that are not activated! -*/ -conn_list_t *lookup_conn(ip_t ip) -{ - conn_list_t *p = conn_list; -cp - /* Exact match suggested by James B. MacLean */ - for(p = conn_list; p != NULL; p = p->next) - if((ip == p->vpn_ip) && p->status.active) - return p; - for(p = conn_list; p != NULL; p = p->next) - if(((ip & p->vpn_mask) == (p->vpn_ip & p->vpn_mask)) && p->status.active) - return p; -cp - return NULL; -} /* free a queue and all of its elements @@ -79,91 +61,7 @@ cp cp } -/* - free a conn_list_t element and all its pointers -*/ -void free_conn_element(conn_list_t *p) -{ -cp - if(p->hostname) - free(p->hostname); - if(p->sq) - destroy_queue(p->sq); - if(p->rq) - destroy_queue(p->rq); - free_key(p->public_key); - free_key(p->key); - free(p); -cp -} - -/* - remove all marked connections -*/ -void prune_conn_list(void) -{ - conn_list_t *p, *prev = NULL, *next = NULL; -cp - for(p = conn_list; p != NULL; ) - { - next = p->next; - - if(p->status.remove) - { - if(prev) - prev->next = next; - else - conn_list = next; - - free_conn_element(p); - } - else - prev = p; - - p = next; - } -cp -} - -/* - creates new conn_list element, and initializes it -*/ -conn_list_t *new_conn_list(void) -{ - conn_list_t *p = xmalloc(sizeof(*p)); -cp - /* initialise all those stupid pointers at once */ - memset(p, '\0', sizeof(*p)); - p->vpn_mask = (ip_t)(~0L); /* If this isn't done, it would be a - wastebucket for all packets with - unknown destination. */ - p->nexthop = p; -cp - return p; -} - -/* - free all elements of conn_list -*/ -void destroy_conn_list(void) -{ - conn_list_t *p, *next; -cp - for(p = conn_list; p != NULL; ) - { - next = p->next; - free_conn_element(p); - p = next; - } - conn_list = NULL; -cp -} - -/* - look up the name associated with the ip - address `addr' -*/ char *hostlookup(unsigned long addr) { char *name; @@ -175,7 +73,7 @@ cp in.s_addr = addr; lookup_hostname = 0; - if((cfg = get_config_val(resolve_dns)) != NULL) + if((cfg = get_config_val(config, resolve_dns)) != NULL) if(cfg->data.val == stupid_true) lookup_hostname = 1; @@ -184,13 +82,11 @@ cp if(!lookup_hostname || !host) { - name = xmalloc(20); - sprintf(name, "%s", inet_ntoa(in)); + asprintf(&name, "%s", inet_ntoa(in)); } else { - name = xmalloc(strlen(host->h_name)+20); - sprintf(name, "%s (%s)", host->h_name, inet_ntoa(in)); + asprintf(&name, "%s", host->h_name); } cp return name; @@ -216,7 +112,7 @@ cp if(!(h = gethostbyname(p))) { - fprintf(stderr, _("Error looking up `%s': %s\n"), p, sys_errlist[h_errno]); + fprintf(stderr, _("Error looking up `%s': %s\n"), p, strerror(errno)); return NULL; } @@ -236,17 +132,3 @@ cp return ip; } -void dump_conn_list(void) -{ - conn_list_t *p; -cp - syslog(LOG_DEBUG, _("Connection list:")); - - for(p = conn_list; p != NULL; p = p->next) - { - syslog(LOG_DEBUG, " " IP_ADDR_S "/" IP_ADDR_S ": %04x (%d|%d)", - IP_ADDR_V(p->vpn_ip), IP_ADDR_V(p->vpn_mask), p->status, - p->socket, p->meta_socket); - } -cp -} diff --git a/src/netutl.h b/src/netutl.h index f2187406..4c47a077 100644 --- a/src/netutl.h +++ b/src/netutl.h @@ -15,21 +15,17 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id: netutl.h,v 1.3 2000/10/18 20:12:09 zarq Exp $ */ #ifndef __TINC_NETUTL_H__ #define __TINC_NETUTL_H__ #include "net.h" +#include "conf.h" -extern conn_list_t *lookup_conn(ip_t); -extern void free_conn_element(conn_list_t *); -extern void free_conn_list(conn_list_t*); -extern void prune_conn_list(void); -extern conn_list_t *new_conn_list(void); -extern void destroy_conn_list(void); extern char *hostlookup(unsigned long); extern ip_mask_t *strtoip(char*); -extern void dump_conn_list(void); #endif /* __TINC_NETUTL_H__ */ diff --git a/src/protocol.c b/src/protocol.c index e9bad82e..235aa9b1 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol.c,v 1.28 2000/05/30 21:36:16 zarq Exp $ + $Id: protocol.c,v 1.29 2000/10/18 20:12:09 zarq Exp $ */ #include "config.h" @@ -34,785 +34,1022 @@ #include #include +#include + +#include + #include "conf.h" #include "encr.h" #include "net.h" #include "netutl.h" #include "protocol.h" +#include "meta.h" #include "system.h" -char buffer[MAXBUFSIZE+1]; -int buflen; +int check_id(char *id) +{ + int i; + + for (i = 0; i < strlen(id); i++) + if(!isalnum(id[i]) && id[i] != '_') + return -1; + + return 0; +} -/* Outgoing request routines */ +/* Generic request routines - takes care of logging and error detection as well */ -int send_ack(conn_list_t *cl) +int send_request(conn_list_t *cl, const char *format, ...) { + va_list args; + char buffer[MAXBUFSIZE]; + int len, request; + cp - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("Send ACK to %s"), cl->hostname); + /* Use vsnprintf instead of vasprintf: faster, no memory fragmentation, cleanup is automatic, + and there is a limit on the input buffer anyway */ - buflen = snprintf(buffer, MAXBUFSIZE, "%d\n", ACK); + va_start(args, format); + len = vsnprintf(buffer, MAXBUFSIZE, format, args); + request = va_arg(args, int); + va_end(args); - if((write(cl->meta_socket, buffer, buflen)) < 0) + if(len < 0 || len > MAXBUFSIZE-1) { - syslog(LOG_ERR, _("send failed: %d:%d: %m"), __FILE__, __LINE__); + syslog(LOG_ERR, _("Output buffer overflow while sending %s to %s (%s)"), request_name[request], cl->name, cl->hostname); return -1; } - syslog(LOG_NOTICE, _("Connection with %s activated."), cl->hostname); + len++; + + if(debug_lvl >= DEBUG_PROTOCOL) + syslog(LOG_DEBUG, _("Sending %s to %s (%s)"), request_name[request], cl->name, cl->hostname); + cp - return 0; + return send_meta(cl, buffer, len); } -int send_termreq(conn_list_t *cl) +int receive_request(conn_list_t *cl) { -cp - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("Send TERMREQ to " IP_ADDR_S), - IP_ADDR_V(cl->vpn_ip)); - - buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx\n", TERMREQ, myself->vpn_ip); - - if(write(cl->meta_socket, buffer, buflen) < 0) + int request; +cp + if(sscanf(cl->buffer, "%d", &request) == 1) + { + if((request < 0) || (request > 255) || (request_handlers[request] == NULL)) + { + syslog(LOG_ERR, _("Unknown request from %s (%s)"), + cl->name, cl->hostname); + return -1; + } + else + { + if(debug_lvl > DEBUG_PROTOCOL) + syslog(LOG_DEBUG, _("Got %s from %s (%s)"), + request_name[request], cl->name, cl->hostname); + } + if(request_handlers[request](cl)) + /* Something went wrong. Probably scriptkiddies. Terminate. */ + { + syslog(LOG_ERR, _("Error while processing %s from %s (%s)"), + request_name[request], cl->name, cl->hostname); + return -1; + } + } + else { - if(debug_lvl > 1) - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); + syslog(LOG_ERR, _("Bogus data received from %s (%s)"), + cl->name, cl->hostname); return -1; } +} + +/* Connection protocol: + + Client Server + send_id(u) + send_challenge(R) + send_chal_reply(H) + send_id(u) + send_challenge(R) + send_chal_reply(H) + --------------------------------------- + Any negotations about the meta protocol + encryption go here(u). + --------------------------------------- + send_ack(u) + send_ack(u) + --------------------------------------- + Other requests(E)... + + (u) Unencrypted, + (R) RSA, + (H) SHA1, + (E) Encrypted with symmetric cipher. + + Part of the challenge is directly used to set the symmetric cipher key and the initial vector. + Since a man-in-the-middle cannot decrypt the RSA challenges, this means that he cannot get or + forge the key for the symmetric cipher. +*/ + +int send_id(conn_list_t *cl) +{ cp - return 0; + cl->allow_request = CHALLENGE; +cp + return send_request(cl, "%d %s %d %lx %hd", ID, myself->name, myself->protocol_version, myself->options, myself->port); } -int send_timeout(conn_list_t *cl) +int id_h(conn_list_t *cl) { + conn_list_t *old; cp - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("Send TIMEOUT to " IP_ADDR_S), - IP_ADDR_V(cl->vpn_ip)); + if(sscanf(cl->buffer, "%*d %as %d %lx %hd", &cl->name, &cl->protocol_version, &cl->options, &cl->port) != 4) + { + syslog(LOG_ERR, _("Got bad ID from %s"), cl->hostname); + return -1; + } + + /* Check if version matches */ + + if(cl->protocol_version != myself->protocol_version) + { + syslog(LOG_ERR, _("Peer %s (%s) uses incompatible version %d"), + cl->name, cl->hostname, cl->protocol_version); + return -1; + } + + /* Check if identity is a valid name */ + + if(check_id(cl->name)) + { + syslog(LOG_ERR, _("Peer %s uses invalid identity name"), cl->hostname); + return -1; + } - buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx\n", PINGTIMEOUT, myself->vpn_ip); + /* Load information about peer */ - if((write(cl->meta_socket, buffer, buflen)) < 0) + if(read_host_config(cl)) { - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); + syslog(LOG_ERR, _("Peer %s had unknown identity (%s)"), cl->hostname, cl->name); return -1; } + + + /* First check if the host we connected to is already in our + connection list. If so, we are probably making a loop, which + is not desirable. + */ + + if(cl->status.outgoing) + { + if((old = lookup_id(cl->name))) + { + if(debug_lvl > DEBUG_CONNECTIONS) + syslog(LOG_NOTICE, _("Uplink %s (%s) is already in our connection list"), cl->name, cl->hostname); + cl->status.outgoing = 0; + old->status.outgoing = 1; + terminate_connection(cl); + return 0; + } + } cp - return 0; + return send_challenge(cl); } -int send_del_host(conn_list_t *cl, conn_list_t *new_host) +int send_challenge(conn_list_t *cl) { + char buffer[CHAL_LENGTH*2+1]; cp - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("Sending delete host " IP_ADDR_S " to " IP_ADDR_S), - IP_ADDR_V(new_host->vpn_ip), IP_ADDR_V(cl->vpn_ip)); + /* Allocate buffers for the challenge */ - buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx\n", DEL_HOST, new_host->vpn_ip); + if(!cl->hischallenge) + cl->hischallenge = xmalloc(CHAL_LENGTH); +cp + /* Copy random data to the buffer */ - if((write(cl->meta_socket, buffer, buflen)) < 0) - { - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); - return -1; - } + RAND_bytes(cl->hischallenge, CHAL_LENGTH); cp - return 0; + /* Convert the random data to a hexadecimal formatted string */ + + bin2hex(cl->hischallenge, buffer, CHAL_LENGTH); + buffer[CHAL_LENGTH*2] = '\0'; + + /* Send the challenge */ + + cl->allow_request = CHAL_REPLY; +cp + return send_request(cl, "%d %s", CHALLENGE, buffer); } -int send_ping(conn_list_t *cl) +int challenge_h(conn_list_t *cl) { + char *buffer; cp - if(debug_lvl > 3) - syslog(LOG_DEBUG, _("pinging " IP_ADDR_S), IP_ADDR_V(cl->vpn_ip)); + if(sscanf(cl->buffer, "%*d %as", &buffer) != 1) + { + syslog(LOG_ERR, _("Got bad CHALLENGE from %s (%s)"), cl->name, cl->hostname); + return -1; + } - buflen = snprintf(buffer, MAXBUFSIZE, "%d\n", PING); + /* Check if the length of the challenge is all right */ - if((write(cl->meta_socket, buffer, buflen)) < 0) + if(strlen(buffer) != CHAL_LENGTH*2) { - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); + syslog(LOG_ERR, _("Intruder: wrong challenge length from %s (%s)"), cl->name, cl->hostname); + free(buffer); return -1; } + + /* Allocate buffers for the challenge */ + + if(!cl->mychallenge) + cl->mychallenge = xmalloc(CHAL_LENGTH); + + /* Convert the challenge from hexadecimal back to binary */ + + hex2bin(buffer,cl->mychallenge,CHAL_LENGTH); + free(buffer); + + /* Rest is done by send_chal_reply() */ cp - return 0; + return send_chal_reply(cl); } -int send_pong(conn_list_t *cl) +int send_chal_reply(conn_list_t *cl) { + char hash[SHA_DIGEST_LENGTH*2+1]; cp - buflen = snprintf(buffer, MAXBUFSIZE, "%d\n", PONG); - - if((write(cl->meta_socket, buffer, buflen)) < 0) + if(!cl->mychallenge) { - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); + syslog(LOG_ERR, _("Trying to send CHAL_REPLY to %s (%s) without a valid CHALLENGE"), cl->name, cl->hostname); return -1; } + + /* Calculate the hash from the challenge we received */ + + SHA1(cl->mychallenge, CHAL_LENGTH, hash); + + /* Convert the hash to a hexadecimal formatted string */ + + bin2hex(hash,hash,SHA_DIGEST_LENGTH); + hash[SHA_DIGEST_LENGTH*2] = '\0'; + + /* Send the reply */ + + if(cl->status.outgoing) + cl->allow_request = ID; + else + cl->allow_request = ACK; + cp - return 0; + return send_request(cl, "%d %s", CHAL_REPLY, hash); } -int send_add_host(conn_list_t *cl, conn_list_t *new_host) +int chal_reply_h(conn_list_t *cl) { + char *hishash; + char myhash[SHA_DIGEST_LENGTH]; cp - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("Sending add host to " IP_ADDR_S), - IP_ADDR_V(cl->vpn_ip)); + if(sscanf(cl->buffer, "%*d %as", &hishash) != 1) + { + syslog(LOG_ERR, _("Got bad CHAL_REPLY from %s (%s)"), cl->name, cl->hostname); + free(hishash); + return -1; + } - buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx %lx/%lx:%x\n", ADD_HOST, new_host->real_ip, new_host->vpn_ip, new_host->vpn_mask, new_host->port); + /* Check if the length of the hash is all right */ - if((write(cl->meta_socket, buffer, buflen)) < 0) + if(strlen(hishash) != SHA_DIGEST_LENGTH*2) { - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); + syslog(LOG_ERR, _("Intruder: wrong challenge reply length from %s (%s)"), cl->name, cl->hostname); + free(hishash); return -1; } -cp - return 0; -} -int send_key_changed(conn_list_t *cl, conn_list_t *src) -{ -cp - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("Sending KEY_CHANGED to " IP_ADDR_S), - IP_ADDR_V(cl->vpn_ip)); + /* Convert the hash to binary format */ + + hex2bin(hishash, hishash, SHA_DIGEST_LENGTH); - buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx\n", KEY_CHANGED, src->vpn_ip); + /* Calculate the hash from the challenge we sent */ - if((write(cl->meta_socket, buffer, buflen)) < 0) + SHA1(cl->hischallenge, CHAL_LENGTH, myhash); + + /* Verify the incoming hash with the calculated hash */ + + if(memcmp(hishash, myhash, SHA_DIGEST_LENGTH)) { - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); + syslog(LOG_ERR, _("Intruder: wrong challenge reply from %s (%s)"), cl->name, cl->hostname); + free(hishash); return -1; } + + free(hishash); + + /* Identity has now been positively verified. + If we are accepting this new connection, then send our identity, + if we are making this connecting, acknowledge. + */ cp - return 0; + if(cl->status.outgoing) + return send_ack(cl); + else + return send_id(cl); } -void send_key_changed_all(void) +int send_ack(conn_list_t *cl) { - conn_list_t *p; cp - for(p = conn_list; p != NULL; p = p->next) - if(p->status.meta && p->status.active) - send_key_changed(p, myself); + cl->allow_request = ACK; cp + return send_request(cl, "%d", ACK); } -int send_basic_info(conn_list_t *cl) +int ack_h(conn_list_t *cl) { + conn_list_t *old; cp - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("Send BASIC_INFO to " IP_ADDR_S), - IP_ADDR_V(cl->real_ip)); + /* Okay, before we active the connection, we check if there is another entry + in the connection list with the same name. If so, it presumably is an + old connection that has timed out but we don't know it yet. + */ - buflen = snprintf(buffer, MAXBUFSIZE, "%d %d %lx/%lx:%x\n", BASIC_INFO, PROT_CURRENT, myself->vpn_ip, myself->vpn_mask, myself->port); - - if((write(cl->meta_socket, buffer, buflen)) < 0) + while((old = lookup_id(cl->name))) { - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); - return -1; + if(debug_lvl > DEBUG_CONNECTIONS) + syslog(LOG_NOTICE, _("Removing old entry for %s at %s in favour of new connection from %s"), + cl->name, old->hostname, cl->hostname); + old->status.active = 0; + terminate_connection(old); } + + /* Activate this connection */ + + cl->allow_request = ALL; + cl->status.active = 1; + + if(debug_lvl > DEBUG_CONNECTIONS) + syslog(LOG_NOTICE, _("Connection with %s (%s) activated"), cl->name, cl->hostname); + + /* Exchange information about other tinc daemons */ + +/* FIXME: reprogram this. + notify_others(cl, NULL, send_add_host); + notify_one(cl); +*/ + upstreamindex = 0; + cp - return 0; + if(cl->status.outgoing) + return 0; + else + return send_ack(cl); } -int send_passphrase(conn_list_t *cl) +/* Address and subnet information exchange */ + +int send_add_subnet(conn_list_t *cl, conn_list_t *other, subnet_t *subnet) { - passphrase_t tmp; + int x; + char *netstr; +cp + x = send_request(cl, "%d %s %s", ADD_SUBNET, + other->name, netstr = net2str(subnet)); + free(netstr); cp - encrypt_passphrase(&tmp); + return x; +} - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("Send PASSPHRASE %s to " IP_ADDR_S), - tmp.phrase, IP_ADDR_V(cl->vpn_ip)); +int add_subnet_h(conn_list_t *cl) +{ + char *subnetstr; + char *name; + conn_list_t *owner; + subnet_t *subnet, *old; +cp + if(sscanf(cl->buffer, "%*d %as %as", &name, &subnetstr) != 3) + { + syslog(LOG_ERR, _("Got bad ADD_SUBNET from %s (%s)"), cl->name, cl->hostname); + free(name); free(subnetstr); + return -1; + } - buflen = snprintf(buffer, MAXBUFSIZE, "%d %s\n", PASSPHRASE, tmp.phrase); + /* Check if owner name is a valid */ - if((write(cl->meta_socket, buffer, buflen)) < 0) + if(check_id(name)) { - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); + syslog(LOG_ERR, _("Got bad ADD_SUBNET from %s (%s): invalid identity name"), cl->name, cl->hostname); + free(name); free(subnetstr); return -1; } -cp - return 0; -} -int send_public_key(conn_list_t *cl) -{ -cp - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("Send PUBLIC_KEY %s to " IP_ADDR_S), - my_public_key_base36, IP_ADDR_V(cl->vpn_ip)); - - buflen = snprintf(buffer, MAXBUFSIZE, "%d %s\n", PUBLIC_KEY, my_public_key_base36); + /* Check if subnet string is valid */ - if((write(cl->meta_socket, buffer, buflen)) < 0) + if(!(subnet = str2net(subnetstr))) { - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); + syslog(LOG_ERR, _("Got bad ADD_SUBNET from %s (%s): invalid subnet string"), cl->name, cl->hostname); + free(name); free(subnetstr); return -1; } -cp - return 0; -} -int send_calculate(conn_list_t *cl, char *k) -{ -cp - buflen = snprintf(buffer, MAXBUFSIZE, "%d %s\n", CALCULATE, k); + free(subnetstr); + + /* Check if somebody tries to add a subnet of ourself */ + + if(!strcmp(name, myself->name)) + { + syslog(LOG_ERR, _("Warning: got ADD_SUBNET from %s (%s) for ourself, restarting"), + cl->name, cl->hostname); + free(name); + sighup = 1; + return 0; + } + + /* Check if the owner of the new subnet is in the connection list */ - if((write(cl->meta_socket, buffer, buflen)) < 0) + if(!(owner = lookup_id(name))) { - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); + syslog(LOG_ERR, _("Got ADD_SUBNET for %s from %s (%s) which is not in our connection list"), + name, cl->name, cl->hostname); + free(name); return -1; } + + /* If everything is correct, add the subnet to the list of the owner */ + + subnet_add(owner, subnet); cp return 0; } -int send_key_request(ip_t to) +int send_del_subnet(conn_list_t *cl, conn_list_t *other, subnet_t *subnet) +{ +cp + return send_request(cl, "%d %s %s", DEL_SUBNET, other->name, net2str(subnet)); +} + +int del_subnet_h(conn_list_t *cl) { - conn_list_t *fw; + char *subnetstr; + char *name; + conn_list_t *owner; + subnet_t *subnet, *old; cp - fw = lookup_conn(to); - if(!fw) + if(sscanf(cl->buffer, "%*d %as %as", &name, &subnetstr) != 3) { - syslog(LOG_ERR, _("Attempting to send key request to " IP_ADDR_S ", which does not exist?"), - IP_ADDR_V(to)); + syslog(LOG_ERR, _("Got bad DEL_SUBNET from %s (%s)"), cl->name, cl->hostname); + free(name); free(subnetstr); return -1; } - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("Sending out request for public key to " IP_ADDR_S), - IP_ADDR_V(fw->nexthop->vpn_ip)); - - buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx %lx\n", REQ_KEY, to, myself->vpn_ip); + /* Check if owner name is a valid */ - if((write(fw->nexthop->meta_socket, buffer, buflen)) < 0) + if(check_id(name)) { - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); + syslog(LOG_ERR, _("Got bad DEL_SUBNET from %s (%s): invalid identity name"), cl->name, cl->hostname); + free(name); free(subnetstr); return -1; } - fw->status.waitingforkey = 1; -cp - return 0; -} -int send_key_answer(conn_list_t *cl, ip_t to) -{ - conn_list_t *fw; -cp + /* Check if subnet string is valid */ - fw = lookup_conn(to); - - if(!fw) + if(!(subnet = str2net(subnetstr))) { - syslog(LOG_ERR, _("Attempting to send key answer to " IP_ADDR_S ", which does not exist?"), - IP_ADDR_V(to)); + syslog(LOG_ERR, _("Got bad DEL_SUBNET from %s (%s): invalid subnet string"), cl->name, cl->hostname); + free(name); free(subnetstr); return -1; } - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("Sending public key to " IP_ADDR_S), - IP_ADDR_V(fw->nexthop->vpn_ip)); + free(subnetstr); + + /* Check if somebody tries to add a subnet of ourself */ + + if(!strcmp(name, myself->name)) + { + syslog(LOG_ERR, _("Warning: got DEL_SUBNET from %s (%s) for ourself, restarting"), + cl->name, cl->hostname); + free(name); + sighup = 1; + return 0; + } - buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx %lx %d %s\n", ANS_KEY, to, myself->vpn_ip, my_key_expiry, my_public_key_base36); + /* Check if the owner of the new subnet is in the connection list */ - if((write(fw->nexthop->meta_socket, buffer, buflen)) < 0) + if(!(owner = lookup_id(name))) { - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); + syslog(LOG_ERR, _("Got DEL_SUBNET for %s from %s (%s) which is not in our connection list"), + name, cl->name, cl->hostname); + free(name); return -1; } -cp - return 0; -} -/* - notify all my direct connections of a new host - that was added to the vpn, with the exception - of the source of the announcement. -*/ -int notify_others(conn_list_t *new, conn_list_t *source, - int (*function)(conn_list_t*, conn_list_t*)) -{ - conn_list_t *p; -cp - for(p = conn_list; p != NULL; p = p->next) - if(p != new && p != source && p->status.meta && p->status.active) - function(p, new); + /* If everything is correct, delete the subnet from the list of the owner */ + + subnet_del(subnet); cp return 0; } -/* - notify one connection of everything - i have connected -*/ -int notify_one(conn_list_t *new) +/* New and closed connections notification */ + +int send_add_host(conn_list_t *cl, conn_list_t *other) { - conn_list_t *p; -cp - for(p = conn_list; p != NULL; p = p->next) - if(p != new && p->status.active) - send_add_host(new, p); cp - return 0; + return send_request(cl, "%d %s %s %lx:%d %lx", ADD_HOST, + myself->name, other->name, other->address, other->port, other->options); } -/* - The incoming request handlers -*/ - -int basic_info_h(conn_list_t *cl) +int add_host_h(conn_list_t *cl) { + char *sender; + conn_list_t *old, *new, *hisuplink; cp - if(sscanf(cl->buffer, "%*d %d %lx/%lx:%hx", &cl->protocol_version, &cl->vpn_ip, &cl->vpn_mask, &cl->port) != 4) + new = new_conn_list(); + + if(sscanf(cl->buffer, "%*d %as %as %lx:%d %lx", &sender, &new->name, &new->address, &new->port, &new->options) != 5) { - syslog(LOG_ERR, _("got bad BASIC_INFO request: %s"), cl->buffer); + syslog(LOG_ERR, _("Got bad ADD_HOST from %s (%s)"), cl->name, cl->hostname); return -1; - } + } + + /* Check if identity is a valid name */ - if(cl->protocol_version != PROT_CURRENT) + if(check_id(new->name) || check_id(sender)) { - syslog(LOG_ERR, _("Peer uses incompatible protocol version %d."), - cl->protocol_version); + syslog(LOG_ERR, _("Got bad ADD_HOST from %s (%s): invalid identity name"), cl->name, cl->hostname); + free(sender); return -1; } - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("got BASIC_INFO(%hd," IP_ADDR_S "," IP_ADDR_S ")"), cl->port, - IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->vpn_mask)); - if(debug_lvl > 1) - syslog(LOG_DEBUG, _("Peer uses protocol version %d"), - cl->protocol_version); + /* Check if somebody tries to add ourself */ - if(cl->status.outgoing) + if(!strcmp(new->name, myself->name)) { - if(setup_vpn_connection(cl) < 0) - return -1; - send_basic_info(cl); + syslog(LOG_ERR, _("Warning: got ADD_HOST from %s (%s) for ourself, restarting"), cl->name, cl->hostname); + sighup = 1; + free(sender); + return 0; } - else + + /* We got an ADD_HOST from ourself!? */ + + if(!strcmp(sender, myself->name)) { - if(setup_vpn_connection(cl) < 0) - return -1; - send_passphrase(cl); + syslog(LOG_ERR, _("Warning: got ADD_HOST from %s (%s) from ourself, restarting"), cl->name, cl->hostname); + sighup = 1; + free(sender); + return 0; } -cp - return 0; -} -int passphrase_h(conn_list_t *cl) -{ -cp - cl->pp = xmalloc(sizeof(*(cl->pp))); + /* Lookup his uplink */ - if(sscanf(cl->buffer, "%*d %as", &(cl->pp->phrase)) != 1) + if(!(new->hisuplink = lookup_id(sender))) { - syslog(LOG_ERR, _("got bad PASSPHRASE request: %s"), cl->buffer); + syslog(LOG_ERR, _("Got ADD_HOST from %s (%s) with origin %s which is not in our connection list"), + sender, cl->name, cl->hostname); + free(sender); return -1; } - cl->pp->len = strlen(cl->pp->phrase); - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("got PASSPHRASE")); + free(sender); - if(cl->status.outgoing) - send_passphrase(cl); - else - send_public_key(cl); + /* Fill in more of the new conn_list structure */ + + new->hostname = hostlookup(htonl(new->address)); + + /* Check if the new host already exists in the connnection list */ + + if((old = lookup_id(new->name))) + { + if((new->address == old->address) && (new->port == old->port)) + { + if(debug_lvl > DEBUG_CONNECTIONS) + syslog(LOG_NOTICE, _("Got duplicate ADD_HOST for %s (%s) from %s (%s)"), + old->name, old->hostname, new->name, new->hostname); + return 0; + } + else + { + if(debug_lvl > DEBUG_CONNECTIONS) + syslog(LOG_NOTICE, _("Removing old entry for %s (%s)"), + old->name, old->hostname); + old->status.active = 0; + terminate_connection(old); + } + } + + /* Fill in rest of conn_list structure */ + + new->myuplink = cl; + new->status.active = 1; + + /* Hook it up into the conn_list */ + + conn_list_add(conn_list, new); + + /* Tell the rest about the new host */ +/* FIXME: reprogram this. + notify_others(new, cl, send_add_host); +*/ cp return 0; } -int public_key_h(conn_list_t *cl) +int send_del_host(conn_list_t *cl, conn_list_t *other) { - char *g_n; - conn_list_t *old; cp - if(sscanf(cl->buffer, "%*d %as", &g_n) != 1) + return send_request(cl, "%d %s %s %lx:%d %lx", DEL_HOST, + myself->name, other->name, other->address, other->port, other->options); +} + +int del_host_h(conn_list_t *cl) +{ + char *name; + char *sender; + ip_t address; + port_t port; + int options; + conn_list_t *old, *hisuplink; + +cp + if(sscanf(cl->buffer, "%*d %as %as %lx:%d %lx", &sender, &name, &address, &port, &options) != 5) { - syslog(LOG_ERR, _("got bad PUBLIC_KEY request: %s"), cl->buffer); - return -1; - } + syslog(LOG_ERR, _("Got bad DEL_HOST from %s (%s)"), + cl->name, cl->hostname); + return -1; + } - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("got PUBLIC_KEY %s"), g_n); + /* Check if identity is a valid name */ - if(verify_passphrase(cl, g_n)) + if(check_id(name) || check_id(sender)) { - /* intruder! */ - syslog(LOG_ERR, _("Intruder: passphrase does not match.")); + syslog(LOG_ERR, _("Got bad DEL_HOST from %s (%s): invalid identity name"), cl->name, cl->hostname); + free(name); free(sender); return -1; } - if(debug_lvl > 2) - syslog(LOG_INFO, _("Passphrase OK")); + /* Check if somebody tries to delete ourself */ - if(cl->status.outgoing) - send_public_key(cl); - else + if(!strcmp(name, myself->name)) + { + syslog(LOG_ERR, _("Warning: got DEL_HOST from %s (%s) for ourself, restarting"), + cl->name, cl->hostname); + free(name); free(sender); + sighup = 1; + return 0; + } + + /* We got an ADD_HOST from ourself!? */ + + if(!strcmp(sender, myself->name)) { - send_ack(cl); + syslog(LOG_ERR, _("Warning: got DEL_HOST from %s (%s) from ourself, restarting"), cl->name, cl->hostname); + sighup = 1; + free(name); free(sender); + return 0; + } + + /* Lookup his uplink */ - /* Okay, before we active the connection, we check if there is another entry - in the connection list with the same vpn_ip. If so, it presumably is an - old connection that has timed out but we don't know it yet. Because our - conn_list entry is not active, lookup_conn will skip ourself. */ + if(!(hisuplink = lookup_id(sender))) + { + syslog(LOG_ERR, _("Got DEL_HOST from %s (%s) with origin %s which is not in our connection list"), + cl->name, cl->hostname, sender); + free(name); free(sender); + return -1; + } + + free(sender); - while(old=lookup_conn(cl->vpn_ip)) - terminate_connection(old); + /* Check if the new host already exists in the connnection list */ - cl->status.active = 1; - notify_others(cl, NULL, send_add_host); - notify_one(cl); + if(!(old = lookup_id(name))) + { + syslog(LOG_ERR, _("Got DEL_HOST from %s (%s) for %s which is not in our connection list"), + name, cl->name, cl->hostname); + free(name); + return -1; + } + + /* Check if the rest matches */ + + if(address!=old->address || port!=old->port || options!=old->options || hisuplink!=old->hisuplink || cl!=old->myuplink) + { + syslog(LOG_WARNING, _("Got DEL_HOST from %s (%s) for %s which doesn't match"), cl->name, cl->hostname, old->name); + return 0; } + + /* Ok, since EVERYTHING seems to check out all right, delete it */ + + old->status.termreq = 1; + old->status.active = 0; + + terminate_connection(old); cp return 0; } -int ack_h(conn_list_t *cl) +/* Status and error notification routines */ + +int send_status(conn_list_t *cl, int statusno, char *statusstring) { cp - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("got ACK")); - - cl->status.active = 1; - syslog(LOG_NOTICE, _("Connection with %s activated."), cl->hostname); + if(!statusstring) + statusstring = status_text[statusno]; cp - return 0; + return send_request(cl, "%d %d %s", STATUS, statusno, statusstring); } -int termreq_h(conn_list_t *cl) +int status_h(conn_list_t *cl) { + int statusno; + char *statusstring; cp - syslog(LOG_NOTICE, _(IP_ADDR_S " wants to quit"), IP_ADDR_V(cl->vpn_ip)); - cl->status.termreq = 1; - terminate_connection(cl); + if(sscanf(cl->buffer, "%*d %d %as", &statusno, &statusstring) != 2) + { + syslog(LOG_ERR, _("Got bad STATUS from %s (%s)"), + cl->name, cl->hostname); + return -1; + } + + if(debug_lvl > DEBUG_STATUS) + { + syslog(LOG_NOTICE, _("Status message from %s (%s): %s: %s"), + cl->name, cl->hostname, status_text[statusno], statusstring); + } - notify_others(cl, NULL, send_del_host); cp + free(statusstring); return 0; } -int timeout_h(conn_list_t *cl) +int send_error(conn_list_t *cl, int errno, char *errstring) { cp - if(!cl->status.active) return -1; - syslog(LOG_NOTICE, _(IP_ADDR_S " says it's gotten a timeout from us"), IP_ADDR_V(cl->vpn_ip)); - cl->status.termreq = 1; - terminate_connection(cl); -cp - return 0; + if(!errstring) + errstring = strerror(errno); + return send_request(cl, "%d %d %s", ERROR, errno, errstring); } -int del_host_h(conn_list_t *cl) +int error_h(conn_list_t *cl) { - ip_t vpn_ip; - conn_list_t *fw; + int errno; + char *errorstring; cp - if(!cl->status.active) return -1; - - if(sscanf(cl->buffer, "%*d %lx", &vpn_ip) != 1) + if(sscanf(cl->buffer, "%*d %d %as", &errno, &errorstring) != 2) { - syslog(LOG_ERR, _("got bad DEL_HOST request: %s"), cl->buffer); + syslog(LOG_ERR, _("Got bad ERROR from %s (%s)"), + cl->name, cl->hostname); return -1; - } - - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("got DEL_HOST for " IP_ADDR_S), - IP_ADDR_V(vpn_ip)); + } - if(!(fw = lookup_conn(vpn_ip))) + if(debug_lvl > DEBUG_ERROR) { - syslog(LOG_ERR, _("Somebody wanted to delete " IP_ADDR_S " which does not exist?"), - IP_ADDR_V(vpn_ip)); - return 0; + syslog(LOG_NOTICE, _("Error message from %s (%s): %s: %s"), + cl->name, cl->hostname, strerror(errno), errorstring); } - notify_others(cl, fw, send_del_host); + free(errorstring); + cl->status.termreq = 1; + terminate_connection(cl); +cp + return 0; +} + +int send_termreq(conn_list_t *cl) +{ +cp + return send_request(cl, "%d", TERMREQ); +} - fw->status.termreq = 1; - terminate_connection(fw); +int termreq_h(conn_list_t *cl) +{ +cp + cl->status.termreq = 1; + terminate_connection(cl); cp return 0; } +/* Keepalive routines - FIXME: needs a closer look */ + +int send_ping(conn_list_t *cl) +{ + cl->status.pinged = 1; +cp + return send_request(cl, "%d", PING); +} + int ping_h(conn_list_t *cl) { cp - if(!cl->status.active) return -1; - if(debug_lvl > 3) - syslog(LOG_DEBUG, _("responding to ping from " IP_ADDR_S), IP_ADDR_V(cl->vpn_ip)); - cl->status.pinged = 0; - cl->status.got_pong = 1; + return send_pong(cl); +} - send_pong(cl); +int send_pong(conn_list_t *cl) +{ cp - return 0; + return send_request(cl, "%d", PONG); } int pong_h(conn_list_t *cl) { cp - if(!cl->status.active) return -1; - if(debug_lvl > 3) - syslog(LOG_DEBUG, _("ok, got pong from " IP_ADDR_S), IP_ADDR_V(cl->vpn_ip)); cl->status.got_pong = 1; cp return 0; } -int add_host_h(conn_list_t *cl) +/* Key exchange */ + +int send_key_changed(conn_list_t *from, conn_list_t *cl) { - ip_t real_ip; - ip_t vpn_ip; - ip_t vpn_mask; - unsigned short port; - conn_list_t *ncn, *fw; + conn_list_t *p; cp - if(!cl->status.active) - return -1; - if(sscanf(cl->buffer, "%*d %lx %lx/%lx:%hx", &real_ip, &vpn_ip, &vpn_mask, &port) != 4) + for(p = conn_list; p != NULL; p = p->next) { - syslog(LOG_ERR, _("got bad ADD_HOST request: %s"), cl->buffer); - return -1; - } + if(p!=cl && p->status.meta && p->status.active) + send_request(p, "%d %s", KEY_CHANGED, + from->name); + } +cp + return 0; +} - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("Add host request from " IP_ADDR_S), IP_ADDR_V(cl->vpn_ip)); - if(debug_lvl > 3) - syslog(LOG_DEBUG, _("got ADD_HOST(" IP_ADDR_S "," IP_ADDR_S ",%hd)"), - IP_ADDR_V(vpn_ip), IP_ADDR_V(vpn_mask), port); +int key_changed_h(conn_list_t *cl) +{ + char *from_id; + conn_list_t *from; +cp + if(sscanf(cl->buffer, "%*d %as", &from_id) != 1) + { + syslog(LOG_ERR, _("Got bad KEY_CHANGED from %s (%s)"), + cl->name, cl->hostname); + return -1; + } - /* - Suggestion of Hans Bayle - */ - if((fw = lookup_conn(vpn_ip))) + if(!(from = lookup_id(from_id))) { - if(fw->nexthop == cl) - notify_others(fw, cl, send_add_host); - else - if(debug_lvl > 1) - syslog(LOG_DEBUG, _("Invalid add_host request from " IP_ADDR_S), - IP_ADDR_V(cl->vpn_ip)); - return 0; + syslog(LOG_ERR, _("Got KEY_CHANGED from %s (%s) origin %s which does not exist in our connection list"), + cl->name, cl->hostname, from_id); + free(from_id); + return -1; } - ncn = new_conn_list(); - ncn->real_ip = real_ip; - ncn->vpn_ip = vpn_ip; - ncn->vpn_mask = vpn_mask; - ncn->port = port; - ncn->hostname = hostlookup(real_ip); - ncn->nexthop = cl; - ncn->next = conn_list; - conn_list = ncn; - ncn->status.active = 1; - notify_others(ncn, cl, send_add_host); + free(from_id); + + from->status.validkey = 0; + from->status.waitingforkey = 0; + + send_key_changed(from, cl); cp return 0; } +int send_req_key(conn_list_t *from, conn_list_t *to) +{ +cp + return send_request(to->nexthop, "%d %s %s", REQ_KEY, + from->name, to->name); +} + int req_key_h(conn_list_t *cl) { - ip_t to; - ip_t from; - conn_list_t *fw; + char *from_id, *to_id; + conn_list_t *from, *to; cp - if(!cl->status.active) return -1; - if(sscanf(cl->buffer, "%*d %lx %lx", &to, &from) != 2) + if(sscanf(cl->buffer, "%*d %as %as", &from_id, &to_id) != 2) { - syslog(LOG_ERR, _("got bad request: %s"), cl->buffer); + syslog(LOG_ERR, _("Got bad REQ_KEY from %s (%s)"), + cl->name, cl->hostname); return -1; - } - - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("got REQ_KEY from " IP_ADDR_S " for " IP_ADDR_S), - IP_ADDR_V(from), IP_ADDR_V(to)); - - if((to & myself->vpn_mask) == (myself->vpn_ip & myself->vpn_mask)) - { /* hey! they want something from ME! :) */ - send_key_answer(cl, from); - return 0; } - fw = lookup_conn(to); - - if(!fw) + if(!(from = lookup_id(from_id))) { - syslog(LOG_ERR, _("Attempting to forward key request to " IP_ADDR_S ", which does not exist?"), - IP_ADDR_V(to)); + syslog(LOG_ERR, _("Got REQ_KEY from %s (%s) origin %s which does not exist in our connection list"), + cl->name, cl->hostname, from_id); + free(from_id); free(to_id); return -1; } - if(debug_lvl > 3) - syslog(LOG_DEBUG, _("Forwarding request for public key to " IP_ADDR_S), - IP_ADDR_V(fw->nexthop->vpn_ip)); - - cl->buffer[cl->reqlen-1] = '\n'; - - if(write(fw->nexthop->meta_socket, cl->buffer, cl->reqlen) < 0) - { - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); - return -1; - } -cp - return 0; -} + /* Check if this key request is for us */ -void set_keys(conn_list_t *cl, int expiry, char *key) -{ - char *ek; -cp - if(!cl->public_key) + if(!strcmp(to_id, myself->name)) { - cl->public_key = xmalloc(sizeof(*cl->key)); - cl->public_key->key = NULL; + send_ans_key(myself, from, myself->cipher_pktkey); } - - if(cl->public_key->key) - free(cl->public_key->key); - cl->public_key->length = strlen(key); - cl->public_key->expiry = expiry; - cl->public_key->key = xmalloc(cl->public_key->length + 1); - strcpy(cl->public_key->key, key); - - ek = make_shared_key(key); - - if(!cl->key) + else { - cl->key = xmalloc(sizeof(*cl->key)); - cl->key->key = NULL; + if(!(to = lookup_id(to_id))) + { + syslog(LOG_ERR, _("Got REQ_KEY from %s (%s) destination %s which does not exist in our connection list"), + cl->name, cl->hostname, to_id); + free(from_id); free(to_id); + return -1; + } + send_req_key(from, to); } - if(cl->key->key) - free(cl->key->key); + free(from_id); free(to_id); +cp + return 0; +} - cl->key->length = strlen(ek); - cl->key->expiry = expiry; - cl->key->key = xmalloc(cl->key->length + 1); - strcpy(cl->key->key, ek); +int send_ans_key(conn_list_t *from, conn_list_t *to, char *pktkey) +{ cp + return send_request(to->nexthop, "%d %s %s %s", ANS_KEY, + from->name, to->name, pktkey); } int ans_key_h(conn_list_t *cl) { - ip_t to; - ip_t from; - int expiry; - char *key; - conn_list_t *fw, *gk; + char *from_id, *to_id, *pktkey; + int keylength; + conn_list_t *from, *to; cp - if(!cl->status.active) return -1; - if(sscanf(cl->buffer, "%*d %lx %lx %d %as", &to, &from, &expiry, &key) != 4) + if(sscanf(cl->buffer, "%*d %as %as %as", &from_id, &to_id, &pktkey) != 3) { - syslog(LOG_ERR, _("got bad ANS_KEY request: %s"), cl->buffer); + syslog(LOG_ERR, _("Got bad ANS_KEY from %s (%s)"), + cl->name, cl->hostname); return -1; - } - - if(debug_lvl > 3) - syslog(LOG_DEBUG, _("got ANS_KEY from " IP_ADDR_S " for " IP_ADDR_S), - IP_ADDR_V(from), IP_ADDR_V(to)); - - if(to == myself->vpn_ip) - { /* hey! that key's for ME! :) */ - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("Yeah! key arrived. Now do something with it.")); - gk = lookup_conn(from); - - if(!gk) - { - syslog(LOG_ERR, _("Receiving key from " IP_ADDR_S ", which does not exist?"), - IP_ADDR_V(from)); - return -1; - } - - set_keys(gk, expiry, key); - gk->status.validkey = 1; - gk->status.waitingforkey = 0; - flush_queues(gk); - return 0; } - fw = lookup_conn(to); - - if(!fw) + if(!(from = lookup_id(from_id))) { - syslog(LOG_ERR, _("Attempting to forward key to " IP_ADDR_S ", which does not exist?"), - IP_ADDR_V(to)); + syslog(LOG_ERR, _("Got ANS_KEY from %s (%s) origin %s which does not exist in our connection list"), + cl->name, cl->hostname, from_id); + free(from_id); free(to_id); free(pktkey); return -1; } - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("Forwarding public key to " IP_ADDR_S), - IP_ADDR_V(fw->nexthop->vpn_ip)); + /* Check if this key request is for us */ - cl->buffer[cl->reqlen-1] = '\n'; + if(!strcmp(to_id, myself->name)) + { + /* It is for us, convert it to binary and set the key with it. */ + + keylength = strlen(pktkey); - if((write(fw->nexthop->meta_socket, cl->buffer, cl->reqlen)) < 0) + if((keylength%2) || (keylength <= 0)) + { + syslog(LOG_ERR, _("Got bad ANS_KEY from %s (%s) origin %s: invalid key"), + cl->name, cl->hostname, from->name); + free(from_id); free(to_id); free(pktkey); + return -1; + } + keylength /= 2; + hex2bin(pktkey, pktkey, keylength); + BF_set_key(cl->cipher_pktkey, keylength, pktkey); + } + else { - syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__); - return -1; + if(!(to = lookup_id(to_id))) + { + syslog(LOG_ERR, _("Got ANS_KEY from %s (%s) destination %s which does not exist in our connection list"), + cl->name, cl->hostname, to_id); + free(from_id); free(to_id); free(pktkey); + return -1; + } + send_ans_key(from, to, pktkey); } + + free(from_id); free(to_id); free(pktkey); cp return 0; } -int key_changed_h(conn_list_t *cl) -{ - ip_t from; - conn_list_t *ik; -cp - if(!cl->status.active) return -1; - if(sscanf(cl->buffer, "%*d %lx", &from) != 1) - { - syslog(LOG_ERR, _("got bad ANS_KEY request: %s"), cl->buffer); - return -1; - } +/* Jumptable for the request handlers */ - if(debug_lvl > 2) - syslog(LOG_DEBUG, _("got KEY_CHANGED from " IP_ADDR_S), - IP_ADDR_V(from)); +int (*request_handlers[])(conn_list_t*) = { + id_h, challenge_h, chal_reply_h, ack_h, + status_h, error_h, termreq_h, + ping_h, pong_h, + add_host_h, del_host_h, + add_subnet_h, del_subnet_h, + key_changed_h, req_key_h, ans_key_h, +}; - ik = lookup_conn(from); +/* Request names */ - if(!ik) - { - syslog(LOG_ERR, _("Got changed key from " IP_ADDR_S ", which does not exist?"), - IP_ADDR_V(from)); - return -1; - } +char (*request_name[]) = { + "ID", "CHALLENGE", "CHAL_REPLY", "ACK", + "STATUS", "ERROR", "TERMREQ", + "PING", "PONG", + "ADD_HOST", "DEL_HOST", + "ADD_SUBNET", "DEL_SUBNET", + "KEY_CHANGED", "REQ_KEY", "ANS_KEY", +}; - ik->status.validkey = 0; - ik->status.waitingforkey = 0; +/* Status strings */ - if(debug_lvl > 3) - syslog(LOG_DEBUG, _("Forwarding key invalidation request")); +char (*status_text[]) = { + "Warning", +}; - notify_others(cl, ik, send_key_changed); -cp - return 0; -} +/* Error strings */ -int (*request_handlers[256])(conn_list_t*) = { - 0, ack_h, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - termreq_h, timeout_h, del_host_h, 0, 0, 0, 0, 0, 0, 0, - ping_h, pong_h, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - add_host_h, basic_info_h, passphrase_h, public_key_h, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - req_key_h, ans_key_h, key_changed_h, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +char (*error_text[]) = { + "Error", }; diff --git a/src/protocol.h b/src/protocol.h index 88a0de29..7b14dec1 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -1,6 +1,7 @@ /* protocol.h -- header for protocol.c - Copyright (C) 1999,2000 Ivo Timmermans + Copyright (C) 1999,2000 Ivo Timmermans , + 2000 Guus Sliepen 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 @@ -15,60 +16,64 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id: protocol.h,v 1.6 2000/10/18 20:12:09 zarq Exp $ */ #ifndef __TINC_PROTOCOL_H__ #define __TINC_PROTOCOL_H__ #include "net.h" +#include "subnet.h" -enum { - PROT_RESERVED = 0, /* reserved: do not use. */ - PROT_NOT_IN_USE, - PROT_TOO_OLD = 2, - PROT_3, - PROT_4, - PROT_ECHELON, - PROT_CURRENT, /* protocol currently in use */ -}; +/* Protocol version. Different versions are incompatible, + incompatible version have different protocols. + */ + +#define PROT_CURRENT 8 + +/* Length of the challenge. Since the challenge will also + contain the key for the symmetric cipher, it must be + quite large. + */ + +#define CHAL_LENGTH 1024 /* Okay, this is probably waaaaaaaaaaay too large */ + +/* Request numbers */ enum { - ACK = 1, /* acknowledged */ - AUTH_S_INIT = 10, /* initiate authentication */ - AUTH_C_INIT, - AUTH_S_SPP, /* send passphrase */ - AUTH_C_SPP, - AUTH_S_SKEY, /* send g^k */ - AUTH_C_SKEY, - AUTH_S_SACK, /* send ack */ - AUTH_C_RACK, /* waiting for ack */ - TERMREQ = 30, /* terminate connection */ - PINGTIMEOUT, /* terminate due to ping t.o. */ - DEL_HOST, /* forward a termreq to others */ - PING = 40, /* ping */ - PONG, - ADD_HOST = 60, /* Add new given host to connection list */ - BASIC_INFO, /* some basic info follows */ - PASSPHRASE, /* encrypted passphrase */ - PUBLIC_KEY, /* public key in base-36 */ - HOLD = 80, /* don't send any data */ - RESUME, /* resume dataflow with new encryption key */ - CALCULATE = 100, /* calculate the following numer^privkey and send me the result */ - CALC_RES, /* result of the above */ - ALMOST_KEY, /* this number^privkey is the shared key */ - REQ_KEY = 160, /* request public key */ - ANS_KEY, /* answer to such request */ - KEY_CHANGED, /* public key has changed */ + ALL = -1, /* Guardian for allow_request */ + ID = 0, CHALLENGE, CHAL_REPLY, ACK, + STATUS, ERROR, TERMREQ, + PING, PONG, + ADD_HOST, DEL_HOST, + ADD_SUBNET, DEL_SUBNET, + KEY_CHANGED, REQ_KEY, ANS_KEY, + LAST /* Guardian for the highest request number */ }; -extern int (*request_handlers[256])(conn_list_t*); +extern int (*request_handlers[])(conn_list_t*); +extern int send_id(conn_list_t*); +extern int send_challenge(conn_list_t*); +extern int send_chal_reply(conn_list_t*); +extern int send_ack(conn_list_t*); +extern int send_status(conn_list_t*, int, char*); +extern int send_error(conn_list_t*, int, char*); +extern int send_termreq(conn_list_t*); extern int send_ping(conn_list_t*); -extern int send_basic_info(conn_list_t *); -extern int send_termreq(conn_list_t *); -extern int send_timeout(conn_list_t *); -extern int send_key_request(ip_t); -extern void send_key_changed_all(void); +extern int send_pong(conn_list_t*); +extern int send_add_host(conn_list_t*, conn_list_t*); +extern int send_del_host(conn_list_t*, conn_list_t*); +extern int send_add_subnet(conn_list_t*, conn_list_t*, subnet_t*); +extern int send_del_subnet(conn_list_t*, conn_list_t*, subnet_t*); +extern int send_key_changed(conn_list_t*, conn_list_t*); +extern int send_req_key(conn_list_t*, conn_list_t*); +extern int send_ans_key(conn_list_t*, conn_list_t*, char*); -#endif /* __TINC_PROTOCOL_H__ */ +/* Old functions */ +extern int send_tcppacket(conn_list_t *, void *, int); +extern int notify_others(conn_list_t *, conn_list_t *, int (*function)(conn_list_t*, conn_list_t*)); + +#endif /* __TINC_PROTOCOL_H__ */ diff --git a/src/tincd.c b/src/tincd.c index 2a7b63ef..87ccc7fe 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: tincd.c,v 1.10 2000/05/31 18:23:06 zarq Exp $ + $Id: tincd.c,v 1.11 2000/10/18 20:12:10 zarq Exp $ */ #include "config.h" @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef HAVE_SYS_IOCTL_H # include @@ -43,6 +44,7 @@ #include "encr.h" #include "net.h" #include "netutl.h" +#include "protocol.h" #include "system.h" @@ -61,10 +63,7 @@ static int kill_tincd = 0; /* If zero, don't detach from the terminal. */ static int do_detach = 1; -char *confbase = NULL; /* directory in which all config files are */ -char *configfilename = NULL; /* configuration file name */ char *identname; /* program name for syslog */ -char *netname = NULL; /* name of the vpn network */ char *pidfilename; /* pid file location */ static pid_t ppid; /* pid of non-detached part */ char **g_argv; /* a copy of the cmdline arguments */ @@ -96,7 +95,7 @@ usage(int status) else { printf(_("Usage: %s [option]...\n\n"), program_name); - printf(_(" -c, --config=FILE Read configuration options from FILE.\n" + printf(_(" -c, --config=DIR Read configuration options from DIR.\n" " -D, --no-detach Don't fork and detach.\n" " -d Increase debug level.\n" " -k, --kill Attempt to kill a running tincd and exit.\n" @@ -123,8 +122,8 @@ parse_options(int argc, char **argv, char **envp) case 0: /* long option */ break; case 'c': /* config file */ - configfilename = xmalloc(strlen(optarg)+1); - strcpy(configfilename, optarg); + confbase = xmalloc(strlen(optarg)+1); + strcpy(confbase, optarg); break; case 'D': /* no detach */ do_detach = 0; @@ -156,7 +155,7 @@ parse_options(int argc, char **argv, char **envp) void memory_full(int size) { - syslog(LOG_ERR, _("Memory exhausted (last is %s:%d) (couldn't allocate %d bytes); exiting."), cp_file, cp_line, size); + syslog(LOG_ERR, _("Memory exhausted (last is %s:%d) (couldn't allocate %d bytes), exiting."), cp_file, cp_line, size); exit(1); } @@ -180,7 +179,7 @@ int detach(void) if(pid) /* parent process */ { signal(SIGTERM, parent_exit); - sleep(600); /* wait 10 minutes */ +// sleep(600); /* wait 10 minutes */ exit(1); } } @@ -210,11 +209,11 @@ int detach(void) openlog(identname, LOG_CONS | LOG_PID, LOG_DAEMON); - if(debug_lvl > 1) - syslog(LOG_NOTICE, _("tincd %s (%s %s) starting, debug level %d."), + if(debug_lvl > 0) + syslog(LOG_NOTICE, _("tincd %s (%s %s) starting, debug level %d"), VERSION, __DATE__, __TIME__, debug_lvl); else - syslog(LOG_NOTICE, _("tincd %s starting, debug level %d."), VERSION, debug_lvl); + syslog(LOG_NOTICE, _("tincd %s starting"), VERSION, debug_lvl); xalloc_fail_func = memory_full; @@ -229,7 +228,7 @@ void cleanup_and_exit(int c) close_network_connections(); if(debug_lvl > 0) - syslog(LOG_INFO, _("Total bytes written: tap %d, socket %d; bytes read: tap %d, socket %d."), + syslog(LOG_INFO, _("Total bytes written: tap %d, socket %d; bytes read: tap %d, socket %d"), total_tap_out, total_socket_out, total_tap_in, total_socket_in); closelog(); @@ -291,35 +290,24 @@ int kill_other(void) */ void make_names(void) { - if(!configfilename) - { - if(netname) - { - configfilename = xmalloc(strlen(netname)+18+strlen(CONFDIR)); - sprintf(configfilename, "%s/tinc/%s/tinc.conf", CONFDIR, netname); - } - else - { - configfilename = xmalloc(17+strlen(CONFDIR)); - sprintf(configfilename, "%s/tinc/tinc.conf", CONFDIR); - } - } - if(netname) { - pidfilename = xmalloc(strlen(netname)+20); - sprintf(pidfilename, "/var/run/tinc.%s.pid", netname); - confbase = xmalloc(strlen(netname)+8+strlen(CONFDIR)); - sprintf(confbase, "%s/tinc/%s/", CONFDIR, netname); - identname = xmalloc(strlen(netname)+7); - sprintf(identname, "tinc.%s", netname); + if(!pidfilename) + asprintf(&pidfilename, "/var/run/tinc.%s.pid", netname); + if(!confbase) + asprintf(&confbase, "%s/tinc/%s", CONFDIR, netname); + if(!identname) + asprintf(&identname, "tinc.%s", netname); } else { - pidfilename = "/var/run/tinc.pid"; - confbase = xmalloc(7+strlen(CONFDIR)); - sprintf(confbase, "%s/tinc/", CONFDIR); - identname = "tinc"; + netname = "bla"; + if(!pidfilename) + pidfilename = "/var/run/tinc.pid"; + if(!confbase) + asprintf(&confbase, "%s/tinc", CONFDIR); + if(!identname) + identname = "tinc"; } } @@ -332,17 +320,20 @@ main(int argc, char **argv, char **envp) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); + /* Do some intl stuff right now */ + + unknown = _("unknown"); + parse_options(argc, argv, envp); if(show_version) { - printf(_("%s version %s\n"), PACKAGE, VERSION); - printf(_("Copyright (C) 1998,1999,2000 Ivo Timmermans and others,\n" - "see the AUTHORS file for a complete list.\n\n" + printf(_("%s version %s (built %s %s, protocol %d)\n"), PACKAGE, VERSION, __DATE__, __TIME__, PROT_CURRENT); + printf(_("Copyright (C) 1998,1999,2000 Ivo Timmermans, Guus Sliepen and others.\n" + "See the AUTHORS file for a complete list.\n\n" "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" "and you are welcome to redistribute it under certain conditions;\n" - "see the file COPYING for details.\n\n")); - printf(_("This product includes software developed by Eric Young (eay@mincom.oz.au)\n")); + "see the file COPYING for details.\n")); return 0; } @@ -352,7 +343,7 @@ main(int argc, char **argv, char **envp) if(geteuid()) { - fprintf(stderr, _("You must be root to run this program. sorry.\n")); + fprintf(stderr, _("You must be root to run this program. Sorry.\n")); return 1; } @@ -363,7 +354,7 @@ main(int argc, char **argv, char **envp) if(kill_tincd) exit(kill_other()); - if(read_config_file(configfilename)) + if(read_server_config()) return 1; setup_signals(); @@ -371,16 +362,32 @@ main(int argc, char **argv, char **envp) if(detach()) exit(0); +/* FIXME: wt* is this suppose to do? if(security_init()) return 1; - - if(setup_network_connections()) - cleanup_and_exit(1); - - main_loop(); - - cleanup_and_exit(1); - return 1; +*/ + for(;;) + { + if(!setup_network_connections()) + { + main_loop(); + cleanup_and_exit(1); + } + + syslog(LOG_ERR, _("Unrecoverable error")); + cp_trace(); + + if(do_detach) + { + syslog(LOG_NOTICE, _("Restarting in %d seconds!"), MAXTIMEOUT); + sleep(MAXTIMEOUT); + } + else + { + syslog(LOG_ERR, _("Aieee! Not restarting.")); + exit(0); + } + } } RETSIGTYPE @@ -402,41 +409,45 @@ sigquit_handler(int a) RETSIGTYPE sigsegv_square(int a) { - syslog(LOG_NOTICE, _("Got another SEGV signal: not restarting")); + syslog(LOG_ERR, _("Got another SEGV signal: not restarting")); exit(0); } RETSIGTYPE sigsegv_handler(int a) { - if(cp_file) - syslog(LOG_NOTICE, _("Got SEGV signal after %s line %d. Trying to re-execute."), - cp_file, cp_line); - else - syslog(LOG_NOTICE, _("Got SEGV signal; trying to re-execute.")); - - signal(SIGSEGV, sigsegv_square); + syslog(LOG_ERR, _("Got SEGV signal")); + cp_trace(); - close_network_connections(); - remove_pid(pidfilename); - execvp(g_argv[0], g_argv); + if(do_detach) + { + syslog(LOG_NOTICE, _("Trying to re-execute in 5 seconds...")); + signal(SIGSEGV, sigsegv_square); + close_network_connections(); + sleep(5); + remove_pid(pidfilename); + execvp(g_argv[0], g_argv); + } + else + { + syslog(LOG_NOTICE, _("Aieee! Not restarting.")); + exit(0); + } } RETSIGTYPE sighup_handler(int a) { if(debug_lvl > 0) - syslog(LOG_NOTICE, _("Got HUP signal")); - close_network_connections(); - setup_network_connections(); - /* FIXME: read config-file and re-establish network connections */ + syslog(LOG_NOTICE, _("Got HUP signal, rereading configuration and restarting")); + sighup = 1; } RETSIGTYPE sigint_handler(int a) { if(debug_lvl > 0) - syslog(LOG_NOTICE, _("Got INT signal")); + syslog(LOG_NOTICE, _("Got INT signal, exiting")); cleanup_and_exit(0); } @@ -450,18 +461,17 @@ RETSIGTYPE sigusr2_handler(int a) { if(debug_lvl > 1) - syslog(LOG_NOTICE, _("Forcing new key generation")); + syslog(LOG_NOTICE, _("Got USR2 signal, forcing new key generation")); +/* FIXME: reprogram this. regenerate_keys(); +*/ } RETSIGTYPE sighuh(int a) { - if(cp_file) - syslog(LOG_NOTICE, _("Got unexpected signal (%d) after %s line %d."), - a, cp_file, cp_line); - else - syslog(LOG_NOTICE, _("Got unexpected signal (%d)."), a); + syslog(LOG_WARNING, _("Got unexpected signal %d (%s)"), a, strsignal(a)); + cp_trace(); } void @@ -485,7 +495,7 @@ setup_signals(void) signal(SIGINT, sigint_handler); signal(SIGUSR1, sigusr1_handler); signal(SIGUSR2, sigusr2_handler); - signal(SIGCHLD, parent_exit); +// signal(SIGCHLD, parent_exit); } RETSIGTYPE parent_exit(int a) -- 2.39.5