}
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_all); do
+ 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."
+ done >> ${RADVD_CONFIGFILE}
- : > ${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}"
- echo $zone
+ log DEBUG "Writing radvd configuration for ${zone}."
# If the interface does not provide any routing information,
# we can skip this whole stuff.
[ "${active}" = "0" ] && return ${EXIT_OK}
# Skip if there is no prefix or prefix is link-local.
- local prefix=$(routing_db_get ${zone} ipv6 local-ip-address)
- if [ -z "${prefix}" ] || [ "${prefix:0:5}" = "fe80:" ]; then
+ local addr=$(routing_db_get ${zone} ipv6 local-ip-address)
+ if [ -z "${addr}" ] || [ "${addr:0:5}" = "fe80:" ]; then
+ return ${EXIT_OK}
+ fi
+ local prefix=$(ipv6_get_network ${addr})
+
+ # Check if the subnet is configured by the DHCP server.
+ local dhcpd="false"
+ if dhcpd_subnet_match ipv6 "${prefix}"; then
+ dhcpd="true"
+ fi
+
+ print "interface ${zone} {"
+ print " AdvSendAdvert on;"
+ print " MinRtrAdvInterval 3;"
+ print " MaxRtrAdvInterval 10;"
+ print " IgnoreIfMissing on;"
+
+ if enabled dhcpd; then
+ print " AdvManagedFlag on;"
+ print " AdvOtherConfigFlag on;"
+ fi
+
+ print
+ print " prefix ${prefix} {"
+ print " AdvOnLink on;"
+
+ if enabled dhcpd; then
+ print " AdvRouterAddr off;"
+ print " AdvAutonomous off;"
+ else
+ print " AdvRouterAddr on;"
+ print " AdvAutonomous on;"
+ fi
+
+ 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_sorted); 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
- __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 " RDNSS ${servers} {"
+ print " # Use the defaults here."
+ print " };"
+ print
}