aboutsummaryrefslogtreecommitdiff
path: root/src/dns
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-15 10:52:06 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-15 10:52:06 +0000
commit3288af4a4651156c01bdf6ffe1b20c6fbedf4bd8 (patch)
treeed49951102400f7086f4db23846fb7aaf32e5eb1 /src/dns
parent9e94c69b299f74ac88b14f92b7a01bba0c33a776 (diff)
downloadgnunet-3288af4a4651156c01bdf6ffe1b20c6fbedf4bd8.tar.gz
gnunet-3288af4a4651156c01bdf6ffe1b20c6fbedf4bd8.zip
-eliminating duplicate struct definitions
Diffstat (limited to 'src/dns')
-rw-r--r--src/dns/Makefile.am2
-rw-r--r--src/dns/dnsparser.c50
-rw-r--r--src/dns/dnsparser.h195
-rw-r--r--src/dns/gnunet-dns-monitor.c6
-rw-r--r--src/dns/gnunet-service-dns.c2
5 files changed, 30 insertions, 225 deletions
diff --git a/src/dns/Makefile.am b/src/dns/Makefile.am
index 345c1316c..441ffeefd 100644
--- a/src/dns/Makefile.am
+++ b/src/dns/Makefile.am
@@ -82,7 +82,7 @@ gnunet_service_dns_DEPENDENCIES = \
82 libgnunetdnsstub.la 82 libgnunetdnsstub.la
83 83
84libgnunetdnsparser_la_SOURCES = \ 84libgnunetdnsparser_la_SOURCES = \
85 dnsparser.c dnsparser.h 85 dnsparser.c
86libgnunetdnsparser_la_LIBADD = \ 86libgnunetdnsparser_la_LIBADD = \
87 $(top_builddir)/src/util/libgnunetutil.la $(XLIB) \ 87 $(top_builddir)/src/util/libgnunetutil.la $(XLIB) \
88 -lidn 88 -lidn
diff --git a/src/dns/dnsparser.c b/src/dns/dnsparser.c
index 18ef4c219..68b882279 100644
--- a/src/dns/dnsparser.c
+++ b/src/dns/dnsparser.c
@@ -31,7 +31,7 @@
31#endif 31#endif
32#include "gnunet_util_lib.h" 32#include "gnunet_util_lib.h"
33#include "gnunet_dnsparser_lib.h" 33#include "gnunet_dnsparser_lib.h"
34#include "dnsparser.h" 34#include "gnunet_tun_lib.h"
35 35
36 36
37/** 37/**
@@ -235,7 +235,7 @@ parse_query (const char *udp_payload,
235 struct GNUNET_DNSPARSER_Query *q) 235 struct GNUNET_DNSPARSER_Query *q)
236{ 236{
237 char *name; 237 char *name;
238 struct query_line ql; 238 struct GNUNET_TUN_DnsQueryLine ql;
239 239
240 name = parse_name (udp_payload, 240 name = parse_name (udp_payload,
241 udp_payload_length, 241 udp_payload_length,
@@ -243,7 +243,7 @@ parse_query (const char *udp_payload,
243 if (NULL == name) 243 if (NULL == name)
244 return GNUNET_SYSERR; 244 return GNUNET_SYSERR;
245 q->name = name; 245 q->name = name;
246 if (*off + sizeof (struct query_line) > udp_payload_length) 246 if (*off + sizeof (struct GNUNET_TUN_DnsQueryLine) > udp_payload_length)
247 return GNUNET_SYSERR; 247 return GNUNET_SYSERR;
248 memcpy (&ql, &udp_payload[*off], sizeof (ql)); 248 memcpy (&ql, &udp_payload[*off], sizeof (ql));
249 *off += sizeof (ql); 249 *off += sizeof (ql);
@@ -270,12 +270,12 @@ parse_record (const char *udp_payload,
270 struct GNUNET_DNSPARSER_Record *r) 270 struct GNUNET_DNSPARSER_Record *r)
271{ 271{
272 char *name; 272 char *name;
273 struct record_line rl; 273 struct GNUNET_TUN_DnsRecordLine rl;
274 size_t old_off; 274 size_t old_off;
275 struct soa_data soa; 275 struct GNUNET_TUN_DnsSoaRecord soa;
276 uint16_t mxpref; 276 uint16_t mxpref;
277 uint16_t data_len; 277 uint16_t data_len;
278 struct srv_data srv; 278 struct GNUNET_TUN_DnsSrvRecord srv;
279 char *ndup; 279 char *ndup;
280 char *tok; 280 char *tok;
281 281
@@ -285,7 +285,7 @@ parse_record (const char *udp_payload,
285 if (NULL == name) 285 if (NULL == name)
286 return GNUNET_SYSERR; 286 return GNUNET_SYSERR;
287 r->name = name; 287 r->name = name;
288 if (*off + sizeof (struct record_line) > udp_payload_length) 288 if (*off + sizeof (struct GNUNET_TUN_DnsRecordLine) > udp_payload_length)
289 return GNUNET_SYSERR; 289 return GNUNET_SYSERR;
290 memcpy (&rl, &udp_payload[*off], sizeof (rl)); 290 memcpy (&rl, &udp_payload[*off], sizeof (rl));
291 (*off) += sizeof (rl); 291 (*off) += sizeof (rl);
@@ -320,15 +320,15 @@ parse_record (const char *udp_payload,
320 off, 0); 320 off, 0);
321 if ( (NULL == r->data.soa->mname) || 321 if ( (NULL == r->data.soa->mname) ||
322 (NULL == r->data.soa->rname) || 322 (NULL == r->data.soa->rname) ||
323 (*off + sizeof (struct soa_data) > udp_payload_length) ) 323 (*off + sizeof (struct GNUNET_TUN_DnsSoaRecord) > udp_payload_length) )
324 return GNUNET_SYSERR; 324 return GNUNET_SYSERR;
325 memcpy (&soa, &udp_payload[*off], sizeof (struct soa_data)); 325 memcpy (&soa, &udp_payload[*off], sizeof (struct GNUNET_TUN_DnsSoaRecord));
326 r->data.soa->serial = ntohl (soa.serial); 326 r->data.soa->serial = ntohl (soa.serial);
327 r->data.soa->refresh = ntohl (soa.refresh); 327 r->data.soa->refresh = ntohl (soa.refresh);
328 r->data.soa->retry = ntohl (soa.retry); 328 r->data.soa->retry = ntohl (soa.retry);
329 r->data.soa->expire = ntohl (soa.expire); 329 r->data.soa->expire = ntohl (soa.expire);
330 r->data.soa->minimum_ttl = ntohl (soa.minimum); 330 r->data.soa->minimum_ttl = ntohl (soa.minimum);
331 (*off) += sizeof (struct soa_data); 331 (*off) += sizeof (struct GNUNET_TUN_DnsSoaRecord);
332 if (old_off + data_len != *off) 332 if (old_off + data_len != *off)
333 return GNUNET_SYSERR; 333 return GNUNET_SYSERR;
334 return GNUNET_OK; 334 return GNUNET_OK;
@@ -352,10 +352,10 @@ parse_record (const char *udp_payload,
352 if (NULL == strstr (r->name, "._")) 352 if (NULL == strstr (r->name, "._"))
353 return GNUNET_SYSERR; /* necessary string from "._$PROTO" not present */ 353 return GNUNET_SYSERR; /* necessary string from "._$PROTO" not present */
354 old_off = *off; 354 old_off = *off;
355 if (*off + sizeof (struct srv_data) > udp_payload_length) 355 if (*off + sizeof (struct GNUNET_TUN_DnsSrvRecord) > udp_payload_length)
356 return GNUNET_SYSERR; 356 return GNUNET_SYSERR;
357 memcpy (&srv, &udp_payload[*off], sizeof (struct srv_data)); 357 memcpy (&srv, &udp_payload[*off], sizeof (struct GNUNET_TUN_DnsSrvRecord));
358 (*off) += sizeof (struct srv_data); 358 (*off) += sizeof (struct GNUNET_TUN_DnsSrvRecord);
359 r->data.srv = GNUNET_malloc (sizeof (struct GNUNET_DNSPARSER_SrvRecord)); 359 r->data.srv = GNUNET_malloc (sizeof (struct GNUNET_DNSPARSER_SrvRecord));
360 r->data.srv->priority = ntohs (srv.prio); 360 r->data.srv->priority = ntohs (srv.prio);
361 r->data.srv->weight = ntohs (srv.weight); 361 r->data.srv->weight = ntohs (srv.weight);
@@ -685,9 +685,9 @@ add_query (char *dst,
685 const struct GNUNET_DNSPARSER_Query *query) 685 const struct GNUNET_DNSPARSER_Query *query)
686{ 686{
687 int ret; 687 int ret;
688 struct query_line ql; 688 struct GNUNET_TUN_DnsQueryLine ql;
689 689
690 ret = add_name (dst, dst_len - sizeof (struct query_line), off, query->name); 690 ret = add_name (dst, dst_len - sizeof (struct GNUNET_TUN_DnsQueryLine), off, query->name);
691 if (ret != GNUNET_OK) 691 if (ret != GNUNET_OK)
692 return ret; 692 return ret;
693 ql.type = htons (query->type); 693 ql.type = htons (query->type);
@@ -745,7 +745,7 @@ add_soa (char *dst,
745 size_t *off, 745 size_t *off,
746 const struct GNUNET_DNSPARSER_SoaRecord *soa) 746 const struct GNUNET_DNSPARSER_SoaRecord *soa)
747{ 747{
748 struct soa_data sd; 748 struct GNUNET_TUN_DnsSoaRecord sd;
749 int ret; 749 int ret;
750 750
751 if ( (GNUNET_OK != (ret = add_name (dst, 751 if ( (GNUNET_OK != (ret = add_name (dst,
@@ -757,7 +757,7 @@ add_soa (char *dst,
757 off, 757 off,
758 soa->rname)) ) ) 758 soa->rname)) ) )
759 return ret; 759 return ret;
760 if (*off + sizeof (struct soa_data) > dst_len) 760 if (*off + sizeof (struct GNUNET_TUN_DnsSoaRecord) > dst_len)
761 return GNUNET_NO; 761 return GNUNET_NO;
762 sd.serial = htonl (soa->serial); 762 sd.serial = htonl (soa->serial);
763 sd.refresh = htonl (soa->refresh); 763 sd.refresh = htonl (soa->refresh);
@@ -788,10 +788,10 @@ add_srv (char *dst,
788 size_t *off, 788 size_t *off,
789 const struct GNUNET_DNSPARSER_SrvRecord *srv) 789 const struct GNUNET_DNSPARSER_SrvRecord *srv)
790{ 790{
791 struct srv_data sd; 791 struct GNUNET_TUN_DnsSrvRecord sd;
792 int ret; 792 int ret;
793 793
794 if (*off + sizeof (struct srv_data) > dst_len) 794 if (*off + sizeof (struct GNUNET_TUN_DnsSrvRecord) > dst_len)
795 return GNUNET_NO; 795 return GNUNET_NO;
796 sd.prio = htons (srv->priority); 796 sd.prio = htons (srv->priority);
797 sd.weight = htons (srv->weight); 797 sd.weight = htons (srv->weight);
@@ -828,7 +828,7 @@ add_record (char *dst,
828 int ret; 828 int ret;
829 size_t start; 829 size_t start;
830 size_t pos; 830 size_t pos;
831 struct record_line rl; 831 struct GNUNET_TUN_DnsRecordLine rl;
832 char *name; 832 char *name;
833 833
834 start = *off; 834 start = *off;
@@ -842,14 +842,14 @@ add_record (char *dst,
842 record->data.srv->service, 842 record->data.srv->service,
843 record->data.srv->proto, 843 record->data.srv->proto,
844 record->data.srv->domain_name); 844 record->data.srv->domain_name);
845 ret = add_name (dst, dst_len - sizeof (struct record_line), off, name); 845 ret = add_name (dst, dst_len - sizeof (struct GNUNET_TUN_DnsRecordLine), off, name);
846 if (name != record->name) 846 if (name != record->name)
847 GNUNET_free (name); 847 GNUNET_free (name);
848 if (GNUNET_OK != ret) 848 if (GNUNET_OK != ret)
849 return ret; 849 return ret;
850 /* '*off' is now the position where we will need to write the record line */ 850 /* '*off' is now the position where we will need to write the record line */
851 851
852 pos = *off + sizeof (struct record_line); 852 pos = *off + sizeof (struct GNUNET_TUN_DnsRecordLine);
853 switch (record->type) 853 switch (record->type)
854 { 854 {
855 case GNUNET_DNSPARSER_TYPE_MX: 855 case GNUNET_DNSPARSER_TYPE_MX:
@@ -883,7 +883,7 @@ add_record (char *dst,
883 return GNUNET_NO; 883 return GNUNET_NO;
884 } 884 }
885 885
886 if (pos - (*off + sizeof (struct record_line)) > UINT16_MAX) 886 if (pos - (*off + sizeof (struct GNUNET_TUN_DnsRecordLine)) > UINT16_MAX)
887 { 887 {
888 /* record data too long */ 888 /* record data too long */
889 *off = start; 889 *off = start;
@@ -892,8 +892,8 @@ add_record (char *dst,
892 rl.type = htons (record->type); 892 rl.type = htons (record->type);
893 rl.class = htons (record->class); 893 rl.class = htons (record->class);
894 rl.ttl = htonl (GNUNET_TIME_absolute_get_remaining (record->expiration_time).rel_value_us / 1000LL / 1000LL); /* in seconds */ 894 rl.ttl = htonl (GNUNET_TIME_absolute_get_remaining (record->expiration_time).rel_value_us / 1000LL / 1000LL); /* in seconds */
895 rl.data_len = htons ((uint16_t) (pos - (*off + sizeof (struct record_line)))); 895 rl.data_len = htons ((uint16_t) (pos - (*off + sizeof (struct GNUNET_TUN_DnsRecordLine))));
896 memcpy (&dst[*off], &rl, sizeof (struct record_line)); 896 memcpy (&dst[*off], &rl, sizeof (struct GNUNET_TUN_DnsRecordLine));
897 *off = pos; 897 *off = pos;
898 return GNUNET_OK; 898 return GNUNET_OK;
899} 899}
diff --git a/src/dns/dnsparser.h b/src/dns/dnsparser.h
deleted file mode 100644
index d312f8931..000000000
--- a/src/dns/dnsparser.h
+++ /dev/null
@@ -1,195 +0,0 @@
1/*
2 This file is part of GNUnet
3 (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file dns/dnsparser.h
23 * @brief helper library to parse DNS packets.
24 * @author Philipp Toelke
25 * @author Christian Grothoff
26 * @author Martin Schanzenbach
27 */
28GNUNET_NETWORK_STRUCT_BEGIN
29
30/* FIXME: replace this one with the one from tcpip_tun.h!? */
31/**
32 * Head of a any DNS message.
33 */
34struct GNUNET_TUN_DnsHeader
35{
36 /**
37 * Request/response ID. (NBO)
38 */
39 uint16_t id GNUNET_PACKED;
40
41 /**
42 * Flags for the operation.
43 */
44 struct GNUNET_DNSPARSER_Flags flags;
45
46 /**
47 * number of questions (NBO)
48 */
49 uint16_t query_count GNUNET_PACKED;
50
51 /**
52 * number of answers (NBO)
53 */
54 uint16_t answer_rcount GNUNET_PACKED;
55
56 /**
57 * number of authority-records (NBO)
58 */
59 uint16_t authority_rcount GNUNET_PACKED;
60
61 /**
62 * number of additional records (NBO)
63 */
64 uint16_t additional_rcount GNUNET_PACKED;
65};
66
67
68/**
69 * DNS query prefix.
70 */
71struct query_line
72{
73 /**
74 * Desired type (GNUNET_DNSPARSER_TYPE_XXX). (NBO)
75 */
76 uint16_t type GNUNET_PACKED;
77
78 /**
79 * Desired class (usually GNUNET_DNSPARSER_CLASS_INTERNET). (NBO)
80 */
81 uint16_t class GNUNET_PACKED;
82};
83
84
85/**
86 * General DNS record prefix.
87 */
88struct record_line
89{
90 /**
91 * Record type (GNUNET_DNSPARSER_TYPE_XXX). (NBO)
92 */
93 uint16_t type GNUNET_PACKED;
94
95 /**
96 * Record class (usually GNUNET_DNSPARSER_CLASS_INTERNET). (NBO)
97 */
98 uint16_t class GNUNET_PACKED;
99
100 /**
101 * Expiration for the record (in seconds). (NBO)
102 */
103 uint32_t ttl GNUNET_PACKED;
104
105 /**
106 * Number of bytes of data that follow. (NBO)
107 */
108 uint16_t data_len GNUNET_PACKED;
109};
110
111
112/**
113 * Payload of DNS SOA record (header).
114 */
115struct soa_data
116{
117 /**
118 * The version number of the original copy of the zone. (NBO)
119 */
120 uint32_t serial GNUNET_PACKED;
121
122 /**
123 * Time interval before the zone should be refreshed. (NBO)
124 */
125 uint32_t refresh GNUNET_PACKED;
126
127 /**
128 * Time interval that should elapse before a failed refresh should
129 * be retried. (NBO)
130 */
131 uint32_t retry GNUNET_PACKED;
132
133 /**
134 * Time value that specifies the upper limit on the time interval
135 * that can elapse before the zone is no longer authoritative. (NBO)
136 */
137 uint32_t expire GNUNET_PACKED;
138
139 /**
140 * The bit minimum TTL field that should be exported with any RR
141 * from this zone. (NBO)
142 */
143 uint32_t minimum GNUNET_PACKED;
144};
145
146
147/**
148 * Payload of DNS SRV record (header).
149 */
150struct srv_data
151{
152
153 /**
154 * Preference for this entry (lower value is higher preference). Clients
155 * will contact hosts from the lowest-priority group first and fall back
156 * to higher priorities if the low-priority entries are unavailable. (NBO)
157 */
158 uint16_t prio GNUNET_PACKED;
159
160 /**
161 * Relative weight for records with the same priority. Clients will use
162 * the hosts of the same (lowest) priority with a probability proportional
163 * to the weight given. (NBO)
164 */
165 uint16_t weight GNUNET_PACKED;
166
167 /**
168 * TCP or UDP port of the service. (NBO)
169 */
170 uint16_t port GNUNET_PACKED;
171
172 /* followed by 'target' name */
173};
174
175
176/**
177 * Payload of GNS VPN record
178 */
179struct vpn_data
180{
181 /**
182 * The peer to contact
183 */
184 struct GNUNET_HashCode peer;
185
186 /**
187 * The protocol to use
188 */
189 uint16_t proto GNUNET_PACKED;
190
191
192 /* followed by the servicename / identifier / password (0-terminated) */
193};
194
195GNUNET_NETWORK_STRUCT_END
diff --git a/src/dns/gnunet-dns-monitor.c b/src/dns/gnunet-dns-monitor.c
index ece96db71..ed09d49b1 100644
--- a/src/dns/gnunet-dns-monitor.c
+++ b/src/dns/gnunet-dns-monitor.c
@@ -94,9 +94,9 @@ get_class (uint16_t class)
94 static char buf[6]; 94 static char buf[6];
95 switch (class) 95 switch (class)
96 { 96 {
97 case GNUNET_DNSPARSER_CLASS_INTERNET: return "IN"; 97 case GNUNET_TUN_DNS_CLASS_INTERNET: return "IN";
98 case GNUNET_DNSPARSER_CLASS_CHAOS: return "CHAOS"; 98 case GNUNET_TUN_DNS_CLASS_CHAOS: return "CHAOS";
99 case GNUNET_DNSPARSER_CLASS_HESIOD: return "HESIOD"; 99 case GNUNET_TUN_DNS_CLASS_HESIOD: return "HESIOD";
100 } 100 }
101 GNUNET_snprintf (buf, sizeof (buf), "%u", (unsigned int) class); 101 GNUNET_snprintf (buf, sizeof (buf), "%u", (unsigned int) class);
102 return buf; 102 return buf;
diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c
index 4a94283ab..ac410d3ed 100644
--- a/src/dns/gnunet-service-dns.c
+++ b/src/dns/gnunet-service-dns.c
@@ -835,7 +835,7 @@ handle_client_response (void *cls GNUNET_UNUSED,
835 /* if query changed to answer, move past DNS resolution phase... */ 835 /* if query changed to answer, move past DNS resolution phase... */
836 if ( (RP_QUERY == rr->phase) && 836 if ( (RP_QUERY == rr->phase) &&
837 (rr->payload_length > sizeof (struct GNUNET_TUN_DnsHeader)) && 837 (rr->payload_length > sizeof (struct GNUNET_TUN_DnsHeader)) &&
838 ((struct GNUNET_DNSPARSER_Flags*)&(((struct GNUNET_TUN_DnsHeader*) rr->payload)->flags))->query_or_response == 1) 838 ((struct GNUNET_TUN_DnsFlags*)&(((struct GNUNET_TUN_DnsHeader*) rr->payload)->flags))->query_or_response == 1)
839 { 839 {
840 rr->phase = RP_INTERNET_DNS; 840 rr->phase = RP_INTERNET_DNS;
841 GNUNET_array_grow (rr->client_wait_list, 841 GNUNET_array_grow (rr->client_wait_list,