# 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"
blackhole="true"
;;
--mtu=*)
- mtu=$(cli_get_val ${1})
+ mtu=$(cli_get_val "${1}")
;;
*)
if isset network; then
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}"
while [ $# -gt 0 ]; do
case "${1}" in
--protocol=*)
- protocol=$(cli_get_val ${1})
+ protocol=$(cli_get_val "${1}")
;;
*)
warning "Unrecognized argument: ${1}"
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.
}
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() {
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
while [ $# -gt 0 ]; do
case "${1}" in
--protocol=*)
- protocol=$(cli_get_val ${1})
+ protocol=$(cli_get_val "${1}")
;;
*)
table="${1}"
while [ $# -gt 0 ]; do
case "${1}" in
--id=*)
- _id=$(cli_get_val ${1})
+ _id=$(cli_get_val "${1}")
;;
*)
_table=${1}
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}
;;
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}"