GNUnet  0.16.x
Data Structures | Macros | Functions | Variables
gnunet-dns2gns.c File Reference

DNS server that translates DNS requests to GNS. More...

#include "platform.h"
#include <gnunet_util_lib.h>
#include <gnunet_dnsparser_lib.h>
#include <gnunet_gns_service.h>
#include <gnunet_dnsstub_lib.h>
#include "gnunet_vpn_service.h"
#include "gns.h"
Include dependency graph for gnunet-dns2gns.c:

Go to the source code of this file.

Data Structures

struct  VpnContext
 Closure for vpn_allocation_cb. More...
 
struct  Request
 Request we should make. More...
 

Macros

#define TIMEOUT   GNUNET_TIME_UNIT_MINUTES
 Timeout for DNS requests. More...
 
#define VPN_TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
 Default timeout for VPN redirections. More...
 

Functions

static void do_shutdown (void *cls)
 Task run on shutdown. More...
 
static void shuffle_answers (struct Request *request)
 Shuffle answers Fisher-Yates (aka Knuth) Shuffle. More...
 
static void send_response (struct Request *request)
 Send the response for the given request and clean up. More...
 
static void do_timeout (void *cls)
 Task run on timeout. More...
 
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. More...
 
static void vpn_allocation_cb (void *cls, int af, const void *address)
 Callback invoked from the VPN service once a redirection is available. More...
 
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. More...
 
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. More...
 
static void read_dns4 (void *cls)
 Task to read IPv4 DNS packets. More...
 
static void read_dns6 (void *cls)
 Task to read IPv6 DNS packets. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Main function that will be run. More...
 
int main (int argc, char *const *argv)
 The main function for the dns2gns daemon. More...
 

Variables

static in_addr_t address
 The address to bind to. More...
 
static struct in6_addr address6
 The IPv6 address to bind to. More...
 
struct GNUNET_GNS_Handlegns
 Handle to GNS resolver. More...
 
static struct GNUNET_VPN_Handlevpn_handle
 Our handle to the vpn service. More...
 
struct GNUNET_DNSSTUB_Contextdns_stub
 Stub resolver. More...
 
static struct GNUNET_NETWORK_Handlelisten_socket4
 Listen socket for IPv4. More...
 
static struct GNUNET_NETWORK_Handlelisten_socket6
 Listen socket for IPv6. More...
 
static struct GNUNET_SCHEDULER_Taskt4
 Task for IPv4 socket. More...
 
static struct GNUNET_SCHEDULER_Taskt6
 Task for IPv6 socket. More...
 
static char * dns_ip
 IP of DNS server. More...
 
static unsigned int listen_port = 53
 UDP Port we listen on for inbound DNS requests. More...
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Configuration to use. More...
 

Detailed Description

DNS server that translates DNS requests to GNS.

Author
Christian Grothoff

Definition in file gnunet-dns2gns.c.

Macro Definition Documentation

◆ TIMEOUT

#define TIMEOUT   GNUNET_TIME_UNIT_MINUTES

Timeout for DNS requests.

Definition at line 36 of file gnunet-dns2gns.c.

◆ VPN_TIMEOUT

Default timeout for VPN redirections.

Definition at line 41 of file gnunet-dns2gns.c.

Function Documentation

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Task run on shutdown.

Cleans up everything.

Parameters
clsunused

Definition at line 210 of file gnunet-dns2gns.c.

211 {
212  (void) cls;
213  if (NULL != t4)
214  {
216  t4 = NULL;
217  }
218  if (NULL != t6)
219  {
221  t6 = NULL;
222  }
223  if (NULL != listen_socket4)
224  {
226  listen_socket4 = NULL;
227  }
228  if (NULL != listen_socket6)
229  {
231  listen_socket6 = NULL;
232  }
233  if (NULL != gns)
234  {
236  gns = NULL;
237  }
238  if (NULL != vpn_handle)
239  {
241  vpn_handle = NULL;
242  }
243  if (NULL != dns_stub)
244  {
246  dns_stub = NULL;
247  }
248 }
struct GNUNET_GNS_Handle * gns
Handle to GNS resolver.
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 struct GNUNET_SCHEDULER_Task * t4
Task for IPv4 socket.
struct GNUNET_DNSSTUB_Context * dns_stub
Stub resolver.
static struct GNUNET_NETWORK_Handle * listen_socket4
Listen socket for IPv4.
static struct GNUNET_SCHEDULER_Task * t6
Task for IPv6 socket.
void GNUNET_DNSSTUB_stop(struct GNUNET_DNSSTUB_Context *ctx)
Cleanup DNSSTUB resolver.
Definition: dnsstub.c:716
void GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle)
Shutdown connection with the GNS service.
Definition: gns_api.c:290
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:508
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:957
void GNUNET_VPN_disconnect(struct GNUNET_VPN_Handle *vh)
Disconnect from the VPN service.
Definition: vpn_api.c:534

