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