GNUnet  0.11.x
Functions | Variables
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_dnsparser_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 (i.e. More...
 
static const char * dns_number_to_typename (void *cls, uint32_t type)
 Convert a type number (i.e. More...
 
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 42 of file plugin_gnsrecord_dns.c.

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_free_non_null, 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, GNUNET_TUN_DnsTlsaRecord::usage, value, and GNUNET_DNSPARSER_SrvRecord::weight.

Referenced by libgnunet_plugin_gnsrecord_dns_init().

46 {
47  char *result;
48  char tmp[INET6_ADDRSTRLEN];
49 
50  switch (type)
51  {
53  if (data_size != sizeof(struct in_addr))
54  return NULL;
55  if (NULL == inet_ntop (AF_INET, data, tmp, sizeof(tmp)))
56  return NULL;
57  return GNUNET_strdup (tmp);
58 
60  char *ns;
61  size_t off;
62 
63  off = 0;
65  if ((NULL == ns) || (off != data_size))
66  {
67  GNUNET_break_op (0);
69  return NULL;
70  }
71  return ns;
72  }
73 
75  char *cname;
76  size_t off;
77 
78  off = 0;
80  if ((NULL == cname) || (off != data_size))
81  {
82  GNUNET_break_op (0);
83  GNUNET_free_non_null (cname);
84  return NULL;
85  }
86  return cname;
87  }
88 
90  struct GNUNET_DNSPARSER_SoaRecord *soa;
91  size_t off;
92 
93  off = 0;
95  if ((NULL == soa) || (off != data_size))
96  {
97  GNUNET_break_op (0);
98  if (NULL != soa)
100  return NULL;
101  }
102  GNUNET_asprintf (&result,
103  "rname=%s mname=%s %lu,%lu,%lu,%lu,%lu",
104  soa->rname,
105  soa->mname,
106  soa->serial,
107  soa->refresh,
108  soa->retry,
109  soa->expire,
110  soa->minimum_ttl);
112  return result;
113  }
114 
116  char *ptr;
117  size_t off;
118 
119  off = 0;
121  if ((NULL == ptr) || (off != data_size))
122  {
123  GNUNET_break_op (0);
124  GNUNET_free_non_null (ptr);
125  return NULL;
126  }
127  return ptr;
128  }
129 
131  struct GNUNET_DNSPARSER_CertRecord *cert;
132  size_t off;
133  char *base64;
134  int len;
135 
136  off = 0;
138  if ((NULL == cert) || (off != data_size))
139  {
140  GNUNET_break_op (0);
142  return NULL;
143  }
145  cert->certificate_size,
146  &base64);
147  GNUNET_asprintf (&result,
148  "%u %u %u %.*s",
149  cert->cert_type,
150  cert->cert_tag,
151  cert->algorithm,
152  len,
153  base64);
154  GNUNET_free (base64);
156  return result;
157  }
158 
160  struct GNUNET_DNSPARSER_MxRecord *mx;
161  size_t off;
162 
163  off = 0;
165  if ((NULL == mx) || (off != data_size))
166  {
167  GNUNET_break_op (0);
169  return NULL;
170  }
171  GNUNET_asprintf (&result,
172  "%u,%s",
173  (unsigned int) mx->preference,
174  mx->mxhost);
176  return result;
177  }
178 
180  return GNUNET_strndup (data, data_size);
181 
183  if (data_size != sizeof(struct in6_addr))
184  return NULL;
185  if (NULL == inet_ntop (AF_INET6, data, tmp, sizeof(tmp)))
186  return NULL;
187  return GNUNET_strdup (tmp);
188 
190  struct GNUNET_DNSPARSER_SrvRecord *srv;
191  size_t off;
192 
193  off = 0;
195  if ((NULL == srv) || (off != data_size))
196  {
197  GNUNET_break_op (0);
198  if (NULL != srv)
200  return NULL;
201  }
202  GNUNET_asprintf (&result,
203  "%d %d %d %s",
204  srv->priority,
205  srv->weight,
206  srv->port,
207  srv->target);
209  return result;
210  }
211 
213  const struct GNUNET_TUN_DnsTlsaRecord *tlsa;
214  char *tlsa_str;
215  char *hex;
216 
217  if (data_size < sizeof(struct GNUNET_TUN_DnsTlsaRecord))
218  return NULL; /* malformed */
219  tlsa = data;
220  hex =
221  GNUNET_DNSPARSER_bin_to_hex (&tlsa[1],
222  data_size
223  - sizeof(struct GNUNET_TUN_DnsTlsaRecord));
224  if (0 == GNUNET_asprintf (&tlsa_str,
225  "%u %u %u %s",
226  (unsigned int) tlsa->usage,
227  (unsigned int) tlsa->selector,
228  (unsigned int) tlsa->matching_type,
229  hex))
230  {
231  GNUNET_free (hex);
232  GNUNET_free (tlsa_str);
233  return NULL;
234  }
235  GNUNET_free (hex);
236  return tlsa_str;
237  }
238 
239  case GNUNET_DNSPARSER_TYPE_CAA: { // RFC6844
240  const struct GNUNET_DNSPARSER_CaaRecord *caa;
241  char tag[15]; // between 1 and 15 bytes
242  char value[data_size];
243  char *caa_str;
244  if (data_size < sizeof(struct GNUNET_DNSPARSER_CaaRecord))
245  return NULL; /* malformed */
246  caa = data;
247  if ((1 > caa->tag_len) || (15 < caa->tag_len))
248  return NULL; /* malformed */
249  memset (tag, 0, sizeof(tag));
250  memset (value, 0, data_size);
251  memcpy (tag, &caa[1], caa->tag_len);
252  memcpy (value,
253  (char *) &caa[1] + caa->tag_len,
254  data_size - caa->tag_len - 2);
255  if (0 == GNUNET_asprintf (&caa_str,
256  "%u %s %s",
257  (unsigned int) caa->flags,
258  tag,
259  value))
260  {
261  GNUNET_free (caa_str);
262  return NULL;
263  }
264  return caa_str;
265  }
266 
267  default:
268  return NULL;
269  }
270 }
void GNUNET_DNSPARSER_free_soa(struct GNUNET_DNSPARSER_SoaRecord *soa)
Free SOA information record.
Definition: dnsparser.c:108
Information from SOA records (RFC 1035).
uint32_t retry
Time interval that should elapse before a failed refresh should be retried.
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
uint32_t refresh
Time interval before the zone should be refreshed.
Information from CAA records (RFC 6844).
char * mname
The domainname of the name server that was the original or primary source of data for this zone...
enum GNUNET_DNSPARSER_CertAlgorithm algorithm
Algorithm.
void GNUNET_DNSPARSER_free_srv(struct GNUNET_DNSPARSER_SrvRecord *srv)
Free SRV information record.
Definition: dnsparser.c:139
#define GNUNET_DNSPARSER_TYPE_CNAME
char * mxhost
Name of the mail server.
enum GNUNET_DNSPARSER_CertType cert_type
Certificate type.
uint16_t cert_tag
Certificate KeyTag.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
Information from CERT records (RFC 4034).
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_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
uint8_t usage
Certificate usage 0: CA cert 1: Entity cert 2: Trust anchor 3: domain-issued cert.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_DNSPARSER_TYPE_MX
Information from MX records (RFC 1035).
uint32_t serial
The version number of the original copy of the zone.
#define GNUNET_DNSPARSER_TYPE_PTR
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
uint32_t minimum_ttl
The bit minimum TTL field that should be exported with any RR from this zone.
uint8_t flags
The flags of the CAA record.
#define GNUNET_DNSPARSER_TYPE_SOA
static char * value
Value of the record to add/remove.
uint16_t port
TCP or UDP port of the service.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
char * target
Hostname offering the service.
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
char * rname
A domainname which specifies the mailbox of the person responsible for this zone. ...
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
Definition: gnunet-abd.c:41
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
Payload of DNSSEC TLSA record.
static int result
Global testing status.
uint32_t expire
Time value that specifies the upper limit on the time interval that can elapse before the zone is no ...
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
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1855
uint8_t matching_type
Matching type (of selected content) 0: exact match 1: SHA-256 hash 2: SHA-512 hash.
#define GNUNET_DNSPARSER_TYPE_TXT
#define GNUNET_DNSPARSER_TYPE_TLSA
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
uint8_t selector
Selector What part will be matched against the cert presented by server 0: Full cert (in binary) 1: F...
size_t certificate_size
Number of bytes in certificate_data.
#define GNUNET_DNSPARSER_TYPE_CAA
#define GNUNET_DNSPARSER_TYPE_AAAA
#define GNUNET_DNSPARSER_TYPE_NS
void GNUNET_DNSPARSER_free_cert(struct GNUNET_DNSPARSER_CertRecord *cert)
Free CERT information record.
Definition: dnsparser.c:124
uint16_t priority
Preference for this entry (lower value is higher preference).
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint16_t weight
Relative weight for records with the same priority.
char * certificate_data
Data of the certificate.
#define GNUNET_DNSPARSER_TYPE_SRV
uint32_t data
The data value.
uint16_t preference
Preference for this entry (lower value is higher preference).
void GNUNET_DNSPARSER_free_mx(struct GNUNET_DNSPARSER_MxRecord *mx)
Free MX information record.
Definition: dnsparser.c:154
#define GNUNET_DNSPARSER_TYPE_A
#define GNUNET_DNSPARSER_TYPE_CERT
char * GNUNET_DNSPARSER_bin_to_hex(const void *data, size_t data_size)
Convert a block of binary data to HEX.
Definition: dnsparser.c:1354
Information from SRV records (RFC 2782).
#define GNUNET_free(ptr)
Wrapper around free.
uint8_t tag_len
The length of the tag.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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 280 of file plugin_gnsrecord_dns.c.

References table.

Referenced by dns_string_to_value().

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

References table.

Referenced by dns_string_to_value().

314 {
315  static struct
316  {
317  const char *mnemonic;
318  unsigned int val;
319  } table[] = { { "RSAMD5", 1 },
320  { "DH", 2 },
321  { "DSA", 3 },
322  { "ECC", 4 },
323  { "RSASHA1", 5 },
324  { "INDIRECT", 252 },
325  { "PRIVATEDNS", 253 },
326  { "PRIVATEOID", 254 },
327  { NULL, 0 } };
328  unsigned int i;
329 
330  for (i = 0; NULL != table[i].mnemonic; i++)
331  if (0 == strcasecmp (mnemonic, table[i].mnemonic))
332  return table[i].val;
333  return 0;
334 }
static struct PeerEntry ** table
Table with our interned peer IDs.
Definition: peer.c:55
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 349 of file plugin_gnsrecord_dns.c.

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, 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().

354 {
355  struct in_addr value_a;
356  struct in6_addr value_aaaa;
357  struct GNUNET_TUN_DnsTlsaRecord *tlsa;
358 
359  if (NULL == s)
360  return GNUNET_SYSERR;
361  switch (type)
362  {
364  if (1 != inet_pton (AF_INET, s, &value_a))
365  {
367  _ ("Unable to parse IPv4 address `%s'\n"),
368  s);
369  return GNUNET_SYSERR;
370  }
371  *data = GNUNET_new (struct in_addr);
372  GNUNET_memcpy (*data, &value_a, sizeof(value_a));
373  *data_size = sizeof(value_a);
374  return GNUNET_OK;
375 
377  char nsbuf[256];
378  size_t off;
379 
380  off = 0;
381  if (GNUNET_OK !=
382  GNUNET_DNSPARSER_builder_add_name (nsbuf, sizeof(nsbuf), &off, s))
383  {
385  _ ("Failed to serialize NS record with value `%s'\n"),
386  s);
387  return GNUNET_SYSERR;
388  }
389  *data_size = off;
390  *data = GNUNET_malloc (off);
391  GNUNET_memcpy (*data, nsbuf, off);
392  return GNUNET_OK;
393  }
394 
396  char cnamebuf[256];
397  size_t off;
398 
399  off = 0;
401  sizeof(cnamebuf),
402  &off,
403  s))
404  {
406  _ ("Failed to serialize CNAME record with value `%s'\n"),
407  s);
408  return GNUNET_SYSERR;
409  }
410  *data_size = off;
411  *data = GNUNET_malloc (off);
412  GNUNET_memcpy (*data, cnamebuf, off);
413  return GNUNET_OK;
414  }
415 
417  char *sdup;
418  const char *typep;
419  const char *keyp;
420  const char *algp;
421  const char *certp;
422  unsigned int type;
423  unsigned int key;
424  unsigned int alg;
425  size_t cert_size;
426  char *cert_data;
427  struct GNUNET_DNSPARSER_CertRecord cert;
428 
429  sdup = GNUNET_strdup (s);
430  typep = strtok (sdup, " ");
431  if ((NULL == typep) ||
432  ((0 == (type = rfc4398_mnemonic_to_value (typep))) &&
433  ((1 != sscanf (typep, "%u", &type)) || (type > UINT16_MAX))))
434  {
435  GNUNET_free (sdup);
436  return GNUNET_SYSERR;
437  }
438  keyp = strtok (NULL, " ");
439  if ((NULL == keyp) || (1 != sscanf (keyp, "%u", &key)) ||
440  (key > UINT16_MAX))
441  {
442  GNUNET_free (sdup);
443  return GNUNET_SYSERR;
444  }
445  alg = 0;
446  algp = strtok (NULL, " ");
447  if ((NULL == algp) ||
448  ((0 == (type = rfc4034_mnemonic_to_value (typep))) &&
449  ((1 != sscanf (algp, "%u", &alg)) || (alg > UINT8_MAX))))
450  {
451  GNUNET_free (sdup);
452  return GNUNET_SYSERR;
453  }
454  certp = strtok (NULL, " ");
455  if ((NULL == certp) || (0 == strlen (certp)))
456  {
457  GNUNET_free (sdup);
458  return GNUNET_SYSERR;
459  }
460  cert_size = GNUNET_STRINGS_base64_decode (certp,
461  strlen (certp),
462  (void **) &cert_data);
463  GNUNET_free (sdup);
464  cert.cert_type = type;
465  cert.cert_tag = key;
466  cert.algorithm = alg;
467  cert.certificate_size = cert_size;
468  cert.certificate_data = cert_data;
469  {
470  char certbuf[cert_size + sizeof(struct GNUNET_TUN_DnsCertRecord)];
471  size_t off;
472 
473  off = 0;
475  sizeof(certbuf),
476  &off,
477  &cert))
478  {
480  _ ("Failed to serialize CERT record with %u bytes\n"),
481  (unsigned int) cert_size);
482  GNUNET_free (cert_data);
483  return GNUNET_SYSERR;
484  }
485  *data_size = off;
486  *data = GNUNET_malloc (off);
487  GNUNET_memcpy (*data, certbuf, off);
488  }
489  GNUNET_free (cert_data);
490  return GNUNET_OK;
491  }
492 
494  struct GNUNET_DNSPARSER_SoaRecord soa;
495  char soabuf[540];
496  char soa_rname[253 + 1];
497  char soa_mname[253 + 1];
498  unsigned int soa_serial;
499  unsigned int soa_refresh;
500  unsigned int soa_retry;
501  unsigned int soa_expire;
502  unsigned int soa_min;
503  size_t off;
504 
505  if (7 != sscanf (s,
506  "rname=%253s mname=%253s %u,%u,%u,%u,%u",
507  soa_rname,
508  soa_mname,
509  &soa_serial,
510  &soa_refresh,
511  &soa_retry,
512  &soa_expire,
513  &soa_min))
514  {
516  _ ("Unable to parse SOA record `%s'\n"),
517  s);
518  return GNUNET_SYSERR;
519  }
520  soa.mname = soa_mname;
521  soa.rname = soa_rname;
522  soa.serial = (uint32_t) soa_serial;
523  soa.refresh = (uint32_t) soa_refresh;
524  soa.retry = (uint32_t) soa_retry;
525  soa.expire = (uint32_t) soa_expire;
526  soa.minimum_ttl = (uint32_t) soa_min;
527  off = 0;
528  if (GNUNET_OK !=
529  GNUNET_DNSPARSER_builder_add_soa (soabuf, sizeof(soabuf), &off, &soa))
530  {
531  GNUNET_log (
533  _ ("Failed to serialize SOA record with mname `%s' and rname `%s'\n"),
534  soa_mname,
535  soa_rname);
536  return GNUNET_SYSERR;
537  }
538  *data_size = off;
539  *data = GNUNET_malloc (off);
540  GNUNET_memcpy (*data, soabuf, off);
541  return GNUNET_OK;
542  }
543 
545  char ptrbuf[256];
546  size_t off;
547 
548  off = 0;
549  if (GNUNET_OK !=
550  GNUNET_DNSPARSER_builder_add_name (ptrbuf, sizeof(ptrbuf), &off, s))
551  {
553  _ ("Failed to serialize PTR record with value `%s'\n"),
554  s);
555  return GNUNET_SYSERR;
556  }
557  *data_size = off;
558  *data = GNUNET_malloc (off);
559  GNUNET_memcpy (*data, ptrbuf, off);
560  return GNUNET_OK;
561  }
562 
564  struct GNUNET_DNSPARSER_MxRecord mx;
565  char mxbuf[258];
566  char mxhost[253 + 1];
567  unsigned int mx_pref;
568  size_t off;
569 
570  if (2 != sscanf (s, "%u,%253s", &mx_pref, mxhost))
571  {
573  _ ("Unable to parse MX record `%s'\n"),
574  s);
575  return GNUNET_SYSERR;
576  }
577  mx.preference = (uint16_t) mx_pref;
578  mx.mxhost = mxhost;
579  off = 0;
580 
581  if (GNUNET_OK !=
582  GNUNET_DNSPARSER_builder_add_mx (mxbuf, sizeof(mxbuf), &off, &mx))
583  {
585  _ ("Failed to serialize MX record with hostname `%s'\n"),
586  mxhost);
587  return GNUNET_SYSERR;
588  }
589  *data_size = off;
590  *data = GNUNET_malloc (off);
591  GNUNET_memcpy (*data, mxbuf, off);
592  return GNUNET_OK;
593  }
594 
596  struct GNUNET_DNSPARSER_SrvRecord srv;
597  char srvbuf[270];
598  char srvtarget[253 + 1];
599  unsigned int priority;
600  unsigned int weight;
601  unsigned int port;
602  size_t off;
603 
604  if (4 != sscanf (s, "%u %u %u %253s", &priority, &weight, &port,
605  srvtarget))
606  {
608  _ ("Unable to parse SRV record `%s'\n"),
609  s);
610  return GNUNET_SYSERR;
611  }
612  srv.priority = (uint16_t) priority;
613  srv.weight = (uint16_t) weight;
614  srv.port = (uint16_t) port;
615  srv.target = srvtarget;
616  off = 0;
617  if (GNUNET_OK !=
618  GNUNET_DNSPARSER_builder_add_srv (srvbuf, sizeof(srvbuf), &off, &srv))
619  {
621  _ ("Failed to serialize SRV record with target `%s'\n"),
622  srvtarget);
623  return GNUNET_SYSERR;
624  }
625  *data_size = off;
626  *data = GNUNET_malloc (off);
627  GNUNET_memcpy (*data, srvbuf, off);
628  return GNUNET_OK;
629  }
630 
632  *data = GNUNET_strdup (s);
633  *data_size = strlen (s);
634  return GNUNET_OK;
635 
637  if (1 != inet_pton (AF_INET6, s, &value_aaaa))
638  {
640  _ ("Unable to parse IPv6 address `%s'\n"),
641  s);
642  return GNUNET_SYSERR;
643  }
644  *data = GNUNET_new (struct in6_addr);
645  *data_size = sizeof(struct in6_addr);
646  GNUNET_memcpy (*data, &value_aaaa, sizeof(value_aaaa));
647  return GNUNET_OK;
648 
650  unsigned int usage;
651  unsigned int selector;
652  unsigned int matching_type;
653  size_t slen = strlen (s) + 1;
654  char hex[slen];
655 
656  if (4 != sscanf (s, "%u %u %u %s", &usage, &selector, &matching_type,
657  hex))
658  {
660  _ ("Unable to parse TLSA record string `%s'\n"),
661  s);
662  *data_size = 0;
663  return GNUNET_SYSERR;
664  }
665 
666  *data_size = sizeof(struct GNUNET_TUN_DnsTlsaRecord) + strlen (hex) / 2;
667  *data = tlsa = GNUNET_malloc (*data_size);
668  tlsa->usage = (uint8_t) usage;
669  tlsa->selector = (uint8_t) selector;
670  tlsa->matching_type = (uint8_t) matching_type;
671  if (strlen (hex) / 2 != GNUNET_DNSPARSER_hex_to_bin (hex, &tlsa[1]))
672  {
674  _ ("Unable to parse TLSA record string `%s'\n"),
675  s);
676  GNUNET_free (*data);
677  *data = NULL;
678  *data_size = 0;
679  return GNUNET_SYSERR;
680  }
681  return GNUNET_OK;
682  }
683 
684  case GNUNET_DNSPARSER_TYPE_CAA: { // RFC6844
685  struct GNUNET_DNSPARSER_CaaRecord *caa;
686  unsigned int flags;
687  char tag[15]; // Max tag length 15
688  char value[strlen (s) + 1]; // Should be more than enough
689 
690  if (3 != sscanf (s, "%u %s %[^\n]", &flags, tag, value))
691  {
693  _ ("Unable to parse CAA record string `%s'\n"),
694  s);
695  *data_size = 0;
696  return GNUNET_SYSERR;
697  }
698  *data_size = sizeof(struct GNUNET_DNSPARSER_CaaRecord) + strlen (tag)
699  + strlen (value);
700  *data = caa = GNUNET_malloc (*data_size);
701  caa->flags = flags;
702  memcpy (&caa[1], tag, strlen (tag));
703  caa->tag_len = strlen (tag);
704  memcpy ((char *) &caa[1] + caa->tag_len, value, strlen (value));
705  return GNUNET_OK;
706  }
707 
708  default:
709  return GNUNET_SYSERR;
710  }
711 }
Information from SOA records (RFC 1035).
Information from CAA records (RFC 6844).
#define GNUNET_DNSPARSER_TYPE_CNAME
char * mxhost
Name of the mail server.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
Information from CERT records (RFC 4034).
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:1118
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Payload of DNS CERT record.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint8_t usage
Certificate usage 0: CA cert 1: Entity cert 2: Trust anchor 3: domain-issued cert.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_DNSPARSER_TYPE_MX
Information from MX records (RFC 1035).
def usage()
Definition: gnunet-chk.py:356
static unsigned int rfc4398_mnemonic_to_value(const char *mnemonic)
Convert RFC 4394 Mnemonics to the corresponding integer values.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
#define GNUNET_DNSPARSER_TYPE_PTR
size_t GNUNET_DNSPARSER_hex_to_bin(const char *hex, void *data)
Convert a HEX string to block of binary data.
Definition: dnsparser.c:1377
uint8_t flags
The flags of the CAA record.
#define GNUNET_DNSPARSER_TYPE_SOA
static char * value
Value of the record to add/remove.
Payload of DNSSEC TLSA record.
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:1077
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1920
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:1030
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
uint8_t matching_type
Matching type (of selected content) 0: exact match 1: SHA-256 hash 2: SHA-512 hash.
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:1001
#define GNUNET_DNSPARSER_TYPE_TXT
#define GNUNET_DNSPARSER_TYPE_TLSA
uint8_t selector
Selector What part will be matched against the cert presented by server 0: Full cert (in binary) 1: F...
static unsigned int rfc4034_mnemonic_to_value(const char *mnemonic)
Convert RFC 4034 algorithm types to the corresponding integer values.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
#define GNUNET_DNSPARSER_TYPE_CAA
#define GNUNET_DNSPARSER_TYPE_AAAA
#define GNUNET_DNSPARSER_TYPE_NS
#define GNUNET_log(kind,...)
uint16_t priority
Preference for this entry (lower value is higher preference).
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint16_t weight
Relative weight for records with the same priority.
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
#define GNUNET_DNSPARSER_TYPE_SRV
uint32_t data
The data value.
#define GNUNET_DNSPARSER_TYPE_A
#define GNUNET_DNSPARSER_TYPE_CERT
#define GNUNET_malloc(size)
Wrapper around malloc.
Information from SRV records (RFC 2782).
#define GNUNET_free(ptr)
Wrapper around free.
uint8_t tag_len
The length of the tag.
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 (i.e.

"AAAA") to the corresponding number.

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