References dns_stub, gns, GNUNET_DNSSTUB_stop(), GNUNET_GNS_disconnect(), GNUNET_NETWORK_socket_close(), GNUNET_SCHEDULER_cancel(), GNUNET_VPN_disconnect(), listen_socket4, listen_socket6, t4, t6, and vpn_handle.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shuffle_answers()

static void shuffle_answers ( struct Request request)
static

Shuffle answers Fisher-Yates (aka Knuth) Shuffle.

Parameters
requestcontext for the request (with answers)

Definition at line 258 of file gnunet-dns2gns.c.

259 {
260  unsigned int idx = request->packet->num_answers;
261  unsigned int r_idx;
262  struct GNUNET_DNSPARSER_Record tmp_answer;
263 
264  while (0 != idx)
265  {
267  request->packet->num_answers);
268  idx--;
269  tmp_answer = request->packet->answers[idx];
270  memcpy (&request->packet->answers[idx], &request->packet->answers[r_idx],
271  sizeof (struct GNUNET_DNSPARSER_Record));
272  memcpy (&request->packet->answers[r_idx], &tmp_answer,
273  sizeof (struct GNUNET_DNSPARSER_Record));
274  }
275 }
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
A DNS response record.

References GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), and request.

Referenced by send_response().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_response()

static void send_response ( struct Request request)
static

Send the response for the given request and clean up.

Parameters
requestcontext for the request.

Definition at line 284 of file gnunet-dns2gns.c.

285 {
286  char *buf;
287  size_t size;
288  ssize_t sret;
289 
291  if (GNUNET_SYSERR ==
293  UINT16_MAX /* is this not too much? */,
294  &buf,
295  &size))
296  {
298  _ ("Failed to pack DNS response into UDP packet!\n"));
299  }
300  else
301  {
302  sret = GNUNET_NETWORK_socket_sendto (request->lsock,
303  buf,
304  size,
305  request->addr,
306  request->addr_len);
307  if ((sret < 0) ||
308  (size != (size_t) sret))
310  "sendto");
311  GNUNET_free (buf);
312  }
313  GNUNET_SCHEDULER_cancel (request->timeout_task);
315  GNUNET_free (request->udp_msg);
317 }
static void shuffle_answers(struct Request *request)
Shuffle answers Fisher-Yates (aka Knuth) Shuffle.
static char buf[2048]
#define GNUNET_log(kind,...)
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
Definition: dnsparser.c:854
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
#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
#define GNUNET_free(ptr)
Wrapper around free.
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:794
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
const void * addr
Target IP address for the redirection, or NULL for redirection to service.
Definition: vpn_api.c:97

