… | |
… | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
15 | GNU General Public License for more details. |
16 | |
16 | |
17 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
18 | along with gvpe; if not, write to the Free Software |
18 | along with gvpe; if not, write to the Free Software |
19 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | */ |
20 | */ |
|
|
21 | |
|
|
22 | // TODO: EDNS0 option to increase dns mtu? |
|
|
23 | // TODO: re-write dns packet parsing/creation using a safe mem-buffer |
|
|
24 | // to ensure no buffer overflows or similar problems. |
21 | |
25 | |
22 | #include "config.h" |
26 | #include "config.h" |
23 | |
27 | |
24 | #if ENABLE_DNS |
28 | #if ENABLE_DNS |
25 | |
29 | |
… | |
… | |
47 | #include "vpn.h" |
51 | #include "vpn.h" |
48 | |
52 | |
49 | #define MAX_POLL_INTERVAL 5. // how often to poll minimally when the server has no data |
53 | #define MAX_POLL_INTERVAL 5. // how often to poll minimally when the server has no data |
50 | #define ACTIVITY_INTERVAL 5. |
54 | #define ACTIVITY_INTERVAL 5. |
51 | |
55 | |
52 | #define TIMEOUT_FACTOR 2. |
|
|
53 | |
|
|
54 | #define INITIAL_TIMEOUT 0.1 // retry timeouts |
56 | #define INITIAL_TIMEOUT 0.1 // retry timeouts |
55 | #define INITIAL_SYN_TIMEOUT 10. // retry timeout for initial syn |
57 | #define INITIAL_SYN_TIMEOUT 2. // retry timeout for initial syn |
56 | |
58 | |
57 | #define MIN_SEND_INTERVAL 0.001 // wait at least this time between sending requests |
|
|
58 | #define MAX_SEND_INTERVAL 2. // optimistic? |
59 | #define MAX_SEND_INTERVAL 2. // optimistic? |
59 | |
60 | |
60 | #define LATENCY_FACTOR 0.5 // RTT * LATENCY_FACTOR == sending rate |
|
|
61 | #define MAX_OUTSTANDING 100 // max. outstanding requests |
|
|
62 | #define MAX_WINDOW 1000 // max. for MAX_OUTSTANDING, and backlog |
61 | #define MAX_WINDOW 1000 // max. for MAX_OUTSTANDING, and backlog |
63 | #define MAX_BACKLOG (32*1024) // size of gvpe protocol backlog (bytes), must be > MAXSIZE |
62 | #define MAX_BACKLOG (64*1024) // size of gvpe protocol backlog (bytes), must be > MAXSIZE |
64 | |
63 | |
65 | #define MAX_DOMAIN_SIZE 240 // 255 is legal limit, but bind doesn't compress well |
64 | #define MAX_DOMAIN_SIZE 240 // 255 is legal limit, but bind doesn't compress well |
66 | // 240 leaves about 4 bytes of server reply data |
65 | // 240 leaves about 4 bytes of server reply data |
67 | // every request byte less give room for two reply bytes |
66 | // every request byte less give room for two reply bytes |
68 | |
67 | |
… | |
… | |
462 | r4 = r5 = r6 = r7 = 0; |
461 | r4 = r5 = r6 = r7 = 0; |
463 | } |
462 | } |
464 | |
463 | |
465 | bool dns_cfg::valid () |
464 | bool dns_cfg::valid () |
466 | { |
465 | { |
|
|
466 | // although the protocol itself allows for some configurability, |
|
|
467 | // only the following encoding/decoding settings are implemented. |
467 | return id1 == 'G' |
468 | return id1 == 'G' |
468 | && id2 == 'V' |
469 | && id2 == 'V' |
469 | && id3 == 'P' |
470 | && id3 == 'P' |
470 | && id4 == 'E' |
471 | && id4 == 'E' |
471 | && seq_cdc == 26 |
472 | && seq_cdc == 26 |
… | |
… | |
1033 | double latency = NOW - (*i)->sent; |
1034 | double latency = NOW - (*i)->sent; |
1034 | |
1035 | |
1035 | if (latency < dns->min_latency) |
1036 | if (latency < dns->min_latency) |
1036 | dns->min_latency = latency; |
1037 | dns->min_latency = latency; |
1037 | |
1038 | |
1038 | if (dns->send_interval > dns->min_latency * LATENCY_FACTOR) |
1039 | if (dns->send_interval > dns->min_latency * conf.dns_overlap_factor) |
1039 | dns->send_interval = dns->min_latency * LATENCY_FACTOR; |
1040 | dns->send_interval = dns->min_latency * conf.dns_overlap_factor; |
1040 | |
1041 | |
1041 | if (dns->send_interval < MIN_SEND_INTERVAL) |
1042 | if (dns->send_interval < conf.dns_send_interval) |
1042 | dns->send_interval = MIN_SEND_INTERVAL; |
1043 | dns->send_interval = conf.dns_send_interval; |
1043 | } |
1044 | } |
1044 | |
1045 | |
1045 | delete *i; |
1046 | delete *i; |
1046 | dns_sndpq.erase (i); |
1047 | dns_sndpq.erase (i); |
1047 | |
1048 | |
… | |
… | |
1228 | if (!send) |
1229 | if (!send) |
1229 | { |
1230 | { |
1230 | send = r; |
1231 | send = r; |
1231 | |
1232 | |
1232 | r->retry++; |
1233 | r->retry++; |
1233 | r->timeout = NOW + (r->retry * min_latency * TIMEOUT_FACTOR); |
1234 | r->timeout = NOW + (r->retry * min_latency * conf.dns_timeout_factor); |
1234 | |
1235 | |
1235 | // the following code changes the query section a bit, forcing |
1236 | // the following code changes the query section a bit, forcing |
1236 | // the forwarder to generate a new request |
1237 | // the forwarder to generate a new request |
1237 | if (r->stdhdr) |
1238 | if (r->stdhdr) |
1238 | { |
1239 | { |
… | |
… | |
1257 | |
1258 | |
1258 | cfg.reset (THISNODE->id); |
1259 | cfg.reset (THISNODE->id); |
1259 | send->gen_syn_req (); |
1260 | send->gen_syn_req (); |
1260 | } |
1261 | } |
1261 | } |
1262 | } |
1262 | else if (vpn->dns_sndpq.size () < MAX_OUTSTANDING |
1263 | else if (vpn->dns_sndpq.size () < conf.dns_max_outstanding |
1263 | && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1))) |
1264 | && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1))) |
1264 | { |
1265 | { |
1265 | if (last_sent + send_interval <= NOW) |
1266 | if (last_sent + send_interval <= NOW) |
1266 | { |
1267 | { |
1267 | //printf ("sending data request etc.\n"); //D |
1268 | //printf ("sending data request etc.\n"); //D |
… | |
… | |
1271 | NEXT (NOW + send_interval); |
1272 | NEXT (NOW + send_interval); |
1272 | } |
1273 | } |
1273 | |
1274 | |
1274 | send = new dns_snd (this); |
1275 | send = new dns_snd (this); |
1275 | send->gen_stream_req (sndseq, snddq); |
1276 | send->gen_stream_req (sndseq, snddq); |
1276 | send->timeout = NOW + min_latency * TIMEOUT_FACTOR; |
1277 | send->timeout = NOW + min_latency * conf.dns_timeout_factor; |
1277 | |
1278 | |
1278 | sndseq = (sndseq + 1) & SEQNO_MASK; |
1279 | sndseq = (sndseq + 1) & SEQNO_MASK; |
1279 | } |
1280 | } |
1280 | else |
1281 | else |
1281 | NEXT (last_sent + send_interval); |
1282 | NEXT (last_sent + send_interval); |
… | |
… | |
1297 | poll_interval, send_interval, next - NOW, |
1298 | poll_interval, send_interval, next - NOW, |
1298 | vpn->dns_sndpq.size (), snddq.size (), |
1299 | vpn->dns_sndpq.size (), snddq.size (), |
1299 | rcvpq.size ()); |
1300 | rcvpq.size ()); |
1300 | |
1301 | |
1301 | // TODO: no idea when this happens, but when next < NOW, we have a problem |
1302 | // TODO: no idea when this happens, but when next < NOW, we have a problem |
|
|
1303 | // doesn't seem to happen anymore |
1302 | if (next < NOW + 0.001) |
1304 | if (next < NOW + 0.001) |
1303 | next = NOW + 0.1; |
1305 | next = NOW + 0.1; |
1304 | |
1306 | |
1305 | w.start (next); |
1307 | w.start (next); |
1306 | } |
1308 | } |