tunneldigger: add package for establishing L2TPv3 tunnels over UDP
authorNick Hainke <vincent@systemli.org>
Thu, 8 Jun 2023 12:34:09 +0000 (14:34 +0200)
committerNick Hainke <vincent@systemli.org>
Mon, 12 Jun 2023 14:57:55 +0000 (16:57 +0200)
In the previous commit we already added tunneldigger-broker. Add the
corresponding client.

This PR is just a refactoring of the already existing opkg package from
wlanslovenija [0].

[0] - https://github.com/wlanslovenija/firmware-packages-opkg/tree/master/net/tunneldigger

Signed-off-by: Nick Hainke <vincent@systemli.org>
(cherry picked from commit bd2b4f311a95b64e019ef29f7c01326a3dfee7d1)

net/tunneldigger/Makefile [new file with mode: 0644]
net/tunneldigger/files/config.default [new file with mode: 0644]
net/tunneldigger/files/tunneldigger.init [new file with mode: 0644]

diff --git a/net/tunneldigger/Makefile b/net/tunneldigger/Makefile
new file mode 100644 (file)
index 0000000..8cab922
--- /dev/null
@@ -0,0 +1,57 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=tunneldigger
+PKG_RELEASE:=1
+
+PKG_SOURCE_URL:=https://github.com/wlanslovenija/tunneldigger.git
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_VERSION:=4f72b30578ac3dbc5482f4a54054bf870355bdf5
+PKG_MIRROR_HASH:=babc71c757b757026f63e298bd4bd0edceae220827fff5cfad0af3f04ed529c7
+
+PKG_MAINTAINER:=Nick Hainke <vincent@systemli.org>
+PKG_LICENSE:=AGPL-3.0
+PKG_LICENSE_FILES:=COPYING
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/cmake.mk
+
+CMAKE_SOURCE_SUBDIR:=client
+
+define Package/tunneldigger
+  SECTION:=net
+  CATEGORY:=Network
+  DEPENDS:= \
+       +kmod-l2tp \
+       +kmod-l2tp-ip \
+       +kmod-l2tp-eth \
+       +libnl-tiny \
+       +libpthread \
+       +librt
+  TITLE:=L2TPv3 tunneling via UDP
+  URL:=https://github.com/wlanslovenija/tunneldigger
+endef
+
+TARGET_CFLAGS += \
+       -I$(STAGING_DIR)/usr/include/libnl-tiny \
+       -I$(STAGING_DIR)/usr/include \
+       -DLIBNL_TINY
+
+define Package/tunneldigger/description
+Tunneldigger is a simple VPN tunneling solution based on the Linux kernel
+support for L2TPv3 tunnels over UDP.
+endef
+
+define Package/tunneldigger/conffiles
+/etc/config/tunneldigger
+endef
+
+define Package/tunneldigger/install
+       $(INSTALL_DIR) $(1)/usr/bin
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/tunneldigger $(1)/usr/bin/tunneldigger
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/tunneldigger.init $(1)/etc/init.d/tunneldigger
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_DATA) ./files/config.default $(1)/etc/config/tunneldigger
+endef
+
+$(eval $(call BuildPackage,tunneldigger))
diff --git a/net/tunneldigger/files/config.default b/net/tunneldigger/files/config.default
new file mode 100644 (file)
index 0000000..571621a
--- /dev/null
@@ -0,0 +1,8 @@
+config broker
+       list address 'x.y.z.w:8942'
+       list address 'x.y.z.w:53'
+       list address 'x.y.z.w:123'
+       option uuid 'abcd'
+       option interface 'l2tp0'
+       option limit_bw_down '1024'
+       option enabled '0'
diff --git a/net/tunneldigger/files/tunneldigger.init b/net/tunneldigger/files/tunneldigger.init
new file mode 100644 (file)
index 0000000..ea37751
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/sh /etc/rc.common
+
+. $IPKG_INSTROOT/lib/functions/network.sh
+
+USE_PROCD=1
+START=90
+
+tunnel_id=1
+
+missing() {
+       echo "Not starting tunneldigger - missing $1" >&2
+}
+
+parse_broker() {
+       local section="$1"
+
+       config_get_bool enabled "$section" enabled 1
+       config_get addresses "$section" address
+       config_get uuid "$section" uuid
+       config_get interface "$section" interface
+       config_get limit_bw_down "$section" limit_bw_down
+       config_get hook_script "$section" hook_script
+       config_get bind_interface "$section" bind_interface
+       
+       [ $enabled -eq 0 ] && return
+
+       local broker_opts=""
+       for address in $addresses; do
+               append broker_opts "-b ${address}"
+       done
+
+       [ ! -z "${limit_bw_down}" ] && append broker_opts "-L ${limit_bw_down}"
+       [ ! -z "${hook_script}" ] && append broker_opts "-s ${hook_script}"
+       [ ! -z "${bind_interface}" ] && {
+               # Resolve logical interface name.
+               unset _bind_interface
+               network_get_device _bind_interface "${bind_interface}" || _bind_interface="${bind_interface}"
+               append broker_opts "-I ${_bind_interface}"
+       }
+
+       if [ -z "$uuid" ]; then
+               missing uuid
+               return
+       elif [ -z "$interface" ]; then
+               missing interface
+               return
+       fi
+
+       procd_open_instance "tunneldigger_${tunnel_id}"
+       procd_set_param command "/usr/bin/tunneldigger"
+       procd_append_param command -f
+       procd_append_param command -u "${uuid}"
+       procd_append_param command -i "${interface}"
+       procd_append_param command -t "${tunnel_id}"
+       procd_append_param command ${broker_opts}
+       procd_set_param stdout 1
+       procd_set_param stderr 1
+       procd_set_param respawn
+       procd_close_instance
+
+       let tunnel_id++
+}
+
+start_service() {
+       config_load tunneldigger
+       config_foreach parse_broker broker
+}