summaryrefslogtreecommitdiff
path: root/src/ot_accesslist.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/ot_accesslist.h')
-rw-r--r--src/ot_accesslist.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/ot_accesslist.h b/src/ot_accesslist.h
new file mode 100644
index 0000000..c0f3fc2
--- /dev/null
+++ b/src/ot_accesslist.h
@@ -0,0 +1,78 @@
1/* This software was written by Dirk Engling <erdgeist@erdgeist.org>
2 It is considered beerware. Prost. Skol. Cheers or whatever. */
3
4#ifndef OT_ACCESSLIST_H__
5#define OT_ACCESSLIST_H__
6
7#include "trackerlogic.h"
8
9#if defined(WANT_ACCESSLIST_BLACK) && defined(WANT_ACCESSLIST_WHITE)
10#error WANT_ACCESSLIST_BLACK and WANT_ACCESSLIST_WHITE are exclusive.
11#endif
12
13#if defined(WANT_ACCESSLIST_BLACK) || defined(WANT_ACCESSLIST_WHITE)
14#define WANT_ACCESSLIST
15/* Reads the list, then starts a thread that rereads it when sent SIGHUP and
16 is stopped by being sent one, so the caller blocks SIGHUP process wide
17 beforehand */
18void accesslist_init(void);
19void accesslist_deinit(void);
20int accesslist_hashisvalid(const ot_hash hash);
21void accesslist_cleanup(void);
22
23/* Scan buf for up to capacity info_hashes in hexadecimal notation, one per
24 line, and return how many were written to dest */
25size_t accesslist_parse_hashes(ot_hash *dest, size_t capacity, const char *buf, size_t len);
26
27extern const char *g_accesslist_filename;
28#ifdef WANT_DYNAMIC_ACCESSLIST
29extern const char *g_accesslist_pipe_add;
30extern const char *g_accesslist_pipe_delete;
31#endif
32
33#else
34#ifdef WANT_DYNAMIC_ACCESSLIST
35#error WANT_DYNAMIC_ACCESSLIST needs either WANT_ACCESSLIST_BLACK or WANT_ACCESSLIST_WHITE
36#endif
37
38#define accesslist_init(accesslist_filename)
39#define accesslist_deinit()
40#define accesslist_hashisvalid(hash) 1
41#endif
42
43/* Test if an address is subset of an ot_net, return value is considered a bool */
44int accesslist_address_in_net(const ot_ip6 address, const ot_net *net);
45
46/* Store a value into a vector of struct { ot_net net, uint8_t[x] value } member;
47 returns NULL
48 if member_size is too small, or
49 if one of the nets inside the vector are a subnet of _net_, or
50 if _net_ is a subnet of one of the nets inside the vector, or
51 if the vector could not be resized
52 returns pointer to new member in vector for success
53 member_size can be sizeof(ot_net) to reduce the lookup to a boolean mapping
54*/
55void *accesslist_set_value_for_net(const ot_net *net, ot_vector *vector, const void *value, const size_t member_size);
56
57/* Takes a vector filled with struct { ot_net net, uint8_t[x] value } member;
58 Returns pointer to _member_ associated with the net, or NULL if not found
59 member_size can be sizeof(ot_net) to reduce the lookup to a boolean mapping
60*/
61void *accesslist_get_value_for_net(const ot_ip6 address, const ot_vector *vector, const size_t member_size);
62
63#ifdef WANT_IP_FROM_PROXY
64int proxylist_add_network(const ot_net *proxy, const ot_net *net);
65int proxylist_check_network(const ot_ip6 *proxy, const ot_ip6 address /* can be NULL to only check proxy */);
66#endif
67
68typedef enum {
69 OT_PERMISSION_MAY_FULLSCRAPE = 0x1,
70 OT_PERMISSION_MAY_STAT = 0x2,
71 OT_PERMISSION_MAY_LIVESYNC = 0x4,
72 OT_PERMISSION_MAY_PROXY = 0x8
73} ot_permissions;
74
75int accesslist_bless_net(ot_net *net, ot_permissions permissions);
76int accesslist_is_blessed(ot_ip6 ip, ot_permissions permissions);
77
78#endif