aboutsummaryrefslogtreecommitdiff
path: root/src/dns/dnsstub.c
blob: 969ff7beba5360aaac7169546d7d566bd276b52d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
/*
     This file is part of GNUnet.
     Copyright (C) 2012, 2018 GNUnet e.V.

     GNUnet is free software: you can redistribute it and/or modify it
     under the terms of the GNU Affero General Public License as published
     by the Free Software Foundation, either version 3 of the License,
     or (at your option) any later version.

     GNUnet is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     Affero General Public License for more details.
    
     You should have received a copy of the GNU Affero General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
/**
 * @file dns/dnsstub.c
 * @brief DNS stub resolver which sends DNS requests to an actual resolver
 * @author Christian Grothoff
 */
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_tun_lib.h"
#include "gnunet_dnsstub_lib.h"

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


/**
 * DNS Server used for resolution.
 */
struct DnsServer;


/**
 * UDP socket we are using for sending DNS requests to the Internet.
 */
struct GNUNET_DNSSTUB_RequestSocket
{

  /**
   * UDP socket we use for this request for IPv4
   */
  struct GNUNET_NETWORK_Handle *dnsout4;

  /**
   * UDP socket we use for this request for IPv6
   */
  struct GNUNET_NETWORK_Handle *dnsout6;

  /**
   * Function to call with result.
   */
  GNUNET_DNSSTUB_ResultCallback rc;

  /**
   * Closure for @e rc.
   */
  void *rc_cls;

  /**
   * Task for reading from dnsout4 and dnsout6.
   */
  struct GNUNET_SCHEDULER_Task *read_task;

  /**
   * Task for retrying transmission of the query.
   */
  struct GNUNET_SCHEDULER_Task *retry_task;

  /**
   * Next address we sent the DNS request to.
   */
  struct DnsServer *ds_pos;

  /**
   * Context this request executes in.
   */
  struct GNUNET_DNSSTUB_Context *ctx;

  /**
   * Query we sent to @e addr.
   */
  void *request;

  /**
   * Number of bytes in @a request.
   */
  size_t request_len;

};


/**
 * DNS Server used for resolution.
 */
struct DnsServer
{

  /**
   * Kept in a DLL.
   */
  struct DnsServer *next;

  /**
   * Kept in a DLL.
   */
  struct DnsServer *prev;

  /**
   * IP address of the DNS resolver.
   */
  struct sockaddr_storage ss;
};


/**
 * Handle to the stub resolver.
 */
struct GNUNET_DNSSTUB_Context
{

  /**
   * Array of all open sockets for DNS requests.
   */
  struct GNUNET_DNSSTUB_RequestSocket *sockets;

  /**
   * DLL of DNS resolvers we use.
   */
  struct DnsServer *dns_head;

  /**
   * DLL of DNS resolvers we use.
   */
  struct DnsServer *dns_tail;

  /**
   * How frequently do we retry requests?
   */
  struct GNUNET_TIME_Relative retry_freq;

  /**
   * Length of @e sockets array.
   */
  unsigned int num_sockets;

};


/**
 * We're done with a `struct GNUNET_DNSSTUB_RequestSocket`, close it for now.
 *
 * @param rs request socket to clean up
 */
static void
cleanup_rs (struct GNUNET_DNSSTUB_RequestSocket *rs)
{
  if (NULL != rs->dnsout4)
  {
    GNUNET_NETWORK_socket_close (rs->dnsout4);
    rs->dnsout4 = NULL;
  }
  if (NULL != rs->dnsout6)
  {
    GNUNET_NETWORK_socket_close (rs->dnsout6);
    rs->dnsout6 = NULL;
  }
  if (NULL != rs->read_task)
  {
    GNUNET_SCHEDULER_cancel (rs->read_task);
    rs->read_task = NULL;
  }
  if (NULL != rs->retry_task)
  {
    GNUNET_SCHEDULER_cancel (rs->retry_task);
    rs->retry_task = NULL;
  }
  if (NULL != rs->request)
  {
    GNUNET_free (rs->request);
    rs->request = NULL;
  }
}


