From cf95f2d8362ca10b5ec57eb4c1091f12778fcc33 Mon Sep 17 00:00:00 2001 From: Ycarus Date: Wed, 6 Jun 2018 17:57:59 +0200 Subject: [PATCH] Add MLVPN package --- mlvpn/Makefile | 61 +++++++++++++++++++++ mlvpn/files/etc/config/mlvpn | 10 ++++ mlvpn/files/etc/init.d/mlvpn | 73 +++++++++++++++++++++++++ mlvpn/files/etc/uci-defaults/4100-mlvpn | 30 ++++++++++ mlvpn/patches/010-musl-fix.patch | 11 ++++ 5 files changed, 185 insertions(+) create mode 100644 mlvpn/Makefile create mode 100644 mlvpn/files/etc/config/mlvpn create mode 100755 mlvpn/files/etc/init.d/mlvpn create mode 100644 mlvpn/files/etc/uci-defaults/4100-mlvpn create mode 100644 mlvpn/patches/010-musl-fix.patch diff --git a/mlvpn/Makefile b/mlvpn/Makefile new file mode 100644 index 000000000..9b14ee449 --- /dev/null +++ b/mlvpn/Makefile @@ -0,0 +1,61 @@ +# +# Copyright (C) 2017 Zhong Jianxin +# Copyright (C) 2018 Ycarus (Yannick Chabanois) +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +include $(TOPDIR)/rules.mk + +PKG_NAME:=mlvpn +PKG_VERSION:=6f13423b +#PKG_VERSION:=238ae265 +PKG_RELEASE:=1 + +PKG_SOURCE_PROTO:=git +PKG_SOURCE_URL:=https://github.com/zehome/MLVPN.git +PKG_SOURCE_VERSION:=6f13423b8108f46edb9f230deee20e3741abe64c +PKG_SOURCE_DATE:=2017-09-01 +#PKG_SOURCE_URL:=https://github.com/markfoodyburton/MLVPN.git +#PKG_SOURCE_VERSION:=238ae26563740390f3e1eb0e2c83a7d0dc4e920f +#PKG_SOURCE_DATE:=2018-05-31 + +PKG_LICENSE:=BSD-2-Clause +PKG_MAINTAINER:=Ycarus (Yannick Chabanois) + +PKG_INSTALL:=1 +PKG_FIXUP:=autoreconf +PKG_BUILD_PARALLEL:=1 + +include $(INCLUDE_DIR)/package.mk + +define Package/mlvpn + TITLE:=Multi-Link Virtual Public Network + SECTION:=net + CATEGORY:=Network + URL:=https://zehome.github.io/MLVPN/ + SUBMENU:=VPN + MENU:=1 + DEPENDS:=+kmod-tun +libev +libpcap +libsodium +endef + +define Package/mlvpn/description + Multi-Link Virtual Public Network + Bond your internet links to increase bandwidth (unlimited). + Secure your internet connection by actively monitoring your links and removing the faulty ones, without loosing your TCP connections. + Secure your internet connection to the aggregation server using strong cryptography. + Scriptable automation and monitoring. +endef + +define Package/mlvpn/conffiles +/etc/config/mlvpn +endef + +define Package/mlvpn/install + $(INSTALL_DIR) $(1) + $(CP) ./files/* $(1)/ + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/mlvpn $(1)/usr/sbin/ +endef + +$(eval $(call BuildPackage,mlvpn)) diff --git a/mlvpn/files/etc/config/mlvpn b/mlvpn/files/etc/config/mlvpn new file mode 100644 index 000000000..19c261289 --- /dev/null +++ b/mlvpn/files/etc/config/mlvpn @@ -0,0 +1,10 @@ +config mlvpn 'general' + option enable '0' + option password '*****' + option timeout '30' + option reorder_buffer_size '64' + option loss_tolerence '50' + option mode 'client' + option remotehost '128.128.128.128' + option firstremoteport '65201' + option interface_name 'mlvpn0' diff --git a/mlvpn/files/etc/init.d/mlvpn b/mlvpn/files/etc/init.d/mlvpn new file mode 100755 index 000000000..e9e46260c --- /dev/null +++ b/mlvpn/files/etc/init.d/mlvpn @@ -0,0 +1,73 @@ +#!/bin/sh /etc/rc.common + +START=88 +USE_PROCD=1 + +validate_section() { + uci_validate_section mlvpn mlvpn ${1} \ + 'enable:bool:0' \ + 'timeout:uinteger:30' \ + 'mode:string:client' \ + 'password:string' \ + 'reorder_buffer_size:uinteger:64' \ + 'loss_tolerence:uinteger:30' \ + 'interface_name:string:mlvpn0' \ + 'remotehost:host' \ + 'firstremoteport:port:65201' +} + +interface_settings() { + local mode + local config="$1" + id=$(($id+1)) + config_get mode "$config" multipath "off" + [ "$mode" = "off" ] && return 1 + count=$(($count+1)) + port=$((firstremoteport+count)) + cat >> /tmp/etc/${interface_name}.conf <<-EOF + + [${id}] + remotehost = "${remotehost}" + remoteport = "${port}" + EOF +} + +start_service() { + local enable timeout mode password reorder_buffer_size interface_name remotehost firstremoteport loss_tolerence + validate_section "general" || { + _err "validation failed" + return 1 + } + + [ "${enable}" = "1" ] || return 1 + + if [ "$(uci -q get network.omrvpn)" != "" ]; then + uci -q set network.omrvpn.ifname=mlvpn0 + fi + + cat > /tmp/etc/${interface_name}.conf <<-EOF + [general] + tuntap = "tun" + mode = "${mode}" + interface_name = "${interface_name}" + timeout = ${timeout} + reorder_buffer_size = ${reorder_buffer_size} + loss_tolerence = ${loss_tolerence} + password = "${password}" + EOF + local count=0 id=0 + config_load network + config_foreach interface_settings interface + + chmod 0600 "/tmp/etc/${interface_name}.conf" + procd_open_instance + procd_set_param command /usr/sbin/mlvpn --config "/tmp/etc/${interface_name}.conf" --user nobody + procd_set_param file "/tmp/etc/${interface_name}.conf" + procd_set_param reload_signal SIGHUP + procd_set_param respawn + procd_close_instance +} + +service_triggers() { + procd_add_reload_trigger mlvpn network +} \ No newline at end of file diff --git a/mlvpn/files/etc/uci-defaults/4100-mlvpn b/mlvpn/files/etc/uci-defaults/4100-mlvpn new file mode 100644 index 000000000..cd165c37a --- /dev/null +++ b/mlvpn/files/etc/uci-defaults/4100-mlvpn @@ -0,0 +1,30 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@mlvpn[-1] + add ucitrack mlvpn + set ucitrack.@mlvpn[-1].init=mlvpn + commit ucitrack +EOF + +if [ "$(uci -q get network.omrvpn)" = "" ] && [ "$(uci -q get network.mlvpn)" = "" ]; then + uci -q batch <<-EOF >/dev/null + delete network.mlvpn=interface + set network.mlvpn=interface + set network.mlvpn.ifname=mlvpn0 + set network.mlvpn.proto=dhcp + set network.mlvpn.ip4table=vpn + set network.mlvpn.multipath=off + set network.mlvpn.leasetime=12h + set network.mlvpn.mtu=1440 + commit network + EOF +fi + +if [ "$(uci get firewall.@zone[2].network | grep omrvpn)" = "" ] && [ "$(uci get firewall.@zone[2].network | grep mlvpn)" = "" ]; then + uci -q batch <<-EOF >/dev/null + add_list firewall.@zone[2].network='mlvpn' + EOF +fi +rm -f /tmp/luci-indexcache +exit 0 diff --git a/mlvpn/patches/010-musl-fix.patch b/mlvpn/patches/010-musl-fix.patch new file mode 100644 index 000000000..851d3dfca --- /dev/null +++ b/mlvpn/patches/010-musl-fix.patch @@ -0,0 +1,11 @@ +--- a/src/privsep.c ++++ b/src/privsep.c +@@ -778,7 +778,7 @@ sig_got_chld(int sig) + pid_t pid; + + do { +- pid = waitpid(WAIT_ANY, NULL, WNOHANG); ++ pid = waitpid(-1, NULL, WNOHANG); + if (pid == child_pid && cur_state < STATE_QUIT) + cur_state = STATE_QUIT; + } while (pid > 0 || (pid == -1 && errno == EINTR));