From 0e5ec5b26073cb204c1f01899733bc219fa163c6 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Fri, 4 Sep 2020 23:21:21 +0200 Subject: [PATCH] link executor: Refactor VLAN iface management Signed-off-by: Maximilian Wilhelm --- executor-scripts/linux/link | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/executor-scripts/linux/link b/executor-scripts/linux/link index 9921840..9751987 100755 --- a/executor-scripts/linux/link +++ b/executor-scripts/linux/link @@ -43,19 +43,15 @@ pre-up) ip link add "${IFACE}" type dummy fi - ;; -up|down) - if is_vlan; then - ADD_DEL="add" - [ "$PHASE" = "down" ] && ADD_DEL="delete" - if [ "$PHASE" = "up" -a -e /sys/class/net/$IFACE ]; then + if is_vlan; then + if [ -d "/sys/class/net/${IFACE}" ]; then exit 0 fi - if [ -z "$MOCK" ]; then - if ! ip link show "$IF_VLAN_RAW_DEVICE" >/dev/null; then - echo "Device $IF_VLAN_RAW_DEVICE for $IFACE does not exist" + if [ -z "${MOCK}" ]; then + if [ ! -d "/sys/class/net/${IF_VLAN_RAW_DEVICE}" ]; then + echo "Underlay device ${IF_VLAN_RAW_DEVICE} for ${IFACE} does not exist" exit 1 fi @@ -65,10 +61,10 @@ up|down) fi fi - ${MOCK} ip link $ADD_DEL link "$IF_VLAN_RAW_DEVICE" name "$IFACE" type vlan id "$IF_VLAN_ID" - [ "$PHASE" = "down" ] && exit 0 + ${MOCK} ip link add link "${IF_VLAN_RAW_DEVICE}" name "${IFACE}" type vlan id "${IF_VLAN_ID}" fi - + ;; +up|down) ${MOCK} ip link set $PHASE dev $IFACE $IF_LINK_OPTIONS # Set alias is configured @@ -77,7 +73,7 @@ up|down) fi ;; post-down) - if [ "${IF_LINK_TYPE}" = "dummy" ]; then + if [ "${IF_LINK_TYPE}" = "dummy" -o is_vlan ]; then if [ -d "/sys/class/net/${IFACE}" ]; then ip link del "${IFACE}" fi