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