/**
 * Open source port for sending DNS requests
 *
 * @param af AF_INET or AF_INET6
 * @return #GNUNET_OK on success
 */
static struct GNUNET_NETWORK_Handle *
open_socket (int af)
{
  struct sockaddr_in a4;
  struct sockaddr_in6 a6;
  struct sockaddr *sa;
  socklen_t alen;
  struct GNUNET_NETWORK_Handle *ret;

  ret = GNUNET_NETWORK_socket_create (af, SOCK_DGRAM, 0);
  if (NULL == ret)
    return NULL;
  switch (af)
  {
  case AF_INET:
    memset (&a4, 0, alen = sizeof (struct sockaddr_in));
    sa = (struct sockaddr *) &a4;
    break;
  case AF_INET6:
    memset (&a6, 0, alen = sizeof (struct sockaddr_in6));
    sa = (struct sockaddr *) &a6;
    break;
  default:
    GNUNET_break (0);
    GNUNET_NETWORK_socket_close (ret);
    return NULL;
  }
  sa->sa_family = af;
  if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret,
					       sa,
					       alen))
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
		_("Could not bind to any port: %s\n"),
		STRERROR (errno));
    GNUNET_NETWORK_socket_close (ret);
    return NULL;
  }
  return ret;
}


/**
 * Get a socket of the specified address family to send out a
 * UDP DNS request to the Internet.
 *
 * @param ctx the DNSSTUB context
 * @return NULL on error
 */
static struct GNUNET_DNSSTUB_RequestSocket *
get_request_socket (struct GNUNET_DNSSTUB_Context *ctx)
{
  struct GNUNET_DNSSTUB_RequestSocket *rs;

  for (unsigned int i=0;i<256;i++)
  {
    rs = &ctx->sockets[GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
                                                 ctx->num_sockets)];
    if (NULL == rs->rc)
      break;
  }
  if (NULL != rs->rc)
  {
    /* signal "failure" */
    rs->rc (rs->rc_cls,
            NULL,
            0);
    rs->rc = NULL;
  }
  if (NULL != rs->read_task)
  {
    GNUNET_SCHEDULER_cancel (rs->read_task);
    rs->read_task = NULL;
  }
  if (NULL != rs->retry_task)
  {
    GNUNET_SCHEDULER_cancel (rs->retry_task);
    rs->retry_task = NULL;
  }
  if (NULL != rs->request)
  {
    GNUNET_free (rs->request);
    rs->request = NULL;
  }
  rs->ctx = ctx;
  return rs;
}


/**
 * Actually do the reading of a DNS packet from our UDP socket and see
 * if we have a valid, matching, pending request.
 *
 * @param rs request socket with callback details
 * @param dnsout socket to read from
 * @return #GNUNET_OK on success, #GNUNET_NO on drop, #GNUNET_SYSERR on IO-errors (closed socket)
 */
static int
do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
	     struct GNUNET_NETWORK_Handle *dnsout)
{
  struct GNUNET_DNSSTUB_Context *ctx = rs->ctx;
  ssize_t r;
  int len;

#ifndef MINGW
  if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout),
                  FIONREAD,
                  &len))
  {
    /* conservative choice: */
    len = UINT16_MAX;
  }
#else
  /* port the code above? */
  len = UINT16_MAX;