References _, GNUNET_VPN_RedirectionRequest::addr, buf, GNUNET_DNSPARSER_free_packet(), GNUNET_DNSPARSER_pack(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_sendto(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, request, shuffle_answers(), and size.

Referenced by dns_result_processor(), result_processor(), and vpn_allocation_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_timeout()

static void do_timeout ( void *  cls)
static

Task run on timeout.

Cleans up request.

Parameters
clsstruct Request * of the request to clean up

Definition at line 326 of file gnunet-dns2gns.c.

327 {
328  struct Request *request = cls;
329  struct VpnContext *vpn_ctx;
330 
331  if (NULL != request->packet)
333  if (NULL != request->lookup)
335  if (NULL != request->dns_lookup)
337  GNUNET_free (request->udp_msg);
338  if (NULL != (vpn_ctx = request->vpn_ctx))
339  {
341  GNUNET_free (vpn_ctx->rd_data);
342  GNUNET_free (vpn_ctx);
343  }
345 }
void GNUNET_DNSSTUB_resolve_cancel(struct GNUNET_DNSSTUB_RequestSocket *rs)
Cancel DNS resolution.
Definition: dnsstub.c:566
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
Definition: gns_tld_api.c:332
void GNUNET_VPN_cancel_request(struct GNUNET_VPN_RedirectionRequest *rr)
Cancel redirection request with the service.
Definition: vpn_api.c:375
Request we should make.
Closure for vpn_allocation_cb.
struct GNUNET_VPN_RedirectionRequest * vpn_request
Handle to the VPN request that we were performing.
char * rd_data
Serialized records.

References GNUNET_DNSPARSER_free_packet(), GNUNET_DNSSTUB_resolve_cancel(), GNUNET_free, GNUNET_GNS_lookup_with_tld_cancel(), GNUNET_VPN_cancel_request(), VpnContext::rd_data, request, and VpnContext::vpn_request.

Referenced by dns_result_processor(), and handle_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dns_result_processor()

static void dns_result_processor ( void *  cls,
const struct GNUNET_TUN_DnsHeader dns,
size_t  r 
)
static

Iterator called on obtained result for a DNS lookup.

Parameters
clsclosure
dnsthe DNS udp payload
rsize of the DNS payload

Definition at line 356 of file gnunet-dns2gns.c.

359 {
360  struct Request *request = cls;
361 
362  if (NULL == dns)
363  {
364  /* DNSSTUB gave up, so we trigger timeout early */
365  GNUNET_SCHEDULER_cancel (request->timeout_task);
367  return;
368  }
369  if (request->original_request_id != dns->id)
370  {
371  /* for a another query, ignore */
372  return;
373  }
374  request->packet = GNUNET_DNSPARSER_parse ((char *) dns,
375  r);
376  if (NULL == request->packet)
377  {
379  _ ("Failed to parse DNS response!\n"));
380  GNUNET_SCHEDULER_cancel (request->timeout_task);
382  return;
383  }
386 }
static void do_timeout(void *cls)
Task run on timeout.
static void send_response(struct Request *request)
Send the response for the given request and clean up.
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
uint16_t id
Unique identifier for the request/response.

References _, do_timeout(), GNUNET_DNSPARSER_parse(), GNUNET_DNSSTUB_resolve_cancel(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_TUN_DnsHeader::id, request, and send_response().

Referenced by result_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vpn_allocation_cb()

static void vpn_allocation_cb ( void *  cls,
int  af,
const void *  address 
)
static

Callback invoked from the VPN service once a redirection is available.

Provides the IP address that can now be used to reach the requested destination. Replaces the "VPN" record with the respective A/AAAA record and continues processing.

Parameters
clsclosure
afaddress family, AF_INET or AF_INET6; AF_UNSPEC on error; will match 'result_af' from the request
addressIP address (struct in_addr or struct in_addr6, depending on 'af') that the VPN allocated for the redirection; traffic to this IP will now be redirected to the specified target peer; NULL on error

Definition at line 403 of file gnunet-dns2gns.c.

406 {
407  struct VpnContext *vpn_ctx = cls;
408  struct Request *request = vpn_ctx->request;
409  struct GNUNET_GNSRECORD_Data rd[vpn_ctx->rd_count];
410  unsigned int i;
411 
412  vpn_ctx->vpn_request = NULL;
413  request->vpn_ctx = NULL;
416  (size_t) vpn_ctx->rd_data_size,
417  vpn_ctx->rd_data,
418  vpn_ctx->rd_count,
419  rd));
420  for (i = 0; i < vpn_ctx->rd_count; i++)
421  {
423  {
424  switch (af)
425  {
426  case AF_INET:
427  rd[i].record_type = GNUNET_DNSPARSER_TYPE_A;
428  rd[i].data_size = sizeof(struct in_addr);
429  rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (
431  rd[i].flags = 0;
432  rd[i].data = address;
433  break;
434 
435  case AF_INET6:
436  rd[i].record_type = GNUNET_DNSPARSER_TYPE_AAAA;
437  rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (
439  rd[i].flags = 0;
440  rd[i].data = address;
441  rd[i].data_size = sizeof(struct in6_addr);
442  break;
443 
444  default:
445  GNUNET_assert (0);
446  }
447  break;
448  }
449  }
450  GNUNET_assert (i < vpn_ctx->rd_count);
451  if (0 == vpn_ctx->rd_count)
453  _ ("VPN returned empty result for `%s'\n"),
454  request->packet->queries[0].name);
456  GNUNET_free (vpn_ctx->rd_data);
457  GNUNET_free (vpn_ctx);
458 }
#define GNUNET_GNSRECORD_TYPE_VPN
VPN resolution.
#define VPN_TIMEOUT
Default timeout for VPN redirections.
static in_addr_t address
The address to bind to.
@ GNUNET_OK
Definition: gnunet_common.h:95
#define GNUNET_DNSPARSER_TYPE_A
#define GNUNET_DNSPARSER_TYPE_AAAA
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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:315
uint32_t record_type
Type of the GNS/DNS record.
uint64_t abs_value_us
The actual value.
struct VpnContext * vpn_ctx
Vpn resulution context.
ssize_t rd_data_size
Number of bytes in rd_data.
struct Request * request
Which resolution process are we processing.
unsigned int rd_count
Number of records serialized in rd_data.

References _, GNUNET_TIME_Absolute::abs_value_us, address, GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_Data::flags, GNUNET_assert, GNUNET_DNSPARSER_TYPE_A, GNUNET_DNSPARSER_TYPE_AAAA, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_GNSRECORD_records_deserialize(), GNUNET_GNSRECORD_TYPE_VPN, GNUNET_log, GNUNET_OK, GNUNET_TIME_relative_to_absolute(), VpnContext::rd_count, VpnContext::rd_data, VpnContext::rd_data_size, GNUNET_GNSRECORD_Data::record_type, VpnContext::request, request, send_response(), Request::vpn_ctx, VpnContext::vpn_request, and VPN_TIMEOUT.

Referenced by result_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ result_processor()

static void result_processor ( void *  cls,
int  was_gns,
uint32_t  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Iterator called on obtained result for a GNS lookup.

Parameters
clsclosure
was_gnsGNUNET_NO if the TLD is not configured for GNS
rd_countnumber of records in rd
rdthe records in reply

Definition at line 471 of file gnunet-dns2gns.c.

475 {
476  struct Request *request = cls;
477  struct GNUNET_DNSPARSER_Packet *packet;
478  struct GNUNET_DNSPARSER_Record rec;
479  struct VpnContext *vpn_ctx;
480  const struct GNUNET_TUN_GnsVpnRecord *vpn;
481  const char *vname;
482  struct GNUNET_HashCode vhash;
483  int af;
484 
485  request->lookup = NULL;
486  if (GNUNET_NO == was_gns)
487  {
488  /* TLD not configured for GNS, fall back to DNS */
490  "Using DNS resolver IP `%s' to resolve `%s'\n",
491  dns_ip,
492  request->packet->queries[0].name);
493  request->original_request_id = request->packet->id;
495  request->packet = NULL;
496  request->dns_lookup = GNUNET_DNSSTUB_resolve (dns_stub,
497  request->udp_msg,
498  request->udp_msg_size,
500  request);
501  return;
502  }
503  packet = request->packet;
504  packet->flags.query_or_response = 1;
506  packet->flags.checking_disabled = 0;
507  packet->flags.authenticated_data = 1;
508  packet->flags.zero = 0;
509  packet->flags.recursion_available = 1;
510  packet->flags.message_truncated = 0;
511  packet->flags.authoritative_answer = 0;
512  // packet->flags.opcode = GNUNET_TUN_DNS_OPCODE_STATUS; // ???
513  for (uint32_t i = 0; i < rd_count; i++)
514  {
515  rec.expiration_time.abs_value_us = rd[i].expiration_time;
516  switch (rd[i].record_type)
517  {
519  GNUNET_assert (sizeof(struct in_addr) == rd[i].data_size);
520  rec.name = GNUNET_strdup (packet->queries[0].name);
521  rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
522  rec.type = GNUNET_DNSPARSER_TYPE_A;
523  rec.data.raw.data = GNUNET_new (struct in_addr);
524  GNUNET_memcpy (rec.data.raw.data,
525  rd[i].data,
526  rd[i].data_size);
527  rec.data.raw.data_len = sizeof(struct in_addr);
528  GNUNET_array_append (packet->answers,
529  packet->num_answers,
530  rec);
531  break;
532 
534  GNUNET_assert (sizeof(struct in6_addr) == rd[i].data_size);
535  rec.name = GNUNET_strdup (packet->queries[0].name);
536  rec.data.raw.data = GNUNET_new (struct in6_addr);
537  rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
538  rec.type = GNUNET_DNSPARSER_TYPE_AAAA;
539  GNUNET_memcpy (rec.data.raw.data,
540  rd[i].data,
541  rd[i].data_size);
542  rec.data.raw.data_len = sizeof(struct in6_addr);
543  GNUNET_array_append (packet->answers,
544  packet->num_answers,
545  rec);
546  break;
547 
549  rec.name = GNUNET_strdup (packet->queries[0].name);
550  rec.data.hostname = GNUNET_strdup (rd[i].data);
551  rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
552  rec.type = GNUNET_DNSPARSER_TYPE_CNAME;
553  GNUNET_memcpy (rec.data.hostname,
554  rd[i].data,
555  rd[i].data_size);
556  GNUNET_array_append (packet->answers,
557  packet->num_answers,
558  rec);
559  break;
561  if ((GNUNET_DNSPARSER_TYPE_A != request->packet->queries[0].type) &&
562  (GNUNET_DNSPARSER_TYPE_AAAA != request->packet->queries[0].type))
563  break;
564  af = (GNUNET_DNSPARSER_TYPE_A == request->packet->queries[0].type) ? AF_INET :
565  AF_INET6;
566  if (sizeof(struct GNUNET_TUN_GnsVpnRecord) >
567  rd[i].data_size)
568  {
569  GNUNET_break_op (0);
570  break;
571  }
572  vpn = (const struct GNUNET_TUN_GnsVpnRecord *) rd[i].data;
573  vname = (const char *) &vpn[1];
574  if ('\0' != vname[rd[i].data_size - 1 - sizeof(struct
576  ])
577  {
578  GNUNET_break_op (0);
579  break;
580  }
582  &vhash);
584  "Attempting VPN allocation for %s-%s (AF: %d, proto %d)\n",
585  GNUNET_i2s (&vpn->peer),
586  vname,
587  (int) af,
588  (int) ntohs (vpn->proto));
589  vpn_ctx = GNUNET_new (struct VpnContext);
590  request->vpn_ctx = vpn_ctx;
591  vpn_ctx->request = request;
592  vpn_ctx->rd_data_size = GNUNET_GNSRECORD_records_get_size (rd_count,
593  rd);
594  if (vpn_ctx->rd_data_size < 0)
595  {
596  GNUNET_break_op (0);
597  GNUNET_free (vpn_ctx);
598  break;
599  }
600  vpn_ctx->rd_data = GNUNET_malloc ((size_t) vpn_ctx->rd_data_size);
601  vpn_ctx->rd_count = rd_count;
602  GNUNET_assert (vpn_ctx->rd_data_size ==
604  rd,
605  (size_t) vpn_ctx
606  ->rd_data_size,
607  vpn_ctx->rd_data));
609  af,
610  ntohs (
611  vpn->proto),
612  &vpn->peer,
613  &vhash,
615  VPN_TIMEOUT),
616  &
618  vpn_ctx);
619  return;
620 
621 
622  default:
623  /* skip */
624  break;
625  }
626  }
628 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
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 char * dns_ip
IP of DNS server.
static void vpn_allocation_cb(void *cls, int af, const void *address)
Callback invoked from the VPN service once a redirection is available.
uint32_t data
The data value.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_NO
Definition: gnunet_common.h:94
#define GNUNET_DNSPARSER_TYPE_CNAME
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:530
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.
GNUNET_NETWORK_STRUCT_END 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_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).
@ 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_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: regex.c:814
#define GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR
RFC 1035 codes.
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:410
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.
char * name
Name of the record that the query is for (0-terminated).
size_t data_size
Number of bytes in data.
uint64_t expiration_time
Expiration time for the DNS record.
A 512-bit hashcode.
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.
Payload of GNS VPN record.
struct GNUNET_PeerIdentity peer
The peer to contact.
uint16_t proto
The protocol to use.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_DNSPARSER_Packet::answers, GNUNET_TUN_DnsFlags::authenticated_data, GNUNET_TUN_DnsFlags::authoritative_answer, GNUNET_TUN_DnsFlags::checking_disabled, GNUNET_DNSPARSER_RawRecord::data, GNUNET_DNSPARSER_Record::data, GNUNET_GNSRECORD_Data::data, data, GNUNET_DNSPARSER_RawRecord::data_len, data_size, GNUNET_GNSRECORD_Data::data_size, dns_ip, dns_result_processor(), dns_stub, GNUNET_DNSPARSER_Record::dns_traffic_class, GNUNET_DNSPARSER_Record::expiration_time, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_DNSPARSER_Packet::flags, GNUNET_array_append, GNUNET_assert, GNUNET_break_op, GNUNET_DNSPARSER_free_packet(), GNUNET_DNSPARSER_TYPE_A, GNUNET_DNSPARSER_TYPE_AAAA, GNUNET_DNSPARSER_TYPE_CNAME, GNUNET_DNSSTUB_resolve(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), GNUNET_GNSRECORD_TYPE_VPN, GNUNET_i2s(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_strdup, GNUNET_TIME_relative_to_absolute(), GNUNET_TUN_DNS_CLASS_INTERNET, GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR, GNUNET_TUN_service_name_to_hash(), GNUNET_VPN_redirect_to_peer(), GNUNET_DNSPARSER_Record::hostname, GNUNET_TUN_DnsFlags::message_truncated, GNUNET_DNSPARSER_Query::name, GNUNET_DNSPARSER_Record::name, GNUNET_DNSPARSER_Packet::num_answers, GNUNET_TUN_GnsVpnRecord::peer, GNUNET_TUN_GnsVpnRecord::proto, GNUNET_DNSPARSER_Packet::queries, GNUNET_TUN_DnsFlags::query_or_response, GNUNET_DNSPARSER_Record::raw, VpnContext::rd_count, VpnContext::rd_data, VpnContext::rd_data_size, GNUNET_TUN_DnsFlags::recursion_available, VpnContext::request, request, GNUNET_TUN_DnsFlags::return_code, send_response(), GNUNET_DNSPARSER_Record::type, vpn_allocation_cb(), vpn_handle, VpnContext::vpn_request, VPN_TIMEOUT, and GNUNET_TUN_DnsFlags::zero.

Referenced by handle_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_request()

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 
)
static

