From e5cc55570c2c986c71fc75bcde93620598db7be4 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 18 Jul 2024 20:55:16 +0000 Subject: Add accept directive to cache-config Signed-off-by: Laurent Bercot --- src/cache/access.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/cache/tcpconnection.c | 44 -------------------------------------------- 2 files changed, 47 insertions(+), 44 deletions(-) create mode 100644 src/cache/access.c (limited to 'src/cache') diff --git a/src/cache/access.c b/src/cache/access.c new file mode 100644 index 0000000..8f87125 --- /dev/null +++ b/src/cache/access.c @@ -0,0 +1,47 @@ +/* ISC license. */ + +#include + +#include + +#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 ip4_access (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 ; +} + +int ip6_access (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 ; +} diff --git a/src/cache/tcpconnection.c b/src/cache/tcpconnection.c index 7c7f714..bd72fb4 100644 --- a/src/cache/tcpconnection.c +++ b/src/cache/tcpconnection.c @@ -1,49 +1,5 @@ /* ISC license. */ -#include - -#include - #include "shibari-cache-internal.h" genset *tcpconn = 0 ; - -static inline int check (char const *key, size_t keylen) -{ - cdb_data data ; - return cdb_find(&confdb, &data, key, keylen) ; -} - -int tcp4_access (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 ; -} - -int tcp6_access (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 ; -} -- cgit v1.3.1