summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2024-07-25 00:20:30 +0000
committerLaurent Bercot <ska@appnovation.com>2024-07-25 00:20:30 +0000
commitfc85d676b5ca3de92264dfcb41c98d7c9b0d1398 (patch)
treec9e77e23b9b2b35760f18ce8a7c36ab921b9905d
parent8c9b0194063411882d3bbcec80d5e5c861d37544 (diff)
downloadshibari-fc85d676b5ca3de92264dfcb41c98d7c9b0d1398.tar.xz
More shibari-cache stuff
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r--src/cache/clientaccess.c (renamed from src/cache/access.c)8
-rw-r--r--src/cache/conf.c9
-rw-r--r--src/cache/deps-exe/shibari-cache4
-rw-r--r--src/cache/query.c16
-rw-r--r--src/cache/shibari-cache-internal.h75
-rw-r--r--src/cache/shibari-cache.c161
-rw-r--r--src/cache/tcpconnection.c12
-rw-r--r--src/config/defaults.c11
-rw-r--r--src/config/lexparse.c16
-rw-r--r--src/include/shibari/cache.h8
-rw-r--r--src/include/shibari/client.h6
-rw-r--r--src/include/shibari/shibari.h2
12 files changed, 221 insertions, 107 deletions
diff --git a/src/cache/access.c b/src/cache/clientaccess.c
index 8f87125..0dc5270 100644
--- a/src/cache/access.c
+++ b/src/cache/clientaccess.c
@@ -1,8 +1,10 @@
/* ISC license. */
#include <stdint.h>
+#include <string.h>
#include <skalibs/cdb.h>
+#include <skalibs/ip46.h>
#include "shibari-cache-internal.h"
@@ -12,7 +14,7 @@ static inline int check (char const *key, size_t keylen)
return cdb_find(&confdb, &data, key, keylen) ;
}
-int ip4_access (char const *ip)
+int clientaccess_ip4 (char const *ip)
{
int r ;
char key[9] = "A4:" ;
@@ -29,7 +31,8 @@ int ip4_access (char const *ip)
return 0 ;
}
-int ip6_access (char const *ip)
+#ifdef SKALIBS_IPV6_ENABLED
+int clientaccess_ip6 (char const *ip)
{
int r ;
char key[21] = "A6:" ;
@@ -45,3 +48,4 @@ int ip6_access (char const *ip)
}
return 0 ;
}
+#endif
diff --git a/src/cache/conf.c b/src/cache/conf.c
index 209fdc3..c2f3d6b 100644
--- a/src/cache/conf.c
+++ b/src/cache/conf.c
@@ -27,6 +27,15 @@ int conf_get (cdb const *c, char const *key, cdb_data *data)
return conf_getb(c, key, strlen(key), data) ;
}
+int conf_get_uint16 (cdb const *c, char const *key, uint16_t *value)
+{
+ cdb_data data ;
+ if (!conf_get(conf, key, &data)) return 0 ;
+ if (data.len != 2) return (errno = EPROTO, 0) ;
+ uint16_unpack_big(data.s, value) ;
+ return 1 ;
+}
+
int conf_get_uint32 (cdb const *c, char const *key, uint32_t *value)
{
cdb_data data ;
diff --git a/src/cache/deps-exe/shibari-cache b/src/cache/deps-exe/shibari-cache
index 841cf80..19a22c6 100644
--- a/src/cache/deps-exe/shibari-cache
+++ b/src/cache/deps-exe/shibari-cache
@@ -1,5 +1,9 @@
cache.o
+clientaccess.o
conf.o
+query.o
+tcpconnection.o
+udpqueue.o
${LIBDCACHE}
${LIBSHIBARI_COMMON}
-ls6dns
diff --git a/src/cache/query.c b/src/cache/query.c
new file mode 100644
index 0000000..ad606e6
--- /dev/null
+++ b/src/cache/query.c
@@ -0,0 +1,16 @@
+/* ISC license. */
+
+#include "shibari-cache-internal.h"
+
+void query_fail (query *q)
+{
+}
+
+void query_success (query *q)
+{
+}
+
+int query_new (uint8_t source, uint16_t i, char const *ip, uint16_t port, char const *s, uint16_t len)
+{
+ return 1 ;
+}
diff --git a/src/cache/shibari-cache-internal.h b/src/cache/shibari-cache-internal.h
index 606d245..4f6476d 100644
--- a/src/cache/shibari-cache-internal.h
+++ b/src/cache/shibari-cache-internal.h
@@ -3,6 +3,7 @@
#ifndef SHIBARI_CACHE_INTERNAL_H
#define SHIBARI_CACHE_INTERNAL_H
+#include <stddef.h>
#include <stdint.h>
#include <skalibs/uint64.h>
@@ -24,15 +25,47 @@ extern void cache_dump (void) ;
extern void cache_load (void) ;
+ /* clientaccess */
+
+extern int clientaccess_ip4 (char const *) ;
+#if SKALIBS_IPV6_ENABLED
+extern int clientaccess_ip6 (char const *) ;
+#endif
+
/* conf */
extern int conf_getb (cdb const *, char const *, size_t, cdb_data *) ;
extern int conf_get (cdb const *, char const *, cdb_data *) ;
+extern int conf_get_uint16 (cdb const *, char const *, uint16_t *) ;
extern int conf_get_uint32 (cdb const *, char const *, uint32_t *) ;
extern int conf_get_uint64 (cdb const *, char const *, uint64_t *) ;
extern char const *conf_get_string (cdb const *, char const *) ;
+ /* query */
+
+typedef struct query_s query, *query_ref ;
+struct query_s
+{
+ s6dns_engine_t dt ;
+ uint16_t prev ;
+ uint16_t next ;
+ uint16_t xindex ;
+ uint16_t source ;
+ uint16_t i ;
+ uint16_t port ;
+ char ip[SKALIBS_IP_SIZE] ;
+} ;
+#define QUERY_ZERO { .dt = S6DNS_ENGINE_ZERO, .prev = 0, .next = 0, .xindex = UINT16_MAX, .source = 0, .i = 0, .port = 0, .ip = { 0 } }
+#define nq (genset_n(&g->queries) - 1)
+#define QUERY(i) genset_p(query, &g->queries, (i))
+#define qstart (QUERY(g->qsentinel)->next)
+
+extern void query_fail (query *) ;
+extern void query_success (query *) ;
+extern void query_new (uint8_t, uint16_t, char const *, uint16_t, char const *, uint16_t) ;
+
+
/* tcpconnection */
typedef struct tcpconnection_s tcpconnection, *tcpconnection_ref ;
@@ -43,9 +76,9 @@ struct tcpconnection_s
uint32_t instate ;
tain rdeadline ;
tain wdeadline ;
- uint32_t prev ;
- uint32_t next ;
- uint32_t xindex ;
+ uint16_t prev ;
+ uint16_t next ;
+ uint16_t xindex ;
} ;
#define TCPCONNECTION_ZERO { .out = BUFALLOC_ZERO, .in = STRALLOC_ZERO, .instate = 0, .rdeadline = TAIN_INFINITE, .wdeadline = TAIN_INFINITE, .prev = 0, .next = 0. .xindex = UINT32_MAX }
#define ntcp (genset_n(&g->tcpconnections) - 1)
@@ -53,6 +86,7 @@ struct tcpconnection_s
#define tcpstart (TCPCONNECTION(g->tcpsentinel)->next)
extern void tcpconnection_drop (tcpconnection *) ;
+extern int tcpconnection_new (uint8_t, uint16_t, int, char const *, uint16_t) ;
/* udpqueue */
@@ -66,6 +100,7 @@ struct udp4msg_s
} ;
#define UDP4MSG_ZERO { .ip = { 0 }, .port = 0, .len = 0 }
+#ifdef SKALIBS_IPV6_ENABLED
typedef struct udp6msg_s udp6msg, *udp6msg_ref ;
struct udp4msg_s
{
@@ -74,6 +109,7 @@ struct udp4msg_s
uint16_t len ;
} ;
#define UDP6MSG_ZERO { .ip = { 0 }, .port = 0, .len = 0 }
+#endif
typedef struct udpqueue_s udpqueue, *udpqueue_ref ;
struct udpqueue_s
@@ -82,7 +118,7 @@ struct udpqueue_s
stralloc storage ;
genalloc messages ; /* udp[46]msg */
tain deadline ;
- uint32_t xindex ;
+ uint16_t xindex ;
} ;
#define UDPQUEUE_ZERO { .fd = -1, .storage = STRALLOC_ZERO, .messages = GENALLOC_ZERO, .deadline = TAIN_INFINITE, .xindex = UINT32_MAX }
@@ -97,29 +133,6 @@ extern int udpqueue_flush6 (udpqueue *) ;
#endif
- /* query */
-
-typedef struct query_s query, *query_ref ;
-struct query_s
-{
- s6dns_engine_t dt ;
- uint32_t origin ;
- uint32_t prev ;
- uint32_t next ;
- uint32_t xindex ;
- char ip[16] ;
- uint16_t port ;
-} ;
-#define QUERY_ZERO { .dt = S6DNS_ENGINE_ZERO, .origin = 0, .prev = 0, .next = 0, .xindex = UINT32_MAX, .ip = { 0 }, .port = 0 }
-#define nq (genset_n(&g->queries) - 1)
-#define QUERY(i) genset_p(query, &g->queries, (i))
-#define qstart (QUERY(g->qsentinel)->next)
-
-extern void query_fail (query *) ;
-extern void query_success (query *) ;
-extern void query_new (uint32_t, char const *, uint8_t, uint16_t, char const *, uint16_t) ;
-
-
/* main */
typedef struct global_s global, *global_ref ;
@@ -127,13 +140,13 @@ struct global_s
{
cdb confdb ;
char const *dumpfile ;
- uint32_t verbosity ;
+ uint16_t verbosity ;
tain rtto ;
tain wtto ;
genset tcpconnections ; /* tcpconnection */
- uint32_t tcpsentinel ;
genset queries ; /* query */
- uint32_t qsentinel ;
+ uint16_t tcpsentinel ;
+ uint16_t qsentinel ;
} ;
#define GLOBAL_ZERO { \
.confdb = CDB_ZERO, \
@@ -142,8 +155,8 @@ struct global_s
.rtto = TAIN_INFINITE, \
.wtto = TAIN_INFINITE, \
.tcpconnections = GENSET_ZERO, \
- .tcpsentinel = 0, \
.queries = GENSET_ZERO, \
+ .tcpsentinel = 0, \
.qsentinel = 0, \
}
diff --git a/src/cache/shibari-cache.c b/src/cache/shibari-cache.c
index 99d52b8..85f74bc 100644
--- a/src/cache/shibari-cache.c
+++ b/src/cache/shibari-cache.c
@@ -42,11 +42,11 @@ static int flagwantfinaldump = 1 ;
static tain lameduckt = TAIN_INFINITE_RELATIVE ;
-static inline void conf_init (char const *conffile, uint32_t *n4, uint32_t *n6, char const **ip4, char const **ip6, uint32_t *maxtcp, uint32_t *maxqueries)
+static inline void conf_init (char const *conffile, uint16_t *n4, uint16_t *n6, char const **ip4, char const **ip6, uint16_t *maxtcp, uint16_t *maxqueries)
{
cdb_data data ;
uint32_t u ;
- if (!conf_get_uint32(&g->confdb, "G:logv", &g->verbosity))
+ if (!conf_get_uint16(&g->confdb, "G:logv", &g->verbosity))
strerr_diefu4sys(102, "read ", "G:logv", " configuration key from ", conffile) ;
{
uint64_t cachesize ;
@@ -56,11 +56,11 @@ static inline void conf_init (char const *conffile, uint32_t *n4, uint32_t *n6,
strerr_dief2x(102, "invalid G:cachesize in ", conffile) ;
cache_init(cachesize) ;
}
- if (!conf_get_uint32(&g->confdb, "G:maxtcp", maxtcp))
+ if (!conf_get_uint16(&g->confdb, "G:maxtcp", maxtcp))
strerr_diefu4sys(102, "read ", "G:maxtcp", " configuration key from ", conffile) ;
if (*maxtcp > 4096 || *maxtcp < 1)
strerr_dief2x(102, "invalid G:maxtcp in ", conffile) ;
- if (!conf_get_uint32(&g->confdb, "G:maxqueries", maxqueries))
+ if (!conf_get_uint16(&g->confdb, "G:maxqueries", maxqueries))
strerr_diefu4sys(102, "read ", "G:maxqueries", " configuration key from ", conffile) ;
if (*maxqueries > 8192 || *maxqueries < 1)
strerr_dief2x(102, "invalid G:maxqueries in ", conffile) ;
@@ -78,6 +78,8 @@ static inline void conf_init (char const *conffile, uint32_t *n4, uint32_t *n6,
strerr_diefu4sys(102, "read ", "G:listen4", " configuration key from ", conffile) ;
if (data.len & 3)
strerr_diefu4sys(102, "invalid ", "G:listen4", " key in ", conffile) ;
+ if (data.len > 4 * 1024)
+ strerr_diefu3sys(102, "G:listen4", " key too long in ", conffile) ;
*n4 = data.len >> 2 ;
*ip4 = data.s ;
#ifdef SKALIBS_IPV6_ENABLED
@@ -85,6 +87,8 @@ static inline void conf_init (char const *conffile, uint32_t *n4, uint32_t *n6,
strerr_diefu4sys(102, "read ", "G:listen6", " configuration key from ", conffile) ;
if (data.len & 15)
strerr_diefu4sys(102, "invalid ", "G:listen6", " key in ", conffile) ;
+ if (data.len > 16 * 1024)
+ strerr_diefu3sys(102, "G:listen6", " key too long in ", conffile) ;
*n6 = data.len >> 4 ;
*ip6 = data.s ;
#endif
@@ -115,7 +119,7 @@ int main (int argc, char const *const *argv)
{
global globals = GLOBAL_ZERO ;
char const *conffile = SHIBARI_SYSCONFDIR "/shibari-cache.conf.cdb" ;
- uint32_t n4 = 0, n6 = 0, maxtcp, maxqueries ;
+ uint16_t n4 = 0, n6 = 0, maxtcp, maxqueries ;
char const *ip4 = 0, *ip6 = 0 ;
unsigned int cont = 2 ;
int sfd = -1 ;
@@ -181,8 +185,8 @@ int main (int argc, char const *const *argv)
udpqueue udpq6[n6 ? n6 : 1] ;
int tcp4fd[n4 ? n4 : 1] ;
int tcp6fd[n6 ? n6 : 1] ;
- uint32_t tcp4xindex[n4 ? n4 : 1] ;
- uint32_t tcp6xindex[n4 ? n4 : 1] ;
+ uint16_t tcp4xindex[n4 ? n4 : 1] ;
+ uint16_t tcp6xindex[n4 ? n4 : 1] ;
tcpconnection tcpconnection_storage[maxtcp + 1] ;
uint32_t tcpconnection_freelist[maxtcp + 1] ;
query query_storage[maxqueries + 1] ;
@@ -205,7 +209,7 @@ int main (int argc, char const *const *argv)
q->prev = q->next = g->qsentinel ;
}
- for (size_t i = 0 ; i < n4 ; i++)
+ for (uint16_t i = 0 ; i < n4 ; i++)
{
udpq4[i].fd = socket_udp4_nbcoe() ;
if (udpq4[i].fd == -1) strerr_diefu1sys(111, "create udp4 socket") ;
@@ -225,7 +229,7 @@ int main (int argc, char const *const *argv)
}
}
#ifdef SKALIBS_IPV6_ENABLED
- for (size_t i = 0 ; i < n6 ; i++)
+ for (uint16_t i = 0 ; i < n6 ; i++)
{
udpq6[i].fd = socket_udp6_nbcoe() ;
if (udpq6[i].fd == -1) strerr_diefu1sys(111, "create udp6 socket") ;
@@ -275,7 +279,7 @@ int main (int argc, char const *const *argv)
x[0].events = IOPAUSE_READ ;
if (cont == 1 && tain_less(&lameduckt, &deadline)) deadline = lameduckt ;
- for (uint32_t i = 0 ; i < n4 ; i++)
+ for (uint16_t i = 0 ; i < n4 ; i++)
{
x[j].fd = udpq4[i].fd ;
x[j].events = nq < maxqueries && cont >= 2 ? IOPAUSE_READ : 0 ;
@@ -285,7 +289,7 @@ int main (int argc, char const *const *argv)
if (tain_less(&udpq4[i].deadline, &deadline)) deadline = udpq4[i].deadline ;
r = 1 ;
}
- if (x[j].events) udpq4[i].xindex = j++ ; else udpq4[i].xindex = UINT32_MAX ;
+ if (x[j].events) udpq4[i].xindex = j++ ; else udpq4[i].xindex = UINT16_MAX ;
if (ntcp < maxtcp && cont >= 2)
{
@@ -293,11 +297,11 @@ int main (int argc, char const *const *argv)
x[j].events = IOPAUSE_READ ;
tcp4xindex[i] = j++ ;
}
- else tcp4xindex[i] = UINT32_MAX ;
+ else tcp4xindex[i] = UINT16_MAX ;
}
#ifdef SKALIBS_IPV6_ENABLED
- for (uint32_t i = 0 ; i < n6 ; i++)
+ for (uint16_t i = 0 ; i < n6 ; i++)
{
x[j].fd = udpq6[i].fd ;
x[j].events = nq < maxqueries && cont >= 2 ? IOPAUSE_READ : 0 ;
@@ -307,7 +311,7 @@ int main (int argc, char const *const *argv)
if (tain_less(&udpq6[i].deadline, &deadline)) deadline = udpq6[i].deadline ;
r = 1 ;
}
- if (x[j].events) udpq6[i].xindex = j++ ; else udpq6[i].xindex = UINT32_MAX ;
+ if (x[j].events) udpq6[i].xindex = j++ ; else udpq6[i].xindex = UINT16_MAX ;
if (ntcp < maxtcp && cont >= 2)
{
@@ -315,11 +319,11 @@ int main (int argc, char const *const *argv)
x[j].events = IOPAUSE_READ ;
tcp6xindex[i] = j++ ;
}
- else tcp6xindex[i] = UINT32_MAX ;
+ else tcp6xindex[i] = UINT16_MAX ;
}
#endif
- for (uint32_t i = tcpstart ; i != g->tcpsentinel ; i = TCPCONNECTION(i)->next)
+ for (uint16_t i = tcpstart ; i != g->tcpsentinel ; i = TCPCONNECTION(i)->next)
{
tcpconnection *p = TCPCONNECTION(i) ;
x[j].fd = bufalloc_fd(&p->out) ;
@@ -335,16 +339,16 @@ int main (int argc, char const *const *argv)
if (tain_less(&p->wdeadline, &deadline)) deadline = p->wdeadline ;
r = 1 ;
}
- if (x[j].events) p->xindex = j++ ; else p->xindex = UINT32_MAX ;
+ if (x[j].events) p->xindex = j++ ; else p->xindex = UINT16_MAX ;
}
- for (uint32_t i = qstart ; i != g->qsentinel ; i = QUERY(i)->next)
+ for (uint16_t i = qstart ; i != g->qsentinel ; i = QUERY(i)->next)
{
query *p = QUERY(i) ;
x[j].fd = p->dt.fd ;
s6dns_engine_nextdeadline(&p->dt, &deadline) ;
x[j].events = (s6dns_engine_isreadable(&p->dt) ? IOPAUSE_READ : 0) | (s6dns_engine_iswritable(&p->dt) ? IOPAUSE_WRITE : 0) ;
- if (x[j].events) p->xindex = j++ ; else p->xindex = UINT32_MAX ;
+ if (x[j].events) p->xindex = j++ ; else p->xindex = UINT16_MAX ;
}
@@ -364,20 +368,20 @@ int main (int argc, char const *const *argv)
if (!r)
{
if (cont == 1 && !tain_future(&lameduckt)) break ;
- for (uint32_t i = qstart ; i != g->qsentinel ; i = QUERY(i)->next)
+ for (uint16_t i = qstart ; i != g->qsentinel ; i = QUERY(i)->next)
{
query *p = QUERY(i) ;
if (s6dns_engine_timeout_g(&p->dt)) { i = p->prev ; query_fail(p) ; }
}
- for (uint32_t i = tcpstart ; i != g->tcpsentinel ; i = TCPCONNECTION(i)->next)
+ for (uint16_t i = tcpstart ; i != g->tcpsentinel ; i = TCPCONNECTION(i)->next)
{
tcpconnection *p = TCPCONNECTION(i) ;
if (!tain_future(&p->rdeadline) || !tain_future(&p->wdeadline))
tcpconnection_drop(p) ;
}
- for (uint32_t i = 0 ; i < n4 ; i++)
+ for (uint16_t i = 0 ; i < n4 ; i++)
if (!tain_future(&udp4q[i].deadline)) udpqueue_drop(udp4q + i) ;
- for (uint32_t i = 0 ; i < n6 ; i++)
+ for (uint16_t i = 0 ; i < n6 ; i++)
if (!tain_future(&udp6q[i].deadline)) udpqueue_drop(udp6q + i) ;
}
@@ -386,11 +390,11 @@ int main (int argc, char const *const *argv)
else
{
- for (uint32_t i = 0 ; i < j ; i++) if (x[i].revents & IOPAUSE_EXCEPT) x[i].revents |= x[i].events ;
+ for (uint16_t i = 0 ; i < j ; i++) if (x[i].revents & IOPAUSE_EXCEPT) x[i].revents |= x[i].events ;
if (x[0].revents & IOPAUSE_READ) { handle_signals() ; continue ; }
- for (uint32_t i = 0 ; i < n4 ; i++) if (udpq4[i].xindex < UINT32_MAX)
+ for (uint16_t i = 0 ; i < n4 ; i++) if (udpq4[i].xindex < UINT16_MAX)
{
if (x[udpq4[i].xindex].revents & IOPAUSE_WRITE)
{
@@ -404,7 +408,7 @@ int main (int argc, char const *const *argv)
}
#ifdef SKALIBS_IPV6_ENABLED
- for (uint32_t i = 0 ; i < n6 ; i++) if (udpq6[i].xindex < UINT32_MAX)
+ for (uint16_t i = 0 ; i < n6 ; i++) if (udpq6[i].xindex < UINT16_MAX)
{
if (x[udpq6[i].xindex].revents & IOPAUSE_WRITE)
{
@@ -418,10 +422,10 @@ int main (int argc, char const *const *argv)
}
#endif
- for (uint32_t i = tcpstart ; i != g->tcpsentinel ; i = TCPCONNECTION(i)->next)
+ for (uint16_t i = tcpstart ; i != g->tcpsentinel ; i = TCPCONNECTION(i)->next)
{
tcpconnection *p = TCPCONNECTION(i) ;
- if (p->xindex < UINT32_MAX && x[p->xindex].revents & IOPAUSE_WRITE)
+ if (p->xindex < UINT16_MAX && x[p->xindex].revents & IOPAUSE_WRITE)
{
if (tcpconnection_flush(p) == -1)
{
@@ -431,20 +435,20 @@ int main (int argc, char const *const *argv)
}
}
- for (uint32_t i = qstart ; i != g->qsentinel ; i = QUERY(i)->next)
+ for (uint16_t i = qstart ; i != g->qsentinel ; i = QUERY(i)->next)
{
query *p = QUERY(i) ;
- if (p->xindex == UINT32_MAX) continue ;
+ if (p->xindex == UINT16_MAX) continue ;
r = s6dns_engine_event_g(&p->dt) ;
if (r) i = p->prev ;
if (r == -1) query_fail(p) ; else query_success(p) ;
}
- for (uint32_t i = 0 ; i < n4 ; i++)
+ for (uint16_t i = 0 ; i < n4 ; i++)
{
- if (udpq4[i].xindex < UINT32_MAX && x[udpq4[i].xindex].revents & IOPAUSE_READ)
+ if (udpq4[i].xindex < UINT16_MAX && x[udpq4[i].xindex].revents & IOPAUSE_READ)
{
- uint32_t n = MAXSAME ;
+ uint16_t n = MAXSAME ;
char buf[513] ;
char ip[4] ;
uint16_t port ;
@@ -459,18 +463,28 @@ int main (int argc, char const *const *argv)
}
if (!len) break ;
if (len < 12 || len > 512) continue ;
- if (!ip4_access(ip)) continue ;
- query_new(i, ip, 4, port, buf, len) ;
+ if (!clientaccess_ip4(ip)) continue ;
+ if (!query_new(0, i, ip, port, buf, len))
+ {
+ if (g->verbosity)
+ {
+ char fmtip[IP4_FMT] ;
+ char fmtport[UINT16_FMT] ;
+ fmtip[ip4_fmt(fmtip, ip] = 0 ;
+ fmtport[uint16_fmt(fmtport, port] = 0 ;
+ strerr_warnwu4sys("process new UDP query from ip ", fmtip, " port ", fmtport) ;
+ }
+ }
}
}
}
#ifdef SKALIBS_IPV6_ENABLED
- for (uint32_t i = 0 ; i < n6 ; i++)
+ for (uint16_t i = 0 ; i < n6 ; i++)
{
- if (udpq6[i].xindex < UINT32_MAX && x[udpq6[i].xindex].revents & IOPAUSE_READ)
+ if (udpq6[i].xindex < UINT16_MAX && x[udpq6[i].xindex].revents & IOPAUSE_READ)
{
- uint32_t n = MAXSAME ;
+ uint16_t n = MAXSAME ;
char buf[513] ;
char ip[16] ;
uint16_t port ;
@@ -485,39 +499,86 @@ int main (int argc, char const *const *argv)
}
if (!len) break ;
if (len < 12 || len > 512) continue ;
- if (!ip6_access(ip)) continue ;
- query_new(n4 + i, ip, 16, port, buf, len) ;
+ if (!clientaccess_ip6(ip)) continue ;
+ if (!query_new(1, i, ip, port, buf, len))
+ {
+ if (g->verbosity)
+ {
+ char fmtip[IP4_FMT] ;
+ char fmtport[UINT16_FMT] ;
+ fmtip[ip4_fmt(fmtip, ip] = 0 ;
+ fmtport[uint16_fmt(fmtport, port] = 0 ;
+ strerr_warnwu4sys("process new UDP query from ip ", fmtip, " port ", fmtport) ;
+ }
+ }
}
}
}
#endif
- for (uint32_t i = tcpstart ; i != g->tcpsentinel ; i = TCPCONNECTION(i)->next)
+ for (uint16_t i = tcpstart ; i != g->tcpsentinel ; i = TCPCONNECTION(i)->next)
{
tcpconnection *p = TCPCONNECTION(i) ;
- if (p->xindex < UINT32_MAX && x[p->xindex].revents & IOPAUSE_READ)
+ if (p->xindex < UINT16_MAX && x[p->xindex].revents & IOPAUSE_READ)
{
int l = sanitize_read(mininetstring_read(bufalloc_fd(&p->out), &p->in, &p->instate)) ;
if (l == -1) { i = p->prev ; tcpconnection_drop(p) ; }
if (l <= 0) continue ;
if (sa.len < 12 || sa.len > 65536) { i = p->prev ; tcpconnection_drop(p) ; continue ; }
- query_new(n4 + n6 + i, 0, 0, 0, sa.s, sa.len) ;
+ query_new(2, i, 0, 0, sa.s, sa.len) ;
sa.len = 0 ;
}
}
- for (uint32_t i = 0 ; i < n4 ; i++) if (tcp4xindex[i] < UINT32_MAX)
- {
- if (x[tcp4index[i]].revents & IOPAUSE_READ)
- {
- }
- }
+ for (uint16_t i = 0 ; i < n4 ; i++) if (tcp4xindex[i] < UINT16_MAX)
+ {
+ if (x[tcp4index[i]].revents & IOPAUSE_READ)
+ {
+ uint16_t n = MAXSAME ;
+ while (n-- && ntcp < maxtcp)
+ {
+ char ip[4] ;
+ uint16_t port ;
+ int fd = socket_accept4_nbcoe(tcp4fd[i], ip, &port) ;
+ if (fd == -1)
+ {
+ if (error_isagain(errno)) break ;
+ strerr_diefu4sys("create new TCP connection") ;
+ }
+ if (!clientaccess_ip4(ip)) { fd_close(fd) ; continue ; }
+ tcpconnection_new(0, i, fd, ip, port) ;
+ }
+ }
+ }
+
+#ifdef SKALIBS_IPV6_ENABLED
+ for (uint16_t i = 0 ; i < n6 ; i++) if (tcp6xindex[i] < UINT16_MAX)
+ {
+ if (x[tcp6index[i]].revents & IOPAUSE_READ)
+ {
+ uint16_t n = MAXSAME ;
+ while (n-- && ntcp < maxtcp)
+ {
+ char ip[16] ;
+ uint16_t port ;
+ int fd = socket_accept6_nbcoe(tcp6fd[i], ip, &port) ;
+ if (fd == -1)
+ {
+ if (error_isagain(errno)) break ;
+ strerr_diefu4sys("create new TCP connection") ;
+ }
+ if (!clientaccess_ip6(ip)) { fd_close(fd) ; continue ; }
+ tcpconnection_new(1, i, fd, ip, port) ;
+ }
+ }
+ }
+#endif
}
}
}
if (flagwantfinaldump) cache_dump() ;
- shibari_log_exit(verbosity, 0) ;
+// shibari_log_exit(g->verbosity, 0) ;
return 0 ;
}
diff --git a/src/cache/tcpconnection.c b/src/cache/tcpconnection.c
new file mode 100644
index 0000000..d42060f
--- /dev/null
+++ b/src/cache/tcpconnection.c
@@ -0,0 +1,12 @@
+/* ISC license. */
+
+#include "shibari-cache-internal.h"
+
+void tcpconnection_drop (tcpconnection *tc)
+{
+}
+
+int tcpconnection_new (uint8_t source, uint16_t i, int fd, char const *ip, uint16_t port)
+{
+ return 1 ;
+}
diff --git a/src/config/defaults.c b/src/config/defaults.c
index 9222aa4..9a30c98 100644
--- a/src/config/defaults.c
+++ b/src/config/defaults.c
@@ -13,19 +13,20 @@ struct defaults_s
#define REC(k, v, n) { .key = (k), .value = (v), .vlen = (n) }
#define RECS(k, v) REC(k, (v), sizeof(v))
+#define RECU16(k, u) { .key = (k), .value = (char const [2]){ (u) >> 8 & 0xffu, (u) & 0xffu }, .vlen = 2 }
#define RECU32(k, u) { .key = (k), .value = (char const [4]){ (u) >> 24 & 0xffu, (u) >> 16 & 0xffu, (u) >> 8 & 0xffu, (u) & 0xffu }, .vlen = 4 }
#define RECU64(k, u) { .key = (k), .value = (char const [8]){ (u) >> 56 & 0xffu, (u) >> 48 & 0xffu, (u) >> 40 & 0xffu, (u) >> 32 & 0xffu, (u) >> 24 & 0xffu, (u) >> 16 & 0xffu, (u) >> 8 & 0xffu, (u) & 0xffu }, .vlen = 8 }
static struct defaults_s const defaults[] =
{
- RECU32("G:logv", 1),
- REC("G:listen4", "\177\0\0\1", 4),
- REC("G:listen6", "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1", 16),
- RECU32("G:maxtcp", 256),
- RECU32("G:maxqueries", 1024),
+ RECU16("G:logv", 1),
RECU64("G:cachesize", 1048576),
+ RECU16("G:maxtcp", 64),
+ RECU16("G:maxqueries", 256),
RECU32("G:rtimeout", 0),
RECU32("G:wtimeout", 0),
+ REC("G:listen4", "\177\0\0\1", 4),
+ REC("G:listen6", "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1", 16),
REC("R4:",
"\0\306\51\0\4"
diff --git a/src/config/lexparse.c b/src/config/lexparse.c
index 093acf7..7884fee 100644
--- a/src/config/lexparse.c
+++ b/src/config/lexparse.c
@@ -106,6 +106,16 @@ static int ipcmp (void const *a, void const *b, size_t n)
}
+static void parse_u16 (char const *s, size_t const *word, size_t n, char const *ifile, uint32_t line, char const *directive, char const *key)
+{
+ uint16_t u ;
+ char pack[2] ;
+ if (n != 1) dieparse(ifile, line, directive, n ? "too many arguments" : "too few arguments", 0, 0, 0) ;
+ if (!uint160_scan(s + word[0], &u)) dieparse(ifile, line, directive, "argument must be an integer", 0, 0, 0) ;
+ uint16_pack_big(pack, u) ;
+ adds_unique(ifile, line, directive, key, pack, 2) ;
+}
+
static void parse_u32 (char const *s, size_t const *word, size_t n, char const *ifile, uint32_t line, char const *directive, char const *key)
{
uint32_t u ;
@@ -225,16 +235,16 @@ static inline void process_line (char const *s, size_t const *word, size_t n, ch
switch (directive->value)
{
case T_VERBOSITY :
- parse_u32(s, word, n, ifile, line, "verbosity", "G:logv") ;
+ parse_u16(s, word, n, ifile, line, "verbosity", "G:logv") ;
break ;
case T_CACHESIZE :
parse_u64(s, word, n, ifile, line, "cache_size", "G:cachesize") ;
break ;
case T_MAXTCP :
- parse_u32(s, word, n, ifile, line, "maxtcp", "G:maxtcp") ;
+ parse_u16(s, word, n, ifile, line, "maxtcp", "G:maxtcp") ;
break ;
case T_MAXQUERIES :
- parse_u32(s, word, n, ifile, line, "maxqueries", "G:maxqueries") ;
+ parse_u16(s, word, n, ifile, line, "maxqueries", "G:maxqueries") ;
break ;
case T_RTIMEOUT :
parse_u32(s, word, n, ifile, line, "read_timeout", "G:rtimeout") ;
diff --git a/src/include/shibari/cache.h b/src/include/shibari/cache.h
deleted file mode 100644
index d0c6004..0000000
--- a/src/include/shibari/cache.h
+++ /dev/null
@@ -1,8 +0,0 @@
-/* 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
deleted file mode 100644
index 03f8b1b..0000000
--- a/src/include/shibari/client.h
+++ /dev/null
@@ -1,6 +0,0 @@
-/* ISC license. */
-
-#ifndef SHIBARI_CLIENT_H
-#define SHIBARI_CLIENT_H
-
-#endif
diff --git a/src/include/shibari/shibari.h b/src/include/shibari/shibari.h
index a9242d3..123c13f 100644
--- a/src/include/shibari/shibari.h
+++ b/src/include/shibari/shibari.h
@@ -4,8 +4,6 @@
#define SHIBARI_H
#include <shibari/common.h>
-#include <shibari/client.h>
-#include <shibari/cache.h>
#include <shibari/server.h>
#endif