summaryrefslogtreecommitdiff
path: root/contrib/scripts/netjail/netjail_setup_internet.sh
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/scripts/netjail/netjail_setup_internet.sh')
-rwxr-xr-xcontrib/scripts/netjail/netjail_setup_internet.sh54
1 files changed, 38 insertions, 16 deletions
diff --git a/contrib/scripts/netjail/netjail_setup_internet.sh b/contrib/scripts/netjail/netjail_setup_internet.sh
index 7ff25c014..de8ef8f15 100755
--- a/contrib/scripts/netjail/netjail_setup_internet.sh
+++ b/contrib/scripts/netjail/netjail_setup_internet.sh
@@ -31,6 +31,7 @@ netjail_check_bin $1
LOCAL_GROUP="192.168.15"
GLOBAL_GROUP="92.68.150"
+CLEANUP=0
echo "Start [local: $LOCAL_GROUP.0/24, global: $GLOBAL_GROUP.0/24, stun: $STUN]"
NETWORK_NET=$(netjail_print_name "n" $GLOBAL_N $LOCAL_M)
@@ -90,26 +91,47 @@ for N in $(seq $GLOBAL_N); do
done
done
-for PID in $WAITING; do wait $PID; done
-for PID in $KILLING; do netjail_kill $PID; done
-wait
+cleanup() {
+ if [ $STUN -gt 0 ]; then
+ STUN_NODE=$(netjail_print_name "S" 254)
-if [ $STUN -gt 0 ]; then
- STUN_NODE=$(netjail_print_name "S" 254)
+ netjail_node_unlink_bridge $STUN_NODE $NETWORK_NET
+ netjail_node_clear $STUN_NODE
+ fi
- netjail_node_unlink_bridge $STUN_NODE $NETWORK_NET
- netjail_node_clear $STUN_NODE
-fi
+ for N in $(seq $GLOBAL_N); do
+ ROUTER_NET=$(netjail_print_name "r" $N)
-for N in $(seq $GLOBAL_N); do
- for M in $(seq $LOCAL_M); do
- netjail_node_clear $(netjail_print_name "N" $N $M)
+ for M in $(seq $LOCAL_M); do
+ NODE=$(netjail_print_name "N" $N $M)
+
+ netjail_node_unlink_bridge $NODE $ROUTER_NET
+ netjail_node_clear $NODE
+ done
+
+ ROUTER=$(netjail_print_name "R" $N)
+
+ netjail_bridge_clear $ROUTER_NET
+ netjail_node_unlink_bridge $ROUTER $NETWORK_NET
+ netjail_node_clear $ROUTER
done
-
- netjail_bridge_clear $(netjail_print_name "r" $N)
- netjail_node_clear $(netjail_print_name "R" $N)
-done
-netjail_bridge_clear $NETWORK_NET
+ netjail_bridge_clear $NETWORK_NET
+}
+
+trapped_cleanup() {
+ netjail_killall $WAITING
+ netjail_killall $KILLING
+
+ cleanup
+}
+
+trap 'trapped_cleanup' 2
+
+netjail_waitall $WAITING
+netjail_killall $KILLING
+wait
+
+cleanup
echo "Done"