diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2020-01-27 15:46:06 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2020-01-27 15:46:06 +0000 |
commit | b5eba018a0a948d7757448d4cd70fe33cb6b71a0 (patch) | |
tree | 7a00533384303e4802df1e935d50397decb9395b | |
parent | 7e3beac8435b957a583559d13f7666631719d15f (diff) | |
download | s6-dns-b5eba018a0a948d7757448d4cd70fe33cb6b71a0.tar.xz |
Add shibari, prepare for 2.3.2.0dcache
-rw-r--r-- | COPYING | 2 | ||||
-rw-r--r-- | INSTALL | 2 | ||||
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | package/deps.mak | 14 | ||||
-rw-r--r-- | package/info | 2 | ||||
-rw-r--r-- | src/caches/deps-exe/shibari | 6 | ||||
-rw-r--r-- | src/caches/deps-lib/shibari | 4 | ||||
-rw-r--r-- | src/caches/shibari-internal.h | 25 | ||||
-rw-r--r-- | src/caches/shibari.c | 14 | ||||
-rw-r--r-- | src/caches/shibari_whitelist_add6.c | 28 | ||||
-rw-r--r-- | src/caches/shibari_whitelist_ip4_match.c | 15 | ||||
-rw-r--r-- | src/caches/shibari_whitelist_ip6_match.c | 16 | ||||
-rw-r--r-- | src/caches/shibari_whitelist_read.c | 58 |
13 files changed, 190 insertions, 3 deletions
@@ -1,4 +1,4 @@ -Copyright (c) 2011-2019 Laurent Bercot <ska-skaware@skarnet.org> +Copyright (c) 2011-2020 Laurent Bercot <ska-skaware@skarnet.org> Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -6,7 +6,7 @@ Build Instructions - A POSIX-compliant C development environment - GNU make version 3.81 or later - - skalibs version 2.9.1.0 or later: http://skarnet.org/software/skalibs/ + - skalibs version 2.9.2.0 or later: http://skarnet.org/software/skalibs/ This software will run on any operating system that implements POSIX.1-2008, available at: @@ -1,5 +1,12 @@ Changelog for s6-dns. +In 2.3.2.0 +---------- + + - Bugfixes. + - New caching library to build a DNS cache over. + + In 2.3.1.1 ---------- diff --git a/package/deps.mak b/package/deps.mak index a1dd475..b10d4b8 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -19,6 +19,11 @@ src/caches/dcache_init.o src/caches/dcache_init.lo: src/caches/dcache_init.c src src/caches/dcache_load.o src/caches/dcache_load.lo: src/caches/dcache_load.c src/include/s6-dns/dcache.h src/caches/dcache_save.o src/caches/dcache_save.lo: src/caches/dcache_save.c src/include/s6-dns/dcache.h src/caches/dcache_search.o src/caches/dcache_search.lo: src/caches/dcache_search.c src/include/s6-dns/dcache.h +src/caches/shibari.o src/caches/shibari.lo: src/caches/shibari.c src/include/s6-dns/s6dns.h +src/caches/shibari_whitelist_add6.o src/caches/shibari_whitelist_add6.lo: src/caches/shibari_whitelist_add6.c src/caches/shibari-internal.h +src/caches/shibari_whitelist_ip4_match.o src/caches/shibari_whitelist_ip4_match.lo: src/caches/shibari_whitelist_ip4_match.c src/caches/shibari-internal.h +src/caches/shibari_whitelist_ip6_match.o src/caches/shibari_whitelist_ip6_match.lo: src/caches/shibari_whitelist_ip6_match.c src/caches/shibari-internal.h +src/caches/shibari_whitelist_read.o src/caches/shibari_whitelist_read.lo: src/caches/shibari_whitelist_read.c src/caches/shibari-internal.h src/clients/s6-dnsip4-filter.o src/clients/s6-dnsip4-filter.lo: src/clients/s6-dnsip4-filter.c src/include/s6-dns/s6dns-constants.h src/include/s6-dns/s6dns-message.h src/clients/s6dns-generic-filter.h src/clients/s6-dnsip4.o src/clients/s6-dnsip4.lo: src/clients/s6-dnsip4.c src/include/s6-dns/s6dns.h src/clients/s6-dnsip6-filter.o src/clients/s6-dnsip6-filter.lo: src/clients/s6-dnsip6-filter.c src/include/s6-dns/s6dns-constants.h src/include/s6-dns/s6dns-message.h src/clients/s6dns-generic-filter.h @@ -149,6 +154,15 @@ libdcache.a.xyzzy: src/caches/dcache_add.lo src/caches/dcache_free.lo src/caches endif libdcache.so.xyzzy: EXTRA_LIBS := libdcache.so.xyzzy: src/caches/dcache_add.lo src/caches/dcache_free.lo src/caches/dcache_init.lo src/caches/dcache_load.lo src/caches/dcache_save.lo src/caches/dcache_search.lo +ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) +libshibari.a.xyzzy: src/caches/shibari_whitelist_add6.o src/caches/shibari_whitelist_ip4_match.o src/caches/shibari_whitelist_ip6_match.o src/caches/shibari_whitelist_read.o +else +libshibari.a.xyzzy: src/caches/shibari_whitelist_add6.lo src/caches/shibari_whitelist_ip4_match.lo src/caches/shibari_whitelist_ip6_match.lo src/caches/shibari_whitelist_read.lo +endif +libshibari.so.xyzzy: EXTRA_LIBS := +libshibari.so.xyzzy: src/caches/shibari_whitelist_add6.lo src/caches/shibari_whitelist_ip4_match.lo src/caches/shibari_whitelist_ip6_match.lo src/caches/shibari_whitelist_read.lo +shibari: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} +shibari: src/caches/shibari.o libshibari.a.xyzzy ${LIBDCACHE} ${LIBS6DNS} s6-dnsip4: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} s6-dnsip4: src/clients/s6-dnsip4.o ${LIBS6DNS} s6-dnsip4-filter: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} ${SPAWN_LIB} diff --git a/package/info b/package/info index 7c9d314..2e264fb 100644 --- a/package/info +++ b/package/info @@ -1,4 +1,4 @@ package=s6-dns -version=2.3.1.1 +version=2.3.2.0 category=web package_macro_name=S6_DNS 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 ; +} |