GNUnet  0.10.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 {
97 
105  char *name;
106 
110  uint16_t type;
111 
116 
117 };
118 
119 
124 {
125 
129  uint16_t preference;
130 
138  char *mxhost;
139 
140 };
141 
142 
147 {
148 
156  char *target;
157 
163  uint16_t priority;
164 
170  uint16_t weight;
171 
175  uint16_t port;
176 
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 
310 
315 {
316 
321 
325  uint16_t cert_tag;
326 
331 
336 
341 
342 };
343 
344 
349 {
350 
359  char *mname;
360 
369  char *rname;
370 
374  uint32_t serial;
375 
379  uint32_t refresh;
380 
385  uint32_t retry;
386 
391  uint32_t expire;
392 
397  uint32_t minimum_ttl;
398 
399 };
400 
401 
408 {
412  uint8_t flags;
413 
417  uint8_t tag_len;
418 };
419 
420 
421 
426 {
427 
431  void *data;
432 
436  size_t data_len;
437 };
438 
439 
444 {
445 
453  char *name;
454 
458  union
459  {
460 
468  char *hostname;
469 
474 
479 
484 
489 
494 
495  } data;
496 
497 
501  struct GNUNET_TIME_Absolute expiration_time;
502 
506  uint16_t type;
507 
512 
513 };
514 
515 
520 {
525 
530 
535 
540 
544  unsigned int num_queries;
545 
549  unsigned int num_answers;
550 
554  unsigned int num_authority_records;
555 
560 
564  struct GNUNET_TUN_DnsFlags flags;
565 
569  uint16_t id;
570 
571 };
572 
573 
582 int
583 GNUNET_DNSPARSER_check_label (const char *label);
584 
585 
595 int
596 GNUNET_DNSPARSER_check_name (const char *name);
597 
598 
608 GNUNET_DNSPARSER_parse (const char *udp_payload,
609  size_t udp_payload_length);
610 
611 
617 void
619 
620 
635 int
637  uint16_t max,
638  char **buf,
639  size_t *buf_length);
640 
641 /* ***************** low-level packing API ******************** */
642 
656 int
658  size_t dst_len,
659  size_t *off,
660  const char *name);
661 
662 
675 int
677  size_t dst_len,
678  size_t *off,
679  const struct GNUNET_DNSPARSER_Query *query);
680 
681 
694 int
696  size_t dst_len,
697  size_t *off,
698  const struct GNUNET_DNSPARSER_MxRecord *mx);
699 
700 
713 int
715  size_t dst_len,
716  size_t *off,
717  const struct GNUNET_DNSPARSER_SoaRecord *soa);
718 
719 
732 int
734  size_t dst_len,
735  size_t *off,
736  const struct GNUNET_DNSPARSER_CertRecord *cert);
737 
738 
751 int
753  size_t dst_len,
754  size_t *off,
755  const struct GNUNET_DNSPARSER_SrvRecord *srv);
756 
757 /* ***************** low-level parsing API ******************** */
758 
769 int
770 GNUNET_DNSPARSER_parse_record (const char *udp_payload,
771  size_t udp_payload_length,
772  size_t *off,
773  struct GNUNET_DNSPARSER_Record *r);
774 
775 
785 char *
786 GNUNET_DNSPARSER_parse_name (const char *udp_payload,
787  size_t udp_payload_length,
788  size_t *off);
789 
790 
801 int
802 GNUNET_DNSPARSER_parse_query (const char *udp_payload,
803  size_t udp_payload_length,
804  size_t *off,
805  struct GNUNET_DNSPARSER_Query *q);
806 
807 
818 GNUNET_DNSPARSER_parse_soa (const char *udp_payload,
819  size_t udp_payload_length,
820  size_t *off);
821 
822 
833 GNUNET_DNSPARSER_parse_cert (const char *udp_payload,
834  size_t udp_payload_length,
835  size_t *off);
836 
837 
848 GNUNET_DNSPARSER_parse_mx (const char *udp_payload,
849  size_t udp_payload_length,
850  size_t *off);
851 
852 
863 GNUNET_DNSPARSER_parse_srv (const char *udp_payload,
864  size_t udp_payload_length,
865  size_t *off);
866 
867 /* ***************** low-level duplication API ******************** */
868 
877 
878 
887 
888 
897 
898 
907 
908 
917 
918 
919 /* ***************** low-level deallocation API ******************** */
920 
926 void
928 
929 
935 void
937 
938 
944 void
946 
947 
953 void
955 
956 
962 void
964 
965 
973 char *
974 GNUNET_DNSPARSER_bin_to_hex (const void *data,
975  size_t data_size);
976 
977 
986 size_t
987 GNUNET_DNSPARSER_hex_to_bin (const char *hex,
988  void *data);
989 
990 
991 #endif
992  /* end of group */
void GNUNET_DNSPARSER_free_soa(struct GNUNET_DNSPARSER_SoaRecord *soa)
Free SOA information record.
Definition: dnsparser.c:119
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:56
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:344
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:150
char * mxhost
Name of the mail server.
struct GNUNET_DNSPARSER_SrvRecord * srv
SRV data for SRV records.
uint16_t cert_tag
Certificate KeyTag.
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:569
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
void GNUNET_DNSPARSER_free_record(struct GNUNET_DNSPARSER_Record *r)
Free the given DNS record.
Definition: dnsparser.c:180
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:1125
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:401
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:1379
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:662
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:528
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:487
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:1084
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:743
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:446
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:1037
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:363
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:1008
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:86
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:135
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:971
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).
static size_t data_size
Number of bytes in data.
void GNUNET_DNSPARSER_free_mx(struct GNUNET_DNSPARSER_MxRecord *mx)
Free MX information record.
Definition: dnsparser.c:165
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:1356
Information from SRV records (RFC 2782).
uint8_t tag_len
The length of the tag.