GNUnet  0.20.0
plugin_gnsrecord_dns.c File Reference

gnsrecord plugin to provide the API for basic DNS records More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_gnsrecord_plugin.h"
Include dependency graph for plugin_gnsrecord_dns.c:

Go to the source code of this file.

Functions

static char * dns_value_to_string (void *cls, uint32_t type, const void *data, size_t data_size)
 Convert the 'value' of a record to a string. More...
 
static unsigned int rfc4398_mnemonic_to_value (const char *mnemonic)
 Convert RFC 4394 Mnemonics to the corresponding integer values. More...
 
static unsigned int rfc4034_mnemonic_to_value (const char *mnemonic)
 Convert RFC 4034 algorithm types to the corresponding integer values. More...
 
static int dns_string_to_value (void *cls, uint32_t type, const char *s, void **data, size_t *data_size)
 Convert human-readable version of a 'value' of a record to the binary representation. More...
 
static uint32_t dns_typename_to_number (void *cls, const char *dns_typename)
 Convert a type name (e.g. More...
 
static const char * dns_number_to_typename (void *cls, uint32_t type)
 Convert a type number to the corresponding type string (e.g. More...
 
static enum GNUNET_GenericReturnValue dns_is_critical (void *cls, uint32_t type)
 
void * libgnunet_plugin_gnsrecord_dns_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_gnsrecord_dns_done (void *cls)
 Exit point from the plugin. More...
 

Variables

struct {
   const char *   name
 
   uint32_t   number
 
name_map []
 Mapping of record type numbers to human-readable record type names. More...
 

Detailed Description

gnsrecord plugin to provide the API for basic DNS records

Author
Christian Grothoff

Definition in file plugin_gnsrecord_dns.c.

Function Documentation

◆ dns_value_to_string()

static char* dns_value_to_string ( void *  cls,
uint32_t  type,
const void *  data,
size_t  data_size 
)
static

Convert the 'value' of a record to a string.

Parameters
clsclosure, unused
typetype of the record
datavalue in binary encoding
data_sizenumber of bytes in data
Returns
NULL on error, otherwise human-readable representation of the value

Definition at line 41 of file plugin_gnsrecord_dns.c.

45 {
46  char *result;
47  char tmp[INET6_ADDRSTRLEN];
48 
49  switch (type)
50  {
52  if (data_size != sizeof(struct in_addr))
53  return NULL;
54  if (NULL == inet_ntop (AF_INET, data, tmp, sizeof(tmp)))
55  return NULL;
56  return GNUNET_strdup (tmp);
57 
59  char *ns;
60  size_t off;
61 
62  off = 0;
64  if ((NULL == ns) || (off != data_size))
65  {
66  GNUNET_break_op (0);
67  GNUNET_free (ns);
68  return NULL;
69  }
70  return ns;
71  }
72 
74  char *cname;
75  size_t off;
76 
77  off = 0;
79  if ((NULL == cname) || (off != data_size))
80  {
81  GNUNET_break_op (0);
82  GNUNET_free (cname);
83  return NULL;
84  }
85  return cname;
86  }
87 
89  struct GNUNET_DNSPARSER_SoaRecord *soa;
90  size_t off;
91 
92  off = 0;
94  if ((NULL == soa) || (off != data_size))
95  {
96  GNUNET_break_op (0);
97  if (NULL != soa)
99  return NULL;
100  }
102  "%s %s ( %u %u %u %u %u )",
103  soa->rname,
104  soa->mname,
105  soa->serial,
106  soa->refresh,
107  soa->retry,
108  soa->expire,
109  soa->minimum_ttl);
111  return result;
112  }
113 
115  char *ptr;
116  size_t off;
117 
118  off = 0;
120  if ((NULL == ptr) || (off != data_size))
121  {
122  GNUNET_break_op (0);
123  GNUNET_free (ptr);
124  return NULL;
125  }
126  return ptr;
127  }
128 
130  struct GNUNET_DNSPARSER_CertRecord *cert;
131  size_t off;
132  char *base64;
133  int len;
134 
135  off = 0;
137  if ((NULL == cert) || (off != data_size))
138  {
139  GNUNET_break_op (0);
141  return NULL;
142  }
144  cert->certificate_size,
145  &base64);
147  "%u %u %u %.*s",
148  cert->cert_type,
149  cert->cert_tag,
150  cert->algorithm,
151  len,
152  base64);
153  GNUNET_free (base64);
155  return result;
156  }
157 
159  struct GNUNET_DNSPARSER_MxRecord *mx;
160  size_t off;
161 
162  off = 0;
164  if ((NULL == mx) || (off != data_size))
165  {
166  GNUNET_break_op (0);
168  return NULL;
169  }
171  "%u %s",
172  (unsigned int) mx->preference,
173  mx->mxhost);
175  return result;
176  }
177 
179  return GNUNET_strndup (data, data_size);
180 
182  if (data_size != sizeof(struct in6_addr))
183  return NULL;
184  if (NULL == inet_ntop (AF_INET6, data, tmp, sizeof(tmp)))
185  return NULL;
186  return GNUNET_strdup (tmp);
187 
189  struct GNUNET_DNSPARSER_SrvRecord *srv;
190  size_t off;
191 
192  off = 0;
194  if ((NULL == srv) || (off != data_size))
195  {
196  GNUNET_break_op (0);
197  if (NULL != srv)
199  return NULL;
200  }
202  "%d %d %d %s",
203  srv->priority,
204  srv->weight,
205  srv->port,
206  srv->target);
208  return result;
209  }
210 
212  const struct GNUNET_TUN_DnsTlsaRecord *tlsa;
213  char *tlsa_str;
214  char *hex;
215 
216  if (data_size < sizeof(struct GNUNET_TUN_DnsTlsaRecord))
217  return NULL; /* malformed */
218  tlsa = data;
219  hex =
220  GNUNET_DNSPARSER_bin_to_hex (&tlsa[1],
221  data_size
222  - sizeof(struct GNUNET_TUN_DnsTlsaRecord));
223  if (0 == GNUNET_asprintf (&tlsa_str,
224  "%u %u %u %s",
225  (unsigned int) tlsa->usage,
226  (unsigned int) tlsa->selector,
227  (unsigned int) tlsa->matching_type,
228  hex))
229  {
230  GNUNET_free (hex);
231  GNUNET_free (tlsa_str);
232  return NULL;
233  }
234  GNUNET_free (hex);
235  return tlsa_str;
236  }
237 
238  case GNUNET_DNSPARSER_TYPE_CAA: { // RFC6844
239  const struct GNUNET_DNSPARSER_CaaRecord *caa;
240  char tag[15]; // between 1 and 15 bytes
241  char value[data_size];
242  char *caa_str;
243  if (data_size < sizeof(struct GNUNET_DNSPARSER_CaaRecord))
244  return NULL; /* malformed */
245  caa = data;
246  if ((1 > caa->tag_len) || (15 < caa->tag_len))
247  return NULL; /* malformed */
248  memset (tag, 0, sizeof(tag));
249  memset (value, 0, data_size);
250  memcpy (tag, &caa[1], caa->tag_len);
251  memcpy (value,
252  (char *) &caa[1] + caa->tag_len,
253  data_size - caa->tag_len - 2);
254  if (0 == GNUNET_asprintf (&caa_str,
255  "%u %s %s",
256  (unsigned int) caa->flags,
257  tag,
258  value))
259  {
260  GNUNET_free (caa_str);
261  return NULL;
262  }
263  return caa_str;
264  }
265 
266  default:
267  return NULL;
268  }
269 }
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
Definition: gnunet-abd.c:41
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
uint32_t data
The data value.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static char * value
Value of the record to add/remove.
static int result
Global testing status.
struct GNUNET_DNSPARSER_SoaRecord * GNUNET_DNSPARSER_parse_soa(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS SOA record.
Definition: dnsparser.c:391
#define GNUNET_DNSPARSER_TYPE_TLSA
#define GNUNET_DNSPARSER_TYPE_CAA
char * GNUNET_DNSPARSER_bin_to_hex(const void *data, size_t data_size)
Convert a block of binary data to HEX.
Definition: dnsparser.c:1356
#define GNUNET_DNSPARSER_TYPE_SRV
#define GNUNET_DNSPARSER_TYPE_SOA
void GNUNET_DNSPARSER_free_cert(struct GNUNET_DNSPARSER_CertRecord *cert)
Free CERT information record.
Definition: dnsparser.c:124
#define GNUNET_DNSPARSER_TYPE_CERT
#define GNUNET_DNSPARSER_TYPE_A
void GNUNET_DNSPARSER_free_srv(struct GNUNET_DNSPARSER_SrvRecord *srv)
Free SRV information record.
Definition: dnsparser.c:139
#define GNUNET_DNSPARSER_TYPE_PTR
struct GNUNET_DNSPARSER_MxRecord * GNUNET_DNSPARSER_parse_mx(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS MX record.
Definition: dnsparser.c:436
#define GNUNET_DNSPARSER_TYPE_NS
#define GNUNET_DNSPARSER_TYPE_CNAME
void GNUNET_DNSPARSER_free_soa(struct GNUNET_DNSPARSER_SoaRecord *soa)
Free SOA information record.
Definition: dnsparser.c:108
struct GNUNET_DNSPARSER_SrvRecord * GNUNET_DNSPARSER_parse_srv(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS SRV record.
Definition: dnsparser.c:477
void GNUNET_DNSPARSER_free_mx(struct GNUNET_DNSPARSER_MxRecord *mx)
Free MX information record.
Definition: dnsparser.c:154
struct GNUNET_DNSPARSER_CertRecord * GNUNET_DNSPARSER_parse_cert(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS CERT record.
Definition: dnsparser.c:518
#define GNUNET_DNSPARSER_TYPE_AAAA
#define GNUNET_DNSPARSER_TYPE_MX
#define GNUNET_DNSPARSER_TYPE_TXT
char * GNUNET_DNSPARSER_parse_name(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse name inside of a DNS query or record.
Definition: dnsparser.c:334
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#define GNUNET_free(ptr)
Wrapper around free.
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1607
Information from CAA records (RFC 6844).
uint8_t flags
The flags of the CAA record.
uint8_t tag_len
The length of the tag.
Information from CERT records (RFC 4034).
enum GNUNET_DNSPARSER_CertType cert_type
Certificate type.
char * certificate_data
Data of the certificate.
enum GNUNET_DNSPARSER_CertAlgorithm algorithm
Algorithm.
size_t certificate_size
Number of bytes in certificate_data.
uint16_t cert_tag
Certificate KeyTag.
Information from MX records (RFC 1035).
char * mxhost
Name of the mail server.
uint16_t preference
Preference for this entry (lower value is higher preference).
Information from SOA records (RFC 1035).
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.
Information from SRV records (RFC 2782).
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.
Payload of DNSSEC TLSA record.
uint8_t selector
Selector What part will be matched against the cert presented by server 0: Full cert (in binary) 1: F...
uint8_t matching_type
Matching type (of selected content) 0: exact match 1: SHA-256 hash 2: SHA-512 hash.
uint8_t usage
Certificate usage 0: CA cert 1: Entity cert 2: Trust anchor 3: domain-issued cert.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References GNUNET_DNSPARSER_CertRecord::algorithm, GNUNET_DNSPARSER_CertRecord::cert_tag, GNUNET_DNSPARSER_CertRecord::cert_type, GNUNET_DNSPARSER_CertRecord::certificate_data, GNUNET_DNSPARSER_CertRecord::certificate_size, data, data_size, GNUNET_DNSPARSER_SoaRecord::expire, GNUNET_DNSPARSER_CaaRecord::flags, GNUNET_asprintf(), GNUNET_break_op, GNUNET_DNSPARSER_bin_to_hex(), GNUNET_DNSPARSER_free_cert(), GNUNET_DNSPARSER_free_mx(), GNUNET_DNSPARSER_free_soa(), GNUNET_DNSPARSER_free_srv(), GNUNET_DNSPARSER_parse_cert(), GNUNET_DNSPARSER_parse_mx(), GNUNET_DNSPARSER_parse_name(), GNUNET_DNSPARSER_parse_soa(), GNUNET_DNSPARSER_parse_srv(), GNUNET_DNSPARSER_TYPE_A, GNUNET_DNSPARSER_TYPE_AAAA, GNUNET_DNSPARSER_TYPE_CAA, GNUNET_DNSPARSER_TYPE_CERT, GNUNET_DNSPARSER_TYPE_CNAME, GNUNET_DNSPARSER_TYPE_MX, GNUNET_DNSPARSER_TYPE_NS, GNUNET_DNSPARSER_TYPE_PTR, GNUNET_DNSPARSER_TYPE_SOA, GNUNET_DNSPARSER_TYPE_SRV, GNUNET_DNSPARSER_TYPE_TLSA, GNUNET_DNSPARSER_TYPE_TXT, GNUNET_free, GNUNET_strdup, GNUNET_STRINGS_base64_encode(), GNUNET_strndup, len, GNUNET_TUN_DnsTlsaRecord::matching_type, GNUNET_DNSPARSER_SoaRecord::minimum_ttl, GNUNET_DNSPARSER_SoaRecord::mname, GNUNET_DNSPARSER_MxRecord::mxhost, ns, GNUNET_DNSPARSER_SrvRecord::port, GNUNET_DNSPARSER_MxRecord::preference, GNUNET_DNSPARSER_SrvRecord::priority, GNUNET_DNSPARSER_SoaRecord::refresh, result, GNUNET_DNSPARSER_SoaRecord::retry, GNUNET_DNSPARSER_SoaRecord::rname, GNUNET_TUN_DnsTlsaRecord::selector, GNUNET_DNSPARSER_SoaRecord::serial, GNUNET_DNSPARSER_CaaRecord::tag_len, GNUNET_DNSPARSER_SrvRecord::target, type, GNUNET_TUN_DnsTlsaRecord::usage, value, and GNUNET_DNSPARSER_SrvRecord::weight.

Referenced by libgnunet_plugin_gnsrecord_dns_init().

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

◆ rfc4398_mnemonic_to_value()

static unsigned int rfc4398_mnemonic_to_value ( const char *  mnemonic)
static

Convert RFC 4394 Mnemonics to the corresponding integer values.

Parameters
mnemonicstring to look up
Returns
the value, 0 if not found

Definition at line 279 of file plugin_gnsrecord_dns.c.

280 {
281  static struct
282  {
283  const char *mnemonic;
284  unsigned int val;
285  } table[] = { { "PKIX", 1 },
286  { "SPKI", 2 },
287  { "PGP", 3 },
288  { "IPKIX", 4 },
289  { "ISPKI", 5 },
290  { "IPGP", 6 },
291  { "ACPKIX", 7 },
292  { "IACPKIX", 8 },
293  { "URI", 253 },
294  { "OID", 254 },
295  { NULL, 0 } };
296  unsigned int i;
297 
298  for (i = 0; NULL != table[i].mnemonic; i++)
299  if (0 == strcasecmp (mnemonic, table[i].mnemonic))
300  return table[i].val;
301  return 0;
302 }
static struct PeerEntry ** table
Table with our interned peer IDs.
Definition: peer.c:56

References table.

Referenced by dns_string_to_value().

Here is the caller graph for this function:

◆ rfc4034_mnemonic_to_value()

static unsigned int rfc4034_mnemonic_to_value ( const char *  mnemonic)
static

Convert RFC 4034 algorithm types to the corresponding integer values.

Parameters
mnemonicstring to look up
Returns
the value, 0 if not found

Definition at line 312 of file plugin_gnsrecord_dns.c.

313 {
314  static struct
315  {
316  const char *mnemonic;
317  unsigned int val;
318  } table[] = { { "RSAMD5", 1 },
319  { "DH", 2 },
320  { "DSA", 3 },
321  { "ECC", 4 },
322  { "RSASHA1", 5 },
323  { "INDIRECT", 252 },
324  { "PRIVATEDNS", 253 },
325  { "PRIVATEOID", 254 },
326  { NULL, 0 } };
327  unsigned int i;
328 
329  for (i = 0; NULL != table[i].mnemonic; i++)
330  if (0 == strcasecmp (mnemonic, table[i].mnemonic))
331  return table[i].val;
332  return 0;
333 }

References table.

Referenced by dns_string_to_value().

Here is the caller graph for this function:

◆ dns_string_to_value()

static int dns_string_to_value ( void *  cls,
uint32_t  type,
const char *  s,
void **  data,
size_t *  data_size 
)
static

Convert human-readable version of a 'value' of a record to the binary representation.

Parameters
clsclosure, unused
typetype of the record
shuman-readable string
dataset to value in binary encoding (will be allocated)
data_sizeset to number of bytes in data
Returns
GNUNET_OK on success

Definition at line 348 of file plugin_gnsrecord_dns.c.

353 {
354  struct in_addr value_a;
355  struct in6_addr value_aaaa;
356  struct GNUNET_TUN_DnsTlsaRecord *tlsa;
357 
358  if (NULL == s)
359  return GNUNET_SYSERR;
360  switch (type)
361  {
363  if (1 != inet_pton (AF_INET, s, &value_a))
364  {
366  _ ("Unable to parse IPv4 address `%s'\n"),
367  s);
368  return GNUNET_SYSERR;
369  }
370  *data = GNUNET_new (struct in_addr);
371  GNUNET_memcpy (*data, &value_a, sizeof(value_a));
372  *data_size = sizeof(value_a);
373  return GNUNET_OK;
374 
376  char nsbuf[256];
377  size_t off;
378 
379  off = 0;
380  if (GNUNET_OK !=
381  GNUNET_DNSPARSER_builder_add_name (nsbuf, sizeof(nsbuf), &off, s))
382  {
384  _ ("Failed to serialize NS record with value `%s'\n"),
385  s);
386  return GNUNET_SYSERR;
387  }
388  *data_size = off;
389  *data = GNUNET_malloc (off);
390  GNUNET_memcpy (*data, nsbuf, off);
391  return GNUNET_OK;
392  }
393 
395  char cnamebuf[256];
396  size_t off;
397 
398  off = 0;
400  sizeof(cnamebuf),
401  &off,
402  s))
403  {
405  _ ("Failed to serialize CNAME record with value `%s'\n"),
406  s);
407  return GNUNET_SYSERR;
408  }
409  *data_size = off;
410  *data = GNUNET_malloc (off);
411  GNUNET_memcpy (*data, cnamebuf, off);
412  return GNUNET_OK;
413  }
414 
416  char *sdup;
417  const char *typep;
418  const char *keyp;
419  const char *algp;
420  const char *certp;
421  unsigned int type;
422  unsigned int key;
423  unsigned int alg;
424  size_t cert_size;
425  char *cert_data;
426  struct GNUNET_DNSPARSER_CertRecord cert;
427 
428  sdup = GNUNET_strdup (s);
429  typep = strtok (sdup, " ");
430  if ((NULL == typep) ||
431  ((0 == (type = rfc4398_mnemonic_to_value (typep))) &&
432  ((1 != sscanf (typep, "%u", &type)) || (type > UINT16_MAX))))
433  {
434  GNUNET_free (sdup);
435  return GNUNET_SYSERR;
436  }
437  keyp = strtok (NULL, " ");
438  if ((NULL == keyp) || (1 != sscanf (keyp, "%u", &key)) ||
439  (key > UINT16_MAX))
440  {
441  GNUNET_free (sdup);
442  return GNUNET_SYSERR;
443  }
444  alg = 0;
445  algp = strtok (NULL, " ");
446  if ((NULL == algp) ||
447  ((0 == (type = rfc4034_mnemonic_to_value (typep))) &&
448  ((1 != sscanf (algp, "%u", &alg)) || (alg > UINT8_MAX))))
449  {
450  GNUNET_free (sdup);
451  return GNUNET_SYSERR;
452  }
453  certp = strtok (NULL, " ");
454  if ((NULL == certp) || (0 == strlen (certp)))
455  {
456  GNUNET_free (sdup);
457  return GNUNET_SYSERR;
458  }
459  cert_size = GNUNET_STRINGS_base64_decode (certp,
460  strlen (certp),
461  (void **) &cert_data);
462  GNUNET_free (sdup);
463  cert.cert_type = type;
464  cert.cert_tag = key;
465  cert.algorithm = alg;
466  cert.certificate_size = cert_size;
467  cert.certificate_data = cert_data;
468  {
469  char certbuf[cert_size + sizeof(struct GNUNET_TUN_DnsCertRecord)];
470  size_t off;
471 
472  off = 0;
474  sizeof(certbuf),
475  &off,
476  &cert))
477  {
479  _ ("Failed to serialize CERT record with %u bytes\n"),
480  (unsigned int) cert_size);
481  GNUNET_free (cert_data);
482  return GNUNET_SYSERR;
483  }
484  *data_size = off;
485  *data = GNUNET_malloc (off);
486  GNUNET_memcpy (*data, certbuf, off);
487  }
488  GNUNET_free (cert_data);
489  return GNUNET_OK;
490  }
491 
493  struct GNUNET_DNSPARSER_SoaRecord soa;
494  char soabuf[540];
495  char soa_rname[253 + 1];
496  char soa_mname[253 + 1];
497  unsigned int soa_serial;
498  unsigned int soa_refresh;
499  unsigned int soa_retry;
500  unsigned int soa_expire;
501  unsigned int soa_min;
502  size_t off;
503 
504  if (7 != sscanf (s,
505  "%253s %253s ( %u %u %u %u %u )",
506  soa_rname,
507  soa_mname,
508  &soa_serial,
509  &soa_refresh,
510  &soa_retry,
511  &soa_expire,
512  &soa_min))
513  {
515  _ ("Unable to parse SOA record `%s'\n"),
516  s);
517  return GNUNET_SYSERR;
518  }
519  soa.mname = soa_mname;
520  soa.rname = soa_rname;
521  soa.serial = (uint32_t) soa_serial;
522  soa.refresh = (uint32_t) soa_refresh;
523  soa.retry = (uint32_t) soa_retry;
524  soa.expire = (uint32_t) soa_expire;
525  soa.minimum_ttl = (uint32_t) soa_min;
526  off = 0;
527  if (GNUNET_OK !=
528  GNUNET_DNSPARSER_builder_add_soa (soabuf, sizeof(soabuf), &off, &soa))
529  {
530  GNUNET_log (
532  _ ("Failed to serialize SOA record with mname `%s' and rname `%s'\n"),
533  soa_mname,
534  soa_rname);
535  return GNUNET_SYSERR;
536  }
537  *data_size = off;
538  *data = GNUNET_malloc (off);
539  GNUNET_memcpy (*data, soabuf, off);
540  return GNUNET_OK;
541  }
542 
544  char ptrbuf[256];
545  size_t off;
546 
547  off = 0;
548  if (GNUNET_OK !=
549  GNUNET_DNSPARSER_builder_add_name (ptrbuf, sizeof(ptrbuf), &off, s))
550  {
552  _ ("Failed to serialize PTR record with value `%s'\n"),
553  s);
554  return GNUNET_SYSERR;
555  }
556  *data_size = off;
557  *data = GNUNET_malloc (off);
558  GNUNET_memcpy (*data, ptrbuf, off);
559  return GNUNET_OK;
560  }
561 
563  struct GNUNET_DNSPARSER_MxRecord mx;
564  char mxbuf[258];
565  char mxhost[253 + 1];
566  unsigned int mx_pref;
567  size_t off;
568 
569  if (2 != sscanf (s, "%u %253s", &mx_pref, mxhost))
570  {
572  _ ("Unable to parse MX record `%s'\n"),
573  s);
574  return GNUNET_SYSERR;
575  }
576  mx.preference = (uint16_t) mx_pref;
577  mx.mxhost = mxhost;
578  off = 0;
579 
580  if (GNUNET_OK !=
581  GNUNET_DNSPARSER_builder_add_mx (mxbuf, sizeof(mxbuf), &off, &mx))
582  {
584  _ ("Failed to serialize MX record with hostname `%s'\n"),
585  mxhost);
586  return GNUNET_SYSERR;
587  }
588  *data_size = off;
589  *data = GNUNET_malloc (off);
590  GNUNET_memcpy (*data, mxbuf, off);
591  return GNUNET_OK;
592  }
593 
595  struct GNUNET_DNSPARSER_SrvRecord srv;
596  char srvbuf[270];
597  char srvtarget[253 + 1];
598  unsigned int priority;
599  unsigned int weight;
600  unsigned int port;
601  size_t off;
602 
603  if (4 != sscanf (s, "%u %u %u %253s", &priority, &weight, &port,
604  srvtarget))
605  {
607  _ ("Unable to parse SRV record `%s'\n"),
608  s);
609  return GNUNET_SYSERR;
610  }
611  srv.priority = (uint16_t) priority;
612  srv.weight = (uint16_t) weight;
613  srv.port = (uint16_t) port;
614  srv.target = srvtarget;
615  off = 0;
616  if (GNUNET_OK !=
617  GNUNET_DNSPARSER_builder_add_srv (srvbuf, sizeof(srvbuf), &off, &srv))
618  {
620  _ ("Failed to serialize SRV record with target `%s'\n"),
621  srvtarget);
622  return GNUNET_SYSERR;
623  }
624  *data_size = off;
625  *data = GNUNET_malloc (off);
626  GNUNET_memcpy (*data, srvbuf, off);
627  return GNUNET_OK;
628  }
629 
631  *data = GNUNET_strdup (s);
632  *data_size = strlen (s);
633  return GNUNET_OK;
634 
636  if (1 != inet_pton (AF_INET6, s, &value_aaaa))
637  {
639  _ ("Unable to parse IPv6 address `%s'\n"),
640  s);
641  return GNUNET_SYSERR;
642  }
643  *data = GNUNET_new (struct in6_addr);
644  *data_size = sizeof(struct in6_addr);
645  GNUNET_memcpy (*data, &value_aaaa, sizeof(value_aaaa));
646  return GNUNET_OK;
647 
649  unsigned int usage;
650  unsigned int selector;
651  unsigned int matching_type;
652  size_t slen = strlen (s) + 1;
653  char hex[slen];
654 
655  if (4 != sscanf (s, "%u %u %u %s", &usage, &selector, &matching_type,
656  hex))
657  {
659  _ ("Unable to parse TLSA record string `%s'\n"),
660  s);
661  *data_size = 0;
662  return GNUNET_SYSERR;
663  }
664 
665  *data_size = sizeof(struct GNUNET_TUN_DnsTlsaRecord) + strlen (hex) / 2;
666  *data = tlsa = GNUNET_malloc (*data_size);
667  tlsa->usage = (uint8_t) usage;
668  tlsa->selector = (uint8_t) selector;
669  tlsa->matching_type = (uint8_t) matching_type;
670  if (strlen (hex) / 2 != GNUNET_DNSPARSER_hex_to_bin (hex, &tlsa[1]))
671  {
673  _ ("Unable to parse TLSA record string `%s'\n"),
674  s);
675  GNUNET_free (*data);
676  *data = NULL;
677  *data_size = 0;
678  return GNUNET_SYSERR;
679  }
680  return GNUNET_OK;
681  }
682 
683  case GNUNET_DNSPARSER_TYPE_CAA: { // RFC6844
684  struct GNUNET_DNSPARSER_CaaRecord *caa;
685  unsigned int flags;
686  char tag[15]; // Max tag length 15
687  char value[strlen (s) + 1]; // Should be more than enough
688 
689  if (3 != sscanf (s, "%u %s %[^\n]", &flags, tag, value))
690  {
692  _ ("Unable to parse CAA record string `%s'\n"),
693  s);
694  *data_size = 0;
695  return GNUNET_SYSERR;
696  }
697  *data_size = sizeof(struct GNUNET_DNSPARSER_CaaRecord) + strlen (tag)
698  + strlen (value);
699  *data = caa = GNUNET_malloc (*data_size);
700  caa->flags = flags;
701  memcpy (&caa[1], tag, strlen (tag));
702  caa->tag_len = strlen (tag);
703  memcpy ((char *) &caa[1] + caa->tag_len, value, strlen (value));
704  return GNUNET_OK;
705  }
706 
707  default:
708  return GNUNET_SYSERR;
709  }
710 }
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
struct GNUNET_HashCode key
The key used in the DHT.
int GNUNET_DNSPARSER_builder_add_name(char *dst, size_t dst_len, size_t *off, const char *name)
Add a DNS name to the UDP packet at the given location, converting the name to IDNA notation as neces...
Definition: dnsparser.c:889
int GNUNET_DNSPARSER_builder_add_cert(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_CertRecord *cert)
Add CERT record to the UDP packet at the given location.
Definition: dnsparser.c:1032
size_t GNUNET_DNSPARSER_hex_to_bin(const char *hex, void *data)
Convert a HEX string to block of binary data.
Definition: dnsparser.c:1379
int GNUNET_DNSPARSER_builder_add_soa(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_SoaRecord *soa)
Add an SOA record to the UDP packet at the given location.
Definition: dnsparser.c:1079
int GNUNET_DNSPARSER_builder_add_mx(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_MxRecord *mx)
Add an MX record to the UDP packet at the given location.
Definition: dnsparser.c:1003
int GNUNET_DNSPARSER_builder_add_srv(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_SrvRecord *srv)
Add an SRV record to the UDP packet at the given location.
Definition: dnsparser.c:1120
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1695
def usage()
Definition: gnunet-chk.py:355
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static unsigned int rfc4398_mnemonic_to_value(const char *mnemonic)
Convert RFC 4394 Mnemonics to the corresponding integer values.
static unsigned int rfc4034_mnemonic_to_value(const char *mnemonic)
Convert RFC 4034 algorithm types to the corresponding integer values.
Payload of DNS CERT record.

