GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
gnunet-zonewalk.c File Reference
#include "platform.h"
#include <gnunet_util_lib.h>
#include <gnunet_dnsstub_lib.h>
#include <gnunet_dnsparser_lib.h>
Include dependency graph for gnunet-zonewalk.c:

Go to the source code of this file.

Data Structures

struct  Request
 Request we should make. More...
 

Macros

#define THRESH   20
 Maximum number of queries pending at the same time. More...
 
#define TIME_THRESH   10
 TIME_THRESH is in usecs. More...
 
#define MAX_RETRIES   5
 How often do we retry a query before giving up for good? More...
 

Functions

static void process_record (struct Request *req, struct GNUNET_DNSPARSER_Record *rec)
 We received rec for req. More...
 
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. More...
 
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. More...
 
static void process_queue (void *cls)
 Process as many requests as possible from the queue. More...
 
static void do_shutdown (void *cls)
 Clean up and terminate the process. More...
 
static void run (void *cls)
 Process requests from the queue, then if the queue is not empty, try again. More...
 
static void queue (const char *hostname)
 Add hostname to the list of requests to be made. More...
 
int main (int argc, char **argv)
 Call with IP address of resolver to query. More...
 

Variables

static struct GNUNET_DNSSTUB_Contextctx
 Context for DNS resolution. More...
 
static unsigned int pending
 The number of queries that are outstanding. More...
 
static unsigned int lookups
 Number of lookups we performed overall. More...
 
static unsigned int failures
 Number of lookups that failed. More...
 
static unsigned int records
 Number of records we found. More...
 
static struct Requestreq_head
 Head of DLL of all requests to perform. More...
 
static struct Requestreq_tail
 Tail of DLL of all requests to perform. More...
 
static struct GNUNET_SCHEDULER_Taskt
 Main task. More...
 

Macro Definition Documentation

◆ THRESH

#define THRESH   20

Maximum number of queries pending at the same time.

Definition at line 126 of file gnunet-zonewalk.c.

Referenced by submit_req().

◆ TIME_THRESH

#define TIME_THRESH   10

TIME_THRESH is in usecs.

How quickly do we submit fresh queries. Used as an additional throttle.

Definition at line 132 of file gnunet-zonewalk.c.

Referenced by submit_req().

◆ MAX_RETRIES

#define MAX_RETRIES   5

How often do we retry a query before giving up for good?

Definition at line 137 of file gnunet-zonewalk.c.

Referenced by process_result().

Function Documentation

◆ process_record()

static void process_record ( struct Request req,
struct GNUNET_DNSPARSER_Record rec 
)
static

We received rec for req.

Remember the answer.

Parameters
reqrequest
recresponse

Definition at line 147 of file gnunet-zonewalk.c.

