print
print "# Export all routes to kernel"
- for proto in ipv6 ipv4; do
+ for proto in ${IP_SUPPORTED_PROTOCOLS}; do
print "protocol kernel {"
print " ${proto} {"
print " table ${proto/ipv/master};"
print
done
) >> ${BIRD_CONF}
+
+ # Static routes
+ for proto in ${IP_SUPPORTED_PROTOCOLS}; do
+ print "protocol static {"
+ print " ${proto};"
+ print
+
+ # Read routes for this protocol from configuration
+ __bird_static_routes "${proto}"
+
+ print "}"
+ print
+ done >> ${BIRD_CONF}
+}
+
+__bird_static_routes() {
+ local proto="${1}"
+ assert isset proto
+
+ local ${NETWORK_CONFIG_ROUTES_PARAMS}
+ local line
+ while read line; do
+ route_parse_line "${line}"
+ [ $? -eq ${EXIT_OK} ] || continue
+
+ local type
+ local arg
+ for arg in unreachable prohibit blackhole; do
+ if enabled "${arg}"; then
+ type="${arg}"
+ break
+ fi
+ done
+
+ # Skip all routes of another protocol
+ local _proto="$(ip_detect_protocol "${network}")"
+ if [ "${proto}" != "${_proto}" ]; then
+ continue
+ fi
+
+ case "${type}" in
+ unreachable|prohibit|blackhole)
+ print " route ${network} ${type};"
+ ;;
+
+ *)
+ print " route ${network} via ${gateway};"
+ ;;
+ esac
+ done < ${NETWORK_CONFIG_ROUTES}
}
}
route_apply() {
- local table="static"
- local type
+ # Re-generate BIRD configuration
+ bird_generate_config
- log DEBUG "Applying static routes..."
-
- # Flush the routing table.
- route_table_flush ${table}
-
- local ${NETWORK_CONFIG_ROUTES_PARAMS}
- local line
- while read line; do
- route_parse_line ${line}
- [ $? -eq ${EXIT_OK} ] || continue
-
- type="unicast"
- local arg
- for arg in unreachable prohibit blackhole; do
- if enabled ${arg}; then
- type="${arg}"
- break
- fi
- done
-
- # Add the route.
- route_entry_add ${network} --table="static" --proto="static" \
- --type="${type}" --gateway="${gateway}" --mtu="${mtu}"
- local ret=$?
-
- if [ ${ret} -ne ${EXIT_OK} ]; then
- log WARNING "Could not set route '${network}'."
- fi
- done < ${NETWORK_CONFIG_ROUTES}
-
- # Create a lookup rule for the static routing table.
- route_rule_add --lookup="static" --priority=1000
+ # Reload the daemon
+ bird_reload
}
route_entry_add() {