References _, GNUNET_DNSPARSER_CertRecord::algorithm, GNUNET_DNSPARSER_CertRecord::cert_tag, GNUNET_DNSPARSER_CertRecord::cert_type, GNUNET_DNSPARSER_CertRecord::certificate_data, GNUNET_DNSPARSER_CertRecord::certificate_size, data, data_size, GNUNET_DNSPARSER_SoaRecord::expire, GNUNET_DNSPARSER_CaaRecord::flags, GNUNET_DNSPARSER_builder_add_cert(), GNUNET_DNSPARSER_builder_add_mx(), GNUNET_DNSPARSER_builder_add_name(), GNUNET_DNSPARSER_builder_add_soa(), GNUNET_DNSPARSER_builder_add_srv(), GNUNET_DNSPARSER_hex_to_bin(), GNUNET_DNSPARSER_TYPE_A, GNUNET_DNSPARSER_TYPE_AAAA, GNUNET_DNSPARSER_TYPE_CAA, GNUNET_DNSPARSER_TYPE_CERT, GNUNET_DNSPARSER_TYPE_CNAME, GNUNET_DNSPARSER_TYPE_MX, GNUNET_DNSPARSER_TYPE_NS, GNUNET_DNSPARSER_TYPE_PTR, GNUNET_DNSPARSER_TYPE_SOA, GNUNET_DNSPARSER_TYPE_SRV, GNUNET_DNSPARSER_TYPE_TLSA, GNUNET_DNSPARSER_TYPE_TXT, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_base64_decode(), GNUNET_SYSERR, key, GNUNET_TUN_DnsTlsaRecord::matching_type, GNUNET_DNSPARSER_SoaRecord::minimum_ttl, GNUNET_DNSPARSER_SoaRecord::mname, GNUNET_DNSPARSER_MxRecord::mxhost, port, GNUNET_DNSPARSER_SrvRecord::port, GNUNET_DNSPARSER_MxRecord::preference, GNUNET_DNSPARSER_SrvRecord::priority, GNUNET_DNSPARSER_SoaRecord::refresh, GNUNET_DNSPARSER_SoaRecord::retry, rfc4034_mnemonic_to_value(), rfc4398_mnemonic_to_value(), GNUNET_DNSPARSER_SoaRecord::rname, GNUNET_TUN_DnsTlsaRecord::selector, GNUNET_DNSPARSER_SoaRecord::serial, GNUNET_DNSPARSER_CaaRecord::tag_len, GNUNET_DNSPARSER_SrvRecord::target, type, gnunet-chk::usage(), GNUNET_TUN_DnsTlsaRecord::usage, value, and GNUNET_DNSPARSER_SrvRecord::weight.

