summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2024-04-27 12:48:31 +0000
committerLaurent Bercot <ska@appnovation.com>2024-04-27 12:48:31 +0000
commit33e4b9d9137b5dbb02a087956f1558ef30647aea (patch)
treebb9578695eabce49207ad2d4aa3593e950778e25 /src
parent51196c1512f071bec38064f8add058f52542976b (diff)
downloads6-dns-33e4b9d9137b5dbb02a087956f1558ef30647aea.tar.xz
Prepare for 2.3.7.2; implement dns-0x20
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r--src/clients/s6dns_generic_filter_main.c1
-rw-r--r--src/include/s6-dns/skadns.h1
-rw-r--r--src/libs6dns/s6dns_domain_decode.c2
-rw-r--r--src/libs6dns/s6dns_domain_fromstring.c6
-rw-r--r--src/libs6dns/s6dns_domain_tostring.c4
-rw-r--r--src/libs6dns/s6dns_fmt_domainlist.c1
-rw-r--r--src/skadns/skadnsd.c125
7 files changed, 72 insertions, 68 deletions
diff --git a/src/clients/s6dns_generic_filter_main.c b/src/clients/s6dns_generic_filter_main.c
index 4c58aae..81de9e3 100644
--- a/src/clients/s6dns_generic_filter_main.c
+++ b/src/clients/s6dns_generic_filter_main.c
@@ -77,7 +77,6 @@ int s6dns_generic_filter_main (int argc, char const *const *argv, char const *co
}
if (!flag4 && !flag6) flag4 = 1 ;
if (maxconn < 1) maxconn = 1 ;
- if (maxconn > SKADNS_MAXCONCURRENCY) maxconn = SKADNS_MAXCONCURRENCY ;
if (maxlines < maxconn) maxlines = maxconn ;
tain_now_set_stopwatch_g() ;
diff --git a/src/include/s6-dns/skadns.h b/src/include/s6-dns/skadns.h
index 32e3648..b1f91bc 100644
--- a/src/include/s6-dns/skadns.h
+++ b/src/include/s6-dns/skadns.h
@@ -19,7 +19,6 @@
#define SKADNS_BANNER1_LEN (sizeof SKADNS_BANNER1 - 1)
#define SKADNS_BANNER2 "skadns v1.0 (a)\n"
#define SKADNS_BANNER2_LEN (sizeof SKADNS_BANNER2 - 1)
-#define SKADNS_MAXCONCURRENCY 1000
typedef struct skadnsanswer_s skadnsanswer_t, *skadnsanswer_t_ref ;
struct skadnsanswer_s
diff --git a/src/libs6dns/s6dns_domain_decode.c b/src/libs6dns/s6dns_domain_decode.c
index 6fea0d6..e5fab0a 100644
--- a/src/libs6dns/s6dns_domain_decode.c
+++ b/src/libs6dns/s6dns_domain_decode.c
@@ -3,7 +3,6 @@
#include <errno.h>
#include <skalibs/posixishard.h>
-#include <skalibs/bytestr.h>
#include <s6-dns/s6dns-domain.h>
@@ -12,7 +11,6 @@ static inline unsigned int s6dns_domain_label_decode (char *s, unsigned int max)
unsigned int len = *(unsigned char *)s ;
if ((len > 63) || (len >= max)) return (errno = EPROTO, 0) ;
*s = '.' ;
- case_lowerb(s+1, len) ;
return len + 1 ;
}
diff --git a/src/libs6dns/s6dns_domain_fromstring.c b/src/libs6dns/s6dns_domain_fromstring.c
index b87ee10..c8e553b 100644
--- a/src/libs6dns/s6dns_domain_fromstring.c
+++ b/src/libs6dns/s6dns_domain_fromstring.c
@@ -2,7 +2,8 @@
#include <string.h>
#include <errno.h>
-#include <skalibs/bytestr.h>
+#include <ctype.h>
+
#include <s6-dns/s6dns-domain.h>
int s6dns_domain_fromstring (s6dns_domain_t *d, char const *s, size_t len)
@@ -16,7 +17,7 @@ int s6dns_domain_fromstring (s6dns_domain_t *d, char const *s, size_t len)
if (lastdot)
{
if ((j >= 255) || (lastdot++ >= 64)) return (errno = ENAMETOOLONG, 0) ;
- d->s[j++] = s[i] ;
+ d->s[j++] = tolower(s[i]) ;
}
if (s[i] == '.') lastdot = 0 ;
else if (!lastdot)
@@ -25,7 +26,6 @@ int s6dns_domain_fromstring (s6dns_domain_t *d, char const *s, size_t len)
lastdot = 1 ;
}
}
- case_lowerb(d->s + 1, j-1) ;
d->len = j ;
return 1 ;
}
diff --git a/src/libs6dns/s6dns_domain_tostring.c b/src/libs6dns/s6dns_domain_tostring.c
index 2c1cf01..cd60f66 100644
--- a/src/libs6dns/s6dns_domain_tostring.c
+++ b/src/libs6dns/s6dns_domain_tostring.c
@@ -2,6 +2,9 @@
#include <string.h>
#include <errno.h>
+
+#include <skalibs/bytestr.h>
+
#include <s6-dns/s6dns-domain.h>
unsigned int s6dns_domain_tostring (char *s, size_t max, s6dns_domain_t const *d)
@@ -18,6 +21,7 @@ unsigned int s6dns_domain_tostring (char *s, size_t max, s6dns_domain_t const *d
{
memcpy(s, d->s + 1, d->len - 1) ;
s[d->len - 1] = 0 ;
+ case_lowerb(s, d->len - 1) ;
return d->len - 1 ;
}
}
diff --git a/src/libs6dns/s6dns_fmt_domainlist.c b/src/libs6dns/s6dns_fmt_domainlist.c
index 22d6f77..837ee97 100644
--- a/src/libs6dns/s6dns_fmt_domainlist.c
+++ b/src/libs6dns/s6dns_fmt_domainlist.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <errno.h>
+
#include <s6-dns/s6dns-domain.h>
#include <s6-dns/s6dns-fmt.h>
diff --git a/src/skadns/skadnsd.c b/src/skadns/skadnsd.c
index 0909dfa..6e241c8 100644
--- a/src/skadns/skadnsd.c
+++ b/src/skadns/skadnsd.c
@@ -9,6 +9,7 @@
#include <skalibs/types.h>
#include <skalibs/error.h>
#include <skalibs/strerr.h>
+#include <skalibs/genalloc.h>
#include <skalibs/sig.h>
#include <skalibs/tai.h>
#include <skalibs/djbunix.h>
@@ -22,29 +23,34 @@
typedef struct dnsio_s dnsio, *dnsio_ref ;
struct dnsio_s
{
- unsigned int xindex ;
+ size_t xindex ;
s6dns_engine_t dt ;
uint16_t id ;
} ;
-#define DNSIO_ZERO { .xindex = SKADNS_MAXCONCURRENCY, .dt = S6DNS_ENGINE_ZERO, .id = 0 }
+#define DNSIO_ZERO { .xindex = 0, .dt = S6DNS_ENGINE_ZERO, .id = 0 }
-static dnsio a[SKADNS_MAXCONCURRENCY] ;
-static unsigned int sp = 0 ;
+static genalloc g = GENALLOC_ZERO ; /* dnsio */
-static void remove (unsigned int i)
+static inline void dnsio_free (dnsio *p)
{
- dnsio tmp ;
- tmp = a[sp-1] ;
- a[--sp] = a[i] ;
- a[i] = tmp ;
+ s6dns_engine_free(&p->dt) ;
}
-static void fail (unsigned int i)
+static void remove (size_t i)
{
+ size_t n = genalloc_len(dnsio, &g) ;
+ dnsio *a = genalloc_s(dnsio, &g) ;
+ dnsio_free(a + i) ;
+ if (--n) a[i] = a[n] ;
+ genalloc_setlen(dnsio, &g, n) ;
+}
+
+static void fail (size_t i)
+{
+ dnsio *p = genalloc_s(dnsio, &g) + i ;
char pack[3] ;
- uint16_pack_big(pack, a[i].id) ;
- pack[2] = a[i].dt.status ;
- s6dns_engine_recycle(&a[i].dt) ;
+ uint16_pack_big(pack, p->id) ;
+ pack[2] = p->dt.status ;
remove(i) ;
if (!textmessage_put(textmessage_sender_x, pack, 3))
strerr_diefu1sys(111, "textmessage_put") ;
@@ -66,37 +72,44 @@ static int parse_protocol (struct iovec const *v, void *context)
{
case 'Q' : /* send a query */
{
+ dnsio *p ;
+ size_t n = genalloc_len(dnsio, &g) ;
tain limit ;
uint16_t qtype ;
- if (v->iov_len < 21) strerr_dief1x(100, "invalid client request") ;
- if (sp >= SKADNS_MAXCONCURRENCY)
+ if (v->iov_len < 21)
+ strerr_dief1x(100, "invalid client request") ;
+ if (!genalloc_readyplus(dnsio, &g, 1))
{
- answer(ENFILE) ;
+ answer(ENOMEM) ;
break ;
}
+ p = genalloc_s(dnsio, &g) + n ;
+ p->dt = s6dns_engine_zero ;
uint16_unpack_big(s + 3, &qtype) ;
if (memcmp(s + 5, "\0\0\0\0\0\0\0\0\0\0\0", 12))
tain_unpack(s + 5, &limit) ;
else tain_add_g(&limit, &tain_infinite_relative) ;
- if (!s6dns_engine_init_g(&a[sp].dt, &s6dns_rci_here.servers, 1, s + 17, v->iov_len - 17, qtype, &limit))
+ if (!s6dns_engine_init_g(&p->dt, &s6dns_rci_here.servers, 1, s + 17, v->iov_len - 17, qtype, &limit))
{
answer(errno) ;
break ;
}
- a[sp++].id = id ;
+ p->id = id ;
+ genalloc_setlen(dnsio, &g, n+1) ;
answer(0) ;
break ;
}
case 'q' : /* cancel a query */
{
- unsigned int i = 0 ;
- for (; i < sp ; i++) if (a[i].id == id) break ;
- if (i >= sp)
+ dnsio *a = genalloc_s(dnsio, &g) ;
+ size_t n = genalloc_len(dnsio, &g) ;
+ size_t i = 0 ;
+ for (; i < n ; i++) if (a[i].id == id) break ;
+ if (i >= n)
{
answer(ENOENT) ;
break ;
}
- s6dns_engine_recycle(&a[i].dt) ;
remove(i) ;
answer(0) ;
break ;
@@ -111,9 +124,10 @@ int main (void)
{
PROG = "skadnsd" ;
- if (ndelay_on(0) < 0) strerr_diefu2sys(111, "ndelay_on ", "0") ;
- if (ndelay_on(1) < 0) strerr_diefu2sys(111, "ndelay_on ", "1") ;
- if (!sig_ignore(SIGPIPE)) strerr_diefu1sys(111, "ignore SIGPIPE") ;
+ if (ndelay_on(0) == -1 || ndelay_on(1) == -1)
+ strerr_diefu1sys(111, "set fds nonblocking") ;
+ if (!sig_altignore(SIGPIPE))
+ strerr_diefu1sys(111, "ignore SIGPIPE") ;
tain_now_set_stopwatch_g() ;
if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
@@ -125,41 +139,34 @@ int main (void)
if (!textclient_server_01x_init_g(SKADNS_BANNER1, SKADNS_BANNER1_LEN, SKADNS_BANNER2, SKADNS_BANNER2_LEN, &deadline))
strerr_diefu1sys(111, "sync with client") ;
}
- {
- static dnsio const zero = DNSIO_ZERO ;
- unsigned int i = 0 ;
- for (; i < SKADNS_MAXCONCURRENCY ; i++) a[i] = zero ;
- }
for (;;)
{
- iopause_fd x[3 + sp] ;
+ tain deadline = TAIN_INFINITE ;
+ size_t n = genalloc_len(dnsio, &g) ;
+ dnsio *a = genalloc_s(dnsio, &g) ;
+ iopause_fd x[3 + n] ;
int r ;
x[0].fd = 0 ; x[0].events = IOPAUSE_EXCEPT | IOPAUSE_READ ;
x[1].fd = 1 ; x[1].events = IOPAUSE_EXCEPT | (textmessage_sender_isempty(textmessage_sender_1) ? 0 : IOPAUSE_WRITE) ;
x[2].fd = textmessage_sender_fd(textmessage_sender_x) ;
x[2].events = IOPAUSE_EXCEPT | (textmessage_sender_isempty(textmessage_sender_x) ? 0 : IOPAUSE_WRITE) ;
+ for (size_t i = 0 ; i < n ; i++)
{
- tain deadline = TAIN_INFINITE ;
- unsigned int i = 0 ;
- for (; i < sp ; i++)
- {
- unsigned int j = 3 + i ;
- s6dns_engine_nextdeadline(&a[i].dt, &deadline) ;
- x[j].fd = a[i].dt.fd ;
- x[j].events = 0 ;
- if (s6dns_engine_isreadable(&a[i].dt)) x[j].events |= IOPAUSE_READ ;
- if (s6dns_engine_iswritable(&a[i].dt)) x[j].events |= IOPAUSE_WRITE ;
- a[i].xindex = j ;
- }
- r = iopause_g(x, 3 + sp, &deadline) ;
+ size_t j = 3 + i ;
+ s6dns_engine_nextdeadline(&a[i].dt, &deadline) ;
+ x[j].fd = a[i].dt.fd ;
+ x[j].events = 0 ;
+ if (s6dns_engine_isreadable(&a[i].dt)) x[j].events |= IOPAUSE_READ ;
+ if (s6dns_engine_iswritable(&a[i].dt)) x[j].events |= IOPAUSE_WRITE ;
+ a[i].xindex = j ;
}
+ r = iopause_g(x, 3 + n, &deadline) ;
if (r < 0) strerr_diefu1sys(111, "iopause") ;
if (!r)
{
- unsigned int i = 0 ;
- for (; i < sp ; i++)
+ for (size_t i = 0 ; i < genalloc_len(dnsio, &g) ; i++)
if (s6dns_engine_timeout_g(&a[i].dt)) fail(i--) ;
continue ;
}
@@ -171,23 +178,19 @@ int main (void)
if (!textmessage_sender_flush(textmessage_sender_x) && !error_isagain(errno))
strerr_diefu1sys(111, "flush asyncout") ;
+ for (size_t i = 0 ; i < genalloc_len(dnsio, &g) ; i++) if (x[a[i].xindex].revents)
{
- unsigned int i = 0 ;
- for (; i < sp ; i++) if (x[a[i].xindex].revents)
+ int r = s6dns_engine_event_g(&a[i].dt) ;
+ if (r < 0) fail(i--) ;
+ else if (r)
{
- int r = s6dns_engine_event_g(&a[i].dt) ;
- if (r < 0) fail(i--) ;
- else if (r)
- {
- char pack[3] ;
- struct iovec v[2] = { { .iov_base = pack, .iov_len = 3 }, { .iov_base = s6dns_engine_packet(&a[i].dt), .iov_len = s6dns_engine_packetlen(&a[i].dt) } } ;
- uint16_pack_big(pack, a[i].id) ;
- pack[2] = 0 ;
- if (!textmessage_putv(textmessage_sender_x, v, 2))
- strerr_diefu1sys(111, "textmessage_put") ;
- s6dns_engine_recycle(&a[i].dt) ;
- remove(i--) ;
- }
+ char pack[3] ;
+ struct iovec v[2] = { { .iov_base = pack, .iov_len = 3 }, { .iov_base = s6dns_engine_packet(&a[i].dt), .iov_len = s6dns_engine_packetlen(&a[i].dt) } } ;
+ uint16_pack_big(pack, a[i].id) ;
+ pack[2] = 0 ;
+ if (!textmessage_putv(textmessage_sender_x, v, 2))
+ strerr_diefu1sys(111, "textmessage_put") ;
+ remove(i--) ;
}
}