37 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03#4# setup tunnels for flow dissection test5 6readonly SUFFIX="test_$(mktemp -u XXXX)"7CONFIG="remote 127.0.0.2 local 127.0.0.1 dev lo"8 9setup() {10 ip link add "ipip_${SUFFIX}" type ipip ${CONFIG}11 ip link add "gre_${SUFFIX}" type gre ${CONFIG}12 ip link add "sit_${SUFFIX}" type sit ${CONFIG}13 14 echo "tunnels before test:"15 ip tunnel show16 17 ip link set "ipip_${SUFFIX}" up18 ip link set "gre_${SUFFIX}" up19 ip link set "sit_${SUFFIX}" up20}21 22 23cleanup() {24 ip tunnel del "ipip_${SUFFIX}"25 ip tunnel del "gre_${SUFFIX}"26 ip tunnel del "sit_${SUFFIX}"27 28 echo "tunnels after test:"29 ip tunnel show30}31 32trap cleanup EXIT33 34setup35"$@"36exit "$?"37