… | |
… | |
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 | |
… | |
… | |
457 | r4 = r5 = r6 = r7 = 0; |
461 | r4 = r5 = r6 = r7 = 0; |
458 | } |
462 | } |
459 | |
463 | |
460 | bool dns_cfg::valid () |
464 | bool dns_cfg::valid () |
461 | { |
465 | { |
|
|
466 | // although the protocol itself allows for some configurability, |
|
|
467 | // only the following encoding/decoding settings are implemented. |
462 | return id1 == 'G' |
468 | return id1 == 'G' |
463 | && id2 == 'V' |
469 | && id2 == 'V' |
464 | && id3 == 'P' |
470 | && id3 == 'P' |
465 | && id4 == 'E' |
471 | && id4 == 'E' |
466 | && seq_cdc == 26 |
472 | && seq_cdc == 26 |
… | |
… | |
765 | |
771 | |
766 | // find next packet |
772 | // find next packet |
767 | for (vector<dns_rcv *>::iterator i = rcvpq.end (); i-- != rcvpq.begin (); ) |
773 | for (vector<dns_rcv *>::iterator i = rcvpq.end (); i-- != rcvpq.begin (); ) |
768 | if (SEQNO_EQ (rcvseq, (*i)->seqno)) |
774 | if (SEQNO_EQ (rcvseq, (*i)->seqno)) |
769 | { |
775 | { |
|
|
776 | //printf ("seqno eq %x %x\n", rcvseq, (*i)->seqno);//D |
770 | // enter the packet into our input stream |
777 | // enter the packet into our input stream |
771 | r = *i; |
778 | r = *i; |
772 | |
779 | |
773 | // remove the oldest packet, look forward, as it's oldest first |
780 | // remove the oldest packet, look forward, as it's oldest first |
774 | for (vector<dns_rcv *>::iterator j = rcvpq.begin (); j != rcvpq.end (); ++j) |
781 | for (vector<dns_rcv *>::iterator j = rcvpq.begin (); j != rcvpq.end (); ++j) |
775 | if (SEQNO_EQ ((*j)->seqno, rcvseq - MAX_WINDOW)) |
782 | if (SEQNO_EQ ((*j)->seqno, rcvseq - MAX_WINDOW)) |
776 | { |
783 | { |
|
|
784 | //printf ("seqno RR %x %x\n", (*j)->seqno, rcvseq - MAX_WINDOW);//D |
777 | delete *j; |
785 | delete *j; |
778 | rcvpq.erase (j); |
786 | rcvpq.erase (j); |
779 | break; |
787 | break; |
780 | } |
788 | } |
781 | |
789 | |
… | |
… | |
1009 | { |
1017 | { |
1010 | dns_connection *dns = (*i)->dns; |
1018 | dns_connection *dns = (*i)->dns; |
1011 | connection *c = dns->c; |
1019 | connection *c = dns->c; |
1012 | int seqno = (*i)->seqno; |
1020 | int seqno = (*i)->seqno; |
1013 | u8 data[MAXSIZE], *datap = data; |
1021 | u8 data[MAXSIZE], *datap = data; |
|
|
1022 | //printf ("rcv pkt %x\n", seqno);//D |
1014 | |
1023 | |
1015 | if ((*i)->retry) |
1024 | if ((*i)->retry) |
1016 | { |
1025 | { |
1017 | dns->send_interval *= 1.01; |
1026 | dns->send_interval *= 1.01; |
1018 | if (dns->send_interval > MAX_SEND_INTERVAL) |
1027 | if (dns->send_interval > MAX_SEND_INTERVAL) |
… | |
… | |
1224 | { |
1233 | { |
1225 | send = r; |
1234 | send = r; |
1226 | |
1235 | |
1227 | r->retry++; |
1236 | r->retry++; |
1228 | r->timeout = NOW + (r->retry * min_latency * conf.dns_timeout_factor); |
1237 | r->timeout = NOW + (r->retry * min_latency * conf.dns_timeout_factor); |
|
|
1238 | //printf ("RETRY %x (%d, %f)\n", r->seqno, r->retry, r->timeout - NOW);//D |
1229 | |
1239 | |
1230 | // the following code changes the query section a bit, forcing |
1240 | // the following code changes the query section a bit, forcing |
1231 | // the forwarder to generate a new request |
1241 | // the forwarder to generate a new request |
1232 | if (r->stdhdr) |
1242 | if (r->stdhdr) |
1233 | { |
|
|
1234 | //printf ("reencoded header for ID %d retry %d:%d:%d (%p)\n", htons (r->pkt->id), THISNODE->id, r->seqno, r->retry); |
|
|
1235 | //encode_header ((char *)r->pkt->at (6 * 2 + 1), THISNODE->id, r->seqno, r->retry); |
1243 | encode_header ((char *)r->pkt->at (6 * 2 + 1), THISNODE->id, r->seqno, r->retry); |
1236 | } |
|
|
1237 | } |
1244 | } |
1238 | } |
1245 | } |
1239 | else |
1246 | else |
1240 | NEXT (r->timeout); |
1247 | NEXT (r->timeout); |
1241 | } |
1248 | } |
… | |
… | |
1267 | } |
1274 | } |
1268 | |
1275 | |
1269 | send = new dns_snd (this); |
1276 | send = new dns_snd (this); |
1270 | send->gen_stream_req (sndseq, snddq); |
1277 | send->gen_stream_req (sndseq, snddq); |
1271 | send->timeout = NOW + min_latency * conf.dns_timeout_factor; |
1278 | send->timeout = NOW + min_latency * conf.dns_timeout_factor; |
|
|
1279 | //printf ("SEND %x (%f)\n", send->seqno, send->timeout - NOW, min_latency, conf.dns_timeout_factor);//D |
1272 | |
1280 | |
1273 | sndseq = (sndseq + 1) & SEQNO_MASK; |
1281 | sndseq = (sndseq + 1) & SEQNO_MASK; |
1274 | } |
1282 | } |
1275 | else |
1283 | else |
1276 | NEXT (last_sent + send_interval); |
1284 | NEXT (last_sent + send_interval); |