Handle DNS request.

Parameters
lsocksocket to use for sending the reply
addraddress to use for sending the reply
addr_lennumber of bytes in addr
udp_msgDNS request payload
udp_msg_sizenumber of bytes in udp_msg

Definition at line 641 of file gnunet-dns2gns.c.

646 {
647  struct Request *request;
648  struct GNUNET_DNSPARSER_Packet *packet;
649 
650  packet = GNUNET_DNSPARSER_parse (udp_msg,
651  udp_msg_size);
652  if (NULL == packet)
653  {
655  _ ("Cannot parse DNS request from %s\n"),
656  GNUNET_a2s (addr, addr_len));
657  return;
658  }
660  "Received request for `%s' with flags %u, #answers %d, #auth %d, #additional %d\n",
661  packet->queries[0].name,
662  (unsigned int) packet->flags.query_or_response,
663  (int) packet->num_answers,
664  (int) packet->num_authority_records,
665  (int) packet->num_additional_records);
666  if ((0 != packet->flags.query_or_response) ||
667  (0 != packet->num_answers) ||
668  (0 != packet->num_authority_records))
669  {
671  _ ("Received malformed DNS request from %s\n"),
672  GNUNET_a2s (addr, addr_len));
674  return;
675  }
676  if ((1 != packet->num_queries))
677  {
679  _ ("Received unsupported DNS request from %s\n"),
680  GNUNET_a2s (addr,
681  addr_len));
683  return;
684  }
685  request = GNUNET_malloc (sizeof(struct Request) + addr_len);
686  request->lsock = lsock;
687  request->packet = packet;
688  request->addr = &request[1];
689  request->addr_len = addr_len;
690  GNUNET_memcpy (&request[1],
691  addr,
692  addr_len);
693  request->udp_msg_size = udp_msg_size;
694  request->udp_msg = GNUNET_memdup (udp_msg,
695  udp_msg_size);
697  &do_timeout,
698  request);
700  "Calling GNS on `%s'\n",
701  packet->queries[0].name);
703  packet->queries[0].name,
704  packet->queries[0].type,
707  request);
708 }
#define TIMEOUT
Timeout for DNS requests.
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.
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
@ GNUNET_GNS_LO_DEFAULT
Defaults, look in cache, then in DHT.
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_memdup(buf, size)
Allocate and initialize a block of memory.
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:1254
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_*.

