GNUnet  0.11.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 158 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().

159 {
160  if (NULL != rs->dnsout4)
161  {
163  rs->dnsout4 = NULL;
164  }
165  if (NULL != rs->dnsout6)
166  {
168  rs->dnsout6 = NULL;
169  }
170  if (NULL != rs->read_task)
171  {
173  rs->read_task = NULL;
174  }
175  if (NULL != rs->retry_task)
176  {
178  rs->retry_task = NULL;
179  }
180  if (NULL != rs->request)
181  {
182  GNUNET_free (rs->request);
183  rs->request = NULL;
184  }
185 }
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:560
#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:966
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 195 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, and ret.

Referenced by transmit_query().

196 {
197  struct sockaddr_in a4;
198  struct sockaddr_in6 a6;
199  struct sockaddr *sa;
200  socklen_t alen;
201  struct GNUNET_NETWORK_Handle *ret;
202 
203  ret = GNUNET_NETWORK_socket_create (af, SOCK_DGRAM, 0);
204  if (NULL == ret)
205  return NULL;
206  switch (af)
207  {
208  case AF_INET:
209  memset (&a4, 0, alen = sizeof(struct sockaddr_in));
210  sa = (struct sockaddr *) &a4;
211  break;
212 
213  case AF_INET6:
214  memset (&a6, 0, alen = sizeof(struct sockaddr_in6));
215  sa = (struct sockaddr *) &a6;
216  break;
217 
218  default:
219  GNUNET_break (0);
221  return NULL;
222  }
223  sa->sa_family = af;
224  if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret, sa, alen))
225  {
227  _ ("Could not bind to any port: %s\n"),
228  strerror (errno));
230  return NULL;
231  }
232  return ret;
233 }
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
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#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:181
#define GNUNET_log(kind,...)
handle to a socket
Definition: network.c:52
int af
Address family / domain.
Definition: network.c:59
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:912
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 244 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().

245 {
246  struct GNUNET_DNSSTUB_RequestSocket *rs;
247 
248  for (unsigned int i = 0; i < 256; i++)
249  {
251  ctx->num_sockets)];
252  if (NULL == rs->rc)
253  break;
254  }
255  if (NULL != rs->rc)
256  {
257  /* signal "failure" */
258  rs->rc (rs->rc_cls, NULL, 0);
259  rs->rc = NULL;
260  }
261  if (NULL != rs->read_task)
262  {
264  rs->read_task = NULL;
265  }
266  if (NULL != rs->retry_task)
267  {
269  rs->retry_task = NULL;
270  }
271  if (NULL != rs->request)
272  {
273  GNUNET_free (rs->request);
274  rs->request = NULL;
275  }
276  rs->ctx = ctx;
277  return rs;
278 }
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:148
Randomness for IVs etc.
struct GNUNET_DNSSTUB_RequestSocket * sockets
Array of all open sockets for DNS requests.
Definition: dnsstub.c:128
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:44
#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:966
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 290 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().

292 {
293  struct GNUNET_DNSSTUB_Context *ctx = rs->ctx;
294  ssize_t r;
295  int len;
296 
297  if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len))
298  {
299  /* conservative choice: */
300  len = UINT16_MAX;
301  }
302 
303  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving %d byte DNS reply\n", len);
304  {
305  unsigned char buf[len] GNUNET_ALIGN;
306  int found;
307  struct sockaddr_storage addr;
308  socklen_t addrlen;
309  struct GNUNET_TUN_DnsHeader *dns;
310 
311  addrlen = sizeof(addr);
312  memset (&addr, 0, sizeof(addr));
313  r = GNUNET_NETWORK_socket_recvfrom (dnsout,
314  buf,
315  sizeof(buf),
316  (struct sockaddr *) &addr,
317  &addrlen);
318  if (-1 == r)
319  {
322  return GNUNET_SYSERR;
323  }
324  found = GNUNET_NO;
325  for (struct DnsServer *ds = ctx->dns_head; NULL != ds; ds = ds->next)
326  {
327  if (0 == memcmp (&addr,
328  &ds->ss,
329  GNUNET_MIN (sizeof(struct sockaddr_storage), addrlen)))
330  {
331  found = GNUNET_YES;
332  break;
333  }
334  }
335  if (GNUNET_NO == found)
336  {
338  "Received DNS response from server we never asked (ignored)");
339  return GNUNET_NO;
340  }
341  if (sizeof(struct GNUNET_TUN_DnsHeader) > (size_t) r)
342  {
344  _ ("Received DNS response that is too small (%u bytes)"),
345  (unsigned int) r);
346  return GNUNET_NO;
347  }
348  dns = (struct GNUNET_TUN_DnsHeader *) buf;
349  if (NULL == rs->rc)
350  {
352  "Request timeout or cancelled; ignoring reply\n");
353  return GNUNET_NO;
354  }
355  rs->rc (rs->rc_cls, dns, r);
356  }
357  return GNUNET_OK;
358 }
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1080
struct DnsServer * dns_head
DLL of DNS resolvers we use.
Definition: dnsstub.c:133
GNUNET_DNSSTUB_ResultCallback rc
Function to call with result.
Definition: dnsstub.c:59
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:181
#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:101
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:80
static char buf[2048]
Handle to the stub resolver.
Definition: dnsstub.c:123
void * rc_cls
Closure for rc.
Definition: dnsstub.c:64
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#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:77
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:754
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
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 404 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().

