diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-16 16:04:05 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-16 16:04:05 +0000 |
commit | fe14caa055450c56088cfde9e5f008a104175319 (patch) | |
tree | 89314674d77c69fa79829f89b90cfd4e87e3008e | |
parent | 7aa0a04c5c10da835e6e857f71c5d418f9facc47 (diff) | |
download | gnunet-fe14caa055450c56088cfde9e5f008a104175319.tar.gz gnunet-fe14caa055450c56088cfde9e5f008a104175319.zip |
-NS delegation WIP
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 167 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.h | 14 |
2 files changed, 178 insertions, 3 deletions
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 6e20c3f9c..bbdf90194 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -1293,6 +1293,129 @@ handle_record_vpn (void* cls, struct ResolverHandle *rh, | |||
1293 | 1293 | ||
1294 | /** | 1294 | /** |
1295 | * The final phase of resoution. | 1295 | * The final phase of resoution. |
1296 | * We found a NS RR and want to resolve via DNS | ||
1297 | * | ||
1298 | * @param rh the pending lookup handle | ||
1299 | * @param rd_count length of record data | ||
1300 | * @param rd record data containing VPN RR | ||
1301 | */ | ||
1302 | static void | ||
1303 | resolve_record_dns (struct ResolverHandle *rh, | ||
1304 | int rd_count, | ||
1305 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
1306 | { | ||
1307 | struct GNUNET_DNSPARSER_Query query; | ||
1308 | struct GNUNET_DNSPARSER_Packet packet; | ||
1309 | struct GNUNET_DNSPARSER_Flags flags; | ||
1310 | char dns_name[MAX_DNS_NAME_LENGTH]; | ||
1311 | struct in_addr dnsip; | ||
1312 | struct sockaddr_in addr; | ||
1313 | struct sockaddr *sa; | ||
1314 | int i; | ||
1315 | struct RecordLookupHandle *rlh = rh->proc_cls; | ||
1316 | size_t packet_size; | ||
1317 | |||
1318 | /* We cancel here as to not include the ns lookup in the timeout */ | ||
1319 | if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
1320 | { | ||
1321 | GNUNET_SCHEDULER_cancel(rh->timeout_task); | ||
1322 | rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
1323 | } | ||
1324 | /* Start shortening */ | ||
1325 | if ((rh->priv_key != NULL) && is_canonical (rh->name)) | ||
1326 | { | ||
1327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1328 | "GNS_PHASE_REC_DNS-%llu: Trying to shorten authority chain\n", | ||
1329 | rh->id); | ||
1330 | start_shorten (rh->authority_chain_tail, | ||
1331 | rh->priv_key); | ||
1332 | } | ||
1333 | |||
1334 | for (i = 0; i < rd_count; i++) | ||
1335 | { | ||
1336 | /* Synthesize dns name */ | ||
1337 | if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_NS) | ||
1338 | sprintf (dns_name, "%s.%s", rh->name, (char*)rd[i].data); | ||
1339 | /* The glue */ | ||
1340 | if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_A) | ||
1341 | dnsip = *((struct in_addr*)rd[i].data); | ||
1342 | } | ||
1343 | |||
1344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1345 | "GNS_PHASE_REC_DNS-%llu: Looking up %s from %s\n", | ||
1346 | dns_name, | ||
1347 | inet_ntoa (dnsip)); | ||
1348 | rh->dns_ip = dnsip; | ||
1349 | rh->dns_sock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0); | ||
1350 | if (rh->dns_sock == NULL) | ||
1351 | { | ||
1352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1353 | "GNS_PHASE_REC_DNS-%llu: Error creating udp socket for dns!\n", | ||
1354 | rh->id); | ||
1355 | rh->proc(rh->proc_cls, rh, 0, NULL); | ||
1356 | return; | ||
1357 | } | ||
1358 | |||
1359 | memset (&addr, 0, sizeof (struct sockaddr_in)); | ||
1360 | sa = (struct sockaddr *) &addr; | ||
1361 | sa->sa_family = AF_INET; | ||
1362 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (rh->dns_sock, | ||
1363 | sa, | ||
1364 | sizeof (struct sockaddr_in))) | ||
1365 | { | ||
1366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1367 | "GNS_PHASE_REC_DNS-%llu: Error binding udp socket for dns!\n", | ||
1368 | rh->id); | ||
1369 | GNUNET_NETWORK_socket_close (rh->dns_sock); | ||
1370 | rh->proc(rh->proc_cls, rh, 0, NULL); | ||
1371 | return; | ||
1372 | } | ||
1373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1374 | "GNS_PHASE_REC_DNS-%llu: NOT IMPLEMENTED!\n", | ||
1375 | rh->id); | ||
1376 | GNUNET_NETWORK_socket_close (rh->dns_sock); | ||
1377 | rh->proc(rh->proc_cls, rh, 0, NULL); | ||
1378 | /*TODO create dnsparser query, serialize, sendto, handle reply*/ | ||
1379 | query.name = dns_name; | ||
1380 | query.type = rlh->record_type; | ||
1381 | query.class = GNUNET_DNSPARSER_CLASS_INTERNET; | ||
1382 | memset (&flags, 0, sizeof (flags)); | ||
1383 | flags.recursion_desired = 1; | ||
1384 | flags.checking_disabled = 1; | ||
1385 | packet.queries = &query; | ||
1386 | packet.answers = NULL; | ||
1387 | packet.authority_records = NULL; | ||
1388 | packet.num_queries = 1; | ||
1389 | packet.num_answers = 0; | ||
1390 | packet.num_authority_records = 0; | ||
1391 | packet.num_additional_records = 0; | ||
1392 | packet.flags = flags; | ||
1393 | packet.id = rh->id; | ||
1394 | if (GNUNET_OK != GNUNET_DNSPARSER_pack (&packet, | ||
1395 | UINT16_MAX, | ||
1396 | &rh->dns_raw_packet, | ||
1397 | &packet_size)) | ||
1398 | { | ||
1399 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1400 | "GNS_PHASE_REC_DNS-%llu: Creating raw dns packet!\n", | ||
1401 | rh->id); | ||
1402 | GNUNET_NETWORK_socket_close (rh->dns_sock); | ||
1403 | rh->proc(rh->proc_cls, rh, 0, NULL); | ||
1404 | return; | ||
1405 | } | ||
1406 | |||
1407 | |||
1408 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1409 | "GNS_PHASE_REC_DNS-%llu: NOT IMPLEMENTED!\n", | ||
1410 | rh->id); | ||
1411 | GNUNET_free (rh->dns_raw_packet); | ||
1412 | GNUNET_NETWORK_socket_close (rh->dns_sock); | ||
1413 | rh->proc(rh->proc_cls, rh, 0, NULL); | ||
1414 | } | ||
1415 | |||
1416 | |||
1417 | /** | ||
1418 | * The final phase of resoution. | ||
1296 | * We found a VPN RR and want to request an IPv4/6 address | 1419 | * We found a VPN RR and want to request an IPv4/6 address |
1297 | * | 1420 | * |
1298 | * @param rh the pending lookup handle | 1421 | * @param rh the pending lookup handle |
@@ -2141,7 +2264,7 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh, | |||
2141 | 2264 | ||
2142 | if (strcmp(rh->name, "") == 0) | 2265 | if (strcmp(rh->name, "") == 0) |
2143 | { | 2266 | { |
2144 | if ((rlh->record_type == GNUNET_GNS_RECORD_PKEY)) | 2267 | if (rlh->record_type == GNUNET_GNS_RECORD_PKEY) |
2145 | { | 2268 | { |
2146 | GNUNET_assert(rd_count == 1); | 2269 | GNUNET_assert(rd_count == 1); |
2147 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2270 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
@@ -2158,6 +2281,15 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh, | |||
2158 | 2281 | ||
2159 | if (rh->status & RSL_DELEGATE_VPN) | 2282 | if (rh->status & RSL_DELEGATE_VPN) |
2160 | { | 2283 | { |
2284 | if (rlh->record_type == GNUNET_GNS_RECORD_VPN) | ||
2285 | { | ||
2286 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2287 | "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried VPNRR in NS.\n", | ||
2288 | rh->id); | ||
2289 | finish_lookup(rh, rlh, rd_count, rd); | ||
2290 | free_resolver_handle(rh); | ||
2291 | return; | ||
2292 | } | ||
2161 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2293 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2162 | "GNS_PHASE_DELEGATE_NS-%llu: VPN delegation starting.\n", | 2294 | "GNS_PHASE_DELEGATE_NS-%llu: VPN delegation starting.\n", |
2163 | rh->id); | 2295 | rh->id); |
@@ -2165,6 +2297,24 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh, | |||
2165 | rh->proc = &handle_record_vpn; | 2297 | rh->proc = &handle_record_vpn; |
2166 | resolve_record_vpn (rh, rd_count, rd); | 2298 | resolve_record_vpn (rh, rd_count, rd); |
2167 | } | 2299 | } |
2300 | else if (rh->status & RSL_DELEGATE_NS) | ||
2301 | { | ||
2302 | if (rlh->record_type == GNUNET_GNS_RECORD_TYPE_NS) | ||
2303 | { | ||
2304 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2305 | "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried NSRR in NS.\n", | ||
2306 | rh->id); | ||
2307 | finish_lookup(rh, rlh, rd_count, rd); | ||
2308 | free_resolver_handle(rh); | ||
2309 | return; | ||
2310 | } | ||
2311 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2312 | "GNS_PHASE_DELEGATE_NS-%llu: VPN delegation starting.\n", | ||
2313 | rh->id); | ||
2314 | GNUNET_assert (NULL != rd); | ||
2315 | rh->proc = &handle_record_ns; | ||
2316 | resolve_record_dns (rh, rd_count, rd); | ||
2317 | } | ||
2168 | else | 2318 | else |
2169 | { | 2319 | { |
2170 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2320 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
@@ -2342,9 +2492,22 @@ process_delegation_result_ns(void* cls, | |||
2342 | "GNS_PHASE_DELEGATE_NS-%llu: VPNRR found.\n", | 2492 | "GNS_PHASE_DELEGATE_NS-%llu: VPNRR found.\n", |
2343 | rh->id); | 2493 | rh->id); |
2344 | rh->status |= RSL_DELEGATE_VPN; | 2494 | rh->status |= RSL_DELEGATE_VPN; |
2345 | rh->proc(rh->proc_cls, rh, rd_count, rd); | 2495 | rh->proc (rh->proc_cls, rh, rd_count, rd); |
2346 | return; | 2496 | return; |
2347 | } | 2497 | } |
2498 | |||
2499 | /** | ||
2500 | * Redirect via NS | ||
2501 | * FIXME make optional | ||
2502 | */ | ||
2503 | if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_NS) | ||
2504 | { | ||
2505 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2506 | "GNS_PHASE_DELEGATE_NS-%llu: NS found.\n", | ||
2507 | rh->id); | ||
2508 | rh->status |= RSL_DELEGATE_NS; | ||
2509 | rh->proc (rh->proc_cls, rh, rd_count, rd); | ||
2510 | } | ||
2348 | 2511 | ||
2349 | if (rd[i].record_type != GNUNET_GNS_RECORD_PKEY) | 2512 | if (rd[i].record_type != GNUNET_GNS_RECORD_PKEY) |
2350 | continue; | 2513 | continue; |
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index 8387e1166..a0ac2cb0b 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h | |||
@@ -88,13 +88,16 @@ typedef void (*ResolutionResultProcessor) (void *cls, | |||
88 | * RSL_RECORD_EXISTS: the name to lookup exists | 88 | * RSL_RECORD_EXISTS: the name to lookup exists |
89 | * RSL_RECORD_EXPIRED: the name in the record expired | 89 | * RSL_RECORD_EXPIRED: the name in the record expired |
90 | * RSL_TIMED_OUT: resolution timed out | 90 | * RSL_TIMED_OUT: resolution timed out |
91 | * RSL_DELEGATE_VPN: Found VPN delegation | ||
92 | * RSL_DELEGATE_NS: Found NS delegation | ||
91 | */ | 93 | */ |
92 | enum ResolutionStatus | 94 | enum ResolutionStatus |
93 | { | 95 | { |
94 | RSL_RECORD_EXISTS = 1, | 96 | RSL_RECORD_EXISTS = 1, |
95 | RSL_RECORD_EXPIRED = 2, | 97 | RSL_RECORD_EXPIRED = 2, |
96 | RSL_TIMED_OUT = 4, | 98 | RSL_TIMED_OUT = 4, |
97 | RSL_DELEGATE_VPN = 8 | 99 | RSL_DELEGATE_VPN = 8, |
100 | RSL_DELEGATE_NS = 16 | ||
98 | }; | 101 | }; |
99 | 102 | ||
100 | /** | 103 | /** |
@@ -133,6 +136,15 @@ struct ResolverHandle | |||
133 | /* a handle to a vpn request */ | 136 | /* a handle to a vpn request */ |
134 | struct GNUNET_VPN_RedirectionRequest *vpn_handle; | 137 | struct GNUNET_VPN_RedirectionRequest *vpn_handle; |
135 | 138 | ||
139 | /* a socket for a dns request */ | ||
140 | struct GNUNET_NETWORK_Handle *dns_sock; | ||
141 | |||
142 | /* the address of the DNS server FIXME not needed? */ | ||
143 | struct in_addr dns_ip; | ||
144 | |||
145 | /* pointer to raw dns query payload FIXME needs to be freed/NULL */ | ||
146 | char *dns_raw_packet; | ||
147 | |||
136 | /* timeout task for the lookup */ | 148 | /* timeout task for the lookup */ |
137 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; | 149 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; |
138 | 150 | ||