summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-08-30 10:06:42 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2021-08-30 10:06:42 +0200
commit744538ba3d388c3befa367c75d9a85126430cf8e (patch)
treef7edc0162e583bc8b72b5701d1a4164dbc931802 /contrib
parent9eb417e72224c874ed1e31b8b0575a8382173537 (diff)
-removed tmp files from netjail
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/scripts/netjail/netjail_core.sh50
-rwxr-xr-xcontrib/scripts/netjail/netjail_setup_internet.sh47
2 files changed, 54 insertions, 43 deletions
diff --git a/contrib/scripts/netjail/netjail_core.sh b/contrib/scripts/netjail/netjail_core.sh
index c93f26dc9..d53315052 100755
--- a/contrib/scripts/netjail/netjail_core.sh
+++ b/contrib/scripts/netjail/netjail_core.sh
@@ -10,22 +10,20 @@ PREFIX=${PPID:?must run from a parent process}
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-# initialize the numbering to ensure unique names
+export RESULT=
+export NAMESPACE_NUM=0
+export INTERFACE_NUM=0
-NAMESPACE_NUM=${NAMESPACE_FD:?must have a file for ids}
-INTERFACE_NUM=${INTERFACE_FD:?must have a file for ids}
+netjail_next_namespace() {
+ local NUM=$NAMESPACE_NUM
+ NAMESPACE_NUM=$(($NAMESPACE_NUM + 1))
+ RESULT=$NUM
+}
-netjail_read_inc() {
- local FD=$1
- local NUM=$(cat $FD)
- NUM=${NUM:-0}
-
- local RES=$NUM
- NUM=$(($NUM + 1))
-
- echo $NUM > $FD
-
- printf "$RES"
+netjail_next_interface() {
+ local NUM=$INTERFACE_NUM
+ INTERFACE_NUM=$(($INTERFACE_NUM + 1))
+ RESULT=$NUM
}
netjail_opt() {
@@ -36,7 +34,7 @@ netjail_opt() {
while [ $# -gt 0 ]; do
if [ "$1" = "$OPT" ]; then
- printf "%d" $INDEX
+ RESULT=$INDEX
return
fi
@@ -44,7 +42,7 @@ netjail_opt() {
shift 1
done
- printf "%d" 0
+ RESULT=0
}
netjail_opts() {
@@ -61,7 +59,7 @@ netjail_opts() {
shift 1
done
- printf "$DEF"
+ RESULT="$DEF"
}
netjail_check() {
@@ -93,13 +91,14 @@ netjail_check_bin() {
}
netjail_bridge() {
- local NUM=$(netjail_read_inc $INTERFACE_NUM)
+ netjail_next_interface
+ local NUM=$RESULT
local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM)
ip link add $BRIDGE type bridge
ip link set dev $BRIDGE up
- printf "%s" $BRIDGE
+ RESULT=$BRIDGE
}
netjail_bridge_clear() {
@@ -109,12 +108,13 @@ netjail_bridge_clear() {
}
netjail_node() {
- local NUM=$(netjail_read_inc $NAMESPACE_NUM)
+ netjail_next_namespace
+ local NUM=$RESULT
local NODE=$(printf "%06x-%08x" $PREFIX $NUM)
ip netns add $NODE
- printf "%s" $NODE
+ RESULT=$NODE
}
netjail_node_clear() {
@@ -129,8 +129,10 @@ netjail_node_link_bridge() {
local ADDRESS=$3
local MASK=$4
- local NUM_IF=$(netjail_read_inc $INTERFACE_NUM)
- local NUM_BR=$(netjail_read_inc $INTERFACE_NUM)
+ netjail_next_interface
+ local NUM_IF=$RESULT
+ netjail_next_interface
+ local NUM_BR=$RESULT
local LINK_IF=$(printf "%06x-%08x" $PREFIX $NUM_IF)
local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR)
@@ -145,7 +147,7 @@ netjail_node_link_bridge() {
ip link set $LINK_BR up
- printf "%s" $LINK_BR
+ RESULT=$LINK_BR
}
netjail_node_unlink_bridge() {
diff --git a/contrib/scripts/netjail/netjail_setup_internet.sh b/contrib/scripts/netjail/netjail_setup_internet.sh
index c9a6fd6d8..e3880783f 100755
--- a/contrib/scripts/netjail/netjail_setup_internet.sh
+++ b/contrib/scripts/netjail/netjail_setup_internet.sh
@@ -1,10 +1,5 @@
#!/bin/sh
-NAMESPACE_FD=$(mktemp)
-INTERFACE_FD=$(mktemp)
-
-trap "rm -f $NAMESPACE_FD $INTERFACE_FD; exit" ERR EXIT
-
. "./netjail_core.sh"
set -eu
@@ -21,11 +16,14 @@ shift 2
netjail_check $(($LOCAL_M * $GLOBAL_N))
# Starts optionally an amount of nodes without NAT starting with "92.68.151.1"
-KNOWN=$(netjail_opt '--known' $@)
-KNOWN_NUM=$(netjail_opts '--known' 0 $@)
+netjail_opt '--known' $@
+KNOWN=$RESULT
+netjail_opts '--known' 0 $@
+KNOWN_NUM=$RESULT
# Starts optionally 'stunserver' on "92.68.150.254":
-STUN=$(netjail_opt '--stun' $@)
+netjail_opt '--stun' $@
+STUN=$RESULT
if [ $KNOWN -gt 0 ]; then
shift 2
@@ -50,28 +48,37 @@ KNOWN_GROUP="92.68.151"
CLEANUP=0
echo "Start [local: $LOCAL_GROUP.0/24, global: $GLOBAL_GROUP.0/16, stun: $STUN]"
-NETWORK_NET=$(netjail_bridge)
+netjail_bridge
+NETWORK_NET=$RESULT
for X in $(seq $KNOWN); do
- KNOWN_NODES[$X]=$(netjail_node)
- KNOWN_LINKS[$X]=$(netjail_node_link_bridge ${KNOWN_NODES[$X]} $NETWORK_NET "$KNOWN_GROUP.$X" 16)
+ netjail_node
+ KNOWN_NODES[$X]=$RESULT
+ netjail_node_link_bridge ${KNOWN_NODES[$X]} $NETWORK_NET "$KNOWN_GROUP.$X" 16
+ KNOWN_LINKS[$X]=$RESULT
done
declare -A NODES
declare -A NODE_LINKS
for N in $(seq $GLOBAL_N); do
- ROUTERS[$N]=$(netjail_node)
- NETWORK_LINKS[$N]=$(netjail_node_link_bridge ${ROUTERS[$N]} $NETWORK_NET "$GLOBAL_GROUP.$N" 16)
- ROUTER_NETS[$N]=$(netjail_bridge)
+ netjail_node
+ ROUTERS[$N]=$RESULT
+ netjail_node_link_bridge ${ROUTERS[$N]} $NETWORK_NET "$GLOBAL_GROUP.$N" 16
+ NETWORK_LINKS[$N]=$RESULT
+ netjail_bridge
+ ROUTER_NETS[$N]=$RESULT
for M in $(seq $LOCAL_M); do
- NODES[$N,$M]=$(netjail_node)
- NODE_LINKS[$N,$M]=$(netjail_node_link_bridge ${NODES[$N,$M]} ${ROUTER_NETS[$N]} "$LOCAL_GROUP.$M" 24)
+ netjail_node
+ NODES[$N,$M]=$RESULT
+ netjail_node_link_bridge ${NODES[$N,$M]} ${ROUTER_NETS[$N]} "$LOCAL_GROUP.$M" 24
+ NODE_LINKS[$N,$M]=$RESULT
done
ROUTER_ADDR="$LOCAL_GROUP.$(($LOCAL_M+1))"
- ROUTER_LINKS[$N]=$(netjail_node_link_bridge ${ROUTERS[$N]} ${ROUTER_NETS[$N]} $ROUTER_ADDR 24)
+ netjail_node_link_bridge ${ROUTERS[$N]} ${ROUTER_NETS[$N]} $ROUTER_ADDR 24
+ ROUTER_LINKS[$N]=$RESULT
netjail_node_add_nat ${ROUTERS[$N]} $ROUTER_ADDR 24
@@ -84,8 +91,10 @@ WAITING=""
KILLING=""
if [ $STUN -gt 0 ]; then
- STUN_NODE=$(netjail_node)
- STUN_LINK=$(netjail_node_link_bridge $STUN_NODE $NETWORK_NET "$GLOBAL_GROUP.254" 16)
+ netjail_node
+ STUN_NODE=$RESULT
+ netjail_node_link_bridge $STUN_NODE $NETWORK_NET "$GLOBAL_GROUP.254" 16
+ STUN_LINK=$RESULT
netjail_node_exec $STUN_NODE 0 1 stunserver &
KILLING="$!"