Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for connection re-use by secondary for XFR #145

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@
.cproject
.project
.settings/

# Separate build directory
build/*
2 changes: 2 additions & 0 deletions configlexer.lex
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ tcp-count{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_TCP_COUNT;}
tcp-reject-overflow{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_TCP_REJECT_OVERFLOW;}
tcp-query-count{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_TCP_QUERY_COUNT;}
tcp-timeout{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_TCP_TIMEOUT;}
tcp-idle-timeout{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_TCP_IDLE_TIMEOUT;}
tcp-mss{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_TCP_MSS;}
outgoing-tcp-mss{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_OUTGOING_TCP_MSS;}
ipv4-edns-size{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_IPV4_EDNS_SIZE;}
Expand All @@ -241,6 +242,7 @@ difffile{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_DIFFFILE;}
xfrdfile{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_XFRDFILE;}
xfrdir{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_XFRDIR;}
xfrd-reload-timeout{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_XFRD_RELOAD_TIMEOUT;}
xfrd-conn-reuse{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_XFRD_CONN_REUSE;}
verbosity{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_VERBOSITY;}
zone{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_ZONE;}
zonefile{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_ZONEFILE;}
Expand Down
6 changes: 6 additions & 0 deletions configparser.y
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ static int parse_range(const char *str, long long *low, long long *high);
%token VAR_TCP_REJECT_OVERFLOW
%token VAR_TCP_QUERY_COUNT
%token VAR_TCP_TIMEOUT
%token VAR_TCP_IDLE_TIMEOUT
%token VAR_TCP_MSS
%token VAR_OUTGOING_TCP_MSS
%token VAR_IPV4_EDNS_SIZE
%token VAR_IPV6_EDNS_SIZE
%token VAR_STATISTICS
%token VAR_XFRD_RELOAD_TIMEOUT
%token VAR_XFRD_CONN_REUSE
%token VAR_LOG_TIME_ASCII
%token VAR_ROUND_ROBIN
%token VAR_MINIMAL_RESPONSES
Expand Down Expand Up @@ -310,6 +312,8 @@ server_option:
{ cfg_parser->opt->tcp_query_count = (int)$2; }
| VAR_TCP_TIMEOUT number
{ cfg_parser->opt->tcp_timeout = (int)$2; }
| VAR_TCP_IDLE_TIMEOUT number
{ cfg_parser->opt->tcp_idle_timeout = (int)$2; }
| VAR_TCP_MSS number
{ cfg_parser->opt->tcp_mss = (int)$2; }
| VAR_OUTGOING_TCP_MSS number
Expand Down Expand Up @@ -347,6 +351,8 @@ server_option:
{ cfg_parser->opt->xfrdir = region_strdup(cfg_parser->opt->region, $2); }
| VAR_XFRD_RELOAD_TIMEOUT number
{ cfg_parser->opt->xfrd_reload_timeout = (int)$2; }
| VAR_XFRD_CONN_REUSE boolean
{ cfg_parser->opt->xfrd_conn_reuse = $2; }
| VAR_VERBOSITY number
{ cfg_parser->opt->verbosity = (int)$2; }
| VAR_RRL_SIZE number
Expand Down
10 changes: 10 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,16 @@ AC_ARG_WITH([tcp_timeout],
[tcp_timeout=$withval])
AC_DEFINE_UNQUOTED([TCP_TIMEOUT], $tcp_timeout, [Define to the default tcp timeout.])

dnl
dnl Determine the default tcp idle timeout (used when closing outgoing XFR TCP connections)
dnl
tcp_idle_timeout=10
AC_ARG_WITH([tcp_idle_timeout],
AC_HELP_STRING([--with-tcp-idle-timeout=number], [Limit the default tcp idle timeout, used when closing outgoing XFR TCP connections when xfrd-conn-resuse option is enabled]),
[tcp_idle_timeout=$withval])
AC_DEFINE_UNQUOTED([TCP_IDLE_TIMEOUT], $tcp_idle_timeout, [Define to the default tcp idle timeout.])


dnl
dnl Features
dnl
Expand Down
4 changes: 4 additions & 0 deletions nsd-checkconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,14 @@ config_print_zone(nsd_options_type* opt, const char* k, int s, const char *o,
SERV_GET_INT(tcp_count, o);
SERV_GET_INT(tcp_query_count, o);
SERV_GET_INT(tcp_timeout, o);
SERV_GET_INT(tcp_idle_timeout, o);
SERV_GET_INT(tcp_mss, o);
SERV_GET_INT(outgoing_tcp_mss, o);
SERV_GET_INT(ipv4_edns_size, o);
SERV_GET_INT(ipv6_edns_size, o);
SERV_GET_INT(statistics, o);
SERV_GET_INT(xfrd_reload_timeout, o);
SERV_GET_BIN(xfrd_conn_reuse, o);
SERV_GET_INT(verbosity, o);
SERV_GET_INT(send_buffer_size, o);
SERV_GET_INT(receive_buffer_size, o);
Expand Down Expand Up @@ -547,6 +549,7 @@ config_test_print_server(nsd_options_type* opt)
printf("\ttcp-count: %d\n", opt->tcp_count);
printf("\ttcp-query-count: %d\n", opt->tcp_query_count);
printf("\ttcp-timeout: %d\n", opt->tcp_timeout);
printf("\ttcp-idle-timeout: %d\n", opt->tcp_idle_timeout);
printf("\ttcp-mss: %d\n", opt->tcp_mss);
printf("\toutgoing-tcp-mss: %d\n", opt->outgoing_tcp_mss);
printf("\tipv4-edns-size: %d\n", (int) opt->ipv4_edns_size);
Expand All @@ -561,6 +564,7 @@ config_test_print_server(nsd_options_type* opt)
print_string_var("zonelistfile:", opt->zonelistfile);
print_string_var("xfrdir:", opt->xfrdir);
printf("\txfrd-reload-timeout: %d\n", opt->xfrd_reload_timeout);
printf("\txfrd-conn-reuse: %s\n", opt->xfrd_conn_reuse?"yes":"no");
printf("\tlog-time-ascii: %s\n", opt->log_time_ascii?"yes":"no");
printf("\tround-robin: %s\n", opt->round_robin?"yes":"no");
printf("\tminimal-responses: %s\n", opt->minimal_responses?"yes":"no");
Expand Down
2 changes: 2 additions & 0 deletions nsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,8 @@ main(int argc, char *argv[])
nsd.maximum_tcp_count = nsd.options->tcp_count;
}
nsd.tcp_timeout = nsd.options->tcp_timeout;
nsd.tcp_idle_timeout = nsd.options->tcp_idle_timeout;
nsd.xfrd_conn_reuse = nsd.options->xfrd_conn_reuse;
nsd.tcp_query_count = nsd.options->tcp_query_count;
nsd.tcp_mss = nsd.options->tcp_mss;
nsd.outgoing_tcp_mss = nsd.options->outgoing_tcp_mss;
Expand Down
11 changes: 11 additions & 0 deletions nsd.conf.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ Default is 0, meaning there is no maximum.
Overrides the default TCP timeout. This also affects zone transfers over TCP.
The default is 120 seconds.
.TP
.B tcp\-idle\-timeout:\fR <number>
Overrides the default TCP idle timeout. This is used when closing outgoing
TCP connections used for zone transfers when the xfrd\-conn\-reuse option is enabled.
The default is 10 seconds.
.TP
.B tcp-mss:\fR <number>
Maximum segment size (MSS) of TCP socket on which the server responds
to queries. Value lower than common MSS on Ethernet
Expand Down Expand Up @@ -370,6 +375,12 @@ transfer, then it will wait for the number of seconds before it will
trigger a new reload. Setting this value throttles the reloads to
once per the number of seconds. The default is 1 second.
.TP
.B xfrd\-conn\-reuse:\fR <yes or no>
When making outgoing XFR requests to the same master an open TCP connection
will be used in preference to opening a new connection for each request.
After all transfers complete, connections will be left open for
tcp\-idle\-timeout seconds to increase the chance of reuse. Default is no.
.TP
.B verbosity:\fR <level>
This value specifies the verbosity level for (non\-debug) logging.
Default is 0. 1 gives more information about incoming notifies and
Expand Down
8 changes: 8 additions & 0 deletions nsd.conf.sample.in
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ server:
# Override the default (120 seconds) TCP timeout.
# tcp-timeout: 120

# Override the default (10 seconds) TCP idle timeout, used when
# closing outgoing XFR TCP connections when xfrd-conn-reuse is enabled.
# tcp-idle-timeout: 10

# Maximum segment size (MSS) of TCP socket on which the server
# responds to queries. Default is 0, system default MSS.
# tcp-mss: 0
Expand All @@ -187,6 +191,10 @@ server:
# Number of seconds between reloads triggered by xfrd.
# xfrd-reload-timeout: 1

# Prefer to reuse open connections to a master instead of opening
# a new connection for each transfer request to that master.
# xfrd-conn-reuse: no

# log timestamp in ascii (y-m-d h:m:s.msec), yes is default.
# log-time-ascii: yes

Expand Down
3 changes: 3 additions & 0 deletions nsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ struct nsd
int current_tcp_count;
int tcp_query_count;
int tcp_timeout;
int tcp_idle_timeout;
int xfrd_conn_reuse;

int tcp_mss;
int outgoing_tcp_mss;
size_t ipv4_edns_size;
Expand Down
2 changes: 2 additions & 0 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ nsd_options_create(region_type* region)
opt->tcp_reject_overflow = 0;
opt->tcp_query_count = 0;
opt->tcp_timeout = TCP_TIMEOUT;
opt->tcp_idle_timeout = TCP_IDLE_TIMEOUT;
opt->tcp_mss = 0;
opt->outgoing_tcp_mss = 0;
opt->ipv4_edns_size = EDNS_MAX_MESSAGE_LEN;
Expand Down Expand Up @@ -122,6 +123,7 @@ nsd_options_create(region_type* region)
opt->zonefiles_write = ZONEFILES_WRITE_INTERVAL;
else opt->zonefiles_write = 0;
opt->xfrd_reload_timeout = 1;
opt->xfrd_conn_reuse = 0;
opt->tls_service_key = NULL;
opt->tls_service_ocsp = NULL;
opt->tls_service_pem = NULL;
Expand Down
2 changes: 2 additions & 0 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ struct nsd_options {
int confine_to_zone;
int tcp_query_count;
int tcp_timeout;
int tcp_idle_timeout;
int tcp_mss;
int outgoing_tcp_mss;
size_t ipv4_edns_size;
Expand All @@ -102,6 +103,7 @@ struct nsd_options {
const char* zonelistfile;
const char* nsid;
int xfrd_reload_timeout;
int xfrd_conn_reuse;
int zonefiles_check;
int zonefiles_write;
int log_time_ascii;
Expand Down
10 changes: 10 additions & 0 deletions tpkg/checkconf.tdir/checkconf.check
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ server:
tcp-count: 100
tcp-query-count: 0
tcp-timeout: 120
tcp-idle-timeout: 10
tcp-mss: 0
outgoing-tcp-mss: 0
ipv4-edns-size: 4096
Expand All @@ -38,6 +39,7 @@ server:
zonelistfile: "/var/db/nsd/zone.list"
xfrdir: "/tmp"
xfrd-reload-timeout: 1
xfrd-conn-reuse: no
log-time-ascii: yes
round-robin: no
minimal-responses: no
Expand Down Expand Up @@ -135,6 +137,7 @@ server:
tcp-count: 100
tcp-query-count: 0
tcp-timeout: 120
tcp-idle-timeout: 10
tcp-mss: 0
outgoing-tcp-mss: 0
ipv4-edns-size: 4096
Expand All @@ -149,6 +152,7 @@ server:
zonelistfile: "/var/db/nsd/zone.list"
xfrdir: "/tmp"
xfrd-reload-timeout: 1
xfrd-conn-reuse: no
log-time-ascii: yes
round-robin: no
minimal-responses: no
Expand Down Expand Up @@ -199,6 +203,7 @@ server:
tcp-count: 100
tcp-query-count: 0
tcp-timeout: 120
tcp-idle-timeout: 10
tcp-mss: 0
outgoing-tcp-mss: 0
ipv4-edns-size: 4096
Expand All @@ -213,6 +218,7 @@ server:
zonelistfile: "/var/db/nsd/zone.list"
xfrdir: "/tmp"
xfrd-reload-timeout: 1
xfrd-conn-reuse: no
log-time-ascii: no
round-robin: no
minimal-responses: no
Expand Down Expand Up @@ -272,6 +278,7 @@ server:
tcp-count: 100
tcp-query-count: 0
tcp-timeout: 120
tcp-idle-timeout: 10
tcp-mss: 0
outgoing-tcp-mss: 0
ipv4-edns-size: 4096
Expand All @@ -286,6 +293,7 @@ server:
zonelistfile: "/var/db/nsd/zone.list"
xfrdir: "/tmp"
xfrd-reload-timeout: 1
xfrd-conn-reuse: no
log-time-ascii: yes
round-robin: no
minimal-responses: no
Expand Down Expand Up @@ -389,6 +397,7 @@ server:
tcp-count: 100
tcp-query-count: 0
tcp-timeout: 120
tcp-idle-timeout: 10
tcp-mss: 0
outgoing-tcp-mss: 0
ipv4-edns-size: 4096
Expand All @@ -403,6 +412,7 @@ server:
zonelistfile: "/var/db/nsd/zone.list"
xfrdir: "/tmp"
xfrd-reload-timeout: 1
xfrd-conn-reuse: no
log-time-ascii: yes
round-robin: no
minimal-responses: no
Expand Down
10 changes: 10 additions & 0 deletions tpkg/checkconf.tdir/checkconf.check2
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ server:
tcp-count: 100
tcp-query-count: 0
tcp-timeout: 120
tcp-idle-timeout: 10
tcp-mss: 0
outgoing-tcp-mss: 0
ipv4-edns-size: 4096
Expand All @@ -38,6 +39,7 @@ server:
zonelistfile: "/var/db/nsd/zone.list"
xfrdir: "/tmp"
xfrd-reload-timeout: 1
xfrd-conn-reuse: no
log-time-ascii: yes
round-robin: no
minimal-responses: no
Expand Down Expand Up @@ -135,6 +137,7 @@ server:
tcp-count: 100
tcp-query-count: 0
tcp-timeout: 120
tcp-idle-timeout: 10
tcp-mss: 0
outgoing-tcp-mss: 0
ipv4-edns-size: 4096
Expand All @@ -149,6 +152,7 @@ server:
zonelistfile: "/var/db/nsd/zone.list"
xfrdir: "/tmp"
xfrd-reload-timeout: 1
xfrd-conn-reuse: no
log-time-ascii: yes
round-robin: no
minimal-responses: no
Expand Down Expand Up @@ -199,6 +203,7 @@ server:
tcp-count: 100
tcp-query-count: 0
tcp-timeout: 120
tcp-idle-timeout: 10
tcp-mss: 0
outgoing-tcp-mss: 0
ipv4-edns-size: 4096
Expand All @@ -213,6 +218,7 @@ server:
zonelistfile: "/var/db/nsd/zone.list"
xfrdir: "/tmp"
xfrd-reload-timeout: 1
xfrd-conn-reuse: no
log-time-ascii: no
round-robin: no
minimal-responses: no
Expand Down Expand Up @@ -272,6 +278,7 @@ server:
tcp-count: 100
tcp-query-count: 0
tcp-timeout: 120
tcp-idle-timeout: 10
tcp-mss: 0
outgoing-tcp-mss: 0
ipv4-edns-size: 4096
Expand All @@ -286,6 +293,7 @@ server:
zonelistfile: "/var/db/nsd/zone.list"
xfrdir: "/tmp"
xfrd-reload-timeout: 1
xfrd-conn-reuse: no
log-time-ascii: yes
round-robin: no
minimal-responses: no
Expand Down Expand Up @@ -389,6 +397,7 @@ server:
tcp-count: 100
tcp-query-count: 0
tcp-timeout: 120
tcp-idle-timeout: 10
tcp-mss: 0
outgoing-tcp-mss: 0
ipv4-edns-size: 4096
Expand All @@ -403,6 +412,7 @@ server:
zonelistfile: "/var/db/nsd/zone.list"
xfrdir: "/tmp"
xfrd-reload-timeout: 1
xfrd-conn-reuse: no
log-time-ascii: yes
round-robin: no
minimal-responses: no
Expand Down
Loading