diff options
Diffstat (limited to 'contrib/netjail')
-rwxr-xr-x | contrib/netjail/netjail_core.sh | 19 | ||||
-rwxr-xr-x | contrib/netjail/netjail_start.sh | 15 | ||||
-rwxr-xr-x | contrib/netjail/netjail_stop.sh | 6 |
3 files changed, 28 insertions, 12 deletions
diff --git a/contrib/netjail/netjail_core.sh b/contrib/netjail/netjail_core.sh index 8c1744853..302ae922f 100755 --- a/contrib/netjail/netjail_core.sh +++ b/contrib/netjail/netjail_core.sh | |||
@@ -1,7 +1,8 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # | 2 | # |
3 | 3 | ||
4 | 4 | INTERFACE_FORMAT_STRING="%s%06x-%06x" | |
5 | PREPREFIX=if | ||
5 | PREFIX=${PPID:?must run from a parent process} | 6 | PREFIX=${PPID:?must run from a parent process} |
6 | 7 | ||
7 | # running with `sudo` is required to be | 8 | # running with `sudo` is required to be |
@@ -93,7 +94,7 @@ netjail_check_bin() { | |||
93 | netjail_bridge() { | 94 | netjail_bridge() { |
94 | netjail_next_interface | 95 | netjail_next_interface |
95 | local NUM=$RESULT | 96 | local NUM=$RESULT |
96 | local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM) | 97 | local BRIDGE=$(printf $INTERFACE_FORMAT_STRING $PREPREFIX $PREFIX $NUM) |
97 | 98 | ||
98 | ip link add $BRIDGE type bridge | 99 | ip link add $BRIDGE type bridge |
99 | ip link set dev $BRIDGE up | 100 | ip link set dev $BRIDGE up |
@@ -104,7 +105,7 @@ netjail_bridge() { | |||
104 | netjail_bridge_name() { | 105 | netjail_bridge_name() { |
105 | netjail_next_interface | 106 | netjail_next_interface |
106 | local NUM=$RESULT | 107 | local NUM=$RESULT |
107 | local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM) | 108 | local BRIDGE=$(printf $INTERFACE_FORMAT_STRING $PREPREFIX $PREFIX $NUM) |
108 | 109 | ||
109 | RESULT=$BRIDGE | 110 | RESULT=$BRIDGE |
110 | } | 111 | } |
@@ -118,7 +119,7 @@ netjail_bridge_clear() { | |||
118 | netjail_node() { | 119 | netjail_node() { |
119 | netjail_next_namespace | 120 | netjail_next_namespace |
120 | local NUM=$RESULT | 121 | local NUM=$RESULT |
121 | local NODE=$(printf "%06x-%08x" $PREFIX $NUM) | 122 | local NODE=$(printf $INTERFACE_FORMAT_STRING $PREPREFIX $PREFIX $NUM) |
122 | 123 | ||
123 | ip netns add $NODE | 124 | ip netns add $NODE |
124 | 125 | ||
@@ -128,7 +129,7 @@ netjail_node() { | |||
128 | netjail_node_name() { | 129 | netjail_node_name() { |
129 | netjail_next_namespace | 130 | netjail_next_namespace |
130 | local NUM=$RESULT | 131 | local NUM=$RESULT |
131 | local NODE=$(printf "%06x-%08x" $PREFIX $NUM) | 132 | local NODE=$(printf $INTERFACE_FORMAT_STRING $PREPREFIX $PREFIX $NUM) |
132 | 133 | ||
133 | RESULT=$NODE | 134 | RESULT=$NODE |
134 | } | 135 | } |
@@ -150,8 +151,8 @@ netjail_node_link_bridge() { | |||
150 | netjail_next_interface | 151 | netjail_next_interface |
151 | local NUM_BR=$RESULT | 152 | local NUM_BR=$RESULT |
152 | 153 | ||
153 | local LINK_IF=$(printf "%06x-%08x" $PREFIX $NUM_IF) | 154 | local LINK_IF=$(printf $INTERFACE_FORMAT_STRING $PREPREFIX $PREFIX $NUM_IF) |
154 | local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR) | 155 | local LINK_BR=$(printf $INTERFACE_FORMAT_STRING $PREPREFIX $PREFIX $NUM_BR) |
155 | 156 | ||
156 | ip link add $LINK_IF type veth peer name $LINK_BR | 157 | ip link add $LINK_IF type veth peer name $LINK_BR |
157 | ip link set $LINK_IF netns $NODE | 158 | ip link set $LINK_IF netns $NODE |
@@ -172,7 +173,7 @@ netjail_node_link_bridge_name() { | |||
172 | netjail_next_interface | 173 | netjail_next_interface |
173 | local NUM_BR=$RESULT | 174 | local NUM_BR=$RESULT |
174 | 175 | ||
175 | local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR) | 176 | local LINK_BR=$(printf $INTERFACE_FORMAT_STRING $PREPREFIX $PREFIX $NUM_BR) |
176 | 177 | ||
177 | RESULT=$LINK_BR | 178 | RESULT=$LINK_BR |
178 | } | 179 | } |
@@ -192,7 +193,7 @@ netjail_node_add_nat() { | |||
192 | ip netns exec $NODE nft add table nat | 193 | ip netns exec $NODE nft add table nat |
193 | ip netns exec $NODE nft add chain nat postrouting { type nat hook postrouting priority 0 \; } | 194 | ip netns exec $NODE nft add chain nat postrouting { type nat hook postrouting priority 0 \; } |
194 | ip netns exec $NODE nft add rule ip nat postrouting ip saddr "$ADDRESS/$MASK" counter masquerade | 195 | ip netns exec $NODE nft add rule ip nat postrouting ip saddr "$ADDRESS/$MASK" counter masquerade |
195 | # ip netns exec $NODE iptables -t nat -A POSTROUTING -s "$ADDRESS/$MASK" -j MASQUERADE | 196 | # ip netns exec $NODE iptables -t nat -A POSTROUTING -s "$ADDRESS/$MASK" -j MASQUERADE |
196 | } | 197 | } |
197 | 198 | ||
198 | netjail_node_add_default() { | 199 | netjail_node_add_default() { |
diff --git a/contrib/netjail/netjail_start.sh b/contrib/netjail/netjail_start.sh index 5e613048f..e68745746 100755 --- a/contrib/netjail/netjail_start.sh +++ b/contrib/netjail/netjail_start.sh | |||
@@ -24,8 +24,17 @@ fi | |||
24 | shift 2 | 24 | shift 2 |
25 | 25 | ||
26 | LOCAL_GROUP="192.168.15" | 26 | LOCAL_GROUP="192.168.15" |
27 | GLOBAL_GROUP="172.16.150" | 27 | GLOBAL_GROUP="92.68.150" |
28 | KNOWN_GROUP="172.16.151" | 28 | KNOWN_GROUP="92.68.151" |
29 | # Use the IP addresses below instead of the public ones, | ||
30 | # if the script was not started from within a new namespace | ||
31 | # created by unshare. The UPNP test case needs public IP | ||
32 | # addresse for miniupnpd to function. | ||
33 | # FIXME The ip addresses are used in the c code too. We should | ||
34 | # introduce a switch indicating if public addresses should be | ||
35 | # used or not. This info has to be propagated to the c code. | ||
36 | #GLOBAL_GROUP="172.16.150" | ||
37 | #KNOWN_GROUP="172.16.151" | ||
29 | 38 | ||
30 | if [ $BROADCAST -eq 0 ]; then | 39 | if [ $BROADCAST -eq 0 ]; then |
31 | PORT="60002" | 40 | PORT="60002" |
@@ -123,6 +132,6 @@ for N in $(seq $GLOBAL_N); do | |||
123 | fi | 132 | fi |
124 | if [ "" != "${R_SCRIPT[$N]}" ] | 133 | if [ "" != "${R_SCRIPT[$N]}" ] |
125 | then | 134 | then |
126 | ip netns exec ${ROUTERS[$N]} ./${R_SCRIPT[$N]} | 135 | ip netns exec ${ROUTERS[$N]} ./${R_SCRIPT[$N]} ${ROUTER_NETS[$N]} 1 |
127 | fi | 136 | fi |
128 | done | 137 | done |
diff --git a/contrib/netjail/netjail_stop.sh b/contrib/netjail/netjail_stop.sh index c8739dc94..55bcf2a5e 100755 --- a/contrib/netjail/netjail_stop.sh +++ b/contrib/netjail/netjail_stop.sh | |||
@@ -43,6 +43,12 @@ for N in $(seq $GLOBAL_N); do | |||
43 | netjail_node_link_bridge_name | 43 | netjail_node_link_bridge_name |
44 | ROUTER_LINKS[$N]=$RESULT | 44 | ROUTER_LINKS[$N]=$RESULT |
45 | 45 | ||
46 | if [ -d /tmp/netjail_scripts ] | ||
47 | then | ||
48 | ip netns exec ${ROUTERS[$N]} ./${R_SCRIPT[$N]} ${ROUTER_NETS[$N]} 0 | ||
49 | rm -rf /tmp/netjail_scripts | ||
50 | fi | ||
51 | |||
46 | netjail_node_unlink_bridge ${ROUTER_LINKS[$N]} | 52 | netjail_node_unlink_bridge ${ROUTER_LINKS[$N]} |
47 | 53 | ||
48 | for M in $(seq $LOCAL_M); do | 54 | for M in $(seq $LOCAL_M); do |