References _, GNUNET_VPN_RedirectionRequest::addr, do_timeout(), GNUNET_DNSPARSER_Packet::flags, gns, GNUNET_a2s(), GNUNET_DNSPARSER_free_packet(), GNUNET_DNSPARSER_parse(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_GNS_LO_DEFAULT, GNUNET_GNS_lookup_with_tld(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_memdup, GNUNET_SCHEDULER_add_delayed(), GNUNET_DNSPARSER_Query::name, GNUNET_DNSPARSER_Packet::num_additional_records, GNUNET_DNSPARSER_Packet::num_answers, GNUNET_DNSPARSER_Packet::num_authority_records, GNUNET_DNSPARSER_Packet::num_queries, GNUNET_DNSPARSER_Packet::queries, GNUNET_TUN_DnsFlags::query_or_response, request, result_processor(), TIMEOUT, and GNUNET_DNSPARSER_Query::type.

Referenced by read_dns4(), and read_dns6().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_dns4()

static void read_dns4 ( void *  cls)
static

Task to read IPv4 DNS packets.

Parameters
clsthe 'listen_socket4'

Definition at line 717 of file gnunet-dns2gns.c.

718 {
719  struct sockaddr_in v4;
720  socklen_t addrlen;
721  ssize_t size;
722  const struct GNUNET_SCHEDULER_TaskContext *tc;
723 
724  GNUNET_assert (listen_socket4 == cls);
727  &read_dns4,
731  return; /* shutdown? */
733  if (0 > size)
734  {
735  GNUNET_break (0);
736  return; /* read error!? */
737  }
738  {
739  char buf[size + 1];
740  ssize_t sret;
741 
742  addrlen = sizeof(v4);
744  buf,
745  size + 1,
746  (struct sockaddr *) &v4,
747  &addrlen);
748  if (0 > sret)
749  {
751  "recvfrom");
752  return;
753  }
754  GNUNET_break (size == sret);
756  &v4,
757  addrlen,
758  buf,
759  size);
760  }
761 }
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 void read_dns4(void *cls)
Task to read IPv4 DNS packets.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
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:702
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:675
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:1502
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:737
@ GNUNET_SCHEDULER_REASON_READ_READY
The reading socket is ready.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:423
Context information passed to each scheduler task.
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.

