aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-01-20 12:34:21 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2023-01-20 12:34:21 +0900
commit5f17a93c449e78c7d9bb33cfb7069255fdf0a60a (patch)
treede6bc2433343151f8b7cf0f094c400b60035e887
parent1211243e26c219a1b727634b4eb4064c0e9f44bf (diff)
parentde50c9a2d090008afe835b09e5697ec07e08e51c (diff)
downloadgnunet-5f17a93c449e78c7d9bb33cfb7069255fdf0a60a.tar.gz
gnunet-5f17a93c449e78c7d9bb33cfb7069255fdf0a60a.zip
Merge branch 'master' of git+ssh://git.gnunet.org/gnunet
-rwxr-xr-xcontrib/netjail/netjail_core.sh19
-rwxr-xr-xcontrib/netjail/netjail_start.sh15
-rwxr-xr-xcontrib/netjail/netjail_stop.sh6
-rw-r--r--src/testing/gnunet-cmds-helper.c12
-rw-r--r--src/testing/testing.c12
-rw-r--r--src/testing/testing_api_cmd_netjail_start_cmds_helper.c3
-rw-r--r--src/transport/test_transport_nat_upnp_topo.conf7
-rwxr-xr-xsrc/transport/upnp.sh22
8 files changed, 83 insertions, 13 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 4INTERFACE_FORMAT_STRING="%s%06x-%06x"
5PREPREFIX=if
5PREFIX=${PPID:?must run from a parent process} 6PREFIX=${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() {
93netjail_bridge() { 94netjail_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() {
104netjail_bridge_name() { 105netjail_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() {
118netjail_node() { 119netjail_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() {
128netjail_node_name() { 129netjail_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
198netjail_node_add_default() { 199netjail_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
24shift 2 24shift 2
25 25
26LOCAL_GROUP="192.168.15" 26LOCAL_GROUP="192.168.15"
27GLOBAL_GROUP="172.16.150" 27GLOBAL_GROUP="92.68.150"
28KNOWN_GROUP="172.16.151" 28KNOWN_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
30if [ $BROADCAST -eq 0 ]; then 39if [ $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
128done 137done
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
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index 90b686891..de50aca3a 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -61,9 +61,21 @@
61 61
62#define NODE_BASE_IP "192.168.15." 62#define NODE_BASE_IP "192.168.15."
63 63
64#define KNOWN_BASE_IP "92.68.151."
65
66#define ROUTER_BASE_IP "92.68.150."
67
68/* Use the IP addresses below instead of the public ones,
69 * if the start script was not started from within a new namespace
70 * created by unshare. The UPNP test case needs public IP
71 * addresse for miniupnpd to function.
72 * FIXME We should introduce a switch indicating if public
73 * addresses should be used or not. This info has to be
74 * propagated from the start script to the c code.
64#define KNOWN_BASE_IP "172.16.151." 75#define KNOWN_BASE_IP "172.16.151."
65 76
66#define ROUTER_BASE_IP "172.16.150." 77#define ROUTER_BASE_IP "172.16.150."
78*/
67 79
68struct GNUNET_SCHEDULER_Task *finished_task; 80struct GNUNET_SCHEDULER_Task *finished_task;
69 81
diff --git a/src/testing/testing.c b/src/testing/testing.c
index f2bf68c08..a1161925b 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -43,9 +43,21 @@
43 43
44#define CONNECT_ADDRESS_TEMPLATE "%s-192.168.15.%u" 44#define CONNECT_ADDRESS_TEMPLATE "%s-192.168.15.%u"
45 45
46#define ROUTER_CONNECT_ADDRESS_TEMPLATE "%s-92.68.150.%u"
47
48#define KNOWN_CONNECT_ADDRESS_TEMPLATE "%s-92.68.151.%u"
49
50/* Use the IP addresses below instead of the public ones,
51 * if the start script was not started from within a new namespace
52 * created by unshare. The UPNP test case needs public IP
53 * addresse for miniupnpd to function.
54 * FIXME We should introduce a switch indicating if public
55 * addresses should be used or not. This info has to be
56 * propagated from the start script to the c code.
46#define ROUTER_CONNECT_ADDRESS_TEMPLATE "%s-172.16.150.%u" 57#define ROUTER_CONNECT_ADDRESS_TEMPLATE "%s-172.16.150.%u"
47 58
48#define KNOWN_CONNECT_ADDRESS_TEMPLATE "%s-172.16.151.%u" 59#define KNOWN_CONNECT_ADDRESS_TEMPLATE "%s-172.16.151.%u"
60*/
49 61
50#define PREFIX_TCP "tcp" 62#define PREFIX_TCP "tcp"
51 63
diff --git a/src/testing/testing_api_cmd_netjail_start_cmds_helper.c b/src/testing/testing_api_cmd_netjail_start_cmds_helper.c
index c0f238530..545b89b33 100644
--- a/src/testing/testing_api_cmd_netjail_start_cmds_helper.c
+++ b/src/testing/testing_api_cmd_netjail_start_cmds_helper.c
@@ -612,7 +612,8 @@ start_helper (struct NetJailState *ns,
612 GNUNET_asprintf (&local_m_char, "%u", ns->local_m); 612 GNUNET_asprintf (&local_m_char, "%u", ns->local_m);
613 GNUNET_asprintf (&global_n_char, "%u",ns->global_n); 613 GNUNET_asprintf (&global_n_char, "%u",ns->global_n);
614 GNUNET_asprintf (&known_char, "%u",ns->known); 614 GNUNET_asprintf (&known_char, "%u",ns->known);
615 GNUNET_asprintf (&node_id, "%06x-%08x\n", 615 GNUNET_asprintf (&node_id, "%s%06x-%06x\n",
616 "if",
616 pid, 617 pid,
617 script_num); 618 script_num);
618 // GNUNET_asprintf (&topology_data, "'%s'", ns->topology_data); 619 // GNUNET_asprintf (&topology_data, "'%s'", ns->topology_data);
diff --git a/src/transport/test_transport_nat_upnp_topo.conf b/src/transport/test_transport_nat_upnp_topo.conf
new file mode 100644
index 000000000..e02633d4b
--- /dev/null
+++ b/src/transport/test_transport_nat_upnp_topo.conf
@@ -0,0 +1,7 @@
1M:1
2N:1
3X:1
4T:libgnunet_test_transport_plugin_cmd_nat_upnp
5K:1|{connect:{P:1:1:tcp}}
6R:1|{tcp_port:0}|{udp_port:0}|{script:upnp.sh}
7P:1:1|{connect:{K:1:udp}} \ No newline at end of file
diff --git a/src/transport/upnp.sh b/src/transport/upnp.sh
new file mode 100755
index 000000000..d01a1a1a1
--- /dev/null
+++ b/src/transport/upnp.sh
@@ -0,0 +1,22 @@
1#!/bin/bash
2
3if [ $2 -eq 1 ]
4then
5 if [ ! -d /tmp/netjail_scripts ]
6 then
7 mkdir /tmp/netjail_scripts
8 fi
9
10 ext_ifname=$(ip addr |grep UP|grep "@"|awk -F: '{printf $2"\n"}'|tr -d " "|awk -F@ '{printf $1" "}'|awk '{printf $1}')
11 listening_ip=$(ip addr |grep UP|grep "@"|awk -F: '{printf $2"\n"}'|tr -d " "|awk -F@ '{printf $1" "}'|awk '{printf $2}')
12 uuid=$(uuidgen)
13 cat miniupnpd.conf |sed 's/#ext_ifname=eth1/ext_ifname='$ext_ifname'/g'|sed 's/#listening_ip=eth0/listening_ip='$listening_ip'/g'|sed 's/uuid=73a9cb68-a00b-4d2c-8412-75fc989f0c6/uuid='$uuid'/g'|grep -v "^#"|grep -v '^$' > /tmp/netjail_scripts/gargoyle.txt
14 miniupnpd -d -f /tmp/netjail_scripts/gargoyle.txt -P /tmp/netjail_scripts/miniupnpd_$1.pid &
15else
16 kill $(cat /tmp/netjail_scripts/miniupnpd_$1.pid)
17fi
18
19
20
21
22