GNUnet  0.11.x
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_dnsparser_lib.h>
28 #include <gnunet_gns_service.h>
29 #include <gnunet_dnsstub_lib.h>
30 #include "gns.h"
31 
35 #define TIMEOUT GNUNET_TIME_UNIT_MINUTES
36 
40 struct Request
41 {
46 
50  const void *addr;
51 
57 
62 
67 
73 
77  char *udp_msg;
78 
82  size_t addr_len;
83 
87  size_t udp_msg_size;
88 
93 };
94 
98 static in_addr_t address;
99 
103 static struct in6_addr address6;
104 
105 
110 
115 
120 
125 
129 static struct GNUNET_SCHEDULER_Task *t4;
130 
134 static struct GNUNET_SCHEDULER_Task *t6;
135 
139 static char *dns_ip;
140 
144 static unsigned int listen_port = 53;
145 
149 static const struct GNUNET_CONFIGURATION_Handle *cfg;
150 
151 
157 static void
158 do_shutdown (void *cls)
159 {
160  (void) cls;
161  if (NULL != t4)
162  {
164  t4 = NULL;
165  }
166  if (NULL != t6)
167  {
169  t6 = NULL;
170  }
171  if (NULL != listen_socket4)
172  {
173  GNUNET_NETWORK_socket_close (listen_socket4);
174  listen_socket4 = NULL;
175  }
176  if (NULL != listen_socket6)
177  {
178  GNUNET_NETWORK_socket_close (listen_socket6);
179  listen_socket6 = NULL;
180  }
181  if (NULL != gns)
182  {
183  GNUNET_GNS_disconnect (gns);
184  gns = NULL;
185  }
186  if (NULL != dns_stub)
187  {
188  GNUNET_DNSSTUB_stop (dns_stub);
189  dns_stub = NULL;
190  }
191 }
192 
193 
200 static void
202 {
203  unsigned int idx = request->packet->num_answers;
204  unsigned int r_idx;
205  struct GNUNET_DNSPARSER_Record tmp_answer;
206 
207  while (0 != idx)
208  {
210  request->packet->num_answers);
211  idx--;
212  tmp_answer = request->packet->answers[idx];
213  memcpy (&request->packet->answers[idx], &request->packet->answers[r_idx],
214  sizeof (struct GNUNET_DNSPARSER_Record));
215  memcpy (&request->packet->answers[r_idx], &tmp_answer,
216  sizeof (struct GNUNET_DNSPARSER_Record));
217  }
218 }
219 
220 
226 static void
228 {
229  char *buf;
230  size_t size;
231  ssize_t sret;
232 
233  shuffle_answers (request);
234  if (GNUNET_SYSERR ==
235  GNUNET_DNSPARSER_pack (request->packet,
236  UINT16_MAX /* is this not too much? */,
237  &buf,
238  &size))
239  {
241  _ ("Failed to pack DNS response into UDP packet!\n"));
242  }
243  else
244  {
245  sret = GNUNET_NETWORK_socket_sendto (request->lsock,
246  buf,
247  size,
248  request->addr,
249  request->addr_len);
250  if ((sret < 0) ||
251  (size != (size_t) sret))
253  "sendto");
254  GNUNET_free (buf);
255  }
258  GNUNET_free (request->udp_msg);
259  GNUNET_free (request);
260 }
261 
262 
268 static void
269 do_timeout (void *cls)
270 {
271  struct Request *request = cls;
272 
273  if (NULL != request->packet)
275  if (NULL != request->lookup)
277  if (NULL != request->dns_lookup)
279  GNUNET_free (request->udp_msg);
280  GNUNET_free (request);
281 }
282 
283 
291 static void
293  const struct GNUNET_TUN_DnsHeader *dns,
294  size_t r)
295 {
296  struct Request *request = cls;
297 
298  if (NULL == dns)
299  {
300  /* DNSSTUB gave up, so we trigger timeout early */
302  do_timeout (request);
303  return;
304  }
305  if (request->original_request_id != dns->id)
306  {
307  /* for a another query, ignore */
308  return;
309  }
310  request->packet = GNUNET_DNSPARSER_parse ((char *) dns,
311  r);
313  send_response (request);
314 }
315 
316 
325 static void
326 result_processor (void *cls,
327  int was_gns,
328  uint32_t rd_count,
329  const struct GNUNET_GNSRECORD_Data *rd)
330 {
331  struct Request *request = cls;
333  struct GNUNET_DNSPARSER_Record rec;
334 
335  request->lookup = NULL;
336  if (GNUNET_NO == was_gns)
337  {
338  /* TLD not configured for GNS, fall back to DNS */
340  "Using DNS resolver IP `%s' to resolve `%s'\n",
341  dns_ip,
342  request->packet->queries[0].name);
343  request->original_request_id = request->packet->id;
345  request->packet = NULL;
346  request->dns_lookup = GNUNET_DNSSTUB_resolve (dns_stub,
347  request->udp_msg,
348  request->udp_msg_size,
350  request);
351  return;
352  }
353  packet = request->packet;
354  packet->flags.query_or_response = 1;
356  packet->flags.checking_disabled = 0;
357  packet->flags.authenticated_data = 1;
358  packet->flags.zero = 0;
359  packet->flags.recursion_available = 1;
360  packet->flags.message_truncated = 0;
361  packet->flags.authoritative_answer = 0;
362  // packet->flags.opcode = GNUNET_TUN_DNS_OPCODE_STATUS; // ???
363  for (uint32_t i = 0; i < rd_count; i++)
364  {
366  switch (rd[i].record_type)
367  {
369  GNUNET_assert (sizeof(struct in_addr) == rd[i].data_size);
370  rec.name = GNUNET_strdup (packet->queries[0].name);
373  rec.data.raw.data = GNUNET_new (struct in_addr);
374  GNUNET_memcpy (rec.data.raw.data,
375  rd[i].data,
376  rd[i].data_size);
377  rec.data.raw.data_len = sizeof(struct in_addr);
378  GNUNET_array_append (packet->answers,
379  packet->num_answers,
380  rec);
381  break;
382 
384  GNUNET_assert (sizeof(struct in6_addr) == rd[i].data_size);
385  rec.name = GNUNET_strdup (packet->queries[0].name);
386  rec.data.raw.data = GNUNET_new (struct in6_addr);
389  GNUNET_memcpy (rec.data.raw.data,
390  rd[i].data,
391  rd[i].data_size);
392  rec.data.raw.data_len = sizeof(struct in6_addr);
393  GNUNET_array_append (packet->answers,
394  packet->num_answers,
395  rec);
396  break;
397 
399  rec.name = GNUNET_strdup (packet->queries[0].name);
400  rec.data.hostname = GNUNET_strdup (rd[i].data);
404  rd[i].data,
405  rd[i].data_size);
406  GNUNET_array_append (packet->answers,
407  packet->num_answers,
408  rec);
409  break;
410 
411  default:
412  /* skip */
413  break;
414  }
415  }
416  send_response (request);
417 }
418 
419 
429 static void
431  const void *addr,
432  size_t addr_len,
433  const char *udp_msg,
434  size_t udp_msg_size)
435 {
436  struct Request *request;
438 
439  packet = GNUNET_DNSPARSER_parse (udp_msg,
440  udp_msg_size);
441  if (NULL == packet)
442  {
444  _ ("Cannot parse DNS request from %s\n"),
445  GNUNET_a2s (addr, addr_len));
446  return;
447  }
449  "Received request for `%s' with flags %u, #answers %d, #auth %d, #additional %d\n",
450  packet->queries[0].name,
451  (unsigned int) packet->flags.query_or_response,
452  (int) packet->num_answers,
453  (int) packet->num_authority_records,
454  (int) packet->num_additional_records);
455  if ((0 != packet->flags.query_or_response) ||
456  (0 != packet->num_answers) ||
457  (0 != packet->num_authority_records))
458  {
460  _ ("Received malformed DNS request from %s\n"),
461  GNUNET_a2s (addr, addr_len));
463  return;
464  }
465  if ((1 != packet->num_queries))
466  {
468  _ ("Received unsupported DNS request from %s\n"),
469  GNUNET_a2s (addr,
470  addr_len));
472  return;
473  }
474  request = GNUNET_malloc (sizeof(struct Request) + addr_len);
475  request->lsock = lsock;
476  request->packet = packet;
477  request->addr = &request[1];
478  request->addr_len = addr_len;
479  GNUNET_memcpy (&request[1],
480  addr,
481  addr_len);
482  request->udp_msg_size = udp_msg_size;
483  request->udp_msg = GNUNET_memdup (udp_msg,
484  udp_msg_size);
486  &do_timeout,
487  request);
489  "Calling GNS on `%s'\n",
490  packet->queries[0].name);
491  request->lookup = GNUNET_GNS_lookup_with_tld (gns,
492  packet->queries[0].name,
493  packet->queries[0].type,
496  request);
497 }
498 
499 
505 static void
506 read_dns4 (void *cls)
507 {
508  struct sockaddr_in v4;
509  socklen_t addrlen;
510  ssize_t size;
511  const struct GNUNET_SCHEDULER_TaskContext *tc;
512 
513  GNUNET_assert (listen_socket4 == cls);
515  listen_socket4,
516  &read_dns4,
517  listen_socket4);
520  return; /* shutdown? */
521  size = GNUNET_NETWORK_socket_recvfrom_amount (listen_socket4);
522  if (0 > size)
523  {
524  GNUNET_break (0);
525  return; /* read error!? */
526  }
527  {
528  char buf[size + 1];
529  ssize_t sret;
530 
531  addrlen = sizeof(v4);
532  sret = GNUNET_NETWORK_socket_recvfrom (listen_socket4,
533  buf,
534  size + 1,
535  (struct sockaddr *) &v4,
536  &addrlen);
537  if (0 > sret)
538  {
540  "recvfrom");
541  return;
542  }
543  GNUNET_break (size == sret);
544  handle_request (listen_socket4,
545  &v4,
546  addrlen,
547  buf,
548  size);
549  }
550 }
551 
552 
558 static void
559 read_dns6 (void *cls)
560 {
561  struct sockaddr_in6 v6;
562  socklen_t addrlen;
563  ssize_t size;
564  const struct GNUNET_SCHEDULER_TaskContext *tc;
565 
566  GNUNET_assert (listen_socket6 == cls);
568  listen_socket6,
569  &read_dns6,
570  listen_socket6);
573  return; /* shutdown? */
574  size = GNUNET_NETWORK_socket_recvfrom_amount (listen_socket6);
575  if (0 > size)
576  {
577  GNUNET_break (0);
578  return; /* read error!? */
579  }
580  {
581  char buf[size];
582  ssize_t sret;
583 
584  addrlen = sizeof(v6);
585  sret = GNUNET_NETWORK_socket_recvfrom (listen_socket6,
586  buf,
587  size,
588  (struct sockaddr *) &v6,
589  &addrlen);
590  if (0 > sret)
591  {
593  "recvfrom");
594  return;
595  }
596  GNUNET_break (size == sret);
597  handle_request (listen_socket6,
598  &v6,
599  addrlen,
600  buf,
601  size);
602  }
603 }
604 
605 
614 static void
615 run (void *cls,
616  char *const *args,
617  const char *cfgfile,
618  const struct GNUNET_CONFIGURATION_Handle *c)
619 {
620  char *addr_str;
621 
622  (void) cls;
623  (void) args;
624  (void) cfgfile;
625  cfg = c;
626  if (NULL == dns_ip)
627  {
629  _ ("No DNS server specified!\n"));
630  return;
631  }
633  NULL);
634  if (NULL == (gns = GNUNET_GNS_connect (cfg)))
635  return;
636  GNUNET_assert (NULL != (dns_stub = GNUNET_DNSSTUB_start (128)));
637  if (GNUNET_OK !=
638  GNUNET_DNSSTUB_add_dns_ip (dns_stub,
639  dns_ip))
640  {
641  GNUNET_DNSSTUB_stop (dns_stub);
642  GNUNET_GNS_disconnect (gns);
643  gns = NULL;
644  return;
645  }
646 
647  /* Get address to bind to */
649  "BIND_TO",
650  &addr_str))
651  {
652  // No address specified
654  "Don't know what to bind to...\n");
655  GNUNET_free (addr_str);
657  return;
658  }
659  if (1 != inet_pton (AF_INET, addr_str, &address))
660  {
662  "Unable to parse address %s\n",
663  addr_str);
664  GNUNET_free (addr_str);
666  return;
667  }
668  GNUNET_free (addr_str);
669  /* Get address to bind to */
671  "BIND_TO6",
672  &addr_str))
673  {
674  // No address specified
676  "Don't know what to bind6 to...\n");
677  GNUNET_free (addr_str);
679  return;
680  }
681  if (1 != inet_pton (AF_INET6, addr_str, &address6))
682  {
684  "Unable to parse IPv6 address %s\n",
685  addr_str);
686  GNUNET_free (addr_str);
688  return;
689  }
690  GNUNET_free (addr_str);
691 
692  listen_socket4 = GNUNET_NETWORK_socket_create (PF_INET,
693  SOCK_DGRAM,
694  IPPROTO_UDP);
695  if (NULL != listen_socket4)
696  {
697  struct sockaddr_in v4;
698 
699  memset (&v4, 0, sizeof(v4));
700  v4.sin_family = AF_INET;
701  v4.sin_addr.s_addr = address;
702 #if HAVE_SOCKADDR_IN_SIN_LEN
703  v4.sin_len = sizeof(v4);
704 #endif
705  v4.sin_port = htons (listen_port);
706  if (GNUNET_OK !=
707  GNUNET_NETWORK_socket_bind (listen_socket4,
708  (struct sockaddr *) &v4,
709  sizeof(v4)))
710  {
712  GNUNET_NETWORK_socket_close (listen_socket4);
713  listen_socket4 = NULL;
714  }
715  }
716  listen_socket6 = GNUNET_NETWORK_socket_create (PF_INET6,
717  SOCK_DGRAM,
718  IPPROTO_UDP);
719  if (NULL != listen_socket6)
720  {
721  struct sockaddr_in6 v6;
722 
723  memset (&v6, 0, sizeof(v6));
724  v6.sin6_family = AF_INET6;
725  v6.sin6_addr = address6;
726 #if HAVE_SOCKADDR_IN_SIN_LEN
727  v6.sin6_len = sizeof(v6);
728 #endif
729  v6.sin6_port = htons (listen_port);
730  if (GNUNET_OK !=
731  GNUNET_NETWORK_socket_bind (listen_socket6,
732  (struct sockaddr *) &v6,
733  sizeof(v6)))
734  {
736  GNUNET_NETWORK_socket_close (listen_socket6);
737  listen_socket6 = NULL;
738  }
739  }
740  if ((NULL == listen_socket4) &&
741  (NULL == listen_socket6))
742  {
743  GNUNET_GNS_disconnect (gns);
744  gns = NULL;
745  GNUNET_DNSSTUB_stop (dns_stub);
746  dns_stub = NULL;
747  return;
748  }
749  if (NULL != listen_socket4)
751  listen_socket4,
752  &read_dns4,
753  listen_socket4);
754  if (NULL != listen_socket6)
756  listen_socket6,
757  &read_dns6,
758  listen_socket6);
759 }
760 
761 
769 int
770 main (int argc,
771  char *const *argv)
772 {
773  struct GNUNET_GETOPT_CommandLineOption options[] = {
775  "dns",
776  "IP",
777  gettext_noop (
778  "IP of recursive DNS resolver to use (required)"),
779  &dns_ip),
781  "port",
782  "UDPPORT",
783  gettext_noop (
784  "UDP port to listen on for inbound DNS requests; default: 2853"),
785  &listen_port),
787  };
788  int ret;
789 
790  if (GNUNET_OK !=
791  GNUNET_STRINGS_get_utf8_args (argc, argv,
792  &argc, &argv))
793  return 2;
794  GNUNET_log_setup ("gnunet-dns2gns",
795  "WARNING",
796  NULL);
797  ret =
798  (GNUNET_OK ==
799  GNUNET_PROGRAM_run (argc, argv,
800  "gnunet-dns2gns",
801  _ ("GNUnet DNS-to-GNS proxy (a DNS server)"),
802  options,
803  &run, NULL)) ? 0 : 1;
804  GNUNET_free_nz ((void *) argv);
805  return ret;
806 }
807 
808 
809 /* end of gnunet-dns2gns.c */
Connection to the GNS service.
Definition: gns_api.h:35
struct GNUNET_DNSPARSER_Record * answers
Array of all answers in the packet, must contain "num_answers" entries.
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:752
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
unsigned int zero
Always zero.
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.
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
static unsigned int listen_port
UDP Port we listen on for inbound DNS requests.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_DNSPARSER_TYPE_CNAME
static void read_dns6(void *cls)
Task to read IPv6 DNS packets.
The reading socket is ready.
Context information passed to each scheduler task.
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1331
static char * dns_ip
IP of DNS server.
static void read_dns4(void *cls)
Task to read IPv4 DNS packets.
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
Definition: gns_tld_api.c:332
unsigned int return_code
See GNUNET_TUN_DNS_RETURN_CODE_ defines.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1459
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
int main(int argc, char *const *argv)
The main function for the dns2gns daemon.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_DNSSTUB_stop(struct GNUNET_DNSSTUB_Context *ctx)
Cleanup DNSSTUB resolver.
Definition: dnsstub.c:690
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:1257
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:423
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:591
int 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:485
uint16_t id
DNS ID (to match replies to requests).
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run.
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 ...
Definition: gns_tld_api.c:241
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
Definition: dnsparser.c:854
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
size_t data_size
Number of bytes in data.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Definition of a command line option.
static struct GNUNET_NETWORK_Handle * listen_socket4
Listen socket for IPv4.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
unsigned int recursion_available
Set to 1 if recursion is available (server -> client)
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
unsigned int num_answers
Number of answers in the packet, should be 0 for queries.
uint64_t abs_value_us
The actual value.
uint16_t id
Unique identifier for the request/response.
IPC messages between GNS API and GNS service.
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
unsigned int authoritative_answer
Set to 1 if this is an authoritative answer.
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.
const void * addr
Destination address to use.
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.
static void send_response(struct Request *request)
Send the response for the given request and clean up.
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
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.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
struct GNUNET_GNS_Handle * gns
Handle to GNS resolver.
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:1269
#define TIMEOUT
Timeout for DNS requests.
struct GNUNET_SCHEDULER_Task * timeout_task
Task run on timeout or shutdown to clean up without response.
unsigned int authenticated_data
Response has been cryptographically verified, RFC 4035.
unsigned int query_or_response
query:0, response:1
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
char * name
Name of the record that the query is for (0-terminated).
char * hostname
For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname.
const void * data
Binary value stored in the DNS record.
unsigned int num_additional_records
Number of additional records in the packet, should be 0 for queries.
static in_addr_t address
The address to bind to.
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:656
struct GNUNET_DNSSTUB_Context * GNUNET_DNSSTUB_start(unsigned int num_sockets)
Start a DNS stub resolver.
Definition: dnsstub.c:564
uint64_t expiration_time
Expiration time for the DNS record.
static struct GNUNET_SCHEDULER_Task * t4
Task for IPv4 socket.
void GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle)
Shutdown connection with the GNS service.
Definition: gns_api.c:290
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:850
static void do_timeout(void *cls)
Task run on timeout.
#define GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR
RFC 1035 codes.
static char buf[2048]
union GNUNET_DNSPARSER_Record::@24 data
Payload of the record (which one of these is valid depends on the &#39;type&#39;).
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
unsigned int message_truncated
Set to 1 if message is truncated.
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)...
struct GNUNET_GNS_Handle * GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the GNS service.
Definition: gns_api.c:268
A DNS response record.
Handle to the stub resolver.
Definition: dnsstub.c:123
struct GNUNET_DNSPARSER_Query * queries
Array of all queries in the packet, must contain "num_queries" entries.
struct GNUNET_DNSPARSER_Packet * packet
Initially, this is the DNS request, it will then be converted to the DNS response.
int 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.
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:504
#define GNUNET_free_nz(ptr)
Wrapper around free.
static unsigned int size
Size of the "table".
Definition: peer.c:67
size_t data_len
Number of bytes in data.
void * data
Binary record data.
unsigned int num_authority_records
Number of authoritative answers in the packet, should be 0 for queries.
size_t udp_msg_size
Number of bytes in udp_msg.
#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&#39;r...
struct GNUNET_TIME_Absolute expiration_time
When does the record expire?
Request we should make.
static void do_shutdown(void *cls)
Task run on shutdown.
#define GNUNET_DNSPARSER_TYPE_AAAA
configuration data
Definition: configuration.c:84
void GNUNET_DNSSTUB_resolve_cancel(struct GNUNET_DNSSTUB_RequestSocket *rs)
Cancel DNS resolution.
Definition: dnsstub.c:540
struct GNUNET_DNSSTUB_RequestSocket * dns_lookup
Our DNS request handle.
Easy-to-process, parsed version of a DNS packet.
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
size_t addr_len
Number of bytes in addr.
uint16_t dns_traffic_class
See GNUNET_TUN_DNS_CLASS_*.
static struct GNUNET_NETWORK_Handle * listen_socket6
Listen socket for IPv6.
struct GNUNET_NETWORK_Handle * lsock
Socket to use for sending the reply.
handle to a socket
Definition: network.c:52
int GNUNET_PROGRAM_run(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, parse options).
Definition: program.c:372
char * name
Name of the record that the query is for (0-terminated).
unsigned int num_queries
Number of queries in the packet.
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:727
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
Defaults, look in cache, then in DHT.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
struct GNUNET_TUN_DnsFlags flags
Bitfield of DNS flags.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
UDP socket we are using for sending DNS requests to the Internet.
Definition: dnsstub.c:44
static void shuffle_answers(struct Request *request)
Shuffle answers Fisher-Yates (aka Knuth) Shuffle.
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:754
Handle to a lookup request.
Definition: gns_tld_api.c:44
uint32_t data
The data value.
struct GNUNET_GNS_LookupWithTldRequest * lookup
Our GNS request handle.
struct GNUNET_DNSSTUB_Context * dns_stub
Stub resolver.
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
#define GNUNET_DNSPARSER_TYPE_A
char * udp_msg
Original UDP request message.
unsigned int checking_disabled
See RFC 4035.
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
static struct GNUNET_SCHEDULER_Task * t6
Task for IPv6 socket.
static struct in6_addr address6
The IPv6 address to bind to.
#define gettext_noop(String)
Definition: gettext.h:69
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:912
uint16_t original_request_id
ID of the original request.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972