GNUnet 0.22.2
DNS Stub library

Helper library to send DNS requests to DNS resolver. More...

Collaboration diagram for DNS Stub library:

Typedefs

typedef void(* GNUNET_DNSSTUB_ResultCallback) (void *cls, const struct GNUNET_TUN_DnsHeader *dns, size_t dns_len)
 Function called with the result of a DNS resolution. More...
 

Functions

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...
 
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...
 

Detailed Description

Helper library to send DNS requests to DNS resolver.

Typedef Documentation

◆ GNUNET_DNSSTUB_ResultCallback

typedef void(* GNUNET_DNSSTUB_ResultCallback) (void *cls, const struct GNUNET_TUN_DnsHeader *dns, size_t dns_len)

Function called with the result of a DNS resolution.

Once this function is called, the resolution request is automatically cancelled / cleaned up. In particular, the function will only be called once.

Parameters
clsclosure
dnsdns response, NULL on hard error (i.e. timeout)
dns_lennumber of bytes in dns

Definition at line 122 of file gnunet_dnsstub_lib.h.

Function Documentation

◆ GNUNET_DNSSTUB_start()

struct GNUNET_DNSSTUB_Context * GNUNET_DNSSTUB_start ( unsigned int  num_sockets)

Start a DNS stub resolver.

Parameters
num_socketshow many sockets should we open in parallel for DNS queries for this stub?
Returns
NULL on error

Definition at line 586 of file dnsstub.c.

587{
589
590 if (0 == num_sockets)
591 {
592 GNUNET_break (0);
593 return NULL;
594 }
596 ctx->num_sockets = num_sockets;
597 ctx->sockets =
599 ctx->retry_freq = DNS_RETRANSMIT_DELAY;
600 return ctx;
601}
#define DNS_RETRANSMIT_DELAY
Timeout for retrying DNS queries.
Definition: dnsstub.c:32
static struct GNUNET_FS_Handle * ctx
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
Handle to the stub resolver.
Definition: dnsstub.c:125
unsigned int num_sockets
Length of sockets array.
Definition: dnsstub.c:149
UDP socket we are using for sending DNS requests to the Internet.
Definition: dnsstub.c:46

References ctx, DNS_RETRANSMIT_DELAY, GNUNET_break, GNUNET_new, GNUNET_new_array, and GNUNET_DNSSTUB_Context::num_sockets.

Referenced by advertise_dns_exit(), init_cb(), main(), recursive_gns2dns_resolution(), and run().

Here is the caller graph for this function:

◆ GNUNET_DNSSTUB_add_dns_ip()

int GNUNET_DNSSTUB_add_dns_ip ( struct GNUNET_DNSSTUB_Context ctx,
const char *  dns_ip 
)

Add nameserver for use by the DNSSTUB.

We will use all provided nameservers for resolution (round-robin).

Parameters
ctxresolver context to modify
dns_iptarget IP address to use (as string)
Returns
GNUNET_OK on success

Definition at line 613 of file dnsstub.c.

615{
616 struct DnsServer *ds;
617 struct in_addr i4;
618 struct in6_addr i6;
619
620 ds = GNUNET_new (struct DnsServer);
621 if (1 == inet_pton (AF_INET, dns_ip, &i4))
622 {
623 struct sockaddr_in *s4 = (struct sockaddr_in *) &ds->ss;
624
625 s4->sin_family = AF_INET;
626 s4->sin_port = htons (53);
627 s4->sin_addr = i4;
628#if HAVE_SOCKADDR_IN_SIN_LEN
629 s4->sin_len = (u_char) sizeof(struct sockaddr_in);
630#endif
631 }
632 else if (1 == inet_pton (AF_INET6, dns_ip, &i6))
633 {
634 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &ds->ss;
635
636 s6->sin6_family = AF_INET6;
637 s6->sin6_port = htons (53);
638 s6->sin6_addr = i6;
639#if HAVE_SOCKADDR_IN_SIN_LEN
640 s6->sin6_len = (u_char) sizeof(struct sockaddr_in6);
641#endif
642 }
643 else
644 {
646 "Malformed IP address `%s' for DNS server\n",
647 dns_ip);
648 GNUNET_free (ds);
649 return GNUNET_SYSERR;
650 }
651 GNUNET_CONTAINER_DLL_insert (ctx->dns_head, ctx->dns_tail, ds);
652 return GNUNET_OK;
653}
static char * dns_ip
IP of DNS server.
static struct GNUNET_FS_DirScanner * ds
Handle to the directory scanner (for recursive insertions).
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
DNS Server used for resolution.
Definition: dnsstub.c:103

References ctx, dns_ip, ds, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_new, GNUNET_OK, and GNUNET_SYSERR.

Referenced by advertise_dns_exit(), init_cb(), main(), recursive_gns2dns_resolution(), and run().

Here is the caller graph for this function:

◆ GNUNET_DNSSTUB_add_dns_sa()

int GNUNET_DNSSTUB_add_dns_sa ( struct GNUNET_DNSSTUB_Context ctx,
const struct sockaddr *  sa 
)

Add nameserver for use by the DNSSTUB.

We will use all provided nameservers for resolution (round-robin).

Parameters
ctxresolver context to modify
sasocket address of DNS resolver to use
Returns
GNUNET_OK on success

Definition at line 665 of file dnsstub.c.

667{
668 struct DnsServer *ds;
669
670 ds = GNUNET_new (struct DnsServer);
671 switch (sa->sa_family)
672 {
673 case AF_INET :
674 GNUNET_memcpy (&ds->ss, sa, sizeof(struct sockaddr_in));
675 break;
676
677 case AF_INET6:
678 GNUNET_memcpy (&ds->ss, sa, sizeof(struct sockaddr_in6));
679 break;
680
681 default:
682 GNUNET_break (0);
683 GNUNET_free (ds);
684 return GNUNET_SYSERR;
685 }
686 GNUNET_CONTAINER_DLL_insert (ctx->dns_head, ctx->dns_tail, ds);
687 return GNUNET_OK;
688}
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.