#endif
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
	      "Receiving %d byte DNS reply\n",
	      len);
  {
    unsigned char buf[len] GNUNET_ALIGN;
    int found;
    struct sockaddr_storage addr;
    socklen_t addrlen;
    struct GNUNET_TUN_DnsHeader *dns;

    addrlen = sizeof (addr);
    memset (&addr,
            0,
            sizeof (addr));
    r = GNUNET_NETWORK_socket_recvfrom (dnsout,
					buf,
                                        sizeof (buf),
					(struct sockaddr*) &addr,
                                        &addrlen);
    if (-1 == r)
    {
      GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
                           "recvfrom");
      GNUNET_NETWORK_socket_close (dnsout);
      return GNUNET_SYSERR;
    }
    found = GNUNET_NO;
    for (struct DnsServer *ds = ctx->dns_head; NULL != ds; ds = ds->next)
    {
      if (0 == memcmp (&addr,
                       &ds->ss,
                       GNUNET_MIN (sizeof (struct sockaddr_storage),
                                   addrlen)))
      {
        found = GNUNET_YES;
        break;
      }
    }
    if (GNUNET_NO == found)
    {
      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
		  "Received DNS response from server we never asked (ignored)");
      return GNUNET_NO;
    }
    if (sizeof (struct GNUNET_TUN_DnsHeader) > r)
    {
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
		  _("Received DNS response that is too small (%u bytes)"),
		  (unsigned int) r);
      return GNUNET_NO;
    }
    dns = (struct GNUNET_TUN_DnsHeader *) buf;
    if (NULL == rs->rc)
    {
      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
		  "Request timeout or cancelled; ignoring reply\n");
      return GNUNET_NO;
    }
    rs->rc (rs->rc_cls,
            dns,
            r);
  }
  return GNUNET_OK;
}


/**
 * Read a DNS response from the (unhindered) UDP-Socket
 *
 * @param cls socket to read from
 */
static void
read_response (void *cls);


/**
 * Schedule #read_response() task for @a rs.
 *
 * @param rs request to schedule read operation for
 */
static void
schedule_read (struct GNUNET_DNSSTUB_RequestSocket *rs)
{
  struct GNUNET_NETWORK_FDSet *rset;

  if (NULL != rs->read_task)
    GNUNET_SCHEDULER_cancel (rs->read_task);
  rset = GNUNET_NETWORK_fdset_create ();
  if (NULL != rs->dnsout4)
    GNUNET_NETWORK_fdset_set (rset,
                              rs->dnsout4);
  if (NULL != rs->dnsout6)
    GNUNET_NETWORK_fdset_set (rset,
                              rs->dnsout6);
  rs->read_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
					       GNUNET_TIME_UNIT_FOREVER_REL,
					       rset,
					       NULL,
					       &read_response,
                                               rs);
  GNUNET_NETWORK_fdset_destroy (rset);
}


/**
 * Read a DNS response from the (unhindered) UDP-Socket
 *
 * @param cls `struct GNUNET_DNSSTUB_RequestSocket` to read from
 */
static void
read_response (void *cls)
{
  struct GNUNET_DNSSTUB_RequestSocket *rs = cls;
  const struct GNUNET_SCHEDULER_TaskContext *tc;

  rs->read_task = NULL;
  tc = GNUNET_SCHEDULER_get_task_context ();
  /* read and process ready sockets */
  if ( (NULL != rs->dnsout4) &&
       (GNUNET_NETWORK_fdset_isset (tc->read_ready,
                                    rs->dnsout4)) &&
       (GNUNET_SYSERR ==
        do_dns_read (rs,
                     rs->dnsout4)) )
    rs->dnsout4 = NULL;
  if ( (NULL != rs->dnsout6) &&
       (GNUNET_NETWORK_fdset_isset (tc->read_ready,
                                    rs->dnsout6)) &&
       (GNUNET_SYSERR ==
        do_dns_read (rs,
                     rs->dnsout6)) )
    rs->dnsout6 = NULL;
  /* re-schedule read task */
  schedule_read (rs);
}


/**
 * Task to (re)transmit the DNS query, possibly repeatedly until
 * we succeed.
 *
 * @param cls our `struct GNUNET_DNSSTUB_RequestSocket *`
 */
