aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dns/dnsparser.c123
-rw-r--r--src/include/gnunet_dnsparser_lib.h68
2 files changed, 185 insertions, 6 deletions
diff --git a/src/dns/dnsparser.c b/src/dns/dnsparser.c
index 0e658bdda..c11ec25d6 100644
--- a/src/dns/dnsparser.c
+++ b/src/dns/dnsparser.c
@@ -29,42 +29,153 @@
29#include "gnunet_dnsparser_lib.h" 29#include "gnunet_dnsparser_lib.h"
30 30
31 31
32// DNS-Stuff
33GNUNET_NETWORK_STRUCT_BEGIN 32GNUNET_NETWORK_STRUCT_BEGIN
34/* FIXME: replace this one with the one from tcpip_tun.h! */ 33
34/* FIXME: replace this one with the one from tcpip_tun.h!? */
35/**
36 * Head of a any DNS message.
37 */
35struct GNUNET_TUN_DnsHeader 38struct GNUNET_TUN_DnsHeader
36{ 39{
40 /**
41 * Request/response ID. (NBO)
42 */
37 uint16_t id GNUNET_PACKED; 43 uint16_t id GNUNET_PACKED;
44
45 /**
46 * Flags for the operation.
47 */
38 struct GNUNET_DNSPARSER_Flags flags; 48 struct GNUNET_DNSPARSER_Flags flags;
39 uint16_t query_count GNUNET_PACKED; // number of questions 49
40 uint16_t answer_rcount GNUNET_PACKED; // number of answers 50 /**
41 uint16_t authority_rcount GNUNET_PACKED; // number of authority-records 51 * number of questions (NBO)
42 uint16_t additional_rcount GNUNET_PACKED; // number of additional records 52 */
53 uint16_t query_count GNUNET_PACKED;
54
55 /**
56 * number of answers (NBO)
57 */
58 uint16_t answer_rcount GNUNET_PACKED;
59
60 /**
61 * number of authority-records (NBO)
62 */
63 uint16_t authority_rcount GNUNET_PACKED;
64
65 /**
66 * number of additional records (NBO)
67 */
68 uint16_t additional_rcount GNUNET_PACKED;
43}; 69};
44 70
71
72/**
73 * DNS query prefix.
74 */
45struct query_line 75struct query_line
46{ 76{
77 /**
78 * Desired type (GNUNET_DNSPARSER_TYPE_XXX). (NBO)
79 */
47 uint16_t type GNUNET_PACKED; 80 uint16_t type GNUNET_PACKED;
81
82 /**
83 * Desired class (usually GNUNET_DNSPARSER_CLASS_INTERNET). (NBO)
84 */
48 uint16_t class GNUNET_PACKED; 85 uint16_t class GNUNET_PACKED;
49}; 86};
50 87
88
89/**
90 * General DNS record prefix.
91 */
51struct record_line 92struct record_line
52{ 93{
94 /**
95 * Record type (GNUNET_DNSPARSER_TYPE_XXX). (NBO)
96 */
53 uint16_t type GNUNET_PACKED; 97 uint16_t type GNUNET_PACKED;
98
99 /**
100 * Record class (usually GNUNET_DNSPARSER_CLASS_INTERNET). (NBO)
101 */
54 uint16_t class GNUNET_PACKED; 102 uint16_t class GNUNET_PACKED;
103
104 /**
105 * Expiration for the record (in seconds). (NBO)
106 */
55 uint32_t ttl GNUNET_PACKED; 107 uint32_t ttl GNUNET_PACKED;
108
109 /**
110 * Number of bytes of data that follow. (NBO)
111 */
56 uint16_t data_len GNUNET_PACKED; 112 uint16_t data_len GNUNET_PACKED;
57}; 113};
58 114
115
116/**
117 * Payload of DNS SOA record (header).
118 */
59struct soa_data 119struct soa_data
60{ 120{
121 /**
122 * The version number of the original copy of the zone. (NBO)
123 */
61 uint32_t serial GNUNET_PACKED; 124 uint32_t serial GNUNET_PACKED;
125
126 /**
127 * Time interval before the zone should be refreshed. (NBO)
128 */
62 uint32_t refresh GNUNET_PACKED; 129 uint32_t refresh GNUNET_PACKED;
130
131 /**
132 * Time interval that should elapse before a failed refresh should
133 * be retried. (NBO)
134 */
63 uint32_t retry GNUNET_PACKED; 135 uint32_t retry GNUNET_PACKED;
136
137 /**
138 * Time value that specifies the upper limit on the time interval
139 * that can elapse before the zone is no longer authoritative. (NBO)
140 */
64 uint32_t expire GNUNET_PACKED; 141 uint32_t expire GNUNET_PACKED;
142
143 /**
144 * The bit minimum TTL field that should be exported with any RR
145 * from this zone. (NBO)
146 */
65 uint32_t minimum GNUNET_PACKED; 147 uint32_t minimum GNUNET_PACKED;
66}; 148};
67 149
150
151/**
152 * Payload of DNS SRV record (header).
153 */
154struct srv_data
155{
156
157 /**
158 * Preference for this entry (lower value is higher preference). Clients
159 * will contact hosts from the lowest-priority group first and fall back
160 * to higher priorities if the low-priority entries are unavailable. (NBO)
161 */
162 uint16_t prio GNUNET_PACKED;
163
164 /**
165 * Relative weight for records with the same priority. Clients will use
166 * the hosts of the same (lowest) priority with a probability proportional
167 * to the weight given. (NBO)
168 */
169 uint16_t weight GNUNET_PACKED;
170
171 /**
172 * TCP or UDP port of the service. (NBO)
173 */
174 uint16_t port GNUNET_PACKED;
175
176 /* followed by 'target' name */
177};
178
68GNUNET_NETWORK_STRUCT_END 179GNUNET_NETWORK_STRUCT_END
69 180
70 181
diff --git a/src/include/gnunet_dnsparser_lib.h b/src/include/gnunet_dnsparser_lib.h
index 28cc4c048..5a42baea6 100644
--- a/src/include/gnunet_dnsparser_lib.h
+++ b/src/include/gnunet_dnsparser_lib.h
@@ -41,6 +41,7 @@
41#define GNUNET_DNSPARSER_TYPE_MX 15 41#define GNUNET_DNSPARSER_TYPE_MX 15
42#define GNUNET_DNSPARSER_TYPE_TXT 16 42#define GNUNET_DNSPARSER_TYPE_TXT 16
43#define GNUNET_DNSPARSER_TYPE_AAAA 28 43#define GNUNET_DNSPARSER_TYPE_AAAA 28
44#define GNUNET_DNSPARSER_TYPE_SRV 33
44 45
45/** 46/**
46 * A few common DNS classes (ok, only one is common, but I list a 47 * A few common DNS classes (ok, only one is common, but I list a
@@ -173,6 +174,65 @@ struct GNUNET_DNSPARSER_MxRecord
173 174
174}; 175};
175 176
177
178/**
179 * Information from SRV records (RFC 2782). The 'service', 'proto'
180 * and 'domain_name' fields together give the DNS-name which for SRV
181 * records is of the form "_$SERVICE._$PROTO.$DOMAIN_NAME". The DNS
182 * parser provides the full name in 'struct DNSPARSER_Record' and the
183 * individual components in the respective fields of this struct.
184 * When serializing, you CAN set the 'name' field of 'struct
185 * GNUNET_DNSPARSER_Record' to NULL, in which case the DNSPARSER code
186 * will populate 'name' from the 'service', 'proto' and 'domain_name'
187 * fields in this struct.
188 */
189struct GNUNET_DNSPARSER_SrvRecord
190{
191
192 /**
193 * Preference for this entry (lower value is higher preference).
194 * Without the underscore (!). Note that RFC 6335 clarifies the
195 * set of legal characters for service names.
196 */
197 char *service;
198
199 /**
200 * Transport protocol (typcially "tcp" or "udp", but others might be allowed).
201 * Without the underscore (!).
202 */
203 char *proto;
204
205 /**
206 * Domain name for which the record is valid
207 */
208 char *domain_name;
209
210 /**
211 * Hostname offering the service.
212 */
213 char *target;
214
215 /**
216 * Preference for this entry (lower value is higher preference). Clients
217 * will contact hosts from the lowest-priority group first and fall back
218 * to higher priorities if the low-priority entries are unavailable.
219 */
220 uint16_t priority;
221
222 /**
223 * Relative weight for records with the same priority. Clients will use
224 * the hosts of the same (lowest) priority with a probability proportional
225 * to the weight given.
226 */
227 uint16_t weight;
228
229 /**
230 * TCP or UDP port of the service.
231 */
232 uint16_t port;
233
234};
235
176 236
177/** 237/**
178 * Information from SOA records (RFC 1035). 238 * Information from SOA records (RFC 1035).
@@ -252,6 +312,9 @@ struct GNUNET_DNSPARSER_Record
252 */ 312 */
253 char *name; 313 char *name;
254 314
315 /**
316 * Payload of the record (which one of these is valid depends on the 'type').
317 */
255 union 318 union
256 { 319 {
257 320
@@ -271,6 +334,11 @@ struct GNUNET_DNSPARSER_Record
271 struct GNUNET_DNSPARSER_MxRecord *mx; 334 struct GNUNET_DNSPARSER_MxRecord *mx;
272 335
273 /** 336 /**
337 * SRV data for SRV records.
338 */
339 struct GNUNET_DNSPARSER_SrvRecord *srv;
340
341 /**
274 * Raw data for all other types. 342 * Raw data for all other types.
275 */ 343 */
276 struct GNUNET_DNSPARSER_RawRecord raw; 344 struct GNUNET_DNSPARSER_RawRecord raw;