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