static void
transmit_query (void *cls)
{
  struct GNUNET_DNSSTUB_RequestSocket *rs = cls;
  struct GNUNET_DNSSTUB_Context *ctx = rs->ctx;
  const struct sockaddr *sa;
  socklen_t salen;
  struct DnsServer *ds;
  struct GNUNET_NETWORK_Handle *dnsout;

  rs->retry_task = GNUNET_SCHEDULER_add_delayed (ctx->retry_freq,
                                                 &transmit_query,
                                                 rs);
  ds = rs->ds_pos;
  rs->ds_pos = ds->next;
  if (NULL == rs->ds_pos)
    rs->ds_pos = ctx->dns_head;
  GNUNET_assert (NULL != ds);
  dnsout = NULL;
  switch (ds->ss.ss_family)
  {
  case AF_INET:
    if (NULL == rs->dnsout4)
      rs->dnsout4 = open_socket (AF_INET);
    dnsout = rs->dnsout4;
    sa = (const struct sockaddr *) &ds->ss;
    salen = sizeof (struct sockaddr_in);
    break;
  case AF_INET6:
    if (NULL == rs->dnsout6)
      rs->dnsout6 = open_socket (AF_INET6);
    dnsout = rs->dnsout6;
    sa = (const struct sockaddr *) &ds->ss;
    salen = sizeof (struct sockaddr_in6);
    break;
  default:
    return;
  }
  if (NULL == dnsout)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Unable to use configure DNS server, skipping\n");
    return;
  }
  if (GNUNET_SYSERR ==
      GNUNET_NETWORK_socket_sendto (dnsout,
				    rs->request,
				    rs->request_len,
                                    sa,
                                    salen))
    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
		_("Failed to send DNS request to %s: %s\n"),
		GNUNET_a2s (sa,
                            salen),
                STRERROR (errno));
  else
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
		_("Sent DNS request to %s\n"),
		GNUNET_a2s (sa,
                            salen));
  schedule_read (rs);
}


/**
 * Perform DNS resolution using our default IP from init.
 *
 * @param ctx stub resolver to use
 * @param request DNS request to transmit
 * @param request_len number of bytes in msg
 * @param rc function to call with result
 * @param rc_cls closure for 'rc'
 * @return socket used for the request, NULL on error
 */
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)
{
  struct GNUNET_DNSSTUB_RequestSocket *rs;

  if (NULL == ctx->dns_head)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "No DNS server configured for resolution\n");
    return NULL;
  }
  if (NULL == (rs = get_request_socket (ctx)))
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "No request socket available for DNS resolution\n");
    return NULL;
  }
  rs->ds_pos = ctx->dns_head;
  rs->rc = rc;
  rs->rc_cls = rc_cls;
  rs->request = GNUNET_memdup (request,
                               request_len);
  rs->request_len = request_len;
  rs->retry_task = GNUNET_SCHEDULER_add_now (&transmit_query,
                                             rs);
  return rs;
}


/**
 * Cancel DNS resolution.
 *
 * @param rs resolution to cancel
 */
void
GNUNET_DNSSTUB_resolve_cancel (struct GNUNET_DNSSTUB_RequestSocket *rs)
{
  rs->rc = NULL;
  if (NULL != rs->retry_task)
  {
    GNUNET_SCHEDULER_cancel (rs->retry_task);
    rs->retry_task = NULL;
  }
  if (NULL != rs->read_task)
  {
    GNUNET_SCHEDULER_cancel (rs->read_task);
    rs->read_task = NULL;
  }
}


/**
 * Start a DNS stub resolver.
 *
 * @param num_sockets how many sockets should we open
 *        in parallel for DNS queries for this stub?
 * @return NULL on error
 */
struct GNUNET_DNSSTUB_Context *
GNUNET_DNSSTUB_start (unsigned int num_sockets)
{
  struct GNUNET_DNSSTUB_Context *ctx;

  if (0 == num_sockets)
  {
    GNUNET_break (0);
    return NULL;
  }
  ctx = GNUNET_new (struct GNUNET_DNSSTUB_Context);
  ctx->num_sockets = num_sockets;
  ctx->sockets = GNUNET_new_array (num_sockets,
                                   struct GNUNET_DNSSTUB_RequestSocket);
  ctx->retry_freq = DNS_RETRANSMIT_DELAY;
  return ctx;
}


