GNUnet  0.10.x
Data Structures | Macros | Functions
dnsstub.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for dnsstub.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_DNSSTUB_RequestSocket
 UDP socket we are using for sending DNS requests to the Internet. More...
 
struct  DnsServer
 DNS Server used for resolution. More...
 
struct  GNUNET_DNSSTUB_Context
 Handle to the stub resolver. More...
 

Macros

#define DNS_RETRANSMIT_DELAY   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
 Timeout for retrying DNS queries. More...
 

Functions

static void cleanup_rs (struct GNUNET_DNSSTUB_RequestSocket *rs)
 We're done with a struct GNUNET_DNSSTUB_RequestSocket, close it for now. More...
 
static struct GNUNET_NETWORK_Handleopen_socket (int af)
 Open source port for sending DNS requests. More...
 
static struct GNUNET_DNSSTUB_RequestSocketget_request_socket (struct GNUNET_DNSSTUB_Context *ctx)
 Get a socket of the specified address family to send out a UDP DNS request to the Internet. More...
 
static int do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs, struct GNUNET_NETWORK_Handle *dnsout)
 Actually do the reading of a DNS packet from our UDP socket and see if we have a valid, matching, pending request. More...
 
static void read_response (void *cls)
 Read a DNS response from the (unhindered) UDP-Socket. More...
 
static void schedule_read (struct GNUNET_DNSSTUB_RequestSocket *rs)
 Schedule read_response() task for rs. More...
 
static void transmit_query (void *cls)
 Task to (re)transmit the DNS query, possibly repeatedly until we succeed. More...
 
struct GNUNET_DNSSTUB_RequestSocketGNUNET_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. More...
 
void GNUNET_DNSSTUB_resolve_cancel (struct GNUNET_DNSSTUB_RequestSocket *rs)
 Cancel DNS resolution. More...
 
struct GNUNET_DNSSTUB_ContextGNUNET_DNSSTUB_start (unsigned int num_sockets)
 Start a DNS stub resolver. More...
 
int GNUNET_DNSSTUB_add_dns_ip (struct GNUNET_DNSSTUB_Context *ctx, const char *dns_ip)
 Add nameserver for use by the DNSSTUB. More...
 
int GNUNET_DNSSTUB_add_dns_sa (struct GNUNET_DNSSTUB_Context *ctx, const struct sockaddr *sa)
 Add nameserver for use by the DNSSTUB. More...
 
void GNUNET_DNSSTUB_set_retry (struct GNUNET_DNSSTUB_Context *ctx, struct GNUNET_TIME_Relative retry_freq)
 How long should we try requests before timing out? Only effective for requests issued after this call. More...
 
void GNUNET_DNSSTUB_stop (struct GNUNET_DNSSTUB_Context *ctx)
 Cleanup DNSSTUB resolver. More...
 

Macro Definition Documentation

◆ DNS_RETRANSMIT_DELAY

#define DNS_RETRANSMIT_DELAY   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)

Timeout for retrying DNS queries.

Definition at line 31 of file dnsstub.c.

Referenced by GNUNET_DNSSTUB_start().

Function Documentation

◆ cleanup_rs()

static void cleanup_rs ( struct GNUNET_DNSSTUB_RequestSocket rs)
static

We're done with a struct GNUNET_DNSSTUB_RequestSocket, close it for now.

Parameters
rsrequest socket to clean up

Definition at line 162 of file dnsstub.c.

References GNUNET_DNSSTUB_RequestSocket::dnsout4, GNUNET_DNSSTUB_RequestSocket::dnsout6, GNUNET_free, GNUNET_NETWORK_socket_close(), GNUNET_SCHEDULER_cancel(), GNUNET_DNSSTUB_RequestSocket::read_task, GNUNET_DNSSTUB_RequestSocket::request, and GNUNET_DNSSTUB_RequestSocket::retry_task.

