From 805da540a4efd01d521f8dc74d05179601188f9a Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 13 Oct 2012 15:29:18 +0000 Subject: [PATCH] DNS: Add static search domains. --- functions.dns | 18 ++++++++++++++++-- functions.list | 11 +++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/functions.dns b/functions.dns index 33f80201..5f964ba5 100644 --- a/functions.dns +++ b/functions.dns @@ -28,6 +28,9 @@ NETWORK_CONFIG_FILE_PARAMS="${NETWORK_CONFIG_FILE_PARAMS} DNS_USE_LOCAL_RESOLVER DNS_RANDOMIZE=false NETWORK_CONFIG_FILE_PARAMS="${NETWORK_CONFIG_FILE_PARAMS} DNS_RANDOMIZE" +DNS_SEARCH_DOMAINS="" +NETWORK_CONFIG_FILE_PARAMS="${NETWORK_CONFIG_FILE_PARAMS} DNS_SEARCH_DOMAINS" + # Set this option to true if the DNS servers should be advertised by # radvd. DNS_ADVERTISE_SERVERS="true" @@ -126,7 +129,10 @@ function dns_generate_resolvconf() { print "option rotate\n" >> ${file} fi - # XXX Add search domain. + # Add search domains. + local search_domains="$(unquote ${DNS_SEARCH_DOMAINS})" + + # Get search domains from DHCP clients, etc. local proto local zone local domainname @@ -134,9 +140,17 @@ function dns_generate_resolvconf() { for proto in ${IP_SUPPORTED_PROTOCOLS}; do domainname=$(routing_db_get ${zone} ${proto} domain-name) if [ -n "${domainname}" ]; then - print "search ${domainname}" + list_append search_domains "${domainname}" fi done + done + + # Sort out duplicate entries. + search_domains=$(list_unique ${search_domains}) + + # Write search domains to file. + for domainname in ${search_domains}; do + print "search ${domainname}" done >> ${file} # Add the local resolver as the first DNS server if enabled. diff --git a/functions.list b/functions.list index fa22a666..c33d4db6 100644 --- a/functions.list +++ b/functions.list @@ -59,6 +59,17 @@ function list_sort() { print } +function list_unique() { + local items item + for item in $@; do + # Check if the item has already been processed. + list_match "${item}" ${items} && continue + + list_append items "${item}" + print "${item}" + done +} + function list_match() { local match=${1} shift -- 2.47.2