summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-05-02 21:33:35 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2021-05-02 21:33:35 +0200
commit2a027d304a09fa9645cb7e121a2650085328fb6c (patch)
tree1697b4ad145c8bdaeee8ad826b7929669cae3e1c
parenta5082240f035f1851715771b0265e25088bb687c (diff)
-added optional stunserver to netjail script
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rwxr-xr-xcontrib/scripts/netjail/netjail_core.sh29
-rwxr-xr-xcontrib/scripts/netjail/netjail_setup_internet.sh33
2 files changed, 60 insertions, 2 deletions
diff --git a/contrib/scripts/netjail/netjail_core.sh b/contrib/scripts/netjail/netjail_core.sh
index 6a18ea902..8dbbeacf1 100755
--- a/contrib/scripts/netjail/netjail_core.sh
+++ b/contrib/scripts/netjail/netjail_core.sh
@@ -9,6 +9,25 @@ JAILOR=${SUDO_USER:?must run in sudo}
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
+netjail_opt() {
+ OPT=$1
+ shift 1
+
+ INDEX=1
+
+ while [ $# -gt 0 ]; do
+ if [ "$1" = "$OPT" ]; then
+ printf "%d" $INDEX
+ return
+ fi
+
+ INDEX=$(($INDEX + 1))
+ shift 1
+ done
+
+ printf "%d" 0
+}
+
netjail_check() {
NODE_COUNT=$1
@@ -74,6 +93,15 @@ netjail_node_link_bridge() {
ip link set $LINK_BR up
}
+netjail_node_unlink_bridge() {
+ NODE=$1
+ BRIDGE=$2
+
+ LINK_BR="$NODE-$BRIDGE-1"
+
+ ip link delete $LINK_BR
+}
+
netjail_node_add_nat() {
NODE=$1
ADDRESS=$2
@@ -98,3 +126,4 @@ netjail_node_exec() {
unshare -fp --kill-child -- ip netns exec $NODE sudo -u $JAILOR -- $@ 1>& $FD_OUT 0<& $FD_IN
}
+
diff --git a/contrib/scripts/netjail/netjail_setup_internet.sh b/contrib/scripts/netjail/netjail_setup_internet.sh
index d99709555..2d448168a 100755
--- a/contrib/scripts/netjail/netjail_setup_internet.sh
+++ b/contrib/scripts/netjail/netjail_setup_internet.sh
@@ -9,16 +9,19 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
LOCAL_M=$1
GLOBAL_N=$2
-# TODO: stunserver? ..and globally known peer?
+# TODO: globally known peer?
shift 2
netjail_check $(($LOCAL_M * $GLOBAL_N))
+# Starts optionally 'stunserver' on "92.68.150.$(($GLOBAL_N + 1))":
+STUN=$(netjail_opt '--stun' $@)
+
LOCAL_GROUP="192.168.15"
GLOBAL_GROUP="92.68.150"
-echo "Start [local: $LOCAL_GROUP.0/24, global: $GLOBAL_GROUP.0/24]"
+echo "Start [local: $LOCAL_GROUP.0/24, global: $GLOBAL_GROUP.0/24, stun: $STUN]"
NETWORK_NET=$(netjail_print_name "n" $GLOBAL_N $LOCAL_M)
@@ -53,6 +56,22 @@ for N in $(seq $GLOBAL_N); do
done
done
+WAITING=""
+KILLING=""
+
+if [ $STUN -gt 0 ]; then
+ shift 1
+
+ S=$(($GLOBAL_N + 1))
+ STUN_NODE=$(netjail_print_name "S" $S)
+
+ netjail_node $STUN_NODE
+ netjail_node_link_bridge $STUN_NODE $NETWORK_NET "$GLOBAL_GROUP.$S" 24
+
+ netjail_node_exec $STUN_NODE 0 1 stunserver &
+ KILLING="$!"
+fi
+
for N in $(seq $GLOBAL_N); do
for M in $(seq $LOCAL_M); do
NODE=$(netjail_print_name "N" $N $M)
@@ -62,11 +81,21 @@ for N in $(seq $GLOBAL_N); do
FD_Y=$(($INDEX * 2 + 3 + 1))
netjail_node_exec $NODE $FD_X $FD_Y $@ &
+ WAITING="$! $WAITING"
done
done
+for PID in $WAITING; do wait $PID; done
+for PID in $KILLING; do kill $PID; done
wait
+if [ $STUN -gt 0 ]; then
+ STUN_NODE=$(netjail_print_name "S" $(($GLOBAL_N + 1)))
+
+ netjail_node_unlink_bridge $STUN_NODE $NETWORK_NET
+ netjail_node_clear $STUN_NODE
+fi
+
for N in $(seq $GLOBAL_N); do
for M in $(seq $LOCAL_M); do
netjail_node_clear $(netjail_print_name "N" $N $M)