Referenced by GNUNET_DNSSTUB_stop().

163 {
164  if (NULL != rs->dnsout4)
165  {
167  rs->dnsout4 = NULL;
168  }
169  if (NULL != rs->dnsout6)
170  {
172  rs->dnsout6 = NULL;
173  }
174  if (NULL != rs->read_task)
175  {
177  rs->read_task = NULL;
178  }
179  if (NULL != rs->retry_task)
180  {
182  rs->retry_task = NULL;
183  }
184  if (NULL != rs->request)
185  {
186  GNUNET_free (rs->request);
187  rs->request = NULL;
188  }
189 }
struct GNUNET_SCHEDULER_Task * read_task
Task for reading from dnsout4 and dnsout6.
Definition: dnsstub.c:69
struct GNUNET_NETWORK_Handle * dnsout6
UDP socket we use for this request for IPv6.
Definition: dnsstub.c:54
void * request
Query we sent to addr.
Definition: dnsstub.c:89
struct GNUNET_NETWORK_Handle * dnsout4
UDP socket we use for this request for IPv4.
Definition: dnsstub.c:49
struct GNUNET_SCHEDULER_Task * retry_task
Task for retrying transmission of the query.
Definition: dnsstub.c:74
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:604
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_socket()

static struct GNUNET_NETWORK_Handle* open_socket ( int  af)
static

Open source port for sending DNS requests.

Parameters
afAF_INET or AF_INET6
Returns
GNUNET_OK on success

Definition at line 199 of file dnsstub.c.

References _, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_NETWORK_socket_bind(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_OK, ret, and STRERROR.

Referenced by transmit_query().

200 {
201  struct sockaddr_in a4;
202  struct sockaddr_in6 a6;
203  struct sockaddr *sa;
204  socklen_t alen;
205  struct GNUNET_NETWORK_Handle *ret;
206 
207  ret = GNUNET_NETWORK_socket_create (af, SOCK_DGRAM, 0);
208  if (NULL == ret)
209  return NULL;
210  switch (af)
211  {
212  case AF_INET:
213  memset (&a4, 0, alen = sizeof (struct sockaddr_in));
214  sa = (struct sockaddr *) &a4;
215  break;
216  case AF_INET6:
217  memset (&a6, 0, alen = sizeof (struct sockaddr_in6));
218  sa = (struct sockaddr *) &a6;
219  break;
220  default:
221  GNUNET_break (0);
223  return NULL;
224  }
225  sa->sa_family = af;
227  sa,
228  alen))
229  {
231  _("Could not bind to any port: %s\n"),
232  STRERROR (errno));
234  return NULL;
235  }
236  return ret;
237 }
#define STRERROR(i)
Definition: plibc.h:676
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:522
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
#define GNUNET_log(kind,...)
handle to a socket
Definition: network.c:46
int af
Address family / domain.
Definition: network.c:57
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:604
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:1037
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_request_socket()

static struct GNUNET_DNSSTUB_RequestSocket* get_request_socket ( struct GNUNET_DNSSTUB_Context ctx)
static

Get a socket of the specified address family to send out a UDP DNS request to the Internet.

Parameters
ctxthe DNSSTUB context
Returns
NULL on error

Definition at line 248 of file dnsstub.c.

References GNUNET_DNSSTUB_RequestSocket::ctx, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_free, GNUNET_SCHEDULER_cancel(), GNUNET_DNSSTUB_Context::num_sockets, GNUNET_DNSSTUB_RequestSocket::rc, GNUNET_DNSSTUB_RequestSocket::rc_cls, GNUNET_DNSSTUB_RequestSocket::read_task, GNUNET_DNSSTUB_RequestSocket::request, GNUNET_DNSSTUB_RequestSocket::retry_task, and GNUNET_DNSSTUB_Context::sockets.

Referenced by GNUNET_DNSSTUB_resolve().

