From 828bbd61d60c7844e82eb5d53dfbbded1b321d53 Mon Sep 17 00:00:00 2001 From: William Fleurant Date: Wed, 20 Dec 2023 19:00:01 +0100 Subject: [PATCH] yggdrasil-jumper: add multiple ygg support Signed-off-by: William Fleurant --- net/yggdrasil-jumper/Makefile | 32 +++-- .../files/yggdrasil-jumper.defaults | 47 ++++++++ .../files/yggdrasil-jumper.init | 112 ++++++++++++++++++ 3 files changed, 181 insertions(+), 10 deletions(-) create mode 100644 net/yggdrasil-jumper/files/yggdrasil-jumper.defaults create mode 100755 net/yggdrasil-jumper/files/yggdrasil-jumper.init diff --git a/net/yggdrasil-jumper/Makefile b/net/yggdrasil-jumper/Makefile index 2723ca7e6f..d8e40b889b 100644 --- a/net/yggdrasil-jumper/Makefile +++ b/net/yggdrasil-jumper/Makefile @@ -17,6 +17,7 @@ PKG_BUILD_PARALLEL:=1 include $(INCLUDE_DIR)/package.mk include ../../lang/rust/rust-package.mk + define Package/yggdrasil-jumper SECTION:=net CATEGORY:=Network @@ -26,25 +27,36 @@ define Package/yggdrasil-jumper DEPENDS:=$(RUST_ARCH_DEPENDS) @!arc @IPV6 +kmod-tun endef + define Package/yggdrasil-jumper/description - Yggdrasil-jumper enhances the performance of data-intensive applications over the Yggdrasil - network by establishing direct peer-to-peer connections, bypassing intermediary nodes. - It utilizes NAT traversal to create a direct bridge to potentially reduce latency. + Yggdrasil-Jumper utilizes NAT traversal for latency reduction within the Yggdrasil network by + creating direct peer-to-peer connections. It offers self-activating NAT/Firewall traversal, + eliminating the necessity for firewall or port configuration. It probles for Yggdrasil-Jumper + of routers found in active sessions to leverage NAT traversal for constructing direct internet + bridges. endef -# define Package/yggdrasil-jumper/conffiles -# /etc/yggdrasil-jumper/yggdrasil-jumper.conf -# endef define Package/yggdrasil-jumper/install - $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/uci-defaults $(1)/etc/init.d + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/bin/yggdrasil-jumper $(1)/usr/sbin - $(INSTALL_BIN) $(PKG_INSTALL_DIR)/bin/stun-tcp $(1)/usr/sbin - # $(INSTALL_DIR) $(1)/etc/yggdrasil-jumper - # $(INSTALL_CONF) ./files/etc/yggdrasil-jumper/yggdrasil-jumper.conf $(1)/etc/yggdrasil-jumper + $(INSTALL_BIN) ./files/yggdrasil-jumper.defaults $(1)/etc/uci-defaults/yggdrasil-jumper + $(INSTALL_BIN) ./files/yggdrasil-jumper.init $(1)/etc/init.d/yggdrasil-jumper endef + +define Package/cjdns/postinst +#!/bin/sh +if [ -z $${IPKG_INSTROOT} ] ; then + ( . /etc/uci-defaults/yggdrasil-jumper ) && rm -f /etc/uci-defaults/yggdrasil-jumper + /etc/init.d/yggdrasil-jumper enabled || /etc/init.d/yggdrasil-jumper enable + exit 0 +fi +endef + + $(eval $(call RustBinPackage,yggdrasil-jumper)) $(eval $(call BuildPackage,yggdrasil-jumper)) diff --git a/net/yggdrasil-jumper/files/yggdrasil-jumper.defaults b/net/yggdrasil-jumper/files/yggdrasil-jumper.defaults new file mode 100644 index 0000000000..5954370cba --- /dev/null +++ b/net/yggdrasil-jumper/files/yggdrasil-jumper.defaults @@ -0,0 +1,47 @@ +#!/bin/sh + +# if there is an existing config, our work is already done +uci -q get yggdrasil-jumper.config.stun_server >/dev/null 2>&1 + +if [ $? -ne 0 ]; then + + # register commit handler + uci -q batch <<-EOF >/dev/null + delete ucitrack.@yggdrasil-jumper[-1] + add ucitrack yggdrasil-jumper + set ucitrack.@yggdrasil-jumper[-1].init=yggdrasil-jumper + commit ucitrack +EOF + + # generate configuration + touch /etc/config/yggdrasil-jumper + + uci batch <<-EOF + set yggdrasil-jumper.config=yggdrasil-jumper + set yggdrasil-jumper.config.listen_port=4701 + set yggdrasil-jumper.config.allow_ipv4=1 + set yggdrasil-jumper.config.allow_ipv6=0 + add_list yggdrasil-jumper.config.stun_server='stunserver.stunprotocol.org:3478' + add_list yggdrasil-jumper.config.stun_server='136.243.59.79:3478' + add_list yggdrasil-jumper.config.stun_server='34.192.137.246:3478' + add_list yggdrasil-jumper.config.stun_server='94.130.130.49:3478' + add_list yggdrasil-jumper.config.stun_server='192.172.233.145:3478' + add_list yggdrasil-jumper.config.stun_server='185.125.180.70:3478' + add_list yggdrasil-jumper.config.stun_server='95.216.78.222:3478' + add_list yggdrasil-jumper.config.stun_server='88.99.67.241:3478' + add_list yggdrasil-jumper.config.stun_server='88.218.220.40:3478' + add_list yggdrasil-jumper.config.stun_server='54.177.85.190:3478' + add_list yggdrasil-jumper.config.stun_server='88.198.151.128:3478' + add_list yggdrasil-jumper.config.stun_server='83.64.250.246:3478' + add_list yggdrasil-jumper.config.stun_server='62.72.83.10:3478' + add_list yggdrasil-jumper.config.stun_server='202.1.117.2:3478' + add_list yggdrasil-jumper.config.stun_server='188.118.52.172:3478' + add_list yggdrasil-jumper.config.stun_server='51.83.201.84:3478' + add_list yggdrasil-jumper.config.stun_server='34.206.168.53:3478' + add_list yggdrasil-jumper.config.stun_server='157.161.10.32:3478' + add_list yggdrasil-jumper.config.stun_server='91.213.98.54:3478' + set yggdrasil-jumper.config.stun_randomize=1 + commit yggdrasil-jumper +EOF + +fi diff --git a/net/yggdrasil-jumper/files/yggdrasil-jumper.init b/net/yggdrasil-jumper/files/yggdrasil-jumper.init new file mode 100755 index 0000000000..b1e6acb6f5 --- /dev/null +++ b/net/yggdrasil-jumper/files/yggdrasil-jumper.init @@ -0,0 +1,112 @@ +#!/bin/sh /etc/rc.common + +START=98 +STOP=98 + +USE_PROCD=1 + +YGG_JUMPER_INTERFACES="" + + +envset_jumper_interfaces() { + + all_ygg_interfaces=$(uci show network | grep ".proto='yggdrasil'" | awk -F '.' '{print $2}') + + for interface in ${all_ygg_interfaces}; do + + is_started_on_boot="$(uci -q get network.${interface}.auto)" + + if [ "${is_started_on_boot}" == "0" ]; then + : # Skip interface is is disabled + else + + is_yggdrasil_jumper_enabled="$(uci -q get network.${interface}.jumper)" + + YGG_JUMPER_INTERFACES=" $YGG_JUMPER_INTERFACES ${interface} " + + ## - [ ] add jumper flag support in luci-proto-yggdrasil + # if [ "${is_yggdrasil_jumper_enabled}" == "1" ]; then + # : # Append yggdrasil + jumper interface to the global + # YGG_JUMPER_INTERFACES=" $YGG_JUMPER_INTERFACES ${interface} " + # fi + fi + + done + + : # Strip leading/trailing space + YGG_JUMPER_INTERFACES="$(echo ${YGG_JUMPER_INTERFACES} | xargs)" + + +} + + +uci_to_jumper_configs() { + # remove stale not used configs avoiding confusion + cfgs="/tmp/yggdrasil/*-jumper.conf" + rm $cfgs + + # scoop up uci details from /etc/config/yggdrasil-jumper + admin_listen=$(uci -q get yggdrasil-jumper.config.admin_listen) + listen_port=$(uci -q get yggdrasil-jumper.config.listen_port) + allow_ipv4=$(uci -q get yggdrasil-jumper.config.allow_ipv4) + allow_ipv6=$(uci -q get yggdrasil-jumper.config.allow_ipv6) + stun_server=$(uci -q get yggdrasil-jumper.config.stun_server) + stun_randomize=$(uci -q get yggdrasil-jumper.config.stun_randomize) + + for interface in $YGG_JUMPER_INTERFACES; do + ali="unix:///tmp/yggdrasil/${interface}.sock" + cfg="/tmp/yggdrasil/${interface}-jumper.conf" +: # write a interface-jumper.conf file for yggdrasil interface + cat < "${cfg}" +yggdrasil_admin_listen = [ "${ali}" ] +yggdrasil_listen = [ ] +listen_port = $listen_port +allow_ipv4 = $( [ "$allow_ipv4" = "1" ] && echo true || echo false ) +allow_ipv6 = $( [ "$allow_ipv6" = "1" ] && echo true || echo false ) +whitelist = [ ] +stun_servers = [ "${stun_server// /\",\"}" ] +stun_randomize = $( [ "$stun_randomize" = "1" ] && echo true || echo false ) +EOF + done + + +} + + +start_service() { + [ -f /etc/uci-defaults/yggdrasil-jumper ] && ( . /etc/uci-defaults/yggdrasil-jumper ) + + envset_jumper_interfaces + + uci_to_jumper_configs + + for interface in $YGG_JUMPER_INTERFACES; do + jumper_cfg="/tmp/yggdrasil/${interface}-jumper.conf" + procd_open_instance ${interface} + procd_set_param respawn + procd_set_param command yggdrasil-jumper --config "${jumper_cfg}" + procd_set_param facility "yggdrasil-jumper-${interface}" + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_close_instance + done + +} + + +stop_service() { + killall yggdrasil-jumper +} + + +x_reload_service() { + : + # cat /tmp/etc/cjdroute.conf | cjdrouteconf reload +} + + +service_triggers() { + procd_add_reload_trigger yggdrasil-jumper +} + + -- 2.30.2