diff --git a/doc/proto_00000800.txt b/doc/proto_00000800.txt index 75eff72..a62c056 100644 --- a/doc/proto_00000800.txt +++ b/doc/proto_00000800.txt @@ -250,7 +250,10 @@ Client sends: The server response to Ping and Data packets is a DNS NULL/TXT/.. type response, always starting with the 3 bytes downstream data header as shown above. If R bit -set, server must respond with a ping downstream header. +set, server must respond with a ping downstream header. This also requires the +server to set its windowsizes to the ones provided. +If the T but is set, the server sets the user's DNS timeout to the value spec- +ified by the packet. A timeout value of 0 implies disabling lazy mode. If server has nothing to send, no data is added after the header. If server has something to send, it will add the downstream data packet (or some fragment of it) after the header. diff --git a/src/server.c b/src/server.c index 5b9de9f..505df98 100644 --- a/src/server.c +++ b/src/server.c @@ -262,8 +262,10 @@ qmem_max_wait(struct dnsfd *dns_fds, int *touser, struct query **sendq) u = &users[userid]; qnum = u->qmem.start_pending; - if (u->qmem.num_pending == 0 || !u->lazy) + if (u->qmem.num_pending == 0) continue; + + /* Keep track of how many fragments we can send */ total = window_sending(u->outgoing); if (u->qmem.num_pending > u->outgoing->windowsize) { @@ -273,6 +275,11 @@ qmem_max_wait(struct dnsfd *dns_fds, int *touser, struct query **sendq) sending = total; sent = 0; + if (!u->lazy && u->qmem.num_pending > 0) { + QMEM_DEBUG(2, userid, "User switched to immediate mode, answering all pending queries..."); + sending = u->qmem.num_pending; + } + for (; qnum != u->qmem.end; qnum = (qnum + 1) % QMEM_LEN) { q = &u->qmem.queries[qnum]; @@ -1697,8 +1704,12 @@ handle_null_request(int tun_fd, int dns_fd, struct dnsfd *dns_fds, struct query respond = unpacked[8] & 1; if ((unpacked[8] >> 3) & 1) { - /* update user's query timeout */ + /* update user's query timeout if timeout flag set */ users[userid].dns_timeout = timeout; + if (timeout_ms == 0) { + /* immediate mode is implied by server timeout of 0 */ + users[userid].lazy = 0; + } } if (debug >= 2) {