From f9cbba8607ba6e8fdcdab4577b9c4827ac4eaa9b Mon Sep 17 00:00:00 2001 From: redxef Date: Thu, 15 Jun 2023 13:34:08 +0200 Subject: [PATCH] Add pssibility of delay between ip commands. Also fix wg interface name detection to use the name, and not wg0. --- gre-on-wg.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/gre-on-wg.sh b/gre-on-wg.sh index c48f843..765dd61 100755 --- a/gre-on-wg.sh +++ b/gre-on-wg.sh @@ -3,6 +3,12 @@ set -euo pipefail _="${DEBUG:=}" +_="${GOW_IP_DELAY:=0}" + +ip_hook() { + ip "$@" + sleep "$GOW_IP_DELAY" +} strstrip() { sed -E -e 's/^\s*//' -e 's/\s*$//' @@ -21,8 +27,8 @@ create_gre() { local_ip="$(sed 's_/.*$__' <<< "$2")" remote_ip="$(sed 's_/.*$__' <<< "$3")" - $DEBUG ip link add "$name" type gretap local "$local_ip" remote "$remote_ip" - $DEBUG ip link set up "$name" + $DEBUG ip_hook link add "$name" type gretap local "$local_ip" remote "$remote_ip" + $DEBUG ip_hook link set up "$name" } add_gre_to_br() { @@ -30,7 +36,7 @@ add_gre_to_br() { br_name="$1" gre_name="$2" - $DEBUG ip link set "$gre_name" master "$br_name" + $DEBUG ip_hook link set "$gre_name" master "$br_name" } finish_br() { @@ -38,8 +44,8 @@ finish_br() { name="$1" local_ip="$2" - $DEBUG ip addr add "$local_ip" dev "$name" - $DEBUG ip link set up "$name" + $DEBUG ip_hook addr add "$local_ip" dev "$name" + $DEBUG ip_hook link set up "$name" } read_wg_conf() { @@ -138,8 +144,8 @@ down() { filepath="/etc/wireguard/$filepath.conf" fi wg_name="$(basename --suffix=.conf "$filepath")" - for link in $(ip link list | grep -Eo '^[0-9]+:\s+wg0[^:@]+' | sed -E 's/[0-9]+:\s+//'); do - $DEBUG ip link del "$link" + for link in $(ip_hook link list | grep -Eo '^[0-9]+:\s+'"$wg_name"'[^:@]+' | sed -E 's/[0-9]+:\s+//' | tac); do + $DEBUG ip_hook link del "$link" done }