405 {
406  struct GNUNET_DNSSTUB_RequestSocket *rs = cls;
407  const struct GNUNET_SCHEDULER_TaskContext *tc;
408 
409  rs->read_task = NULL;
411  /* read and process ready sockets */
412  if ((NULL != rs->dnsout4) &&
414  (GNUNET_SYSERR == do_dns_read (rs, rs->dnsout4)))
415  rs->dnsout4 = NULL;
416  if ((NULL != rs->dnsout6) &&
418  (GNUNET_SYSERR == do_dns_read (rs, rs->dnsout6)))
419  rs->dnsout6 = NULL;
420  /* re-schedule read task */
421  schedule_read (rs);
422 }
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:747
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:418
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:290
static void schedule_read(struct GNUNET_DNSSTUB_RequestSocket *rs)
Schedule read_response() task for rs.
Definition: dnsstub.c:376
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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:44
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:1029
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 376 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().

377 {
378  struct GNUNET_NETWORK_FDSet *rset;
379 
380  if (NULL != rs->read_task)
382  rset = GNUNET_NETWORK_fdset_create ();
383  if (NULL != rs->dnsout4)
384  GNUNET_NETWORK_fdset_set (rset, rs->dnsout4);
385  if (NULL != rs->dnsout6)
386  GNUNET_NETWORK_fdset_set (rset, rs->dnsout6);
387  rs->read_task =
390  rset,
391  NULL,
392  &read_response,
393  rs);
395 }
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:1266
static void read_response(void *cls)
Read a DNS response from the (unhindered) UDP-Socket.
Definition: dnsstub.c:404
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1250
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:1810
#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:1011
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:966
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 432 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(), and DnsServer::ss.

Referenced by GNUNET_DNSSTUB_resolve().

433 {
434  struct GNUNET_DNSSTUB_RequestSocket *rs = cls;
435  struct GNUNET_DNSSTUB_Context *ctx = rs->ctx;
436  const struct sockaddr *sa;
437  socklen_t salen;
438  struct DnsServer *ds;
439  struct GNUNET_NETWORK_Handle *dnsout;
440 
441  rs->retry_task =
443  ds = rs->ds_pos;
444  rs->ds_pos = ds->next;
445  if (NULL == rs->ds_pos)
446  rs->ds_pos = ctx->dns_head;
447  GNUNET_assert (NULL != ds);
448  dnsout = NULL;
449  switch (ds->ss.ss_family)
450  {
451  case AF_INET:
452  if (NULL == rs->dnsout4)
453  rs->dnsout4 = open_socket (AF_INET);
454  dnsout = rs->dnsout4;
455  sa = (const struct sockaddr *) &ds->ss;
456  salen = sizeof(struct sockaddr_in);
457  break;
458 
459  case AF_INET6:
460  if (NULL == rs->dnsout6)
461  rs->dnsout6 = open_socket (AF_INET6);
462  dnsout = rs->dnsout6;
463  sa = (const struct sockaddr *) &ds->ss;
464  salen = sizeof(struct sockaddr_in6);
465  break;
466 
467  default:
468  return;
469  }
470  if (NULL == dnsout)
471  {
473  "Unable to use configure DNS server, skipping\n");
474  return;
475  }
477  rs->request,
478  rs->request_len,
479  sa,
480  salen))
482  _ ("Failed to send DNS request to %s: %s\n"),
483  GNUNET_a2s (sa, salen),
484  strerror (errno));
485  else
487  _ ("Sent DNS request to %s\n"),
488  GNUNET_a2s (sa, salen));
489  schedule_read (rs);
490 }
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:133
static void transmit_query(void *cls)
Task to (re)transmit the DNS query, possibly repeatedly until we succeed.
Definition: dnsstub.c:432
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:116
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:106
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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:1253
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:195
DNS Server used for resolution.
Definition: dnsstub.c:101
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
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:123
static void schedule_read(struct GNUNET_DNSSTUB_RequestSocket *rs)
Schedule read_response() task for rs.
Definition: dnsstub.c:376
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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:52
struct GNUNET_TIME_Relative retry_freq
How frequently do we retry requests?
Definition: dnsstub.c:143
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:44
Here is the call graph for this function:
Here is the caller graph for this function: