GNUnet  0.17.6
gnunet_dnsparser_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2010-2014 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
35 #ifndef GNUNET_DNSPARSER_LIB_H
36 #define GNUNET_DNSPARSER_LIB_H
37 
38 #include "gnunet_util_lib.h"
39 
43 #define GNUNET_DNSPARSER_MAX_LABEL_LENGTH 63
44 
48 #define GNUNET_DNSPARSER_MAX_NAME_LENGTH 253
49 
50 
54 #define GNUNET_DNSPARSER_TYPE_ANY 0
55 #define GNUNET_DNSPARSER_TYPE_A 1
56 #define GNUNET_DNSPARSER_TYPE_NS 2
57 #define GNUNET_DNSPARSER_TYPE_CNAME 5
58 #define GNUNET_DNSPARSER_TYPE_SOA 6
59 #define GNUNET_DNSPARSER_TYPE_PTR 12
60 #define GNUNET_DNSPARSER_TYPE_MX 15
61 #define GNUNET_DNSPARSER_TYPE_TXT 16
62 #define GNUNET_DNSPARSER_TYPE_RP 17
63 #define GNUNET_DNSPARSER_TYPE_AFSDB 18
64 #define GNUNET_DNSPARSER_TYPE_SIG 24
65 #define GNUNET_DNSPARSER_TYPE_KEY 25
66 #define GNUNET_DNSPARSER_TYPE_AAAA 28
67 #define GNUNET_DNSPARSER_TYPE_LOC 29
68 #define GNUNET_DNSPARSER_TYPE_SRV 33
69 #define GNUNET_DNSPARSER_TYPE_NAPTR 35
70 #define GNUNET_DNSPARSER_TYPE_KX 36
71 #define GNUNET_DNSPARSER_TYPE_CERT 37
72 #define GNUNET_DNSPARSER_TYPE_DNAME 39
73 #define GNUNET_DNSPARSER_TYPE_APL 42
74 #define GNUNET_DNSPARSER_TYPE_DS 43
75 #define GNUNET_DNSPARSER_TYPE_SSHFP 44
76 #define GNUNET_DNSPARSER_TYPE_IPSECKEY 45
77 #define GNUNET_DNSPARSER_TYPE_RRSIG 46
78 #define GNUNET_DNSPARSER_TYPE_NSEC 47
79 #define GNUNET_DNSPARSER_TYPE_DNSKEY 48
80 #define GNUNET_DNSPARSER_TYPE_DHCID 49
81 #define GNUNET_DNSPARSER_TYPE_NSEC3 50
82 #define GNUNET_DNSPARSER_TYPE_NSEC3PARAM 51
83 #define GNUNET_DNSPARSER_TYPE_TLSA 52
84 #define GNUNET_DNSPARSER_TYPE_HIP 55
85 #define GNUNET_DNSPARSER_TYPE_CDS 59
86 #define GNUNET_DNSPARSER_TYPE_CDNSKEY 60
87 #define GNUNET_DNSPARSER_TYPE_OPENPGPKEY 61
88 #define GNUNET_DNSPARSER_TYPE_TKEY 249
89 #define GNUNET_DNSPARSER_TYPE_TSIG 250
90 #define GNUNET_DNSPARSER_TYPE_ALL 255
91 #define GNUNET_DNSPARSER_TYPE_URI 256
92 #define GNUNET_DNSPARSER_TYPE_CAA 257
93 #define GNUNET_DNSPARSER_TYPE_TA 32768
94 
99 {
107  char *name;
108 
112  uint16_t type;
113 
118 };
119 
120 
125 {
129  uint16_t preference;
130 
138  char *mxhost;
139 };
140 
141 
146 {
154  char *target;
155 
161  uint16_t priority;
162 
168  uint16_t weight;
169 
173  uint16_t port;
174 };
175 
176 
181 {
186 
191 
196 
201 
206 
211 
216 
221 
226 };
227 
228 
234 {
239 
244 
249 
254 
259 
264 
269 
274 
279 
284 
289 
294 
299 
304 };
305 
306 
311 {
316 
320  uint16_t cert_tag;
321 
326 
331 
336 };
337 
338 
343 {
352  char *mname;
353 
362  char *rname;
363 
367  uint32_t serial;
368 
372  uint32_t refresh;
373 
378  uint32_t retry;
379 
384  uint32_t expire;
385 
390  uint32_t minimum_ttl;
391 };
392 
393 
400 {
404  uint8_t flags;
405 
409  uint8_t tag_len;
410 };
411 
412 
417 {
421  void *data;
422 
426  size_t data_len;
427 };
428 
429 
434 {
442  char *name;
443 
447  union
448  {
456  char *hostname;
457 
462 
467 
472 
477 
482  } data;
483 
484 
489 
493  uint16_t type;
494 
499 };
500 
501 
506 {
511 
516 
521 
526 
530  unsigned int num_queries;
531 
535  unsigned int num_answers;
536 
540  unsigned int num_authority_records;
541 
546 
550  struct GNUNET_TUN_DnsFlags flags;
551 
555  uint16_t id;
556 };
557 
558 
567 int
568 GNUNET_DNSPARSER_check_label (const char *label);
569 
570 
580 int
581 GNUNET_DNSPARSER_check_name (const char *name);
582 
583 
593 GNUNET_DNSPARSER_parse (const char *udp_payload,
594  size_t udp_payload_length);
595 
596 
602 void
604 
605 
620 int
622  uint16_t max,
623  char **buf,
624  size_t *buf_length);
625 
626 /* ***************** low-level packing API ******************** */
627 
641 int
643  size_t dst_len,
644  size_t *off,
645  const char *name);
646 
647 
660 int
662  size_t dst_len,
663  size_t *off,
664  const struct GNUNET_DNSPARSER_Query *query);
665 
666 
679 int
681  size_t dst_len,
682  size_t *off,
683  const struct GNUNET_DNSPARSER_MxRecord *mx);
684 
685 
698 int
700  size_t dst_len,
701  size_t *off,
702  const struct GNUNET_DNSPARSER_SoaRecord *soa);
703 
704 
717 int
719  size_t dst_len,
720  size_t *off,
721  const struct
723 
724 
737 int
739  size_t dst_len,
740  size_t *off,
741  const struct GNUNET_DNSPARSER_SrvRecord *srv);
742 
743 /* ***************** low-level parsing API ******************** */
744 
755 int
756 GNUNET_DNSPARSER_parse_record (const char *udp_payload,
757  size_t udp_payload_length,
758  size_t *off,
759  struct GNUNET_DNSPARSER_Record *r);
760 
761 
771 char *
772 GNUNET_DNSPARSER_parse_name (const char *udp_payload,
773  size_t udp_payload_length,
774  size_t *off);
775 
776 
787 int
788 GNUNET_DNSPARSER_parse_query (const char *udp_payload,
789  size_t udp_payload_length,
790  size_t *off,
791  struct GNUNET_DNSPARSER_Query *q);
792 
793 
804 GNUNET_DNSPARSER_parse_soa (const char *udp_payload,
805  size_t udp_payload_length,
806  size_t *off);
807 
808 
819 GNUNET_DNSPARSER_parse_cert (const char *udp_payload,
820  size_t udp_payload_length,
821  size_t *off);
822 
823 
834 GNUNET_DNSPARSER_parse_mx (const char *udp_payload,
835  size_t udp_payload_length,
836  size_t *off);
837 
838 
849 GNUNET_DNSPARSER_parse_srv (const char *udp_payload,
850  size_t udp_payload_length,
851  size_t *off);
852 
853 /* ***************** low-level duplication API ******************** */
854 
863 
864 
874 
875 
885 
886 
896 
897 
907 
908 
909 /* ***************** low-level deallocation API ******************** */
910 
916 void
918 
919 
925 void
927 
928 
934 void
936 
937 
943 void
945 
946 
952 void
954 
955 
963 char *
964 GNUNET_DNSPARSER_bin_to_hex (const void *data,
965  size_t data_size);
966 
967 
976 size_t
977 GNUNET_DNSPARSER_hex_to_bin (const char *hex,
978  void *data);
979 
980 
981 #endif
982  /* end of group */
984  /* end of group addition */
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
uint32_t data
The data value.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
static char buf[2048]
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:37
GNUNET_DNSPARSER_CertAlgorithm
DNSCERT algorithms as defined in http://www.iana.org/assignments/ dns-sec-alg-numbers/dns-sec-alg-num...
int GNUNET_DNSPARSER_builder_add_name(char *dst, size_t dst_len, size_t *off, const char *name)
Add a DNS name to the UDP packet at the given location, converting the name to IDNA notation as neces...
Definition: dnsparser.c:889
int GNUNET_DNSPARSER_builder_add_cert(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_CertRecord *cert)
Add CERT record to the UDP packet at the given location.
Definition: dnsparser.c:1030
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
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
Definition: dnsparser.c:854
int GNUNET_DNSPARSER_builder_add_query(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_Query *query)
Add a DNS query to the UDP packet at the given location.
Definition: dnsparser.c:964
GNUNET_DNSPARSER_CertType
DNS CERT types as defined in RFC 4398.
struct GNUNET_DNSPARSER_SrvRecord * GNUNET_DNSPARSER_duplicate_srv_record(const struct GNUNET_DNSPARSER_SrvRecord *r)
Duplicate (deep-copy) the given DNS record.
Definition: dnsparser.c:838
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
void GNUNET_DNSPARSER_free_record(struct GNUNET_DNSPARSER_Record *r)
Free the given DNS record.
Definition: dnsparser.c:169
void GNUNET_DNSPARSER_free_cert(struct GNUNET_DNSPARSER_CertRecord *cert)
Free CERT information record.
Definition: dnsparser.c:124
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
void GNUNET_DNSPARSER_free_srv(struct GNUNET_DNSPARSER_SrvRecord *srv)
Free SRV information record.
Definition: dnsparser.c:139
struct GNUNET_DNSPARSER_Packet * GNUNET_DNSPARSER_parse(const char *udp_payload, size_t udp_payload_length)
Parse a UDP payload of a DNS packet in to a nice struct for further processing and manipulation.
Definition: dnsparser.c:656
int GNUNET_DNSPARSER_check_name(const char *name)
Check if a hostname in UTF-8 format can be coded into valid IDNA.
Definition: dnsparser.c:79
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
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
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
void GNUNET_DNSPARSER_free_soa(struct GNUNET_DNSPARSER_SoaRecord *soa)
Free SOA information record.
Definition: dnsparser.c:108
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
struct GNUNET_DNSPARSER_SrvRecord * GNUNET_DNSPARSER_parse_srv(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS SRV record.
Definition: dnsparser.c:477
void GNUNET_DNSPARSER_free_mx(struct GNUNET_DNSPARSER_MxRecord *mx)
Free MX information record.
Definition: dnsparser.c:154
struct GNUNET_DNSPARSER_CertRecord * GNUNET_DNSPARSER_parse_cert(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS CERT record.
Definition: dnsparser.c:518
struct GNUNET_DNSPARSER_MxRecord * GNUNET_DNSPARSER_duplicate_mx_record(const struct GNUNET_DNSPARSER_MxRecord *r)
Duplicate (deep-copy) the given DNS record.
Definition: dnsparser.c:822
int GNUNET_DNSPARSER_parse_query(const char *udp_payload, size_t udp_payload_length, size_t *off, struct GNUNET_DNSPARSER_Query *q)
Parse a DNS query entry.
Definition: dnsparser.c:353
int GNUNET_DNSPARSER_pack(const struct GNUNET_DNSPARSER_Packet *p, uint16_t max, char **buf, size_t *buf_length)
Given a DNS packet p, generate the corresponding UDP payload.
Definition: dnsparser.c:1257
int GNUNET_DNSPARSER_parse_record(const char *udp_payload, size_t udp_payload_length, size_t *off, struct GNUNET_DNSPARSER_Record *r)
Parse a DNS record entry.
Definition: dnsparser.c:559
int GNUNET_DNSPARSER_check_label(const char *label)
Check if a label in UTF-8 format can be coded into valid IDNA.
Definition: dnsparser.c:53
struct GNUNET_DNSPARSER_SoaRecord * GNUNET_DNSPARSER_duplicate_soa_record(const struct GNUNET_DNSPARSER_SoaRecord *r)
Duplicate (deep-copy) the given DNS record.
Definition: dnsparser.c:787
struct GNUNET_DNSPARSER_Record * GNUNET_DNSPARSER_duplicate_record(const struct GNUNET_DNSPARSER_Record *r)
Duplicate (deep-copy) the given DNS record.
Definition: dnsparser.c:737
struct GNUNET_DNSPARSER_CertRecord * GNUNET_DNSPARSER_duplicate_cert_record(const struct GNUNET_DNSPARSER_CertRecord *r)
Duplicate (deep-copy) the given DNS record.
Definition: dnsparser.c:805
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
@ GNUNET_DNSPARSER_CERTALGO_RSAMD5
RSA/MD5.
@ GNUNET_DNSPARSER_CERTALGO_RSASHA
RSA/SHA1.
@ GNUNET_DNSPARSER_CERTALGO_RSRVD9
Reserved.
@ GNUNET_DNSPARSER_CERTALGO_GOST_R34
GHOST R 34.10-2001.
@ GNUNET_DNSPARSER_CERTALGO_RSASHA256
RSA/SHA256.
@ GNUNET_DNSPARSER_CERTALGO_RSRVD4
Reserved.
@ GNUNET_DNSPARSER_CERTALGO_DSANSEC3
DSA/NSEC3/SHA.
@ GNUNET_DNSPARSER_CERTALGO_ECDSA_P256SHA256
ECDSA Curve P-256/SHA256.
@ GNUNET_DNSPARSER_CERTALGO_RSASHA512
RSA/SHA512.
@ GNUNET_DNSPARSER_CERTALGO_DH
Diffie-Hellman.
@ GNUNET_DNSPARSER_CERTALGO_ECDSA_P384SHA384
ECDSA Curve P-384/SHA384.
@ GNUNET_DNSPARSER_CERTALGO_RSANSEC3
RSA/NSEC3/SHA.
@ GNUNET_DNSPARSER_CERTALGO_DSASHA
DSA/SHA1.
@ GNUNET_DNSPARSER_CERTALGO_UNDEFINED
No defined.
@ GNUNET_DNSPARSER_CERTTYPE_SKPI
A SKPI certificate.
@ GNUNET_DNSPARSER_CERTTYPE_ISKPI
A SKPI cert URL.
@ GNUNET_DNSPARSER_CERTTYPE_IPGP
A PGP cert fingerprint and URL.
@ GNUNET_DNSPARSER_CERTTYPE_IACKPIX
An attribute cert URL.
@ GNUNET_DNSPARSER_CERTTYPE_PGP
A PGP certificate.
@ GNUNET_DNSPARSER_CERTTYPE_ACPKIX
An attribute Certificate.
@ GNUNET_DNSPARSER_CERTTYPE_RESERVED
Reserved value.
@ GNUNET_DNSPARSER_CERTTYPE_PKIX
An x509 PKIX certificate.
@ GNUNET_DNSPARSER_CERTTYPE_IPKIX
An x509 PKIX cert URL.
#define max(x, y)
const char * name
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).
Easy-to-process, parsed version of a DNS packet.
struct GNUNET_DNSPARSER_Query * queries
Array of all queries in the packet, must contain "num_queries" entries.
unsigned int num_answers
Number of answers in the packet, should be 0 for queries.
struct GNUNET_TUN_DnsFlags flags
Bitfield of DNS flags.
struct GNUNET_DNSPARSER_Record * answers
Array of all answers in the packet, must contain "num_answers" entries.
unsigned int num_additional_records
Number of additional records in the packet, should be 0 for queries.
struct GNUNET_DNSPARSER_Record * additional_records
Array of all additional answers in the packet, must contain "num_additional_records" entries.
struct GNUNET_DNSPARSER_Record * authority_records
Array of all authority records in the packet, must contain "num_authority_records" entries.
unsigned int num_authority_records
Number of authoritative answers in the packet, should be 0 for queries.
unsigned int num_queries
Number of queries in the packet.
uint16_t id
DNS ID (to match replies to requests).
uint16_t dns_traffic_class
See GNUNET_TUN_DNS_CLASS_*.
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
char * name
Name of the record that the query is for (0-terminated).
Binary record information (unparsed).
void * data
Binary record data.
size_t data_len
Number of bytes in data.
A DNS response record.
uint16_t dns_traffic_class
See GNUNET_TUN_DNS_CLASS_*.
struct GNUNET_DNSPARSER_SoaRecord * soa
SOA data for SOA records.
struct GNUNET_DNSPARSER_SrvRecord * srv
SRV data for SRV records.
struct GNUNET_DNSPARSER_MxRecord * mx
MX data for MX records.
char * hostname
For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname.
struct GNUNET_DNSPARSER_CertRecord * cert
CERT data for CERT records.
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
struct GNUNET_TIME_Absolute expiration_time
When does the record expire?
union GNUNET_DNSPARSER_Record::@24 data
Payload of the record (which one of these is valid depends on the 'type').
char * name
Name of the record that the query is for (0-terminated).
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
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.
Time for absolute times used by GNUnet, in microseconds.
DNS flags (largely RFC 1035 / RFC 2136).