Commit 097fea9d authored by Vitaly Lipatov's avatar Vitaly Lipatov

router: filter dig diagnostics from gateway resolve and PTR lookup

When DNS times out, "dig +short" can emit ";; communications error to SERVER#53: timed out" to stdout (not just stderr). resolve_gw's grep -m1 '[0-9]' would accept that line as an "IP" (it contains "10#53"); gw_monitor_tag would carry it through sed and produce a multi-line tag. The latter ended up as state directory names like "gw-;; communications error to ...\\nikev2.hetzner.v6/". Wrap dig in 2>/dev/null and filter "^;" diagnostics; in gw_monitor_tag also take only the first PTR line.
parent 5c9edd5f
...@@ -46,9 +46,9 @@ resolve_gw() ...@@ -46,9 +46,9 @@ resolve_gw()
*:*) echo "$val" ;; *:*) echo "$val" ;;
*[a-zA-Z]*) *[a-zA-Z]*)
if [ "$ipcmd" = "ip -6" ] ; then if [ "$ipcmd" = "ip -6" ] ; then
dig +short AAAA "$val" | grep -m1 ':' dig +short AAAA "$val" 2>/dev/null | grep -v '^;' | grep -m1 ':'
else else
dig +short A "$val" | grep -m1 '[0-9]' dig +short A "$val" 2>/dev/null | grep -v '^;' | grep -m1 '[0-9]'
fi ;; fi ;;
*) echo "$val" ;; *) echo "$val" ;;
esac esac
......
...@@ -165,7 +165,7 @@ get_health() ...@@ -165,7 +165,7 @@ get_health()
gw_monitor_tag() gw_monitor_tag()
{ {
local gw_ip="$1" ipcmd="$2" local gw_ip="$1" ipcmd="$2"
local ptr=$(dig +short -x "$gw_ip" 2>/dev/null | sed 's/\.$//') local ptr=$(dig +short -x "$gw_ip" 2>/dev/null | grep -v '^;' | head -1 | sed 's/\.$//')
[ -z "$ptr" ] && return [ -z "$ptr" ] && return
local tag=$(echo "$ptr" | sed 's/\.egw\.etersoft\.ru$//') local tag=$(echo "$ptr" | sed 's/\.egw\.etersoft\.ru$//')
[ "$tag" = "$ptr" ] && return # not in egw zone [ "$tag" = "$ptr" ] && return # not in egw zone
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment