summaryrefslogtreecommitdiff
path: root/src/pt/test_gnunet_vpn.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pt/test_gnunet_vpn.c')
-rw-r--r--src/pt/test_gnunet_vpn.c521
1 files changed, 261 insertions, 260 deletions
diff --git a/src/pt/test_gnunet_vpn.c b/src/pt/test_gnunet_vpn.c
index 7cc77fe24..ae5910824 100644
--- a/src/pt/test_gnunet_vpn.c
+++ b/src/pt/test_gnunet_vpn.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file test_gnunet_vpn.c 22 * @file test_gnunet_vpn.c
@@ -32,7 +32,7 @@
32 32
33#define PORT 48080 33#define PORT 48080
34 34
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) 35#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300)
36 36
37 37
38/** 38/**
@@ -74,8 +74,7 @@ static int dest_af;
74static int src_af; 74static int src_af;
75 75
76 76
77struct CBC 77struct CBC {
78{
79 char buf[1024]; 78 char buf[1024];
80 size_t pos; 79 size_t pos;
81}; 80};
@@ -84,87 +83,87 @@ static struct CBC cbc;
84 83
85 84
86static size_t 85static size_t
87copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx) 86copy_buffer(void *ptr, size_t size, size_t nmemb, void *ctx)
88{ 87{
89 struct CBC *cbc = ctx; 88 struct CBC *cbc = ctx;
90 89
91 if (cbc->pos + size * nmemb > sizeof (cbc->buf)) 90 if (cbc->pos + size * nmemb > sizeof(cbc->buf))
92 return 0; /* overflow */ 91 return 0; /* overflow */
93 GNUNET_memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb); 92 GNUNET_memcpy(&cbc->buf[cbc->pos], ptr, size * nmemb);
94 cbc->pos += size * nmemb; 93 cbc->pos += size * nmemb;
95 return size * nmemb; 94 return size * nmemb;
96} 95}
97 96
98 97
99static int 98static int
100mhd_ahc (void *cls, 99mhd_ahc(void *cls,
101 struct MHD_Connection *connection, 100 struct MHD_Connection *connection,
102 const char *url, 101 const char *url,
103 const char *method, 102 const char *method,
104 const char *version, 103 const char *version,
105 const char *upload_data, 104 const char *upload_data,
106 size_t * upload_data_size, 105 size_t * upload_data_size,
107 void **unused) 106 void **unused)
108{ 107{
109 static int ptr; 108 static int ptr;
110 struct MHD_Response *response; 109 struct MHD_Response *response;
111 int ret; 110 int ret;
112 111
113 if (0 != strcmp ("GET", method)) 112 if (0 != strcmp("GET", method))
114 return MHD_NO; /* unexpected method */ 113 return MHD_NO; /* unexpected method */
115 if (&ptr != *unused) 114 if (&ptr != *unused)
116 { 115 {
117 *unused = &ptr; 116 *unused = &ptr;
118 return MHD_YES; 117 return MHD_YES;
119 } 118 }
120 *unused = NULL; 119 *unused = NULL;
121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 120 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
122 "MHD sends respose for request to URL `%s'\n", url); 121 "MHD sends respose for request to URL `%s'\n", url);
123 response = 122 response =
124 MHD_create_response_from_buffer (strlen (url), (void *) url, 123 MHD_create_response_from_buffer(strlen(url), (void *)url,
125 MHD_RESPMEM_MUST_COPY); 124 MHD_RESPMEM_MUST_COPY);
126 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 125 ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
127 MHD_destroy_response (response); 126 MHD_destroy_response(response);
128 if (ret == MHD_NO) 127 if (ret == MHD_NO)
129 abort (); 128 abort();
130 return ret; 129 return ret;
131} 130}
132 131
133 132
134static void 133static void
135do_shutdown (void *cls) 134do_shutdown(void *cls)
136{ 135{
137 if (NULL != mhd_task_id) 136 if (NULL != mhd_task_id)
138 { 137 {
139 GNUNET_SCHEDULER_cancel (mhd_task_id); 138 GNUNET_SCHEDULER_cancel(mhd_task_id);
140 mhd_task_id = NULL; 139 mhd_task_id = NULL;
141 } 140 }
142 if (NULL != curl_task_id) 141 if (NULL != curl_task_id)
143 { 142 {
144 GNUNET_SCHEDULER_cancel (curl_task_id); 143 GNUNET_SCHEDULER_cancel(curl_task_id);
145 curl_task_id = NULL; 144 curl_task_id = NULL;
146 } 145 }
147 if (NULL != timeout_task_id) 146 if (NULL != timeout_task_id)
148 { 147 {
149 GNUNET_SCHEDULER_cancel (timeout_task_id); 148 GNUNET_SCHEDULER_cancel(timeout_task_id);
150 timeout_task_id = NULL; 149 timeout_task_id = NULL;
151 } 150 }
152 if (NULL != mhd) 151 if (NULL != mhd)
153 { 152 {
154 MHD_stop_daemon (mhd); 153 MHD_stop_daemon(mhd);
155 mhd = NULL; 154 mhd = NULL;
156 } 155 }
157 if (NULL != rr) 156 if (NULL != rr)
158 { 157 {
159 GNUNET_VPN_cancel_request (rr); 158 GNUNET_VPN_cancel_request(rr);
160 rr = NULL; 159 rr = NULL;
161 } 160 }
162 if (NULL != vpn) 161 if (NULL != vpn)
163 { 162 {
164 GNUNET_VPN_disconnect (vpn); 163 GNUNET_VPN_disconnect(vpn);
165 vpn = NULL; 164 vpn = NULL;
166 } 165 }
167 GNUNET_free_non_null (url); 166 GNUNET_free_non_null(url);
168 url = NULL; 167 url = NULL;
169} 168}
170 169
@@ -173,7 +172,7 @@ do_shutdown (void *cls)
173 * Function to run the HTTP client. 172 * Function to run the HTTP client.
174 */ 173 */
175static void 174static void
176curl_main (void *cls) 175curl_main(void *cls)
177{ 176{
178 fd_set rs; 177 fd_set rs;
179 fd_set ws; 178 fd_set ws;
@@ -188,55 +187,55 @@ curl_main (void *cls)
188 187
189 curl_task_id = NULL; 188 curl_task_id = NULL;
190 max = 0; 189 max = 0;
191 FD_ZERO (&rs); 190 FD_ZERO(&rs);
192 FD_ZERO (&ws); 191 FD_ZERO(&ws);
193 FD_ZERO (&es); 192 FD_ZERO(&es);
194 curl_multi_perform (multi, &running); 193 curl_multi_perform(multi, &running);
195 if (running == 0) 194 if (running == 0)
196 {
197 GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running)));
198 if (msg->msg == CURLMSG_DONE)
199 { 195 {
200 if (msg->data.result != CURLE_OK) 196 GNUNET_assert(NULL != (msg = curl_multi_info_read(multi, &running)));
201 { 197 if (msg->msg == CURLMSG_DONE)
202 fprintf (stderr, "%s failed at %s:%d: `%s'\n", "curl_multi_perform", 198 {
203 __FILE__, __LINE__, curl_easy_strerror (msg->data.result)); 199 if (msg->data.result != CURLE_OK)
204 global_ret = 1; 200 {
205 } 201 fprintf(stderr, "%s failed at %s:%d: `%s'\n", "curl_multi_perform",
202 __FILE__, __LINE__, curl_easy_strerror(msg->data.result));
203 global_ret = 1;
204 }
205 }
206 curl_multi_remove_handle(multi, curl);
207 curl_multi_cleanup(multi);
208 curl_easy_cleanup(curl);
209 curl = NULL;
210 multi = NULL;
211 if (cbc.pos != strlen("/hello_world"))
212 {
213 GNUNET_break(0);
214 global_ret = 2;
215 }
216 if (0 != strncmp("/hello_world", cbc.buf, strlen("/hello_world")))
217 {
218 GNUNET_break(0);
219 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
220 "You might want to check if your host-based firewall is blocking the connections.\n");
221 global_ret = 3;
222 }
223 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n");
224 GNUNET_SCHEDULER_shutdown();
225 return;
206 } 226 }
207 curl_multi_remove_handle (multi, curl); 227 GNUNET_assert(CURLM_OK == curl_multi_fdset(multi, &rs, &ws, &es, &max));
208 curl_multi_cleanup (multi); 228 if ((CURLM_OK != curl_multi_timeout(multi, &timeout)) || (-1 == timeout))
209 curl_easy_cleanup (curl);
210 curl = NULL;
211 multi = NULL;
212 if (cbc.pos != strlen ("/hello_world"))
213 {
214 GNUNET_break (0);
215 global_ret = 2;
216 }
217 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
218 {
219 GNUNET_break (0);
220 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
221 "You might want to check if your host-based firewall is blocking the connections.\n");
222 global_ret = 3;
223 }
224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n");
225 GNUNET_SCHEDULER_shutdown ();
226 return;
227 }
228 GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max));
229 if ((CURLM_OK != curl_multi_timeout (multi, &timeout)) || (-1 == timeout))
230 delay = GNUNET_TIME_UNIT_SECONDS; 229 delay = GNUNET_TIME_UNIT_SECONDS;
231 else 230 else
232 delay = 231 delay =
233 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 232 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,
234 (unsigned int) timeout); 233 (unsigned int)timeout);
235 GNUNET_NETWORK_fdset_copy_native (&nrs, &rs, max + 1); 234 GNUNET_NETWORK_fdset_copy_native(&nrs, &rs, max + 1);
236 GNUNET_NETWORK_fdset_copy_native (&nws, &ws, max + 1); 235 GNUNET_NETWORK_fdset_copy_native(&nws, &ws, max + 1);
237 curl_task_id = 236 curl_task_id =
238 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay, 237 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay,
239 &nrs, &nws, &curl_main, NULL); 238 &nrs, &nws, &curl_main, NULL);
240} 239}
241 240
242 241
@@ -254,53 +253,53 @@ curl_main (void *cls)
254 * specified target peer; NULL on error 253 * specified target peer; NULL on error
255 */ 254 */
256static void 255static void
257allocation_cb (void *cls, int af, const void *address) 256allocation_cb(void *cls, int af, const void *address)
258{ 257{
259 char ips[INET6_ADDRSTRLEN]; 258 char ips[INET6_ADDRSTRLEN];
260 259
261 rr = NULL; 260 rr = NULL;
262 if (src_af != af) 261 if (src_af != af)
263 { 262 {
264 fprintf (stderr, 263 fprintf(stderr,
265 "VPN failed to allocate appropriate address\n"); 264 "VPN failed to allocate appropriate address\n");
266 GNUNET_SCHEDULER_shutdown (); 265 GNUNET_SCHEDULER_shutdown();
267 return; 266 return;
268 } 267 }
269 if (AF_INET6 == af) 268 if (AF_INET6 == af)
270 GNUNET_asprintf (&url, 269 GNUNET_asprintf(&url,
271 "http://[%s]:%u/hello_world", 270 "http://[%s]:%u/hello_world",
272 inet_ntop (af, 271 inet_ntop(af,
273 address, 272 address,
274 ips, 273 ips,
275 sizeof (ips)), 274 sizeof(ips)),
276 (unsigned int) PORT); 275 (unsigned int)PORT);
277 else 276 else
278 GNUNET_asprintf (&url, 277 GNUNET_asprintf(&url,
279 "http://%s:%u/hello_world", 278 "http://%s:%u/hello_world",
280 inet_ntop (af, 279 inet_ntop(af,
281 address, 280 address,
282 ips, 281 ips,
283 sizeof (ips)), 282 sizeof(ips)),
284 (unsigned int) PORT); 283 (unsigned int)PORT);
285 curl = curl_easy_init (); 284 curl = curl_easy_init();
286 curl_easy_setopt (curl, CURLOPT_URL, url); 285 curl_easy_setopt(curl, CURLOPT_URL, url);
287 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &copy_buffer); 286 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &copy_buffer);
288 curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc); 287 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &cbc);
289 curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); 288 curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
290 curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L); 289 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 150L);
291 curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L); 290 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15L);
292 curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); 291 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
293 curl_easy_setopt (curl, CURLOPT_VERBOSE, 0); 292 curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
294 293
295 multi = curl_multi_init (); 294 multi = curl_multi_init();
296 GNUNET_assert (multi != NULL); 295 GNUNET_assert(multi != NULL);
297 GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); 296 GNUNET_assert(CURLM_OK == curl_multi_add_handle(multi, curl));
298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 297 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
299 "Beginning HTTP download from `%s'\n", 298 "Beginning HTTP download from `%s'\n",
300 url); 299 url);
301 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 300 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
302 &curl_main, 301 &curl_main,
303 NULL); 302 NULL);
304} 303}
305 304
306 305
@@ -308,30 +307,30 @@ allocation_cb (void *cls, int af, const void *address)
308 * Function to keep the HTTP server running. 307 * Function to keep the HTTP server running.
309 */ 308 */
310static void 309static void
311mhd_main (void); 310mhd_main(void);
312 311
313 312
314static void 313static void
315mhd_task (void *cls) 314mhd_task(void *cls)
316{ 315{
317 mhd_task_id = NULL; 316 mhd_task_id = NULL;
318 MHD_run (mhd); 317 MHD_run(mhd);
319 mhd_main (); 318 mhd_main();
320} 319}
321 320
322 321
323static void 322static void
324do_timeout (void *cls) 323do_timeout(void *cls)
325{ 324{
326 timeout_task_id = NULL; 325 timeout_task_id = NULL;
327 GNUNET_SCHEDULER_shutdown (); 326 GNUNET_SCHEDULER_shutdown();
328 GNUNET_break (0); 327 GNUNET_break(0);
329 global_ret = 1; 328 global_ret = 1;
330} 329}
331 330
332 331
333static void 332static void
334mhd_main () 333mhd_main()
335{ 334{
336 struct GNUNET_NETWORK_FDSet nrs; 335 struct GNUNET_NETWORK_FDSet nrs;
337 struct GNUNET_NETWORK_FDSet nws; 336 struct GNUNET_NETWORK_FDSet nws;
@@ -342,76 +341,78 @@ mhd_main ()
342 unsigned MHD_LONG_LONG timeout; 341 unsigned MHD_LONG_LONG timeout;
343 struct GNUNET_TIME_Relative delay; 342 struct GNUNET_TIME_Relative delay;
344 343
345 GNUNET_assert (NULL == mhd_task_id); 344 GNUNET_assert(NULL == mhd_task_id);
346 FD_ZERO (&rs); 345 FD_ZERO(&rs);
347 FD_ZERO (&ws); 346 FD_ZERO(&ws);
348 FD_ZERO (&es); 347 FD_ZERO(&es);
349 max_fd = -1; 348 max_fd = -1;
350 GNUNET_assert (MHD_YES == MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd)); 349 GNUNET_assert(MHD_YES == MHD_get_fdset(mhd, &rs, &ws, &es, &max_fd));
351 if (MHD_YES == MHD_get_timeout (mhd, &timeout)) 350 if (MHD_YES == MHD_get_timeout(mhd, &timeout))
352 delay = 351 delay =
353 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 352 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,
354 (unsigned int) timeout); 353 (unsigned int)timeout);
355 else 354 else
356 delay = GNUNET_TIME_UNIT_FOREVER_REL; 355 delay = GNUNET_TIME_UNIT_FOREVER_REL;
357 GNUNET_NETWORK_fdset_copy_native (&nrs, &rs, max_fd + 1); 356 GNUNET_NETWORK_fdset_copy_native(&nrs, &rs, max_fd + 1);
358 GNUNET_NETWORK_fdset_copy_native (&nws, &ws, max_fd + 1); 357 GNUNET_NETWORK_fdset_copy_native(&nws, &ws, max_fd + 1);
359 mhd_task_id = 358 mhd_task_id =
360 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay, 359 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay,
361 &nrs, &nws, &mhd_task, NULL); 360 &nrs, &nws, &mhd_task, NULL);
362} 361}
363 362
364 363
365static void 364static void
366run (void *cls, 365run(void *cls,
367 const struct GNUNET_CONFIGURATION_Handle *cfg, 366 const struct GNUNET_CONFIGURATION_Handle *cfg,
368 struct GNUNET_TESTING_Peer *peer) 367 struct GNUNET_TESTING_Peer *peer)
369{ 368{
370 struct in_addr v4; 369 struct in_addr v4;
371 struct in6_addr v6; 370 struct in6_addr v6;
372 void *addr; 371 void *addr;
373 enum MHD_FLAG flags; 372 enum MHD_FLAG flags;
374 373
375 vpn = GNUNET_VPN_connect (cfg); 374 vpn = GNUNET_VPN_connect(cfg);
376 GNUNET_assert (NULL != vpn); 375 GNUNET_assert(NULL != vpn);
377 flags = MHD_USE_DEBUG; 376 flags = MHD_USE_DEBUG;
378 if (AF_INET6 == dest_af) 377 if (AF_INET6 == dest_af)
379 flags |= MHD_USE_IPv6; 378 flags |= MHD_USE_IPv6;
380 mhd = 379 mhd =
381 MHD_start_daemon (flags, PORT, NULL, NULL, &mhd_ahc, NULL, 380 MHD_start_daemon(flags, PORT, NULL, NULL, &mhd_ahc, NULL,
382 MHD_OPTION_END); 381 MHD_OPTION_END);
383 382
384 383
385 GNUNET_assert (NULL != mhd); 384 GNUNET_assert(NULL != mhd);
386 mhd_main (); 385 mhd_main();
387 addr = NULL; 386 addr = NULL;
388 switch (dest_af) 387 switch (dest_af)
389 { 388 {
390 case AF_INET: 389 case AF_INET:
391 GNUNET_assert (1 == inet_pton (dest_af, dest_ip, &v4)); 390 GNUNET_assert(1 == inet_pton(dest_af, dest_ip, &v4));
392 addr = &v4; 391 addr = &v4;
393 break; 392 break;
394 case AF_INET6: 393
395 GNUNET_assert (1 == inet_pton (dest_af, dest_ip, &v6)); 394 case AF_INET6:
396 addr = &v6; 395 GNUNET_assert(1 == inet_pton(dest_af, dest_ip, &v6));
397 break; 396 addr = &v6;
398 default: 397 break;
399 GNUNET_assert (0); 398
400 } 399 default:
401 rr = GNUNET_VPN_redirect_to_ip (vpn, src_af, dest_af, addr, 400 GNUNET_assert(0);
402 GNUNET_TIME_UNIT_FOREVER_ABS, &allocation_cb, 401 }
403 NULL); 402 rr = GNUNET_VPN_redirect_to_ip(vpn, src_af, dest_af, addr,
403 GNUNET_TIME_UNIT_FOREVER_ABS, &allocation_cb,
404 NULL);
404 timeout_task_id = 405 timeout_task_id =
405 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 406 GNUNET_SCHEDULER_add_delayed(TIMEOUT,
406 &do_timeout, 407 &do_timeout,
407 NULL);
408 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
409 NULL); 408 NULL);
409 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
410 NULL);
410} 411}
411 412
412 413
413int 414int
414main (int argc, char *const *argv) 415main(int argc, char *const *argv)
415{ 416{
416 const char *type; 417 const char *type;
417 const char *bin; 418 const char *bin;
@@ -420,90 +421,90 @@ main (int argc, char *const *argv)
420 int ret = 0; 421 int ret = 0;
421 422
422#ifndef MINGW 423#ifndef MINGW
423 if (0 != ACCESS ("/dev/net/tun", R_OK)) 424 if (0 != ACCESS("/dev/net/tun", R_OK))
424 { 425 {
425 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 426 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR,
426 "access", 427 "access",
427 "/dev/net/tun"); 428 "/dev/net/tun");
428 fprintf (stderr, 429 fprintf(stderr,
429 "WARNING: System unable to run test, skipping.\n"); 430 "WARNING: System unable to run test, skipping.\n");
430 return 77; 431 return 77;
431 } 432 }
432#endif 433#endif
433 vpn_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn"); 434 vpn_binary = GNUNET_OS_get_libexec_binary_path("gnunet-helper-vpn");
434 exit_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-exit"); 435 exit_binary = GNUNET_OS_get_libexec_binary_path("gnunet-helper-exit");
435 if ((GNUNET_YES != (ret = GNUNET_OS_check_helper_binary (vpn_binary, GNUNET_YES, "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0"))) || //ipv4 only please! 436 if ((GNUNET_YES != (ret = GNUNET_OS_check_helper_binary(vpn_binary, GNUNET_YES, "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0"))) || //ipv4 only please!
436 (GNUNET_YES != (ret = GNUNET_OS_check_helper_binary (exit_binary, GNUNET_YES, "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")))) //no nat, ipv4 only 437 (GNUNET_YES != (ret = GNUNET_OS_check_helper_binary(exit_binary, GNUNET_YES, "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")))) //no nat, ipv4 only
437 { 438 {
438 GNUNET_free (vpn_binary); 439 GNUNET_free(vpn_binary);
439 GNUNET_free (exit_binary); 440 GNUNET_free(exit_binary);
440 fprintf (stderr, 441 fprintf(stderr,
441 "WARNING: gnunet-helper-{exit,vpn} binaries are not SUID, refusing to run test (as it would have to fail). %d\n", ret); 442 "WARNING: gnunet-helper-{exit,vpn} binaries are not SUID, refusing to run test (as it would have to fail). %d\n", ret);
442 return 77; 443 return 77;
443 } 444 }
444 445
445 GNUNET_free (vpn_binary); 446 GNUNET_free(vpn_binary);
446 GNUNET_free (exit_binary); 447 GNUNET_free(exit_binary);
447 bin = argv[0]; 448 bin = argv[0];
448 if (NULL != strstr (bin, "lt-")) 449 if (NULL != strstr(bin, "lt-"))
449 bin = strstr (bin, "lt-") + 4; 450 bin = strstr(bin, "lt-") + 4;
450 type = strstr (bin, "-"); 451 type = strstr(bin, "-");
451 if (NULL == type) 452 if (NULL == type)
452 { 453 {
453 fprintf (stderr, 454 fprintf(stderr,
454 "invalid binary name\n"); 455 "invalid binary name\n");
455 return 1; 456 return 1;
456 } 457 }
457 type++; 458 type++;
458 /* on Windows, .exe is suffixed to these binaries, 459 /* on Windows, .exe is suffixed to these binaries,
459 * thus cease comparison after the 6th char. 460 * thus cease comparison after the 6th char.
460 */ 461 */
461 if (0 == strncmp (type, "4_to_6",6)) 462 if (0 == strncmp(type, "4_to_6", 6))
462 { 463 {
463 dest_ip = "FC5A:04E1:C2BA::1"; 464 dest_ip = "FC5A:04E1:C2BA::1";
464 dest_af = AF_INET6; 465 dest_af = AF_INET6;
465 src_af = AF_INET; 466 src_af = AF_INET;
466 } 467 }
467 else if (0 == strncmp (type, "6_to_4",6)) 468 else if (0 == strncmp(type, "6_to_4", 6))
468 { 469 {
469 dest_ip = "169.254.86.1"; 470 dest_ip = "169.254.86.1";
470 dest_af = AF_INET; 471 dest_af = AF_INET;
471 src_af = AF_INET6; 472 src_af = AF_INET6;
472 } 473 }
473 else if (0 == strncmp (type, "4_over",6)) 474 else if (0 == strncmp(type, "4_over", 6))
474 { 475 {
475 dest_ip = "169.254.86.1"; 476 dest_ip = "169.254.86.1";
476 dest_af = AF_INET; 477 dest_af = AF_INET;
477 src_af = AF_INET; 478 src_af = AF_INET;
478 } 479 }
479 else if (0 == strncmp (type, "6_over",6)) 480 else if (0 == strncmp(type, "6_over", 6))
480 { 481 {
481 dest_ip = "FC5A:04E1:C2BA::1"; 482 dest_ip = "FC5A:04E1:C2BA::1";
482 dest_af = AF_INET6; 483 dest_af = AF_INET6;
483 src_af = AF_INET6; 484 src_af = AF_INET6;
484 } 485 }
485 else 486 else
486 { 487 {
487 fprintf (stderr, "invalid binary suffix `%s'\n", type); 488 fprintf(stderr, "invalid binary suffix `%s'\n", type);
488 return 1; 489 return 1;
489 } 490 }
490 if ((GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) || 491 if ((GNUNET_OK != GNUNET_NETWORK_test_pf(src_af)) ||
491 (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af))) 492 (GNUNET_OK != GNUNET_NETWORK_test_pf(dest_af)))
492 { 493 {
493 fprintf (stderr, 494 fprintf(stderr,
494 "Required address families not supported by this system, skipping test.\n"); 495 "Required address families not supported by this system, skipping test.\n");
495 return 0; 496 return 0;
496 } 497 }
497 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 498 if (0 != curl_global_init(CURL_GLOBAL_WIN32))
498 { 499 {
499 fprintf (stderr, "failed to initialize curl\n"); 500 fprintf(stderr, "failed to initialize curl\n");
500 return 2; 501 return 2;
501 } 502 }
502 if (0 != 503 if (0 !=
503 GNUNET_TESTING_peer_run ("test-gnunet-vpn", "test_gnunet_vpn.conf", &run, 504 GNUNET_TESTING_peer_run("test-gnunet-vpn", "test_gnunet_vpn.conf", &run,
504 NULL)) 505 NULL))
505 return 1; 506 return 1;
506 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn"); 507 GNUNET_DISK_directory_remove("/tmp/gnunet-test-vpn");
507 return global_ret; 508 return global_ret;
508} 509}
509 510