diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-07 19:36:34 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-07 19:36:34 +0000 |
commit | 9accb73ff8df685cae8adb1d4dc5c84c4c7ea1dd (patch) | |
tree | 78dd3a7036fbf97128253d215e0fcd60416ec624 | |
parent | 2b10e1f8373f14ffdeb40e735340fd467dee0b0d (diff) | |
download | gnunet-9accb73ff8df685cae8adb1d4dc5c84c4c7ea1dd.tar.gz gnunet-9accb73ff8df685cae8adb1d4dc5c84c4c7ea1dd.zip |
-skeleton code for gnunet-vpn command
-rw-r--r-- | src/vpn/Makefile.am | 9 | ||||
-rw-r--r-- | src/vpn/gnunet-service-vpn.c | 2 | ||||
-rw-r--r-- | src/vpn/gnunet-vpn.c | 149 |
3 files changed, 158 insertions, 2 deletions
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am index dd617c2d5..6dcc85f67 100644 --- a/src/vpn/Makefile.am +++ b/src/vpn/Makefile.am | |||
@@ -30,7 +30,7 @@ lib_LTLIBRARIES = \ | |||
30 | 30 | ||
31 | 31 | ||
32 | bin_PROGRAMS = \ | 32 | bin_PROGRAMS = \ |
33 | gnunet-daemon-exit gnunet-daemon-vpn $(VPNBIN) gnunet-service-vpn | 33 | gnunet-daemon-exit gnunet-daemon-vpn $(VPNBIN) gnunet-service-vpn gnunet-vpn |
34 | 34 | ||
35 | 35 | ||
36 | gnunet_helper_vpn_SOURCES = \ | 36 | gnunet_helper_vpn_SOURCES = \ |
@@ -64,6 +64,13 @@ gnunet_daemon_exit_LDADD = \ | |||
64 | $(top_builddir)/src/mesh/libgnunetmesh.la \ | 64 | $(top_builddir)/src/mesh/libgnunetmesh.la \ |
65 | $(GN_LIBINTL) | 65 | $(GN_LIBINTL) |
66 | 66 | ||
67 | gnunet_vpn_SOURCES = \ | ||
68 | gnunet-vpn.c | ||
69 | gnunet_vpn_LDADD = \ | ||
70 | $(top_builddir)/src/vpn/libgnunetvpn.la \ | ||
71 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
72 | $(GN_LIBINTL) | ||
73 | |||
67 | libgnunetvpn_la_SOURCES = \ | 74 | libgnunetvpn_la_SOURCES = \ |
68 | vpn_api.c vpn.h | 75 | vpn_api.c vpn.h |
69 | libgnunetvpn_la_LIBADD = \ | 76 | libgnunetvpn_la_LIBADD = \ |
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index e736b7746..f45c22370 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c | |||
@@ -34,7 +34,7 @@ | |||
34 | * - build IP messages from mesh replies | 34 | * - build IP messages from mesh replies |
35 | * - fully implement shutdown code | 35 | * - fully implement shutdown code |
36 | * - [implement VPN library] | 36 | * - [implement VPN library] |
37 | * - add back ICMP support (especially needed for IPv6)o | 37 | * - add back ICMP support (especially needed for IPv6) |
38 | */ | 38 | */ |
39 | #include "platform.h" | 39 | #include "platform.h" |
40 | #include "gnunet_util_lib.h" | 40 | #include "gnunet_util_lib.h" |
diff --git a/src/vpn/gnunet-vpn.c b/src/vpn/gnunet-vpn.c new file mode 100644 index 000000000..3be830a6a --- /dev/null +++ b/src/vpn/gnunet-vpn.c | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | 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 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file src/vpn/gnunet-vpn.c | ||
23 | * @brief Tool to manually request VPN tunnels to be created | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_vpn_service.h" | ||
30 | |||
31 | |||
32 | /** | ||
33 | * Handle to vpn service. | ||
34 | */ | ||
35 | static struct GNUNET_VPN_Handle *handle; | ||
36 | |||
37 | /** | ||
38 | * Opaque redirection request handle. | ||
39 | */ | ||
40 | static struct GNUNET_VPN_RedirectionRequest *request; | ||
41 | |||
42 | /** | ||
43 | * Option -p: destination peer identity for service | ||
44 | */ | ||
45 | static char *peer_id; | ||
46 | |||
47 | /** | ||
48 | * Option -s: service name (hash to get service descriptor) | ||
49 | */ | ||
50 | static char *service_name; | ||
51 | |||
52 | /** | ||
53 | * Option -i: target IP | ||
54 | */ | ||
55 | static char *target_ip; | ||
56 | |||
57 | /** | ||
58 | * Option -4: IPv4 requested. | ||
59 | */ | ||
60 | static int ipv4; | ||
61 | |||
62 | /** | ||
63 | * Option -6: IPv6 requested. | ||
64 | */ | ||
65 | static int ipv6; | ||
66 | |||
67 | /** | ||
68 | * Selected level of verbosity. | ||
69 | */ | ||
70 | static int verbosity; | ||
71 | |||
72 | /** | ||
73 | * Global return value. | ||
74 | */ | ||
75 | static int ret; | ||
76 | |||
77 | |||
78 | /** | ||
79 | * Shutdown. | ||
80 | */ | ||
81 | static void | ||
82 | do_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
83 | { | ||
84 | if (NULL != request) | ||
85 | { | ||
86 | GNUNET_VPN_cancel_request (request); | ||
87 | request = NULL; | ||
88 | } | ||
89 | if (NULL != handle) | ||
90 | { | ||
91 | GNUNET_VPN_disconnect (handle); | ||
92 | handle = NULL; | ||
93 | } | ||
94 | GNUNET_free_non_null (peer_id); | ||
95 | GNUNET_free_non_null (service_name); | ||
96 | GNUNET_free_non_null (target_ip); | ||
97 | } | ||
98 | |||
99 | |||
100 | /** | ||
101 | * Main function that will be run by the scheduler. | ||
102 | * | ||
103 | * @param cls closure | ||
104 | * @param args remaining command-line arguments | ||
105 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
106 | * @param cfg configuration | ||
107 | */ | ||
108 | static void | ||
109 | run (void *cls, char *const *args, const char *cfgfile, | ||
110 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
111 | { | ||
112 | handle = GNUNET_VPN_connect (cfg); | ||
113 | |||
114 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
115 | &do_disconnect, NULL); | ||
116 | } | ||
117 | |||
118 | |||
119 | int | ||
120 | main (int argc, char *const *argv) | ||
121 | { | ||
122 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
123 | {'4', "ipv4", NULL, | ||
124 | gettext_noop ("request that result should be an IPv4 address"), | ||
125 | 0, &GNUNET_GETOPT_set_one, &ipv4}, | ||
126 | {'6', "ipv6", NULL, | ||
127 | gettext_noop ("request that result should be an IPv6 address"), | ||
128 | 0, &GNUNET_GETOPT_set_one, &ipv6}, | ||
129 | {'i', "ip", "IP", | ||
130 | gettext_noop ("destination IP for the tunnel"), | ||
131 | 1, &GNUNET_GETOPT_set_string, &target_ip}, | ||
132 | {'p', "peer", "PEERID", | ||
133 | gettext_noop ("peer offering the service we would like to access"), | ||
134 | 1, &GNUNET_GETOPT_set_string, &peer_id}, | ||
135 | {'s', "service", "NAME", | ||
136 | gettext_noop ("name of the service we would like to access"), | ||
137 | 1, &GNUNET_GETOPT_set_string, &peer_id}, | ||
138 | GNUNET_GETOPT_OPTION_VERBOSE (&verbosity), | ||
139 | GNUNET_GETOPT_OPTION_END | ||
140 | }; | ||
141 | return (GNUNET_OK == | ||
142 | GNUNET_PROGRAM_run (argc, argv, "gnunet-vpn", | ||
143 | gettext_noop | ||
144 | ("Setup tunnels via VPN."), options, | ||
145 | &run, NULL)) ? ret : 1; | ||
146 | } | ||
147 | |||
148 | |||
149 | /* end of gnunet-vpn.c */ | ||