From 64cf4869536a5b1d5785ebbeee735ec063420ea3 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 16 Nov 2024 08:08:12 +0100 Subject: [PATCH 1/2] Use the correct counters when resizing lookup tables Signed-off-by: DL6ER --- src/shmem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shmem.c b/src/shmem.c index 773582a3e..872db0c2a 100644 --- a/src/shmem.c +++ b/src/shmem.c @@ -1010,7 +1010,7 @@ void shm_ensure_size(void) exit(EXIT_FAILURE); } } - if(counters->clients >= counters->clients_lookup_MAX-1) + if(counters->clients_lookup_size >= counters->clients_lookup_MAX-1) { // Have to reallocate shared memory clients_lookup = enlarge_shmem_struct(CLIENTS_LOOKUP); @@ -1020,7 +1020,7 @@ void shm_ensure_size(void) exit(EXIT_FAILURE); } } - if(counters->domains >= counters->domains_lookup_MAX-1) + if(counters->domains_lookup_size >= counters->domains_lookup_MAX-1) { // Have to reallocate shared memory domains_lookup = enlarge_shmem_struct(DOMAINS_LOOKUP); @@ -1030,7 +1030,7 @@ void shm_ensure_size(void) exit(EXIT_FAILURE); } } - if(counters->dns_cache_size >= counters->dns_cache_lookup_MAX-1) + if(counters->dns_cache_lookup_size >= counters->dns_cache_lookup_MAX-1) { // Have to reallocate shared memory dns_cache_lookup = enlarge_shmem_struct(DNS_CACHE_LOOKUP); From 81d06bfc8a909febb9ef75fafe24d9f8d6a82f73 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 17 Nov 2024 21:46:45 +0100 Subject: [PATCH 2/2] Remap shared memory lookup tables after they have been resized Signed-off-by: DL6ER --- src/shmem.c | 9 +++++++++ src/shmem.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/shmem.c b/src/shmem.c index 872db0c2a..e5b7aa0d1 100644 --- a/src/shmem.c +++ b/src/shmem.c @@ -333,6 +333,15 @@ static void remap_shm(void) realloc_shm(&shm_strings, counters->strings_MAX, sizeof(char), false); // strings are not exposed by a global pointer + realloc_shm(&shm_domains_lookup, counters->domains_lookup_MAX, sizeof(struct lookup_table), false); + domains_lookup = (struct lookup_table*)shm_domains_lookup.ptr; + + realloc_shm(&shm_clients_lookup, counters->clients_lookup_MAX, sizeof(struct lookup_table), false); + clients_lookup = (struct lookup_table*)shm_clients_lookup.ptr; + + realloc_shm(&shm_dns_cache_lookup, counters->dns_cache_lookup_MAX, sizeof(struct lookup_table), false); + dns_cache_lookup = (struct lookup_table*)shm_dns_cache_lookup.ptr; + // Update local counter to reflect that we absorbed this change local_shm_counter = shmSettings->global_shm_counter; } diff --git a/src/shmem.h b/src/shmem.h index 4f87de895..ad03099fa 100644 --- a/src/shmem.h +++ b/src/shmem.h @@ -96,7 +96,7 @@ static bool create_shm(const char *name, SharedMemory *sharedMemory, const size_ /// \param sharedMemory the shared memory struct /// \param size1 the new size (factor 1) /// \param size2 the new size (factor 2) -/// \param resize whether the object should be resized or only remapped +/// \param resize whether the object should be resized (true) or only remapped (false) /// \return if reallocation was successful static bool realloc_shm(SharedMemory *sharedMemory, const size_t size1, const size_t size2, const bool resize);