add IPv6 default route interface auto-detection for permanent/temporary IPv6 without netif
- get_default_route_netif_index(): UDP connect trick + getifaddrs to find default route iface - etcp_socket_add(): auto-detect netif_index when not specified in config - queue_new() API: explicit index_offset/index_size params instead of implicit from hash_size - radix: cleanup types (uint8_t*), replace bzero/bcmp with memset/memcmp, remove kernel ifdefs - route6_lib: new IPv6 routing library + get_node_v6_routes()
This commit is contained in:
1 parent
e1f051856f
commit
c24a6367cc
65 files changed
+34811
-556
No files matched your search
+33
-36
@@ -51,7 +51,7 @@ static void remove_from_hash(struct ll_queue* q, struct ll_entry* entry);
|
||||
|
||||
// ==================== Управление очередью ====================
|
||||
|
||||
struct ll_queue* queue_new(struct UASYNC* ua, size_t hash_size, char* name) {
|
||||
struct ll_queue* queue_new(struct UASYNC* ua, size_t hash_size, uint16_t index_offset, uint16_t index_size, char* name) {
|
||||
if (!ua) return NULL;
|
||||
|
||||
struct ll_queue* q = u_calloc(1, sizeof(struct ll_queue));
|
||||
@@ -61,6 +61,8 @@ struct ll_queue* queue_new(struct UASYNC* ua, size_t hash_size, char* name) {
|
||||
q->ua = ua;
|
||||
q->size_limit = -1; // Без ограничения по умолчанию
|
||||
q->hash_size = hash_size;
|
||||
q->index_offset = index_offset;
|
||||
q->index_size = index_size;
|
||||
|
||||
#ifdef QUEUE_THREAD_CHECK
|
||||
#ifdef _WIN32
|
||||
@@ -225,8 +227,8 @@ void queue_entry_free(struct ll_entry* entry) {
|
||||
static void add_to_hash(struct ll_queue* q, struct ll_entry* entry) {
|
||||
if (!q || !entry) return;
|
||||
|
||||
if (q->hash_size == 0 || entry->index_size == 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_LL_QUEUE, "[%s] Empty hash_size=%d or index_size=%d",q->name, q->hash_size, entry->index_size);
|
||||
if (q->hash_size == 0 || q->index_size == 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_LL_QUEUE, "[%s] Empty hash_size=%d or index_size=%d",q->name, q->hash_size, q->index_size);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -291,10 +293,6 @@ int queue_data_put(struct ll_queue* q, struct ll_entry* entry) {
|
||||
queue_check_thread(q);
|
||||
#endif
|
||||
|
||||
entry->index_offset = 0;
|
||||
entry->index_size = 0;
|
||||
entry->index_hash = 0;
|
||||
|
||||
if (q->hash_size > 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_LL_QUEUE, "[%s] Put no-hash data to hash queue",q->name);
|
||||
queue_dgram_free(entry);
|
||||
@@ -330,23 +328,20 @@ int queue_data_put(struct ll_queue* q, struct ll_entry* entry) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int queue_data_put_with_index(struct ll_queue* q, struct ll_entry* entry, uint16_t index_offset, uint16_t index_size) {
|
||||
int queue_data_put_with_index(struct ll_queue* q, struct ll_entry* entry) {
|
||||
if (!q || !entry) return -1;
|
||||
#ifdef QUEUE_THREAD_CHECK
|
||||
queue_check_thread(q);
|
||||
#endif
|
||||
|
||||
if (index_size == 0 || (size_t)index_offset + index_size > (size_t)entry->size) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_LL_QUEUE, "[%s] invalid index: offset=%u size=%u (data_size=%u)",q->name, index_offset, index_size, entry->size);
|
||||
if (q->index_size == 0 || (size_t)q->index_offset + q->index_size > (size_t)entry->size) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_LL_QUEUE, "[%s] invalid index: offset=%u size=%u (data_size=%u)",q->name, q->index_offset, q->index_size, entry->size);
|
||||
queue_dgram_free(entry);
|
||||
queue_entry_free(entry);
|
||||
return -1;
|
||||
}
|
||||
|
||||
entry->index_offset = index_offset;
|
||||
entry->index_size = index_size;
|
||||
|
||||
entry->index_hash = make_hash(entry->data + index_offset, index_size);
|
||||
entry->index_hash = make_hash(entry->data + q->index_offset, q->index_size);
|
||||
|
||||
if (q->size_limit >= 0 && q->count >= q->size_limit) {
|
||||
queue_dgram_free(entry);
|
||||
@@ -382,18 +377,8 @@ int queue_data_put_first(struct ll_queue* q, struct ll_entry* entry) {
|
||||
queue_check_thread(q);
|
||||
#endif
|
||||
|
||||
entry->index_offset = 0;
|
||||
entry->index_size = 0;
|
||||
entry->index_hash = 0;
|
||||
|
||||
if (q->hash_size > 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_LL_QUEUE, "[%s] Put no-hash data to hash queue",q->name);
|
||||
queue_dgram_free(entry);
|
||||
queue_entry_free(entry);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (q->size_limit >= 0 && q->count >= q->size_limit) {
|
||||
queue_dgram_free(entry);
|
||||
queue_entry_free(entry); // как было в оригинале
|
||||
return -1;
|
||||
@@ -419,22 +404,20 @@ int queue_data_put_first(struct ll_queue* q, struct ll_entry* entry) {
|
||||
}
|
||||
|
||||
// С хешем для put_first
|
||||
int queue_data_put_first_with_index(struct ll_queue* q, struct ll_entry* entry, uint16_t index_offset, uint16_t index_size) {
|
||||
int queue_data_put_first_with_index(struct ll_queue* q, struct ll_entry* entry) {
|
||||
if (!q || !entry) return -1;
|
||||
#ifdef QUEUE_THREAD_CHECK
|
||||
queue_check_thread(q);
|
||||
#endif
|
||||
|
||||
if (index_size == 0 || (size_t)index_offset + index_size > (size_t)entry->size) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_LL_QUEUE, "[%s] invalid index: offset=%u size=%u (data_size=%u)",q->name, index_offset, index_size, entry->size);
|
||||
if (q->index_size == 0 || (size_t)q->index_offset + q->index_size > (size_t)entry->size) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_LL_QUEUE, "[%s] invalid index: offset=%u size=%u (data_size=%u)",q->name, q->index_offset, q->index_size, entry->size);
|
||||
queue_dgram_free(entry);
|
||||
queue_entry_free(entry);
|
||||
return -1;
|
||||
}
|
||||
|
||||
entry->index_offset = index_offset;
|
||||
entry->index_size = index_size;
|
||||
entry->index_hash = make_hash(entry->data + index_offset, index_size);
|
||||
entry->index_hash = make_hash(entry->data + q->index_offset, q->index_size);
|
||||
|
||||
if (q->size_limit >= 0 && q->count >= q->size_limit) {
|
||||
queue_dgram_free(entry);
|
||||
@@ -581,18 +564,32 @@ void queue_cancel_wait(struct ll_queue* q, struct queue_waiter* waiter) {
|
||||
|
||||
// ==================== Поиск и удаление по ID ====================
|
||||
|
||||
struct ll_entry* queue_find_data_by_index(struct ll_queue* q, const void* index_key, uint16_t index_size) {
|
||||
if (!q || q->hash_size == 0 || !q->hash_table || index_size == 0 || !index_key) return NULL;
|
||||
struct ll_entry* queue_find_data_by_index(struct ll_queue* q, const void* index_key) {
|
||||
if (!q || q->hash_size == 0 || !q->hash_table || q->index_size == 0 || !index_key) return NULL;
|
||||
|
||||
uint32_t hash_val = make_hash(index_key, index_size);
|
||||
uint32_t hash_val = make_hash(index_key, q->index_size);
|
||||
|
||||
uint32_t slot = hash_val % q->hash_size;
|
||||
struct ll_entry* entry = q->hash_table[slot];
|
||||
|
||||
while (entry) {
|
||||
if (entry->index_size == index_size &&
|
||||
(size_t)entry->index_offset + index_size <= (size_t)entry->size &&
|
||||
memcmp(entry->data + entry->index_offset, index_key, index_size) == 0) {
|
||||
if ((size_t)q->index_offset + q->index_size <= (size_t)entry->size &&
|
||||
memcmp(entry->data + q->index_offset, index_key, q->index_size) == 0) {
|
||||
return entry;
|
||||
}
|
||||
entry = entry->hash_next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct ll_entry* queue_find_next_by_index(struct ll_queue* q, const void* index_key,
|
||||
struct ll_entry* prev_entry) {
|
||||
if (!q || q->hash_size == 0 || !index_key || q->index_size == 0 || !prev_entry) return NULL;
|
||||
|
||||
struct ll_entry* entry = prev_entry->hash_next;
|
||||
while (entry) {
|
||||
if ((size_t)q->index_offset + q->index_size <= (size_t)entry->size &&
|
||||
memcmp(entry->data + q->index_offset, index_key, q->index_size) == 0) {
|
||||
return entry;
|
||||
}
|
||||
entry = entry->hash_next;
|
||||
|
||||
Reference in new issue
Block a user