Skip to content

Commit

Permalink
Limit number of upstream nameservers when logging configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
infinet committed May 17, 2016
1 parent e994d62 commit 5821105
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ MANDIR = $(PREFIX)/share/man
LOCALEDIR = $(PREFIX)/share/locale
BUILDDIR = $(SRC)
DESTDIR =
CFLAGS = -Wall -W -O0 -g
CFLAGS = -Wall -W -O2
LDFLAGS =
COPTS =
RPM_OPT_FLAGS =
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define TIMEOUT 10 /* drop UDP queries after TIMEOUT seconds */
#define FORWARD_TEST 50 /* try all servers every 50 queries */
#define FORWARD_TIME 20 /* or 20 seconds */
#define SERVERS_LOGGED 30 /* Only log this many servers when logging state */
#define RANDOM_SOCKS 64 /* max simultaneous random ports */
#define LEASE_RETRY 60 /* on error, retry writing leasefile after LEASE_RETRY seconds */
#define CACHESIZ 150 /* default cache size */
Expand Down
4 changes: 2 additions & 2 deletions src/dnsmasq.h
Original file line number Diff line number Diff line change
Expand Up @@ -1406,8 +1406,8 @@ struct htree_node *domain_match(struct htree_node *root, char *domain);
struct htree_node *domain_find_or_add(struct htree_node *root, char *domain);
struct server *lookup_or_install_new_server(struct server *serv);
void htree_free (struct htree_node *node);
void print_server_special_domains(struct htree_node *node,
char *parents[], int current_level);
void print_server_special_domains(struct htree_node *node, char *parents[],
int current_level, int *count);

/* helper.c */
#if defined(HAVE_SCRIPT)
Expand Down
26 changes: 14 additions & 12 deletions src/htree.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,11 @@ struct server *lookup_or_install_new_server(struct server *serv)
}

/* print the daemon->htree_special_domains tree recursively */
void print_server_special_domains (struct htree_node *node,
char *parents[], int current_level)
void print_server_special_domains (struct htree_node *node, char *parents[],
int current_level, int *count)
{
struct htree_node *np;
struct special_domain *obj;
char buf[MAXDNAME];
char ip_buf[ADDRSTRLEN];
int j, level;
int port = 0;
Expand All @@ -463,16 +462,19 @@ void print_server_special_domains (struct htree_node *node,
obj = (struct special_domain *) node->ptr;
if (obj->domain_flags & SERV_HAS_DOMAIN)
{
memset (buf, 0, MAXDNAME);
for (j = level; j > 1; j--)
if ((*count)++ < SERVERS_LOGGED)
{
strcat (buf, parents[j]);
strcat (buf, ".");
memset (buf, 0, MAXDNAME);
for (j = level; j > 1; j--)
{
strcat (buf, parents[j]);
strcat (buf, ".");
}
buf[strlen (buf) - 1] = '\0';
port = prettyprint_addr (&obj->server->addr, ip_buf);
my_syslog(LOG_INFO, _("using nameserver %s#%d for domain %s"),
ip_buf, port, buf);
}
buf[strlen (buf) - 1] = '\0';
port = prettyprint_addr (&obj->server->addr, ip_buf);
my_syslog(LOG_INFO, _("using nameserver %s#%d for domain %s"),
ip_buf, port, buf);
}
}
}
Expand All @@ -481,6 +483,6 @@ void print_server_special_domains (struct htree_node *node,
{
for (i = 0; i < node->sub_size; i++)
if ((np = node->sub[i]) != NULL)
print_server_special_domains (np, parents, level);
print_server_special_domains (np, parents, level, count);
}
}
5 changes: 4 additions & 1 deletion src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -1417,14 +1417,17 @@ void check_servers(void)
struct irec *iface;
struct server *serv;
int port = 0;
int count = 0;

/* interface may be new since startup */
if (!option_bool(OPT_NOWILD))
enumerate_interfaces(0);

char *levels[MAXLABELS + 1]; /* the root node starts at 1 */
struct htree_node *root = daemon->htree_special_domains;
print_server_special_domains(root, levels, 0);
print_server_special_domains(root, levels, 0, &count);
if (count > SERVERS_LOGGED)
my_syslog(LOG_INFO, _("using %d more nameservers"), count - SERVERS_LOGGED);

for (serv = daemon->servers; serv; serv = serv->next)
{
Expand Down

0 comments on commit 5821105

Please sign in to comment.