diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-12-21 09:44:02 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-12-21 09:44:02 +0000 |
commit | 071535f5d7aa811647ed359fab431c17c9c5e2a0 (patch) | |
tree | ec1e670f772805b47e3892c5cba7294414ee2f13 | |
parent | b30b381737525c88ae8623258d63f793dbdca08f (diff) | |
download | s6-dns-071535f5d7aa811647ed359fab431c17c9c5e2a0.tar.xz |
Remove unused caches/ subdir
dcache is moved to shibari.
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | package/deps.mak | 30 | ||||
-rw-r--r-- | package/targets.mak | 2 | ||||
-rw-r--r-- | src/caches/dcache-internal.h | 18 | ||||
-rw-r--r-- | src/caches/dcache_add.c | 86 | ||||
-rw-r--r-- | src/caches/dcache_clean_expired.c | 20 | ||||
-rw-r--r-- | src/caches/dcache_delete.c | 19 | ||||
-rw-r--r-- | src/caches/dcache_free.c | 22 | ||||
-rw-r--r-- | src/caches/dcache_init.c | 55 | ||||
-rw-r--r-- | src/caches/dcache_load.c | 81 | ||||
-rw-r--r-- | src/caches/dcache_save.c | 73 | ||||
-rw-r--r-- | src/caches/dcache_search.c | 15 | ||||
-rw-r--r-- | src/caches/deps-exe/shibari | 6 | ||||
-rw-r--r-- | src/caches/deps-lib/dcache | 8 | ||||
-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 |
20 files changed, 1 insertions, 594 deletions
diff --git a/package/deps.mak b/package/deps.mak index 478c81a..7593af4 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -13,21 +13,7 @@ src/include/s6-dns/s6dns-rci.h: src/include/s6-dns/s6dns-constants.h src/include src/include/s6-dns/s6dns-resolve.h: src/include/s6-dns/s6dns-constants.h src/include/s6-dns/s6dns-domain.h src/include/s6-dns/s6dns-engine.h src/include/s6-dns/s6dns-ip46.h src/include/s6-dns/s6dns-message.h src/include/s6-dns/s6dns-rci.h src/include/s6-dns/s6dns.h: src/include/s6-dns/hosts.h src/include/s6-dns/s6dns-constants.h src/include/s6-dns/s6dns-domain.h src/include/s6-dns/s6dns-engine.h src/include/s6-dns/s6dns-fmt.h src/include/s6-dns/s6dns-ip46.h src/include/s6-dns/s6dns-message.h src/include/s6-dns/s6dns-rci.h src/include/s6-dns/s6dns-resolve.h src/include/s6-dns/skadns.h: src/include/s6-dns/config.h src/include/s6-dns/s6dns-domain.h -src/caches/dcache-internal.h: src/include/s6-dns/dcache.h src/clients/s6dns-generic-filter.h: src/include/s6-dns/s6dns-domain.h -src/caches/dcache_add.o src/caches/dcache_add.lo: src/caches/dcache_add.c src/caches/dcache-internal.h src/include/s6-dns/dcache.h -src/caches/dcache_clean_expired.o src/caches/dcache_clean_expired.lo: src/caches/dcache_clean_expired.c src/caches/dcache-internal.h src/include/s6-dns/dcache.h -src/caches/dcache_delete.o src/caches/dcache_delete.lo: src/caches/dcache_delete.c src/caches/dcache-internal.h src/include/s6-dns/dcache.h -src/caches/dcache_free.o src/caches/dcache_free.lo: src/caches/dcache_free.c src/include/s6-dns/dcache.h -src/caches/dcache_init.o src/caches/dcache_init.lo: src/caches/dcache_init.c src/include/s6-dns/dcache.h -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/caches/dcache-internal.h 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-dnsip.o src/clients/s6-dnsip.lo: src/clients/s6-dnsip.c src/include/s6-dns/s6dns.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 @@ -162,22 +148,6 @@ src/skadns/skadns_zero.o src/skadns/skadns_zero.lo: src/skadns/skadns_zero.c src src/skadns/skadnsd.o src/skadns/skadnsd.lo: src/skadns/skadnsd.c src/include/s6-dns/s6dns.h src/include/s6-dns/skadns.h src/utilities/s6-dns-hosts-compile.o src/utilities/s6-dns-hosts-compile.lo: src/utilities/s6-dns-hosts-compile.c src/include/s6-dns/hosts.h -ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) -libdcache.a.xyzzy: src/caches/dcache_add.o src/caches/dcache_clean_expired.o src/caches/dcache_delete.o src/caches/dcache_free.o src/caches/dcache_init.o src/caches/dcache_load.o src/caches/dcache_save.o src/caches/dcache_search.o -else -libdcache.a.xyzzy: src/caches/dcache_add.lo src/caches/dcache_clean_expired.lo src/caches/dcache_delete.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 -endif -libdcache.so.xyzzy: EXTRA_LIBS := -libdcache.so.xyzzy: src/caches/dcache_add.lo src/caches/dcache_clean_expired.lo src/caches/dcache_delete.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-dnsip: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} s6-dnsip: src/clients/s6-dnsip.o ${LIBS6DNS} s6-dnsip4: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} diff --git a/package/targets.mak b/package/targets.mak index f4300e9..f735727 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -20,4 +20,4 @@ s6-dns-hosts-compile LIBEXEC_TARGETS := -LIB_DEFS := S6DNS=s6dns SKADNS=skadns DCACHE=dcache +LIB_DEFS := S6DNS=s6dns SKADNS=skadns diff --git a/src/caches/dcache-internal.h b/src/caches/dcache-internal.h deleted file mode 100644 index 4fdfa4c..0000000 --- a/src/caches/dcache-internal.h +++ /dev/null @@ -1,18 +0,0 @@ -/* ISC license. */ - -#ifndef S6DNS_DCACHE_INTERNAL_H -#define S6DNS_DCACHE_INTERNAL_H - -#include <stdint.h> - -#include <skalibs/avlnode.h> -#include <skalibs/gensetdyn.h> - -#include <s6-dns/dcache.h> - -#define DNODE(z, i) GENSETDYN_P(dcache_node_t, &(z)->storage, i) -#define DCACHE_NODE_OVERHEAD (32 + sizeof(dcache_node_t) + 3 * sizeof(avlnode)) - -extern void dcache_delete (dcache_t *, uint32_t) ; - -#endif diff --git a/src/caches/dcache_add.c b/src/caches/dcache_add.c deleted file mode 100644 index 650f51b..0000000 --- a/src/caches/dcache_add.c +++ /dev/null @@ -1,86 +0,0 @@ -/* ISC license. */ - -#include <stdint.h> -#include <string.h> -#include <errno.h> - -#include <skalibs/uint64.h> -#include <skalibs/alloc.h> -#include <skalibs/tai.h> -#include <skalibs/gensetdyn.h> -#include <skalibs/avlnode.h> -#include <skalibs/avltree.h> - -#include <s6-dns/dcache.h> -#include "dcache-internal.h" - -static void uniquify (avltree const *tree, tain *stamp) -{ - static tain const nano = { .sec = TAI_ZERO, .nano = 1 } ; - uint32_t dummy ; - while (avltree_search(tree, stamp, &dummy)) - tain_add(stamp, stamp, &nano) ; -} - -static inline void dcache_gc_by_entry (dcache_t *z, uint64_t max) -{ - while (z->size > max) - { - uint32_t oldest ; - if (!avltree_min(&z->by_entry, &oldest)) break ; - dcache_delete(z, oldest) ; - } -} - -static inline int dcache_add_node (dcache_t *z, dcache_node_t const *node) -{ - uint32_t i ; - dcache_node_t *y ; - if (!gensetdyn_new(&z->storage, &i)) return 0 ; - y = DNODE(z, i) ; *y = *node ; - uniquify(&z->by_entry, &y->entry) ; - uniquify(&z->by_expire, &y->expire) ; - if (!avltree_insert(&z->by_key, i)) goto err1 ; - if (!avltree_insert(&z->by_entry, i)) goto err2 ; - if (!avltree_insert(&z->by_expire, i)) goto err3 ; - return 1 ; - - err3: - avltree_delete(&z->by_entry, &y->entry) ; - err2: - avltree_delete(&z->by_key, &y->key) ; - err1: - gensetdyn_delete(&z->storage, i) ; - return 0 ; -} - -static inline int dcache_add_unbounded (dcache_t *z, char const *key, uint16_t keylen, char const *data, uint16_t datalen, tain const *expire, tain const *stamp) -{ - uint32_t len = (uint32_t)keylen + (uint32_t)datalen ; - dcache_node_t y = { .key = { .s = alloc(len) } } ; - if (!y.key.s) return 0 ; - memcpy(y.key.s, key, keylen) ; - memcpy(y.key.s + keylen, data, datalen) ; - y.key.len = keylen ; - y.datalen = datalen ; - y.entry = *stamp ; - y.expire = *expire ; - if (!dcache_add_node(z, &y)) - { - alloc_free(y.key.s) ; - return 0 ; - } - z->size += DCACHE_NODE_OVERHEAD + len ; - z->motion += DCACHE_NODE_OVERHEAD + len ; - return 1 ; -} - - -int dcache_add (dcache_t *z, uint64_t max, char const *key, uint16_t keylen, char const *data, uint16_t datalen, tain const *expire, tain const *stamp) -{ - uint64_t size = DCACHE_NODE_OVERHEAD + keylen + datalen ; - if (size > max) return (errno = EINVAL, 0) ; - if (z->size > max - size) dcache_clean_expired(z, stamp) ; - if (z->size > max - size) dcache_gc_by_entry(z, max - size) ; - return dcache_add_unbounded(z, key, keylen, data, datalen, expire, stamp) ; -} diff --git a/src/caches/dcache_clean_expired.c b/src/caches/dcache_clean_expired.c deleted file mode 100644 index 8a5b12c..0000000 --- a/src/caches/dcache_clean_expired.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ISC license. */ - -#include <stdint.h> - -#include <skalibs/tai.h> -#include <skalibs/avltree.h> - -#include <s6-dns/dcache.h> -#include "dcache-internal.h" - -void dcache_clean_expired (dcache_t *z, tain const *stamp) -{ - for (;;) - { - uint32_t i ; - if (!avltree_min(&z->by_expire, &i)) break ; - if (tain_less(stamp, &DNODE(z, i)->expire)) break ; - dcache_delete(z, i) ; - } -} diff --git a/src/caches/dcache_delete.c b/src/caches/dcache_delete.c deleted file mode 100644 index e0dca4e..0000000 --- a/src/caches/dcache_delete.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -#include <skalibs/alloc.h> -#include <skalibs/gensetdyn.h> -#include <skalibs/avltree.h> - -#include <s6-dns/dcache.h> -#include "dcache-internal.h" - -void dcache_delete (dcache_t *z, uint32_t i) -{ - dcache_node_t *y = DNODE(z, i) ; - avltree_delete(&z->by_expire, &y->expire) ; - avltree_delete(&z->by_entry, &y->entry) ; - avltree_delete(&z->by_key, &y->key) ; - alloc_free(y->key.s) ; - z->size -= DCACHE_NODE_OVERHEAD + y->key.len + y->datalen ; - gensetdyn_delete(&z->storage, i) ; -} diff --git a/src/caches/dcache_free.c b/src/caches/dcache_free.c deleted file mode 100644 index 1ba8041..0000000 --- a/src/caches/dcache_free.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ISC license. */ - -#include <skalibs/alloc.h> -#include <skalibs/gensetdyn.h> -#include <skalibs/avltree.h> - -#include <s6-dns/dcache.h> - -static void dcache_node_free (void *p) -{ - alloc_free(((dcache_node_t *)p)->key.s) ; -} - -void dcache_free (dcache_t *z) -{ - static dcache_t const dcache_zero = DCACHE_ZERO ; - avltree_free(&z->by_expire) ; - avltree_free(&z->by_entry) ; - avltree_free(&z->by_key) ; - gensetdyn_deepfree(&z->storage, &dcache_node_free) ; - *z = dcache_zero ; -} diff --git a/src/caches/dcache_init.c b/src/caches/dcache_init.c deleted file mode 100644 index cc6c635..0000000 --- a/src/caches/dcache_init.c +++ /dev/null @@ -1,55 +0,0 @@ -/* ISC license. */ - -#include <stdint.h> -#include <string.h> - -#include <skalibs/uint64.h> -#include <skalibs/tai.h> -#include <skalibs/gensetdyn.h> -#include <skalibs/avltree.h> - -#include <s6-dns/dcache.h> - -static int key_cmp (void const *a, void const *b, void *x) -{ - dcache_key_t const *ka = a ; - dcache_key_t const *kb = b ; - if (ka->len < kb->len) return -1 ; - if (kb->len < ka->len) return 1 ; - (void)x ; - return memcmp(ka->s, kb->s, ka->len) ; -} - -static int tain_cmp (void const *a, void const *b, void *x) -{ - tain const *ta = a ; - tain const *tb = b ; - (void)x ; - return tain_less(ta, tb) ? -1 : tain_less(tb, ta) ; -} - -static void *key_dtok (uint32_t d, void *x) -{ - return &GENSETDYN_P(dcache_node_t, (gensetdyn *)x, d)->key ; -} - -static void *entry_dtok (uint32_t d, void *x) -{ - return &GENSETDYN_P(dcache_node_t, (gensetdyn *)x, d)->entry ; -} - -static void *expire_dtok (uint32_t d, void *x) -{ - return &GENSETDYN_P(dcache_node_t, (gensetdyn *)x, d)->expire ; -} - - -void dcache_init (dcache_t *z, uint64_t max) -{ - gensetdyn_init(&z->storage, sizeof(dcache_node_t), max >> 9, 3, 8) ; - avltree_init(&z->by_key, max >> 9, 3, 8, &key_dtok, &key_cmp, &z->storage) ; - avltree_init(&z->by_entry, max >> 9, 3, 8, &entry_dtok, &tain_cmp, &z->storage) ; - avltree_init(&z->by_expire, max >> 9, 3, 8, &expire_dtok, &tain_cmp, &z->storage) ; - z->size = 0 ; - z->motion = 0 ; -} diff --git a/src/caches/dcache_load.c b/src/caches/dcache_load.c deleted file mode 100644 index 71d38e0..0000000 --- a/src/caches/dcache_load.c +++ /dev/null @@ -1,81 +0,0 @@ -/* ISC license. */ - -#include <stdint.h> -#include <string.h> -#include <errno.h> - -#include <skalibs/posixishard.h> -#include <skalibs/uint16.h> -#include <skalibs/uint64.h> -#include <skalibs/buffer.h> -#include <skalibs/tai.h> -#include <skalibs/djbunix.h> - -#include <s6-dns/dcache.h> - -static inline int dcache_load_node (dcache_t *z, uint64_t max, buffer *b) -{ - tain entry = { .nano = 0 } ; - tain expire = { .nano = 0 } ; - uint16_t keylen ; - uint16_t datalen ; - char pack[TAI_PACK * 2 + 4] ; - ssize_t r = buffer_get(b, pack, TAI_PACK * 2 + 4) ; - if (!r) return 0 ; - if (r < TAI_PACK * 2 + 4) return -1 ; - tai_unpack(pack, tain_secp(&entry)) ; - tai_unpack(pack + TAI_PACK, tain_secp(&expire)) ; - uint16_unpack_big(pack + TAI_PACK * 2, &keylen) ; - uint16_unpack_big(pack + TAI_PACK * 2 + 2, &datalen) ; - { - uint32_t len = (uint32_t)keylen + (uint32_t)datalen ; - char blob[len+1] ; /* 128 kB max, it's ok */ - r = buffer_get(b, blob, len+1) ; - if (!r) return (errno = EPIPE, -1) ; - if (r < len) return -1 ; - if (blob[len]) return (errno = EPROTO, -1) ; - if (!dcache_add(z, max, blob, keylen, blob + keylen, datalen, &expire, &entry)) return -1 ; - } - return 1 ; -} - -static inline int dcache_load_from_buffer (dcache_t *z, uint64_t max, buffer *b) -{ - { - char banner[sizeof(DCACHE_MAGIC) - 1] ; - char pack[8] ; - if (buffer_get(b, banner, sizeof(DCACHE_MAGIC) - 1) < sizeof(DCACHE_MAGIC) - 1) - return 0 ; - if (memcmp(banner, DCACHE_MAGIC, sizeof(DCACHE_MAGIC) - 1)) return 0 ; - if (buffer_get(b, pack, 8) < 8) return 0 ; - uint64_unpack_big(pack, &z->size) ; - if (buffer_get(b, pack, 8) < 8) return 0 ; - uint64_unpack_big(pack, &z->motion) ; - } - for (;;) - { - int r = dcache_load_node(z, max, b) ; - if (r < 0) return 0 ; - if (!r) break ; - } - return 1 ; -} - -#define N 8192 - -int dcache_load (dcache_t *z, uint64_t max, char const *file) -{ - char buf[N] ; - buffer b ; - int fd = open_readb(file) ; - if (fd == -1) return 0 ; - buffer_init(&b, &buffer_read, fd, buf, N) ; - if (!dcache_load_from_buffer(z, max, &b)) goto err ; - fd_close(fd) ; - return 1 ; - - err: - dcache_free(z) ; - fd_close(fd) ; - return 0 ; -} diff --git a/src/caches/dcache_save.c b/src/caches/dcache_save.c deleted file mode 100644 index f7ae6a4..0000000 --- a/src/caches/dcache_save.c +++ /dev/null @@ -1,73 +0,0 @@ -/* ISC license. */ - -#include <stdint.h> -#include <string.h> -#include <unistd.h> -#include <stdlib.h> -#include <stdio.h> - -#include <skalibs/posixplz.h> -#include <skalibs/uint16.h> -#include <skalibs/uint64.h> -#include <skalibs/buffer.h> -#include <skalibs/tai.h> -#include <skalibs/djbunix.h> -#include <skalibs/skamisc.h> -#include <skalibs/gensetdyn.h> - -#include <s6-dns/dcache.h> - -static int write_node_iter (void *data, void *aux) -{ - dcache_node_t *y = data ; - buffer *b = aux ; - char pack[TAI_PACK * 2 + 4] ; - tai_pack(pack, tain_secp(&y->entry)) ; - tai_pack(pack + TAI_PACK, tain_secp(&y->expire)) ; - uint16_pack(pack + TAI_PACK * 2, y->key.len) ; - uint16_pack(pack + TAI_PACK * 2 + 2, y->datalen) ; - if (buffer_put(b, pack, TAI_PACK * 2 + 4) == -1) return 0 ; - if (buffer_put(b, y->key.s, y->key.len + y->datalen) == -1) return 0 ; - if (buffer_put(b, "", 1) == -1) return 0 ; - return 1 ; -} - -static inline int dcache_save_to_buffer (dcache_t const *z, buffer *b) -{ - char pack[16] ; - if (buffer_puts(b, DCACHE_MAGIC) == -1) return 0 ; - uint64_pack_big(pack, z->size) ; - uint64_pack_big(pack + 8, z->motion) ; - if (buffer_put(b, pack, 16) < 16) return 0 ; - - /* XXX: can gensetdyn_iter blow up the stack if z->storage is huge? */ - if (gensetdyn_iter_nocancel((gensetdyn *)&z->storage, gensetdyn_n(&z->storage), &write_node_iter, b) < gensetdyn_n(&z->storage)) return 0 ; - - return buffer_flush(b) ; -} - -#define N 8192 - -int dcache_save (dcache_t const *z, char const *file) -{ - size_t len = strlen(file) ; - int fd ; - buffer b ; - char buf[N] ; - char tmp[len + 20] ; - memcpy(tmp, file, len) ; - memcpy(tmp + len, ":dcache_save:XXXXXX", 20) ; - fd = mkstemp(tmp) ; - if (fd == -1) return 0 ; - buffer_init(&b, &buffer_write, fd, buf, N) ; - if (!dcache_save_to_buffer(z, &b) || fsync(fd) < 0) goto err2 ; - fd_close(fd) ; - if (rename(tmp, file) == -1) goto err1 ; - return 1 ; - - err2: - fd_close(fd) ; - err1: - unlink_void(tmp) ; - return 0 ; -} diff --git a/src/caches/dcache_search.c b/src/caches/dcache_search.c deleted file mode 100644 index 7ca8324..0000000 --- a/src/caches/dcache_search.c +++ /dev/null @@ -1,15 +0,0 @@ -/* ISC license. */ - -#include <stdint.h> - -#include <skalibs/avltree.h> - -#include <s6-dns/dcache.h> -#include "dcache-internal.h" - -dcache_node_t *dcache_search (dcache_t *z, char const *key, uint16_t keylen) -{ - uint32_t i ; - dcache_key_t k = { .s = (char *)key, .len = keylen } ; - return avltree_search(&z->by_key, &k, &i) ? DNODE(z, i) : 0 ; -} diff --git a/src/caches/deps-exe/shibari b/src/caches/deps-exe/shibari deleted file mode 100644 index ae7e7f9..0000000 --- a/src/caches/deps-exe/shibari +++ /dev/null @@ -1,6 +0,0 @@ -libshibari.a.xyzzy -${LIBDCACHE} -${LIBS6DNS} --lskarnet -${SOCKET_LIB} -${SYSCLOCK_LIB} diff --git a/src/caches/deps-lib/dcache b/src/caches/deps-lib/dcache deleted file mode 100644 index fcc09a0..0000000 --- a/src/caches/deps-lib/dcache +++ /dev/null @@ -1,8 +0,0 @@ -dcache_add.o -dcache_clean_expired.o -dcache_delete.o -dcache_free.o -dcache_init.o -dcache_load.o -dcache_save.o -dcache_search.o diff --git a/src/caches/deps-lib/shibari b/src/caches/deps-lib/shibari deleted file mode 100644 index 9e34094..0000000 --- a/src/caches/deps-lib/shibari +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 048faa5..0000000 --- a/src/caches/shibari-internal.h +++ /dev/null @@ -1,25 +0,0 @@ -/* 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 deleted file mode 100644 index b945fd4..0000000 --- a/src/caches/shibari.c +++ /dev/null @@ -1,14 +0,0 @@ -/* ISC license. */ - -#include <skalibs/sgetopt.h> -#include <skalibs/strerr.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 deleted file mode 100644 index 0c9e53a..0000000 --- a/src/caches/shibari_whitelist_add6.c +++ /dev/null @@ -1,28 +0,0 @@ -/* 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 deleted file mode 100644 index fbf11ac..0000000 --- a/src/caches/shibari_whitelist_ip4_match.c +++ /dev/null @@ -1,15 +0,0 @@ -/* 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 deleted file mode 100644 index c728081..0000000 --- a/src/caches/shibari_whitelist_ip6_match.c +++ /dev/null @@ -1,16 +0,0 @@ -/* 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 deleted file mode 100644 index 48fcbcc..0000000 --- a/src/caches/shibari_whitelist_read.c +++ /dev/null @@ -1,58 +0,0 @@ -/* 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 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 ; -} |