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.
}
function __dns_server_sort() {
- sort -k2 -u -g
+ sort -k2 -g | uniq
}
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
}
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.
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
}
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"
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.
# Update the local DNS configuration after changes have been made.
dns_generate_resolvconf
+ radvd_update
exit ${EXIT_OK}
}