summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-05-17 18:07:58 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-05-17 18:07:58 +0000
commit91e808f1db0b76f3625f516ec73a95b4e32decb2 (patch)
treecacbb0f21daa96bffa4a74c8395c82983b185be5 /src
parent8e3663ba249b572af9332f2762f29ba514620a27 (diff)
downloads6-dns-91e808f1db0b76f3625f516ec73a95b4e32decb2.tar.xz
Add s6-dnsip, prepare for 2.3.3.0, fix resolvenoq_aaaaa
TODO: resolveq_aaaaa returns the best (1 answer) whereas we want both ip6 and ip4 when available. It works with noq, it should work with q too.
Diffstat (limited to 'src')
-rw-r--r--src/clients/deps-exe/s6-dnsip4
-rw-r--r--src/clients/s6-dnsip.c67
-rw-r--r--src/include/s6-dns/s6dns-resolve.h2
-rw-r--r--src/libs6dns/s6dns_resolvenoq_aaaaa.c12
-rw-r--r--src/libs6dns/s6dns_resolveq_aaaaa.c12
5 files changed, 87 insertions, 10 deletions
diff --git a/src/clients/deps-exe/s6-dnsip b/src/clients/deps-exe/s6-dnsip
new file mode 100644
index 0000000..9bc872f
--- /dev/null
+++ b/src/clients/deps-exe/s6-dnsip
@@ -0,0 +1,4 @@
+${LIBS6DNS}
+-lskarnet
+${SOCKET_LIB}
+${SYSCLOCK_LIB}
diff --git a/src/clients/s6-dnsip.c b/src/clients/s6-dnsip.c
new file mode 100644
index 0000000..f4c1a58
--- /dev/null
+++ b/src/clients/s6-dnsip.c
@@ -0,0 +1,67 @@
+/* ISC license. */
+
+#include <string.h>
+#include <errno.h>
+
+#include <skalibs/types.h>
+#include <skalibs/sgetopt.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/ip46.h>
+#include <skalibs/genalloc.h>
+#include <skalibs/buffer.h>
+#include <skalibs/tai.h>
+#include <skalibs/random.h>
+#include <s6-dns/s6dns.h>
+
+#define USAGE "s6-dnsip [ -q ] [ -r ] [ -t timeout ] domain"
+#define dieusage() strerr_dieusage(100, USAGE)
+
+int main (int argc, char const *const *argv)
+{
+ genalloc ips = GENALLOC_ZERO ; /* ip46full_t */
+ tain_t deadline ;
+ size_t i = 0 ;
+ unsigned int t = 0 ;
+ int flagqualify = 0 ;
+ int flagunsort = 0 ;
+ PROG = "s6-dnsip" ;
+
+ for (;;)
+ {
+ int opt = subgetopt(argc, argv, "qrt:") ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 'q' : flagqualify = 1 ; break ;
+ case 'r' : flagunsort = 1 ; break ;
+ case 't' : if (!uint0_scan(subgetopt_here.arg, &t)) dieusage() ; break ;
+ default : dieusage() ;
+ }
+ }
+ argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ;
+ if (argc < 1) dieusage() ;
+
+ tain_now_set_stopwatch_g() ;
+ if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ;
+ tain_add_g(&deadline, &deadline) ;
+ if (!s6dns_init()) strerr_diefu1sys(111, "s6dns_init") ;
+ {
+ int r = s6dns_resolve_aaaaa_g(&ips, argv[0], strlen(argv[0]), flagqualify, &deadline) ;
+ if (r < 0) strerr_diefu2sys((errno == ETIMEDOUT) ? 99 : 111, "resolve ", argv[0]) ;
+ if (!r) strerr_diefu4x(2, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ;
+ }
+ if (!genalloc_len(ip46full_t, &ips)) return 1 ;
+
+ if (flagunsort) random_unsort(ips.s, genalloc_len(ip46full_t, &ips), sizeof(ip46full_t)) ;
+ for (i = 0 ; i < genalloc_len(ip46full_t, &ips) ; i++)
+ {
+ char fmt[IP6_FMT] ;
+ size_t n = ip46full_fmt(fmt, genalloc_s(ip46full_t, &ips) + i) ;
+ fmt[n++] = '\n' ;
+ if (buffer_put(buffer_1small, fmt, n) < (ssize_t)n)
+ strerr_diefu1sys(111, "write to stdout") ;
+ }
+ if (!buffer_flush(buffer_1small))
+ strerr_diefu1sys(111, "write to stdout") ;
+ return 0 ;
+}
diff --git a/src/include/s6-dns/s6dns-resolve.h b/src/include/s6-dns/s6dns-resolve.h
index a571103..7369ffd 100644
--- a/src/include/s6-dns/s6dns-resolve.h
+++ b/src/include/s6-dns/s6dns-resolve.h
@@ -155,7 +155,7 @@ extern int s6dns_resolve_name6_r (genalloc *, char const *, s6dns_engine_t *, s6
#define s6dns_resolve_name46(ds, i, deadline, stamp) s6dns_resolve_name46_r(ds, i, &s6dns_engine_here, &s6dns_rci_here.servers, &s6dns_debughook_zero, deadline, stamp)
#define s6dns_resolve_name46_g(ds, i, deadline) s6dns_resolve_name46(ds, i, (deadline), &STAMP)
-#define s6dns_resolve_name46_r(ds, i, dt, servers, dbh, deadline, stamp) (ip46_is6(i) ? s6dns_resolve_name6_r(ds, (i)->ip, dt, servers, dbh, deadline, stamp) : s6dns_resolve_name4_r(ds, (i)->ip, dt, servers, dbh, deadline, stamp))
+#define s6dns_resolve_name46_r(ds, i, dt, servers, dbh, deadline, stamp) (ip46full_is6(i) ? s6dns_resolve_name6_r(ds, (i)->ip, dt, servers, dbh, deadline, stamp) : s6dns_resolve_name4_r(ds, (i)->ip, dt, servers, dbh, deadline, stamp))
#define s6dns_resolve_name46_r_g(ds, i, dt, servers, dbh, deadline) s6dns_resolve_name46_r(ds, i, dt, servers, dbh, (deadline), &STAMP)
#define s6dns_resolve_txt(sa, offsets, name, len, qualif, deadline, stamp) s6dns_resolve_txt_r(sa, offsets, name, len, qualif, &s6dns_engine_here, &s6dns_rci_here, &s6dns_debughook_zero, deadline, stamp)
diff --git a/src/libs6dns/s6dns_resolvenoq_aaaaa.c b/src/libs6dns/s6dns_resolvenoq_aaaaa.c
index 734d048..7012594 100644
--- a/src/libs6dns/s6dns_resolvenoq_aaaaa.c
+++ b/src/libs6dns/s6dns_resolvenoq_aaaaa.c
@@ -26,7 +26,7 @@ int s6dns_resolvenoq_aaaaa_r (genalloc *ips, char const *name, size_t len, s6dns
blob[1].data = &sa[1] ;
if (!s6dns_resolven_parse_r(blob, 2, servers, dbh, deadline, stamp)) return -1 ;
if (blob[0].status && blob[1].status) return (errno = blob[1].status, 0) ;
- if (!genalloc_readyplus(ip46_t, ips, (sa[0].len >> 4) + (sa[1].len >> 2)))
+ if (!genalloc_readyplus(ip46full_t, ips, (sa[0].len >> 4) + (sa[1].len >> 2)))
{
stralloc_free(&sa[0]) ;
stralloc_free(&sa[1]) ;
@@ -34,13 +34,15 @@ int s6dns_resolvenoq_aaaaa_r (genalloc *ips, char const *name, size_t len, s6dns
}
{
int e = (!!sa[0].len << 1) | !!sa[1].len ;
- size_t n = genalloc_len(ip46_t, ips) ;
+ size_t n = genalloc_len(ip46full_t, ips) ;
size_t i = 0 ;
for (; i < (sa[0].len >> 4) ; i++)
- ip46_from_ip6(genalloc_s(ip46_t, ips) + n++, sa[0].s + (i << 4)) ;
+ ip46full_from_ip6(genalloc_s(ip46full_t, ips) + n + i, sa[0].s + (i << 4)) ;
+ n += i ;
for (i = 0 ; i < (sa[1].len >> 2) ; i++)
- ip46_from_ip4(genalloc_s(ip46_t, ips) + n++, sa[1].s + (i << 2)) ;
- genalloc_setlen(ip46_t, ips, n) ;
+ ip46full_from_ip4(genalloc_s(ip46full_t, ips) + n + i, sa[1].s + (i << 2)) ;
+ n += i ;
+ genalloc_setlen(ip46full_t, ips, n) ;
stralloc_free(&sa[0]) ;
stralloc_free(&sa[1]) ;
return e ;
diff --git a/src/libs6dns/s6dns_resolveq_aaaaa.c b/src/libs6dns/s6dns_resolveq_aaaaa.c
index 5a0a358..f990a7c 100644
--- a/src/libs6dns/s6dns_resolveq_aaaaa.c
+++ b/src/libs6dns/s6dns_resolveq_aaaaa.c
@@ -1,16 +1,20 @@
/* ISC license. */
#include <errno.h>
+
#include <skalibs/error.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
#include <skalibs/ip46.h>
+
#include <s6-dns/s6dns-constants.h>
#include <s6-dns/s6dns-domain.h>
#include <s6-dns/s6dns-message.h>
#include <s6-dns/s6dns-engine.h>
#include <s6-dns/s6dns-resolve.h>
+#define d_ip46full_from_ip(i, s, h) ((h) ? ip46full_from_ip6(i, s) : ip46full_from_ip4(i, s))
+
int s6dns_resolveq_aaaaa_r (genalloc *ips, char const *name, size_t len, s6dns_rci_t const *rci, s6dns_debughook_t const *dbh, tain_t const *deadline, tain_t *stamp)
{
s6dns_engine_t dtl[rci->rulesnum << 1] ;
@@ -75,11 +79,11 @@ int s6dns_resolveq_aaaaa_r (genalloc *ips, char const *name, size_t len, s6dns_r
{
size_t len = data.len >> ((best & 1) ? 2 : 4) ;
size_t i = 0 ;
- size_t base = genalloc_len(ip46_t, ips) ;
- if (!genalloc_readyplus(ip46_t, ips, len)) return -1 ;
+ size_t base = genalloc_len(ip46full_t, ips) ;
+ if (!genalloc_readyplus(ip46full_t, ips, len)) return -1 ;
for (; i < len ; i++)
- ip46_from_ip(genalloc_s(ip46_t, ips) + base + i, data.s + (i << ((best & 1) ? 2 : 4)), !(best & 1)) ;
- genalloc_setlen(ip46_t, ips, base + len) ;
+ d_ip46full_from_ip(genalloc_s(ip46full_t, ips) + base + i, data.s + (i << ((best & 1) ? 2 : 4)), !(best & 1)) ;
+ genalloc_setlen(ip46full_t, ips, base + len) ;
}
stralloc_free(&data) ;
return 1 ;