GNUnet 0.21.0
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_SMIMEA 53
88#define GNUNET_DNSPARSER_TYPE_HIP 55
89#define GNUNET_DNSPARSER_TYPE_CDS 59
90#define GNUNET_DNSPARSER_TYPE_CDNSKEY 60
91#define GNUNET_DNSPARSER_TYPE_OPENPGPKEY 61
92#define GNUNET_DNSPARSER_TYPE_TKEY 249
93#define GNUNET_DNSPARSER_TYPE_TSIG 250
94#define GNUNET_DNSPARSER_TYPE_ALL 255
95#define GNUNET_DNSPARSER_TYPE_URI 256
96#define GNUNET_DNSPARSER_TYPE_CAA 257
97#define GNUNET_DNSPARSER_TYPE_TA 32768
98
103{
111 char *name;
112
116 uint16_t type;
117
122};
123
124
129{
133 uint16_t preference;
134
142 char *mxhost;
143};
144
145
150{
158 char *target;
159
165 uint16_t priority;
166
172 uint16_t weight;
173
177 uint16_t port;
178};
179
180
185{
190 char *target;
191
197 uint16_t priority;
198
204 uint16_t weight;
205};
206
207
212{
217
222
227
232
237
242
247
252
258
259
265{
270
275
280
285
290
295
300
305
310
315
320
325
330
336
337
342{
347
351 uint16_t cert_tag;
352
357
362
367};
368
369
374{
383 char *mname;
384
393 char *rname;
394
398 uint32_t serial;
399
403 uint32_t refresh;
404
409 uint32_t retry;
410
415 uint32_t expire;
416
421 uint32_t minimum_ttl;
422};
423
424
431{
435 uint8_t flags;
436
440 uint8_t tag_len;
441};
442
443
448{
452 void *data;
453
457 size_t data_len;
458};
459
460
465{
473 char *name;
474
478 union
479 {
487 char *hostname;
488
493
498
503
508
513
519
520
525
529 uint16_t type;
530
535};
536
537
542{
547
552
557
562
566 unsigned int num_queries;
567
571 unsigned int num_answers;
572
577
582
587
591 uint16_t id;
592};
593
594
603int
604GNUNET_DNSPARSER_check_label (const char *label);
605
606
616int
618
619
629GNUNET_DNSPARSER_parse (const char *udp_payload,
630 size_t udp_payload_length);
631
632
638void
640
641
656int
658 uint16_t max,
659 char **buf,
660 size_t *buf_length);
661
662/* ***************** low-level packing API ******************** */
663
677int
679 size_t dst_len,
680 size_t *off,
681 const char *name);
682
683
696int
698 size_t dst_len,
699 size_t *off,
700 const struct GNUNET_DNSPARSER_Query *query);
701
702
715int
717 size_t dst_len,
718 size_t *off,
719 const struct GNUNET_DNSPARSER_MxRecord *mx);
720
721
734int
736 size_t dst_len,
737 size_t *off,
738 const struct GNUNET_DNSPARSER_SoaRecord *soa);
739
740
753int
755 size_t dst_len,
756 size_t *off,
757 const struct
759
760
773int
775 size_t dst_len,
776 size_t *off,
777 const struct GNUNET_DNSPARSER_SrvRecord *srv);
778
779
792int
794 size_t dst_len,
795 size_t *off,
796 const struct GNUNET_DNSPARSER_UriRecord *uri);
797
798/* ***************** low-level parsing API ******************** */
799
810int
811GNUNET_DNSPARSER_parse_record (const char *udp_payload,
812 size_t udp_payload_length,
813 size_t *off,
814 struct GNUNET_DNSPARSER_Record *r);
815
816
826char *
827GNUNET_DNSPARSER_parse_name (const char *udp_payload,
828 size_t udp_payload_length,
829 size_t *off);
830
831
842int
843GNUNET_DNSPARSER_parse_query (const char *udp_payload,
844 size_t udp_payload_length,
845 size_t *off,
846 struct GNUNET_DNSPARSER_Query *q);
847
848
859GNUNET_DNSPARSER_parse_soa (const char *udp_payload,
860 size_t udp_payload_length,
861 size_t *off);
862
863
874GNUNET_DNSPARSER_parse_cert (const char *udp_payload,
875 size_t udp_payload_length,
876 size_t *off);
877
878
889GNUNET_DNSPARSER_parse_mx (const char *udp_payload,
890 size_t udp_payload_length,
891 size_t *off);
892
893
904GNUNET_DNSPARSER_parse_srv (const char *udp_payload,
905 size_t udp_payload_length,
906 size_t *off);
907
908
919GNUNET_DNSPARSER_parse_uri (const char *udp_payload,
920 size_t udp_payload_length,
921 size_t *off);
922
923/* ***************** low-level duplication API ******************** */
924
933
934
944
945
955
956
966
967
977
978
988
989/* ***************** low-level deallocation API ******************** */
990
996void
998
999
1005void
1007
1008
1014void
1016
1017
1023void
1025
1026
1032void
1034
1035
1041void
1043
1044
1052char *
1054 size_t data_size);
1055
1056
1065size_t
1066GNUNET_DNSPARSER_hex_to_bin (const char *hex,
1067 void *data);
1068
1069
1070#endif
1071 /* end of group */
1073 /* end of group addition */
static char * data
The data to insert into the dht.
static char * name
Name (label) of the records to list.
static size_t data_size
Number of bytes in data.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
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...
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:455
char * GNUNET_DNSPARSER_bin_to_hex(const void *data, size_t data_size)
Convert a block of binary data to HEX.
Definition: dnsparser.c:1489
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:982
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:1125
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
Definition: dnsparser.c:947
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:898
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:1059
GNUNET_DNSPARSER_CertType
DNS CERT types as defined in RFC 4398.
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:863
void GNUNET_DNSPARSER_free_record(struct GNUNET_DNSPARSER_Record *r)
Free the given DNS record.
Definition: dnsparser.c:184
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:1512
void GNUNET_DNSPARSER_free_srv(struct GNUNET_DNSPARSER_SrvRecord *srv)
Free SRV information record.
Definition: dnsparser.c:139
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:914
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:410
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_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:579
void GNUNET_DNSPARSER_free_uri(struct GNUNET_DNSPARSER_UriRecord *uri)
Free URI information record.
Definition: dnsparser.c:154
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:1172
struct GNUNET_DNSPARSER_UriRecord * GNUNET_DNSPARSER_parse_uri(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS URI record.
Definition: dnsparser.c:537
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:496
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:881
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:353
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:1096
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:1213
void GNUNET_DNSPARSER_free_mx(struct GNUNET_DNSPARSER_MxRecord *mx)
Free MX information record.
Definition: dnsparser.c:169
struct GNUNET_DNSPARSER_UriRecord * GNUNET_DNSPARSER_duplicate_uri_record(const struct GNUNET_DNSPARSER_UriRecord *r)
Duplicate (deep-copy) the given DNS record.
Definition: dnsparser.c:931
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:372
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:1392
int GNUNET_DNSPARSER_builder_add_uri(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_UriRecord *uri)
Add an URI record to the UDP packet at the given location.
Definition: dnsparser.c:1249
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:620
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_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:727
struct GNUNET_DNSPARSER_Record * GNUNET_DNSPARSER_duplicate_record(const struct GNUNET_DNSPARSER_Record *r)
Duplicate (deep-copy) the given DNS record.
Definition: dnsparser.c:808
@ 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)
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?
char * name
Name of the record that the query is for (0-terminated).
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
union GNUNET_DNSPARSER_Record::@20 data
Payload of the record (which one of these is valid depends on the 'type').
struct GNUNET_DNSPARSER_UriRecord * uri
URI data for URI records.
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.
Information from URI records (RFC 7553).
uint16_t priority
Preference for this entry (lower value is higher preference).
uint16_t weight
Relative weight for records with the same priority.
char * target
URI of the target, where the URI is as specified in RFC 3986.
Time for absolute times used by GNUnet, in microseconds.
DNS flags (largely RFC 1035 / RFC 2136).