wg-installer: add babeld hotplug.d script
authorNick Hainke <vincent@systemli.org>
Sun, 7 Feb 2021 19:47:59 +0000 (20:47 +0100)
committerPolynomdivision <vincent@systemli.org>
Mon, 8 Feb 2021 10:38:36 +0000 (11:38 +0100)
Add a hotplug.d-extension that automatically configures babeld for
meshing via wireguard interfaces.

It checks for "add" and "remove" of a wireguard interface with name
"wg_*". Depending on the action, it removes it from the babeld config
or adds the interface and reloads babeld.

Signed-off-by: Nick Hainke <vincent@systemli.org>
net/wg-installer/Makefile
net/wg-installer/README.md
net/wg-installer/wg-server/hotplug.d/99-mesh-babeld [new file with mode: 0644]

index d43407b03b41046c688a3640d31c3a7f8b58896b..b39a8903cdf273327610a80c328fff173ede7000 100644 (file)
@@ -21,6 +21,7 @@ endef
 define Package/wg-installer-server
        $(call Package/wg-installer/Default)
        TITLE+= (server)
+       MENU:=1
        DEPENDS:=+rpcd +uhttpd +uhttpd-mod-ubus +owipcalc
 endef
 
@@ -47,6 +48,16 @@ define Package/wg-installer-server/postinst
        fi
 endef
 
+define Package/wg-installer-server-hotplug-babeld
+       $(call Package/wg-installer-server)
+       DEPENDS:=wg-installer-server
+endef
+
+define Package/wg-installer-server-hotplug-babeld/install
+       $(INSTALL_DIR) $(1)/etc/hotplug.d/net/
+       $(INSTALL_BIN) ./wg-server/hotplug.d/99-mesh-babeld $(1)/etc/hotplug.d/net/99-mesh-babeld
+endef
+
 define Package/wg-installer-client
        $(call Package/wg-installer/Default)
        TITLE+= (client)
@@ -66,4 +77,5 @@ define Package/wg-installer-client/install
 endef
 
 $(eval $(call BuildPackage,wg-installer-server))
+$(eval $(call BuildPackage,wg-installer-server-hotplug-babeld))
 $(eval $(call BuildPackage,wg-installer-client))
index f64fa61d3d495748bbab940b0ae29cea05212bb7..0f8189d97bfb3ddf09dd654284213e6be5360945 100644 (file)
@@ -24,3 +24,7 @@ Get Usage Statistics
 Register Tunnel Interface
 
     wg-client-installer register --ip 127.0.0.1 --user wginstaller --password wginstaller --bandwidth 10
+
+## Hotplugs
+
+- wg-installer-server-hotplug-babeld: mesh automatically via wireguard with babeld
diff --git a/net/wg-installer/wg-server/hotplug.d/99-mesh-babeld b/net/wg-installer/wg-server/hotplug.d/99-mesh-babeld
new file mode 100644 (file)
index 0000000..068b199
--- /dev/null
@@ -0,0 +1,31 @@
+#!/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 babeld interface
+       uci set babeld.@interface[-1].ifname="${INTERFACE}"
+       uci commit
+       /etc/init.d/babeld reload
+fi
+
+if [ "${ACTION}" == "remove" ]; then
+       i=0
+       while uci get babeld.@interface[$i] &> /dev/null ; do
+               if [ "$(uci get babeld.@interface[$i].ifname)" == "${INTERFACE}" ]; then
+                       uci delete babeld.@interface[$i]
+               fi
+               i=$((i+1));
+       done
+       uci commit
+       /etc/init.d/babeld reload
+fi