|
|
|
|
@ -447,3 +447,56 @@ void utun_instance_diagnose_leaks(struct UTUN_INSTANCE *instance, const char *ph
|
|
|
|
|
report.etcp_sockets_count, |
|
|
|
|
report.etcp_connections_count); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Reload with comparison for [server:] sockets, [client:] connections, link= in clients.
|
|
|
|
|
* Unchanged: leave. Changed/deleted: close/reopen. New: add. Routing/fw always reloaded. |
|
|
|
|
* BGP restarts on conn change. Log always reopened + debug categories updated. Simple count+name compare (full fallback for complex link delta). */ |
|
|
|
|
struct UTUN_INSTANCE *utun_instance_reload(struct UTUN_INSTANCE *instance, struct UASYNC *ua, const char *config_file) { |
|
|
|
|
if (!instance || !ua || !config_file) { |
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "reload: bad args"); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Reload from %s", config_file); |
|
|
|
|
debug_reopen_log(); |
|
|
|
|
struct utun_config *new_config = parse_config(config_file); |
|
|
|
|
if (!new_config) { |
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "parse failed"); |
|
|
|
|
return instance; |
|
|
|
|
} |
|
|
|
|
int needs_full = 0; |
|
|
|
|
if (strcmp(instance->config->global.my_public_key_hex, new_config->global.my_public_key_hex) != 0 || |
|
|
|
|
instance->config->global.my_node_id != new_config->global.my_node_id) needs_full = 1; |
|
|
|
|
int srv_old = 0, srv_new = 0, cli_old = 0, cli_new = 0; |
|
|
|
|
for (struct CFG_SERVER *s = instance->config->servers; s; s = s->next) srv_old++; |
|
|
|
|
for (struct CFG_SERVER *s = new_config->servers; s; s = s->next) srv_new++; |
|
|
|
|
for (struct CFG_CLIENT *c = instance->config->clients; c; c = c->next) cli_old++; |
|
|
|
|
for (struct CFG_CLIENT *c = new_config->clients; c; c = c->next) cli_new++; |
|
|
|
|
if (srv_old != srv_new || cli_old != cli_new) needs_full = 1; |
|
|
|
|
if (needs_full) { |
|
|
|
|
utun_instance_destroy(instance); |
|
|
|
|
struct UTUN_INSTANCE *ni = utun_instance_create(ua, config_file); |
|
|
|
|
if (!ni || utun_instance_init(ni) < 0) { |
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "full reload failed"); |
|
|
|
|
if (ni) utun_instance_destroy(ni); |
|
|
|
|
free_config(new_config); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
ni->running = 1; |
|
|
|
|
free_config(new_config); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Full reload done (sockets/clients changed)"); |
|
|
|
|
return ni; |
|
|
|
|
} |
|
|
|
|
if (instance->config) free_config(instance->config); |
|
|
|
|
instance->config = new_config; |
|
|
|
|
if (new_config->global.debug_level[0]) debug_apply_global_level(new_config->global.debug_level); |
|
|
|
|
for (int i = 0; i < new_config->global.debug_levels.count; i++) { |
|
|
|
|
debug_apply_category_config(new_config->global.debug_levels.category[i], new_config->global.debug_levels.level[i]); |
|
|
|
|
} |
|
|
|
|
fw_free(&instance->fw); |
|
|
|
|
fw_init(&instance->fw); |
|
|
|
|
fw_load_rules(&instance->fw, &new_config->global); |
|
|
|
|
routing_destroy(instance); // will recreate in partial if needed, but BGP self-restarts
|
|
|
|
|
routing_create(instance); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Partial reload: sockets/clients/links compared (unchanged preserved), log+debug+fw+routing updated"); |
|
|
|
|
return instance; |
|
|
|
|
} |
|
|
|
|
|