[BB#63] conf: Allow multiple Listen statements in the config.
This introduces a list (vector) of addresses instead of having just one address string. Signed-off-by: Michael Adam <obnox@samba.org>
This commit is contained in:
parent
d0732f9ade
commit
e82080a5f6
39
src/child.c
39
src/child.c
@ -522,9 +522,16 @@ void child_kill_children (int sig)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int child_listening_sock (const char *addr, uint16_t port)
|
|
||||||
|
/**
|
||||||
|
* Listen on the various configured interfaces
|
||||||
|
*/
|
||||||
|
int child_listening_sockets(vector_t listen_addrs, uint16_t port)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
ssize_t i;
|
||||||
|
|
||||||
|
assert (port > 0);
|
||||||
|
|
||||||
if (listen_fds == NULL) {
|
if (listen_fds == NULL) {
|
||||||
listen_fds = vector_create();
|
listen_fds = vector_create();
|
||||||
@ -535,8 +542,34 @@ int child_listening_sock (const char *addr, uint16_t port)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = listen_sock (addr, port, listen_fds);
|
if ((listen_addrs == NULL) ||
|
||||||
return ret;
|
(vector_length(config.listen_addrs) == 0))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* no Listen directive:
|
||||||
|
* listen on the wildcard address(es)
|
||||||
|
*/
|
||||||
|
ret = listen_sock(NULL, port, listen_fds);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < vector_length(config.listen_addrs); i++) {
|
||||||
|
const char *addr;
|
||||||
|
|
||||||
|
addr = (char *)vector_getentry(config.listen_addrs, i, NULL);
|
||||||
|
if (addr == NULL) {
|
||||||
|
log_message(LOG_WARNING,
|
||||||
|
"got NULL from listen_addrs - skipping");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = listen_sock(addr, port, listen_fds);
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void child_close_sock (void)
|
void child_close_sock (void)
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#ifndef TINYPROXY_CHILD_H
|
#ifndef TINYPROXY_CHILD_H
|
||||||
#define TINYPROXY_CHILD_H
|
#define TINYPROXY_CHILD_H
|
||||||
|
|
||||||
|
#include "vector.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CHILD_MAXCLIENTS,
|
CHILD_MAXCLIENTS,
|
||||||
CHILD_MAXSPARESERVERS,
|
CHILD_MAXSPARESERVERS,
|
||||||
@ -30,7 +32,7 @@ typedef enum {
|
|||||||
} child_config_t;
|
} child_config_t;
|
||||||
|
|
||||||
extern short int child_pool_create (void);
|
extern short int child_pool_create (void);
|
||||||
extern int child_listening_sock (const char *addr, uint16_t port);
|
extern int child_listening_sockets (vector_t listen_addrs, uint16_t port);
|
||||||
extern void child_close_sock (void);
|
extern void child_close_sock (void);
|
||||||
extern void child_main_loop (void);
|
extern void child_main_loop (void);
|
||||||
extern void child_kill_children (int sig);
|
extern void child_kill_children (int sig);
|
||||||
|
40
src/conf.c
40
src/conf.c
@ -288,7 +288,7 @@ static void free_config (struct config_s *conf)
|
|||||||
safefree (conf->stathost);
|
safefree (conf->stathost);
|
||||||
safefree (conf->user);
|
safefree (conf->user);
|
||||||
safefree (conf->group);
|
safefree (conf->group);
|
||||||
safefree (conf->ipAddr);
|
vector_delete(conf->listen_addrs);
|
||||||
#ifdef FILTER_ENABLE
|
#ifdef FILTER_ENABLE
|
||||||
safefree (conf->filter);
|
safefree (conf->filter);
|
||||||
#endif /* FILTER_ENABLE */
|
#endif /* FILTER_ENABLE */
|
||||||
@ -465,8 +465,18 @@ static void initialize_with_defaults (struct config_s *conf,
|
|||||||
conf->group = safestrdup (defaults->group);
|
conf->group = safestrdup (defaults->group);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defaults->ipAddr) {
|
if (defaults->listen_addrs) {
|
||||||
conf->ipAddr = safestrdup (defaults->ipAddr);
|
ssize_t i;
|
||||||
|
|
||||||
|
conf->listen_addrs = vector_create();
|
||||||
|
for (i=0; i < vector_length(defaults->listen_addrs); i++) {
|
||||||
|
char *addr;
|
||||||
|
size_t size;
|
||||||
|
addr = (char *)vector_getentry(defaults->listen_addrs,
|
||||||
|
i, &size);
|
||||||
|
vector_append(conf->listen_addrs, addr, size);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FILTER_ENABLE
|
#ifdef FILTER_ENABLE
|
||||||
@ -882,11 +892,26 @@ static HANDLE_FUNC (handle_bind)
|
|||||||
|
|
||||||
static HANDLE_FUNC (handle_listen)
|
static HANDLE_FUNC (handle_listen)
|
||||||
{
|
{
|
||||||
int r = set_string_arg (&conf->ipAddr, line, &match[2]);
|
char *arg = get_string_arg (line, &match[2]);
|
||||||
|
|
||||||
if (r)
|
if (arg == NULL) {
|
||||||
return r;
|
return -1;
|
||||||
log_message (LOG_INFO, "Listening on IP %s", conf->ipAddr);
|
}
|
||||||
|
|
||||||
|
if (conf->listen_addrs == NULL) {
|
||||||
|
conf->listen_addrs = vector_create();
|
||||||
|
if (conf->listen_addrs == NULL) {
|
||||||
|
log_message(LOG_WARNING, "Could not create a list "
|
||||||
|
"of listen addresses.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vector_append (conf->listen_addrs, arg, strlen(arg) + 1);
|
||||||
|
|
||||||
|
log_message(LOG_INFO, "Added address [%s] to listen addresses.", arg);
|
||||||
|
|
||||||
|
safefree (arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -933,6 +958,7 @@ static HANDLE_FUNC (handle_addheader)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Log level's strings.
|
* Log level's strings.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
struct log_levels_s {
|
struct log_levels_s {
|
||||||
const char *string;
|
const char *string;
|
||||||
|
@ -46,7 +46,7 @@ struct config_s {
|
|||||||
unsigned int quit; /* boolean */
|
unsigned int quit; /* boolean */
|
||||||
char *user;
|
char *user;
|
||||||
char *group;
|
char *group;
|
||||||
char *ipAddr;
|
vector_t listen_addrs;
|
||||||
#ifdef FILTER_ENABLE
|
#ifdef FILTER_ENABLE
|
||||||
char *filter;
|
char *filter;
|
||||||
unsigned int filter_url; /* boolean */
|
unsigned int filter_url; /* boolean */
|
||||||
|
@ -430,8 +430,8 @@ main (int argc, char **argv)
|
|||||||
#endif /* FILTER_ENABLE */
|
#endif /* FILTER_ENABLE */
|
||||||
|
|
||||||
/* Start listening on the selected port. */
|
/* Start listening on the selected port. */
|
||||||
if (child_listening_sock (config.ipAddr, config.port) < 0) {
|
if (child_listening_sockets(config.listen_addrs, config.port) < 0) {
|
||||||
fprintf (stderr, "%s: Could not create listening socket.\n",
|
fprintf (stderr, "%s: Could not create listening sockets.\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
exit (EX_OSERR);
|
exit (EX_OSERR);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user