diff options
Diffstat (limited to 'src/gns/gnunet-service-gns_resolver.c')
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 337 |
1 files changed, 226 insertions, 111 deletions
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 533c0cada..ef191bbb3 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include "gnunet_tun_lib.h" | 37 | #include "gnunet_tun_lib.h" |
38 | #include "gnunet_gns_service.h" | 38 | #include "gnunet_gns_service.h" |
39 | #include "gns.h" | 39 | #include "gns.h" |
40 | #include "gnunet-service-gns.h" | ||
40 | #include "gnunet-service-gns_resolver.h" | 41 | #include "gnunet-service-gns_resolver.h" |
41 | #include "gnunet_vpn_service.h" | 42 | #include "gnunet_vpn_service.h" |
42 | 43 | ||
@@ -237,6 +238,10 @@ struct Gns2DnsContext | |||
237 | */ | 238 | */ |
238 | struct GNS_ResolverHandle *rh; | 239 | struct GNS_ResolverHandle *rh; |
239 | 240 | ||
241 | /** | ||
242 | * Handle for DNS resolution of the DNS nameserver. | ||
243 | */ | ||
244 | struct GNUNET_RESOLVER_RequestHandle *dns_rh; | ||
240 | }; | 245 | }; |
241 | 246 | ||
242 | 247 | ||
@@ -473,7 +478,7 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
473 | * even though they consist of multiple labels. | 478 | * even though they consist of multiple labels. |
474 | * | 479 | * |
475 | * Examples: | 480 | * Examples: |
476 | * a.b.gnu = not canonical | 481 | * a.b.gnu = not canonical |
477 | * a = canonical | 482 | * a = canonical |
478 | * _foo._srv = canonical | 483 | * _foo._srv = canonical |
479 | * _f.bar = not canonical | 484 | * _f.bar = not canonical |
@@ -481,18 +486,20 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
481 | * @param name the name to test | 486 | * @param name the name to test |
482 | * @return #GNUNET_YES if canonical | 487 | * @return #GNUNET_YES if canonical |
483 | */ | 488 | */ |
484 | static int | 489 | /* dead, but keep for now */ int |
485 | is_canonical (const char *name) | 490 | is_canonical (const char *name) |
486 | { | 491 | { |
487 | const char *pos; | 492 | const char *pos; |
488 | const char *dot; | 493 | const char *dot; |
489 | 494 | ||
490 | if (NULL == strchr (name, '.')) | 495 | if (NULL == strchr (name, |
496 | (unsigned char) '.')) | ||
491 | return GNUNET_YES; | 497 | return GNUNET_YES; |
492 | if ('_' != name[0]) | 498 | if ('_' != name[0]) |
493 | return GNUNET_NO; | 499 | return GNUNET_NO; |
494 | pos = &name[1]; | 500 | pos = &name[1]; |
495 | while (NULL != (dot = strchr (pos, '.'))) | 501 | while (NULL != (dot = strchr (pos, |
502 | (unsigned char) '.'))) | ||
496 | if ('_' != dot[1]) | 503 | if ('_' != dot[1]) |
497 | return GNUNET_NO; | 504 | return GNUNET_NO; |
498 | else | 505 | else |
@@ -857,11 +864,31 @@ dns_result_parser (void *cls, | |||
857 | (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) && | 864 | (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) && |
858 | (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) ) | 865 | (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) ) |
859 | { | 866 | { |
867 | int af; | ||
868 | |||
860 | GNUNET_free (rh->name); | 869 | GNUNET_free (rh->name); |
861 | rh->name = GNUNET_strdup (p->answers[0].data.hostname); | 870 | rh->name = GNUNET_strdup (p->answers[0].data.hostname); |
862 | rh->name_resolution_pos = strlen (rh->name); | 871 | rh->name_resolution_pos = strlen (rh->name); |
863 | rh->task_id = GNUNET_SCHEDULER_add_now (&start_resolver_lookup, | 872 | switch (rh->record_type) |
864 | rh); | 873 | { |
874 | case GNUNET_DNSPARSER_TYPE_A: | ||
875 | af = AF_INET; | ||
876 | break; | ||
877 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
878 | af = AF_INET6; | ||
879 | break; | ||
880 | default: | ||
881 | af = AF_UNSPEC; | ||
882 | break; | ||
883 | } | ||
884 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
885 | "Doing standard DNS lookup for `%s'\n", | ||
886 | rh->name); | ||
887 | rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name, | ||
888 | af, | ||
889 | DNS_LOOKUP_TIMEOUT, | ||
890 | &handle_dns_result, | ||
891 | rh); | ||
865 | GNUNET_DNSPARSER_free_packet (p); | 892 | GNUNET_DNSPARSER_free_packet (p); |
866 | return; | 893 | return; |
867 | } | 894 | } |
@@ -944,9 +971,9 @@ dns_result_parser (void *cls, | |||
944 | buf_start = buf_off; | 971 | buf_start = buf_off; |
945 | if (GNUNET_OK != | 972 | if (GNUNET_OK != |
946 | GNUNET_DNSPARSER_builder_add_soa (buf, | 973 | GNUNET_DNSPARSER_builder_add_soa (buf, |
947 | sizeof (buf), | 974 | sizeof (buf), |
948 | &buf_off, | 975 | &buf_off, |
949 | rec->data.soa)) | 976 | rec->data.soa)) |
950 | { | 977 | { |
951 | GNUNET_break (0); | 978 | GNUNET_break (0); |
952 | skip++; | 979 | skip++; |
@@ -997,7 +1024,9 @@ dns_result_parser (void *cls, | |||
997 | "Returning DNS response for `%s' with %u answers\n", | 1024 | "Returning DNS response for `%s' with %u answers\n", |
998 | rh->ac_tail->label, | 1025 | rh->ac_tail->label, |
999 | (unsigned int) p->num_answers); | 1026 | (unsigned int) p->num_answers); |
1000 | rh->proc (rh->proc_cls, rd_count - skip, rd); | 1027 | rh->proc (rh->proc_cls, |
1028 | rd_count - skip, | ||
1029 | rd); | ||
1001 | GNS_resolver_lookup_cancel (rh); | 1030 | GNS_resolver_lookup_cancel (rh); |
1002 | } | 1031 | } |
1003 | GNUNET_DNSPARSER_free_packet (p); | 1032 | GNUNET_DNSPARSER_free_packet (p); |
@@ -1100,6 +1129,7 @@ handle_gns_cname_result (struct GNS_ResolverHandle *rh, | |||
1100 | size_t nlen; | 1129 | size_t nlen; |
1101 | char *res; | 1130 | char *res; |
1102 | struct AuthorityChain *ac; | 1131 | struct AuthorityChain *ac; |
1132 | int af; | ||
1103 | 1133 | ||
1104 | nlen = strlen (cname); | 1134 | nlen = strlen (cname); |
1105 | if ( (nlen > 2) && | 1135 | if ( (nlen > 2) && |
@@ -1139,12 +1169,30 @@ handle_gns_cname_result (struct GNS_ResolverHandle *rh, | |||
1139 | rh); | 1169 | rh); |
1140 | return; | 1170 | return; |
1141 | } | 1171 | } |
1142 | /* name is absolute, start from the beginning */ | 1172 | /* name is absolute, go to DNS */ |
1143 | GNUNET_free (rh->name); | 1173 | GNUNET_free (rh->name); |
1144 | rh->name = GNUNET_strdup (cname); | 1174 | rh->name = GNUNET_strdup (cname); |
1145 | rh->name_resolution_pos = strlen (rh->name); | 1175 | rh->name_resolution_pos = strlen (rh->name); |
1146 | rh->task_id = GNUNET_SCHEDULER_add_now (&start_resolver_lookup, | 1176 | switch (rh->record_type) |
1147 | rh); | 1177 | { |
1178 | case GNUNET_DNSPARSER_TYPE_A: | ||
1179 | af = AF_INET; | ||
1180 | break; | ||
1181 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
1182 | af = AF_INET6; | ||
1183 | break; | ||
1184 | default: | ||
1185 | af = AF_UNSPEC; | ||
1186 | break; | ||
1187 | } | ||
1188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1189 | "Doing standard DNS lookup for `%s'\n", | ||
1190 | rh->name); | ||
1191 | rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name, | ||
1192 | af, | ||
1193 | DNS_LOOKUP_TIMEOUT, | ||
1194 | &handle_dns_result, | ||
1195 | rh); | ||
1148 | } | 1196 | } |
1149 | 1197 | ||
1150 | 1198 | ||
@@ -1247,7 +1295,6 @@ handle_gns2dns_result (void *cls, | |||
1247 | { | 1295 | { |
1248 | struct GNS_ResolverHandle *rh = cls; | 1296 | struct GNS_ResolverHandle *rh = cls; |
1249 | struct AuthorityChain *ac; | 1297 | struct AuthorityChain *ac; |
1250 | unsigned int j; | ||
1251 | struct sockaddr *sa; | 1298 | struct sockaddr *sa; |
1252 | struct sockaddr_in v4; | 1299 | struct sockaddr_in v4; |
1253 | struct sockaddr_in6 v6; | 1300 | struct sockaddr_in6 v6; |
@@ -1258,13 +1305,16 @@ handle_gns2dns_result (void *cls, | |||
1258 | "Received %u results for IP address of DNS server for GNS2DNS transition\n", | 1305 | "Received %u results for IP address of DNS server for GNS2DNS transition\n", |
1259 | rd_count); | 1306 | rd_count); |
1260 | /* enable cleanup of 'rh' handle that comes next... */ | 1307 | /* enable cleanup of 'rh' handle that comes next... */ |
1261 | GNUNET_CONTAINER_DLL_insert (rlh_head, | 1308 | if (NULL != rh->g2dc->rh) |
1262 | rlh_tail, | 1309 | { |
1263 | rh->g2dc->rh); | 1310 | GNUNET_CONTAINER_DLL_insert (rlh_head, |
1264 | rh->g2dc->rh = NULL; | 1311 | rlh_tail, |
1312 | rh->g2dc->rh); | ||
1313 | rh->g2dc->rh = NULL; | ||
1314 | } | ||
1265 | sa = NULL; | 1315 | sa = NULL; |
1266 | sa_len = 0; | 1316 | sa_len = 0; |
1267 | for (j=0;j<rd_count;j++) | 1317 | for (unsigned int j=0;j<rd_count;j++) |
1268 | { | 1318 | { |
1269 | switch (rd[j].record_type) | 1319 | switch (rd[j].record_type) |
1270 | { | 1320 | { |
@@ -1348,7 +1398,8 @@ handle_gns2dns_result (void *cls, | |||
1348 | rh->g2dc = NULL; | 1398 | rh->g2dc = NULL; |
1349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1399 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1350 | "Will continue resolution using DNS server `%s' to resolve `%s'\n", | 1400 | "Will continue resolution using DNS server `%s' to resolve `%s'\n", |
1351 | GNUNET_a2s (sa, sa_len), | 1401 | GNUNET_a2s (sa, |
1402 | sa_len), | ||
1352 | ac->label); | 1403 | ac->label); |
1353 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | 1404 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, |
1354 | rh->ac_tail, | 1405 | rh->ac_tail, |
@@ -1369,6 +1420,69 @@ handle_gns2dns_result (void *cls, | |||
1369 | 1420 | ||
1370 | 1421 | ||
1371 | /** | 1422 | /** |
1423 | * Function called by the resolver for each address obtained from DNS. | ||
1424 | * | ||
1425 | * @param cls closure, a `struct Gns2DnsContext *` | ||
1426 | * @param addr one of the addresses of the host, NULL for the last address | ||
1427 | * @param addrlen length of @a addr | ||
1428 | */ | ||
1429 | static void | ||
1430 | handle_gns2dns_ip (void *cls, | ||
1431 | const struct sockaddr *addr, | ||
1432 | socklen_t addrlen) | ||
1433 | { | ||
1434 | struct Gns2DnsContext *g2dc = cls; | ||
1435 | struct GNUNET_GNSRECORD_Data rd; | ||
1436 | |||
1437 | if (NULL == addr) | ||
1438 | { | ||
1439 | /* DNS resolution failed */ | ||
1440 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1441 | "Failed to use DNS to resolve name of DNS resolver\n"); | ||
1442 | g2dc->rh->g2dc = NULL; | ||
1443 | fail_resolution (g2dc->rh); | ||
1444 | GNUNET_free (g2dc); | ||
1445 | } | ||
1446 | switch (addr->sa_family) | ||
1447 | { | ||
1448 | case AF_INET: | ||
1449 | { | ||
1450 | const struct sockaddr_in *v4 = (const struct sockaddr_in *) addr; | ||
1451 | |||
1452 | GNUNET_assert (sizeof (*v4) == addrlen); | ||
1453 | rd.data = v4; | ||
1454 | rd.data_size = sizeof (*v4); | ||
1455 | rd.expiration_time = UINT64_MAX; | ||
1456 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | ||
1457 | rd.flags = 0; | ||
1458 | break; | ||
1459 | } | ||
1460 | case AF_INET6: | ||
1461 | { | ||
1462 | const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *) addr; | ||
1463 | |||
1464 | GNUNET_assert (sizeof (*v6) == addrlen); | ||
1465 | rd.data = v6; | ||
1466 | rd.data_size = sizeof (v6); | ||
1467 | rd.expiration_time = UINT64_MAX; | ||
1468 | rd.record_type = GNUNET_DNSPARSER_TYPE_AAAA; | ||
1469 | rd.flags = 0; | ||
1470 | break; | ||
1471 | } | ||
1472 | default: | ||
1473 | return; | ||
1474 | } | ||
1475 | GNUNET_RESOLVER_request_cancel (g2dc->dns_rh); | ||
1476 | g2dc->dns_rh = NULL; | ||
1477 | handle_gns2dns_result (g2dc->rh, | ||
1478 | 1, | ||
1479 | &rd); | ||
1480 | |||
1481 | } | ||
1482 | |||
1483 | |||
1484 | |||
1485 | /** | ||
1372 | * Process a records that were decrypted from a block. | 1486 | * Process a records that were decrypted from a block. |
1373 | * | 1487 | * |
1374 | * @param cls closure with the `struct GNS_ResolverHandle` | 1488 | * @param cls closure with the `struct GNS_ResolverHandle` |
@@ -1513,7 +1627,7 @@ handle_gns_resolution_result (void *cls, | |||
1513 | rd_new[rd_off] = rd[i]; | 1627 | rd_new[rd_off] = rd[i]; |
1514 | /* Check if the embedded name(s) end in "+", and if so, | 1628 | /* Check if the embedded name(s) end in "+", and if so, |
1515 | replace the "+" with the zone at "ac_tail", changing the name | 1629 | replace the "+" with the zone at "ac_tail", changing the name |
1516 | to a ".zkey". The name is allocated on the 'scratch' array, | 1630 | to a ".ZONEKEY". The name is allocated on the 'scratch' array, |
1517 | so we can free it afterwards. */ | 1631 | so we can free it afterwards. */ |
1518 | switch (rd[i].record_type) | 1632 | switch (rd[i].record_type) |
1519 | { | 1633 | { |
@@ -1760,7 +1874,9 @@ handle_gns_resolution_result (void *cls, | |||
1760 | "Returning GNS response for `%s' with %u answers\n", | 1874 | "Returning GNS response for `%s' with %u answers\n", |
1761 | rh->ac_tail->label, | 1875 | rh->ac_tail->label, |
1762 | rd_off); | 1876 | rd_off); |
1763 | rh->proc (rh->proc_cls, rd_off, rd_new); | 1877 | rh->proc (rh->proc_cls, |
1878 | rd_off, | ||
1879 | rd_new); | ||
1764 | GNS_resolver_lookup_cancel (rh); | 1880 | GNS_resolver_lookup_cancel (rh); |
1765 | return; | 1881 | return; |
1766 | } | 1882 | } |
@@ -1804,6 +1920,10 @@ handle_gns_resolution_result (void *cls, | |||
1804 | struct Gns2DnsContext *g2dc; | 1920 | struct Gns2DnsContext *g2dc; |
1805 | char *ip; | 1921 | char *ip; |
1806 | char *ns; | 1922 | char *ns; |
1923 | const char *tld; | ||
1924 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; | ||
1925 | struct in_addr v4; | ||
1926 | struct in6_addr v6; | ||
1807 | 1927 | ||
1808 | off = 0; | 1928 | off = 0; |
1809 | ns = GNUNET_DNSPARSER_parse_name (rd[i].data, | 1929 | ns = GNUNET_DNSPARSER_parse_name (rd[i].data, |
@@ -1819,29 +1939,96 @@ handle_gns_resolution_result (void *cls, | |||
1819 | GNUNET_break_op (0); | 1939 | GNUNET_break_op (0); |
1820 | GNUNET_free_non_null (ns); | 1940 | GNUNET_free_non_null (ns); |
1821 | GNUNET_free_non_null (ip); | 1941 | GNUNET_free_non_null (ip); |
1822 | rh->proc (rh->proc_cls, 0, NULL); | 1942 | fail_resolution (rh); |
1823 | GNS_resolver_lookup_cancel (rh); | ||
1824 | return; | 1943 | return; |
1825 | } | 1944 | } |
1826 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1827 | "Resolving `%s' to determine IP address of DNS server for GNS2DNS transition\n", | ||
1828 | ip); | ||
1829 | /* resolve 'ip' to determine the IP(s) of the DNS | 1945 | /* resolve 'ip' to determine the IP(s) of the DNS |
1830 | resolver to use */ | 1946 | resolver to use for lookup of 'ns' */ |
1831 | g2dc = GNUNET_new (struct Gns2DnsContext); | 1947 | g2dc = GNUNET_new (struct Gns2DnsContext); |
1832 | g2dc->ns = ns; | 1948 | g2dc->ns = ns; |
1949 | rh->g2dc = g2dc; | ||
1950 | |||
1951 | /* check if 'ip' is already an IPv4/IPv6 address */ | ||
1952 | if (1 == inet_pton (AF_INET, | ||
1953 | ip, | ||
1954 | &v4)) | ||
1955 | { | ||
1956 | /* name is IPv4 address, pretend it's an A record */ | ||
1957 | struct GNUNET_GNSRECORD_Data rd; | ||
1958 | |||
1959 | GNUNET_free (ip); | ||
1960 | rd.data = &v4; | ||
1961 | rd.data_size = sizeof (v4); | ||
1962 | rd.expiration_time = UINT64_MAX; | ||
1963 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | ||
1964 | rd.flags = 0; | ||
1965 | handle_gns2dns_result (rh, | ||
1966 | 1, | ||
1967 | &rd); | ||
1968 | return; | ||
1969 | } | ||
1970 | if (1 == inet_pton (AF_INET6, | ||
1971 | ip, | ||
1972 | &v6)) | ||
1973 | { | ||
1974 | /* name is IPv6 address, pretend it's an AAAA record */ | ||
1975 | struct GNUNET_GNSRECORD_Data rd; | ||
1976 | |||
1977 | GNUNET_free (ip); | ||
1978 | rd.data = &v6; | ||
1979 | rd.data_size = sizeof (v6); | ||
1980 | rd.expiration_time = UINT64_MAX; | ||
1981 | rd.record_type = GNUNET_DNSPARSER_TYPE_AAAA; | ||
1982 | rd.flags = 0; | ||
1983 | handle_gns2dns_result (rh, | ||
1984 | 1, | ||
1985 | &rd); | ||
1986 | return; | ||
1987 | } | ||
1833 | 1988 | ||
1989 | tld = GNS_get_tld (ip); | ||
1990 | if (0 != strcmp (tld, | ||
1991 | "+")) | ||
1992 | { | ||
1993 | /* 'ip' is a DNS name */ | ||
1994 | g2dc->dns_rh = GNUNET_RESOLVER_ip_get (ip, | ||
1995 | AF_UNSPEC, | ||
1996 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1997 | &handle_gns2dns_ip, | ||
1998 | g2dc); | ||
1999 | GNUNET_free (ip); | ||
2000 | return; | ||
2001 | } | ||
2002 | |||
2003 | /* 'ip' should be a GNS name */ | ||
1834 | g2dc->rh = GNUNET_new (struct GNS_ResolverHandle); | 2004 | g2dc->rh = GNUNET_new (struct GNS_ResolverHandle); |
1835 | g2dc->rh->authority_zone = rh->ac_tail->authority_info.gns_authority; | 2005 | |
1836 | ip = translate_dot_plus (rh, ip); | 2006 | ip = translate_dot_plus (rh, |
2007 | ip); | ||
2008 | tld = GNS_get_tld (ip); | ||
2009 | if (GNUNET_OK != | ||
2010 | GNUNET_GNSRECORD_zkey_to_pkey (tld, | ||
2011 | &zone)) | ||
2012 | { | ||
2013 | GNUNET_break_op (0); | ||
2014 | GNUNET_free_non_null (ns); | ||
2015 | GNUNET_free_non_null (ip); | ||
2016 | GNUNET_free (g2dc); | ||
2017 | fail_resolution (rh); | ||
2018 | return; | ||
2019 | } | ||
2020 | g2dc->rh->authority_zone = zone; | ||
2021 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2022 | "Resolving `%s' to determine IP address of DNS server for GNS2DNS transition for `%s'\n", | ||
2023 | ip, | ||
2024 | ns); | ||
1837 | g2dc->rh->name = ip; | 2025 | g2dc->rh->name = ip; |
1838 | g2dc->rh->name_resolution_pos = strlen (ip); | 2026 | g2dc->rh->name_resolution_pos = strlen (ip) - strlen (tld) - 1; |
1839 | g2dc->rh->proc = &handle_gns2dns_result; | 2027 | g2dc->rh->proc = &handle_gns2dns_result; |
1840 | g2dc->rh->proc_cls = rh; | 2028 | g2dc->rh->proc_cls = rh; |
1841 | g2dc->rh->record_type = GNUNET_GNSRECORD_TYPE_ANY; | 2029 | g2dc->rh->record_type = GNUNET_GNSRECORD_TYPE_ANY; |
1842 | g2dc->rh->options = GNUNET_GNS_LO_DEFAULT; | 2030 | g2dc->rh->options = GNUNET_GNS_LO_DEFAULT; |
1843 | g2dc->rh->loop_limiter = rh->loop_limiter + 1; | 2031 | g2dc->rh->loop_limiter = rh->loop_limiter + 1; |
1844 | rh->g2dc = g2dc; | ||
1845 | g2dc->rh->task_id | 2032 | g2dc->rh->task_id |
1846 | = GNUNET_SCHEDULER_add_now (&start_resolver_lookup, | 2033 | = GNUNET_SCHEDULER_add_now (&start_resolver_lookup, |
1847 | g2dc->rh); | 2034 | g2dc->rh); |
@@ -2259,7 +2446,6 @@ start_resolver_lookup (void *cls) | |||
2259 | { | 2446 | { |
2260 | struct GNS_ResolverHandle *rh = cls; | 2447 | struct GNS_ResolverHandle *rh = cls; |
2261 | struct AuthorityChain *ac; | 2448 | struct AuthorityChain *ac; |
2262 | char *y; | ||
2263 | struct in_addr v4; | 2449 | struct in_addr v4; |
2264 | struct in6_addr v6; | 2450 | struct in6_addr v6; |
2265 | 2451 | ||
@@ -2296,66 +2482,14 @@ start_resolver_lookup (void *cls) | |||
2296 | GNS_resolver_lookup_cancel (rh); | 2482 | GNS_resolver_lookup_cancel (rh); |
2297 | return; | 2483 | return; |
2298 | } | 2484 | } |
2299 | if ( ( (GNUNET_YES == is_canonical (rh->name)) && | ||
2300 | (0 != strcmp (GNUNET_GNS_TLD, rh->name)) ) || | ||
2301 | ( (GNUNET_YES != is_gnu_tld (rh->name)) && | ||
2302 | (GNUNET_YES != is_zkey_tld (rh->name)) ) ) | ||
2303 | { | ||
2304 | /* use standard DNS lookup */ | ||
2305 | int af; | ||
2306 | 2485 | ||
2307 | switch (rh->record_type) | ||
2308 | { | ||
2309 | case GNUNET_DNSPARSER_TYPE_A: | ||
2310 | af = AF_INET; | ||
2311 | break; | ||
2312 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
2313 | af = AF_INET6; | ||
2314 | break; | ||
2315 | default: | ||
2316 | af = AF_UNSPEC; | ||
2317 | break; | ||
2318 | } | ||
2319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2320 | "Doing standard DNS lookup for `%s'\n", | ||
2321 | rh->name); | ||
2322 | rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name, | ||
2323 | af, | ||
2324 | DNS_LOOKUP_TIMEOUT, | ||
2325 | &handle_dns_result, | ||
2326 | rh); | ||
2327 | return; | ||
2328 | } | ||
2329 | if (is_zkey_tld (rh->name)) | ||
2330 | { | ||
2331 | /* Name ends with ".zkey", try to replace authority zone with zkey | ||
2332 | authority */ | ||
2333 | GNUNET_free (resolver_lookup_get_next_label (rh)); /* will return "zkey" */ | ||
2334 | y = resolver_lookup_get_next_label (rh); /* will return 'y' coordinate */ | ||
2335 | if ( (NULL == y) || | ||
2336 | (GNUNET_OK != | ||
2337 | GNUNET_CRYPTO_ecdsa_public_key_from_string (y, | ||
2338 | strlen (y), | ||
2339 | &rh->authority_zone)) ) | ||
2340 | { | ||
2341 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2342 | _("Hostname `%s' is not well-formed, resolution fails\n"), | ||
2343 | rh->name); | ||
2344 | rh->task_id = GNUNET_SCHEDULER_add_now (&fail_resolution, rh); | ||
2345 | } | ||
2346 | GNUNET_free_non_null (y); | ||
2347 | } | ||
2348 | else | ||
2349 | { | ||
2350 | /* Name ends with ".gnu", eat ".gnu" and continue with resolution */ | ||
2351 | GNUNET_free (resolver_lookup_get_next_label (rh)); | ||
2352 | } | ||
2353 | ac = GNUNET_new (struct AuthorityChain); | 2486 | ac = GNUNET_new (struct AuthorityChain); |
2354 | ac->rh = rh; | 2487 | ac->rh = rh; |
2355 | ac->label = resolver_lookup_get_next_label (rh); | 2488 | ac->label = resolver_lookup_get_next_label (rh); |
2356 | ac->suggested_shortening_label = NULL; | 2489 | ac->suggested_shortening_label = NULL; |
2357 | if (NULL == ac->label) | 2490 | if (NULL == ac->label) |
2358 | /* name was just "gnu", so we default to label '+' */ | 2491 | /* name was just the "TLD", so we default to label |
2492 | #GNUNET_GNS_MASTERZONE_STR */ | ||
2359 | ac->label = GNUNET_strdup (GNUNET_GNS_MASTERZONE_STR); | 2493 | ac->label = GNUNET_strdup (GNUNET_GNS_MASTERZONE_STR); |
2360 | ac->gns_authority = GNUNET_YES; | 2494 | ac->gns_authority = GNUNET_YES; |
2361 | ac->authority_info.gns_authority = rh->authority_zone; | 2495 | ac->authority_info.gns_authority = rh->authority_zone; |
@@ -2446,6 +2580,11 @@ GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh) | |||
2446 | GNS_resolver_lookup_cancel (rh->g2dc->rh); | 2580 | GNS_resolver_lookup_cancel (rh->g2dc->rh); |
2447 | rh->g2dc->rh = NULL; | 2581 | rh->g2dc->rh = NULL; |
2448 | } | 2582 | } |
2583 | if (NULL != rh->g2dc->dns_rh) | ||
2584 | { | ||
2585 | GNUNET_RESOLVER_request_cancel (rh->g2dc->dns_rh); | ||
2586 | rh->g2dc->rh = NULL; | ||
2587 | } | ||
2449 | GNUNET_free (rh->g2dc->ns); | 2588 | GNUNET_free (rh->g2dc->ns); |
2450 | GNUNET_free (rh->g2dc); | 2589 | GNUNET_free (rh->g2dc); |
2451 | rh->g2dc = NULL; | 2590 | rh->g2dc = NULL; |
@@ -2588,28 +2727,4 @@ GNS_resolver_done () | |||
2588 | } | 2727 | } |
2589 | 2728 | ||
2590 | 2729 | ||
2591 | /* *************** common helper functions (do not really belong here) *********** */ | ||
2592 | |||
2593 | /** | ||
2594 | * Checks if @a name ends in ".TLD" | ||
2595 | * | ||
2596 | * @param name the name to check | ||
2597 | * @param tld the TLD to check for | ||
2598 | * @return #GNUNET_YES or #GNUNET_NO | ||
2599 | */ | ||
2600 | int | ||
2601 | is_tld (const char* name, | ||
2602 | const char* tld) | ||
2603 | { | ||
2604 | size_t offset = 0; | ||
2605 | |||
2606 | if (strlen (name) <= strlen (tld)) | ||
2607 | return GNUNET_NO; | ||
2608 | offset = strlen (name) - strlen (tld); | ||
2609 | if (0 != strcmp (name + offset, tld)) | ||
2610 | return GNUNET_NO; | ||
2611 | return GNUNET_YES; | ||
2612 | } | ||
2613 | |||
2614 | |||
2615 | /* end of gnunet-service-gns_resolver.c */ | 2730 | /* end of gnunet-service-gns_resolver.c */ |