GNUnet  0.19.5
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 
21 #if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22 #error "Only <gnunet_util_lib.h> can be included directly."
23 #endif
24 
25 
40 #ifndef GNUNET_DNSPARSER_LIB_H
41 #define GNUNET_DNSPARSER_LIB_H
42 
46 #define GNUNET_DNSPARSER_MAX_LABEL_LENGTH 63
47 
51 #define GNUNET_DNSPARSER_MAX_NAME_LENGTH 253
52 
53 
57 #define GNUNET_DNSPARSER_TYPE_ANY 0
58 #define GNUNET_DNSPARSER_TYPE_A 1
59 #define GNUNET_DNSPARSER_TYPE_NS 2
60 #define GNUNET_DNSPARSER_TYPE_CNAME 5
61 #define GNUNET_DNSPARSER_TYPE_SOA 6
62 #define GNUNET_DNSPARSER_TYPE_PTR 12
63 #define GNUNET_DNSPARSER_TYPE_MX 15
64 #define GNUNET_DNSPARSER_TYPE_TXT 16
65 #define GNUNET_DNSPARSER_TYPE_RP 17
66 #define GNUNET_DNSPARSER_TYPE_AFSDB 18
67 #define GNUNET_DNSPARSER_TYPE_SIG 24
68 #define GNUNET_DNSPARSER_TYPE_KEY 25
69 #define GNUNET_DNSPARSER_TYPE_AAAA 28
70 #define GNUNET_DNSPARSER_TYPE_LOC 29
71 #define GNUNET_DNSPARSER_TYPE_SRV 33
72 #define GNUNET_DNSPARSER_TYPE_NAPTR 35
73 #define GNUNET_DNSPARSER_TYPE_KX 36
74 #define GNUNET_DNSPARSER_TYPE_CERT 37
75 #define GNUNET_DNSPARSER_TYPE_DNAME 39
76 #define GNUNET_DNSPARSER_TYPE_APL 42
77 #define GNUNET_DNSPARSER_TYPE_DS 43
78 #define GNUNET_DNSPARSER_TYPE_SSHFP 44
79 #define GNUNET_DNSPARSER_TYPE_IPSECKEY 45
80 #define GNUNET_DNSPARSER_TYPE_RRSIG 46
81 #define GNUNET_DNSPARSER_TYPE_NSEC 47
82 #define GNUNET_DNSPARSER_TYPE_DNSKEY 48
83 #define GNUNET_DNSPARSER_TYPE_DHCID 49
84 #define GNUNET_DNSPARSER_TYPE_NSEC3 50
85 #define GNUNET_DNSPARSER_TYPE_NSEC3PARAM 51
86 #define GNUNET_DNSPARSER_TYPE_TLSA 52
87 #define GNUNET_DNSPARSER_TYPE_HIP 55
88 #define GNUNET_DNSPARSER_TYPE_CDS 59
89 #define GNUNET_DNSPARSER_TYPE_CDNSKEY 60
90 #define GNUNET_DNSPARSER_TYPE_OPENPGPKEY 61
91 #define GNUNET_DNSPARSER_TYPE_TKEY 249
92 #define GNUNET_DNSPARSER_TYPE_TSIG 250
93 #define GNUNET_DNSPARSER_TYPE_ALL 255
94 #define GNUNET_DNSPARSER_TYPE_URI 256
95 #define GNUNET_DNSPARSER_TYPE_CAA 257
96 #define GNUNET_DNSPARSER_TYPE_TA 32768
97 
102 {
110  char *name;
111 
115  uint16_t type;
116 
121 };
122 
123 
128 {
132  uint16_t preference;
133 
141  char *mxhost;
142 };
143 
144 
149 {
157  char *target;
158 
164  uint16_t priority;
165 
171  uint16_t weight;
172 
176  uint16_t port;
177 };
178 
179 
184 {
189 
194 
199 
204 
209 
214 
219 
224 
229 };
230 
231 
237 {
242 
247 
252 
257 
262 
267 
272 
277 
282 
287 
292 
297 
302 
307 };
308 
309 
314 {
319 
323  uint16_t cert_tag;
324 
329 
334 
339 };
340 
341 
346 {
355  char *mname;
356 
365  char *rname;
366 
370  uint32_t serial;
371 
375  uint32_t refresh;
376 
381  uint32_t retry;
382 
387  uint32_t expire;
388 
393  uint32_t minimum_ttl;
394 };
395 
396 
403 {
407  uint8_t flags;
408 
412  uint8_t tag_len;
413 };
414 
415 
420 {
424  void *data;
425 
429  size_t data_len;
430 };
431 
432 
437 {
445  char *name;
446 
450  union
451  {
459  char *hostname;
460 
465 
470 
475 
480 
485  } data;
486 
487 
492 
496  uint16_t type;
497 
502 };
503 
504 
509 {
514 
519 
524 
529 
533  unsigned int num_queries;
534 
538  unsigned int num_answers;
539 
543  unsigned int num_authority_records;
544 
549 
553  struct GNUNET_TUN_DnsFlags flags;
554 
558  uint16_t id;
559 };
560 
561 
570 int
571 GNUNET_DNSPARSER_check_label (const char *label);
572 
573 
583 int
584 GNUNET_DNSPARSER_check_name (const char *name);
585 
586 
596 GNUNET_DNSPARSER_parse (const char *udp_payload,
597  size_t udp_payload_length);
598 
599 
605 void
607 
608 
623 int
625  uint16_t max,
626  char **buf,
627  size_t *buf_length);
628 
629 /* ***************** low-level packing API ******************** */
630 
644 int
646  size_t dst_len,
647  size_t *off,
648  const char *name);
649 
650 
663 int
665  size_t dst_len,
666  size_t *off,
667  const struct GNUNET_DNSPARSER_Query *query);
668 
669 
682 int
684  size_t dst_len,
685  size_t *off,
686  const struct GNUNET_DNSPARSER_MxRecord *mx);
687 
688 
701 int
703  size_t dst_len,
704  size_t *off,
705  const struct GNUNET_DNSPARSER_SoaRecord *soa);
706 
707 
720 int
722  size_t dst_len,
723  size_t *off,
724  const struct
726 
727 
740 int
742  size_t dst_len,
743  size_t *off,
744  const struct GNUNET_DNSPARSER_SrvRecord *srv);
745 
746 /* ***************** low-level parsing API ******************** */
747 
758 int
759 GNUNET_DNSPARSER_parse_record (const char *udp_payload,
760  size_t udp_payload_length,
761  size_t *off,
762  struct GNUNET_DNSPARSER_Record *r);
763 
764 
774 char *
775 GNUNET_DNSPARSER_parse_name (const char *udp_payload,
776  size_t udp_payload_length,
777  size_t *off);
778 
779 
790 int
791 GNUNET_DNSPARSER_parse_query (const char *udp_payload,
792  size_t udp_payload_length,
793  size_t *off,
794  struct GNUNET_DNSPARSER_Query *q);
795 
796 
807 GNUNET_DNSPARSER_parse_soa (const char *udp_payload,
808  size_t udp_payload_length,
809  size_t *off);
810 
811 
822 GNUNET_DNSPARSER_parse_cert (const char *udp_payload,
823  size_t udp_payload_length,
824  size_t *off);
825 
826 
837 GNUNET_DNSPARSER_parse_mx (const char *udp_payload,
838  size_t udp_payload_length,
839  size_t *off);
840 
841 
852 GNUNET_DNSPARSER_parse_srv (const char *udp_payload,
853  size_t udp_payload_length,
854  size_t *off);
855 
856 /* ***************** low-level duplication API ******************** */
857 
866 
867 
877 
878 
888 
889 
899 
900 
910 
911 
912 /* ***************** low-level deallocation API ******************** */
913 
919 void
921 
922 
928 void
930 
931 
937 void
939 
940 
946 void
948 
949 
955 void
957 
958 
966 char *
967 GNUNET_DNSPARSER_bin_to_hex (const void *data,
968  size_t data_size);
969 
970 
979 size_t
980 GNUNET_DNSPARSER_hex_to_bin (const char *hex,
981  void *data);
982 
983 
984 #endif
985  /* end of group */
987  /* 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:38
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:1032
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:966
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:1356
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:1379
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:1079
int GNUNET_DNSPARSER_builder_add_mx(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_MxRecord *mx)
Add an MX record to the UDP packet at the given location.
Definition: dnsparser.c:1003
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:1120
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:1259
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).