Add support for dereferencing SRV records via f_host_lookup(). Takes the

media choice into consideration for determining the appropriate SRV records
to query (e.g., _http._tcp, _ftp._tcp, _nfs.tcp, _nfs.udp, etc.).
This commit is contained in:
dteske 2013-11-06 18:26:38 +00:00
parent f293f84ee2
commit c6bf517ec1

View File

@ -1020,10 +1020,41 @@ f_host_lookup()
# Fall back to host(1) -- which is further governed by nsswitch.conf(5)
#
local __output __ip6 __addrs="" __wait=""
f_getvar $VAR_MEDIA_TIMEOUT __wait
[ "$__wait" ] && __wait="-W $(( $__wait / 2 ))"
local __output __ip6 __addrs=
f_getvar $VAR_IPV6_ENABLE __ip6
# If we have a TCP media type configured, check for an SRV record
local __srvtypes=
{ f_quietly f_getvar $VAR_HTTP_PATH ||
f_quietly f_getvar $VAR_HTTP_PROXY_PATH
} && __srvtypes="$__srvtypes _http._tcp"
f_quietly f_getvar $VAR_FTP_PATH && __srvtypes="$__srvtypes _ftp._tcp"
f_quietly f_getvar $VAR_NFS_PATH &&
__srvtypes="$__srvtypes _nfs._tcp _nfs._udp"
# Calculate wait time as dividend of total time and host(1) invocations
local __host_runs __wait
if [ "$__ip6" = "YES" ]; then
__host_runs=$(( 2 + $( set -- $__srvtypes; echo $# ) ))
else
__host_runs=$(( 1 + $( set -- $__srvtypes; echo $# ) ))
fi
f_getvar $VAR_MEDIA_TIMEOUT __wait
[ "$__wait" ] && __wait="-W $(( $__wait / $__host_runs ))"
# Query SRV types first (1st host response taken as new host to query)
for __type in $__srvtypes; do
if __output=$(
host -t SRV $__wait -- "$__type.$__host" \
2> /dev/null
); then
__host=$( echo "$__output" |
awk '/ SRV /{print $NF;exit}' )
break
fi
done
# Try IPv6 first (if enabled)
if [ "$__ip6" = "YES" ]; then
if ! __output=$( host -t AAAA $__wait -- "$__host" 2>&1 ); then
# An error occurred, display in-full and return error
@ -1031,13 +1062,17 @@ f_host_lookup()
setvar "$__var_to_set" "$__output"
return $FAILURE
fi
# Add the IPv6 addresses and fall-through to collect IPv4 too
__addrs=$( echo "$__output" | awk '/ address /{print $NF}' )
fi
# Good ol' IPv4
if ! __output=$( host -t A $__wait -- "$__host" 2>&1 ); then
# An error occurred, display it in-full and return error
[ "$__var_to_set" ] && setvar "$__var_to_set" "$__output"
return $FAILURE
fi
__addrs="$__addrs${__addrs:+ }$(
echo "$__output" | awk '/ address /{print $NF}' )"
if [ "$__var_to_set" ]; then