GNUnet 0.21.1
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 {
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 {
82 GNUNET_free (cname);
83 return NULL;
84 }
85 return cname;
86 }
87
90 size_t off;
91
92 off = 0;
94 if ((NULL == soa) || (off != data_size))
95 {
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
211 case GNUNET_DNSPARSER_TYPE_URI: { // RFC7553
213 size_t off;
214
215 off = 0;
217 if ((NULL == uri) || (off != data_size))
218 {
219 GNUNET_break_op (0);
220 if (NULL != uri)
222 return NULL;
223 }
225 "%d %d \"%s\"",
226 uri->priority,
227 uri->weight,
228 uri->target);
230 return result;
231 }
232
235 const struct GNUNET_TUN_DnsTlsaRecord *tlsa;
236 char *tlsa_str;
237 char *hex;
238
239 if (data_size < sizeof(struct GNUNET_TUN_DnsTlsaRecord))
240 return NULL; /* malformed */
241 tlsa = data;
242 hex =
245 - sizeof(struct GNUNET_TUN_DnsTlsaRecord));
246 if (0 == GNUNET_asprintf (&tlsa_str,
247 "%u %u %u %s",
248 (unsigned int) tlsa->usage,
249 (unsigned int) tlsa->selector,
250 (unsigned int) tlsa->matching_type,
251 hex))
252 {
253 GNUNET_free (hex);
254 GNUNET_free (tlsa_str);
255 return NULL;
256 }
257 GNUNET_free (hex);
258 return tlsa_str;
259 }
260
261 case GNUNET_DNSPARSER_TYPE_CAA: { // RFC6844
262 const struct GNUNET_DNSPARSER_CaaRecord *caa;
263 char tag[15]; // between 1 and 15 bytes
264 char value[data_size];
265 char *caa_str;
266 if (data_size < sizeof(struct GNUNET_DNSPARSER_CaaRecord))
267 return NULL; /* malformed */
268 caa = data;
269 if ((1 > caa->tag_len) || (15 < caa->tag_len))
270 return NULL; /* malformed */
271 memset (tag, 0, sizeof(tag));
272 memset (value, 0, data_size);
273 memcpy (tag, &caa[1], caa->tag_len);
274 memcpy (value,
275 (char *) &caa[1] + caa->tag_len,
276 data_size - caa->tag_len - 2);
277 if (0 == GNUNET_asprintf (&caa_str,
278 "%u %s %s",
279 (unsigned int) caa->flags,
280 tag,
281 value))
282 {
283 GNUNET_free (caa_str);
284 return NULL;
285 }
286 return caa_str;
287 }
288
289 default:
290 return NULL;
291 }
292}
static char * data
The data to insert into the dht.
static struct GNUNET_NAMECACHE_Handle * ns
Handle to the namecache.
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static int result
Global testing status.
#define GNUNET_DNSPARSER_TYPE_URI
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:455
char * GNUNET_DNSPARSER_bin_to_hex(const void *data, size_t data_size)
Convert a block of binary data to HEX.
Definition: dnsparser.c:1489
#define GNUNET_DNSPARSER_TYPE_TLSA
#define GNUNET_DNSPARSER_TYPE_CAA
#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_SMIMEA
#define GNUNET_DNSPARSER_TYPE_PTR
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:410
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:579
void GNUNET_DNSPARSER_free_uri(struct GNUNET_DNSPARSER_UriRecord *uri)
Free URI information record.
Definition: dnsparser.c:154
#define GNUNET_DNSPARSER_TYPE_NS
#define GNUNET_DNSPARSER_TYPE_CNAME
struct GNUNET_DNSPARSER_UriRecord * GNUNET_DNSPARSER_parse_uri(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS URI record.
Definition: dnsparser.c:537
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:496
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:353
void GNUNET_DNSPARSER_free_soa(struct GNUNET_DNSPARSER_SoaRecord *soa)
Free SOA information record.
Definition: dnsparser.c:108
void GNUNET_DNSPARSER_free_mx(struct GNUNET_DNSPARSER_MxRecord *mx)
Free MX information record.
Definition: dnsparser.c:169
#define GNUNET_DNSPARSER_TYPE_AAAA
#define GNUNET_DNSPARSER_TYPE_MX
#define GNUNET_DNSPARSER_TYPE_TXT
#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:1622
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.
Information from URI records (RFC 7553).
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.

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_free_uri(), GNUNET_DNSPARSER_parse_cert(), GNUNET_DNSPARSER_parse_mx(), GNUNET_DNSPARSER_parse_name(), GNUNET_DNSPARSER_parse_soa(), GNUNET_DNSPARSER_parse_srv(), GNUNET_DNSPARSER_parse_uri(), 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_SMIMEA, GNUNET_DNSPARSER_TYPE_SOA, GNUNET_DNSPARSER_TYPE_SRV, GNUNET_DNSPARSER_TYPE_TLSA, GNUNET_DNSPARSER_TYPE_TXT, GNUNET_DNSPARSER_TYPE_URI, GNUNET_free, GNUNET_strdup, GNUNET_STRINGS_base64_encode(), GNUNET_strndup, 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, uri, 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 302 of file plugin_gnsrecord_dns.c.

303{
304 static struct
305 {
306 const char *mnemonic;
307 unsigned int val;
308 } table[] = { { "PKIX", 1 },
309 { "SPKI", 2 },
310 { "PGP", 3 },
311 { "IPKIX", 4 },
312 { "ISPKI", 5 },
313 { "IPGP", 6 },
314 { "ACPKIX", 7 },
315 { "IACPKIX", 8 },
316 { "URI", 253 },
317 { "OID", 254 },
318 { NULL, 0 } };
319 unsigned int i;
320
321 for (i = 0; NULL != table[i].mnemonic; i++)
322 if (0 == strcasecmp (mnemonic, table[i].mnemonic))
323 return table[i].val;
324 return 0;
325}
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 335 of file plugin_gnsrecord_dns.c.

336{
337 static struct
338 {
339 const char *mnemonic;
340 unsigned int val;
341 } table[] = { { "RSAMD5", 1 },
342 { "DH", 2 },
343 { "DSA", 3 },
344 { "ECC", 4 },
345 { "RSASHA1", 5 },
346 { "INDIRECT", 252 },
347 { "PRIVATEDNS", 253 },
348 { "PRIVATEOID", 254 },
349 { NULL, 0 } };
350 unsigned int i;
351
352 for (i = 0; NULL != table[i].mnemonic; i++)
353 if (0 == strcasecmp (mnemonic, table[i].mnemonic))
354 return table[i].val;
355 return 0;
356}

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 371 of file plugin_gnsrecord_dns.c.

376{
377 struct in_addr value_a;
378 struct in6_addr value_aaaa;
379 struct GNUNET_TUN_DnsTlsaRecord *tlsa;
380
381 if (NULL == s)
382 return GNUNET_SYSERR;
383 switch (type)
384 {
386 if (1 != inet_pton (AF_INET, s, &value_a))
387 {
389 _ ("Unable to parse IPv4 address `%s'\n"),
390 s);
391 return GNUNET_SYSERR;
392 }
393 *data = GNUNET_new (struct in_addr);
394 GNUNET_memcpy (*data, &value_a, sizeof(value_a));
395 *data_size = sizeof(value_a);
396 return GNUNET_OK;
397
399 char nsbuf[256];
400 size_t off;
401
402 off = 0;
403 if (GNUNET_OK !=
404 GNUNET_DNSPARSER_builder_add_name (nsbuf, sizeof(nsbuf), &off, s))
405 {
407 _ ("Failed to serialize NS record with value `%s'\n"),
408 s);
409 return GNUNET_SYSERR;
410 }
411 *data_size = off;
412 *data = GNUNET_malloc (off);
413 GNUNET_memcpy (*data, nsbuf, off);
414 return GNUNET_OK;
415 }
416
418 char cnamebuf[256];
419 size_t off;
420
421 off = 0;
423 sizeof(cnamebuf),
424 &off,
425 s))
426 {
428 _ ("Failed to serialize CNAME record with value `%s'\n"),
429 s);
430 return GNUNET_SYSERR;
431 }
432 *data_size = off;
433 *data = GNUNET_malloc (off);
434 GNUNET_memcpy (*data, cnamebuf, off);
435 return GNUNET_OK;
436 }
437
439 char *sdup;
440 const char *typep;
441 const char *keyp;
442 const char *algp;
443 const char *certp;
444 unsigned int type;
445 unsigned int key;
446 unsigned int alg;
447 size_t cert_size;
448 char *cert_data;
449 struct GNUNET_DNSPARSER_CertRecord cert;
450
451 sdup = GNUNET_strdup (s);
452 typep = strtok (sdup, " ");
453 if ((NULL == typep) ||
454 ((0 == (type = rfc4398_mnemonic_to_value (typep))) &&
455 ((1 != sscanf (typep, "%u", &type)) || (type > UINT16_MAX))))
456 {
457 GNUNET_free (sdup);
458 return GNUNET_SYSERR;
459 }
460 keyp = strtok (NULL, " ");
461 if ((NULL == keyp) || (1 != sscanf (keyp, "%u", &key)) ||
462 (key > UINT16_MAX))
463 {
464 GNUNET_free (sdup);
465 return GNUNET_SYSERR;
466 }
467 alg = 0;
468 algp = strtok (NULL, " ");
469 if ((NULL == algp) ||
470 ((0 == (type = rfc4034_mnemonic_to_value (typep))) &&
471 ((1 != sscanf (algp, "%u", &alg)) || (alg > UINT8_MAX))))
472 {
473 GNUNET_free (sdup);
474 return GNUNET_SYSERR;
475 }
476 certp = strtok (NULL, " ");
477 if ((NULL == certp) || (0 == strlen (certp)))
478 {
479 GNUNET_free (sdup);
480 return GNUNET_SYSERR;
481 }
482 cert_size = GNUNET_STRINGS_base64_decode (certp,
483 strlen (certp),
484 (void **) &cert_data);
485 GNUNET_free (sdup);
486 cert.cert_type = type;
487 cert.cert_tag = key;
488 cert.algorithm = alg;
489 cert.certificate_size = cert_size;
490 cert.certificate_data = cert_data;
491 {
492 char certbuf[cert_size + sizeof(struct GNUNET_TUN_DnsCertRecord)];
493 size_t off;
494
495 off = 0;
497 sizeof(certbuf),
498 &off,
499 &cert))
500 {
502 _ ("Failed to serialize CERT record with %u bytes\n"),
503 (unsigned int) cert_size);
504 GNUNET_free (cert_data);
505 return GNUNET_SYSERR;
506 }
507 *data_size = off;
508 *data = GNUNET_malloc (off);
509 GNUNET_memcpy (*data, certbuf, off);
510 }
511 GNUNET_free (cert_data);
512 return GNUNET_OK;
513 }
514
517 char soabuf[540];
518 char soa_rname[253 + 1];
519 char soa_mname[253 + 1];
520 unsigned int soa_serial;
521 unsigned int soa_refresh;
522 unsigned int soa_retry;
523 unsigned int soa_expire;
524 unsigned int soa_min;
525 size_t off;
526
527 if (7 != sscanf (s,
528 "%253s %253s ( %u %u %u %u %u )",
529 soa_rname,
530 soa_mname,
531 &soa_serial,
532 &soa_refresh,
533 &soa_retry,
534 &soa_expire,
535 &soa_min))
536 {
538 _ ("Unable to parse SOA record `%s'\n"),
539 s);
540 return GNUNET_SYSERR;
541 }
542 soa.mname = soa_mname;
543 soa.rname = soa_rname;
544 soa.serial = (uint32_t) soa_serial;
545 soa.refresh = (uint32_t) soa_refresh;
546 soa.retry = (uint32_t) soa_retry;
547 soa.expire = (uint32_t) soa_expire;
548 soa.minimum_ttl = (uint32_t) soa_min;
549 off = 0;
550 if (GNUNET_OK !=
551 GNUNET_DNSPARSER_builder_add_soa (soabuf, sizeof(soabuf), &off, &soa))
552 {
553 GNUNET_log (
555 _ ("Failed to serialize SOA record with mname `%s' and rname `%s'\n"),
556 soa_mname,
557 soa_rname);
558 return GNUNET_SYSERR;
559 }
560 *data_size = off;
561 *data = GNUNET_malloc (off);
562 GNUNET_memcpy (*data, soabuf, off);
563 return GNUNET_OK;
564 }
565
567 char ptrbuf[256];
568 size_t off;
569
570 off = 0;
571 if (GNUNET_OK !=
572 GNUNET_DNSPARSER_builder_add_name (ptrbuf, sizeof(ptrbuf), &off, s))
573 {
575 _ ("Failed to serialize PTR record with value `%s'\n"),
576 s);
577 return GNUNET_SYSERR;
578 }
579 *data_size = off;
580 *data = GNUNET_malloc (off);
581 GNUNET_memcpy (*data, ptrbuf, off);
582 return GNUNET_OK;
583 }
584
587 char mxbuf[258];
588 char mxhost[253 + 1];
589 unsigned int mx_pref;
590 size_t off;
591
592 if (2 != sscanf (s, "%u %253s", &mx_pref, mxhost))
593 {
595 _ ("Unable to parse MX record `%s'\n"),
596 s);
597 return GNUNET_SYSERR;
598 }
599 mx.preference = (uint16_t) mx_pref;
600 mx.mxhost = mxhost;
601 off = 0;
602
603 if (GNUNET_OK !=
604 GNUNET_DNSPARSER_builder_add_mx (mxbuf, sizeof(mxbuf), &off, &mx))
605 {
607 _ ("Failed to serialize MX record with hostname `%s'\n"),
608 mxhost);
609 return GNUNET_SYSERR;
610 }
611 *data_size = off;
612 *data = GNUNET_malloc (off);
613 GNUNET_memcpy (*data, mxbuf, off);
614 return GNUNET_OK;
615 }
616
619 char srvbuf[270];
620 char srvtarget[253 + 1];
621 unsigned int priority;
622 unsigned int weight;
623 unsigned int port;
624 size_t off;
625
626 if (4 != sscanf (s, "%u %u %u %253s", &priority, &weight, &port,
627 srvtarget))
628 {
630 _ ("Unable to parse SRV record `%s'\n"),
631 s);
632 return GNUNET_SYSERR;
633 }
634 srv.priority = (uint16_t) priority;
635 srv.weight = (uint16_t) weight;
636 srv.port = (uint16_t) port;
637 srv.target = srvtarget;
638 off = 0;
639 if (GNUNET_OK !=
640 GNUNET_DNSPARSER_builder_add_srv (srvbuf, sizeof(srvbuf), &off, &srv))
641 {
643 _ ("Failed to serialize SRV record with target `%s'\n"),
644 srvtarget);
645 return GNUNET_SYSERR;
646 }
647 *data_size = off;
648 *data = GNUNET_malloc (off);
649 GNUNET_memcpy (*data, srvbuf, off);
650 return GNUNET_OK;
651 }
652
655 char target[strlen (s)];
656 unsigned int priority;
657 unsigned int weight;
658 size_t off;
659
660 if (3 != sscanf (s, "%u %u \"%s", &priority, &weight, &target[0])) // only \" befor %s because %s will consume the ending " of the presentation of the URI record
661 {
663 _ ("Unable to parse URI record `%s'\n"),
664 s);
665 return GNUNET_SYSERR;
666 }
667 target[strlen (target) - 1] = '\0'; // Removing the last " of the presentation of the URI record
668
669 uri.priority = (uint16_t) priority;
670 uri.weight = (uint16_t) weight;
671 uri.target = target;
672 off = 0;
673
674 // TODO add more precise uri checking (RFC3986)
675 if (strstr (target, ":") == NULL ||
676 target[0] == 58 ||
677 target[strlen (target) - 1] == 58)
678 {
680 _ ("Failed to serialize URI record with target `%s'\n"),
681 target);
682 return GNUNET_SYSERR;
683 }
684
685 char uribuf[sizeof(struct GNUNET_TUN_DnsUriRecord) + strlen (target) + 1];
686
687 if (GNUNET_OK !=
688 GNUNET_DNSPARSER_builder_add_uri (uribuf, sizeof(uribuf), &off, &uri))
689 {
691 _ ("Failed to serialize URI record with target `%s'\n"),
692 target);
693 return GNUNET_SYSERR;
694 }
695 *data_size = off;
696 *data = GNUNET_malloc (off);
697 GNUNET_memcpy (*data, uribuf, off);
698 return GNUNET_OK;
699 }
700
702 *data = GNUNET_strdup (s);
703 *data_size = strlen (s);
704 return GNUNET_OK;
705
707 if (1 != inet_pton (AF_INET6, s, &value_aaaa))
708 {
710 _ ("Unable to parse IPv6 address `%s'\n"),
711 s);
712 return GNUNET_SYSERR;
713 }
714 *data = GNUNET_new (struct in6_addr);
715 *data_size = sizeof(struct in6_addr);
716 GNUNET_memcpy (*data, &value_aaaa, sizeof(value_aaaa));
717 return GNUNET_OK;
718
721 unsigned int usage;
722 unsigned int selector;
723 unsigned int matching_type;
724 size_t slen = strlen (s) + 1;
725 char hex[slen];
726
727 if (4 != sscanf (s, "%u %u %u %s", &usage, &selector, &matching_type,
728 hex))
729 {
731 _ ("Unable to parse TLSA/SMIMEA record string `%s'\n"),
732 s);
733 *data_size = 0;
734 return GNUNET_SYSERR;
735 }
736
737 *data_size = sizeof(struct GNUNET_TUN_DnsTlsaRecord) + strlen (hex) / 2;
738 *data = tlsa = GNUNET_malloc (*data_size);
739 tlsa->usage = (uint8_t) usage;
740 tlsa->selector = (uint8_t) selector;
741 tlsa->matching_type = (uint8_t) matching_type;
742 if (strlen (hex) / 2 != GNUNET_DNSPARSER_hex_to_bin (hex, &tlsa[1]))
743 {
745 _ ("Unable to parse TLSA/SMIMEA record string `%s'\n"),
746 s);
747 GNUNET_free (*data);
748 *data = NULL;
749 *data_size = 0;
750 return GNUNET_SYSERR;
751 }
752 return GNUNET_OK;
753 }
754
755 case GNUNET_DNSPARSER_TYPE_CAA: { // RFC6844
756 struct GNUNET_DNSPARSER_CaaRecord *caa;
757 unsigned int flags;
758 char tag[15]; // Max tag length 15
759 char value[strlen (s) + 1]; // Should be more than enough
760
761 if (3 != sscanf (s, "%u %s %[^\n]", &flags, tag, value))
762 {
764 _ ("Unable to parse CAA record string `%s'\n"),
765 s);
766 *data_size = 0;
767 return GNUNET_SYSERR;
768 }
769 *data_size = sizeof(struct GNUNET_DNSPARSER_CaaRecord) + strlen (tag)
770 + strlen (value);
771 *data = caa = GNUNET_malloc (*data_size);
772 caa->flags = flags;
773 memcpy (&caa[1], tag, strlen (tag));
774 caa->tag_len = strlen (tag);
775 memcpy ((char *) &caa[1] + caa->tag_len, value, strlen (value));
776 return GNUNET_OK;
777 }
778
779 default:
780 return GNUNET_SYSERR;
781 }
782}
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:982
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:1125
size_t GNUNET_DNSPARSER_hex_to_bin(const char *hex, void *data)
Convert a HEX string to block of binary data.
Definition: dnsparser.c:1512
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:1172
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:1096
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:1213
int GNUNET_DNSPARSER_builder_add_uri(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_UriRecord *uri)
Add an URI record to the UDP packet at the given location.
Definition: dnsparser.c:1249
#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:1724
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.
uint16_t priority
Preference for this entry (lower value is higher preference).
uint16_t weight
Relative weight for records with the same priority.
char * target
URI of the target, where the URI is as specified in RFC 3986.
Payload of DNS CERT record.
Payload of DNS URI record (header).

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_builder_add_uri(), 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_SMIMEA, GNUNET_DNSPARSER_TYPE_SOA, GNUNET_DNSPARSER_TYPE_SRV, GNUNET_DNSPARSER_TYPE_TLSA, GNUNET_DNSPARSER_TYPE_TXT, GNUNET_DNSPARSER_TYPE_URI, 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, GNUNET_DNSPARSER_SrvRecord::port, port, GNUNET_DNSPARSER_MxRecord::preference, GNUNET_DNSPARSER_SrvRecord::priority, GNUNET_DNSPARSER_UriRecord::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, GNUNET_DNSPARSER_UriRecord::target, type, uri, gnunet-chk::usage(), GNUNET_TUN_DnsTlsaRecord::usage, value, GNUNET_DNSPARSER_SrvRecord::weight, and GNUNET_DNSPARSER_UriRecord::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 818 of file plugin_gnsrecord_dns.c.

819{
820 unsigned int i;
821
822 i = 0;
823 while ((NULL != name_map[i].name) &&
824 (0 != strcasecmp (dns_typename, name_map[i].name)))
825 i++;
826 return name_map[i].number;
827}
static struct @38 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 838 of file plugin_gnsrecord_dns.c.

839{
840 unsigned int i;
841
842 i = 0;
843 while ((NULL != name_map[i].name) && (type != name_map[i].number))
844 i++;
845 return name_map[i].name;
846}
uint32_t number

References name, name_map, number, and type.

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 850 of file plugin_gnsrecord_dns.c.

851{
852 return GNUNET_NO;
853}
@ GNUNET_NO

References GNUNET_NO.

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 863 of file plugin_gnsrecord_dns.c.

864{
866
873 return api;
874}
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 const char * dns_number_to_typename(void *cls, uint32_t type)
Convert a type number to the corresponding type string (e.g.
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 884 of file plugin_gnsrecord_dns.c.

885{
887
888 GNUNET_free (api);
889 return NULL;
890}
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 791 of file plugin_gnsrecord_dns.c.

Referenced by dns_number_to_typename(), and dns_typename_to_number().

◆ number

uint32_t number

Definition at line 792 of file plugin_gnsrecord_dns.c.

Referenced by dns_number_to_typename().

◆ 

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

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

Referenced by dns_number_to_typename(), and dns_typename_to_number().