summaryrefslogtreecommitdiff
path: root/src/cache/dns.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2024-07-25 06:10:28 +0000
committerLaurent Bercot <ska@appnovation.com>2024-07-25 06:10:28 +0000
commita788cfec66d6e672fd9bf2e1038d075b5318459a (patch)
tree7610959f7fbc543d0834f4ed7f5d895402f17da2 /src/cache/dns.c
parent6b8bb38398e58539096fb054e354bddadda09f9b (diff)
downloadshibari-a788cfec66d6e672fd9bf2e1038d075b5318459a.tar.xz
More skeleton
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/cache/dns.c')
-rw-r--r--src/cache/dns.c38
1 files changed, 38 insertions, 0 deletions
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 ;
+}