diff options
Diffstat (limited to 'src/dns/gnunet-service-dns.c')
-rw-r--r-- | src/dns/gnunet-service-dns.c | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c index ac410d3ed..53c19d01c 100644 --- a/src/dns/gnunet-service-dns.c +++ b/src/dns/gnunet-service-dns.c | |||
@@ -34,7 +34,7 @@ | |||
34 | * each request will be given one of 128 random source ports, and the | 34 | * each request will be given one of 128 random source ports, and the |
35 | * 128 random source ports will also change "often" (less often if the | 35 | * 128 random source ports will also change "often" (less often if the |
36 | * system is very busy, each time if we are mostly idle). At the same | 36 | * system is very busy, each time if we are mostly idle). At the same |
37 | * time, the system will never use more than 256 UDP sockets. | 37 | * time, the system will never use more than 256 UDP sockets. |
38 | */ | 38 | */ |
39 | #include "platform.h" | 39 | #include "platform.h" |
40 | #include "gnunet_util_lib.h" | 40 | #include "gnunet_util_lib.h" |
@@ -88,7 +88,7 @@ enum RequestPhase | |||
88 | * Global Internet query is now pending. | 88 | * Global Internet query is now pending. |
89 | */ | 89 | */ |
90 | RP_INTERNET_DNS, | 90 | RP_INTERNET_DNS, |
91 | 91 | ||
92 | /** | 92 | /** |
93 | * Client (or global DNS request) has resulted in a response. | 93 | * Client (or global DNS request) has resulted in a response. |
94 | * Forward to all POST-RESOLUTION clients. If client list is empty, | 94 | * Forward to all POST-RESOLUTION clients. If client list is empty, |
@@ -111,22 +111,22 @@ enum RequestPhase | |||
111 | 111 | ||
112 | /** | 112 | /** |
113 | * Entry we keep for each client. | 113 | * Entry we keep for each client. |
114 | */ | 114 | */ |
115 | struct ClientRecord | 115 | struct ClientRecord |
116 | { | 116 | { |
117 | /** | 117 | /** |
118 | * Kept in doubly-linked list. | 118 | * Kept in doubly-linked list. |
119 | */ | 119 | */ |
120 | struct ClientRecord *next; | 120 | struct ClientRecord *next; |
121 | 121 | ||
122 | /** | 122 | /** |
123 | * Kept in doubly-linked list. | 123 | * Kept in doubly-linked list. |
124 | */ | 124 | */ |
125 | struct ClientRecord *prev; | 125 | struct ClientRecord *prev; |
126 | 126 | ||
127 | /** | 127 | /** |
128 | * Handle to the client. | 128 | * Handle to the client. |
129 | */ | 129 | */ |
130 | struct GNUNET_SERVER_Client *client; | 130 | struct GNUNET_SERVER_Client *client; |
131 | 131 | ||
132 | /** | 132 | /** |
@@ -139,7 +139,7 @@ struct ClientRecord | |||
139 | 139 | ||
140 | /** | 140 | /** |
141 | * Entry we keep for each active request. | 141 | * Entry we keep for each active request. |
142 | */ | 142 | */ |
143 | struct RequestRecord | 143 | struct RequestRecord |
144 | { | 144 | { |
145 | 145 | ||
@@ -180,7 +180,7 @@ struct RequestRecord | |||
180 | 180 | ||
181 | /** | 181 | /** |
182 | * Number of bytes in payload. | 182 | * Number of bytes in payload. |
183 | */ | 183 | */ |
184 | size_t payload_length; | 184 | size_t payload_length; |
185 | 185 | ||
186 | /** | 186 | /** |
@@ -317,7 +317,7 @@ request_done (struct RequestRecord *rr) | |||
317 | 317 | ||
318 | GNUNET_array_grow (rr->client_wait_list, | 318 | GNUNET_array_grow (rr->client_wait_list, |
319 | rr->client_wait_list_length, | 319 | rr->client_wait_list_length, |
320 | 0); | 320 | 0); |
321 | if (RP_RESPONSE_MONITOR != rr->phase) | 321 | if (RP_RESPONSE_MONITOR != rr->phase) |
322 | { | 322 | { |
323 | /* no response, drop */ | 323 | /* no response, drop */ |
@@ -330,7 +330,7 @@ request_done (struct RequestRecord *rr) | |||
330 | 330 | ||
331 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 331 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
332 | "Transmitting response for request %llu\n", | 332 | "Transmitting response for request %llu\n", |
333 | (unsigned long long) rr->request_id); | 333 | (unsigned long long) rr->request_id); |
334 | /* send response via hijacker */ | 334 | /* send response via hijacker */ |
335 | reply_len = sizeof (struct GNUNET_MessageHeader); | 335 | reply_len = sizeof (struct GNUNET_MessageHeader); |
336 | reply_len += sizeof (struct GNUNET_TUN_Layer2PacketHeader); | 336 | reply_len += sizeof (struct GNUNET_TUN_Layer2PacketHeader); |
@@ -345,7 +345,7 @@ request_done (struct RequestRecord *rr) | |||
345 | default: | 345 | default: |
346 | GNUNET_break (0); | 346 | GNUNET_break (0); |
347 | cleanup_rr (rr); | 347 | cleanup_rr (rr); |
348 | return; | 348 | return; |
349 | } | 349 | } |
350 | reply_len += sizeof (struct GNUNET_TUN_UdpHeader); | 350 | reply_len += sizeof (struct GNUNET_TUN_UdpHeader); |
351 | reply_len += rr->payload_length; | 351 | reply_len += rr->payload_length; |
@@ -354,7 +354,7 @@ request_done (struct RequestRecord *rr) | |||
354 | /* response too big, drop */ | 354 | /* response too big, drop */ |
355 | GNUNET_break (0); /* how can this be? */ | 355 | GNUNET_break (0); /* how can this be? */ |
356 | cleanup_rr(rr); | 356 | cleanup_rr(rr); |
357 | return; | 357 | return; |
358 | } | 358 | } |
359 | { | 359 | { |
360 | char buf[reply_len] GNUNET_ALIGN; | 360 | char buf[reply_len] GNUNET_ALIGN; |
@@ -374,7 +374,7 @@ request_done (struct RequestRecord *rr) | |||
374 | 374 | ||
375 | tun.flags = htons (0); | 375 | tun.flags = htons (0); |
376 | if (rr->src_addr.ss_family == AF_INET) | 376 | if (rr->src_addr.ss_family == AF_INET) |
377 | tun.proto = htons (ETH_P_IPV4); | 377 | tun.proto = htons (ETH_P_IPV4); |
378 | else | 378 | else |
379 | tun.proto = htons (ETH_P_IPV6); | 379 | tun.proto = htons (ETH_P_IPV6); |
380 | memcpy (&buf[off], &tun, sizeof (struct GNUNET_TUN_Layer2PacketHeader)); | 380 | memcpy (&buf[off], &tun, sizeof (struct GNUNET_TUN_Layer2PacketHeader)); |
@@ -483,14 +483,14 @@ send_request_to_client (struct RequestRecord *rr, | |||
483 | } | 483 | } |
484 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 484 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
485 | "Sending information about request %llu to local client\n", | 485 | "Sending information about request %llu to local client\n", |
486 | (unsigned long long) rr->request_id); | 486 | (unsigned long long) rr->request_id); |
487 | req = (struct GNUNET_DNS_Request*) buf; | 487 | req = (struct GNUNET_DNS_Request*) buf; |
488 | req->header.type = htons (GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST); | 488 | req->header.type = htons (GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST); |
489 | req->header.size = htons (sizeof (buf)); | 489 | req->header.size = htons (sizeof (buf)); |
490 | req->reserved = htonl (0); | 490 | req->reserved = htonl (0); |
491 | req->request_id = rr->request_id; | 491 | req->request_id = rr->request_id; |
492 | memcpy (&req[1], rr->payload, rr->payload_length); | 492 | memcpy (&req[1], rr->payload, rr->payload_length); |
493 | GNUNET_SERVER_notification_context_unicast (nc, | 493 | GNUNET_SERVER_notification_context_unicast (nc, |
494 | client, | 494 | client, |
495 | &req->header, | 495 | &req->header, |
496 | GNUNET_NO); | 496 | GNUNET_NO); |
@@ -541,8 +541,8 @@ next_phase (struct RequestRecord *rr) | |||
541 | nz = (int) j; | 541 | nz = (int) j; |
542 | break; | 542 | break; |
543 | } | 543 | } |
544 | } | 544 | } |
545 | if (-1 != nz) | 545 | if (-1 != nz) |
546 | { | 546 | { |
547 | send_request_to_client (rr, rr->client_wait_list[nz]->client); | 547 | send_request_to_client (rr, rr->client_wait_list[nz]->client); |
548 | return; | 548 | return; |
@@ -551,7 +551,7 @@ next_phase (struct RequestRecord *rr) | |||
551 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 551 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
552 | "Request %llu now in phase %d\n", | 552 | "Request %llu now in phase %d\n", |
553 | rr->request_id, | 553 | rr->request_id, |
554 | rr->phase); | 554 | rr->phase); |
555 | switch (rr->phase) | 555 | switch (rr->phase) |
556 | { | 556 | { |
557 | case RP_INIT: | 557 | case RP_INIT: |
@@ -647,7 +647,7 @@ next_phase (struct RequestRecord *rr) | |||
647 | * | 647 | * |
648 | * @param cls unused | 648 | * @param cls unused |
649 | * @param client handle of client that disconnected | 649 | * @param client handle of client that disconnected |
650 | */ | 650 | */ |
651 | static void | 651 | static void |
652 | client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | 652 | client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) |
653 | { | 653 | { |
@@ -674,7 +674,7 @@ client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
674 | if (rr->client_wait_list[j] == cr) | 674 | if (rr->client_wait_list[j] == cr) |
675 | { | 675 | { |
676 | rr->client_wait_list[j] = NULL; | 676 | rr->client_wait_list[j] = NULL; |
677 | next_phase (rr); | 677 | next_phase (rr); |
678 | } | 678 | } |
679 | } | 679 | } |
680 | } | 680 | } |
@@ -714,8 +714,8 @@ process_dns_result (void *cls, | |||
714 | gettext_noop ("# External DNS response discarded (no matching request)"), | 714 | gettext_noop ("# External DNS response discarded (no matching request)"), |
715 | 1, GNUNET_NO); | 715 | 1, GNUNET_NO); |
716 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 716 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
717 | "Received DNS reply that does not match any pending request. Dropping.\n"); | 717 | "Received DNS reply that does not match any pending request. Dropping.\n"); |
718 | return; | 718 | return; |
719 | } | 719 | } |
720 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 720 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
721 | "Got a response from the stub resolver for DNS request %llu intercepted locally!\n", | 721 | "Got a response from the stub resolver for DNS request %llu intercepted locally!\n", |
@@ -736,7 +736,7 @@ process_dns_result (void *cls, | |||
736 | * @param message the init message (unused) | 736 | * @param message the init message (unused) |
737 | */ | 737 | */ |
738 | static void | 738 | static void |
739 | handle_client_init (void *cls GNUNET_UNUSED, | 739 | handle_client_init (void *cls GNUNET_UNUSED, |
740 | struct GNUNET_SERVER_Client *client, | 740 | struct GNUNET_SERVER_Client *client, |
741 | const struct GNUNET_MessageHeader *message) | 741 | const struct GNUNET_MessageHeader *message) |
742 | { | 742 | { |
@@ -745,7 +745,7 @@ handle_client_init (void *cls GNUNET_UNUSED, | |||
745 | 745 | ||
746 | cr = GNUNET_malloc (sizeof (struct ClientRecord)); | 746 | cr = GNUNET_malloc (sizeof (struct ClientRecord)); |
747 | cr->client = client; | 747 | cr->client = client; |
748 | cr->flags = (enum GNUNET_DNS_Flags) ntohl (reg->flags); | 748 | cr->flags = (enum GNUNET_DNS_Flags) ntohl (reg->flags); |
749 | GNUNET_SERVER_client_keep (client); | 749 | GNUNET_SERVER_client_keep (client); |
750 | GNUNET_CONTAINER_DLL_insert (clients_head, | 750 | GNUNET_CONTAINER_DLL_insert (clients_head, |
751 | clients_tail, | 751 | clients_tail, |
@@ -763,7 +763,7 @@ handle_client_init (void *cls GNUNET_UNUSED, | |||
763 | * @param message the response | 763 | * @param message the response |
764 | */ | 764 | */ |
765 | static void | 765 | static void |
766 | handle_client_response (void *cls GNUNET_UNUSED, | 766 | handle_client_response (void *cls GNUNET_UNUSED, |
767 | struct GNUNET_SERVER_Client *client, | 767 | struct GNUNET_SERVER_Client *client, |
768 | const struct GNUNET_MessageHeader *message) | 768 | const struct GNUNET_MessageHeader *message) |
769 | { | 769 | { |
@@ -816,7 +816,7 @@ handle_client_response (void *cls GNUNET_UNUSED, | |||
816 | { | 816 | { |
817 | GNUNET_break (0); | 817 | GNUNET_break (0); |
818 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 818 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
819 | next_phase (rr); | 819 | next_phase (rr); |
820 | return; | 820 | return; |
821 | } | 821 | } |
822 | GNUNET_free_non_null (rr->payload); | 822 | GNUNET_free_non_null (rr->payload); |
@@ -844,9 +844,9 @@ handle_client_response (void *cls GNUNET_UNUSED, | |||
844 | } | 844 | } |
845 | break; | 845 | break; |
846 | } | 846 | } |
847 | next_phase (rr); | 847 | next_phase (rr); |
848 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 848 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
849 | return; | 849 | return; |
850 | } | 850 | } |
851 | /* odd, client was not on our list for the request, that ought | 851 | /* odd, client was not on our list for the request, that ought |
852 | to be an error */ | 852 | to be an error */ |
@@ -936,7 +936,7 @@ process_helper_messages (void *cls GNUNET_UNUSED, void *client, | |||
936 | } | 936 | } |
937 | if ( (msize <= sizeof (struct GNUNET_TUN_UdpHeader) + sizeof (struct GNUNET_TUN_DnsHeader)) || | 937 | if ( (msize <= sizeof (struct GNUNET_TUN_UdpHeader) + sizeof (struct GNUNET_TUN_DnsHeader)) || |
938 | (DNS_PORT != ntohs (udp->destination_port)) ) | 938 | (DNS_PORT != ntohs (udp->destination_port)) ) |
939 | { | 939 | { |
940 | /* non-DNS packet received on TUN, ignore */ | 940 | /* non-DNS packet received on TUN, ignore */ |
941 | GNUNET_STATISTICS_update (stats, | 941 | GNUNET_STATISTICS_update (stats, |
942 | gettext_noop ("# Non-DNS UDP packet received via TUN interface"), | 942 | gettext_noop ("# Non-DNS UDP packet received via TUN interface"), |
@@ -1025,7 +1025,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1025 | { | 1025 | { |
1026 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 1026 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
1027 | /* callback, cls, type, size */ | 1027 | /* callback, cls, type, size */ |
1028 | {&handle_client_init, NULL, GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT, | 1028 | {&handle_client_init, NULL, GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT, |
1029 | sizeof (struct GNUNET_DNS_Register)}, | 1029 | sizeof (struct GNUNET_DNS_Register)}, |
1030 | {&handle_client_response, NULL, GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE, 0}, | 1030 | {&handle_client_response, NULL, GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE, 0}, |
1031 | {NULL, NULL, 0, 0} | 1031 | {NULL, NULL, 0, 0} |
@@ -1059,7 +1059,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1059 | cls); | 1059 | cls); |
1060 | dns_exit = NULL; | 1060 | dns_exit = NULL; |
1061 | if ( ( (GNUNET_OK != | 1061 | if ( ( (GNUNET_OK != |
1062 | GNUNET_CONFIGURATION_get_value_string (cfg, "dns", | 1062 | GNUNET_CONFIGURATION_get_value_string (cfg, "dns", |
1063 | "DNS_EXIT", | 1063 | "DNS_EXIT", |
1064 | &dns_exit)) || | 1064 | &dns_exit)) || |
1065 | ( (1 != inet_pton (AF_INET, dns_exit, &dns_exit4)) && | 1065 | ( (1 != inet_pton (AF_INET, dns_exit, &dns_exit4)) && |
@@ -1157,7 +1157,7 @@ main (int argc, char *const *argv) | |||
1157 | strerror (errno)); | 1157 | strerror (errno)); |
1158 | } | 1158 | } |
1159 | else if (sgid != rgid) | 1159 | else if (sgid != rgid) |
1160 | { | 1160 | { |
1161 | if (-1 == setregid (sgid, sgid)) | 1161 | if (-1 == setregid (sgid, sgid)) |
1162 | fprintf (stderr, "setregid failed: %s\n", strerror (errno)); | 1162 | fprintf (stderr, "setregid failed: %s\n", strerror (errno)); |
1163 | } | 1163 | } |