summaryrefslogtreecommitdiff
path: root/ot_accesslist.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_accesslist.c')
-rw-r--r--ot_accesslist.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/ot_accesslist.c b/ot_accesslist.c
index d7e88ee..79a11a5 100644
--- a/ot_accesslist.c
+++ b/ot_accesslist.c
@@ -110,7 +110,7 @@ size_t accesslist_parse_hashes(ot_hash *dest, size_t capacity, const char *buf,
110 size_t count = 0; 110 size_t count = 0;
111 111
112 while (count < capacity && end - offs >= 40) { 112 while (count < capacity && end - offs >= 40) {
113 if (hex_tohash(dest[count], offs)) { 113 if (hex_to_hash(dest[count], offs)) {
114 offs += 40; 114 offs += 40;
115 115
116 if (offs == end || !hex_isdigit((unsigned char)*offs)) 116 if (offs == end || !hex_isdigit((unsigned char)*offs))
@@ -308,7 +308,7 @@ static void *accesslist_adddel_worker(const char *fifoname, ot_accesslist *_
308 if (linelen < 41) 308 if (linelen < 41)
309 continue; 309 continue;
310 310
311 if (!hex_tohash(info_hash, line)) 311 if (!hex_to_hash(info_hash, line))
312 continue; 312 continue;
313 313
314 /* From now on we modify g_accesslist_add and g_accesslist_delete, so prevent the 314 /* From now on we modify g_accesslist_add and g_accesslist_delete, so prevent the
@@ -339,7 +339,7 @@ static void *accesslist_adddel_worker(const char *fifoname, ot_accesslist *_
339 } 339 }
340 } else { 340 } else {
341 int exactmatch = 0; 341 int exactmatch = 0;
342 ot_hash *insert_point = binary_search(info_hash, (*adding_to)->list, (*adding_to)->size, sizeof(ot_hash), OT_HASH_COMPARE_SIZE, &exactmatch); 342 ot_hash *insert_point = vector_binary_search(info_hash, (*adding_to)->list, (*adding_to)->size, sizeof(ot_hash), OT_HASH_COMPARE_SIZE, &exactmatch);
343 343
344 /* 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 */
345 if (!exactmatch) { 345 if (!exactmatch) {
@@ -416,7 +416,7 @@ void accesslist_cleanup(void) {
416} 416}
417#endif 417#endif
418 418
419int address_in_net(const ot_ip6 address, const ot_net *net) { 419int accesslist_address_in_net(const ot_ip6 address, const ot_net *net) {
420 int bits = net->bits, checkbits = (0x7f00 >> (bits & 7)); 420 int bits = net->bits, checkbits = (0x7f00 >> (bits & 7));
421 int result = memcmp(address, &net->address, bits >> 3); 421 int result = memcmp(address, &net->address, bits >> 3);
422 if (!result && (bits & 7)) 422 if (!result && (bits & 7))
@@ -424,7 +424,7 @@ int address_in_net(const ot_ip6 address, const ot_net *net) {
424 return result == 0; 424 return result == 0;
425} 425}
426 426
427void *set_value_for_net(const ot_net *net, ot_vector *vector, const void *value, const size_t member_size) { 427void *accesslist_set_value_for_net(const ot_net *net, ot_vector *vector, const void *value, const size_t member_size) {
428 size_t i; 428 size_t i;
429 int exactmatch; 429 int exactmatch;
430 430
@@ -435,7 +435,7 @@ void *set_value_for_net(const ot_net *net, ot_vector *vector, const void *value,
435 /* Check each net in vector for overlap */ 435 /* Check each net in vector for overlap */
436 uint8_t *member = ((uint8_t *)vector->data); 436 uint8_t *member = ((uint8_t *)vector->data);
437 for (i = 0; i < vector->size; ++i) { 437 for (i = 0; i < vector->size; ++i) {
438 if (address_in_net(*(ot_ip6 *)member, net) || address_in_net(net->address, (ot_net *)member)) 438 if (accesslist_address_in_net(*(ot_ip6 *)member, net) || accesslist_address_in_net(net->address, (ot_net *)member))
439 return 0; 439 return 0;
440 member += member_size; 440 member += member_size;
441 } 441 }
@@ -451,16 +451,16 @@ void *set_value_for_net(const ot_net *net, ot_vector *vector, const void *value,
451 451
452/* Takes a vector filled with { ot_net net, uint8_t[x] value }; 452/* Takes a vector filled with { ot_net net, uint8_t[x] value };
453 Returns value associated with the net, or NULL if not found */ 453 Returns value associated with the net, or NULL if not found */
454void *get_value_for_net(const ot_ip6 address, const ot_vector *vector, const size_t member_size) { 454void *accesslist_get_value_for_net(const ot_ip6 address, const ot_vector *vector, const size_t member_size) {
455 int exactmatch; 455 int exactmatch;
456 /* This binary search will return a pointer to the first non-containing network... */ 456 /* This binary search will return a pointer to the first non-containing network... */
457 ot_net *net = binary_search(address, vector->data, vector->size, member_size, sizeof(ot_ip6), &exactmatch); 457 ot_net *net = vector_binary_search(address, vector->data, vector->size, member_size, sizeof(ot_ip6), &exactmatch);
458 if (!net) 458 if (!net)
459 return NULL; 459 return NULL;
460 /* ... so we'll need to move back one step unless we've exactly hit the first address in network */ 460 /* ... so we'll need to move back one step unless we've exactly hit the first address in network */
461 if (!exactmatch && ((void *)net > vector->data)) 461 if (!exactmatch && ((void *)net > vector->data))
462 --net; 462 --net;
463 if (!address_in_net(address, net)) 463 if (!accesslist_address_in_net(address, net))
464 return NULL; 464 return NULL;
465 return (void *)net; 465 return (void *)net;
466} 466}
@@ -472,7 +472,7 @@ static pthread_mutex_t g_lognets_list_mutex = PTHREAD_MUTEX_INITIALIZER;
472 472
473void loglist_add_network(const ot_net *net) { 473void loglist_add_network(const ot_net *net) {
474 pthread_mutex_lock(&g_lognets_list_mutex); 474 pthread_mutex_lock(&g_lognets_list_mutex);
475 set_value_for_net(net, &g_lognets_list, NULL, sizeof(ot_net)); 475 accesslist_set_value_for_net(net, &g_lognets_list, NULL, sizeof(ot_net));
476 pthread_mutex_unlock(&g_lognets_list_mutex); 476 pthread_mutex_unlock(&g_lognets_list_mutex);
477} 477}
478 478
@@ -487,7 +487,7 @@ void loglist_reset(void) {
487int loglist_check_address(const ot_ip6 address) { 487int loglist_check_address(const ot_ip6 address) {
488 int result; 488 int result;
489 pthread_mutex_lock(&g_lognets_list_mutex); 489 pthread_mutex_lock(&g_lognets_list_mutex);
490 result = (NULL != get_value_for_net(address, &g_lognets_list, sizeof(ot_net))); 490 result = (NULL != accesslist_get_value_for_net(address, &g_lognets_list, sizeof(ot_net)));
491 pthread_mutex_unlock(&g_lognets_list_mutex); 491 pthread_mutex_unlock(&g_lognets_list_mutex);
492 return result; 492 return result;
493} 493}
@@ -508,17 +508,17 @@ int proxylist_add_network(const ot_net *proxy, const ot_net *net) {
508 pthread_mutex_lock(&g_proxies_list_mutex); 508 pthread_mutex_lock(&g_proxies_list_mutex);
509 509
510 /* If we have a direct hit, use and extend the vector there */ 510 /* If we have a direct hit, use and extend the vector there */
511 map = binary_search(proxy, g_proxies_list.data, g_proxies_list.size, sizeof(ot_proxymap), sizeof(ot_net), &exactmatch); 511 map = vector_binary_search(proxy, g_proxies_list.data, g_proxies_list.size, sizeof(ot_proxymap), sizeof(ot_net), &exactmatch);
512 512
513 if (!map || !exactmatch) { 513 if (!map || !exactmatch) {
514 /* else see, if we've got overlapping networks 514 /* else see, if we've got overlapping networks
515 and get a new empty vector if not */ 515 and get a new empty vector if not */
516 ot_vector empty; 516 ot_vector empty;
517 memset(&empty, 0, sizeof(ot_vector)); 517 memset(&empty, 0, sizeof(ot_vector));
518 map = set_value_for_net(proxy, &g_proxies_list, &empty, sizeof(ot_proxymap)); 518 map = accesslist_set_value_for_net(proxy, &g_proxies_list, &empty, sizeof(ot_proxymap));
519 } 519 }
520 520
521 if (map && set_value_for_net(net, &map->networks, NULL, sizeof(ot_net))) 521 if (map && accesslist_set_value_for_net(net, &map->networks, NULL, sizeof(ot_net)))
522 result = 1; 522 result = 1;
523 523
524 pthread_mutex_unlock(&g_proxies_list_mutex); 524 pthread_mutex_unlock(&g_proxies_list_mutex);
@@ -531,8 +531,8 @@ int proxylist_check_proxy(const ot_ip6 proxy, const ot_ip6 address) {
531 531
532 pthread_mutex_lock(&g_proxies_list_mutex); 532 pthread_mutex_lock(&g_proxies_list_mutex);
533 533
534 if ((map = get_value_for_net(proxy, &g_proxies_list, sizeof(ot_proxymap)))) 534 if ((map = accesslist_get_value_for_net(proxy, &g_proxies_list, sizeof(ot_proxymap))))
535 if (!address || get_value_for_net(address, &map->networks, sizeof(ot_net))) 535 if (!address || accesslist_get_value_for_net(address, &map->networks, sizeof(ot_net)))
536 result = 1; 536 result = 1;
537 537
538 pthread_mutex_unlock(&g_proxies_list_mutex); 538 pthread_mutex_unlock(&g_proxies_list_mutex);
@@ -587,7 +587,7 @@ int accesslist_bless_net(ot_net *net, ot_permissions permissions) {
587int accesslist_is_blessed(ot_ip6 ip, ot_permissions permissions) { 587int accesslist_is_blessed(ot_ip6 ip, ot_permissions permissions) {
588 size_t i; 588 size_t i;
589 for (i = 0; i < g_admin_nets_count; ++i) 589 for (i = 0; i < g_admin_nets_count; ++i)
590 if (address_in_net(ip, g_admin_nets + i) && (g_admin_nets_permissions[i] & permissions)) 590 if (accesslist_address_in_net(ip, g_admin_nets + i) && (g_admin_nets_permissions[i] & permissions))
591 return 1; 591 return 1;
592 return 0; 592 return 0;
593} 593}