Referenced by libgnunet_plugin_gnsrecord_dns_init().

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

◆ dns_typename_to_number()

static uint32_t dns_typename_to_number ( void *  cls,
const char *  dns_typename 
)
static

Convert a type name (e.g.

"AAAA") to the corresponding number.

Parameters
clsclosure, unused
dns_typenamename to convert
Returns
corresponding number, UINT32_MAX on error

Definition at line 744 of file plugin_gnsrecord_dns.c.

745 {
746  unsigned int i;
747 
748  i = 0;
749  while ((NULL != name_map[i].name) &&
750  (0 != strcasecmp (dns_typename, name_map[i].name)))
751  i++;
752  return name_map[i].number;
753 }
static struct @23 name_map[]
Mapping of record type numbers to human-readable record type names.
const char * name

References name, and name_map.

Referenced by libgnunet_plugin_gnsrecord_dns_init().

Here is the caller graph for this function:

◆ dns_number_to_typename()

static const char* dns_number_to_typename ( void *  cls,
uint32_t  type 
)
static

Convert a type number to the corresponding type string (e.g.

1 to "A")

Parameters
clsclosure, unused
typenumber of a type to convert
Returns
corresponding typestring, NULL on error

Definition at line 764 of file plugin_gnsrecord_dns.c.

