1
--- maradns-2.0.02/server/MaraDNS.c 2011-02-05 19:21:40.000000000 -0700
2
+++ maradns-2.0.03/server/MaraDNS.c 2011-02-18 15:19:12.000000000 -0700
4
-/* Copyright (c) 2002-2010 Sam Trenholme
5
+/* Copyright (c) 2002-2011 Sam Trenholme
10
int len_inet = sizeof(struct sockaddr);
12
int authoritative = 1;
21
- if(called_from_recursive == 1) {
22
- goto use_old_udpany_code;
25
/* Start synthesizing the reply */
26
/* Look for the list of all of the answers */
27
spot_data = mhash_get(bighash,query);
28
@@ -1020,228 +1015,6 @@
29
js_destroy(starwhitis);
30
goto old_udpany_code_disabled;
34
- /* The old udpany code is still used by the recursive half of
35
- * MaraDNS, so we have to keep it for the time being */
37
- /* Look for an A record with the same name as the query */
38
- if(change_rtype(query,RR_A) == JS_ERROR)
40
- spot_data = mhash_get(bighash,query);
41
- /* If found, add the data to our records */
42
- if(spot_data.value != 0 && spot_data.datatype == MARA_DNSRR) {
44
- where = spot_data.value;
45
- authoritative = where->authoritative;
46
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
47
- &(header.nscount),&(header.arcount),1,
48
- spot_data.point,0,0) == JS_ERROR)
51
- /* Look for MX record with the same name as the query */
52
- if(change_rtype(query,RR_MX) == JS_ERROR)
54
- spot_data = mhash_get(bighash,query);
55
- if(spot_data.value != 0 && spot_data.datatype == MARA_DNSRR) {
57
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
58
- &(header.nscount),&(header.arcount),0,
59
- spot_data.point,0,0) == JS_ERROR)
63
- where = spot_data.value;
64
- authoritative = where->authoritative;
65
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
66
- &(header.nscount),&(header.arcount),1,
67
- spot_data.point,0,0) == JS_ERROR)
73
- /* We optionally look for NS and SOA on an RR_ANY query */
75
- /* Look for NS record with the same name as the query */
76
- if(change_rtype(query,RR_NS) == JS_ERROR)
78
- spot_data = mhash_get(bighash,query);
79
- if(spot_data.value != 0 && spot_data.datatype == MARA_DNSRR) {
81
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
82
- &(header.nscount),&(header.arcount),0,
83
- spot_data.point,0,0) == JS_ERROR)
87
- where = spot_data.value;
88
- authoritative = where->authoritative;
89
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
90
- &(header.nscount),&(header.arcount),1,
91
- spot_data.point,0,0) == JS_ERROR)
96
- /* Look for SOA record with the same name as the query */
97
- if(change_rtype(query,RR_SOA) == JS_ERROR)
99
- spot_data = mhash_get(bighash,query);
100
- if(spot_data.value != 0 && spot_data.datatype == MARA_DNSRR) {
102
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
103
- &(header.nscount),&(header.arcount),0,
104
- spot_data.point,0,0) == JS_ERROR)
108
- where = spot_data.value;
109
- authoritative = where->authoritative;
110
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
111
- &(header.nscount),&(header.arcount),1,
112
- spot_data.point,0,0) == JS_ERROR)
119
- /* If not found, look for lower-case version of the same query */
121
- found = fold_case(query);
122
- if(found == JS_ERROR)
124
- if(found == 1) /* Case folded */ {
126
- /* Look for lower case version of A record */
127
- if(change_rtype(query,RR_A) == JS_ERROR)
129
- spot_data = mhash_get(bighash,query);
130
- /* If A record of lower-case found... */
131
- if(spot_data.value != 0 && spot_data.datatype == MARA_DNSRR) {
133
- where = spot_data.value;
134
- authoritative = where->authoritative;
135
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
136
- &(header.nscount),&(header.arcount),1,
137
- spot_data.point,0,0) == JS_ERROR)
140
- if(change_rtype(query,RR_MX) == JS_ERROR)
142
- spot_data = mhash_get(bighash,query);
143
- /* If MX record of lower-case found... */
144
- if(spot_data.value != 0 && spot_data.datatype == MARA_DNSRR) {
146
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
147
- &(header.nscount),&(header.arcount),0,
148
- spot_data.point,0,0) == JS_ERROR)
152
- where = spot_data.value;
153
- authoritative = where->authoritative;
154
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
155
- &(header.nscount),&(header.arcount),1,
156
- spot_data.point,0,0) == JS_ERROR)
160
- /* Optionally look for SOA and NS records */
162
- if(change_rtype(query,RR_NS) == JS_ERROR)
164
- spot_data = mhash_get(bighash,query);
165
- /* If NS record of lower-case found... */
166
- if(spot_data.value != 0 && spot_data.datatype == MARA_DNSRR) {
168
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
169
- &(header.nscount),&(header.arcount),0,
170
- spot_data.point,0,0) == JS_ERROR)
174
- where = spot_data.value;
175
- authoritative = where->authoritative;
176
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
177
- &(header.nscount),&(header.arcount),1,
178
- spot_data.point,0,0) == JS_ERROR)
182
- if(change_rtype(query,RR_SOA) == JS_ERROR)
184
- spot_data = mhash_get(bighash,query);
185
- /* If SOA record of lower-case found... */
186
- if(spot_data.value != 0 && spot_data.datatype == MARA_DNSRR) {
188
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
189
- &(header.nscount),&(header.arcount),0,
190
- spot_data.point,0,0) == JS_ERROR)
194
- where = spot_data.value;
195
- authoritative = where->authoritative;
196
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
197
- &(header.nscount),&(header.arcount),1,
198
- spot_data.point,0,0) == JS_ERROR)
204
- if(found == 0) { /* If not found, do star record search */
205
- found = starwhitis_seek_any(query,RR_A,0,&header,&where,
206
- &authoritative,most,ns,ar);
207
- found = starwhitis_seek_any(query,RR_MX,found,&header,
208
- &where,&authoritative,most,ns,ar);
210
- found = starwhitis_seek_any(query,RR_NS,found,
211
- &header,&where,&authoritative,most,
213
- found = starwhitis_seek_any(query,RR_SOA,found,
214
- &header,&where,&authoritative,most,
217
- if(found == JS_ERROR) {
223
- /* If nothing found, look for a CNAME record with the same name as
226
- if(change_rtype(query,RR_CNAME) == JS_ERROR)
228
- spot_data = mhash_get(bighash,query);
229
- /* If found, add the data to our records */
230
- if(spot_data.value != 0 && spot_data.datatype == MARA_DNSRR) {
232
- if(add_answer(spot_data.value,most,ns,ar,&(header.ancount),
233
- &(header.nscount),&(header.arcount),1,
234
- spot_data.point,0,0) == JS_ERROR)
239
- /* If nothing found, look for DDIP notation */
241
- if(change_rtype(query,RR_ANY) == JS_ERROR)
243
- found = ddip_check(id,sock,ect,query);
244
- if(found == JS_ERROR)
246
- if(found == JS_SUCCESS) {
254
old_udpany_code_disabled:
256
/* Return with exit code of 0 if no answer was found */
257
@@ -1290,12 +1063,36 @@
259
/* Check to make sure the data fits in under 512 bytes */
260
if(ar->unit_count > 512) {
262
+ /* If this is an ipv4 connection and we didn't get a compress error */
263
+ if(ect->type == 4) {
264
+ struct sockaddr_in *dq;
266
+ dq = (struct sockaddr_in *)(ect->d);
267
+ ip_test = ntohl(dq->sin_addr.s_addr);
268
+ /* See if we are allowed to send a long packet up to
269
+ * 4096 bytes to this ip address */
270
+ if(check_ipv4_acl(ip_test,long_packet) == 1) {
271
+ if(ar->unit_count < 4096) {
272
+ goto long_packet_ok;
277
/* We handle truncation by truncating everything except the
280
+ header.ancount = 0;
281
make_hdr(&header,ar);
282
+ /* Append the question, if there is one */
284
+ js_append(query,ar);
285
+ js_adduint16(ar,1);
291
/* Success! Put out the good data */
293
sendto(sock,ar->string,ar->unit_count,0,