249 {
250  struct GNUNET_DNSSTUB_RequestSocket *rs;
251 
252  for (unsigned int i=0;i<256;i++)
253  {
255  ctx->num_sockets)];
256  if (NULL == rs->rc)
257  break;
258  }
259  if (NULL != rs->rc)
260  {
261  /* signal "failure" */
262  rs->rc (rs->rc_cls,
263  NULL,
264  0);
265  rs->rc = NULL;
266  }
267  if (NULL != rs->read_task)
268  {
270  rs->read_task = NULL;
271  }
272  if (NULL != rs->retry_task)
273  {
275  rs->retry_task = NULL;
276  }
277  if (NULL != rs->request)
278  {
279  GNUNET_free (rs->request);
280  rs->request = NULL;
281  }
282  rs->ctx = ctx;
283  return rs;
284 }
struct GNUNET_SCHEDULER_Task * read_task
Task for reading from dnsout4 and dnsout6.
Definition: dnsstub.c:69
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
GNUNET_DNSSTUB_ResultCallback rc
Function to call with result.
Definition: dnsstub.c:59
void * request
Query we sent to addr.
Definition: dnsstub.c:89
struct GNUNET_DNSSTUB_Context * ctx
Context this request executes in.
Definition: dnsstub.c:84
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
unsigned int num_sockets
Length of sockets array.
Definition: dnsstub.c:151
Randomness for IVs etc.
struct GNUNET_DNSSTUB_RequestSocket * sockets
Array of all open sockets for DNS requests.
Definition: dnsstub.c:131
void * rc_cls
Closure for rc.
Definition: dnsstub.c:64
struct GNUNET_SCHEDULER_Task * retry_task
Task for retrying transmission of the query.
Definition: dnsstub.c:74
UDP socket we are using for sending DNS requests to the Internet.
Definition: dnsstub.c:43
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_dns_read()

static int do_dns_read ( struct GNUNET_DNSSTUB_RequestSocket rs,
struct GNUNET_NETWORK_Handle dnsout 
)
static

Actually do the reading of a DNS packet from our UDP socket and see if we have a valid, matching, pending request.

Parameters
rsrequest socket with callback details
dnsoutsocket to read from
Returns
GNUNET_OK on success, GNUNET_NO on drop, GNUNET_SYSERR on IO-errors (closed socket)

Definition at line 296 of file dnsstub.c.

