]> git.ipfire.org Git - people/stevee/network.git/blob - functions.radvd
Remove a line of debugging code.
[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 "#"
42 __radvd_write "# $(date -u)"
43 __radvd_write "#\n"
44
45 # Write the configuration for all zones.
46 local zone
47 for zone in $(zones_get_local); do
48 __radvd_config_interface ${zone}
49 done
50 }
51
52 function radvd_clear() {
53 __radvd_clear
54 }
55
56 function __radvd_clear() {
57 log DEBUG "Clearing radvd config file."
58
59 : > ${RADVD_CONFIGFILE}
60 }
61
62 function __radvd_write() {
63 echo -e "$@" >> ${RADVD_CONFIGFILE}
64 }
65
66 function __radvd_config_interface() {
67 local zone=${1}
68 shift
69
70 assert isset zone
71
72 log DEBUG "Writing radvd configuration for ${zone}"
73
74 # If the interface does not provide any routing information,
75 # we can skip this whole stuff.
76 if ! routing_db_exists ${zone} ipv6; then
77 return ${EXIT_OK}
78 fi
79
80 # Skip if zone is not active.
81 local active=$(routing_db_get ${zone} ipv6 active)
82 [ "${active}" = "0" ] && return ${EXIT_OK}
83
84 # Skip if there is no prefix or prefix is link-local.
85 local prefix=$(routing_db_get ${zone} ipv6 local-ip-address)
86 if [ -z "${prefix}" ] || [ "${prefix:0:5}" = "fe80:" ]; then
87 return ${EXIT_OK}
88 fi
89
90 __radvd_write "interface ${zone} {"
91 __radvd_write " AdvSendAdvert on;"
92 __radvd_write " MinRtrAdvInterval 3;"
93 __radvd_write " MaxRtrAdvInterval 10;"
94 __radvd_write " IgnoreIfMissing on;"
95 __radvd_write ""
96 __radvd_write " prefix ${prefix} {"
97 __radvd_write " AdvOnLink on;"
98 __radvd_write " AdvAutonomous on;"
99 __radvd_write " AdvRouterAddr on;"
100 __radvd_write " };"
101 __radvd_write "};\n"
102 }