#!/bin/bash # Copyright 2021-2022 Ian Jackson and contributors to Hippotat # SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Hippotat-OpenSSL-Exception # There is NO WARRANTY. set -ex slug=$1 c_ns=hippotat-t-$slug-client s_ns=hippotat-t-$slug-server ip netns delete $s_ns 2>/dev/null ||: ip netns delete $c_ns 2>/dev/null ||: ip netns add $c_ns ip netns add $s_ns ip link add t.s.$$ type veth peer name t.c.$$ move_to_netns () { cs=$1; ns=$2 ip link set t.$cs.$$ netns $ns ip netns exec $ns ip link set t.$cs.$$ name eth0 } move_to_netns s $s_ns move_to_netns c $c_ns config_netns () { ns=$1; num=$2; ip netns exec $ns ip addr add dev lo 127.0.0.1 ip netns exec $ns ip addr add dev eth0 198.51.100.$num/24 ip netns exec $ns ip link set lo up ip netns exec $ns ip link set eth0 up } config_netns $s_ns 1 config_netns $c_ns 2