From: Guus Sliepen Date: Mon, 6 Nov 2017 20:46:17 +0000 (+0100) Subject: Don't log errors when autoconnecting fails and debuglevel is 0. X-Git-Tag: release-1.1pre16~56 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=6123ed30992d671b94fc016660086be6a62a3871;p=tinc Don't log errors when autoconnecting fails and debuglevel is 0. --- diff --git a/src/autoconnect.c b/src/autoconnect.c index 8adb74f3..132467e6 100644 --- a/src/autoconnect.c +++ b/src/autoconnect.c @@ -65,7 +65,7 @@ static void make_new_connection() { outgoing_t *outgoing = xzalloc(sizeof(*outgoing)); outgoing->name = xstrdup(n->name); list_insert_tail(outgoing_list, outgoing); - setup_outgoing_connection(outgoing); + setup_outgoing_connection(outgoing, false); } break; @@ -102,7 +102,7 @@ static void connect_to_unreachable() { outgoing_t *outgoing = xzalloc(sizeof(*outgoing)); outgoing->name = xstrdup(n->name); list_insert_tail(outgoing_list, outgoing); - setup_outgoing_connection(outgoing); + setup_outgoing_connection(outgoing, false); return; } diff --git a/src/conf.c b/src/conf.c index e789f72c..5304ab5e 100644 --- a/src/conf.c +++ b/src/conf.c @@ -313,7 +313,7 @@ config_t *parse_config_line(char *line, const char *fname, int lineno) { Parse a configuration file and put the results in the configuration tree starting at *base. */ -bool read_config_file(splay_tree_t *config_tree, const char *fname) { +bool read_config_file(splay_tree_t *config_tree, const char *fname, bool verbose) { FILE *fp; char buffer[MAX_STRING_SIZE]; char *line; @@ -325,7 +325,7 @@ bool read_config_file(splay_tree_t *config_tree, const char *fname) { fp = fopen(fname, "r"); if(!fp) { - logger(DEBUG_ALWAYS, LOG_DEBUG, "Cannot open config file %s: %s", fname, strerror(errno)); + logger(verbose ? DEBUG_ALWAYS : DEBUG_CONNECTIONS, LOG_ERR, "Cannot open config file %s: %s", fname, strerror(errno)); return false; } @@ -415,7 +415,7 @@ bool read_server_config(void) { snprintf(fname, sizeof(fname), "%s" SLASH "tinc.conf", confbase); errno = 0; - x = read_config_file(config_tree, fname); + x = read_config_file(config_tree, fname, true); // We will try to read the conf files in the "conf.d" dir if(x) { @@ -434,7 +434,7 @@ bool read_server_config(void) { // And we try to read the ones that end with ".conf" if(l > 5 && !strcmp(".conf", & ep->d_name[ l - 5 ])) { snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ep->d_name); - x = read_config_file(config_tree, fname); + x = read_config_file(config_tree, fname, true); } } @@ -449,16 +449,12 @@ bool read_server_config(void) { return x; } -bool read_host_config(splay_tree_t *config_tree, const char *name) { - char fname[PATH_MAX]; - bool x; - +bool read_host_config(splay_tree_t *config_tree, const char *name, bool verbose) { read_config_options(config_tree, name); + char fname[PATH_MAX]; snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, name); - x = read_config_file(config_tree, fname); - - return x; + return read_config_file(config_tree, fname, verbose); } bool append_config_file(const char *name, const char *key, const char *value) { diff --git a/src/conf.h b/src/conf.h index 817c2cb5..62204794 100644 --- a/src/conf.h +++ b/src/conf.h @@ -55,10 +55,10 @@ extern bool get_config_address(const config_t *, struct addrinfo **); extern bool get_config_subnet(const config_t *, struct subnet_t **); extern config_t *parse_config_line(char *, const char *, int); -extern bool read_config_file(splay_tree_t *, const char *); +extern bool read_config_file(splay_tree_t *, const char *, bool verbose); extern void read_config_options(splay_tree_t *, const char *); extern bool read_server_config(void); -extern bool read_host_config(splay_tree_t *, const char *); +extern bool read_host_config(splay_tree_t *, const char *, bool verbose); extern bool append_config_file(const char *, const char *, const char *); #endif diff --git a/src/net.c b/src/net.c index 097a79c0..5d84741d 100644 --- a/src/net.c +++ b/src/net.c @@ -327,7 +327,7 @@ int reload_configuration(void) { read_config_options(config_tree, NULL); snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, myself->name); - read_config_file(config_tree, fname); + read_config_file(config_tree, fname, true); /* Parse some options that are allowed to be changed while tinc is running */ diff --git a/src/net.h b/src/net.h index 6d4dfc89..73e82e05 100644 --- a/src/net.h +++ b/src/net.h @@ -204,7 +204,7 @@ extern void device_enable(void); extern void device_disable(void); extern bool setup_myself_reloadable(void); extern bool setup_network(void); -extern void setup_outgoing_connection(struct outgoing_t *); +extern void setup_outgoing_connection(struct outgoing_t *, bool verbose); extern void try_outgoing_connections(void); extern void close_network_connections(void); extern int main_loop(void); diff --git a/src/net_setup.c b/src/net_setup.c index 49ea31b6..ad9398db 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -75,7 +75,7 @@ bool node_read_ecdsa_public_key(node_t *n) { init_configuration(&config_tree); - if(!read_host_config(config_tree, n->name)) { + if(!read_host_config(config_tree, n->name, true)) { goto exit; } @@ -120,7 +120,7 @@ bool read_ecdsa_public_key(connection_t *c) { if(!c->config_tree) { init_configuration(&c->config_tree); - if(!read_host_config(c->config_tree, c->name)) { + if(!read_host_config(c->config_tree, c->name, true)) { return false; } } @@ -382,7 +382,7 @@ void load_all_nodes(void) { splay_tree_t *config_tree; init_configuration(&config_tree); read_config_options(config_tree, ent->d_name); - read_host_config(config_tree, ent->d_name); + read_host_config(config_tree, ent->d_name, true); if(!n) { n = new_node(); @@ -843,7 +843,7 @@ static bool setup_myself(void) { myself->connection = new_connection(); myself->name = name; myself->connection->name = xstrdup(name); - read_host_config(config_tree, name); + read_host_config(config_tree, name, true); if(!get_config_string(lookup_config(config_tree, "Port"), &myport)) { myport = xstrdup("655"); diff --git a/src/net_socket.c b/src/net_socket.c index c020e8f6..43ea4f8d 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -332,7 +332,7 @@ int setup_vpn_in_socket(const sockaddr_t *sa) { } /* int setup_vpn_in_socket */ static void retry_outgoing_handler(void *data) { - setup_outgoing_connection(data); + setup_outgoing_connection(data, true); } void retry_outgoing(outgoing_t *outgoing) { @@ -678,7 +678,7 @@ static struct addrinfo *get_known_addresses(node_t *n) { return ai; } -void setup_outgoing_connection(outgoing_t *outgoing) { +void setup_outgoing_connection(outgoing_t *outgoing, bool verbose) { timeout_del(&outgoing->ev); node_t *n = lookup_node(outgoing->name); @@ -695,7 +695,7 @@ void setup_outgoing_connection(outgoing_t *outgoing) { } init_configuration(&outgoing->config_tree); - read_host_config(outgoing->config_tree, outgoing->name); + read_host_config(outgoing->config_tree, outgoing->name, verbose); outgoing->cfg = lookup_config(outgoing->config_tree, "Address"); if(!outgoing->cfg) { @@ -704,7 +704,7 @@ void setup_outgoing_connection(outgoing_t *outgoing) { } if(!outgoing->kai) { - logger(DEBUG_ALWAYS, LOG_DEBUG, "No address known for %s", outgoing->name); + logger(verbose ? DEBUG_ALWAYS : DEBUG_CONNECTIONS, LOG_DEBUG, "No address known for %s", outgoing->name); goto remove; } } @@ -920,7 +920,7 @@ void try_outgoing_connections(void) { outgoing_t *outgoing = xzalloc(sizeof(*outgoing)); outgoing->name = name; list_insert_tail(outgoing_list, outgoing); - setup_outgoing_connection(outgoing); + setup_outgoing_connection(outgoing, true); } } diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 56ff3b12..c0a2aeaf 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -428,7 +428,7 @@ bool id_h(connection_t *c, const char *request) { if(!c->config_tree) { init_configuration(&c->config_tree); - if(!read_host_config(c->config_tree, c->name)) { + if(!read_host_config(c->config_tree, c->name, false)) { logger(DEBUG_ALWAYS, LOG_ERR, "Peer %s had unknown identity (%s)", c->hostname, c->name); return false; }