Skip to content

Commit

Permalink
- For #145: Fix that service of remaining TCP and TLS connections
Browse files Browse the repository at this point in the history
  does not allow new queries to be made, the connection is closed.
  Only existing queries and zone transfers are answered, new ones
  are rejected by a close of the channel.
  • Loading branch information
wcawijngaards committed Dec 3, 2020
1 parent ce23089 commit 696d35a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
6 changes: 6 additions & 0 deletions doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
3 December 2020: Wouter
- For #145: Fix that service of remaining TCP and TLS connections
does not allow new queries to be made, the connection is closed.
Only existing queries and zone transfers are answered, new ones
are rejected by a close of the channel.

30 November 2020: Wouter
- Fix #144: fix better.

Expand Down
4 changes: 4 additions & 0 deletions doc/RELNOTES
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ FEATURES:
BUG FIXES:
- Fix #143: xfrd no hysteresis with NOT IMPLEMENTED rcode.
- Fix #144: Typo fix in nsd.conf.5.in.
- For #145: Fix that service of remaining TCP and TLS connections
does not allow new queries to be made, the connection is closed.
Only existing queries and zone transfers are answered, new ones
are rejected by a close of the channel.


4.3.4
Expand Down
27 changes: 19 additions & 8 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ struct tcp_handler_data
* The timeout in msec for this tcp connection
*/
int tcp_timeout;

/*
* If the connection is allowed to have further queries on it.
*/
int tcp_no_more_queries;
#ifdef HAVE_SSL
/*
* TLS object.
Expand Down Expand Up @@ -3096,6 +3101,7 @@ service_remaining_tcp(struct nsd* nsd)
}
#endif

p->tcp_no_more_queries = 1;
/* set timeout to 1/10 second */
if(p->tcp_timeout > 100)
p->tcp_timeout = 100;
Expand Down Expand Up @@ -3487,8 +3493,9 @@ handle_tcp_reading(int fd, short event, void* arg)
return;
}

if (data->nsd->tcp_query_count > 0 &&
data->query_count >= data->nsd->tcp_query_count) {
if ((data->nsd->tcp_query_count > 0 &&
data->query_count >= data->nsd->tcp_query_count) ||
data->tcp_no_more_queries) {
/* No more queries allowed on this tcp connection. */
cleanup_tcp_handler(data);
return;
Expand Down Expand Up @@ -3840,8 +3847,9 @@ handle_tcp_writing(int fd, short event, void* arg)
* Done sending, wait for the next request to arrive on the
* TCP socket by installing the TCP read handler.
*/
if (data->nsd->tcp_query_count > 0 &&
data->query_count >= data->nsd->tcp_query_count) {
if ((data->nsd->tcp_query_count > 0 &&
data->query_count >= data->nsd->tcp_query_count) ||
data->tcp_no_more_queries) {

(void) shutdown(fd, SHUT_WR);
}
Expand Down Expand Up @@ -3965,8 +3973,9 @@ handle_tls_reading(int fd, short event, void* arg)
return;
}

if (data->nsd->tcp_query_count > 0 &&
data->query_count >= data->nsd->tcp_query_count) {
if ((data->nsd->tcp_query_count > 0 &&
data->query_count >= data->nsd->tcp_query_count) ||
data->tcp_no_more_queries) {
/* No more queries allowed on this tcp connection. */
cleanup_tcp_handler(data);
return;
Expand Down Expand Up @@ -4280,8 +4289,9 @@ handle_tls_writing(int fd, short event, void* arg)
* Done sending, wait for the next request to arrive on the
* TCP socket by installing the TCP read handler.
*/
if (data->nsd->tcp_query_count > 0 &&
data->query_count >= data->nsd->tcp_query_count) {
if ((data->nsd->tcp_query_count > 0 &&
data->query_count >= data->nsd->tcp_query_count) ||
data->tcp_no_more_queries) {

(void) shutdown(fd, SHUT_WR);
}
Expand Down Expand Up @@ -4426,6 +4436,7 @@ handle_tcp_accept(int fd, short event, void* arg)
memcpy(&tcp_data->query->addr, &addr, addrlen);
tcp_data->query->addrlen = addrlen;

tcp_data->tcp_no_more_queries = 0;
tcp_data->tcp_timeout = data->nsd->tcp_timeout * 1000;
if (data->nsd->current_tcp_count > data->nsd->maximum_tcp_count/2) {
/* very busy, give smaller timeout */
Expand Down

0 comments on commit 696d35a

Please sign in to comment.