summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-01-27 15:46:06 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-01-27 15:46:06 +0000
commitb5eba018a0a948d7757448d4cd70fe33cb6b71a0 (patch)
tree7a00533384303e4802df1e935d50397decb9395b /src
parent7e3beac8435b957a583559d13f7666631719d15f (diff)
downloads6-dns-b5eba018a0a948d7757448d4cd70fe33cb6b71a0.tar.xz
Add shibari, prepare for 2.3.2.0dcache
Diffstat (limited to 'src')
-rw-r--r--src/caches/deps-exe/shibari6
-rw-r--r--src/caches/deps-lib/shibari4
-rw-r--r--src/caches/shibari-internal.h25
-rw-r--r--src/caches/shibari.c14
-rw-r--r--src/caches/shibari_whitelist_add6.c28
-rw-r--r--src/caches/shibari_whitelist_ip4_match.c15
-rw-r--r--src/caches/shibari_whitelist_ip6_match.c16
-rw-r--r--src/caches/shibari_whitelist_read.c58
8 files changed, 166 insertions, 0 deletions
diff --git a/src/caches/deps-exe/shibari b/src/caches/deps-exe/shibari
new file mode 100644
index 0000000..ae7e7f9
--- /dev/null
+++ b/src/caches/deps-exe/shibari
@@ -0,0 +1,6 @@
+libshibari.a.xyzzy
+${LIBDCACHE}
+${LIBS6DNS}
+-lskarnet
+${SOCKET_LIB}
+${SYSCLOCK_LIB}
diff --git a/src/caches/deps-lib/shibari b/src/caches/deps-lib/shibari
new file mode 100644
index 0000000..9e34094
--- /dev/null
+++ b/src/caches/deps-lib/shibari
@@ -0,0 +1,4 @@
+shibari_whitelist_add6.o
+shibari_whitelist_ip4_match.o
+shibari_whitelist_ip6_match.o
+shibari_whitelist_read.o
diff --git a/src/caches/shibari-internal.h b/src/caches/shibari-internal.h
new file mode 100644
index 0000000..048faa5
--- /dev/null
+++ b/src/caches/shibari-internal.h
@@ -0,0 +1,25 @@
+/* ISC license. */
+
+#ifndef S6DNS_SHIBARI_INTERNAL_H
+#define S6DNS_SHIBARI_INTERNAL_H
+
+#include <stdint.h>
+
+#include <skalibs/diuint32.h>
+#include <skalibs/genalloc.h>
+
+typedef struct shibari_ip6_s shibari_ip6_t, *shibari_ip6_t_ref ;
+struct shibari_ip6_s
+{
+ uint64_t addr0 ;
+ uint64_t addr1 ;
+ uint64_t mask0 ;
+ uint64_t mask1 ;
+} ;
+
+extern int shibari_whitelist_add6 (genalloc *g, char const *, uint16_t) ;
+extern int shibari_whitelist_read (char const *, genalloc *, genalloc *) ;
+extern int shibari_whitelist_ip4_match (diuint32 const *, size_t, char const *) ;
+extern int shibari_whitelist_ip6_match (shibari_ip6_t const *, size_t, char const *) ;
+
+#endif
diff --git a/src/caches/shibari.c b/src/caches/shibari.c
new file mode 100644
index 0000000..77334f6
--- /dev/null
+++ b/src/caches/shibari.c
@@ -0,0 +1,14 @@
+/* ISC license. */
+
+#include <skalibs/sgetopt.h>
+#include <skalibs/strerr2.h>
+
+#include <s6-dns/s6dns.h>
+
+#define USAGE "shibari [ -m max ] [ -i ipsend ] [ [ -u uid ] [ -g gid ] | [ -U ] ]"
+#define dieusage() strerr_dieusage(100, USAGE)
+
+int main (int argc, char const *const *argv)
+{
+ return 0 ;
+}
diff --git a/src/caches/shibari_whitelist_add6.c b/src/caches/shibari_whitelist_add6.c
new file mode 100644
index 0000000..0c9e53a
--- /dev/null
+++ b/src/caches/shibari_whitelist_add6.c
@@ -0,0 +1,28 @@
+/* ISC license. */
+
+#include <stdint.h>
+
+#include <skalibs/uint64.h>
+#include <skalibs/genalloc.h>
+
+#include "shibari-internal.h"
+
+int shibari_whitelist_add6 (genalloc *g, char const *ip6, uint16_t mask)
+{
+ shibari_ip6_t shix ;
+ if (mask >= 64)
+ {
+ shix.mask0 = ~(uint64_t)0 ;
+ shix.mask1 = ((uint64_t)1 << (mask - 64)) - 1 ;
+ }
+ else
+ {
+ shix.mask0 = ((uint64_t)1 << mask) - 1 ;
+ shix.mask1 = 0 ;
+ }
+ uint64_unpack_big(ip6, &shix.addr0) ;
+ shix.addr0 &= shix.mask0 ;
+ uint64_unpack_big(ip6 + 8, &shix.addr1) ;
+ shix.addr1 &= shix.mask1 ;
+ return genalloc_append(shibari_ip6_t, g, &shix) ;
+}
diff --git a/src/caches/shibari_whitelist_ip4_match.c b/src/caches/shibari_whitelist_ip4_match.c
new file mode 100644
index 0000000..fbf11ac
--- /dev/null
+++ b/src/caches/shibari_whitelist_ip4_match.c
@@ -0,0 +1,15 @@
+/* ISC license. */
+
+#include <stdint.h>
+
+#include <skalibs/uint32.h>
+
+#include "shibari-internal.h"
+
+int shibari_whitelist_ip4_match (diuint32 const *s, size_t len, char const *ip)
+{
+ uint32_t ip4 ;
+ uint32_unpack_big(ip, &ip4) ;
+ for (; len-- ; s++) if ((ip4 & s->right) == s->left) return 1 ;
+ return 0 ;
+}
diff --git a/src/caches/shibari_whitelist_ip6_match.c b/src/caches/shibari_whitelist_ip6_match.c
new file mode 100644
index 0000000..c728081
--- /dev/null
+++ b/src/caches/shibari_whitelist_ip6_match.c
@@ -0,0 +1,16 @@
+/* ISC license. */
+
+#include <stdint.h>
+
+#include <skalibs/uint64.h>
+
+#include "shibari-internal.h"
+
+int shibari_whitelist_ip6_match (shibari_ip6_t const *s, size_t len, char const *ip)
+{
+ uint64_t addr0, addr1 ;
+ uint64_unpack_big(ip, &addr0) ;
+ uint64_unpack_big(ip + 8, &addr1) ;
+ for (; len-- ; s++) if ((addr0 & s->mask0) == s->addr0 && (addr1 & s->mask1) == s->addr1) return 1 ;
+ return 0 ;
+}
diff --git a/src/caches/shibari_whitelist_read.c b/src/caches/shibari_whitelist_read.c
new file mode 100644
index 0000000..58dd2a0
--- /dev/null
+++ b/src/caches/shibari_whitelist_read.c
@@ -0,0 +1,58 @@
+/* ISC license. */
+
+#include <stdint.h>
+#include <errno.h>
+#include <dirent.h>
+
+#include <skalibs/uint16.h>
+#include <skalibs/uint32.h>
+#include <skalibs/diuint32.h>
+#include <skalibs/genalloc.h>
+#include <skalibs/direntry.h>
+#include <skalibs/ip46.h>
+
+#include "shibari-internal.h"
+
+static int shibari_whitelist_add4 (genalloc *g, char const *ip4, uint16_t mask)
+{
+ diuint32 d = { .right = ((uint32_t)1 << mask) - 1 } ;
+ uint32_unpack_big(ip4, &d.left) ;
+ d.left &= d.right ;
+ return genalloc_append(diuint32, g, &d) ;
+}
+
+int shibari_whitelist_read (char const *path, genalloc *ip4, genalloc *ip6)
+{
+ DIR *dir = opendir(path) ;
+ if (!dir) return 0 ;
+ genalloc_setlen(diuint32, ip4, 0) ;
+ genalloc_setlen(shibari_ip6_t, ip6, 0) ;
+ for (;;)
+ {
+ direntry *d ;
+ size_t pos ;
+ ip46_t ip ;
+ uint16_t mask ;
+ errno = 0 ;
+ d = readdir(dir) ;
+ if (!d) break ;
+ if (d->d_name[0] == '.' && (!d->d_name[1] || (d->d_name[1] == '.' && !d->d_name[2]))) continue ;
+ pos = ip46_scan(d->d_name, &ip) ;
+ if (!pos) continue ;
+ if (d->d_name[pos] && d->d_name[pos] != '_') continue ;
+ if (!d->d_name[pos]) mask = ip46_is6(&ip) ? 128 : 32 ;
+ else
+ {
+ if (!uint160_scan(d->d_name + pos + 1, &mask)) continue ;
+ if (mask > (ip46_is6(&ip) ? 128 : 32)) continue ;
+ }
+ if (!(ip46_is6(&ip) ? shibari_whitelist_add6(ip6, ip.ip, mask) : shibari_whitelist_add4(ip4, ip.ip, mask))) goto err ;
+ }
+ if (errno) goto err ;
+ dir_close(dir) ;
+ return 1 ;
+
+ err:
+ dir_close(dir) ;
+ return 0 ;
+}