Date: Wed, 6 Nov 2013 18:26:38 +0000 (UTC) From: Devin Teske <dteske@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r257755 - head/usr.sbin/bsdconfig/share/media Message-ID: <201311061826.rA6IQcTb089766@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dteske Date: Wed Nov 6 18:26:38 2013 New Revision: 257755 URL: http://svnweb.freebsd.org/changeset/base/257755 Log: 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.). Modified: head/usr.sbin/bsdconfig/share/media/tcpip.subr Modified: head/usr.sbin/bsdconfig/share/media/tcpip.subr ============================================================================== --- head/usr.sbin/bsdconfig/share/media/tcpip.subr Wed Nov 6 17:20:49 2013 (r257754) +++ head/usr.sbin/bsdconfig/share/media/tcpip.subr Wed Nov 6 18:26:38 2013 (r257755) @@ -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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201311061826.rA6IQcTb089766>