From af94d760d03e6621d0c35ca03f35b067b6d1254e Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Thu, 10 Sep 2020 00:48:35 +0200 Subject: [PATCH] Update executors to reflect new create/destroy phase. Signed-off-by: Maximilian Wilhelm --- executor-scripts/linux/bridge | 13 +++++++++++-- executor-scripts/linux/gre | 4 ++-- executor-scripts/linux/link | 4 ++-- executor-scripts/linux/ppp | 14 +++++++++++--- executor-scripts/linux/tunnel | 4 ++-- executor-scripts/linux/vrf | 10 +++++----- executor-scripts/linux/wireguard | 6 ++++-- 7 files changed, 37 insertions(+), 18 deletions(-) diff --git a/executor-scripts/linux/bridge b/executor-scripts/linux/bridge index 3a4a41c..144b75f 100755 --- a/executor-scripts/linux/bridge +++ b/executor-scripts/linux/bridge @@ -4,6 +4,7 @@ set -e # Copyright (C) 2012, 2020 Natanael Copa # Copyright (C) 2020 Ariadne Conill +# Copyright (C) 2020 Maximilian Wilhelm # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -134,8 +135,12 @@ esac [ -z "$PORTS" ] && ! env | grep -q "^IF_BRIDGE" && exit case "$PHASE" in +create) + if [ ! -d "/sys/class/net/${IFACE}" ]; then + brctl addbr "${IFACE}" + fi + ;; pre-up) - brctl addbr $IFACE || exit 1 wait_ports set_bridge_opts add_ports @@ -144,6 +149,10 @@ pre-up) post-down) del_ports ip link set dev $IFACE down - brctl delbr $IFACE || exit 1 + ;; +destroy) + if [ -d "/sys/class/net/${IFACE}" ]; then + brctl delbr "${IFACE}" + fi ;; esac diff --git a/executor-scripts/linux/gre b/executor-scripts/linux/gre index 40b96e8..c226963 100755 --- a/executor-scripts/linux/gre +++ b/executor-scripts/linux/gre @@ -19,10 +19,10 @@ PARAMS="mode $IF_GRE_MODE local '$IF_GRE_LOCAL' remote '$IF_GRE_REMOTE'" [ -n "$PARAMS" ] || exit 0 case "$PHASE" in -pre-up) +create) ${MOCK} eval ip $FAMILY $COMMAND add $IFACE $PARAMS ;; -post-down) +destroy) ${MOCK} ip $FAMILY $COMMAND del $IFACE ;; depend) diff --git a/executor-scripts/linux/link b/executor-scripts/linux/link index 7211d70..02633ef 100755 --- a/executor-scripts/linux/link +++ b/executor-scripts/linux/link @@ -28,7 +28,7 @@ is_vlan() { } case "$PHASE" in -pre-up) +create) if [ "${IF_LINK_TYPE}" = "dummy" ]; then if [ -d "/sys/class/net/${IFACE}" ]; then iface_type=$(ip -d link show dev "${IFACE}" | head -n3 | tail -n1 | awk '{ print $1 }') @@ -76,7 +76,7 @@ up) down) ${MOCK} ip link set down dev "${IFACE}" ;; -post-down) +destroy) if [ "${IF_LINK_TYPE}" = "dummy" ] || is_vlan; then if [ -z "${MOCK}" -a ! -d "/sys/class/net/${IFACE}" ]; then exit 0 diff --git a/executor-scripts/linux/ppp b/executor-scripts/linux/ppp index 3ba001b..c608a4e 100755 --- a/executor-scripts/linux/ppp +++ b/executor-scripts/linux/ppp @@ -1,8 +1,16 @@ #!/bin/sh set -e + [ -z "$IF_PPP_PROVIDER" ] && exit 0 + case "$PHASE" in -pre-up) ${MOCK} pon $IF_PPP_PROVIDER ;; -post-down) ${MOCK} poff $IF_PPP_PROVIDER ;; -depend) echo "$IF_PPP_PHYSDEV" ;; +create) + ${MOCK} pon $IF_PPP_PROVIDER + ;; +destroy) + ${MOCK} poff $IF_PPP_PROVIDER + ;; +depend) + echo "$IF_PPP_PHYSDEV" + ;; esac diff --git a/executor-scripts/linux/tunnel b/executor-scripts/linux/tunnel index e370b2a..a39eb34 100755 --- a/executor-scripts/linux/tunnel +++ b/executor-scripts/linux/tunnel @@ -37,10 +37,10 @@ PARAMS=$(set | sed -E ' [ "$PARAMS" ] || exit 0 case "$PHASE" in -pre-up) +create) ${MOCK} eval ip $FAMILY $COMMAND add $IFACE $PARAMS ;; -post-down) +destroy) ${MOCK} ip $FAMILY $COMMAND del $IFACE ;; depend) diff --git a/executor-scripts/linux/vrf b/executor-scripts/linux/vrf index c42b000..d9b4373 100755 --- a/executor-scripts/linux/vrf +++ b/executor-scripts/linux/vrf @@ -14,14 +14,14 @@ handle_member() { [ -n "$VERBOSE" ] && set -x case "$PHASE" in -pre-up) +create) [ -n "$IF_VRF_TABLE" ] && handle_init "add" - [ -n "$IF_VRF_MEMBER" ] && handle_member - exit 0 ;; -post-down) +pre-up) + [ -n "$IF_VRF_MEMBER" ] && handle_member + ;; +destroy) [ -n "$IF_VRF_TABLE" ] && handle_init "del" - exit 0 ;; depend) echo "$IF_VRF_MEMBER" diff --git a/executor-scripts/linux/wireguard b/executor-scripts/linux/wireguard index fa4a059..3ab56e3 100755 --- a/executor-scripts/linux/wireguard +++ b/executor-scripts/linux/wireguard @@ -6,11 +6,13 @@ set -e [ -z "$IF_WIREGUARD_CONFIG_PATH" ] && IF_WIREGUARD_CONFIG_PATH="/etc/wireguard/$IFACE.conf" case "$PHASE" in -pre-up) +create) ${MOCK} ip link add $IFACE type wireguard + ;; +pre-up) ${MOCK} wg setconf $IFACE $IF_WIREGUARD_CONFIG_PATH ;; -post-down) +destroy) ${MOCK} ip link delete dev $IFACE ;; esac