GNUnet 0.22.2
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:1497
#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:581
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:1599
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 cert_rrtype;
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 == (cert_rrtype = rfc4398_mnemonic_to_value (typep))) &&
455 ((1 != sscanf (typep, "%u", &cert_rrtype)) || (cert_rrtype >
456 UINT16_MAX))))
457 {
458 GNUNET_free (sdup);
459 return GNUNET_SYSERR;
460 }
461 keyp = strtok (NULL, " ");
462 if ((NULL == keyp) || (1 != sscanf (keyp, "%u", &key)) ||
463 (key > UINT16_MAX))
464 {
465 GNUNET_free (sdup);
466 return GNUNET_SYSERR;
467 }
468 alg = 0;
469 algp = strtok (NULL, " ");
470 if ((NULL == algp) ||
471 ((0 == (cert_rrtype = rfc4034_mnemonic_to_value (typep))) &&
472 ((1 != sscanf (algp, "%u", &alg)) || (alg > UINT8_MAX))))
473 {
474 GNUNET_free (sdup);
475 return GNUNET_SYSERR;
476 }
477 certp = strtok (NULL, " ");
478 if ((NULL == certp) || (0 == strlen (certp)))
479 {
480 GNUNET_free (sdup);
481 return GNUNET_SYSERR;
482 }
483 cert_size = GNUNET_STRINGS_base64_decode (certp,
484 strlen (certp),
485 (void **) &cert_data);
486 GNUNET_free (sdup);
487 cert.cert_type = cert_rrtype;
488 cert.cert_tag = key;
489 cert.algorithm = alg;
490 cert.certificate_size = cert_size;
491 cert.certificate_data = cert_data;
492 {
493 char certbuf[cert_size + sizeof(struct GNUNET_TUN_DnsCertRecord)];
494 size_t off;
495
496 off = 0;
498 sizeof(certbuf),
499 &off,
500 &cert))
501 {
503 _ ("Failed to serialize CERT record with %u bytes\n"),
504 (unsigned int) cert_size);
505 GNUNET_free (cert_data);
506 return GNUNET_SYSERR;
507 }
508 *data_size = off;
509 *data = GNUNET_malloc (off);
510 GNUNET_memcpy (*data, certbuf, off);
511 }
512 GNUNET_free (cert_data);
513 return GNUNET_OK;
514 }
515
518 char soabuf[540];
519 char soa_rname[253 + 1];
520 char soa_mname[253 + 1];
521 unsigned int soa_serial;
522 unsigned int soa_refresh;
523 unsigned int soa_retry;
524 unsigned int soa_expire;
525 unsigned int soa_min;
526 size_t off;
527
528 if (7 != sscanf (s,
529 "%253s %253s ( %u %u %u %u %u )",
530 soa_rname,
531 soa_mname,
532 &soa_serial,
533 &soa_refresh,
534 &soa_retry,
535 &soa_expire,
536 &soa_min))
537 {
539 _ ("Unable to parse SOA record `%s'\n"),
540 s);
541 return GNUNET_SYSERR;
542 }
543 soa.mname = soa_mname;
544 soa.rname = soa_rname;
545 soa.serial = (uint32_t) soa_serial;
546 soa.refresh = (uint32_t) soa_refresh;
547 soa.retry = (uint32_t) soa_retry;
548 soa.expire = (uint32_t) soa_expire;
549 soa.minimum_ttl = (uint32_t) soa_min;
550 off = 0;
551 if (GNUNET_OK !=
552 GNUNET_DNSPARSER_builder_add_soa (soabuf, sizeof(soabuf), &off, &soa))
553 {
554 GNUNET_log (
556 _ ("Failed to serialize SOA record with mname `%s' and rname `%s'\n"),
557 soa_mname,
558 soa_rname);
559 return GNUNET_SYSERR;
560 }
561 *data_size = off;
562 *data = GNUNET_malloc (off);
563 GNUNET_memcpy (*data, soabuf, off);
564 return GNUNET_OK;
565 }
566
568 char ptrbuf[256];
569 size_t off;
570
571 off = 0;
572 if (GNUNET_OK !=
573 GNUNET_DNSPARSER_builder_add_name (ptrbuf, sizeof(ptrbuf), &off, s))
574 {
576 _ ("Failed to serialize PTR record with value `%s'\n"),
577 s);
578 return GNUNET_SYSERR;
579 }
580 *data_size = off;
581 *data = GNUNET_malloc (off);
582 GNUNET_memcpy (*data, ptrbuf, off);
583 return GNUNET_OK;
584 }
585
588 char mxbuf[258];
589 char mxhost[253 + 1];
590 unsigned int mx_pref;
591 size_t off;
592
593 if (2 != sscanf (s, "%u %253s", &mx_pref, mxhost))
594 {
596 _ ("Unable to parse MX record `%s'\n"),
597 s);
598 return GNUNET_SYSERR;
599 }
600 mx.preference = (uint16_t) mx_pref;
601 mx.mxhost = mxhost;
602 off = 0;
603
604 if (GNUNET_OK !=
605 GNUNET_DNSPARSER_builder_add_mx (mxbuf, sizeof(mxbuf), &off, &mx))
606 {
608 _ ("Failed to serialize MX record with hostname `%s'\n"),
609 mxhost);
610 return GNUNET_SYSERR;
611 }
612 *data_size = off;
613 *data = GNUNET_malloc (off);
614 GNUNET_memcpy (*data, mxbuf, off);
615 return GNUNET_OK;
616 }
617
620 char srvbuf[270];
621 char srvtarget[253 + 1];
622 unsigned int priority;
623 unsigned int weight;
624 unsigned int port;
625 size_t off;
626
627 if (4 != sscanf (s, "%u %u %u %253s", &priority, &weight, &port,
628 srvtarget))
629 {
631 _ ("Unable to parse SRV record `%s'\n"),
632 s);
633 return GNUNET_SYSERR;
634 }
635 srv.priority = (uint16_t) priority;
636 srv.weight = (uint16_t) weight;
637 srv.port = (uint16_t) port;
638 srv.target = srvtarget;
639 off = 0;
640 if (GNUNET_OK !=
641 GNUNET_DNSPARSER_builder_add_srv (srvbuf, sizeof(srvbuf), &off, &srv))
642 {
644 _ ("Failed to serialize SRV record with target `%s'\n"),
645 srvtarget);
646 return GNUNET_SYSERR;
647 }
648 *data_size = off;
649 *data = GNUNET_malloc (off);
650 GNUNET_memcpy (*data, srvbuf, off);
651 return GNUNET_OK;
652 }
653
656 char target[strlen (s) + 1];
657 unsigned int priority;
658 unsigned int weight;
659 size_t off;
660
661 if (3 != sscanf (s, "%u %u \"%s", &priority, &weight, &target[0])) // only \" before %s because %s will consume the ending " of the presentation of the URI record
662 {
664 _ ("Unable to parse URI record `%s'\n"),
665 s);
666 return GNUNET_SYSERR;
667 }
668 target[strlen (target) - 1] = '\0'; // Removing the last " of the presentation of the URI record
669
670 uri.priority = (uint16_t) priority;
671 uri.weight = (uint16_t) weight;
672 uri.target = target;
673 off = 0;
674
675 // TODO add more precise uri checking (RFC3986)
676 if (strstr (target, ":") == NULL ||
677 target[0] == 58 ||
678 target[strlen (target) - 1] == 58)
679 {
681 _ ("Failed to serialize URI record with target `%s'\n"),
682 target);
683 return GNUNET_SYSERR;
684 }
685 {
686 char uribuf[sizeof(struct GNUNET_TUN_DnsUriRecord) + strlen (target) + 1
687 ];
688
689 if (GNUNET_OK !=
690 GNUNET_DNSPARSER_builder_add_uri (uribuf, sizeof(uribuf), &off, &uri
691 ))
692 {
694 _ ("Failed to serialize URI record with target `%s'\n"),
695 target);
696 return GNUNET_SYSERR;
697 }
698 *data_size = off;
699 *data = GNUNET_malloc (off);
700 GNUNET_memcpy (*data, uribuf, off);
701 }
702 return GNUNET_OK;
703 }
704
706 *data = GNUNET_strdup (s);
707 *data_size = strlen (s);
708 return GNUNET_OK;
709
711 if (1 != inet_pton (AF_INET6, s, &value_aaaa))
712 {
714 _ ("Unable to parse IPv6 address `%s'\n"),
715 s);
716 return GNUNET_SYSERR;
717 }
718 *data = GNUNET_new (struct in6_addr);
719 *data_size = sizeof(struct in6_addr);
720 GNUNET_memcpy (*data, &value_aaaa, sizeof(value_aaaa));
721 return GNUNET_OK;
722
725 unsigned int usage;
726 unsigned int selector;
727 unsigned int matching_type;
728 size_t slen = strlen (s) + 1;
729 char hex[slen];
730
731 if (4 != sscanf (s, "%u %u %u %s", &usage, &selector, &matching_type,
732 hex))
733 {
735 _ ("Unable to parse TLSA/SMIMEA record string `%s'\n"),
736 s);
737 *data_size = 0;
738 return GNUNET_SYSERR;
739 }
740
741 *data_size = sizeof(struct GNUNET_TUN_DnsTlsaRecord) + strlen (hex) / 2;
742 *data = tlsa = GNUNET_malloc (*data_size);
743 tlsa->usage = (uint8_t) usage;
744 tlsa->selector = (uint8_t) selector;
745 tlsa->matching_type = (uint8_t) matching_type;
746 if (strlen (hex) / 2 != GNUNET_DNSPARSER_hex_to_bin (hex, &tlsa[1]))
747 {
749 _ ("Unable to parse TLSA/SMIMEA record string `%s'\n"),
750 s);
751 GNUNET_free (*data);
752 *data = NULL;
753 *data_size = 0;
754 return GNUNET_SYSERR;
755 }
756 return GNUNET_OK;
757 }
758
759 case GNUNET_DNSPARSER_TYPE_CAA: { // RFC6844
760 struct GNUNET_DNSPARSER_CaaRecord *caa;
761 unsigned int flags;
762 char tag[15]; // Max tag length 15
763 char value[strlen (s) + 1]; // Should be more than enough
764
765 if (3 != sscanf (s, "%u %s %[^\n]", &flags, tag, value))
766 {
768 _ ("Unable to parse CAA record string `%s'\n"),
769 s);
770 *data_size = 0;
771 return GNUNET_SYSERR;
772 }
773 *data_size = sizeof(struct GNUNET_DNSPARSER_CaaRecord) + strlen (tag)
774 + strlen (value);
775 *data = caa = GNUNET_malloc (*data_size);
776 caa->flags = flags;
777 memcpy (&caa[1], tag, strlen (tag));
778 caa->tag_len = strlen (tag);
779 memcpy ((char *) &caa[1] + caa->tag_len, value, strlen (value));
780 return GNUNET_OK;
781 }
782
783 default:
784 return GNUNET_SYSERR;
785 }
786}
static uint16_t port
Port number.
Definition: gnunet-bcd.c:146
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:985
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:1129
size_t GNUNET_DNSPARSER_hex_to_bin(const char *hex, void *data)
Convert a HEX string to block of binary data.
Definition: dnsparser.c:1520
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:1177
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:1099
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:1218
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:1255
#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:1701
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 822 of file plugin_gnsrecord_dns.c.

823{
824 unsigned int i;
825
826 i = 0;
827 while ((NULL != name_map[i].name) &&
828 (0 != strcasecmp (dns_typename, name_map[i].name)))
829 i++;
830 return name_map[i].number;
831}
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 842 of file plugin_gnsrecord_dns.c.

843{
844 unsigned int i;
845
846 i = 0;
847 while ((NULL != name_map[i].name) && (type != name_map[i].number))
848 i++;
849 return name_map[i].name;
850}
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 854 of file plugin_gnsrecord_dns.c.

855{
856 return GNUNET_NO;
857}
@ 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 870 of file plugin_gnsrecord_dns.c.

871{
873
880 return api;
881}
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 894 of file plugin_gnsrecord_dns.c.

895{
897
898 GNUNET_free (api);
899 return NULL;
900}
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 795 of file plugin_gnsrecord_dns.c.

Referenced by dns_number_to_typename(), and dns_typename_to_number().

◆ number

uint32_t number

Definition at line 796 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().