References ctx, ds, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_free, GNUNET_memcpy, GNUNET_new, GNUNET_OK, and GNUNET_SYSERR.

Referenced by handle_gns2dns_ip(), and handle_gns2dns_result().

Here is the caller graph for this function:

◆ GNUNET_DNSSTUB_set_retry()

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.

Parameters
ctxresolver context to modify
retry_freqhow long to wait between retries

Definition at line 692 of file dnsstub.c.

694{
695 ctx->retry_freq = retry_freq;
696}

References ctx.

◆ GNUNET_DNSSTUB_stop()

void GNUNET_DNSSTUB_stop ( struct GNUNET_DNSSTUB_Context ctx)

Cleanup DNSSTUB resolver.

Parameters
ctxstub resolver to clean up

Definition at line 705 of file dnsstub.c.

706{
707 struct DnsServer *ds;
708
709 while (NULL != (ds = ctx->dns_head))
710 {
711 GNUNET_CONTAINER_DLL_remove (ctx->dns_head, ctx->dns_tail, ds);
712 GNUNET_free (ds);
713 }
714 for (unsigned int i = 0; i < ctx->num_sockets; i++)
715 cleanup_rs (&ctx->sockets[i]);
716 GNUNET_free (ctx->sockets);
718}
static void cleanup_rs(struct GNUNET_DNSSTUB_RequestSocket *rs)
We're done with a struct GNUNET_DNSSTUB_RequestSocket, close it for now.
Definition: dnsstub.c:159
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.

References cleanup_rs(), ctx, ds, GNUNET_CONTAINER_DLL_remove, and GNUNET_free.

Referenced by cleanup(), cleanup_task(), do_shutdown(), GNS_resolver_lookup_cancel(), run(), and shutdown_task().

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

◆ GNUNET_DNSSTUB_resolve()

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.

Parameters
ctxstub resolver to use
requestDNS request to transmit
request_lennumber of bytes in msg
rcfunction to call with result (once)
rc_clsclosure for rc
Returns
socket used for the request, NULL on error
Parameters
ctxstub resolver to use
requestDNS request to transmit
request_lennumber of bytes in msg
rcfunction to call with result
rc_clsclosure for 'rc'
Returns
socket used for the request, NULL on error

Definition at line 526 of file dnsstub.c.

531{
533
534 if (NULL == ctx->dns_head)
535 {
537 "No DNS server configured for resolution\n");
538 return NULL;
539 }
540 if (NULL == (rs = get_request_socket (ctx)))
541 {
543 "No request socket available for DNS resolution\n");
544 return NULL;
545 }
546 rs->ds_pos = ctx->dns_head;
547 rs->rc = rc;
548 rs->rc_cls = rc_cls;
552 return rs;
553}
static void transmit_query(void *cls)
Task to (re)transmit the DNS query, possibly repeatedly until we succeed.
Definition: dnsstub.c:454
static struct GNUNET_DNSSTUB_RequestSocket * get_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.
Definition: dnsstub.c:245
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:40
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1304
void * request
Query we sent to addr.
Definition: dnsstub.c:90
GNUNET_DNSSTUB_ResultCallback rc
Function to call with result.
Definition: dnsstub.c:60
struct GNUNET_SCHEDULER_Task * retry_task
Task for retrying transmission of the query.
Definition: dnsstub.c:75
size_t request_len
Number of bytes in request.
Definition: dnsstub.c:95
void * rc_cls
Closure for rc.
Definition: dnsstub.c:65
struct DnsServer * ds_pos
Next address we sent the DNS request to.
Definition: dnsstub.c:80

References ctx, GNUNET_DNSSTUB_RequestSocket::ds_pos, get_request_socket(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_memdup, GNUNET_SCHEDULER_add_now(), GNUNET_DNSSTUB_RequestSocket::rc, GNUNET_DNSSTUB_RequestSocket::rc_cls, request, GNUNET_DNSSTUB_RequestSocket::request, GNUNET_DNSSTUB_RequestSocket::request_len, GNUNET_DNSSTUB_RequestSocket::retry_task, and transmit_query().

Referenced by handle_dns_request(), handle_resolve_result(), next_phase(), process_queue(), recursive_dns_resolution(), resolve_and_cache(), result_processor(), and submit_req().

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

◆ GNUNET_DNSSTUB_resolve_cancel()

void GNUNET_DNSSTUB_resolve_cancel ( struct GNUNET_DNSSTUB_RequestSocket rs)

Cancel DNS resolution.

Parameters
rsresolution to cancel

Definition at line 562 of file dnsstub.c.

563{
564 rs->rc = NULL;
565 if (NULL != rs->retry_task)
566 {
568 rs->retry_task = NULL;
569 }
570 if (NULL != rs->read_task)
571 {
573 rs->read_task = NULL;
574 }
575}
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
struct GNUNET_SCHEDULER_Task * read_task
Task for reading from dnsout4 and dnsout6.
Definition: dnsstub.c:70

References GNUNET_SCHEDULER_cancel(), GNUNET_DNSSTUB_RequestSocket::rc, GNUNET_DNSSTUB_RequestSocket::read_task, and GNUNET_DNSSTUB_RequestSocket::retry_task.

Referenced by dns_result_parser(), dns_result_processor(), do_timeout(), free_active_lookup(), GNS_resolver_lookup_cancel(), handle_resolve_result(), and process_result().

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