aboutsummaryrefslogtreecommitdiff
path: root/src/dns
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-09-30 13:39:32 +0000
committerChristian Grothoff <christian@grothoff.org>2016-09-30 13:39:32 +0000
commit489f6cd93578b60a89f6df1d295518d33de7ddb9 (patch)
treefd1a236b5c62273ee43706f68326bd226c43a595 /src/dns
parent030a97d44c3a36fd62efcb524a974bdc1b8bb48c (diff)
downloadgnunet-489f6cd93578b60a89f6df1d295518d33de7ddb9.tar.gz
gnunet-489f6cd93578b60a89f6df1d295518d33de7ddb9.zip
porting DNS to new service API
Diffstat (limited to 'src/dns')
-rw-r--r--src/dns/gnunet-service-dns.c299
1 files changed, 163 insertions, 136 deletions
diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c
index 52f924cdf..74f595c5e 100644
--- a/src/dns/gnunet-service-dns.c
+++ b/src/dns/gnunet-service-dns.c
@@ -119,15 +119,20 @@ struct ClientRecord
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_SERVICE_Client *client;
131
132 /**
133 * Message queue to talk to @a client.
134 */
135 struct GNUNET_MQ_Handle *mq;
131 136
132 /** 137 /**
133 * Flags for the client. 138 * Flags for the client.
@@ -184,7 +189,7 @@ struct RequestRecord
184 size_t payload_length; 189 size_t payload_length;
185 190
186 /** 191 /**
187 * Length of the client wait list. 192 * Length of the @e client_wait_list.
188 */ 193 */
189 unsigned int client_wait_list_length; 194 unsigned int client_wait_list_length;
190 195
@@ -232,11 +237,6 @@ static struct ClientRecord *clients_head;
232static struct ClientRecord *clients_tail; 237static struct ClientRecord *clients_tail;
233 238
234/** 239/**
235 * Our notification context.
236 */
237static struct GNUNET_SERVER_NotificationContext *nc;
238
239/**
240 * Array of all open requests. 240 * Array of all open requests.
241 */ 241 */
242static struct RequestRecord requests[UINT16_MAX + 1]; 242static struct RequestRecord requests[UINT16_MAX + 1];
@@ -277,22 +277,19 @@ cleanup_rr (struct RequestRecord *rr)
277static void 277static void
278cleanup_task (void *cls GNUNET_UNUSED) 278cleanup_task (void *cls GNUNET_UNUSED)
279{ 279{
280 unsigned int i;
281
282 if (NULL != hijacker) 280 if (NULL != hijacker)
283 { 281 {
284 GNUNET_HELPER_stop (hijacker, GNUNET_NO); 282 GNUNET_HELPER_stop (hijacker, GNUNET_NO);
285 hijacker = NULL; 283 hijacker = NULL;
286 } 284 }
287 for (i=0;i<8;i++) 285 for (unsigned int i=0;i<8;i++)
288 GNUNET_free_non_null (helper_argv[i]); 286 GNUNET_free_non_null (helper_argv[i]);
289 for (i=0;i<=UINT16_MAX;i++) 287 for (unsigned int i=0;i<=UINT16_MAX;i++)
290 cleanup_rr (&requests[i]); 288 cleanup_rr (&requests[i]);
291 GNUNET_SERVER_notification_context_destroy (nc); 289 if (NULL != stats)
292 nc = NULL;
293 if (stats != NULL)
294 { 290 {
295 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 291 GNUNET_STATISTICS_destroy (stats,
292 GNUNET_NO);
296 stats = NULL; 293 stats = NULL;
297 } 294 }
298 if (NULL != dnsstub) 295 if (NULL != dnsstub)
@@ -378,7 +375,9 @@ request_done (struct RequestRecord *rr)
378 tun.proto = htons (ETH_P_IPV4); 375 tun.proto = htons (ETH_P_IPV4);
379 else 376 else
380 tun.proto = htons (ETH_P_IPV6); 377 tun.proto = htons (ETH_P_IPV6);
381 GNUNET_memcpy (&buf[off], &tun, sizeof (struct GNUNET_TUN_Layer2PacketHeader)); 378 GNUNET_memcpy (&buf[off],
379 &tun,
380 sizeof (struct GNUNET_TUN_Layer2PacketHeader));
382 off += sizeof (struct GNUNET_TUN_Layer2PacketHeader); 381 off += sizeof (struct GNUNET_TUN_Layer2PacketHeader);
383 } 382 }
384 383
@@ -397,7 +396,9 @@ request_done (struct RequestRecord *rr)
397 reply_len - off - sizeof (struct GNUNET_TUN_IPv4Header), 396 reply_len - off - sizeof (struct GNUNET_TUN_IPv4Header),
398 &dst->sin_addr, 397 &dst->sin_addr,
399 &src->sin_addr); 398 &src->sin_addr);
400 GNUNET_memcpy (&buf[off], &ip4, sizeof (ip4)); 399 GNUNET_memcpy (&buf[off],
400 &ip4,
401 sizeof (ip4));
401 off += sizeof (ip4); 402 off += sizeof (ip4);
402 } 403 }
403 break; 404 break;
@@ -413,7 +414,9 @@ request_done (struct RequestRecord *rr)
413 reply_len - off - sizeof (struct GNUNET_TUN_IPv6Header), 414 reply_len - off - sizeof (struct GNUNET_TUN_IPv6Header),
414 &dst->sin6_addr, 415 &dst->sin6_addr,
415 &src->sin6_addr); 416 &src->sin6_addr);
416 GNUNET_memcpy (&buf[off], &ip6, sizeof (ip6)); 417 GNUNET_memcpy (&buf[off],
418 &ip6,
419 sizeof (ip6));
417 off += sizeof (ip6); 420 off += sizeof (ip6);
418 } 421 }
419 break; 422 break;
@@ -438,7 +441,9 @@ request_done (struct RequestRecord *rr)
438 &udp, 441 &udp,
439 rr->payload, 442 rr->payload,
440 rr->payload_length); 443 rr->payload_length);
441 GNUNET_memcpy (&buf[off], &udp, sizeof (udp)); 444 GNUNET_memcpy (&buf[off],
445 &udp,
446 sizeof (udp));
442 off += sizeof (udp); 447 off += sizeof (udp);
443 } 448 }
444 449
@@ -467,16 +472,16 @@ request_done (struct RequestRecord *rr)
467 * (and wait for a response). 472 * (and wait for a response).
468 * 473 *
469 * @param rr request to send to client 474 * @param rr request to send to client
470 * @param client client to send the response to 475 * @param cr client to send the response to
471 */ 476 */
472static void 477static void
473send_request_to_client (struct RequestRecord *rr, 478send_request_to_client (struct RequestRecord *rr,
474 struct GNUNET_SERVER_Client *client) 479 struct ClientRecord *cr)
475{ 480{
476 char buf[sizeof (struct GNUNET_DNS_Request) + rr->payload_length] GNUNET_ALIGN; 481 struct GNUNET_MQ_Envelope *env;
477 struct GNUNET_DNS_Request *req; 482 struct GNUNET_DNS_Request *req;
478 483
479 if (sizeof (buf) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 484 if (sizeof (struct GNUNET_DNS_Request) + rr->payload_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
480 { 485 {
481 GNUNET_break (0); 486 GNUNET_break (0);
482 cleanup_rr (rr); 487 cleanup_rr (rr);
@@ -485,20 +490,19 @@ send_request_to_client (struct RequestRecord *rr,
485 LOG (GNUNET_ERROR_TYPE_DEBUG, 490 LOG (GNUNET_ERROR_TYPE_DEBUG,
486 "Sending information about request %llu to local client\n", 491 "Sending information about request %llu to local client\n",
487 (unsigned long long) rr->request_id); 492 (unsigned long long) rr->request_id);
488 req = (struct GNUNET_DNS_Request*) buf; 493 env = GNUNET_MQ_msg_extra (req,
489 req->header.type = htons (GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST); 494 rr->payload_length,
490 req->header.size = htons (sizeof (buf)); 495 GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST);
491 req->reserved = htonl (0); 496 req->reserved = htonl (0);
492 req->request_id = rr->request_id; 497 req->request_id = rr->request_id;
493 GNUNET_memcpy (&req[1], rr->payload, rr->payload_length); 498 GNUNET_memcpy (&req[1],
494 GNUNET_SERVER_notification_context_unicast (nc, 499 rr->payload,
495 client, 500 rr->payload_length);
496 &req->header, 501 GNUNET_MQ_send (cr->mq,
497 GNUNET_NO); 502 env);
498} 503}
499 504
500 505
501
502/** 506/**
503 * Callback called from DNSSTUB resolver when a resolution 507 * Callback called from DNSSTUB resolver when a resolution
504 * succeeded. 508 * succeeded.
@@ -526,7 +530,6 @@ next_phase (struct RequestRecord *rr)
526{ 530{
527 struct ClientRecord *cr; 531 struct ClientRecord *cr;
528 int nz; 532 int nz;
529 unsigned int j;
530 socklen_t salen; 533 socklen_t salen;
531 534
532 if (rr->phase == RP_DROP) 535 if (rr->phase == RP_DROP)
@@ -535,7 +538,7 @@ next_phase (struct RequestRecord *rr)
535 return; 538 return;
536 } 539 }
537 nz = -1; 540 nz = -1;
538 for (j=0;j<rr->client_wait_list_length;j++) 541 for (unsigned int j=0;j<rr->client_wait_list_length;j++)
539 { 542 {
540 if (NULL != rr->client_wait_list[j]) 543 if (NULL != rr->client_wait_list[j])
541 { 544 {
@@ -545,7 +548,8 @@ next_phase (struct RequestRecord *rr)
545 } 548 }
546 if (-1 != nz) 549 if (-1 != nz)
547 { 550 {
548 send_request_to_client (rr, rr->client_wait_list[nz]->client); 551 send_request_to_client (rr,
552 rr->client_wait_list[nz]);
549 return; 553 return;
550 } 554 }
551 /* done with current phase, advance! */ 555 /* done with current phase, advance! */
@@ -602,7 +606,8 @@ next_phase (struct RequestRecord *rr)
602 { 606 {
603 GNUNET_STATISTICS_update (stats, 607 GNUNET_STATISTICS_update (stats,
604 gettext_noop ("# DNS exit failed (failed to open socket)"), 608 gettext_noop ("# DNS exit failed (failed to open socket)"),
605 1, GNUNET_NO); 609 1,
610 GNUNET_NO);
606 cleanup_rr (rr); 611 cleanup_rr (rr);
607 return; 612 return;
608 } 613 }
@@ -644,45 +649,63 @@ next_phase (struct RequestRecord *rr)
644 649
645 650
646/** 651/**
652 * A client connected, setup our data structures.
653 *
654 * @param cls unused
655 * @param client handle of client that connected
656 * @param mq message queue to talk to @a client
657 * @return our `struct ClientRecord`
658 */
659static void *
660client_connect_cb (void *cls,
661 struct GNUNET_SERVICE_Client *client,
662 struct GNUNET_MQ_Handle *mq)
663{
664 struct ClientRecord *cr = cls;
665
666 cr = GNUNET_new (struct ClientRecord);
667 cr->client = client;
668 cr->mq = mq;
669 GNUNET_CONTAINER_DLL_insert (clients_head,
670 clients_tail,
671 cr);
672 return cr;
673}
674
675
676/**
647 * A client disconnected, clean up after it. 677 * A client disconnected, clean up after it.
648 * 678 *
649 * @param cls unused 679 * @param cls unused
650 * @param client handle of client that disconnected 680 * @param client handle of client that disconnected
681 * @param app_ctx our `struct ClientRecord`
651 */ 682 */
652static void 683static void
653client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) 684client_disconnect_cb (void *cls,
685 struct GNUNET_SERVICE_Client *client,
686 void *app_ctx)
654{ 687{
655 struct ClientRecord *cr; 688 struct ClientRecord *cr = app_ctx;
656 struct RequestRecord *rr; 689 struct RequestRecord *rr;
657 unsigned int i;
658 unsigned int j;
659 690
660 for (cr = clients_head; NULL != cr; cr = cr->next) 691 GNUNET_CONTAINER_DLL_remove (clients_head,
692 clients_tail,
693 cr);
694 for (unsigned int i=0;i<UINT16_MAX;i++)
661 { 695 {
662 if (cr->client == client) 696 rr = &requests[i];
697 if (0 == rr->client_wait_list_length)
698 continue; /* not in use */
699 for (unsigned int j=0;j<rr->client_wait_list_length;j++)
663 { 700 {
664 GNUNET_SERVER_client_drop (client); 701 if (rr->client_wait_list[j] == cr)
665 GNUNET_CONTAINER_DLL_remove (clients_head,
666 clients_tail,
667 cr);
668 for (i=0;i<UINT16_MAX;i++)
669 { 702 {
670 rr = &requests[i]; 703 rr->client_wait_list[j] = NULL;
671 if (0 == rr->client_wait_list_length) 704 next_phase (rr);
672 continue; /* not in use */
673 for (j=0;j<rr->client_wait_list_length;j++)
674 {
675 if (rr->client_wait_list[j] == cr)
676 {
677 rr->client_wait_list[j] = NULL;
678 next_phase (rr);
679 }
680 }
681 } 705 }
682 GNUNET_free (cr);
683 return;
684 } 706 }
685 } 707 }
708 GNUNET_free (cr);
686} 709}
687 710
688 711
@@ -723,7 +746,9 @@ process_dns_result (void *cls,
723 (unsigned long long) rr->request_id); 746 (unsigned long long) rr->request_id);
724 GNUNET_free_non_null (rr->payload); 747 GNUNET_free_non_null (rr->payload);
725 rr->payload = GNUNET_malloc (r); 748 rr->payload = GNUNET_malloc (r);
726 GNUNET_memcpy (rr->payload, dns, r); 749 GNUNET_memcpy (rr->payload,
750 dns,
751 r);
727 rr->payload_length = r; 752 rr->payload_length = r;
728 next_phase (rr); 753 next_phase (rr);
729} 754}
@@ -732,56 +757,51 @@ process_dns_result (void *cls,
732/** 757/**
733 * We got a new client. Make sure all new DNS requests pass by its desk. 758 * We got a new client. Make sure all new DNS requests pass by its desk.
734 * 759 *
735 * @param cls unused 760 * @param cls the client
736 * @param client the new client 761 * @param reg the init message
737 * @param message the init message (unused)
738 */ 762 */
739static void 763static void
740handle_client_init (void *cls GNUNET_UNUSED, 764handle_client_init (void *cls,
741 struct GNUNET_SERVER_Client *client, 765 const struct GNUNET_DNS_Register *reg)
742 const struct GNUNET_MessageHeader *message)
743{ 766{
744 struct ClientRecord *cr; 767 struct ClientRecord *cr = cls;
745 const struct GNUNET_DNS_Register *reg = (const struct GNUNET_DNS_Register*) message;
746 768
747 cr = GNUNET_new (struct ClientRecord);
748 cr->client = client;
749 cr->flags = (enum GNUNET_DNS_Flags) ntohl (reg->flags); 769 cr->flags = (enum GNUNET_DNS_Flags) ntohl (reg->flags);
750 GNUNET_SERVER_client_keep (client); 770 GNUNET_SERVICE_client_continue (cr->client);
751 GNUNET_CONTAINER_DLL_insert (clients_head,
752 clients_tail,
753 cr);
754 GNUNET_SERVER_notification_context_add (nc, client);
755 GNUNET_SERVER_receive_done (client, GNUNET_OK);
756} 771}
757 772
758 773
759/** 774/**
760 * We got a response from a client. 775 * Check a response from a client.
761 * 776 *
762 * @param cls unused 777 * @param cls the client
763 * @param client the client 778 * @param resp the response
764 * @param message the response 779 * @return #GNUNET_OK (always fine)
780 */
781static int
782check_client_response (void *cls,
783 const struct GNUNET_DNS_Response *resp)
784{
785 return GNUNET_OK; /* any payload is acceptable */
786}
787
788
789/**
790 * Handle a response from a client.
791 *
792 * @param cls the client
793 * @param resp the response
765 */ 794 */
766static void 795static void
767handle_client_response (void *cls GNUNET_UNUSED, 796handle_client_response (void *cls,
768 struct GNUNET_SERVER_Client *client, 797 const struct GNUNET_DNS_Response *resp)
769 const struct GNUNET_MessageHeader *message)
770{ 798{
771 const struct GNUNET_DNS_Response *resp; 799 struct ClientRecord *cr = cls;
772 struct RequestRecord *rr; 800 struct RequestRecord *rr;
773 unsigned int i;
774 uint16_t msize; 801 uint16_t msize;
775 uint16_t off; 802 uint16_t off;
776 803
777 msize = ntohs (message->size); 804 msize = ntohs (resp->header.size);
778 if (msize < sizeof (struct GNUNET_DNS_Response))
779 {
780 GNUNET_break (0);
781 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
782 return;
783 }
784 resp = (const struct GNUNET_DNS_Response*) message;
785 off = (uint16_t) resp->request_id; 805 off = (uint16_t) resp->request_id;
786 rr = &requests[off]; 806 rr = &requests[off];
787 LOG (GNUNET_ERROR_TYPE_DEBUG, 807 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -791,15 +811,16 @@ handle_client_response (void *cls GNUNET_UNUSED,
791 { 811 {
792 GNUNET_STATISTICS_update (stats, 812 GNUNET_STATISTICS_update (stats,
793 gettext_noop ("# Client response discarded (no matching request)"), 813 gettext_noop ("# Client response discarded (no matching request)"),
794 1, GNUNET_NO); 814 1,
795 GNUNET_SERVER_receive_done (client, GNUNET_OK); 815 GNUNET_NO);
816 GNUNET_SERVICE_client_continue (cr->client);
796 return; 817 return;
797 } 818 }
798 for (i=0;i<rr->client_wait_list_length;i++) 819 for (unsigned int i=0;i<rr->client_wait_list_length;i++)
799 { 820 {
800 if (NULL == rr->client_wait_list[i]) 821 if (NULL == rr->client_wait_list[i])
801 continue; 822 continue;
802 if (rr->client_wait_list[i]->client != client) 823 if (rr->client_wait_list[i] != cr)
803 continue; 824 continue;
804 rr->client_wait_list[i] = NULL; 825 rr->client_wait_list[i] = NULL;
805 switch (ntohl (resp->drop_flag)) 826 switch (ntohl (resp->drop_flag))
@@ -816,7 +837,7 @@ handle_client_response (void *cls GNUNET_UNUSED,
816 (RP_RESPONSE_MONITOR == rr->phase) ) 837 (RP_RESPONSE_MONITOR == rr->phase) )
817 { 838 {
818 GNUNET_break (0); 839 GNUNET_break (0);
819 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 840 GNUNET_SERVICE_client_drop (cr->client);
820 next_phase (rr); 841 next_phase (rr);
821 return; 842 return;
822 } 843 }
@@ -846,13 +867,13 @@ handle_client_response (void *cls GNUNET_UNUSED,
846 break; 867 break;
847 } 868 }
848 next_phase (rr); 869 next_phase (rr);
849 GNUNET_SERVER_receive_done (client, GNUNET_OK); 870 GNUNET_SERVICE_client_continue (cr->client);
850 return; 871 return;
851 } 872 }
852 /* odd, client was not on our list for the request, that ought 873 /* odd, client was not on our list for the request, that ought
853 to be an error */ 874 to be an error */
854 GNUNET_break (0); 875 GNUNET_break (0);
855 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 876 GNUNET_SERVICE_client_drop (cr->client);
856} 877}
857 878
858 879
@@ -1019,20 +1040,14 @@ process_helper_messages (void *cls GNUNET_UNUSED, void *client,
1019 1040
1020/** 1041/**
1021 * @param cls closure 1042 * @param cls closure
1022 * @param server the initialized server
1023 * @param cfg_ configuration to use 1043 * @param cfg_ configuration to use
1044 * @param service the initialized service
1024 */ 1045 */
1025static void 1046static void
1026run (void *cls, struct GNUNET_SERVER_Handle *server, 1047run (void *cls,
1027 const struct GNUNET_CONFIGURATION_Handle *cfg_) 1048 const struct GNUNET_CONFIGURATION_Handle *cfg_,
1049 struct GNUNET_SERVICE_Handle *service)
1028{ 1050{
1029 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1030 /* callback, cls, type, size */
1031 {&handle_client_init, NULL, GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT,
1032 sizeof (struct GNUNET_DNS_Register)},
1033 {&handle_client_response, NULL, GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE, 0},
1034 {NULL, NULL, 0, 0}
1035 };
1036 char *ifc_name; 1051 char *ifc_name;
1037 char *ipv4addr; 1052 char *ipv4addr;
1038 char *ipv4mask; 1053 char *ipv4mask;
@@ -1046,7 +1061,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1046 1061
1047 cfg = cfg_; 1062 cfg = cfg_;
1048 stats = GNUNET_STATISTICS_create ("dns", cfg); 1063 stats = GNUNET_STATISTICS_create ("dns", cfg);
1049 nc = GNUNET_SERVER_notification_context_create (server, 1);
1050 GNUNET_SCHEDULER_add_shutdown (&cleanup_task, 1064 GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
1051 cls); 1065 cls);
1052 dns_exit = NULL; 1066 dns_exit = NULL;
@@ -1067,11 +1081,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1067 } 1081 }
1068 dnsstub = GNUNET_DNSSTUB_start (dns_exit); 1082 dnsstub = GNUNET_DNSSTUB_start (dns_exit);
1069 GNUNET_free_non_null (dns_exit); 1083 GNUNET_free_non_null (dns_exit);
1070 GNUNET_SERVER_add_handlers (server,
1071 handlers);
1072 GNUNET_SERVER_disconnect_notify (server,
1073 &client_disconnect,
1074 NULL);
1075 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-dns"); 1084 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-dns");
1076 if (GNUNET_YES != 1085 if (GNUNET_YES !=
1077 GNUNET_OS_check_helper_binary (binary, 1086 GNUNET_OS_check_helper_binary (binary,
@@ -1156,23 +1165,41 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1156 1165
1157 1166
1158/** 1167/**
1159 * The main function for the dns service. 1168 * Define "main" method using service macro.
1160 *
1161 * @param argc number of arguments from the command line
1162 * @param argv command line arguments
1163 * @return 0 ok, 1 on error
1164 */ 1169 */
1165int 1170GNUNET_SERVICE_MAIN
1166main (int argc, char *const *argv) 1171("dns",
1167{ 1172 GNUNET_SERVICE_OPTION_NONE,
1168 /* make use of SGID capabilities on POSIX */ 1173 &run,
1169 /* FIXME: this might need a port on systems without 'getresgid' */ 1174 &client_connect_cb,
1175 &client_disconnect_cb,
1176 NULL,
1177 GNUNET_MQ_hd_fixed_size (client_init,
1178 GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT,
1179 struct GNUNET_DNS_Register,
1180 NULL),
1181 GNUNET_MQ_hd_var_size (client_response,
1182 GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE,
1183 struct GNUNET_DNS_Response,
1184 NULL),
1185 GNUNET_MQ_handler_end ());
1186
1187
1188/* FIXME: this might need a port on systems without 'getresgid' */
1170#if HAVE_GETRESGID 1189#if HAVE_GETRESGID
1190/**
1191 * Enable use of SGID capabilities on POSIX
1192 */
1193void __attribute__ ((constructor))
1194GNUNET_DNS_init ()
1195{
1171 gid_t rgid; 1196 gid_t rgid;
1172 gid_t egid; 1197 gid_t egid;
1173 gid_t sgid; 1198 gid_t sgid;
1174 1199
1175 if (-1 == getresgid (&rgid, &egid, &sgid)) 1200 if (-1 == getresgid (&rgid,
1201 &egid,
1202 &sgid))
1176 { 1203 {
1177 fprintf (stderr, 1204 fprintf (stderr,
1178 "getresgid failed: %s\n", 1205 "getresgid failed: %s\n",
@@ -1180,14 +1207,14 @@ main (int argc, char *const *argv)
1180 } 1207 }
1181 else if (sgid != rgid) 1208 else if (sgid != rgid)
1182 { 1209 {
1183 if (-1 == setregid (sgid, sgid)) 1210 if (-1 == setregid (sgid,
1184 fprintf (stderr, "setregid failed: %s\n", strerror (errno)); 1211 sgid))
1212 fprintf (stderr,
1213 "setregid failed: %s\n",
1214 strerror (errno));
1185 } 1215 }
1186#endif
1187 return (GNUNET_OK ==
1188 GNUNET_SERVICE_run (argc, argv, "dns", GNUNET_SERVICE_OPTION_NONE,
1189 &run, NULL)) ? global_ret : 1;
1190} 1216}
1217#endif
1191 1218
1192 1219
1193/* end of gnunet-service-dns.c */ 1220/* end of gnunet-service-dns.c */