Hi,

commit message should be redacted.

Best

Adrian

> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-boun...@lists.openwrt.org]
> On Behalf Of Florian Eckert
> Sent: Mittwoch, 4. Dezember 2019 14:05
> To: eckert.flor...@googlemail.com; ja...@zx2c4.com; ldir@darbyshire-
> bryant.me.uk; daniel.engberg.li...@pyret.net
> Cc: openwrt-devel@lists.openwrt.org; Florian Eckert <f...@dev.tdt.de>
> Subject: [OpenWrt-Devel] [PATCH] wireguard: fix interface remove on lonely
> peers
> 
> Redmine-patch-id: 4230
> If we delete the main wireguard interface, then the related are not
delete.
> They remain in the network configuration.
> 
> With this commit wo get called on a network config change, and check if
each
> wireguard peer has an interface. If this is not the case delete alle peers
that
> do not have a related wireguard interface.
> 
> Signed-off-by: Florian Eckert <f...@dev.tdt.de>
> ---
> This was discussed on the irc with Kevin Darbyshire-Bryant alias ldir on
the irc
> that this is a bug and should be get fixed.
> 
>  package/network/services/wireguard/Makefile   |  2 ++
>  .../services/wireguard/files/wireguard.init   | 31 +++++++++++++++++++
>  2 files changed, 33 insertions(+)
>  create mode 100644
> package/network/services/wireguard/files/wireguard.init
> 
> diff --git a/package/network/services/wireguard/Makefile
> b/package/network/services/wireguard/Makefile
> index ea34b7550b..d78fcfface 100644
> --- a/package/network/services/wireguard/Makefile
> +++ b/package/network/services/wireguard/Makefile
> @@ -93,6 +93,8 @@ define Package/wireguard-tools/install
>       $(INSTALL_BIN) ./files/wireguard_watchdog $(1)/usr/bin/
>       $(INSTALL_DIR) $(1)/lib/netifd/proto/
>       $(INSTALL_BIN) ./files/wireguard.sh $(1)/lib/netifd/proto/
> +     $(INSTALL_DIR) $(1)/etc/init.d/
> +     $(INSTALL_BIN) ./files/wireguard.init $(1)/etc/init.d/wireguard
>  endef
> 
>  define KernelPackage/wireguard
> diff --git a/package/network/services/wireguard/files/wireguard.init
> b/package/network/services/wireguard/files/wireguard.init
> new file mode 100644
> index 0000000000..781d0839bc
> --- /dev/null
> +++ b/package/network/services/wireguard/files/wireguard.init
> @@ -0,0 +1,31 @@
> +#!/bin/sh /etc/rc.common
> +
> +START=80
> +USE_PROCD=1
> +
> +service_triggers() {
> +     procd_add_reload_trigger "network"
> +}
> +
> +reload_service() {
> +     # delete old peers of related wireguard interface
> +     wireguard_check_peers
> +}
> +
> +wireguard_check_peers() {
> +     local iface peer
> +
> +     # get all wireguard peers
> +     for peer in $(uci show network | grep =wireguard_); do
> +             # extract peer section type
> +             peer="${peer##*=}"
> +             # extract interface name
> +             iface="${peer#*_}"
> +
> +             # delete peer if iface is not present anymore
> +             if ! uci -q show "network.${iface}" 1>/dev/null 2>/dev/null;
> then
> +                     uci -q delete "network.@${peer}[-1]"
> +                     uci commit network
> +             fi
> +     done
> +}
> --
> 2.20.1
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel


_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to