… | |
… | |
39 | |
39 | |
40 | #include "netcompat.h" |
40 | #include "netcompat.h" |
41 | |
41 | |
42 | #include "vpn.h" |
42 | #include "vpn.h" |
43 | |
43 | |
44 | #if ENABLE_HTTP_PROXY |
|
|
45 | # include "conf.h" |
|
|
46 | #endif |
|
|
47 | |
|
|
48 | #define MIN_RETRY 1. |
44 | #define MIN_RETRY 1. |
49 | #define MAX_RETRY 60. |
45 | #define MAX_RETRY 60. |
50 | |
46 | |
51 | #define SERVER conf.dns_port |
47 | #define MAX_OUTSTANDING 10 // max. outstanding requests |
52 | |
48 | |
53 | /* |
49 | /* |
54 | |
50 | |
55 | protocol, in shorthand :) |
51 | protocol, in shorthand :) |
56 | |
52 | |
… | |
… | |
140 | *dst++ = accum >> (bits - 8); |
136 | *dst++ = accum >> (bits - 8); |
141 | bits -= 8; |
137 | bits -= 8; |
142 | } |
138 | } |
143 | } |
139 | } |
144 | } |
140 | } |
|
|
141 | |
|
|
142 | ///////////////////////////////////////////////////////////////////////////// |
145 | |
143 | |
146 | #define FLAG_QUERY ( 0 << 15) |
144 | #define FLAG_QUERY ( 0 << 15) |
147 | #define FLAG_RESPONSE ( 1 << 15) |
145 | #define FLAG_RESPONSE ( 1 << 15) |
148 | #define FLAG_OP_MASK (15 << 14) |
146 | #define FLAG_OP_MASK (15 << 14) |
149 | #define FLAG_OP_QUERY ( 0 << 11) |
147 | #define FLAG_OP_QUERY ( 0 << 11) |
… | |
… | |
204 | } |
202 | } |
205 | |
203 | |
206 | return data - orig; |
204 | return data - orig; |
207 | } |
205 | } |
208 | |
206 | |
|
|
207 | ///////////////////////////////////////////////////////////////////////////// |
|
|
208 | |
|
|
209 | struct dns_req |
|
|
210 | { |
|
|
211 | dns_packet *pkt; |
|
|
212 | tstamp next; |
|
|
213 | int retry; |
|
|
214 | |
|
|
215 | dns_req (connection *c, vpn_packet *p, int &offs); |
|
|
216 | }; |
|
|
217 | |
|
|
218 | struct dns_rep |
|
|
219 | { |
|
|
220 | }; |
|
|
221 | |
|
|
222 | static u16 dns_id; // TODO: should be per-vpn |
|
|
223 | |
|
|
224 | dns_req::dns_req (connection *c, vpn_packet *p, int &offs) |
|
|
225 | { |
|
|
226 | next = 0; |
|
|
227 | retry = 0; |
|
|
228 | |
|
|
229 | pkt = new dns_packet; |
|
|
230 | |
|
|
231 | pkt->id = dns_id++; |
|
|
232 | pkt->flags = DEFAULT_CLIENT_FLAGS; |
|
|
233 | pkt->qdcount = htons (1 * 0); |
|
|
234 | pkt->ancount = 0; |
|
|
235 | pkt->nscount = 0; |
|
|
236 | pkt->arcount = 0; |
|
|
237 | |
|
|
238 | offs += 10000; |
|
|
239 | |
|
|
240 | c->dns_sndq.push_back (this); |
|
|
241 | } |
|
|
242 | |
|
|
243 | ///////////////////////////////////////////////////////////////////////////// |
|
|
244 | |
209 | struct dns_cfg |
245 | struct dns_cfg |
210 | { |
246 | { |
211 | u8 id1, id2, id3; |
247 | u8 id1, id2, id3; |
212 | u8 def_ttl; |
248 | u8 def_ttl; |
213 | u8 unused1; |
249 | u8 unused1; |
… | |
… | |
303 | } |
339 | } |
304 | } |
340 | } |
305 | } |
341 | } |
306 | |
342 | |
307 | bool |
343 | bool |
308 | vpn::send_dnsv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) |
344 | connection::send_dnsv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) |
309 | { |
345 | { |
310 | //return i->send_packet (pkt, tos); |
346 | if (dns_sndq.size () >= MAX_OUTSTANDING) |
|
|
347 | return false; |
|
|
348 | |
|
|
349 | // split vpn packet into dns packets, add to sndq |
|
|
350 | for (int offs = 0; offs < pkt->len; ) |
|
|
351 | new dns_req (this, pkt, offs); |
|
|
352 | |
|
|
353 | // force transmit |
|
|
354 | dnsv4_cb (dnsv4_tw); |
|
|
355 | |
|
|
356 | return true; |
|
|
357 | } |
|
|
358 | |
|
|
359 | void |
|
|
360 | connection::dnsv4_cb (time_watcher &w) |
|
|
361 | { |
|
|
362 | // check for timeouts and (re)transmit |
|
|
363 | tstamp next = NOW + 60; |
|
|
364 | |
|
|
365 | slog (L_NOISE, _("dnsv4, %d packets in send queue\n"), dns_sndq.size ()); |
|
|
366 | |
|
|
367 | if (dns_sndq.empty ()) |
|
|
368 | { |
|
|
369 | next = NOW + 1; |
|
|
370 | // push poll packet |
|
|
371 | } |
|
|
372 | |
|
|
373 | for (vector<dns_req *>::iterator i = dns_sndq.begin (); |
|
|
374 | i != dns_sndq.end (); |
|
|
375 | ++i) |
|
|
376 | { |
|
|
377 | dns_req *r = *i; |
|
|
378 | |
|
|
379 | if (r->next <= NOW) |
|
|
380 | { |
|
|
381 | slog (L_NOISE, _("dnsv4, send req %d\n"), r->pkt->id); |
|
|
382 | r->retry++; |
|
|
383 | r->next = NOW + r->retry; |
|
|
384 | } |
|
|
385 | |
|
|
386 | if (r->next < next) |
|
|
387 | next = r->next; |
|
|
388 | } |
|
|
389 | |
|
|
390 | printf ("%f next\n", next); |
|
|
391 | w.start (next); |
311 | } |
392 | } |
312 | |
393 | |
313 | #endif |
394 | #endif |
314 | |
395 | |