GNUnet 0.28.0-dev.3-7-g31e20e2e6
 
Loading...
Searching...
No Matches
gnunet-dns2gns.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
25#include "platform.h"
26#include <gnunet_util_lib.h>
27#include <gnunet_gns_service.h>
28#include "gnunet_vpn_service.h"
29
33#define TIMEOUT GNUNET_TIME_UNIT_MINUTES
34
38#define VPN_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
39
40
41struct Request;
42
47{
52
57
61 unsigned int rd_count;
62
66 char *rd_data;
67
71 ssize_t rd_data_size;
72};
73
74
78struct Request
79{
84
88 const void *addr;
89
95
100
105
111
116
120 char *udp_msg;
121
125 size_t addr_len;
126
131
136
137};
138
142static in_addr_t address;
143
147static struct in6_addr address6;
148
149
154
159
164
169
174
179
184
188static char *dns_ip;
189
193static unsigned long long listen_port = 53;
194
198static const struct GNUNET_CONFIGURATION_Handle *cfg;
199
200
206static void
207do_shutdown (void *cls)
208{
209 (void) cls;
210 if (NULL != t4)
211 {
213 t4 = NULL;
214 }
215 if (NULL != t6)
216 {
218 t6 = NULL;
219 }
220 if (NULL != listen_socket4)
221 {
223 listen_socket4 = NULL;
224 }
225 if (NULL != listen_socket6)
226 {
228 listen_socket6 = NULL;
229 }
230 if (NULL != gns)
231 {
233 gns = NULL;
234 }
235 if (NULL != vpn_handle)
236 {
238 vpn_handle = NULL;
239 }
240 if (NULL != dns_stub)
241 {
243 dns_stub = NULL;
244 }
245}
246
247
254static void
256{
257 unsigned int idx = request->packet->num_answers;
258 unsigned int r_idx;
259 struct GNUNET_DNSPARSER_Record tmp_answer;
260
261 while (0 != idx)
262 {
263 r_idx = GNUNET_CRYPTO_random_u32 (request->packet->num_answers);
264 idx--;
265 tmp_answer = request->packet->answers[idx];
266 memcpy (&request->packet->answers[idx], &request->packet->answers[r_idx],
267 sizeof (struct GNUNET_DNSPARSER_Record));
268 memcpy (&request->packet->answers[r_idx], &tmp_answer,
269 sizeof (struct GNUNET_DNSPARSER_Record));
270 }
271}
272
273
279static void
281{
282 char *buf;
283 size_t size;
284 ssize_t sret;
285
287 if (GNUNET_SYSERR ==
289 UINT16_MAX /* is this not too much? */,
290 &buf,
291 &size))
292 {
294 _ ("Failed to pack DNS response into UDP packet!\n"));
295 }
296 else
297 {
299 buf,
300 size,
301 request->addr,
302 request->addr_len);
303 if ((sret < 0) ||
304 (size != (size_t) sret))
306 "sendto");
307 GNUNET_free (buf);
308 }
309 GNUNET_SCHEDULER_cancel (request->timeout_task);
311 GNUNET_free (request->udp_msg);
313}
314
315
321static void
322do_timeout (void *cls)
323{
324 struct Request *request = cls;
325 struct VpnContext *vpn_ctx;
326
327 if (NULL != request->packet)
329 if (NULL != request->lookup)
331 if (NULL != request->dns_lookup)
333 GNUNET_free (request->udp_msg);
334 if (NULL != (vpn_ctx = request->vpn_ctx))
335 {
337 GNUNET_free (vpn_ctx->rd_data);
338 GNUNET_free (vpn_ctx);
339 }
341}
342
343
351static void
353 const struct GNUNET_TUN_DnsHeader *dns,
354 size_t r)
355{
356 struct Request *request = cls;
357
358 if (NULL == dns)
359 {
360 /* DNSSTUB gave up, so we trigger timeout early */
361 GNUNET_SCHEDULER_cancel (request->timeout_task);
363 return;
364 }
365 if (request->original_request_id != dns->id)
366 {
367 /* for a another query, ignore */
368 return;
369 }
370 request->packet = GNUNET_DNSPARSER_parse ((char *) dns,
371 r);
372 if (NULL == request->packet)
373 {
375 _ ("Failed to parse DNS response!\n"));
376 GNUNET_SCHEDULER_cancel (request->timeout_task);
378 return;
379 }
382}
383
384
399static void
401 int af,
402 const void *vaddress)
403{
404 struct VpnContext *vpn_ctx = cls;
405 struct Request *request = vpn_ctx->request;
406 struct GNUNET_GNSRECORD_Data rd[vpn_ctx->rd_count];
407 unsigned int i;
408
409 vpn_ctx->vpn_request = NULL;
410 request->vpn_ctx = NULL;
413 (size_t) vpn_ctx->rd_data_size,
414 vpn_ctx->rd_data,
415 vpn_ctx->rd_count,
416 rd));
417 for (i = 0; i < vpn_ctx->rd_count; i++)
418 {
420 {
421 switch (af)
422 {
423 case AF_INET:
425 rd[i].data_size = sizeof(struct in_addr);
428 rd[i].flags = 0;
429 rd[i].data = vaddress;
430 break;
431
432 case AF_INET6:
436 rd[i].flags = 0;
437 rd[i].data = vaddress;
438 rd[i].data_size = sizeof(struct in6_addr);
439 break;
440
441 default:
442 GNUNET_assert (0);
443 }
444 break;
445 }
446 }
447 GNUNET_assert (i < vpn_ctx->rd_count);
448 if (0 == vpn_ctx->rd_count)
450 _ ("VPN returned empty result for `%s'\n"),
451 request->packet->queries[0].name);
453 GNUNET_free (vpn_ctx->rd_data);
454 GNUNET_free (vpn_ctx);
455}
456
457
466static void
468 int was_gns,
469 uint32_t rd_count,
470 const struct GNUNET_GNSRECORD_Data *rd)
471{
472 struct Request *request = cls;
473 struct GNUNET_DNSPARSER_Packet *packet;
474 struct GNUNET_DNSPARSER_Record rec;
475 struct VpnContext *vpn_ctx;
476 const struct GNUNET_TUN_GnsVpnRecord *vpn;
477 const char *vname;
478 struct GNUNET_HashCode vhash;
479 int af;
480
481 request->lookup = NULL;
482 if (GNUNET_NO == was_gns)
483 {
484 /* TLD not configured for GNS, fall back to DNS */
486 "Using DNS resolver IP `%s' to resolve `%s'\n",
487 dns_ip,
488 request->packet->queries[0].name);
489 request->original_request_id = request->packet->id;
491 request->packet = NULL;
493 request->udp_msg,
494 request->udp_msg_size,
496 request);
497 return;
498 }
499 packet = request->packet;
500 packet->flags.query_or_response = 1;
502 packet->flags.checking_disabled = 0;
503 packet->flags.authenticated_data = 1;
504 packet->flags.zero = 0;
505 packet->flags.recursion_available = 1;
506 packet->flags.message_truncated = 0;
507 packet->flags.authoritative_answer = 0;
508 // packet->flags.opcode = GNUNET_TUN_DNS_OPCODE_STATUS; // ???
509 for (uint32_t i = 0; i < rd_count; i++)
510 {
512 switch (rd[i].record_type)
513 {
515 GNUNET_assert (sizeof(struct in_addr) == rd[i].data_size);
516 rec.name = GNUNET_strdup (packet->queries[0].name);
519 rec.data.raw.data = GNUNET_new (struct in_addr);
521 rd[i].data,
522 rd[i].data_size);
523 rec.data.raw.data_len = sizeof(struct in_addr);
525 packet->num_answers,
526 rec);
527 break;
528
530 GNUNET_assert (sizeof(struct in6_addr) == rd[i].data_size);
531 rec.name = GNUNET_strdup (packet->queries[0].name);
532 rec.data.raw.data = GNUNET_new (struct in6_addr);
536 rd[i].data,
537 rd[i].data_size);
538 rec.data.raw.data_len = sizeof(struct in6_addr);
540 packet->num_answers,
541 rec);
542 break;
543
545 rec.name = GNUNET_strdup (packet->queries[0].name);
546 rec.data.hostname = GNUNET_strdup (rd[i].data);
550 rd[i].data,
551 rd[i].data_size);
553 packet->num_answers,
554 rec);
555 break;
557 if ((GNUNET_DNSPARSER_TYPE_A != request->packet->queries[0].type) &&
558 (GNUNET_DNSPARSER_TYPE_AAAA != request->packet->queries[0].type))
559 break;
560 af = (GNUNET_DNSPARSER_TYPE_A == request->packet->queries[0].type) ?
561 AF_INET :
562 AF_INET6;
563 if (sizeof(struct GNUNET_TUN_GnsVpnRecord) >
564 rd[i].data_size)
565 {
566 GNUNET_break_op (0);
567 break;
568 }
569 vpn = (const struct GNUNET_TUN_GnsVpnRecord *) rd[i].data;
570 vname = (const char *) &vpn[1];
571 if ('\0' != vname[rd[i].data_size - 1 - sizeof(struct
573 ])
574 {
575 GNUNET_break_op (0);
576 break;
577 }
579 &vhash);
581 "Attempting VPN allocation for %s-%s (AF: %d, proto %d)\n",
582 GNUNET_i2s (&vpn->peer),
583 vname,
584 (int) af,
585 (int) ntohs (vpn->proto));
586 vpn_ctx = GNUNET_new (struct VpnContext);
587 request->vpn_ctx = vpn_ctx;
588 vpn_ctx->request = request;
590 rd);
591 if (vpn_ctx->rd_data_size < 0)
592 {
593 GNUNET_break_op (0);
594 GNUNET_free (vpn_ctx);
595 break;
596 }
597 vpn_ctx->rd_data = GNUNET_malloc ((size_t) vpn_ctx->rd_data_size);
598 vpn_ctx->rd_count = rd_count;
599 GNUNET_assert (vpn_ctx->rd_data_size ==
601 rd,
602 (size_t) vpn_ctx
603 ->rd_data_size,
604 vpn_ctx->rd_data));
606 af,
607 ntohs (
608 vpn->proto),
609 &vpn->peer,
610 &vhash,
612 (
614 &
616 vpn_ctx);
617 return;
618
619
620 default:
621 /* skip */
622 break;
623 }
624 }
626}
627
628
638static void
640 const void *addr,
641 size_t addr_len,
642 const char *udp_msg,
643 size_t udp_msg_size)
644{
645 struct Request *request;
646 struct GNUNET_DNSPARSER_Packet *packet;
647
648 packet = GNUNET_DNSPARSER_parse (udp_msg,
649 udp_msg_size);
650 if (NULL == packet)
651 {
653 _ ("Cannot parse DNS request from %s\n"),
654 GNUNET_a2s (addr, addr_len));
655 return;
656 }
658 "Received request for `%s' with flags %u, #answers %d, #auth %d, #additional %d\n",
659 packet->queries[0].name,
660 (unsigned int) packet->flags.query_or_response,
661 (int) packet->num_answers,
662 (int) packet->num_authority_records,
663 (int) packet->num_additional_records);
664 if ((0 != packet->flags.query_or_response) ||
665 (0 != packet->num_answers) ||
666 (0 != packet->num_authority_records))
667 {
669 _ ("Received malformed DNS request from %s\n"),
670 GNUNET_a2s (addr, addr_len));
672 return;
673 }
674 if ((1 != packet->num_queries))
675 {
677 _ ("Received unsupported DNS request from %s\n"),
678 GNUNET_a2s (addr,
679 addr_len));
681 return;
682 }
683 request = GNUNET_malloc (sizeof(struct Request) + addr_len);
684 request->lsock = lsock;
685 request->packet = packet;
686 request->addr = &request[1];
687 request->addr_len = addr_len;
689 addr,
690 addr_len);
691 request->udp_msg_size = udp_msg_size;
692 request->udp_msg = GNUNET_memdup (udp_msg,
693 udp_msg_size);
695 &do_timeout,
696 request);
698 "Calling GNS on `%s'\n",
699 packet->queries[0].name);
701 packet->queries[0].name,
702 packet->queries[0].type,
705 request);
706}
707
708
714static void
715read_dns4 (void *cls)
716{
717 struct sockaddr_in v4;
718 socklen_t addrlen;
719 ssize_t size;
720 const struct GNUNET_SCHEDULER_TaskContext *tc;
721
725 &read_dns4,
729 return; /* shutdown? */
731 if (0 > size)
732 {
733 GNUNET_break (0);
734 return; /* read error!? */
735 }
736 {
737 char buf[size + 1];
738 ssize_t sret;
739
740 addrlen = sizeof(v4);
742 buf,
743 size + 1,
744 (struct sockaddr *) &v4,
745 &addrlen);
746 if (0 > sret)
747 {
749 "recvfrom");
750 return;
751 }
752 GNUNET_break (size != sret);
754 &v4,
755 addrlen,
756 buf,
757 size);
758 }
759}
760
761
767static void
768read_dns6 (void *cls)
769{
770 struct sockaddr_in6 v6;
771 socklen_t addrlen;
772 ssize_t size;
773 const struct GNUNET_SCHEDULER_TaskContext *tc;
774
778 &read_dns6,
782 return; /* shutdown? */
784 if (0 > size)
785 {
786 GNUNET_break (0);
787 return; /* read error!? */
788 }
789 {
790 char buf[size];
791 ssize_t sret;
792
793 addrlen = sizeof(v6);
795 buf,
796 size,
797 (struct sockaddr *) &v6,
798 &addrlen);
799 if (0 > sret)
800 {
802 "recvfrom");
803 return;
804 }
805 GNUNET_break (size != sret);
807 &v6,
808 addrlen,
809 buf,
810 size);
811 }
812}
813
814
823static void
824run (void *cls,
825 char *const *args,
826 const char *cfgfile,
827 const struct GNUNET_CONFIGURATION_Handle *c)
828{
829 char *addr_str;
830
831 (void) cls;
832 (void) args;
833 (void) cfgfile;
834 cfg = c;
835 if (NULL == dns_ip)
836 {
838 _ ("No DNS server specified!\n"));
839 return;
840 }
842 NULL);
843 if (NULL == (gns = GNUNET_GNS_connect (cfg)))
844 return;
845 if (NULL == (vpn_handle = GNUNET_VPN_connect (cfg)))
846 return;
847 GNUNET_assert (NULL != (dns_stub = GNUNET_DNSSTUB_start (128)));
848 if (GNUNET_OK !=
850 dns_ip))
851 {
854 gns = NULL;
856 vpn_handle = NULL;
857 return;
858 }
859
860 /* Get address to bind to */
862 "BIND_TO",
863 &addr_str))
864 {
865 // No address specified
867 "Don't know what to bind to...\n");
868 GNUNET_free (addr_str);
870 return;
871 }
872 if (1 != inet_pton (AF_INET, addr_str, &address))
873 {
875 "Unable to parse address %s\n",
876 addr_str);
877 GNUNET_free (addr_str);
879 return;
880 }
881 GNUNET_free (addr_str);
882 /* Get address to bind to */
884 "BIND_TO6",
885 &addr_str))
886 {
887 // No address specified
889 "Don't know what to bind6 to...\n");
890 GNUNET_free (addr_str);
892 return;
893 }
894 if (1 != inet_pton (AF_INET6, addr_str, &address6))
895 {
897 "Unable to parse IPv6 address %s\n",
898 addr_str);
899 GNUNET_free (addr_str);
901 return;
902 }
903 GNUNET_free (addr_str);
905 "PORT",
906 &listen_port))
908 "Listening on %llu\n", listen_port);
909
911 SOCK_DGRAM,
912 IPPROTO_UDP);
913 if (NULL != listen_socket4)
914 {
915 struct sockaddr_in v4;
916
917 memset (&v4, 0, sizeof(v4));
918 v4.sin_family = AF_INET;
919 v4.sin_addr.s_addr = address;
920#if HAVE_SOCKADDR_IN_SIN_LEN
921 v4.sin_len = sizeof(v4);
922#endif
923 v4.sin_port = htons (listen_port);
924 if (GNUNET_OK !=
926 (struct sockaddr *) &v4,
927 sizeof(v4)))
928 {
931 listen_socket4 = NULL;
932 }
933 }
935 SOCK_DGRAM,
936 IPPROTO_UDP);
937 if (NULL != listen_socket6)
938 {
939 struct sockaddr_in6 v6;
940
941 memset (&v6, 0, sizeof(v6));
942 v6.sin6_family = AF_INET6;
943 v6.sin6_addr = address6;
944#if HAVE_SOCKADDR_IN_SIN_LEN
945 v6.sin6_len = sizeof(v6);
946#endif
947 v6.sin6_port = htons (listen_port);
948 if (GNUNET_OK !=
950 (struct sockaddr *) &v6,
951 sizeof(v6)))
952 {
955 listen_socket6 = NULL;
956 }
957 }
958 if ((NULL == listen_socket4) &&
959 (NULL == listen_socket6))
960 {
962 gns = NULL;
964 vpn_handle = NULL;
966 dns_stub = NULL;
967 return;
968 }
969 if (NULL != listen_socket4)
972 &read_dns4,
974 if (NULL != listen_socket6)
977 &read_dns6,
979}
980
981
989int
990main (int argc,
991 char *const *argv)
992{
995 "dns",
996 "IP",
998 "IP of recursive DNS resolver to use (required)"),
999 &dns_ip),
1001 };
1002 int ret;
1003
1004 GNUNET_log_setup ("gnunet-dns2gns",
1005 "WARNING",
1006 NULL);
1007 ret =
1008 (GNUNET_OK ==
1010 argc, argv,
1011 "gnunet-dns2gns",
1012 _ ("GNUnet DNS-to-GNS proxy (a DNS server)"),
1013 options,
1014 &run, NULL)) ? 0 : 1;
1015 return ret;
1016}
1017
1018
1019/* end of gnunet-dns2gns.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
#define gettext_noop(String)
Definition gettext.h:74
#define GNUNET_GNSRECORD_TYPE_VPN
VPN resolution.
static int ret
Final status code.
Definition gnunet-arm.c:93
static int do_shutdown
Set to GNUNET_YES if we are shutting down.
static char * data
The data to insert into the dht.
struct GNUNET_GNS_Handle * gns
Handle to GNS resolver.
static void dns_result_processor(void *cls, const struct GNUNET_TUN_DnsHeader *dns, size_t r)
Iterator called on obtained result for a DNS lookup.
static void read_dns6(void *cls)
Task to read IPv6 DNS packets.
static struct GNUNET_VPN_Handle * vpn_handle
Our handle to the vpn service.
static struct GNUNET_NETWORK_Handle * listen_socket6
Listen socket for IPv6.
static unsigned long long listen_port
UDP Port we listen on for inbound DNS requests.
static void do_timeout(void *cls)
Task run on timeout.
#define TIMEOUT
Timeout for DNS requests.
static char * dns_ip
IP of DNS server.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
static struct GNUNET_SCHEDULER_Task * t4
Task for IPv4 socket.
static void shuffle_answers(struct Request *request)
Shuffle answers Fisher-Yates (aka Knuth) Shuffle.
static void handle_request(struct GNUNET_NETWORK_Handle *lsock, const void *addr, size_t addr_len, const char *udp_msg, size_t udp_msg_size)
Handle DNS request.
static struct in6_addr address6
The IPv6 address to bind to.
static void vpn_allocation_cb(void *cls, int af, const void *vaddress)
Callback invoked from the VPN service once a redirection is available.
struct GNUNET_DNSSTUB_Context * dns_stub
Stub resolver.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run.
#define VPN_TIMEOUT
Default timeout for VPN redirections.
static void read_dns4(void *cls)
Task to read IPv4 DNS packets.
static struct GNUNET_NETWORK_Handle * listen_socket4
Listen socket for IPv4.
static void result_processor(void *cls, int was_gns, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Iterator called on obtained result for a GNS lookup.
static in_addr_t address
The address to bind to.
static void send_response(struct Request *request)
Send the response for the given request and clean up.
static struct GNUNET_SCHEDULER_Task * t6
Task for IPv6 socket.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static size_t data_size
Number of bytes in data.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition gnunet-vpn.c:40
API to the GNS service.
API to access the VPN service.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
uint32_t GNUNET_CRYPTO_random_u32(uint32_t i)
Produce a random value.
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
Definition dnsparser.c:967
#define GNUNET_DNSPARSER_TYPE_A
#define GNUNET_DNSPARSER_TYPE_CNAME
#define GNUNET_DNSPARSER_TYPE_AAAA
int GNUNET_DNSPARSER_pack(const struct GNUNET_DNSPARSER_Packet *p, uint16_t max, char **buf, size_t *buf_length)
Given a DNS packet p, generate the corresponding UDP payload.
Definition dnsparser.c:1417
struct GNUNET_DNSPARSER_Packet * GNUNET_DNSPARSER_parse(const char *udp_payload, size_t udp_payload_length)
Parse a UDP payload of a DNS packet in to a nice struct for further processing and manipulation.
Definition dnsparser.c:746
struct GNUNET_DNSSTUB_Context * GNUNET_DNSSTUB_start(unsigned int num_sockets)
Start a DNS stub resolver.
Definition dnsstub.c:585
int GNUNET_DNSSTUB_add_dns_ip(struct GNUNET_DNSSTUB_Context *ctx, const char *dns_ip)
Add nameserver for use by the DNSSTUB.
Definition dnsstub.c:612
void GNUNET_DNSSTUB_stop(struct GNUNET_DNSSTUB_Context *ctx)
Cleanup DNSSTUB resolver.
Definition dnsstub.c:704
struct GNUNET_DNSSTUB_RequestSocket * GNUNET_DNSSTUB_resolve(struct GNUNET_DNSSTUB_Context *ctx, const void *request, size_t request_len, GNUNET_DNSSTUB_ResultCallback rc, void *rc_cls)
Perform DNS resolution using our default IP from init.
Definition dnsstub.c:525
void GNUNET_DNSSTUB_resolve_cancel(struct GNUNET_DNSSTUB_RequestSocket *rs)
Cancel DNS resolution.
Definition dnsstub.c:561
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
void GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle)
Shutdown connection with the GNS service.
Definition gns_api.c:289
struct GNUNET_GNS_LookupWithTldRequest * GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle, const char *name, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor2 proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS, determining the zone using the TLD of the given ...
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
struct GNUNET_GNS_Handle * GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the GNS service.
Definition gns_api.c:267
@ GNUNET_GNS_LO_DEFAULT
Defaults, look in cache, then in DHT.
int GNUNET_GNSRECORD_records_deserialize(size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
Deserialize the given records to the given destination.
ssize_t GNUNET_GNSRECORD_records_serialize(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, size_t dest_size, char *dest)
Serialize the given records to the given destination buffer.
ssize_t GNUNET_GNSRECORD_records_get_size(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Calculate how many bytes we will need to serialize the given records.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages).
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition network.c:508
ssize_t GNUNET_NETWORK_socket_recvfrom(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length, struct sockaddr *src_addr, socklen_t *addrlen)
Read data from a socket (always non-blocking).
Definition network.c:687
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition network.c:832
ssize_t GNUNET_NETWORK_socket_recvfrom_amount(const struct GNUNET_NETWORK_Handle *desc)
How much data is available to be read on this descriptor?
Definition network.c:670
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
Definition network.c:439
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
Definition network.c:771
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:406
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:572
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition scheduler.c:1517
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition scheduler.c:764
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition scheduler.c:1345
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1283
@ GNUNET_SCHEDULER_REASON_READ_READY
The reading socket is ready.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition time.c:316
#define GNUNET_TUN_DNS_CLASS_INTERNET
A few common DNS classes (ok, only one is common, but I list a couple more to make it clear what we'r...
void GNUNET_TUN_service_name_to_hash(const char *service_name, struct GNUNET_HashCode *hc)
Hash the service name of a hosted service to the hash code that is used to identify the service on th...
Definition tun.c:38
#define GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR
RFC 1035 codes.
struct GNUNET_VPN_Handle * GNUNET_VPN_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the VPN service.
Definition vpn_api.c:490
struct GNUNET_VPN_RedirectionRequest * GNUNET_VPN_redirect_to_peer(struct GNUNET_VPN_Handle *vh, int result_af, uint8_t protocol, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HashCode *serv, struct GNUNET_TIME_Absolute expiration_time, GNUNET_VPN_AllocationCallback cb, void *cb_cls)
Tell the VPN that a forwarding to a particular peer offering a particular service is requested.
Definition vpn_api.c:388
void GNUNET_VPN_cancel_request(struct GNUNET_VPN_RedirectionRequest *rr)
Cancel redirection request with the service.
Definition vpn_api.c:375
void GNUNET_VPN_disconnect(struct GNUNET_VPN_Handle *vh)
Disconnect from the VPN service.
Definition vpn_api.c:512
static unsigned int size
Size of the "table".
Definition peer.c:68
#define _(String)
GNU gettext support macro.
Definition platform.h:179
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition scheduler.c:436
Easy-to-process, parsed version of a DNS packet.
struct GNUNET_DNSPARSER_Query * queries
Array of all queries in the packet, must contain "num_queries" entries.
unsigned int num_answers
Number of answers in the packet, should be 0 for queries.
struct GNUNET_TUN_DnsFlags flags
Bitfield of DNS flags.
struct GNUNET_DNSPARSER_Record * answers
Array of all answers in the packet, must contain "num_answers" entries.
unsigned int num_additional_records
Number of additional records in the packet, should be 0 for queries.
unsigned int num_authority_records
Number of authoritative answers in the packet, should be 0 for queries.
unsigned int num_queries
Number of queries in the packet.
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
char * name
Name of the record that the query is for (0-terminated).
void * data
Binary record data.
size_t data_len
Number of bytes in data.
A DNS response record.
uint16_t dns_traffic_class
See GNUNET_TUN_DNS_CLASS_*.
char * hostname
For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname.
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
struct GNUNET_TIME_Absolute expiration_time
When does the record expire?
union GNUNET_DNSPARSER_Record::@24 data
Payload of the record (which one of these is valid depends on the 'type').
char * name
Name of the record that the query is for (0-terminated).
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
Handle to the stub resolver.
Definition dnsstub.c:125
UDP socket we are using for sending DNS requests to the Internet.
Definition dnsstub.c:46
Definition of a command line option.
uint32_t record_type
Type of the GNS/DNS record.
const void * data
Binary value stored in the DNS record.
size_t data_size
Number of bytes in data.
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
uint64_t expiration_time
Expiration time for the DNS record.
Connection to the GNS service.
Definition gns_api.h:36
Handle to a lookup request.
Definition gns_tld_api.c:45
A 512-bit hashcode.
handle to a socket
Definition network.c:53
Context information passed to each scheduler task.
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.
Entry in list of pending tasks.
Definition scheduler.c:141
uint64_t abs_value_us
The actual value.
unsigned int checking_disabled
See RFC 4035.
unsigned int zero
Always zero.
unsigned int message_truncated
Set to 1 if message is truncated.
unsigned int query_or_response
query:0, response:1
unsigned int return_code
See GNUNET_TUN_DNS_RETURN_CODE_ defines.
unsigned int recursion_available
Set to 1 if recursion is available (server -> client)
unsigned int authenticated_data
Response has been cryptographically verified, RFC 4035.
unsigned int authoritative_answer
Set to 1 if this is an authoritative answer.
uint16_t id
Unique identifier for the request/response.
Payload of GNS VPN record.
struct GNUNET_PeerIdentity peer
The peer to contact.
uint16_t proto
The protocol to use.
Opaque VPN handle.
Definition vpn_api.c:35
Opaque redirection request handle.
Definition vpn_api.c:77
const void * addr
Target IP address for the redirection, or NULL for redirection to service.
Definition vpn_api.c:97
Request we should make.
struct GNUNET_NETWORK_Handle * lsock
Socket to use for sending the reply.
size_t udp_msg_size
Number of bytes in udp_msg.
struct GNUNET_SCHEDULER_Task * timeout_task
Task run on timeout or shutdown to clean up without response.
uint16_t original_request_id
ID of the original request.
struct GNUNET_DNSPARSER_Packet * packet
Initially, this is the DNS request, it will then be converted to the DNS response.
const void * addr
Destination address to use.
struct VpnContext * vpn_ctx
Vpn resolution context.
struct GNUNET_DNSSTUB_RequestSocket * dns_lookup
Our DNS request handle.
size_t addr_len
Number of bytes in addr.
struct GNUNET_GNS_LookupWithTldRequest * lookup
Our GNS request handle.
char * udp_msg
Original UDP request message.
Closure for vpn_allocation_cb.
struct GNUNET_VPN_RedirectionRequest * vpn_request
Handle to the VPN request that we were performing.
ssize_t rd_data_size
Number of bytes in rd_data.
struct Request * request
Which resolution process are we processing.
char * rd_data
Serialized records.
unsigned int rd_count
Number of records serialized in rd_data.