Add pssibility of delay between ip commands.
Also fix wg interface name detection to use the name, and not wg0.
This commit is contained in:
parent
5d368bb9bb
commit
f9cbba8607
1 changed files with 13 additions and 7 deletions
20
gre-on-wg.sh
20
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue