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

Allow user to specify socket type per ip-addres #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 38 additions & 17 deletions configlexer.lex
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ COMMENT \#
COLON \:
ANY [^\"\n\r\\]|\\.

%s ip_address
%x quotedstring include include_quoted

%%
{SPACE}* { LEXOUT(("SP ")); /* ignore */ }
{SPACE}*{COMMENT}.* { LEXOUT(("comment(%s) ", yytext)); /* ignore */ }
server{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_SERVER;}
name{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_NAME;}
ip-address{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_IP_ADDRESS;}
interface{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_IP_ADDRESS;}
ip-transparent{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_IP_TRANSPARENT;}
ip-freebind{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_IP_FREEBIND;}
Expand Down Expand Up @@ -299,24 +299,42 @@ cookie-secret{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_COOKIE_SECRET;}
cookie-secret-file{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_COOKIE_SECRET_FILE;}
xfrd-tcp-max{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_XFRD_TCP_MAX;}
xfrd-tcp-pipeline{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_XFRD_TCP_PIPELINE;}
{NEWLINE} { LEXOUT(("NL\n")); cfg_parser->line++;}

servers={UNQUOTEDLETTER}* {
ip-address{COLON} {
BEGIN(ip_address);
LEXOUT(("v(%s) ", yytext));
return VAR_IP_ADDRESS;
}
<ip_address>tcp {
LEXOUT(("v(%s) ", yytext));
return VAR_TCP;
}
<ip_address>udp {
LEXOUT(("v(%s) ", yytext));
return VAR_UDP;
}
<ip_address>servers={UNQUOTEDLETTER}* {
yyless(yyleng - (yyleng - 8));
LEXOUT(("v(%s) ", yytext));
return VAR_SERVERS;
}
bindtodevice={UNQUOTEDLETTER}* {
<ip_address>bindtodevice={UNQUOTEDLETTER}* {
yyless(yyleng - (yyleng - 13));
LEXOUT(("v(%s) ", yytext));
return VAR_BINDTODEVICE;
}
setfib={UNQUOTEDLETTER}* {
<ip_address>setfib={UNQUOTEDLETTER}* {
yyless(yyleng - (yyleng - 7));
LEXOUT(("v(%s) ", yytext));
return VAR_SETFIB;
}

{NEWLINE} {
BEGIN(INITIAL);
LEXOUT(("NL\n"));
cfg_parser->line++;
}

cpu-affinity{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_CPU_AFFINITY; }
xfrd-cpu-affinity{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_XFRD_CPU_AFFINITY; }
server-[1-9][0-9]*-cpu-affinity{COLON} {
Expand All @@ -333,24 +351,24 @@ server-[1-9][0-9]*-cpu-affinity{COLON} {
/* Quoted strings. Strip leading and ending quotes */
\" { BEGIN(quotedstring); LEXOUT(("QS ")); }
<quotedstring><<EOF>> {
c_error("EOF inside quoted string");
BEGIN(INITIAL);
c_error("EOF inside quoted string");
BEGIN(INITIAL);
}
<quotedstring>{ANY}* { LEXOUT(("STR(%s) ", yytext)); yymore(); }
<quotedstring>\n { cfg_parser->line++; yymore(); }
<quotedstring>\" {
LEXOUT(("QE "));
BEGIN(INITIAL);
yytext[yyleng - 1] = '\0';
LEXOUT(("QE "));
BEGIN(INITIAL);
yytext[yyleng - 1] = '\0';
c_lval.str = region_strdup(cfg_parser->opt->region, yytext);
return STRING;
return STRING;
}

/* include: directive */
include{COLON} { LEXOUT(("v(%s) ", yytext)); BEGIN(include); }
<include><<EOF>> {
c_error("EOF inside include directive");
BEGIN(INITIAL);
c_error("EOF inside include directive");
BEGIN(INITIAL);
}
<include>{SPACE}* { LEXOUT(("ISP ")); /* ignore */ }
<include>{NEWLINE} { LEXOUT(("NL\n")); cfg_parser->line++;}
Expand All @@ -361,8 +379,8 @@ include{COLON} { LEXOUT(("v(%s) ", yytext)); BEGIN(include); }
BEGIN(INITIAL);
}
<include_quoted><<EOF>> {
c_error("EOF inside quoted string");
BEGIN(INITIAL);
c_error("EOF inside quoted string");
BEGIN(INITIAL);
}
<include_quoted>{ANY}* { LEXOUT(("ISTR(%s) ", yytext)); yymore(); }
<include_quoted>{NEWLINE} { cfg_parser->line++; yymore(); }
Expand All @@ -382,7 +400,10 @@ include{COLON} { LEXOUT(("v(%s) ", yytext)); BEGIN(include); }
}
}

{UNQUOTEDLETTER}* { LEXOUT(("unquotedstr(%s) ", yytext));
c_lval.str = region_strdup(cfg_parser->opt->region, yytext); return STRING; }
{UNQUOTEDLETTER}* {
LEXOUT(("unquotedstr(%s) ", yytext));
c_lval.str = region_strdup(cfg_parser->opt->region, yytext);
return STRING;
}

%%
24 changes: 24 additions & 0 deletions configparser.y
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ static int parse_range(const char *str, long long *low, long long *high);
%token VAR_ALLOW_QUERY
%token VAR_AXFR
%token VAR_UDP
%token VAR_TCP
%token VAR_NOTIFY_RETRY
%token VAR_ALLOW_NOTIFY
%token VAR_REQUEST_XFR
Expand Down Expand Up @@ -226,6 +227,7 @@ server_option:

cfg_parser->ip = $2;
}
socket_types
socket_options
{
cfg_parser->ip = NULL;
Expand Down Expand Up @@ -494,6 +496,26 @@ server_option:
}
;

socket_types:
| udp_and_tcp
{ cfg_parser->ip->udp = 1;
cfg_parser->ip->tcp = 1;
}
| VAR_UDP
{ cfg_parser->ip->tcp = 0;
cfg_parser->ip->udp = 1;
}
| VAR_TCP
{ cfg_parser->ip->tcp = 1;
cfg_parser->ip->udp = 0;
}
;

udp_and_tcp:
VAR_UDP VAR_TCP
| VAR_TCP VAR_UDP
;

socket_options:
| socket_options socket_option ;

Expand Down Expand Up @@ -971,6 +993,8 @@ ip_address:
cfg_parser->opt->region, sizeof(*ip));
ip->address = region_strdup(cfg_parser->opt->region, $1);
ip->fib = -1;
ip->udp = 2;
ip->tcp = 2;
$$ = ip;
} ;

Expand Down
4 changes: 2 additions & 2 deletions ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ child_handle_parent_command(int fd, short event, void* arg)
break;
case NSD_QUIT_CHILD:
/* close our listening sockets and ack */
server_close_all_sockets(data->nsd->udp, data->nsd->ifs);
server_close_all_sockets(data->nsd->tcp, data->nsd->ifs);
server_close_all_sockets(&data->nsd->udp);
server_close_all_sockets(&data->nsd->tcp);
/* mode == NSD_QUIT_CHILD */
if(write(fd, &mode, sizeof(mode)) == -1) {
VERBOSITY(3, (LOG_INFO, "quit child write: %s",
Expand Down
4 changes: 4 additions & 0 deletions nsd-checkconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,10 @@ config_test_print_server(nsd_options_type* opt)
for(ip = opt->ip_addresses; ip; ip=ip->next)
{
printf("\tip-address: %s", ip->address);
if(ip->udp == 1)
printf(" udp");
if(ip->tcp == 1)
printf(" tcp");
if(ip->servers) {
const char *sep;
struct range_option *n;
Expand Down
Loading