References buf, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror, GNUNET_NETWORK_socket_recvfrom(), GNUNET_NETWORK_socket_recvfrom_amount(), GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_READ_READY, GNUNET_TIME_UNIT_FOREVER_REL, handle_request(), listen_socket4, GNUNET_SCHEDULER_TaskContext::reason, size, t4, and tc.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_dns6()

static void read_dns6 ( void *  cls)
static

Task to read IPv6 DNS packets.

Parameters
clsthe 'listen_socket6'

Definition at line 770 of file gnunet-dns2gns.c.

771 {
772  struct sockaddr_in6 v6;
773  socklen_t addrlen;
774  ssize_t size;
775  const struct GNUNET_SCHEDULER_TaskContext *tc;
776 
777  GNUNET_assert (listen_socket6 == cls);
780  &read_dns6,
784  return; /* shutdown? */
786  if (0 > size)
787  {
788  GNUNET_break (0);
789  return; /* read error!? */
790  }
791  {
792  char buf[size];
793  ssize_t sret;
794 
795  addrlen = sizeof(v6);
797  buf,
798  size,
799  (struct sockaddr *) &v6,
800  &addrlen);
801  if (0 > sret)
802  {
804  "recvfrom");
805  return;
806  }
807  GNUNET_break (size == sret);
809  &v6,
810  addrlen,
811  buf,
812  size);
813  }
814 }
static void read_dns6(void *cls)
Task to read IPv6 DNS packets.

