From 200d5c965ead0d867e25b7ff2be46b392b86d80e Mon Sep 17 00:00:00 2001 From: SoerenBusse Date: Sun, 16 Feb 2020 17:14:15 +0100 Subject: [PATCH] Add up/down script. See issue #136 Signed-off-by: Pascal Vorwerk --- .../vyatta-cfg/templates/interfaces/wireguard/node.def | 10 +++++++--- .../wireguard/node.tag/down-command/node.def | 4 ++++ .../interfaces/wireguard/node.tag/up-command/node.def | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 generic/opt/vyatta/share/vyatta-cfg/templates/interfaces/wireguard/node.tag/down-command/node.def create mode 100644 generic/opt/vyatta/share/vyatta-cfg/templates/interfaces/wireguard/node.tag/up-command/node.def diff --git a/generic/opt/vyatta/share/vyatta-cfg/templates/interfaces/wireguard/node.def b/generic/opt/vyatta/share/vyatta-cfg/templates/interfaces/wireguard/node.def index ed4e5e1..7d5b3d2 100644 --- a/generic/opt/vyatta/share/vyatta-cfg/templates/interfaces/wireguard/node.def +++ b/generic/opt/vyatta/share/vyatta-cfg/templates/interfaces/wireguard/node.def @@ -8,13 +8,17 @@ syntax:expression: pattern $VAR(@) "^wg[0-9]+$" \ create: ip link show dev $VAR(@) &>/dev/null || sudo ip link add dev $VAR(@) type wireguard -delete: sudo ip link del dev $VAR(@) +delete: (eval "$VAR(down-command/@)" >/dev/null || exit 1) && sudo ip link del dev $VAR(@) -end: if [ "$COMMIT_ACTION" != DELETE ]; then - sudo ip link set down dev $VAR(@) +end: + if [ "$COMMIT_ACTION" != DELETE ]; then + eval "$VAR(down-command/@) >/dev/null" || exit 1; + sudo ip link set down dev $VAR(@) if [ ! -n "$VAR(./disable)" ]; then sudo ip link set up dev $VAR(@) + eval "$VAR(up-command/@) >/dev/null" || exit 1; if [ "$VAR(route-allowed-ips/@)" == "true" ]; then + [ -n "$VAR(./route-table)" ] && tnum="$VAR(./route-table/@)" for i in $(sudo wg show $VAR(@) allowed-ips | sed 's/^.*\t//;s/ /\n/g' | sort -nr -k 2 -t /); do if [ $i == "(none)" ]; then continue; fi [[ $(sudo ip route get "$i" 2>/dev/null) == *dev\ $VAR(@)\ * ]] || sudo ip route add "$i" dev $VAR(@) diff --git a/generic/opt/vyatta/share/vyatta-cfg/templates/interfaces/wireguard/node.tag/down-command/node.def b/generic/opt/vyatta/share/vyatta-cfg/templates/interfaces/wireguard/node.tag/down-command/node.def new file mode 100644 index 0000000..a0429a1 --- /dev/null +++ b/generic/opt/vyatta/share/vyatta-cfg/templates/interfaces/wireguard/node.tag/down-command/node.def @@ -0,0 +1,4 @@ +type: txt +help: Script or command executed before the interface goes down +val_help: txt; Command +val_help: txt; Executable script in /config/scripts diff --git a/generic/opt/vyatta/share/vyatta-cfg/templates/interfaces/wireguard/node.tag/up-command/node.def b/generic/opt/vyatta/share/vyatta-cfg/templates/interfaces/wireguard/node.tag/up-command/node.def new file mode 100644 index 0000000..603f9ee --- /dev/null +++ b/generic/opt/vyatta/share/vyatta-cfg/templates/interfaces/wireguard/node.tag/up-command/node.def @@ -0,0 +1,4 @@ +type: txt +help: Script or command executed after the interface went up +val_help: txt; Command +val_help: txt; Executable script in /config/scripts