summaryrefslogtreecommitdiff
path: root/ot_accesslist.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_accesslist.c')
-rw-r--r--ot_accesslist.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/ot_accesslist.c b/ot_accesslist.c
index 7df503f..5bd81f0 100644
--- a/ot_accesslist.c
+++ b/ot_accesslist.c
@@ -21,6 +21,7 @@
21#include "scan.h" 21#include "scan.h"
22#include "ip6.h" 22#include "ip6.h"
23#include "mmap.h" 23#include "mmap.h"
24#include "fmt.h"
24 25
25/* Opentracker */ 26/* Opentracker */
26#include "trackerlogic.h" 27#include "trackerlogic.h"
@@ -509,29 +510,37 @@ int proxylist_check_proxy( const ot_ip6 proxy, const ot_ip6 address ) {
509 510
510#endif 511#endif
511 512
512static ot_ip6 g_adminip_addresses[OT_ADMINIP_MAX]; 513static ot_net g_admin_nets[OT_ADMINIP_MAX];
513static ot_permissions g_adminip_permissions[OT_ADMINIP_MAX]; 514static ot_permissions g_admin_nets_permissions[OT_ADMINIP_MAX];
514static unsigned int g_adminip_count = 0; 515static unsigned int g_admin_nets_count = 0;
515 516
516int accesslist_blessip( ot_ip6 ip, ot_permissions permissions ) { 517int accesslist_bless_net( ot_net *net, ot_permissions permissions ) {
517 if( g_adminip_count >= OT_ADMINIP_MAX ) 518 if( g_admin_nets_count >= OT_ADMINIP_MAX )
518 return -1; 519 return -1;
519 520
520 memcpy(g_adminip_addresses + g_adminip_count,ip,sizeof(ot_ip6)); 521 memcpy(g_admin_nets + g_admin_nets_count, &net, sizeof(ot_net));
521 g_adminip_permissions[ g_adminip_count++ ] = permissions; 522 g_admin_nets_permissions[ g_admin_nets_count++ ] = permissions;
522 523
523#ifdef _DEBUG 524#ifdef _DEBUG
524 { 525 {
525 char _debug[512]; 526 char _debug[512];
526 int off = snprintf( _debug, sizeof(_debug), "Blessing ip address " ); 527 int off = snprintf( _debug, sizeof(_debug), "Blessing ip net " );
527 off += fmt_ip6c(_debug+off, ip ); 528 off += fmt_ip6c(_debug+off, net->address );
529 if( net->bits < 128) {
530 _debug[off++] = '/';
531 if( ip6_isv4mapped(net->address) )
532 off += fmt_long(_debug+off, net->bits-96);
533 else
534 off += fmt_long(_debug+off, net->bits);
535 }
528 536
529 if( permissions & OT_PERMISSION_MAY_STAT ) off += snprintf( _debug+off, 512-off, " may_fetch_stats" ); 537 if( permissions & OT_PERMISSION_MAY_STAT ) off += snprintf( _debug+off, 512-off, " may_fetch_stats" );
530 if( permissions & OT_PERMISSION_MAY_LIVESYNC ) off += snprintf( _debug+off, 512-off, " may_sync_live" ); 538 if( permissions & OT_PERMISSION_MAY_LIVESYNC ) off += snprintf( _debug+off, 512-off, " may_sync_live" );
531 if( permissions & OT_PERMISSION_MAY_FULLSCRAPE ) off += snprintf( _debug+off, 512-off, " may_fetch_fullscrapes" ); 539 if( permissions & OT_PERMISSION_MAY_FULLSCRAPE ) off += snprintf( _debug+off, 512-off, " may_fetch_fullscrapes" );
532 if( permissions & OT_PERMISSION_MAY_PROXY ) off += snprintf( _debug+off, 512-off, " may_proxy" ); 540 if( permissions & OT_PERMISSION_MAY_PROXY ) off += snprintf( _debug+off, 512-off, " may_proxy" );
533 if( !permissions ) off += snprintf( _debug+off, sizeof(_debug)-off, " nothing\n" ); 541 if( !permissions ) off += snprintf( _debug+off, sizeof(_debug)-off, " nothing" );
534 _debug[off++] = '.'; 542 _debug[off++] = '.';
543 _debug[off++] = '\n';
535 (void)write( 2, _debug, off ); 544 (void)write( 2, _debug, off );
536 } 545 }
537#endif 546#endif
@@ -539,10 +548,10 @@ int accesslist_blessip( ot_ip6 ip, ot_permissions permissions ) {
539 return 0; 548 return 0;
540} 549}
541 550
542int accesslist_isblessed( ot_ip6 ip, ot_permissions permissions ) { 551int accesslist_is_blessed( ot_ip6 ip, ot_permissions permissions ) {
543 unsigned int i; 552 unsigned int i;
544 for( i=0; i<g_adminip_count; ++i ) 553 for( i=0; i<g_admin_nets_count; ++i )
545 if( !memcmp( g_adminip_addresses + i, ip, sizeof(ot_ip6)) && ( g_adminip_permissions[ i ] & permissions ) ) 554 if( address_in_net(ip, g_admin_nets + i) && (g_admin_nets_permissions[ i ] & permissions ))
546 return 1; 555 return 1;
547 return 0; 556 return 0;
548} 557}