Merge branch 'master' into 1.1
Conflicts: NEWS configure.in lib/Makefile.am lib/pidfile.c lib/pidfile.h lib/utils.c po/POTFILES.in po/nl.po src/Makefile.am src/bsd/device.c src/conf.c src/connection.c src/cygwin/device.c src/edge.c src/event.c src/graph.c src/linux/device.c src/meta.c src/mingw/device.c src/net.c src/net_packet.c src/net_setup.c src/net_socket.c src/netutl.c src/node.c src/process.c src/protocol.c src/protocol_auth.c src/protocol_edge.c src/protocol_key.c src/protocol_misc.c src/protocol_subnet.c src/raw_socket/device.c src/route.c src/solaris/device.c src/subnet.c src/tincd.c src/uml_socket/device.c
This commit is contained in:
commit
7ea85043ac
84 changed files with 810 additions and 1518 deletions
14
AUTHORS
14
AUTHORS
|
@ -1,11 +1,21 @@
|
|||
Main tinc authors:
|
||||
Guus Sliepen <guus@tinc-vpn.org>
|
||||
Ivo Timmermans (inactive)
|
||||
- Guus Sliepen <guus@tinc-vpn.org>
|
||||
- Ivo Timmermans (inactive)
|
||||
|
||||
Significant contributions from:
|
||||
- Michael Tokarev <mjt@tls.msk.ru>
|
||||
- Florian Forster <octo@verplant.org>
|
||||
- Grzegorz Dymarek <gregd72002@googlemail.com>
|
||||
- Max Rijevski <maksuf@gmail.com>
|
||||
- Scott Lamb <slamb@slamb.org>
|
||||
|
||||
These files are from other sources:
|
||||
* lib/pidfile.h and lib/pidfile.c are by Martin Schulze, taken from
|
||||
the syslog 1.3 sources.
|
||||
|
||||
* src/bsd/tunemu.c and tunemu.h are by Friedrich Schöller
|
||||
<friedrich.schoeller@gmail.com>
|
||||
|
||||
Also some of the macro files in the directory m4, and their
|
||||
accompanying files in lib, were taken from GNU fileutils.
|
||||
|
||||
|
|
|
@ -7,8 +7,11 @@ of the GPL are met.
|
|||
|
||||
The following applies to the LZO library:
|
||||
|
||||
Hereby I grant a special exception to the tinc VPN project
|
||||
(http://tinc.nl.linux.org/) to link the LZO library with the OpenSSL library
|
||||
(http://www.openssl.org).
|
||||
Hereby I grant a special exception to the tinc VPN project
|
||||
(http://tinc.nl.linux.org/) to link the LZO library with the OpenSSL library
|
||||
(http://www.openssl.org).
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
Markus F.X.J. Oberhumer
|
||||
|
||||
When tinc is compiled with the --enable-tunemu option, the resulting binary
|
||||
falls under the GPL version 3 or later.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
AUTOMAKE_OPTIONS = gnu
|
||||
|
||||
SUBDIRS = m4 lib src doc po
|
||||
SUBDIRS = m4 lib src doc
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
|
|
39
NEWS
39
NEWS
|
@ -4,6 +4,39 @@ Version 1.1-cvs Work in progress
|
|||
|
||||
* Use splay trees instead of AVL trees.
|
||||
|
||||
Version 1.0.10 not yet released
|
||||
|
||||
* Fixed potential crashes during shutdown and (in rare conditions) when other
|
||||
nodes disconnected from the VPN.
|
||||
|
||||
* Improved NAT handling: tinc now copes with mangled port numbers, and will
|
||||
automatically fall back to TCP if direct UDP connection between nodes is not
|
||||
possible.
|
||||
|
||||
* Allow configuration files with CRLF line endings to be read on UNIX.
|
||||
|
||||
* Disable old RSA keys when generating new ones.
|
||||
|
||||
* Many fixes in the path MTU discovery code.
|
||||
|
||||
* Tinc can now drop privileges and/or chroot itself.
|
||||
|
||||
* The TunnelServer code now just ignores information from clients instead of
|
||||
disconnecting them.
|
||||
|
||||
* Improved performance on Windows by using the new ProcessPriority option and
|
||||
by making the handling of packets received from the TAP-Win32 adapter more
|
||||
efficient.
|
||||
|
||||
* Code cleanups: tinc now follows the C99 standard, copyright headers have
|
||||
been updated to include patch authors, checkpoint tracing and localisation
|
||||
features have been removed.
|
||||
|
||||
* Support for (jailbroken) iPhone and iPod Touch has been added.
|
||||
|
||||
Thanks to Florian Forster, Grzegorz Dymarek and especially Michael Tokarev for
|
||||
their contributions to this version of tinc.
|
||||
|
||||
Version 1.0.9 Dec 26 2008
|
||||
|
||||
* Fixed tinc as a service under Windows 2003.
|
||||
|
@ -21,12 +54,16 @@ Version 1.0.9 Dec 26 2008
|
|||
|
||||
* Fixed a memory leak that occured when connections were closed.
|
||||
|
||||
Thanks to Max Rijevski for his contributions to this version of tinc.
|
||||
|
||||
Version 1.0.8 May 16 2007
|
||||
|
||||
* Fixed some memory and resource leaks.
|
||||
|
||||
* Made network sockets non-blocking under Windows.
|
||||
|
||||
Thanks to Scott Lamb and "dnk" for their contributions to this version of tinc.
|
||||
|
||||
Version 1.0.7 Jan 5 2007
|
||||
|
||||
* Fixed a bug that caused slow network speeds on Windows.
|
||||
|
@ -54,6 +91,8 @@ version 1.0.5 Nov 14 2006
|
|||
|
||||
* Support LZO 2.0 and later.
|
||||
|
||||
Thanks to Scott Lamb for his contributions to this version of tinc.
|
||||
|
||||
version 1.0.4 May 4 2005
|
||||
|
||||
* Fix switch and hub modes.
|
||||
|
|
21
configure.in
21
configure.in
|
@ -1,8 +1,6 @@
|
|||
dnl Process this file with autoconf to produce a configure script.
|
||||
|
||||
dnl $Id$
|
||||
|
||||
AC_PREREQ(2.59)
|
||||
AC_PREREQ(2.61)
|
||||
AC_INIT
|
||||
AC_CONFIG_SRCDIR([src/tincd.c])
|
||||
AC_GNU_SOURCE
|
||||
|
@ -10,9 +8,10 @@ AM_INIT_AUTOMAKE(tinc, 1.1-cvs)
|
|||
AC_CONFIG_HEADERS([config.h])
|
||||
AM_MAINTAINER_MODE
|
||||
|
||||
AM_GNU_GETTEXT([external])
|
||||
AM_GNU_GETTEXT_VERSION(0.14.1)
|
||||
|
||||
# Enable GNU extensions.
|
||||
# Define this here, not in acconfig's @TOP@ section, since definitions
|
||||
# in the latter don't make it into the configure-time tests.
|
||||
AC_GNU_SOURCE
|
||||
AC_DEFINE([__USE_BSD], 1, [Enable BSD extensions])
|
||||
|
||||
ALL_LINGUAS="nl"
|
||||
|
@ -26,7 +25,7 @@ AC_PROG_RANLIB
|
|||
|
||||
dnl Check and set OS
|
||||
|
||||
#AC_CANONICAL_HOST
|
||||
AC_CANONICAL_HOST
|
||||
|
||||
case $host_os in
|
||||
*linux*)
|
||||
|
@ -172,14 +171,8 @@ AC_ARG_ENABLE(jumbograms,
|
|||
[ AC_DEFINE(ENABLE_JUMBOGRAMS, 1, [Support for jumbograms (packets up to 9000 bytes)]) ]
|
||||
)
|
||||
|
||||
dnl Check if checkpoint tracing has to be enabled
|
||||
AC_ARG_ENABLE(tracing,
|
||||
AS_HELP_STRING([--enable-tracing], [enable checkpoint tracing (debugging only)]),
|
||||
[ AC_DEFINE(ENABLE_TRACING, 1, [Checkpoint tracing]) ]
|
||||
)
|
||||
|
||||
AC_SUBST(INCLUDES)
|
||||
|
||||
AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile lib/Makefile po/Makefile.in m4/Makefile])
|
||||
AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile lib/Makefile m4/Makefile])
|
||||
|
||||
AC_OUTPUT
|
||||
|
|
|
@ -12,8 +12,6 @@ maintain a stable network.
|
|||
provided that the entire resulting derived work is distributed
|
||||
under the terms of a permission notice identical to this one.
|
||||
|
||||
$Id$
|
||||
|
||||
1. Synchronisation
|
||||
==================
|
||||
|
||||
|
|
|
@ -12,8 +12,6 @@ Network daemon.
|
|||
provided that the entire resulting derived work is distributed
|
||||
under the terms of a permission notice identical to this one.
|
||||
|
||||
$Id$
|
||||
|
||||
1. Packet flow
|
||||
==============
|
||||
|
||||
|
|
|
@ -12,9 +12,6 @@ This is the protocol documentation for tinc, a Virtual Private Network daemon.
|
|||
provided that the entire resulting derived work is distributed
|
||||
under the terms of a permission notice identical to this one.
|
||||
|
||||
$Id$
|
||||
|
||||
|
||||
1. Protocols used in tinc
|
||||
-------------------------
|
||||
|
||||
|
|
|
@ -12,8 +12,6 @@ This is the security documentation for tinc, a Virtual Private Network daemon.
|
|||
provided that the entire resulting derived work is distributed
|
||||
under the terms of a permission notice identical to this one.
|
||||
|
||||
$Id$
|
||||
|
||||
Proposed new authentication scheme
|
||||
----------------------------------
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
\input texinfo @c -*-texinfo-*-
|
||||
@c $Id$
|
||||
@c %**start of header
|
||||
@setfilename tinc.info
|
||||
@settitle tinc Manual
|
||||
|
@ -20,8 +19,6 @@ Copyright @copyright{} 1998-2009 Ivo Timmermans,
|
|||
Guus Sliepen <guus@@tinc-vpn.org> and
|
||||
Wessel Dankers <wsl@@tinc-vpn.org>.
|
||||
|
||||
$Id$
|
||||
|
||||
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.
|
||||
|
@ -47,8 +44,6 @@ Copyright @copyright{} 1998-2009 Ivo Timmermans,
|
|||
Guus Sliepen <guus@@tinc-vpn.org> and
|
||||
Wessel Dankers <wsl@@tinc-vpn.org>.
|
||||
|
||||
$Id$
|
||||
|
||||
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.
|
||||
|
@ -2459,7 +2454,7 @@ and join channel #tinc.
|
|||
@section Authors
|
||||
|
||||
@table @asis
|
||||
@item Ivo Timmermans (zarq) (@email{ivo@@tinc-vpn.org})
|
||||
@item Ivo Timmermans (zarq)
|
||||
@item Guus Sliepen (guus) (@email{guus@@tinc-vpn.org})
|
||||
@end table
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.Dd 2002-03-25
|
||||
.Dd 2009-05-18
|
||||
.Dt TINCD 8
|
||||
.\" Manual page created by:
|
||||
.\" Ivo Timmermans
|
||||
|
|
8
have.h
8
have.h
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
have.h -- include headers which are known to exist
|
||||
Copyright (C) 1998-2005 Ivo Timmermans
|
||||
2003-2006 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2003-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
|
||||
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
|
||||
|
@ -13,9 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_HAVE_H__
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
## Process this file with automake to produce Makefile.in
|
||||
# $Id$
|
||||
|
||||
noinst_LIBRARIES = libvpn.a
|
||||
|
||||
|
@ -10,6 +9,6 @@ libvpn_a_SOURCES = xmalloc.c utils.c getopt.c getopt1.c list.c splay_tree.c drop
|
|||
libvpn_a_LIBADD = @LIBOBJS@ @ALLOCA@
|
||||
libvpn_a_DEPENDENCIES = $(libvpn_a_LIBADD)
|
||||
|
||||
noinst_HEADERS = xalloc.h utils.h getopt.h list.h splay_tree.h dropin.h fake-getaddrinfo.h fake-getnameinfo.h fake-gai-errnos.h gettext.h ipv6.h ipv4.h ethernet.h
|
||||
noinst_HEADERS = xalloc.h utils.h getopt.h list.h splay_tree.h dropin.h fake-getaddrinfo.h fake-getnameinfo.h fake-gai-errnos.h ipv6.h ipv4.h ethernet.h
|
||||
|
||||
EXTRA_DIST =
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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.
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Original AVL tree library by Michael H. Buselli <cosine@cosine.org>.
|
||||
|
||||
|
@ -28,8 +28,6 @@
|
|||
Cleaned up and incorporated some of the ideas from the red-black tree
|
||||
library for inclusion into tinc (http://www.tinc-vpn.org/) by
|
||||
Guus Sliepen <guus@tinc-vpn.org>.
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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.
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Original AVL tree library by Michael H. Buselli <cosine@cosine.org>.
|
||||
|
||||
|
@ -28,8 +28,6 @@
|
|||
Cleaned up and incorporated some of the ideas from the red-black tree
|
||||
library for inclusion into tinc (http://www.tinc-vpn.org/) by
|
||||
Guus Sliepen <guus@tinc-vpn.org>.
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
|
||||
|
|
10
lib/dropin.c
10
lib/dropin.c
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
dropin.c -- a set of drop-in replacements for libc functions
|
||||
Copyright (C) 2000-2005 Ivo Timmermans,
|
||||
2000-2006 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
|
||||
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
|
||||
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
|
10
lib/dropin.h
10
lib/dropin.h
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
dropin.h -- header file for dropin.c
|
||||
Copyright (C) 2000-2005 Ivo Timmermans,
|
||||
2000-2006 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
|
||||
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
|
||||
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __DROPIN_H__
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_ETHERNET_H__
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
* See getaddrinfo.c and getnameinfo.c.
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* for old netdb.h */
|
||||
#ifndef EAI_NODATA
|
||||
#define EAI_NODATA 1
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
/* $Id$ */
|
||||
|
||||
#ifndef _FAKE_GETADDRINFO_H
|
||||
#define _FAKE_GETADDRINFO_H
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
/* $Id$ */
|
||||
|
||||
#ifndef _FAKE_GETNAMEINFO_H
|
||||
#define _FAKE_GETNAMEINFO_H
|
||||
|
||||
|
|
36
lib/getopt.c
36
lib/getopt.c
|
@ -19,10 +19,10 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA. */
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
|
||||
Ditto for AIX 3.2 and <stdlib.h>. */
|
||||
|
@ -669,7 +669,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
|
|||
if (ambig && !exact)
|
||||
{
|
||||
if (opterr)
|
||||
fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
|
||||
fprintf (stderr, "%s: option `%s' is ambiguous\n",
|
||||
argv[0], argv[optind]);
|
||||
nextchar += strlen (nextchar);
|
||||
optind++;
|
||||
|
@ -693,12 +693,12 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
|
|||
if (argv[optind - 1][1] == '-')
|
||||
/* --option */
|
||||
fprintf (stderr,
|
||||
_("%s: option `--%s' doesn't allow an argument\n"),
|
||||
"%s: option `--%s' doesn't allow an argument\n",
|
||||
argv[0], pfound->name);
|
||||
else
|
||||
/* +option or -option */
|
||||
fprintf (stderr,
|
||||
_("%s: option `%c%s' doesn't allow an argument\n"),
|
||||
"%s: option `%c%s' doesn't allow an argument\n",
|
||||
argv[0], argv[optind - 1][0], pfound->name);
|
||||
|
||||
nextchar += strlen (nextchar);
|
||||
|
@ -715,7 +715,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
|
|||
{
|
||||
if (opterr)
|
||||
fprintf (stderr,
|
||||
_("%s: option `%s' requires an argument\n"),
|
||||
"%s: option `%s' requires an argument\n",
|
||||
argv[0], argv[optind - 1]);
|
||||
nextchar += strlen (nextchar);
|
||||
optopt = pfound->val;
|
||||
|
@ -744,11 +744,11 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
|
|||
{
|
||||
if (argv[optind][1] == '-')
|
||||
/* --option */
|
||||
fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
|
||||
fprintf (stderr, "%s: unrecognized option `--%s'\n",
|
||||
argv[0], nextchar);
|
||||
else
|
||||
/* +option or -option */
|
||||
fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
|
||||
fprintf (stderr, "%s: unrecognized option `%c%s'\n",
|
||||
argv[0], argv[optind][0], nextchar);
|
||||
}
|
||||
nextchar = (char *) "";
|
||||
|
@ -774,10 +774,10 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
|
|||
{
|
||||
if (posixly_correct)
|
||||
/* 1003.2 specifies the format of this message. */
|
||||
fprintf (stderr, _("%s: illegal option -- %c\n"),
|
||||
fprintf (stderr, "%s: illegal option -- %c\n",
|
||||
argv[0], c);
|
||||
else
|
||||
fprintf (stderr, _("%s: invalid option -- %c\n"),
|
||||
fprintf (stderr, "%s: invalid option -- %c\n",
|
||||
argv[0], c);
|
||||
}
|
||||
optopt = c;
|
||||
|
@ -807,7 +807,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
|
|||
if (opterr)
|
||||
{
|
||||
/* 1003.2 specifies the format of this message. */
|
||||
fprintf (stderr, _("%s: option requires an argument -- %c\n"),
|
||||
fprintf (stderr, "%s: option requires an argument -- %c\n",
|
||||
argv[0], c);
|
||||
}
|
||||
optopt = c;
|
||||
|
@ -854,7 +854,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
|
|||
if (ambig && !exact)
|
||||
{
|
||||
if (opterr)
|
||||
fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
|
||||
fprintf (stderr, "%s: option `-W %s' is ambiguous\n",
|
||||
argv[0], argv[optind]);
|
||||
nextchar += strlen (nextchar);
|
||||
optind++;
|
||||
|
@ -872,8 +872,8 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
|
|||
else
|
||||
{
|
||||
if (opterr)
|
||||
fprintf (stderr, _("\
|
||||
%s: option `-W %s' doesn't allow an argument\n"),
|
||||
fprintf (stderr,
|
||||
"%s: option `-W %s' doesn't allow an argument\n",
|
||||
argv[0], pfound->name);
|
||||
|
||||
nextchar += strlen (nextchar);
|
||||
|
@ -888,7 +888,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
|
|||
{
|
||||
if (opterr)
|
||||
fprintf (stderr,
|
||||
_("%s: option `%s' requires an argument\n"),
|
||||
"%s: option `%s' requires an argument\n",
|
||||
argv[0], argv[optind - 1]);
|
||||
nextchar += strlen (nextchar);
|
||||
return optstring[0] == ':' ? ':' : '?';
|
||||
|
@ -937,7 +937,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
|
|||
{
|
||||
/* 1003.2 specifies the format of this message. */
|
||||
fprintf (stderr,
|
||||
_("%s: option requires an argument -- %c\n"),
|
||||
"%s: option requires an argument -- %c\n",
|
||||
argv[0], c);
|
||||
}
|
||||
optopt = c;
|
||||
|
|
|
@ -14,10 +14,10 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA. */
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef _GETOPT_H
|
||||
#define _GETOPT_H 1
|
||||
|
|
|
@ -14,10 +14,10 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA. */
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
/* Convenience header for conditional use of GNU <libintl.h>.
|
||||
Copyright (C) 1995-1998, 2000-2003 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Library General Public License as published
|
||||
by the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA. */
|
||||
|
||||
#ifndef _LIBGETTEXT_H
|
||||
#define _LIBGETTEXT_H 1
|
||||
|
||||
/* NLS can be disabled through the configure --disable-nls option. */
|
||||
#if ENABLE_NLS
|
||||
|
||||
/* Get declarations of GNU message catalog functions. */
|
||||
# include <libintl.h>
|
||||
# include <locale.h>
|
||||
|
||||
/* Shorthand notation */
|
||||
|
||||
# define _(Text) gettext (Text)
|
||||
|
||||
#else
|
||||
|
||||
/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
|
||||
chokes if dcgettext is defined as a macro. So include it now, to make
|
||||
later inclusions of <locale.h> a NOP. We don't include <libintl.h>
|
||||
as well because people using "gettext.h" will not include <libintl.h>,
|
||||
and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
|
||||
is OK. */
|
||||
#if defined(__sun)
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
/* Disabled NLS.
|
||||
The casts to 'const char *' serve the purpose of producing warnings
|
||||
for invalid uses of the value returned from these functions.
|
||||
On pre-ANSI systems without 'const', the config.h file is supposed to
|
||||
contain "#define const". */
|
||||
# define gettext(Msgid) ((const char *) (Msgid))
|
||||
# define dgettext(Domainname, Msgid) ((const char *) (Msgid))
|
||||
# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
|
||||
# define ngettext(Msgid1, Msgid2, N) \
|
||||
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
|
||||
# define dngettext(Domainname, Msgid1, Msgid2, N) \
|
||||
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
|
||||
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
|
||||
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
|
||||
# define textdomain(Domainname) ((const char *) (Domainname))
|
||||
# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname))
|
||||
# define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset))
|
||||
|
||||
# define _(Text) Text
|
||||
# define setlocale(Category, Locale) ((const char *) (Locale))
|
||||
|
||||
#endif
|
||||
|
||||
/* A pseudo function call that serves as a marker for the automated
|
||||
extraction of messages, but does not call gettext(). The run-time
|
||||
translation is done at a different place in the code.
|
||||
The argument, String, should be a literal string. Concatenated strings
|
||||
and other string expressions won't work.
|
||||
The macro's expansion is not parenthesized, so that it is suitable as
|
||||
initializer for static 'char[]' or 'const char[]' variables. */
|
||||
#define gettext_noop(String) String
|
||||
|
||||
#define N_(Text) Text
|
||||
|
||||
#endif /* _LIBGETTEXT_H */
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_IPV4_H__
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_IPV6_H__
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_LIST_H__
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
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., Foundation,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
|
||||
|
||||
/* written by Jim Meyering */
|
||||
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA. */
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
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., Foundation,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
|
||||
|
||||
/* written by Jim Meyering */
|
||||
|
||||
|
|
|
@ -12,11 +12,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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: splay_tree.c 1374 2004-03-21 14:21:22Z guus $
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
|
|
@ -12,11 +12,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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: splay_tree.h 1374 2004-03-21 14:21:22Z guus $
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
|
||||
|
|
41
lib/utils.c
41
lib/utils.c
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
utils.c -- gathering of some stupid small functions
|
||||
Copyright (C) 1999-2005 Ivo Timmermans <zarq@iname.com>
|
||||
2000-2006 Guus Sliepen <guus@tinc-vpn.org>
|
||||
Copyright (C) 1999-2005 Ivo Timmermans
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
|
||||
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
|
||||
|
@ -13,9 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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.
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -23,12 +23,6 @@
|
|||
#include "../src/logger.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifdef ENABLE_TRACING
|
||||
volatile int (cp_line[]) = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
volatile char (*cp_file[]) = {"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?"};
|
||||
volatile int cp_index = 0;
|
||||
#endif
|
||||
|
||||
const char hexadecimals[] = "0123456789ABCDEF";
|
||||
|
||||
int charhex2bin(char c) {
|
||||
|
@ -53,29 +47,6 @@ void bin2hex(char *src, char *dst, int length) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_TRACING
|
||||
void cp_trace() {
|
||||
logger(LOG_DEBUG, "Checkpoint trace: %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d...",
|
||||
cp_file[(cp_index + 15) % 16], cp_line[(cp_index + 15) % 16],
|
||||
cp_file[(cp_index + 14) % 16], cp_line[(cp_index + 14) % 16],
|
||||
cp_file[(cp_index + 13) % 16], cp_line[(cp_index + 13) % 16],
|
||||
cp_file[(cp_index + 12) % 16], cp_line[(cp_index + 12) % 16],
|
||||
cp_file[(cp_index + 11) % 16], cp_line[(cp_index + 11) % 16],
|
||||
cp_file[(cp_index + 10) % 16], cp_line[(cp_index + 10) % 16],
|
||||
cp_file[(cp_index + 9) % 16], cp_line[(cp_index + 9) % 16],
|
||||
cp_file[(cp_index + 8) % 16], cp_line[(cp_index + 8) % 16],
|
||||
cp_file[(cp_index + 7) % 16], cp_line[(cp_index + 7) % 16],
|
||||
cp_file[(cp_index + 6) % 16], cp_line[(cp_index + 6) % 16],
|
||||
cp_file[(cp_index + 5) % 16], cp_line[(cp_index + 5) % 16],
|
||||
cp_file[(cp_index + 4) % 16], cp_line[(cp_index + 4) % 16],
|
||||
cp_file[(cp_index + 3) % 16], cp_line[(cp_index + 3) % 16],
|
||||
cp_file[(cp_index + 2) % 16], cp_line[(cp_index + 2) % 16],
|
||||
cp_file[(cp_index + 1) % 16], cp_line[(cp_index + 1) % 16],
|
||||
cp_file[cp_index], cp_line[cp_index]
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_MINGW) || defined(HAVE_CYGWIN)
|
||||
#ifdef HAVE_CYGWIN
|
||||
#include <w32api/windows.h>
|
||||
|
@ -86,7 +57,7 @@ const char *winerror(int err) {
|
|||
|
||||
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, sizeof(buf), NULL)) {
|
||||
strncpy(buf, _("(unable to format errormessage)"), sizeof(buf));
|
||||
strncpy(buf, "(unable to format errormessage)", sizeof(buf));
|
||||
};
|
||||
|
||||
if((newline = strchr(buf, '\r')))
|
||||
|
|
24
lib/utils.h
24
lib/utils.h
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
utils.h -- header file for utils.c
|
||||
Copyright (C) 1999-2005 Ivo Timmermans <zarq@iname.com>
|
||||
2000-2006 Guus Sliepen <guus@tinc-vpn.org>
|
||||
Copyright (C) 1999-2005 Ivo Timmermans
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
|
||||
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
|
||||
|
@ -13,28 +13,14 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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.
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_UTILS_H__
|
||||
#define __TINC_UTILS_H__
|
||||
|
||||
#ifdef ENABLE_TRACING
|
||||
extern volatile int cp_line[];
|
||||
extern volatile char *cp_file[];
|
||||
extern volatile int cp_index;
|
||||
extern void cp_trace(void);
|
||||
|
||||
#define cp() { cp_line[cp_index] = __LINE__; cp_file[cp_index] = __FILE__; cp_index++; cp_index %= 16; }
|
||||
#define ecp() { fprintf(stderr, "Explicit checkpoint in %s line %d\n", __FILE__, __LINE__); }
|
||||
#else
|
||||
#define cp()
|
||||
#define ecp()
|
||||
#define cp_trace()
|
||||
#endif
|
||||
|
||||
extern void hex2bin(char *src, char *dst, int length);
|
||||
extern void bin2hex(char *src, char *dst, int length);
|
||||
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
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., Foundation,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
|
@ -34,7 +34,6 @@ void *realloc ();
|
|||
void free ();
|
||||
#endif
|
||||
|
||||
#include "gettext.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
#ifndef EXIT_FAILURE
|
||||
|
@ -53,7 +52,7 @@ void *xrealloc (void *p, size_t n);
|
|||
int xalloc_exit_failure = EXIT_FAILURE;
|
||||
|
||||
/* FIXME: describe */
|
||||
char *const xalloc_msg_memory_exhausted = N_("Memory exhausted");
|
||||
char *const xalloc_msg_memory_exhausted = "Memory exhausted";
|
||||
|
||||
/* FIXME: describe */
|
||||
void (*xalloc_fail_func) (int) = 0;
|
||||
|
|
41
po/Makevars
41
po/Makevars
|
@ -1,41 +0,0 @@
|
|||
# Makefile variables for PO directory in any package using GNU gettext.
|
||||
|
||||
# Usually the message domain is the same as the package name.
|
||||
DOMAIN = $(PACKAGE)
|
||||
|
||||
# These two variables depend on the location of this directory.
|
||||
subdir = po
|
||||
top_builddir = ..
|
||||
|
||||
# These options get passed to xgettext.
|
||||
XGETTEXT_OPTIONS = --keyword=_ --keyword=N_
|
||||
|
||||
# This is the copyright holder that gets inserted into the header of the
|
||||
# $(DOMAIN).pot file. Set this to the copyright holder of the surrounding
|
||||
# package. (Note that the msgstr strings, extracted from the package's
|
||||
# sources, belong to the copyright holder of the package.) Translators are
|
||||
# expected to transfer the copyright for their translations to this person
|
||||
# or entity, or to disclaim their copyright. The empty string stands for
|
||||
# the public domain; in this case the translators are expected to disclaim
|
||||
# their copyright.
|
||||
COPYRIGHT_HOLDER = Ivo Timmermans and Guus Sliepen
|
||||
|
||||
# This is the email address or URL to which the translators shall report
|
||||
# bugs in the untranslated strings:
|
||||
# - Strings which are not entire sentences, see the maintainer guidelines
|
||||
# in the GNU gettext documentation, section 'Preparing Strings'.
|
||||
# - Strings which use unclear terms or require additional context to be
|
||||
# understood.
|
||||
# - Strings which make invalid assumptions about notation of date, time or
|
||||
# money.
|
||||
# - Pluralisation problems.
|
||||
# - Incorrect English spelling.
|
||||
# - Incorrect formatting.
|
||||
# It can be your email address, or a mailing list address where translators
|
||||
# can write to without being subscribed, or the URL of a web page through
|
||||
# which the translators can contact you.
|
||||
MSGID_BUGS_ADDRESS = tinc-devel@tinc-vpn.org
|
||||
|
||||
# This is the list of locale categories, beyond LC_MESSAGES, for which the
|
||||
# message catalogs shall be used. It is usually empty.
|
||||
EXTRA_LOCALE_CATEGORIES =
|
|
@ -1,5 +1,4 @@
|
|||
## Produce this file with automake to get Makefile.in
|
||||
# $Id: Makefile.am,v 1.4.4.33 2003/08/02 15:13:08 guus Exp $
|
||||
|
||||
sbin_PROGRAMS = tincd tincctl
|
||||
|
||||
|
@ -24,7 +23,7 @@ INCLUDES = @INCLUDES@ -I$(top_builddir) -I$(top_srcdir)/lib
|
|||
noinst_HEADERS = cipher.h conf.h connection.h control.h crypto.h device.h digest.h edge.h graph.h logger.h meta.h net.h netutl.h node.h process.h \
|
||||
protocol.h route.h rsa.h rsagen.h subnet.h bsd/tunemu.h
|
||||
|
||||
LIBS = @LIBS@ @LIBGCRYPT_LIBS@ @LIBINTL@
|
||||
LIBS = @LIBS@ @LIBGCRYPT_LIBS@
|
||||
|
||||
if TUNEMU
|
||||
LIBS += -lpcap
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
device.c -- Interaction BSD tun/tap device
|
||||
Copyright (C) 2001-2005 Ivo Timmermans,
|
||||
2001-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2009 Grzegorz Dymarek <gregd72002@googlemail.com>
|
||||
|
||||
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
|
||||
|
@ -13,11 +14,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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: device.c 1398 2004-11-01 15:18:53Z guus $
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -61,8 +60,6 @@ static device_type_t device_type = DEVICE_TYPE_TUN;
|
|||
bool setup_device(void) {
|
||||
char *type;
|
||||
|
||||
cp();
|
||||
|
||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
||||
device = xstrdup(DEFAULT_DEVICE);
|
||||
|
||||
|
@ -83,7 +80,7 @@ bool setup_device(void) {
|
|||
else if(!strcasecmp(type, "tap"))
|
||||
device_type = DEVICE_TYPE_TAP;
|
||||
else {
|
||||
logger(LOG_ERR, _("Unknown device type %s!"), type);
|
||||
logger(LOG_ERR, "Unknown device type %s!", type);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
@ -104,7 +101,7 @@ bool setup_device(void) {
|
|||
}
|
||||
|
||||
if(device_fd < 0) {
|
||||
logger(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
|
||||
logger(LOG_ERR, "Could not open %s: %s", device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -116,7 +113,7 @@ bool setup_device(void) {
|
|||
{
|
||||
const int zero = 0;
|
||||
if(ioctl(device_fd, TUNSIFHEAD, &zero, sizeof zero) == -1) {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "ioctl", strerror(errno));
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "ioctl", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -128,14 +125,14 @@ bool setup_device(void) {
|
|||
}
|
||||
#endif
|
||||
|
||||
device_info = _("Generic BSD tun device");
|
||||
device_info = "Generic BSD tun device";
|
||||
break;
|
||||
case DEVICE_TYPE_TUNIFHEAD:
|
||||
#ifdef TUNSIFHEAD
|
||||
{
|
||||
const int one = 1;
|
||||
if(ioctl(device_fd, TUNSIFHEAD, &one, sizeof one) == -1) {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "ioctl", strerror(errno));
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "ioctl", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -147,28 +144,26 @@ bool setup_device(void) {
|
|||
}
|
||||
#endif
|
||||
|
||||
device_info = _("Generic BSD tun device");
|
||||
device_info = "Generic BSD tun device";
|
||||
break;
|
||||
case DEVICE_TYPE_TAP:
|
||||
if(routing_mode == RMODE_ROUTER)
|
||||
overwrite_mac = true;
|
||||
device_info = _("Generic BSD tap device");
|
||||
device_info = "Generic BSD tap device";
|
||||
break;
|
||||
#ifdef HAVE_TUNEMU
|
||||
case DEVICE_TYPE_TUNEMU:
|
||||
device_info = _("BSD tunemu device");
|
||||
device_info = "BSD tunemu device";
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
logger(LOG_INFO, _("%s is a %s"), device, device_info);
|
||||
logger(LOG_INFO, "%s is a %s", device, device_info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void close_device(void) {
|
||||
cp();
|
||||
|
||||
switch(device_type) {
|
||||
#ifdef HAVE_TUNEMU
|
||||
case DEVICE_TYPE_TUNEMU:
|
||||
|
@ -186,8 +181,6 @@ void close_device(void) {
|
|||
bool read_packet(vpn_packet_t *packet) {
|
||||
int inlen;
|
||||
|
||||
cp();
|
||||
|
||||
switch(device_type) {
|
||||
case DEVICE_TYPE_TUN:
|
||||
#ifdef HAVE_TUNEMU
|
||||
|
@ -200,7 +193,7 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
#endif
|
||||
|
||||
if(inlen <= 0) {
|
||||
logger(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Error while reading from %s %s: %s", device_info,
|
||||
device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -229,7 +222,7 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
struct iovec vector[2] = {{&type, sizeof type}, {packet->data + 14, MTU - 14}};
|
||||
|
||||
if((inlen = readv(device_fd, vector, 2)) <= 0) {
|
||||
logger(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Error while reading from %s %s: %s", device_info,
|
||||
device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -258,7 +251,7 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
|
||||
case DEVICE_TYPE_TAP:
|
||||
if((inlen = read(device_fd, packet->data, MTU)) <= 0) {
|
||||
logger(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Error while reading from %s %s: %s", device_info,
|
||||
device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -272,7 +265,7 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
|
||||
device_total_in += packet->len;
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Read packet of %d bytes from %s"),
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Read packet of %d bytes from %s",
|
||||
packet->len, device_info);
|
||||
|
||||
logger(LOG_INFO, "E:fd_read");
|
||||
|
@ -280,15 +273,13 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
}
|
||||
|
||||
bool write_packet(vpn_packet_t *packet) {
|
||||
cp();
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Writing packet of %d bytes to %s",
|
||||
packet->len, device_info);
|
||||
|
||||
switch(device_type) {
|
||||
case DEVICE_TYPE_TUN:
|
||||
if(write(device_fd, packet->data + 14, packet->len - 14) < 0) {
|
||||
logger(LOG_ERR, _("Error while writing to %s %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Error while writing to %s %s: %s", device_info,
|
||||
device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -310,13 +301,13 @@ bool write_packet(vpn_packet_t *packet) {
|
|||
break;
|
||||
default:
|
||||
ifdebug(TRAFFIC) logger(LOG_ERR,
|
||||
_("Unknown address family %x while writing packet to %s %s"),
|
||||
"Unknown address family %x while writing packet to %s %s",
|
||||
af, device_info, device);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(writev(device_fd, vector, 2) < 0) {
|
||||
logger(LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
|
||||
logger(LOG_ERR, "Can't write to %s %s: %s", device_info, device,
|
||||
strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -325,7 +316,7 @@ bool write_packet(vpn_packet_t *packet) {
|
|||
|
||||
case DEVICE_TYPE_TAP:
|
||||
if(write(device_fd, packet->data, packet->len) < 0) {
|
||||
logger(LOG_ERR, _("Error while writing to %s %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Error while writing to %s %s: %s", device_info,
|
||||
device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -334,7 +325,7 @@ bool write_packet(vpn_packet_t *packet) {
|
|||
#ifdef HAVE_TUNEMU
|
||||
case DEVICE_TYPE_TUNEMU:
|
||||
if(tunemu_write(device_fd, packet->data + 14, packet->len - 14) < 0) {
|
||||
logger(LOG_ERR, _("Error while writing to %s %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Error while writing to %s %s: %s", device_info,
|
||||
device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -351,9 +342,7 @@ bool write_packet(vpn_packet_t *packet) {
|
|||
}
|
||||
|
||||
void dump_device_stats(void) {
|
||||
cp();
|
||||
|
||||
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
|
||||
logger(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
|
||||
logger(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
|
||||
logger(LOG_DEBUG, "Statistics for %s %s:", device_info, device);
|
||||
logger(LOG_DEBUG, " total bytes in: %10d", device_total_in);
|
||||
logger(LOG_DEBUG, " total bytes out: %10d", device_total_out);
|
||||
}
|
||||
|
|
52
src/conf.c
52
src/conf.c
|
@ -15,11 +15,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -55,27 +53,19 @@ static int config_compare(const config_t *a, const config_t *b) {
|
|||
}
|
||||
|
||||
void init_configuration(splay_tree_t ** config_tree) {
|
||||
cp();
|
||||
|
||||
*config_tree = splay_alloc_tree((splay_compare_t) config_compare, (splay_action_t) free_config);
|
||||
}
|
||||
|
||||
void exit_configuration(splay_tree_t ** config_tree) {
|
||||
cp();
|
||||
|
||||
splay_delete_tree(*config_tree);
|
||||
*config_tree = NULL;
|
||||
}
|
||||
|
||||
config_t *new_config(void) {
|
||||
cp();
|
||||
|
||||
return xmalloc_and_zero(sizeof(config_t));
|
||||
}
|
||||
|
||||
void free_config(config_t *cfg) {
|
||||
cp();
|
||||
|
||||
if(cfg->variable)
|
||||
free(cfg->variable);
|
||||
|
||||
|
@ -89,16 +79,12 @@ void free_config(config_t *cfg) {
|
|||
}
|
||||
|
||||
void config_add(splay_tree_t *config_tree, config_t *cfg) {
|
||||
cp();
|
||||
|
||||
splay_insert(config_tree, cfg);
|
||||
}
|
||||
|
||||
config_t *lookup_config(splay_tree_t *config_tree, char *variable) {
|
||||
config_t cfg, *found;
|
||||
|
||||
cp();
|
||||
|
||||
cfg.variable = variable;
|
||||
cfg.file = "";
|
||||
cfg.line = 0;
|
||||
|
@ -118,8 +104,6 @@ config_t *lookup_config_next(splay_tree_t *config_tree, const config_t *cfg) {
|
|||
splay_node_t *node;
|
||||
config_t *found;
|
||||
|
||||
cp();
|
||||
|
||||
node = splay_search_node(config_tree, cfg);
|
||||
|
||||
if(node) {
|
||||
|
@ -135,8 +119,6 @@ config_t *lookup_config_next(splay_tree_t *config_tree, const config_t *cfg) {
|
|||
}
|
||||
|
||||
bool get_config_bool(const config_t *cfg, bool *result) {
|
||||
cp();
|
||||
|
||||
if(!cfg)
|
||||
return false;
|
||||
|
||||
|
@ -148,30 +130,26 @@ bool get_config_bool(const config_t *cfg, bool *result) {
|
|||
return true;
|
||||
}
|
||||
|
||||
logger(LOG_ERR, _("\"yes\" or \"no\" expected for configuration variable %s in %s line %d"),
|
||||
logger(LOG_ERR, "\"yes\" or \"no\" expected for configuration variable %s in %s line %d",
|
||||
cfg->variable, cfg->file, cfg->line);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get_config_int(const config_t *cfg, int *result) {
|
||||
cp();
|
||||
|
||||
if(!cfg)
|
||||
return false;
|
||||
|
||||
if(sscanf(cfg->value, "%d", result) == 1)
|
||||
return true;
|
||||
|
||||
logger(LOG_ERR, _("Integer expected for configuration variable %s in %s line %d"),
|
||||
logger(LOG_ERR, "Integer expected for configuration variable %s in %s line %d",
|
||||
cfg->variable, cfg->file, cfg->line);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get_config_string(const config_t *cfg, char **result) {
|
||||
cp();
|
||||
|
||||
if(!cfg)
|
||||
return false;
|
||||
|
||||
|
@ -183,8 +161,6 @@ bool get_config_string(const config_t *cfg, char **result) {
|
|||
bool get_config_address(const config_t *cfg, struct addrinfo **result) {
|
||||
struct addrinfo *ai;
|
||||
|
||||
cp();
|
||||
|
||||
if(!cfg)
|
||||
return false;
|
||||
|
||||
|
@ -195,7 +171,7 @@ bool get_config_address(const config_t *cfg, struct addrinfo **result) {
|
|||
return true;
|
||||
}
|
||||
|
||||
logger(LOG_ERR, _("Hostname or IP address expected for configuration variable %s in %s line %d"),
|
||||
logger(LOG_ERR, "Hostname or IP address expected for configuration variable %s in %s line %d",
|
||||
cfg->variable, cfg->file, cfg->line);
|
||||
|
||||
return false;
|
||||
|
@ -204,13 +180,11 @@ bool get_config_address(const config_t *cfg, struct addrinfo **result) {
|
|||
bool get_config_subnet(const config_t *cfg, subnet_t ** result) {
|
||||
subnet_t subnet = {0};
|
||||
|
||||
cp();
|
||||
|
||||
if(!cfg)
|
||||
return false;
|
||||
|
||||
if(!str2net(&subnet, cfg->value)) {
|
||||
logger(LOG_ERR, _("Subnet expected for configuration variable %s in %s line %d"),
|
||||
logger(LOG_ERR, "Subnet expected for configuration variable %s in %s line %d",
|
||||
cfg->variable, cfg->file, cfg->line);
|
||||
return false;
|
||||
}
|
||||
|
@ -221,7 +195,7 @@ bool get_config_subnet(const config_t *cfg, subnet_t ** result) {
|
|||
&& !maskcheck(&subnet.net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof subnet.net.ipv4.address))
|
||||
|| ((subnet.type == SUBNET_IPV6)
|
||||
&& !maskcheck(&subnet.net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof subnet.net.ipv6.address))) {
|
||||
logger(LOG_ERR, _ ("Network address and prefix length do not match for configuration variable %s in %s line %d"),
|
||||
logger(LOG_ERR, "Network address and prefix length do not match for configuration variable %s in %s line %d",
|
||||
cfg->variable, cfg->file, cfg->line);
|
||||
return false;
|
||||
}
|
||||
|
@ -316,12 +290,10 @@ int read_config_file(splay_tree_t *config_tree, const char *fname) {
|
|||
config_t *cfg;
|
||||
size_t bufsize;
|
||||
|
||||
cp();
|
||||
|
||||
fp = fopen(fname, "r");
|
||||
|
||||
if(!fp) {
|
||||
logger(LOG_ERR, _("Cannot open config file %s: %s"), fname,
|
||||
logger(LOG_ERR, "Cannot open config file %s: %s", fname,
|
||||
strerror(errno));
|
||||
return -3;
|
||||
}
|
||||
|
@ -375,7 +347,7 @@ int read_config_file(splay_tree_t *config_tree, const char *fname) {
|
|||
|
||||
|
||||
if(!*value) {
|
||||
logger(LOG_ERR, _("No value for variable `%s' on line %d while reading config file %s"),
|
||||
logger(LOG_ERR, "No value for variable `%s' on line %d while reading config file %s",
|
||||
variable, lineno, fname);
|
||||
break;
|
||||
}
|
||||
|
@ -399,13 +371,11 @@ bool read_server_config() {
|
|||
char *fname;
|
||||
int x;
|
||||
|
||||
cp();
|
||||
|
||||
xasprintf(&fname, "%s/tinc.conf", confbase);
|
||||
x = read_config_file(config_tree, fname);
|
||||
|
||||
if(x == -1) { /* System error: complain */
|
||||
logger(LOG_ERR, _("Failed to read `%s': %s"), fname, strerror(errno));
|
||||
logger(LOG_ERR, "Failed to read `%s': %s", fname, strerror(errno));
|
||||
}
|
||||
|
||||
free(fname);
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_CONF_H__
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
/*
|
||||
connection.c -- connection list management
|
||||
Copyright (C) 2000-2007 Guus Sliepen <guus@tinc-vpn.org>,
|
||||
Copyright (C) 2000-2009 Guus Sliepen <guus@tinc-vpn.org>,
|
||||
2000-2005 Ivo Timmermans
|
||||
2008 Max Rijevski <maksuf@gmail.com>
|
||||
|
||||
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
|
||||
|
@ -13,11 +14,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -41,30 +40,22 @@ static int connection_compare(const connection_t *a, const connection_t *b) {
|
|||
}
|
||||
|
||||
void init_connections(void) {
|
||||
cp();
|
||||
|
||||
connection_tree = splay_alloc_tree((splay_compare_t) connection_compare, (splay_action_t) free_connection);
|
||||
broadcast = new_connection();
|
||||
broadcast->name = xstrdup(_("everyone"));
|
||||
broadcast->hostname = xstrdup(_("BROADCAST"));
|
||||
broadcast->name = xstrdup("everyone");
|
||||
broadcast->hostname = xstrdup("BROADCAST");
|
||||
}
|
||||
|
||||
void exit_connections(void) {
|
||||
cp();
|
||||
|
||||
splay_delete_tree(connection_tree);
|
||||
free_connection(broadcast);
|
||||
}
|
||||
|
||||
connection_t *new_connection(void) {
|
||||
cp();
|
||||
|
||||
return xmalloc_and_zero(sizeof(connection_t));
|
||||
}
|
||||
|
||||
void free_connection(connection_t *c) {
|
||||
cp();
|
||||
|
||||
if(!c)
|
||||
return;
|
||||
|
||||
|
@ -93,14 +84,10 @@ void free_connection(connection_t *c) {
|
|||
}
|
||||
|
||||
void connection_add(connection_t *c) {
|
||||
cp();
|
||||
|
||||
splay_insert(connection_tree, c);
|
||||
}
|
||||
|
||||
void connection_del(connection_t *c) {
|
||||
cp();
|
||||
|
||||
splay_delete(connection_tree, c);
|
||||
}
|
||||
|
||||
|
@ -108,12 +95,10 @@ int dump_connections(struct evbuffer *out) {
|
|||
splay_node_t *node;
|
||||
connection_t *c;
|
||||
|
||||
cp();
|
||||
|
||||
for(node = connection_tree->head; node; node = node->next) {
|
||||
c = node->data;
|
||||
if(evbuffer_add_printf(out,
|
||||
_(" %s at %s options %lx socket %d status %04x\n"),
|
||||
" %s at %s options %lx socket %d status %04x\n",
|
||||
c->name, c->hostname, c->options, c->socket,
|
||||
bitfield_to_int(&c->status, sizeof c->status)) == -1)
|
||||
return errno;
|
||||
|
@ -126,8 +111,6 @@ bool read_connection_config(connection_t *c) {
|
|||
char *fname;
|
||||
int x;
|
||||
|
||||
cp();
|
||||
|
||||
xasprintf(&fname, "%s/hosts/%s", confbase, c->name);
|
||||
x = read_config_file(c->config_tree, fname);
|
||||
free(fname);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
connection.h -- header for connection.c
|
||||
Copyright (C) 2000-2006 Guus Sliepen <guus@tinc-vpn.org>,
|
||||
Copyright (C) 2000-2009 Guus Sliepen <guus@tinc-vpn.org>,
|
||||
2000-2005 Ivo Timmermans
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_CONNECTION_H__
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -59,15 +57,13 @@ bool setup_device(void) {
|
|||
|
||||
bool found = false;
|
||||
|
||||
cp();
|
||||
|
||||
get_config_string(lookup_config(config_tree, "Device"), &device);
|
||||
get_config_string(lookup_config(config_tree, "Interface"), &iface);
|
||||
|
||||
/* Open registry and look for network adapters */
|
||||
|
||||
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, NETWORK_CONNECTIONS_KEY, 0, KEY_READ, &key)) {
|
||||
logger(LOG_ERR, _("Unable to read registry: %s"), winerror(GetLastError()));
|
||||
logger(LOG_ERR, "Unable to read registry: %s", winerror(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -119,7 +115,7 @@ bool setup_device(void) {
|
|||
RegCloseKey(key);
|
||||
|
||||
if(!found) {
|
||||
logger(LOG_ERR, _("No Windows tap device found!"));
|
||||
logger(LOG_ERR, "No Windows tap device found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -136,7 +132,7 @@ bool setup_device(void) {
|
|||
Furthermore I don't really know how to do it the "Windows" way. */
|
||||
|
||||
if(socketpair(AF_UNIX, SOCK_DGRAM, PF_UNIX, sp)) {
|
||||
logger(LOG_DEBUG, _("System call `%s' failed: %s"), "socketpair", strerror(errno));
|
||||
logger(LOG_DEBUG, "System call `%s' failed: %s", "socketpair", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -145,7 +141,7 @@ bool setup_device(void) {
|
|||
device_handle = CreateFile(tapname, GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM , 0);
|
||||
|
||||
if(device_handle == INVALID_HANDLE_VALUE) {
|
||||
logger(LOG_ERR, _("Could not open Windows tap device %s (%s) for writing: %s"), device, iface, winerror(GetLastError()));
|
||||
logger(LOG_ERR, "Could not open Windows tap device %s (%s) for writing: %s", device, iface, winerror(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -154,7 +150,7 @@ bool setup_device(void) {
|
|||
/* Get MAC address from tap device */
|
||||
|
||||
if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof mymac.x, mymac.x, sizeof mymac.x, &len, 0)) {
|
||||
logger(LOG_ERR, _("Could not get MAC address from Windows tap device %s (%s): %s"), device, iface, winerror(GetLastError()));
|
||||
logger(LOG_ERR, "Could not get MAC address from Windows tap device %s (%s): %s", device, iface, winerror(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -167,7 +163,7 @@ bool setup_device(void) {
|
|||
reader_pid = fork();
|
||||
|
||||
if(reader_pid == -1) {
|
||||
logger(LOG_DEBUG, _("System call `%s' failed: %s"), "fork", strerror(errno));
|
||||
logger(LOG_DEBUG, "System call `%s' failed: %s", "fork", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -183,13 +179,13 @@ bool setup_device(void) {
|
|||
device_handle = CreateFile(tapname, GENERIC_READ, FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, 0);
|
||||
|
||||
if(device_handle == INVALID_HANDLE_VALUE) {
|
||||
logger(LOG_ERR, _("Could not open Windows tap device %s (%s) for reading: %s"), device, iface, winerror(GetLastError()));
|
||||
logger(LOG_ERR, "Could not open Windows tap device %s (%s) for reading: %s", device, iface, winerror(GetLastError()));
|
||||
buf[0] = 0;
|
||||
write(sp[1], buf, 1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
logger(LOG_DEBUG, _("Tap reader forked and running."));
|
||||
logger(LOG_DEBUG, "Tap reader forked and running.");
|
||||
|
||||
/* Notify success */
|
||||
|
||||
|
@ -206,20 +202,18 @@ bool setup_device(void) {
|
|||
|
||||
read(device_fd, &gelukt, 1);
|
||||
if(gelukt != 1) {
|
||||
logger(LOG_DEBUG, _("Tap reader failed!"));
|
||||
logger(LOG_DEBUG, "Tap reader failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
device_info = _("Windows tap device");
|
||||
device_info = "Windows tap device";
|
||||
|
||||
logger(LOG_INFO, _("%s (%s) is a %s"), device, iface, device_info);
|
||||
logger(LOG_INFO, "%s (%s) is a %s", device, iface, device_info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void close_device(void) {
|
||||
cp();
|
||||
|
||||
close(sp[0]);
|
||||
close(sp[1]);
|
||||
CloseHandle(device_handle);
|
||||
|
@ -233,10 +227,8 @@ void close_device(void) {
|
|||
bool read_packet(vpn_packet_t *packet) {
|
||||
int inlen;
|
||||
|
||||
cp();
|
||||
|
||||
if((inlen = read(sp[0], packet->data, MTU)) <= 0) {
|
||||
logger(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Error while reading from %s %s: %s", device_info,
|
||||
device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -245,7 +237,7 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
|
||||
device_total_in += packet->len;
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Read packet of %d bytes from %s", packet->len,
|
||||
device_info);
|
||||
|
||||
return true;
|
||||
|
@ -254,13 +246,11 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
bool write_packet(vpn_packet_t *packet) {
|
||||
long outlen;
|
||||
|
||||
cp();
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Writing packet of %d bytes to %s",
|
||||
packet->len, device_info);
|
||||
|
||||
if(!WriteFile (device_handle, packet->data, packet->len, &outlen, NULL)) {
|
||||
logger(LOG_ERR, _("Error while writing to %s %s: %s"), device_info, device, winerror(GetLastError()));
|
||||
logger(LOG_ERR, "Error while writing to %s %s: %s", device_info, device, winerror(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -270,9 +260,7 @@ bool write_packet(vpn_packet_t *packet) {
|
|||
}
|
||||
|
||||
void dump_device_stats(void) {
|
||||
cp();
|
||||
|
||||
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
|
||||
logger(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
|
||||
logger(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
|
||||
logger(LOG_DEBUG, "Statistics for %s %s:", device_info, device);
|
||||
logger(LOG_DEBUG, " total bytes in: %10d", device_total_in);
|
||||
logger(LOG_DEBUG, " total bytes out: %10d", device_total_out);
|
||||
}
|
||||
|
|
10
src/device.h
10
src/device.h
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
net.h -- generic header for device.c
|
||||
Copyright (C) 2001-2005 Ivo Timmermans <zarq@iname.com>
|
||||
Copyright (C) 2001-2005 Ivo Timmermans
|
||||
2001-2006 Guus Sliepen <guus@tinc-vpn.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_DEVICE_H__
|
||||
|
|
30
src/edge.c
30
src/edge.c
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -53,48 +51,34 @@ static int edge_weight_compare(const edge_t *a, const edge_t *b) {
|
|||
}
|
||||
|
||||
void init_edges(void) {
|
||||
cp();
|
||||
|
||||
edge_weight_tree = splay_alloc_tree((splay_compare_t) edge_weight_compare, NULL);
|
||||
}
|
||||
|
||||
splay_tree_t *new_edge_tree(void) {
|
||||
cp();
|
||||
|
||||
return splay_alloc_tree((splay_compare_t) edge_compare, (splay_action_t) free_edge);
|
||||
}
|
||||
|
||||
void free_edge_tree(splay_tree_t *edge_tree) {
|
||||
cp();
|
||||
|
||||
splay_delete_tree(edge_tree);
|
||||
}
|
||||
|
||||
void exit_edges(void) {
|
||||
cp();
|
||||
|
||||
splay_delete_tree(edge_weight_tree);
|
||||
}
|
||||
|
||||
/* Creation and deletion of connection elements */
|
||||
|
||||
edge_t *new_edge(void) {
|
||||
cp();
|
||||
|
||||
return xmalloc_and_zero(sizeof(edge_t));
|
||||
}
|
||||
|
||||
void free_edge(edge_t *e) {
|
||||
cp();
|
||||
|
||||
sockaddrfree(&e->address);
|
||||
|
||||
free(e);
|
||||
}
|
||||
|
||||
void edge_add(edge_t *e) {
|
||||
cp();
|
||||
|
||||
splay_insert(edge_weight_tree, e);
|
||||
splay_insert(e->from->edge_tree, e);
|
||||
|
||||
|
@ -105,8 +89,6 @@ void edge_add(edge_t *e) {
|
|||
}
|
||||
|
||||
void edge_del(edge_t *e) {
|
||||
cp();
|
||||
|
||||
if(e->reverse)
|
||||
e->reverse->reverse = NULL;
|
||||
|
||||
|
@ -117,8 +99,6 @@ void edge_del(edge_t *e) {
|
|||
edge_t *lookup_edge(node_t *from, node_t *to) {
|
||||
edge_t v;
|
||||
|
||||
cp();
|
||||
|
||||
v.from = from;
|
||||
v.to = to;
|
||||
|
||||
|
@ -131,15 +111,13 @@ int dump_edges(struct evbuffer *out) {
|
|||
edge_t *e;
|
||||
char *address;
|
||||
|
||||
cp();
|
||||
|
||||
for(node = node_tree->head; node; node = node->next) {
|
||||
n = node->data;
|
||||
for(node2 = n->edge_tree->head; node2; node2 = node2->next) {
|
||||
e = node2->data;
|
||||
address = sockaddr2hostname(&e->address);
|
||||
if(evbuffer_add_printf(out,
|
||||
_(" %s to %s at %s options %lx weight %d\n"),
|
||||
" %s to %s at %s options %lx weight %d\n",
|
||||
e->from->name, e->to->name, address,
|
||||
e->options, e->weight) == -1) {
|
||||
free(address);
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_EDGE_H__
|
||||
|
|
18
src/graph.c
18
src/graph.c
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
/* We need to generate two trees from the graph:
|
||||
|
@ -70,8 +68,6 @@ void mst_kruskal(void) {
|
|||
node_t *n;
|
||||
connection_t *c;
|
||||
|
||||
cp();
|
||||
|
||||
/* Clear MST status on connections */
|
||||
|
||||
for(node = connection_tree->head; node; node = node->next) {
|
||||
|
@ -123,8 +119,6 @@ void sssp_dijkstra(void) {
|
|||
list_node_t *lnode, *nnode;
|
||||
bool indirect;
|
||||
|
||||
cp();
|
||||
|
||||
todo_list = list_alloc(NULL);
|
||||
|
||||
ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Running Dijkstra's algorithm:");
|
||||
|
@ -249,8 +243,6 @@ void sssp_bfs(void) {
|
|||
list_node_t *from, *todonext;
|
||||
bool indirect;
|
||||
|
||||
cp();
|
||||
|
||||
todo_list = list_alloc(NULL);
|
||||
|
||||
/* Clear visited status on nodes */
|
||||
|
@ -344,10 +336,10 @@ void check_reachability() {
|
|||
n->status.reachable = !n->status.reachable;
|
||||
|
||||
if(n->status.reachable) {
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Node %s (%s) became reachable"),
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Node %s (%s) became reachable",
|
||||
n->name, n->hostname);
|
||||
} else {
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Node %s (%s) became unreachable"),
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Node %s (%s) became unreachable",
|
||||
n->name, n->hostname);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_GRAPH_H__
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -55,8 +53,6 @@ static int device_total_out = 0;
|
|||
bool setup_device(void) {
|
||||
struct ifreq ifr;
|
||||
|
||||
cp();
|
||||
|
||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
||||
device = xstrdup(DEFAULT_DEVICE);
|
||||
|
||||
|
@ -70,7 +66,7 @@ bool setup_device(void) {
|
|||
device_fd = open(device, O_RDWR | O_NONBLOCK);
|
||||
|
||||
if(device_fd < 0) {
|
||||
logger(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
|
||||
logger(LOG_ERR, "Could not open %s: %s", device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -81,11 +77,11 @@ bool setup_device(void) {
|
|||
if(routing_mode == RMODE_ROUTER) {
|
||||
ifr.ifr_flags = IFF_TUN;
|
||||
device_type = DEVICE_TYPE_TUN;
|
||||
device_info = _("Linux tun/tap device (tun mode)");
|
||||
device_info = "Linux tun/tap device (tun mode)";
|
||||
} else {
|
||||
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
|
||||
device_type = DEVICE_TYPE_TAP;
|
||||
device_info = _("Linux tun/tap device (tap mode)");
|
||||
device_info = "Linux tun/tap device (tap mode)";
|
||||
}
|
||||
|
||||
if(iface)
|
||||
|
@ -96,7 +92,7 @@ bool setup_device(void) {
|
|||
if(iface) free(iface);
|
||||
iface = xstrdup(ifrname);
|
||||
} else if(!ioctl(device_fd, (('T' << 8) | 202), &ifr)) {
|
||||
logger(LOG_WARNING, _("Old ioctl() request was needed for %s"), device);
|
||||
logger(LOG_WARNING, "Old ioctl() request was needed for %s", device);
|
||||
strncpy(ifrname, ifr.ifr_name, IFNAMSIZ);
|
||||
if(iface) free(iface);
|
||||
iface = xstrdup(ifrname);
|
||||
|
@ -105,21 +101,19 @@ bool setup_device(void) {
|
|||
{
|
||||
if(routing_mode == RMODE_ROUTER)
|
||||
overwrite_mac = true;
|
||||
device_info = _("Linux ethertap device");
|
||||
device_info = "Linux ethertap device";
|
||||
device_type = DEVICE_TYPE_ETHERTAP;
|
||||
if(iface)
|
||||
free(iface);
|
||||
iface = xstrdup(rindex(device, '/') ? rindex(device, '/') + 1 : device);
|
||||
}
|
||||
|
||||
logger(LOG_INFO, _("%s is a %s"), device, device_info);
|
||||
logger(LOG_INFO, "%s is a %s", device, device_info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void close_device(void) {
|
||||
cp();
|
||||
|
||||
close(device_fd);
|
||||
|
||||
free(device);
|
||||
|
@ -129,14 +123,12 @@ void close_device(void) {
|
|||
bool read_packet(vpn_packet_t *packet) {
|
||||
int inlen;
|
||||
|
||||
cp();
|
||||
|
||||
switch(device_type) {
|
||||
case DEVICE_TYPE_TUN:
|
||||
inlen = read(device_fd, packet->data + 10, MTU - 10);
|
||||
|
||||
if(inlen <= 0) {
|
||||
logger(LOG_ERR, _("Error while reading from %s %s: %s"),
|
||||
logger(LOG_ERR, "Error while reading from %s %s: %s",
|
||||
device_info, device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -147,7 +139,7 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
inlen = read(device_fd, packet->data, MTU);
|
||||
|
||||
if(inlen <= 0) {
|
||||
logger(LOG_ERR, _("Error while reading from %s %s: %s"),
|
||||
logger(LOG_ERR, "Error while reading from %s %s: %s",
|
||||
device_info, device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -158,7 +150,7 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
inlen = read(device_fd, packet->data - 2, MTU + 2);
|
||||
|
||||
if(inlen <= 0) {
|
||||
logger(LOG_ERR, _("Error while reading from %s %s: %s"),
|
||||
logger(LOG_ERR, "Error while reading from %s %s: %s",
|
||||
device_info, device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -169,30 +161,28 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
|
||||
device_total_in += packet->len;
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Read packet of %d bytes from %s", packet->len,
|
||||
device_info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool write_packet(vpn_packet_t *packet) {
|
||||
cp();
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Writing packet of %d bytes to %s",
|
||||
packet->len, device_info);
|
||||
|
||||
switch(device_type) {
|
||||
case DEVICE_TYPE_TUN:
|
||||
packet->data[10] = packet->data[11] = 0;
|
||||
if(write(device_fd, packet->data + 10, packet->len - 10) < 0) {
|
||||
logger(LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
|
||||
logger(LOG_ERR, "Can't write to %s %s: %s", device_info, device,
|
||||
strerror(errno));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case DEVICE_TYPE_TAP:
|
||||
if(write(device_fd, packet->data, packet->len) < 0) {
|
||||
logger(LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
|
||||
logger(LOG_ERR, "Can't write to %s %s: %s", device_info, device,
|
||||
strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -201,7 +191,7 @@ bool write_packet(vpn_packet_t *packet) {
|
|||
*(short int *)(packet->data - 2) = packet->len;
|
||||
|
||||
if(write(device_fd, packet->data - 2, packet->len + 2) < 0) {
|
||||
logger(LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
|
||||
logger(LOG_ERR, "Can't write to %s %s: %s", device_info, device,
|
||||
strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -214,9 +204,7 @@ bool write_packet(vpn_packet_t *packet) {
|
|||
}
|
||||
|
||||
void dump_device_stats(void) {
|
||||
cp();
|
||||
|
||||
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
|
||||
logger(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
|
||||
logger(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
|
||||
logger(LOG_DEBUG, "Statistics for %s %s:", device_info, device);
|
||||
logger(LOG_DEBUG, " total bytes in: %10d", device_total_in);
|
||||
logger(LOG_DEBUG, " total bytes out: %10d", device_total_out);
|
||||
}
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
|
37
src/meta.c
37
src/meta.c
|
@ -1,7 +1,8 @@
|
|||
/*
|
||||
meta.c -- handle the meta communication
|
||||
Copyright (C) 2000-2006 Guus Sliepen <guus@tinc-vpn.org>,
|
||||
Copyright (C) 2000-2009 Guus Sliepen <guus@tinc-vpn.org>,
|
||||
2000-2005 Ivo Timmermans
|
||||
2006 Scott Lamb <slamb@slamb.org>
|
||||
|
||||
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
|
||||
|
@ -13,11 +14,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -33,14 +32,12 @@
|
|||
#include "xalloc.h"
|
||||
|
||||
bool send_meta(connection_t *c, const char *buffer, int length) {
|
||||
cp();
|
||||
|
||||
if(!c) {
|
||||
logger(LOG_ERR, _("send_meta() called with NULL pointer!"));
|
||||
logger(LOG_ERR, "send_meta() called with NULL pointer!");
|
||||
abort();
|
||||
}
|
||||
|
||||
ifdebug(META) logger(LOG_DEBUG, _("Sending %d bytes of metadata to %s (%s)"), length,
|
||||
ifdebug(META) logger(LOG_DEBUG, "Sending %d bytes of metadata to %s (%s)", length,
|
||||
c->name, c->hostname);
|
||||
|
||||
/* Add our data to buffer */
|
||||
|
@ -49,18 +46,18 @@ bool send_meta(connection_t *c, const char *buffer, int length) {
|
|||
size_t outlen = length;
|
||||
|
||||
if(!cipher_encrypt(&c->outcipher, buffer, length, outbuf, &outlen, false) || outlen != length) {
|
||||
logger(LOG_ERR, _("Error while encrypting metadata to %s (%s)"),
|
||||
logger(LOG_ERR, "Error while encrypting metadata to %s (%s)",
|
||||
c->name, c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
ifdebug(META) logger(LOG_DEBUG, _("Encrypted write %p %p %p %d"), c, c->buffer, outbuf, length);
|
||||
ifdebug(META) logger(LOG_DEBUG, "Encrypted write %p %p %p %d", c, c->buffer, outbuf, length);
|
||||
bufferevent_write(c->buffer, (void *)outbuf, length);
|
||||
ifdebug(META) logger(LOG_DEBUG, _("Done."));
|
||||
ifdebug(META) logger(LOG_DEBUG, "Done.");
|
||||
} else {
|
||||
ifdebug(META) logger(LOG_DEBUG, _("Unencrypted write %p %p %p %d"), c, c->buffer, buffer, length);
|
||||
ifdebug(META) logger(LOG_DEBUG, "Unencrypted write %p %p %p %d", c, c->buffer, buffer, length);
|
||||
bufferevent_write(c->buffer, (void *)buffer, length);
|
||||
ifdebug(META) logger(LOG_DEBUG, _("Done."));
|
||||
ifdebug(META) logger(LOG_DEBUG, "Done.");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -70,8 +67,6 @@ void broadcast_meta(connection_t *from, const char *buffer, int length) {
|
|||
splay_node_t *node;
|
||||
connection_t *c;
|
||||
|
||||
cp();
|
||||
|
||||
for(node = connection_tree->head; node; node = node->next) {
|
||||
c = node->data;
|
||||
|
||||
|
@ -85,8 +80,6 @@ bool receive_meta(connection_t *c) {
|
|||
char inbuf[MAXBUFSIZE];
|
||||
char *bufp = inbuf, *endp;
|
||||
|
||||
cp();
|
||||
|
||||
/* Strategy:
|
||||
- Read as much as possible from the TCP socket in one go.
|
||||
- Decrypt it.
|
||||
|
@ -99,7 +92,7 @@ bool receive_meta(connection_t *c) {
|
|||
inlen = recv(c->socket, inbuf, sizeof inbuf, 0);
|
||||
|
||||
if(inlen <= 0) {
|
||||
logger(LOG_ERR, _("Receive callback called for %s (%s) but no data to receive: %s"), c->name, c->hostname, strerror(errno));
|
||||
logger(LOG_ERR, "Receive callback called for %s (%s) but no data to receive: %s", c->name, c->hostname, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -117,11 +110,11 @@ bool receive_meta(connection_t *c) {
|
|||
bufp = endp;
|
||||
} else {
|
||||
size_t outlen = inlen;
|
||||
ifdebug(META) logger(LOG_DEBUG, _("Received encrypted %zu bytes"), inlen);
|
||||
ifdebug(META) logger(LOG_DEBUG, "Received encrypted %zu bytes", inlen);
|
||||
evbuffer_expand(c->buffer->input, c->buffer->input->off + inlen);
|
||||
|
||||
if(!cipher_decrypt(&c->incipher, bufp, inlen, c->buffer->input->buffer + c->buffer->input->off, &outlen, false) || inlen != outlen) {
|
||||
logger(LOG_ERR, _("Error while decrypting metadata from %s (%s)"),
|
||||
logger(LOG_ERR, "Error while decrypting metadata from %s (%s)",
|
||||
c->name, c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_META_H__
|
||||
|
|
|
@ -21,10 +21,9 @@
|
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program (see the file COPYING included with this
|
||||
* distribution); if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
//===============================================
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -51,7 +49,7 @@ static DWORD WINAPI tapreader(void *bla) {
|
|||
OVERLAPPED overlapped;
|
||||
vpn_packet_t packet;
|
||||
|
||||
logger(LOG_DEBUG, _("Tap reader running"));
|
||||
logger(LOG_DEBUG, "Tap reader running");
|
||||
|
||||
/* Read from tap device and send to parent */
|
||||
|
||||
|
@ -70,7 +68,7 @@ static DWORD WINAPI tapreader(void *bla) {
|
|||
if(!GetOverlappedResult(device_handle, &overlapped, &len, FALSE))
|
||||
continue;
|
||||
} else {
|
||||
logger(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Error while reading from %s %s: %s", device_info,
|
||||
device, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
@ -108,15 +106,13 @@ bool setup_device(void) {
|
|||
.ai_flags = 0,
|
||||
};
|
||||
|
||||
cp();
|
||||
|
||||
get_config_string(lookup_config(config_tree, "Device"), &device);
|
||||
get_config_string(lookup_config(config_tree, "Interface"), &iface);
|
||||
|
||||
/* Open registry and look for network adapters */
|
||||
|
||||
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, NETWORK_CONNECTIONS_KEY, 0, KEY_READ, &key)) {
|
||||
logger(LOG_ERR, _("Unable to read registry: %s"), winerror(GetLastError()));
|
||||
logger(LOG_ERR, "Unable to read registry: %s", winerror(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -167,7 +163,7 @@ bool setup_device(void) {
|
|||
RegCloseKey(key);
|
||||
|
||||
if(!found) {
|
||||
logger(LOG_ERR, _("No Windows tap device found!"));
|
||||
logger(LOG_ERR, "No Windows tap device found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -185,14 +181,14 @@ bool setup_device(void) {
|
|||
}
|
||||
|
||||
if(device_handle == INVALID_HANDLE_VALUE) {
|
||||
logger(LOG_ERR, _("%s (%s) is not a usable Windows tap device: %s"), device, iface, winerror(GetLastError()));
|
||||
logger(LOG_ERR, "%s (%s) is not a usable Windows tap device: %s", device, iface, winerror(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Get MAC address from tap device */
|
||||
|
||||
if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof mymac.x, mymac.x, sizeof mymac.x, &len, 0)) {
|
||||
logger(LOG_ERR, _("Could not get MAC address from Windows tap device %s (%s): %s"), device, iface, winerror(GetLastError()));
|
||||
logger(LOG_ERR, "Could not get MAC address from Windows tap device %s (%s): %s", device, iface, winerror(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -205,7 +201,7 @@ bool setup_device(void) {
|
|||
thread = CreateThread(NULL, 0, tapreader, NULL, 0, NULL);
|
||||
|
||||
if(!thread) {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "CreateThread", winerror(GetLastError()));
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "CreateThread", winerror(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -214,16 +210,14 @@ bool setup_device(void) {
|
|||
status = true;
|
||||
DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof status, &status, sizeof status, &len, NULL);
|
||||
|
||||
device_info = _("Windows tap device");
|
||||
device_info = "Windows tap device";
|
||||
|
||||
logger(LOG_INFO, _("%s (%s) is a %s"), device, iface, device_info);
|
||||
logger(LOG_INFO, "%s (%s) is a %s", device, iface, device_info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void close_device(void) {
|
||||
cp();
|
||||
|
||||
CloseHandle(device_handle);
|
||||
|
||||
free(device);
|
||||
|
@ -238,13 +232,11 @@ bool write_packet(vpn_packet_t *packet) {
|
|||
long outlen;
|
||||
OVERLAPPED overlapped = {0};
|
||||
|
||||
cp();
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Writing packet of %d bytes to %s",
|
||||
packet->len, device_info);
|
||||
|
||||
if(!WriteFile(device_handle, packet->data, packet->len, &outlen, &overlapped)) {
|
||||
logger(LOG_ERR, _("Error while writing to %s %s: %s"), device_info, device, winerror(GetLastError()));
|
||||
logger(LOG_ERR, "Error while writing to %s %s: %s", device_info, device, winerror(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -254,9 +246,7 @@ bool write_packet(vpn_packet_t *packet) {
|
|||
}
|
||||
|
||||
void dump_device_stats(void) {
|
||||
cp();
|
||||
|
||||
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
|
||||
logger(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
|
||||
logger(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
|
||||
logger(LOG_DEBUG, "Statistics for %s %s:", device_info, device);
|
||||
logger(LOG_DEBUG, " total bytes in: %10d", device_total_in);
|
||||
logger(LOG_DEBUG, " total bytes out: %10d", device_total_out);
|
||||
}
|
||||
|
|
39
src/net.c
39
src/net.c
|
@ -2,6 +2,7 @@
|
|||
net.c -- most of the network code
|
||||
Copyright (C) 1998-2005 Ivo Timmermans,
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2006 Scott Lamb <slamb@slamb.org>
|
||||
|
||||
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
|
||||
|
@ -13,11 +14,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -47,9 +46,7 @@ void purge(void) {
|
|||
edge_t *e;
|
||||
subnet_t *s;
|
||||
|
||||
cp();
|
||||
|
||||
ifdebug(PROTOCOL) logger(LOG_DEBUG, _("Purging unreachable nodes"));
|
||||
ifdebug(PROTOCOL) logger(LOG_DEBUG, "Purging unreachable nodes");
|
||||
|
||||
/* Remove all edges and subnets owned by unreachable nodes. */
|
||||
|
||||
|
@ -58,7 +55,7 @@ void purge(void) {
|
|||
n = nnode->data;
|
||||
|
||||
if(!n->status.reachable) {
|
||||
ifdebug(SCARY_THINGS) logger(LOG_DEBUG, _("Purging node %s (%s)"), n->name,
|
||||
ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Purging node %s (%s)", n->name,
|
||||
n->hostname);
|
||||
|
||||
for(snode = n->subnet_tree->head; snode; snode = snext) {
|
||||
|
@ -108,9 +105,7 @@ void purge(void) {
|
|||
- Deactivate the host
|
||||
*/
|
||||
void terminate_connection(connection_t *c, bool report) {
|
||||
cp();
|
||||
|
||||
ifdebug(CONNECTIONS) logger(LOG_NOTICE, _("Closing connection with %s (%s)"),
|
||||
ifdebug(CONNECTIONS) logger(LOG_NOTICE, "Closing connection with %s (%s)",
|
||||
c->name, c->hostname);
|
||||
|
||||
c->status.active = false;
|
||||
|
@ -165,8 +160,6 @@ static void timeout_handler(int fd, short events, void *event) {
|
|||
connection_t *c;
|
||||
time_t now = time(NULL);
|
||||
|
||||
cp();
|
||||
|
||||
for(node = connection_tree->head; node; node = next) {
|
||||
next = node->next;
|
||||
c = node->data;
|
||||
|
@ -174,7 +167,7 @@ static void timeout_handler(int fd, short events, void *event) {
|
|||
if(c->last_ping_time + pingtimeout < now) {
|
||||
if(c->status.active) {
|
||||
if(c->status.pinged) {
|
||||
ifdebug(CONNECTIONS) logger(LOG_INFO, _("%s (%s) didn't respond to PING in %ld seconds"),
|
||||
ifdebug(CONNECTIONS) logger(LOG_INFO, "%s (%s) didn't respond to PING in %ld seconds",
|
||||
c->name, c->hostname, now - c->last_ping_time);
|
||||
terminate_connection(c, true);
|
||||
continue;
|
||||
|
@ -184,12 +177,12 @@ static void timeout_handler(int fd, short events, void *event) {
|
|||
} else {
|
||||
if(c->status.connecting) {
|
||||
ifdebug(CONNECTIONS)
|
||||
logger(LOG_WARNING, _("Timeout while connecting to %s (%s)"), c->name, c->hostname);
|
||||
logger(LOG_WARNING, "Timeout while connecting to %s (%s)", c->name, c->hostname);
|
||||
c->status.connecting = false;
|
||||
closesocket(c->socket);
|
||||
do_outgoing_connection(c);
|
||||
} else {
|
||||
ifdebug(CONNECTIONS) logger(LOG_WARNING, _("Timeout from %s (%s) during authentication"), c->name, c->hostname);
|
||||
ifdebug(CONNECTIONS) logger(LOG_WARNING, "Timeout from %s (%s) during authentication", c->name, c->hostname);
|
||||
terminate_connection(c, false);
|
||||
continue;
|
||||
}
|
||||
|
@ -214,7 +207,7 @@ void handle_meta_connection_data(int fd, short events, void *data) {
|
|||
finish_connecting(c);
|
||||
else {
|
||||
ifdebug(CONNECTIONS) logger(LOG_DEBUG,
|
||||
_("Error while connecting to %s (%s): %s"),
|
||||
"Error while connecting to %s (%s): %s",
|
||||
c->name, c->hostname, strerror(result));
|
||||
closesocket(c->socket);
|
||||
do_outgoing_connection(c);
|
||||
|
@ -229,12 +222,12 @@ void handle_meta_connection_data(int fd, short events, void *data) {
|
|||
}
|
||||
|
||||
static void sigterm_handler(int signal, short events, void *data) {
|
||||
logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
|
||||
logger(LOG_NOTICE, "Got %s signal", strsignal(signal));
|
||||
event_loopexit(NULL);
|
||||
}
|
||||
|
||||
static void sighup_handler(int signal, short events, void *data) {
|
||||
logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
|
||||
logger(LOG_NOTICE, "Got %s signal", strsignal(signal));
|
||||
reload_configuration();
|
||||
}
|
||||
|
||||
|
@ -251,7 +244,7 @@ int reload_configuration(void) {
|
|||
init_configuration(&config_tree);
|
||||
|
||||
if(!read_server_config()) {
|
||||
logger(LOG_ERR, _("Unable to reread configuration file, exitting."));
|
||||
logger(LOG_ERR, "Unable to reread configuration file, exitting.");
|
||||
event_loopexit(NULL);
|
||||
return EINVAL;
|
||||
}
|
||||
|
@ -312,8 +305,6 @@ int main_loop(void) {
|
|||
struct event sigterm_event;
|
||||
struct event sigquit_event;
|
||||
|
||||
cp();
|
||||
|
||||
timeout_set(&timeout_event, timeout_handler, &timeout_event);
|
||||
event_add(&timeout_event, &(struct timeval){pingtimeout, 0});
|
||||
signal_set(&sighup_event, SIGHUP, sighup_handler, NULL);
|
||||
|
@ -324,7 +315,7 @@ int main_loop(void) {
|
|||
signal_add(&sigquit_event, NULL);
|
||||
|
||||
if(event_loop(0) < 0) {
|
||||
logger(LOG_ERR, _("Error while waiting for input: %s"), strerror(errno));
|
||||
logger(LOG_ERR, "Error while waiting for input: %s", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
10
src/net.h
10
src/net.h
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
net.h -- header for net.c
|
||||
Copyright (C) 1998-2005 Ivo Timmermans <zarq@iname.com>
|
||||
Copyright (C) 1998-2005 Ivo Timmermans
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_NET_H__
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -61,24 +59,22 @@ static void send_mtu_probe_handler(int fd, short events, void *data) {
|
|||
vpn_packet_t packet;
|
||||
int len, i;
|
||||
|
||||
cp();
|
||||
|
||||
n->mtuprobes++;
|
||||
|
||||
if(!n->status.reachable) {
|
||||
logger(LOG_DEBUG, _("Trying to send MTU probe to unreachable node %s (%s)"), n->name, n->hostname);
|
||||
logger(LOG_DEBUG, "Trying to send MTU probe to unreachable node %s (%s)", n->name, n->hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
if(n->mtuprobes >= 10 && !n->minmtu) {
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, _("No response to MTU probes from %s (%s)"), n->name, n->hostname);
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, "No response to MTU probes from %s (%s)", n->name, n->hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
for(i = 0; i < 3; i++) {
|
||||
if(n->mtuprobes >= 30 || n->minmtu >= n->maxmtu) {
|
||||
n->mtu = n->minmtu;
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, _("Fixing MTU of %s (%s) to %d after %d probes"), n->name, n->hostname, n->mtu, n->mtuprobes);
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, "Fixing MTU of %s (%s) to %d after %d probes", n->name, n->hostname, n->mtu, n->mtuprobes);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -91,7 +87,7 @@ static void send_mtu_probe_handler(int fd, short events, void *data) {
|
|||
packet.len = len;
|
||||
packet.priority = 0;
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, _("Sending MTU probe length %d to %s (%s)"), len, n->name, n->hostname);
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, "Sending MTU probe length %d to %s (%s)", len, n->name, n->hostname);
|
||||
|
||||
send_udppacket(n, &packet);
|
||||
}
|
||||
|
@ -106,7 +102,7 @@ void send_mtu_probe(node_t *n) {
|
|||
}
|
||||
|
||||
void mtu_probe_h(node_t *n, vpn_packet_t *packet, length_t len) {
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, _("Got MTU probe length %d from %s (%s)"), packet->len, n->name, n->hostname);
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, "Got MTU probe length %d from %s (%s)", packet->len, n->name, n->hostname);
|
||||
|
||||
if(!packet->data[0]) {
|
||||
packet->data[0] = 1;
|
||||
|
@ -158,24 +154,20 @@ static length_t uncompress_packet(uint8_t *dest, const uint8_t *source, length_t
|
|||
/* VPN packet I/O */
|
||||
|
||||
static void receive_packet(node_t *n, vpn_packet_t *packet) {
|
||||
cp();
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Received packet of %d bytes from %s (%s)"),
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Received packet of %d bytes from %s (%s)",
|
||||
packet->len, n->name, n->hostname);
|
||||
|
||||
route(n, packet);
|
||||
}
|
||||
|
||||
static bool try_mac(node_t *n, const vpn_packet_t *inpkt)
|
||||
{
|
||||
static bool try_mac(node_t *n, const vpn_packet_t *inpkt) {
|
||||
if(!digest_active(&n->indigest) || inpkt->len < sizeof inpkt->seqno + digest_length(&n->indigest))
|
||||
return false;
|
||||
|
||||
return digest_verify(&n->indigest, &inpkt->seqno, inpkt->len, (const char *)&inpkt->seqno + inpkt->len);
|
||||
}
|
||||
|
||||
static void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
|
||||
{
|
||||
static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
|
||||
vpn_packet_t pkt1, pkt2;
|
||||
vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 };
|
||||
int nextpkt = 0;
|
||||
|
@ -183,10 +175,8 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
|
|||
size_t outlen;
|
||||
int i;
|
||||
|
||||
cp();
|
||||
|
||||
if(!cipher_active(&n->incipher)) {
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Got packet from %s (%s) but he hasn't got our key yet"),
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Got packet from %s (%s) but he hasn't got our key yet",
|
||||
n->name, n->hostname);
|
||||
return;
|
||||
}
|
||||
|
@ -194,7 +184,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
|
|||
/* Check packet length */
|
||||
|
||||
if(inpkt->len < sizeof inpkt->seqno + digest_length(&n->indigest)) {
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Got too short packet from %s (%s)"),
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Got too short packet from %s (%s)",
|
||||
n->name, n->hostname);
|
||||
return;
|
||||
}
|
||||
|
@ -202,7 +192,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
|
|||
/* Check the message authentication code */
|
||||
|
||||
if(digest_active(&n->indigest) && !digest_verify(&n->indigest, &inpkt->seqno, inpkt->len, (const char *)&inpkt->seqno + inpkt->len)) {
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Got unauthenticated packet from %s (%s)"), n->name, n->hostname);
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Got unauthenticated packet from %s (%s)", n->name, n->hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -213,7 +203,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
|
|||
outlen = MAXSIZE;
|
||||
|
||||
if(!cipher_decrypt(&n->incipher, &inpkt->seqno, inpkt->len, &outpkt->seqno, &outlen, true)) {
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Error decrypting packet from %s (%s)"), n->name, n->hostname);
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Error decrypting packet from %s (%s)", n->name, n->hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -228,13 +218,13 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
|
|||
|
||||
if(inpkt->seqno != n->received_seqno + 1) {
|
||||
if(inpkt->seqno >= n->received_seqno + sizeof n->late * 8) {
|
||||
logger(LOG_WARNING, _("Lost %d packets from %s (%s)"),
|
||||
logger(LOG_WARNING, "Lost %d packets from %s (%s)",
|
||||
inpkt->seqno - n->received_seqno - 1, n->name, n->hostname);
|
||||
|
||||
memset(n->late, 0, sizeof n->late);
|
||||
} else if (inpkt->seqno <= n->received_seqno) {
|
||||
if((n->received_seqno >= sizeof n->late * 8 && inpkt->seqno <= n->received_seqno - sizeof n->late * 8) || !(n->late[(inpkt->seqno / 8) % sizeof n->late] & (1 << inpkt->seqno % 8))) {
|
||||
logger(LOG_WARNING, _("Got late or replayed packet from %s (%s), seqno %d, last received %d"),
|
||||
logger(LOG_WARNING, "Got late or replayed packet from %s (%s), seqno %d, last received %d",
|
||||
n->name, n->hostname, inpkt->seqno, n->received_seqno);
|
||||
return;
|
||||
}
|
||||
|
@ -260,7 +250,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
|
|||
outpkt = pkt[nextpkt++];
|
||||
|
||||
if((outpkt->len = uncompress_packet(outpkt->data, inpkt->data, inpkt->len, n->incompression)) < 0) {
|
||||
ifdebug(TRAFFIC) logger(LOG_ERR, _("Error while uncompressing packet from %s (%s)"),
|
||||
ifdebug(TRAFFIC) logger(LOG_ERR, "Error while uncompressing packet from %s (%s)",
|
||||
n->name, n->hostname);
|
||||
return;
|
||||
}
|
||||
|
@ -281,8 +271,6 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
|
|||
void receive_tcppacket(connection_t *c, char *buffer, int len) {
|
||||
vpn_packet_t outpkt;
|
||||
|
||||
cp();
|
||||
|
||||
outpkt.len = len;
|
||||
if(c->options & OPTION_TCPONLY)
|
||||
outpkt.priority = 0;
|
||||
|
@ -305,10 +293,8 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
|
|||
int origpriority;
|
||||
int sock;
|
||||
|
||||
cp();
|
||||
|
||||
if(!n->status.reachable) {
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, _("Trying to send UDP packet to unreachable node %s (%s)"), n->name, n->hostname);
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, "Trying to send UDP packet to unreachable node %s (%s)", n->name, n->hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -316,7 +302,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
|
|||
|
||||
if(!n->status.validkey) {
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO,
|
||||
_("No valid key known yet for %s (%s), forwarding via TCP"),
|
||||
"No valid key known yet for %s (%s), forwarding via TCP",
|
||||
n->name, n->hostname);
|
||||
|
||||
if(!n->status.waitingforkey)
|
||||
|
@ -331,7 +317,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
|
|||
|
||||
if(n->options & OPTION_PMTU_DISCOVERY && inpkt->len > n->minmtu && (inpkt->data[12] | inpkt->data[13])) {
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO,
|
||||
_("Packet for %s (%s) larger than minimum MTU, forwarding via TCP"),
|
||||
"Packet for %s (%s) larger than minimum MTU, forwarding via TCP",
|
||||
n->name, n->hostname);
|
||||
|
||||
send_tcppacket(n->nexthop->connection, origpkt);
|
||||
|
@ -348,7 +334,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
|
|||
outpkt = pkt[nextpkt++];
|
||||
|
||||
if((outpkt->len = compress_packet(outpkt->data, inpkt->data, inpkt->len, n->outcompression)) < 0) {
|
||||
ifdebug(TRAFFIC) logger(LOG_ERR, _("Error while compressing packet to %s (%s)"),
|
||||
ifdebug(TRAFFIC) logger(LOG_ERR, "Error while compressing packet to %s (%s)",
|
||||
n->name, n->hostname);
|
||||
return;
|
||||
}
|
||||
|
@ -368,7 +354,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
|
|||
outlen = MAXSIZE;
|
||||
|
||||
if(!cipher_encrypt(&n->outcipher, &inpkt->seqno, inpkt->len, &outpkt->seqno, &outlen, true)) {
|
||||
ifdebug(TRAFFIC) logger(LOG_ERR, _("Error while encrypting packet to %s (%s)"), n->name, n->hostname);
|
||||
ifdebug(TRAFFIC) logger(LOG_ERR, "Error while encrypting packet to %s (%s)", n->name, n->hostname);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -398,9 +384,9 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
|
|||
if(priorityinheritance && origpriority != priority
|
||||
&& listen_socket[sock].sa.sa.sa_family == AF_INET) {
|
||||
priority = origpriority;
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Setting outgoing packet priority to %d"), priority);
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Setting outgoing packet priority to %d", priority);
|
||||
if(setsockopt(listen_socket[sock].udp, SOL_IP, IP_TOS, &priority, sizeof priority)) /* SO_PRIORITY doesn't seem to work */
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "setsockopt", strerror(errno));
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "setsockopt", strerror(errno));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -411,7 +397,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
|
|||
if(n->mtu >= origlen)
|
||||
n->mtu = origlen - 1;
|
||||
} else
|
||||
logger(LOG_ERR, _("Error sending packet to %s (%s): %s"), n->name, n->hostname, strerror(errno));
|
||||
logger(LOG_ERR, "Error sending packet to %s (%s): %s", n->name, n->hostname, strerror(errno));
|
||||
}
|
||||
|
||||
end:
|
||||
|
@ -424,8 +410,6 @@ end:
|
|||
void send_packet(const node_t *n, vpn_packet_t *packet) {
|
||||
node_t *via;
|
||||
|
||||
cp();
|
||||
|
||||
if(n == myself) {
|
||||
if(overwrite_mac)
|
||||
memcpy(packet->data, mymac.x, ETH_ALEN);
|
||||
|
@ -433,11 +417,11 @@ void send_packet(const node_t *n, vpn_packet_t *packet) {
|
|||
return;
|
||||
}
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_ERR, _("Sending packet of %d bytes to %s (%s)"),
|
||||
ifdebug(TRAFFIC) logger(LOG_ERR, "Sending packet of %d bytes to %s (%s)",
|
||||
packet->len, n->name, n->hostname);
|
||||
|
||||
if(!n->status.reachable) {
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, _("Node %s (%s) is not reachable"),
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, "Node %s (%s) is not reachable",
|
||||
n->name, n->hostname);
|
||||
return;
|
||||
}
|
||||
|
@ -445,7 +429,7 @@ void send_packet(const node_t *n, vpn_packet_t *packet) {
|
|||
via = (packet->priority == -1 || n->via == myself) ? n->nexthop : n->via;
|
||||
|
||||
if(via != n)
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, _("Sending packet to %s via %s (%s)"),
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, "Sending packet to %s via %s (%s)",
|
||||
n->name, via->name, n->via->hostname);
|
||||
|
||||
if(packet->priority == -1 || ((myself->options | via->options) & OPTION_TCPONLY)) {
|
||||
|
@ -461,9 +445,7 @@ void broadcast_packet(const node_t *from, vpn_packet_t *packet) {
|
|||
splay_node_t *node;
|
||||
connection_t *c;
|
||||
|
||||
cp();
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, _("Broadcasting packet of %d bytes from %s (%s)"),
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, "Broadcasting packet of %d bytes from %s (%s)",
|
||||
packet->len, from->name, from->hostname);
|
||||
|
||||
if(from != myself) {
|
||||
|
@ -507,21 +489,18 @@ static node_t *try_harder(const sockaddr_t *from, const vpn_packet_t *pkt) {
|
|||
return n;
|
||||
}
|
||||
|
||||
void handle_incoming_vpn_data(int sock, short events, void *data)
|
||||
{
|
||||
void handle_incoming_vpn_data(int sock, short events, void *data) {
|
||||
vpn_packet_t pkt;
|
||||
char *hostname;
|
||||
sockaddr_t from;
|
||||
socklen_t fromlen = sizeof from;
|
||||
node_t *n;
|
||||
|
||||
cp();
|
||||
|
||||
pkt.len = recvfrom(sock, (char *) &pkt.seqno, MAXSIZE, 0, &from.sa, &fromlen);
|
||||
|
||||
if(pkt.len < 0) {
|
||||
if(errno != EAGAIN && errno != EINTR)
|
||||
logger(LOG_ERR, _("Receiving packet failed: %s"), strerror(errno));
|
||||
logger(LOG_ERR, "Receiving packet failed: %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -535,7 +514,7 @@ void handle_incoming_vpn_data(int sock, short events, void *data)
|
|||
update_node_udp(n, &from);
|
||||
else ifdebug(PROTOCOL) {
|
||||
hostname = sockaddr2hostname(&from);
|
||||
logger(LOG_WARNING, _("Received UDP packet from unknown source %s"), hostname);
|
||||
logger(LOG_WARNING, "Received UDP packet from unknown source %s", hostname);
|
||||
free(hostname);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
net_setup.c -- Setup.
|
||||
Copyright (C) 1998-2005 Ivo Timmermans,
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2006 Scott Lamb <slamb@slamb.org>
|
||||
|
||||
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
|
||||
|
@ -13,11 +14,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -50,8 +49,6 @@ bool read_rsa_public_key(connection_t *c) {
|
|||
char *n;
|
||||
bool result;
|
||||
|
||||
cp();
|
||||
|
||||
/* First, check for simple PublicKey statement */
|
||||
|
||||
if(get_config_string(lookup_config(c->config_tree, "PublicKey"), &n)) {
|
||||
|
@ -68,7 +65,7 @@ bool read_rsa_public_key(connection_t *c) {
|
|||
fp = fopen(fname, "r");
|
||||
|
||||
if(!fp) {
|
||||
logger(LOG_ERR, _("Error reading RSA public key file `%s': %s"),
|
||||
logger(LOG_ERR, "Error reading RSA public key file `%s': %s",
|
||||
fname, strerror(errno));
|
||||
free(fname);
|
||||
return false;
|
||||
|
@ -78,7 +75,7 @@ bool read_rsa_public_key(connection_t *c) {
|
|||
fclose(fp);
|
||||
|
||||
if(!result)
|
||||
logger(LOG_ERR, _("Reading RSA public key file `%s' failed: %s"), fname, strerror(errno));
|
||||
logger(LOG_ERR, "Reading RSA public key file `%s' failed: %s", fname, strerror(errno));
|
||||
free(fname);
|
||||
return result;
|
||||
}
|
||||
|
@ -89,13 +86,11 @@ bool read_rsa_private_key() {
|
|||
char *n, *d;
|
||||
bool result;
|
||||
|
||||
cp();
|
||||
|
||||
/* First, check for simple PrivateKey statement */
|
||||
|
||||
if(get_config_string(lookup_config(config_tree, "PrivateKey"), &d)) {
|
||||
if(!get_config_string(lookup_config(myself->connection->config_tree, "PublicKey"), &n)) {
|
||||
logger(LOG_ERR, _("PrivateKey used but no PublicKey found!"));
|
||||
logger(LOG_ERR, "PrivateKey used but no PublicKey found!");
|
||||
free(d);
|
||||
return false;
|
||||
}
|
||||
|
@ -113,7 +108,7 @@ bool read_rsa_private_key() {
|
|||
fp = fopen(fname, "r");
|
||||
|
||||
if(!fp) {
|
||||
logger(LOG_ERR, _("Error reading RSA private key file `%s': %s"),
|
||||
logger(LOG_ERR, "Error reading RSA private key file `%s': %s",
|
||||
fname, strerror(errno));
|
||||
free(fname);
|
||||
return false;
|
||||
|
@ -123,20 +118,20 @@ bool read_rsa_private_key() {
|
|||
struct stat s;
|
||||
|
||||
if(fstat(fileno(fp), &s)) {
|
||||
logger(LOG_ERR, _("Could not stat RSA private key file `%s': %s'"), fname, strerror(errno));
|
||||
logger(LOG_ERR, "Could not stat RSA private key file `%s': %s'", fname, strerror(errno));
|
||||
free(fname);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(s.st_mode & ~0100700)
|
||||
logger(LOG_WARNING, _("Warning: insecure file permissions for RSA private key file `%s'!"), fname);
|
||||
logger(LOG_WARNING, "Warning: insecure file permissions for RSA private key file `%s'!", fname);
|
||||
#endif
|
||||
|
||||
result = rsa_read_pem_private_key(&myself->connection->rsa, fp);
|
||||
fclose(fp);
|
||||
|
||||
if(!result)
|
||||
logger(LOG_ERR, _("Reading RSA private key file `%s' failed: %s"), fname, strerror(errno));
|
||||
logger(LOG_ERR, "Reading RSA private key file `%s' failed: %s", fname, strerror(errno));
|
||||
free(fname);
|
||||
return result;
|
||||
}
|
||||
|
@ -149,7 +144,7 @@ static void keyexpire_handler(int fd, short events, void *data) {
|
|||
|
||||
void regenerate_key() {
|
||||
if(timeout_initialized(&keyexpire_event)) {
|
||||
ifdebug(STATUS) logger(LOG_INFO, _("Expiring symmetric keys"));
|
||||
ifdebug(STATUS) logger(LOG_INFO, "Expiring symmetric keys");
|
||||
event_del(&keyexpire_event);
|
||||
send_key_changed(broadcast, myself);
|
||||
} else {
|
||||
|
@ -172,25 +167,23 @@ bool setup_myself(void) {
|
|||
bool choice;
|
||||
int i, err;
|
||||
|
||||
cp();
|
||||
|
||||
myself = new_node();
|
||||
myself->connection = new_connection();
|
||||
init_configuration(&myself->connection->config_tree);
|
||||
|
||||
xasprintf(&myself->hostname, _("MYSELF"));
|
||||
xasprintf(&myself->connection->hostname, _("MYSELF"));
|
||||
xasprintf(&myself->hostname, "MYSELF");
|
||||
xasprintf(&myself->connection->hostname, "MYSELF");
|
||||
|
||||
myself->connection->options = 0;
|
||||
myself->connection->protocol_version = PROT_CURRENT;
|
||||
|
||||
if(!get_config_string(lookup_config(config_tree, "Name"), &name)) { /* Not acceptable */
|
||||
logger(LOG_ERR, _("Name for tinc daemon required!"));
|
||||
logger(LOG_ERR, "Name for tinc daemon required!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!check_id(name)) {
|
||||
logger(LOG_ERR, _("Invalid name for myself!"));
|
||||
logger(LOG_ERR, "Invalid name for myself!");
|
||||
free(name);
|
||||
return false;
|
||||
}
|
||||
|
@ -199,7 +192,7 @@ bool setup_myself(void) {
|
|||
myself->connection->name = xstrdup(name);
|
||||
|
||||
if(!read_connection_config(myself->connection)) {
|
||||
logger(LOG_ERR, _("Cannot open host configuration file for myself!"));
|
||||
logger(LOG_ERR, "Cannot open host configuration file for myself!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -249,7 +242,7 @@ bool setup_myself(void) {
|
|||
else if(!strcasecmp(mode, "hub"))
|
||||
routing_mode = RMODE_HUB;
|
||||
else {
|
||||
logger(LOG_ERR, _("Invalid routing mode!"));
|
||||
logger(LOG_ERR, "Invalid routing mode!");
|
||||
return false;
|
||||
}
|
||||
free(mode);
|
||||
|
@ -267,7 +260,7 @@ bool setup_myself(void) {
|
|||
|
||||
#if !defined(SOL_IP) || !defined(IP_TOS)
|
||||
if(priorityinheritance)
|
||||
logger(LOG_WARNING, _("%s not supported on this platform"), "PriorityInheritance");
|
||||
logger(LOG_WARNING, "%s not supported on this platform", "PriorityInheritance");
|
||||
#endif
|
||||
|
||||
if(!get_config_int(lookup_config(config_tree, "MACExpire"), &macexpire))
|
||||
|
@ -275,7 +268,7 @@ bool setup_myself(void) {
|
|||
|
||||
if(get_config_int(lookup_config(config_tree, "MaxTimeout"), &maxtimeout)) {
|
||||
if(maxtimeout <= 0) {
|
||||
logger(LOG_ERR, _("Bogus maximum timeout!"));
|
||||
logger(LOG_ERR, "Bogus maximum timeout!");
|
||||
return false;
|
||||
}
|
||||
} else
|
||||
|
@ -289,7 +282,7 @@ bool setup_myself(void) {
|
|||
else if(!strcasecmp(afname, "any"))
|
||||
addressfamily = AF_UNSPEC;
|
||||
else {
|
||||
logger(LOG_ERR, _("Invalid address family!"));
|
||||
logger(LOG_ERR, "Invalid address family!");
|
||||
return false;
|
||||
}
|
||||
free(afname);
|
||||
|
@ -303,7 +296,7 @@ bool setup_myself(void) {
|
|||
cipher = xstrdup("aes256");
|
||||
|
||||
if(!cipher_open_by_name(&myself->incipher, cipher)) {
|
||||
logger(LOG_ERR, _("Unrecognized cipher type!"));
|
||||
logger(LOG_ERR, "Unrecognized cipher type!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -321,12 +314,12 @@ bool setup_myself(void) {
|
|||
get_config_int(lookup_config(myself->connection->config_tree, "MACLength"), &maclength);
|
||||
|
||||
if(maclength < 0) {
|
||||
logger(LOG_ERR, _("Bogus MAC length!"));
|
||||
logger(LOG_ERR, "Bogus MAC length!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!digest_open_by_name(&myself->indigest, digest, maclength)) {
|
||||
logger(LOG_ERR, _("Unrecognized digest type!"));
|
||||
logger(LOG_ERR, "Unrecognized digest type!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -334,7 +327,7 @@ bool setup_myself(void) {
|
|||
|
||||
if(get_config_int(lookup_config(myself->connection->config_tree, "Compression"), &myself->incompression)) {
|
||||
if(myself->incompression < 0 || myself->incompression > 11) {
|
||||
logger(LOG_ERR, _("Bogus compression level!"));
|
||||
logger(LOG_ERR, "Bogus compression level!");
|
||||
return false;
|
||||
}
|
||||
} else
|
||||
|
@ -359,7 +352,7 @@ bool setup_myself(void) {
|
|||
event_set(&device_ev, device_fd, EV_READ|EV_PERSIST, handle_device_data, NULL);
|
||||
|
||||
if (event_add(&device_ev, NULL) < 0) {
|
||||
logger(LOG_ERR, _("event_add failed: %s"), strerror(errno));
|
||||
logger(LOG_ERR, "event_add failed: %s", strerror(errno));
|
||||
close_device();
|
||||
return false;
|
||||
}
|
||||
|
@ -392,7 +385,7 @@ bool setup_myself(void) {
|
|||
err = getaddrinfo(address, myport, &hint, &ai);
|
||||
|
||||
if(err || !ai) {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "getaddrinfo",
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "getaddrinfo",
|
||||
gai_strerror(err));
|
||||
return false;
|
||||
}
|
||||
|
@ -419,7 +412,7 @@ bool setup_myself(void) {
|
|||
EV_READ|EV_PERSIST,
|
||||
handle_new_meta_connection, NULL);
|
||||
if(event_add(&listen_socket[listen_sockets].ev_tcp, NULL) < 0) {
|
||||
logger(LOG_EMERG, _("event_add failed: %s"), strerror(errno));
|
||||
logger(LOG_EMERG, "event_add failed: %s", strerror(errno));
|
||||
abort();
|
||||
}
|
||||
|
||||
|
@ -428,13 +421,13 @@ bool setup_myself(void) {
|
|||
EV_READ|EV_PERSIST,
|
||||
handle_incoming_vpn_data, NULL);
|
||||
if(event_add(&listen_socket[listen_sockets].ev_udp, NULL) < 0) {
|
||||
logger(LOG_EMERG, _("event_add failed: %s"), strerror(errno));
|
||||
logger(LOG_EMERG, "event_add failed: %s", strerror(errno));
|
||||
abort();
|
||||
}
|
||||
|
||||
ifdebug(CONNECTIONS) {
|
||||
hostname = sockaddr2hostname((sockaddr_t *) aip->ai_addr);
|
||||
logger(LOG_NOTICE, _("Listening on %s"), hostname);
|
||||
logger(LOG_NOTICE, "Listening on %s", hostname);
|
||||
free(hostname);
|
||||
}
|
||||
|
||||
|
@ -442,7 +435,7 @@ bool setup_myself(void) {
|
|||
listen_sockets++;
|
||||
|
||||
if(listen_sockets >= MAXSOCKETS) {
|
||||
logger(LOG_WARNING, _("Maximum of %d listening sockets reached"), MAXSOCKETS);
|
||||
logger(LOG_WARNING, "Maximum of %d listening sockets reached", MAXSOCKETS);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -450,9 +443,9 @@ bool setup_myself(void) {
|
|||
freeaddrinfo(ai);
|
||||
|
||||
if(listen_sockets)
|
||||
logger(LOG_NOTICE, _("Ready"));
|
||||
logger(LOG_NOTICE, "Ready");
|
||||
else {
|
||||
logger(LOG_ERR, _("Unable to create any listening socket!"));
|
||||
logger(LOG_ERR, "Unable to create any listening socket!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -462,10 +455,7 @@ bool setup_myself(void) {
|
|||
/*
|
||||
initialize network
|
||||
*/
|
||||
bool setup_network(void)
|
||||
{
|
||||
cp();
|
||||
|
||||
bool setup_network(void) {
|
||||
init_connections();
|
||||
init_subnets();
|
||||
init_nodes();
|
||||
|
@ -502,8 +492,6 @@ void close_network_connections(void) {
|
|||
char *envp[5];
|
||||
int i;
|
||||
|
||||
cp();
|
||||
|
||||
for(node = connection_tree->head; node; node = next) {
|
||||
next = node->next;
|
||||
c = node->data;
|
||||
|
|
104
src/net_socket.c
104
src/net_socket.c
|
@ -2,6 +2,8 @@
|
|||
net_socket.c -- Handle various kinds of sockets.
|
||||
Copyright (C) 1998-2005 Ivo Timmermans,
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2006 Scott Lamb <slamb@slamb.org>
|
||||
2009 Florian Forster <octo@verplant.org>
|
||||
|
||||
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
|
||||
|
@ -13,11 +15,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -61,13 +61,13 @@ static void configure_tcp(connection_t *c) {
|
|||
int flags = fcntl(c->socket, F_GETFL);
|
||||
|
||||
if(fcntl(c->socket, F_SETFL, flags | O_NONBLOCK) < 0) {
|
||||
logger(LOG_ERR, _("fcntl for %s: %s"), c->hostname, strerror(errno));
|
||||
logger(LOG_ERR, "fcntl for %s: %s", c->hostname, strerror(errno));
|
||||
}
|
||||
#elif defined(WIN32)
|
||||
unsigned long arg = 1;
|
||||
|
||||
if(ioctlsocket(c->socket, FIONBIO, &arg) != 0) {
|
||||
logger(LOG_ERR, _("ioctlsocket for %s: WSA error %d"), c->hostname, WSAGetLastError());
|
||||
logger(LOG_ERR, "ioctlsocket for %s: WSA error %d", c->hostname, WSAGetLastError());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -82,7 +82,7 @@ static void configure_tcp(connection_t *c) {
|
|||
#endif
|
||||
}
|
||||
|
||||
static bool bind_to_interface(int sd) { /* {{{ */
|
||||
static bool bind_to_interface(int sd) {
|
||||
char *iface;
|
||||
|
||||
#if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE)
|
||||
|
@ -100,18 +100,18 @@ static bool bind_to_interface(int sd) { /* {{{ */
|
|||
|
||||
status = setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr));
|
||||
if(status) {
|
||||
logger(LOG_ERR, _("Can't bind to interface %s: %s"), iface,
|
||||
logger(LOG_ERR, "Can't bind to interface %s: %s", iface,
|
||||
strerror(errno));
|
||||
return false;
|
||||
}
|
||||
#else /* if !defined(SOL_SOCKET) || !defined(SO_BINDTODEVICE) */
|
||||
logger(LOG_WARNING, _("%s not supported on this platform"), "BindToInterface");
|
||||
logger(LOG_WARNING, "%s not supported on this platform", "BindToInterface");
|
||||
#endif
|
||||
|
||||
return true;
|
||||
} /* }}} bool bind_to_interface */
|
||||
}
|
||||
|
||||
static bool bind_to_address(connection_t *c) { /* {{{ */
|
||||
static bool bind_to_address(connection_t *c) {
|
||||
char *node;
|
||||
struct addrinfo *ai_list;
|
||||
struct addrinfo *ai_ptr;
|
||||
|
@ -140,8 +140,8 @@ static bool bind_to_address(connection_t *c) { /* {{{ */
|
|||
&ai_hints, &ai_list);
|
||||
if(status) {
|
||||
free(node);
|
||||
logger(LOG_WARNING, _("Error looking up %s port %s: %s"),
|
||||
node, _("any"), gai_strerror(status));
|
||||
logger(LOG_WARNING, "Error looking up %s port %s: %s",
|
||||
node, "any", gai_strerror(status));
|
||||
return false;
|
||||
}
|
||||
assert(ai_list != NULL);
|
||||
|
@ -156,7 +156,7 @@ static bool bind_to_address(connection_t *c) { /* {{{ */
|
|||
|
||||
|
||||
if(status) {
|
||||
logger(LOG_ERR, _("Can't bind to %s/tcp: %s"), node,
|
||||
logger(LOG_ERR, "Can't bind to %s/tcp: %s", node,
|
||||
strerror(errno));
|
||||
} else ifdebug(CONNECTIONS) {
|
||||
logger(LOG_DEBUG, "Successfully bound outgoing "
|
||||
|
@ -167,21 +167,18 @@ static bool bind_to_address(connection_t *c) { /* {{{ */
|
|||
freeaddrinfo(ai_list);
|
||||
|
||||
return status ? false : true;
|
||||
} /* }}} bool bind_to_address */
|
||||
}
|
||||
|
||||
int setup_listen_socket(const sockaddr_t *sa)
|
||||
{
|
||||
int setup_listen_socket(const sockaddr_t *sa) {
|
||||
int nfd;
|
||||
char *addrstr;
|
||||
int option;
|
||||
char *iface;
|
||||
|
||||
cp();
|
||||
|
||||
nfd = socket(sa->sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
if(nfd < 0) {
|
||||
ifdebug(STATUS) logger(LOG_ERR, _("Creating metasocket failed: %s"), strerror(errno));
|
||||
ifdebug(STATUS) logger(LOG_ERR, "Creating metasocket failed: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -205,19 +202,19 @@ int setup_listen_socket(const sockaddr_t *sa)
|
|||
|
||||
if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof ifr)) {
|
||||
closesocket(nfd);
|
||||
logger(LOG_ERR, _("Can't bind to interface %s: %s"), iface,
|
||||
logger(LOG_ERR, "Can't bind to interface %s: %s", iface,
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
logger(LOG_WARNING, _("%s not supported on this platform"), "BindToInterface");
|
||||
logger(LOG_WARNING, "%s not supported on this platform", "BindToInterface");
|
||||
#endif
|
||||
}
|
||||
|
||||
if(bind(nfd, &sa->sa, SALEN(sa->sa))) {
|
||||
closesocket(nfd);
|
||||
addrstr = sockaddr2hostname(sa);
|
||||
logger(LOG_ERR, _("Can't bind to %s/tcp: %s"), addrstr,
|
||||
logger(LOG_ERR, "Can't bind to %s/tcp: %s", addrstr,
|
||||
strerror(errno));
|
||||
free(addrstr);
|
||||
return -1;
|
||||
|
@ -225,7 +222,7 @@ int setup_listen_socket(const sockaddr_t *sa)
|
|||
|
||||
if(listen(nfd, 3)) {
|
||||
closesocket(nfd);
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "listen",
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "listen",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
@ -238,12 +235,10 @@ int setup_vpn_in_socket(const sockaddr_t *sa) {
|
|||
char *addrstr;
|
||||
int option;
|
||||
|
||||
cp();
|
||||
|
||||
nfd = socket(sa->sa.sa_family, SOCK_DGRAM, IPPROTO_UDP);
|
||||
|
||||
if(nfd < 0) {
|
||||
logger(LOG_ERR, _("Creating UDP socket failed: %s"), strerror(errno));
|
||||
logger(LOG_ERR, "Creating UDP socket failed: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -253,7 +248,7 @@ int setup_vpn_in_socket(const sockaddr_t *sa) {
|
|||
|
||||
if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) {
|
||||
closesocket(nfd);
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "fcntl",
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "fcntl",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
@ -263,7 +258,7 @@ int setup_vpn_in_socket(const sockaddr_t *sa) {
|
|||
unsigned long arg = 1;
|
||||
if(ioctlsocket(nfd, FIONBIO, &arg) != 0) {
|
||||
closesocket(nfd);
|
||||
logger(LOG_ERR, _("Call to `%s' failed: WSA error %d"), "ioctlsocket",
|
||||
logger(LOG_ERR, "Call to `%s' failed: WSA error %d", "ioctlsocket",
|
||||
WSAGetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
@ -300,7 +295,7 @@ int setup_vpn_in_socket(const sockaddr_t *sa) {
|
|||
if(bind(nfd, &sa->sa, SALEN(sa->sa))) {
|
||||
closesocket(nfd);
|
||||
addrstr = sockaddr2hostname(sa);
|
||||
logger(LOG_ERR, _("Can't bind to %s/udp: %s"), addrstr,
|
||||
logger(LOG_ERR, "Can't bind to %s/udp: %s", addrstr,
|
||||
strerror(errno));
|
||||
free(addrstr);
|
||||
return -1;
|
||||
|
@ -314,8 +309,6 @@ static void retry_outgoing_handler(int fd, short events, void *data) {
|
|||
}
|
||||
|
||||
void retry_outgoing(outgoing_t *outgoing) {
|
||||
cp();
|
||||
|
||||
outgoing->timeout += 5;
|
||||
|
||||
if(outgoing->timeout > maxtimeout)
|
||||
|
@ -325,14 +318,12 @@ void retry_outgoing(outgoing_t *outgoing) {
|
|||
event_add(&outgoing->ev, &(struct timeval){outgoing->timeout, 0});
|
||||
|
||||
ifdebug(CONNECTIONS) logger(LOG_NOTICE,
|
||||
_("Trying to re-establish outgoing connection in %d seconds"),
|
||||
"Trying to re-establish outgoing connection in %d seconds",
|
||||
outgoing->timeout);
|
||||
}
|
||||
|
||||
void finish_connecting(connection_t *c) {
|
||||
cp();
|
||||
|
||||
ifdebug(CONNECTIONS) logger(LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname);
|
||||
ifdebug(CONNECTIONS) logger(LOG_INFO, "Connected to %s (%s)", c->name, c->hostname);
|
||||
|
||||
configure_tcp(c);
|
||||
|
||||
|
@ -346,12 +337,10 @@ void do_outgoing_connection(connection_t *c) {
|
|||
char *address, *port;
|
||||
int result;
|
||||
|
||||
cp();
|
||||
|
||||
begin:
|
||||
if(!c->outgoing->ai) {
|
||||
if(!c->outgoing->cfg) {
|
||||
ifdebug(CONNECTIONS) logger(LOG_ERR, _("Could not set up a meta connection to %s"),
|
||||
ifdebug(CONNECTIONS) logger(LOG_ERR, "Could not set up a meta connection to %s",
|
||||
c->name);
|
||||
retry_outgoing(c->outgoing);
|
||||
c->outgoing = NULL;
|
||||
|
@ -387,13 +376,13 @@ begin:
|
|||
|
||||
c->hostname = sockaddr2hostname(&c->address);
|
||||
|
||||
ifdebug(CONNECTIONS) logger(LOG_INFO, _("Trying to connect to %s (%s)"), c->name,
|
||||
ifdebug(CONNECTIONS) logger(LOG_INFO, "Trying to connect to %s (%s)", c->name,
|
||||
c->hostname);
|
||||
|
||||
c->socket = socket(c->address.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
if(c->socket == -1) {
|
||||
ifdebug(CONNECTIONS) logger(LOG_ERR, _("Creating socket for %s failed: %s"), c->hostname,
|
||||
ifdebug(CONNECTIONS) logger(LOG_ERR, "Creating socket for %s failed: %s", c->hostname,
|
||||
strerror(errno));
|
||||
|
||||
goto begin;
|
||||
|
@ -428,7 +417,7 @@ begin:
|
|||
|
||||
closesocket(c->socket);
|
||||
|
||||
ifdebug(CONNECTIONS) logger(LOG_ERR, _("%s: %s"), c->hostname, strerror(errno));
|
||||
ifdebug(CONNECTIONS) logger(LOG_ERR, "%s: %s", c->hostname, strerror(errno));
|
||||
|
||||
goto begin;
|
||||
}
|
||||
|
@ -439,17 +428,17 @@ begin:
|
|||
}
|
||||
|
||||
void handle_meta_read(struct bufferevent *event, void *data) {
|
||||
logger(LOG_EMERG, _("handle_meta_read() called"));
|
||||
logger(LOG_EMERG, "handle_meta_read() called");
|
||||
abort();
|
||||
}
|
||||
|
||||
void handle_meta_write(struct bufferevent *event, void *data) {
|
||||
ifdebug(META) logger(LOG_DEBUG, _("handle_meta_write() called"));
|
||||
ifdebug(META) logger(LOG_DEBUG, "handle_meta_write() called");
|
||||
}
|
||||
|
||||
void handle_meta_connection_error(struct bufferevent *event, short what, void *data) {
|
||||
connection_t *c = data;
|
||||
logger(LOG_EMERG, _("handle_meta_connection_error() called: %d: %s"), what, strerror(errno));
|
||||
logger(LOG_EMERG, "handle_meta_connection_error() called: %d: %s", what, strerror(errno));
|
||||
terminate_connection(c, c->status.active);
|
||||
}
|
||||
|
||||
|
@ -457,13 +446,11 @@ void setup_outgoing_connection(outgoing_t *outgoing) {
|
|||
connection_t *c;
|
||||
node_t *n;
|
||||
|
||||
cp();
|
||||
|
||||
n = lookup_node(outgoing->name);
|
||||
|
||||
if(n)
|
||||
if(n->connection) {
|
||||
ifdebug(CONNECTIONS) logger(LOG_INFO, _("Already connected to %s"), outgoing->name);
|
||||
ifdebug(CONNECTIONS) logger(LOG_INFO, "Already connected to %s", outgoing->name);
|
||||
|
||||
n->connection->outgoing = outgoing;
|
||||
return;
|
||||
|
@ -482,7 +469,7 @@ void setup_outgoing_connection(outgoing_t *outgoing) {
|
|||
outgoing->cfg = lookup_config(c->config_tree, "Address");
|
||||
|
||||
if(!outgoing->cfg) {
|
||||
logger(LOG_ERR, _("No address specified for %s"), c->name);
|
||||
logger(LOG_ERR, "No address specified for %s", c->name);
|
||||
free_connection(c);
|
||||
return;
|
||||
}
|
||||
|
@ -498,7 +485,7 @@ void setup_outgoing_connection(outgoing_t *outgoing) {
|
|||
event_add(&c->inevent, NULL);
|
||||
c->buffer = bufferevent_new(c->socket, handle_meta_read, handle_meta_write, handle_meta_connection_error, c);
|
||||
if(!c->buffer) {
|
||||
logger(LOG_EMERG, _("bufferevent_new() failed: %s"), strerror(errno));
|
||||
logger(LOG_EMERG, "bufferevent_new() failed: %s", strerror(errno));
|
||||
abort();
|
||||
}
|
||||
bufferevent_disable(c->buffer, EV_READ);
|
||||
|
@ -514,12 +501,10 @@ void handle_new_meta_connection(int sock, short events, void *data) {
|
|||
int fd;
|
||||
socklen_t len = sizeof sa;
|
||||
|
||||
cp();
|
||||
|
||||
fd = accept(sock, &sa.sa, &len);
|
||||
|
||||
if(fd < 0) {
|
||||
logger(LOG_ERR, _("Accepting a new connection failed: %s"), strerror(errno));
|
||||
logger(LOG_ERR, "Accepting a new connection failed: %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -537,13 +522,13 @@ void handle_new_meta_connection(int sock, short events, void *data) {
|
|||
c->socket = fd;
|
||||
c->last_ping_time = time(NULL);
|
||||
|
||||
ifdebug(CONNECTIONS) logger(LOG_NOTICE, _("Connection from %s"), c->hostname);
|
||||
ifdebug(CONNECTIONS) logger(LOG_NOTICE, "Connection from %s", c->hostname);
|
||||
|
||||
event_set(&c->inevent, c->socket, EV_READ | EV_PERSIST, handle_meta_connection_data, c);
|
||||
event_add(&c->inevent, NULL);
|
||||
c->buffer = bufferevent_new(c->socket, NULL, handle_meta_write, handle_meta_connection_error, c);
|
||||
if(!c->buffer) {
|
||||
logger(LOG_EMERG, _("bufferevent_new() failed: %s"), strerror(errno));
|
||||
logger(LOG_EMERG, "bufferevent_new() failed: %s", strerror(errno));
|
||||
abort();
|
||||
}
|
||||
bufferevent_disable(c->buffer, EV_READ);
|
||||
|
@ -566,16 +551,13 @@ void free_outgoing(outgoing_t *outgoing) {
|
|||
free(outgoing);
|
||||
}
|
||||
|
||||
void try_outgoing_connections(void)
|
||||
{
|
||||
void try_outgoing_connections(void) {
|
||||
static config_t *cfg = NULL;
|
||||
char *name;
|
||||
outgoing_t *outgoing;
|
||||
connection_t *c;
|
||||
splay_node_t *node;
|
||||
|
||||
cp();
|
||||
|
||||
if(outgoing_list) {
|
||||
for(node = connection_tree->head; node; node = node->next) {
|
||||
c = node->data;
|
||||
|
@ -592,7 +574,7 @@ void try_outgoing_connections(void)
|
|||
|
||||
if(!check_id(name)) {
|
||||
logger(LOG_ERR,
|
||||
_("Invalid name for outgoing connection in %s line %d"),
|
||||
"Invalid name for outgoing connection in %s line %d",
|
||||
cfg->file, cfg->line);
|
||||
free(name);
|
||||
continue;
|
||||
|
|
59
src/netutl.c
59
src/netutl.c
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
netutl.c -- some supporting network utility code
|
||||
Copyright (C) 1998-2005 Ivo Timmermans
|
||||
2000-2006 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
|
||||
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
|
||||
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -38,15 +36,13 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock
|
|||
struct addrinfo *ai, hint = {0};
|
||||
int err;
|
||||
|
||||
cp();
|
||||
|
||||
hint.ai_family = addressfamily;
|
||||
hint.ai_socktype = socktype;
|
||||
|
||||
err = getaddrinfo(address, service, &hint, &ai);
|
||||
|
||||
if(err) {
|
||||
logger(LOG_WARNING, _("Error looking up %s port %s: %s"), address,
|
||||
logger(LOG_WARNING, "Error looking up %s port %s: %s", address,
|
||||
service, gai_strerror(err));
|
||||
return NULL;
|
||||
}
|
||||
|
@ -59,8 +55,6 @@ sockaddr_t str2sockaddr(const char *address, const char *port) {
|
|||
sockaddr_t result;
|
||||
int err;
|
||||
|
||||
cp();
|
||||
|
||||
hint.ai_family = AF_UNSPEC;
|
||||
hint.ai_flags = AI_NUMERICHOST;
|
||||
hint.ai_socktype = SOCK_STREAM;
|
||||
|
@ -88,8 +82,6 @@ void sockaddr2str(const sockaddr_t *sa, char **addrstr, char **portstr) {
|
|||
char *scopeid;
|
||||
int err;
|
||||
|
||||
cp();
|
||||
|
||||
if(sa->sa.sa_family == AF_UNKNOWN) {
|
||||
*addrstr = xstrdup(sa->unknown.address);
|
||||
*portstr = xstrdup(sa->unknown.port);
|
||||
|
@ -99,9 +91,8 @@ void sockaddr2str(const sockaddr_t *sa, char **addrstr, char **portstr) {
|
|||
err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof address, port, sizeof port, NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
|
||||
if(err) {
|
||||
logger(LOG_ERR, _("Error while translating addresses: %s"),
|
||||
logger(LOG_ERR, "Error while translating addresses: %s",
|
||||
gai_strerror(err));
|
||||
cp_trace();
|
||||
raise(SIGFPE);
|
||||
exit(0);
|
||||
}
|
||||
|
@ -121,31 +112,26 @@ char *sockaddr2hostname(const sockaddr_t *sa) {
|
|||
char port[NI_MAXSERV] = "unknown";
|
||||
int err;
|
||||
|
||||
cp();
|
||||
|
||||
if(sa->sa.sa_family == AF_UNKNOWN) {
|
||||
xasprintf(&str, _("%s port %s"), sa->unknown.address, sa->unknown.port);
|
||||
xasprintf(&str, "%s port %s", sa->unknown.address, sa->unknown.port);
|
||||
return str;
|
||||
}
|
||||
|
||||
err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof address, port, sizeof port,
|
||||
hostnames ? 0 : (NI_NUMERICHOST | NI_NUMERICSERV));
|
||||
if(err) {
|
||||
logger(LOG_ERR, _("Error while looking up hostname: %s"),
|
||||
logger(LOG_ERR, "Error while looking up hostname: %s",
|
||||
gai_strerror(err));
|
||||
}
|
||||
|
||||
xasprintf(&str, _("%s port %s"), address, port);
|
||||
xasprintf(&str, "%s port %s", address, port);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
int sockaddrcmp_noport(const sockaddr_t *a, const sockaddr_t *b)
|
||||
{
|
||||
int sockaddrcmp_noport(const sockaddr_t *a, const sockaddr_t *b) {
|
||||
int result;
|
||||
|
||||
cp();
|
||||
|
||||
result = a->sa.sa_family - b->sa.sa_family;
|
||||
|
||||
if(result)
|
||||
|
@ -165,20 +151,16 @@ int sockaddrcmp_noport(const sockaddr_t *a, const sockaddr_t *b)
|
|||
return memcmp(&a->in6.sin6_addr, &b->in6.sin6_addr, sizeof(a->in6.sin6_addr));
|
||||
|
||||
default:
|
||||
logger(LOG_ERR, _("sockaddrcmp() was called with unknown address family %d, exitting!"),
|
||||
logger(LOG_ERR, "sockaddrcmp() was called with unknown address family %d, exitting!",
|
||||
a->sa.sa_family);
|
||||
cp_trace();
|
||||
raise(SIGFPE);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b)
|
||||
{
|
||||
int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b) {
|
||||
int result;
|
||||
|
||||
cp();
|
||||
|
||||
result = a->sa.sa_family - b->sa.sa_family;
|
||||
|
||||
if(result)
|
||||
|
@ -213,17 +195,14 @@ int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b)
|
|||
return memcmp(&a->in6.sin6_port, &b->in6.sin6_port, sizeof a->in6.sin6_port);
|
||||
|
||||
default:
|
||||
logger(LOG_ERR, _("sockaddrcmp() was called with unknown address family %d, exitting!"),
|
||||
logger(LOG_ERR, "sockaddrcmp() was called with unknown address family %d, exitting!",
|
||||
a->sa.sa_family);
|
||||
cp_trace();
|
||||
raise(SIGFPE);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
void sockaddrcpy(sockaddr_t *a, const sockaddr_t *b) {
|
||||
cp();
|
||||
|
||||
if(b->sa.sa_family != AF_UNKNOWN) {
|
||||
*a = *b;
|
||||
} else {
|
||||
|
@ -234,8 +213,6 @@ void sockaddrcpy(sockaddr_t *a, const sockaddr_t *b) {
|
|||
}
|
||||
|
||||
void sockaddrfree(sockaddr_t *a) {
|
||||
cp();
|
||||
|
||||
if(a->sa.sa_family == AF_UNKNOWN) {
|
||||
free(a->unknown.address);
|
||||
free(a->unknown.port);
|
||||
|
@ -243,8 +220,6 @@ void sockaddrfree(sockaddr_t *a) {
|
|||
}
|
||||
|
||||
void sockaddrunmap(sockaddr_t *sa) {
|
||||
cp();
|
||||
|
||||
if(sa->sa.sa_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&sa->in6.sin6_addr)) {
|
||||
sa->in.sin_addr.s_addr = ((uint32_t *) & sa->in6.sin6_addr)[3];
|
||||
sa->in.sin_family = AF_INET;
|
||||
|
@ -258,8 +233,6 @@ int maskcmp(const void *va, const void *vb, int masklen) {
|
|||
const char *a = va;
|
||||
const char *b = vb;
|
||||
|
||||
cp();
|
||||
|
||||
for(m = masklen, i = 0; m >= 8; m -= 8, i++) {
|
||||
result = a[i] - b[i];
|
||||
if(result)
|
||||
|
@ -277,8 +250,6 @@ void mask(void *va, int masklen, int len) {
|
|||
int i;
|
||||
char *a = va;
|
||||
|
||||
cp();
|
||||
|
||||
i = masklen / 8;
|
||||
masklen %= 8;
|
||||
|
||||
|
@ -294,8 +265,6 @@ void maskcpy(void *va, const void *vb, int masklen, int len) {
|
|||
char *a = va;
|
||||
const char *b = vb;
|
||||
|
||||
cp();
|
||||
|
||||
for(m = masklen, i = 0; m >= 8; m -= 8, i++)
|
||||
a[i] = b[i];
|
||||
|
||||
|
@ -312,8 +281,6 @@ bool maskcheck(const void *va, int masklen, int len) {
|
|||
int i;
|
||||
const char *a = va;
|
||||
|
||||
cp();
|
||||
|
||||
i = masklen / 8;
|
||||
masklen %= 8;
|
||||
|
||||
|
|
12
src/netutl.h
12
src/netutl.h
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
netutl.h -- header file for netutl.c
|
||||
Copyright (C) 1998-2005 Ivo Timmermans <zarq@iname.com>
|
||||
2000-2006 Guus Sliepen <guus@tinc-vpn.org>
|
||||
Copyright (C) 1998-2005 Ivo Timmermans
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
|
||||
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
|
||||
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_NETUTL_H__
|
||||
|
|
33
src/node.c
33
src/node.c
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -42,8 +40,6 @@ static int node_compare(const node_t *a, const node_t *b) {
|
|||
static int node_udp_compare(const node_t *a, const node_t *b) {
|
||||
int result;
|
||||
|
||||
cp();
|
||||
|
||||
result = sockaddrcmp(&a->address, &b->address);
|
||||
|
||||
if(result)
|
||||
|
@ -53,15 +49,11 @@ static int node_udp_compare(const node_t *a, const node_t *b) {
|
|||
}
|
||||
|
||||
void init_nodes(void) {
|
||||
cp();
|
||||
|
||||
node_tree = splay_alloc_tree((splay_compare_t) node_compare, (splay_action_t) free_node);
|
||||
node_udp_tree = splay_alloc_tree((splay_compare_t) node_udp_compare, NULL);
|
||||
}
|
||||
|
||||
void exit_nodes(void) {
|
||||
cp();
|
||||
|
||||
splay_delete_tree(node_udp_tree);
|
||||
splay_delete_tree(node_tree);
|
||||
}
|
||||
|
@ -69,8 +61,6 @@ void exit_nodes(void) {
|
|||
node_t *new_node(void) {
|
||||
node_t *n = xmalloc_and_zero(sizeof *n);
|
||||
|
||||
cp();
|
||||
|
||||
n->subnet_tree = new_subnet_tree();
|
||||
n->edge_tree = new_edge_tree();
|
||||
n->mtu = MTU;
|
||||
|
@ -80,8 +70,6 @@ node_t *new_node(void) {
|
|||
}
|
||||
|
||||
void free_node(node_t *n) {
|
||||
cp();
|
||||
|
||||
if(n->subnet_tree)
|
||||
free_subnet_tree(n->subnet_tree);
|
||||
|
||||
|
@ -107,8 +95,6 @@ void free_node(node_t *n) {
|
|||
}
|
||||
|
||||
void node_add(node_t *n) {
|
||||
cp();
|
||||
|
||||
splay_insert(node_tree, n);
|
||||
}
|
||||
|
||||
|
@ -117,8 +103,6 @@ void node_del(node_t *n) {
|
|||
edge_t *e;
|
||||
subnet_t *s;
|
||||
|
||||
cp();
|
||||
|
||||
for(node = n->subnet_tree->head; node; node = next) {
|
||||
next = node->next;
|
||||
s = node->data;
|
||||
|
@ -138,8 +122,6 @@ void node_del(node_t *n) {
|
|||
node_t *lookup_node(char *name) {
|
||||
node_t n = {0};
|
||||
|
||||
cp();
|
||||
|
||||
n.name = name;
|
||||
|
||||
return splay_search(node_tree, &n);
|
||||
|
@ -148,16 +130,13 @@ node_t *lookup_node(char *name) {
|
|||
node_t *lookup_node_udp(const sockaddr_t *sa) {
|
||||
node_t n = {0};
|
||||
|
||||
cp();
|
||||
|
||||
n.address = *sa;
|
||||
n.name = NULL;
|
||||
|
||||
return splay_search(node_udp_tree, &n);
|
||||
}
|
||||
|
||||
void update_node_udp(node_t *n, const sockaddr_t *sa)
|
||||
{
|
||||
void update_node_udp(node_t *n, const sockaddr_t *sa) {
|
||||
splay_delete(node_udp_tree, n);
|
||||
|
||||
if(n->hostname)
|
||||
|
@ -179,11 +158,9 @@ int dump_nodes(struct evbuffer *out) {
|
|||
splay_node_t *node;
|
||||
node_t *n;
|
||||
|
||||
cp();
|
||||
|
||||
for(node = node_tree->head; node; node = node->next) {
|
||||
n = node->data;
|
||||
if(evbuffer_add_printf(out, _(" %s at %s cipher %d digest %d maclength %d compression %d options %lx status %04x nexthop %s via %s distance %d pmtu %d (min %d max %d)\n"),
|
||||
if(evbuffer_add_printf(out, " %s at %s cipher %d digest %d maclength %d compression %d options %lx status %04x nexthop %s via %s distance %d pmtu %d (min %d max %d)\n",
|
||||
n->name, n->hostname, cipher_get_nid(&n->outcipher),
|
||||
digest_get_nid(&n->outdigest), digest_length(&n->outdigest), n->outcompression,
|
||||
n->options, bitfield_to_int(&n->status, sizeof n->status), n->nexthop ? n->nexthop->name : "-",
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_NODE_H__
|
||||
|
|
|
@ -12,11 +12,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_RSAGEN_H__
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
process.c -- process management functions
|
||||
Copyright (C) 1999-2005 Ivo Timmermans,
|
||||
2000-2007 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
|
||||
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
|
||||
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -45,8 +43,7 @@ extern bool use_logfile;
|
|||
sigset_t emptysigset;
|
||||
|
||||
static void memory_full(int size) {
|
||||
logger(LOG_ERR, _("Memory exhausted (couldn't allocate %d bytes), exitting."), size);
|
||||
cp_trace();
|
||||
logger(LOG_ERR, "Memory exhausted (couldn't allocate %d bytes), exitting.", size);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -70,7 +67,7 @@ bool install_service(void) {
|
|||
|
||||
manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
if(!manager) {
|
||||
logger(LOG_ERR, _("Could not open service manager: %s"), winerror(GetLastError()));
|
||||
logger(LOG_ERR, "Could not open service manager: %s", winerror(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -101,18 +98,18 @@ bool install_service(void) {
|
|||
command, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
if(!service) {
|
||||
logger(LOG_ERR, _("Could not create %s service: %s"), identname, winerror(GetLastError()));
|
||||
logger(LOG_ERR, "Could not create %s service: %s", identname, winerror(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &description);
|
||||
|
||||
logger(LOG_INFO, _("%s service installed"), identname);
|
||||
logger(LOG_INFO, "%s service installed", identname);
|
||||
|
||||
if(!StartService(service, 0, NULL))
|
||||
logger(LOG_WARNING, _("Could not start %s service: %s"), identname, winerror(GetLastError()));
|
||||
logger(LOG_WARNING, "Could not start %s service: %s", identname, winerror(GetLastError()));
|
||||
else
|
||||
logger(LOG_INFO, _("%s service started"), identname);
|
||||
logger(LOG_INFO, "%s service started", identname);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -120,28 +117,28 @@ bool install_service(void) {
|
|||
bool remove_service(void) {
|
||||
manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
if(!manager) {
|
||||
logger(LOG_ERR, _("Could not open service manager: %s"), winerror(GetLastError()));
|
||||
logger(LOG_ERR, "Could not open service manager: %s", winerror(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
service = OpenService(manager, identname, SERVICE_ALL_ACCESS);
|
||||
|
||||
if(!service) {
|
||||
logger(LOG_ERR, _("Could not open %s service: %s"), identname, winerror(GetLastError()));
|
||||
logger(LOG_ERR, "Could not open %s service: %s", identname, winerror(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!ControlService(service, SERVICE_CONTROL_STOP, &status))
|
||||
logger(LOG_ERR, _("Could not stop %s service: %s"), identname, winerror(GetLastError()));
|
||||
logger(LOG_ERR, "Could not stop %s service: %s", identname, winerror(GetLastError()));
|
||||
else
|
||||
logger(LOG_INFO, _("%s service stopped"), identname);
|
||||
logger(LOG_INFO, "%s service stopped", identname);
|
||||
|
||||
if(!DeleteService(service)) {
|
||||
logger(LOG_ERR, _("Could not remove %s service: %s"), identname, winerror(GetLastError()));
|
||||
logger(LOG_ERR, "Could not remove %s service: %s", identname, winerror(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
logger(LOG_INFO, _("%s service removed"), identname);
|
||||
logger(LOG_INFO, "%s service removed", identname);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -152,13 +149,13 @@ DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) {
|
|||
SetServiceStatus(statushandle, &status);
|
||||
return NO_ERROR;
|
||||
case SERVICE_CONTROL_STOP:
|
||||
logger(LOG_NOTICE, _("Got %s request"), "SERVICE_CONTROL_STOP");
|
||||
logger(LOG_NOTICE, "Got %s request", "SERVICE_CONTROL_STOP");
|
||||
break;
|
||||
case SERVICE_CONTROL_SHUTDOWN:
|
||||
logger(LOG_NOTICE, _("Got %s request"), "SERVICE_CONTROL_SHUTDOWN");
|
||||
logger(LOG_NOTICE, "Got %s request", "SERVICE_CONTROL_SHUTDOWN");
|
||||
break;
|
||||
default:
|
||||
logger(LOG_WARNING, _("Got unexpected request %d"), request);
|
||||
logger(LOG_WARNING, "Got unexpected request %d", request);
|
||||
return ERROR_CALL_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
@ -183,7 +180,7 @@ VOID WINAPI run_service(DWORD argc, LPTSTR* argv) {
|
|||
statushandle = RegisterServiceCtrlHandlerEx(identname, controlhandler, NULL);
|
||||
|
||||
if (!statushandle) {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "RegisterServiceCtrlHandlerEx", winerror(GetLastError()));
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "RegisterServiceCtrlHandlerEx", winerror(GetLastError()));
|
||||
err = 1;
|
||||
} else {
|
||||
status.dwWaitHint = 30000;
|
||||
|
@ -216,7 +213,7 @@ bool init_service(void) {
|
|||
return false;
|
||||
}
|
||||
else
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "StartServiceCtrlDispatcher", winerror(GetLastError()));
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "StartServiceCtrlDispatcher", winerror(GetLastError()));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -227,8 +224,6 @@ bool init_service(void) {
|
|||
Detach from current terminal
|
||||
*/
|
||||
bool detach(void) {
|
||||
cp();
|
||||
|
||||
setup_signals();
|
||||
|
||||
#ifndef HAVE_MINGW
|
||||
|
@ -238,7 +233,7 @@ bool detach(void) {
|
|||
if(do_detach) {
|
||||
#ifndef HAVE_MINGW
|
||||
if(daemon(0, 0)) {
|
||||
fprintf(stderr, _("Couldn't detach from terminal: %s"),
|
||||
fprintf(stderr, "Couldn't detach from terminal: %s",
|
||||
strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -250,7 +245,7 @@ bool detach(void) {
|
|||
|
||||
openlogger(identname, use_logfile?LOGMODE_FILE:(do_detach?LOGMODE_SYSLOG:LOGMODE_STDERR));
|
||||
|
||||
logger(LOG_NOTICE, _("tincd %s (%s %s) starting, debug level %d"),
|
||||
logger(LOG_NOTICE, "tincd %s (%s %s) starting, debug level %d",
|
||||
VERSION, __DATE__, __TIME__, debug_level);
|
||||
|
||||
xalloc_fail_func = memory_full;
|
||||
|
@ -264,8 +259,6 @@ bool execute_script(const char *name, char **envp) {
|
|||
char *scriptname, *p;
|
||||
int i;
|
||||
|
||||
cp();
|
||||
|
||||
#ifndef HAVE_MINGW
|
||||
len = xasprintf(&scriptname, "\"%s/%s\"", confbase, name);
|
||||
#else
|
||||
|
@ -285,7 +278,7 @@ bool execute_script(const char *name, char **envp) {
|
|||
}
|
||||
#endif
|
||||
|
||||
ifdebug(STATUS) logger(LOG_INFO, _("Executing script %s"), name);
|
||||
ifdebug(STATUS) logger(LOG_INFO, "Executing script %s", name);
|
||||
|
||||
#ifdef HAVE_PUTENV
|
||||
/* Set environment */
|
||||
|
@ -315,20 +308,20 @@ bool execute_script(const char *name, char **envp) {
|
|||
if(status != -1) {
|
||||
if(WIFEXITED(status)) { /* Child exited by itself */
|
||||
if(WEXITSTATUS(status)) {
|
||||
logger(LOG_ERR, _("Script %s exited with non-zero status %d"),
|
||||
logger(LOG_ERR, "Script %s exited with non-zero status %d",
|
||||
name, WEXITSTATUS(status));
|
||||
return false;
|
||||
}
|
||||
} else if(WIFSIGNALED(status)) { /* Child was killed by a signal */
|
||||
logger(LOG_ERR, _("Script %s was killed by signal %d (%s)"),
|
||||
logger(LOG_ERR, "Script %s was killed by signal %d (%s)",
|
||||
name, WTERMSIG(status), strsignal(WTERMSIG(status)));
|
||||
return false;
|
||||
} else { /* Something strange happened */
|
||||
logger(LOG_ERR, _("Script %s terminated abnormally"), name);
|
||||
logger(LOG_ERR, "Script %s terminated abnormally", name);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "system", strerror(errno));
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "system", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
@ -343,19 +336,17 @@ bool execute_script(const char *name, char **envp) {
|
|||
|
||||
#ifndef HAVE_MINGW
|
||||
static RETSIGTYPE fatal_signal_square(int a) {
|
||||
logger(LOG_ERR, _("Got another fatal signal %d (%s): not restarting."), a,
|
||||
logger(LOG_ERR, "Got another fatal signal %d (%s): not restarting.", a,
|
||||
strsignal(a));
|
||||
cp_trace();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static RETSIGTYPE fatal_signal_handler(int a) {
|
||||
struct sigaction act;
|
||||
logger(LOG_ERR, _("Got fatal signal %d (%s)"), a, strsignal(a));
|
||||
cp_trace();
|
||||
logger(LOG_ERR, "Got fatal signal %d (%s)", a, strsignal(a));
|
||||
|
||||
if(do_detach) {
|
||||
logger(LOG_NOTICE, _("Trying to re-execute in 5 seconds..."));
|
||||
logger(LOG_NOTICE, "Trying to re-execute in 5 seconds...");
|
||||
|
||||
act.sa_handler = fatal_signal_square;
|
||||
act.sa_mask = emptysigset;
|
||||
|
@ -367,18 +358,17 @@ static RETSIGTYPE fatal_signal_handler(int a) {
|
|||
exit_control();
|
||||
execvp(g_argv[0], g_argv);
|
||||
} else {
|
||||
logger(LOG_NOTICE, _("Not restarting."));
|
||||
logger(LOG_NOTICE, "Not restarting.");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static RETSIGTYPE unexpected_signal_handler(int a) {
|
||||
logger(LOG_WARNING, _("Got unexpected signal %d (%s)"), a, strsignal(a));
|
||||
cp_trace();
|
||||
logger(LOG_WARNING, "Got unexpected signal %d (%s)", a, strsignal(a));
|
||||
}
|
||||
|
||||
static RETSIGTYPE ignore_signal_handler(int a) {
|
||||
ifdebug(SCARY_THINGS) logger(LOG_DEBUG, _("Ignored signal %d (%s)"), a, strsignal(a));
|
||||
ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Ignored signal %d (%s)", a, strsignal(a));
|
||||
}
|
||||
|
||||
static struct {
|
||||
|
@ -423,7 +413,7 @@ void setup_signals(void) {
|
|||
for(i = 0; sighandlers[i].signal; i++) {
|
||||
act.sa_handler = sighandlers[i].handler;
|
||||
if(sigaction(sighandlers[i].signal, &act, NULL) < 0)
|
||||
fprintf(stderr, _("Installing signal handler for signal %d (%s) failed: %s\n"),
|
||||
fprintf(stderr, "Installing signal handler for signal %d (%s) failed: %s\n",
|
||||
sighandlers[i].signal, strsignal(sighandlers[i].signal),
|
||||
strerror(errno));
|
||||
}
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_PROCESS_H__
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
protocol.c -- handle the meta-protocol, basic functions
|
||||
Copyright (C) 1999-2005 Ivo Timmermans,
|
||||
2000-2006 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
|
||||
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
|
||||
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -71,8 +69,6 @@ bool send_request(connection_t *c, const char *format, ...) {
|
|||
char request[MAXBUFSIZE];
|
||||
int len;
|
||||
|
||||
cp();
|
||||
|
||||
/* Use vsnprintf instead of vxasprintf: faster, no memory
|
||||
fragmentation, cleanup is automatic, and there is a limit on the
|
||||
input buffer anyway */
|
||||
|
@ -82,17 +78,17 @@ bool send_request(connection_t *c, const char *format, ...) {
|
|||
va_end(args);
|
||||
|
||||
if(len < 0 || len > MAXBUFSIZE - 1) {
|
||||
logger(LOG_ERR, _("Output buffer overflow while sending request to %s (%s)"),
|
||||
logger(LOG_ERR, "Output buffer overflow while sending request to %s (%s)",
|
||||
c->name, c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
ifdebug(PROTOCOL) {
|
||||
ifdebug(META)
|
||||
logger(LOG_DEBUG, _("Sending %s to %s (%s): %s"),
|
||||
logger(LOG_DEBUG, "Sending %s to %s (%s): %s",
|
||||
request_name[atoi(request)], c->name, c->hostname, request);
|
||||
else
|
||||
logger(LOG_DEBUG, _("Sending %s to %s (%s)"), request_name[atoi(request)],
|
||||
logger(LOG_DEBUG, "Sending %s to %s (%s)", request_name[atoi(request)],
|
||||
c->name, c->hostname);
|
||||
}
|
||||
|
||||
|
@ -106,14 +102,12 @@ bool send_request(connection_t *c, const char *format, ...) {
|
|||
}
|
||||
|
||||
void forward_request(connection_t *from, char *request) {
|
||||
cp();
|
||||
|
||||
ifdebug(PROTOCOL) {
|
||||
ifdebug(META)
|
||||
logger(LOG_DEBUG, _("Forwarding %s from %s (%s): %s"),
|
||||
logger(LOG_DEBUG, "Forwarding %s from %s (%s): %s",
|
||||
request_name[atoi(request)], from->name, from->hostname, request);
|
||||
else
|
||||
logger(LOG_DEBUG, _("Forwarding %s from %s (%s)"),
|
||||
logger(LOG_DEBUG, "Forwarding %s from %s (%s)",
|
||||
request_name[atoi(request)], from->name, from->hostname);
|
||||
}
|
||||
|
||||
|
@ -125,31 +119,29 @@ void forward_request(connection_t *from, char *request) {
|
|||
bool receive_request(connection_t *c, char *request) {
|
||||
int reqno = atoi(request);
|
||||
|
||||
cp();
|
||||
|
||||
if(reqno || *request == '0') {
|
||||
if((reqno < 0) || (reqno >= LAST) || !request_handlers[reqno]) {
|
||||
ifdebug(META)
|
||||
logger(LOG_DEBUG, _("Unknown request from %s (%s): %s"),
|
||||
logger(LOG_DEBUG, "Unknown request from %s (%s): %s",
|
||||
c->name, c->hostname, request);
|
||||
else
|
||||
logger(LOG_ERR, _("Unknown request from %s (%s)"),
|
||||
logger(LOG_ERR, "Unknown request from %s (%s)",
|
||||
c->name, c->hostname);
|
||||
|
||||
return false;
|
||||
} else {
|
||||
ifdebug(PROTOCOL) {
|
||||
ifdebug(META)
|
||||
logger(LOG_DEBUG, _("Got %s from %s (%s): %s"),
|
||||
logger(LOG_DEBUG, "Got %s from %s (%s): %s",
|
||||
request_name[reqno], c->name, c->hostname, request);
|
||||
else
|
||||
logger(LOG_DEBUG, _("Got %s from %s (%s)"),
|
||||
logger(LOG_DEBUG, "Got %s from %s (%s)",
|
||||
request_name[reqno], c->name, c->hostname);
|
||||
}
|
||||
}
|
||||
|
||||
if((c->allow_request != ALL) && (c->allow_request != reqno)) {
|
||||
logger(LOG_ERR, _("Unauthorized request from %s (%s)"), c->name,
|
||||
logger(LOG_ERR, "Unauthorized request from %s (%s)", c->name,
|
||||
c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
@ -157,12 +149,12 @@ bool receive_request(connection_t *c, char *request) {
|
|||
if(!request_handlers[reqno](c, request)) {
|
||||
/* Something went wrong. Probably scriptkiddies. Terminate. */
|
||||
|
||||
logger(LOG_ERR, _("Error while processing %s from %s (%s)"),
|
||||
logger(LOG_ERR, "Error while processing %s from %s (%s)",
|
||||
request_name[reqno], c->name, c->hostname);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
logger(LOG_ERR, _("Bogus data received from %s (%s)"),
|
||||
logger(LOG_ERR, "Bogus data received from %s (%s)",
|
||||
c->name, c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
@ -175,8 +167,6 @@ static int past_request_compare(const past_request_t *a, const past_request_t *b
|
|||
}
|
||||
|
||||
static void free_past_request(past_request_t *r) {
|
||||
cp();
|
||||
|
||||
if(r->request)
|
||||
free(r->request);
|
||||
|
||||
|
@ -188,12 +178,10 @@ static struct event past_request_event;
|
|||
bool seen_request(char *request) {
|
||||
past_request_t *new, p = {0};
|
||||
|
||||
cp();
|
||||
|
||||
p.request = request;
|
||||
|
||||
if(splay_search(past_request_tree, &p)) {
|
||||
ifdebug(SCARY_THINGS) logger(LOG_DEBUG, _("Already seen request"));
|
||||
ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Already seen request");
|
||||
return true;
|
||||
} else {
|
||||
new = xmalloc(sizeof *new);
|
||||
|
@ -211,8 +199,6 @@ void age_past_requests(int fd, short events, void *data) {
|
|||
int left = 0, deleted = 0;
|
||||
time_t now = time(NULL);
|
||||
|
||||
cp();
|
||||
|
||||
for(node = past_request_tree->head; node; node = next) {
|
||||
next = node->next;
|
||||
p = node->data;
|
||||
|
@ -224,7 +210,7 @@ void age_past_requests(int fd, short events, void *data) {
|
|||
}
|
||||
|
||||
if(left || deleted)
|
||||
ifdebug(SCARY_THINGS) logger(LOG_DEBUG, _("Aging past requests: deleted %d, left %d"),
|
||||
ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Aging past requests: deleted %d, left %d",
|
||||
deleted, left);
|
||||
|
||||
if(left)
|
||||
|
@ -232,16 +218,12 @@ void age_past_requests(int fd, short events, void *data) {
|
|||
}
|
||||
|
||||
void init_requests(void) {
|
||||
cp();
|
||||
|
||||
past_request_tree = splay_alloc_tree((splay_compare_t) past_request_compare, (splay_action_t) free_past_request);
|
||||
|
||||
timeout_set(&past_request_event, age_past_requests, NULL);
|
||||
}
|
||||
|
||||
void exit_requests(void) {
|
||||
cp();
|
||||
|
||||
splay_delete_tree(past_request_tree);
|
||||
|
||||
event_del(&past_request_event);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
protocol.h -- header for protocol.c
|
||||
Copyright (C) 1999-2005 Ivo Timmermans,
|
||||
2000-2006 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
|
||||
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
|
||||
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_PROTOCOL_H__
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -38,8 +36,6 @@
|
|||
#include "xalloc.h"
|
||||
|
||||
bool send_id(connection_t *c) {
|
||||
cp();
|
||||
|
||||
gettimeofday(&c->start, NULL);
|
||||
|
||||
return send_request(c, "%d %s %d", ID, myself->connection->name,
|
||||
|
@ -49,10 +45,8 @@ bool send_id(connection_t *c) {
|
|||
bool id_h(connection_t *c, char *request) {
|
||||
char name[MAX_STRING_SIZE];
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d " MAX_STRING " %d", name, &c->protocol_version) != 2) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "ID", c->name,
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "ID", c->name,
|
||||
c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
@ -60,7 +54,7 @@ bool id_h(connection_t *c, char *request) {
|
|||
/* Check if identity is a valid name */
|
||||
|
||||
if(!check_id(name)) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ID", c->name,
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s): %s", "ID", c->name,
|
||||
c->hostname, "invalid name");
|
||||
return false;
|
||||
}
|
||||
|
@ -69,7 +63,7 @@ bool id_h(connection_t *c, char *request) {
|
|||
|
||||
if(c->outgoing) {
|
||||
if(strcmp(c->name, name)) {
|
||||
logger(LOG_ERR, _("Peer %s is %s instead of %s"), c->hostname, name,
|
||||
logger(LOG_ERR, "Peer %s is %s instead of %s", c->hostname, name,
|
||||
c->name);
|
||||
return false;
|
||||
}
|
||||
|
@ -82,7 +76,7 @@ bool id_h(connection_t *c, char *request) {
|
|||
/* Check if version matches */
|
||||
|
||||
if(c->protocol_version != myself->connection->protocol_version) {
|
||||
logger(LOG_ERR, _("Peer %s (%s) uses incompatible version %d"),
|
||||
logger(LOG_ERR, "Peer %s (%s) uses incompatible version %d",
|
||||
c->name, c->hostname, c->protocol_version);
|
||||
return false;
|
||||
}
|
||||
|
@ -98,7 +92,7 @@ bool id_h(connection_t *c, char *request) {
|
|||
init_configuration(&c->config_tree);
|
||||
|
||||
if(!read_connection_config(c)) {
|
||||
logger(LOG_ERR, _("Peer %s had unknown identity (%s)"), c->hostname,
|
||||
logger(LOG_ERR, "Peer %s had unknown identity (%s)", c->hostname,
|
||||
c->name);
|
||||
return false;
|
||||
}
|
||||
|
@ -119,8 +113,6 @@ bool send_metakey(connection_t *c) {
|
|||
char enckey[len];
|
||||
char hexkey[2 * len + 1];
|
||||
|
||||
cp();
|
||||
|
||||
if(!cipher_open_blowfish_ofb(&c->outcipher))
|
||||
return false;
|
||||
|
||||
|
@ -148,7 +140,7 @@ bool send_metakey(connection_t *c) {
|
|||
ifdebug(SCARY_THINGS) {
|
||||
bin2hex(key, hexkey, len);
|
||||
hexkey[len * 2] = '\0';
|
||||
logger(LOG_DEBUG, _("Generated random meta key (unencrypted): %s"), hexkey);
|
||||
logger(LOG_DEBUG, "Generated random meta key (unencrypted): %s", hexkey);
|
||||
}
|
||||
|
||||
/* Encrypt the random data
|
||||
|
@ -159,7 +151,7 @@ bool send_metakey(connection_t *c) {
|
|||
*/
|
||||
|
||||
if(!rsa_public_encrypt(&c->rsa, key, len, enckey)) {
|
||||
logger(LOG_ERR, _("Error during encryption of meta key for %s (%s)"), c->name, c->hostname);
|
||||
logger(LOG_ERR, "Error during encryption of meta key for %s (%s)", c->name, c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -186,17 +178,15 @@ bool metakey_h(connection_t *c, char *request) {
|
|||
char enckey[len];
|
||||
char key[len];
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d %d %d %d %d " MAX_STRING, &cipher, &digest, &maclength, &compression, hexkey) != 5) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "METAKEY", c->name, c->hostname);
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "METAKEY", c->name, c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check if the length of the meta key is all right */
|
||||
|
||||
if(strlen(hexkey) != len * 2) {
|
||||
logger(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name, c->hostname, "wrong keylength");
|
||||
logger(LOG_ERR, "Possible intruder %s (%s): %s", c->name, c->hostname, "wrong keylength");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -207,25 +197,25 @@ bool metakey_h(connection_t *c, char *request) {
|
|||
/* Decrypt the meta key */
|
||||
|
||||
if(!rsa_private_decrypt(&myself->connection->rsa, enckey, len, key)) {
|
||||
logger(LOG_ERR, _("Error during decryption of meta key for %s (%s)"), c->name, c->hostname);
|
||||
logger(LOG_ERR, "Error during decryption of meta key for %s (%s)", c->name, c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
ifdebug(SCARY_THINGS) {
|
||||
bin2hex(key, hexkey, len);
|
||||
hexkey[len * 2] = '\0';
|
||||
logger(LOG_DEBUG, _("Received random meta key (unencrypted): %s"), hexkey);
|
||||
logger(LOG_DEBUG, "Received random meta key (unencrypted): %s", hexkey);
|
||||
}
|
||||
|
||||
/* Check and lookup cipher and digest algorithms */
|
||||
|
||||
if(!cipher_open_by_nid(&c->incipher, cipher) || !cipher_set_key_from_rsa(&c->incipher, key, len, false)) {
|
||||
logger(LOG_ERR, _("Error during initialisation of cipher from %s (%s)"), c->name, c->hostname);
|
||||
logger(LOG_ERR, "Error during initialisation of cipher from %s (%s)", c->name, c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!digest_open_by_nid(&c->indigest, digest, -1)) {
|
||||
logger(LOG_ERR, _("Error during initialisation of digest from %s (%s)"), c->name, c->hostname);
|
||||
logger(LOG_ERR, "Error during initialisation of digest from %s (%s)", c->name, c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -240,8 +230,6 @@ bool send_challenge(connection_t *c) {
|
|||
size_t len = rsa_size(&c->rsa);
|
||||
char buffer[len * 2 + 1];
|
||||
|
||||
cp();
|
||||
|
||||
if(!c->hischallenge)
|
||||
c->hischallenge = xrealloc(c->hischallenge, len);
|
||||
|
||||
|
@ -265,17 +253,15 @@ bool challenge_h(connection_t *c, char *request) {
|
|||
size_t digestlen = digest_length(&c->outdigest);
|
||||
char digest[digestlen];
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d " MAX_STRING, buffer) != 1) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "CHALLENGE", c->name, c->hostname);
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "CHALLENGE", c->name, c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check if the length of the challenge is all right */
|
||||
|
||||
if(strlen(buffer) != len * 2) {
|
||||
logger(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name, c->hostname, "wrong challenge length");
|
||||
logger(LOG_ERR, "Possible intruder %s (%s): %s", c->name, c->hostname, "wrong challenge length");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -285,8 +271,6 @@ bool challenge_h(connection_t *c, char *request) {
|
|||
|
||||
c->allow_request = CHAL_REPLY;
|
||||
|
||||
cp();
|
||||
|
||||
/* Calculate the hash from the challenge we received */
|
||||
|
||||
digest_create(&c->indigest, buffer, len, digest);
|
||||
|
@ -304,10 +288,8 @@ bool challenge_h(connection_t *c, char *request) {
|
|||
bool chal_reply_h(connection_t *c, char *request) {
|
||||
char hishash[MAX_STRING_SIZE];
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d " MAX_STRING, hishash) != 1) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "CHAL_REPLY", c->name,
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "CHAL_REPLY", c->name,
|
||||
c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
@ -315,7 +297,7 @@ bool chal_reply_h(connection_t *c, char *request) {
|
|||
/* Check if the length of the hash is all right */
|
||||
|
||||
if(strlen(hishash) != digest_length(&c->outdigest) * 2) {
|
||||
logger(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name, c->hostname, _("wrong challenge reply length"));
|
||||
logger(LOG_ERR, "Possible intruder %s (%s): %s", c->name, c->hostname, _("wrong challenge reply length"));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -326,7 +308,7 @@ bool chal_reply_h(connection_t *c, char *request) {
|
|||
/* Verify the hash */
|
||||
|
||||
if(!digest_verify(&c->outdigest, c->hischallenge, rsa_size(&c->rsa), hishash)) {
|
||||
logger(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name, c->hostname, _("wrong challenge reply"));
|
||||
logger(LOG_ERR, "Possible intruder %s (%s): %s", c->name, c->hostname, _("wrong challenge reply"));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -348,8 +330,6 @@ bool send_ack(connection_t *c) {
|
|||
struct timeval now;
|
||||
bool choice;
|
||||
|
||||
cp();
|
||||
|
||||
/* Estimate weight */
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
|
@ -410,10 +390,8 @@ bool ack_h(connection_t *c, char *request) {
|
|||
long int options;
|
||||
node_t *n;
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d " MAX_STRING " %d %lx", hisport, &weight, &options) != 3) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "ACK", c->name,
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "ACK", c->name,
|
||||
c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
@ -429,11 +407,11 @@ bool ack_h(connection_t *c, char *request) {
|
|||
} else {
|
||||
if(n->connection) {
|
||||
/* Oh dear, we already have a connection to this node. */
|
||||
ifdebug(CONNECTIONS) logger(LOG_DEBUG, _("Established a second connection with %s (%s), closing old connection"), n->connection->name, n->connection->hostname);
|
||||
ifdebug(CONNECTIONS) logger(LOG_DEBUG, "Established a second connection with %s (%s), closing old connection", n->connection->name, n->connection->hostname);
|
||||
|
||||
if(n->connection->outgoing) {
|
||||
if(c->outgoing)
|
||||
logger(LOG_WARNING, _("Two outgoing connections to the same node!"));
|
||||
logger(LOG_WARNING, "Two outgoing connections to the same node!");
|
||||
else
|
||||
c->outgoing = n->connection->outgoing;
|
||||
|
||||
|
@ -465,7 +443,7 @@ bool ack_h(connection_t *c, char *request) {
|
|||
c->allow_request = ALL;
|
||||
c->status.active = true;
|
||||
|
||||
ifdebug(CONNECTIONS) logger(LOG_NOTICE, _("Connection with %s (%s) activated"), c->name,
|
||||
ifdebug(CONNECTIONS) logger(LOG_NOTICE, "Connection with %s (%s) activated", c->name,
|
||||
c->hostname);
|
||||
|
||||
/* Send him everything we know */
|
||||
|
@ -475,7 +453,6 @@ bool ack_h(connection_t *c, char *request) {
|
|||
/* Create an edge_t for this connection */
|
||||
|
||||
c->edge = new_edge();
|
||||
cp();
|
||||
c->edge->from = myself;
|
||||
c->edge->to = n;
|
||||
sockaddr2str(&c->address, &hisaddress, &dummy);
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
/*
|
||||
protocol_edge.c -- handle the meta-protocol, edges
|
||||
Copyright (C) 1999-2005 Ivo Timmermans,
|
||||
2000-2006 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2009 Michael Tokarev <mjt@corpit.ru>
|
||||
|
||||
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
|
||||
|
@ -13,11 +14,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -40,8 +39,6 @@ bool send_add_edge(connection_t *c, const edge_t *e) {
|
|||
bool x;
|
||||
char *address, *port;
|
||||
|
||||
cp();
|
||||
|
||||
sockaddr2str(&e->address, &address, &port);
|
||||
|
||||
x = send_request(c, "%d %x %s %s %s %s %lx %d", ADD_EDGE, rand(),
|
||||
|
@ -64,11 +61,9 @@ bool add_edge_h(connection_t *c, char *request) {
|
|||
long int options;
|
||||
int weight;
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %lx %d",
|
||||
from_name, to_name, to_address, to_port, &options, &weight) != 6) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_EDGE", c->name,
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "ADD_EDGE", c->name,
|
||||
c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
@ -76,14 +71,14 @@ bool add_edge_h(connection_t *c, char *request) {
|
|||
/* Check if names are valid */
|
||||
|
||||
if(!check_id(from_name)) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_EDGE", c->name,
|
||||
c->hostname, _("invalid name"));
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s): %s", "ADD_EDGE", c->name,
|
||||
c->hostname, "invalid name");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!check_id(to_name)) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_EDGE", c->name,
|
||||
c->hostname, _("invalid name"));
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s): %s", "ADD_EDGE", c->name,
|
||||
c->hostname, "invalid name");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -100,7 +95,7 @@ bool add_edge_h(connection_t *c, char *request) {
|
|||
to != myself && to != c->node) {
|
||||
/* ignore indirect edge registrations for tunnelserver */
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING,
|
||||
_("Ignoring indirect %s from %s (%s)"),
|
||||
"Ignoring indirect %s from %s (%s)",
|
||||
"ADD_EDGE", c->name, c->hostname);
|
||||
return true;
|
||||
}
|
||||
|
@ -129,12 +124,12 @@ bool add_edge_h(connection_t *c, char *request) {
|
|||
if(e) {
|
||||
if(e->weight != weight || e->options != options || sockaddrcmp(&e->address, &address)) {
|
||||
if(from == myself) {
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) for ourself which does not match existing entry"),
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) for ourself which does not match existing entry",
|
||||
"ADD_EDGE", c->name, c->hostname);
|
||||
send_add_edge(c, e);
|
||||
return true;
|
||||
} else {
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) which does not match existing entry"),
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) which does not match existing entry",
|
||||
"ADD_EDGE", c->name, c->hostname);
|
||||
edge_del(e);
|
||||
graph();
|
||||
|
@ -142,7 +137,7 @@ bool add_edge_h(connection_t *c, char *request) {
|
|||
} else
|
||||
return true;
|
||||
} else if(from == myself) {
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) for ourself which does not exist"),
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) for ourself which does not exist",
|
||||
"ADD_EDGE", c->name, c->hostname);
|
||||
e = new_edge();
|
||||
e->from = from;
|
||||
|
@ -173,8 +168,6 @@ bool add_edge_h(connection_t *c, char *request) {
|
|||
}
|
||||
|
||||
bool send_del_edge(connection_t *c, const edge_t *e) {
|
||||
cp();
|
||||
|
||||
return send_request(c, "%d %x %s %s", DEL_EDGE, rand(),
|
||||
e->from->name, e->to->name);
|
||||
}
|
||||
|
@ -185,10 +178,8 @@ bool del_edge_h(connection_t *c, char *request) {
|
|||
char to_name[MAX_STRING_SIZE];
|
||||
node_t *from, *to;
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d %*x "MAX_STRING" "MAX_STRING, from_name, to_name) != 2) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "DEL_EDGE", c->name,
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "DEL_EDGE", c->name,
|
||||
c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
@ -196,14 +187,14 @@ bool del_edge_h(connection_t *c, char *request) {
|
|||
/* Check if names are valid */
|
||||
|
||||
if(!check_id(from_name)) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_EDGE", c->name,
|
||||
c->hostname, _("invalid name"));
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s): %s", "DEL_EDGE", c->name,
|
||||
c->hostname, "invalid name");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!check_id(to_name)) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_EDGE", c->name,
|
||||
c->hostname, _("invalid name"));
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s): %s", "DEL_EDGE", c->name,
|
||||
c->hostname, "invalid name");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -220,19 +211,19 @@ bool del_edge_h(connection_t *c, char *request) {
|
|||
to != myself && to != c->node) {
|
||||
/* ignore indirect edge registrations for tunnelserver */
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING,
|
||||
_("Ignoring indirect %s from %s (%s)"),
|
||||
"Ignoring indirect %s from %s (%s)",
|
||||
"DEL_EDGE", c->name, c->hostname);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!from) {
|
||||
ifdebug(PROTOCOL) logger(LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"),
|
||||
ifdebug(PROTOCOL) logger(LOG_ERR, "Got %s from %s (%s) which does not appear in the edge tree",
|
||||
"DEL_EDGE", c->name, c->hostname);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!to) {
|
||||
ifdebug(PROTOCOL) logger(LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"),
|
||||
ifdebug(PROTOCOL) logger(LOG_ERR, "Got %s from %s (%s) which does not appear in the edge tree",
|
||||
"DEL_EDGE", c->name, c->hostname);
|
||||
return true;
|
||||
}
|
||||
|
@ -242,13 +233,13 @@ bool del_edge_h(connection_t *c, char *request) {
|
|||
e = lookup_edge(from, to);
|
||||
|
||||
if(!e) {
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) which does not appear in the edge tree"),
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) which does not appear in the edge tree",
|
||||
"DEL_EDGE", c->name, c->hostname);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(e->from == myself) {
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) for ourself"),
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) for ourself",
|
||||
"DEL_EDGE", c->name, c->hostname);
|
||||
send_add_edge(c, e); /* Send back a correction */
|
||||
return true;
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -37,8 +35,6 @@
|
|||
static bool mykeyused = false;
|
||||
|
||||
bool send_key_changed() {
|
||||
cp();
|
||||
|
||||
/* Only send this message if some other daemon requested our key previously.
|
||||
This reduces unnecessary key_changed broadcasts.
|
||||
*/
|
||||
|
@ -53,10 +49,8 @@ bool key_changed_h(connection_t *c, char *request) {
|
|||
char name[MAX_STRING_SIZE];
|
||||
node_t *n;
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d %*x " MAX_STRING, name) != 1) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "KEY_CHANGED",
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "KEY_CHANGED",
|
||||
c->name, c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
@ -67,7 +61,7 @@ bool key_changed_h(connection_t *c, char *request) {
|
|||
n = lookup_node(name);
|
||||
|
||||
if(!n) {
|
||||
logger(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist"),
|
||||
logger(LOG_ERR, "Got %s from %s (%s) origin %s which does not exist",
|
||||
"KEY_CHANGED", c->name, c->hostname, name);
|
||||
return false;
|
||||
}
|
||||
|
@ -84,8 +78,6 @@ bool key_changed_h(connection_t *c, char *request) {
|
|||
}
|
||||
|
||||
bool send_req_key(node_t *to) {
|
||||
cp();
|
||||
|
||||
return send_request(to->nexthop->connection, "%d %s %s", REQ_KEY, myself->name, to->name);
|
||||
}
|
||||
|
||||
|
@ -94,10 +86,8 @@ bool req_key_h(connection_t *c, char *request) {
|
|||
char to_name[MAX_STRING_SIZE];
|
||||
node_t *from, *to;
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d " MAX_STRING " " MAX_STRING, from_name, to_name) != 2) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "REQ_KEY", c->name,
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "REQ_KEY", c->name,
|
||||
c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
@ -105,7 +95,7 @@ bool req_key_h(connection_t *c, char *request) {
|
|||
from = lookup_node(from_name);
|
||||
|
||||
if(!from) {
|
||||
logger(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist in our connection list"),
|
||||
logger(LOG_ERR, "Got %s from %s (%s) origin %s which does not exist in our connection list",
|
||||
"REQ_KEY", c->name, c->hostname, from_name);
|
||||
return false;
|
||||
}
|
||||
|
@ -113,7 +103,7 @@ bool req_key_h(connection_t *c, char *request) {
|
|||
to = lookup_node(to_name);
|
||||
|
||||
if(!to) {
|
||||
logger(LOG_ERR, _("Got %s from %s (%s) destination %s which does not exist in our connection list"),
|
||||
logger(LOG_ERR, "Got %s from %s (%s) destination %s which does not exist in our connection list",
|
||||
"REQ_KEY", c->name, c->hostname, to_name);
|
||||
return false;
|
||||
}
|
||||
|
@ -128,7 +118,7 @@ bool req_key_h(connection_t *c, char *request) {
|
|||
return false;
|
||||
|
||||
if(!to->status.reachable) {
|
||||
logger(LOG_WARNING, _("Got %s from %s (%s) destination %s which is not reachable"),
|
||||
logger(LOG_WARNING, "Got %s from %s (%s) destination %s which is not reachable",
|
||||
"REQ_KEY", c->name, c->hostname, to_name);
|
||||
return true;
|
||||
}
|
||||
|
@ -143,8 +133,6 @@ bool send_ans_key(node_t *to) {
|
|||
size_t keylen = cipher_keylength(&myself->incipher);
|
||||
char key[keylen * 2 + 1];
|
||||
|
||||
cp();
|
||||
|
||||
cipher_open_by_nid(&to->incipher, cipher_get_nid(&myself->incipher));
|
||||
digest_open_by_nid(&to->indigest, digest_get_nid(&myself->indigest), digest_length(&myself->indigest));
|
||||
to->incompression = myself->incompression;
|
||||
|
@ -175,12 +163,10 @@ bool ans_key_h(connection_t *c, char *request) {
|
|||
int cipher, digest, maclength, compression;
|
||||
node_t *from, *to;
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d %d %d",
|
||||
from_name, to_name, key, &cipher, &digest, &maclength,
|
||||
&compression) != 7) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "ANS_KEY", c->name,
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "ANS_KEY", c->name,
|
||||
c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
@ -188,7 +174,7 @@ bool ans_key_h(connection_t *c, char *request) {
|
|||
from = lookup_node(from_name);
|
||||
|
||||
if(!from) {
|
||||
logger(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist in our connection list"),
|
||||
logger(LOG_ERR, "Got %s from %s (%s) origin %s which does not exist in our connection list",
|
||||
"ANS_KEY", c->name, c->hostname, from_name);
|
||||
return false;
|
||||
}
|
||||
|
@ -196,7 +182,7 @@ bool ans_key_h(connection_t *c, char *request) {
|
|||
to = lookup_node(to_name);
|
||||
|
||||
if(!to) {
|
||||
logger(LOG_ERR, _("Got %s from %s (%s) destination %s which does not exist in our connection list"),
|
||||
logger(LOG_ERR, "Got %s from %s (%s) destination %s which does not exist in our connection list",
|
||||
"ANS_KEY", c->name, c->hostname, to_name);
|
||||
return false;
|
||||
}
|
||||
|
@ -208,7 +194,7 @@ bool ans_key_h(connection_t *c, char *request) {
|
|||
return false;
|
||||
|
||||
if(!to->status.reachable) {
|
||||
logger(LOG_WARNING, _("Got %s from %s (%s) destination %s which is not reachable"),
|
||||
logger(LOG_WARNING, "Got %s from %s (%s) destination %s which is not reachable",
|
||||
"ANS_KEY", c->name, c->hostname, to_name);
|
||||
return true;
|
||||
}
|
||||
|
@ -219,27 +205,27 @@ bool ans_key_h(connection_t *c, char *request) {
|
|||
/* Check and lookup cipher and digest algorithms */
|
||||
|
||||
if(!cipher_open_by_nid(&from->outcipher, cipher)) {
|
||||
logger(LOG_ERR, _("Node %s (%s) uses unknown cipher!"), from->name, from->hostname);
|
||||
logger(LOG_ERR, "Node %s (%s) uses unknown cipher!", from->name, from->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(strlen(key) / 2 != cipher_keylength(&from->outcipher)) {
|
||||
logger(LOG_ERR, _("Node %s (%s) uses wrong keylength!"), from->name, from->hostname);
|
||||
logger(LOG_ERR, "Node %s (%s) uses wrong keylength!", from->name, from->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!digest_open_by_nid(&from->outdigest, digest, maclength)) {
|
||||
logger(LOG_ERR, _("Node %s (%s) uses unknown digest!"), from->name, from->hostname);
|
||||
logger(LOG_ERR, "Node %s (%s) uses unknown digest!", from->name, from->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(maclength != digest_length(&from->outdigest)) {
|
||||
logger(LOG_ERR, _("Node %s (%s) uses bogus MAC length!"), from->name, from->hostname);
|
||||
logger(LOG_ERR, "Node %s (%s) uses bogus MAC length!", from->name, from->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(compression < 0 || compression > 11) {
|
||||
logger(LOG_ERR, _("Node %s (%s) uses bogus compression level!"), from->name, from->hostname);
|
||||
logger(LOG_ERR, "Node %s (%s) uses bogus compression level!", from->name, from->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
protocol_misc.c -- handle the meta-protocol, miscellaneous functions
|
||||
Copyright (C) 1999-2005 Ivo Timmermans,
|
||||
2000-2006 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
|
||||
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
|
||||
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -35,106 +33,76 @@ int maxoutbufsize = 0;
|
|||
|
||||
/* Status and error notification routines */
|
||||
|
||||
bool send_status(connection_t *c, int statusno, const char *statusstring)
|
||||
{
|
||||
cp();
|
||||
|
||||
bool send_status(connection_t *c, int statusno, const char *statusstring) {
|
||||
if(!statusstring)
|
||||
statusstring = "Status";
|
||||
|
||||
return send_request(c, "%d %d %s", STATUS, statusno, statusstring);
|
||||
}
|
||||
|
||||
bool status_h(connection_t *c, char *request)
|
||||
{
|
||||
bool status_h(connection_t *c, char *request) {
|
||||
int statusno;
|
||||
char statusstring[MAX_STRING_SIZE];
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d %d " MAX_STRING, &statusno, statusstring) != 2) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "STATUS",
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "STATUS",
|
||||
c->name, c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
ifdebug(STATUS) logger(LOG_NOTICE, _("Status message from %s (%s): %d: %s"),
|
||||
ifdebug(STATUS) logger(LOG_NOTICE, "Status message from %s (%s): %d: %s",
|
||||
c->name, c->hostname, statusno, statusstring);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool send_error(connection_t *c, int err, const char *errstring)
|
||||
{
|
||||
cp();
|
||||
|
||||
bool send_error(connection_t *c, int err, const char *errstring) {
|
||||
if(!errstring)
|
||||
errstring = "Error";
|
||||
|
||||
return send_request(c, "%d %d %s", ERROR, err, errstring);
|
||||
}
|
||||
|
||||
bool error_h(connection_t *c, char *request)
|
||||
{
|
||||
bool error_h(connection_t *c, char *request) {
|
||||
int err;
|
||||
char errorstring[MAX_STRING_SIZE];
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d %d " MAX_STRING, &err, errorstring) != 2) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "ERROR",
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "ERROR",
|
||||
c->name, c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
||||
ifdebug(ERROR) logger(LOG_NOTICE, _("Error message from %s (%s): %d: %s"),
|
||||
ifdebug(ERROR) logger(LOG_NOTICE, "Error message from %s (%s): %d: %s",
|
||||
c->name, c->hostname, err, errorstring);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool send_termreq(connection_t *c)
|
||||
{
|
||||
cp();
|
||||
|
||||
bool send_termreq(connection_t *c) {
|
||||
return send_request(c, "%d", TERMREQ);
|
||||
}
|
||||
|
||||
bool termreq_h(connection_t *c, char *request)
|
||||
{
|
||||
cp();
|
||||
|
||||
bool termreq_h(connection_t *c, char *request) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool send_ping(connection_t *c)
|
||||
{
|
||||
cp();
|
||||
|
||||
bool send_ping(connection_t *c) {
|
||||
c->status.pinged = true;
|
||||
c->last_ping_time = time(NULL);
|
||||
|
||||
return send_request(c, "%d", PING);
|
||||
}
|
||||
|
||||
bool ping_h(connection_t *c, char *request)
|
||||
{
|
||||
cp();
|
||||
|
||||
bool ping_h(connection_t *c, char *request) {
|
||||
return send_pong(c);
|
||||
}
|
||||
|
||||
bool send_pong(connection_t *c)
|
||||
{
|
||||
cp();
|
||||
|
||||
bool send_pong(connection_t *c) {
|
||||
return send_request(c, "%d", PONG);
|
||||
}
|
||||
|
||||
bool pong_h(connection_t *c, char *request)
|
||||
{
|
||||
cp();
|
||||
|
||||
bool pong_h(connection_t *c, char *request) {
|
||||
c->status.pinged = false;
|
||||
|
||||
/* Succesful connection, reset timeout if this is an outgoing connection. */
|
||||
|
@ -147,10 +115,7 @@ bool pong_h(connection_t *c, char *request)
|
|||
|
||||
/* Sending and receiving packets via TCP */
|
||||
|
||||
bool send_tcppacket(connection_t *c, vpn_packet_t *packet)
|
||||
{
|
||||
cp();
|
||||
|
||||
bool send_tcppacket(connection_t *c, vpn_packet_t *packet) {
|
||||
/* If there already is a lot of data in the outbuf buffer, discard this packet.
|
||||
We use a very simple Random Early Drop algorithm. */
|
||||
|
||||
|
@ -163,14 +128,11 @@ bool send_tcppacket(connection_t *c, vpn_packet_t *packet)
|
|||
return send_meta(c, (char *)packet->data, packet->len);
|
||||
}
|
||||
|
||||
bool tcppacket_h(connection_t *c, char *request)
|
||||
{
|
||||
bool tcppacket_h(connection_t *c, char *request) {
|
||||
short int len;
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d %hd", &len) != 1) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "PACKET", c->name,
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "PACKET", c->name,
|
||||
c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
protocol_subnet.c -- handle the meta-protocol, subnets
|
||||
Copyright (C) 1999-2005 Ivo Timmermans,
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2009 Michael Tokarev <mjt@tls.msk.ru>
|
||||
|
||||
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
|
||||
|
@ -13,11 +14,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -33,29 +32,23 @@
|
|||
#include "utils.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
bool send_add_subnet(connection_t *c, const subnet_t *subnet)
|
||||
{
|
||||
bool send_add_subnet(connection_t *c, const subnet_t *subnet) {
|
||||
char netstr[MAXNETSTR];
|
||||
|
||||
cp();
|
||||
|
||||
if(!net2str(netstr, sizeof netstr, subnet))
|
||||
return false;
|
||||
|
||||
return send_request(c, "%d %x %s %s", ADD_SUBNET, rand(), subnet->owner->name, netstr);
|
||||
}
|
||||
|
||||
bool add_subnet_h(connection_t *c, char *request)
|
||||
{
|
||||
bool add_subnet_h(connection_t *c, char *request) {
|
||||
char subnetstr[MAX_STRING_SIZE];
|
||||
char name[MAX_STRING_SIZE];
|
||||
node_t *owner;
|
||||
subnet_t s = {0}, *new;
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_SUBNET", c->name,
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "ADD_SUBNET", c->name,
|
||||
c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
@ -63,16 +56,16 @@ bool add_subnet_h(connection_t *c, char *request)
|
|||
/* Check if owner name is valid */
|
||||
|
||||
if(!check_id(name)) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_SUBNET", c->name,
|
||||
c->hostname, _("invalid name"));
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s): %s", "ADD_SUBNET", c->name,
|
||||
c->hostname, "invalid name");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check if subnet string is valid */
|
||||
|
||||
if(!str2net(&s, subnetstr)) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_SUBNET", c->name,
|
||||
c->hostname, _("invalid subnet string"));
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s): %s", "ADD_SUBNET", c->name,
|
||||
c->hostname, "invalid subnet string");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -85,7 +78,7 @@ bool add_subnet_h(connection_t *c, char *request)
|
|||
|
||||
if(tunnelserver && owner != myself && owner != c->node) {
|
||||
/* in case of tunnelserver, ignore indirect subnet registrations */
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, _("Ignoring indirect %s from %s (%s) for %s"),
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, "Ignoring indirect %s from %s (%s) for %s",
|
||||
"ADD_SUBNET", c->name, c->hostname, subnetstr);
|
||||
return true;
|
||||
}
|
||||
|
@ -104,7 +97,7 @@ bool add_subnet_h(connection_t *c, char *request)
|
|||
/* If we don't know this subnet, but we are the owner, retaliate with a DEL_SUBNET */
|
||||
|
||||
if(owner == myself) {
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) for ourself"),
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) for ourself",
|
||||
"ADD_SUBNET", c->name, c->hostname);
|
||||
s.owner = myself;
|
||||
send_del_subnet(c, &s);
|
||||
|
@ -128,7 +121,7 @@ bool add_subnet_h(connection_t *c, char *request)
|
|||
}
|
||||
|
||||
if(!cfg) {
|
||||
logger(LOG_WARNING, _("Unauthorized %s from %s (%s) for %s"),
|
||||
logger(LOG_WARNING, "Unauthorized %s from %s (%s) for %s",
|
||||
"ADD_SUBNET", c->name, c->hostname, subnetstr);
|
||||
return false;
|
||||
}
|
||||
|
@ -152,29 +145,23 @@ bool add_subnet_h(connection_t *c, char *request)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool send_del_subnet(connection_t *c, const subnet_t *s)
|
||||
{
|
||||
bool send_del_subnet(connection_t *c, const subnet_t *s) {
|
||||
char netstr[MAXNETSTR];
|
||||
|
||||
cp();
|
||||
|
||||
if(!net2str(netstr, sizeof netstr, s))
|
||||
return false;
|
||||
|
||||
return send_request(c, "%d %x %s %s", DEL_SUBNET, rand(), s->owner->name, netstr);
|
||||
}
|
||||
|
||||
bool del_subnet_h(connection_t *c, char *request)
|
||||
{
|
||||
bool del_subnet_h(connection_t *c, char *request) {
|
||||
char subnetstr[MAX_STRING_SIZE];
|
||||
char name[MAX_STRING_SIZE];
|
||||
node_t *owner;
|
||||
subnet_t s = {0}, *find;
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(request, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s)"), "DEL_SUBNET", c->name,
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s)", "DEL_SUBNET", c->name,
|
||||
c->hostname);
|
||||
return false;
|
||||
}
|
||||
|
@ -182,16 +169,16 @@ bool del_subnet_h(connection_t *c, char *request)
|
|||
/* Check if owner name is valid */
|
||||
|
||||
if(!check_id(name)) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_SUBNET", c->name,
|
||||
c->hostname, _("invalid name"));
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s): %s", "DEL_SUBNET", c->name,
|
||||
c->hostname, "invalid name");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check if subnet string is valid */
|
||||
|
||||
if(!str2net(&s, subnetstr)) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_SUBNET", c->name,
|
||||
c->hostname, _("invalid subnet string"));
|
||||
logger(LOG_ERR, "Got bad %s from %s (%s): %s", "DEL_SUBNET", c->name,
|
||||
c->hostname, "invalid subnet string");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -204,13 +191,13 @@ bool del_subnet_h(connection_t *c, char *request)
|
|||
|
||||
if(tunnelserver && owner != myself && owner != c->node) {
|
||||
/* in case of tunnelserver, ignore indirect subnet deletion */
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, _("Ignoring indirect %s from %s (%s) for %s"),
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, "Ignoring indirect %s from %s (%s) for %s",
|
||||
"DEL_SUBNET", c->name, c->hostname, subnetstr);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!owner) {
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) for %s which is not in our node tree"),
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) for %s which is not in our node tree",
|
||||
"DEL_SUBNET", c->name, c->hostname, name);
|
||||
return true;
|
||||
}
|
||||
|
@ -222,7 +209,7 @@ bool del_subnet_h(connection_t *c, char *request)
|
|||
find = lookup_subnet(owner, &s);
|
||||
|
||||
if(!find) {
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) for %s which does not appear in his subnet tree"),
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) for %s which does not appear in his subnet tree",
|
||||
"DEL_SUBNET", c->name, c->hostname, name);
|
||||
return true;
|
||||
}
|
||||
|
@ -230,7 +217,7 @@ bool del_subnet_h(connection_t *c, char *request)
|
|||
/* If we are the owner of this subnet, retaliate with an ADD_SUBNET */
|
||||
|
||||
if(owner == myself) {
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) for ourself"),
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) for ourself",
|
||||
"DEL_SUBNET", c->name, c->hostname);
|
||||
send_add_subnet(c, find);
|
||||
return true;
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -44,18 +42,16 @@ bool setup_device(void) {
|
|||
struct ifreq ifr;
|
||||
struct sockaddr_ll sa;
|
||||
|
||||
cp();
|
||||
|
||||
if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
|
||||
iface = xstrdup("eth0");
|
||||
|
||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
||||
device = xstrdup(iface);
|
||||
|
||||
device_info = _("raw socket");
|
||||
device_info = "raw socket";
|
||||
|
||||
if((device_fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) {
|
||||
logger(LOG_ERR, _("Could not open %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Could not open %s: %s", device_info,
|
||||
strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -64,7 +60,7 @@ bool setup_device(void) {
|
|||
strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ);
|
||||
if(ioctl(device_fd, SIOCGIFINDEX, &ifr)) {
|
||||
close(device_fd);
|
||||
logger(LOG_ERR, _("Can't find interface %s: %s"), iface,
|
||||
logger(LOG_ERR, "Can't find interface %s: %s", iface,
|
||||
strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -75,18 +71,16 @@ bool setup_device(void) {
|
|||
sa.sll_ifindex = ifr.ifr_ifindex;
|
||||
|
||||
if(bind(device_fd, (struct sockaddr *) &sa, (socklen_t) sizeof sa)) {
|
||||
logger(LOG_ERR, _("Could not bind %s to %s: %s"), device, iface, strerror(errno));
|
||||
logger(LOG_ERR, "Could not bind %s to %s: %s", device, iface, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
logger(LOG_INFO, _("%s is a %s"), device, device_info);
|
||||
logger(LOG_INFO, "%s is a %s", device, device_info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void close_device(void) {
|
||||
cp();
|
||||
|
||||
close(device_fd);
|
||||
|
||||
free(device);
|
||||
|
@ -96,10 +90,8 @@ void close_device(void) {
|
|||
bool read_packet(vpn_packet_t *packet) {
|
||||
int inlen;
|
||||
|
||||
cp();
|
||||
|
||||
if((inlen = read(device_fd, packet->data, MTU)) <= 0) {
|
||||
logger(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Error while reading from %s %s: %s", device_info,
|
||||
device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -108,20 +100,18 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
|
||||
device_total_in += packet->len;
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Read packet of %d bytes from %s", packet->len,
|
||||
device_info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool write_packet(vpn_packet_t *packet) {
|
||||
cp();
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Writing packet of %d bytes to %s",
|
||||
packet->len, device_info);
|
||||
|
||||
if(write(device_fd, packet->data, packet->len) < 0) {
|
||||
logger(LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
|
||||
logger(LOG_ERR, "Can't write to %s %s: %s", device_info, device,
|
||||
strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -132,9 +122,7 @@ bool write_packet(vpn_packet_t *packet) {
|
|||
}
|
||||
|
||||
void dump_device_stats(void) {
|
||||
cp();
|
||||
|
||||
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
|
||||
logger(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
|
||||
logger(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
|
||||
logger(LOG_DEBUG, "Statistics for %s %s:", device_info, device);
|
||||
logger(LOG_DEBUG, " total bytes in: %10d", device_total_in);
|
||||
logger(LOG_DEBUG, " total bytes out: %10d", device_total_out);
|
||||
}
|
||||
|
|
114
src/route.c
114
src/route.c
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -55,8 +53,7 @@ static struct event age_subnets_event;
|
|||
|
||||
/* RFC 1071 */
|
||||
|
||||
static uint16_t inet_checksum(void *data, int len, uint16_t prevsum)
|
||||
{
|
||||
static uint16_t inet_checksum(void *data, int len, uint16_t prevsum) {
|
||||
uint16_t *p = data;
|
||||
uint32_t checksum = prevsum ^ 0xFFFF;
|
||||
|
||||
|
@ -92,7 +89,7 @@ static bool ratelimit(int frequency) {
|
|||
|
||||
static bool checklength(node_t *source, vpn_packet_t *packet, length_t length) {
|
||||
if(packet->len < length) {
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Got too short packet from %s (%s)"), source->name, source->hostname);
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Got too short packet from %s (%s)", source->name, source->hostname);
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
|
@ -105,16 +102,13 @@ static void swap_mac_addresses(vpn_packet_t *packet) {
|
|||
memcpy(&packet->data[6], &tmp, sizeof tmp);
|
||||
}
|
||||
|
||||
static void age_subnets(int fd, short events, void *data)
|
||||
{
|
||||
static void age_subnets(int fd, short events, void *data) {
|
||||
subnet_t *s;
|
||||
connection_t *c;
|
||||
splay_node_t *node, *next, *node2;
|
||||
bool left = false;
|
||||
time_t now = time(NULL);
|
||||
|
||||
cp();
|
||||
|
||||
for(node = myself->subnet_tree->head; node; node = next) {
|
||||
next = node->next;
|
||||
s = node->data;
|
||||
|
@ -122,7 +116,7 @@ static void age_subnets(int fd, short events, void *data)
|
|||
ifdebug(TRAFFIC) {
|
||||
char netstr[MAXNETSTR];
|
||||
if(net2str(netstr, sizeof netstr, s))
|
||||
logger(LOG_INFO, _("Subnet %s expired"), netstr);
|
||||
logger(LOG_INFO, "Subnet %s expired", netstr);
|
||||
}
|
||||
|
||||
for(node2 = connection_tree->head; node2; node2 = node2->next) {
|
||||
|
@ -148,14 +142,12 @@ static void learn_mac(mac_t *address)
|
|||
splay_node_t *node;
|
||||
connection_t *c;
|
||||
|
||||
cp();
|
||||
|
||||
subnet = lookup_subnet_mac(address);
|
||||
|
||||
/* If we don't know this MAC address yet, store it */
|
||||
|
||||
if(!subnet) {
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, _("Learned new MAC address %hx:%hx:%hx:%hx:%hx:%hx"),
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, "Learned new MAC address %hx:%hx:%hx:%hx:%hx:%hx",
|
||||
address->x[0], address->x[1], address->x[2], address->x[3],
|
||||
address->x[4], address->x[5]);
|
||||
|
||||
|
@ -184,8 +176,7 @@ static void learn_mac(mac_t *address)
|
|||
|
||||
/* RFC 792 */
|
||||
|
||||
static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, uint8_t type, uint8_t code)
|
||||
{
|
||||
static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, uint8_t type, uint8_t code) {
|
||||
struct ip ip = {0};
|
||||
struct icmp icmp = {0};
|
||||
|
||||
|
@ -196,8 +187,6 @@ static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, uint8_t
|
|||
if(ratelimit(3))
|
||||
return;
|
||||
|
||||
cp();
|
||||
|
||||
/* Swap Ethernet source and destination addresses */
|
||||
|
||||
swap_mac_addresses(packet);
|
||||
|
@ -267,8 +256,6 @@ static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet) {
|
|||
uint8_t *offset;
|
||||
uint16_t ip_off, origf;
|
||||
|
||||
cp();
|
||||
|
||||
memcpy(&ip, packet->data + ether_size, ip_size);
|
||||
fragment.priority = packet->priority;
|
||||
|
||||
|
@ -278,11 +265,11 @@ static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet) {
|
|||
todo = ntohs(ip.ip_len) - ip_size;
|
||||
|
||||
if(ether_size + ip_size + todo != packet->len) {
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Length of packet (%d) doesn't match length in IPv4 header (%zd)"), packet->len, ether_size + ip_size + todo);
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Length of packet (%d) doesn't match length in IPv4 header (%zd)", packet->len, ether_size + ip_size + todo);
|
||||
return;
|
||||
}
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, _("Fragmenting packet of %d bytes to %s (%s)"), packet->len, dest->name, dest->hostname);
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, "Fragmenting packet of %d bytes to %s (%s)", packet->len, dest->name, dest->hostname);
|
||||
|
||||
offset = packet->data + ether_size + ip_size;
|
||||
maxlen = (dest->mtu - ether_size - ip_size) & ~0x7;
|
||||
|
@ -310,19 +297,16 @@ static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet) {
|
|||
}
|
||||
}
|
||||
|
||||
static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet)
|
||||
{
|
||||
static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) {
|
||||
subnet_t *subnet;
|
||||
node_t *via;
|
||||
ipv4_t dest;
|
||||
|
||||
cp();
|
||||
|
||||
memcpy(&dest, &packet->data[30], sizeof dest);
|
||||
subnet = lookup_subnet_ipv4(&dest);
|
||||
|
||||
if(!subnet) {
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Cannot route packet from %s (%s): unknown IPv4 destination address %d.%d.%d.%d"),
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet from %s (%s): unknown IPv4 destination address %d.%d.%d.%d",
|
||||
source->name, source->hostname,
|
||||
dest.x[0],
|
||||
dest.x[1],
|
||||
|
@ -334,7 +318,7 @@ static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet)
|
|||
}
|
||||
|
||||
if(subnet->owner == source) {
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Packet looping back to %s (%s)!"), source->name, source->hostname);
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -347,7 +331,7 @@ static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet)
|
|||
via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
|
||||
|
||||
if(via && packet->len > via->mtu && via != myself) {
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, _("Packet for %s (%s) length %d larger than MTU %d"), subnet->owner->name, subnet->owner->hostname, packet->len, via->mtu);
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, "Packet for %s (%s) length %d larger than MTU %d", subnet->owner->name, subnet->owner->hostname, packet->len, via->mtu);
|
||||
if(packet->data[20] & 0x40) {
|
||||
packet->len = via->mtu;
|
||||
route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED);
|
||||
|
@ -361,10 +345,7 @@ static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet)
|
|||
send_packet(subnet->owner, packet);
|
||||
}
|
||||
|
||||
static void route_ipv4(node_t *source, vpn_packet_t *packet)
|
||||
{
|
||||
cp();
|
||||
|
||||
static void route_ipv4(node_t *source, vpn_packet_t *packet) {
|
||||
if(!checklength(source, packet, ether_size + ip_size))
|
||||
return;
|
||||
|
||||
|
@ -380,8 +361,7 @@ static void route_ipv4(node_t *source, vpn_packet_t *packet)
|
|||
|
||||
/* RFC 2463 */
|
||||
|
||||
static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t type, uint8_t code)
|
||||
{
|
||||
static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t type, uint8_t code) {
|
||||
struct ip6_hdr ip6;
|
||||
struct icmp6_hdr icmp6 = {0};
|
||||
uint16_t checksum;
|
||||
|
@ -396,8 +376,6 @@ static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t
|
|||
if(ratelimit(3))
|
||||
return;
|
||||
|
||||
cp();
|
||||
|
||||
/* Swap Ethernet source and destination addresses */
|
||||
|
||||
swap_mac_addresses(packet);
|
||||
|
@ -461,19 +439,16 @@ static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t
|
|||
send_packet(source, packet);
|
||||
}
|
||||
|
||||
static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet)
|
||||
{
|
||||
static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet) {
|
||||
subnet_t *subnet;
|
||||
node_t *via;
|
||||
ipv6_t dest;
|
||||
|
||||
cp();
|
||||
|
||||
memcpy(&dest, &packet->data[38], sizeof dest);
|
||||
subnet = lookup_subnet_ipv6(&dest);
|
||||
|
||||
if(!subnet) {
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Cannot route packet from %s (%s): unknown IPv6 destination address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet from %s (%s): unknown IPv6 destination address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
|
||||
source->name, source->hostname,
|
||||
ntohs(dest.x[0]),
|
||||
ntohs(dest.x[1]),
|
||||
|
@ -489,7 +464,7 @@ static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet)
|
|||
}
|
||||
|
||||
if(subnet->owner == source) {
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Packet looping back to %s (%s)!"), source->name, source->hostname);
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -499,7 +474,7 @@ static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet)
|
|||
via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
|
||||
|
||||
if(via && packet->len > via->mtu && via != myself) {
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, _("Packet for %s (%s) length %d larger than MTU %d"), subnet->owner->name, subnet->owner->hostname, packet->len, via->mtu);
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, "Packet for %s (%s) length %d larger than MTU %d", subnet->owner->name, subnet->owner->hostname, packet->len, via->mtu);
|
||||
packet->len = via->mtu;
|
||||
route_ipv6_unreachable(source, packet, ICMP6_PACKET_TOO_BIG, 0);
|
||||
return;
|
||||
|
@ -510,8 +485,7 @@ static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet)
|
|||
|
||||
/* RFC 2461 */
|
||||
|
||||
static void route_neighborsol(node_t *source, vpn_packet_t *packet)
|
||||
{
|
||||
static void route_neighborsol(node_t *source, vpn_packet_t *packet) {
|
||||
struct ip6_hdr ip6;
|
||||
struct nd_neighbor_solicit ns;
|
||||
struct nd_opt_hdr opt;
|
||||
|
@ -526,15 +500,13 @@ static void route_neighborsol(node_t *source, vpn_packet_t *packet)
|
|||
uint32_t next;
|
||||
} pseudo;
|
||||
|
||||
cp();
|
||||
|
||||
if(!checklength(source, packet, ether_size + ip6_size + ns_size))
|
||||
return;
|
||||
|
||||
has_opt = packet->len >= ether_size + ip6_size + ns_size + opt_size + ETH_ALEN;
|
||||
|
||||
if(source != myself) {
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Got neighbor solicitation request from %s (%s) while in router mode!"), source->name, source->hostname);
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Got neighbor solicitation request from %s (%s) while in router mode!", source->name, source->hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -554,7 +526,7 @@ static void route_neighborsol(node_t *source, vpn_packet_t *packet)
|
|||
|
||||
if(ns.nd_ns_hdr.icmp6_type != ND_NEIGHBOR_SOLICIT ||
|
||||
(has_opt && opt.nd_opt_type != ND_OPT_SOURCE_LINKADDR)) {
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Cannot route packet: received unknown type neighbor solicitation request"));
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: received unknown type neighbor solicitation request");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -578,7 +550,7 @@ static void route_neighborsol(node_t *source, vpn_packet_t *packet)
|
|||
}
|
||||
|
||||
if(checksum) {
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Cannot route packet: checksum error for neighbor solicitation request"));
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: checksum error for neighbor solicitation request");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -587,7 +559,7 @@ static void route_neighborsol(node_t *source, vpn_packet_t *packet)
|
|||
subnet = lookup_subnet_ipv6((ipv6_t *) &ns.nd_ns_target);
|
||||
|
||||
if(!subnet) {
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Cannot route packet: neighbor solicitation request for unknown address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: neighbor solicitation request for unknown address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
|
||||
ntohs(((uint16_t *) &ns.nd_ns_target)[0]),
|
||||
ntohs(((uint16_t *) &ns.nd_ns_target)[1]),
|
||||
ntohs(((uint16_t *) &ns.nd_ns_target)[2]),
|
||||
|
@ -652,10 +624,7 @@ static void route_neighborsol(node_t *source, vpn_packet_t *packet)
|
|||
send_packet(source, packet);
|
||||
}
|
||||
|
||||
static void route_ipv6(node_t *source, vpn_packet_t *packet)
|
||||
{
|
||||
cp();
|
||||
|
||||
static void route_ipv6(node_t *source, vpn_packet_t *packet) {
|
||||
if(!checklength(source, packet, ether_size + ip6_size))
|
||||
return;
|
||||
|
||||
|
@ -672,19 +641,16 @@ static void route_ipv6(node_t *source, vpn_packet_t *packet)
|
|||
|
||||
/* RFC 826 */
|
||||
|
||||
static void route_arp(node_t *source, vpn_packet_t *packet)
|
||||
{
|
||||
static void route_arp(node_t *source, vpn_packet_t *packet) {
|
||||
struct ether_arp arp;
|
||||
subnet_t *subnet;
|
||||
struct in_addr addr;
|
||||
|
||||
cp();
|
||||
|
||||
if(!checklength(source, packet, ether_size + arp_size))
|
||||
return;
|
||||
|
||||
if(source != myself) {
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Got ARP request from %s (%s) while in router mode!"), source->name, source->hostname);
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Got ARP request from %s (%s) while in router mode!", source->name, source->hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -701,7 +667,7 @@ static void route_arp(node_t *source, vpn_packet_t *packet)
|
|||
|
||||
if(ntohs(arp.arp_hrd) != ARPHRD_ETHER || ntohs(arp.arp_pro) != ETH_P_IP ||
|
||||
arp.arp_hln != ETH_ALEN || arp.arp_pln != sizeof addr || ntohs(arp.arp_op) != ARPOP_REQUEST) {
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Cannot route packet: received unknown type ARP request"));
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: received unknown type ARP request");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -710,7 +676,7 @@ static void route_arp(node_t *source, vpn_packet_t *packet)
|
|||
subnet = lookup_subnet_ipv4((ipv4_t *) &arp.arp_tpa);
|
||||
|
||||
if(!subnet) {
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Cannot route packet: ARP request for unknown address %d.%d.%d.%d"),
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: ARP request for unknown address %d.%d.%d.%d",
|
||||
arp.arp_tpa[0], arp.arp_tpa[1], arp.arp_tpa[2],
|
||||
arp.arp_tpa[3]);
|
||||
return;
|
||||
|
@ -739,14 +705,10 @@ static void route_arp(node_t *source, vpn_packet_t *packet)
|
|||
send_packet(source, packet);
|
||||
}
|
||||
|
||||
static void route_mac(node_t *source, vpn_packet_t *packet)
|
||||
{
|
||||
static void route_mac(node_t *source, vpn_packet_t *packet) {
|
||||
subnet_t *subnet;
|
||||
mac_t dest;
|
||||
|
||||
cp();
|
||||
|
||||
|
||||
/* Learn source address */
|
||||
|
||||
if(source == myself) {
|
||||
|
@ -766,7 +728,7 @@ static void route_mac(node_t *source, vpn_packet_t *packet)
|
|||
}
|
||||
|
||||
if(subnet->owner == source) {
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Packet looping back to %s (%s)!"), source->name, source->hostname);
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -775,7 +737,7 @@ static void route_mac(node_t *source, vpn_packet_t *packet)
|
|||
node_t *via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
|
||||
|
||||
if(via && packet->len > via->mtu && via != myself) {
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, _("Packet for %s (%s) length %d larger than MTU %d"), subnet->owner->name, subnet->owner->hostname, packet->len, via->mtu);
|
||||
ifdebug(TRAFFIC) logger(LOG_INFO, "Packet for %s (%s) length %d larger than MTU %d", subnet->owner->name, subnet->owner->hostname, packet->len, via->mtu);
|
||||
uint16_t type = packet->data[12] << 8 | packet->data[13];
|
||||
if(type == ETH_P_IP) {
|
||||
if(packet->data[20] & 0x40) {
|
||||
|
@ -795,11 +757,7 @@ static void route_mac(node_t *source, vpn_packet_t *packet)
|
|||
send_packet(subnet->owner, packet);
|
||||
}
|
||||
|
||||
|
||||
void route(node_t *source, vpn_packet_t *packet)
|
||||
{
|
||||
cp();
|
||||
|
||||
void route(node_t *source, vpn_packet_t *packet) {
|
||||
if(!checklength(source, packet, ether_size))
|
||||
return;
|
||||
|
||||
|
@ -822,7 +780,7 @@ void route(node_t *source, vpn_packet_t *packet)
|
|||
break;
|
||||
|
||||
default:
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, _("Cannot route packet from %s (%s): unknown type %hx"), source->name, source->hostname, type);
|
||||
ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet from %s (%s): unknown type %hx", source->name, source->hostname, type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
10
src/route.h
10
src/route.h
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
route.h -- header file for route.c
|
||||
Copyright (C) 2000-2005 Ivo Timmermans <zarq@iname.com>
|
||||
Copyright (C) 2000-2005 Ivo Timmermans
|
||||
2000-2006 Guus Sliepen <guus@tinc-vpn.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_ROUTE_H__
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
|
||||
|
@ -48,13 +46,11 @@ bool setup_device(void) {
|
|||
int ppa;
|
||||
char *ptr;
|
||||
|
||||
cp();
|
||||
|
||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
||||
device = xstrdup(DEFAULT_DEVICE);
|
||||
|
||||
if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
|
||||
logger(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
|
||||
logger(LOG_ERR, "Could not open %s: %s", device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -66,51 +62,49 @@ bool setup_device(void) {
|
|||
ppa = atoi(ptr);
|
||||
|
||||
if((ip_fd = open("/dev/ip", O_RDWR, 0)) < 0) {
|
||||
logger(LOG_ERR, _("Could not open /dev/ip: %s"), strerror(errno));
|
||||
logger(LOG_ERR, "Could not open /dev/ip: %s", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Assign a new PPA and get its unit number. */
|
||||
if((ppa = ioctl(device_fd, TUNNEWPPA, ppa)) < 0) {
|
||||
logger(LOG_ERR, _("Can't assign new interface: %s"), strerror(errno));
|
||||
logger(LOG_ERR, "Can't assign new interface: %s", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if((if_fd = open(device, O_RDWR, 0)) < 0) {
|
||||
logger(LOG_ERR, _("Could not open %s twice: %s"), device,
|
||||
logger(LOG_ERR, "Could not open %s twice: %s", device,
|
||||
strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(ioctl(if_fd, I_PUSH, "ip") < 0) {
|
||||
logger(LOG_ERR, _("Can't push IP module: %s"), strerror(errno));
|
||||
logger(LOG_ERR, "Can't push IP module: %s", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Assign ppa according to the unit number returned by tun device */
|
||||
if(ioctl(if_fd, IF_UNITSEL, (char *) &ppa) < 0) {
|
||||
logger(LOG_ERR, _("Can't set PPA %d: %s"), ppa, strerror(errno));
|
||||
logger(LOG_ERR, "Can't set PPA %d: %s", ppa, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(ioctl(ip_fd, I_LINK, if_fd) < 0) {
|
||||
logger(LOG_ERR, _("Can't link TUN device to IP: %s"), strerror(errno));
|
||||
logger(LOG_ERR, "Can't link TUN device to IP: %s", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
|
||||
xasprintf(&iface, "tun%d", ppa);
|
||||
|
||||
device_info = _("Solaris tun device");
|
||||
device_info = "Solaris tun device";
|
||||
|
||||
logger(LOG_INFO, _("%s is a %s"), device, device_info);
|
||||
logger(LOG_INFO, "%s is a %s", device, device_info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void close_device(void) {
|
||||
cp();
|
||||
|
||||
close(device_fd);
|
||||
|
||||
free(device);
|
||||
|
@ -120,10 +114,8 @@ void close_device(void) {
|
|||
bool read_packet(vpn_packet_t *packet) {
|
||||
int inlen;
|
||||
|
||||
cp();
|
||||
|
||||
if((inlen = read(device_fd, packet->data + 14, MTU - 14)) <= 0) {
|
||||
logger(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Error while reading from %s %s: %s", device_info,
|
||||
device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -148,20 +140,18 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
|
||||
device_total_in += packet->len;
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Read packet of %d bytes from %s", packet->len,
|
||||
device_info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool write_packet(vpn_packet_t *packet) {
|
||||
cp();
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Writing packet of %d bytes to %s",
|
||||
packet->len, device_info);
|
||||
|
||||
if(write(device_fd, packet->data + 14, packet->len - 14) < 0) {
|
||||
logger(LOG_ERR, _("Can't write to %s %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Can't write to %s %s: %s", device_info,
|
||||
device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -172,9 +162,7 @@ bool write_packet(vpn_packet_t *packet) {
|
|||
}
|
||||
|
||||
void dump_device_stats(void) {
|
||||
cp();
|
||||
|
||||
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
|
||||
logger(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
|
||||
logger(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
|
||||
logger(LOG_DEBUG, "Statistics for %s %s:", device_info, device);
|
||||
logger(LOG_DEBUG, " total bytes in: %10d", device_total_in);
|
||||
logger(LOG_DEBUG, " total bytes out: %10d", device_total_out);
|
||||
}
|
||||
|
|
105
src/subnet.c
105
src/subnet.c
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -56,8 +54,7 @@ void subnet_cache_flush() {
|
|||
|
||||
/* Subnet comparison */
|
||||
|
||||
static int subnet_compare_mac(const subnet_t *a, const subnet_t *b)
|
||||
{
|
||||
static int subnet_compare_mac(const subnet_t *a, const subnet_t *b) {
|
||||
int result;
|
||||
|
||||
result = memcmp(&a->net.mac.address, &b->net.mac.address, sizeof a->net.mac.address);
|
||||
|
@ -73,8 +70,7 @@ static int subnet_compare_mac(const subnet_t *a, const subnet_t *b)
|
|||
return strcmp(a->owner->name, b->owner->name);
|
||||
}
|
||||
|
||||
static int subnet_compare_ipv4(const subnet_t *a, const subnet_t *b)
|
||||
{
|
||||
static int subnet_compare_ipv4(const subnet_t *a, const subnet_t *b) {
|
||||
int result;
|
||||
|
||||
result = b->net.ipv4.prefixlength - a->net.ipv4.prefixlength;
|
||||
|
@ -95,8 +91,7 @@ static int subnet_compare_ipv4(const subnet_t *a, const subnet_t *b)
|
|||
return strcmp(a->owner->name, b->owner->name);
|
||||
}
|
||||
|
||||
static int subnet_compare_ipv6(const subnet_t *a, const subnet_t *b)
|
||||
{
|
||||
static int subnet_compare_ipv6(const subnet_t *a, const subnet_t *b) {
|
||||
int result;
|
||||
|
||||
result = b->net.ipv6.prefixlength - a->net.ipv6.prefixlength;
|
||||
|
@ -117,8 +112,7 @@ static int subnet_compare_ipv6(const subnet_t *a, const subnet_t *b)
|
|||
return strcmp(a->owner->name, b->owner->name);
|
||||
}
|
||||
|
||||
int subnet_compare(const subnet_t *a, const subnet_t *b)
|
||||
{
|
||||
int subnet_compare(const subnet_t *a, const subnet_t *b) {
|
||||
int result;
|
||||
|
||||
result = a->type - b->type;
|
||||
|
@ -134,9 +128,8 @@ int subnet_compare(const subnet_t *a, const subnet_t *b)
|
|||
case SUBNET_IPV6:
|
||||
return subnet_compare_ipv6(a, b);
|
||||
default:
|
||||
logger(LOG_ERR, _("subnet_compare() was called with unknown subnet type %d, exitting!"),
|
||||
logger(LOG_ERR, "subnet_compare() was called with unknown subnet type %d, exitting!",
|
||||
a->type);
|
||||
cp_trace();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -145,58 +138,37 @@ int subnet_compare(const subnet_t *a, const subnet_t *b)
|
|||
|
||||
/* Initialising trees */
|
||||
|
||||
void init_subnets(void)
|
||||
{
|
||||
cp();
|
||||
|
||||
void init_subnets(void) {
|
||||
subnet_tree = splay_alloc_tree((splay_compare_t) subnet_compare, (splay_action_t) free_subnet);
|
||||
|
||||
subnet_cache_flush();
|
||||
}
|
||||
|
||||
void exit_subnets(void)
|
||||
{
|
||||
cp();
|
||||
|
||||
void exit_subnets(void) {
|
||||
splay_delete_tree(subnet_tree);
|
||||
}
|
||||
|
||||
splay_tree_t *new_subnet_tree(void)
|
||||
{
|
||||
cp();
|
||||
|
||||
splay_tree_t *new_subnet_tree(void) {
|
||||
return splay_alloc_tree((splay_compare_t) subnet_compare, NULL);
|
||||
}
|
||||
|
||||
void free_subnet_tree(splay_tree_t *subnet_tree)
|
||||
{
|
||||
cp();
|
||||
|
||||
void free_subnet_tree(splay_tree_t *subnet_tree) {
|
||||
splay_delete_tree(subnet_tree);
|
||||
}
|
||||
|
||||
/* Allocating and freeing space for subnets */
|
||||
|
||||
subnet_t *new_subnet(void)
|
||||
{
|
||||
cp();
|
||||
|
||||
subnet_t *new_subnet(void) {
|
||||
return xmalloc_and_zero(sizeof(subnet_t));
|
||||
}
|
||||
|
||||
void free_subnet(subnet_t *subnet)
|
||||
{
|
||||
cp();
|
||||
|
||||
void free_subnet(subnet_t *subnet) {
|
||||
free(subnet);
|
||||
}
|
||||
|
||||
/* Adding and removing subnets */
|
||||
|
||||
void subnet_add(node_t *n, subnet_t *subnet)
|
||||
{
|
||||
cp();
|
||||
|
||||
void subnet_add(node_t *n, subnet_t *subnet) {
|
||||
subnet->owner = n;
|
||||
|
||||
splay_insert(subnet_tree, subnet);
|
||||
|
@ -205,10 +177,7 @@ void subnet_add(node_t *n, subnet_t *subnet)
|
|||
subnet_cache_flush();
|
||||
}
|
||||
|
||||
void subnet_del(node_t *n, subnet_t *subnet)
|
||||
{
|
||||
cp();
|
||||
|
||||
void subnet_del(node_t *n, subnet_t *subnet) {
|
||||
splay_delete(n->subnet_tree, subnet);
|
||||
splay_delete(subnet_tree, subnet);
|
||||
|
||||
|
@ -217,14 +186,11 @@ void subnet_del(node_t *n, subnet_t *subnet)
|
|||
|
||||
/* Ascii representation of subnets */
|
||||
|
||||
bool str2net(subnet_t *subnet, const char *subnetstr)
|
||||
{
|
||||
bool str2net(subnet_t *subnet, const char *subnetstr) {
|
||||
int i, l;
|
||||
uint16_t x[8];
|
||||
int weight = 10;
|
||||
|
||||
cp();
|
||||
|
||||
if(sscanf(subnetstr, "%hu.%hu.%hu.%hu/%d#%d",
|
||||
&x[0], &x[1], &x[2], &x[3], &l, &weight) >= 5) {
|
||||
if(l < 0 || l > 32)
|
||||
|
@ -299,12 +265,9 @@ bool str2net(subnet_t *subnet, const char *subnetstr)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool net2str(char *netstr, int len, const subnet_t *subnet)
|
||||
{
|
||||
cp();
|
||||
|
||||
bool net2str(char *netstr, int len, const subnet_t *subnet) {
|
||||
if(!netstr || !subnet) {
|
||||
logger(LOG_ERR, _("net2str() was called with netstr=%p, subnet=%p!\n"), netstr, subnet);
|
||||
logger(LOG_ERR, "net2str() was called with netstr=%p, subnet=%p!\n", netstr, subnet);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -346,9 +309,8 @@ bool net2str(char *netstr, int len, const subnet_t *subnet)
|
|||
|
||||
default:
|
||||
logger(LOG_ERR,
|
||||
_("net2str() was called with unknown subnet type %d, exiting!"),
|
||||
"net2str() was called with unknown subnet type %d, exiting!",
|
||||
subnet->type);
|
||||
cp_trace();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -357,19 +319,13 @@ bool net2str(char *netstr, int len, const subnet_t *subnet)
|
|||
|
||||
/* Subnet lookup routines */
|
||||
|
||||
subnet_t *lookup_subnet(const node_t *owner, const subnet_t *subnet)
|
||||
{
|
||||
cp();
|
||||
|
||||
subnet_t *lookup_subnet(const node_t *owner, const subnet_t *subnet) {
|
||||
return splay_search(owner->subnet_tree, subnet);
|
||||
}
|
||||
|
||||
subnet_t *lookup_subnet_mac(const mac_t *address)
|
||||
{
|
||||
subnet_t *lookup_subnet_mac(const mac_t *address) {
|
||||
subnet_t *p, subnet = {0};
|
||||
|
||||
cp();
|
||||
|
||||
subnet.type = SUBNET_MAC;
|
||||
subnet.net.mac.address = *address;
|
||||
subnet.owner = NULL;
|
||||
|
@ -379,14 +335,11 @@ subnet_t *lookup_subnet_mac(const mac_t *address)
|
|||
return p;
|
||||
}
|
||||
|
||||
subnet_t *lookup_subnet_ipv4(const ipv4_t *address)
|
||||
{
|
||||
subnet_t *lookup_subnet_ipv4(const ipv4_t *address) {
|
||||
subnet_t *p, *r = NULL, subnet = {0};
|
||||
splay_node_t *n;
|
||||
int i;
|
||||
|
||||
cp();
|
||||
|
||||
// Check if this address is cached
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
|
@ -426,14 +379,11 @@ subnet_t *lookup_subnet_ipv4(const ipv4_t *address)
|
|||
return r;
|
||||
}
|
||||
|
||||
subnet_t *lookup_subnet_ipv6(const ipv6_t *address)
|
||||
{
|
||||
subnet_t *lookup_subnet_ipv6(const ipv6_t *address) {
|
||||
subnet_t *p, *r = NULL, subnet = {0};
|
||||
splay_node_t *n;
|
||||
int i;
|
||||
|
||||
cp();
|
||||
|
||||
// Check if this address is cached
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
|
@ -540,19 +490,16 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) {
|
|||
free(envp[i]);
|
||||
}
|
||||
|
||||
int dump_subnets(struct evbuffer *out)
|
||||
{
|
||||
int dump_subnets(struct evbuffer *out) {
|
||||
char netstr[MAXNETSTR];
|
||||
subnet_t *subnet;
|
||||
splay_node_t *node;
|
||||
|
||||
cp();
|
||||
|
||||
for(node = subnet_tree->head; node; node = node->next) {
|
||||
subnet = node->data;
|
||||
if(!net2str(netstr, sizeof netstr, subnet))
|
||||
continue;
|
||||
if(evbuffer_add_printf(out, _(" %s owner %s\n"),
|
||||
if(evbuffer_add_printf(out, " %s owner %s\n",
|
||||
netstr, subnet->owner->name) == -1)
|
||||
return errno;
|
||||
}
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_SUBNET_H__
|
||||
|
|
73
src/tincd.c
73
src/tincd.c
|
@ -2,6 +2,8 @@
|
|||
tincd.c -- the main file for tincd
|
||||
Copyright (C) 1998-2005 Ivo Timmermans
|
||||
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
|
||||
2008 Max Rijevski <maksuf@gmail.com>
|
||||
2009 Michael Tokarev <mjt@tls.msk.ru>
|
||||
|
||||
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
|
||||
|
@ -13,11 +15,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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$
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -105,14 +105,13 @@ static struct WSAData wsa_state;
|
|||
CRITICAL_SECTION mutex;
|
||||
#endif
|
||||
|
||||
static void usage(bool status)
|
||||
{
|
||||
static void usage(bool status) {
|
||||
if(status)
|
||||
fprintf(stderr, _("Try `%s --help\' for more information.\n"),
|
||||
fprintf(stderr, "Try `%s --help\' for more information.\n",
|
||||
program_name);
|
||||
else {
|
||||
printf(_("Usage: %s [option]...\n\n"), program_name);
|
||||
printf(_( " -c, --config=DIR Read configuration options from DIR.\n"
|
||||
printf("Usage: %s [option]...\n\n", program_name);
|
||||
printf( " -c, --config=DIR Read configuration options from DIR.\n"
|
||||
" -D, --no-detach Don't fork and detach.\n"
|
||||
" -d, --debug[=LEVEL] Increase debug level or set it to LEVEL.\n"
|
||||
" -n, --net=NETNAME Connect to net NETNAME.\n"
|
||||
|
@ -122,13 +121,12 @@ static void usage(bool status)
|
|||
" --bypass-security Disables meta protocol security, for debugging.\n"
|
||||
" -R, --chroot chroot to NET dir at startup.\n"
|
||||
" -U, --user=USER setuid to given USER at startup.\n" " --help Display this help and exit.\n"
|
||||
" --version Output version information and exit.\n\n"));
|
||||
printf(_("Report bugs to tinc@tinc-vpn.org.\n"));
|
||||
" --version Output version information and exit.\n\n");
|
||||
printf("Report bugs to tinc@tinc-vpn.org.\n");
|
||||
}
|
||||
}
|
||||
|
||||
static bool parse_options(int argc, char **argv)
|
||||
{
|
||||
static bool parse_options(int argc, char **argv) {
|
||||
int r;
|
||||
int option_index = 0;
|
||||
|
||||
|
@ -147,7 +145,7 @@ static bool parse_options(int argc, char **argv)
|
|||
|
||||
case 'L': /* no detach */
|
||||
#ifndef HAVE_MLOCKALL
|
||||
logger(LOG_ERR, _("%s not supported on this platform"), "mlockall()");
|
||||
logger(LOG_ERR, "%s not supported on this platform", "mlockall()");
|
||||
return false;
|
||||
#else
|
||||
do_mlock = true;
|
||||
|
@ -210,8 +208,7 @@ static bool parse_options(int argc, char **argv)
|
|||
/*
|
||||
Set all files and paths according to netname
|
||||
*/
|
||||
static void make_names(void)
|
||||
{
|
||||
static void make_names(void) {
|
||||
#ifdef HAVE_MINGW
|
||||
HKEY key;
|
||||
char installdir[1024] = "";
|
||||
|
@ -251,7 +248,7 @@ static void make_names(void)
|
|||
if(!confbase)
|
||||
xasprintf(&confbase, CONFDIR "/tinc/%s", netname);
|
||||
else
|
||||
logger(LOG_INFO, _("Both netname and configuration directory given, using the latter..."));
|
||||
logger(LOG_INFO, "Both netname and configuration directory given, using the latter...");
|
||||
} else {
|
||||
if(!confbase)
|
||||
xasprintf(&confbase, CONFDIR "/tinc");
|
||||
|
@ -269,11 +266,11 @@ static void free_names() {
|
|||
static bool drop_privs() {
|
||||
#ifdef HAVE_MINGW
|
||||
if (switchuser) {
|
||||
logger(LOG_ERR, _("%s not supported on this platform"), "-U");
|
||||
logger(LOG_ERR, "%s not supported on this platform", "-U");
|
||||
return false;
|
||||
}
|
||||
if (do_chroot) {
|
||||
logger(LOG_ERR, _("%s not supported on this platform"), "-R");
|
||||
logger(LOG_ERR, "%s not supported on this platform", "-R");
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
|
@ -281,13 +278,13 @@ static bool drop_privs() {
|
|||
if (switchuser) {
|
||||
struct passwd *pw = getpwnam(switchuser);
|
||||
if (!pw) {
|
||||
logger(LOG_ERR, _("unknown user `%s'"), switchuser);
|
||||
logger(LOG_ERR, "unknown user `%s'", switchuser);
|
||||
return false;
|
||||
}
|
||||
uid = pw->pw_uid;
|
||||
if (initgroups(switchuser, pw->pw_gid) != 0 ||
|
||||
setgid(pw->pw_gid) != 0) {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"),
|
||||
logger(LOG_ERR, "System call `%s' failed: %s",
|
||||
"initgroups", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -297,7 +294,7 @@ static bool drop_privs() {
|
|||
if (do_chroot) {
|
||||
tzset(); /* for proper timestamps in logs */
|
||||
if (chroot(confbase) != 0 || chdir("/") != 0) {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"),
|
||||
logger(LOG_ERR, "System call `%s' failed: %s",
|
||||
"chroot", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -306,7 +303,7 @@ static bool drop_privs() {
|
|||
}
|
||||
if (switchuser)
|
||||
if (setuid(uid) != 0) {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"),
|
||||
logger(LOG_ERR, "System call `%s' failed: %s",
|
||||
"setuid", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -323,27 +320,22 @@ static bool drop_privs() {
|
|||
# define setpriority(level) nice(level)
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
program_name = argv[0];
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
|
||||
if(!parse_options(argc, argv))
|
||||
return 1;
|
||||
|
||||
make_names();
|
||||
|
||||
if(show_version) {
|
||||
printf(_("%s version %s (built %s %s, protocol %d)\n"), PACKAGE,
|
||||
printf("%s version %s (built %s %s, protocol %d)\n", PACKAGE,
|
||||
VERSION, __DATE__, __TIME__, PROT_CURRENT);
|
||||
printf(_("Copyright (C) 1998-2009 Ivo Timmermans, Guus Sliepen and others.\n"
|
||||
printf("Copyright (C) 1998-2009 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"));
|
||||
"see the file COPYING for details.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -356,7 +348,7 @@ int main(int argc, char **argv)
|
|||
openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR);
|
||||
|
||||
if(!event_init()) {
|
||||
logger(LOG_ERR, _("Error initializing libevent!"));
|
||||
logger(LOG_ERR, "Error initializing libevent!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -376,13 +368,13 @@ int main(int argc, char **argv)
|
|||
return 1;
|
||||
|
||||
if(lzo_init() != LZO_E_OK) {
|
||||
logger(LOG_ERR, _("Error initializing LZO compressor!"));
|
||||
logger(LOG_ERR, "Error initializing LZO compressor!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef HAVE_MINGW
|
||||
if(WSAStartup(MAKEWORD(2, 2), &wsa_state)) {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "WSAStartup", winerror(GetLastError()));
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "WSAStartup", winerror(GetLastError()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -392,8 +384,7 @@ int main(int argc, char **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int main2(int argc, char **argv)
|
||||
{
|
||||
int main2(int argc, char **argv) {
|
||||
InitializeCriticalSection(&mutex);
|
||||
EnterCriticalSection(&mutex);
|
||||
#endif
|
||||
|
@ -406,7 +397,7 @@ int main2(int argc, char **argv)
|
|||
* This has to be done after daemon()/fork() so it works for child.
|
||||
* No need to do that in parent as it's very short-lived. */
|
||||
if(do_mlock && mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "mlockall",
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "mlockall",
|
||||
strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
@ -433,7 +424,7 @@ int main2(int argc, char **argv)
|
|||
else if(!strcasecmp(priority, "High"))
|
||||
setpriority(HIGH_PRIORITY_CLASS);
|
||||
else {
|
||||
logger(LOG_ERR, _("Invalid priority `%s`!"), priority);
|
||||
logger(LOG_ERR, "Invalid priority `%s`!", priority);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
@ -454,7 +445,7 @@ int main2(int argc, char **argv)
|
|||
close_network_connections();
|
||||
|
||||
end:
|
||||
logger(LOG_NOTICE, _("Terminating"));
|
||||
logger(LOG_NOTICE, "Terminating");
|
||||
|
||||
#ifndef HAVE_MINGW
|
||||
exit_control();
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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: device.c 1374 2004-03-21 14:21:22Z guus $
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
@ -67,17 +65,15 @@ bool setup_device(void) {
|
|||
} name;
|
||||
struct timeval tv;
|
||||
|
||||
cp();
|
||||
|
||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
||||
xasprintf(&device, LOCALSTATEDIR "/run/%s.umlsocket", identname);
|
||||
|
||||
get_config_string(lookup_config(config_tree, "Interface"), &iface);
|
||||
|
||||
device_info = _("UML network socket");
|
||||
device_info = "UML network socket";
|
||||
|
||||
if((write_fd = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) {
|
||||
logger(LOG_ERR, _("Could not open write %s: %s"), device_info, strerror(errno));
|
||||
logger(LOG_ERR, "Could not open write %s: %s", device_info, strerror(errno));
|
||||
running = false;
|
||||
return false;
|
||||
}
|
||||
|
@ -85,13 +81,13 @@ bool setup_device(void) {
|
|||
setsockopt(write_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one);
|
||||
|
||||
if(fcntl(write_fd, F_SETFL, O_NONBLOCK) < 0) {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "fcntl", strerror(errno));
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
|
||||
running = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if((data_fd = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) {
|
||||
logger(LOG_ERR, _("Could not open data %s: %s"), device_info, strerror(errno));
|
||||
logger(LOG_ERR, "Could not open data %s: %s", device_info, strerror(errno));
|
||||
running = false;
|
||||
return false;
|
||||
}
|
||||
|
@ -99,7 +95,7 @@ bool setup_device(void) {
|
|||
setsockopt(data_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one);
|
||||
|
||||
if(fcntl(data_fd, F_SETFL, O_NONBLOCK) < 0) {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "fcntl", strerror(errno));
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
|
||||
running = false;
|
||||
return false;
|
||||
}
|
||||
|
@ -112,13 +108,13 @@ bool setup_device(void) {
|
|||
memcpy(&data_sun.sun_path, &name, sizeof name);
|
||||
|
||||
if(bind(data_fd, (struct sockaddr *)&data_sun, sizeof data_sun) < 0) {
|
||||
logger(LOG_ERR, _("Could not bind data %s: %s"), device_info, strerror(errno));
|
||||
logger(LOG_ERR, "Could not bind data %s: %s", device_info, strerror(errno));
|
||||
running = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if((listen_fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||
logger(LOG_ERR, _("Could not open %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Could not open %s: %s", device_info,
|
||||
strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
@ -126,26 +122,26 @@ bool setup_device(void) {
|
|||
setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one);
|
||||
|
||||
if(fcntl(listen_fd, F_SETFL, O_NONBLOCK) < 0) {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "fcntl", strerror(errno));
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
listen_sun.sun_family = AF_UNIX;
|
||||
strncpy(listen_sun.sun_path, device, sizeof listen_sun.sun_path);
|
||||
if(bind(listen_fd, (struct sockaddr *)&listen_sun, sizeof listen_sun) < 0) {
|
||||
logger(LOG_ERR, _("Could not bind %s to %s: %s"), device_info, device, strerror(errno));
|
||||
logger(LOG_ERR, "Could not bind %s to %s: %s", device_info, device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(listen(listen_fd, 1) < 0) {
|
||||
logger(LOG_ERR, _("Could not listen on %s %s: %s"), device_info, device, strerror(errno));
|
||||
logger(LOG_ERR, "Could not listen on %s %s: %s", device_info, device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
device_fd = listen_fd;
|
||||
state = 0;
|
||||
|
||||
logger(LOG_INFO, _("%s is a %s"), device, device_info);
|
||||
logger(LOG_INFO, "%s is a %s", device, device_info);
|
||||
|
||||
if(routing_mode == RMODE_ROUTER)
|
||||
overwrite_mac = true;
|
||||
|
@ -154,8 +150,6 @@ bool setup_device(void) {
|
|||
}
|
||||
|
||||
void close_device(void) {
|
||||
cp();
|
||||
|
||||
if(listen_fd >= 0)
|
||||
close(listen_fd);
|
||||
|
||||
|
@ -177,8 +171,6 @@ void close_device(void) {
|
|||
bool read_packet(vpn_packet_t *packet) {
|
||||
int inlen;
|
||||
|
||||
cp();
|
||||
|
||||
switch(state) {
|
||||
case 0: {
|
||||
struct sockaddr sa;
|
||||
|
@ -186,12 +178,12 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
|
||||
request_fd = accept(listen_fd, &sa, &salen);
|
||||
if(request_fd < 0) {
|
||||
logger(LOG_ERR, _("Could not accept connection to %s %s: %s"), device_info, device, strerror(errno));
|
||||
logger(LOG_ERR, "Could not accept connection to %s %s: %s", device_info, device, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(fcntl(listen_fd, F_SETFL, O_NONBLOCK) < 0) {
|
||||
logger(LOG_ERR, _("System call `%s' failed: %s"), "fcntl", strerror(errno));
|
||||
logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno));
|
||||
running = false;
|
||||
return false;
|
||||
}
|
||||
|
@ -206,21 +198,21 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
|
||||
case 1: {
|
||||
if((inlen = read(request_fd, &request, sizeof request)) != sizeof request) {
|
||||
logger(LOG_ERR, _("Error while reading request from %s %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Error while reading request from %s %s: %s", device_info,
|
||||
device, strerror(errno));
|
||||
running = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(request.magic != 0xfeedface || request.version != 3 || request.type != REQ_NEW_CONTROL) {
|
||||
logger(LOG_ERR, _("Unknown magic %x, version %d, request type %d from %s %s"),
|
||||
logger(LOG_ERR, "Unknown magic %x, version %d, request type %d from %s %s",
|
||||
request.magic, request.version, request.type, device_info, device);
|
||||
running = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(connect(write_fd, &request.sock, sizeof request.sock) < 0) {
|
||||
logger(LOG_ERR, _("Could not bind write %s: %s"), device_info, strerror(errno));
|
||||
logger(LOG_ERR, "Could not bind write %s: %s", device_info, strerror(errno));
|
||||
running = false;
|
||||
return false;
|
||||
}
|
||||
|
@ -228,7 +220,7 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
write(request_fd, &data_sun, sizeof data_sun);
|
||||
device_fd = data_fd;
|
||||
|
||||
logger(LOG_INFO, _("Connection with UML established"));
|
||||
logger(LOG_INFO, "Connection with UML established");
|
||||
|
||||
state = 2;
|
||||
return false;
|
||||
|
@ -236,7 +228,7 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
|
||||
case 2: {
|
||||
if((inlen = read(data_fd, packet->data, MTU)) <= 0) {
|
||||
logger(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
|
||||
logger(LOG_ERR, "Error while reading from %s %s: %s", device_info,
|
||||
device, strerror(errno));
|
||||
running = false;
|
||||
return false;
|
||||
|
@ -246,7 +238,7 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
|
||||
device_total_in += packet->len;
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Read packet of %d bytes from %s", packet->len,
|
||||
device_info);
|
||||
|
||||
return true;
|
||||
|
@ -255,20 +247,18 @@ bool read_packet(vpn_packet_t *packet) {
|
|||
}
|
||||
|
||||
bool write_packet(vpn_packet_t *packet) {
|
||||
cp();
|
||||
|
||||
if(state != 2) {
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Dropping packet of %d bytes to %s: not connected to UML yet"),
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Dropping packet of %d bytes to %s: not connected to UML yet",
|
||||
packet->len, device_info);
|
||||
return false;
|
||||
}
|
||||
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
|
||||
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Writing packet of %d bytes to %s",
|
||||
packet->len, device_info);
|
||||
|
||||
if(write(write_fd, packet->data, packet->len) < 0) {
|
||||
if(errno != EINTR && errno != EAGAIN) {
|
||||
logger(LOG_ERR, _("Can't write to %s %s: %s"), device_info, device, strerror(errno));
|
||||
logger(LOG_ERR, "Can't write to %s %s: %s", device_info, device, strerror(errno));
|
||||
running = false;
|
||||
}
|
||||
|
||||
|
@ -281,9 +271,7 @@ bool write_packet(vpn_packet_t *packet) {
|
|||
}
|
||||
|
||||
void dump_device_stats(void) {
|
||||
cp();
|
||||
|
||||
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
|
||||
logger(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
|
||||
logger(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
|
||||
logger(LOG_DEBUG, "Statistics for %s %s:", device_info, device);
|
||||
logger(LOG_DEBUG, " total bytes in: %10d", device_total_in);
|
||||
logger(LOG_DEBUG, " total bytes out: %10d", device_total_out);
|
||||
}
|
||||
|
|
10
system.h
10
system.h
|
@ -13,9 +13,9 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __TINC_SYSTEM_H__
|
||||
|
@ -31,10 +31,6 @@ typedef int bool;
|
|||
#define false 0
|
||||
#endif
|
||||
|
||||
/* Include localisation support */
|
||||
|
||||
#include "gettext.h"
|
||||
|
||||
#ifndef HAVE_STRSIGNAL
|
||||
# define strsignal(p) ""
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue