diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2024-07-25 06:10:28 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2024-07-25 06:10:28 +0000 |
commit | a788cfec66d6e672fd9bf2e1038d075b5318459a (patch) | |
tree | 7610959f7fbc543d0834f4ed7f5d895402f17da2 | |
parent | 6b8bb38398e58539096fb054e354bddadda09f9b (diff) | |
download | shibari-a788cfec66d6e672fd9bf2e1038d075b5318459a.tar.gz shibari-a788cfec66d6e672fd9bf2e1038d075b5318459a.tar.xz shibari-a788cfec66d6e672fd9bf2e1038d075b5318459a.zip |
More skeleton
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | package/deps.mak | 4 | ||||
-rw-r--r-- | src/cache/cache.c | 19 | ||||
-rw-r--r-- | src/cache/deps-exe/shibari-cache | 1 | ||||
-rw-r--r-- | src/cache/dns.c | 38 | ||||
-rw-r--r-- | src/cache/query.c | 2 | ||||
-rw-r--r-- | src/cache/shibari-cache-internal.h | 10 | ||||
-rw-r--r-- | src/cache/shibari-cache.c | 6 |
7 files changed, 74 insertions, 6 deletions
diff --git a/package/deps.mak b/package/deps.mak index ca15915..19bdf1a 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -6,10 +6,12 @@ src/include/shibari/common.h: src/include/shibari/constants.h src/include/shibar src/include/shibari/packet.h: src/include/shibari/tdb.h src/include/shibari/server.h: src/include/shibari/log.h src/include/shibari/packet.h src/include/shibari/tdb.h src/include/shibari/shibari.h: src/include/shibari/common.h src/include/shibari/server.h +src/cache/shibari-cache-internal.h: src/include/shibari/dcache.h src/libdcache/dcache-internal.h: src/include/shibari/dcache.h src/cache/cache.o src/cache/cache.lo: src/cache/cache.c src/cache/shibari-cache-internal.h src/include/shibari/dcache.h src/cache/clientaccess.o src/cache/clientaccess.lo: src/cache/clientaccess.c src/cache/shibari-cache-internal.h src/cache/conf.o src/cache/conf.lo: src/cache/conf.c src/cache/shibari-cache-internal.h +src/cache/dns.o src/cache/dns.lo: src/cache/dns.c src/cache/shibari-cache-internal.h src/cache/log.o src/cache/log.lo: src/cache/log.c src/cache/shibari-cache-internal.h src/cache/query.o src/cache/query.lo: src/cache/query.c src/cache/shibari-cache-internal.h src/cache/shibari-cache.o src/cache/shibari-cache.lo: src/cache/shibari-cache.c src/cache/shibari-cache-internal.h src/include/shibari/common.h src/include/shibari/config.h @@ -54,7 +56,7 @@ src/server/shibari_tdb_find_authority.o src/server/shibari_tdb_find_authority.lo src/server/shibari_tdb_read_entry.o src/server/shibari_tdb_read_entry.lo: src/server/shibari_tdb_read_entry.c src/include/shibari/tdb.h shibari-cache: EXTRA_LIBS := -ls6dns -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} -shibari-cache: src/cache/shibari-cache.o src/cache/cache.o src/cache/clientaccess.o src/cache/conf.o src/cache/log.o src/cache/query.o src/cache/tcpconnection.o src/cache/udpqueue.o ${LIBDCACHE} ${LIBSHIBARI_COMMON} +shibari-cache: src/cache/shibari-cache.o src/cache/cache.o src/cache/clientaccess.o src/cache/conf.o src/cache/dns.o src/cache/log.o src/cache/query.o src/cache/tcpconnection.o src/cache/udpqueue.o ${LIBDCACHE} ${LIBSHIBARI_COMMON} ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) libshibari-common.a.xyzzy: src/common/shibari_log_answer.o src/common/shibari_log_exit.o src/common/shibari_log_query.o src/common/shibari_log_queryplus.o src/common/shibari_log_start.o src/common/shibari_util_qtype_num.o src/common/shibari_util_qtype_str.o src/common/shibari_util_rcode_str.o src/common/shibari_util_canon_domain.o src/common/shibari_util_get_prefixlen.o else diff --git a/src/cache/cache.c b/src/cache/cache.c index 7080240..e8796f7 100644 --- a/src/cache/cache.c +++ b/src/cache/cache.c @@ -1,9 +1,13 @@ /* ISC license. */ -#include <skalibs/uint64.h> +#include <string.h> + +#include <skalibs/uint16.h> #include <skalibs/posixplz.h> #include <skalibs/strerr.h> +#include <s6-dns/s6dns-domain.h> + #include <shibari/dcache.h> #include "shibari-cache-internal.h" @@ -34,3 +38,16 @@ void cache_load (void) strerr_warnwu2sys("load cache contents from ", g->dumpfile) ; } } + +int cache_search (s6dns_domain_t const *name, uint16_t qtype, dcache_key_t *data) +{ + dcache_node_t *node ; + char key[name->len + 1] ; + uint16_pack_big(key, qtype) ; + memcpy(key + 2, name->s, name->len - 1) ; + node = dcache_search(&cache, key, name->len + 1) ; + if (!node) return 0 ; + data->s = node->key.s + node->key.len ; + data->len = node->datalen ; + return 1 ; +} diff --git a/src/cache/deps-exe/shibari-cache b/src/cache/deps-exe/shibari-cache index e363f19..44d74a0 100644 --- a/src/cache/deps-exe/shibari-cache +++ b/src/cache/deps-exe/shibari-cache @@ -1,6 +1,7 @@ cache.o clientaccess.o conf.o +dns.o log.o query.o tcpconnection.o diff --git a/src/cache/dns.c b/src/cache/dns.c new file mode 100644 index 0000000..ce5b611 --- /dev/null +++ b/src/cache/dns.c @@ -0,0 +1,38 @@ +/* ISC license. */ + +#include <skalibs/uint16.h> + +#include <s6-dns/s6dns.h> + +#include "shibari-cache-internal.h" + +int dns_newquery (uint8_t source, uint16_t i, char const *ip, uint16_t port, char const *buf, uint16_t len) +{ + dcache_key_t data ; + s6dns_message_header_t hdr ; + s6dns_message_counts_t counts ; + s6dns_domain_t name ; + unsigned int pos ; + unsigned int rcode ; + uint16_t qtype ; + char key[257] ; + + if (!s6dns_message_parse_init(&hdr, &counts, buf, len, &pos)) return 1 ; + if (hdr.opcode) { rcode = 4 ; goto err ; } + if (!hdr.rd) { rcode = 1 ; goto err ; } + if (!s6dns_message_parse_question(&counts, &name, &qtype, buf, len, &pos) + || !s6dns_domain_encode(&name)) + { + rcode = errno == ENOTSUP ? 4 : 1 ; + goto answer ; + } + + if (cache_search(&name, qtype, &data)) goto got ; + return 1 ; + + answer: + return 1 ; + err: + got : + return 1 ; +} diff --git a/src/cache/query.c b/src/cache/query.c index 6c4bda8..8f5e423 100644 --- a/src/cache/query.c +++ b/src/cache/query.c @@ -38,7 +38,7 @@ uint16_t query_succeed (uint16_t id) return query_delete(q) ; } -int query_new (uint8_t source, uint16_t i, char const *ip, uint16_t port, char const *s, uint16_t len) +int query_new (uint8_t source, uint16_t i, char const *ip, uint16_t port, char const *buf, uint16_t len) { return 1 ; } diff --git a/src/cache/shibari-cache-internal.h b/src/cache/shibari-cache-internal.h index 6c42055..c8819fd 100644 --- a/src/cache/shibari-cache-internal.h +++ b/src/cache/shibari-cache-internal.h @@ -15,14 +15,18 @@ #include <skalibs/genset.h> #include <skalibs/ip46.h> +#include <s6-dns/s6dns-domain.h> #include <s6-dns/s6dns-engine.h> +#include <shibari/dcache.h> + /* cache */ extern void cache_init (uint64_t) ; extern void cache_dump (void) ; extern void cache_load (void) ; +extern int cache_search (s6dns_domain_t const *, uint16_t, dcache_key_t *) ; /* clientaccess */ @@ -32,6 +36,7 @@ extern int clientaccess_ip4 (char const *) ; extern int clientaccess_ip6 (char const *) ; #endif + /* conf */ extern int conf_getb (char const *, size_t, cdb_data *) ; @@ -42,6 +47,11 @@ extern int conf_get_uint64 (char const *, uint64_t *) ; extern char const *conf_get_string (char const *) ; + /* dns */ + +extern int dns_newquery (uint8_t, uint16_t, char const *, uint16_t, char const *, uint16_t) ; + + /* log */ extern void log_newtcp4 (char const *, uint16_t) ; diff --git a/src/cache/shibari-cache.c b/src/cache/shibari-cache.c index cd0e4f4..ea705bd 100644 --- a/src/cache/shibari-cache.c +++ b/src/cache/shibari-cache.c @@ -458,7 +458,7 @@ int main (int argc, char const *const *argv) if (!len) break ; if (len < 12 || len > 512) continue ; if (!clientaccess_ip4(ip)) continue ; - if (!query_new(0, i, ip, port, buf, len)) + if (!dns_newquery(0, i, ip, port, buf, len)) { if (g->verbosity) { @@ -494,7 +494,7 @@ int main (int argc, char const *const *argv) if (!len) break ; if (len < 12 || len > 512) continue ; if (!clientaccess_ip6(ip)) continue ; - if (!query_new(1, i, ip, port, buf, len)) + if (!dns_newquery(1, i, ip, port, buf, len)) { if (g->verbosity) { @@ -522,7 +522,7 @@ int main (int argc, char const *const *argv) if (l == -1) { i = tcpconnection_delete(p) ; break ; } if (!l) break ; if (p->in.len < 12 || p->in.len > 65536) { i = tcpconnection_delete(p) ; break ; } - if (!query_new(2, i, 0, 0, p->in.s, p->in.len)) + if (!dns_newquery(2, i, 0, 0, p->in.s, p->in.len)) { if (g->verbosity) { |