… | |
… | |
50 | #define ACTIVITY_INTERVAL 5. |
50 | #define ACTIVITY_INTERVAL 5. |
51 | |
51 | |
52 | #define INITIAL_TIMEOUT 1. |
52 | #define INITIAL_TIMEOUT 1. |
53 | #define INITIAL_SYN_TIMEOUT 2. |
53 | #define INITIAL_SYN_TIMEOUT 2. |
54 | |
54 | |
55 | #define MIN_SEND_INTERVAL (1./1000.) |
55 | #define MIN_SEND_INTERVAL 0.001 |
56 | #define MAX_SEND_INTERVAL 0.5 // optimistic? |
56 | #define MAX_SEND_INTERVAL 0.5 // optimistic? |
57 | |
57 | |
58 | #define MAX_OUTSTANDING 400 // max. outstanding requests |
58 | #define MAX_OUTSTANDING 400 // max. outstanding requests |
59 | #define MAX_WINDOW 1000 // max. for MAX_OUTSTANDING |
59 | #define MAX_WINDOW 1000 // max. for MAX_OUTSTANDING |
60 | #define MAX_RATE 100 // requests/s |
|
|
61 | #define MAX_BACKLOG (100*1024) // size of protocol backlog, must be > MAXSIZE |
60 | #define MAX_BACKLOG (100*1024) // size of protocol backlog, must be > MAXSIZE |
62 | |
61 | |
63 | #define MAX_DOMAIN_SIZE 220 // 255 is legal limit, but bind doesn't compress well |
62 | #define MAX_DOMAIN_SIZE 220 // 255 is legal limit, but bind doesn't compress well |
64 | // 240 leaves about 4 bytes of server reply data |
63 | // 240 leaves about 4 bytes of server reply data |
65 | // every two request byte sless give room for one reply byte |
64 | // every two request byte sless give room for one reply byte |
… | |
… | |
501 | tstamp timeout, sent; |
500 | tstamp timeout, sent; |
502 | int retry; |
501 | int retry; |
503 | struct dns_connection *dns; |
502 | struct dns_connection *dns; |
504 | int seqno; |
503 | int seqno; |
505 | |
504 | |
506 | dns_snd (dns_connection *dns); |
|
|
507 | void gen_stream_req (int seqno, byte_stream &stream); |
505 | void gen_stream_req (int seqno, byte_stream &stream); |
508 | void gen_syn_req (const dns_cfg &cfg); |
506 | void gen_syn_req (const dns_cfg &cfg); |
|
|
507 | |
|
|
508 | dns_snd (dns_connection *dns); |
|
|
509 | ~dns_snd (); |
509 | }; |
510 | }; |
510 | |
511 | |
511 | static u16 dns_id = 12098; // TODO: should be per-vpn |
512 | static u16 dns_id = 12098; // TODO: should be per-vpn |
512 | |
513 | |
513 | static u16 next_id () |
514 | static u16 next_id () |
… | |
… | |
526 | : dns (dns) |
527 | : dns (dns) |
527 | { |
528 | { |
528 | timeout = 0; |
529 | timeout = 0; |
529 | retry = 0; |
530 | retry = 0; |
530 | seqno = 0; |
531 | seqno = 0; |
|
|
532 | sent = NOW; |
531 | |
533 | |
532 | pkt = new dns_packet; |
534 | pkt = new dns_packet; |
533 | |
535 | |
534 | pkt->id = next_id (); |
536 | pkt->id = next_id (); |
|
|
537 | } |
|
|
538 | |
|
|
539 | dns_snd::~dns_snd () |
|
|
540 | { |
|
|
541 | delete pkt; |
535 | } |
542 | } |
536 | |
543 | |
537 | static void append_domain (dns_packet &pkt, int &offs, const char *domain) |
544 | static void append_domain (dns_packet &pkt, int &offs, const char *domain) |
538 | { |
545 | { |
539 | // add tunnel domain |
546 | // add tunnel domain |
… | |
… | |
749 | { |
756 | { |
750 | sockinfo si; |
757 | sockinfo si; |
751 | si.host = 0; si.port = 0; si.prot = PROT_DNSv4; |
758 | si.host = 0; si.port = 0; si.prot = PROT_DNSv4; |
752 | |
759 | |
753 | vpn->recv_vpn_packet (pkt, si); |
760 | vpn->recv_vpn_packet (pkt, si); |
|
|
761 | |
|
|
762 | delete pkt; |
754 | } |
763 | } |
755 | |
764 | |
756 | // check for further packets |
765 | // check for further packets |
757 | goto redo; |
766 | goto redo; |
758 | } |
767 | } |
… | |
… | |
831 | dns->receive_rep (rcv); |
840 | dns->receive_rep (rcv); |
832 | } |
841 | } |
833 | |
842 | |
834 | pkt [offs++] = 0xc0; pkt [offs++] = 6 * 2; // refer to name in query section |
843 | pkt [offs++] = 0xc0; pkt [offs++] = 6 * 2; // refer to name in query section |
835 | |
844 | |
836 | // type |
|
|
837 | int rtype = dns ? dns->cfg.rrtype : RR_TYPE_A; |
845 | int rtype = dns ? dns->cfg.rrtype : RR_TYPE_A; |
838 | pkt [offs++] = rtype >> 8; pkt [offs++] = rtype; |
846 | pkt [offs++] = rtype >> 8; pkt [offs++] = rtype; // type |
839 | |
|
|
840 | // class |
|
|
841 | pkt [offs++] = RR_CLASS_IN >> 8; pkt [offs++] = RR_CLASS_IN; |
847 | pkt [offs++] = RR_CLASS_IN >> 8; pkt [offs++] = RR_CLASS_IN; // class |
842 | |
|
|
843 | // TTL |
|
|
844 | pkt [offs++] = 0; pkt [offs++] = 0; |
848 | pkt [offs++] = 0; pkt [offs++] = 0; |
845 | pkt [offs++] = 0; pkt [offs++] = dns ? dns->cfg.def_ttl : 0; |
849 | pkt [offs++] = 0; pkt [offs++] = dns ? dns->cfg.def_ttl : 0; // TTL |
846 | |
850 | |
847 | int rdlen_offs = offs += 2; |
851 | int rdlen_offs = offs += 2; |
848 | |
852 | |
849 | int dlen = (dns ? ntohs (dns->cfg.max_size) : MAX_PKT_SIZE) - offs; |
853 | int dlen = (dns ? ntohs (dns->cfg.max_size) : MAX_PKT_SIZE) - offs; |
850 | // bind doesn't compress well, so reduce further by one label length |
854 | // bind doesn't compress well, so reduce further by one label length |
… | |
… | |
1143 | |
1147 | |
1144 | r->retry++; |
1148 | r->retry++; |
1145 | r->timeout = NOW + r->retry; |
1149 | r->timeout = NOW + r->retry; |
1146 | } |
1150 | } |
1147 | } |
1151 | } |
1148 | else if (r->timeout < next) |
1152 | else |
1149 | NEXT (r->timeout); |
1153 | NEXT (r->timeout); |
1150 | } |
1154 | } |
1151 | |
1155 | |
1152 | if (last_sent + send_interval <= NOW) |
1156 | if (last_sent + send_interval <= NOW) |
1153 | { |
1157 | { |
… | |
… | |
1177 | vpn->dns_sndpq.push_back (send); |
1181 | vpn->dns_sndpq.push_back (send); |
1178 | } |
1182 | } |
1179 | |
1183 | |
1180 | if (send) |
1184 | if (send) |
1181 | { |
1185 | { |
1182 | printf ("send pkt\n"); |
|
|
1183 | last_sent = NOW; |
1186 | last_sent = NOW; |
1184 | |
|
|
1185 | if (!send->retry) |
|
|
1186 | send->sent = NOW; |
|
|
1187 | |
1187 | |
1188 | sendto (vpn->dnsv4_fd, |
1188 | sendto (vpn->dnsv4_fd, |
1189 | send->pkt->at (0), send->pkt->len, 0, |
1189 | send->pkt->at (0), send->pkt->len, 0, |
1190 | vpn->dns_forwarder.sav4 (), vpn->dns_forwarder.salenv4 ()); |
1190 | vpn->dns_forwarder.sav4 (), vpn->dns_forwarder.salenv4 ()); |
1191 | } |
1191 | } |
1192 | } |
1192 | } |
1193 | else |
1193 | else |
1194 | NEXT (last_sent + send_interval); |
1194 | NEXT (last_sent + send_interval); |
1195 | |
1195 | |
1196 | printf ("pi %f si %f N %f (%d:%d)\n", poll_interval, send_interval, next - NOW, vpn->dns_sndpq.size (), snddq.size ()); |
1196 | //printf ("pi %f si %f N %f (%d:%d)\n", poll_interval, send_interval, next - NOW, vpn->dns_sndpq.size (), snddq.size ()); |
|
|
1197 | |
|
|
1198 | // TODO: no idea when this happens, but when next < NOW, we have a problem |
|
|
1199 | if (next < NOW + 0.0001) |
|
|
1200 | next = NOW + 0.1; |
1197 | |
1201 | |
1198 | w.start (next); |
1202 | w.start (next); |
1199 | } |
1203 | } |
1200 | |
1204 | |
1201 | #endif |
1205 | #endif |