aboutsummaryrefslogtreecommitdiffstats
path: root/src/include
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-12-10 11:48:01 +0000
committerLaurent Bercot <ska@appnovation.com>2023-12-10 11:48:01 +0000
commitb8d0f83e6cea9640a7ee4402c163ad812237355d (patch)
tree57a64ac8aa0e98c40db8c36e96e7379490e44dbf /src/include
downloadshibari-b8d0f83e6cea9640a7ee4402c163ad812237355d.tar.gz
Initial commit
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/include')
-rw-r--r--src/include/shibari/cache.h8
-rw-r--r--src/include/shibari/client.h6
-rw-r--r--src/include/shibari/common.h9
-rw-r--r--src/include/shibari/constants.h109
-rw-r--r--src/include/shibari/dcache.h54
-rw-r--r--src/include/shibari/log.h20
-rw-r--r--src/include/shibari/packet.h39
-rw-r--r--src/include/shibari/server.h10
-rw-r--r--src/include/shibari/shibari.h11
-rw-r--r--src/include/shibari/tdb.h29
-rw-r--r--src/include/shibari/util.h14
11 files changed, 309 insertions, 0 deletions
diff --git a/src/include/shibari/cache.h b/src/include/shibari/cache.h
new file mode 100644
index 0000000..d0c6004
--- /dev/null
+++ b/src/include/shibari/cache.h
@@ -0,0 +1,8 @@
+/* ISC license. */
+
+#ifndef SHIBARI_CACHE_H
+#define SHIBARI_CACHE_H
+
+#include <shibari/dcache.h>
+
+#endif
diff --git a/src/include/shibari/client.h b/src/include/shibari/client.h
new file mode 100644
index 0000000..03f8b1b
--- /dev/null
+++ b/src/include/shibari/client.h
@@ -0,0 +1,6 @@
+/* ISC license. */
+
+#ifndef SHIBARI_CLIENT_H
+#define SHIBARI_CLIENT_H
+
+#endif
diff --git a/src/include/shibari/common.h b/src/include/shibari/common.h
new file mode 100644
index 0000000..d36d055
--- /dev/null
+++ b/src/include/shibari/common.h
@@ -0,0 +1,9 @@
+/* ISC license. */
+
+#ifndef SHIBARI_COMMON_H
+#define SHIBARI_COMMON_H
+
+#include <shibari/constants.h>
+#include <shibari/util.h>
+
+#endif
diff --git a/src/include/shibari/constants.h b/src/include/shibari/constants.h
new file mode 100644
index 0000000..a4f86f3
--- /dev/null
+++ b/src/include/shibari/constants.h
@@ -0,0 +1,109 @@
+/* ISC license. */
+
+#ifndef SHIBARI_CONSTANTS_H
+#define SHIBARI_CONSTANTS_H
+
+enum shibari_qclass_e
+{
+ SHIBARI_C_IN = 1,
+ SHIBARI_C_CH = 3,
+ SHIBARI_C_HS = 4,
+ SHIBARI_C_NONE = 254,
+ SHIBARI_C_ANY = 255,
+} ;
+
+enum shibari_qtype_e
+{
+ SHIBARI_T_A = 1,
+ SHIBARI_T_NS = 2,
+ SHIBARI_T_MD = 3,
+ SHIBARI_T_MF = 4,
+ SHIBARI_T_CNAME = 5,
+ SHIBARI_T_SOA = 6,
+ SHIBARI_T_MB = 7,
+ SHIBARI_T_MG = 8,
+ SHIBARI_T_MR = 9,
+ SHIBARI_T_NULL = 10,
+ SHIBARI_T_WKS = 11,
+ SHIBARI_T_PTR = 12,
+ SHIBARI_T_HINFO = 13,
+ SHIBARI_T_MINFO = 14,
+ SHIBARI_T_MX = 15,
+ SHIBARI_T_TXT = 16,
+ SHIBARI_T_RP = 17,
+ SHIBARI_T_AFSDB = 18,
+ SHIBARI_T_X25 = 19,
+ SHIBARI_T_ISDN = 20,
+ SHIBARI_T_RT = 21,
+ SHIBARI_T_NSAP = 22,
+ SHIBARI_T_NSAP_PTR = 23,
+ SHIBARI_T_SIG = 24,
+ SHIBARI_T_KEY = 25,
+ SHIBARI_T_PX = 26,
+ SHIBARI_T_GPOS = 27,
+ SHIBARI_T_AAAA = 28,
+ SHIBARI_T_LOC = 29,
+ SHIBARI_T_NXT = 30,
+ SHIBARI_T_EID = 31,
+ SHIBARI_T_NIMLOC = 32,
+ SHIBARI_T_SRV = 33,
+ SHIBARI_T_ATMA = 34,
+ SHIBARI_T_NAPTR = 35,
+ SHIBARI_T_KX = 36,
+ SHIBARI_T_CERT = 37,
+ SHIBARI_T_A6 = 38,
+ SHIBARI_T_DNAME = 39,
+ SHIBARI_T_SINK = 40,
+ SHIBARI_T_OPT = 41,
+ SHIBARI_T_APL = 42,
+ SHIBARI_T_DS = 43,
+ SHIBARI_T_SSHFP = 44,
+ SHIBARI_T_IPSECKEY = 45,
+ SHIBARI_T_RRSIG = 46,
+ SHIBARI_T_NSEC = 47,
+ SHIBARI_T_DNSKEY = 48,
+ SHIBARI_T_DHCID = 49,
+ SHIBARI_T_NSEC3 = 50,
+ SHIBARI_T_NSEC3PARAM = 51,
+ SHIBARI_T_TLSA = 52,
+ SHIBARI_T_SMIMEA = 53,
+ SHIBARI_T_HIP = 55,
+ SHIBARI_T_NINFO = 56,
+ SHIBARI_T_RKEY = 57,
+ SHIBARI_T_TALINK = 58,
+ SHIBARI_T_CDS = 59,
+ SHIBARI_T_CDNSKEY = 60,
+ SHIBARI_T_OPENPGPKEY = 61,
+ SHIBARI_T_CSYNC = 62,
+ SHIBARI_T_ZONEMD = 63,
+ SHIBARI_T_SVCB = 64,
+ SHIBARI_T_HTTPS = 65,
+ SHIBARI_T_SPF = 99,
+ SHIBARI_T_UINFO = 100,
+ SHIBARI_T_UID = 101,
+ SHIBARI_T_GID = 102,
+ SHIBARI_T_UNSPEC = 103,
+ SHIBARI_T_NID = 104,
+ SHIBARI_T_L32 = 105,
+ SHIBARI_T_L64 = 106,
+ SHIBARI_T_LP = 107,
+ SHIBARI_T_EUI48 = 108,
+ SHIBARI_T_EUI64 = 109,
+ SHIBARI_T_TKEY = 249,
+ SHIBARI_T_TSIG = 250,
+ SHIBARI_T_IXFR = 251,
+ SHIBARI_T_AXFR = 252,
+ SHIBARI_T_MAILB = 253,
+ SHIBARI_T_MAILA = 254,
+ SHIBARI_T_ANY = 255,
+ SHIBARI_T_URI = 256,
+ SHIBARI_T_CAA = 257,
+ SHIBARI_T_AVC = 258,
+ SHIBARI_T_DOA = 259,
+ SHIBARI_T_AMIRELAY = 260,
+ SHIBARI_T_RESINFO = 261,
+ SHIBARI_T_TA = 32768,
+ SHIBARI_T_DLV = 32769
+} ;
+
+#endif
diff --git a/src/include/shibari/dcache.h b/src/include/shibari/dcache.h
new file mode 100644
index 0000000..6e0d0ab
--- /dev/null
+++ b/src/include/shibari/dcache.h
@@ -0,0 +1,54 @@
+/* ISC license. */
+
+#ifndef SHIBARI_DCACHE_H
+#define SHIBARI_DCACHE_H
+
+#include <stdint.h>
+
+#include <skalibs/uint64.h>
+#include <skalibs/tai.h>
+#include <skalibs/gensetdyn.h>
+#include <skalibs/avltree.h>
+
+#define DCACHE_MAGIC "--DCACHE--\n"
+
+typedef struct dcache_key_s dcache_key_t, *dcache_key_t_ref ;
+struct dcache_key_s
+{
+ char *s ;
+ uint16_t len ;
+} ;
+
+typedef struct dcache_node_s dcache_node_t, *dcache_node_t_ref ;
+struct dcache_node_s
+{
+ dcache_key_t key ;
+ uint16_t datalen ;
+ tain entry ;
+ tain expire ;
+} ;
+
+typedef struct dcache_s dcache_t, *dcache_t_ref ;
+struct dcache_s
+{
+ gensetdyn storage ; /* dcache_node_t */
+ avltree by_key ;
+ avltree by_entry ;
+ avltree by_expire ;
+ uint64_t size ;
+ uint64_t motion ;
+} ;
+#define DCACHE_ZERO { .storage = GENSETDYN_ZERO, .by_key = AVLTREE_ZERO, .by_entry = AVLTREE_ZERO, .by_expire = AVLTREE_ZERO, .size = 0, .motion = 0 }
+
+extern void dcache_init (dcache_t *, uint64_t) ;
+extern dcache_node_t *dcache_search (dcache_t *, char const *, uint16_t) ;
+extern int dcache_add (dcache_t *, uint64_t, char const *, uint16_t, char const *, uint16_t, tain const *, tain const *) ;
+#define dcache_add_g(d, max, key, keylen, data, datalen, expire) dcache_add(d, max, key, keylen, data, datalen, (expire), &STAMP)
+extern void dcache_clean_expired (dcache_t *, tain const *) ;
+#define dcache_clean_expired_g(d) dcache_clean_expired((d), &STAMP)
+extern void dcache_free (dcache_t *) ;
+
+extern int dcache_save (dcache_t const *, char const *) ;
+extern int dcache_load (dcache_t *, uint64_t, char const *) ;
+
+#endif
diff --git a/src/include/shibari/log.h b/src/include/shibari/log.h
new file mode 100644
index 0000000..a01e499
--- /dev/null
+++ b/src/include/shibari/log.h
@@ -0,0 +1,20 @@
+/* ISC license. */
+
+#ifndef SHIBARI_LOG_H
+#define SHIBARI_LOG_H
+
+#include <stdint.h>
+
+#include <skalibs/ip46.h>
+
+#include <s6-dns/s6dns-domain.h>
+#include <s6-dns/s6dns-message.h>
+
+extern void shibari_log_start (uint32_t, ip46 const *, uint16_t) ;
+extern void shibari_log_exit (uint32_t, int) ;
+
+extern void shibari_log_query (uint32_t, s6dns_domain_t const *, uint16_t) ;
+extern void shibari_log_queryplus (uint32_t, s6dns_domain_t const *, uint16_t, ip46 const *, uint16_t) ;
+extern void shibari_log_answer (uint32_t, s6dns_message_header_t const *, uint16_t) ;
+
+#endif
diff --git a/src/include/shibari/packet.h b/src/include/shibari/packet.h
new file mode 100644
index 0000000..1f4fa93
--- /dev/null
+++ b/src/include/shibari/packet.h
@@ -0,0 +1,39 @@
+/* ISC license. */
+
+#ifndef SHIBARI_PACKET_H
+#define SHIBARI_PACKET_H
+
+#include <stdint.h>
+
+#include <skalibs/cdb.h>
+#include <skalibs/tai.h>
+
+#include <s6-dns/s6dns-domain.h>
+#include <s6-dns/s6dns-message.h>
+
+#include <shibari/tdb.h>
+
+typedef struct shibari_packet_s shibari_packet, *shibari_packet_ref ;
+struct shibari_packet_s
+{
+ s6dns_message_header_t hdr ;
+ char *buf ;
+ uint16_t max ;
+ uint16_t pos ;
+ uint8_t flagtcp : 1 ;
+} ;
+#define SHIBARI_PACKET_ZERO { .hdr = S6DNS_MESSAGE_HEADER_ZERO, .buf = "", .pos = 0, .flagtcp = 0 }
+#define SHIBARI_PACKET_INIT(rbuf, rmax, tcp) { .hdr = S6DNS_MESSAGE_HEADER_ZERO, .buf = tcp ? rbuf + 2 : rbuf, .max = tcp ? rmax - 2 : rmax, .pos = 0, .flagtcp = !!tcp }
+
+extern void shibari_packet_init (shibari_packet *, char *, uint32_t, int) ;
+
+extern void shibari_packet_begin (shibari_packet *, uint16_t, s6dns_domain_t const *, uint16_t) ;
+extern void shibari_packet_end (shibari_packet *) ;
+
+extern int shibari_packet_add_rr (shibari_packet *, shibari_tdb_entry const *, int, uint16_t, unsigned int) ;
+extern unsigned int shibari_packet_add_glue (shibari_packet *, cdb const *, char const *, uint16_t, uint16_t, char const *, uint16_t, uint16_t, uint16_t, char const *, tain const *) ;
+extern unsigned int shibari_packet_assert_authority (shibari_packet *, cdb const *, char const *, uint16_t, uint16_t, char const *, tain const *) ;
+
+extern unsigned int shibari_packet_tdb_answer_query (shibari_packet *, cdb const *, s6dns_message_header_t const *, s6dns_domain_t const *, uint16_t, char const *, tain const *) ;
+
+#endif
diff --git a/src/include/shibari/server.h b/src/include/shibari/server.h
new file mode 100644
index 0000000..db5af40
--- /dev/null
+++ b/src/include/shibari/server.h
@@ -0,0 +1,10 @@
+/* ISC license. */
+
+#ifndef SHIBARI_SERVER_H
+#define SHIBARI_SERVER_H
+
+#include <shibari/log.h>
+#include <shibari/tdb.h>
+#include <shibari/packet.h>
+
+#endif
diff --git a/src/include/shibari/shibari.h b/src/include/shibari/shibari.h
new file mode 100644
index 0000000..a9242d3
--- /dev/null
+++ b/src/include/shibari/shibari.h
@@ -0,0 +1,11 @@
+/* ISC license. */
+
+#ifndef SHIBARI_H
+#define SHIBARI_H
+
+#include <shibari/common.h>
+#include <shibari/client.h>
+#include <shibari/cache.h>
+#include <shibari/server.h>
+
+#endif
diff --git a/src/include/shibari/tdb.h b/src/include/shibari/tdb.h
new file mode 100644
index 0000000..f61df5b
--- /dev/null
+++ b/src/include/shibari/tdb.h
@@ -0,0 +1,29 @@
+/* ISC license. */
+
+#ifndef SHIBARI_TDB_H
+#define SHIBARI_TDB_H
+
+#include <stdint.h>
+
+#include <skalibs/cdb.h>
+#include <skalibs/tai.h>
+
+#include <s6-dns/s6dns-message.h>
+
+typedef struct shibari_tdb_entry_s shibari_tdb_entry, *shibari_tdb_entry_ref ;
+struct shibari_tdb_entry_s
+{
+ uint16_t type ;
+ uint16_t len ;
+ uint32_t ttl ;
+ uint32_t flags ;
+ cdb_data key ;
+ cdb_data data ;
+} ;
+
+extern int shibari_tdb_entry_parse (shibari_tdb_entry *, char const *, uint16_t, uint16_t, unsigned int, char const *, tain const *) ;
+extern int shibari_tdb_read_entry (cdb const *, cdb_find_state *, shibari_tdb_entry *, char const *, uint16_t, uint16_t, unsigned int, char const *, tain const *, uint32_t *) ;
+extern int shibari_tdb_extract_domain (shibari_tdb_entry const *, cdb_data *) ;
+extern int shibari_tdb_find_authority (cdb const *, char const *, uint16_t, char const *, tain const *, int *) ;
+
+#endif
diff --git a/src/include/shibari/util.h b/src/include/shibari/util.h
new file mode 100644
index 0000000..82092a3
--- /dev/null
+++ b/src/include/shibari/util.h
@@ -0,0 +1,14 @@
+/* ISC license. */
+
+#ifndef SHIBARI_UTIL_H
+#define SHIBARI_UTIL_H
+
+#include <stdint.h>
+
+extern char const *shibari_util_qtype_str (uint16_t) ;
+extern uint16_t shibari_util_qtype_num (char const *) ;
+extern char const *shibari_util_rcode_str (uint16_t) ;
+
+extern int shibari_util_get_prefixlen (char const *, uint16_t, char const *, uint16_t) ;
+
+#endif