summaryrefslogtreecommitdiff
path: root/src/libs6dns
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/libs6dns
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/libs6dns')
-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
3 files changed, 28 insertions, 20 deletions
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: