aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dns/dns_api_new.c60
-rw-r--r--src/dns/dns_new.h49
-rw-r--r--src/include/gnunet_dns_service-new.h54
-rw-r--r--src/include/gnunet_dnsparser_lib.h23
4 files changed, 66 insertions, 120 deletions
diff --git a/src/dns/dns_api_new.c b/src/dns/dns_api_new.c
index 0b654e139..a61676a47 100644
--- a/src/dns/dns_api_new.c
+++ b/src/dns/dns_api_new.c
@@ -224,8 +224,7 @@ request_handler (void *cls,
224 struct GNUNET_DNS_Handle *dh = cls; 224 struct GNUNET_DNS_Handle *dh = cls;
225 const struct GNUNET_DNS_Request *req; 225 const struct GNUNET_DNS_Request *req;
226 struct GNUNET_DNS_RequestHandle *rh; 226 struct GNUNET_DNS_RequestHandle *rh;
227 const char *name; 227 size_t payload_length;
228 uint16_t name_len;
229 228
230 /* the service disconnected, reconnect after short wait */ 229 /* the service disconnected, reconnect after short wait */
231 if (msg == NULL) 230 if (msg == NULL)
@@ -236,20 +235,18 @@ request_handler (void *cls,
236 &reconnect, dh); 235 &reconnect, dh);
237 return; 236 return;
238 } 237 }
239 /* the service did something strange, reconnect immediately */
240 req = (const struct GNUNET_DNS_Request *) msg;
241 name = (const char*) &req[1];
242
243 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST) || 238 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST) ||
244 (ntohs (msg->size) < sizeof (struct GNUNET_DNS_Request)) || 239 (ntohs (msg->size) < sizeof (struct GNUNET_DNS_Request)) )
245 (ntohs (msg->size) != sizeof (struct GNUNET_DNS_Request) + ntohs (req->rdata_length) + (name_len = ntohs (req->name_length))) ||
246 (name[name_len-1] != '\0') )
247 { 240 {
241 /* the service did something strange, reconnect immediately */
248 GNUNET_break (0); 242 GNUNET_break (0);
249 disconnect (dh); 243 disconnect (dh);
250 dh->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, dh); 244 dh->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, dh);
251 return; 245 return;
252 } 246 }
247 req = (const struct GNUNET_DNS_Request *) msg;
248 GNUNET_break (ntohl (req->reserved) == 0);
249 payload_length = ntohs (req->header.size) - sizeof (struct GNUNET_DNS_Request);
253 GNUNET_CLIENT_receive (dh->dns_connection, 250 GNUNET_CLIENT_receive (dh->dns_connection,
254 &request_handler, dh, 251 &request_handler, dh,
255 GNUNET_TIME_UNIT_FOREVER_REL); 252 GNUNET_TIME_UNIT_FOREVER_REL);
@@ -262,12 +259,8 @@ request_handler (void *cls,
262 dh->pending_requests++; 259 dh->pending_requests++;
263 dh->rh (dh->rh_cls, 260 dh->rh (dh->rh_cls,
264 rh, 261 rh,
265 name, 262 payload_length,
266 ntohs (req->dns_type), 263 (const char*) &req[1]);
267 ntohs (req->dns_class),
268 ntohl (req->dns_ttl),
269 ntohs (req->rdata_length),
270 &name[name_len]);
271} 264}
272 265
273 266
@@ -393,10 +386,8 @@ GNUNET_DNS_request_forward (struct GNUNET_DNS_RequestHandle *rh)
393 qe->msg = &resp->header; 386 qe->msg = &resp->header;
394 resp->header.size = htons (sizeof (struct GNUNET_DNS_Response)); 387 resp->header.size = htons (sizeof (struct GNUNET_DNS_Response));
395 resp->header.type = htons (GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); 388 resp->header.type = htons (GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE);
396 resp->dns_ttl = htonl (0); 389 resp->drop_flag = htonl (1);
397 resp->request_id = rh->request_id; 390 resp->request_id = rh->request_id;
398 resp->drop_flag = htons (0);
399 resp->rdata_length = htons (0);
400 queue_reply (rh->dh, qe); 391 queue_reply (rh->dh, qe);
401 GNUNET_free (rh); 392 GNUNET_free (rh);
402} 393}
@@ -426,29 +417,26 @@ GNUNET_DNS_request_drop (struct GNUNET_DNS_RequestHandle *rh)
426 qe->msg = &resp->header; 417 qe->msg = &resp->header;
427 resp->header.size = htons (sizeof (struct GNUNET_DNS_Response)); 418 resp->header.size = htons (sizeof (struct GNUNET_DNS_Response));
428 resp->header.type = htons (GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); 419 resp->header.type = htons (GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE);
429 resp->dns_ttl = htonl (0);
430 resp->request_id = rh->request_id; 420 resp->request_id = rh->request_id;
431 resp->drop_flag = htons (1); 421 resp->drop_flag = htonl (0);
432 resp->rdata_length = htons (0);
433 queue_reply (rh->dh, qe); 422 queue_reply (rh->dh, qe);
434 GNUNET_free (rh); 423 GNUNET_free (rh);
435} 424}
436 425
437 426
438/** 427/**
439 * If a GNUNET_DNS_RequestHandler calls this function, the request is supposed to 428 * If a GNUNET_DNS_RequestHandler calls this function, the request is
440 * be answered with the data provided to this call (with the modifications the function might have made). 429 * supposed to be answered with the data provided to this call (with
430 * the modifications the function might have made).
441 * 431 *
442 * @param rh request that should now be answered 432 * @param rh request that should now be answered
443 * @param dns_ttl seconds that the RR stays valid, can be updated 433 * @param reply_length size of reply (uint16_t to force sane size)
444 * @param rdata_length size of rdata, can be updated 434 * @param reply reply data
445 * @param rdata record data, can be updated
446 */ 435 */
447void 436void
448GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh, 437GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh,
449 uint32_t dns_ttl, 438 uint16_t reply_length,
450 uint16_t rdata_length, 439 const char *reply)
451 char *rdata)
452{ 440{
453 struct ReplyQueueEntry *qe; 441 struct ReplyQueueEntry *qe;
454 struct GNUNET_DNS_Response *resp; 442 struct GNUNET_DNS_Response *resp;
@@ -459,23 +447,21 @@ GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh,
459 GNUNET_free (rh); 447 GNUNET_free (rh);
460 return; 448 return;
461 } 449 }
462 if (rdata_length + sizeof (struct GNUNET_DNS_Response) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 450 if (reply_length + sizeof (struct GNUNET_DNS_Response) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
463 { 451 {
464 GNUNET_break (0); 452 GNUNET_break (0);
465 GNUNET_free (rh); 453 GNUNET_free (rh);
466 return; 454 return;
467 } 455 }
468 qe = GNUNET_malloc (sizeof (struct ReplyQueueEntry) + 456 qe = GNUNET_malloc (sizeof (struct ReplyQueueEntry) +
469 sizeof (struct GNUNET_DNS_Response) + rdata_length); 457 sizeof (struct GNUNET_DNS_Response) + reply_length);
470 resp = (struct GNUNET_DNS_Response*) &qe[1]; 458 resp = (struct GNUNET_DNS_Response*) &qe[1];
471 qe->msg = &resp->header; 459 qe->msg = &resp->header;
472 resp->header.size = htons (sizeof (struct GNUNET_DNS_Response) + rdata_length); 460 resp->header.size = htons (sizeof (struct GNUNET_DNS_Response) + reply_length);
473 resp->header.type = htons (GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); 461 resp->header.type = htons (GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE);
474 resp->dns_ttl = htonl (dns_ttl); 462 resp->drop_flag = htons (2);
475 resp->request_id = rh->request_id; 463 resp->request_id = rh->request_id;
476 resp->drop_flag = htons (0); 464 memcpy (&resp[1], reply, reply_length);
477 resp->rdata_length = htons (rdata_length);
478 memcpy (&resp[1], rdata, rdata_length);
479 queue_reply (rh->dh, qe); 465 queue_reply (rh->dh, qe);
480 GNUNET_free (rh); 466 GNUNET_free (rh);
481} 467}
diff --git a/src/dns/dns_new.h b/src/dns/dns_new.h
index 4f3493db2..7cf3a316a 100644
--- a/src/dns/dns_new.h
+++ b/src/dns/dns_new.h
@@ -39,38 +39,16 @@ struct GNUNET_DNS_Request
39 struct GNUNET_MessageHeader header; 39 struct GNUNET_MessageHeader header;
40 40
41 /** 41 /**
42 * A DNS type (GNUNET_DNS_TYPE_*) 42 * Always zero.
43 */ 43 */
44 uint16_t dns_type GNUNET_PACKED; 44 uint32_t reserved GNUNET_PACKED;
45 45
46 /** 46 /**
47 * A DNS class (usually 1).
48 */
49 uint16_t dns_class GNUNET_PACKED;
50
51 /**
52 * Unique request ID. 47 * Unique request ID.
53 */ 48 */
54 uint64_t request_id GNUNET_PACKED; 49 uint64_t request_id GNUNET_PACKED;
55 50
56 /** 51 /* followed by original DNS request (without UDP header) */
57 * TTL if rdata is present, otherwise 0.
58 */
59 uint32_t dns_ttl GNUNET_PACKED;
60
61 /**
62 * Number of bytes of rdata that follow at the end.
63 */
64 uint16_t rdata_length GNUNET_PACKED;
65
66 /**
67 * Number of bytes of the name that follow right now (including 0-termination).
68 */
69 uint16_t name_length GNUNET_PACKED;
70
71 /* followed by char name[name_length] */
72
73 /* followed by char rdata[rdata_length] */
74 52
75}; 53};
76 54
@@ -86,27 +64,16 @@ struct GNUNET_DNS_Response
86 struct GNUNET_MessageHeader header; 64 struct GNUNET_MessageHeader header;
87 65
88 /** 66 /**
89 * TTL if rdata is present, otherwise 0. 67 * Zero to drop, 1 for no change (no payload), 2 for update (message has payload).
90 */ 68 */
91 uint32_t dns_ttl GNUNET_PACKED; 69 uint32_t drop_flag GNUNET_PACKED;
92 70
93 /** 71 /**
94 * Unique request ID, matches the original request. 72 * Unique request ID.
95 */ 73 */
96 uint64_t request_id GNUNET_PACKED; 74 uint64_t request_id GNUNET_PACKED;
97 75
98 /** 76 /* followed by original DNS request (without UDP header) */
99 * 1 to drop request, 0 to forward if there is no response
100 * or to answer if there is a response.
101 */
102 uint16_t drop_flag GNUNET_PACKED;
103
104 /**
105 * Number of bytes of rdata that follow at the end.
106 */
107 uint16_t rdata_length GNUNET_PACKED;
108
109 /* followed by char rdata[rdata_length] */
110 77
111}; 78};
112 79
diff --git a/src/include/gnunet_dns_service-new.h b/src/include/gnunet_dns_service-new.h
index a05f2cd17..06b9a87a1 100644
--- a/src/include/gnunet_dns_service-new.h
+++ b/src/include/gnunet_dns_service-new.h
@@ -29,28 +29,6 @@
29#include "gnunet_common.h" 29#include "gnunet_common.h"
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31 31
32/**
33 * A few common DNS types.
34 */
35#define GNUNET_DNS_TYPE_A 1
36#define GNUNET_DNS_TYPE_NS 2
37#define GNUNET_DNS_TYPE_CNAME 5
38#define GNUNET_DNS_TYPE_SOA 6
39#define GNUNET_DNS_TYPE_PTR 12
40#define GNUNET_DNS_TYPE_MX 15
41#define GNUNET_DNS_TYPE_TXT 16
42#define GNUNET_DNS_TYPE_AAAA 28
43#define GNUNET_DNS_TYPE_IXFR 251
44#define GNUNET_DNS_TYPE_AXFR 252
45
46/**
47 * A few common DNS classes (ok, only one is common, but I list a
48 * couple more to make it clear what we're talking about here).
49 */
50#define GNUNET_DNS_CLASS_INTERNET 1
51#define GNUNET_DNS_CLASS_CHAOS 3
52#define GNUNET_DNS_CLASS_HESIOD 4
53
54 32
55/** 33/**
56 * Opaque DNS handle 34 * Opaque DNS handle
@@ -82,21 +60,14 @@ struct GNUNET_DNS_RequestHandle;
82 * functions call GNUNET_DNS_request_drop, the response is dropped. 60 * functions call GNUNET_DNS_request_drop, the response is dropped.
83 * 61 *
84 * @param cls closure 62 * @param cls closure
85 * @param name name of the node to which the record pertains 63 * @param rh request handle to user for reply
86 * @param dns_type type of RR 64 * @param request_length number of bytes in request
87 * @param dns_class class code 65 * @param request udp payload of the DNS request
88 * @param dns_ttl seconds that the RR stays valid, can be updated
89 * @param rdata_length size of rdata, can be updated
90 * @param rdata record data, can be updated
91 */ 66 */
92typedef void (*GNUNET_DNS_RequestHandler)(void *cls, 67typedef void (*GNUNET_DNS_RequestHandler)(void *cls,
93 struct GNUNET_DNS_RequestHandle *rh, 68 struct GNUNET_DNS_RequestHandle *rh,
94 const char *name, 69 size_t request_length,
95 uint16_t dns_type, 70 const char *request);
96 uint16_t dns_class,
97 uint32_t dns_ttl,
98 uint16_t rdata_length,
99 const char *rdata);
100 71
101 72
102/** 73/**
@@ -124,19 +95,18 @@ GNUNET_DNS_request_drop (struct GNUNET_DNS_RequestHandle *rh);
124 95
125 96
126/** 97/**
127 * If a GNUNET_DNS_RequestHandler calls this function, the request is supposed to 98 * If a GNUNET_DNS_RequestHandler calls this function, the request is
128 * be answered with the data provided to this call (with the modifications the function might have made). 99 * supposed to be answered with the data provided to this call (with
100 * the modifications the function might have made).
129 * 101 *
130 * @param rh request that should now be answered 102 * @param rh request that should now be answered
131 * @param dns_ttl seconds that the RR stays valid, can be updated 103 * @param reply_length size of reply (uint16_t to force sane size)
132 * @param rdata_length size of rdata, can be updated 104 * @param reply reply data
133 * @param rdata record data, can be updated
134 */ 105 */
135void 106void
136GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh, 107GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh,
137 uint32_t dns_ttl, 108 uint16_t reply_length,
138 uint16_t rdata_length, 109 const char *reply);
139 char *rdata);
140 110
141 111
142/** 112/**
diff --git a/src/include/gnunet_dnsparser_lib.h b/src/include/gnunet_dnsparser_lib.h
index 37e31d24f..3aa289e70 100644
--- a/src/include/gnunet_dnsparser_lib.h
+++ b/src/include/gnunet_dnsparser_lib.h
@@ -29,6 +29,29 @@
29#include "platform.h" 29#include "platform.h"
30#include "gnunet_common.h" 30#include "gnunet_common.h"
31 31
32/**
33 * A few common DNS types.
34 */
35#define GNUNET_DNS_TYPE_A 1
36#define GNUNET_DNS_TYPE_NS 2
37#define GNUNET_DNS_TYPE_CNAME 5
38#define GNUNET_DNS_TYPE_SOA 6
39#define GNUNET_DNS_TYPE_PTR 12
40#define GNUNET_DNS_TYPE_MX 15
41#define GNUNET_DNS_TYPE_TXT 16
42#define GNUNET_DNS_TYPE_AAAA 28
43#define GNUNET_DNS_TYPE_IXFR 251
44#define GNUNET_DNS_TYPE_AXFR 252
45
46/**
47 * A few common DNS classes (ok, only one is common, but I list a
48 * couple more to make it clear what we're talking about here).
49 */
50#define GNUNET_DNS_CLASS_INTERNET 1
51#define GNUNET_DNS_CLASS_CHAOS 3
52#define GNUNET_DNS_CLASS_HESIOD 4
53
54
32// DNS-Stuff 55// DNS-Stuff
33GNUNET_NETWORK_STRUCT_BEGIN 56GNUNET_NETWORK_STRUCT_BEGIN
34 57