References buf, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror, GNUNET_NETWORK_socket_recvfrom(), GNUNET_NETWORK_socket_recvfrom_amount(), GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_READ_READY, GNUNET_TIME_UNIT_FOREVER_REL, handle_request(), listen_socket6, GNUNET_SCHEDULER_TaskContext::reason, size, t6, and tc.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle c 
)
static

Main function that will be run.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cconfiguration

Definition at line 826 of file gnunet-dns2gns.c.

830 {
831  char *addr_str;
832 
833  (void) cls;
834  (void) args;
835  (void) cfgfile;
836  cfg = c;
837  if (NULL == dns_ip)
838  {
840  _ ("No DNS server specified!\n"));
841  return;
842  }
844  NULL);
845  if (NULL == (gns = GNUNET_GNS_connect (cfg)))
846  return;
847  if (NULL == (vpn_handle = GNUNET_VPN_connect (cfg)))
848  return;
849  GNUNET_assert (NULL != (dns_stub = GNUNET_DNSSTUB_start (128)));
850  if (GNUNET_OK !=
852  dns_ip))
853  {
856  gns = NULL;
858  vpn_handle = NULL;
859  return;
860  }
861 
862  /* Get address to bind to */
864  "BIND_TO",
865  &addr_str))
866  {
867  // No address specified
869  "Don't know what to bind to...\n");
870  GNUNET_free (addr_str);
872  return;
873  }
874  if (1 != inet_pton (AF_INET, addr_str, &address))
875  {
877  "Unable to parse address %s\n",
878  addr_str);
879  GNUNET_free (addr_str);
881  return;
882  }
883  GNUNET_free (addr_str);
884  /* Get address to bind to */
886  "BIND_TO6",
887  &addr_str))
888  {
889  // No address specified
891  "Don't know what to bind6 to...\n");
892  GNUNET_free (addr_str);
894  return;
895  }
896  if (1 != inet_pton (AF_INET6, addr_str, &address6))
897  {
899  "Unable to parse IPv6 address %s\n",
900  addr_str);
901  GNUNET_free (addr_str);
903  return;
904  }
905  GNUNET_free (addr_str);
906 
908  SOCK_DGRAM,
909  IPPROTO_UDP);
910  if (NULL != listen_socket4)
911  {
912  struct sockaddr_in v4;
913 
914  memset (&v4, 0, sizeof(v4));
915  v4.sin_family = AF_INET;
916  v4.sin_addr.s_addr = address;
917 #if HAVE_SOCKADDR_IN_SIN_LEN
918  v4.sin_len = sizeof(v4);
919 #endif
920  v4.sin_port = htons (listen_port);
921  if (GNUNET_OK !=
923  (struct sockaddr *) &v4,
924  sizeof(v4)))
925  {
928  listen_socket4 = NULL;
929  }
930  }
932  SOCK_DGRAM,
933  IPPROTO_UDP);
934  if (NULL != listen_socket6)
935  {
936  struct sockaddr_in6 v6;
937 
938  memset (&v6, 0, sizeof(v6));
939  v6.sin6_family = AF_INET6;
940  v6.sin6_addr = address6;
941 #if HAVE_SOCKADDR_IN_SIN_LEN
942  v6.sin6_len = sizeof(v6);
943 #endif
944  v6.sin6_port = htons (listen_port);
945  if (GNUNET_OK !=
947  (struct sockaddr *) &v6,
948  sizeof(v6)))
949  {
952  listen_socket6 = NULL;
953  }
954  }
955  if ((NULL == listen_socket4) &&
956  (NULL == listen_socket6))
957  {
959  gns = NULL;
961  vpn_handle = NULL;
963  dns_stub = NULL;
964  return;
965  }
966  if (NULL != listen_socket4)
969  &read_dns4,
971  if (NULL != listen_socket6)
974  &read_dns6,
976 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
static struct in6_addr address6
The IPv6 address to bind to.
static void do_shutdown(void *cls)
Task run on shutdown.
static unsigned int listen_port
UDP Port we listen on for inbound DNS requests.
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.
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:617
struct GNUNET_DNSSTUB_Context * GNUNET_DNSSTUB_start(unsigned int num_sockets)
Start a DNS stub resolver.
Definition: dnsstub.c:590
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
@ GNUNET_ERROR_TYPE_ERROR
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:855
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
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:533
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:1316
struct GNUNET_VPN_Handle * GNUNET_VPN_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the VPN service.
Definition: vpn_api.c:512

