From 6f923dac5a3dbdb4d88119b766b16fa2d1490bb8 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 30 Jun 2012 13:12:57 +0000 Subject: [PATCH] DNS: Add RDNSS functionality. The radv daemon is now able to announce DNS servers. There have also been bugfixes for minor problems. --- functions.dns | 13 ++++++- functions.radvd | 93 ++++++++++++++++++++++++++++--------------------- network | 13 ++++--- 3 files changed, 75 insertions(+), 44 deletions(-) diff --git a/functions.dns b/functions.dns index 39ddfad7..7d153cd0 100644 --- a/functions.dns +++ b/functions.dns @@ -28,6 +28,10 @@ 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" +# Set this option to true if the DNS servers should be advertised by +# radvd. +DNS_ADVERTISE_SERVERS="true" + DNS_SERVER_CONFIG_FILE="${NETWORK_CONFIG_DIR}/dns-servers" # Path to the configuration file of the DNS resolver. @@ -52,7 +56,7 @@ function __dns_server_println() { } function __dns_server_sort() { - sort -k2 -u -g + sort -k2 -g | uniq } function dns_server_list() { @@ -66,6 +70,13 @@ function dns_server_list() { done < ${DNS_SERVER_CONFIG_FILE} | __dns_server_sort } +function dns_server_list_no_priority() { + local server priority + dns_server_list | while read server priority; do + echo "${server}" + done +} + function dns_server_add() { local server=${1} assert isset server diff --git a/functions.radvd b/functions.radvd index 81e7aba9..0126a67a 100644 --- a/functions.radvd +++ b/functions.radvd @@ -30,46 +30,23 @@ function radvd_update() { } function radvd_write_config() { - # Clear the config file. - __radvd_clear - - # Write header to the file. - __radvd_write "#" - __radvd_write "# This is the radvd daemon configuration file." - __radvd_write "# THIS FILE IS AUTOMATICALLY GENERATED AND WILL OVERWRITE" - __radvd_write "# ANY CUSTOM CHANGES!" - __radvd_write "#" - __radvd_write "# $(date -u)" - __radvd_write "#\n" + config_header "radv daemon configuration file" > ${RADVD_CONFIGFILE} # Write the configuration for all zones. local zone for zone in $(zones_get_local); do __radvd_config_interface ${zone} - done -} - -function radvd_clear() { - __radvd_clear -} - -function __radvd_clear() { - log DEBUG "Clearing radvd config file." - : > ${RADVD_CONFIGFILE} -} + done >> ${RADVD_CONFIGFILE} -function __radvd_write() { - echo -e "$@" >> ${RADVD_CONFIGFILE} + return ${EXIT_OK} } function __radvd_config_interface() { local zone=${1} - shift - assert isset zone - log DEBUG "Writing radvd configuration for ${zone}" + log DEBUG "Writing radvd configuration for ${zone}." # If the interface does not provide any routing information, # we can skip this whole stuff. @@ -87,16 +64,54 @@ function __radvd_config_interface() { return ${EXIT_OK} fi - __radvd_write "interface ${zone} {" - __radvd_write " AdvSendAdvert on;" - __radvd_write " MinRtrAdvInterval 3;" - __radvd_write " MaxRtrAdvInterval 10;" - __radvd_write " IgnoreIfMissing on;" - __radvd_write "" - __radvd_write " prefix ${prefix} {" - __radvd_write " AdvOnLink on;" - __radvd_write " AdvAutonomous on;" - __radvd_write " AdvRouterAddr on;" - __radvd_write " };" - __radvd_write "};\n" + print "interface ${zone} {" + print " AdvSendAdvert on;" + print " MinRtrAdvInterval 3;" + print " MaxRtrAdvInterval 10;" + print " IgnoreIfMissing on;" + print + print " prefix ${prefix} {" + print " AdvOnLink on;" + print " AdvAutonomous on;" + print " AdvRouterAddr on;" + print " };" + print + + # Add the DNS configuration. + __radvd_config_dns ${zone} + + print "};" + print +} + +function __radvd_config_dns() { + local zone=${1} + + # Do nothing, when this option is not enabled. + enabled DNS_ADVERTISE_SERVERS || return ${EXIT_OK} + + # XXX it is kind of difficult to announce our local + # resolver. + + local server servers + for server in $(dns_server_list_no_priority); do + # Filter out non IPv6 addresses. + ipv6_is_valid ${server} || continue + + servers="${servers} ${server}" + done + + # Remove whitespaces. + servers=$(echo ${servers}) + + # If there are no servers to announce, we stop right here. + if ! isset servers; then + log DEBUG "No servers to announce." + return ${EXIT_OK} + fi + + print " RDNSS ${servers} {" + print " # Use the defaults here." + print " };" + print } diff --git a/network b/network index 9dee7472..808d2cd6 100755 --- a/network +++ b/network @@ -544,6 +544,10 @@ function cli_dns() { exit ${EXIT_ERROR} fi + # Get the new server to process (if any). + local server=${1} + local priority=${2} + case "${cmd}" in list) __dns_server_println "SERVER" "PRIORITY" @@ -551,12 +555,12 @@ function cli_dns() { exit ${EXIT_OK} ;; add) - log INFO "Adding new DNS server: ${server}..." - dns_server_add $@ + log INFO "Adding new DNS server: ${server}" + dns_server_add ${server} ${priority} ;; remove) - log INFO "Removing DNS server: ${server}..." - dns_server_remove $@ + log INFO "Removing DNS server: ${server}" + dns_server_remove ${server} ${priority} ;; update) # Just run the update afterwards. @@ -568,6 +572,7 @@ function cli_dns() { # Update the local DNS configuration after changes have been made. dns_generate_resolvconf + radvd_update exit ${EXIT_OK} } -- 2.47.3