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 /src/gns/gnunet-service-gns_resolver.c | |
parent | afd2cb5db220ce528b6222340b31b8a1a365c8e4 (diff) | |
download | gnunet-f3eaf5dae9a14fc62109b6e7c69571a068301fed.tar.gz gnunet-f3eaf5dae9a14fc62109b6e7c69571a068301fed.zip |
GNS: Move VPN to DNS2GNS. Fixes #7171
Diffstat (limited to 'src/gns/gnunet-service-gns_resolver.c')
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 204 |
1 files changed, 3 insertions, 201 deletions
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 | } |