765 {
766  unsigned int i;
767 
768  i = 0;
769  while ((NULL != name_map[i].name) && (type != name_map[i].number))
770  i++;
771  return name_map[i].name;
772 }
uint32_t number

Referenced by libgnunet_plugin_gnsrecord_dns_init().

Here is the caller graph for this function:

◆ dns_is_critical()

static enum GNUNET_GenericReturnValue dns_is_critical ( void *  cls,
uint32_t  type 
)
static

Definition at line 764 of file plugin_gnsrecord_dns.c.

777 {
778  return GNUNET_NO;
779 }
@ GNUNET_NO

References name, name_map, number, and type.

Referenced by libgnunet_plugin_gnsrecord_dns_init().

Here is the caller graph for this function:

◆ libgnunet_plugin_gnsrecord_dns_init()

void* libgnunet_plugin_gnsrecord_dns_init ( void *  cls)

Entry point for the plugin.

Parameters
clsNULL
Returns
the exported block API

Definition at line 788 of file plugin_gnsrecord_dns.c.

789 {
791 
798  return api;
799 }
static const char * dns_number_to_typename(void *cls, uint32_t type)
Convert a type number to the corresponding type string (e.g.
static enum GNUNET_GenericReturnValue dns_is_critical(void *cls, uint32_t type)
static int dns_string_to_value(void *cls, uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a 'value' of a record to the binary representation.
static char * dns_value_to_string(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the 'value' of a record to a string.
static uint32_t dns_typename_to_number(void *cls, const char *dns_typename)
Convert a type name (e.g.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
GNUNET_GNSRECORD_IsCriticalFunction is_critical
Is critical.
GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number
Typename to number.
GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename
Number to typename.
GNUNET_GNSRECORD_ValueToStringFunction value_to_string
Conversion to string.
GNUNET_GNSRECORD_StringToValueFunction string_to_value
Conversion to binary.

References dns_is_critical(), dns_number_to_typename(), dns_string_to_value(), dns_typename_to_number(), dns_value_to_string(), GNUNET_new, GNUNET_GNSRECORD_PluginFunctions::is_critical, GNUNET_GNSRECORD_PluginFunctions::number_to_typename, GNUNET_GNSRECORD_PluginFunctions::string_to_value, GNUNET_GNSRECORD_PluginFunctions::typename_to_number, and GNUNET_GNSRECORD_PluginFunctions::value_to_string.

Here is the call graph for this function:

◆ libgnunet_plugin_gnsrecord_dns_done()

void* libgnunet_plugin_gnsrecord_dns_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe return value from libgnunet_plugin_block_test_init
Returns
NULL

Definition at line 809 of file plugin_gnsrecord_dns.c.

810 {
812 
813  GNUNET_free (api);
814  return NULL;
815 }
void * cls
Closure for all of the callbacks.

References GNUNET_GNSRECORD_PluginFunctions::cls, and GNUNET_free.

Variable Documentation

◆ name

const char* name

Definition at line 719 of file plugin_gnsrecord_dns.c.

Referenced by dns_is_critical(), and dns_typename_to_number().

◆ number

uint32_t number

Definition at line 720 of file plugin_gnsrecord_dns.c.

Referenced by dns_is_critical().

◆ 

struct { ... } name_map[]
Initial value:

Mapping of record type numbers to human-readable record type names.

Referenced by dns_is_critical(), and dns_typename_to_number().