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