aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-08-17 20:37:50 +0200
committert3sserakt <t3ss@posteo.de>2021-08-17 20:37:50 +0200
commit48b633f2a47f47200fb72cca8d84b1f0c2d44ee0 (patch)
tree5d91e9191e3d4def1da30314818a8d9edf0deb73 /src/testing
parent32a8c505c1fa27bb43c4e7c8d288566d51417f56 (diff)
downloadgnunet-48b633f2a47f47200fb72cca8d84b1f0c2d44ee0.tar.gz
gnunet-48b633f2a47f47200fb72cca8d84b1f0c2d44ee0.zip
- moved additional files from testbed to testing
Diffstat (limited to 'src/testing')
-rwxr-xr-xsrc/testing/netjail_core.sh107
-rwxr-xr-xsrc/testing/netjail_exec.sh2
-rwxr-xr-xsrc/testing/netjail_start.sh2
-rwxr-xr-xsrc/testing/netjail_stop.sh2
4 files changed, 110 insertions, 3 deletions
diff --git a/src/testing/netjail_core.sh b/src/testing/netjail_core.sh
new file mode 100755
index 000000000..f49d4b312
--- /dev/null
+++ b/src/testing/netjail_core.sh
@@ -0,0 +1,107 @@
1#!/bin/sh
2#
3
4JAILOR=${SUDO_USER:?must run in sudo}
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 NODE=$1
94 FD_IN=$2
95 FD_OUT=$3
96 shift 3
97
98 ip netns exec $NODE sudo -u $JAILOR -- $@ 1>& $FD_OUT 0<& $FD_IN
99}
100
101netjail_node_exec_without_fds() {
102 NODE=$1
103 shift 1
104
105 ip netns exec $NODE sudo -u $JAILOR -- $@
106}
107
diff --git a/src/testing/netjail_exec.sh b/src/testing/netjail_exec.sh
index b76d2e444..c20a8c117 100755
--- a/src/testing/netjail_exec.sh
+++ b/src/testing/netjail_exec.sh
@@ -1,5 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2. "./../testbed/netjail_core.sh" 2. "./../testing/netjail_core.sh"
3 3
4set -eu 4set -eu
5set -x 5set -x
diff --git a/src/testing/netjail_start.sh b/src/testing/netjail_start.sh
index 4c1c33c83..0984a3c42 100755
--- a/src/testing/netjail_start.sh
+++ b/src/testing/netjail_start.sh
@@ -1,5 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2. "./../testbed/netjail_core.sh" 2. "./../testing/netjail_core.sh"
3 3
4set -eu 4set -eu
5set -x 5set -x
diff --git a/src/testing/netjail_stop.sh b/src/testing/netjail_stop.sh
index 689bf7ae9..08f68cf7f 100755
--- a/src/testing/netjail_stop.sh
+++ b/src/testing/netjail_stop.sh
@@ -1,5 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2. "./../testbed/netjail_core.sh" 2. "./../testing/netjail_core.sh"
3 3
4set -eu 4set -eu
5set -x 5set -x