130#define TIME_THRESH 10
148 char buf[INET6_ADDRSTRLEN];
197 "%s SOA %s %s %u %u %u %u %u\n",
210 "%s SRV %s %u %u %u\n",
220 "%s URI \"%s\" %u %u\n",
299 "Unsupported type %u\n",
300 (
unsigned int) rec->
type);
326 "Stub gave up on DNS reply for `%s'\n",
345 if (req->
id != dns->
id)
358 "Failed to parse DNS reply for `%s'\n",
373 for (
unsigned int i = 0; i <
p->num_answers; i++)
380 for (
unsigned int i = 0; i <
p->num_authority_records; i++)
387 for (
unsigned int i = 0; i <
p->num_additional_records; i++)
413 static struct timeval last_request;
420 if ((((now.tv_sec - last_request.tv_sec) == 0) &&
421 ((now.tv_usec - last_request.tv_usec) <
TIME_THRESH)) ||
435 req->
time = time (NULL);
522 "Refusing invalid hostname `%s'\n",
546 "Failed to pack query for hostname `%s'\n",
578 "Missing required configuration argument\n");
585 "Failed to initialize GNUnet DNS STUB\n");
593 "Failed to use `%s' for DNS resolver\n",
604 hn[strlen (
hn) - 1] =
'\0';
610 "Did %u lookups, found %u records, %u lookups failed, %u pending on shutdown\n",
static int ret
Final status code.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
static struct GNUNET_OS_Process * p
Helper process we started.
#define THRESH
Maximum number of queries pending at the same time.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static unsigned int records
Number of records we found.
static void process_queue(void *cls)
Process as many requests as possible from the queue.
int main(int argc, char **argv)
Call with IP address of resolver to query.
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
static unsigned int pending
The number of queries that are outstanding.
static struct GNUNET_SCHEDULER_Task * t
Main task.
static void run(void *cls)
Process requests from the queue, then if the queue is not empty, try again.
static void do_shutdown(void *cls)
Clean up and terminate the process.
static int submit_req(struct Request *req)
Submit a request to DNS unless we need to slow down because we are at the rate limit.
static unsigned int lookups
Number of lookups we performed overall.
static void process_result(void *cls, const struct GNUNET_TUN_DnsHeader *dns, size_t dns_len)
Function called with the result of a DNS resolution.
static struct Request * req_tail
Tail of DLL of all requests to perform.
static struct Request * req_head
Head of DLL of all requests to perform.
#define MAX_RETRIES
How often do we retry a query before giving up for good?
#define TIME_THRESH
TIME_THRESH is in usecs.
static unsigned int failures
Number of lookups that failed.
static void process_record(struct Request *req, struct GNUNET_DNSPARSER_Record *rec)
We received rec for req.
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_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_DNSPARSER_TYPE_RRSIG
#define GNUNET_DNSPARSER_TYPE_SIG
#define GNUNET_DNSPARSER_TYPE_TKEY
#define GNUNET_DNSPARSER_TYPE_URI
#define GNUNET_DNSPARSER_TYPE_OPENPGPKEY
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
#define GNUNET_DNSPARSER_TYPE_TA
#define GNUNET_DNSPARSER_TYPE_IPSECKEY
#define GNUNET_DNSPARSER_TYPE_TLSA
#define GNUNET_DNSPARSER_TYPE_DHCID
#define GNUNET_DNSPARSER_TYPE_NSEC3
#define GNUNET_DNSPARSER_TYPE_SRV
#define GNUNET_DNSPARSER_TYPE_SSHFP
#define GNUNET_DNSPARSER_TYPE_SOA
#define GNUNET_DNSPARSER_TYPE_CERT
#define GNUNET_DNSPARSER_TYPE_A
#define GNUNET_DNSPARSER_TYPE_NSEC3PARAM
#define GNUNET_DNSPARSER_TYPE_SMIMEA
#define GNUNET_DNSPARSER_TYPE_NSEC
#define GNUNET_DNSPARSER_TYPE_DS
#define GNUNET_DNSPARSER_TYPE_PTR
#define GNUNET_DNSPARSER_TYPE_HIP
int GNUNET_DNSPARSER_check_name(const char *name)
Check if a hostname in UTF-8 format can be coded into valid IDNA.
#define GNUNET_DNSPARSER_TYPE_DNSKEY
#define GNUNET_DNSPARSER_TYPE_TSIG
#define GNUNET_DNSPARSER_TYPE_NS
#define GNUNET_DNSPARSER_TYPE_NAPTR
#define GNUNET_DNSPARSER_TYPE_CNAME
#define GNUNET_DNSPARSER_TYPE_DNAME
#define GNUNET_DNSPARSER_TYPE_LOC
#define GNUNET_DNSPARSER_TYPE_RP
#define GNUNET_DNSPARSER_TYPE_CDS
#define GNUNET_DNSPARSER_TYPE_APL
#define GNUNET_DNSPARSER_TYPE_AAAA
#define GNUNET_DNSPARSER_TYPE_AFSDB
int GNUNET_DNSPARSER_pack(const struct GNUNET_DNSPARSER_Packet *p, uint16_t max, char **buf, size_t *buf_length)
Given a DNS packet p, generate the corresponding UDP payload.
#define GNUNET_DNSPARSER_TYPE_KEY
#define GNUNET_DNSPARSER_TYPE_KX
#define GNUNET_DNSPARSER_TYPE_MX
#define GNUNET_DNSPARSER_TYPE_TXT
#define GNUNET_DNSPARSER_TYPE_CDNSKEY
struct GNUNET_DNSPARSER_Packet * GNUNET_DNSPARSER_parse(const char *udp_payload, size_t udp_payload_length)
Parse a UDP payload of a DNS packet in to a nice struct for further processing and manipulation.
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_stop(struct GNUNET_DNSSTUB_Context *ctx)
Cleanup DNSSTUB resolver.
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.
#define GNUNET_log(kind,...)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
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.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
#define GNUNET_TUN_DNS_CLASS_INTERNET
A few common DNS classes (ok, only one is common, but I list a couple more to make it clear what we'r...
char * mxhost
Name of the mail server.
uint16_t preference
Preference for this entry (lower value is higher preference).
Easy-to-process, parsed version of a DNS packet.
void * data
Binary record data.
size_t data_len
Number of bytes in data.
struct GNUNET_DNSPARSER_SoaRecord * soa
SOA data for SOA records.
struct GNUNET_DNSPARSER_SrvRecord * srv
SRV data for SRV records.
struct GNUNET_DNSPARSER_MxRecord * mx
MX data for MX records.
char * hostname
For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname.
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
union GNUNET_DNSPARSER_Record::@20 data
Payload of the record (which one of these is valid depends on the 'type').
struct GNUNET_DNSPARSER_UriRecord * uri
URI data for URI records.
uint32_t retry
Time interval that should elapse before a failed refresh should be retried.
char * mname
The domainname of the name server that was the original or primary source of data for this zone.
uint32_t refresh
Time interval before the zone should be refreshed.
uint32_t minimum_ttl
The bit minimum TTL field that should be exported with any RR from this zone.
char * rname
A domainname which specifies the mailbox of the person responsible for this zone.
uint32_t expire
Time value that specifies the upper limit on the time interval that can elapse before the zone is no ...
uint32_t serial
The version number of the original copy of the zone.
uint16_t port
TCP or UDP port of the service.
uint16_t weight
Relative weight for records with the same priority.
uint16_t priority
Preference for this entry (lower value is higher preference).
char * target
Hostname offering the service.
uint16_t priority
Preference for this entry (lower value is higher preference).
uint16_t weight
Relative weight for records with the same priority.
char * target
URI of the target, where the URI is as specified in RFC 3986.
Handle to the stub resolver.
UDP socket we are using for sending DNS requests to the Internet.
Entry in list of pending tasks.
char * hostname
Hostname we are resolving, allocated at the end of this struct (optimizing memory consumption by redu...
struct Request * next
Active requests are kept in a DLL.
time_t time
When did we last issue this request?
struct GNUNET_CONTAINER_HeapNode * hn
Requests are kept in a heap while waiting to be resolved.
struct GNUNET_DNSSTUB_RequestSocket * rs
Socket used to make the request, NULL if not active.
int issue_num
How often did we issue this query?
size_t raw_len
Number of bytes in raw.
uint16_t id
random 16-bit DNS query identifier.
struct Request * prev
Active requests are kept in a DLL.
unsigned int issue_num
How often did we issue this query? (And failed, reset to zero once we were successful....