diff options
Diffstat (limited to 'ot_accesslist.c')
| -rw-r--r-- | ot_accesslist.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/ot_accesslist.c b/ot_accesslist.c index a199fa4..2465ada 100644 --- a/ot_accesslist.c +++ b/ot_accesslist.c | |||
| @@ -22,11 +22,11 @@ | |||
| 22 | #endif | 22 | #endif |
| 23 | 23 | ||
| 24 | /* Libowfat */ | 24 | /* Libowfat */ |
| 25 | #include "ip6.h" | ||
| 26 | 25 | ||
| 27 | /* Opentracker */ | 26 | /* Opentracker */ |
| 28 | #include "ot_accesslist.h" | 27 | #include "ot_accesslist.h" |
| 29 | #include "ot_hex.h" | 28 | #include "ot_hex.h" |
| 29 | #include "ot_ip.h" | ||
| 30 | #include "ot_vector.h" | 30 | #include "ot_vector.h" |
| 31 | #include "trackerlogic.h" | 31 | #include "trackerlogic.h" |
| 32 | 32 | ||
| @@ -81,7 +81,7 @@ static ot_accesslist *accesslist_make(ot_accesslist *next, size_t size) { | |||
| 81 | if (accesslist_new) { | 81 | if (accesslist_new) { |
| 82 | accesslist_new->list = size ? malloc(sizeof(ot_hash) * size) : NULL; | 82 | accesslist_new->list = size ? malloc(sizeof(ot_hash) * size) : NULL; |
| 83 | accesslist_new->size = size; | 83 | accesslist_new->size = size; |
| 84 | accesslist_new->base = g_now_minutes; | 84 | accesslist_new->base = 0; |
| 85 | accesslist_new->next = next; | 85 | accesslist_new->next = next; |
| 86 | if (size && !accesslist_new->list) { | 86 | if (size && !accesslist_new->list) { |
| 87 | free(accesslist_new); | 87 | free(accesslist_new); |
| @@ -192,16 +192,24 @@ static void accesslist_readfile(void) { | |||
| 192 | 192 | ||
| 193 | /* Now exchange the accesslist vector in the least race condition prone way */ | 193 | /* Now exchange the accesslist vector in the least race condition prone way */ |
| 194 | pthread_mutex_lock(&g_accesslist_mutex); | 194 | pthread_mutex_lock(&g_accesslist_mutex); |
| 195 | |||
| 196 | /* Mark old accesslist as "needs to live another five minutes" */ | ||
| 197 | if (g_accesslist) | ||
| 198 | g_accesslist->base = g_now_minutes; | ||
| 195 | accesslist_new->next = g_accesslist; | 199 | accesslist_new->next = g_accesslist; |
| 196 | g_accesslist = accesslist_new; /* Only now set a new list */ | 200 | g_accesslist = accesslist_new; /* Only now set a new list */ |
| 197 | 201 | ||
| 198 | #ifdef WANT_DYNAMIC_ACCESSLIST | 202 | #ifdef WANT_DYNAMIC_ACCESSLIST |
| 199 | /* If we have dynamic accesslists, reloading a new one will always void the add/delete lists. | 203 | /* If we have dynamic accesslists, reloading a new one will always void the add/delete lists. |
| 200 | Insert empty ones at the list head */ | 204 | Insert empty ones at the list head */ |
| 201 | if (g_accesslist_add && (accesslist_new = accesslist_make(g_accesslist_add, 0)) != NULL) | 205 | if (g_accesslist_add && (accesslist_new = accesslist_make(g_accesslist_add, 0)) != NULL) { |
| 206 | g_accesslist_add->base = g_now_minutes; | ||
| 202 | g_accesslist_add = accesslist_new; | 207 | g_accesslist_add = accesslist_new; |
| 203 | if (g_accesslist_delete && (accesslist_new = accesslist_make(g_accesslist_delete, 0)) != NULL) | 208 | } |
| 209 | if (g_accesslist_delete && (accesslist_new = accesslist_make(g_accesslist_delete, 0)) != NULL) { | ||
| 210 | g_accesslist_delete->base = g_now_minutes; | ||
| 204 | g_accesslist_delete = accesslist_new; | 211 | g_accesslist_delete = accesslist_new; |
| 212 | } | ||
| 205 | #endif | 213 | #endif |
| 206 | 214 | ||
| 207 | accesslist_clean(g_accesslist); | 215 | accesslist_clean(g_accesslist); |
| @@ -209,7 +217,7 @@ static void accesslist_readfile(void) { | |||
| 209 | pthread_mutex_unlock(&g_accesslist_mutex); | 217 | pthread_mutex_unlock(&g_accesslist_mutex); |
| 210 | } | 218 | } |
| 211 | 219 | ||
| 212 | int accesslist_hashisvalid(ot_hash hash) { | 220 | int accesslist_hashisvalid(const ot_hash hash) { |
| 213 | /* Get working copy of current access list */ | 221 | /* Get working copy of current access list */ |
| 214 | ot_accesslist *accesslist = g_accesslist; | 222 | ot_accesslist *accesslist = g_accesslist; |
| 215 | #ifdef WANT_DYNAMIC_ACCESSLIST | 223 | #ifdef WANT_DYNAMIC_ACCESSLIST |
| @@ -315,7 +323,8 @@ static void *accesslist_adddel_worker(char *fifoname, ot_accesslist *_Atomic | |||
| 315 | ot_accesslist *accesslist_new = accesslist_make(*removing_from, (*removing_from)->size - 1); | 323 | ot_accesslist *accesslist_new = accesslist_make(*removing_from, (*removing_from)->size - 1); |
| 316 | if (accesslist_new) { | 324 | if (accesslist_new) { |
| 317 | memcpy(accesslist_new->list, (*removing_from)->list, sizeof(ot_hash) * off); | 325 | memcpy(accesslist_new->list, (*removing_from)->list, sizeof(ot_hash) * off); |
| 318 | memcpy(accesslist_new->list + off, (*removing_from)->list + off + 1, (*removing_from)->size - off - 1); | 326 | memcpy(accesslist_new->list + off, (*removing_from)->list + off + 1, sizeof(ot_hash) * ((*removing_from)->size - off - 1)); |
| 327 | (*removing_from)->base = g_now_minutes; | ||
| 319 | *removing_from = accesslist_new; | 328 | *removing_from = accesslist_new; |
| 320 | } | 329 | } |
| 321 | } | 330 | } |
| @@ -330,7 +339,7 @@ static void *accesslist_adddel_worker(char *fifoname, ot_accesslist *_Atomic | |||
| 330 | } | 339 | } |
| 331 | } else { | 340 | } else { |
| 332 | int exactmatch = 0; | 341 | int exactmatch = 0; |
| 333 | ot_hash *insert_point = binary_search(info_hash, (*adding_to)->list, (*adding_to)->size, OT_HASH_COMPARE_SIZE, sizeof(ot_hash), &exactmatch); | 342 | ot_hash *insert_point = binary_search(info_hash, (*adding_to)->list, (*adding_to)->size, sizeof(ot_hash), OT_HASH_COMPARE_SIZE, &exactmatch); |
| 334 | 343 | ||
| 335 | /* Only if the info hash is not in the adding_to list, create a new head with that entry */ | 344 | /* Only if the info hash is not in the adding_to list, create a new head with that entry */ |
| 336 | if (!exactmatch) { | 345 | if (!exactmatch) { |
| @@ -339,7 +348,8 @@ static void *accesslist_adddel_worker(char *fifoname, ot_accesslist *_Atomic | |||
| 339 | if (accesslist_new) { | 348 | if (accesslist_new) { |
| 340 | memcpy(accesslist_new->list, (*adding_to)->list, sizeof(ot_hash) * off); | 349 | memcpy(accesslist_new->list, (*adding_to)->list, sizeof(ot_hash) * off); |
| 341 | memcpy(accesslist_new->list + off, info_hash, sizeof(info_hash)); | 350 | memcpy(accesslist_new->list + off, info_hash, sizeof(info_hash)); |
| 342 | memcpy(accesslist_new->list + off + 1, (*adding_to)->list + off, (*adding_to)->size - off); | 351 | memcpy(accesslist_new->list + off + 1, (*adding_to)->list + off, sizeof(ot_hash) * ((*adding_to)->size - off)); |
| 352 | (*adding_to)->base = g_now_minutes; | ||
| 343 | *adding_to = accesslist_new; | 353 | *adding_to = accesslist_new; |
| 344 | } | 354 | } |
| 345 | } | 355 | } |
| @@ -546,10 +556,10 @@ int accesslist_bless_net(ot_net *net, ot_permissions permissions) { | |||
| 546 | { | 556 | { |
| 547 | char _debug[512]; | 557 | char _debug[512]; |
| 548 | int off = snprintf(_debug, sizeof(_debug), "Blessing ip net "); | 558 | int off = snprintf(_debug, sizeof(_debug), "Blessing ip net "); |
| 549 | off += fmt_ip6c(_debug + off, net->address); | 559 | off += ip_format(_debug + off, net->address); |
| 550 | if (net->bits < 128) { | 560 | if (net->bits < 128) { |
| 551 | _debug[off++] = '/'; | 561 | _debug[off++] = '/'; |
| 552 | if (ip6_isv4mapped(net->address)) | 562 | if (ip_is_v4mapped(net->address)) |
| 553 | off += snprintf(_debug + off, sizeof(_debug) - off, "%d", net->bits - 96); | 563 | off += snprintf(_debug + off, sizeof(_debug) - off, "%d", net->bits - 96); |
| 554 | else | 564 | else |
| 555 | off += snprintf(_debug + off, sizeof(_debug) - off, "%d", net->bits); | 565 | off += snprintf(_debug + off, sizeof(_debug) - off, "%d", net->bits); |
