diff options
Diffstat (limited to 'src/util/gnunet-service-resolver.c')
-rw-r--r-- | src/util/gnunet-service-resolver.c | 1243 |
1 files changed, 623 insertions, 620 deletions
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c index a69a7bd66..23ba39fee 100644 --- a/src/util/gnunet-service-resolver.c +++ b/src/util/gnunet-service-resolver.c | |||
@@ -33,7 +33,7 @@ | |||
33 | /** | 33 | /** |
34 | * How long do we wait for DNS answers? | 34 | * How long do we wait for DNS answers? |
35 | */ | 35 | */ |
36 | #define DNS_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) | 36 | #define DNS_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Maximum number of hostnames we cache results for. | 39 | * Maximum number of hostnames we cache results for. |
@@ -43,7 +43,8 @@ | |||
43 | /** | 43 | /** |
44 | * Entry in list of cached DNS records for a hostname. | 44 | * Entry in list of cached DNS records for a hostname. |
45 | */ | 45 | */ |
46 | struct RecordListEntry { | 46 | struct RecordListEntry |
47 | { | ||
47 | /** | 48 | /** |
48 | * This is a doubly linked list. | 49 | * This is a doubly linked list. |
49 | */ | 50 | */ |
@@ -64,7 +65,8 @@ struct RecordListEntry { | |||
64 | /** | 65 | /** |
65 | * A cached DNS lookup result. | 66 | * A cached DNS lookup result. |
66 | */ | 67 | */ |
67 | struct ResolveCache { | 68 | struct ResolveCache |
69 | { | ||
68 | /** | 70 | /** |
69 | * This is a doubly linked list. | 71 | * This is a doubly linked list. |
70 | */ | 72 | */ |
@@ -95,7 +97,8 @@ struct ResolveCache { | |||
95 | /** | 97 | /** |
96 | * Information about pending lookups. | 98 | * Information about pending lookups. |
97 | */ | 99 | */ |
98 | struct ActiveLookup { | 100 | struct ActiveLookup |
101 | { | ||
99 | /** | 102 | /** |
100 | * Stored in a DLL. | 103 | * Stored in a DLL. |
101 | */ | 104 | */ |
@@ -203,21 +206,21 @@ static unsigned int cache_size; | |||
203 | * @param rc entry to free | 206 | * @param rc entry to free |
204 | */ | 207 | */ |
205 | static void | 208 | static void |
206 | free_cache_entry(struct ResolveCache *rc) | 209 | free_cache_entry (struct ResolveCache *rc) |
207 | { | 210 | { |
208 | struct RecordListEntry *pos; | 211 | struct RecordListEntry *pos; |
209 | 212 | ||
210 | while (NULL != (pos = rc->records_head)) | 213 | while (NULL != (pos = rc->records_head)) |
211 | { | 214 | { |
212 | GNUNET_CONTAINER_DLL_remove(rc->records_head, rc->records_tail, pos); | 215 | GNUNET_CONTAINER_DLL_remove (rc->records_head, rc->records_tail, pos); |
213 | GNUNET_DNSPARSER_free_record(pos->record); | 216 | GNUNET_DNSPARSER_free_record (pos->record); |
214 | GNUNET_free(pos->record); | 217 | GNUNET_free (pos->record); |
215 | GNUNET_free(pos); | 218 | GNUNET_free (pos); |
216 | } | 219 | } |
217 | GNUNET_free_non_null(rc->hostname); | 220 | GNUNET_free_non_null (rc->hostname); |
218 | GNUNET_CONTAINER_DLL_remove(cache_head, cache_tail, rc); | 221 | GNUNET_CONTAINER_DLL_remove (cache_head, cache_tail, rc); |
219 | cache_size--; | 222 | cache_size--; |
220 | GNUNET_free(rc); | 223 | GNUNET_free (rc); |
221 | } | 224 | } |
222 | 225 | ||
223 | 226 | ||
@@ -227,21 +230,21 @@ free_cache_entry(struct ResolveCache *rc) | |||
227 | * @param rc entry to free | 230 | * @param rc entry to free |
228 | */ | 231 | */ |
229 | static void | 232 | static void |
230 | free_hosts_entry(struct ResolveCache *rc) | 233 | free_hosts_entry (struct ResolveCache *rc) |
231 | { | 234 | { |
232 | struct RecordListEntry *pos; | 235 | struct RecordListEntry *pos; |
233 | 236 | ||
234 | while (NULL != (pos = rc->records_head)) | 237 | while (NULL != (pos = rc->records_head)) |
235 | { | 238 | { |
236 | GNUNET_CONTAINER_DLL_remove(rc->records_head, rc->records_tail, pos); | 239 | GNUNET_CONTAINER_DLL_remove (rc->records_head, rc->records_tail, pos); |
237 | GNUNET_DNSPARSER_free_record(pos->record); | 240 | GNUNET_DNSPARSER_free_record (pos->record); |
238 | GNUNET_free(pos->record); | 241 | GNUNET_free (pos->record); |
239 | GNUNET_free(pos); | 242 | GNUNET_free (pos); |
240 | } | 243 | } |
241 | GNUNET_free_non_null(rc->hostname); | 244 | GNUNET_free_non_null (rc->hostname); |
242 | GNUNET_CONTAINER_DLL_remove(hosts_head, hosts_tail, rc); | 245 | GNUNET_CONTAINER_DLL_remove (hosts_head, hosts_tail, rc); |
243 | cache_size--; | 246 | cache_size--; |
244 | GNUNET_free(rc); | 247 | GNUNET_free (rc); |
245 | } | 248 | } |
246 | 249 | ||
247 | 250 | ||
@@ -251,21 +254,21 @@ free_hosts_entry(struct ResolveCache *rc) | |||
251 | * @param al an active lookup | 254 | * @param al an active lookup |
252 | */ | 255 | */ |
253 | static void | 256 | static void |
254 | free_active_lookup(struct ActiveLookup *al) | 257 | free_active_lookup (struct ActiveLookup *al) |
255 | { | 258 | { |
256 | GNUNET_CONTAINER_DLL_remove(lookup_head, lookup_tail, al); | 259 | GNUNET_CONTAINER_DLL_remove (lookup_head, lookup_tail, al); |
257 | if (NULL != al->resolve_handle) | 260 | if (NULL != al->resolve_handle) |
258 | { | 261 | { |
259 | GNUNET_DNSSTUB_resolve_cancel(al->resolve_handle); | 262 | GNUNET_DNSSTUB_resolve_cancel (al->resolve_handle); |
260 | al->resolve_handle = NULL; | 263 | al->resolve_handle = NULL; |
261 | } | 264 | } |
262 | if (NULL != al->timeout_task) | 265 | if (NULL != al->timeout_task) |
263 | { | 266 | { |
264 | GNUNET_SCHEDULER_cancel(al->timeout_task); | 267 | GNUNET_SCHEDULER_cancel (al->timeout_task); |
265 | al->timeout_task = NULL; | 268 | al->timeout_task = NULL; |
266 | } | 269 | } |
267 | GNUNET_free_non_null(al->hostname); | 270 | GNUNET_free_non_null (al->hostname); |
268 | GNUNET_free(al); | 271 | GNUNET_free (al); |
269 | } | 272 | } |
270 | 273 | ||
271 | 274 | ||
@@ -279,11 +282,11 @@ free_active_lookup(struct ActiveLookup *al) | |||
279 | * @return NULL if no nameserver is configured in this @a line | 282 | * @return NULL if no nameserver is configured in this @a line |
280 | */ | 283 | */ |
281 | static char * | 284 | static char * |
282 | extract_dns_server(const char *line, size_t line_len) | 285 | extract_dns_server (const char *line, size_t line_len) |
283 | { | 286 | { |
284 | if (0 == strncmp(line, "nameserver ", strlen("nameserver "))) | 287 | if (0 == strncmp (line, "nameserver ", strlen ("nameserver "))) |
285 | return GNUNET_strndup(line + strlen("nameserver "), | 288 | return GNUNET_strndup (line + strlen ("nameserver "), |
286 | line_len - strlen("nameserver ")); | 289 | line_len - strlen ("nameserver ")); |
287 | return NULL; | 290 | return NULL; |
288 | } | 291 | } |
289 | 292 | ||
@@ -298,11 +301,11 @@ extract_dns_server(const char *line, size_t line_len) | |||
298 | * @return NULL if no nameserver is configured in this @a line | 301 | * @return NULL if no nameserver is configured in this @a line |
299 | */ | 302 | */ |
300 | static char * | 303 | static char * |
301 | extract_search_domain(const char *line, size_t line_len) | 304 | extract_search_domain (const char *line, size_t line_len) |
302 | { | 305 | { |
303 | if (0 == strncmp(line, "search ", strlen("search "))) | 306 | if (0 == strncmp (line, "search ", strlen ("search "))) |
304 | return GNUNET_strndup(line + strlen("search "), | 307 | return GNUNET_strndup (line + strlen ("search "), |
305 | line_len - strlen("search ")); | 308 | line_len - strlen ("search ")); |
306 | return NULL; | 309 | return NULL; |
307 | } | 310 | } |
308 | 311 | ||
@@ -314,7 +317,7 @@ extract_search_domain(const char *line, size_t line_len) | |||
314 | * @return the number of server addresses in @server_addrs, -1 on error | 317 | * @return the number of server addresses in @server_addrs, -1 on error |
315 | */ | 318 | */ |
316 | static int | 319 | static int |
317 | lookup_dns_servers(char ***server_addrs) | 320 | lookup_dns_servers (char ***server_addrs) |
318 | { | 321 | { |
319 | struct GNUNET_DISK_FileHandle *fh; | 322 | struct GNUNET_DISK_FileHandle *fh; |
320 | struct GNUNET_DISK_MapHandle *mh; | 323 | struct GNUNET_DISK_MapHandle *mh; |
@@ -323,63 +326,63 @@ lookup_dns_servers(char ***server_addrs) | |||
323 | size_t read_offset; | 326 | size_t read_offset; |
324 | unsigned int num_dns_servers; | 327 | unsigned int num_dns_servers; |
325 | 328 | ||
326 | fh = GNUNET_DISK_file_open("/etc/resolv.conf", | 329 | fh = GNUNET_DISK_file_open ("/etc/resolv.conf", |
327 | GNUNET_DISK_OPEN_READ, | 330 | GNUNET_DISK_OPEN_READ, |
328 | GNUNET_DISK_PERM_NONE); | 331 | GNUNET_DISK_PERM_NONE); |
329 | if (NULL == fh) | 332 | if (NULL == fh) |
330 | { | 333 | { |
331 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 334 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
332 | "Could not open /etc/resolv.conf. " | 335 | "Could not open /etc/resolv.conf. " |
333 | "DNS resolution will not be possible.\n"); | 336 | "DNS resolution will not be possible.\n"); |
334 | return -1; | 337 | return -1; |
335 | } | 338 | } |
336 | if (GNUNET_OK != GNUNET_DISK_file_handle_size(fh, &bytes_read)) | 339 | if (GNUNET_OK != GNUNET_DISK_file_handle_size (fh, &bytes_read)) |
337 | { | 340 | { |
338 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 341 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
339 | "Could not determine size of /etc/resolv.conf. " | 342 | "Could not determine size of /etc/resolv.conf. " |
340 | "DNS resolution will not be possible.\n"); | 343 | "DNS resolution will not be possible.\n"); |
341 | GNUNET_DISK_file_close(fh); | 344 | GNUNET_DISK_file_close (fh); |
342 | return -1; | 345 | return -1; |
343 | } | 346 | } |
344 | if (((unsigned long long)bytes_read) > (unsigned long long)SIZE_MAX) | 347 | if (((unsigned long long) bytes_read) > (unsigned long long) SIZE_MAX) |
345 | { | 348 | { |
346 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 349 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
347 | "/etc/resolv.conf file too large to mmap. " | 350 | "/etc/resolv.conf file too large to mmap. " |
348 | "DNS resolution will not be possible.\n"); | 351 | "DNS resolution will not be possible.\n"); |
349 | GNUNET_DISK_file_close(fh); | 352 | GNUNET_DISK_file_close (fh); |
350 | return -1; | 353 | return -1; |
351 | } | 354 | } |
352 | buf = GNUNET_DISK_file_map(fh, | 355 | buf = GNUNET_DISK_file_map (fh, |
353 | &mh, | 356 | &mh, |
354 | GNUNET_DISK_MAP_TYPE_READ, | 357 | GNUNET_DISK_MAP_TYPE_READ, |
355 | (size_t)bytes_read); | 358 | (size_t) bytes_read); |
356 | *server_addrs = NULL; | 359 | *server_addrs = NULL; |
357 | read_offset = 0; | 360 | read_offset = 0; |
358 | num_dns_servers = 0; | 361 | num_dns_servers = 0; |
359 | while (read_offset < (size_t)bytes_read) | 362 | while (read_offset < (size_t) bytes_read) |
363 | { | ||
364 | const char *newline; | ||
365 | size_t line_len; | ||
366 | char *dns_server; | ||
367 | |||
368 | newline = strchr (buf + read_offset, '\n'); | ||
369 | if (NULL == newline) | ||
370 | break; | ||
371 | line_len = newline - buf - read_offset; | ||
372 | dns_server = extract_dns_server (buf + read_offset, line_len); | ||
373 | if (NULL != dns_server) | ||
360 | { | 374 | { |
361 | const char *newline; | 375 | GNUNET_array_append (*server_addrs, num_dns_servers, dns_server); |
362 | size_t line_len; | ||
363 | char *dns_server; | ||
364 | |||
365 | newline = strchr(buf + read_offset, '\n'); | ||
366 | if (NULL == newline) | ||
367 | break; | ||
368 | line_len = newline - buf - read_offset; | ||
369 | dns_server = extract_dns_server(buf + read_offset, line_len); | ||
370 | if (NULL != dns_server) | ||
371 | { | ||
372 | GNUNET_array_append(*server_addrs, num_dns_servers, dns_server); | ||
373 | } | ||
374 | else if (NULL == my_domain) | ||
375 | { | ||
376 | my_domain = extract_search_domain(buf + read_offset, line_len); | ||
377 | } | ||
378 | read_offset += line_len + 1; | ||
379 | } | 376 | } |
380 | GNUNET_DISK_file_unmap(mh); | 377 | else if (NULL == my_domain) |
381 | GNUNET_DISK_file_close(fh); | 378 | { |
382 | return (int)num_dns_servers; | 379 | my_domain = extract_search_domain (buf + read_offset, line_len); |
380 | } | ||
381 | read_offset += line_len + 1; | ||
382 | } | ||
383 | GNUNET_DISK_file_unmap (mh); | ||
384 | GNUNET_DISK_file_close (fh); | ||
385 | return (int) num_dns_servers; | ||
383 | } | 386 | } |
384 | 387 | ||
385 | 388 | ||
@@ -390,52 +393,52 @@ lookup_dns_servers(char ***server_addrs) | |||
390 | * @param af address family of @a ip, AF_INET or AF_INET6 | 393 | * @param af address family of @a ip, AF_INET or AF_INET6 |
391 | */ | 394 | */ |
392 | static char * | 395 | static char * |
393 | make_reverse_hostname(const void *ip, int af) | 396 | make_reverse_hostname (const void *ip, int af) |
394 | { | 397 | { |
395 | char *buf = GNUNET_new_array(80, char); | 398 | char *buf = GNUNET_new_array (80, char); |
396 | int pos = 0; | 399 | int pos = 0; |
397 | 400 | ||
398 | if (AF_INET == af) | 401 | if (AF_INET == af) |
402 | { | ||
403 | struct in_addr *addr = (struct in_addr *) ip; | ||
404 | uint32_t ip_int = addr->s_addr; | ||
405 | |||
406 | for (int i = 3; i >= 0; i--) | ||
399 | { | 407 | { |
400 | struct in_addr *addr = (struct in_addr *)ip; | 408 | int n = |
401 | uint32_t ip_int = addr->s_addr; | 409 | GNUNET_snprintf (buf + pos, 80 - pos, "%u.", ((uint8_t *) &ip_int)[i]); |
402 | 410 | if (n < 0) | |
403 | for (int i = 3; i >= 0; i--) | 411 | { |
404 | { | 412 | GNUNET_free (buf); |
405 | int n = | 413 | return NULL; |
406 | GNUNET_snprintf(buf + pos, 80 - pos, "%u.", ((uint8_t *)&ip_int)[i]); | 414 | } |
407 | if (n < 0) | 415 | pos += n; |
408 | { | ||
409 | GNUNET_free(buf); | ||
410 | return NULL; | ||
411 | } | ||
412 | pos += n; | ||
413 | } | ||
414 | pos += GNUNET_snprintf(buf + pos, 80 - pos, "in-addr.arpa"); | ||
415 | } | 416 | } |
417 | pos += GNUNET_snprintf (buf + pos, 80 - pos, "in-addr.arpa"); | ||
418 | } | ||
416 | else if (AF_INET6 == af) | 419 | else if (AF_INET6 == af) |
420 | { | ||
421 | struct in6_addr *addr = (struct in6_addr *) ip; | ||
422 | for (int i = 15; i >= 0; i--) | ||
417 | { | 423 | { |
418 | struct in6_addr *addr = (struct in6_addr *)ip; | 424 | int n = |
419 | for (int i = 15; i >= 0; i--) | 425 | GNUNET_snprintf (buf + pos, 80 - pos, "%x.", addr->s6_addr[i] & 0xf); |
420 | { | 426 | if (n < 0) |
421 | int n = | 427 | { |
422 | GNUNET_snprintf(buf + pos, 80 - pos, "%x.", addr->s6_addr[i] & 0xf); | 428 | GNUNET_free (buf); |
423 | if (n < 0) | 429 | return NULL; |
424 | { | 430 | } |
425 | GNUNET_free(buf); | 431 | pos += n; |
426 | return NULL; | 432 | n = GNUNET_snprintf (buf + pos, 80 - pos, "%x.", addr->s6_addr[i] >> 4); |
427 | } | 433 | if (n < 0) |
428 | pos += n; | 434 | { |
429 | n = GNUNET_snprintf(buf + pos, 80 - pos, "%x.", addr->s6_addr[i] >> 4); | 435 | GNUNET_free (buf); |
430 | if (n < 0) | 436 | return NULL; |
431 | { | 437 | } |
432 | GNUNET_free(buf); | 438 | pos += n; |
433 | return NULL; | ||
434 | } | ||
435 | pos += n; | ||
436 | } | ||
437 | pos += GNUNET_snprintf(buf + pos, 80 - pos, "ip6.arpa"); | ||
438 | } | 439 | } |
440 | pos += GNUNET_snprintf (buf + pos, 80 - pos, "ip6.arpa"); | ||
441 | } | ||
439 | buf[pos] = '\0'; | 442 | buf[pos] = '\0'; |
440 | return buf; | 443 | return buf; |
441 | } | 444 | } |
@@ -453,10 +456,10 @@ make_reverse_hostname(const void *ip, int af) | |||
453 | * does not match @a record_type | 456 | * does not match @a record_type |
454 | */ | 457 | */ |
455 | static int | 458 | static int |
456 | send_reply(struct GNUNET_DNSPARSER_Record *record, | 459 | send_reply (struct GNUNET_DNSPARSER_Record *record, |
457 | uint16_t record_type, | 460 | uint16_t record_type, |
458 | uint32_t client_request_id, | 461 | uint32_t client_request_id, |
459 | struct GNUNET_SERVICE_Client *client) | 462 | struct GNUNET_SERVICE_Client *client) |
460 | { | 463 | { |
461 | struct GNUNET_RESOLVER_ResponseMessage *msg; | 464 | struct GNUNET_RESOLVER_ResponseMessage *msg; |
462 | struct GNUNET_MQ_Envelope *env; | 465 | struct GNUNET_MQ_Envelope *env; |
@@ -464,49 +467,49 @@ send_reply(struct GNUNET_DNSPARSER_Record *record, | |||
464 | size_t payload_len; | 467 | size_t payload_len; |
465 | 468 | ||
466 | switch (record->type) | 469 | switch (record->type) |
467 | { | 470 | { |
468 | case GNUNET_DNSPARSER_TYPE_CNAME: | 471 | case GNUNET_DNSPARSER_TYPE_CNAME: |
469 | if (GNUNET_DNSPARSER_TYPE_CNAME != record_type) | 472 | if (GNUNET_DNSPARSER_TYPE_CNAME != record_type) |
470 | return GNUNET_NO; | 473 | return GNUNET_NO; |
471 | payload = record->data.hostname; | 474 | payload = record->data.hostname; |
472 | payload_len = strlen(record->data.hostname) + 1; | 475 | payload_len = strlen (record->data.hostname) + 1; |
473 | break; | 476 | break; |
474 | |||
475 | case GNUNET_DNSPARSER_TYPE_PTR: | ||
476 | if (GNUNET_DNSPARSER_TYPE_PTR != record_type) | ||
477 | return GNUNET_NO; | ||
478 | payload = record->data.hostname; | ||
479 | payload_len = strlen(record->data.hostname) + 1; | ||
480 | break; | ||
481 | 477 | ||
482 | case GNUNET_DNSPARSER_TYPE_A: | 478 | case GNUNET_DNSPARSER_TYPE_PTR: |
483 | if ((GNUNET_DNSPARSER_TYPE_A != record_type) && | 479 | if (GNUNET_DNSPARSER_TYPE_PTR != record_type) |
484 | (GNUNET_DNSPARSER_TYPE_ALL != record_type)) | 480 | return GNUNET_NO; |
485 | return GNUNET_NO; | 481 | payload = record->data.hostname; |
486 | payload = record->data.raw.data; | 482 | payload_len = strlen (record->data.hostname) + 1; |
487 | payload_len = record->data.raw.data_len; | 483 | break; |
488 | break; | ||
489 | 484 | ||
490 | case GNUNET_DNSPARSER_TYPE_AAAA: | 485 | case GNUNET_DNSPARSER_TYPE_A: |
491 | if ((GNUNET_DNSPARSER_TYPE_AAAA != record_type) && | 486 | if ((GNUNET_DNSPARSER_TYPE_A != record_type) && |
492 | (GNUNET_DNSPARSER_TYPE_ALL != record_type)) | 487 | (GNUNET_DNSPARSER_TYPE_ALL != record_type)) |
493 | return GNUNET_NO; | 488 | return GNUNET_NO; |
494 | payload = record->data.raw.data; | 489 | payload = record->data.raw.data; |
495 | payload_len = record->data.raw.data_len; | 490 | payload_len = record->data.raw.data_len; |
496 | break; | 491 | break; |
497 | 492 | ||
498 | default: | 493 | case GNUNET_DNSPARSER_TYPE_AAAA: |
499 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 494 | if ((GNUNET_DNSPARSER_TYPE_AAAA != record_type) && |
500 | "Cannot handle DNS response type %u: not supported here\n", | 495 | (GNUNET_DNSPARSER_TYPE_ALL != record_type)) |
501 | record->type); | ||
502 | return GNUNET_NO; | 496 | return GNUNET_NO; |
503 | } | 497 | payload = record->data.raw.data; |
504 | env = GNUNET_MQ_msg_extra(msg, | 498 | payload_len = record->data.raw.data_len; |
505 | payload_len, | 499 | break; |
506 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 500 | |
501 | default: | ||
502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
503 | "Cannot handle DNS response type %u: not supported here\n", | ||
504 | record->type); | ||
505 | return GNUNET_NO; | ||
506 | } | ||
507 | env = GNUNET_MQ_msg_extra (msg, | ||
508 | payload_len, | ||
509 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | ||
507 | msg->client_id = client_request_id; | 510 | msg->client_id = client_request_id; |
508 | GNUNET_memcpy(&msg[1], payload, payload_len); | 511 | GNUNET_memcpy (&msg[1], payload, payload_len); |
509 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); | 512 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); |
510 | return GNUNET_YES; | 513 | return GNUNET_YES; |
511 | } | 514 | } |
512 | 515 | ||
@@ -519,15 +522,15 @@ send_reply(struct GNUNET_DNSPARSER_Record *record, | |||
519 | * @param client where to send @a record | 522 | * @param client where to send @a record |
520 | */ | 523 | */ |
521 | static void | 524 | static void |
522 | send_end_msg(uint32_t client_request_id, struct GNUNET_SERVICE_Client *client) | 525 | send_end_msg (uint32_t client_request_id, struct GNUNET_SERVICE_Client *client) |
523 | { | 526 | { |
524 | struct GNUNET_RESOLVER_ResponseMessage *msg; | 527 | struct GNUNET_RESOLVER_ResponseMessage *msg; |
525 | struct GNUNET_MQ_Envelope *env; | 528 | struct GNUNET_MQ_Envelope *env; |
526 | 529 | ||
527 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending END message\n"); | 530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending END message\n"); |
528 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 531 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
529 | msg->client_id = client_request_id; | 532 | msg->client_id = client_request_id; |
530 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); | 533 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); |
531 | } | 534 | } |
532 | 535 | ||
533 | 536 | ||
@@ -539,27 +542,27 @@ send_end_msg(uint32_t client_request_id, struct GNUNET_SERVICE_Client *client) | |||
539 | * #GNUNET_NO if some entries are left | 542 | * #GNUNET_NO if some entries are left |
540 | */ | 543 | */ |
541 | static int | 544 | static int |
542 | remove_expired(struct ResolveCache *rc) | 545 | remove_expired (struct ResolveCache *rc) |
543 | { | 546 | { |
544 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); | 547 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
545 | struct RecordListEntry *n; | 548 | struct RecordListEntry *n; |
546 | 549 | ||
547 | for (struct RecordListEntry *pos = rc->records_head; NULL != pos; pos = n) | 550 | for (struct RecordListEntry *pos = rc->records_head; NULL != pos; pos = n) |
551 | { | ||
552 | n = pos->next; | ||
553 | if (now.abs_value_us > pos->record->expiration_time.abs_value_us) | ||
548 | { | 554 | { |
549 | n = pos->next; | 555 | GNUNET_CONTAINER_DLL_remove (rc->records_head, rc->records_tail, pos); |
550 | if (now.abs_value_us > pos->record->expiration_time.abs_value_us) | 556 | GNUNET_DNSPARSER_free_record (pos->record); |
551 | { | 557 | GNUNET_free (pos->record); |
552 | GNUNET_CONTAINER_DLL_remove(rc->records_head, rc->records_tail, pos); | 558 | GNUNET_free (pos); |
553 | GNUNET_DNSPARSER_free_record(pos->record); | ||
554 | GNUNET_free(pos->record); | ||
555 | GNUNET_free(pos); | ||
556 | } | ||
557 | } | 559 | } |
560 | } | ||
558 | if (NULL == rc->records_head) | 561 | if (NULL == rc->records_head) |
559 | { | 562 | { |
560 | free_cache_entry(rc); | 563 | free_cache_entry (rc); |
561 | return GNUNET_YES; | 564 | return GNUNET_YES; |
562 | } | 565 | } |
563 | return GNUNET_NO; | 566 | return GNUNET_NO; |
564 | } | 567 | } |
565 | 568 | ||
@@ -574,10 +577,10 @@ remove_expired(struct ResolveCache *rc) | |||
574 | * @param client who should get the result? | 577 | * @param client who should get the result? |
575 | */ | 578 | */ |
576 | static void | 579 | static void |
577 | process_get(const char *hostname, | 580 | process_get (const char *hostname, |
578 | uint16_t record_type, | 581 | uint16_t record_type, |
579 | uint32_t client_request_id, | 582 | uint32_t client_request_id, |
580 | struct GNUNET_SERVICE_Client *client); | 583 | struct GNUNET_SERVICE_Client *client); |
581 | 584 | ||
582 | 585 | ||
583 | /** | 586 | /** |
@@ -592,10 +595,10 @@ process_get(const char *hostname, | |||
592 | * @param client handle to the client making the request (for sending the reply) | 595 | * @param client handle to the client making the request (for sending the reply) |
593 | */ | 596 | */ |
594 | static int | 597 | static int |
595 | try_cache(const char *hostname, | 598 | try_cache (const char *hostname, |
596 | uint16_t record_type, | 599 | uint16_t record_type, |
597 | uint32_t client_request_id, | 600 | uint32_t client_request_id, |
598 | struct GNUNET_SERVICE_Client *client) | 601 | struct GNUNET_SERVICE_Client *client) |
599 | { | 602 | { |
600 | struct ResolveCache *pos; | 603 | struct ResolveCache *pos; |
601 | struct ResolveCache *next; | 604 | struct ResolveCache *next; |
@@ -604,57 +607,57 @@ try_cache(const char *hostname, | |||
604 | 607 | ||
605 | in_hosts = GNUNET_NO; | 608 | in_hosts = GNUNET_NO; |
606 | for (pos = hosts_head; NULL != pos; pos = pos->next) | 609 | for (pos = hosts_head; NULL != pos; pos = pos->next) |
607 | if (0 == strcmp(pos->hostname, hostname)) | 610 | if (0 == strcmp (pos->hostname, hostname)) |
608 | { | ||
609 | in_hosts = GNUNET_YES; | ||
610 | break; | ||
611 | } | ||
612 | if (NULL == pos) | ||
613 | { | 611 | { |
614 | next = cache_head; | 612 | in_hosts = GNUNET_YES; |
615 | for (pos = next; NULL != pos; pos = next) | 613 | break; |
616 | { | ||
617 | next = pos->next; | ||
618 | if (GNUNET_YES == remove_expired(pos)) | ||
619 | continue; | ||
620 | if (0 == strcmp(pos->hostname, hostname)) | ||
621 | break; | ||
622 | } | ||
623 | } | 614 | } |
624 | if (NULL == pos) | 615 | if (NULL == pos) |
616 | { | ||
617 | next = cache_head; | ||
618 | for (pos = next; NULL != pos; pos = next) | ||
625 | { | 619 | { |
626 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "No cache entry for '%s'\n", hostname); | 620 | next = pos->next; |
627 | return GNUNET_NO; | 621 | if (GNUNET_YES == remove_expired (pos)) |
622 | continue; | ||
623 | if (0 == strcmp (pos->hostname, hostname)) | ||
624 | break; | ||
628 | } | 625 | } |
626 | } | ||
627 | if (NULL == pos) | ||
628 | { | ||
629 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No cache entry for '%s'\n", hostname); | ||
630 | return GNUNET_NO; | ||
631 | } | ||
629 | if ((GNUNET_NO == in_hosts) && (cache_head != pos)) | 632 | if ((GNUNET_NO == in_hosts) && (cache_head != pos)) |
630 | { | 633 | { |
631 | /* move result to head to achieve LRU for cache eviction */ | 634 | /* move result to head to achieve LRU for cache eviction */ |
632 | GNUNET_CONTAINER_DLL_remove(cache_head, cache_tail, pos); | 635 | GNUNET_CONTAINER_DLL_remove (cache_head, cache_tail, pos); |
633 | GNUNET_CONTAINER_DLL_insert(cache_head, cache_tail, pos); | 636 | GNUNET_CONTAINER_DLL_insert (cache_head, cache_tail, pos); |
634 | } | 637 | } |
635 | found = GNUNET_NO; | 638 | found = GNUNET_NO; |
636 | for (struct RecordListEntry *rle = pos->records_head; NULL != rle; | 639 | for (struct RecordListEntry *rle = pos->records_head; NULL != rle; |
637 | rle = rle->next) | 640 | rle = rle->next) |
641 | { | ||
642 | const struct GNUNET_DNSPARSER_Record *record = rle->record; | ||
643 | |||
644 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
645 | "Found cache entry for '%s', record type '%u'\n", | ||
646 | hostname, | ||
647 | record_type); | ||
648 | if ((GNUNET_DNSPARSER_TYPE_CNAME == record->type) && | ||
649 | (GNUNET_DNSPARSER_TYPE_CNAME != record_type) && (GNUNET_NO == found)) | ||
638 | { | 650 | { |
639 | const struct GNUNET_DNSPARSER_Record *record = rle->record; | 651 | const char *hostname = record->data.hostname; |
640 | 652 | ||
641 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 653 | process_get (hostname, record_type, client_request_id, client); |
642 | "Found cache entry for '%s', record type '%u'\n", | 654 | return GNUNET_YES; /* counts as a cache "hit" */ |
643 | hostname, | ||
644 | record_type); | ||
645 | if ((GNUNET_DNSPARSER_TYPE_CNAME == record->type) && | ||
646 | (GNUNET_DNSPARSER_TYPE_CNAME != record_type) && (GNUNET_NO == found)) | ||
647 | { | ||
648 | const char *hostname = record->data.hostname; | ||
649 | |||
650 | process_get(hostname, record_type, client_request_id, client); | ||
651 | return GNUNET_YES; /* counts as a cache "hit" */ | ||
652 | } | ||
653 | found |= send_reply(rle->record, record_type, client_request_id, client); | ||
654 | } | 655 | } |
656 | found |= send_reply (rle->record, record_type, client_request_id, client); | ||
657 | } | ||
655 | if (GNUNET_NO == found) | 658 | if (GNUNET_NO == found) |
656 | return GNUNET_NO; /* had records, but none matched! */ | 659 | return GNUNET_NO; /* had records, but none matched! */ |
657 | send_end_msg(client_request_id, client); | 660 | send_end_msg (client_request_id, client); |
658 | return GNUNET_YES; | 661 | return GNUNET_YES; |
659 | } | 662 | } |
660 | 663 | ||
@@ -671,64 +674,64 @@ try_cache(const char *hostname, | |||
671 | * @return #GNUNET_OK on success | 674 | * @return #GNUNET_OK on success |
672 | */ | 675 | */ |
673 | static int | 676 | static int |
674 | pack(const char *hostname, | 677 | pack (const char *hostname, |
675 | uint16_t type, | 678 | uint16_t type, |
676 | uint16_t dns_id, | 679 | uint16_t dns_id, |
677 | char **packet_buf, | 680 | char **packet_buf, |
678 | size_t *packet_size) | 681 | size_t *packet_size) |
679 | { | 682 | { |
680 | struct GNUNET_DNSPARSER_Query query; | 683 | struct GNUNET_DNSPARSER_Query query; |
681 | struct GNUNET_DNSPARSER_Packet packet; | 684 | struct GNUNET_DNSPARSER_Packet packet; |
682 | 685 | ||
683 | query.name = (char *)hostname; | 686 | query.name = (char *) hostname; |
684 | query.type = type; | 687 | query.type = type; |
685 | query.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; | 688 | query.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; |
686 | memset(&packet, 0, sizeof(packet)); | 689 | memset (&packet, 0, sizeof(packet)); |
687 | packet.num_queries = 1; | 690 | packet.num_queries = 1; |
688 | packet.queries = &query; | 691 | packet.queries = &query; |
689 | packet.id = htons(dns_id); | 692 | packet.id = htons (dns_id); |
690 | packet.flags.recursion_desired = 1; | 693 | packet.flags.recursion_desired = 1; |
691 | if (GNUNET_OK != | 694 | if (GNUNET_OK != |
692 | GNUNET_DNSPARSER_pack(&packet, UINT16_MAX, packet_buf, packet_size)) | 695 | GNUNET_DNSPARSER_pack (&packet, UINT16_MAX, packet_buf, packet_size)) |
693 | { | 696 | { |
694 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 697 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
695 | "Failed to pack query for hostname `%s'\n", | 698 | "Failed to pack query for hostname `%s'\n", |
696 | hostname); | 699 | hostname); |
697 | packet_buf = NULL; | 700 | packet_buf = NULL; |
698 | return GNUNET_SYSERR; | 701 | return GNUNET_SYSERR; |
699 | } | 702 | } |
700 | return GNUNET_OK; | 703 | return GNUNET_OK; |
701 | } | 704 | } |
702 | 705 | ||
703 | static void | 706 | static void |
704 | cache_answers(const char *name, | 707 | cache_answers (const char *name, |
705 | struct GNUNET_DNSPARSER_Record *records, | 708 | struct GNUNET_DNSPARSER_Record *records, |
706 | unsigned int num_records) | 709 | unsigned int num_records) |
707 | { | 710 | { |
708 | struct ResolveCache *rc; | 711 | struct ResolveCache *rc; |
709 | struct GNUNET_DNSPARSER_Record *record; | 712 | struct GNUNET_DNSPARSER_Record *record; |
710 | struct RecordListEntry *rle; | 713 | struct RecordListEntry *rle; |
711 | 714 | ||
712 | for (unsigned int i = 0; i != num_records; i++) | 715 | for (unsigned int i = 0; i != num_records; i++) |
716 | { | ||
717 | record = &records[i]; | ||
718 | |||
719 | for (rc = cache_head; NULL != rc; rc = rc->next) | ||
720 | if (0 == strcasecmp (rc->hostname, name)) | ||
721 | break; | ||
722 | if (NULL == rc) | ||
713 | { | 723 | { |
714 | record = &records[i]; | 724 | rc = GNUNET_new (struct ResolveCache); |
715 | 725 | rc->hostname = GNUNET_strdup (name); | |
716 | for (rc = cache_head; NULL != rc; rc = rc->next) | 726 | GNUNET_CONTAINER_DLL_insert (cache_head, cache_tail, rc); |
717 | if (0 == strcasecmp(rc->hostname, name)) | 727 | cache_size++; |
718 | break; | ||
719 | if (NULL == rc) | ||
720 | { | ||
721 | rc = GNUNET_new(struct ResolveCache); | ||
722 | rc->hostname = GNUNET_strdup(name); | ||
723 | GNUNET_CONTAINER_DLL_insert(cache_head, cache_tail, rc); | ||
724 | cache_size++; | ||
725 | } | ||
726 | /* TODO: ought to check first if we have this exact record | ||
727 | already in the cache! */ | ||
728 | rle = GNUNET_new(struct RecordListEntry); | ||
729 | rle->record = GNUNET_DNSPARSER_duplicate_record(record); | ||
730 | GNUNET_CONTAINER_DLL_insert(rc->records_head, rc->records_tail, rle); | ||
731 | } | 728 | } |
729 | /* TODO: ought to check first if we have this exact record | ||
730 | already in the cache! */ | ||
731 | rle = GNUNET_new (struct RecordListEntry); | ||
732 | rle->record = GNUNET_DNSPARSER_duplicate_record (record); | ||
733 | GNUNET_CONTAINER_DLL_insert (rc->records_head, rc->records_tail, rle); | ||
734 | } | ||
732 | } | 735 | } |
733 | 736 | ||
734 | /** | 737 | /** |
@@ -740,107 +743,107 @@ cache_answers(const char *name, | |||
740 | * @param dns_len number of bytes in @a dns | 743 | * @param dns_len number of bytes in @a dns |
741 | */ | 744 | */ |
742 | static void | 745 | static void |
743 | handle_resolve_result(void *cls, | 746 | handle_resolve_result (void *cls, |
744 | const struct GNUNET_TUN_DnsHeader *dns, | 747 | const struct GNUNET_TUN_DnsHeader *dns, |
745 | size_t dns_len) | 748 | size_t dns_len) |
746 | { | 749 | { |
747 | struct ActiveLookup *al = cls; | 750 | struct ActiveLookup *al = cls; |
748 | struct GNUNET_DNSPARSER_Packet *parsed; | 751 | struct GNUNET_DNSPARSER_Packet *parsed; |
749 | 752 | ||
750 | parsed = GNUNET_DNSPARSER_parse((const char *)dns, dns_len); | 753 | parsed = GNUNET_DNSPARSER_parse ((const char *) dns, dns_len); |
751 | if (NULL == parsed) | 754 | if (NULL == parsed) |
755 | { | ||
756 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
757 | "Failed to parse DNS reply (hostname %s, request ID %u)\n", | ||
758 | al->hostname, | ||
759 | al->dns_id); | ||
760 | return; | ||
761 | } | ||
762 | if (al->dns_id != ntohs (parsed->id)) | ||
763 | { | ||
764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
765 | "Request ID in DNS reply does not match\n"); | ||
766 | GNUNET_DNSPARSER_free_packet (parsed); | ||
767 | return; | ||
768 | } | ||
769 | if (0 == parsed->num_answers + parsed->num_authority_records | ||
770 | + parsed->num_additional_records) | ||
771 | { | ||
772 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
773 | "DNS reply (hostname %s, request ID %u) contains no answers\n", | ||
774 | al->hostname, | ||
775 | (unsigned int) al->client_request_id); | ||
776 | /* resume by trying again from cache */ | ||
777 | if (GNUNET_NO == try_cache (al->hostname, | ||
778 | al->record_type, | ||
779 | al->client_request_id, | ||
780 | al->client)) | ||
781 | /* cache failed, tell client we could not get an answer */ | ||
752 | { | 782 | { |
753 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 783 | send_end_msg (al->client_request_id, al->client); |
754 | "Failed to parse DNS reply (hostname %s, request ID %u)\n", | ||
755 | al->hostname, | ||
756 | al->dns_id); | ||
757 | return; | ||
758 | } | ||
759 | if (al->dns_id != ntohs(parsed->id)) | ||
760 | { | ||
761 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
762 | "Request ID in DNS reply does not match\n"); | ||
763 | GNUNET_DNSPARSER_free_packet(parsed); | ||
764 | return; | ||
765 | } | ||
766 | if (0 == parsed->num_answers + parsed->num_authority_records + | ||
767 | parsed->num_additional_records) | ||
768 | { | ||
769 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
770 | "DNS reply (hostname %s, request ID %u) contains no answers\n", | ||
771 | al->hostname, | ||
772 | (unsigned int)al->client_request_id); | ||
773 | /* resume by trying again from cache */ | ||
774 | if (GNUNET_NO == try_cache(al->hostname, | ||
775 | al->record_type, | ||
776 | al->client_request_id, | ||
777 | al->client)) | ||
778 | /* cache failed, tell client we could not get an answer */ | ||
779 | { | ||
780 | send_end_msg(al->client_request_id, al->client); | ||
781 | } | ||
782 | GNUNET_DNSPARSER_free_packet(parsed); | ||
783 | free_active_lookup(al); | ||
784 | return; | ||
785 | } | 784 | } |
785 | GNUNET_DNSPARSER_free_packet (parsed); | ||
786 | free_active_lookup (al); | ||
787 | return; | ||
788 | } | ||
786 | /* LRU-based cache eviction: we remove from tail */ | 789 | /* LRU-based cache eviction: we remove from tail */ |
787 | while (cache_size > MAX_CACHE) | 790 | while (cache_size > MAX_CACHE) |
788 | free_cache_entry(cache_tail); | 791 | free_cache_entry (cache_tail); |
789 | 792 | ||
790 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 793 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
791 | "Got reply for hostname %s and request ID %u\n", | 794 | "Got reply for hostname %s and request ID %u\n", |
792 | al->hostname, | 795 | al->hostname, |
793 | (unsigned int)al->client_request_id); | 796 | (unsigned int) al->client_request_id); |
794 | /* add to cache */ | 797 | /* add to cache */ |
795 | cache_answers(al->hostname, parsed->answers, parsed->num_answers); | 798 | cache_answers (al->hostname, parsed->answers, parsed->num_answers); |
796 | cache_answers(al->hostname, | 799 | cache_answers (al->hostname, |
797 | parsed->authority_records, | 800 | parsed->authority_records, |
798 | parsed->num_authority_records); | 801 | parsed->num_authority_records); |
799 | cache_answers(al->hostname, | 802 | cache_answers (al->hostname, |
800 | parsed->additional_records, | 803 | parsed->additional_records, |
801 | parsed->num_additional_records); | 804 | parsed->num_additional_records); |
802 | 805 | ||
803 | /* see if we need to do the 2nd request for AAAA records */ | 806 | /* see if we need to do the 2nd request for AAAA records */ |
804 | if ((GNUNET_DNSPARSER_TYPE_ALL == al->record_type) && | 807 | if ((GNUNET_DNSPARSER_TYPE_ALL == al->record_type) && |
805 | (GNUNET_NO == al->did_aaaa)) | 808 | (GNUNET_NO == al->did_aaaa)) |
806 | { | 809 | { |
807 | char *packet_buf; | 810 | char *packet_buf; |
808 | size_t packet_size; | 811 | size_t packet_size; |
809 | uint16_t dns_id; | 812 | uint16_t dns_id; |
810 | 813 | ||
811 | dns_id = (uint16_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, | 814 | dns_id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
812 | UINT16_MAX); | 815 | UINT16_MAX); |
813 | if (GNUNET_OK == pack(al->hostname, | 816 | if (GNUNET_OK == pack (al->hostname, |
814 | GNUNET_DNSPARSER_TYPE_AAAA, | 817 | GNUNET_DNSPARSER_TYPE_AAAA, |
815 | dns_id, | 818 | dns_id, |
816 | &packet_buf, | 819 | &packet_buf, |
817 | &packet_size)) | 820 | &packet_size)) |
818 | { | 821 | { |
819 | al->did_aaaa = GNUNET_YES; | 822 | al->did_aaaa = GNUNET_YES; |
820 | al->dns_id = dns_id; | 823 | al->dns_id = dns_id; |
821 | GNUNET_DNSSTUB_resolve_cancel(al->resolve_handle); | 824 | GNUNET_DNSSTUB_resolve_cancel (al->resolve_handle); |
822 | al->resolve_handle = GNUNET_DNSSTUB_resolve(dnsstub_ctx, | 825 | al->resolve_handle = GNUNET_DNSSTUB_resolve (dnsstub_ctx, |
823 | packet_buf, | 826 | packet_buf, |
824 | packet_size, | 827 | packet_size, |
825 | &handle_resolve_result, | 828 | &handle_resolve_result, |
826 | al); | 829 | al); |
827 | GNUNET_free(packet_buf); | 830 | GNUNET_free (packet_buf); |
828 | GNUNET_DNSPARSER_free_packet(parsed); | 831 | GNUNET_DNSPARSER_free_packet (parsed); |
829 | return; | 832 | return; |
830 | } | ||
831 | } | 833 | } |
834 | } | ||
832 | 835 | ||
833 | /* resume by trying again from cache */ | 836 | /* resume by trying again from cache */ |
834 | if (GNUNET_NO == try_cache(al->hostname, | 837 | if (GNUNET_NO == try_cache (al->hostname, |
835 | al->record_type, | 838 | al->record_type, |
836 | al->client_request_id, | 839 | al->client_request_id, |
837 | al->client)) | 840 | al->client)) |
838 | /* cache failed, tell client we could not get an answer */ | 841 | /* cache failed, tell client we could not get an answer */ |
839 | { | 842 | { |
840 | send_end_msg(al->client_request_id, al->client); | 843 | send_end_msg (al->client_request_id, al->client); |
841 | } | 844 | } |
842 | free_active_lookup(al); | 845 | free_active_lookup (al); |
843 | GNUNET_DNSPARSER_free_packet(parsed); | 846 | GNUNET_DNSPARSER_free_packet (parsed); |
844 | } | 847 | } |
845 | 848 | ||
846 | 849 | ||
@@ -851,14 +854,14 @@ handle_resolve_result(void *cls, | |||
851 | * @param cls a `struct ActiveLookup` | 854 | * @param cls a `struct ActiveLookup` |
852 | */ | 855 | */ |
853 | static void | 856 | static void |
854 | handle_resolve_timeout(void *cls) | 857 | handle_resolve_timeout (void *cls) |
855 | { | 858 | { |
856 | struct ActiveLookup *al = cls; | 859 | struct ActiveLookup *al = cls; |
857 | 860 | ||
858 | al->timeout_task = NULL; | 861 | al->timeout_task = NULL; |
859 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DNS lookup timeout!\n"); | 862 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DNS lookup timeout!\n"); |
860 | send_end_msg(al->client_request_id, al->client); | 863 | send_end_msg (al->client_request_id, al->client); |
861 | free_active_lookup(al); | 864 | free_active_lookup (al); |
862 | } | 865 | } |
863 | 866 | ||
864 | 867 | ||
@@ -873,10 +876,10 @@ handle_resolve_timeout(void *cls) | |||
873 | * @return #GNUNET_OK if the DNS query is now pending | 876 | * @return #GNUNET_OK if the DNS query is now pending |
874 | */ | 877 | */ |
875 | static int | 878 | static int |
876 | resolve_and_cache(const char *hostname, | 879 | resolve_and_cache (const char *hostname, |
877 | uint16_t record_type, | 880 | uint16_t record_type, |
878 | uint32_t client_request_id, | 881 | uint32_t client_request_id, |
879 | struct GNUNET_SERVICE_Client *client) | 882 | struct GNUNET_SERVICE_Client *client) |
880 | { | 883 | { |
881 | char *packet_buf; | 884 | char *packet_buf; |
882 | size_t packet_size; | 885 | size_t packet_size; |
@@ -884,42 +887,42 @@ resolve_and_cache(const char *hostname, | |||
884 | uint16_t dns_id; | 887 | uint16_t dns_id; |
885 | uint16_t type; | 888 | uint16_t type; |
886 | 889 | ||
887 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "resolve_and_cache `%s'\n", hostname); | 890 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "resolve_and_cache `%s'\n", hostname); |
888 | dns_id = (uint16_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, | 891 | dns_id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
889 | UINT16_MAX); | 892 | UINT16_MAX); |
890 | 893 | ||
891 | if (GNUNET_DNSPARSER_TYPE_ALL == record_type) | 894 | if (GNUNET_DNSPARSER_TYPE_ALL == record_type) |
892 | type = GNUNET_DNSPARSER_TYPE_A; | 895 | type = GNUNET_DNSPARSER_TYPE_A; |
893 | else | 896 | else |
894 | type = record_type; | 897 | type = record_type; |
895 | if (GNUNET_OK != pack(hostname, type, dns_id, &packet_buf, &packet_size)) | 898 | if (GNUNET_OK != pack (hostname, type, dns_id, &packet_buf, &packet_size)) |
896 | { | 899 | { |
897 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 900 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
898 | "Failed to pack query for hostname `%s'\n", | 901 | "Failed to pack query for hostname `%s'\n", |
899 | hostname); | 902 | hostname); |
900 | return GNUNET_SYSERR; | 903 | return GNUNET_SYSERR; |
901 | } | 904 | } |
902 | 905 | ||
903 | al = GNUNET_new(struct ActiveLookup); | 906 | al = GNUNET_new (struct ActiveLookup); |
904 | al->hostname = GNUNET_strdup(hostname); | 907 | al->hostname = GNUNET_strdup (hostname); |
905 | al->record_type = record_type; | 908 | al->record_type = record_type; |
906 | al->client_request_id = client_request_id; | 909 | al->client_request_id = client_request_id; |
907 | al->dns_id = dns_id; | 910 | al->dns_id = dns_id; |
908 | al->client = client; | 911 | al->client = client; |
909 | al->timeout_task = | 912 | al->timeout_task = |
910 | GNUNET_SCHEDULER_add_delayed(DNS_TIMEOUT, &handle_resolve_timeout, al); | 913 | GNUNET_SCHEDULER_add_delayed (DNS_TIMEOUT, &handle_resolve_timeout, al); |
911 | al->resolve_handle = GNUNET_DNSSTUB_resolve(dnsstub_ctx, | 914 | al->resolve_handle = GNUNET_DNSSTUB_resolve (dnsstub_ctx, |
912 | packet_buf, | 915 | packet_buf, |
913 | packet_size, | 916 | packet_size, |
914 | &handle_resolve_result, | 917 | &handle_resolve_result, |
915 | al); | 918 | al); |
916 | GNUNET_free(packet_buf); | 919 | GNUNET_free (packet_buf); |
917 | GNUNET_CONTAINER_DLL_insert(lookup_head, lookup_tail, al); | 920 | GNUNET_CONTAINER_DLL_insert (lookup_head, lookup_tail, al); |
918 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 921 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
919 | "Resolving %s, client_request_id = %u, dns_id = %u\n", | 922 | "Resolving %s, client_request_id = %u, dns_id = %u\n", |
920 | hostname, | 923 | hostname, |
921 | (unsigned int)client_request_id, | 924 | (unsigned int) client_request_id, |
922 | (unsigned int)dns_id); | 925 | (unsigned int) dns_id); |
923 | return GNUNET_OK; | 926 | return GNUNET_OK; |
924 | } | 927 | } |
925 | 928 | ||
@@ -934,38 +937,38 @@ resolve_and_cache(const char *hostname, | |||
934 | * @param client who should get the result? | 937 | * @param client who should get the result? |
935 | */ | 938 | */ |
936 | static void | 939 | static void |
937 | process_get(const char *hostname, | 940 | process_get (const char *hostname, |
938 | uint16_t record_type, | 941 | uint16_t record_type, |
939 | uint32_t client_request_id, | 942 | uint32_t client_request_id, |
940 | struct GNUNET_SERVICE_Client *client) | 943 | struct GNUNET_SERVICE_Client *client) |
941 | { | 944 | { |
942 | char fqdn[255]; | 945 | char fqdn[255]; |
943 | 946 | ||
944 | if (GNUNET_NO != try_cache(hostname, record_type, client_request_id, client)) | 947 | if (GNUNET_NO != try_cache (hostname, record_type, client_request_id, client)) |
945 | return; | 948 | return; |
946 | if ((NULL != my_domain) && (NULL == strchr(hostname, (unsigned char)'.')) && | 949 | if ((NULL != my_domain) && (NULL == strchr (hostname, (unsigned char) '.')) && |
947 | (strlen(hostname) + strlen(my_domain) <= 253)) | 950 | (strlen (hostname) + strlen (my_domain) <= 253)) |
948 | { | 951 | { |
949 | GNUNET_snprintf(fqdn, sizeof(fqdn), "%s.%s", hostname, my_domain); | 952 | GNUNET_snprintf (fqdn, sizeof(fqdn), "%s.%s", hostname, my_domain); |
950 | } | 953 | } |
951 | else if (strlen(hostname) < 255) | 954 | else if (strlen (hostname) < 255) |
952 | { | 955 | { |
953 | GNUNET_snprintf(fqdn, sizeof(fqdn), "%s", hostname); | 956 | GNUNET_snprintf (fqdn, sizeof(fqdn), "%s", hostname); |
954 | } | 957 | } |
955 | else | 958 | else |
959 | { | ||
960 | GNUNET_break (0); | ||
961 | GNUNET_SERVICE_client_drop (client); | ||
962 | return; | ||
963 | } | ||
964 | if (GNUNET_NO == try_cache (fqdn, record_type, client_request_id, client)) | ||
965 | { | ||
966 | if (GNUNET_OK != | ||
967 | resolve_and_cache (fqdn, record_type, client_request_id, client)) | ||
956 | { | 968 | { |
957 | GNUNET_break(0); | 969 | send_end_msg (client_request_id, client); |
958 | GNUNET_SERVICE_client_drop(client); | ||
959 | return; | ||
960 | } | ||
961 | if (GNUNET_NO == try_cache(fqdn, record_type, client_request_id, client)) | ||
962 | { | ||
963 | if (GNUNET_OK != | ||
964 | resolve_and_cache(fqdn, record_type, client_request_id, client)) | ||
965 | { | ||
966 | send_end_msg(client_request_id, client); | ||
967 | } | ||
968 | } | 970 | } |
971 | } | ||
969 | } | 972 | } |
970 | 973 | ||
971 | 974 | ||
@@ -977,43 +980,43 @@ process_get(const char *hostname, | |||
977 | * @return #GNUNET_OK if @a get is well-formed | 980 | * @return #GNUNET_OK if @a get is well-formed |
978 | */ | 981 | */ |
979 | static int | 982 | static int |
980 | check_get(void *cls, const struct GNUNET_RESOLVER_GetMessage *get) | 983 | check_get (void *cls, const struct GNUNET_RESOLVER_GetMessage *get) |
981 | { | 984 | { |
982 | uint16_t size; | 985 | uint16_t size; |
983 | int direction; | 986 | int direction; |
984 | int af; | 987 | int af; |
985 | 988 | ||
986 | (void)cls; | 989 | (void) cls; |
987 | size = ntohs(get->header.size) - sizeof(*get); | 990 | size = ntohs (get->header.size) - sizeof(*get); |
988 | direction = ntohl(get->direction); | 991 | direction = ntohl (get->direction); |
989 | if (GNUNET_NO == direction) | 992 | if (GNUNET_NO == direction) |
990 | { | 993 | { |
991 | GNUNET_MQ_check_zero_termination(get); | 994 | GNUNET_MQ_check_zero_termination (get); |
992 | return GNUNET_OK; | 995 | return GNUNET_OK; |
993 | } | 996 | } |
994 | af = ntohl(get->af); | 997 | af = ntohl (get->af); |
995 | switch (af) | 998 | switch (af) |
999 | { | ||
1000 | case AF_INET: | ||
1001 | if (size != sizeof(struct in_addr)) | ||
996 | { | 1002 | { |
997 | case AF_INET: | 1003 | GNUNET_break (0); |
998 | if (size != sizeof(struct in_addr)) | 1004 | return GNUNET_SYSERR; |
999 | { | 1005 | } |
1000 | GNUNET_break(0); | 1006 | break; |
1001 | return GNUNET_SYSERR; | ||
1002 | } | ||
1003 | break; | ||
1004 | |||
1005 | case AF_INET6: | ||
1006 | if (size != sizeof(struct in6_addr)) | ||
1007 | { | ||
1008 | GNUNET_break(0); | ||
1009 | return GNUNET_SYSERR; | ||
1010 | } | ||
1011 | break; | ||
1012 | 1007 | ||
1013 | default: | 1008 | case AF_INET6: |
1014 | GNUNET_break(0); | 1009 | if (size != sizeof(struct in6_addr)) |
1010 | { | ||
1011 | GNUNET_break (0); | ||
1015 | return GNUNET_SYSERR; | 1012 | return GNUNET_SYSERR; |
1016 | } | 1013 | } |
1014 | break; | ||
1015 | |||
1016 | default: | ||
1017 | GNUNET_break (0); | ||
1018 | return GNUNET_SYSERR; | ||
1019 | } | ||
1017 | return GNUNET_OK; | 1020 | return GNUNET_OK; |
1018 | } | 1021 | } |
1019 | 1022 | ||
@@ -1025,7 +1028,7 @@ check_get(void *cls, const struct GNUNET_RESOLVER_GetMessage *get) | |||
1025 | * @param msg the actual message | 1028 | * @param msg the actual message |
1026 | */ | 1029 | */ |
1027 | static void | 1030 | static void |
1028 | handle_get(void *cls, const struct GNUNET_RESOLVER_GetMessage *msg) | 1031 | handle_get (void *cls, const struct GNUNET_RESOLVER_GetMessage *msg) |
1029 | { | 1032 | { |
1030 | struct GNUNET_SERVICE_Client *client = cls; | 1033 | struct GNUNET_SERVICE_Client *client = cls; |
1031 | int direction; | 1034 | int direction; |
@@ -1033,59 +1036,59 @@ handle_get(void *cls, const struct GNUNET_RESOLVER_GetMessage *msg) | |||
1033 | uint32_t client_request_id; | 1036 | uint32_t client_request_id; |
1034 | char *hostname; | 1037 | char *hostname; |
1035 | 1038 | ||
1036 | direction = ntohl(msg->direction); | 1039 | direction = ntohl (msg->direction); |
1037 | af = ntohl(msg->af); | 1040 | af = ntohl (msg->af); |
1038 | client_request_id = msg->client_id; | 1041 | client_request_id = msg->client_id; |
1039 | GNUNET_SERVICE_client_continue(client); | 1042 | GNUNET_SERVICE_client_continue (client); |
1040 | if (GNUNET_NO == direction) | 1043 | if (GNUNET_NO == direction) |
1044 | { | ||
1045 | /* IP from hostname */ | ||
1046 | hostname = GNUNET_strdup ((const char *) &msg[1]); | ||
1047 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1048 | "Client asks to resolve `%s'\n", | ||
1049 | hostname); | ||
1050 | switch (af) | ||
1041 | { | 1051 | { |
1042 | /* IP from hostname */ | 1052 | case AF_UNSPEC: { |
1043 | hostname = GNUNET_strdup((const char *)&msg[1]); | 1053 | process_get (hostname, |
1044 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1054 | GNUNET_DNSPARSER_TYPE_ALL, |
1045 | "Client asks to resolve `%s'\n", | 1055 | client_request_id, |
1046 | hostname); | 1056 | client); |
1047 | switch (af) | 1057 | break; |
1048 | { | 1058 | } |
1049 | case AF_UNSPEC: { | 1059 | |
1050 | process_get(hostname, | 1060 | case AF_INET: { |
1051 | GNUNET_DNSPARSER_TYPE_ALL, | 1061 | process_get (hostname, |
1052 | client_request_id, | 1062 | GNUNET_DNSPARSER_TYPE_A, |
1053 | client); | 1063 | client_request_id, |
1054 | break; | 1064 | client); |
1055 | } | 1065 | break; |
1056 | 1066 | } | |
1057 | case AF_INET: { | 1067 | |
1058 | process_get(hostname, | 1068 | case AF_INET6: { |
1059 | GNUNET_DNSPARSER_TYPE_A, | 1069 | process_get (hostname, |
1060 | client_request_id, | 1070 | GNUNET_DNSPARSER_TYPE_AAAA, |
1061 | client); | 1071 | client_request_id, |
1062 | break; | 1072 | client); |
1063 | } | 1073 | break; |
1064 | 1074 | } | |
1065 | case AF_INET6: { | 1075 | |
1066 | process_get(hostname, | 1076 | default: { |
1067 | GNUNET_DNSPARSER_TYPE_AAAA, | 1077 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got invalid af: %d\n", af); |
1068 | client_request_id, | 1078 | GNUNET_assert (0); |
1069 | client); | 1079 | } |
1070 | break; | ||
1071 | } | ||
1072 | |||
1073 | default: { | ||
1074 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "got invalid af: %d\n", af); | ||
1075 | GNUNET_assert(0); | ||
1076 | } | ||
1077 | } | ||
1078 | } | 1080 | } |
1081 | } | ||
1079 | else | 1082 | else |
1080 | { | 1083 | { |
1081 | /* hostname from IP */ | 1084 | /* hostname from IP */ |
1082 | hostname = make_reverse_hostname(&msg[1], af); | 1085 | hostname = make_reverse_hostname (&msg[1], af); |
1083 | process_get(hostname, | 1086 | process_get (hostname, |
1084 | GNUNET_DNSPARSER_TYPE_PTR, | 1087 | GNUNET_DNSPARSER_TYPE_PTR, |
1085 | client_request_id, | 1088 | client_request_id, |
1086 | client); | 1089 | client); |
1087 | } | 1090 | } |
1088 | GNUNET_free_non_null(hostname); | 1091 | GNUNET_free_non_null (hostname); |
1089 | } | 1092 | } |
1090 | 1093 | ||
1091 | 1094 | ||
@@ -1095,18 +1098,18 @@ handle_get(void *cls, const struct GNUNET_RESOLVER_GetMessage *msg) | |||
1095 | * @param cls NULL, unused | 1098 | * @param cls NULL, unused |
1096 | */ | 1099 | */ |
1097 | static void | 1100 | static void |
1098 | shutdown_task(void *cls) | 1101 | shutdown_task (void *cls) |
1099 | { | 1102 | { |
1100 | (void)cls; | 1103 | (void) cls; |
1101 | 1104 | ||
1102 | while (NULL != lookup_head) | 1105 | while (NULL != lookup_head) |
1103 | free_active_lookup(lookup_head); | 1106 | free_active_lookup (lookup_head); |
1104 | while (NULL != cache_head) | 1107 | while (NULL != cache_head) |
1105 | free_cache_entry(cache_head); | 1108 | free_cache_entry (cache_head); |
1106 | while (NULL != hosts_head) | 1109 | while (NULL != hosts_head) |
1107 | free_hosts_entry(hosts_head); | 1110 | free_hosts_entry (hosts_head); |
1108 | GNUNET_DNSSTUB_stop(dnsstub_ctx); | 1111 | GNUNET_DNSSTUB_stop (dnsstub_ctx); |
1109 | GNUNET_free_non_null(my_domain); | 1112 | GNUNET_free_non_null (my_domain); |
1110 | } | 1113 | } |
1111 | 1114 | ||
1112 | 1115 | ||
@@ -1120,28 +1123,28 @@ shutdown_task(void *cls) | |||
1120 | * @param data_size number of bytes in @a data | 1123 | * @param data_size number of bytes in @a data |
1121 | */ | 1124 | */ |
1122 | static void | 1125 | static void |
1123 | add_host(const char *hostname, | 1126 | add_host (const char *hostname, |
1124 | uint16_t rec_type, | 1127 | uint16_t rec_type, |
1125 | const void *data, | 1128 | const void *data, |
1126 | size_t data_size) | 1129 | size_t data_size) |
1127 | { | 1130 | { |
1128 | struct ResolveCache *rc; | 1131 | struct ResolveCache *rc; |
1129 | struct RecordListEntry *rle; | 1132 | struct RecordListEntry *rle; |
1130 | struct GNUNET_DNSPARSER_Record *rec; | 1133 | struct GNUNET_DNSPARSER_Record *rec; |
1131 | 1134 | ||
1132 | rec = GNUNET_malloc(sizeof(struct GNUNET_DNSPARSER_Record)); | 1135 | rec = GNUNET_malloc (sizeof(struct GNUNET_DNSPARSER_Record)); |
1133 | rec->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS; | 1136 | rec->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS; |
1134 | rec->type = rec_type; | 1137 | rec->type = rec_type; |
1135 | rec->dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; | 1138 | rec->dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; |
1136 | rec->name = GNUNET_strdup(hostname); | 1139 | rec->name = GNUNET_strdup (hostname); |
1137 | rec->data.raw.data = GNUNET_memdup(data, data_size); | 1140 | rec->data.raw.data = GNUNET_memdup (data, data_size); |
1138 | rec->data.raw.data_len = data_size; | 1141 | rec->data.raw.data_len = data_size; |
1139 | rle = GNUNET_new(struct RecordListEntry); | 1142 | rle = GNUNET_new (struct RecordListEntry); |
1140 | rle->record = rec; | 1143 | rle->record = rec; |
1141 | rc = GNUNET_new(struct ResolveCache); | 1144 | rc = GNUNET_new (struct ResolveCache); |
1142 | rc->hostname = GNUNET_strdup(hostname); | 1145 | rc->hostname = GNUNET_strdup (hostname); |
1143 | GNUNET_CONTAINER_DLL_insert(rc->records_head, rc->records_tail, rle); | 1146 | GNUNET_CONTAINER_DLL_insert (rc->records_head, rc->records_tail, rle); |
1144 | GNUNET_CONTAINER_DLL_insert(hosts_head, hosts_tail, rc); | 1147 | GNUNET_CONTAINER_DLL_insert (hosts_head, hosts_tail, rc); |
1145 | } | 1148 | } |
1146 | 1149 | ||
1147 | 1150 | ||
@@ -1152,7 +1155,7 @@ add_host(const char *hostname, | |||
1152 | * @param line_len number of bytes in @a line | 1155 | * @param line_len number of bytes in @a line |
1153 | */ | 1156 | */ |
1154 | static void | 1157 | static void |
1155 | extract_hosts(const char *line, size_t line_len) | 1158 | extract_hosts (const char *line, size_t line_len) |
1156 | { | 1159 | { |
1157 | const char *c; | 1160 | const char *c; |
1158 | struct in_addr v4; | 1161 | struct in_addr v4; |
@@ -1161,33 +1164,33 @@ extract_hosts(const char *line, size_t line_len) | |||
1161 | char *tok; | 1164 | char *tok; |
1162 | 1165 | ||
1163 | /* ignore everything after '#' */ | 1166 | /* ignore everything after '#' */ |
1164 | c = memrchr(line, (unsigned char)'#', line_len); | 1167 | c = memrchr (line, (unsigned char) '#', line_len); |
1165 | if (NULL != c) | 1168 | if (NULL != c) |
1166 | line_len = c - line; | 1169 | line_len = c - line; |
1167 | /* ignore leading whitespace */ | 1170 | /* ignore leading whitespace */ |
1168 | while ((0 < line_len) && isspace((unsigned char)*line)) | 1171 | while ((0 < line_len) && isspace ((unsigned char) *line)) |
1169 | { | 1172 | { |
1170 | line++; | 1173 | line++; |
1171 | line_len--; | 1174 | line_len--; |
1172 | } | 1175 | } |
1173 | tbuf = GNUNET_strndup(line, line_len); | 1176 | tbuf = GNUNET_strndup (line, line_len); |
1174 | tok = strtok(tbuf, " \t"); | 1177 | tok = strtok (tbuf, " \t"); |
1175 | if (NULL == tok) | 1178 | if (NULL == tok) |
1176 | { | 1179 | { |
1177 | GNUNET_free(tbuf); | 1180 | GNUNET_free (tbuf); |
1178 | return; | 1181 | return; |
1179 | } | 1182 | } |
1180 | if (1 == inet_pton(AF_INET, tok, &v4)) | 1183 | if (1 == inet_pton (AF_INET, tok, &v4)) |
1181 | { | 1184 | { |
1182 | while (NULL != (tok = strtok(NULL, " \t"))) | 1185 | while (NULL != (tok = strtok (NULL, " \t"))) |
1183 | add_host(tok, GNUNET_DNSPARSER_TYPE_A, &v4, sizeof(struct in_addr)); | 1186 | add_host (tok, GNUNET_DNSPARSER_TYPE_A, &v4, sizeof(struct in_addr)); |
1184 | } | 1187 | } |
1185 | else if (1 == inet_pton(AF_INET6, tok, &v6)) | 1188 | else if (1 == inet_pton (AF_INET6, tok, &v6)) |
1186 | { | 1189 | { |
1187 | while (NULL != (tok = strtok(NULL, " \t"))) | 1190 | while (NULL != (tok = strtok (NULL, " \t"))) |
1188 | add_host(tok, GNUNET_DNSPARSER_TYPE_AAAA, &v6, sizeof(struct in6_addr)); | 1191 | add_host (tok, GNUNET_DNSPARSER_TYPE_AAAA, &v6, sizeof(struct in6_addr)); |
1189 | } | 1192 | } |
1190 | GNUNET_free(tbuf); | 1193 | GNUNET_free (tbuf); |
1191 | } | 1194 | } |
1192 | 1195 | ||
1193 | 1196 | ||
@@ -1195,7 +1198,7 @@ extract_hosts(const char *line, size_t line_len) | |||
1195 | * Reads the list of hosts from /etc/hosts. | 1198 | * Reads the list of hosts from /etc/hosts. |
1196 | */ | 1199 | */ |
1197 | static void | 1200 | static void |
1198 | load_etc_hosts(void) | 1201 | load_etc_hosts (void) |
1199 | { | 1202 | { |
1200 | struct GNUNET_DISK_FileHandle *fh; | 1203 | struct GNUNET_DISK_FileHandle *fh; |
1201 | struct GNUNET_DISK_MapHandle *mh; | 1204 | struct GNUNET_DISK_MapHandle *mh; |
@@ -1203,49 +1206,49 @@ load_etc_hosts(void) | |||
1203 | const char *buf; | 1206 | const char *buf; |
1204 | size_t read_offset; | 1207 | size_t read_offset; |
1205 | 1208 | ||
1206 | fh = GNUNET_DISK_file_open("/etc/hosts", | 1209 | fh = GNUNET_DISK_file_open ("/etc/hosts", |
1207 | GNUNET_DISK_OPEN_READ, | 1210 | GNUNET_DISK_OPEN_READ, |
1208 | GNUNET_DISK_PERM_NONE); | 1211 | GNUNET_DISK_PERM_NONE); |
1209 | if (NULL == fh) | 1212 | if (NULL == fh) |
1210 | { | 1213 | { |
1211 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Failed to open /etc/hosts"); | 1214 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to open /etc/hosts"); |
1212 | return; | 1215 | return; |
1213 | } | 1216 | } |
1214 | if (GNUNET_OK != GNUNET_DISK_file_handle_size(fh, &bytes_read)) | 1217 | if (GNUNET_OK != GNUNET_DISK_file_handle_size (fh, &bytes_read)) |
1215 | { | 1218 | { |
1216 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1219 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1217 | "Could not determin size of /etc/hosts. " | 1220 | "Could not determin size of /etc/hosts. " |
1218 | "DNS resolution will not be possible.\n"); | 1221 | "DNS resolution will not be possible.\n"); |
1219 | GNUNET_DISK_file_close(fh); | 1222 | GNUNET_DISK_file_close (fh); |
1220 | return; | 1223 | return; |
1221 | } | 1224 | } |
1222 | if (((unsigned long long)bytes_read) > (unsigned long long)SIZE_MAX) | 1225 | if (((unsigned long long) bytes_read) > (unsigned long long) SIZE_MAX) |
1223 | { | 1226 | { |
1224 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1227 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1225 | "/etc/hosts file too large to mmap. " | 1228 | "/etc/hosts file too large to mmap. " |
1226 | "DNS resolution will not be possible.\n"); | 1229 | "DNS resolution will not be possible.\n"); |
1227 | GNUNET_DISK_file_close(fh); | 1230 | GNUNET_DISK_file_close (fh); |
1228 | return; | 1231 | return; |
1229 | } | 1232 | } |
1230 | buf = GNUNET_DISK_file_map(fh, | 1233 | buf = GNUNET_DISK_file_map (fh, |
1231 | &mh, | 1234 | &mh, |
1232 | GNUNET_DISK_MAP_TYPE_READ, | 1235 | GNUNET_DISK_MAP_TYPE_READ, |
1233 | (size_t)bytes_read); | 1236 | (size_t) bytes_read); |
1234 | read_offset = 0; | 1237 | read_offset = 0; |
1235 | while (read_offset < (size_t)bytes_read) | 1238 | while (read_offset < (size_t) bytes_read) |
1236 | { | 1239 | { |
1237 | const char *newline; | 1240 | const char *newline; |
1238 | size_t line_len; | 1241 | size_t line_len; |
1239 | 1242 | ||
1240 | newline = strchr(buf + read_offset, '\n'); | 1243 | newline = strchr (buf + read_offset, '\n'); |
1241 | if (NULL == newline) | 1244 | if (NULL == newline) |
1242 | break; | 1245 | break; |
1243 | line_len = newline - buf - read_offset; | 1246 | line_len = newline - buf - read_offset; |
1244 | extract_hosts(buf + read_offset, line_len); | 1247 | extract_hosts (buf + read_offset, line_len); |
1245 | read_offset += line_len + 1; | 1248 | read_offset += line_len + 1; |
1246 | } | 1249 | } |
1247 | GNUNET_DISK_file_unmap(mh); | 1250 | GNUNET_DISK_file_unmap (mh); |
1248 | GNUNET_DISK_file_close(fh); | 1251 | GNUNET_DISK_file_close (fh); |
1249 | } | 1252 | } |
1250 | 1253 | ||
1251 | 1254 | ||
@@ -1257,37 +1260,37 @@ load_etc_hosts(void) | |||
1257 | * @param sh service handle | 1260 | * @param sh service handle |
1258 | */ | 1261 | */ |
1259 | static void | 1262 | static void |
1260 | init_cb(void *cls, | 1263 | init_cb (void *cls, |
1261 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1264 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1262 | struct GNUNET_SERVICE_Handle *sh) | 1265 | struct GNUNET_SERVICE_Handle *sh) |
1263 | { | 1266 | { |
1264 | char **dns_servers; | 1267 | char **dns_servers; |
1265 | int num_dns_servers; | 1268 | int num_dns_servers; |
1266 | 1269 | ||
1267 | (void)cfg; | 1270 | (void) cfg; |
1268 | (void)sh; | 1271 | (void) sh; |
1269 | load_etc_hosts(); | 1272 | load_etc_hosts (); |
1270 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, cls); | 1273 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, cls); |
1271 | dnsstub_ctx = GNUNET_DNSSTUB_start(128); | 1274 | dnsstub_ctx = GNUNET_DNSSTUB_start (128); |
1272 | dns_servers = NULL; | 1275 | dns_servers = NULL; |
1273 | num_dns_servers = lookup_dns_servers(&dns_servers); | 1276 | num_dns_servers = lookup_dns_servers (&dns_servers); |
1274 | if (0 >= num_dns_servers) | 1277 | if (0 >= num_dns_servers) |
1275 | { | 1278 | { |
1276 | GNUNET_log( | 1279 | GNUNET_log ( |
1277 | GNUNET_ERROR_TYPE_ERROR, | 1280 | GNUNET_ERROR_TYPE_ERROR, |
1278 | _("No DNS server available. DNS resolution will not be possible.\n")); | 1281 | _ ("No DNS server available. DNS resolution will not be possible.\n")); |
1279 | return; | 1282 | return; |
1280 | } | 1283 | } |
1281 | for (int i = 0; i < num_dns_servers; i++) | 1284 | for (int i = 0; i < num_dns_servers; i++) |
1282 | { | 1285 | { |
1283 | int result = GNUNET_DNSSTUB_add_dns_ip(dnsstub_ctx, dns_servers[i]); | 1286 | int result = GNUNET_DNSSTUB_add_dns_ip (dnsstub_ctx, dns_servers[i]); |
1284 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1285 | "Adding DNS server '%s': %s\n", | 1288 | "Adding DNS server '%s': %s\n", |
1286 | dns_servers[i], | 1289 | dns_servers[i], |
1287 | GNUNET_OK == result ? "success" : "failure"); | 1290 | GNUNET_OK == result ? "success" : "failure"); |
1288 | GNUNET_free(dns_servers[i]); | 1291 | GNUNET_free (dns_servers[i]); |
1289 | } | 1292 | } |
1290 | GNUNET_free_non_null(dns_servers); | 1293 | GNUNET_free_non_null (dns_servers); |
1291 | } | 1294 | } |
1292 | 1295 | ||
1293 | 1296 | ||
@@ -1300,12 +1303,12 @@ init_cb(void *cls, | |||
1300 | * @return @a c | 1303 | * @return @a c |
1301 | */ | 1304 | */ |
1302 | static void * | 1305 | static void * |
1303 | connect_cb(void *cls, | 1306 | connect_cb (void *cls, |
1304 | struct GNUNET_SERVICE_Client *c, | 1307 | struct GNUNET_SERVICE_Client *c, |
1305 | struct GNUNET_MQ_Handle *mq) | 1308 | struct GNUNET_MQ_Handle *mq) |
1306 | { | 1309 | { |
1307 | (void)cls; | 1310 | (void) cls; |
1308 | (void)mq; | 1311 | (void) mq; |
1309 | 1312 | ||
1310 | return c; | 1313 | return c; |
1311 | } | 1314 | } |
@@ -1319,38 +1322,38 @@ connect_cb(void *cls, | |||
1319 | * @param internal_cls should be equal to @a c | 1322 | * @param internal_cls should be equal to @a c |
1320 | */ | 1323 | */ |
1321 | static void | 1324 | static void |
1322 | disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls) | 1325 | disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls) |
1323 | { | 1326 | { |
1324 | struct ActiveLookup *n; | 1327 | struct ActiveLookup *n; |
1325 | 1328 | ||
1326 | (void)cls; | 1329 | (void) cls; |
1327 | 1330 | ||
1328 | GNUNET_assert(c == internal_cls); | 1331 | GNUNET_assert (c == internal_cls); |
1329 | n = lookup_head; | 1332 | n = lookup_head; |
1330 | for (struct ActiveLookup *al = n; NULL != al; al = n) | 1333 | for (struct ActiveLookup *al = n; NULL != al; al = n) |
1331 | { | 1334 | { |
1332 | n = al->next; | 1335 | n = al->next; |
1333 | if (al->client == c) | 1336 | if (al->client == c) |
1334 | free_active_lookup(al); | 1337 | free_active_lookup (al); |
1335 | } | 1338 | } |
1336 | } | 1339 | } |
1337 | 1340 | ||
1338 | 1341 | ||
1339 | /** | 1342 | /** |
1340 | * Define "main" method using service macro. | 1343 | * Define "main" method using service macro. |
1341 | */ | 1344 | */ |
1342 | GNUNET_SERVICE_MAIN( | 1345 | GNUNET_SERVICE_MAIN ( |
1343 | "resolver", | 1346 | "resolver", |
1344 | GNUNET_SERVICE_OPTION_NONE, | 1347 | GNUNET_SERVICE_OPTION_NONE, |
1345 | &init_cb, | 1348 | &init_cb, |
1346 | &connect_cb, | 1349 | &connect_cb, |
1347 | &disconnect_cb, | 1350 | &disconnect_cb, |
1348 | NULL, | 1351 | NULL, |
1349 | GNUNET_MQ_hd_var_size(get, | 1352 | GNUNET_MQ_hd_var_size (get, |
1350 | GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST, | 1353 | GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST, |
1351 | struct GNUNET_RESOLVER_GetMessage, | 1354 | struct GNUNET_RESOLVER_GetMessage, |
1352 | NULL), | 1355 | NULL), |
1353 | GNUNET_MQ_handler_end()); | 1356 | GNUNET_MQ_handler_end ()); |
1354 | 1357 | ||
1355 | 1358 | ||
1356 | #if defined(LINUX) && defined(__GLIBC__) | 1359 | #if defined(LINUX) && defined(__GLIBC__) |
@@ -1359,11 +1362,11 @@ GNUNET_SERVICE_MAIN( | |||
1359 | /** | 1362 | /** |
1360 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | 1363 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. |
1361 | */ | 1364 | */ |
1362 | void __attribute__ ((constructor)) GNUNET_RESOLVER_memory_init() | 1365 | void __attribute__ ((constructor)) GNUNET_RESOLVER_memory_init () |
1363 | { | 1366 | { |
1364 | mallopt(M_TRIM_THRESHOLD, 4 * 1024); | 1367 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); |
1365 | mallopt(M_TOP_PAD, 1 * 1024); | 1368 | mallopt (M_TOP_PAD, 1 * 1024); |
1366 | malloc_trim(0); | 1369 | malloc_trim (0); |
1367 | } | 1370 | } |
1368 | #endif | 1371 | #endif |
1369 | 1372 | ||