summaryrefslogtreecommitdiff
path: root/src/ot_accesslist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ot_accesslist.c')
-rw-r--r--src/ot_accesslist.c607
1 files changed, 607 insertions, 0 deletions
diff --git a/src/ot_accesslist.c b/src/ot_accesslist.c
new file mode 100644
index 0000000..5d4f059
--- /dev/null
+++ b/src/ot_accesslist.c
@@ -0,0 +1,607 @@
1/* This software was written by Dirk Engling <erdgeist@erdgeist.org>
2 It is considered beerware. Prost. Skol. Cheers or whatever. */
3
4/* System */
5#include <pthread.h>
6#include <signal.h>
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <unistd.h>
11#if defined(WANT_ACCESSLIST_BLACK) || defined(WANT_ACCESSLIST_WHITE)
12#include <fcntl.h>
13#include <stdint.h>
14#include <sys/mman.h>
15#include <sys/stat.h>
16#include <sys/types.h>
17#endif
18#ifdef WANT_DYNAMIC_ACCESSLIST
19#include <errno.h>
20#endif
21
22/* Opentracker */
23#include "ot_accesslist.h"
24#include "ot_hex.h"
25#include "ot_ip.h"
26#include "ot_vector.h"
27#include "trackerlogic.h"
28
29/* GLOBAL VARIABLES */
30#ifdef WANT_ACCESSLIST
31const char *g_accesslist_filename = NULL;
32#ifdef WANT_DYNAMIC_ACCESSLIST
33const char *g_accesslist_pipe_add = NULL;
34const char *g_accesslist_pipe_delete = NULL;
35#endif
36static pthread_mutex_t g_accesslist_mutex = PTHREAD_MUTEX_INITIALIZER;
37
38/* Accesslists are lock free linked lists. We can not make them locking, because every announce
39 would try to acquire the mutex, making it the most contested mutex in the whole of opentracker,
40 basically creating a central performance choke point.
41
42 The idea is that updating the list heads happens under the g_accesslist_mutex guard and is
43 done atomically, while consumers might potentially still hold pointers deeper inside the list.
44
45 Consumers (for now only via accesslist_hashisvalid) will always fetch the list head pointer
46 that is guaranteed to live for at least five minutes. This should be many orders of magnitudes
47 more than how long it will be needed by the bsearch done on the list. */
48struct ot_accesslist;
49typedef struct ot_accesslist ot_accesslist;
50struct ot_accesslist {
51 ot_hash *list;
52 size_t size;
53 ot_time base;
54 ot_accesslist *next;
55};
56static ot_accesslist *_Atomic g_accesslist = NULL;
57#ifdef WANT_DYNAMIC_ACCESSLIST
58static ot_accesslist *_Atomic g_accesslist_add = NULL;
59static ot_accesslist *_Atomic g_accesslist_delete = NULL;
60#endif
61
62/* Helpers to work on access lists */
63static int vector_compare_hash(const void *hash1, const void *hash2) { return memcmp(hash1, hash2, OT_HASH_COMPARE_SIZE); }
64
65static ot_accesslist *accesslist_free(ot_accesslist *accesslist) {
66 while (accesslist) {
67 ot_accesslist *this_accesslist = accesslist;
68 accesslist = this_accesslist->next;
69 free(this_accesslist->list);
70 free(this_accesslist);
71 }
72 return NULL;
73}
74
75static ot_accesslist *accesslist_make(ot_accesslist *next, size_t size) {
76 ot_accesslist *accesslist_new = malloc(sizeof(ot_accesslist));
77 if (accesslist_new) {
78 accesslist_new->list = size ? malloc(sizeof(ot_hash) * size) : NULL;
79 accesslist_new->size = size;
80 accesslist_new->base = 0;
81 accesslist_new->next = next;
82 if (size && !accesslist_new->list) {
83 free(accesslist_new);
84 accesslist_new = NULL;
85 }
86 }
87 return accesslist_new;
88}
89
90/* This must be called with g_accesslist_mutex held.
91 This will never delete head, because that might still be in use. */
92static void accesslist_clean(ot_accesslist *accesslist) {
93 while (accesslist && accesslist->next) {
94 if (time_since_minutes(accesslist->next->base) > 5)
95 accesslist->next = accesslist_free(accesslist->next);
96 accesslist = accesslist->next;
97 }
98}
99
100/* A hash needs forty bytes, and all but a final one are followed by at least
101 one separator, so n hashes need at least 41n - 1 bytes. (len + 1) / 41 is
102 therefore an exact upper bound on what a buffer of len bytes can hold. */
103size_t accesslist_parse_hashes(ot_hash *dest, size_t capacity, const char *buf, size_t len) {
104 const char *end = buf + len;
105 const char *offs = buf;
106 size_t count = 0;
107
108 while (count < capacity && end - offs >= 40) {
109 if (hex_to_hash(dest[count], offs)) {
110 offs += 40;
111
112 if (offs == end || !hex_isdigit((unsigned char)*offs))
113 ++count;
114 }
115
116 /* Find start of next line */
117 while (offs < end && *(offs++) != '\n') {}
118 }
119
120 return count;
121}
122
123/* Map a file read only. Returns 0 and sets map and maplen on success, -1 if
124 the file cannot be opened or mapped. */
125static int accesslist_map(const char *filename, const char **map, size_t *maplen) {
126 struct stat st;
127 void *mapped;
128 int fd = open(filename, O_RDONLY);
129
130 if (fd < 0)
131 return -1;
132
133 if (fstat(fd, &st) < 0 || st.st_size < 0 || (uintmax_t)st.st_size > (uintmax_t)SIZE_MAX) {
134 close(fd);
135 return -1;
136 }
137
138 if (st.st_size == 0) {
139 close(fd);
140 *map = NULL;
141 *maplen = 0;
142 return 0;
143 }
144
145 mapped = mmap(NULL, (size_t)st.st_size, PROT_READ, MAP_SHARED, fd, 0);
146 close(fd);
147
148 if (mapped == MAP_FAILED)
149 return -1;
150
151 *map = mapped;
152 *maplen = (size_t)st.st_size;
153 return 0;
154}
155
156static void accesslist_readfile(void) {
157 ot_accesslist *accesslist_new;
158 const char *map;
159 size_t maplen, capacity, found;
160
161 if (!g_accesslist_filename)
162 return;
163
164 if (accesslist_map(g_accesslist_filename, &map, &maplen) < 0) {
165 char *wd = getcwd(NULL, 0);
166 fprintf(stderr, "Warning: Can't open accesslist file: %s (but will try to create it later, if necessary and possible).\nPWD: %s\n", g_accesslist_filename, wd);
167 free(wd);
168 return;
169 }
170
171 /* Make room for the most info_hashes this file could possibly hold */
172 capacity = (maplen + 1) / 41;
173 accesslist_new = accesslist_make(g_accesslist, capacity);
174 if (!accesslist_new) {
175 fprintf(stderr, "Warning: Not enough memory to allocate %zd bytes for accesslist buffer. May succeed later.\n", capacity * sizeof(ot_hash));
176 if (map)
177 munmap((void *)map, maplen);
178 return;
179 }
180
181 found = maplen ? accesslist_parse_hashes(accesslist_new->list, capacity, map, maplen) : 0;
182#ifdef _DEBUG
183 fprintf(stderr, "Added %zd info_hashes to accesslist\n", found);
184#endif
185
186 if (map)
187 munmap((void *)map, maplen);
188
189 if (found)
190 qsort(accesslist_new->list, found, sizeof(ot_hash), vector_compare_hash);
191 accesslist_new->size = found;
192
193 /* Now exchange the accesslist vector in the least race condition prone way */
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 = time_now_minutes();
199 accesslist_new->next = g_accesslist;
200 g_accesslist = accesslist_new; /* Only now set a new list */
201
202#ifdef WANT_DYNAMIC_ACCESSLIST
203 /* If we have dynamic accesslists, reloading a new one will always void the add/delete lists.
204 Insert empty ones at the list head */
205 if (g_accesslist_add && (accesslist_new = accesslist_make(g_accesslist_add, 0)) != NULL) {
206 g_accesslist_add->base = time_now_minutes();
207 g_accesslist_add = accesslist_new;
208 }
209 if (g_accesslist_delete && (accesslist_new = accesslist_make(g_accesslist_delete, 0)) != NULL) {
210 g_accesslist_delete->base = time_now_minutes();
211 g_accesslist_delete = accesslist_new;
212 }
213#endif
214
215 accesslist_clean(g_accesslist);
216
217 pthread_mutex_unlock(&g_accesslist_mutex);
218}
219
220int accesslist_hashisvalid(const ot_hash hash) {
221 /* Get working copy of current access list */
222 ot_accesslist *accesslist = g_accesslist;
223#ifdef WANT_DYNAMIC_ACCESSLIST
224 ot_accesslist *accesslist_add, *accesslist_delete;
225#endif
226 void *exactmatch = NULL;
227
228 if (accesslist && accesslist->size)
229 exactmatch = bsearch(hash, accesslist->list, accesslist->size, OT_HASH_COMPARE_SIZE, vector_compare_hash);
230
231#ifdef WANT_DYNAMIC_ACCESSLIST
232 /* If we had no match on the main list, scan the list of dynamically added hashes */
233 accesslist_add = g_accesslist_add;
234 if ((exactmatch == NULL) && accesslist_add && accesslist_add->size)
235 exactmatch = bsearch(hash, accesslist_add->list, accesslist_add->size, OT_HASH_COMPARE_SIZE, vector_compare_hash);
236
237 /* If we found a matching hash on the main list, scan the list of dynamically deleted hashes */
238 accesslist_delete = g_accesslist_delete;
239 if ((exactmatch != NULL) && accesslist_delete && accesslist_delete->size && bsearch(hash, accesslist_delete->list, accesslist_delete->size, OT_HASH_COMPARE_SIZE, vector_compare_hash))
240 exactmatch = NULL;
241#endif
242
243#ifdef WANT_ACCESSLIST_BLACK
244 return exactmatch == NULL;
245#else
246 return exactmatch != NULL;
247#endif
248}
249
250static void *accesslist_worker(void *args) {
251 int sig;
252 sigset_t signal_mask;
253
254 sigemptyset(&signal_mask);
255 sigaddset(&signal_mask, SIGHUP);
256
257 (void)args;
258
259 while (1) {
260 /* Wait for signals */
261 while (sigwait(&signal_mask, &sig) != 0)
262 ;
263
264 if (!g_opentracker_running)
265 return NULL;
266
267 accesslist_readfile();
268 }
269 return NULL;
270}
271
272#ifdef WANT_DYNAMIC_ACCESSLIST
273static pthread_t thread_adder_id, thread_deleter_id;
274static _Atomic int adder_left, deleter_left;
275static void *accesslist_adddel_worker(const char *fifoname, ot_accesslist *_Atomic *adding_to, ot_accesslist *_Atomic *removing_from) {
276 struct stat st;
277
278 if (!stat(fifoname, &st)) {
279 if (!S_ISFIFO(st.st_mode)) {
280 fprintf(stderr, "Error when starting dynamic accesslists: Found Non-FIFO file at %s.\nPlease remove it and restart opentracker.\n", fifoname);
281 return NULL;
282 }
283 } else {
284 if (mkfifo(fifoname, 0600) && errno != EEXIST) {
285 fprintf(stderr, "Error when starting dynamic accesslists: Couldn't create FIFO at %s, error: %s\n", fifoname, strerror(errno));
286 return NULL;
287 }
288 }
289
290 while (g_opentracker_running) {
291 FILE *fifo = fopen(fifoname, "r");
292 char *line = NULL;
293 size_t linecap = 0;
294 ssize_t linelen;
295
296 if (!fifo) {
297 /* Woken on purpose: the loop condition above decides what happens next */
298 if (errno == EINTR)
299 continue;
300 fprintf(stderr, "Error when reading dynamic accesslists: Couldn't open FIFO at %s, error: %s\n", fifoname, strerror(errno));
301 return NULL;
302 }
303
304 while ((linelen = getline(&line, &linecap, fifo)) > 0) {
305 ot_hash info_hash;
306
307 printf("Got line %*s", (int)linelen, line);
308 /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*"
309 If there's not enough characters for an info_hash in the line, skip it. */
310 if (linelen < 41)
311 continue;
312
313 if (!hex_to_hash(info_hash, line))
314 continue;
315
316 /* From now on we modify g_accesslist_add and g_accesslist_delete, so prevent the
317 other worker threads from doing the same */
318 pthread_mutex_lock(&g_accesslist_mutex);
319
320 /* If the info hash is in the removing_from list, create a new head without that entry */
321 if (*removing_from && (*removing_from)->list) {
322 ot_hash *exactmatch = bsearch(info_hash, (*removing_from)->list, (*removing_from)->size, OT_HASH_COMPARE_SIZE, vector_compare_hash);
323 if (exactmatch) {
324 ptrdiff_t off = exactmatch - (*removing_from)->list;
325 ot_accesslist *accesslist_new = accesslist_make(*removing_from, (*removing_from)->size - 1);
326 if (accesslist_new) {
327 size_t after = (*removing_from)->size - off - 1;
328
329 /* Removing the only entry leaves a list with no room at all, and
330 memcpy may not be handed that even for nothing */
331 if (off)
332 memcpy(accesslist_new->list, (*removing_from)->list, sizeof(ot_hash) * off);
333 if (after)
334 memcpy(accesslist_new->list + off, (*removing_from)->list + off + 1, sizeof(ot_hash) * after);
335 (*removing_from)->base = time_now_minutes();
336 *removing_from = accesslist_new;
337 }
338 }
339 }
340
341 /* Simple case: there's no adding_to list yet, create one with one member */
342 if (!*adding_to) {
343 ot_accesslist *accesslist_new = accesslist_make(NULL, 1);
344 if (accesslist_new) {
345 memcpy(accesslist_new->list, info_hash, sizeof(ot_hash));
346 *adding_to = accesslist_new;
347 }
348 } else {
349 int exactmatch = 0;
350 ot_hash *insert_point = vector_binary_search(info_hash, (*adding_to)->list, (*adding_to)->size, sizeof(ot_hash), OT_HASH_COMPARE_SIZE, &exactmatch);
351
352 /* Only if the info hash is not in the adding_to list, create a new head with that entry */
353 if (!exactmatch) {
354 ot_accesslist *accesslist_new = accesslist_make(*adding_to, (*adding_to)->size + 1);
355 if (accesslist_new) {
356 ptrdiff_t off = (*adding_to)->size ? insert_point - (*adding_to)->list : 0;
357 size_t after = (*adding_to)->size - off;
358
359 /* A reload leaves an empty list with no array at all, and memcpy
360 may not be handed a null pointer even for nothing */
361 if (off)
362 memcpy(accesslist_new->list, (*adding_to)->list, sizeof(ot_hash) * off);
363 memcpy(accesslist_new->list + off, info_hash, sizeof(info_hash));
364 if (after)
365 memcpy(accesslist_new->list + off + 1, (*adding_to)->list + off, sizeof(ot_hash) * after);
366 (*adding_to)->base = time_now_minutes();
367 *adding_to = accesslist_new;
368 }
369 }
370 }
371
372 pthread_mutex_unlock(&g_accesslist_mutex);
373 }
374
375 free(line);
376 fclose(fifo);
377 }
378 return NULL;
379}
380
381static void *accesslist_adder_worker(void *args) {
382 (void)args;
383 accesslist_adddel_worker(g_accesslist_pipe_add, &g_accesslist_add, &g_accesslist_delete);
384 atomic_store(&adder_left, 1);
385 return NULL;
386}
387static void *accesslist_deleter_worker(void *args) {
388 (void)args;
389 accesslist_adddel_worker(g_accesslist_pipe_delete, &g_accesslist_delete, &g_accesslist_add);
390 atomic_store(&deleter_left, 1);
391 return NULL;
392}
393
394/* These sit in a blocking open or read on a FIFO, so they are woken the way
395 the other workers are, and the signal is repeated because it only
396 interrupts a call already under way. The pipe name is what says whether
397 the thread was ever started. */
398static void accesslist_stop_fifo_worker(pthread_t thread, _Atomic int *left, const char *pipe_name) {
399 if (!pipe_name)
400 return;
401
402 while (!atomic_load(left)) {
403 pthread_kill(thread, OT_SIGNAL_WAKE);
404 usleep(1000);
405 }
406 pthread_join(thread, NULL);
407}
408#endif
409
410static pthread_t thread_id;
411void accesslist_init(void) {
412 /* Everything that consults the list starts after this returns */
413 accesslist_readfile();
414
415 if (pthread_create(&thread_id, NULL, accesslist_worker, NULL))
416 exerr("Cannot create accesslist worker thread.");
417#ifdef WANT_DYNAMIC_ACCESSLIST
418 if (g_accesslist_pipe_add && pthread_create(&thread_adder_id, NULL, accesslist_adder_worker, NULL))
419 exerr("Cannot create accesslist adder thread.");
420 if (g_accesslist_pipe_delete && pthread_create(&thread_deleter_id, NULL, accesslist_deleter_worker, NULL))
421 exerr("Cannot create accesslist deleter thread.");
422#endif
423}
424
425void accesslist_deinit(void) {
426 /* Wake the worker and wait for it to notice that the tracker is stopping. */
427 pthread_kill(thread_id, SIGHUP);
428 pthread_join(thread_id, NULL);
429
430#ifdef WANT_DYNAMIC_ACCESSLIST
431 /* Before the lists they are reading are freed below */
432 accesslist_stop_fifo_worker(thread_adder_id, &adder_left, g_accesslist_pipe_add);
433 accesslist_stop_fifo_worker(thread_deleter_id, &deleter_left, g_accesslist_pipe_delete);
434#endif
435
436 pthread_mutex_lock(&g_accesslist_mutex);
437
438 g_accesslist = accesslist_free(g_accesslist);
439
440#ifdef WANT_DYNAMIC_ACCESSLIST
441 g_accesslist_add = accesslist_free(g_accesslist_add);
442 g_accesslist_delete = accesslist_free(g_accesslist_delete);
443#endif
444
445 pthread_mutex_unlock(&g_accesslist_mutex);
446}
447
448void accesslist_cleanup(void) {
449 pthread_mutex_lock(&g_accesslist_mutex);
450
451 accesslist_clean(g_accesslist);
452#if WANT_DYNAMIC_ACCESSLIST
453 accesslist_clean(g_accesslist_add);
454 accesslist_clean(g_accesslist_delete);
455#endif
456
457 pthread_mutex_unlock(&g_accesslist_mutex);
458}
459#endif
460
461int accesslist_address_in_net(const ot_ip6 address, const ot_net *net) {
462 int bits = net->bits, checkbits = (0x7f00 >> (bits & 7));
463 int result = memcmp(address, &net->address, bits >> 3);
464 if (!result && (bits & 7))
465 result = (checkbits & address[bits >> 3]) - (checkbits & net->address[bits >> 3]);
466 return result == 0;
467}
468
469void *accesslist_set_value_for_net(const ot_net *net, ot_vector *vector, const void *value, const size_t member_size) {
470 size_t i;
471 int exactmatch;
472
473 /* Caller must have a concept of ot_net in it's member */
474 if (member_size < sizeof(ot_net))
475 return 0;
476
477 /* Check each net in vector for overlap */
478 uint8_t *member = ((uint8_t *)vector->data);
479 for (i = 0; i < vector->size; ++i) {
480 if (accesslist_address_in_net(*(ot_ip6 *)member, net) || accesslist_address_in_net(net->address, (ot_net *)member))
481 return 0;
482 member += member_size;
483 }
484
485 member = vector_find_or_insert(vector, (void *)net, member_size, sizeof(ot_net), &exactmatch);
486 if (member) {
487 memcpy(member, net, sizeof(ot_net));
488 memcpy(member + sizeof(ot_net), value, member_size - sizeof(ot_net));
489 }
490
491 return member;
492}
493
494/* Takes a vector filled with { ot_net net, uint8_t[x] value };
495 Returns value associated with the net, or NULL if not found */
496void *accesslist_get_value_for_net(const ot_ip6 address, const ot_vector *vector, const size_t member_size) {
497 int exactmatch;
498 /* This binary search will return a pointer to the first non-containing network... */
499 ot_net *net = vector_binary_search(address, vector->data, vector->size, member_size, sizeof(ot_ip6), &exactmatch);
500 if (!net)
501 return NULL;
502 /* ... so we'll need to move back one step unless we've exactly hit the first address in network */
503 if (!exactmatch && ((void *)net > vector->data))
504 --net;
505 if (!accesslist_address_in_net(address, net))
506 return NULL;
507 return (void *)net;
508}
509
510#ifdef WANT_IP_FROM_PROXY
511typedef struct {
512 ot_net *proxy;
513 ot_vector networks;
514} ot_proxymap;
515
516static ot_vector g_proxies_list;
517static pthread_mutex_t g_proxies_list_mutex = PTHREAD_MUTEX_INITIALIZER;
518
519int proxylist_add_network(const ot_net *proxy, const ot_net *net) {
520 ot_proxymap *map;
521 int exactmatch, result = 1;
522 pthread_mutex_lock(&g_proxies_list_mutex);
523
524 /* If we have a direct hit, use and extend the vector there */
525 map = vector_binary_search(proxy, g_proxies_list.data, g_proxies_list.size, sizeof(ot_proxymap), sizeof(ot_net), &exactmatch);
526
527 if (!map || !exactmatch) {
528 /* else see, if we've got overlapping networks
529 and get a new empty vector if not */
530 ot_vector empty;
531 memset(&empty, 0, sizeof(ot_vector));
532 map = accesslist_set_value_for_net(proxy, &g_proxies_list, &empty, sizeof(ot_proxymap));
533 }
534
535 if (map && accesslist_set_value_for_net(net, &map->networks, NULL, sizeof(ot_net)))
536 result = 1;
537
538 pthread_mutex_unlock(&g_proxies_list_mutex);
539 return result;
540}
541
542int proxylist_check_proxy(const ot_ip6 proxy, const ot_ip6 address) {
543 int result = 0;
544 ot_proxymap *map;
545
546 pthread_mutex_lock(&g_proxies_list_mutex);
547
548 if ((map = accesslist_get_value_for_net(proxy, &g_proxies_list, sizeof(ot_proxymap))))
549 if (!address || accesslist_get_value_for_net(address, &map->networks, sizeof(ot_net)))
550 result = 1;
551
552 pthread_mutex_unlock(&g_proxies_list_mutex);
553 return result;
554}
555
556#endif
557
558static ot_net g_admin_nets[OT_ADMINIP_MAX];
559static ot_permissions g_admin_nets_permissions[OT_ADMINIP_MAX];
560static size_t g_admin_nets_count = 0;
561
562int accesslist_bless_net(ot_net *net, ot_permissions permissions) {
563 if (g_admin_nets_count >= OT_ADMINIP_MAX)
564 return -1;
565
566 memcpy(g_admin_nets + g_admin_nets_count, net, sizeof(ot_net));
567 g_admin_nets_permissions[g_admin_nets_count++] = permissions;
568
569#ifdef _DEBUG
570 {
571 char _debug[512];
572 int off = snprintf(_debug, sizeof(_debug), "Blessing ip net ");
573 off += ip_format(_debug + off, net->address);
574 if (net->bits < 128) {
575 _debug[off++] = '/';
576 if (ip_is_v4mapped(net->address))
577 off += snprintf(_debug + off, sizeof(_debug) - off, "%d", net->bits - 96);
578 else
579 off += snprintf(_debug + off, sizeof(_debug) - off, "%d", net->bits);
580 }
581
582 if (permissions & OT_PERMISSION_MAY_STAT)
583 off += snprintf(_debug + off, 512 - off, " may_fetch_stats");
584 if (permissions & OT_PERMISSION_MAY_LIVESYNC)
585 off += snprintf(_debug + off, 512 - off, " may_sync_live");
586 if (permissions & OT_PERMISSION_MAY_FULLSCRAPE)
587 off += snprintf(_debug + off, 512 - off, " may_fetch_fullscrapes");
588 if (permissions & OT_PERMISSION_MAY_PROXY)
589 off += snprintf(_debug + off, 512 - off, " may_proxy");
590 if (!permissions)
591 off += snprintf(_debug + off, sizeof(_debug) - off, " nothing");
592 _debug[off++] = '.';
593 _debug[off++] = '\n';
594 (void)write(2, _debug, off);
595 }
596#endif
597
598 return 0;
599}
600
601int accesslist_is_blessed(ot_ip6 ip, ot_permissions permissions) {
602 size_t i;
603 for (i = 0; i < g_admin_nets_count; ++i)
604 if (accesslist_address_in_net(ip, g_admin_nets + i) && (g_admin_nets_permissions[i] & permissions))
605 return 1;
606 return 0;
607}