+2010.02.16 -- Version 0.3.3
+
+* added -v|--version option
+* added prebuilt manpage to release tarball (less build deps)
+* added multi socket support which allows simultanous usage
+ of IPv4 and IPv6 even on operating systems without V4_MAPPED
+ address support
+
2009.12.02 -- Version 0.3.2
* clenaups and improvements at configure and install target of Makefile
Linux
-----
+(this includes Debian with FreeBSD Kernel)
using libgcrypt:
build-essential
libssl-dev
-only for manpage:
+if you want to rebuild the manpage:
asciidoc
devel/gmake
-only for manpage:
+if you want to rebuild the manpage:
textproc/asciidoc
textproc/libxslt
## tunneling and relaying of packets of any protocol.
##
##
-## Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+## Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
##
## This file is part of uAnytun.
##
manpage: uanytun.8
clean:
- rm -f uanytun.8 uanytun.8.xml
+ rm -f uanytun.8.xml
+
+realclean: clean
+ rm -f uanytun.8
--- /dev/null
+'\" t
+.\" Title: uanytun
+.\" Author: [see the "AUTHORS" section]
+.\" Generator: DocBook XSL Stylesheets v1.75.1 <http://docbook.sf.net/>
+.\" Date: 02/17/2010
+.\" Manual: uanytun user manual
+.\" Source: uanytun 0.3.3
+.\" Language: English
+.\"
+.TH "UANYTUN" "8" "02/17/2010" "uanytun 0.3.3" "uanytun user manual"
+.\" -----------------------------------------------------------------
+.\" * set default formatting
+.\" -----------------------------------------------------------------
+.\" disable hyphenation
+.nh
+.\" disable justification (adjust text to left margin only)
+.ad l
+.\" -----------------------------------------------------------------
+.\" * MAIN CONTENT STARTS HERE *
+.\" -----------------------------------------------------------------
+.SH "NAME"
+uanytun \- micro anycast tunneling daemon
+.SH "SYNOPSIS"
+.sp
+.nf
+\fBuanytun\fR
+ [ \fB\-h|\-\-help\fR ]
+ [ \fB\-D|\-\-nodaemonize\fR ]
+ [ \fB\-u|\-\-username\fR <username> ]
+ [ \fB\-g|\-\-groupname\fR <groupname> ]
+ [ \fB\-C|\-\-chroot\fR <path> ]
+ [ \fB\-P|\-\-write\-pid\fR <filename> ]
+ [ \fB\-L|\-\-log\fR <target>:<level>[,<param1>[,<param2>[\&.\&.]]] ]
+ [ \fB\-U|\-\-debug\fR ]
+ [ \fB\-i|\-\-interface\fR <ip\-address> ]
+ [ \fB\-p|\-\-port\fR <port> ]
+ [ \fB\-r|\-\-remote\-host\fR <hostname|ip> ]
+ [ \fB\-o|\-\-remote\-port\fR <port> ]
+ [ \fB\-4|\-\-ipv4\-only\fR ]
+ [ \fB\-6|\-\-ipv6\-only\fR ]
+ [ \fB\-d|\-\-dev\fR <name> ]
+ [ \fB\-t|\-\-type\fR <tun|tap> ]
+ [ \fB\-n|\-\-ifconfig\fR <local>/<prefix> ]
+ [ \fB\-x|\-\-post\-up\-script\fR <script> ]
+ [ \fB\-m|\-\-mux\fR <mux\-id> ]
+ [ \fB\-s|\-\-sender\-id\fR <sender id> ]
+ [ \fB\-w|\-\-window\-size\fR <window size> ]
+ [ \fB\-k|\-\-kd\-prf\fR <kd\-prf type> ]
+ [ \fB\-e|\-\-role\fR <role> ]
+ [ \fB\-E|\-\-passphrase\fR <pass phrase> ]
+ [ \fB\-K|\-\-key\fR <master key> ]
+ [ \fB\-A|\-\-salt\fR <master salt> ]
+ [ \fB\-c|\-\-cipher\fR <cipher type> ]
+ [ \fB\-a|\-\-auth\-algo\fR <algo type> ]
+ [ \fB\-b|\-\-auth\-tag\-length\fR <length> ]
+.fi
+.SH "DESCRIPTION"
+.sp
+\fBuAnytun\fR is a tiny implementation of the Secure Anycast Tunneling Protocol (SATP)\&. It provides a complete VPN solution similar to OpenVPN or IPsec in tunnel mode\&. The main difference is that anycast enables the setup of tunnels between an arbitrary combination of anycast, unicast and multicast hosts\&. Unlike Anytun which is a full featured implementation uAnytun has no support for multiple connections or synchronisation\&. It is a small single threaded implementation intended to act as a client on small platforms\&.
+.SH "OPTIONS"
+.sp
+\fBuAnytun\fR has been designed as a peer to peer application, so there is no difference between client and server\&. The following options can be passed to the daemon:
+.PP
+\fB\-D, \-\-nodaemonize\fR
+.RS 4
+This option instructs
+\fBuAnytun\fR
+to run in foreground instead of becoming a daemon which is the default\&.
+.RE
+.PP
+\fB\-u, \-\-username \fR\fB\fI<username>\fR\fR
+.RS 4
+run as this user\&. If no group is specified (\fB\-g\fR) the default group of the user is used\&. The default is to not drop privileges\&.
+.RE
+.PP
+\fB\-g, \-\-groupname \fR\fB\fI<groupname>\fR\fR
+.RS 4
+run as this group\&. If no username is specified (\fB\-u\fR) this gets ignored\&. The default is to not drop privileges\&.
+.RE
+.PP
+\fB\-C, \-\-chroot \fR\fB\fI<path>\fR\fR
+.RS 4
+Instruct
+\fBuAnytun\fR
+to run in a chroot jail\&. The default is to not run in chroot\&.
+.RE
+.PP
+\fB\-P, \-\-write\-pid <filename>\fR
+.RS 4
+Instruct
+\fBuAnytun\fR
+to write it\(cqs pid to this file\&. The default is to not create a pid file\&.
+.RE
+.PP
+\fB\-L, \-\-log \fR\fB\fI<target>:<level>[,<param1>[,<param2>[\&.\&.]]]\fR\fR
+.RS 4
+add log target to logging system\&. This can be invoked several times in order to log to different targets at the same time\&. Every target hast its own log level which is a number between 0 and 5\&. Where 0 means disabling log and 5 means debug messages are enabled\&.
+
+The file target can be used more the once with different levels\&. If no target is provided at the command line a single target with the config
+\fIsyslog:3,uanytun,daemon\fR
+is added\&.
+
+The following targets are supported:
+.PP
+\fIsyslog\fR
+.RS 4
+log to syslog daemon, parameters <level>[,<logname>[,<facility>]]
+.RE
+.PP
+\fIfile\fR
+.RS 4
+log to file, parameters <level>[,<path>]
+.RE
+.PP
+\fIstdout\fR
+.RS 4
+log to standard output, parameters <level>
+.RE
+.PP
+\fIstderr\fR
+.RS 4
+log to standard error, parameters <level>
+.RE
+.RE
+.PP
+\fB\-U, \-\-debug\fR
+.RS 4
+This option instructs
+\fBuAnytun\fR
+to run in debug mode\&. It implicits
+\fB\-D\fR
+(don\(cqt daemonize) and adds a log target with the configuration
+\fIstdout:5\fR
+(logging with maximum level)\&. In future releases there might be additional output when this option is supplied\&.
+.RE
+.PP
+\fB\-i, \-\-interface \fR\fB\fI<ip address>\fR\fR
+.RS 4
+This IP address is used as the sender address for outgoing packets\&. The default is to not use a special inteface and just bind on all interfaces\&.
+.RE
+.PP
+\fB\-p, \-\-port \fR\fB\fI<port>\fR\fR
+.RS 4
+The local UDP port that is used to send and receive the payload data\&. The two tunnel endpoints can use different ports\&. default: 4444
+.RE
+.PP
+\fB\-r, \-\-remote\-host \fR\fB\fI<hostname|ip>\fR\fR
+.RS 4
+This option can be used to specify the remote tunnel endpoint\&. In case of anycast tunnel endpoints, the anycast IP address has to be used\&. If you do not specify an address, it is automatically determined after receiving the first data packet\&.
+.RE
+.PP
+\fB\-o, \-\-remote\-port \fR\fB\fI<port>\fR\fR
+.RS 4
+The UDP port used for payload data by the remote host (specified with \-p on the remote host)\&. If you do not specify a port, it is automatically determined after receiving the first data packet\&.
+.RE
+.PP
+\fB\-4, \-\-ipv4\-only\fR
+.RS 4
+Resolv to IPv4 addresses only\&. The default is to resolv both IPv4 and IPv6 addresses\&.
+.RE
+.PP
+\fB\-6, \-\-ipv6\-only\fR
+.RS 4
+Resolv to IPv6 addresses only\&. The default is to resolv both IPv4 and IPv6 addresses\&.
+.RE
+.PP
+\fB\-d, \-\-dev \fR\fB\fI<name>\fR\fR
+.RS 4
+device name
+
+By default, tapN is used for Ethernet tunnel interfaces, and tunN for IP tunnels, respectively\&. This option can be used to manually override these defaults\&.
+.RE
+.PP
+\fB\-t, \-\-type \fR\fB\fI<tun|tap>\fR\fR
+.RS 4
+device type
+
+Type of the tunnels to create\&. Use tap for Ethernet tunnels, tun for IP tunnels\&.
+.RE
+.PP
+\fB\-n, \-\-ifconfig \fR\fB\fI<local>/<prefix>\fR\fR
+.RS 4
+The local IP address and prefix length\&. The remote tunnel endpoint has to use a different IP address in the same subnet\&.
+.PP
+\fI<local>\fR
+.RS 4
+the local IP address for the tun/tap device
+.RE
+.PP
+\fI<prefix>\fR
+.RS 4
+the prefix length of the network
+.RE
+.RE
+.PP
+\fB\-x, \-\-post\-up\-script \fR\fB\fI<script>\fR\fR
+.RS 4
+This option instructs
+\fBuAnytun\fR
+to run this script after the interface is created\&. By default no script will be executed\&.
+.RE
+.PP
+\fB\-m, \-\-mux \fR\fB\fI<mux\-id>\fR\fR
+.RS 4
+the multiplex id to use\&. default: 0
+.RE
+.PP
+\fB\-s, \-\-sender\-id \fR\fB\fI<sender id>\fR\fR
+.RS 4
+Each anycast tunnel endpoint needs a unique sender id (1, 2, 3, \&...)\&. It is needed to distinguish the senders in case of replay attacks\&. As
+\fBuAnytun\fR
+does not support synchronisation it can\(cqt be used as an anycast endpoint therefore this option is quite useless but implemented for compatibility reasons\&. default: 0
+.RE
+.PP
+\fB\-w, \-\-window\-size \fR\fB\fI<window size>\fR\fR
+.RS 4
+seqence window size
+
+Sometimes, packets arrive out of order on the receiver side\&. This option defines the size of a list of received packets\' sequence numbers\&. If, according to this list, a received packet has been previously received or has been transmitted in the past, and is therefore not in the list anymore, this is interpreted as a replay attack and the packet is dropped\&. A value of 0 deactivates this list and, as a consequence, the replay protection employed by filtering packets according to their secuence number\&. By default the sequence window is disabled and therefore a window size of 0 is used\&.
+.RE
+.PP
+\fB\-k, \-\-kd\(emprf \fR\fB\fI<kd\-prf type>\fR\fR
+.RS 4
+key derivation pseudo random function
+
+The pseudo random function which is used for calculating the session keys and session salt\&.
+
+Possible values:
+.PP
+\fInull\fR
+.RS 4
+no random function, keys and salt are set to 0\&.\&.00
+.RE
+.PP
+\fIaes\-ctr\fR
+.RS 4
+AES in counter mode with 128 Bits, default value
+.RE
+.PP
+\fIaes\-ctr\-128\fR
+.RS 4
+AES in counter mode with 128 Bits
+.RE
+.PP
+\fIaes\-ctr\-192\fR
+.RS 4
+AES in counter mode with 192 Bits
+.RE
+.PP
+\fIaes\-ctr\-256\fR
+.RS 4
+AES in counter mode with 256 Bits
+.RE
+.RE
+.PP
+\fB\-e, \-\-role \fR\fB\fI<role>\fR\fR
+.RS 4
+SATP uses different session keys for inbound and outbound traffic\&. The role parameter is used to determine which keys to use for outbound or inbound packets\&. On both sides of a vpn connection different roles have to be used\&. Possible values are
+\fIleft\fR
+and
+\fIright\fR\&. You may also use
+\fIalice\fR
+or
+\fIserver\fR
+as a replacement for
+\fIleft\fR
+and
+\fIbob\fR
+or
+\fIclient\fR
+as a replacement for
+\fIright\fR\&. By default
+\fIleft\fR
+is used\&.
+.RE
+.PP
+\fB\-E, \-\-passphrase \fR\fB\fI<pass phrase>\fR\fR
+.RS 4
+This passphrase is used to generate the master key and master salt\&. For the master key the last n bits of the SHA256 digest of the passphrase (where n is the length of the master key in bits) is used\&. The master salt gets generated with the SHA1 digest\&. You may force a specific key and or salt by using
+\fB\-\-key\fR
+and
+\fB\-\-salt\fR\&.
+.RE
+.PP
+\fB\-K, \-\-key \fR\fB\fI<master key>\fR\fR
+.RS 4
+master key to use for key derivation
+
+Master key in hexadecimal notation, e\&.g\&. 01a2b3c4d5e6f708a9b0cadbecfd0fa1, with a mandatory length of 32, 48 or 64 characters (128, 192 or 256 bits)\&.
+.RE
+.PP
+\fB\-A, \-\-salt \fR\fB\fI<master salt>\fR\fR
+.RS 4
+master salt to use for key derivation
+
+Master salt in hexadecimal notation, e\&.g\&. 01a2b3c4d5e6f708a9b0cadbecfd, with a mandatory length of 28 characters (14 bytes)\&.
+.RE
+.PP
+\fB\-c, \-\-cipher \fR\fB\fI<cipher type>\fR\fR
+.RS 4
+payload encryption algorithm
+
+Encryption algorithm used for encrypting the payload
+
+Possible values:
+.PP
+\fInull\fR
+.RS 4
+no encryption
+.RE
+.PP
+\fIaes\-ctr\fR
+.RS 4
+AES in counter mode with 128 Bits, default value
+.RE
+.PP
+\fIaes\-ctr\-128\fR
+.RS 4
+AES in counter mode with 128 Bits
+.RE
+.PP
+\fIaes\-ctr\-192\fR
+.RS 4
+AES in counter mode with 192 Bits
+.RE
+.PP
+\fIaes\-ctr\-256\fR
+.RS 4
+AES in counter mode with 256 Bits
+.RE
+.RE
+.PP
+\fB\-a, \-\-auth\-algo \fR\fB\fI<algo type>\fR\fR
+.RS 4
+message authentication algorithm
+
+This option sets the message authentication algorithm\&.
+
+If HMAC\-SHA1 is used, the packet length is increased\&. The additional bytes contain the authentication data\&. see
+\fB\-\-auth\-tag\-length\fR
+for more info\&.
+
+Possible values:
+.PP
+\fInull\fR
+.RS 4
+no message authentication
+.RE
+.PP
+\fIsha1\fR
+.RS 4
+HMAC\-SHA1, default value
+.RE
+.RE
+.PP
+\fB\-b, \-\-auth\-tag\-length \fR\fB\fI<length>\fR\fR
+.RS 4
+The number of bytes to use for the auth tag\&. This value defaults to 10 bytes unless the
+\fInull\fR
+auth algo is used in which case it defaults to 0\&.
+.RE
+.SH "EXAMPLES"
+.SS "P2P Setup between two unicast enpoints:"
+.sp
+.it 1 an-trap
+.nr an-no-space-flag 1
+.nr an-break-flag 1
+.br
+.ps +1
+\fBHost A:\fR
+.RS 4
+.sp
+uanytun \-r hostb\&.example\&.com \-t tun \-n 192\&.168\&.123\&.1/30 \-c aes\-ctr\-256 \-k aes\-ctr\-256 \e \-E have_a_very_safe_and_productive_day \-e left
+.RE
+.sp
+.it 1 an-trap
+.nr an-no-space-flag 1
+.nr an-break-flag 1
+.br
+.ps +1
+\fBHost B:\fR
+.RS 4
+.sp
+uanytun \-r hosta\&.example\&.com \-t tun \-n 192\&.168\&.123\&.2/30 \-c aes\-ctr\-256 \-k aes\-ctr\-256 \e \-E have_a_very_safe_and_productive_day \-e right
+.RE
+.SS "One unicast and one anycast tunnel endpoint:"
+.sp
+.it 1 an-trap
+.nr an-no-space-flag 1
+.nr an-break-flag 1
+.br
+.ps +1
+\fBUnicast tunnel endpoint:\fR
+.RS 4
+.sp
+uanytun \-r anycast\&.anytun\&.org \-d anytun0 \-t tun \-n 192\&.0\&.2\&.2/30 \-a null \-c null \-w 0 \-e client
+.RE
+.sp
+.it 1 an-trap
+.nr an-no-space-flag 1
+.nr an-break-flag 1
+.br
+.ps +1
+\fBAnycast tunnel endpoints:\fR
+.RS 4
+.sp
+As \fBuAnytun\fR can\(cqt work as an anycast endpoint it can\(cqt be used for this purpose\&. You have to use \fBAnytun\fR for that job\&.
+.RE
+.SH "BUGS"
+.sp
+Most likely there are some bugs in \fBuAnytun\fR\&. If you find a bug, please let the developers know at uanytun@anytun\&.org\&. Of course, patches are preferred\&.
+.SH "AUTHORS"
+.sp
+Christian Pointner <equinox@anytun\&.org>
+.SH "RESOURCES"
+.sp
+Main web site: http://www\&.anytun\&.org/
+.SH "COPYING"
+.sp
+Copyright (C) 2008\-2010 Christian Pointner\&. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version\&.
[ -C|--chroot <path> ]
[ -P|--write-pid <filename> ]
[ -L|--log <target>:<level>[,<param1>[,<param2>[..]]] ]
+ [ -U|--debug ]
[ -i|--interface <ip-address> ]
[ -p|--port <port> ]
[ -r|--remote-host <hostname|ip> ]
This option instructs *uAnytun* to run in foreground
instead of becoming a daemon which is the default.
-*-u, --username <username>*::
+*-u, --username '<username>'*::
run as this user. If no group is specified (*-g*) the default group of
the user is used. The default is to not drop privileges.
-*-g, --groupname <groupname>*::
+*-g, --groupname '<groupname>'*::
run as this group. If no username is specified (*-u*) this gets ignored.
The default is to not drop privileges.
-*-C, --chroot <path>*::
+*-C, --chroot '<path>'*::
Instruct *uAnytun* to run in a chroot jail. The default is
to not run in chroot.
Instruct *uAnytun* to write it's pid to this file. The default is
to not create a pid file.
-*-L, --log <target>:<level>[,<param1>[,<param2>[..]]]*::
+*-L, --log '<target>:<level>[,<param1>[,<param2>[..]]]'*::
add log target to logging system. This can be invoked several times
in order to log to different targets at the same time. Every target
hast its own log level which is a number between 0 and 5. Where 0 means
disabling log and 5 means debug messages are enabled. +
The file target can be used more the once with different levels.
If no target is provided at the command line a single target with the
- config *syslog:3,uanytun,daemon* is added. +
+ config 'syslog:3,uanytun,daemon' is added. +
The following targets are supported:
- *syslog*;; log to syslog daemon, parameters <level>[,<logname>[,<facility>]]
- *file*;; log to file, parameters <level>[,<path>]
- *stdout*;; log to standard output, parameters <level>
- *stderr*;; log to standard error, parameters <level>
+ 'syslog';; log to syslog daemon, parameters <level>[,<logname>[,<facility>]]
+ 'file';; log to file, parameters <level>[,<path>]
+ 'stdout';; log to standard output, parameters <level>
+ 'stderr';; log to standard error, parameters <level>
-*-i, --interface <ip address>*::
+*-U, --debug*::
+ This option instructs *uAnytun* to run in debug mode. It implicits *-D*
+ (don't daemonize) and adds a log target with the configuration
+ 'stdout:5' (logging with maximum level). In future releases there might
+ be additional output when this option is supplied.
+
+*-i, --interface '<ip address>'*::
This IP address is used as the sender address for outgoing
packets. The default is to not use a special inteface and just
bind on all interfaces.
-*-p, --port <port>*::
+*-p, --port '<port>'*::
The local UDP port that is used to send and receive the
payload data. The two tunnel endpoints can use different
ports. default: 4444
-*-r, --remote-host <hostname|ip>*::
+*-r, --remote-host '<hostname|ip>'*::
This option can be used to specify the remote tunnel
endpoint. In case of anycast tunnel endpoints, the
anycast IP address has to be used. If you do not specify
an address, it is automatically determined after receiving
the first data packet.
-*-o, --remote-port <port>*::
+*-o, --remote-port '<port>'*::
The UDP port used for payload data by the remote host
(specified with -p on the remote host). If you do not specify
a port, it is automatically determined after receiving
Resolv to IPv6 addresses only. The default is to resolv both
IPv4 and IPv6 addresses.
-*-d, --dev <name>*::
+*-d, --dev '<name>'*::
device name +
By default, tapN is used for Ethernet tunnel interfaces,
and tunN for IP tunnels, respectively. This option can
be used to manually override these defaults.
-*-t, --type <tun|tap>*::
+*-t, --type '<tun|tap>'*::
device type +
Type of the tunnels to create. Use tap for Ethernet
tunnels, tun for IP tunnels.
-*-n, --ifconfig <local>/<prefix>*::
+*-n, --ifconfig '<local>/<prefix>'*::
The local IP address and prefix length. The remote tunnel endpoint
has to use a different IP address in the same subnet.
- *<local>*;; the local IP address for the tun/tap device
- *<prefix>*;; the prefix length of the network
+ '<local>';; the local IP address for the tun/tap device
+ '<prefix>';; the prefix length of the network
-*-x, --post-up-script <script>*::
+*-x, --post-up-script '<script>'*::
This option instructs *uAnytun* to run this script after the interface
is created. By default no script will be executed.
-*-m, --mux <mux-id>*::
+*-m, --mux '<mux-id>'*::
the multiplex id to use. default: 0
-*-s, --sender-id <sender id>*::
+*-s, --sender-id '<sender id>'*::
Each anycast tunnel endpoint needs a unique sender id
(1, 2, 3, ...). It is needed to distinguish the senders
in case of replay attacks. As *uAnytun* does not support
synchronisation it can't be used as an anycast endpoint therefore
- this option is quite useless but implemented for compability
+ this option is quite useless but implemented for compatibility
reasons. default: 0
-*-w, --window-size <window size>*::
+*-w, --window-size '<window size>'*::
seqence window size +
Sometimes, packets arrive out of order on the receiver
side. This option defines the size of a list of received
By default the sequence window is disabled and therefore a
window size of 0 is used.
-*-k, --kd--prf <kd-prf type>*::
+*-k, --kd--prf '<kd-prf type>'*::
key derivation pseudo random function +
The pseudo random function which is used for calculating the
session keys and session salt. +
Possible values:
- *null*;; no random function, keys and salt are set to 0..00
- *aes-ctr*;; AES in counter mode with 128 Bits, default value
- *aes-ctr-128*;; AES in counter mode with 128 Bits
- *aes-ctr-192*;; AES in counter mode with 192 Bits
- *aes-ctr-256*;; AES in counter mode with 256 Bits
+ 'null';; no random function, keys and salt are set to 0..00
+ 'aes-ctr';; AES in counter mode with 128 Bits, default value
+ 'aes-ctr-128';; AES in counter mode with 128 Bits
+ 'aes-ctr-192';; AES in counter mode with 192 Bits
+ 'aes-ctr-256';; AES in counter mode with 256 Bits
-*-e, --role <role>*::
+*-e, --role '<role>'*::
SATP uses different session keys for inbound and outbound traffic. The
role parameter is used to determine which keys to use for outbound or
inbound packets. On both sides of a vpn connection different roles have
- to be used. Possible values are *left* and *right*. You may also use
- *alice* or *server* as a replacement for *left* and *bob* or *client* as
- a replacement for *right*. By default *left* is used.
+ to be used. Possible values are 'left' and 'right'. You may also use
+ 'alice' or 'server' as a replacement for 'left' and 'bob' or 'client' as
+ a replacement for 'right'. By default 'left' is used.
-*-E, --passphrase <pass phrase>*::
+*-E, --passphrase '<pass phrase>'*::
This passphrase is used to generate the master key and master salt.
For the master key the last n bits of the SHA256 digest of the
passphrase (where n is the length of the master key in bits) is used.
The master salt gets generated with the SHA1 digest.
You may force a specific key and or salt by using *--key* and *--salt*.
-*-K, --key <master key>*::
+*-K, --key '<master key>'*::
master key to use for key derivation +
Master key in hexadecimal notation, e.g.
01a2b3c4d5e6f708a9b0cadbecfd0fa1, with a mandatory length
of 32, 48 or 64 characters (128, 192 or 256 bits).
-*-A, --salt <master salt>*::
+*-A, --salt '<master salt>'*::
master salt to use for key derivation +
Master salt in hexadecimal notation, e.g.
01a2b3c4d5e6f708a9b0cadbecfd, with a mandatory length
of 28 characters (14 bytes).
-*-c, --cipher <cipher type>*::
+*-c, --cipher '<cipher type>'*::
payload encryption algorithm +
Encryption algorithm used for encrypting the payload +
Possible values:
- *null*;; no encryption
- *aes-ctr*;; AES in counter mode with 128 Bits, default value
- *aes-ctr-128*;; AES in counter mode with 128 Bits
- *aes-ctr-192*;; AES in counter mode with 192 Bits
- *aes-ctr-256*;; AES in counter mode with 256 Bits
+ 'null';; no encryption
+ 'aes-ctr';; AES in counter mode with 128 Bits, default value
+ 'aes-ctr-128';; AES in counter mode with 128 Bits
+ 'aes-ctr-192';; AES in counter mode with 192 Bits
+ 'aes-ctr-256';; AES in counter mode with 256 Bits
-*-a, --auth-algo <algo type>*::
+*-a, --auth-algo '<algo type>'*::
message authentication algorithm +
This option sets the message authentication algorithm. +
If HMAC-SHA1 is used, the packet length is increased. The additional bytes
contain the authentication data. see *--auth-tag-length* for more info. +
Possible values:
- *null*;; no message authentication
- *sha1*;; HMAC-SHA1, default value
+ 'null';; no message authentication
+ 'sha1';; HMAC-SHA1, default value
-*-b, --auth-tag-length <length>*::
+*-b, --auth-tag-length '<length>'*::
The number of bytes to use for the auth tag. This value defaults to 10 bytes
- unless the *null* auth algo is used in which case it defaults to 0.
+ unless the 'null' auth algo is used in which case it defaults to 0.
EXAMPLES
COPYING
-------
-Copyright \(C) 2008-2009 Christian Pointner. This program is free
+Copyright \(C) 2008-2010 Christian Pointner. This program is free
software: you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or any later version.
CONFIG_DIR=/etc/uanytun
NAME=uanytun
DESC=uanytun
+VARRUN_DIR=/var/run/$NAME
test -x $DAEMON || exit 0
start_vpn () {
STATUS="OK"
- if [ -f $CONFIG_DIR/$NAME/config ] ; then
+ if [ -f $CONFIG_DIR/$VPNNAME/config ] ; then
POSTUP=''
- test -f $CONFIG_DIR/$NAME/post-up.sh && POSTUP="-x $CONFIG_DIR/$NAME/post-up.sh"
- CHROOTDIR=`grep '^chroot' < $CONFIG_DIR/$NAME/config | sed 's/chroot\s*//'`
+ test -f $CONFIG_DIR/$VPNNAME/post-up.sh && POSTUP="-x $CONFIG_DIR/$VPNNAME/post-up.sh"
+ CHROOTDIR=`grep '^chroot' < $CONFIG_DIR/$VPNNAME/config | sed 's/chroot\s*//'`
if [ -n "$CHROOTDIR" ] ; then
test -d $CHROOTDIR || mkdir -p $CHROOTDIR
fi
- DAEMONARG=`sed 's/#.*//' < $CONFIG_DIR/$NAME/config | grep -e '\w' | sed 's/^/--/' | tr '\n' ' '`
- $DAEMON --write-pid /var/run/uanytun.$NAME.pid $POSTUP $DAEMONOPTS $DAEMONARG || STATUS="FAILED"
+ test -d $VARRUN_DIR || mkdir -p $VARRUN_DIR
+ DAEMONARG=`sed 's/#.*//' < $CONFIG_DIR/$VPNNAME/config | grep -e '\w' | sed 's/^/--/' | tr '\n' ' '`
+ $DAEMON --write-pid $VARRUN_DIR/$VPNNAME.pid $POSTUP $DAEMONOPTS $DAEMONARG || STATUS="FAILED"
else
STATUS="no config found"
fi
echo -n "Starting $DESC:"
if test -z "$2" ; then
if [ -f $CONFIG_DIR/autostart ] ; then
- for NAME in `sed 's/#.*//' < $CONFIG_DIR/autostart | grep -e '\w'`; do
- echo -n " $NAME"
+ for VPNNAME in `sed 's/#.*//' < $CONFIG_DIR/autostart | grep -e '\w'`; do
+ echo -n " $VPNNAME"
start_vpn
done
else
else
while shift ; do
[ -z "$1" ] && break
- NAME=$1
- echo -n " $NAME"
+ VPNNAME=$1
+ echo -n " $VPNNAME"
start_vpn
done
fi
stop)
echo -n "Stoping $DESC:"
if test -z "$2" ; then
- for PIDFILE in `ls /var/run/uanytun.*.pid 2> /dev/null`; do
- NAME=`echo $PIDFILE | cut -c18-`
- NAME=${NAME%%.pid}
- echo -n " $NAME"
+ for PIDFILE in `ls $VARRUN_DIR/*.pid 2> /dev/null`; do
+ VPNNAME=`basename $PIDFILE .pid`
+ echo -n " $VPNNAME"
stop_vpn
done
else
while shift ; do
[ -z "$1" ] && break
- if test -e /var/run/uanytun.$1.pid ; then
- PIDFILE=`ls /var/run/uanytun.$1.pid 2> /dev/null`
- NAME=`echo $PIDFILE | cut -c18-`
- NAME=${NAME%%.pid}
- echo -n " $NAME"
+ if test -e $VARRUN_DIR/$1.pid ; then
+ PIDFILE=`ls $VARRUN_DIR/$1.pid 2> /dev/null`
+ VPNNAME=`basename $PIDFILE .pid`
+ echo -n " $VPNNAME"
stop_vpn
else
echo -n " (failure: No such tunnel is running: $1)"
reload)
echo -n "Reloading $DESC:"
if test -z "$2" ; then
- for PIDFILE in `ls /var/run/uanytun.*.pid 2> /dev/null`; do
- NAME=`echo $PIDFILE | cut -c18-`
- NAME=${NAME%%.pid}
- echo -n " $NAME"
+ for PIDFILE in `ls $VARRUN_DIR/*.pid 2> /dev/null`; do
+ VPNNAME=`basename $PIDFILE .pid`
+ echo -n " $VPNNAME"
stop_vpn
start_vpn
done
else
while shift ; do
[ -z "$1" ] && break
- if test -e /var/run/uanytun.$1.pid ; then
- PIDFILE=`ls /var/run/uanytun.$1.pid 2> /dev/null`
- NAME=`echo $PIDFILE | cut -c18-`
- NAME=${NAME%%.pid}
- echo -n " $NAME"
+ if test -e $VARRUN_DIR/$1.pid ; then
+ PIDFILE=`ls $VARRUN_DIR/$1.pid 2> /dev/null`
+ VPNNAME=`basename $PIDFILE .pid`
+ echo -n " $VPNNAME"
stop_vpn
start_vpn
else
fi
echo "."
;;
- restart)
+ restart|force-reload)
SCRIPT=$0
shift
$SCRIPT stop $*
## tunneling and relaying of packets of any protocol.
##
##
-## Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+## Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
##
## This file is part of uAnytun.
##
find . -name *.o -exec rm -f {} \;
find . -name "*.\~*" -exec rm -rf {} \;
rm -f include.mk
+ rm -f version.h
rm -f tun.c
clean:
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
# tunneling and relaying of packets of any protocol.
#
#
-# Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+# Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
#
# This file is part of uAnytun.
#
CRYPTO_LIB='gcrypt'
PASSPHRASE=1
-V4_MAPPED=1
PREFIX='/usr/local'
SBINDIR=''
echo " --no-crypto disable crypto at all (only NULL cipher)"
echo " --disable-passphrase disable master key and salt passphrase"
echo " --enable-passphrase enable master key and salt passphrase"
- echo " --disable-v4-mapped disable V4-Mapped addresses (this means to disable"
- echo " simultanious use of IPv4 and IPv6)"
- echo " --enable-v4-mapped enable V4-Mapped addresses"
}
for arg
--enable-passphrase)
PASSPHRASE=1
;;
- --disable-v4-mapped)
- V4_MAPPED=0
- ;;
- --enable-v4-mapped)
- V4_MAPPED=2
- ;;
--ebuild-compat)
EBUILD_COMPAT=1
;;
exit 1
fi
-
+rm -f version.h
rm -f include.mk
case $TARGET in
Linux)
echo "loading BSD specific TUN Device"
CFLAGS=$CFLAGS' -I/usr/local/include'
LDFLAGS=$LDFLAGS' -L/usr/local/lib'
- if [ $V4_MAPPED -ne 2 ]; then
- V4_MAPPED=0
- fi
;;
*)
- echo "Plattform not supported"
+ echo "platform not supported"
exit 1;
;;
esac
echo "disabling master key and salt passphrase"
fi
-if [ $V4_MAPPED -eq 0 ]; then
- CFLAGS=$CFLAGS' -DNO_V4MAPPED'
- echo "WARNING: disabling V4 mapped addresses, this prevents uanytun from using IPv6 and IPv4 Sockets at the same time"
-fi
-
if [ -z "$SBINDIR" ]; then
SBINDIR=$PREFIX/sbin
fi
echo "not installing example files"
fi
+VERSION=`cat ../version`
+if which svn >/dev/null; then
+ SVN_REV=`svn info | grep "^Revision: " | awk '{print($2)}'`
+ if [ -n "$SVN_REV" ]; then
+ VERSION="$VERSION (svn$SVN_REV)"
+ fi
+fi
+HOSTNAME=`hostname`
+DATE=`date +"%d.%m.%Y %H:%M:%S %Z"`
+
+cat >> version.h <<EOF
+/*
+ * uanytun version info
+ *
+ * this file was created automatically
+ * do not edit this file directly
+ * use ./configure instead
+ */
+
+#ifndef UANYTUN_version_h_INCLUDED
+#define UANYTUN_version_h_INCLUDED
+
+#define VERSION_STRING_0 "uanytun version $VERSION"
+#define VERSION_STRING_1 "built on $HOSTNAME, $DATE"
+
+#endif
+
+EOF
+
exit 0
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
int do_chroot(const char* chrootdir)
{
if(getuid() != 0) {
- log_printf(ERROR, "this programm has to be run as root in order to run in a chroot");
+ log_printf(ERROR, "this program has to be run as root in order to run in a chroot");
return -1;
}
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
--- /dev/null
+/*
+ * uAnytun
+ *
+ * uAnytun is a tiny implementation of SATP. Unlike Anytun which is a full
+ * featured implementation uAnytun has no support for multiple connections
+ * or synchronisation. It is a small single threaded implementation intended
+ * to act as a client on small platforms.
+ * The secure anycast tunneling protocol (satp) defines a protocol used
+ * for communication between any combination of unicast and anycast
+ * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
+ * mode and allows tunneling of every ETHER TYPE protocol (e.g.
+ * ethernet, ip, arp ...). satp directly includes cryptography and
+ * message authentication based on the methodes used by SRTP. It is
+ * intended to deliver a generic, scaleable and secure solution for
+ * tunneling and relaying of packets of any protocol.
+ *
+ *
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
+ *
+ * This file is part of uAnytun.
+ *
+ * uAnytun is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * uAnytun is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with uAnytun. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UANYTUN_init_crypt_h_INCLUDED
+#define UANYTUN_init_crypt_h_INCLUDED
+
+#ifdef NO_CRYPT
+
+
+int init_crypt()
+{
+ return 0;
+}
+
+
+#else
+
+
+#ifndef USE_SSL_CRYPTO
+
+#include <gcrypt.h>
+
+#define MIN_GCRYPT_VERSION "1.2.0"
+
+int init_crypt()
+{
+ if(!gcry_check_version(MIN_GCRYPT_VERSION)) {
+ log_printf(NOTICE, "invalid Version of libgcrypt, should be >= %s", MIN_GCRYPT_VERSION);
+ return -1;
+ }
+
+ gcry_error_t err = gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
+ if(err) {
+ log_printf(ERROR, "failed to disable secure memory: %s", gcry_strerror(err));
+ return -1;
+ }
+
+ err = gcry_control(GCRYCTL_INITIALIZATION_FINISHED);
+ if(err) {
+ log_printf(ERROR, "failed to finish libgcrypt initialization: %s", gcry_strerror(err));
+ return -1;
+ }
+
+ log_printf(NOTICE, "libgcrypt init finished");
+ return 0;
+}
+
+#else
+
+int init_crypt()
+{
+// nothing here
+ return 0;
+}
+
+#endif
+
+
+#endif
+
+#endif
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
*/
#include "datatypes.h"
+#include "version.h"
#include "options.h"
if(!strcmp(str,"-h") || !strcmp(str,"--help"))
return -1;
+ else if(!strcmp(str,"-v") || !strcmp(str,"--version"))
+ return -5;
PARSE_INVERSE_BOOL_PARAM("-D","--nodaemonize", opt->daemonize_)
PARSE_STRING_PARAM("-u","--username", opt->username_)
PARSE_STRING_PARAM("-g","--groupname", opt->groupname_)
PARSE_STRING_PARAM("-p","--port", opt->local_port_)
PARSE_INT_PARAM("-s","--sender-id", opt->sender_id_)
PARSE_STRING_LIST("-L","--log", opt->log_targets_)
+ PARSE_BOOL_PARAM("-U", "--debug", opt->debug_)
PARSE_STRING_PARAM("-r","--remote-host", opt->remote_addr_)
PARSE_STRING_PARAM("-o","--remote-port", opt->remote_port_)
PARSE_BOOL_PARAM("-4","--ipv4-only", ipv4_only)
if(ipv6_only)
opt->resolv_addr_type_ = IPV6_ONLY;
+ if(opt->debug_) {
+ string_list_add(&opt->log_targets_, "stdout:5");
+ opt->daemonize_ = 0;
+ }
+
+ if(!opt->log_targets_.first_)
+ string_list_add(&opt->log_targets_, "syslog:3,uanytun,daemon");
+
#ifndef NO_CRYPT
if(role) {
if(!strcmp(role, "alice") || !strcmp(role, "server") || !strcmp(role, "left"))
if(!opt)
return;
-#ifdef NO_V4MAPPED
- if(opt->resolv_addr_type_ == ANY) {
- opt->resolv_addr_type_ = IPV4_ONLY;
- log_printf(WARNING, "No support for V4-mapped Adresses on this platform, defaulting to only use IPv4 addresses");
- }
-#endif
-
#ifndef NO_CRYPT
if(!strcmp(opt->cipher_, "null") && !strcmp(opt->auth_algo_, "null") &&
strcmp(opt->kd_prf_, "null")) {
opt->chroot_dir_ = NULL;
opt->pid_file_ = NULL;
string_list_init(&opt->log_targets_);
+ opt->debug_ = 0;
opt->local_addr_ = NULL;
opt->local_port_ = strdup("4444");
opt->sender_id_ = 0;
{
printf("USAGE:\n");
printf("uanytun [-h|--help] prints this...\n");
+ printf(" [-v|--version] print version info and exit\n");
printf(" [-D|--nodaemonize] don't run in background\n");
printf(" [-u|--username] <username> change to this user\n");
printf(" [-g|--groupname] <groupname> change to this group\n");
printf(" [-s|--sender-id ] <sender id> the sender id to use\n");
printf(" [-L|--log] <target>:<level>[,<param1>[,<param2>..]]\n");
printf(" add a log target, can be invoked several times\n");
+ printf(" [-U|--debug] don't daemonize and log to stdout with maximum log level\n");
printf(" [-r|--remote-host] <hostname|ip> remote host\n");
printf(" [-o|--remote-port] <port> remote port\n");
#endif
}
+void options_print_version()
+{
+ printf("%s\n", VERSION_STRING_0);
+ printf("%s\n", VERSION_STRING_1);
+}
+
void options_print(options_t* opt)
{
if(!opt)
printf("pid_file: '%s'\n", opt->pid_file_);
printf("log_targets: \n");
string_list_print(&opt->log_targets_, " '", "'\n");
+ printf("debug: %s\n", !opt->debug_ ? "false" : "true");
printf("local_addr: '%s'\n", opt->local_addr_);
printf("local_port: '%s'\n", opt->local_port_);
printf("sender_id: %d\n", opt->sender_id_);
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
char* chroot_dir_;
char* pid_file_;
string_list_t log_targets_;
+ int debug_;
char* local_addr_;
char* local_port_;
sender_id_t sender_id_;
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
#include "datatypes.h"
#include "log.h"
+#include "sig_handler.h"
+
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
-#include <sys/select.h>
#include <errno.h>
-#include "sig_handler.h"
-
-#include <stdio.h>
-
static int sig_pipe_fds[2];
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
#ifndef NO_CRYPT
#include "key_derivation.h"
#include "auth_algo.h"
-
-#ifndef USE_SSL_CRYPTO
-#include <gcrypt.h>
-#endif
+#else
+typedef u_int8_t auth_algo_t;
#endif
-
+#include "init_crypt.h"
#include "daemon.h"
#include "sysexec.h"
-#ifndef NO_CRYPT
-#ifndef USE_SSL_CRYPTO
-
-#define MIN_GCRYPT_VERSION "1.2.0"
-
-int init_libgcrypt()
-{
- if(!gcry_check_version(MIN_GCRYPT_VERSION)) {
- log_printf(NOTICE, "invalid Version of libgcrypt, should be >= %s", MIN_GCRYPT_VERSION);
- return -1;
- }
-
- gcry_error_t err = gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
- if(err) {
- log_printf(ERROR, "failed to disable secure memory: %s", gcry_strerror(err));
- return -1;
- }
-
- err = gcry_control(GCRYCTL_INITIALIZATION_FINISHED);
- if(err) {
- log_printf(ERROR, "failed to finish libgcrypt initialization: %s", gcry_strerror(err));
- return -1;
- }
-
- log_printf(NOTICE, "libgcrypt init finished");
- return 0;
-}
-#endif
-#endif
-
-#ifdef NO_CRYPT
-typedef u_int8_t auth_algo_t;
-#endif
int init_main_loop(options_t* opt, cipher_t* c, auth_algo_t* aa, key_derivation_t* kd, seq_win_t* seq_win)
{
return 0;
}
-int process_tun_data(tun_device_t* dev, udp_socket_t* sock, options_t* opt, plain_packet_t* plain_packet, encrypted_packet_t* encrypted_packet,
+int process_tun_data(tun_device_t* dev, udp_t* sock, options_t* opt, plain_packet_t* plain_packet, encrypted_packet_t* encrypted_packet,
cipher_t* c, auth_algo_t* aa, key_derivation_t* kd, seq_nr_t seq_nr)
{
plain_packet_set_payload_length(plain_packet, -1);
#ifndef NO_CRYPT
auth_algo_generate(aa, kd, kd_outbound, encrypted_packet);
#endif
-
+
len = udp_write(sock, encrypted_packet_get_packet(encrypted_packet), encrypted_packet_get_length(encrypted_packet));
if(len == -1)
log_printf(ERROR, "error on sending udp packet: %s", strerror(errno));
return 0;
}
-int process_sock_data(tun_device_t* dev, udp_socket_t* sock, options_t* opt, plain_packet_t* plain_packet, encrypted_packet_t* encrypted_packet,
+int process_sock_data(tun_device_t* dev, int fd, udp_t* sock, options_t* opt, plain_packet_t* plain_packet, encrypted_packet_t* encrypted_packet,
cipher_t* c, auth_algo_t* aa, key_derivation_t* kd, seq_win_t* seq_win)
{
plain_packet_set_payload_length(plain_packet, -1);
udp_endpoint_t remote;
memset(&remote, 0, sizeof(udp_endpoint_t));
- int len = udp_read(sock, encrypted_packet_get_packet(encrypted_packet), encrypted_packet_get_length(encrypted_packet), &remote);
+ int len = udp_read(sock, fd, encrypted_packet_get_packet(encrypted_packet), encrypted_packet_get_length(encrypted_packet), &remote);
if(len == -1) {
log_printf(ERROR, "error on receiving udp packet: %s", strerror(errno));
return 0;
}
else if(len < encrypted_packet_get_minimum_length(encrypted_packet)) {
- log_printf(WARNING, "received packet is to short");
+ log_printf(WARNING, "received packet is too short");
return 0;
}
encrypted_packet_set_length(encrypted_packet, len);
return -2;
}
+ udp_set_active_sock(sock, fd);
if(memcmp(&remote, &(sock->remote_end_), sizeof(remote))) {
memcpy(&(sock->remote_end_), &remote, sizeof(remote));
sock->remote_end_set_ = 1;
}
-int main_loop(tun_device_t* dev, udp_socket_t* sock, options_t* opt)
+int main_loop(tun_device_t* dev, udp_t* sock, options_t* opt)
{
log_printf(INFO, "entering main loop");
FD_ZERO(&readfds);
FD_SET(dev->fd_, &readfds);
- FD_SET(sock->fd_, &readfds);
- int nfds = dev->fd_ > sock->fd_ ? dev->fd_ : sock->fd_;
+ int nfds = udp_init_fd_set(sock, &readfds);
+ nfds = dev->fd_ > nfds ? dev->fd_ : nfds;
int return_value = 0;
int sig_fd = signal_init();
break;
}
- if(FD_ISSET(sock->fd_, &readyfds)) {
- return_value = process_sock_data(dev, sock, opt, &plain_packet, &encrypted_packet, &c, &aa, &kd, &seq_win);
- if(return_value)
- break;
+ udp_socket_t* s = sock->socks_;
+ while(s) {
+ if(FD_ISSET(s->fd_, &readyfds)) {
+ return_value = process_sock_data(dev, s->fd_, sock, opt, &plain_packet, &encrypted_packet, &c, &aa, &kd, &seq_win);
+ if(return_value)
+ break;
+ }
+ s = s->next_;
}
}
if(ret == -4) {
fprintf(stderr, "syntax error: unknown role name\n\n");
}
+ if(ret == -5) {
+ options_print_version();
+ }
- if(ret != -2)
+ if(ret != -2 && ret != -5)
options_print_usage();
+ if(ret == -1 || ret == -5)
+ ret = 0;
+
options_clear(&opt);
log_close();
exit(ret);
}
string_list_element_t* tmp = opt.log_targets_.first_;
- if(!tmp) {
- log_add_target("syslog:3,uanytun,daemon");
- }
- else {
- while(tmp) {
- ret = log_add_target(tmp->string_);
- if(ret) {
- switch(ret) {
- case -2: fprintf(stderr, "memory error on log_add_target, exitting\n"); break;
- case -3: fprintf(stderr, "unknown log target: '%s', exitting\n", tmp->string_); break;
- case -4: fprintf(stderr, "this log target is only allowed once: '%s', exitting\n", tmp->string_); break;
- default: fprintf(stderr, "syntax error near: '%s', exitting\n", tmp->string_); break;
- }
-
- options_clear(&opt);
- log_close();
- exit(ret);
+ while(tmp) {
+ ret = log_add_target(tmp->string_);
+ if(ret) {
+ switch(ret) {
+ case -2: fprintf(stderr, "memory error on log_add_target, exitting\n"); break;
+ case -3: fprintf(stderr, "unknown log target: '%s', exitting\n", tmp->string_); break;
+ case -4: fprintf(stderr, "this log target is only allowed once: '%s', exitting\n", tmp->string_); break;
+ default: fprintf(stderr, "syntax error near: '%s', exitting\n", tmp->string_); break;
}
- tmp = tmp->next_;
+
+ options_clear(&opt);
+ log_close();
+ exit(ret);
}
+ tmp = tmp->next_;
}
log_printf(NOTICE, "just started...");
exit(-1);
}
-#ifndef NO_CRYPT
-#ifndef USE_SSL_CRYPTO
- ret = init_libgcrypt();
+ ret = init_crypt();
if(ret) {
- log_printf(ERROR, "error on libgcrpyt initialization, exitting");
+ log_printf(ERROR, "error on crpyto initialization, exitting");
options_clear(&opt);
log_close();
exit(ret);
}
-#endif
-#endif
tun_device_t dev;
ret = tun_init(&dev, opt.dev_name_, opt.dev_type_, opt.ifconfig_param_.net_addr_, opt.ifconfig_param_.prefix_length_);
}
- udp_socket_t sock;
+ udp_t sock;
ret = udp_init(&sock, opt.local_addr_, opt.local_port_, opt.resolv_addr_type_);
if(ret) {
log_printf(ERROR, "error on udp_init, exitting");
log_close();
exit(ret);
}
- char* local_string = udp_get_local_end_string(&sock);
- if(local_string) {
- log_printf(NOTICE, "listening on: %s", local_string);
- free(local_string);
- }
-
if(opt.remote_addr_) {
if(!udp_set_remote(&sock, opt.remote_addr_, opt.remote_port_, opt.resolv_addr_type_)) {
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
#include <arpa/inet.h>
#include <netinet/in.h>
-int udp_init(udp_socket_t* sock, const char* local_addr, const char* port, resolv_addr_type_t resolv_type)
+int udp_init(udp_t* sock, const char* local_addr, const char* port, resolv_addr_type_t resolv_type)
{
if(!sock || !port)
return -1;
-
- sock->fd_ = 0;
- memset(&(sock->local_end_), 0, sizeof(sock->local_end_));
- memset(&(sock->remote_end_), 0, sizeof(sock->local_end_));
+
+ sock->socks_ = NULL;
+ sock->active_sock_ = NULL;
+ memset(&(sock->remote_end_), 0, sizeof(sock->remote_end_));
sock->remote_end_set_ = 0;
struct addrinfo hints, *res;
res = NULL;
memset (&hints, 0, sizeof (hints));
hints.ai_socktype = SOCK_DGRAM;
- hints.ai_flags |= AI_PASSIVE;
+ hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
switch(resolv_type) {
- case IPV4_ONLY: hints.ai_family = PF_INET; break;
- case IPV6_ONLY: hints.ai_family = PF_INET6; break;
- default: hints.ai_family = PF_UNSPEC; break;
+ case IPV4_ONLY: hints.ai_family = AF_INET; break;
+ case IPV6_ONLY: hints.ai_family = AF_INET6; break;
+ default: hints.ai_family = AF_UNSPEC; break;
}
int errcode = getaddrinfo(local_addr, port, &hints, &res);
udp_close(sock);
return -1;
}
-
if(!res) {
udp_close(sock);
log_printf(ERROR, "getaddrinfo returned no address for %s:%s", local_addr, port);
return -1;
}
- memcpy(&(sock->local_end_), res->ai_addr, res->ai_addrlen);
+ struct addrinfo* r = res;
+ udp_socket_t* prev_sock = NULL;
+ while(r) {
+ udp_socket_t* new_sock = malloc(sizeof(udp_socket_t));
+ if(!new_sock) {
+ log_printf(ERROR, "memory error at udp_init");
+ freeaddrinfo(res);
+ udp_close(sock);
+ return -2;
+ }
+ memset(&(new_sock->local_end_), 0, sizeof(new_sock->local_end_));
+ new_sock->next_ = NULL;
+
+ if(!sock->socks_) {
+ sock->socks_ = new_sock;
+ prev_sock = new_sock;
+ }
+ else {
+ prev_sock->next_ = new_sock;
+ prev_sock = new_sock;
+ }
+
+ memcpy(&(new_sock->local_end_), r->ai_addr, r->ai_addrlen);
+ new_sock->fd_ = socket(r->ai_family, SOCK_DGRAM, 0);
+ if(new_sock->fd_ < 0) {
+ log_printf(ERROR, "Error on opening udp socket: %s", strerror(errno));
+ freeaddrinfo(res);
+ udp_close(sock);
+ return -1;
+ }
+
+ if(r->ai_family == AF_INET6) {
+ int on = 1;
+ if(setsockopt(new_sock->fd_, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)))
+ log_printf(ERROR, "Error on setting IPV6_V6ONLY socket option: %s", strerror(errno));
+ }
+
+ errcode = bind(new_sock->fd_, r->ai_addr, r->ai_addrlen);
+ if(errcode) {
+ log_printf(ERROR, "Error on binding udp socket: %s", strerror(errno));
+ freeaddrinfo(res);
+ udp_close(sock);
+ return -1;
+ }
+
+ char* local_string = udp_endpoint_to_string(new_sock->local_end_);
+ if(local_string) {
+ log_printf(NOTICE, "listening on: %s", local_string);
+ free(local_string);
+ }
- sock->fd_ = socket(res->ai_family, SOCK_DGRAM, 0);
- if(sock->fd_ < 0) {
- log_printf(ERROR, "Error on opening udp socket: %s", strerror(errno));
- freeaddrinfo(res);
- udp_close(sock);
- return -1;
+ r = r->ai_next;
}
- errcode = bind(sock->fd_, res->ai_addr, res->ai_addrlen);
- if(errcode) {
- log_printf(ERROR, "Error on binding udp socket: %s", strerror(errno));
- freeaddrinfo(res);
- udp_close(sock);
- return -1;
- }
-
-/* this doesn't work on linux ?? */
-/* #ifdef NO_V4MAPPED */
-/* if(res->ai_family == AF_INET6) { */
-/* log_printf(NOTICE, "disabling V4-Mapped addresses"); */
-/* int on = 1; */
-/* if(setsockopt(sock->fd_, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on))) */
-/* log_printf(ERROR, "Error on setting IPV6_V6ONLY socket option: %s", strerror(errno)); */
-/* } */
-/* #endif */
freeaddrinfo(res);
return 0;
}
-int udp_set_remote(udp_socket_t* sock, const char* remote_addr, const char* port, resolv_addr_type_t resolv_type)
+int udp_init_fd_set(udp_t* sock, fd_set* set)
+{
+ int max_fd = 0;
+
+ udp_socket_t* s = sock->socks_;
+ while(s) {
+ FD_SET(s->fd_, set);
+ max_fd = s->fd_ > max_fd ? s->fd_ : max_fd;
+ s = s->next_;
+ }
+
+ return max_fd;
+}
+
+int udp_set_remote(udp_t* sock, const char* remote_addr, const char* port, resolv_addr_type_t resolv_type)
{
if(!sock || !remote_addr || !port)
return -1;
}
memcpy(&(sock->remote_end_), res->ai_addr, res->ai_addrlen);
sock->remote_end_set_ = 1;
+
+ if(!sock->active_sock_) {
+ udp_socket_t* s = sock->socks_;
+ while(s) {
+ if((((struct sockaddr *)&s->local_end_)->sa_family) == res->ai_family) {
+ sock->active_sock_ = s;
+ break;
+ }
+ s = s->next_;
+ }
+ }
+
freeaddrinfo(res);
return 0;
}
-void udp_close(udp_socket_t* sock)
+void udp_set_active_sock(udp_t* sock, int fd)
+{
+ if(!sock || (sock->active_sock_ && sock->active_sock_->fd_ == fd))
+ return;
+
+ udp_socket_t* s = sock->socks_;
+ while(s) {
+ if(s->fd_ == fd) {
+ sock->active_sock_ = s;
+ return;
+ }
+ s = s->next_;
+ }
+}
+
+void udp_close(udp_t* sock)
{
if(!sock)
return;
- if(sock->fd_ > 0)
- close(sock->fd_);
+ while(sock->socks_) {
+ if(sock->socks_->fd_ > 0)
+ close(sock->socks_->fd_);
+
+ udp_socket_t*s = sock->socks_;
+ sock->socks_ = sock->socks_->next_;
+
+ free(s);
+ }
+ sock->socks_ = NULL;
}
char* udp_endpoint_to_string(udp_endpoint_t e)
return ret;
}
-char* udp_get_local_end_string(udp_socket_t* sock)
-{
- if(!sock)
- return NULL;
-
- return udp_endpoint_to_string(sock->local_end_);
-}
-
-char* udp_get_remote_end_string(udp_socket_t* sock)
+char* udp_get_remote_end_string(udp_t* sock)
{
if(!sock || !sock->remote_end_set_)
return NULL;
return udp_endpoint_to_string(sock->remote_end_);
}
-int udp_read(udp_socket_t* sock, u_int8_t* buf, u_int32_t len, udp_endpoint_t* remote_end)
+int udp_read(udp_t* sock, int fd, u_int8_t* buf, u_int32_t len, udp_endpoint_t* remote_end)
{
if(!sock || !remote_end)
return -1;
socklen_t socklen = sizeof(*remote_end);
- return recvfrom(sock->fd_, buf, len, 0, (struct sockaddr *)remote_end, &socklen);
+ return recvfrom(fd, buf, len, 0, (struct sockaddr *)remote_end, &socklen);
}
-int udp_write(udp_socket_t* sock, u_int8_t* buf, u_int32_t len)
+int udp_write(udp_t* sock, u_int8_t* buf, u_int32_t len)
{
- if(!sock || !sock->remote_end_set_)
- return -1;
+ if(!sock || !sock->remote_end_set_ || !sock->active_sock_)
+ return 0;
socklen_t socklen = sizeof(sock->remote_end_);
-#ifdef NO_V4MAPPED
- if((((struct sockaddr *)&sock->local_end_)->sa_family) == AF_INET)
+ if((((struct sockaddr *)&sock->active_sock_->local_end_)->sa_family) == AF_INET)
socklen = sizeof(struct sockaddr_in);
- else if ((((struct sockaddr *)&sock->local_end_)->sa_family) == AF_INET6)
+ else if ((((struct sockaddr *)&sock->active_sock_->local_end_)->sa_family) == AF_INET6)
socklen = sizeof(struct sockaddr_in6);
-#endif
- return sendto(sock->fd_, buf, len, 0, (struct sockaddr *)&(sock->remote_end_), socklen);;
+
+ return sendto(sock->active_sock_->fd_, buf, len, 0, (struct sockaddr *)&(sock->remote_end_), socklen);
}
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ * Copyright (C) 2007-2010 Christian Pointner <equinox@anytun.org>
*
* This file is part of uAnytun.
*
struct udp_socket_struct {
int fd_;
udp_endpoint_t local_end_;
+ struct udp_socket_struct* next_;
+};
+typedef struct udp_socket_struct udp_socket_t;
+
+struct udp_struct {
+ udp_socket_t* socks_;
+ udp_socket_t* active_sock_;
udp_endpoint_t remote_end_;
int remote_end_set_;
};
-typedef struct udp_socket_struct udp_socket_t;
+typedef struct udp_struct udp_t;
-int udp_init(udp_socket_t* sock, const char* local_addr, const char* port, resolv_addr_type_t resolv_type);
-int udp_set_remote(udp_socket_t* sock, const char* remote_addr, const char* port, resolv_addr_type_t resolv_type);
-void udp_close(udp_socket_t* sock);
+int udp_init(udp_t* sock, const char* local_addr, const char* port, resolv_addr_type_t resolv_type);
+int udp_init_fd_set(udp_t* sock, fd_set* set);
+int udp_set_remote(udp_t* sock, const char* remote_addr, const char* port, resolv_addr_type_t resolv_type);
+void udp_set_active_sock(udp_t* sock, int fd);
+void udp_close(udp_t* sock);
char* udp_endpoint_to_string(udp_endpoint_t e);
-char* udp_get_local_end_string(udp_socket_t* sock);
-char* udp_get_remote_end_string(udp_socket_t* sock);
+char* udp_get_remote_end_string(udp_t* sock);
-int udp_read(udp_socket_t* sock, u_int8_t* buf, u_int32_t len, udp_endpoint_t* remote_end);
-int udp_write(udp_socket_t* sock, u_int8_t* buf, u_int32_t len);
+int udp_read(udp_t* sock, int fd, u_int8_t* buf, u_int32_t len, udp_endpoint_t* remote_end);
+int udp_write(udp_t* sock, u_int8_t* buf, u_int32_t len);
#endif