GNUnet 0.28.0-dev.3-20-gf1136b0b8
 
Loading...
Searching...
No Matches
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.
 

Functions

struct GNUNET_DNSSTUB_ContextGNUNET_DNSSTUB_start (unsigned int num_sockets)
 Start a DNS stub resolver.
 
int GNUNET_DNSSTUB_add_dns_ip (struct GNUNET_DNSSTUB_Context *ctx, const char *dns_ip)
 Add nameserver for use by the DNSSTUB.
 
int GNUNET_DNSSTUB_add_dns_sa (struct GNUNET_DNSSTUB_Context *ctx, const struct sockaddr *sa)
 Add nameserver for use by the DNSSTUB.
 
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.
 
void GNUNET_DNSSTUB_stop (struct GNUNET_DNSSTUB_Context *ctx)
 Cleanup DNSSTUB resolver.
 
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.
 
void GNUNET_DNSSTUB_resolve_cancel (struct GNUNET_DNSSTUB_RequestSocket *rs)
 Cancel DNS resolution.
 

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 585 of file dnsstub.c.

586{
588
589 if (0 == num_sockets)
590 {
591 GNUNET_break (0);
592 return NULL;
593 }
595 ctx->num_sockets = num_sockets;
596 ctx->sockets =
598 ctx->retry_freq = DNS_RETRANSMIT_DELAY;
599 return ctx;
600}
#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(), run(), run(), 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 612 of file dnsstub.c.

614{
615 struct DnsServer *ds;
616 struct in_addr i4;
617 struct in6_addr i6;
618
619 ds = GNUNET_new (struct DnsServer);
620 if (1 == inet_pton (AF_INET, dns_ip, &i4))
621 {
622 struct sockaddr_in *s4 = (struct sockaddr_in *) &ds->ss;
623
624 s4->sin_family = AF_INET;
625 s4->sin_port = htons (53);
626 s4->sin_addr = i4;
627#if HAVE_SOCKADDR_IN_SIN_LEN
628 s4->sin_len = (u_char) sizeof(struct sockaddr_in);
629#endif
630 }
631 else if (1 == inet_pton (AF_INET6, dns_ip, &i6))
632 {
633 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &ds->ss;
634
635 s6->sin6_family = AF_INET6;
636 s6->sin6_port = htons (53);
637 s6->sin6_addr = i6;
638#if HAVE_SOCKADDR_IN_SIN_LEN
639 s6->sin6_len = (u_char) sizeof(struct sockaddr_in6);
640#endif
641 }
642 else
643 {
645 "Malformed IP address `%s' for DNS server\n",
646 dns_ip);
647 GNUNET_free (ds);
648 return GNUNET_SYSERR;
649 }
650 GNUNET_CONTAINER_DLL_insert (ctx->dns_head, ctx->dns_tail, ds);
651 return GNUNET_OK;
652}
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(), run(), run(), 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 664 of file dnsstub.c.

666{
667 struct DnsServer *ds;
668
669 ds = GNUNET_new (struct DnsServer);
670 switch (sa->sa_family)
671 {
672 case AF_INET:
673 GNUNET_memcpy (&ds->ss, sa, sizeof(struct sockaddr_in));
674 break;
675
676 case AF_INET6:
677 GNUNET_memcpy (&ds->ss, sa, sizeof(struct sockaddr_in6));
678 break;
679
680 default:
681 GNUNET_break (0);
682 GNUNET_free (ds);
683 return GNUNET_SYSERR;
684 }
685 GNUNET_CONTAINER_DLL_insert (ctx->dns_head, ctx->dns_tail, ds);
686 return GNUNET_OK;
687}
#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 691 of file dnsstub.c.

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

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 704 of file dnsstub.c.

705{
706 struct DnsServer *ds;
707
708 while (NULL != (ds = ctx->dns_head))
709 {
710 GNUNET_CONTAINER_DLL_remove (ctx->dns_head, ctx->dns_tail, ds);
711 GNUNET_free (ds);
712 }
713 for (unsigned int i = 0; i < ctx->num_sockets; i++)
714 cleanup_rs (&ctx->sockets[i]);
715 GNUNET_free (ctx->sockets);
717}
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(), do_shutdown(), 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 525 of file dnsstub.c.

530{
532
533 if (NULL == ctx->dns_head)
534 {
536 "No DNS server configured for resolution\n");
537 return NULL;
538 }
539 if (NULL == (rs = get_request_socket (ctx)))
540 {
542 "No request socket available for DNS resolution\n");
543 return NULL;
544 }
545 rs->ds_pos = ctx->dns_head;
546 rs->rc = rc;
547 rs->rc_cls = rc_cls;
551 return rs;
552}
static void transmit_query(void *cls)
Task to (re)transmit the DNS query, possibly repeatedly until we succeed.
Definition dnsstub.c:453
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:1310
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 561 of file dnsstub.c.

562{
563 rs->rc = NULL;
564 if (NULL != rs->retry_task)
565 {
567 rs->retry_task = NULL;
568 }
569 if (NULL != rs->read_task)
570 {
572 rs->read_task = NULL;
573 }
574}
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
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(), process_result(), and process_result().

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