aboutsummaryrefslogtreecommitdiff
path: root/src/pt/test_gns_vpn.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pt/test_gns_vpn.c')
-rw-r--r--src/pt/test_gns_vpn.c865
1 files changed, 0 insertions, 865 deletions
diff --git a/src/pt/test_gns_vpn.c b/src/pt/test_gns_vpn.c
deleted file mode 100644
index d2d28d7c7..000000000
--- a/src/pt/test_gns_vpn.c
+++ /dev/null
@@ -1,865 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2007, 2009, 2011, 2012, 2015, 2017 Christian Grothoff
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file test_gns_vpn.c
23 * @brief testcase for accessing VPN services via GNS
24 * @author Martin Schanzenbach
25 * @author Christian Grothoff
26 *
27 * This test requires libcurl/libgnurl *with* support for C-ARES.
28 * This is NOT the default on most platforms, which means the test
29 * will be skipped in many cases. Compile libcurl/libgnurl with
30 * "--enable-ares" to get this test to pass.
31 *
32 * Furthermore, the test relies on gnunet-dns2gns being able to bind
33 * to port 53. This means that 'setcap' has to have worked during
34 * 'make install'. If this failed, but everything else is OK, the
35 * test may FAIL hard even though it is just an installation issue (we
36 * cannot conveniently test for the setcap to have worked). However,
37 * you should get a warning that gnunet-dns2gns failed to 'bind'.
38 */
39#include "platform.h"
40/* Just included for the right curl.h */
41#include "gnunet_curl_lib.h"
42#include <microhttpd.h>
43#include "gnunet_identity_service.h"
44#include "gnunet_namestore_service.h"
45#include "gnunet_gnsrecord_lib.h"
46#include "gnunet_gns_service.h"
47#include "gnunet_testing_lib.h"
48#include "gnunet_mhd_compat.h"
49
50#define PORT 8080
51#define TEST_DOMAIN "www.gnu"
52
53#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
54
55/**
56 * Return value for #main().
57 */
58static int global_ret;
59
60static struct GNUNET_NAMESTORE_Handle *namestore;
61
62static struct MHD_Daemon *mhd;
63
64static struct GNUNET_SCHEDULER_Task *mhd_task_id;
65
66static struct GNUNET_SCHEDULER_Task *curl_task_id;
67
68static struct GNUNET_SCHEDULER_Task *timeout_task;
69
70static struct GNUNET_IDENTITY_Handle *identity;
71
72static struct GNUNET_NAMESTORE_QueueEntry *qe;
73
74static CURL *curl;
75
76static CURLM *multi;
77
78static char *url;
79
80static struct GNUNET_PeerIdentity id;
81
82/**
83 * IP address of the ultimate destination.
84 */
85static const char *dest_ip;
86
87/**
88 * Address family of the dest_ip.
89 */
90static int dest_af;
91
92/**
93 * Address family to use by the curl client.
94 */
95static int src_af;
96
97static int use_v6;
98
99
100struct CBC
101{
102 char buf[1024];
103 size_t pos;
104};
105
106static struct CBC cbc;
107
108
109static size_t
110copy_buffer (void *ptr,
111 size_t size,
112 size_t nmemb,
113 void *ctx)
114{
115 struct CBC *cbc = ctx;
116
117 if (cbc->pos + size * nmemb > sizeof(cbc->buf))
118 return 0; /* overflow */
119 GNUNET_memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb);
120 cbc->pos += size * nmemb;
121 return size * nmemb;
122}
123
124
125static MHD_RESULT
126mhd_ahc (void *cls,
127 struct MHD_Connection *connection,
128 const char *url,
129 const char *method,
130 const char *version,
131 const char *upload_data, size_t *upload_data_size,
132 void **unused)
133{
134 static int ptr;
135 struct MHD_Response *response;
136 int ret;
137
138 if (0 != strcmp ("GET", method))
139 return MHD_NO; /* unexpected method */
140 if (&ptr != *unused)
141 {
142 *unused = &ptr;
143 return MHD_YES;
144 }
145 *unused = NULL;
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 "MHD sends response for request to URL `%s'\n", url);
148 response = MHD_create_response_from_buffer (strlen (url),
149 (void *) url,
150 MHD_RESPMEM_MUST_COPY);
151 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
152 MHD_destroy_response (response);
153 if (ret == MHD_NO)
154 abort ();
155 return ret;
156}
157
158
159static void
160do_shutdown (void *cls)
161{
162 if (NULL != mhd_task_id)
163 {
164 GNUNET_SCHEDULER_cancel (mhd_task_id);
165 mhd_task_id = NULL;
166 }
167 if (NULL != curl_task_id)
168 {
169 GNUNET_SCHEDULER_cancel (curl_task_id);
170 curl_task_id = NULL;
171 }
172 if (NULL != timeout_task)
173 {
174 GNUNET_SCHEDULER_cancel (timeout_task);
175 timeout_task = NULL;
176 }
177 if (NULL != mhd)
178 {
179 MHD_stop_daemon (mhd);
180 mhd = NULL;
181 }
182 if (NULL != identity)
183 {
184 GNUNET_IDENTITY_disconnect (identity);
185 identity = NULL;
186 }
187 if (NULL != qe)
188 {
189 GNUNET_NAMESTORE_cancel (qe);
190 qe = NULL;
191 }
192 if (NULL != namestore)
193 {
194 GNUNET_NAMESTORE_disconnect (namestore);
195 namestore = NULL;
196 }
197 GNUNET_free (url);
198 url = NULL;
199}
200
201
202static void
203do_timeout (void *cls)
204{
205 timeout_task = NULL;
206 GNUNET_SCHEDULER_shutdown ();
207}
208
209
210/**
211 * Function to run the HTTP client.
212 */
213static void
214curl_main (void);
215
216
217static void
218curl_task (void *cls)
219{
220 curl_task_id = NULL;
221 curl_main ();
222}
223
224
225static void
226curl_main ()
227{
228 fd_set rs;
229 fd_set ws;
230 fd_set es;
231 int max;
232 struct GNUNET_NETWORK_FDSet nrs;
233 struct GNUNET_NETWORK_FDSet nws;
234 struct GNUNET_TIME_Relative delay;
235 long timeout;
236 int running;
237 struct CURLMsg *msg;
238
239 max = 0;
240 FD_ZERO (&rs);
241 FD_ZERO (&ws);
242 FD_ZERO (&es);
243 curl_multi_perform (multi, &running);
244 if (running == 0)
245 {
246 GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running)));
247 if (msg->msg == CURLMSG_DONE)
248 {
249 if (msg->data.result != CURLE_OK)
250 {
251 fprintf (stderr,
252 "%s failed at %s:%d: `%s'\n",
253 "curl_multi_perform",
254 __FILE__,
255 __LINE__, curl_easy_strerror (msg->data.result));
256 global_ret = 1;
257 }
258 }
259 curl_multi_remove_handle (multi, curl);
260 curl_multi_cleanup (multi);
261 curl_easy_cleanup (curl);
262 curl = NULL;
263 multi = NULL;
264 if (cbc.pos != strlen ("/hello_world"))
265 {
266 GNUNET_break (0);
267 global_ret = 2;
268 }
269 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
270 {
271 GNUNET_break (0);
272 global_ret = 3;
273 }
274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
275 "Download complete, shutting down!\n");
276 GNUNET_SCHEDULER_shutdown ();
277 return;
278 }
279 GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max));
280 if ((CURLM_OK != curl_multi_timeout (multi, &timeout)) ||
281 (-1 == timeout))
282 delay = GNUNET_TIME_UNIT_SECONDS;
283 else
284 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
285 (unsigned int) timeout);
286 GNUNET_NETWORK_fdset_copy_native (&nrs,
287 &rs,
288 max + 1);
289 GNUNET_NETWORK_fdset_copy_native (&nws,
290 &ws,
291 max + 1);
292 curl_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
293 delay,
294 &nrs,
295 &nws,
296 &curl_task,
297 NULL);
298}
299
300
301static void
302start_curl (void *cls)
303{
304 CURLcode ec;
305
306 curl_task_id = NULL;
307 GNUNET_asprintf (&url,
308 "http://%s/hello_world",
309 TEST_DOMAIN);
310 curl = curl_easy_init ();
311 curl_easy_setopt (curl, CURLOPT_URL, url);
312 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &copy_buffer);
313 curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc);
314 curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1);
315 curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L);
316 curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 150L);
317 curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1);
318 if (CURLE_OK !=
319 (ec = curl_easy_setopt (curl,
320 CURLOPT_DNS_SERVERS,
321 "127.0.0.1:53")))
322 {
323 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
324 "curl build without support for CURLOPT_DNS_SERVERS (%s), cannot run test\n",
325 curl_easy_strerror (ec));
326 global_ret = 77;
327 GNUNET_SCHEDULER_shutdown ();
328 return;
329 }
330 multi = curl_multi_init ();
331 GNUNET_assert (multi != NULL);
332 GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl));
333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
334 "Beginning HTTP download from `%s'\n",
335 url);
336 curl_main ();
337}
338
339
340/**
341 * Callback invoked from the namestore service once record is
342 * created.
343 *
344 * @param cls closure
345 * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error;
346 * will match 'result_af' from the request
347 * @param address IP address (struct in_addr or struct in_addr6, depending on 'af')
348 * that the VPN allocated for the redirection;
349 * traffic to this IP will now be redirected to the
350 * specified target peer; NULL on error
351 */
352static void
353commence_testing (void *cls,
354 int32_t success,
355 const char *emsg)
356{
357 qe = NULL;
358 if ((NULL != emsg) &&
359 (GNUNET_YES != success))
360 {
361 fprintf (stderr,
362 "NS failed to create record %s\n",
363 emsg);
364 GNUNET_SCHEDULER_shutdown ();
365 return;
366 }
367
368 /* wait a little bit before downloading, as we just created the record */
369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
370 "Launching cURL request\n");
371 curl_task_id
372 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
373 &start_curl,
374 NULL);
375}
376
377
378/**
379 * Function to keep the HTTP server running.
380 */
381static void
382mhd_main (void);
383
384
385static void
386mhd_task (void *cls)
387{
388 mhd_task_id = NULL;
389 MHD_run (mhd);
390 mhd_main ();
391}
392
393
394static void
395mhd_main ()
396{
397 struct GNUNET_NETWORK_FDSet nrs;
398 struct GNUNET_NETWORK_FDSet nws;
399 fd_set rs;
400 fd_set ws;
401 fd_set es;
402 int max_fd;
403 unsigned MHD_LONG_LONG timeout;
404 struct GNUNET_TIME_Relative delay;
405
406 GNUNET_assert (NULL == mhd_task_id);
407 FD_ZERO (&rs);
408 FD_ZERO (&ws);
409 FD_ZERO (&es);
410 max_fd = -1;
411 GNUNET_assert (MHD_YES ==
412 MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd));
413 if (MHD_YES == MHD_get_timeout (mhd, &timeout))
414 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
415 (unsigned int) timeout);
416 else
417 delay = GNUNET_TIME_UNIT_FOREVER_REL;
418 GNUNET_NETWORK_fdset_copy_native (&nrs,
419 &rs,
420 max_fd + 1);
421 GNUNET_NETWORK_fdset_copy_native (&nws,
422 &ws,
423 max_fd + 1);
424 mhd_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
425 delay,
426 &nrs,
427 &nws,
428 &mhd_task,
429 NULL);
430}
431
432
433/**
434 * Open '/dev/null' and make the result the given
435 * file descriptor.
436 *
437 * @param target_fd desired FD to point to /dev/null
438 * @param flags open flags (O_RDONLY, O_WRONLY)
439 */
440static void
441open_dev_null (int target_fd,
442 int flags)
443{
444 int fd;
445
446 fd = open ("/dev/null", flags);
447 if (-1 == fd)
448 abort ();
449 if (fd == target_fd)
450 return;
451 if (-1 == dup2 (fd, target_fd))
452 {
453 (void) close (fd);
454 abort ();
455 }
456 (void) close (fd);
457}
458
459
460/**
461 * Run the given command and wait for it to complete.
462 *
463 * @param file name of the binary to run
464 * @param cmd command line arguments (as given to 'execv')
465 * @return 0 on success, 1 on any error
466 */
467static int
468fork_and_exec (const char *file,
469 char *const cmd[])
470{
471 int status;
472 pid_t pid;
473 pid_t ret;
474
475 pid = fork ();
476 if (-1 == pid)
477 {
478 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
479 "fork");
480 return 1;
481 }
482 if (0 == pid)
483 {
484 /* we are the child process */
485 /* close stdin/stdout to not cause interference
486 with the helper's main protocol! */
487 (void) close (0);
488 open_dev_null (0, O_RDONLY);
489 (void) close (1);
490 open_dev_null (1, O_WRONLY);
491 (void) execv (file, cmd);
492 /* can only get here on error */
493 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
494 "exec",
495 file);
496 _exit (1);
497 }
498 /* keep running waitpid as long as the only error we get is 'EINTR' */
499 while ((-1 == (ret = waitpid (pid, &status, 0))) &&
500 (errno == EINTR))
501 ;
502 if (-1 == ret)
503 {
504 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
505 "waitpid");
506 return 1;
507 }
508 if (! (WIFEXITED (status) &&
509 (0 == WEXITSTATUS (status))))
510 {
511 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
512 "Process `%s` returned status code %d/%d.\n",
513 file,
514 WIFEXITED (status),
515 WEXITSTATUS (status));
516 return 1;
517 }
518 /* child process completed and returned success, we're happy */
519 return 0;
520}
521
522
523/**
524 * Method called to inform about the egos of this peer.
525 *
526 * When used with #GNUNET_IDENTITY_connect, this function is
527 * initially called for all egos and then again whenever a
528 * ego's name changes or if it is deleted. At the end of
529 * the initial pass over all egos, the function is once called
530 * with 'NULL' for @a ego. That does NOT mean that the callback won't
531 * be invoked in the future or that there was an error.
532 *
533 * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get, this
534 * function is only called ONCE, and 'NULL' being passed in @a ego does
535 * indicate an error (for example because name is taken or no default value is
536 * known). If @a ego is non-NULL and if '*ctx' is set in those callbacks, the
537 * value WILL be passed to a subsequent call to the identity callback of
538 * #GNUNET_IDENTITY_connect (if that one was not NULL).
539 *
540 * When an identity is renamed, this function is called with the
541 * (known) @a ego but the NEW @a name.
542 *
543 * When an identity is deleted, this function is called with the
544 * (known) ego and "NULL" for the @a name. In this case,
545 * the @a ego is henceforth invalid (and the @a ctx should also be
546 * cleaned up).
547 *
548 * @param cls closure
549 * @param ego ego handle
550 * @param ctx context for application to store data for this ego
551 * (during the lifetime of this process, initially NULL)
552 * @param name name assigned by the user for this ego,
553 * NULL if the user just deleted the ego and it
554 * must thus no longer be used
555 */
556static void
557identity_cb (void *cls,
558 struct GNUNET_IDENTITY_Ego *ego,
559 void **ctx,
560 const char *name)
561{
562 const struct GNUNET_IDENTITY_PrivateKey *zone_key;
563 struct GNUNET_GNSRECORD_Data rd;
564 char *rd_string;
565 char *peername;
566
567 if (NULL == name)
568 return;
569 if (NULL == ego)
570 {
571 if (NULL == qe)
572 {
573 fprintf (stderr,
574 "Failed to find master-zone ego\n");
575 GNUNET_SCHEDULER_shutdown ();
576 return;
577 }
578 GNUNET_IDENTITY_disconnect (identity);
579 identity = NULL;
580 return;
581 }
582 GNUNET_assert (NULL != name);
583 if (0 != strcmp (name,
584 "master-zone"))
585 {
586 fprintf (stderr,
587 "Unexpected name %s\n",
588 name);
589 return;
590 }
591 zone_key = GNUNET_IDENTITY_ego_get_private_key (ego);
592 rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
593 peername = GNUNET_strdup (GNUNET_i2s_full (&id));
594 GNUNET_asprintf (&rd_string,
595 "6 %s %s",
596 peername,
597 "www");
598 GNUNET_free (peername);
599 GNUNET_assert (GNUNET_OK ==
600 GNUNET_GNSRECORD_string_to_value (GNUNET_GNSRECORD_TYPE_VPN,
601 rd_string,
602 (void **) &rd.data,
603 &rd.data_size));
604 rd.record_type = GNUNET_GNSRECORD_TYPE_VPN;
605
606 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
607 "Creating `www` record\n");
608 qe = GNUNET_NAMESTORE_records_store (namestore,
609 zone_key,
610 "www",
611 1, &rd,
612 &commence_testing,
613 NULL);
614 GNUNET_free_nz ((void **) rd.data);
615 GNUNET_free (rd_string);
616}
617
618
619static void
620run (void *cls,
621 const struct GNUNET_CONFIGURATION_Handle *cfg,
622 struct GNUNET_TESTING_Peer *peer)
623{
624 enum MHD_FLAG flags;
625
626 char *bin;
627 char *bin_identity;
628 char *bin_gns;
629 char *bin_arm;
630 char *config;
631
632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
633 "Test logic starting...\n");
634 if (GNUNET_OK !=
635 GNUNET_CONFIGURATION_get_value_string (cfg,
636 "arm",
637 "CONFIG",
638 &config))
639 {
640 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
641 "Failed to locate configuration file. Skipping test.\n");
642 GNUNET_SCHEDULER_shutdown ();
643 return;
644 }
645
646 char *const identity_args[] = {
647 "gnunet-identity",
648 "-C", "master-zone",
649 "-c", config,
650 NULL
651 };
652 char *const identity2_args[] = {
653 "gnunet-identity",
654 "-e", "master-zone",
655 "-s", "gns-master",
656 "-c", config,
657 NULL
658 };
659 char *const identity3_args[] = {
660 "gnunet-identity",
661 "-e", "master-zone",
662 "-s", "dns2gns",
663 "-c", config,
664 NULL
665 };
666 char *const arm_args[] = {
667 "gnunet-arm",
668 "-i", "dns2gns",
669 "-c", config,
670 NULL
671 };
672 char *const gns_args[] = {
673 "gnunet-gns",
674 "-u", "www.gnu",
675 "-c", config,
676 NULL
677 };
678
679 GNUNET_TESTING_peer_get_identity (peer,
680 &id);
681 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
682 NULL);
683 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
684 &do_timeout,
685 NULL);
686 bin = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
687 GNUNET_asprintf (&bin_identity,
688 "%s/%s",
689 bin,
690 "gnunet-identity");
691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
692 "Creating `master-zone` ego\n");
693 if (0 != fork_and_exec (bin_identity, identity_args))
694 {
695 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
696 "Failed to run `gnunet-identity -C`. Skipping test.\n");
697 GNUNET_SCHEDULER_shutdown ();
698 GNUNET_free (bin_identity);
699 GNUNET_free (config);
700 GNUNET_free (bin);
701 return;
702 }
703 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
704 "Setting `master-zone` ego as default for `gns-master` and `dns2gns`\n");
705 if (0 != fork_and_exec (bin_identity, identity2_args))
706 {
707 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
708 "Failed to run `gnunet-identity -e`. Skipping test.\n");
709 GNUNET_SCHEDULER_shutdown ();
710 GNUNET_free (bin_identity);
711 GNUNET_free (config);
712 GNUNET_free (bin);
713 return;
714 }
715 if (0 != fork_and_exec (bin_identity, identity3_args))
716 {
717 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
718 "Failed to run `gnunet-identity -e`. Skipping test.\n");
719 GNUNET_SCHEDULER_shutdown ();
720 GNUNET_free (bin_identity);
721 GNUNET_free (config);
722 GNUNET_free (bin);
723 return;
724 }
725 GNUNET_free (bin_identity);
726
727 /* do lookup just to launch GNS service */
728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
729 "Resolving `www.gnu` zone entry to launch GNS (will yield no answer yet)\n");
730 GNUNET_asprintf (&bin_gns,
731 "%s/%s",
732 bin,
733 "gnunet-gns");
734 if (0 != fork_and_exec (bin_gns,
735 gns_args))
736 {
737 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
738 "Failed to run `gnunet-gns -u. Skipping test.\n");
739 GNUNET_SCHEDULER_shutdown ();
740 GNUNET_free (bin_gns);
741 GNUNET_free (config);
742 GNUNET_free (bin);
743 return;
744 }
745 GNUNET_free (bin_gns);
746
747 GNUNET_asprintf (&bin_arm,
748 "%s/%s",
749 bin,
750 "gnunet-arm");
751 if (0 != fork_and_exec (bin_arm,
752 arm_args))
753 {
754 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
755 "Failed to run `gnunet-arm -i dns2gns. Skipping test.\n");
756 GNUNET_SCHEDULER_shutdown ();
757 GNUNET_free (bin_arm);
758 GNUNET_free (config);
759 GNUNET_free (bin);
760 return;
761 }
762 GNUNET_free (bin_arm);
763
764 GNUNET_free (config);
765 GNUNET_free (bin);
766 sleep (1); /* give dns2gns chance to really run */
767
768 namestore = GNUNET_NAMESTORE_connect (cfg);
769 GNUNET_assert (NULL != namestore);
770 flags = MHD_USE_DEBUG;
771 if (GNUNET_YES == use_v6)
772 flags |= MHD_USE_DUAL_STACK;
773 mhd = MHD_start_daemon (flags,
774 PORT,
775 NULL, NULL,
776 &mhd_ahc, NULL,
777 MHD_OPTION_END);
778 GNUNET_assert (NULL != mhd);
779 mhd_main ();
780
781 identity = GNUNET_IDENTITY_connect (cfg,
782 &identity_cb,
783 NULL);
784}
785
786
787int
788main (int argc,
789 char *const *argv)
790{
791 char *bin_vpn;
792 char *bin_exit;
793
794 GNUNET_log_setup ("test-gns-vpn",
795 "WARNING",
796 NULL);
797 if (0 != access ("/dev/net/tun", R_OK))
798 {
799 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
800 "access",
801 "/dev/net/tun");
802 fprintf (stderr,
803 "WARNING: System unable to run test, skipping.\n");
804 return 77;
805 }
806
807 bin_vpn = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn");
808 bin_exit = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-exit");
809 if ((0 != geteuid ()) &&
810 ((GNUNET_YES !=
811 GNUNET_OS_check_helper_binary (bin_vpn,
812 GNUNET_YES,
813 "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0"))
814 || // ipv4 only please!
815 (GNUNET_YES !=
816 GNUNET_OS_check_helper_binary (bin_exit,
817 GNUNET_YES,
818 "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")))) // no nat, ipv4 only
819 {
820 fprintf (stderr,
821 "WARNING: gnunet-helper-{exit,vpn} binaries in $PATH are not SUID, refusing to run test (as it would have to fail).\n");
822 fprintf (stderr,
823 "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n");
824 GNUNET_free (bin_vpn);
825 GNUNET_free (bin_exit);
826 return 77;
827 }
828 GNUNET_free (bin_vpn);
829 GNUNET_free (bin_exit);
830
831 dest_ip = "169.254.86.1";
832 dest_af = AF_INET;
833 src_af = AF_INET;
834
835 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6))
836 use_v6 = GNUNET_YES;
837 else
838 use_v6 = GNUNET_NO;
839
840 if ((GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) ||
841 (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af)))
842 {
843 fprintf (stderr,
844 "Required address families not supported by this system, skipping test.\n");
845 return 77;
846 }
847 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
848 {
849 fprintf (stderr, "failed to initialize curl\n");
850 return 2;
851 }
852
853
854 if (0 !=
855 GNUNET_TESTING_peer_run ("test_gns_vpn",
856 "test_gns_vpn.conf",
857 &run,
858 NULL))
859 return 1;
860 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn");
861 return global_ret;
862}
863
864
865/* end of test_gns_vpn.c */