aboutsummaryrefslogtreecommitdiff
path: root/src/testing/netjail_core.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/netjail_core.sh')
-rwxr-xr-xsrc/testing/netjail_core.sh116
1 files changed, 0 insertions, 116 deletions
diff --git a/src/testing/netjail_core.sh b/src/testing/netjail_core.sh
deleted file mode 100755
index cf350d3fa..000000000
--- a/src/testing/netjail_core.sh
+++ /dev/null
@@ -1,116 +0,0 @@
1#!/bin/sh
2#
3
4
5
6# running with `sudo` is required to be
7# able running the actual commands as the
8# original user.
9
10export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
11
12netjail_check() {
13 NODE_COUNT=$1
14
15 FD_COUNT=$(($(ls /proc/self/fd | wc -w) - 4))
16
17 # quit if `$FD_COUNT < ($LOCAL_M * $GLOBAL_N * 2)`:
18 # the script also requires `sudo -C ($FD_COUNT + 4)`
19 # so you need 'Defaults closefrom_override' in the
20 # sudoers file.
21
22 if [ $FD_COUNT -lt $(($NODE_COUNT * 2)) ]; then
23 echo "File descriptors do not match requirements!" >&2
24 exit 1
25 fi
26}
27
28netjail_print_name() {
29 printf "%s%02x%02x" $1 $2 ${3:-0}
30}
31
32netjail_bridge() {
33 BRIDGE=$1
34
35 ip link add $BRIDGE type bridge
36 ip link set dev $BRIDGE up
37}
38
39netjail_bridge_clear() {
40 BRIDGE=$1
41
42 ip link delete $BRIDGE
43}
44
45netjail_node() {
46 NODE=$1
47
48 ip netns add $NODE
49}
50
51netjail_node_clear() {
52 NODE=$1
53
54 ip netns delete $NODE
55}
56
57netjail_node_link_bridge() {
58 NODE=$1
59 BRIDGE=$2
60 ADDRESS=$3
61 MASK=$4
62
63 LINK_IF="$NODE-$BRIDGE-0"
64 LINK_BR="$NODE-$BRIDGE-1"
65
66 ip link add $LINK_IF type veth peer name $LINK_BR
67 ip link set $LINK_IF netns $NODE
68 ip link set $LINK_BR master $BRIDGE
69
70 ip -n $NODE addr add "$ADDRESS/$MASK" dev $LINK_IF
71 ip -n $NODE link set $LINK_IF up
72 ip -n $NODE link set up dev lo
73
74 ip link set $LINK_BR up
75}
76
77netjail_node_add_nat() {
78 NODE=$1
79 ADDRESS=$2
80 MASK=$3
81
82 ip netns exec $NODE iptables -t nat -A POSTROUTING -s "$ADDRESS/$MASK" -j MASQUERADE
83}
84
85netjail_node_add_default() {
86 NODE=$1
87 ADDRESS=$2
88
89 ip -n $NODE route add default via $ADDRESS
90}
91
92netjail_node_exec() {
93 JAILOR=${SUDO_USER:?must run in sudo}
94 NODE=$1
95 FD_IN=$2
96 FD_OUT=$3
97 shift 3
98
99 ip netns exec $NODE sudo -u $JAILOR -- $@ 1>& $FD_OUT 0<& $FD_IN
100}
101
102netjail_node_exec_without_fds() {
103 JAILOR=${SUDO_USER:?must run in sudo}
104 NODE=$1
105 shift 1
106
107 ip netns exec $NODE sudo -u $JAILOR -- $@
108}
109
110netjail_node_exec_without_fds_and_sudo() {
111 NODE=$1
112 shift 1
113
114 ip netns exec $NODE $@
115}
116