summaryrefslogtreecommitdiff
path: root/src/cache/tcpconnection.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2024-07-16 01:51:04 +0000
committerLaurent Bercot <ska@appnovation.com>2024-07-16 01:51:04 +0000
commitd1c4602f80e395d1d6ab0453b8f0a6cc10aefadf (patch)
tree9e1410955b66e99d2284b0baa207d32264669716 /src/cache/tcpconnection.c
parent8b435b76d68dd8f11808f0cff4d8998d2be48f4c (diff)
downloadshibari-d1c4602f80e395d1d6ab0453b8f0a6cc10aefadf.tar.xz
Refactor dcache, add prep for shibari-cache
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/cache/tcpconnection.c')
-rw-r--r--src/cache/tcpconnection.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/cache/tcpconnection.c b/src/cache/tcpconnection.c
new file mode 100644
index 0000000..7c7f714
--- /dev/null
+++ b/src/cache/tcpconnection.c
@@ -0,0 +1,49 @@
+/* ISC license. */
+
+#include <stdint.h>
+
+#include <skalibs/cdb.h>
+
+#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 ;
+}