]> git.ipfire.org Git - people/stevee/network.git/commitdiff
DNS: Add RDNSS functionality.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Jun 2012 13:12:57 +0000 (13:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Jun 2012 13:12:57 +0000 (13:12 +0000)
The radv daemon is now able to announce DNS servers.
There have also been bugfixes for minor problems.

functions.dns
functions.radvd
network

index 39ddfad729672bf160c88fe77c2418131dcf85ea..7d153cd0dc01c3f960ed3eb5cc88beeacb663073 100644 (file)
@@ -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
index 81e7aba9b86b897e57902fd3dae85f728fc7b3e1..0126a67a8a32c0665aa47291b5d6f2b523e59755 100644 (file)
@@ -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 9dee7472ea6ef523a1ba9f7eec225ef6e6db0e05..808d2cd6f398f0939abff1eff3d618df84cf5dc4 100755 (executable)
--- 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}
 }