2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2018 IPFire Network Development Team #
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. #
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. #
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/>. #
20 ###############################################################################
22 BIRD_CONF
="/etc/bird.conf"
25 service_is_active
"bird.service"
29 service_start
"bird.service"
33 service_stop
"bird.service"
37 service_reload
"bird.service"
40 # Update configuration any apply it in one go
42 if ! bird_generate_config
; then
43 log ERROR
"Could not write Bird configuration"
48 if bird_is_active
; then
55 bird_generate_config
() {
56 log DEBUG
"Write BIRD configuration file"
59 config_header
"bird" > ${BIRD_CONF}
61 # Write some basic settings
64 print
"# Log everything to syslog"
65 print
"log syslog all;"
68 print
"# Turn on internal watchdog"
69 print
"watchdog warning 5s;"
70 print
"watchdog timeout 30s;"
73 print
"# Define default route tables"
74 print
"ipv6 table master6;"
75 print
"ipv4 table master4;"
77 print
"# Enable device configuration"
78 print
"protocol device {}"
81 print
"# Export all routes to kernel"
82 for proto
in ${IP_SUPPORTED_PROTOCOLS}; do
83 print
"protocol kernel {"
85 print
" table ${proto/ipv/master};"
95 for proto
in ${IP_SUPPORTED_PROTOCOLS}; do
96 print
"protocol static {"
100 # Read routes for this protocol from configuration
101 __bird_static_routes
"${proto}"
107 # Write IPv6 Router Advertisement configuration
108 __bird_ipv6_radv
>> ${BIRD_CONF}
111 __bird_static_routes
() {
115 local ${NETWORK_CONFIG_ROUTES_PARAMS}
118 route_parse_line
"${line}"
119 [ $?
-eq ${EXIT_OK} ] ||
continue
123 for arg
in unreachable prohibit blackhole
; do
124 if enabled
"${arg}"; then
130 # Skip all routes of another protocol
131 local _proto
="$(ip_detect_protocol "${network}")"
132 if [ "${proto}" != "${_proto}" ]; then
137 unreachable|prohibit|blackhole
)
138 print
" route ${network} ${type};"
142 print
" route ${network} via ${gateway};"
145 done < ${NETWORK_CONFIG_ROUTES}
149 print
"protocol radv {"
152 for zone
in $
(zones_get_local
); do
153 log DEBUG
"Writing bird radv configuration for ${zone}"
155 # Skip if there is no prefix or prefix is link-local.
156 local addr
="$(db_get "${zone}/ipv
6/local-ip-address
")"
157 if [ -z "${addr}" ] ||
[ "${addr:0:5}" = "fe80:" ]; then
161 # Check if the subnet is configured by the DHCP server.
163 local prefix
="$(ipv6_get_network "${addr}")"
164 if isset prefix
&& dhcpd_subnet_match ipv6
"${prefix}"; then
168 print
" interface \"${zone}\" {"
169 # Failover to other routers within 10s
170 print
" max ra interval 10;"
172 # Tell clients we are running DHCP
173 if enabled dhcp
; then
174 print
" managed yes;"
175 print
" other config yes;"
178 if device_exists
"${zone}"; then
180 local mtu
="$(device_get_mtu "${zone}")"
181 print
" link mtu ${mtu};"
186 # Announce all prefixes
187 print
" prefix ::/0 {"
189 if enabled dhcp
; then
190 print
" autonomous off;"
197 # Advertise any DNS servers
198 if enabled DNS_ADVERTISE_SERVERS
; then
199 # Get a list of all IPv6 name servers
202 for server
in $
(dns_server_list_sorted
); do
203 # Skip any non-IPv6 servers
204 ipv6_is_valid
"${server}" ||
continue
206 servers
+=( "${server}" )
209 if isset servers
; then
213 for server
in ${servers}; do
214 print
" ns ${server};"
225 for domain
in $
(dns_get_search_domains
); do
226 print
" domain \"${domain}\";"