Fixed a segfault when all nodes available for autoconnect has been exhausted

In cases when tinc has all available nodes in outgoing connections and
can not establish those connection due to network outage periodic_handler()
would crash since tmp_node_tree->count is 0.

This commit adds also new flag node->status.has_cfg_address to prevent
update_udp_address() from removing this flag.

Fixed node_status_t->unused - 13 + 19 = 32
This commit is contained in:
thorkill 2015-07-23 20:45:37 +02:00
parent f12d4a3e6d
commit 618ddadeab
3 changed files with 21 additions and 15 deletions

View file

@ -215,7 +215,7 @@ static void periodic_handler(void *data) {
for splay_each(node_t, n, node_tree) {
if(!n->status.has_known_address || n->connection)
if ((!n->status.has_known_address && !n->status.has_cfg_address) || n->connection)
continue;
bool found = false;
@ -230,20 +230,23 @@ static void periodic_handler(void *data) {
splay_insert(tmp_node_tree, n);
}
int r = rand() % tmp_node_tree->count;
int i = 0;
if (tmp_node_tree->count) {
int r = rand() % tmp_node_tree->count;
int i = 0;
for splay_each(node_t, n, tmp_node_tree) {
for splay_each(node_t, n, tmp_node_tree) {
if(i++ != r)
continue;
if(i++ != r)
continue;
logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name);
outgoing_t *outgoing = xzalloc(sizeof *outgoing);
outgoing->name = xstrdup(n->name);
list_insert_tail(outgoing_list, outgoing);
setup_outgoing_connection(outgoing);
logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name);
outgoing_t *outgoing = xzalloc(sizeof *outgoing);
outgoing->name = xstrdup(n->name);
list_insert_tail(outgoing_list, outgoing);
setup_outgoing_connection(outgoing);
}
} else {
logger(DEBUG_ALWAYS, LOG_INFO, "No more nodes available for autoconnect!");
}
splay_delete_tree(tmp_node_tree);
} else if(nc > 3) {