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 
103  char *name;
104 
108  uint16_t type;
109 
114 };
115 
116 
124  uint16_t preference;
125 
133  char *mxhost;
134 };
135 
136 
148  char *target;
149 
155  uint16_t priority;
156 
162  uint16_t weight;
163 
167  uint16_t port;
168 };
169 
170 
179 
184 
189 
194 
199 
204 
209 
214 
219 };
220 
221 
231 
236 
241 
246 
251 
256 
261 
266 
271 
276 
281 
286 
291 
296 };
297 
298 
307 
311  uint16_t cert_tag;
312 
317 
322 
327 };
328 
329 
342  char *mname;
343 
352  char *rname;
353 
357  uint32_t serial;
358 
362  uint32_t refresh;
363 
368  uint32_t retry;
369 
374  uint32_t expire;
375 
380  uint32_t minimum_ttl;
381 };
382 
383 
393  uint8_t flags;
394 
398  uint8_t tag_len;
399 };
400 
401 
402 
410  void *data;
411 
415  size_t data_len;
416 };
417 
418 
430  char *name;
431 
435  union {
443  char *hostname;
444 
449 
454 
459 
464 
469  } data;
470 
471 
475  struct GNUNET_TIME_Absolute expiration_time;
476 
480  uint16_t type;
481 
486 };
487 
488 
497 
502 
507 
512 
516  unsigned int num_queries;
517 
521  unsigned int num_answers;
522 
526  unsigned int num_authority_records;
527 
532 
536  struct GNUNET_TUN_DnsFlags flags;
537 
541  uint16_t id;
542 };
543 
544 
553 int
554 GNUNET_DNSPARSER_check_label(const char *label);
555 
556 
566 int
567 GNUNET_DNSPARSER_check_name(const char *name);
568 
569 
579 GNUNET_DNSPARSER_parse(const char *udp_payload,
580  size_t udp_payload_length);
581 
582 
588 void
590 
591 
606 int
608  uint16_t max,
609  char **buf,
610  size_t *buf_length);
611 
612 /* ***************** low-level packing API ******************** */
613 
627 int
629  size_t dst_len,
630  size_t *off,
631  const char *name);
632 
633 
646 int
648  size_t dst_len,
649  size_t *off,
650  const struct GNUNET_DNSPARSER_Query *query);
651 
652 
665 int
667  size_t dst_len,
668  size_t *off,
669  const struct GNUNET_DNSPARSER_MxRecord *mx);
670 
671 
684 int
686  size_t dst_len,
687  size_t *off,
688  const struct GNUNET_DNSPARSER_SoaRecord *soa);
689 
690 
703 int
705  size_t dst_len,
706  size_t *off,
707  const struct GNUNET_DNSPARSER_CertRecord *cert);
708 
709 
722 int
724  size_t dst_len,
725  size_t *off,
726  const struct GNUNET_DNSPARSER_SrvRecord *srv);
727 
728 /* ***************** low-level parsing API ******************** */
729 
740 int
741 GNUNET_DNSPARSER_parse_record(const char *udp_payload,
742  size_t udp_payload_length,
743  size_t *off,
744  struct GNUNET_DNSPARSER_Record *r);
745 
746 
756 char *
757 GNUNET_DNSPARSER_parse_name(const char *udp_payload,
758  size_t udp_payload_length,
759  size_t *off);
760 
761 
772 int
773 GNUNET_DNSPARSER_parse_query(const char *udp_payload,
774  size_t udp_payload_length,
775  size_t *off,
776  struct GNUNET_DNSPARSER_Query *q);
777 
778 
789 GNUNET_DNSPARSER_parse_soa(const char *udp_payload,
790  size_t udp_payload_length,
791  size_t *off);
792 
793 
804 GNUNET_DNSPARSER_parse_cert(const char *udp_payload,
805  size_t udp_payload_length,
806  size_t *off);
807 
808 
819 GNUNET_DNSPARSER_parse_mx(const char *udp_payload,
820  size_t udp_payload_length,
821  size_t *off);
822 
823 
834 GNUNET_DNSPARSER_parse_srv(const char *udp_payload,
835  size_t udp_payload_length,
836  size_t *off);
837 
838 /* ***************** low-level duplication API ******************** */
839 
848 
849 
858 
859 
868 
869 
878 
879 
888 
889 
890 /* ***************** low-level deallocation API ******************** */
891 
897 void
899 
900 
906 void
908 
909 
915 void
917 
918 
924 void
926 
927 
933 void
935 
936 
944 char *
946  size_t data_size);
947 
948 
957 size_t
958 GNUNET_DNSPARSER_hex_to_bin(const char *hex,
959  void *data);
960 
961 
962 #endif
963  /* 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.
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:1256
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:1117
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:786
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
Definition: dnsparser.c:853
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:804
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:1376
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:837
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:1076
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:821
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:1029
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:1000
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:963
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:888
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: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:1353
Information from SRV records (RFC 2782).
uint8_t tag_len
The length of the tag.