New config options.

git-svn-id: file:///svn/unbound/trunk@138 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2007-02-23 11:00:55 +00:00
parent 84053077eb
commit c4d87f4f5d
10 changed files with 72 additions and 10 deletions

View file

@ -240,8 +240,9 @@ worker_init(struct config_file *cfg, struct listen_port* ports,
return NULL; return NULL;
} }
worker->back = outside_network_create(worker->base, worker->back = outside_network_create(worker->base,
buffer_size, (size_t)cfg->outgoing_num_ports, NULL, 0, buffer_size, (size_t)cfg->outgoing_num_ports, cfg->ifs,
cfg->do_ip4, cfg->do_ip6, cfg->outgoing_base_port); cfg->num_ifs, cfg->do_ip4, cfg->do_ip6,
cfg->outgoing_base_port);
if(!worker->back) { if(!worker->back) {
log_err("could not create outgoing sockets"); log_err("could not create outgoing sockets");
worker_delete(worker); worker_delete(worker);

View file

@ -3,6 +3,7 @@
except the listening ports. Then the config file is reread. except the listening ports. Then the config file is reread.
And everything is started again (and listening ports if needed). And everything is started again (and listening ports if needed).
- Ports for queries are shared. - Ports for queries are shared.
- config file added interface:, chroot: and username:.
22 February 2007: Wouter 22 February 2007: Wouter
- Have a config file. Removed commandline options, moved to config. - Have a config file. Removed commandline options, moved to config.

View file

@ -18,6 +18,10 @@ server:
# number of threads to create. 1 disables threading. # number of threads to create. 1 disables threading.
# num-threads: 1 # num-threads: 1
# specify the interfaces to answer queries from by ip-address.
# If you give none the default (all) interface is used.
# interface: 127.0.0.1
# port to answer queries from # port to answer queries from
# port: 53 # port: 53
@ -52,3 +56,9 @@ server:
# The port number to send forwarded queries to. # The port number to send forwarded queries to.
# forward-to-port: 53 # forward-to-port: 53
# if given, a chroot(2) is done to the given directory.
# chroot: "/some/directory"
# if given, user privileges are dropped (after binding port),
# and the given username is assumed. Default is nothing "".
# username: "unbound"

View file

@ -49,6 +49,9 @@ output per query. Level 3 gives algorithm level information.
The number of threads to create to serve clients. Use 1 for no threading. The number of threads to create to serve clients. Use 1 for no threading.
.It \fBport:\fR <port number> .It \fBport:\fR <port number>
The port number, default 53, on which the server responds to queries. The port number, default 53, on which the server responds to queries.
.It \fBinterface:\fR <ip address>
Interface to use to connect to the network. Can be given multiple times to
work on several interfaces. If none are given the default (all) is used.
.It \fBoutgoing-port:\fR <port number> .It \fBoutgoing-port:\fR <port number>
The starting port number where the outgoing query port range is allocated. The starting port number where the outgoing query port range is allocated.
Default is 1053. Default is 1053.
@ -71,6 +74,14 @@ The ip address is used to forward all DNS queries to.
.It \fBforward-to-port:\fR <port number> .It \fBforward-to-port:\fR <port number>
The port on which the remote server is running that answers forwarded queries. The port on which the remote server is running that answers forwarded queries.
Default is 53. Default is 53.
.It \fBchroot:\fR <directory>
If given a chroot is done to the given directory. The default is none ("").
.It \fBusername:\fR <name>
If given, after binding the port the user privileges are dropped. Default is
not to change user, username: "". If this user is not capable of binding the
port, reloads (by signal HUP) will work, however, if you change the port
number in the config file, and that port number requires privileges, then
a reload will fail to bind to the new port number; a restart is needed.
.Sh FILES .Sh FILES
.Bl -tag -width indent .Bl -tag -width indent

View file

@ -229,7 +229,7 @@ make_udp_range(struct comm_point** coms, const char* ifname,
/** calculate number of ip4 and ip6 interfaces, times multiplier. */ /** calculate number of ip4 and ip6 interfaces, times multiplier. */
static void static void
calc_num46(const char** ifs, int num_ifs, int do_ip4, int do_ip6, calc_num46(char** ifs, int num_ifs, int do_ip4, int do_ip6,
size_t multiplier, size_t* num_ip4, size_t* num_ip6) size_t multiplier, size_t* num_ip4, size_t* num_ip6)
{ {
int i; int i;
@ -268,7 +268,7 @@ pending_udp_timer_cb(void *arg)
struct outside_network* struct outside_network*
outside_network_create(struct comm_base *base, size_t bufsize, outside_network_create(struct comm_base *base, size_t bufsize,
size_t num_ports, const char** ifs, int num_ifs, int do_ip4, size_t num_ports, char** ifs, int num_ifs, int do_ip4,
int do_ip6, int port_base) int do_ip6, int port_base)
{ {
struct outside_network* outnet = (struct outside_network*) struct outside_network* outnet = (struct outside_network*)

View file

@ -119,7 +119,7 @@ struct pending {
* @return: the new structure (with no pending answers) or NULL on error. * @return: the new structure (with no pending answers) or NULL on error.
*/ */
struct outside_network* outside_network_create(struct comm_base* base, struct outside_network* outside_network_create(struct comm_base* base,
size_t bufsize, size_t num_ports, const char** ifs, int num_ifs, size_t bufsize, size_t num_ports, char** ifs, int num_ifs,
int do_ip4, int do_ip6, int port_base); int do_ip4, int do_ip6, int port_base);
/** /**

View file

@ -617,7 +617,7 @@ comm_point_drop_reply(struct comm_reply* repinfo)
struct outside_network* struct outside_network*
outside_network_create(struct comm_base* base, size_t bufsize, outside_network_create(struct comm_base* base, size_t bufsize,
size_t ATTR_UNUSED(num_ports), const char** ATTR_UNUSED(ifs), size_t ATTR_UNUSED(num_ports), char** ATTR_UNUSED(ifs),
int ATTR_UNUSED(num_ifs), int ATTR_UNUSED(do_ip4), int ATTR_UNUSED(num_ifs), int ATTR_UNUSED(do_ip4),
int ATTR_UNUSED(do_ip6), int ATTR_UNUSED(port_base)) int ATTR_UNUSED(do_ip6), int ATTR_UNUSED(port_base))
{ {

View file

@ -140,6 +140,12 @@ config_delete(struct config_file* cfg)
free(cfg->fwd_address); free(cfg->fwd_address);
free(cfg->username); free(cfg->username);
free(cfg->chrootdir); free(cfg->chrootdir);
if(cfg->ifs) {
int i;
for(i=0; i<cfg->num_ifs; i++)
free(cfg->ifs[i]);
free(cfg->ifs);
}
free(cfg); free(cfg);
} }

View file

@ -108,6 +108,9 @@ do-udp{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_DO_UDP;}
do-tcp{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_DO_TCP;} do-tcp{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_DO_TCP;}
forward-to{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_FORWARD_TO;} forward-to{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_FORWARD_TO;}
forward-to-port{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_FORWARD_TO_PORT;} forward-to-port{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_FORWARD_TO_PORT;}
interface{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_INTERFACE;}
chroot{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_CHROOT;}
username{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_USERNAME;}
{NEWLINE} { LEXOUT(("NL\n")); cfg_parser->line++;} {NEWLINE} { LEXOUT(("NL\n")); cfg_parser->line++;}
/* Quoted strings. Strip leading and ending quotes */ /* Quoted strings. Strip leading and ending quotes */
@ -123,6 +126,8 @@ forward-to-port{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_FORWARD_TO_PORT;
BEGIN(INITIAL); BEGIN(INITIAL);
yytext[yyleng - 1] = '\0'; yytext[yyleng - 1] = '\0';
yylval.str = strdup(yytext); yylval.str = strdup(yytext);
if(!yylval.str)
yyerror("out of memory");
return STRING; return STRING;
} }

View file

@ -67,10 +67,10 @@ extern struct config_parser_state* cfg_parser;
%token SPACE LETTER NEWLINE COMMENT COLON ANY ZONESTR %token SPACE LETTER NEWLINE COMMENT COLON ANY ZONESTR
%token <str> STRING %token <str> STRING
%token VAR_SERVER VAR_VERBOSITY VAR_NUM_THREADS VAR_PORT %token VAR_SERVER VAR_VERBOSITY VAR_NUM_THREADS VAR_PORT
%token VAR_OUTGOING_PORT VAR_OUTGOING_RANGE %token VAR_OUTGOING_PORT VAR_OUTGOING_RANGE VAR_INTERFACE
%token VAR_DO_IP4 VAR_DO_IP6 VAR_DO_UDP VAR_DO_TCP %token VAR_DO_IP4 VAR_DO_IP6 VAR_DO_UDP VAR_DO_TCP
%token VAR_FORWARD_TO VAR_FORWARD_TO_PORT %token VAR_FORWARD_TO VAR_FORWARD_TO_PORT VAR_CHROOT
%token VAR_USERNAME
%% %%
toplevelvars: /* empty */ | toplevelvars toplevelvar ; toplevelvars: /* empty */ | toplevelvars toplevelvar ;
@ -89,7 +89,8 @@ contents_server: contents_server content_server | ;
content_server: server_num_threads | server_verbosity | server_port | content_server: server_num_threads | server_verbosity | server_port |
server_outgoing_port | server_outgoing_range | server_do_ip4 | server_outgoing_port | server_outgoing_range | server_do_ip4 |
server_do_ip6 | server_do_udp | server_do_tcp | server_forward_to | server_do_ip6 | server_do_udp | server_do_tcp | server_forward_to |
server_forward_to_port; server_forward_to_port | server_interface | server_chroot |
server_username;
server_num_threads: VAR_NUM_THREADS STRING server_num_threads: VAR_NUM_THREADS STRING
{ {
OUTYY(("P(server_num_threads:%s)\n", $2)); OUTYY(("P(server_num_threads:%s)\n", $2));
@ -117,6 +118,19 @@ server_port: VAR_PORT STRING
free($2); free($2);
} }
; ;
server_interface: VAR_INTERFACE STRING
{
OUTYY(("P(server_interface:%s)\n", $2));
if(cfg_parser->cfg->num_ifs == 0)
cfg_parser->cfg->ifs = calloc(1, sizeof(char*));
else cfg_parser->cfg->ifs = realloc(cfg_parser->cfg->ifs,
(cfg_parser->cfg->num_ifs+1)*sizeof(char*));
if(!cfg_parser->cfg->ifs)
yyerror("out of memory");
else
cfg_parser->cfg->ifs[cfg_parser->cfg->num_ifs++] = $2;
}
;
server_outgoing_port: VAR_OUTGOING_PORT STRING server_outgoing_port: VAR_OUTGOING_PORT STRING
{ {
OUTYY(("P(server_outgoing_port:%s)\n", $2)); OUTYY(("P(server_outgoing_port:%s)\n", $2));
@ -187,6 +201,20 @@ server_forward_to_port: VAR_FORWARD_TO_PORT STRING
free($2); free($2);
} }
; ;
server_chroot: VAR_CHROOT STRING
{
OUTYY(("P(server_chroot:%s)\n", $2));
free(cfg_parser->cfg->chrootdir);
cfg_parser->cfg->chrootdir = $2;
}
;
server_username: VAR_USERNAME STRING
{
OUTYY(("P(server_username:%s)\n", $2));
free(cfg_parser->cfg->username);
cfg_parser->cfg->username = $2;
}
;
%% %%
/* parse helper routines could be here */ /* parse helper routines could be here */