summaryrefslogtreecommitdiff
path: root/src/vpn/gnunet-vpn.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vpn/gnunet-vpn.c')
-rw-r--r--src/vpn/gnunet-vpn.c334
1 files changed, 167 insertions, 167 deletions
diff --git a/src/vpn/gnunet-vpn.c b/src/vpn/gnunet-vpn.c
index e5b79be6e..6dcd227c7 100644
--- a/src/vpn/gnunet-vpn.c
+++ b/src/vpn/gnunet-vpn.c
@@ -95,21 +95,21 @@ static struct GNUNET_TIME_Relative duration = { 5 * 60 * 1000 };
95 * Shutdown. 95 * Shutdown.
96 */ 96 */
97static void 97static void
98do_disconnect(void *cls) 98do_disconnect (void *cls)
99{ 99{
100 if (NULL != request) 100 if (NULL != request)
101 { 101 {
102 GNUNET_VPN_cancel_request(request); 102 GNUNET_VPN_cancel_request (request);
103 request = NULL; 103 request = NULL;
104 } 104 }
105 if (NULL != handle) 105 if (NULL != handle)
106 { 106 {
107 GNUNET_VPN_disconnect(handle); 107 GNUNET_VPN_disconnect (handle);
108 handle = NULL; 108 handle = NULL;
109 } 109 }
110 GNUNET_free_non_null(peer_id); 110 GNUNET_free_non_null (peer_id);
111 GNUNET_free_non_null(service_name); 111 GNUNET_free_non_null (service_name);
112 GNUNET_free_non_null(target_ip); 112 GNUNET_free_non_null (target_ip);
113} 113}
114 114
115 115
@@ -127,27 +127,27 @@ do_disconnect(void *cls)
127 * specified target peer; NULL on error 127 * specified target peer; NULL on error
128 */ 128 */
129static void 129static void
130allocation_cb(void *cls, int af, const void *address) 130allocation_cb (void *cls, int af, const void *address)
131{ 131{
132 char buf[INET6_ADDRSTRLEN]; 132 char buf[INET6_ADDRSTRLEN];
133 133
134 request = NULL; 134 request = NULL;
135 switch (af) 135 switch (af)
136 { 136 {
137 case AF_INET6: 137 case AF_INET6:
138 case AF_INET: 138 case AF_INET:
139 fprintf(stdout, "%s\n", inet_ntop(af, address, buf, sizeof(buf))); 139 fprintf (stdout, "%s\n", inet_ntop (af, address, buf, sizeof(buf)));
140 break; 140 break;
141 141
142 case AF_UNSPEC: 142 case AF_UNSPEC:
143 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Error creating tunnel\n")); 143 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Error creating tunnel\n"));
144 ret = 1; 144 ret = 1;
145 break; 145 break;
146 146
147 default: 147 default:
148 break; 148 break;
149 } 149 }
150 GNUNET_SCHEDULER_shutdown(); 150 GNUNET_SCHEDULER_shutdown ();
151} 151}
152 152
153 153
@@ -160,10 +160,10 @@ allocation_cb(void *cls, int af, const void *address)
160 * @param cfg configuration 160 * @param cfg configuration
161 */ 161 */
162static void 162static void
163run(void *cls, 163run (void *cls,
164 char *const *args, 164 char *const *args,
165 const char *cfgfile, 165 const char *cfgfile,
166 const struct GNUNET_CONFIGURATION_Handle *cfg) 166 const struct GNUNET_CONFIGURATION_Handle *cfg)
167{ 167{
168 int dst_af; 168 int dst_af;
169 int req_af; 169 int req_af;
@@ -175,189 +175,189 @@ run(void *cls,
175 uint8_t protocol; 175 uint8_t protocol;
176 struct GNUNET_TIME_Absolute etime; 176 struct GNUNET_TIME_Absolute etime;
177 177
178 etime = GNUNET_TIME_relative_to_absolute(duration); 178 etime = GNUNET_TIME_relative_to_absolute (duration);
179 GNUNET_SCHEDULER_add_shutdown(&do_disconnect, NULL); 179 GNUNET_SCHEDULER_add_shutdown (&do_disconnect, NULL);
180 handle = GNUNET_VPN_connect(cfg); 180 handle = GNUNET_VPN_connect (cfg);
181 if (NULL == handle) 181 if (NULL == handle)
182 goto error; 182 goto error;
183 req_af = AF_UNSPEC; 183 req_af = AF_UNSPEC;
184 if (ipv4) 184 if (ipv4)
185 {
186 if (ipv6)
185 { 187 {
186 if (ipv6) 188 fprintf (stderr,
187 { 189 _ ("Option `%s' makes no sense with option `%s'.\n"),
188 fprintf(stderr, 190 "-4",
189 _("Option `%s' makes no sense with option `%s'.\n"), 191 "-6");
190 "-4", 192 goto error;
191 "-6");
192 goto error;
193 }
194 req_af = AF_INET;
195 } 193 }
194 req_af = AF_INET;
195 }
196 if (ipv6) 196 if (ipv6)
197 req_af = AF_INET6; 197 req_af = AF_INET6;
198 198
199 if (NULL == target_ip) 199 if (NULL == target_ip)
200 {
201 if (NULL == service_name)
202 {
203 fprintf (stderr, _ ("Option `%s' or `%s' is required.\n"), "-i", "-s");
204 goto error;
205 }
206 if (NULL == peer_id)
200 { 207 {
201 if (NULL == service_name) 208 fprintf (stderr,
202 { 209 _ ("Option `%s' is required when using option `%s'.\n"),
203 fprintf(stderr, _("Option `%s' or `%s' is required.\n"), "-i", "-s"); 210 "-p",
204 goto error; 211 "-s");
205 } 212 goto error;
206 if (NULL == peer_id)
207 {
208 fprintf(stderr,
209 _("Option `%s' is required when using option `%s'.\n"),
210 "-p",
211 "-s");
212 goto error;
213 }
214 if (!(tcp | udp))
215 {
216 fprintf(stderr,
217 _("Option `%s' or `%s' is required when using option `%s'.\n"),
218 "-t",
219 "-u",
220 "-s");
221 goto error;
222 }
223 if (tcp & udp)
224 {
225 fprintf(stderr,
226 _("Option `%s' makes no sense with option `%s'.\n"),
227 "-t",
228 "-u");
229 goto error;
230 }
231 if (tcp)
232 protocol = IPPROTO_TCP;
233 if (udp)
234 protocol = IPPROTO_UDP;
235 if (GNUNET_OK !=
236 GNUNET_CRYPTO_eddsa_public_key_from_string(peer_id,
237 strlen(peer_id),
238 &peer.public_key))
239 {
240 fprintf(stderr, _("`%s' is not a valid peer identifier.\n"), peer_id);
241 goto error;
242 }
243 GNUNET_TUN_service_name_to_hash(service_name, &sd);
244 request = GNUNET_VPN_redirect_to_peer(handle,
245 req_af,
246 protocol,
247 &peer,
248 &sd,
249 etime,
250 &allocation_cb,
251 NULL);
252 } 213 }
214 if (! (tcp | udp))
215 {
216 fprintf (stderr,
217 _ ("Option `%s' or `%s' is required when using option `%s'.\n"),
218 "-t",
219 "-u",
220 "-s");
221 goto error;
222 }
223 if (tcp & udp)
224 {
225 fprintf (stderr,
226 _ ("Option `%s' makes no sense with option `%s'.\n"),
227 "-t",
228 "-u");
229 goto error;
230 }
231 if (tcp)
232 protocol = IPPROTO_TCP;
233 if (udp)
234 protocol = IPPROTO_UDP;
235 if (GNUNET_OK !=
236 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
237 strlen (peer_id),
238 &peer.public_key))
239 {
240 fprintf (stderr, _ ("`%s' is not a valid peer identifier.\n"), peer_id);
241 goto error;
242 }
243 GNUNET_TUN_service_name_to_hash (service_name, &sd);
244 request = GNUNET_VPN_redirect_to_peer (handle,
245 req_af,
246 protocol,
247 &peer,
248 &sd,
249 etime,
250 &allocation_cb,
251 NULL);
252 }
253 else 253 else
254 {
255 if (1 != inet_pton (AF_INET6, target_ip, &v6))
254 { 256 {
255 if (1 != inet_pton(AF_INET6, target_ip, &v6)) 257 if (1 != inet_pton (AF_INET, target_ip, &v4))
256 { 258 {
257 if (1 != inet_pton(AF_INET, target_ip, &v4)) 259 fprintf (stderr, _ ("`%s' is not a valid IP address.\n"), target_ip);
258 { 260 goto error;
259 fprintf(stderr, _("`%s' is not a valid IP address.\n"), target_ip); 261 }
260 goto error;
261 }
262 else
263 {
264 dst_af = AF_INET;
265 addr = &v4;
266 }
267 }
268 else 262 else
269 { 263 {
270 dst_af = AF_INET6; 264 dst_af = AF_INET;
271 addr = &v6; 265 addr = &v4;
272 } 266 }
273 request = GNUNET_VPN_redirect_to_ip(handle, 267 }
274 req_af, 268 else
275 dst_af, 269 {
276 addr, 270 dst_af = AF_INET6;
277 etime, 271 addr = &v6;
278 &allocation_cb,
279 NULL);
280 } 272 }
273 request = GNUNET_VPN_redirect_to_ip (handle,
274 req_af,
275 dst_af,
276 addr,
277 etime,
278 &allocation_cb,
279 NULL);
280 }
281 return; 281 return;
282 282
283error: 283error:
284 GNUNET_SCHEDULER_shutdown(); 284 GNUNET_SCHEDULER_shutdown ();
285 ret = 1; 285 ret = 1;
286} 286}
287 287
288 288
289int 289int
290main(int argc, char *const *argv) 290main (int argc, char *const *argv)
291{ 291{
292 struct GNUNET_GETOPT_CommandLineOption options[] = 292 struct GNUNET_GETOPT_CommandLineOption options[] =
293 { GNUNET_GETOPT_option_flag('4', 293 { GNUNET_GETOPT_option_flag ('4',
294 "ipv4", 294 "ipv4",
295 gettext_noop( 295 gettext_noop (
296 "request that result should be an IPv4 address"), 296 "request that result should be an IPv4 address"),
297 &ipv4), 297 &ipv4),
298 298
299 GNUNET_GETOPT_option_flag('6', 299 GNUNET_GETOPT_option_flag ('6',
300 "ipv6", 300 "ipv6",
301 gettext_noop( 301 gettext_noop (
302 "request that result should be an IPv6 address"), 302 "request that result should be an IPv6 address"),
303 &ipv6), 303 &ipv6),
304 304
305 GNUNET_GETOPT_option_relative_time( 305 GNUNET_GETOPT_option_relative_time (
306 'd', 306 'd',
307 "duration", 307 "duration",
308 "TIME", 308 "TIME",
309 gettext_noop("how long should the mapping be valid for new tunnels?"), 309 gettext_noop ("how long should the mapping be valid for new tunnels?"),
310 &duration), 310 &duration),
311 311
312 GNUNET_GETOPT_option_string('i', 312 GNUNET_GETOPT_option_string ('i',
313 "ip", 313 "ip",
314 "IP", 314 "IP",
315 gettext_noop( 315 gettext_noop (
316 "destination IP for the tunnel"), 316 "destination IP for the tunnel"),
317 &target_ip), 317 &target_ip),
318 318
319 GNUNET_GETOPT_option_string( 319 GNUNET_GETOPT_option_string (
320 'p', 320 'p',
321 "peer", 321 "peer",
322 "PEERID", 322 "PEERID",
323 gettext_noop("peer offering the service we would like to access"), 323 gettext_noop ("peer offering the service we would like to access"),
324 &peer_id), 324 &peer_id),
325 325
326 GNUNET_GETOPT_option_string('s', 326 GNUNET_GETOPT_option_string ('s',
327 "service", 327 "service",
328 "NAME", 328 "NAME",
329 gettext_noop( 329 gettext_noop (
330 "name of the service we would like to access"), 330 "name of the service we would like to access"),
331 &service_name), 331 &service_name),
332 332
333 GNUNET_GETOPT_option_flag('t', 333 GNUNET_GETOPT_option_flag ('t',
334 "tcp", 334 "tcp",
335 gettext_noop("service is offered via TCP"), 335 gettext_noop ("service is offered via TCP"),
336 &tcp), 336 &tcp),
337 337
338 GNUNET_GETOPT_option_flag('u', 338 GNUNET_GETOPT_option_flag ('u',
339 "udp", 339 "udp",
340 gettext_noop("service is offered via UDP"), 340 gettext_noop ("service is offered via UDP"),
341 &udp), 341 &udp),
342 342
343 GNUNET_GETOPT_option_verbose(&verbosity), 343 GNUNET_GETOPT_option_verbose (&verbosity),
344 344
345 GNUNET_GETOPT_OPTION_END }; 345 GNUNET_GETOPT_OPTION_END };
346 346
347 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 347 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
348 return 2; 348 return 2;
349 349
350 ret = 350 ret =
351 (GNUNET_OK == GNUNET_PROGRAM_run(argc, 351 (GNUNET_OK == GNUNET_PROGRAM_run (argc,
352 argv, 352 argv,
353 "gnunet-vpn", 353 "gnunet-vpn",
354 gettext_noop("Setup tunnels via VPN."), 354 gettext_noop ("Setup tunnels via VPN."),
355 options, 355 options,
356 &run, 356 &run,
357 NULL)) 357 NULL))
358 ? ret 358 ? ret
359 : 1; 359 : 1;
360 GNUNET_free((void *)argv); 360 GNUNET_free ((void *) argv);
361 return ret; 361 return ret;
362} 362}
363 363