diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2024-07-25 00:20:30 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska@appnovation.com> | 2024-07-25 00:20:30 +0000 |
| commit | fc85d676b5ca3de92264dfcb41c98d7c9b0d1398 (patch) | |
| tree | c9e77e23b9b2b35760f18ce8a7c36ab921b9905d /src/cache/clientaccess.c | |
| parent | 8c9b0194063411882d3bbcec80d5e5c861d37544 (diff) | |
| download | shibari-fc85d676b5ca3de92264dfcb41c98d7c9b0d1398.tar.gz | |
More shibari-cache stuff
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/cache/clientaccess.c')
| -rw-r--r-- | src/cache/clientaccess.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/cache/clientaccess.c b/src/cache/clientaccess.c new file mode 100644 index 0000000..0dc5270 --- /dev/null +++ b/src/cache/clientaccess.c @@ -0,0 +1,51 @@ +/* ISC license. */ + +#include <stdint.h> +#include <string.h> + +#include <skalibs/cdb.h> +#include <skalibs/ip46.h> + +#include "shibari-cache-internal.h" + +static inline int check (char const *key, size_t keylen) +{ + cdb_data data ; + return cdb_find(&confdb, &data, key, keylen) ; +} + +int clientaccess_ip4 (char const *ip) +{ + int r ; + char key[9] = "A4:" ; + uint8_t i = 33 ; + memcpy(key+4, ip, 4) ; + key[8] = 0 ; + while (i--) + { + key[3] = i ; + key[4 + (i>>3)] &= ~(1U << (7 - (i & 7))) ; + r = check(key, 8) ; + if (r) return r ; + } + return 0 ; +} + +#ifdef SKALIBS_IPV6_ENABLED +int clientaccess_ip6 (char const *ip) +{ + int r ; + char key[21] = "A6:" ; + uint8_t i = 129 ; + memcpy(key+4, ip, 16) ; + key[20] = 0 ; + while (i--) + { + key[3] = i ; + key[4 + (i>>3)] &= ~(1U << (7 - (i & 7))) ; + r = check(key, 20) ; + if (r) return r ; + } + return 0 ; +} +#endif |