References _, address, address6, consensus-simulation::args, cfg, dns_ip, dns_stub, do_shutdown(), gns, GNUNET_assert, GNUNET_CONFIGURATION_get_value_string(), GNUNET_DNSSTUB_add_dns_ip(), GNUNET_DNSSTUB_start(), GNUNET_DNSSTUB_stop(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GNS_connect(), GNUNET_GNS_disconnect(), GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_bind(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_VPN_connect(), GNUNET_VPN_disconnect(), listen_port, listen_socket4, listen_socket6, read_dns4(), read_dns6(), t4, t6, and vpn_handle.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function for the dns2gns daemon.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 987 of file gnunet-dns2gns.c.

989 {
992  "dns",
993  "IP",
994  gettext_noop (
995  "IP of recursive DNS resolver to use (required)"),
996  &dns_ip),
998  "port",
999  "UDPPORT",
1000  gettext_noop (
1001  "UDP port to listen on for inbound DNS requests; default: 2853"),
1002  &listen_port),
1004  };
1005  int ret;
1006 
1007  if (GNUNET_OK !=
1008  GNUNET_STRINGS_get_utf8_args (argc, argv,
1009  &argc, &argv))
1010  return 2;
1011  GNUNET_log_setup ("gnunet-dns2gns",
1012  "WARNING",
1013  NULL);
1014  ret =
1015  (GNUNET_OK ==
1016  GNUNET_PROGRAM_run (argc, argv,
1017  "gnunet-dns2gns",
1018  _ ("GNUnet DNS-to-GNS proxy (a DNS server)"),
1019  options,
1020  &run, NULL)) ? 0 : 1;
1021  GNUNET_free_nz ((void *) argv);
1022  return ret;
1023 }
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:69
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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_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_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.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_free_nz(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue 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,...
Definition: program.c:399
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1223
Definition of a command line option.

References _, dns_ip, gettext_noop, GNUNET_free_nz, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_string(), GNUNET_GETOPT_option_uint(), GNUNET_log_setup(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), listen_port, options, ret, and run().

Here is the call graph for this function:

Variable Documentation

◆ address

in_addr_t address
static

The address to bind to.

Definition at line 145 of file gnunet-dns2gns.c.

Referenced by run(), and vpn_allocation_cb().

◆ address6

struct in6_addr address6
static

The IPv6 address to bind to.

Definition at line 145 of file gnunet-dns2gns.c.

Referenced by run().

◆ gns

struct GNUNET_GNS_Handle* gns

Handle to GNS resolver.

Definition at line 156 of file gnunet-dns2gns.c.

Referenced by do_shutdown(), handle_request(), and run().

◆ vpn_handle

struct GNUNET_VPN_Handle* vpn_handle
static

Our handle to the vpn service.

Definition at line 161 of file gnunet-dns2gns.c.

Referenced by do_shutdown(), result_processor(), and run().

◆ dns_stub

struct GNUNET_DNSSTUB_Context* dns_stub

Stub resolver.

Definition at line 166 of file gnunet-dns2gns.c.

Referenced by do_shutdown(), result_processor(), and run().

◆ listen_socket4

struct GNUNET_NETWORK_Handle* listen_socket4
static

Listen socket for IPv4.

Definition at line 171 of file gnunet-dns2gns.c.

Referenced by do_shutdown(), read_dns4(), and run().

◆ listen_socket6

struct GNUNET_NETWORK_Handle* listen_socket6
static

Listen socket for IPv6.

Definition at line 176 of file gnunet-dns2gns.c.

Referenced by do_shutdown(), read_dns6(), and run().

◆ t4

struct GNUNET_SCHEDULER_Task* t4
static

◆ t6

struct GNUNET_SCHEDULER_Task* t6
static

◆ dns_ip

char* dns_ip
static

IP of DNS server.

Definition at line 191 of file gnunet-dns2gns.c.

Referenced by GNUNET_DNSSTUB_add_dns_ip(), main(), result_processor(), and run().

◆ listen_port

unsigned int listen_port = 53
static

UDP Port we listen on for inbound DNS requests.

Definition at line 196 of file gnunet-dns2gns.c.

Referenced by main(), and run().

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Configuration to use.

Definition at line 201 of file gnunet-dns2gns.c.

Referenced by run().