aboutsummaryrefslogtreecommitdiff
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.c205
1 files changed, 108 insertions, 97 deletions
diff --git a/src/vpn/gnunet-vpn.c b/src/vpn/gnunet-vpn.c
index 38ead2023..1651767f4 100644
--- a/src/vpn/gnunet-vpn.c
+++ b/src/vpn/gnunet-vpn.c
@@ -88,7 +88,7 @@ static int ret;
88/** 88/**
89 * Option '-d': duration of the mapping 89 * Option '-d': duration of the mapping
90 */ 90 */
91static struct GNUNET_TIME_Relative duration = { 5 * 60 * 1000} ; 91static struct GNUNET_TIME_Relative duration = {5 * 60 * 1000};
92 92
93 93
94/** 94/**
@@ -127,9 +127,7 @@ 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, 130allocation_cb (void *cls, int af, const void *address)
131 int af,
132 const void *address)
133{ 131{
134 char buf[INET6_ADDRSTRLEN]; 132 char buf[INET6_ADDRSTRLEN];
135 133
@@ -138,13 +136,10 @@ allocation_cb (void *cls,
138 { 136 {
139 case AF_INET6: 137 case AF_INET6:
140 case AF_INET: 138 case AF_INET:
141 FPRINTF (stdout, 139 fprintf (stdout, "%s\n", inet_ntop (af, address, buf, sizeof (buf)));
142 "%s\n",
143 inet_ntop (af, address, buf, sizeof (buf)));
144 break; 140 break;
145 case AF_UNSPEC: 141 case AF_UNSPEC:
146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Error creating tunnel\n"));
147 _("Error creating tunnel\n"));
148 ret = 1; 143 ret = 1;
149 break; 144 break;
150 default: 145 default:
@@ -188,8 +183,10 @@ run (void *cls,
188 { 183 {
189 if (ipv6) 184 if (ipv6)
190 { 185 {
191 FPRINTF (stderr, _("Option `%s' makes no sense with option `%s'.\n"), 186 fprintf (stderr,
192 "-4", "-6"); 187 _ ("Option `%s' makes no sense with option `%s'.\n"),
188 "-4",
189 "-6");
193 goto error; 190 goto error;
194 } 191 }
195 req_af = AF_INET; 192 req_af = AF_INET;
@@ -201,26 +198,32 @@ run (void *cls,
201 { 198 {
202 if (NULL == service_name) 199 if (NULL == service_name)
203 { 200 {
204 FPRINTF (stderr, _("Option `%s' or `%s' is required.\n"), 201 fprintf (stderr, _ ("Option `%s' or `%s' is required.\n"), "-i", "-s");
205 "-i", "-s");
206 goto error; 202 goto error;
207 } 203 }
208 if (NULL == peer_id) 204 if (NULL == peer_id)
209 { 205 {
210 FPRINTF (stderr, _("Option `%s' is required when using option `%s'.\n"), 206 fprintf (stderr,
211 "-p", "-s"); 207 _ ("Option `%s' is required when using option `%s'.\n"),
208 "-p",
209 "-s");
212 goto error; 210 goto error;
213 } 211 }
214 if (! (tcp | udp) ) 212 if (! (tcp | udp))
215 { 213 {
216 FPRINTF (stderr, _("Option `%s' or `%s' is required when using option `%s'.\n"), 214 fprintf (stderr,
217 "-t", "-u", "-s"); 215 _ ("Option `%s' or `%s' is required when using option `%s'.\n"),
216 "-t",
217 "-u",
218 "-s");
218 goto error; 219 goto error;
219 } 220 }
220 if (tcp & udp) 221 if (tcp & udp)
221 { 222 {
222 FPRINTF (stderr, _("Option `%s' makes no sense with option `%s'.\n"), 223 fprintf (stderr,
223 "-t", "-u"); 224 _ ("Option `%s' makes no sense with option `%s'.\n"),
225 "-t",
226 "-u");
224 goto error; 227 goto error;
225 } 228 }
226 if (tcp) 229 if (tcp)
@@ -228,24 +231,22 @@ run (void *cls,
228 if (udp) 231 if (udp)
229 protocol = IPPROTO_UDP; 232 protocol = IPPROTO_UDP;
230 if (GNUNET_OK != 233 if (GNUNET_OK !=
231 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, 234 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
232 strlen (peer_id), 235 strlen (peer_id),
233 &peer.public_key)) 236 &peer.public_key))
234 { 237 {
235 FPRINTF (stderr, 238 fprintf (stderr, _ ("`%s' is not a valid peer identifier.\n"), peer_id);
236 _("`%s' is not a valid peer identifier.\n"),
237 peer_id);
238 goto error; 239 goto error;
239 } 240 }
240 GNUNET_TUN_service_name_to_hash (service_name, 241 GNUNET_TUN_service_name_to_hash (service_name, &sd);
241 &sd);
242 request = GNUNET_VPN_redirect_to_peer (handle, 242 request = GNUNET_VPN_redirect_to_peer (handle,
243 req_af, 243 req_af,
244 protocol, 244 protocol,
245 &peer, 245 &peer,
246 &sd, 246 &sd,
247 etime, 247 etime,
248 &allocation_cb, NULL); 248 &allocation_cb,
249 NULL);
249 } 250 }
250 else 251 else
251 { 252 {
@@ -253,14 +254,13 @@ run (void *cls,
253 { 254 {
254 if (1 != inet_pton (AF_INET, target_ip, &v4)) 255 if (1 != inet_pton (AF_INET, target_ip, &v4))
255 { 256 {
256 FPRINTF (stderr, _("`%s' is not a valid IP address.\n"), 257 fprintf (stderr, _ ("`%s' is not a valid IP address.\n"), target_ip);
257 target_ip); 258 goto error;
258 goto error;
259 } 259 }
260 else 260 else
261 { 261 {
262 dst_af = AF_INET; 262 dst_af = AF_INET;
263 addr = &v4; 263 addr = &v4;
264 } 264 }
265 } 265 }
266 else 266 else
@@ -269,15 +269,16 @@ run (void *cls,
269 addr = &v6; 269 addr = &v6;
270 } 270 }
271 request = GNUNET_VPN_redirect_to_ip (handle, 271 request = GNUNET_VPN_redirect_to_ip (handle,
272 req_af, 272 req_af,
273 dst_af, 273 dst_af,
274 addr, 274 addr,
275 etime, 275 etime,
276 &allocation_cb, NULL); 276 &allocation_cb,
277 NULL);
277 } 278 }
278 return; 279 return;
279 280
280 error: 281error:
281 GNUNET_SCHEDULER_shutdown (); 282 GNUNET_SCHEDULER_shutdown ();
282 ret = 1; 283 ret = 1;
283} 284}
@@ -286,63 +287,73 @@ run (void *cls,
286int 287int
287main (int argc, char *const *argv) 288main (int argc, char *const *argv)
288{ 289{
289 struct GNUNET_GETOPT_CommandLineOption options[] = { 290 struct GNUNET_GETOPT_CommandLineOption options[] =
290 GNUNET_GETOPT_option_flag ('4', 291 {GNUNET_GETOPT_option_flag ('4',
291 "ipv4", 292 "ipv4",
292 gettext_noop ("request that result should be an IPv4 address"), 293 gettext_noop (
293 &ipv4), 294 "request that result should be an IPv4 address"),
294 295 &ipv4),
295 GNUNET_GETOPT_option_flag ('6', 296
296 "ipv6", 297 GNUNET_GETOPT_option_flag ('6',
297 gettext_noop ("request that result should be an IPv6 address"), 298 "ipv6",
298 &ipv6), 299 gettext_noop (
299 300 "request that result should be an IPv6 address"),
300 GNUNET_GETOPT_option_relative_time ('d', 301 &ipv6),
301 "duration", 302
302 "TIME", 303 GNUNET_GETOPT_option_relative_time (
303 gettext_noop ("how long should the mapping be valid for new tunnels?"), 304 'd',
304 &duration), 305 "duration",
305 306 "TIME",
306 GNUNET_GETOPT_option_string ('i', 307 gettext_noop ("how long should the mapping be valid for new tunnels?"),
307 "ip", 308 &duration),
308 "IP", 309
309 gettext_noop ("destination IP for the tunnel"), 310 GNUNET_GETOPT_option_string ('i',
310 &target_ip), 311 "ip",
311 312 "IP",
312 GNUNET_GETOPT_option_string ('p', 313 gettext_noop (
313 "peer", 314 "destination IP for the tunnel"),
314 "PEERID", 315 &target_ip),
315 gettext_noop ("peer offering the service we would like to access"), 316
316 &peer_id), 317 GNUNET_GETOPT_option_string (
317 318 'p',
318 GNUNET_GETOPT_option_string ('s', 319 "peer",
319 "service", 320 "PEERID",
320 "NAME", 321 gettext_noop ("peer offering the service we would like to access"),
321 gettext_noop ("name of the service we would like to access"), 322 &peer_id),
322 &service_name), 323
323 324 GNUNET_GETOPT_option_string ('s',
324 GNUNET_GETOPT_option_flag ('t', 325 "service",
325 "tcp", 326 "NAME",
326 gettext_noop ("service is offered via TCP"), 327 gettext_noop (
327 &tcp), 328 "name of the service we would like to access"),
328 329 &service_name),
329 GNUNET_GETOPT_option_flag ('u', 330
330 "udp", 331 GNUNET_GETOPT_option_flag ('t',
331 gettext_noop ("service is offered via UDP"), 332 "tcp",
332 &udp), 333 gettext_noop ("service is offered via TCP"),
333 334 &tcp),
334 GNUNET_GETOPT_option_verbose (&verbosity), 335
335 336 GNUNET_GETOPT_option_flag ('u',
336 GNUNET_GETOPT_OPTION_END 337 "udp",
337 }; 338 gettext_noop ("service is offered via UDP"),
339 &udp),
340
341 GNUNET_GETOPT_option_verbose (&verbosity),
342
343 GNUNET_GETOPT_OPTION_END};
338 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 344 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
339 return 2; 345 return 2;
340 346
341 ret = (GNUNET_OK == 347 ret =
342 GNUNET_PROGRAM_run (argc, argv, "gnunet-vpn", 348 (GNUNET_OK == GNUNET_PROGRAM_run (argc,
343 gettext_noop 349 argv,
344 ("Setup tunnels via VPN."), options, 350 "gnunet-vpn",
345 &run, NULL)) ? ret : 1; 351 gettext_noop ("Setup tunnels via VPN."),
352 options,
353 &run,
354 NULL))
355 ? ret
356 : 1;
346 GNUNET_free ((void *) argv); 357 GNUNET_free ((void *) argv);
347 return ret; 358 return ret;
348} 359}