Definition at line 745 of file plugin_gnsrecord_dns.c.

References name, and name_map.

Referenced by libgnunet_plugin_gnsrecord_dns_init().

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

1) to the corresponding type string (i.e. "A")

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

Definition at line 765 of file plugin_gnsrecord_dns.c.

References name, name_map, and number.

Referenced by libgnunet_plugin_gnsrecord_dns_init().

766 {
767  unsigned int i;
768 
769  i = 0;
770  while ((NULL != name_map[i].name) && (type != name_map[i].number))
771  i++;
772  return name_map[i].name;
773 }
const char * name
uint32_t number
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static struct @23 name_map[]
Mapping of record type numbers to human-readable record type names.
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 783 of file plugin_gnsrecord_dns.c.

References dns_number_to_typename(), dns_string_to_value(), dns_typename_to_number(), dns_value_to_string(), GNUNET_new, 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.

784 {
786 
792  return api;
793 }
GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number
Typename to number.
GNUNET_GNSRECORD_ValueToStringFunction value_to_string
Conversion to string.
GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename
Number to typename.
GNUNET_GNSRECORD_StringToValueFunction string_to_value
Conversion to binary.
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 &#39;value&#39; of a record to the binary representation.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static const char * dns_number_to_typename(void *cls, uint32_t type)
Convert a type number (i.e.
static char * dns_value_to_string(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
static uint32_t dns_typename_to_number(void *cls, const char *dns_typename)
Convert a type name (i.e.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
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 803 of file plugin_gnsrecord_dns.c.

References GNUNET_GNSRECORD_PluginFunctions::cls, and GNUNET_free.

804 {
806 
807  GNUNET_free (api);
808  return NULL;
809 }
void * cls
Closure for all of the callbacks.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_free(ptr)
Wrapper around free.

Variable Documentation

◆ name

const char* name

Definition at line 720 of file plugin_gnsrecord_dns.c.

Referenced by dns_number_to_typename(), and dns_typename_to_number().

◆ number

uint32_t number

Definition at line 721 of file plugin_gnsrecord_dns.c.

Referenced by dns_number_to_typename().

◆ name_map

struct { ... } name_map[]
Initial value:
{ NULL, UINT32_MAX } }
#define GNUNET_DNSPARSER_TYPE_CNAME
#define GNUNET_DNSPARSER_TYPE_MX
#define GNUNET_DNSPARSER_TYPE_PTR
#define GNUNET_DNSPARSER_TYPE_SOA
#define GNUNET_DNSPARSER_TYPE_TXT
#define GNUNET_DNSPARSER_TYPE_TLSA
#define GNUNET_DNSPARSER_TYPE_CAA
#define GNUNET_DNSPARSER_TYPE_AAAA
#define GNUNET_DNSPARSER_TYPE_NS
#define GNUNET_DNSPARSER_TYPE_SRV
#define GNUNET_DNSPARSER_TYPE_A
#define GNUNET_DNSPARSER_TYPE_CERT

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

Referenced by dns_number_to_typename(), and dns_typename_to_number().