Skip to content

Commit

Permalink
mlvpn: Add package (Multi-Link Virtual Public Network)
Browse files Browse the repository at this point in the history
Signed-off-by: Zhong Jianxin <azuwis@gmail.com>
  • Loading branch information
azuwis committed Apr 1, 2019
1 parent d64590a commit 6aeb566
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 0 deletions.
62 changes: 62 additions & 0 deletions net/mlvpn/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# Copyright (C) 2017 Zhong Jianxin <azuwis@gmail.com>
#
# 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:=2.3.2
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/zehome/MLVPN.git
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=6f13423b8108f46edb9f230deee20e3741abe64c
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.xz
PKG_MIRROR_HASH:=e77916143162ffa050bc07482264f726b0c03a8fa9e07bb594a3759f512830cd

PKG_LICENSE:=BSD-2-Clause
PKG_MAINTAINER:=Zhong Jianxin <azuwis@gmail.com>

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/mlvpn/
endef

define Package/mlvpn/install
$(INSTALL_DIR) \
$(1)/usr/sbin \
$(1)/etc/init.d \
$(1)/etc/mlvpn \

$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/mlvpn $(1)/usr/sbin/
install -m0700 files/mlvpn-updown $(1)/usr/sbin/
$(INSTALL_BIN) files/mlvpn.init $(1)/etc/init.d/mlvpn
endef

$(eval $(call BuildPackage,mlvpn))
115 changes: 115 additions & 0 deletions net/mlvpn/files/mlvpn-updown
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/sh

# up/down script for MLVPN.
#
# MLVPN calls this script with at least 2 arguments:
# $1 : interface name
# $2 : "command"
# command can be:
# - "tuntap_up"
# - "tuntap_down"
# - "rtun_up" $3 : tunnel name
# - "rtun_down" $3 : tunnel name
# tuntap_up is called when at least one tunnel is up
# tuntap_down is called when at every tunnel is down
# rtun_up is called when successfully connected
# rtun_down is called when disconnected

# Environment variables are set by mlvpn, reflecting
# settings in mlvpn.conf
# IP4=
# IP6=
# IP4_GATEWAY=
# IP6_GATEWAY=
# IP4_ROUTES=
# IP6_ROUTES=
# MTU=
# DEVICE=

DEVICE="$1"
STATUS="$2"

[ -z "$STATUS" ] || [ -z "$DEVICE" ] || [ -z "$MTU" ] && exit 1

unamestr=$(uname)

link_up()
{
if [ "$unamestr" = "Linux" ]; then
ip link set dev "$DEVICE" mtu "$MTU" up
if [ ! -z "$IP4" ]; then
ip -4 addr add "$IP4" dev "$DEVICE"
fi
if [ ! -z "$IP6" ]; then
ip -6 addr add "$IP6" dev "$DEVICE"
fi
else
ifconfig "$DEVICE" mtu "$MTU" up
if [ ! -z "$IP4" ] && [ ! -z "$IP4_GATEWAY" ]; then
ifconfig "$DEVICE" inet "$IP4" "$IP4_GATEWAY" mtu "$MTU" up
fi
if [ ! -z "$IP6" ] && [ ! -z "$IP6_GATEWAY" ]; then
ifconfig "$DEVICE" inet "$IP6" "$IP6_GATEWAY" mtu "$MTU" up
fi
fi
}
link_down()
{
if [ "$unamestr" = "Linux" ]; then
ip link set dev "$DEVICE" down
else
ifconfig "$DEVICE" down
fi
}
route_add()
{
family=$1
route=$2
if [ "$unamestr" = "Linux" ]; then
via=""
if [ "$family" = "4" ]; then
[ -z "$IP4_GATEWAY" ] || via="via $IP4_GATEWAY"
ip -4 route add "$route" $via dev "$DEVICE"
elif [ "$family" = "6" ]; then
[ -z "$IP6_GATEWAY" ] || via="via $IP6_GATEWAY"
ip -6 route add "$route" $via dev "$DEVICE"
fi
else
if [ "$family" = "4" ]; then
route add -inet "$route" "$IP4_GATEWAY"
elif [ "$family" = "6" ]; then
route add -inet6 "$route" "$IP6_GATEWAY"
fi
fi
}

(
ECHO="echo"
[ "$MTU" -gt 1452 ] && (echo "MTU set too high."; exit 1)
[ "$MTU" -lt 100 ] && (echo "MTU set too low."; exit 1)
case "$STATUS" in
"tuntap_up")
$ECHO "$DEVICE up"
link_up
for r in $IP4_ROUTES; do
route_add 4 "$r"
done
for r in $IP6_ROUTES; do
route_add 6 "$r"
done
;;
"tuntap_down")
$ECHO "$DEVICE down"
link_down
;;
"rtun_up")
$ECHO "tunnel [$3] is up"
;;
"rtun_down")
$ECHO "tunnel [$3] is down"
;;
esac

) 2>&1 | logger -t mlvpn

exit 0
17 changes: 17 additions & 0 deletions net/mlvpn/files/mlvpn.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh /etc/rc.common

START=88
USE_PROCD=1

start_service() {
for path in /etc/mlvpn/*.conf; do
if [ -f "$path" ]; then
procd_open_instance
procd_set_param command /usr/sbin/mlvpn --config "$path" --user nobody
procd_set_param file "$path"
procd_set_param reload_signal SIGHUP
procd_set_param respawn
procd_close_instance
fi
done
}
11 changes: 11 additions & 0 deletions net/mlvpn/patches/010-musl-fix.patch
Original file line number Diff line number Diff line change
@@ -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));

0 comments on commit 6aeb566

Please sign in to comment.