diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-02-03 22:47:03 +0100 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-02-03 22:47:03 +0100 |
commit | f3eaf5dae9a14fc62109b6e7c69571a068301fed (patch) | |
tree | cec115818f7e41db3f5d6eccd1b04ed5b0b96fec | |
parent | afd2cb5db220ce528b6222340b31b8a1a365c8e4 (diff) | |
download | gnunet-f3eaf5dae9a14fc62109b6e7c69571a068301fed.tar.gz gnunet-f3eaf5dae9a14fc62109b6e7c69571a068301fed.zip |
GNS: Move VPN to DNS2GNS. Fixes #7171
-rw-r--r-- | src/gns/Makefile.am | 2 | ||||
-rw-r--r-- | src/gns/gnunet-dns2gns.c | 209 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 204 |
3 files changed, 213 insertions, 202 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 315b4dbf3..c21f37ca1 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -155,6 +155,7 @@ gnunet_dns2gns_LDADD = \ | |||
155 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 155 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
156 | libgnunetgns.la \ | 156 | libgnunetgns.la \ |
157 | $(top_builddir)/src/util/libgnunetutil.la \ | 157 | $(top_builddir)/src/util/libgnunetutil.la \ |
158 | $(USE_VPN) \ | ||
158 | $(top_builddir)/src/identity/libgnunetidentity.la \ | 159 | $(top_builddir)/src/identity/libgnunetidentity.la \ |
159 | $(GN_LIBINTL) | 160 | $(GN_LIBINTL) |
160 | 161 | ||
@@ -218,7 +219,6 @@ gnunet_service_gns_LDADD = \ | |||
218 | $(top_builddir)/src/dht/libgnunetdht.la \ | 219 | $(top_builddir)/src/dht/libgnunetdht.la \ |
219 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ | 220 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ |
220 | $(LIBIDN) $(LIBIDN2) \ | 221 | $(LIBIDN) $(LIBIDN2) \ |
221 | $(USE_VPN) \ | ||
222 | $(GN_LIBINTL) | 222 | $(GN_LIBINTL) |
223 | 223 | ||
224 | 224 | ||
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c index 06f4c9841..46659cdda 100644 --- a/src/gns/gnunet-dns2gns.c +++ b/src/gns/gnunet-dns2gns.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <gnunet_dnsparser_lib.h> | 27 | #include <gnunet_dnsparser_lib.h> |
28 | #include <gnunet_gns_service.h> | 28 | #include <gnunet_gns_service.h> |
29 | #include <gnunet_dnsstub_lib.h> | 29 | #include <gnunet_dnsstub_lib.h> |
30 | #include "gnunet_vpn_service.h" | ||
30 | #include "gns.h" | 31 | #include "gns.h" |
31 | 32 | ||
32 | /** | 33 | /** |
@@ -35,6 +36,46 @@ | |||
35 | #define TIMEOUT GNUNET_TIME_UNIT_MINUTES | 36 | #define TIMEOUT GNUNET_TIME_UNIT_MINUTES |
36 | 37 | ||
37 | /** | 38 | /** |
39 | * Default timeout for VPN redirections. | ||
40 | */ | ||
41 | #define VPN_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) | ||
42 | |||
43 | |||
44 | struct Request; | ||
45 | |||
46 | /** | ||
47 | * Closure for #vpn_allocation_cb. | ||
48 | */ | ||
49 | struct VpnContext | ||
50 | { | ||
51 | /** | ||
52 | * Which resolution process are we processing. | ||
53 | */ | ||
54 | struct Request *request; | ||
55 | |||
56 | /** | ||
57 | * Handle to the VPN request that we were performing. | ||
58 | */ | ||
59 | struct GNUNET_VPN_RedirectionRequest *vpn_request; | ||
60 | |||
61 | /** | ||
62 | * Number of records serialized in @e rd_data. | ||
63 | */ | ||
64 | unsigned int rd_count; | ||
65 | |||
66 | /** | ||
67 | * Serialized records. | ||
68 | */ | ||
69 | char *rd_data; | ||
70 | |||
71 | /** | ||
72 | * Number of bytes in @e rd_data. | ||
73 | */ | ||
74 | ssize_t rd_data_size; | ||
75 | }; | ||
76 | |||
77 | |||
78 | /** | ||
38 | * Data kept per request. | 79 | * Data kept per request. |
39 | */ | 80 | */ |
40 | struct Request | 81 | struct Request |
@@ -72,6 +113,11 @@ struct Request | |||
72 | struct GNUNET_SCHEDULER_Task *timeout_task; | 113 | struct GNUNET_SCHEDULER_Task *timeout_task; |
73 | 114 | ||
74 | /** | 115 | /** |
116 | * Vpn resulution context | ||
117 | */ | ||
118 | struct VpnContext *vpn_ctx; | ||
119 | |||
120 | /** | ||
75 | * Original UDP request message. | 121 | * Original UDP request message. |
76 | */ | 122 | */ |
77 | char *udp_msg; | 123 | char *udp_msg; |
@@ -90,6 +136,7 @@ struct Request | |||
90 | * ID of the original request. | 136 | * ID of the original request. |
91 | */ | 137 | */ |
92 | uint16_t original_request_id; | 138 | uint16_t original_request_id; |
139 | |||
93 | }; | 140 | }; |
94 | 141 | ||
95 | /** | 142 | /** |
@@ -109,6 +156,11 @@ static struct in6_addr address6; | |||
109 | struct GNUNET_GNS_Handle *gns; | 156 | struct GNUNET_GNS_Handle *gns; |
110 | 157 | ||
111 | /** | 158 | /** |
159 | * Our handle to the vpn service | ||
160 | */ | ||
161 | static struct GNUNET_VPN_Handle *vpn_handle; | ||
162 | |||
163 | /** | ||
112 | * Stub resolver | 164 | * Stub resolver |
113 | */ | 165 | */ |
114 | struct GNUNET_DNSSTUB_Context *dns_stub; | 166 | struct GNUNET_DNSSTUB_Context *dns_stub; |
@@ -183,6 +235,11 @@ do_shutdown (void *cls) | |||
183 | GNUNET_GNS_disconnect (gns); | 235 | GNUNET_GNS_disconnect (gns); |
184 | gns = NULL; | 236 | gns = NULL; |
185 | } | 237 | } |
238 | if (NULL != vpn_handle) | ||
239 | { | ||
240 | GNUNET_VPN_disconnect (vpn_handle); | ||
241 | vpn_handle = NULL; | ||
242 | } | ||
186 | if (NULL != dns_stub) | 243 | if (NULL != dns_stub) |
187 | { | 244 | { |
188 | GNUNET_DNSSTUB_stop (dns_stub); | 245 | GNUNET_DNSSTUB_stop (dns_stub); |
@@ -269,6 +326,7 @@ static void | |||
269 | do_timeout (void *cls) | 326 | do_timeout (void *cls) |
270 | { | 327 | { |
271 | struct Request *request = cls; | 328 | struct Request *request = cls; |
329 | struct VpnContext *vpn_ctx; | ||
272 | 330 | ||
273 | if (NULL != request->packet) | 331 | if (NULL != request->packet) |
274 | GNUNET_DNSPARSER_free_packet (request->packet); | 332 | GNUNET_DNSPARSER_free_packet (request->packet); |
@@ -277,6 +335,12 @@ do_timeout (void *cls) | |||
277 | if (NULL != request->dns_lookup) | 335 | if (NULL != request->dns_lookup) |
278 | GNUNET_DNSSTUB_resolve_cancel (request->dns_lookup); | 336 | GNUNET_DNSSTUB_resolve_cancel (request->dns_lookup); |
279 | GNUNET_free (request->udp_msg); | 337 | GNUNET_free (request->udp_msg); |
338 | if (NULL != (vpn_ctx = request->vpn_ctx)) | ||
339 | { | ||
340 | GNUNET_VPN_cancel_request (vpn_ctx->vpn_request); | ||
341 | GNUNET_free (vpn_ctx->rd_data); | ||
342 | GNUNET_free (vpn_ctx); | ||
343 | } | ||
280 | GNUNET_free (request); | 344 | GNUNET_free (request); |
281 | } | 345 | } |
282 | 346 | ||
@@ -321,6 +385,79 @@ dns_result_processor (void *cls, | |||
321 | send_response (request); | 385 | send_response (request); |
322 | } | 386 | } |
323 | 387 | ||
388 | /** | ||
389 | * Callback invoked from the VPN service once a redirection is | ||
390 | * available. Provides the IP address that can now be used to | ||
391 | * reach the requested destination. Replaces the "VPN" record | ||
392 | * with the respective A/AAAA record and continues processing. | ||
393 | * | ||
394 | * @param cls closure | ||
395 | * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error; | ||
396 | * will match 'result_af' from the request | ||
397 | * @param address IP address (struct in_addr or struct in_addr6, depending on 'af') | ||
398 | * that the VPN allocated for the redirection; | ||
399 | * traffic to this IP will now be redirected to the | ||
400 | * specified target peer; NULL on error | ||
401 | */ | ||
402 | static void | ||
403 | vpn_allocation_cb (void *cls, | ||
404 | int af, | ||
405 | const void *address) | ||
406 | { | ||
407 | struct VpnContext *vpn_ctx = cls; | ||
408 | struct Request *request = vpn_ctx->request; | ||
409 | struct GNUNET_GNSRECORD_Data rd[vpn_ctx->rd_count]; | ||
410 | unsigned int i; | ||
411 | |||
412 | vpn_ctx->vpn_request = NULL; | ||
413 | request->vpn_ctx = NULL; | ||
414 | GNUNET_assert (GNUNET_OK == | ||
415 | GNUNET_GNSRECORD_records_deserialize ( | ||
416 | (size_t) vpn_ctx->rd_data_size, | ||
417 | vpn_ctx->rd_data, | ||
418 | vpn_ctx->rd_count, | ||
419 | rd)); | ||
420 | for (i = 0; i < vpn_ctx->rd_count; i++) | ||
421 | { | ||
422 | if (GNUNET_GNSRECORD_TYPE_VPN == rd[i].record_type) | ||
423 | { | ||
424 | switch (af) | ||
425 | { | ||
426 | case AF_INET: | ||
427 | rd[i].record_type = GNUNET_DNSPARSER_TYPE_A; | ||
428 | rd[i].data_size = sizeof(struct in_addr); | ||
429 | rd[i].expiration_time = GNUNET_TIME_relative_to_absolute ( | ||
430 | VPN_TIMEOUT).abs_value_us; | ||
431 | rd[i].flags = 0; | ||
432 | rd[i].data = address; | ||
433 | break; | ||
434 | |||
435 | case AF_INET6: | ||
436 | rd[i].record_type = GNUNET_DNSPARSER_TYPE_AAAA; | ||
437 | rd[i].expiration_time = GNUNET_TIME_relative_to_absolute ( | ||
438 | VPN_TIMEOUT).abs_value_us; | ||
439 | rd[i].flags = 0; | ||
440 | rd[i].data = address; | ||
441 | rd[i].data_size = sizeof(struct in6_addr); | ||
442 | break; | ||
443 | |||
444 | default: | ||
445 | GNUNET_assert (0); | ||
446 | } | ||
447 | break; | ||
448 | } | ||
449 | } | ||
450 | GNUNET_assert (i < vpn_ctx->rd_count); | ||
451 | if (0 == vpn_ctx->rd_count) | ||
452 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
453 | _ ("VPN returned empty result for `%s'\n"), | ||
454 | request->packet->queries[0].name); | ||
455 | send_response (request); | ||
456 | GNUNET_free (vpn_ctx->rd_data); | ||
457 | GNUNET_free (vpn_ctx); | ||
458 | } | ||
459 | |||
460 | |||
324 | 461 | ||
325 | /** | 462 | /** |
326 | * Iterator called on obtained result for a GNS lookup. | 463 | * Iterator called on obtained result for a GNS lookup. |
@@ -339,6 +476,11 @@ result_processor (void *cls, | |||
339 | struct Request *request = cls; | 476 | struct Request *request = cls; |
340 | struct GNUNET_DNSPARSER_Packet *packet; | 477 | struct GNUNET_DNSPARSER_Packet *packet; |
341 | struct GNUNET_DNSPARSER_Record rec; | 478 | struct GNUNET_DNSPARSER_Record rec; |
479 | struct VpnContext *vpn_ctx; | ||
480 | const struct GNUNET_TUN_GnsVpnRecord *vpn; | ||
481 | const char *vname; | ||
482 | struct GNUNET_HashCode vhash; | ||
483 | int af; | ||
342 | 484 | ||
343 | request->lookup = NULL; | 485 | request->lookup = NULL; |
344 | if (GNUNET_NO == was_gns) | 486 | if (GNUNET_NO == was_gns) |
@@ -415,6 +557,67 @@ result_processor (void *cls, | |||
415 | packet->num_answers, | 557 | packet->num_answers, |
416 | rec); | 558 | rec); |
417 | break; | 559 | break; |
560 | case GNUNET_GNSRECORD_TYPE_VPN: | ||
561 | if ((GNUNET_DNSPARSER_TYPE_A != request->packet->queries[0].type) && | ||
562 | (GNUNET_DNSPARSER_TYPE_AAAA != request->packet->queries[0].type)) | ||
563 | break; | ||
564 | af = (GNUNET_DNSPARSER_TYPE_A == request->packet->queries[0].type) ? AF_INET : | ||
565 | AF_INET6; | ||
566 | if (sizeof(struct GNUNET_TUN_GnsVpnRecord) > | ||
567 | rd[i].data_size) | ||
568 | { | ||
569 | GNUNET_break_op (0); | ||
570 | break; | ||
571 | } | ||
572 | vpn = (const struct GNUNET_TUN_GnsVpnRecord *) rd[i].data; | ||
573 | vname = (const char *) &vpn[1]; | ||
574 | if ('\0' != vname[rd[i].data_size - 1 - sizeof(struct | ||
575 | GNUNET_TUN_GnsVpnRecord) | ||
576 | ]) | ||
577 | { | ||
578 | GNUNET_break_op (0); | ||
579 | break; | ||
580 | } | ||
581 | GNUNET_TUN_service_name_to_hash (vname, | ||
582 | &vhash); | ||
583 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
584 | "Attempting VPN allocation for %s-%s (AF: %d, proto %d)\n", | ||
585 | GNUNET_i2s (&vpn->peer), | ||
586 | vname, | ||
587 | (int) af, | ||
588 | (int) ntohs (vpn->proto)); | ||
589 | vpn_ctx = GNUNET_new (struct VpnContext); | ||
590 | request->vpn_ctx = vpn_ctx; | ||
591 | vpn_ctx->request = request; | ||
592 | vpn_ctx->rd_data_size = GNUNET_GNSRECORD_records_get_size (rd_count, | ||
593 | rd); | ||
594 | if (vpn_ctx->rd_data_size < 0) | ||
595 | { | ||
596 | GNUNET_break_op (0); | ||
597 | GNUNET_free (vpn_ctx); | ||
598 | break; | ||
599 | } | ||
600 | vpn_ctx->rd_data = GNUNET_malloc ((size_t) vpn_ctx->rd_data_size); | ||
601 | vpn_ctx->rd_count = rd_count; | ||
602 | GNUNET_assert (vpn_ctx->rd_data_size == | ||
603 | GNUNET_GNSRECORD_records_serialize (rd_count, | ||
604 | rd, | ||
605 | (size_t) vpn_ctx | ||
606 | ->rd_data_size, | ||
607 | vpn_ctx->rd_data)); | ||
608 | vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle, | ||
609 | af, | ||
610 | ntohs ( | ||
611 | vpn->proto), | ||
612 | &vpn->peer, | ||
613 | &vhash, | ||
614 | GNUNET_TIME_relative_to_absolute ( | ||
615 | VPN_TIMEOUT), | ||
616 | & | ||
617 | vpn_allocation_cb, | ||
618 | vpn_ctx); | ||
619 | return; | ||
620 | |||
418 | 621 | ||
419 | default: | 622 | default: |
420 | /* skip */ | 623 | /* skip */ |
@@ -641,6 +844,8 @@ run (void *cls, | |||
641 | NULL); | 844 | NULL); |
642 | if (NULL == (gns = GNUNET_GNS_connect (cfg))) | 845 | if (NULL == (gns = GNUNET_GNS_connect (cfg))) |
643 | return; | 846 | return; |
847 | if (NULL == (vpn_handle = GNUNET_VPN_connect (cfg))) | ||
848 | return; | ||
644 | GNUNET_assert (NULL != (dns_stub = GNUNET_DNSSTUB_start (128))); | 849 | GNUNET_assert (NULL != (dns_stub = GNUNET_DNSSTUB_start (128))); |
645 | if (GNUNET_OK != | 850 | if (GNUNET_OK != |
646 | GNUNET_DNSSTUB_add_dns_ip (dns_stub, | 851 | GNUNET_DNSSTUB_add_dns_ip (dns_stub, |
@@ -649,6 +854,8 @@ run (void *cls, | |||
649 | GNUNET_DNSSTUB_stop (dns_stub); | 854 | GNUNET_DNSSTUB_stop (dns_stub); |
650 | GNUNET_GNS_disconnect (gns); | 855 | GNUNET_GNS_disconnect (gns); |
651 | gns = NULL; | 856 | gns = NULL; |
857 | GNUNET_VPN_disconnect (vpn_handle); | ||
858 | vpn_handle = NULL; | ||
652 | return; | 859 | return; |
653 | } | 860 | } |
654 | 861 | ||
@@ -750,6 +957,8 @@ run (void *cls, | |||
750 | { | 957 | { |
751 | GNUNET_GNS_disconnect (gns); | 958 | GNUNET_GNS_disconnect (gns); |
752 | gns = NULL; | 959 | gns = NULL; |
960 | GNUNET_VPN_disconnect (vpn_handle); | ||
961 | vpn_handle = NULL; | ||
753 | GNUNET_DNSSTUB_stop (dns_stub); | 962 | GNUNET_DNSSTUB_stop (dns_stub); |
754 | dns_stub = NULL; | 963 | dns_stub = NULL; |
755 | return; | 964 | return; |
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 461257609..5573d072a 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -52,7 +52,6 @@ | |||
52 | #include "gns.h" | 52 | #include "gns.h" |
53 | #include "gnunet-service-gns.h" | 53 | #include "gnunet-service-gns.h" |
54 | #include "gnunet-service-gns_resolver.h" | 54 | #include "gnunet-service-gns_resolver.h" |
55 | #include "gnunet_vpn_service.h" | ||
56 | 55 | ||
57 | 56 | ||
58 | /** | 57 | /** |
@@ -68,11 +67,6 @@ | |||
68 | GNUNET_TIME_UNIT_SECONDS, 15) | 67 | GNUNET_TIME_UNIT_SECONDS, 15) |
69 | 68 | ||
70 | /** | 69 | /** |
71 | * Default timeout for VPN redirections. | ||
72 | */ | ||
73 | #define VPN_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) | ||
74 | |||
75 | /** | ||
76 | * DHT replication level | 70 | * DHT replication level |
77 | */ | 71 | */ |
78 | #define DHT_GNS_REPLICATION_LEVEL 10 | 72 | #define DHT_GNS_REPLICATION_LEVEL 10 |
@@ -255,38 +249,6 @@ struct DnsResult | |||
255 | 249 | ||
256 | 250 | ||
257 | /** | 251 | /** |
258 | * Closure for #vpn_allocation_cb. | ||
259 | */ | ||
260 | struct VpnContext | ||
261 | { | ||
262 | /** | ||
263 | * Which resolution process are we processing. | ||
264 | */ | ||
265 | struct GNS_ResolverHandle *rh; | ||
266 | |||
267 | /** | ||
268 | * Handle to the VPN request that we were performing. | ||
269 | */ | ||
270 | struct GNUNET_VPN_RedirectionRequest *vpn_request; | ||
271 | |||
272 | /** | ||
273 | * Number of records serialized in @e rd_data. | ||
274 | */ | ||
275 | unsigned int rd_count; | ||
276 | |||
277 | /** | ||
278 | * Serialized records. | ||
279 | */ | ||
280 | char *rd_data; | ||
281 | |||
282 | /** | ||
283 | * Number of bytes in @e rd_data. | ||
284 | */ | ||
285 | ssize_t rd_data_size; | ||
286 | }; | ||
287 | |||
288 | |||
289 | /** | ||
290 | * Handle to a currently pending resolution. On result (positive or | 252 | * Handle to a currently pending resolution. On result (positive or |
291 | * negative) the #GNS_ResultProcessor is called. | 253 | * negative) the #GNS_ResultProcessor is called. |
292 | */ | 254 | */ |
@@ -322,10 +284,6 @@ struct GNS_ResolverHandle | |||
322 | */ | 284 | */ |
323 | struct GNUNET_DHT_GetHandle *get_handle; | 285 | struct GNUNET_DHT_GetHandle *get_handle; |
324 | 286 | ||
325 | /** | ||
326 | * Handle to a VPN request, NULL if none is active. | ||
327 | */ | ||
328 | struct VpnContext *vpn_ctx; | ||
329 | 287 | ||
330 | /** | 288 | /** |
331 | * Socket for a DNS request, NULL if none is active. | 289 | * Socket for a DNS request, NULL if none is active. |
@@ -463,11 +421,6 @@ struct CacheOps | |||
463 | static struct GNUNET_NAMECACHE_Handle *namecache_handle; | 421 | static struct GNUNET_NAMECACHE_Handle *namecache_handle; |
464 | 422 | ||
465 | /** | 423 | /** |
466 | * Our handle to the vpn service | ||
467 | */ | ||
468 | static struct GNUNET_VPN_Handle *vpn_handle; | ||
469 | |||
470 | /** | ||
471 | * Resolver handle to the dht | 424 | * Resolver handle to the dht |
472 | */ | 425 | */ |
473 | static struct GNUNET_DHT_Handle *dht_handle; | 426 | static struct GNUNET_DHT_Handle *dht_handle; |
@@ -1425,80 +1378,6 @@ handle_gns_resolution_result (void *cls, | |||
1425 | const struct GNUNET_GNSRECORD_Data *rd); | 1378 | const struct GNUNET_GNSRECORD_Data *rd); |
1426 | 1379 | ||
1427 | 1380 | ||
1428 | /** | ||
1429 | * Callback invoked from the VPN service once a redirection is | ||
1430 | * available. Provides the IP address that can now be used to | ||
1431 | * reach the requested destination. Replaces the "VPN" record | ||
1432 | * with the respective A/AAAA record and continues processing. | ||
1433 | * | ||
1434 | * @param cls closure | ||
1435 | * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error; | ||
1436 | * will match 'result_af' from the request | ||
1437 | * @param address IP address (struct in_addr or struct in_addr6, depending on 'af') | ||
1438 | * that the VPN allocated for the redirection; | ||
1439 | * traffic to this IP will now be redirected to the | ||
1440 | * specified target peer; NULL on error | ||
1441 | */ | ||
1442 | static void | ||
1443 | vpn_allocation_cb (void *cls, | ||
1444 | int af, | ||
1445 | const void *address) | ||
1446 | { | ||
1447 | struct VpnContext *vpn_ctx = cls; | ||
1448 | struct GNS_ResolverHandle *rh = vpn_ctx->rh; | ||
1449 | struct GNUNET_GNSRECORD_Data rd[vpn_ctx->rd_count]; | ||
1450 | unsigned int i; | ||
1451 | |||
1452 | vpn_ctx->vpn_request = NULL; | ||
1453 | rh->vpn_ctx = NULL; | ||
1454 | GNUNET_assert (GNUNET_OK == | ||
1455 | GNUNET_GNSRECORD_records_deserialize ( | ||
1456 | (size_t) vpn_ctx->rd_data_size, | ||
1457 | vpn_ctx->rd_data, | ||
1458 | vpn_ctx->rd_count, | ||
1459 | rd)); | ||
1460 | for (i = 0; i < vpn_ctx->rd_count; i++) | ||
1461 | { | ||
1462 | if (GNUNET_GNSRECORD_TYPE_VPN == rd[i].record_type) | ||
1463 | { | ||
1464 | switch (af) | ||
1465 | { | ||
1466 | case AF_INET: | ||
1467 | rd[i].record_type = GNUNET_DNSPARSER_TYPE_A; | ||
1468 | rd[i].data_size = sizeof(struct in_addr); | ||
1469 | rd[i].expiration_time = GNUNET_TIME_relative_to_absolute ( | ||
1470 | VPN_TIMEOUT).abs_value_us; | ||
1471 | rd[i].flags = 0; | ||
1472 | rd[i].data = address; | ||
1473 | break; | ||
1474 | |||
1475 | case AF_INET6: | ||
1476 | rd[i].record_type = GNUNET_DNSPARSER_TYPE_AAAA; | ||
1477 | rd[i].expiration_time = GNUNET_TIME_relative_to_absolute ( | ||
1478 | VPN_TIMEOUT).abs_value_us; | ||
1479 | rd[i].flags = 0; | ||
1480 | rd[i].data = address; | ||
1481 | rd[i].data_size = sizeof(struct in6_addr); | ||
1482 | break; | ||
1483 | |||
1484 | default: | ||
1485 | GNUNET_assert (0); | ||
1486 | } | ||
1487 | break; | ||
1488 | } | ||
1489 | } | ||
1490 | GNUNET_assert (i < vpn_ctx->rd_count); | ||
1491 | if (0 == vpn_ctx->rd_count) | ||
1492 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1493 | _ ("VPN returned empty result for `%s'\n"), | ||
1494 | rh->name); | ||
1495 | handle_gns_resolution_result (rh, | ||
1496 | vpn_ctx->rd_count, | ||
1497 | rd); | ||
1498 | GNUNET_free (vpn_ctx->rd_data); | ||
1499 | GNUNET_free (vpn_ctx); | ||
1500 | } | ||
1501 | |||
1502 | 1381 | ||
1503 | /** | 1382 | /** |
1504 | * We have resolved one or more of the nameservers for a | 1383 | * We have resolved one or more of the nameservers for a |
@@ -2016,10 +1895,6 @@ handle_gns_resolution_result (void *cls, | |||
2016 | { | 1895 | { |
2017 | struct GNS_ResolverHandle *rh = cls; | 1896 | struct GNS_ResolverHandle *rh = cls; |
2018 | char *cname; | 1897 | char *cname; |
2019 | struct VpnContext *vpn_ctx; | ||
2020 | const struct GNUNET_TUN_GnsVpnRecord *vpn; | ||
2021 | const char *vname; | ||
2022 | struct GNUNET_HashCode vhash; | ||
2023 | int af; | 1898 | int af; |
2024 | char scratch[UINT16_MAX]; | 1899 | char scratch[UINT16_MAX]; |
2025 | size_t scratch_off; | 1900 | size_t scratch_off; |
@@ -2076,8 +1951,8 @@ handle_gns_resolution_result (void *cls, | |||
2076 | } | 1951 | } |
2077 | 1952 | ||
2078 | 1953 | ||
2079 | /* If A/AAAA was requested, but we got a VPN | 1954 | /* If A/AAAA was requested, |
2080 | record, we convert it to A/AAAA using GNUnet VPN */ | 1955 | * but we got a GNS2DNS record */ |
2081 | if ((GNUNET_DNSPARSER_TYPE_A == rh->record_type) || | 1956 | if ((GNUNET_DNSPARSER_TYPE_A == rh->record_type) || |
2082 | (GNUNET_DNSPARSER_TYPE_AAAA == rh->record_type)) | 1957 | (GNUNET_DNSPARSER_TYPE_AAAA == rh->record_type)) |
2083 | { | 1958 | { |
@@ -2085,69 +1960,6 @@ handle_gns_resolution_result (void *cls, | |||
2085 | { | 1960 | { |
2086 | switch (rd[i].record_type) | 1961 | switch (rd[i].record_type) |
2087 | { | 1962 | { |
2088 | case GNUNET_GNSRECORD_TYPE_VPN: | ||
2089 | { | ||
2090 | af = (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ? AF_INET : | ||
2091 | AF_INET6; | ||
2092 | if (sizeof(struct GNUNET_TUN_GnsVpnRecord) > | ||
2093 | rd[i].data_size) | ||
2094 | { | ||
2095 | GNUNET_break_op (0); | ||
2096 | fail_resolution (rh); | ||
2097 | return; | ||
2098 | } | ||
2099 | vpn = (const struct GNUNET_TUN_GnsVpnRecord *) rd[i].data; | ||
2100 | vname = (const char *) &vpn[1]; | ||
2101 | if ('\0' != vname[rd[i].data_size - 1 - sizeof(struct | ||
2102 | GNUNET_TUN_GnsVpnRecord) | ||
2103 | ]) | ||
2104 | { | ||
2105 | GNUNET_break_op (0); | ||
2106 | fail_resolution (rh); | ||
2107 | return; | ||
2108 | } | ||
2109 | GNUNET_TUN_service_name_to_hash (vname, | ||
2110 | &vhash); | ||
2111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2112 | "Attempting VPN allocation for %s-%s (AF: %d, proto %d)\n", | ||
2113 | GNUNET_i2s (&vpn->peer), | ||
2114 | vname, | ||
2115 | (int) af, | ||
2116 | (int) ntohs (vpn->proto)); | ||
2117 | vpn_ctx = GNUNET_new (struct VpnContext); | ||
2118 | rh->vpn_ctx = vpn_ctx; | ||
2119 | vpn_ctx->rh = rh; | ||
2120 | vpn_ctx->rd_data_size = GNUNET_GNSRECORD_records_get_size (rd_count, | ||
2121 | rd); | ||
2122 | if (vpn_ctx->rd_data_size < 0) | ||
2123 | { | ||
2124 | GNUNET_break_op (0); | ||
2125 | GNUNET_free (vpn_ctx); | ||
2126 | fail_resolution (rh); | ||
2127 | return; | ||
2128 | } | ||
2129 | vpn_ctx->rd_data = GNUNET_malloc ((size_t) vpn_ctx->rd_data_size); | ||
2130 | vpn_ctx->rd_count = rd_count; | ||
2131 | GNUNET_assert (vpn_ctx->rd_data_size == | ||
2132 | GNUNET_GNSRECORD_records_serialize (rd_count, | ||
2133 | rd, | ||
2134 | (size_t) vpn_ctx | ||
2135 | ->rd_data_size, | ||
2136 | vpn_ctx->rd_data)); | ||
2137 | vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle, | ||
2138 | af, | ||
2139 | ntohs ( | ||
2140 | vpn->proto), | ||
2141 | &vpn->peer, | ||
2142 | &vhash, | ||
2143 | GNUNET_TIME_relative_to_absolute ( | ||
2144 | VPN_TIMEOUT), | ||
2145 | & | ||
2146 | vpn_allocation_cb, | ||
2147 | vpn_ctx); | ||
2148 | return; | ||
2149 | } | ||
2150 | |||
2151 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: | 1963 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: |
2152 | { | 1964 | { |
2153 | /* delegation to DNS */ | 1965 | /* delegation to DNS */ |
@@ -3014,7 +2826,6 @@ GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh) | |||
3014 | { | 2826 | { |
3015 | struct DnsResult *dr; | 2827 | struct DnsResult *dr; |
3016 | struct AuthorityChain *ac; | 2828 | struct AuthorityChain *ac; |
3017 | struct VpnContext *vpn_ctx; | ||
3018 | 2829 | ||
3019 | GNUNET_CONTAINER_DLL_remove (rlh_head, | 2830 | GNUNET_CONTAINER_DLL_remove (rlh_head, |
3020 | rlh_tail, | 2831 | rlh_tail, |
@@ -3079,12 +2890,6 @@ GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh) | |||
3079 | GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node); | 2890 | GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node); |
3080 | rh->dht_heap_node = NULL; | 2891 | rh->dht_heap_node = NULL; |
3081 | } | 2892 | } |
3082 | if (NULL != (vpn_ctx = rh->vpn_ctx)) | ||
3083 | { | ||
3084 | GNUNET_VPN_cancel_request (vpn_ctx->vpn_request); | ||
3085 | GNUNET_free (vpn_ctx->rd_data); | ||
3086 | GNUNET_free (vpn_ctx); | ||
3087 | } | ||
3088 | if (NULL != rh->namecache_qe) | 2893 | if (NULL != rh->namecache_qe) |
3089 | { | 2894 | { |
3090 | GNUNET_NAMECACHE_cancel (rh->namecache_qe); | 2895 | GNUNET_NAMECACHE_cancel (rh->namecache_qe); |
@@ -3144,8 +2949,7 @@ GNS_resolver_init (struct GNUNET_NAMECACHE_Handle *nc, | |||
3144 | if (GNUNET_YES == disable_cache) | 2949 | if (GNUNET_YES == disable_cache) |
3145 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2950 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3146 | "Namecache disabled\n"); | 2951 | "Namecache disabled\n"); |
3147 | vpn_handle = GNUNET_VPN_connect (cfg); | 2952 | } |
3148 | } | ||
3149 | 2953 | ||
3150 | 2954 | ||
3151 | /** | 2955 | /** |
@@ -3175,8 +2979,6 @@ GNS_resolver_done () | |||
3175 | } | 2979 | } |
3176 | GNUNET_CONTAINER_heap_destroy (dht_lookup_heap); | 2980 | GNUNET_CONTAINER_heap_destroy (dht_lookup_heap); |
3177 | dht_lookup_heap = NULL; | 2981 | dht_lookup_heap = NULL; |
3178 | GNUNET_VPN_disconnect (vpn_handle); | ||
3179 | vpn_handle = NULL; | ||
3180 | dht_handle = NULL; | 2982 | dht_handle = NULL; |
3181 | namecache_handle = NULL; | 2983 | namecache_handle = NULL; |
3182 | } | 2984 | } |