References _, buf, GNUNET_DNSSTUB_RequestSocket::ctx, GNUNET_DNSSTUB_Context::dns_head, ds, GNUNET_ALIGN, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_log_strerror, GNUNET_MIN, GNUNET_NETWORK_get_fd(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_recvfrom(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, len, GNUNET_DNSSTUB_RequestSocket::rc, GNUNET_DNSSTUB_RequestSocket::rc_cls, and read_response().

Referenced by read_response().

298 {
299  struct GNUNET_DNSSTUB_Context *ctx = rs->ctx;
300  ssize_t r;
301  int len;
302 
303 #ifndef MINGW
304  if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout),
305  FIONREAD,
306  &len))
307  {
308  /* conservative choice: */
309  len = UINT16_MAX;
310  }
311 #else
312  /* port the code above? */
313  len = UINT16_MAX;
314 #endif
316  "Receiving %d byte DNS reply\n",
317  len);
318  {
319  unsigned char buf[len] GNUNET_ALIGN;
320  int found;
321  struct sockaddr_storage addr;
322  socklen_t addrlen;
323  struct GNUNET_TUN_DnsHeader *dns;
324 
325  addrlen = sizeof (addr);
326  memset (&addr,
327  0,
328  sizeof (addr));
329  r = GNUNET_NETWORK_socket_recvfrom (dnsout,
330  buf,
331  sizeof (buf),
332  (struct sockaddr*) &addr,
333  &addrlen);
334  if (-1 == r)
335  {
337  "recvfrom");
339  return GNUNET_SYSERR;
340  }
341  found = GNUNET_NO;
342  for (struct DnsServer *ds = ctx->dns_head; NULL != ds; ds = ds->next)
343  {
344  if (0 == memcmp (&addr,
345  &ds->ss,
346  GNUNET_MIN (sizeof (struct sockaddr_storage),
347  addrlen)))
348  {
349  found = GNUNET_YES;
350  break;
351  }
352  }
353  if (GNUNET_NO == found)
354  {
356  "Received DNS response from server we never asked (ignored)");
357  return GNUNET_NO;
358  }
359  if (sizeof (struct GNUNET_TUN_DnsHeader) > (size_t) r)
360  {
362  _("Received DNS response that is too small (%u bytes)"),
363  (unsigned int) r);
364  return GNUNET_NO;
365  }
366  dns = (struct GNUNET_TUN_DnsHeader *) buf;
367  if (NULL == rs->rc)
368  {
370  "Request timeout or cancelled; ignoring reply\n");
371  return GNUNET_NO;
372  }
373  rs->rc (rs->rc_cls,
374  dns,
375  r);
376  }
377  return GNUNET_OK;
378 }
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1268
struct DnsServer * dns_head
DLL of DNS resolvers we use.
Definition: dnsstub.c:136
GNUNET_DNSSTUB_ResultCallback rc
Function to call with result.
Definition: dnsstub.c:59
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_DNSSTUB_Context * ctx
Context this request executes in.
Definition: dnsstub.c:84
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
#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...
DNS Server used for resolution.
Definition: dnsstub.c:102
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:83
static char buf[2048]
Handle to the stub resolver.
Definition: dnsstub.c:125
void * rc_cls
Closure for rc.
Definition: dnsstub.c:64
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to &#39;struct&#39;s...
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
static struct GNUNET_FS_DirScanner * ds
Handle to the directory scanner (for recursive insertions).
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:856
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:604
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_response()

static void read_response ( void *  cls)
static

Read a DNS response from the (unhindered) UDP-Socket.

Parameters
clssocket to read from
clsstruct GNUNET_DNSSTUB_RequestSocket to read from

Definition at line 425 of file dnsstub.c.

References GNUNET_DNSSTUB_RequestSocket::dnsout4, GNUNET_DNSSTUB_RequestSocket::dnsout6, do_dns_read(), GNUNET_NETWORK_fdset_isset(), GNUNET_SCHEDULER_get_task_context(), GNUNET_SYSERR, GNUNET_SCHEDULER_TaskContext::read_ready, GNUNET_DNSSTUB_RequestSocket::read_task, schedule_read(), and tc.

Referenced by do_dns_read(), and schedule_read().

426 {
427  struct GNUNET_DNSSTUB_RequestSocket *rs = cls;
428  const struct GNUNET_SCHEDULER_TaskContext *tc;
429 
430  rs->read_task = NULL;
432  /* read and process ready sockets */
433  if ( (NULL != rs->dnsout4) &&
435  rs->dnsout4)) &&
436  (GNUNET_SYSERR ==
437  do_dns_read (rs,
438  rs->dnsout4)) )
439  rs->dnsout4 = NULL;
440  if ( (NULL != rs->dnsout6) &&
442  rs->dnsout6)) &&
443  (GNUNET_SYSERR ==
444  do_dns_read (rs,
445  rs->dnsout6)) )
446  rs->dnsout6 = NULL;
447  /* re-schedule read task */
448  schedule_read (rs);
449 }
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:746
struct GNUNET_SCHEDULER_Task * read_task
Task for reading from dnsout4 and dnsout6.
Definition: dnsstub.c:69
struct GNUNET_NETWORK_Handle * dnsout6
UDP socket we use for this request for IPv6.
Definition: dnsstub.c:54
Context information passed to each scheduler task.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:417
const struct GNUNET_NETWORK_FDSet * read_ready
Set of file descriptors ready for reading; note that additional bits may be set that were not in the ...
static int do_dns_read(struct GNUNET_DNSSTUB_RequestSocket *rs, struct GNUNET_NETWORK_Handle *dnsout)
Actually do the reading of a DNS packet from our UDP socket and see if we have a valid, matching, pending request.
Definition: dnsstub.c:296
static void schedule_read(struct GNUNET_DNSSTUB_RequestSocket *rs)
Schedule read_response() task for rs.
Definition: dnsstub.c:396
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_NETWORK_Handle * dnsout4
UDP socket we use for this request for IPv4.
Definition: dnsstub.c:49
UDP socket we are using for sending DNS requests to the Internet.
Definition: dnsstub.c:43
int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Check whether a socket is part of the fd set.
Definition: network.c:1181
Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedule_read()