/**
 * Add nameserver for use by the DNSSTUB.  We will use
 * all provided nameservers for resolution (round-robin).
 *
 * @param ctx resolver context to modify
 * @param dns_ip target IP address to use (as string)
 * @return #GNUNET_OK on success
 */
int
GNUNET_DNSSTUB_add_dns_ip (struct GNUNET_DNSSTUB_Context *ctx,
                           const char *dns_ip)
{
  struct DnsServer *ds;
  struct in_addr i4;
  struct in6_addr i6;

  ds = GNUNET_new (struct DnsServer);
  if (1 == inet_pton (AF_INET,
                      dns_ip,
                      &i4))
  {
    struct sockaddr_in *s4 = (struct sockaddr_in *) &ds->ss;

    s4->sin_family = AF_INET;
    s4->sin_port = htons (53);
    s4->sin_addr = i4;
#if HAVE_SOCKADDR_IN_SIN_LEN
    s4->sin_len = (u_char) sizeof (struct sockaddr_in);
#endif
  }
  else if (1 == inet_pton (AF_INET6,
                           dns_ip,
                           &i6))
  {
    struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &ds->ss;

    s6->sin6_family = AF_INET6;
    s6->sin6_port = htons (53);
    s6->sin6_addr = i6;
#if HAVE_SOCKADDR_IN_SIN_LEN
    s6->sin6_len = (u_char) sizeof (struct sockaddr_in6);
#endif
  }
  else
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Malformed IP address `%s' for DNS server\n",
                dns_ip);
    GNUNET_free (ds);
    return GNUNET_SYSERR;
  }
  GNUNET_CONTAINER_DLL_insert (ctx->dns_head,
                               ctx->dns_tail,
                               ds);
  return GNUNET_OK;
}


/**
 * Add nameserver for use by the DNSSTUB.  We will use
 * all provided nameservers for resolution (round-robin).
 *
 * @param ctx resolver context to modify
 * @param sa socket address of DNS resolver to use
 * @return #GNUNET_OK on success
 */
int
GNUNET_DNSSTUB_add_dns_sa (struct GNUNET_DNSSTUB_Context *ctx,
                           const struct sockaddr *sa)
{
  struct DnsServer *ds;

  ds = GNUNET_new (struct DnsServer);
  switch (sa->sa_family)
  {
  case AF_INET:
    GNUNET_memcpy (&ds->ss,
                   sa,
                   sizeof (struct sockaddr_in));
    break;
  case AF_INET6:
    GNUNET_memcpy (&ds->ss,
                   sa,
                   sizeof (struct sockaddr_in6));
    break;
  default:
    GNUNET_break (0);
    GNUNET_free (ds);
    return GNUNET_SYSERR;
  }
  GNUNET_CONTAINER_DLL_insert (ctx->dns_head,
                               ctx->dns_tail,
                               ds);
  return GNUNET_OK;
}


/**
 * How long should we try requests before timing out?
 * Only effective for requests issued after this call.
 *
 * @param ctx resolver context to modify
 * @param retry_freq how long to wait between retries
 */
void
GNUNET_DNSSTUB_set_retry (struct GNUNET_DNSSTUB_Context *ctx,
                          struct GNUNET_TIME_Relative retry_freq)
{
  ctx->retry_freq = retry_freq;
}


/**
 * Cleanup DNSSTUB resolver.
 *
 * @param ctx stub resolver to clean up
 */
void
GNUNET_DNSSTUB_stop (struct GNUNET_DNSSTUB_Context *ctx)
{
  struct DnsServer *ds;

  while (NULL != (ds = ctx->dns_head))
  {
    GNUNET_CONTAINER_DLL_remove (ctx->dns_head,
                                 ctx->dns_tail,
                                 ds);
    GNUNET_free (ds);
  }
  for (unsigned int i=0;i<ctx->num_sockets;i++)
    cleanup_rs (&ctx->sockets[i]);
  GNUNET_free (ctx->sockets);
  GNUNET_free (ctx);
}


/* end of dnsstub.c */