From f755690b0e29b96ed3d23c8f48454d481847018a Mon Sep 17 00:00:00 2001 From: Nick Hainke Date: Thu, 6 Jan 2022 22:03:18 +0100 Subject: [PATCH] wg-installer: add hotplug script for olsr Add hotplug-olsrd to automatically mesh with olsrd via new wireguard links. Signed-off-by: Nick Hainke (cherry picked from commit d35c22951bfabb9b34133471fe1e389909d2007b) --- net/wg-installer/Makefile | 11 +++++++ .../wg-server/hotplug.d/99-mesh-olsrd | 33 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 net/wg-installer/wg-server/hotplug.d/99-mesh-olsrd diff --git a/net/wg-installer/Makefile b/net/wg-installer/Makefile index b39a8903cd..dc1983b440 100644 --- a/net/wg-installer/Makefile +++ b/net/wg-installer/Makefile @@ -58,6 +58,16 @@ define Package/wg-installer-server-hotplug-babeld/install $(INSTALL_BIN) ./wg-server/hotplug.d/99-mesh-babeld $(1)/etc/hotplug.d/net/99-mesh-babeld endef +define Package/wg-installer-server-hotplug-olsrd + $(call Package/wg-installer-server) + DEPENDS:=wg-installer-server +endef + +define Package/wg-installer-server-hotplug-olsrd/install + $(INSTALL_DIR) $(1)/etc/hotplug.d/net/ + $(INSTALL_BIN) ./wg-server/hotplug.d/99-mesh-olsrd $(1)/etc/hotplug.d/net/99-mesh-olsrd +endef + define Package/wg-installer-client $(call Package/wg-installer/Default) TITLE+= (client) @@ -78,4 +88,5 @@ endef $(eval $(call BuildPackage,wg-installer-server)) $(eval $(call BuildPackage,wg-installer-server-hotplug-babeld)) +$(eval $(call BuildPackage,wg-installer-server-hotplug-olsrd)) $(eval $(call BuildPackage,wg-installer-client)) diff --git a/net/wg-installer/wg-server/hotplug.d/99-mesh-olsrd b/net/wg-installer/wg-server/hotplug.d/99-mesh-olsrd new file mode 100644 index 0000000000..648ef6989d --- /dev/null +++ b/net/wg-installer/wg-server/hotplug.d/99-mesh-olsrd @@ -0,0 +1,33 @@ +#!/bin/sh + +# check if wireguard +if [ "${DEVTYPE}" != "wireguard" ]; then + exit 0 +fi + +# check if correct naming +slicedint=$(echo $INTERFACE | cut -c1-3) +if [ "${slicedint}" != "wg_" ]; then + exit 0 +fi + +if [ "${ACTION}" == "add" ]; then + uci add olsrd Interface + uci set olsrd.@Interface[-1].ignore=0 + uci set olsrd.@Interface[-1].interface="${INTERFACE}" + uci set olsrd.@Interface[-1].Mode="ether" + uci commit + /etc/init.d/olsrd reload +fi + +if [ "${ACTION}" == "remove" ]; then + i=0 + while uci get olsrd.@Interface[$i] &> /dev/null ; do + if [ "$(uci get olsrd.@Interface[$i].interface)" == "${INTERFACE}" ]; then + uci delete olsrd.@Interface[$i] + fi + i=$((i+1)); + done + uci commit + /etc/init.d/olsrd reload +fi -- 2.30.2