static void schedule_read ( struct GNUNET_DNSSTUB_RequestSocket rs)
static

Schedule read_response() task for rs.

Parameters
rsrequest to schedule read operation for

Definition at line 396 of file dnsstub.c.

References GNUNET_DNSSTUB_RequestSocket::dnsout4, GNUNET_DNSSTUB_RequestSocket::dnsout6, GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_destroy(), GNUNET_NETWORK_fdset_set(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_PRIORITY_DEFAULT, GNUNET_TIME_UNIT_FOREVER_REL, read_response(), and GNUNET_DNSSTUB_RequestSocket::read_task.

Referenced by read_response(), and transmit_query().

397 {
398  struct GNUNET_NETWORK_FDSet *rset;
399 
400  if (NULL != rs->read_task)
402  rset = GNUNET_NETWORK_fdset_create ();
403  if (NULL != rs->dnsout4)
405  rs->dnsout4);
406  if (NULL != rs->dnsout6)
408  rs->dnsout6);
411  rset,
412  NULL,
413  &read_response,
414  rs);
416 }
struct GNUNET_SCHEDULER_Task * read_task
Task for reading from dnsout4 and dnsout6.
Definition: dnsstub.c:69
struct GNUNET_NETWORK_Handle * dnsout6
UDP socket we use for this request for IPv6.
Definition: dnsstub.c:54
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1554
static void read_response(void *cls)
Read a DNS response from the (unhindered) UDP-Socket.
Definition: dnsstub.c:425
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1538
collection of IO descriptors
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
Definition: scheduler.c:1829
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Add a socket to the FD set.
Definition: network.c:1163
struct GNUNET_NETWORK_Handle * dnsout4
UDP socket we use for this request for IPv4.
Definition: dnsstub.c:49
Run with the default priority (normal P2P operations).
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_query()

static void transmit_query ( void *  cls)
static

Task to (re)transmit the DNS query, possibly repeatedly until we succeed.

Parameters
clsour struct GNUNET_DNSSTUB_RequestSocket *

Definition at line 459 of file dnsstub.c.

