From aeec9a86e2dce3883d146959071ebfa62b254c82 Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Wed, 19 Apr 2023 13:48:59 +0300 Subject: [PATCH] Pull request 1836: 5714-handle-zeroes-health Merge in DNS/adguard-home from 5714-handle-zeroes-health to master Updates #5714. Squashed commit of the following: commit 24faab01faf723e313050294b3a35e249c3cd3e3 Author: Eugene Burkov Date: Wed Apr 19 13:10:24 2023 +0300 docker: add curly brackets commit 67365d02856200685551a79aa23cf59df4a3484b Author: Eugene Burkov Date: Tue Apr 18 20:16:12 2023 +0300 docker: imp zeroes check --- docker/dns-bind.awk | 7 +++---- docker/healthcheck.sh | 28 +++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/docker/dns-bind.awk b/docker/dns-bind.awk index 4173614c..778ebec0 100644 --- a/docker/dns-bind.awk +++ b/docker/dns-bind.awk @@ -7,11 +7,10 @@ addrs[$2] = true prev_line = FNR - if ($2 == "0.0.0.0" || $2 == "::") { - delete addrs - addrs["localhost"] = true - + if ($2 == "0.0.0.0" || $2 == "\"\"" || $2 == "'::'") { # Drop all the other addresses. + delete addrs + addrs[""] = true prev_line = -1 } } diff --git a/docker/healthcheck.sh b/docker/healthcheck.sh index 881bbd60..a50de230 100755 --- a/docker/healthcheck.sh +++ b/docker/healthcheck.sh @@ -61,8 +61,11 @@ then error_exit "no DNS bindings could be retrieved from $filename" fi +first_dns="$( echo "$dns_hosts" | head -n 1 )" +readonly first_dns + # TODO(e.burkov): Deal with 0 port. -case "$( echo "$dns_hosts" | head -n 1 )" +case "$first_dns" in (*':0') error_exit '0 in DNS port is not supported by healthcheck' @@ -82,8 +85,23 @@ esac # See https://github.com/AdguardTeam/AdGuardHome/issues/5642. wget --no-check-certificate "$web_url" -O /dev/null -q || exit 1 -echo "$dns_hosts" | while read -r host -do - nslookup -type=a healthcheck.adguardhome.test. "$host" > /dev/null ||\ +test_fqdn="healthcheck.adguardhome.test." +readonly test_fqdn + +# The awk script currently returns only port prefixed with colon in case of +# unspecified address. +case "$first_dns" +in +(':'*) + nslookup -type=a "$test_fqdn" "127.0.0.1${first_dns}" > /dev/null ||\ + nslookup -type=a "$test_fqdn" "[::1]${first_dns}" > /dev/null ||\ error_exit "nslookup failed for $host" -done + ;; +(*) + echo "$dns_hosts" | while read -r host + do + nslookup -type=a "$test_fqdn" "$host" > /dev/null ||\ + error_exit "nslookup failed for $host" + done + ;; +esac