References buf, GNUNET_DNSPARSER_RawRecord::data, GNUNET_DNSPARSER_Record::data, GNUNET_DNSPARSER_RawRecord::data_len, GNUNET_DNSPARSER_SoaRecord::expire, GNUNET_DNSPARSER_TYPE_A, GNUNET_DNSPARSER_TYPE_AAAA, GNUNET_DNSPARSER_TYPE_AFSDB, GNUNET_DNSPARSER_TYPE_APL, GNUNET_DNSPARSER_TYPE_CDNSKEY, GNUNET_DNSPARSER_TYPE_CDS, GNUNET_DNSPARSER_TYPE_CERT, GNUNET_DNSPARSER_TYPE_CNAME, GNUNET_DNSPARSER_TYPE_DHCID, GNUNET_DNSPARSER_TYPE_DNAME, GNUNET_DNSPARSER_TYPE_DNSKEY, GNUNET_DNSPARSER_TYPE_DS, GNUNET_DNSPARSER_TYPE_HIP, GNUNET_DNSPARSER_TYPE_IPSECKEY, GNUNET_DNSPARSER_TYPE_KEY, GNUNET_DNSPARSER_TYPE_KX, GNUNET_DNSPARSER_TYPE_LOC, GNUNET_DNSPARSER_TYPE_MX, GNUNET_DNSPARSER_TYPE_NAPTR, GNUNET_DNSPARSER_TYPE_NS, GNUNET_DNSPARSER_TYPE_NSEC, GNUNET_DNSPARSER_TYPE_NSEC3, GNUNET_DNSPARSER_TYPE_NSEC3PARAM, GNUNET_DNSPARSER_TYPE_OPENPGPKEY, GNUNET_DNSPARSER_TYPE_PTR, GNUNET_DNSPARSER_TYPE_RP, GNUNET_DNSPARSER_TYPE_RRSIG, GNUNET_DNSPARSER_TYPE_SIG, GNUNET_DNSPARSER_TYPE_SOA, GNUNET_DNSPARSER_TYPE_SRV, GNUNET_DNSPARSER_TYPE_SSHFP, GNUNET_DNSPARSER_TYPE_TA, GNUNET_DNSPARSER_TYPE_TKEY, GNUNET_DNSPARSER_TYPE_TLSA, GNUNET_DNSPARSER_TYPE_TSIG, GNUNET_DNSPARSER_TYPE_TXT, GNUNET_DNSPARSER_TYPE_URI, GNUNET_free, GNUNET_STRINGS_data_to_string_alloc(), Request::hostname, GNUNET_DNSPARSER_Record::hostname, GNUNET_DNSPARSER_SoaRecord::minimum_ttl, GNUNET_DNSPARSER_SoaRecord::mname, GNUNET_DNSPARSER_Record::mx, GNUNET_DNSPARSER_MxRecord::mxhost, GNUNET_DNSPARSER_SrvRecord::port, GNUNET_DNSPARSER_MxRecord::preference, GNUNET_DNSPARSER_SrvRecord::priority, GNUNET_DNSPARSER_Record::raw, records, GNUNET_DNSPARSER_SoaRecord::refresh, GNUNET_DNSPARSER_SoaRecord::retry, GNUNET_DNSPARSER_SoaRecord::rname, GNUNET_DNSPARSER_SoaRecord::serial, GNUNET_DNSPARSER_Record::soa, GNUNET_DNSPARSER_Record::srv, GNUNET_DNSPARSER_SrvRecord::target, GNUNET_DNSPARSER_Record::type, and GNUNET_DNSPARSER_SrvRecord::weight.

Referenced by process_result().

149 {
150  char buf[INET6_ADDRSTRLEN];
151 
152  records++;
153  switch (rec->type)
154  {
156  fprintf (stdout,
157  "%s A %s\n",
158  req->hostname,
159  inet_ntop (AF_INET,
160  rec->data.raw.data,
161  buf,
162  sizeof (buf)));
163  break;
165  fprintf (stdout,
166  "%s AAAA %s\n",
167  req->hostname,
168  inet_ntop (AF_INET6,
169  rec->data.raw.data,
170  buf,
171  sizeof (buf)));
172  break;
174  fprintf (stdout,
175  "%s NS %s\n",
176  req->hostname,
177  rec->data.hostname);
178  break;
180  fprintf (stdout,
181  "%s CNAME %s\n",
182  req->hostname,
183  rec->data.hostname);
184  break;
186  fprintf (stdout,
187  "%s MX %u %s\n",
188  req->hostname,
189  (unsigned int) rec->data.mx->preference,
190  rec->data.mx->mxhost);
191  break;
193  fprintf (stdout,
194  "%s SOA %s %s %u %u %u %u %u\n",
195  req->hostname,
196  rec->data.soa->mname,
197  rec->data.soa->rname,
198  (unsigned int) rec->data.soa->serial,
199  (unsigned int) rec->data.soa->refresh,
200  (unsigned int) rec->data.soa->retry,
201  (unsigned int) rec->data.soa->expire,
202  (unsigned int) rec->data.soa->minimum_ttl);
203  break;
205  fprintf (stdout,
206  "%s SRV %s %u %u %u\n",
207  req->hostname,
208  rec->data.srv->target,
209  rec->data.srv->priority,
210  rec->data.srv->weight,
211  rec->data.srv->port);
212  break;
214  fprintf (stdout,
215  "%s PTR %s\n",
216  req->hostname,
217  rec->data.hostname);
218  break;
220  fprintf (stdout,
221  "%s TXT %.*s\n",
222  req->hostname,
223  (int) rec->data.raw.data_len,
224  (char *) rec->data.raw.data);
225  break;
227  fprintf (stdout,
228  "%s DNAME %s\n",
229  req->hostname,
230  rec->data.hostname);
231  break;
232 
233  /* obscure records */
245 
246  /* DNSSEC */
255 
256  /* DNSSEC payload */
262 
263  /* obsolete records */
267  {
268  char *base32;
269 
271  rec->data.raw.data_len);
272  fprintf (stdout,
273  "%s (%u) %s\n",
274  req->hostname,
275  rec->type,
276  base32);
277  GNUNET_free (base32);
278  }
279  break;
280  default:
281  fprintf (stderr,
282  "Unsupported type %u\n",
283  (unsigned int) rec->type);
284  break;
285  }
286 }
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
#define GNUNET_DNSPARSER_TYPE_SIG
#define GNUNET_DNSPARSER_TYPE_AFSDB
uint32_t retry
Time interval that should elapse before a failed refresh should be retried.
uint32_t refresh
Time interval before the zone should be refreshed.
char * mname
The domainname of the name server that was the original or primary source of data for this zone...
char * hostname
Hostname we are resolving.
#define GNUNET_DNSPARSER_TYPE_KX
#define GNUNET_DNSPARSER_TYPE_TKEY
#define GNUNET_DNSPARSER_TYPE_CNAME
char * mxhost
Name of the mail server.
struct GNUNET_DNSPARSER_SrvRecord * srv
SRV data for SRV records.
#define GNUNET_DNSPARSER_TYPE_SSHFP
#define GNUNET_DNSPARSER_TYPE_APL
#define GNUNET_DNSPARSER_TYPE_LOC
#define GNUNET_DNSPARSER_TYPE_NSEC3PARAM
#define GNUNET_DNSPARSER_TYPE_MX
#define GNUNET_DNSPARSER_TYPE_HIP
uint32_t serial
The version number of the original copy of the zone.
#define GNUNET_DNSPARSER_TYPE_PTR
static unsigned int records
Number of records we found.
uint32_t minimum_ttl
The bit minimum TTL field that should be exported with any RR from this zone.
#define GNUNET_DNSPARSER_TYPE_SOA
char * hostname
For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname.
struct GNUNET_DNSPARSER_SoaRecord * soa
SOA data for SOA records.
#define GNUNET_DNSPARSER_TYPE_RP
uint16_t port
TCP or UDP port of the service.
#define GNUNET_DNSPARSER_TYPE_TA
#define GNUNET_DNSPARSER_TYPE_DNAME
char * target
Hostname offering the service.
#define GNUNET_DNSPARSER_TYPE_DS
char * rname
A domainname which specifies the mailbox of the person responsible for this zone. ...
static char buf[2048]
uint32_t expire
Time value that specifies the upper limit on the time interval that can elapse before the zone is no ...
#define GNUNET_DNSPARSER_TYPE_RRSIG
#define GNUNET_DNSPARSER_TYPE_CDNSKEY
#define GNUNET_DNSPARSER_TYPE_IPSECKEY
size_t data_len
Number of bytes in data.
void * data
Binary record data.
#define GNUNET_DNSPARSER_TYPE_TXT
#define GNUNET_DNSPARSER_TYPE_NAPTR
#define GNUNET_DNSPARSER_TYPE_OPENPGPKEY
#define GNUNET_DNSPARSER_TYPE_URI
#define GNUNET_DNSPARSER_TYPE_TLSA
struct GNUNET_DNSPARSER_MxRecord * mx
MX data for MX records.
#define GNUNET_DNSPARSER_TYPE_KEY
#define GNUNET_DNSPARSER_TYPE_AAAA
#define GNUNET_DNSPARSER_TYPE_NS
#define GNUNET_DNSPARSER_TYPE_NSEC
#define GNUNET_DNSPARSER_TYPE_CDS
#define GNUNET_DNSPARSER_TYPE_NSEC3
uint16_t priority
Preference for this entry (lower value is higher preference).
uint16_t weight
Relative weight for records with the same priority.
#define GNUNET_DNSPARSER_TYPE_DHCID
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:988
union GNUNET_DNSPARSER_Record::@27 data
Payload of the record (which one of these is valid depends on the &#39;type&#39;).
#define GNUNET_DNSPARSER_TYPE_SRV
uint16_t preference
Preference for this entry (lower value is higher preference).
#define GNUNET_DNSPARSER_TYPE_TSIG
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
#define GNUNET_DNSPARSER_TYPE_A
#define GNUNET_DNSPARSER_TYPE_CERT
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_DNSPARSER_TYPE_DNSKEY
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_result()

static void process_result ( void *  cls,
const struct GNUNET_TUN_DnsHeader dns,
size_t  dns_len 
)
static

Function called with the result of a DNS resolution.

Parameters
clsclosure with the struct Request
dnsdns response, never NULL
dns_lennumber of bytes in dns

Definition at line 297 of file gnunet-zonewalk.c.

References GNUNET_DNSPARSER_Packet::additional_records, GNUNET_DNSPARSER_Packet::answers, GNUNET_DNSPARSER_Packet::authority_records, failures, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_DNSPARSER_free_packet(), GNUNET_DNSPARSER_parse(), GNUNET_DNSSTUB_resolve_cancel(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, Request::hostname, Request::id, GNUNET_TUN_DnsHeader::id, Request::issue_num, MAX_RETRIES, GNUNET_DNSPARSER_Packet::num_additional_records, GNUNET_DNSPARSER_Packet::num_answers, GNUNET_DNSPARSER_Packet::num_authority_records, p, pending, process_record(), Request::raw, and Request::rs.

Referenced by submit_req().

300 {
301  struct Request *req = cls;
302  struct GNUNET_DNSPARSER_Packet *p;
303 
304  if (NULL == dns)
305  {
306  /* stub gave up */
307  pending--;
309  "Stub gave up on DNS reply for `%s'\n",
310  req->hostname);
312  req_tail,
313  req);
314  if (req->issue_num > MAX_RETRIES)
315  {
316  failures++;
317  GNUNET_free (req->hostname);
318  GNUNET_free (req->raw);
319  GNUNET_free (req);
320  return;
321  }
323  req_tail,
324  req);
325  req->rs = NULL;
326  return;
327  }
328  if (req->id != dns->id)
329  return;
330  pending--;
332  req->rs = NULL;
334  req_tail,
335  req);
336  p = GNUNET_DNSPARSER_parse ((const char *) dns,
337  dns_len);
338  if (NULL == p)
339  {
341  "Failed to parse DNS reply for `%s'\n",
342  req->hostname);
343  if (req->issue_num > MAX_RETRIES)
344  {
345  failures++;
346  GNUNET_free (req->hostname);
347  GNUNET_free (req->raw);
348  GNUNET_free (req);
349  return;
350  }
352  req_tail,
353  req);
354  return;
355  }
356  for (unsigned int i=0;i<p->num_answers;i++)
357  {
358  struct GNUNET_DNSPARSER_Record *rs = &p->answers[i];
359 
360  process_record (req,
361  rs);
362  }
363  for (unsigned int i=0;i<p->num_authority_records;i++)
364  {
365  struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i];
366 
367  process_record (req,
368  rs);
369  }
370  for (unsigned int i=0;i<p->num_additional_records;i++)
371  {
372  struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i];
373 
374  process_record (req,
375  rs);
376  }
378  GNUNET_free (req->hostname);
379  GNUNET_free (req->raw);
380  GNUNET_free (req);
381 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_DNSPARSER_Record * answers
Array of all answers in the packet, must contain "num_answers" entries.
char * hostname
Hostname we are resolving.
uint16_t id
random 16-bit DNS query identifier.
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
Definition: dnsparser.c:854
struct GNUNET_DNSPARSER_Record * additional_records
Array of all additional answers in the packet, must contain "num_additional_records" entries...
unsigned int num_answers
Number of answers in the packet, should be 0 for queries.
uint16_t id
Unique identifier for the request/response.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
unsigned int num_additional_records
Number of additional records in the packet, should be 0 for queries.
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...
Definition: dnsparser.c:662
#define MAX_RETRIES
How often do we retry a query before giving up for good?
A DNS response record.
struct GNUNET_DNSPARSER_Record * authority_records
Array of all authority records in the packet, must contain "num_authority_records" entries...
int issue_num
How often did we issue this query?
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
unsigned int num_authority_records
Number of authoritative answers in the packet, should be 0 for queries.
static unsigned int pending
The number of queries that are outstanding.
Request we should make.
struct GNUNET_DNSSTUB_RequestSocket * rs
Socket used to make the request, NULL if not active.
void * raw
Raw DNS query.
void GNUNET_DNSSTUB_resolve_cancel(struct GNUNET_DNSSTUB_RequestSocket *rs)
Cancel DNS resolution.
Definition: dnsstub.c:571
Easy-to-process, parsed version of a DNS packet.
static unsigned int failures
Number of lookups that failed.
#define GNUNET_log(kind,...)
static struct Request * req_tail
Tail of DLL of all requests to perform.
static void process_record(struct Request *req, struct GNUNET_DNSPARSER_Record *rec)
We received rec for req.
static struct Request * req_head
Head of DLL of all requests to perform.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ submit_req()

static int submit_req ( struct Request req)
static

Submit a request to DNS unless we need to slow down because we are at the rate limit.

Parameters
reqrequest to submit
Returns
GNUNET_OK if request was submitted GNUNET_NO if request was already submitted GNUNET_SYSERR if we are at the rate limit

Definition at line 394 of file gnunet-zonewalk.c.

References GNUNET_assert, GNUNET_DNSSTUB_resolve(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, Request::issue_num, lookups, pending, process_result(), Request::raw, Request::raw_len, Request::rs, THRESH, Request::time, and TIME_THRESH.

Referenced by process_queue().

395 {
396  static struct timeval last_request;
397  struct timeval now;
398 
399  if (NULL != req->rs)
400  return GNUNET_NO; /* already submitted */
401  gettimeofday (&now,
402  NULL);
403  if ( ( ( (now.tv_sec - last_request.tv_sec) == 0) &&
404  ( (now.tv_usec - last_request.tv_usec) < TIME_THRESH) ) ||
405  (pending >= THRESH) )
406  return GNUNET_SYSERR;
407  GNUNET_assert (NULL == req->rs);
408  req->rs = GNUNET_DNSSTUB_resolve (ctx,
409  req->raw,
410  req->raw_len,
412  req);
413  GNUNET_assert (NULL != req->rs);
414  req->issue_num++;
415  last_request = now;
416  lookups++;
417  pending++;
418  req->time = time (NULL);
419  return GNUNET_OK;
420 }
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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
#define TIME_THRESH
TIME_THRESH is in usecs.
#define THRESH
Maximum number of queries pending at the same time.
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.
Definition: dnsstub.c:533
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
int issue_num
How often did we issue this query?
static unsigned int pending
The number of queries that are outstanding.
struct GNUNET_DNSSTUB_RequestSocket * rs
Socket used to make the request, NULL if not active.
void * raw
Raw DNS query.
size_t raw_len
Number of bytes in raw.
time_t time
When did we last issue this request?
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_queue()

static void process_queue ( void *  cls)
static

Process as many requests as possible from the queue.

Parameters
clsNULL

Definition at line 429 of file gnunet-zonewalk.c.

References GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, GNUNET_TIME_UNIT_MILLISECONDS, Request::next, and submit_req().

Referenced by run().

430 {
431  (void) cls;
432  t = NULL;
433  for (struct Request *req = req_head;
434  NULL != req;
435  req = req->next)
436  {
437  if (GNUNET_SYSERR == submit_req (req))
438  break;
439  }
440  if (NULL != req_head)
442  &process_queue,
443  NULL);
444  else
446 }
static struct GNUNET_SCHEDULER_Task * t
Main task.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
static void process_queue(void *cls)
Process as many requests as possible from the queue.
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.
Definition: scheduler.c:1246
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.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
Request we should make.
struct Request * next
Requests are kept in a DLL.
static struct Request * req_head
Head of DLL of all requests to perform.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Clean up and terminate the process.

Parameters
clsNULL

Definition at line 455 of file gnunet-zonewalk.c.

References GNUNET_DNSSTUB_stop(), and GNUNET_SCHEDULER_cancel().

Referenced by run().

456 {
457  (void) cls;
458  if (NULL != t)
459  {
461  t = NULL;
462  }
464  ctx = NULL;
465 }
void GNUNET_DNSSTUB_stop(struct GNUNET_DNSSTUB_Context *ctx)
Cleanup DNSSTUB resolver.
Definition: dnsstub.c:731
static struct GNUNET_SCHEDULER_Task * t
Main task.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls)
static

Process requests from the queue, then if the queue is not empty, try again.

Parameters
clsNULL

Definition at line 475 of file gnunet-zonewalk.c.

References do_shutdown(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), and process_queue().

Referenced by main().

476 {
477  (void) cls;
478 
480  NULL);
482  NULL);
483 }
static void do_shutdown(void *cls)
Clean up and terminate the process.
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
static struct GNUNET_SCHEDULER_Task * t
Main task.
static void process_queue(void *cls)
Process as many requests as possible from the queue.
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:1273
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue()

static void queue ( const char *  hostname)
static

Add hostname to the list of requests to be made.

Parameters
hostnamename to resolve

Definition at line 492 of file gnunet-zonewalk.c.

References GNUNET_DNSPARSER_Query::dns_traffic_class, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_DNSPARSER_check_name(), GNUNET_DNSPARSER_pack(), GNUNET_DNSPARSER_TYPE_NS, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_TUN_DNS_CLASS_INTERNET, Request::hostname, Request::id, GNUNET_DNSPARSER_Packet::id, GNUNET_DNSPARSER_Query::name, GNUNET_DNSPARSER_Packet::num_queries, q, GNUNET_DNSPARSER_Packet::queries, Request::raw, Request::raw_len, ret, and GNUNET_DNSPARSER_Query::type.

Referenced by check_vl_transmission(), core_read_finished_cb(), free_pending_acknowledgement(), get_audiobin(), get_queue_delete_it(), handle_add_queue_message(), handle_del_queue_message(), handle_send_message_ack(), lookup_queue_it(), main(), mq_cancel(), mq_destroy(), mq_error(), mq_init(), mq_send(), prepare_pending_acknowledgement(), proto_read_kx(), queue_read(), queue_read_kx(), queue_send_msg(), queue_timeout(), queue_write(), select_read_cb(), select_write_cb(), setup_queue(), and transmit_on_queue().

493 {
494  struct GNUNET_DNSPARSER_Packet p;
495  struct GNUNET_DNSPARSER_Query q;
496  struct Request *req;
497  char *raw;
498  size_t raw_size;
499  int ret;
500 
501  if (GNUNET_OK !=
503  {
505  "Refusing invalid hostname `%s'\n",
506  hostname);
507  return;
508  }
509  q.name = (char *) hostname;
511  q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
512 
513  memset (&p,
514  0,
515  sizeof (p));
516  p.num_queries = 1;
517  p.queries = &q;
519  UINT16_MAX);
520  ret = GNUNET_DNSPARSER_pack (&p,
521  UINT16_MAX,
522  &raw,
523  &raw_size);
524  if (GNUNET_OK != ret)
525  {
526  if (GNUNET_NO == ret)
527  GNUNET_free (raw);
529  "Failed to pack query for hostname `%s'\n",
530  hostname);
531  return;
532  }
533 
534  req = GNUNET_new (struct Request);
535  req->hostname = strdup (hostname);
536  req->raw = raw;
537  req->raw_len = raw_size;
538  req->id = p.id;
540  req_tail,
541  req);
542 }
static int raw
raw output
Definition: gnunet-gns.c:55
char * hostname
Hostname we are resolving.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
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.
Definition: dnsparser.c:1259
uint16_t id
random 16-bit DNS query identifier.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
Randomness for IVs etc.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
int GNUNET_DNSPARSER_check_name(const char *name)
Check if a hostname in UTF-8 format can be coded into valid IDNA.
Definition: dnsparser.c:86
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#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&#39;r...
Request we should make.
void * raw
Raw DNS query.
static char * hostname
Our hostname; we give this to all the peers we start.
#define GNUNET_DNSPARSER_TYPE_NS
Easy-to-process, parsed version of a DNS packet.
#define GNUNET_log(kind,...)
static struct Request * req_tail
Tail of DLL of all requests to perform.
size_t raw_len
Number of bytes in raw.
static struct Request * req_head
Head of DLL of all requests to perform.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Call with IP address of resolver to query.

Parameters
argcshould be 2
argv[1]should contain IP address
Returns
0 on success

Definition at line 553 of file gnunet-zonewalk.c.

References failures, GNUNET_DNSSTUB_add_dns_ip(), GNUNET_DNSSTUB_start(), GNUNET_OK, GNUNET_SCHEDULER_run(), Request::hn, lookups, pending, queue(), records, and run().

555 {
556  char hn[256];
557 
558  if (2 != argc)
559  {
560  fprintf (stderr,
561  "Missing required configuration argument\n");
562  return -1;
563  }
564  ctx = GNUNET_DNSSTUB_start (256);
565  if (NULL == ctx)
566  {
567  fprintf (stderr,
568  "Failed to initialize GNUnet DNS STUB\n");
569  return 1;
570  }
571  if (GNUNET_OK !=
573  argv[1]))
574  {
575  fprintf (stderr,
576  "Failed to use `%s' for DNS resolver\n",
577  argv[1]);
578  return 1;
579  }
580 
581  while (NULL !=
582  fgets (hn,
583  sizeof (hn),
584  stdin))
585  {
586  if (strlen(hn) > 0)
587  hn[strlen(hn)-1] = '\0'; /* eat newline */
588  queue (hn);
589  }
591  NULL);
592  fprintf (stderr,
593  "Did %u lookups, found %u records, %u lookups failed, %u pending on shutdown\n",
594  lookups,
595  records,
596  failures,
597  pending);
598  return 0;
599 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
static unsigned int lookups
Number of lookups we performed overall.
int GNUNET_DNSSTUB_add_dns_ip(struct GNUNET_DNSSTUB_Context *ctx, const char *dns_ip)
Add nameserver for use by the DNSSTUB.
Definition: dnsstub.c:622
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:716
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static unsigned int records
Number of records we found.
struct GNUNET_DNSSTUB_Context * GNUNET_DNSSTUB_start(unsigned int num_sockets)
Start a DNS stub resolver.
Definition: dnsstub.c:595
static void run(void *cls)
Process requests from the queue, then if the queue is not empty, try again.
struct GNUNET_CONTAINER_HeapNode * hn
Requests are kept in a heap while waiting to be resolved.
static unsigned int pending
The number of queries that are outstanding.
static unsigned int failures
Number of lookups that failed.
Here is the call graph for this function:

Variable Documentation

◆ ctx

struct GNUNET_DNSSTUB_Context* ctx
static

Context for DNS resolution.

Definition at line 86 of file gnunet-zonewalk.c.

