GNUnet  0.11.x
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 
32 #ifndef GNUNET_DNSPARSER_LIB_H
33 #define GNUNET_DNSPARSER_LIB_H
34 
35 #include "gnunet_util_lib.h"
36 
40 #define GNUNET_DNSPARSER_MAX_LABEL_LENGTH 63
41 
45 #define GNUNET_DNSPARSER_MAX_NAME_LENGTH 253
46 
47 
51 #define GNUNET_DNSPARSER_TYPE_ANY 0
52 #define GNUNET_DNSPARSER_TYPE_A 1
53 #define GNUNET_DNSPARSER_TYPE_NS 2
54 #define GNUNET_DNSPARSER_TYPE_CNAME 5
55 #define GNUNET_DNSPARSER_TYPE_SOA 6
56 #define GNUNET_DNSPARSER_TYPE_PTR 12
57 #define GNUNET_DNSPARSER_TYPE_MX 15
58 #define GNUNET_DNSPARSER_TYPE_TXT 16
59 #define GNUNET_DNSPARSER_TYPE_RP 17
60 #define GNUNET_DNSPARSER_TYPE_AFSDB 18
61 #define GNUNET_DNSPARSER_TYPE_SIG 24
62 #define GNUNET_DNSPARSER_TYPE_KEY 25
63 #define GNUNET_DNSPARSER_TYPE_AAAA 28
64 #define GNUNET_DNSPARSER_TYPE_LOC 29
65 #define GNUNET_DNSPARSER_TYPE_SRV 33
66 #define GNUNET_DNSPARSER_TYPE_NAPTR 35
67 #define GNUNET_DNSPARSER_TYPE_KX 36
68 #define GNUNET_DNSPARSER_TYPE_CERT 37
69 #define GNUNET_DNSPARSER_TYPE_DNAME 39
70 #define GNUNET_DNSPARSER_TYPE_APL 42
71 #define GNUNET_DNSPARSER_TYPE_DS 43
72 #define GNUNET_DNSPARSER_TYPE_SSHFP 44
73 #define GNUNET_DNSPARSER_TYPE_IPSECKEY 45
74 #define GNUNET_DNSPARSER_TYPE_RRSIG 46
75 #define GNUNET_DNSPARSER_TYPE_NSEC 47
76 #define GNUNET_DNSPARSER_TYPE_DNSKEY 48
77 #define GNUNET_DNSPARSER_TYPE_DHCID 49
78 #define GNUNET_DNSPARSER_TYPE_NSEC3 50
79 #define GNUNET_DNSPARSER_TYPE_NSEC3PARAM 51
80 #define GNUNET_DNSPARSER_TYPE_TLSA 52
81 #define GNUNET_DNSPARSER_TYPE_HIP 55
82 #define GNUNET_DNSPARSER_TYPE_CDS 59
83 #define GNUNET_DNSPARSER_TYPE_CDNSKEY 60
84 #define GNUNET_DNSPARSER_TYPE_OPENPGPKEY 61
85 #define GNUNET_DNSPARSER_TYPE_TKEY 249
86 #define GNUNET_DNSPARSER_TYPE_TSIG 250
87 #define GNUNET_DNSPARSER_TYPE_ALL 255
88 #define GNUNET_DNSPARSER_TYPE_URI 256
89 #define GNUNET_DNSPARSER_TYPE_CAA 257
90 #define GNUNET_DNSPARSER_TYPE_TA 32768
91 
96 {
104  char *name;
105 
109  uint16_t type;
110 
115 };
116 
117 
122 {
126  uint16_t preference;
127 
135  char *mxhost;
136 };
137 
138 
143 {
151  char *target;
152 
158  uint16_t priority;
159 
165  uint16_t weight;
166 
170  uint16_t port;
171 };
172 
173 
178 {
183 
188 
193 
198 
203 
208 
213 
218 
223 };
224 
225 
231 {
236 
241 
246 
251 
256 
261 
266 
271 
276 
281 
286 
291 
296 
301 };
302 
303 
308 {
313 
317  uint16_t cert_tag;
318 
323 
328 
333 };
334 
335 
340 {
349  char *mname;
350 
359  char *rname;
360 
364  uint32_t serial;
365 
369  uint32_t refresh;
370 
375  uint32_t retry;
376 
381  uint32_t expire;
382 
387  uint32_t minimum_ttl;
388 };
389 
390 
397 {
401  uint8_t flags;
402 
406  uint8_t tag_len;
407 };
408 
409 
414 {
418  void *data;
419 
423  size_t data_len;
424 };
425 
426 
431 {
439  char *name;
440 
444  union
445  {
453  char *hostname;
454 
459 
464 
469 
474 
479  } data;
480 
481 
485  struct GNUNET_TIME_Absolute expiration_time;
486 
490  uint16_t type;
491 
496 };
497 
498 
503 {
508 
513 
518 
523 
527  unsigned int num_queries;
528 
532  unsigned int num_answers;
533 
537  unsigned int num_authority_records;
538 
543 
547  struct GNUNET_TUN_DnsFlags flags;
548 
552  uint16_t id;
553 };
554 
555 
564 int
565 GNUNET_DNSPARSER_check_label (const char *label);
566 
567 
577 int
578 GNUNET_DNSPARSER_check_name (const char *name);
579 
580 
590 GNUNET_DNSPARSER_parse (const char *udp_payload,
591  size_t udp_payload_length);
592 
593 
599 void
601 
602 
617 int
619  uint16_t max,
620  char **buf,
621  size_t *buf_length);
622 
623 /* ***************** low-level packing API ******************** */
624 
638 int
640  size_t dst_len,
641  size_t *off,
642  const char *name);
643 
644 
657 int
659  size_t dst_len,
660  size_t *off,
661  const struct GNUNET_DNSPARSER_Query *query);
662 
663 
676 int
678  size_t dst_len,
679  size_t *off,
680  const struct GNUNET_DNSPARSER_MxRecord *mx);
681 
682 
695 int
697  size_t dst_len,
698  size_t *off,
699  const struct GNUNET_DNSPARSER_SoaRecord *soa);
700 
701 
714 int
716  size_t dst_len,
717  size_t *off,
718  const struct
720 
721 
734 int
736  size_t dst_len,
737  size_t *off,
738  const struct GNUNET_DNSPARSER_SrvRecord *srv);
739 
740 /* ***************** low-level parsing API ******************** */
741 
752 int
753 GNUNET_DNSPARSER_parse_record (const char *udp_payload,
754  size_t udp_payload_length,
755  size_t *off,
756  struct GNUNET_DNSPARSER_Record *r);
757 
758 
768 char *
769 GNUNET_DNSPARSER_parse_name (const char *udp_payload,
770  size_t udp_payload_length,
771  size_t *off);
772 
773 
784 int
785 GNUNET_DNSPARSER_parse_query (const char *udp_payload,
786  size_t udp_payload_length,
787  size_t *off,
788  struct GNUNET_DNSPARSER_Query *q);
789 
790 
801 GNUNET_DNSPARSER_parse_soa (const char *udp_payload,
802  size_t udp_payload_length,
803  size_t *off);
804 
805 
816 GNUNET_DNSPARSER_parse_cert (const char *udp_payload,
817  size_t udp_payload_length,
818  size_t *off);
819 
820 
831 GNUNET_DNSPARSER_parse_mx (const char *udp_payload,
832  size_t udp_payload_length,
833  size_t *off);
834 
835 
846 GNUNET_DNSPARSER_parse_srv (const char *udp_payload,
847  size_t udp_payload_length,
848  size_t *off);
849 
850 /* ***************** low-level duplication API ******************** */
851 
860 
861 
871 
872 
882 
883 
893 
894 
904 
905 
906 /* ***************** low-level deallocation API ******************** */
907 
913 void
915 
916 
922 void
924 
925 
931 void
933 
934 
940 void
942 
943 
949 void
951 
952 
960 char *
961 GNUNET_DNSPARSER_bin_to_hex (const void *data,
962  size_t data_size);
963 
964 
973 size_t
974 GNUNET_DNSPARSER_hex_to_bin (const char *hex,
975  void *data);
976 
977 
978 #endif
979  /* end of group */
void GNUNET_DNSPARSER_free_soa(struct GNUNET_DNSPARSER_SoaRecord *soa)
Free SOA information record.
Definition: dnsparser.c:108
struct GNUNET_DNSPARSER_Record * answers
Array of all answers in the packet, must contain "num_answers" entries.
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
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
Information from SOA records (RFC 1035).
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
uint32_t retry
Time interval that should elapse before a failed refresh should be retried.
A PGP cert fingerprint and URL.
DNS flags (largely RFC 1035 / RFC 2136).
char * GNUNET_DNSPARSER_parse_name(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse name inside of a DNS query or record.
Definition: dnsparser.c:334
uint32_t refresh
Time interval before the zone should be refreshed.
Information from CAA records (RFC 6844).
static int raw
raw output
Definition: gnunet-gns.c:55
char * mname
The domainname of the name server that was the original or primary source of data for this zone...
void GNUNET_DNSPARSER_free_srv(struct GNUNET_DNSPARSER_SrvRecord *srv)
Free SRV information record.
Definition: dnsparser.c:139
char * mxhost
Name of the mail server.
struct GNUNET_DNSPARSER_SrvRecord * srv
SRV data for SRV records.
uint16_t cert_tag
Certificate KeyTag.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
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_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
void GNUNET_DNSPARSER_free_record(struct GNUNET_DNSPARSER_Record *r)
Free the given DNS record.
Definition: dnsparser.c:169
Information from CERT records (RFC 4034).
int GNUNET_DNSPARSER_builder_add_srv(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_SrvRecord *srv)
Add an SRV record to the UDP packet at the given location.
Definition: dnsparser.c:1118
uint16_t id
DNS ID (to match replies to requests).
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
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
Definition: dnsparser.c:854
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
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
GNUNET_DNSPARSER_CertAlgorithm
DNSCERT algorithms as defined in http://www.iana.org/assignments/ dns-sec-alg-numbers/dns-sec-alg-num...
struct GNUNET_DNSPARSER_Record * additional_records
Array of all additional answers in the packet, must contain "num_additional_records" entries...
Binary record information (unparsed).
Information from MX records (RFC 1035).
unsigned int num_answers
Number of answers in the packet, should be 0 for queries.
GNUNET_DNSPARSER_CertType
DNS CERT types as defined in RFC 4398.
uint32_t serial
The version number of the original copy of the zone.
uint16_t dns_traffic_class
See GNUNET_TUN_DNS_CLASS_*.
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
uint32_t minimum_ttl
The bit minimum TTL field that should be exported with any RR from this zone.
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
uint8_t flags
The flags of the CAA record.
char * name
Name of the record that the query is for (0-terminated).
char * hostname
For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
struct GNUNET_DNSPARSER_SoaRecord * soa
SOA data for SOA records.
unsigned int num_additional_records
Number of additional records in the packet, should be 0 for queries.
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
uint16_t port
TCP or UDP port of the service.
char * target
Hostname offering the service.
struct GNUNET_DNSPARSER_CertRecord * GNUNET_DNSPARSER_parse_cert(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS CERT record.
Definition: dnsparser.c:518
char * rname
A domainname which specifies the mailbox of the person responsible for this zone. ...
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
static char buf[2048]
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
A DNS response record.
struct GNUNET_DNSPARSER_Record * authority_records
Array of all authority records in the packet, must contain "num_authority_records" entries...
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
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
uint32_t expire
Time value that specifies the upper limit on the time interval that can elapse before the zone is no ...
struct GNUNET_DNSPARSER_Query * queries
Array of all queries in the packet, must contain "num_queries" entries.
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
An x509 PKIX certificate.
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
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
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
size_t data_len
Number of bytes in data.
void * data
Binary record data.
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
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
unsigned int num_authority_records
Number of authoritative answers in the packet, should be 0 for queries.
size_t certificate_size
Number of bytes in certificate_data.
struct GNUNET_DNSPARSER_MxRecord * mx
MX data for MX records.
void GNUNET_DNSPARSER_free_cert(struct GNUNET_DNSPARSER_CertRecord *cert)
Free CERT information record.
Definition: dnsparser.c:124
Easy-to-process, parsed version of a DNS packet.
uint16_t dns_traffic_class
See GNUNET_TUN_DNS_CLASS_*.
uint16_t priority
Preference for this entry (lower value is higher preference).
char * name
Name of the record that the query is for (0-terminated).
unsigned int num_queries
Number of queries in the packet.
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
Time for absolute times used by GNUnet, in microseconds.
uint16_t weight
Relative weight for records with the same priority.
char * certificate_data
Data of the certificate.
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
uint32_t data
The data value.
uint16_t preference
Preference for this entry (lower value is higher preference).
void GNUNET_DNSPARSER_free_mx(struct GNUNET_DNSPARSER_MxRecord *mx)
Free MX information record.
Definition: dnsparser.c:154
struct GNUNET_DNSPARSER_CertRecord * cert
CERT data for CERT records.
char * GNUNET_DNSPARSER_bin_to_hex(const void *data, size_t data_size)
Convert a block of binary data to HEX.
Definition: dnsparser.c:1354
Information from SRV records (RFC 2782).
uint8_t tag_len
The length of the tag.