32#define DNS_RETRANSMIT_DELAY \
33 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
117 struct sockaddr_storage
ss;
198 struct sockaddr_in a4;
199 struct sockaddr_in6 a6;
210 memset (&a4, 0, alen =
sizeof(
struct sockaddr_in));
211 sa = (
struct sockaddr *) &a4;
215 memset (&a6, 0, alen =
sizeof(
struct sockaddr_in6));
216 sa = (
struct sockaddr *) &a6;
228 _ (
"Could not bind to any port: %s\n"),
249 for (
unsigned int i = 0; i < 256; i++)
308 struct sockaddr_storage addr;
312 addrlen =
sizeof(addr);
313 memset (&addr, 0,
sizeof(addr));
317 (
struct sockaddr *) &addr,
328 if (
ds->ss.ss_family != addr.ss_family)
330 if (addr.ss_family == AF_INET)
332 struct sockaddr_in *v4 = (
struct sockaddr_in *) &addr;
333 struct sockaddr_in *ds_v4 = (
struct sockaddr_in *) &
ds->ss;
336 if ((0 == memcmp (&v4->sin_addr,
338 sizeof(
struct sockaddr_in))) &&
339 (v4->sin_port == ds_v4->sin_port))
347 struct sockaddr_in6 *v6 = (
struct sockaddr_in6 *) &addr;
348 struct sockaddr_in6 *ds_v6 = (
struct sockaddr_in6 *) &
ds->ss;
350 if (0 == memcmp (&v6->sin6_addr,
352 sizeof (v6->sin6_addr)) &&
353 (v6->sin6_port == ds_v6->sin6_port))
364 "Received DNS response from server we never asked (ignored)\n");
371 _ (
"Received DNS response that is too small (%u bytes)\n"),
379 "Request timeout or cancelled; ignoring reply\n");
458 const struct sockaddr *sa;
471 switch (
ds->ss.ss_family)
477 sa = (
const struct sockaddr *) &
ds->ss;
478 salen =
sizeof(
struct sockaddr_in);
485 sa = (
const struct sockaddr *) &
ds->ss;
486 salen =
sizeof(
struct sockaddr_in6);
495 "Unable to use configure DNS server, skipping\n");
504 _ (
"Failed to send DNS request to %s: %s\n"),
509 _ (
"Sent DNS request to %s\n"),
534 if (NULL ==
ctx->dns_head)
537 "No DNS server configured for resolution\n");
543 "No request socket available for DNS resolution\n");
621 if (1 == inet_pton (AF_INET,
dns_ip, &i4))
623 struct sockaddr_in *s4 = (
struct sockaddr_in *) &
ds->ss;
625 s4->sin_family = AF_INET;
626 s4->sin_port = htons (53);
628#if HAVE_SOCKADDR_IN_SIN_LEN
629 s4->sin_len = (u_char)
sizeof(
struct sockaddr_in);
632 else if (1 == inet_pton (AF_INET6,
dns_ip, &i6))
634 struct sockaddr_in6 *s6 = (
struct sockaddr_in6 *) &
ds->ss;
636 s6->sin6_family = AF_INET6;
637 s6->sin6_port = htons (53);
639#if HAVE_SOCKADDR_IN_SIN_LEN
640 s6->sin6_len = (u_char)
sizeof(
struct sockaddr_in6);
646 "Malformed IP address `%s' for DNS server\n",
666 const struct sockaddr *sa)
671 switch (sa->sa_family)
695 ctx->retry_freq = retry_freq;
709 while (NULL != (
ds =
ctx->dns_head))
714 for (
unsigned int i = 0; i <
ctx->num_sockets; i++)
static void transmit_query(void *cls)
Task to (re)transmit the DNS query, possibly repeatedly until we succeed.
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.
static void read_response(void *cls)
Read a DNS response from the (unhindered) UDP-Socket.
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,...
static void schedule_read(struct GNUNET_DNSSTUB_RequestSocket *rs)
Schedule read_response() task for rs.
static struct GNUNET_NETWORK_Handle * open_socket(int af)
Open source port for sending DNS requests.
static void cleanup_rs(struct GNUNET_DNSSTUB_RequestSocket *rs)
We're done with a struct GNUNET_DNSSTUB_RequestSocket, close it for now.
#define DNS_RETRANSMIT_DELAY
Timeout for retrying DNS queries.
static int ret
Final status code.
static char * dns_ip
IP of DNS server.
static struct GNUNET_FS_Handle * ctx
static struct GNUNET_FS_DirScanner * ds
Handle to the directory scanner (for recursive insertions).
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_DNSSTUB_Context * GNUNET_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.
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.
void GNUNET_DNSSTUB_stop(struct GNUNET_DNSSTUB_Context *ctx)
Cleanup DNSSTUB resolver.
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...
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.
void GNUNET_DNSSTUB_resolve_cancel(struct GNUNET_DNSSTUB_RequestSocket *rs)
Cancel DNS resolution.
int GNUNET_DNSSTUB_add_dns_sa(struct GNUNET_DNSSTUB_Context *ctx, const struct sockaddr *sa)
Add nameserver for use by the DNSSTUB.
#define GNUNET_log(kind,...)
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_SCHEDULER_PRIORITY_DEFAULT
Run with the default priority (normal P2P operations).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
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).
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#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.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
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).
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Add a socket to the FD set.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
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).
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.
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...
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
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.
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.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
DNS Server used for resolution.
struct DnsServer * next
Kept in a DLL.
struct DnsServer * prev
Kept in a DLL.
struct sockaddr_storage ss
IP address of the DNS resolver.
Handle to the stub resolver.
struct DnsServer * dns_tail
DLL of DNS resolvers we use.
unsigned int num_sockets
Length of sockets array.
struct GNUNET_DNSSTUB_RequestSocket * sockets
Array of all open sockets for DNS requests.
struct DnsServer * dns_head
DLL of DNS resolvers we use.
struct GNUNET_TIME_Relative retry_freq
How frequently do we retry requests?
UDP socket we are using for sending DNS requests to the Internet.
void * request
Query we sent to addr.
struct GNUNET_DNSSTUB_Context * ctx
Context this request executes in.
struct GNUNET_NETWORK_Handle * dnsout4
UDP socket we use for this request for IPv4.
struct GNUNET_SCHEDULER_Task * read_task
Task for reading from dnsout4 and dnsout6.
GNUNET_DNSSTUB_ResultCallback rc
Function to call with result.
struct GNUNET_SCHEDULER_Task * retry_task
Task for retrying transmission of the query.
struct GNUNET_NETWORK_Handle * dnsout6
UDP socket we use for this request for IPv6.
size_t request_len
Number of bytes in request.
void * rc_cls
Closure for rc.
struct DnsServer * ds_pos
Next address we sent the DNS request to.
collection of IO descriptors
int af
Address family / domain.
Context information passed to each scheduler task.
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 ...
Entry in list of pending tasks.
Time for relative time used by GNUnet, in microseconds.