]> git.ipfire.org Git - people/stevee/network.git/blame - src/functions/functions.radvd
Ensure that radvd is started when needed
[people/stevee/network.git] / src / functions / 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
1c6a4e30 24radvd_update() {
1eec4672
MT
25 # (Re-)write the configuration file
26 radvd_write_config
27
05ab2f8a
SS
28 # Reload the radvd service if it is already running
29 if service_is_active radvd; then
30 service_reload radvd
31 return ${EXIT_OK}
32 fi
33
34 # Start the radvd service
35 service_start radvd
1eec4672
MT
36}
37
1c6a4e30 38radvd_write_config() {
6f923dac 39 config_header "radv daemon configuration file" > ${RADVD_CONFIGFILE}
1eec4672
MT
40
41 # Write the configuration for all zones.
42 local zone
28f0b4ab 43 for zone in $(zones_get_local); do
1eec4672 44 __radvd_config_interface ${zone}
1eec4672 45
6f923dac 46 done >> ${RADVD_CONFIGFILE}
1eec4672 47
6f923dac 48 return ${EXIT_OK}
1eec4672
MT
49}
50
1c6a4e30 51__radvd_config_interface() {
1eec4672 52 local zone=${1}
1eec4672
MT
53 assert isset zone
54
6f923dac 55 log DEBUG "Writing radvd configuration for ${zone}."
b368da2f 56
1eec4672
MT
57 # If the interface does not provide any routing information,
58 # we can skip this whole stuff.
c041b631 59 if ! db_exists "${zone}/ipv6"; then
1eec4672
MT
60 return ${EXIT_OK}
61 fi
62
63 # Skip if zone is not active.
c041b631 64 local active="$(db_get "${zone}/ipv6/active")"
1eec4672
MT
65 [ "${active}" = "0" ] && return ${EXIT_OK}
66
67 # Skip if there is no prefix or prefix is link-local.
c041b631 68 local addr="$(db_get "${zone}/ipv6/local-ip-address")"
6c07160e 69 if [ -z "${addr}" ] || [ "${addr:0:5}" = "fe80:" ]; then
1eec4672
MT
70 return ${EXIT_OK}
71 fi
6c07160e
MT
72 local prefix=$(ipv6_get_network ${addr})
73
74 # Check if the subnet is configured by the DHCP server.
75 local dhcpd="false"
76 if dhcpd_subnet_match ipv6 "${prefix}"; then
77 dhcpd="true"
78 fi
1eec4672 79
6f923dac
MT
80 print "interface ${zone} {"
81 print " AdvSendAdvert on;"
82 print " MinRtrAdvInterval 3;"
83 print " MaxRtrAdvInterval 10;"
84 print " IgnoreIfMissing on;"
6c07160e
MT
85
86 if enabled dhcpd; then
87 print " AdvManagedFlag on;"
88 print " AdvOtherConfigFlag on;"
89 fi
90
6f923dac 91 print
e0e0193c 92 print " prefix ::/64 {"
6f923dac 93 print " AdvOnLink on;"
6c07160e
MT
94
95 if enabled dhcpd; then
96 print " AdvRouterAddr off;"
97 print " AdvAutonomous off;"
98 else
99 print " AdvRouterAddr on;"
100 print " AdvAutonomous on;"
101 fi
102
6f923dac
MT
103 print " };"
104 print
105
106 # Add the DNS configuration.
107 __radvd_config_dns ${zone}
108
109 print "};"
110 print
111}
112
1c6a4e30 113__radvd_config_dns() {
6f923dac
MT
114 local zone=${1}
115
116 # Do nothing, when this option is not enabled.
117 enabled DNS_ADVERTISE_SERVERS || return ${EXIT_OK}
118
119 # XXX it is kind of difficult to announce our local
120 # resolver.
121
122 local server servers
e5651e17 123 for server in $(dns_server_list_sorted); do
6f923dac
MT
124 # Filter out non IPv6 addresses.
125 ipv6_is_valid ${server} || continue
126
127 servers="${servers} ${server}"
128 done
129
130 # Remove whitespaces.
131 servers=$(echo ${servers})
132
133 # If there are no servers to announce, we stop right here.
134 if ! isset servers; then
135 log DEBUG "No servers to announce."
136 return ${EXIT_OK}
137 fi
138
139 print " RDNSS ${servers} {"
140 print " # Use the defaults here."
141 print " };"
142 print
1eec4672 143}