conn_mgr.h: document in ll_queue style; config_parser/utun_instance updates
This commit is contained in:
1 parent
90ad64a106
commit
59d307f98b
5 files changed
+511
-118
No files matched your search
@@ -27,6 +27,7 @@
|
||||
#include <unistd.h>
|
||||
#include "../lib/platform_compat.h"
|
||||
#include "../lib/mem.h"
|
||||
#include "../lib/ll_queue.h"
|
||||
|
||||
|
||||
|
||||
@@ -85,6 +86,35 @@ static int instance_init_common(struct UTUN_INSTANCE* instance, struct UASYNC* u
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Initialize networks queue (indexed by 56-bit network id)
|
||||
instance->networks = queue_new(ua, 16, offsetof(struct NETWORK_ENTRY, id), 7, "networks");
|
||||
if (!instance->networks) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Failed to create networks queue");
|
||||
return -1;
|
||||
}
|
||||
struct CFG_NETWORK *net = config->networks;
|
||||
while (net) {
|
||||
struct ll_entry *entry = queue_entry_new(sizeof(struct NETWORK_ENTRY));
|
||||
if (!entry) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "Failed to allocate network entry for %s", net->name);
|
||||
net = net->next;
|
||||
continue;
|
||||
}
|
||||
struct NETWORK_ENTRY *ne = (struct NETWORK_ENTRY*)entry->data;
|
||||
ne->id = net->id & 0x00FFFFFFFFFFFFFFULL;
|
||||
for (int i = 0; i < SC_PUBKEY_SIZE; i++) {
|
||||
unsigned int b; sscanf(net->pubkey_hex + i * 2, "%2x", &b); ne->pubkey[i] = (uint8_t)b;
|
||||
}
|
||||
for (int i = 0; i < SC_PRIVKEY_SIZE; i++) {
|
||||
unsigned int b; sscanf(net->signing_key_hex + i * 2, "%2x", &b); ne->signing_key[i] = (uint8_t)b;
|
||||
}
|
||||
strncpy(ne->name, net->name, sizeof(ne->name) - 1);
|
||||
ne->name[sizeof(ne->name) - 1] = '\0';
|
||||
queue_data_put_with_index(instance->networks, entry);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Network added: [%s] id=%012llx", ne->name, (unsigned long long)ne->id);
|
||||
net = net->next;
|
||||
}
|
||||
|
||||
// Create memory pools
|
||||
instance->ack_pool = memory_pool_init(sizeof(struct ACK_PACKET), "ack_pool");
|
||||
instance->data_pool = memory_pool_init(PACKET_DATA_SIZE, "data_pool");
|
||||
@@ -408,6 +438,16 @@ void utun_instance_destroy(struct UTUN_INSTANCE *instance) {
|
||||
instance->stcp_server = NULL;
|
||||
}
|
||||
|
||||
// Cleanup networks queue
|
||||
if (instance->networks) {
|
||||
struct ll_entry *entry;
|
||||
while ((entry = queue_data_get(instance->networks)) != NULL) {
|
||||
queue_entry_free(entry);
|
||||
}
|
||||
queue_free(instance->networks);
|
||||
instance->networks = NULL;
|
||||
}
|
||||
|
||||
// Cleanup config
|
||||
if (instance->config) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "[INSTANCE_DESTROY] Freeing configuration");
|
||||
@@ -754,6 +794,35 @@ struct UTUN_INSTANCE *utun_instance_reload(struct UTUN_INSTANCE *instance, struc
|
||||
l = next_l;
|
||||
}
|
||||
}
|
||||
// Reload networks: clear and repopulate
|
||||
if (instance->networks) {
|
||||
struct ll_entry *entry;
|
||||
while ((entry = queue_data_get(instance->networks)) != NULL) {
|
||||
queue_entry_free(entry);
|
||||
}
|
||||
struct CFG_NETWORK *net = new_config->networks;
|
||||
while (net) {
|
||||
struct ll_entry *new_entry = queue_entry_new(sizeof(struct NETWORK_ENTRY));
|
||||
if (!new_entry) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "Failed to allocate network entry for reload: %s", net->name);
|
||||
net = net->next;
|
||||
continue;
|
||||
}
|
||||
struct NETWORK_ENTRY *ne = (struct NETWORK_ENTRY*)new_entry->data;
|
||||
ne->id = net->id & 0x00FFFFFFFFFFFFFFULL;
|
||||
for (int i = 0; i < SC_PUBKEY_SIZE; i++) {
|
||||
unsigned int b; sscanf(net->pubkey_hex + i * 2, "%2x", &b); ne->pubkey[i] = (uint8_t)b;
|
||||
}
|
||||
for (int i = 0; i < SC_PRIVKEY_SIZE; i++) {
|
||||
unsigned int b; sscanf(net->signing_key_hex + i * 2, "%2x", &b); ne->signing_key[i] = (uint8_t)b;
|
||||
}
|
||||
strncpy(ne->name, net->name, sizeof(ne->name) - 1);
|
||||
ne->name[sizeof(ne->name) - 1] = '\0';
|
||||
queue_data_put_with_index(instance->networks, new_entry);
|
||||
net = net->next;
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Networks reloaded");
|
||||
}
|
||||
fw_free(&instance->fw);
|
||||
fw_init(&instance->fw);
|
||||
fw_load_rules(&instance->fw, &new_config->global);
|
||||
|
||||
Reference in new issue
Block a user