]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/functions/functions.route
bird: Make sure the daemon is always running
[people/ms/network.git] / src / functions / functions.route
index 86328a0c01db8c34db9665a768461ad1bd4e0a90..b8338222556c8b2fa3e63a0c78346ca8586c5fa1 100644 (file)
 # Functions for static routing.
 #
 
+cli_route() {
+       if cli_help_requested "$@"; then
+               cli_show_man network-route
+               exit ${EXIT_OK}
+       fi
+
+       local action=${1}
+       shift
+
+       case "${action}" in
+               static)
+                       cli_route_static "$@"
+                       ;;
+               *)
+                       error "Unrecognized action: ${action}"
+                       cli_run_help network route
+
+                       exit ${EXIT_ERROR}
+                       ;;
+       esac
+
+       exit ${EXIT_OK}
+}
+
+cli_route_static() {
+       if cli_help_requested "$@"; then
+               cli_show_man network-route-static
+               exit ${EXIT_OK}
+       fi
+
+       local action=${1}
+       shift
+
+       case "${action}" in
+               # Add a new route.
+               add)
+                       route_add "$@"
+                       ;;
+               # Remove an existing route.
+               remove)
+                       route_remove "$@"
+                       ;;
+               # List all routes.
+               list)
+                       route_list "$@"
+                       return ${EXIT_OK}
+                       ;;
+               # Reload all routes
+               reload)
+                       route_apply "$@"
+                       ;;
+               *)
+                       error "Unrecognized action: ${action}"
+                       cli_run_help network route
+
+                       exit ${EXIT_ERROR}
+               ;;
+       esac
+
+       # Applying all routes.
+       route_apply
+
+       exit ${EXIT_OK}
+}
+
 route_add() {
        local ${NETWORK_CONFIG_ROUTES_PARAMS}
 
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --gateway=*)
-                               gateway=$(cli_get_val ${1})
+                               gateway=$(cli_get_val "${1}")
                                ;;
                        --unreachable)
                                unreachable="true"
@@ -40,7 +105,7 @@ route_add() {
                                blackhole="true"
                                ;;
                        --mtu=*)
-                               mtu=$(cli_get_val ${1})
+                               mtu=$(cli_get_val "${1}")
                                ;;
                        *)
                                if isset network; then
@@ -152,7 +217,7 @@ route_remove() {
        local _network
        local error=${EXIT_OK}
 
-       for _network in $@; do
+       for _network in "$@"; do
                # Validate input
                if ! ip_net_is_valid ${_network} && ! ip_is_valid ${_network}; then
                        error "Invalid IP address or network: ${_network}"
@@ -195,7 +260,7 @@ route_list() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --protocol=*)
-                               protocol=$(cli_get_val ${1})
+                               protocol=$(cli_get_val "${1}")
                                ;;
                        *)
                                warning "Unrecognized argument: ${1}"
@@ -270,25 +335,25 @@ route_parse_line() {
        while read arg; do
                case "${arg}" in
                        network=*)
-                               network=$(cli_get_val ${arg})
+                               network=$(cli_get_val "${arg}")
                                ;;
                        gateway=*)
-                               gateway=$(cli_get_val ${arg})
+                               gateway=$(cli_get_val "${arg}")
                                ;;
                        unreachable=*)
-                               unreachable=$(cli_get_val ${arg})
+                               unreachable=$(cli_get_val "${arg}")
                                ;;
                        prohibit=*)
-                               prohibit=$(cli_get_val ${arg})
+                               prohibit=$(cli_get_val "${arg}")
                                ;;
                        blackhole=*)
-                               blackhole=$(cli_get_val ${arg})
+                               blackhole=$(cli_get_val "${arg}")
                                ;;
                        mtu=*)
-                               mtu=$(cli_get_val ${arg})
+                               mtu=$(cli_get_val "${arg}")
                                ;;
                esac
-       done <<< "$(args $@)"
+       done <<< "$(args "$@")"
 
        ### Check if all values are correctly set.
 
@@ -328,41 +393,8 @@ route_parse_line() {
 }
 
 route_apply() {
-       local table="static"
-       local type
-
-       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
+       # Update bird
+       bird_update
 }
 
 route_entry_add() {
@@ -378,19 +410,19 @@ route_entry_add() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --gateway=*)
-                               gateway=$(cli_get_val ${1})
+                               gateway=$(cli_get_val "${1}")
                                ;;
                        --table=*)
-                               table=$(cli_get_val ${1})
+                               table=$(cli_get_val "${1}")
                                ;;
                        --type=*)
-                               type=$(cli_get_val ${1})
+                               type=$(cli_get_val "${1}")
                                ;;
                        --proto=*)
-                               proto=$(cli_get_val ${1})
+                               proto=$(cli_get_val "${1}")
                                ;;
                        --mtu=*)
-                               mtu=$(cli_get_val ${1})
+                               mtu=$(cli_get_val "${1}")
                                ;;
                        *)
                                if isset network; then
@@ -509,7 +541,7 @@ route_table_flush() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --protocol=*)
-                               protocol=$(cli_get_val ${1})
+                               protocol=$(cli_get_val "${1}")
                                ;;
                        *)
                                table="${1}"
@@ -556,7 +588,7 @@ route_table_exists() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --id=*)
-                               _id=$(cli_get_val ${1})
+                               _id=$(cli_get_val "${1}")
                                ;;
                        *)
                                _table=${1}
@@ -588,13 +620,13 @@ route_rule_add() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --lookup=*)
-                               lookup=$(cli_get_val ${1})
+                               lookup=$(cli_get_val "${1}")
                                ;;
                        --priority=*)
-                               priority=$(cli_get_val ${1})
+                               priority=$(cli_get_val "${1}")
                                ;;
                        --protocol=*)
-                               protocols=$(cli_get_val ${1})
+                               protocols=$(cli_get_val "${1}")
 
                                assert isoneof protocols ${IP_SUPPORTED_PROTOCOLS}
                                ;;
@@ -652,16 +684,16 @@ route_rule_exists() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --from=*)
-                               from=$(cli_get_val ${1})
+                               from=$(cli_get_val "${1}")
                                ;;
                        --lookup=*)
-                               lookup=$(cli_get_val ${1})
+                               lookup=$(cli_get_val "${1}")
                                ;;
                        --priority=*)
-                               prio=$(cli_get_val ${1})
+                               prio=$(cli_get_val "${1}")
                                ;;
                        --protocol=*)
-                               proto=$(cli_get_val ${1})
+                               proto=$(cli_get_val "${1}")
                                ;;
                        *)
                                warning "Unrecognized argument: ${1}"