summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-11-17 20:23:56 +0000
committerLaurent Bercot <ska@appnovation.com>2023-11-17 20:23:56 +0000
commitd06529686f89074fd4fa574ac6012f8a873e7857 (patch)
treee2fd4e499d8a633feeff288a9d42e904abca8903 /src
parent9d432bd8a07dd36247339c40fa6bf2719600fdb2 (diff)
downloads6-dns-d06529686f89074fd4fa574ac6012f8a873e7857.tar.xz
Prepare for 2.3.7.0; ignore link-local addresses in /etc/hosts
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r--src/clients/s6-dnsip.c13
-rw-r--r--src/clients/s6-dnsip4.c13
-rw-r--r--src/clients/s6-dnsip6.c13
-rw-r--r--src/clients/s6-dnsname.c9
-rw-r--r--src/include/s6-dns/s6dns.h5
-rw-r--r--src/libs6dns/s6dns_hosts_compile.c26
-rw-r--r--src/libs6dns/s6dns_hosts_compile.txt18
-rw-r--r--src/libs6dns/s6dns_init.c4
8 files changed, 43 insertions, 58 deletions
diff --git a/src/clients/s6-dnsip.c b/src/clients/s6-dnsip.c
index 68ce62b..b0d724c 100644
--- a/src/clients/s6-dnsip.c
+++ b/src/clients/s6-dnsip.c
@@ -12,9 +12,7 @@
#include <skalibs/tai.h>
#include <skalibs/random.h>
-#include <s6-dns/s6dns-rci.h>
-#include <s6-dns/hosts.h>
-#include <s6-dns/s6dns-resolve.h>
+#include <s6-dns/s6dns.h>
#define USAGE "s6-dnsip [ -q ] [ -H | -h ] [ -r ] [ -t timeout ] domain"
#define dieusage() strerr_dieusage(100, USAGE)
@@ -54,13 +52,8 @@ int main (int argc, char const *const *argv)
if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ;
tain_add_g(&deadline, &deadline) ;
- if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
- strerr_diefu1sys(111, "initialize structures from /etc/resolv.conf") ;
- if (flaghosts)
- {
- flaghosts = s6dns_hosts_init(&s6dns_hosts_here, "/etc/hosts", "/etc/hosts.cdb", "/tmp/hosts.cdb") ;
- if (flaghosts == -1) strerr_diefu1sys(111, "initialize hosts database from /etc/hosts or /etc/hosts.cdb") ;
- }
+ if (!s6dns_init_options(flaghosts))
+ strerr_diefu1sys(111, "parse /etc/resolv.conf or /etc/hosts") ;
if (flaghosts)
{
diff --git a/src/clients/s6-dnsip4.c b/src/clients/s6-dnsip4.c
index 370c006..6112e14 100644
--- a/src/clients/s6-dnsip4.c
+++ b/src/clients/s6-dnsip4.c
@@ -11,9 +11,7 @@
#include <skalibs/tai.h>
#include <skalibs/random.h>
-#include <s6-dns/s6dns-rci.h>
-#include <s6-dns/hosts.h>
-#include <s6-dns/s6dns-resolve.h>
+#include <s6-dns/s6dns.h>
#define USAGE "s6-dnsip4 [ -q ] [ -H | -h ] [ -r ] [ -t timeout ] domain"
#define dieusage() strerr_dieusage(100, USAGE)
@@ -53,13 +51,8 @@ int main (int argc, char const *const *argv)
if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ;
tain_add_g(&deadline, &deadline) ;
- if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
- strerr_diefu1sys(111, "initialize structures from /etc/resolv.conf") ;
- if (flaghosts)
- {
- flaghosts = s6dns_hosts_init(&s6dns_hosts_here, "/etc/hosts", "/etc/hosts.cdb", "/tmp/hosts.cdb") ;
- if (flaghosts == -1) strerr_diefu1sys(111, "initialize hosts database from /etc/hosts or /etc/hosts.cdb") ;
- }
+ if (!s6dns_init_options(flaghosts))
+ strerr_diefu1sys(111, "parse from /etc/resolv.conf or /etc/hosts") ;
if (flaghosts)
{
diff --git a/src/clients/s6-dnsip6.c b/src/clients/s6-dnsip6.c
index 2fb2f6f..2a7ce8b 100644
--- a/src/clients/s6-dnsip6.c
+++ b/src/clients/s6-dnsip6.c
@@ -11,9 +11,7 @@
#include <skalibs/tai.h>
#include <skalibs/random.h>
-#include <s6-dns/s6dns-rci.h>
-#include <s6-dns/hosts.h>
-#include <s6-dns/s6dns-resolve.h>
+#include <s6-dns/s6dns.h>
#define USAGE "s6-dnsip6 [ -q ] [ -H | -h ] [ -r ] [ -t timeout ] domain"
#define dieusage() strerr_dieusage(100, USAGE)
@@ -53,13 +51,8 @@ int main (int argc, char const *const *argv)
if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ;
tain_add_g(&deadline, &deadline) ;
- if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
- strerr_diefu1sys(111, "initialize structures from /etc/resolv.conf") ;
- if (flaghosts)
- {
- flaghosts = s6dns_hosts_init(&s6dns_hosts_here, "/etc/hosts", "/etc/hosts.cdb", "/tmp/hosts.cdb") ;
- if (flaghosts == -1) strerr_diefu1sys(111, "initialize hosts database from /etc/hosts or /etc/hosts.cdb") ;
- }
+ if (!s6dns_init_options(flaghosts))
+ strerr_diefu1sys(111, "parse /etc/resolv.conf or /etc/hosts") ;
if (flaghosts)
{
diff --git a/src/clients/s6-dnsname.c b/src/clients/s6-dnsname.c
index 7c35f06..6531534 100644
--- a/src/clients/s6-dnsname.c
+++ b/src/clients/s6-dnsname.c
@@ -67,13 +67,8 @@ int main (int argc, char const *const *argv)
if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ;
tain_add_g(&deadline, &deadline) ;
- if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
- strerr_diefu1sys(111, "initialize structures from /etc/resolv.conf") ;
- if (flaghosts)
- {
- flaghosts = s6dns_hosts_init(&s6dns_hosts_here, "/etc/hosts", "/etc/hosts.cdb", "/tmp/hosts.cdb") ;
- if (flaghosts == -1) strerr_diefu1sys(111, "initialize hosts database from /etc/hosts or /etc/hosts.cdb") ;
- }
+ if (!s6dns_init_options(flaghosts))
+ strerr_diefu1sys(111, "parse /etc/resolv.conf or /etc/hosts") ;
if (flaghosts)
{
diff --git a/src/include/s6-dns/s6dns.h b/src/include/s6-dns/s6dns.h
index de8c085..e19ae8d 100644
--- a/src/include/s6-dns/s6dns.h
+++ b/src/include/s6-dns/s6dns.h
@@ -3,6 +3,8 @@
#ifndef S6DNS_H
#define S6DNS_H
+#include <stdint.h>
+
#include <s6-dns/s6dns-constants.h>
#include <s6-dns/s6dns-ip46.h>
#include <s6-dns/s6dns-domain.h>
@@ -13,7 +15,8 @@
#include <s6-dns/s6dns-fmt.h>
#include <s6-dns/hosts.h>
-extern int s6dns_init (void) ;
+#define s6dns_init() s6dns_init_options(0)
+extern int s6dns_init_options (uint32_t) ;
extern void s6dns_finish (void) ;
#endif
diff --git a/src/libs6dns/s6dns_hosts_compile.c b/src/libs6dns/s6dns_hosts_compile.c
index b57ffd3..0d537d7 100644
--- a/src/libs6dns/s6dns_hosts_compile.c
+++ b/src/libs6dns/s6dns_hosts_compile.c
@@ -144,20 +144,20 @@ static void *byipv6_dtok (uint32_t d, void *aux)
static inline uint8_t cclass (char c)
{
- static uint8_t const ctable[128] = "09999999913111999999999999999999199299999999945977777777776999999888888888888888888888888889999898888888888888888888888888899999" ;
+ static uint8_t const ctable[128] = "0999999991311199999999999999999919929:999999945977777777776999999888888888888888888888888889999898888888888888888888888888899999" ;
return c & 0x80 ? 9 : ctable[(uint8_t)c] - '0' ;
}
static int s6dns_hosts_parse (buffer *b, hostdata *hd)
{
- static uint8_t const table[6][10] =
+ static uint8_t const table[6][11] =
{
- { 0x0a, 0x00, 0x01, 0x00, 0x0b, 0x0b, 0x12, 0x12, 0x12, 0x0b },
- { 0x0a, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
- { 0x2a, 0x23, 0x0b, 0x20, 0x0b, 0x12, 0x12, 0x12, 0x12, 0x0b },
- { 0x0a, 0x03, 0x01, 0x00, 0x0b, 0x0b, 0x0b, 0x0b, 0x14, 0x0b },
- { 0x4a, 0xc4, 0x0b, 0x40, 0x14, 0x14, 0x0b, 0x14, 0x14, 0x0b },
- { 0x0a, 0x05, 0x01, 0x00, 0x0b, 0x0b, 0x0b, 0x0b, 0x14, 0x0b }
+ { 0x0a, 0x00, 0x01, 0x00, 0x0b, 0x0b, 0x12, 0x12, 0x12, 0x0b, 0x0b },
+ { 0x0a, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+ { 0x2a, 0x23, 0x0b, 0x20, 0x0b, 0x12, 0x12, 0x12, 0x12, 0x0b, 0x21 },
+ { 0x0a, 0x03, 0x01, 0x00, 0x0b, 0x0b, 0x0b, 0x0b, 0x14, 0x0b, 0x0b },
+ { 0x4a, 0xc4, 0x0b, 0x40, 0x14, 0x14, 0x0b, 0x14, 0x14, 0x0b, 0x0b },
+ { 0x0a, 0x05, 0x01, 0x00, 0x0b, 0x0b, 0x0b, 0x0b, 0x14, 0x0b, 0x0b }
} ;
node_ip *node = 0 ;
size_t mark = hd->storage.len ;
@@ -177,6 +177,12 @@ static int s6dns_hosts_parse (buffer *b, hostdata *hd)
{
char ip[16] ;
if (!stralloc_0(&hd->storage)) goto err ;
+ if (state == 0x01) /* ignore link-local addresses */
+ {
+ if (!ip6_scan(hd->storage.s + mark, ip)) goto errill ;
+ hd->storage.len = mark ;
+ continue ;
+ }
if (ip6_scan(hd->storage.s + mark, ip))
{
uint32_t d ;
@@ -203,7 +209,7 @@ static int s6dns_hosts_parse (buffer *b, hostdata *hd)
flags &= ~1 ;
node = GENSETDYN_P(node_ip, &hd->ipv4, d) ;
}
- else goto err ;
+ else goto errill ;
hd->storage.len = mark ;
flags &= ~2 ;
}
@@ -268,6 +274,8 @@ static int s6dns_hosts_parse (buffer *b, hostdata *hd)
if (state > 0x0a) return (errno = EILSEQ, 0) ;
return 1 ;
+ errill:
+ errno = EILSEQ ;
err:
hostdata_free(hd) ;
return 0 ;
diff --git a/src/libs6dns/s6dns_hosts_compile.txt b/src/libs6dns/s6dns_hosts_compile.txt
index aa71b93..cbcac26 100644
--- a/src/libs6dns/s6dns_hosts_compile.txt
+++ b/src/libs6dns/s6dns_hosts_compile.txt
@@ -1,25 +1,25 @@
-class | 0 1 2 3 4 5 6 7 8 9
-st\ev | \0 space # \n - . : 0-9 alpha other
+class | 0 1 2 3 4 5 6 7 8 9 a
+st\ev | \0 space # \n - . : 0-9 alpha other %
START | p p p
-00 | END START COMMENT START X X IP IP IP X
+00 | END START COMMENT START X X IP IP IP X X
COMMENT |
-01 | END COMMENT COMMENT START COMMENT COMMENT COMMENT COMMENT COMMENT COMMENT
+01 | END COMMENT COMMENT START COMMENT COMMENT COMMENT COMMENT COMMENT COMMENT COMMENT
-IP | s s s p p p p
-02 | END IPDONE X START X IP IP IP IP X
+IP | s s s p p p p s
+02 | END IPDONE X START X IP IP IP IP X COMMENT
IPDONE | p
-03 | END IPDONE COMMENT START X X X X NAME X
+03 | END IPDONE COMMENT START X X X X NAME X X
NAME | f fn f p p p p
-04 | END NAMES X START NAME NAME X NAME NAME X
+04 | END NAMES X START NAME NAME X NAME NAME X X
NAMES | p
-05 | END NAMES COMMENT START X X X X NAME X
+05 | END NAMES COMMENT START X X X X NAME X X
END = 0a
X = 0b
diff --git a/src/libs6dns/s6dns_init.c b/src/libs6dns/s6dns_init.c
index 10dcbf5..5c8a25c 100644
--- a/src/libs6dns/s6dns_init.c
+++ b/src/libs6dns/s6dns_init.c
@@ -4,10 +4,10 @@
#include <s6-dns/hosts.h>
#include <s6-dns/s6dns.h>
-int s6dns_init (void)
+int s6dns_init_options (uint32_t options)
{
if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf")) return 0 ;
- if (s6dns_hosts_init(&s6dns_hosts_here, "/etc/hosts", "/etc/hosts.cdb", "/tmp/hosts.cdb") == -1) goto err ;
+ if (options & 1 && s6dns_hosts_init(&s6dns_hosts_here, "/etc/hosts", "/etc/hosts.cdb", "/tmp/hosts.cdb") == -1) goto err ;
return 1 ;
err: