aboutsummaryrefslogtreecommitdiff
path: root/src/pt
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2012-09-21 12:10:26 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2012-09-21 12:10:26 +0000
commit0f50ba19f099a7ed3c98f92028ea6f96dfd1aa73 (patch)
treefba0c0ad75bfbe98d2d274e05fc3490dbfb1a173 /src/pt
parentb2b71f9f9e123fcf9eeb795451b51a6c292ca7a3 (diff)
downloadgnunet-0f50ba19f099a7ed3c98f92028ea6f96dfd1aa73.tar.gz
gnunet-0f50ba19f099a7ed3c98f92028ea6f96dfd1aa73.zip
Added warning to check the firewall when tests fail (which happend to me). The
long diff is due to running pre-commit script prior to check-in.
Diffstat (limited to 'src/pt')
-rw-r--r--src/pt/test_gnunet_vpn.c187
1 files changed, 75 insertions, 112 deletions
diff --git a/src/pt/test_gnunet_vpn.c b/src/pt/test_gnunet_vpn.c
index d2cfc757b..f40a363b7 100644
--- a/src/pt/test_gnunet_vpn.c
+++ b/src/pt/test_gnunet_vpn.c
@@ -87,7 +87,7 @@ copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx)
87{ 87{
88 struct CBC *cbc = ctx; 88 struct CBC *cbc = ctx;
89 89
90 if (cbc->pos + size * nmemb > sizeof(cbc->buf)) 90 if (cbc->pos + size * nmemb > sizeof (cbc->buf))
91 return 0; /* overflow */ 91 return 0; /* overflow */
92 memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb); 92 memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb);
93 cbc->pos += size * nmemb; 93 cbc->pos += size * nmemb;
@@ -96,13 +96,9 @@ copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx)
96 96
97 97
98static int 98static int
99mhd_ahc (void *cls, 99mhd_ahc (void *cls, struct MHD_Connection *connection, const char *url,
100 struct MHD_Connection *connection, 100 const char *method, const char *version, const char *upload_data,
101 const char *url, 101 size_t * upload_data_size, void **unused)
102 const char *method,
103 const char *version,
104 const char *upload_data, size_t *upload_data_size,
105 void **unused)
106{ 102{
107 static int ptr; 103 static int ptr;
108 struct MHD_Response *response; 104 struct MHD_Response *response;
@@ -116,10 +112,11 @@ mhd_ahc (void *cls,
116 return MHD_YES; 112 return MHD_YES;
117 } 113 }
118 *unused = NULL; 114 *unused = NULL;
119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MHD sends respose for request to URL `%s'\n", url); 115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
120 response = MHD_create_response_from_buffer (strlen (url), 116 "MHD sends respose for request to URL `%s'\n", url);
121 (void *) url, 117 response =
122 MHD_RESPMEM_MUST_COPY); 118 MHD_create_response_from_buffer (strlen (url), (void *) url,
119 MHD_RESPMEM_MUST_COPY);
123 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 120 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
124 MHD_destroy_response (response); 121 MHD_destroy_response (response);
125 if (ret == MHD_NO) 122 if (ret == MHD_NO)
@@ -174,8 +171,7 @@ curl_main (void);
174 171
175 172
176static void 173static void
177curl_task (void *cls, 174curl_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
178 const struct GNUNET_SCHEDULER_TaskContext *tc)
179{ 175{
180 curl_task_id = GNUNET_SCHEDULER_NO_TASK; 176 curl_task_id = GNUNET_SCHEDULER_NO_TASK;
181 curl_main (); 177 curl_main ();
@@ -208,12 +204,9 @@ curl_main ()
208 { 204 {
209 if (msg->data.result != CURLE_OK) 205 if (msg->data.result != CURLE_OK)
210 { 206 {
211 fprintf (stderr, 207 fprintf (stderr, "%s failed at %s:%d: `%s'\n", "curl_multi_perform",
212 "%s failed at %s:%d: `%s'\n", 208 __FILE__, __LINE__, curl_easy_strerror (msg->data.result));
213 "curl_multi_perform", 209 global_ret = 1;
214 __FILE__,
215 __LINE__, curl_easy_strerror (msg->data.result));
216 global_ret = 1;
217 } 210 }
218 } 211 }
219 curl_multi_remove_handle (multi, curl); 212 curl_multi_remove_handle (multi, curl);
@@ -229,30 +222,26 @@ curl_main ()
229 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) 222 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
230 { 223 {
231 GNUNET_break (0); 224 GNUNET_break (0);
225 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
226 "You might want to check if your host-based firewall is blocking the connections.\n");
232 global_ret = 3; 227 global_ret = 3;
233 } 228 }
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n"); 229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n");
235 do_shutdown (); 230 do_shutdown ();
236 return; 231 return;
237 } 232 }
238 GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max)); 233 GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max));
239 if ( (CURLM_OK != curl_multi_timeout (multi, &timeout)) || 234 if ((CURLM_OK != curl_multi_timeout (multi, &timeout)) || (-1 == timeout))
240 (-1 == timeout) )
241 delay = GNUNET_TIME_UNIT_SECONDS; 235 delay = GNUNET_TIME_UNIT_SECONDS;
242 else 236 else
243 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, (unsigned int) timeout); 237 delay =
244 GNUNET_NETWORK_fdset_copy_native (&nrs, 238 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
245 &rs, 239 (unsigned int) timeout);
246 max + 1); 240 GNUNET_NETWORK_fdset_copy_native (&nrs, &rs, max + 1);
247 GNUNET_NETWORK_fdset_copy_native (&nws, 241 GNUNET_NETWORK_fdset_copy_native (&nws, &ws, max + 1);
248 &ws, 242 curl_task_id =
249 max + 1); 243 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay,
250 curl_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 244 &nrs, &nws, &curl_task, NULL);
251 delay,
252 &nrs,
253 &nws,
254 &curl_task,
255 NULL);
256} 245}
257 246
258 247
@@ -266,28 +255,24 @@ curl_main ()
266 * will match 'result_af' from the request 255 * will match 'result_af' from the request
267 * @param address IP address (struct in_addr or struct in_addr6, depending on 'af') 256 * @param address IP address (struct in_addr or struct in_addr6, depending on 'af')
268 * that the VPN allocated for the redirection; 257 * that the VPN allocated for the redirection;
269 * traffic to this IP will now be redirected to the 258 * traffic to this IP will now be redirected to the
270 * specified target peer; NULL on error 259 * specified target peer; NULL on error
271 */ 260 */
272static void 261static void
273allocation_cb (void *cls, 262allocation_cb (void *cls, int af, const void *address)
274 int af,
275 const void *address)
276{ 263{
277 char ips[INET6_ADDRSTRLEN]; 264 char ips[INET6_ADDRSTRLEN];
278 265
279 rr = NULL; 266 rr = NULL;
280 if (src_af != af) 267 if (src_af != af)
281 { 268 {
282 fprintf (stderr, 269 fprintf (stderr, "VPN failed to allocate appropriate address\n");
283 "VPN failed to allocate appropriate address\n");
284 GNUNET_SCHEDULER_shutdown (); 270 GNUNET_SCHEDULER_shutdown ();
285 return; 271 return;
286 } 272 }
287 GNUNET_asprintf (&url, 273 GNUNET_asprintf (&url, "http://%s:%u/hello_world",
288 "http://%s:%u/hello_world", 274 inet_ntop (af, address, ips, sizeof (ips)),
289 inet_ntop (af, address, ips, sizeof (ips)), 275 (unsigned int) PORT);
290 (unsigned int) PORT);
291 curl = curl_easy_init (); 276 curl = curl_easy_init ();
292 curl_easy_setopt (curl, CURLOPT_URL, url); 277 curl_easy_setopt (curl, CURLOPT_URL, url);
293 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &copy_buffer); 278 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &copy_buffer);
@@ -300,7 +285,8 @@ allocation_cb (void *cls,
300 multi = curl_multi_init (); 285 multi = curl_multi_init ();
301 GNUNET_assert (multi != NULL); 286 GNUNET_assert (multi != NULL);
302 GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); 287 GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl));
303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Beginning HTTP download from `%s'\n", url); 288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Beginning HTTP download from `%s'\n",
289 url);
304 curl_main (); 290 curl_main ();
305} 291}
306 292
@@ -308,13 +294,12 @@ allocation_cb (void *cls,
308/** 294/**
309 * Function to keep the HTTP server running. 295 * Function to keep the HTTP server running.
310 */ 296 */
311static void 297static void
312mhd_main (void); 298mhd_main (void);
313 299
314 300
315static void 301static void
316mhd_task (void *cls, 302mhd_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
317 const struct GNUNET_SCHEDULER_TaskContext *tc)
318{ 303{
319 mhd_task_id = GNUNET_SCHEDULER_NO_TASK; 304 mhd_task_id = GNUNET_SCHEDULER_NO_TASK;
320 MHD_run (mhd); 305 MHD_run (mhd);
@@ -323,8 +308,7 @@ mhd_task (void *cls,
323 308
324 309
325static void 310static void
326ctrl_c_shutdown (void *cls, 311ctrl_c_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
327 const struct GNUNET_SCHEDULER_TaskContext *tc)
328{ 312{
329 ctrl_c_task_id = GNUNET_SCHEDULER_NO_TASK; 313 ctrl_c_task_id = GNUNET_SCHEDULER_NO_TASK;
330 do_shutdown (); 314 do_shutdown ();
@@ -333,7 +317,7 @@ ctrl_c_shutdown (void *cls,
333} 317}
334 318
335 319
336static void 320static void
337mhd_main () 321mhd_main ()
338{ 322{
339 struct GNUNET_NETWORK_FDSet nrs; 323 struct GNUNET_NETWORK_FDSet nrs;
@@ -350,31 +334,23 @@ mhd_main ()
350 FD_ZERO (&ws); 334 FD_ZERO (&ws);
351 FD_ZERO (&es); 335 FD_ZERO (&es);
352 max_fd = -1; 336 max_fd = -1;
353 GNUNET_assert (MHD_YES == 337 GNUNET_assert (MHD_YES == MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd));
354 MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd));
355 if (MHD_YES == MHD_get_timeout (mhd, &timeout)) 338 if (MHD_YES == MHD_get_timeout (mhd, &timeout))
356 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 339 delay =
357 (unsigned int) timeout); 340 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
341 (unsigned int) timeout);
358 else 342 else
359 delay = GNUNET_TIME_UNIT_FOREVER_REL; 343 delay = GNUNET_TIME_UNIT_FOREVER_REL;
360 GNUNET_NETWORK_fdset_copy_native (&nrs, 344 GNUNET_NETWORK_fdset_copy_native (&nrs, &rs, max_fd + 1);
361 &rs, 345 GNUNET_NETWORK_fdset_copy_native (&nws, &ws, max_fd + 1);
362 max_fd + 1); 346 mhd_task_id =
363 GNUNET_NETWORK_fdset_copy_native (&nws, 347 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay,
364 &ws, 348 &nrs, &nws, &mhd_task, NULL);
365 max_fd + 1);
366 mhd_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
367 delay,
368 &nrs,
369 &nws,
370 &mhd_task,
371 NULL);
372} 349}
373 350
374 351
375static void 352static void
376run (void *cls, 353run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
377 const struct GNUNET_CONFIGURATION_Handle *cfg,
378 struct GNUNET_TESTING_Peer *peer) 354 struct GNUNET_TESTING_Peer *peer)
379{ 355{
380 struct in_addr v4; 356 struct in_addr v4;
@@ -383,15 +359,13 @@ run (void *cls,
383 enum MHD_FLAG flags; 359 enum MHD_FLAG flags;
384 360
385 vpn = GNUNET_VPN_connect (cfg); 361 vpn = GNUNET_VPN_connect (cfg);
386 GNUNET_assert (NULL != vpn); 362 GNUNET_assert (NULL != vpn);
387 flags = MHD_USE_DEBUG; 363 flags = MHD_USE_DEBUG;
388 if (AF_INET6 == dest_af) 364 if (AF_INET6 == dest_af)
389 flags |= MHD_USE_IPv6; 365 flags |= MHD_USE_IPv6;
390 mhd = MHD_start_daemon (flags, 366 mhd =
391 PORT, 367 MHD_start_daemon (flags, PORT, NULL, NULL, &mhd_ahc, NULL,
392 NULL, NULL, 368 MHD_OPTION_END);
393 &mhd_ahc, NULL,
394 MHD_OPTION_END);
395 GNUNET_assert (NULL != mhd); 369 GNUNET_assert (NULL != mhd);
396 mhd_main (); 370 mhd_main ();
397 addr = NULL; 371 addr = NULL;
@@ -408,22 +382,17 @@ run (void *cls,
408 default: 382 default:
409 GNUNET_assert (0); 383 GNUNET_assert (0);
410 } 384 }
411 rr = GNUNET_VPN_redirect_to_ip (vpn, 385 rr = GNUNET_VPN_redirect_to_ip (vpn, src_af, dest_af, addr, GNUNET_YES,
412 src_af, 386 GNUNET_TIME_UNIT_FOREVER_ABS, &allocation_cb,
413 dest_af, 387 NULL);
414 addr, 388 ctrl_c_task_id =
415 GNUNET_YES, 389 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &ctrl_c_shutdown, NULL);
416 GNUNET_TIME_UNIT_FOREVER_ABS,
417 &allocation_cb, NULL);
418 ctrl_c_task_id = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
419 &ctrl_c_shutdown,
420 NULL);
421} 390}
422 391
423 392
424/** 393/**
425 * Test if the given AF is supported by this system. 394 * Test if the given AF is supported by this system.
426 * 395 *
427 * @param af to test 396 * @param af to test
428 * @return GNUNET_OK if the AF is supported 397 * @return GNUNET_OK if the AF is supported
429 */ 398 */
@@ -450,25 +419,21 @@ main (int argc, char *const *argv)
450{ 419{
451 const char *type; 420 const char *type;
452 const char *bin; 421 const char *bin;
453 422
454 if (0 != ACCESS ("/dev/net/tun", R_OK)) 423 if (0 != ACCESS ("/dev/net/tun", R_OK))
455 { 424 {
456 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 425 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "access",
457 "access", 426 "/dev/net/tun");
458 "/dev/net/tun"); 427 fprintf (stderr, "WARNING: System unable to run test, skipping.\n");
459 fprintf (stderr,
460 "WARNING: System unable to run test, skipping.\n");
461 return 0; 428 return 0;
462 } 429 }
463 if ( (GNUNET_YES != 430 if ((GNUNET_YES != GNUNET_OS_check_helper_binary ("gnunet-helper-vpn")) ||
464 GNUNET_OS_check_helper_binary ("gnunet-helper-vpn")) || 431 (GNUNET_YES != GNUNET_OS_check_helper_binary ("gnunet-helper-exit")))
465 (GNUNET_YES !=
466 GNUNET_OS_check_helper_binary ("gnunet-helper-exit")) )
467 { 432 {
468 fprintf (stderr, 433 fprintf (stderr,
469 "WARNING: gnunet-helper-{exit,vpn} binaries in $PATH are not SUID, refusing to run test (as it would have to fail).\n"); 434 "WARNING: gnunet-helper-{exit,vpn} binaries in $PATH are not SUID, refusing to run test (as it would have to fail).\n");
470 fprintf (stderr, 435 fprintf (stderr,
471 "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n"); 436 "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n");
472 return 0; 437 return 0;
473 } 438 }
474 GNUNET_CRYPTO_setup_hostkey ("test_gnunet_vpn.conf"); 439 GNUNET_CRYPTO_setup_hostkey ("test_gnunet_vpn.conf");
@@ -487,19 +452,19 @@ main (int argc, char *const *argv)
487 dest_ip = "FC5A:04E1:C2BA::1"; 452 dest_ip = "FC5A:04E1:C2BA::1";
488 dest_af = AF_INET6; 453 dest_af = AF_INET6;
489 src_af = AF_INET; 454 src_af = AF_INET;
490 } 455 }
491 else if (0 == strcmp (type, "6_to_4")) 456 else if (0 == strcmp (type, "6_to_4"))
492 { 457 {
493 dest_ip = "169.254.86.1"; 458 dest_ip = "169.254.86.1";
494 dest_af = AF_INET; 459 dest_af = AF_INET;
495 src_af = AF_INET6; 460 src_af = AF_INET6;
496 } 461 }
497 else if (0 == strcmp (type, "4_over")) 462 else if (0 == strcmp (type, "4_over"))
498 { 463 {
499 dest_ip = "169.254.86.1"; 464 dest_ip = "169.254.86.1";
500 dest_af = AF_INET; 465 dest_af = AF_INET;
501 src_af = AF_INET; 466 src_af = AF_INET;
502 } 467 }
503 else if (0 == strcmp (type, "6_over")) 468 else if (0 == strcmp (type, "6_over"))
504 { 469 {
505 dest_ip = "FC5A:04E1:C2BA::1"; 470 dest_ip = "FC5A:04E1:C2BA::1";
@@ -511,11 +476,10 @@ main (int argc, char *const *argv)
511 fprintf (stderr, "invalid binary suffix `%s'\n", type); 476 fprintf (stderr, "invalid binary suffix `%s'\n", type);
512 return 1; 477 return 1;
513 } 478 }
514 if ( (GNUNET_OK != test_af (src_af)) || 479 if ((GNUNET_OK != test_af (src_af)) || (GNUNET_OK != test_af (dest_af)))
515 (GNUNET_OK != test_af (dest_af)) )
516 { 480 {
517 fprintf (stderr, 481 fprintf (stderr,
518 "Required address families not supported by this system, skipping test.\n"); 482 "Required address families not supported by this system, skipping test.\n");
519 return 0; 483 return 0;
520 } 484 }
521 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 485 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
@@ -523,13 +487,12 @@ main (int argc, char *const *argv)
523 fprintf (stderr, "failed to initialize curl\n"); 487 fprintf (stderr, "failed to initialize curl\n");
524 return 2; 488 return 2;
525 } 489 }
526 if (0 != GNUNET_TESTING_peer_run ("test-gnunet-vpn", 490 if (0 !=
527 "test_gnunet_vpn.conf", 491 GNUNET_TESTING_peer_run ("test-gnunet-vpn", "test_gnunet_vpn.conf", &run,
528 &run, NULL)) 492 NULL))
529 return 1; 493 return 1;
530 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn"); 494 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn");
531 return global_ret; 495 return global_ret;
532} 496}
533 497
534/* end of test_gnunet_vpn.c */ 498/* end of test_gnunet_vpn.c */
535