diff --git a/net/fastd/Config.in b/net/fastd/Config.in new file mode 100644 index 0000000..e12705b --- /dev/null +++ b/net/fastd/Config.in @@ -0,0 +1,14 @@ +menu "Configuration" + depends on PACKAGE_fastd + +config FASTD_DISABLE_METHOD_XSALSA20_POLY1305 + bool "Disable xsalsa20-poly1305 method" + depends on PACKAGE_fastd + default n + +config FASTD_DISABLE_METHOD_AES128_GCM + bool "Disable aes128-gcm method" + depends on PACKAGE_fastd + default n + +endmenu diff --git a/net/fastd/Makefile b/net/fastd/Makefile new file mode 100644 index 0000000..175073d --- /dev/null +++ b/net/fastd/Makefile @@ -0,0 +1,78 @@ +# +# Copyright (C) 2012 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=fastd +PKG_VERSION:=0.5-rc2 +PKG_RELEASE:=1 + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 +PKG_SOURCE_URL:=https://projects.universe-factory.net/attachments/download/32 +PKG_MD5SUM:=74b2ab08f90303f8ae1937e99c734134 + +PKG_CONFIG_DEPENDS:=CONFIG_FASTD_DISABLE_METHOD_XSALSA20_POLY1305 CONFIG_FASTD_DISABLE_METHOD_AES128_GCM +PKG_BUILD_DEPENDS:=nacl libuecc + +include $(INCLUDE_DIR)/package.mk +include $(INCLUDE_DIR)/cmake.mk + +define Package/fastd + SECTION:=net + CATEGORY:=Network + DEPENDS:=+kmod-tun +librt +libpthread + TITLE:=Fast and Secure Tunneling Daemon + URL:=https://projects.universe-factory.net/projects/fastd + SUBMENU:=VPN +endef + +define Package/fastd/config + source "$(SOURCE)/Config.in" +endef + +CMAKE_OPTIONS += \ + -DCMAKE_BUILD_TYPE:String="MINSIZEREL" \ + + +ifeq ($(CONFIG_FASTD_DISABLE_METHOD_XSALSA20_POLY1305),y) +CMAKE_OPTIONS += \ + -DWITH_METHOD_XSALSA20_POLY1305:BOOL=FALSE +else +CMAKE_OPTIONS += \ + -DWITH_METHOD_XSALSA20_POLY1305:BOOL=TRUE +endif + +ifeq ($(CONFIG_FASTD_DISABLE_METHOD_AES128_GCM),y) +CMAKE_OPTIONS += \ + -DWITH_METHOD_AES128_GCM:BOOL=FALSE +else +CMAKE_OPTIONS += \ + -DWITH_METHOD_AES128_GCM:BOOL=TRUE +endif + +define Package/fastd/description + Fast and secure tunneling daemon, which is optimized on small code size and few dependencies +endef + +define Package/fastd/conffiles +/etc/config/fastd +endef + +define Package/fastd/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/fastd $(1)/usr/sbin/ + + $(INSTALL_DIR) $(1)/etc/init.d/ + $(INSTALL_BIN) files/fastd.init $(1)/etc/init.d/fastd + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_CONF) files/fastd.config $(1)/etc/config/fastd + $(INSTALL_DIR) $(1)/etc/fastd + $(INSTALL_DIR) $(1)/lib/upgrade/keep.d + $(INSTALL_DATA) files/fastd.upgrade $(1)/lib/upgrade/keep.d/fastd +endef + +$(eval $(call BuildPackage,fastd)) diff --git a/net/fastd/files/fastd.config b/net/fastd/files/fastd.config new file mode 100644 index 0000000..0828e45 --- /dev/null +++ b/net/fastd/files/fastd.config @@ -0,0 +1,61 @@ +package fastd + +config fastd sample_config + + # Set to 1 to enable this instance: + option enabled 0 + + # Sets a static config file, optional + # Options set via UCI have higher priority that statically configured ones + # If a config file is set all other options except the interface may become optional if the are set in the file +# list config '/etc/fastd/sample_config/fastd.conf' + + # Sets a directory from which peers configurations are read + # The peer list can be reloaded without restarting fastd + # This is currently the only way to configure the peers + list config_peer_dir '/etc/fastd/sample_config/peers' + + # Sets the log level + # Possible values: error, warn, info, verbose, debug + # Default: info + option syslog_level 'info' + + # IP address and port of the local end, optional + # 'any' can be used to bind to both IPv4 and IPv6 + # If the port is 0 fastd will bind to a random port +# option bind 'any:1337' +# option bind '0.0.0.0:1337' +# option bind '[::]:1337' + + # "method null" uses no encryption or MAC + # "method xsalsa20-poly1305" uses the XSalsa20 encryption ad the Poly1305 MAC + option method 'xsalsa20-poly1305' + + # "mode tap" will create an ethernet tunnel (tap device), + # "mode tun" will create an IP tunnel (tun device). + option mode 'tap' + + # Set the name of the tunnel interface to use + option interface 'tap0' +# option interface 'tun0' +# option interface 'fastd0' + + # Sets the MTU of the tunnel interface, default is 1500 + # 1426 is a good value that avoids fragmentation for the xsalsa20-poly1305 method + # when the tunnel uses an IPv4 connection on a line with an MTU of 1492 or higher + option mtu 1426 + + # Enables direct forwaring of packets between peers + # WARNING: Only enable this if you know what you are doing, as this can lead to forwarding loops! + option forward 0 + + # The secret key + # A keypair can be generated with `fastd --generate-key` + # When the corresponding public key is lost it can be recovered with `/etc/init.d/fastd show-key ` +# option secret '0000000000000000000000000000000000000000000000000000000000000000' + + # command to configure IP addresses etc. after the tunnel interface is up; $1 will be the interface name (optional) +# option up '' + + # command to execute before the tunnel interface is set down; $1 will be the interface name (optional) +# option down '' diff --git a/net/fastd/files/fastd.init b/net/fastd/files/fastd.init new file mode 100644 index 0000000..0f347af --- /dev/null +++ b/net/fastd/files/fastd.init @@ -0,0 +1,199 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2012 OpenWrt.org + +START=95 + +EXTRA_COMMANDS="up down show_key" + +LIST_SEP=" +" +TMP_FASTD=/tmp/fastd +FASTD_COMMAND=/usr/sbin/fastd + +append_opt() { + local v="$1"; local p="$2" + + OPTS="$OPTS --${p//_/-} '${v//'/\\'}'" +} + +append_opt_bool() { + local p="$1" + + OPTS="$OPTS --${p//_/-}" +} + +append_opts() { + local p; local v; local s="$1"; shift + for p in $*; do + config_get v "$s" "$p" + [ -n "$v" ] && append_opt "$v" "$p" + done +} + +append_opts_bool() { + local p; local v; local s="$1"; shift + for p in $*; do + config_get_bool v "$s" "$p" 0 + [ "$v" == 1 ] && append_opt_bool "$p" + done +} + +append_opts_list() { + local p; local s="$1"; shift + for p in $*; do + config_list_foreach "$s" "$p" append_opt "$p" + done +} + +section_enabled() { + config_get_bool enabled "$1" 'enabled' 0 + [ $enabled -gt 0 ] +} + +error() { + echo "${initscript}:" "$@" 1>&2 +} + +start_instance() { + local s="$1" + + section_enabled "$s" || return 1 + + SERVICE_PID_FILE="/var/run/fastd.$s.pid" + OPTS="" + + config_get interface "$s" interface + if [ -z "$interface" ]; then + error "$s: interface is not set" + return 1 + fi + + if ifconfig "$interface" &>/dev/null; then + error "$s: interface '$interface' is already in use" + return 1 + fi + + config_get secret "$s" secret + if [ -z "$secret" ]; then + error "$s: secret is not set" + return 1 + fi + + append_opts_list "$s" config config_peer_dir + append_opts "$s" syslog_level bind method mode interface mtu + append_opts_bool "$s" forward + + mkdir -p "$TMP_FASTD" + echo "secret \"$secret\";" > "$TMP_FASTD/secret.$s.conf" + + eval service_start "'$FASTD_COMMAND'" --daemon --pid-file "'$SERVICE_PID_FILE'" --syslog-level info $OPTS --config "'$TMP_FASTD/secret.$s.conf'" + + if ! ifconfig "$interface" >/dev/null 2>&1; then + error "$s: startup failed" + return 1 + fi + + config_get up "$s" up + [ -n "$up" ] && sh -c "$up" - "$interface" +} + +stop_instance() { + local s="$1" + + section_enabled "$s" || return 1 + + SERVICE_PID_FILE="/var/run/fastd.$s.pid" + + config_get interface "$s" interface + if [ -z "$interface" ]; then + error "$s: interface is not set" + return 1 + fi + + if ! ifconfig "$interface" &>/dev/null; then + error "$s: interface '$interface' does not exist" + return 1 + fi + + config_get down "$s" down + [ -n "$down" ] && sh -c "$down" - "$interface" + + service_stop "$FASTD_COMMAND" + + rm -f "$TMP_FASTD/secret.$s.conf" +} + +show_key_instance() { + local s="$1" + + config_get secret "$s" secret + if [ -z "$secret" ]; then + error "$s: secret is not set" + return 1 + fi + + mkdir -p "$TMP_FASTD" + echo "secret \"$secret\";" > "$TMP_FASTD/secret.$s.conf" + + "$FASTD_COMMAND" --config "$TMP_FASTD/secret.$s.conf" --show-key --machine-readable +} + +reload_instance() { + local s="$1" + + section_enabled "$s" || return 1 + + SERVICE_PID_FILE="/var/run/fastd.$s.pid" + service_reload "$FASTD_COMMAND" +} + +start() { + config_load 'fastd' + config_foreach start_instance 'fastd' +} + +stop() { + config_load 'fastd' + config_foreach stop_instance 'fastd' +} + +reload() { + config_load 'fastd' + config_foreach reload_instance 'fastd' +} + +up() { + local exists + local instance + config_load 'fastd' + for instance in "$@"; do + config_get exists "$instance" 'TYPE' + if [ "$exists" == "fastd" ]; then + start_instance "$instance" + fi + done +} + +down() { + local exists + local instance + config_load 'fastd' + for instance in "$@"; do + config_get exists "$instance" 'TYPE' + if [ "$exists" == "fastd" ]; then + stop_instance "$instance" + fi + done +} + +show_key() { + local exists + local instance + config_load 'fastd' + for instance in "$@"; do + config_get exists "$instance" 'TYPE' + if [ "$exists" == "fastd" ]; then + show_key_instance "$instance" + fi + done +} diff --git a/net/fastd/files/fastd.upgrade b/net/fastd/files/fastd.upgrade new file mode 100644 index 0000000..7406613 --- /dev/null +++ b/net/fastd/files/fastd.upgrade @@ -0,0 +1 @@ +/etc/fastd/