Referenced by add_address_to_hello(), add_address_to_uri(), add_plugin(), cadet_connect_adapter(), cadet_connect_cb(), cadet_test_run(), cancel_get(), check_connection_quality(), check_edge(), core_env_sent_cb(), create_peer_ctx(), curl_download_cb(), datacache_get_iterator(), debugctx(), delayed_put(), derive_aes_key(), derive_auth_key(), derive_iv(), derive_pong_iv(), dfa_add_multi_strides_helper(), dht_connect_cb(), dht_connected(), dht_get_string_accept_handler(), dht_get_string_handler(), dht_test_run(), find_best_address_it(), get_iter(), get_peer_ctx(), GNUNET_BLOCK_context_create(), GNUNET_CADET_TEST_ruN(), GNUNET_CRYPTO_ecc_ecdh(), GNUNET_CRYPTO_ecdh_eddsa(), GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_CRYPTO_ecdsa_ecdh(), GNUNET_CRYPTO_ecdsa_key_get_public(), GNUNET_CRYPTO_ecdsa_private_key_derive(), GNUNET_CRYPTO_ecdsa_public_key_derive(), GNUNET_CRYPTO_eddsa_ecdh(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_hkdf_v(), GNUNET_DHT_TEST_run(), GNUNET_SET_element_hash(), GNUNET_SIGNAL_raise(), handle_raw_message(), iterate_channels_cb(), new_regex_ctx(), op_get_element_iterator(), regex_edge_iterator(), REGEX_INTERNAL_search(), regex_result_iterator(), REGEX_TEST_automaton_save_graph_step(), REGEX_TEST_combine(), remove_by_unique_id(), service_started(), start_profiling(), t_ax_decrypt_and_validate(), t_ax_encrypt(), t_ax_hmac_hash(), t_hmac(), t_hmac_derive_key(), tcp_send(), tmain(), and try_send_tcp().

◆ pending

unsigned int pending
static

The number of queries that are outstanding.

Definition at line 91 of file gnunet-zonewalk.c.

Referenced by end(), GNUNET_NETWORK_socket_recvfrom_amount(), main(), process_result(), and submit_req().

◆ lookups

unsigned int lookups
static

Number of lookups we performed overall.

Definition at line 96 of file gnunet-zonewalk.c.

Referenced by main(), and submit_req().

◆ failures

unsigned int failures
static

Number of lookups that failed.

Definition at line 101 of file gnunet-zonewalk.c.

Referenced by main(), and process_result().

◆ records

unsigned int records
static

Number of records we found.

Definition at line 106 of file gnunet-zonewalk.c.

Referenced by GNUNET_JSON_from_gnsrecord(), main(), and process_record().

◆ req_head

struct Request* req_head
static

Head of DLL of all requests to perform.

Definition at line 111 of file gnunet-zonewalk.c.

◆ req_tail

struct Request* req_tail
static

Tail of DLL of all requests to perform.

Definition at line 116 of file gnunet-zonewalk.c.

◆ t

struct GNUNET_SCHEDULER_Task* t
static

Main task.

Definition at line 121 of file gnunet-zonewalk.c.

Referenced by add_address_to_uri(), add_without_sets(), automaton_create_proofs(), automaton_destroy_state(), automaton_merge_states(), automaton_state_traverse(), compute_scalar_product(), consider_path_cb(), construct_task_graph(), destroy_tunnels_now(), dfa_add_multi_strides_helper(), dfa_compress_paths(), dfa_compress_paths_helper(), dfa_move(), dfa_remove_dead_states(), extract_abs_time(), find_peer_context(), GCCH_channel_incoming_new(), GCT_add_inbound_connection(), GCT_create_tunnel(), GCT_handle_kx(), GCT_handle_kx_auth(), GCT_send(), get_all_tunnels_iterator(), get_next_free_ctn(), GNUNET_CRYPTO_hkdf_v(), GNUNET_DISK_file_seek(), GNUNET_log_setup(), GNUNET_SCHEDULER_add_at_with_priority(), GNUNET_SCHEDULER_add_now_with_lifeness(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_add_with_reason_and_priority(), GNUNET_SERVICE_client_drop(), GNUNET_STRINGS_fancy_time_to_absolute(), GNUNET_TIME_get_current_year(), GNUNET_TIME_time_to_year(), GNUNET_TRANSPORT_TESTING_done(), GNUNET_TRANSPORT_TESTING_get_test_plugin_name(), GNUNET_W32NSP_LookupServiceNext(), handle_p2p_estimate(), helper_read(), helper_write(), iterate_initial_edge(), mark_connection_unready(), parse_definitions(), parse_pattern(), progress_cb(), put_task(), REGEX_INTERNAL_dfa_add_multi_strides(), restore_fair(), retry_kx(), rsa_gcd_validate(), scc_tarjan_strongconnect(), shutdown_if_no_lifeness(), state_add_transition(), and state_get_edges().