]> git.ipfire.org Git - people/stevee/network.git/blob - functions.radvd
Add support for automatic configuration of radvd.
[people/stevee/network.git] / functions.radvd
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 RADVD_CONFIGFILE="/etc/radvd.conf"
23
24 function radvd_update() {
25 # (Re-)write the configuration file
26 radvd_write_config
27
28 # Reload the radvd service.
29 service_reload radvd
30 }
31
32 function radvd_write_config() {
33 # Clear the config file.
34 __radvd_clear
35
36 # Write header to the file.
37 __radvd_write "#"
38 __radvd_write "# This is the radvd daemon configuration file."
39 __radvd_write "# THIS FILE IS AUTOMATICALLY GENERATED AND WILL OVERWRITE"
40 __radvd_write "# ANY CUSTOM CHANGES!"
41 __radvd_write "#\n"
42
43 # Write the configuration for all zones.
44 local zone
45 for zone in $(zones_get_all); do
46 __radvd_config_interface ${zone}
47 done
48 }
49
50 function __radvd_clear() {
51 log DEBUG "Clearing radvd config file."
52
53 : > ${RADVD_CONFIGFILE}
54 }
55
56 function __radvd_write() {
57 echo -e "$@" >> ${RADVD_CONFIGFILE}
58 }
59
60 function __radvd_config_interface() {
61 local zone=${1}
62 shift
63
64 assert isset zone
65
66 # If the interface does not provide any routing information,
67 # we can skip this whole stuff.
68 if ! routing_db_exists ${zone} ipv6; then
69 return ${EXIT_OK}
70 fi
71
72 # Skip if zone is not active.
73 local active=$(routing_db_get ${zone} ipv6 active)
74 [ "${active}" = "0" ] && return ${EXIT_OK}
75
76 # Skip if there is no prefix or prefix is link-local.
77 local prefix=$(routing_db_get ${zone} ipv6 local-ip-address)
78 if [ -z "${prefix}" ] || [ "${prefix:0:5}" = "fe80:" ]; then
79 return ${EXIT_OK}
80 fi
81
82 __radvd_write "interface ${zone} {"
83 __radvd_write " AdvSendAdvert on;"
84 __radvd_write " MinRtrAdvInterval 3;"
85 __radvd_write " MaxRtrAdvInterval 10;"
86 __radvd_write " IgnoreIfMissing on;"
87 __radvd_write ""
88 __radvd_write " prefix ${prefix} {"
89 __radvd_write " AdvOnLink on;"
90 __radvd_write " AdvAutonomous on;"
91 __radvd_write " AdvRouterAddr on;"
92 __radvd_write " };"
93 __radvd_write "};\n"
94 }