References _, GNUNET_DNSSTUB_RequestSocket::ctx, GNUNET_DNSSTUB_Context::dns_head, GNUNET_DNSSTUB_RequestSocket::dnsout4, GNUNET_DNSSTUB_RequestSocket::dnsout6, ds, GNUNET_DNSSTUB_RequestSocket::ds_pos, GNUNET_a2s(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NETWORK_socket_sendto(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SYSERR, DnsServer::next, open_socket(), GNUNET_DNSSTUB_RequestSocket::request, GNUNET_DNSSTUB_RequestSocket::request_len, GNUNET_DNSSTUB_Context::retry_freq, GNUNET_DNSSTUB_RequestSocket::retry_task, schedule_read(), DnsServer::ss, and STRERROR.

Referenced by GNUNET_DNSSTUB_resolve().

460 {
461  struct GNUNET_DNSSTUB_RequestSocket *rs = cls;
462  struct GNUNET_DNSSTUB_Context *ctx = rs->ctx;
463  const struct sockaddr *sa;
464  socklen_t salen;
465  struct DnsServer *ds;
466  struct GNUNET_NETWORK_Handle *dnsout;
467 
470  rs);
471  ds = rs->ds_pos;
472  rs->ds_pos = ds->next;
473  if (NULL == rs->ds_pos)
474  rs->ds_pos = ctx->dns_head;
475  GNUNET_assert (NULL != ds);
476  dnsout = NULL;
477  switch (ds->ss.ss_family)
478  {
479  case AF_INET:
480  if (NULL == rs->dnsout4)
481  rs->dnsout4 = open_socket (AF_INET);
482  dnsout = rs->dnsout4;
483  sa = (const struct sockaddr *) &ds->ss;
484  salen = sizeof (struct sockaddr_in);
485  break;
486  case AF_INET6:
487  if (NULL == rs->dnsout6)
488  rs->dnsout6 = open_socket (AF_INET6);
489  dnsout = rs->dnsout6;
490  sa = (const struct sockaddr *) &ds->ss;
491  salen = sizeof (struct sockaddr_in6);
492  break;
493  default:
494  return;
495  }
496  if (NULL == dnsout)
497  {
499  "Unable to use configure DNS server, skipping\n");
500  return;
501  }
502  if (GNUNET_SYSERR ==
504  rs->request,
505  rs->request_len,
506  sa,
507  salen))
509  _("Failed to send DNS request to %s: %s\n"),
510  GNUNET_a2s (sa,
511  salen),
512  STRERROR (errno));
513  else
515  _("Sent DNS request to %s\n"),
516  GNUNET_a2s (sa,
517  salen));
518  schedule_read (rs);
519 }
struct GNUNET_NETWORK_Handle * dnsout6
UDP socket we use for this request for IPv6.
Definition: dnsstub.c:54
struct DnsServer * dns_head
DLL of DNS resolvers we use.
Definition: dnsstub.c:136
static void transmit_query(void *cls)
Task to (re)transmit the DNS query, possibly repeatedly until we succeed.
Definition: dnsstub.c:459
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define STRERROR(i)
Definition: plibc.h:676
void * request
Query we sent to addr.
Definition: dnsstub.c:89
size_t request_len
Number of bytes in request.
Definition: dnsstub.c:94
struct sockaddr_storage ss
IP address of the DNS resolver.
Definition: dnsstub.c:118
struct GNUNET_DNSSTUB_Context * ctx
Context this request executes in.
Definition: dnsstub.c:84
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
struct DnsServer * next
Kept in a DLL.
Definition: dnsstub.c:108
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
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:1246
struct DnsServer * ds_pos
Next address we sent the DNS request to.
Definition: dnsstub.c:79
static struct GNUNET_NETWORK_Handle * open_socket(int af)
Open source port for sending DNS requests.
Definition: dnsstub.c:199
DNS Server used for resolution.
Definition: dnsstub.c:102
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:968
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)...
Handle to the stub resolver.
Definition: dnsstub.c:125
static void schedule_read(struct GNUNET_DNSSTUB_RequestSocket *rs)
Schedule read_response() task for rs.
Definition: dnsstub.c:396
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_NETWORK_Handle * dnsout4
UDP socket we use for this request for IPv4.
Definition: dnsstub.c:49
#define GNUNET_log(kind,...)
struct GNUNET_SCHEDULER_Task * retry_task
Task for retrying transmission of the query.
Definition: dnsstub.c:74
handle to a socket
Definition: network.c:46
struct GNUNET_TIME_Relative retry_freq
How frequently do we retry requests?
Definition: dnsstub.c:146
static struct GNUNET_FS_DirScanner * ds
Handle to the directory scanner (for recursive insertions).
UDP socket we are using for sending DNS requests to the Internet.
Definition: dnsstub.c:43
Here is the call graph for this function:
Here is the caller graph for this function: