]> git.ipfire.org Git - people/stevee/network.git/commitdiff
Add support for automatic configuration of radvd.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jun 2011 14:43:44 +0000 (14:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jun 2011 14:43:44 +0000 (14:43 +0000)
functions.radvd [new file with mode: 0644]
functions.service [new file with mode: 0644]

diff --git a/functions.radvd b/functions.radvd
new file mode 100644 (file)
index 0000000..1653415
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2010  Michael Tremer & Christian Schmidt                      #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+RADVD_CONFIGFILE="/etc/radvd.conf"
+
+function radvd_update() {
+       # (Re-)write the configuration file
+       radvd_write_config
+
+       # Reload the radvd service.
+       service_reload radvd
+}
+
+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 "#\n"
+
+       # Write the configuration for all zones.
+       local zone
+       for zone in $(zones_get_all); do
+               __radvd_config_interface ${zone}
+       done
+}
+
+function __radvd_clear() {
+       log DEBUG "Clearing radvd config file."
+
+       : > ${RADVD_CONFIGFILE}
+}
+
+function __radvd_write() {
+       echo -e "$@" >> ${RADVD_CONFIGFILE}
+}
+
+function __radvd_config_interface() {
+       local zone=${1}
+       shift
+
+       assert isset zone
+
+       # If the interface does not provide any routing information,
+       # we can skip this whole stuff.
+       if ! routing_db_exists ${zone} ipv6; then
+               return ${EXIT_OK}
+       fi
+
+       # Skip if zone is not active.
+       local active=$(routing_db_get ${zone} ipv6 active)
+       [ "${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
+               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"
+}
diff --git a/functions.service b/functions.service
new file mode 100644 (file)
index 0000000..b1a9cd8
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2010  Michael Tremer & Christian Schmidt                      #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+function service_start() {
+       local name=${1}
+       shift
+
+       assert isset name
+
+       systemctl start ${name}.service
+}
+
+function service_stop() {
+       local name=${1}
+       shift
+
+       assert isset name
+
+       systemctl stop ${name}.service
+}
+
+function service_restart() {
+       local name=${1}
+       shift
+
+       assert isset name
+
+       systemctl restart ${name}.service
+}
+
+function service_reload() {
+       local name=${1}
+       shift
+
+       assert isset name
+
+       if service_status ${name}; then
+               systemctl reload ${name}.service
+               return $?
+       else
+               log WARNING "Cannot reload service '${name}' which is currently not running."
+       fi
+}
+
+function service_status() {
+       local name=${1}
+       shift
+
+       assert isset name
+
+       systemctl status ${name}.service >/dev/null 2>&1
+       return $?
+}