chiark / gitweb /
rename User from Client
[hippotat.git] / test / netns-setup
1 #!/bin/bash
2 # Copyright 2021 Ian Jackson and contributors to Hippotat
3 # SPDX-License-Identifier: GPL-3.0-or-later
4 # There is NO WARRANTY.
5
6 set -ex
7
8 slug=$1
9
10 c_ns=hippotat-t-$slug-client
11 s_ns=hippotat-t-$slug-server
12
13 ip netns delete $s_ns      2>/dev/null ||:
14 ip netns delete $c_ns      2>/dev/null ||:
15
16 ip netns add $c_ns
17 ip netns add $s_ns
18
19 ip link add t.s.$$ type veth peer name t.c.$$
20 move_to_netns () {
21     cs=$1; ns=$2
22     ip link set t.$cs.$$ netns $ns
23     ip netns exec $ns ip link set t.$cs.$$ name eth0
24 }
25 move_to_netns s $s_ns
26 move_to_netns c $c_ns
27
28 config_netns () {
29     ns=$1; num=$2;
30     ip netns exec $ns ip addr add dev lo   127.0.0.1
31     ip netns exec $ns ip addr add dev eth0 198.51.100.$num/24
32     ip netns exec $ns ip link set     lo   up
33     ip netns exec $ns ip link set     eth0 up
34 }
35 config_netns $s_ns 1
36 config_netns $c_ns 2