]> git.ipfire.org Git - network.git/commitdiff
bird: Apply static routes instead of doing that manually with ip
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 16 Dec 2018 17:47:57 +0000 (17:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 16 Dec 2018 17:47:57 +0000 (17:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.bird
src/functions/functions.route
src/functions/functions.routing

index 9c8b006899fa5e4b316d75eb568b7aa5527d67d6..c6fea321c6743e8795135c8541aec133b718bb0b 100644 (file)
@@ -60,7 +60,7 @@ bird_generate_config() {
                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};"
@@ -71,4 +71,54 @@ bird_generate_config() {
                        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}
 }
index 7ca4f59dc9d6248184b410f6f1781e76fabce890..e6ea2441ef0a69c10dda0a10c7808eab7912425d 100644 (file)
@@ -393,41 +393,11 @@ route_parse_line() {
 }
 
 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() {
index 24365856f155fbc82b6780891a9fd0d1c79ae4f7..c7aac094f11cdca2c4d88abc8a65df4816666425 100644 (file)
@@ -181,7 +181,4 @@ routing_update() {
        cmd ${routing_cmd}
 
        cmd ${ip_cmd} rule add from ${local_ip_address} lookup ${table}
-
-       # Apply all static routes
-       route_apply
 }