From ad541c67761b8aa6da1566802c347cac4018d0c2 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 2 Nov 2026 20:50:24 +0100 Subject: Move the build sources into src/ --- src/ot_accesslist.h | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/ot_accesslist.h (limited to 'src/ot_accesslist.h') diff --git a/src/ot_accesslist.h b/src/ot_accesslist.h new file mode 100644 index 0000000..68c88dc --- /dev/null +++ b/src/ot_accesslist.h @@ -0,0 +1,77 @@ +/* This software was written by Dirk Engling + It is considered beerware. Prost. Skol. Cheers or whatever. */ + +#ifndef OT_ACCESSLIST_H__ +#define OT_ACCESSLIST_H__ + +#include "trackerlogic.h" + +#if defined(WANT_ACCESSLIST_BLACK) && defined(WANT_ACCESSLIST_WHITE) +#error WANT_ACCESSLIST_BLACK and WANT_ACCESSLIST_WHITE are exclusive. +#endif + +#if defined(WANT_ACCESSLIST_BLACK) || defined(WANT_ACCESSLIST_WHITE) +#define WANT_ACCESSLIST +/* Starts a thread that rereads the list when sent SIGHUP, and is stopped by + being sent one, so the caller blocks SIGHUP process wide beforehand */ +void accesslist_init(void); +void accesslist_deinit(void); +int accesslist_hashisvalid(const ot_hash hash); +void accesslist_cleanup(void); + +/* Scan buf for up to capacity info_hashes in hexadecimal notation, one per + line, and return how many were written to dest */ +size_t accesslist_parse_hashes(ot_hash *dest, size_t capacity, const char *buf, size_t len); + +extern const char *g_accesslist_filename; +#ifdef WANT_DYNAMIC_ACCESSLIST +extern const char *g_accesslist_pipe_add; +extern const char *g_accesslist_pipe_delete; +#endif + +#else +#ifdef WANT_DYNAMIC_ACCESSLIST +#error WANT_DYNAMIC_ACCESSLIST needs either WANT_ACCESSLIST_BLACK or WANT_ACCESSLIST_WHITE +#endif + +#define accesslist_init(accesslist_filename) +#define accesslist_deinit() +#define accesslist_hashisvalid(hash) 1 +#endif + +/* Test if an address is subset of an ot_net, return value is considered a bool */ +int accesslist_address_in_net(const ot_ip6 address, const ot_net *net); + +/* Store a value into a vector of struct { ot_net net, uint8_t[x] value } member; + returns NULL + if member_size is too small, or + if one of the nets inside the vector are a subnet of _net_, or + if _net_ is a subnet of one of the nets inside the vector, or + if the vector could not be resized + returns pointer to new member in vector for success + member_size can be sizeof(ot_net) to reduce the lookup to a boolean mapping +*/ +void *accesslist_set_value_for_net(const ot_net *net, ot_vector *vector, const void *value, const size_t member_size); + +/* Takes a vector filled with struct { ot_net net, uint8_t[x] value } member; + Returns pointer to _member_ associated with the net, or NULL if not found + member_size can be sizeof(ot_net) to reduce the lookup to a boolean mapping +*/ +void *accesslist_get_value_for_net(const ot_ip6 address, const ot_vector *vector, const size_t member_size); + +#ifdef WANT_IP_FROM_PROXY +int proxylist_add_network(const ot_net *proxy, const ot_net *net); +int proxylist_check_network(const ot_ip6 *proxy, const ot_ip6 address /* can be NULL to only check proxy */); +#endif + +typedef enum { + OT_PERMISSION_MAY_FULLSCRAPE = 0x1, + OT_PERMISSION_MAY_STAT = 0x2, + OT_PERMISSION_MAY_LIVESYNC = 0x4, + OT_PERMISSION_MAY_PROXY = 0x8 +} ot_permissions; + +int accesslist_bless_net(ot_net *net, ot_permissions permissions); +int accesslist_is_blessed(ot_ip6 ip, ot_permissions permissions); + +#endif -- cgit v1.3