From 478de6f9fdb68c5679f61286c3e477adba7ac8d1 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 13 Oct 2012 17:14:09 +0000 Subject: [PATCH] route: Allow to specify MTU along the path to the destination. --- functions.constants | 2 +- functions.firewall | 3 +-- functions.route | 48 ++++++++++++++++++++++++++++++++++++----- hooks/ports/wireless-ap | 1 - hooks/zones/switch | 1 + man/network-route.8.in | 12 +++++++---- 6 files changed, 54 insertions(+), 13 deletions(-) diff --git a/functions.constants b/functions.constants index bb83a16f..0a9718a5 100644 --- a/functions.constants +++ b/functions.constants @@ -45,7 +45,7 @@ DB_CONNECTION_FILE="${LOG_DIR}/connections.db" # (Static) route settings. NETWORK_CONFIG_ROUTES="${NETWORK_CONFIG_DIR}/routes" -NETWORK_CONFIG_ROUTES_PARAMS="network gateway unreachable prohibit blackhole" +NETWORK_CONFIG_ROUTES_PARAMS="network gateway unreachable prohibit blackhole mtu" # Proper error codes EXIT_OK=0 diff --git a/functions.firewall b/functions.firewall index ba579439..ce42e0f3 100644 --- a/functions.firewall +++ b/functions.firewall @@ -62,8 +62,7 @@ function firewall_start() { # created, we will add a custom policy to every single # zone. - # XXX TODO - #policy_zone_add ${zone} + policy_zone_add ${zone} done # Load the new ruleset. diff --git a/functions.route b/functions.route index fca85437..d72a1071 100644 --- a/functions.route +++ b/functions.route @@ -46,6 +46,9 @@ function route_add() { --blackhole) blackhole="true" ;; + --mtu=*) + mtu=$(cli_get_val ${1}) + ;; *) network=${1} ;; @@ -104,6 +107,11 @@ function route_add() { fi fi + if isset mtu && ! isinteger mtu; then + error "MTU must be an integer number: ${mtu}" + return ${EXIT_ERROR} + fi + local line list_append line "network=\"${network}\"" @@ -121,6 +129,11 @@ function route_add() { fi done + # Add MTU (if set). + if isset mtu; then + list_append line "mtu=\"${mtu}\"" + fi + # Write line to file. print "${line}" >> ${NETWORK_CONFIG_ROUTES} @@ -180,8 +193,8 @@ function route_list() { return ${EXIT_OK} fi - local format="%-40s %-20s" - print "${format}" "NETWORK/HOST" "GATEWAY" + local format="%-40s %-20s %-4s" + print "${format}" "NETWORK/HOST" "GATEWAY" "MTU" local ${NETWORK_CONFIG_ROUTES_PARAMS} local line @@ -203,7 +216,12 @@ function route_list() { [ "${protocol}" = "${proto}" ] || continue fi - print "${format}" "${network}" "${gateway}" + # Print something when no MTU was set. + if ! isset mtu; then + mtu="-" + fi + + print "${format}" "${network}" "${gateway}" "${mtu}" done < ${NETWORK_CONFIG_ROUTES} } @@ -250,6 +268,9 @@ function route_parse_line() { blackhole=*) blackhole=$(cli_get_val ${arg}) ;; + mtu=*) + mtu=$(cli_get_val ${arg}) + ;; esac done <<< "$(args $@)" @@ -274,6 +295,11 @@ function route_parse_line() { [ ${counter} -eq 1 ] || return ${EXIT_ERROR} fi + # mtu must be an integer number. + if isset mtu; then + isinteger mtu || return ${EXIT_ERROR} + fi + return ${EXIT_OK} } @@ -303,7 +329,7 @@ function route_apply() { # Add the route. route_entry_add ${network} --table="static" --proto="static" \ - --type="${type}" --gateway="${gateway}" + --type="${type}" --gateway="${gateway}" --mtu="${mtu}" local ret=$? if [ ${ret} -ne ${EXIT_OK} ]; then @@ -321,6 +347,7 @@ function route_entry_add() { local proto local table local type="unicast" + local mtu local command @@ -338,6 +365,9 @@ function route_entry_add() { --proto=*) proto=$(cli_get_val ${1}) ;; + --mtu=*) + mtu=$(cli_get_val ${1}) + ;; *) if isset network; then warning "Unrecognized argument: ${1}" @@ -352,6 +382,9 @@ function route_entry_add() { # Validate input. assert isoneof type unicast broadcast unreachable prohibit blackhole assert ip_is_network ${network} + if isset mtu; then + assert isinteger mtu + fi # Detect the protocol of the given network. local protocol=$(ip_detect_protocol ${network}) @@ -391,7 +424,12 @@ function route_entry_add() { list_append command "proto ${proto}" fi - cmd "${command}" + # Add MTU. + if isset mtu; then + list_append command "mtu ${mtu}" + fi + + cmd_quiet "${command}" } function route_table_create() { diff --git a/hooks/ports/wireless-ap b/hooks/ports/wireless-ap index 33e0f975..391e6828 100755 --- a/hooks/ports/wireless-ap +++ b/hooks/ports/wireless-ap @@ -149,7 +149,6 @@ function _edit() { function _up() { local port=${1} - assert isset port config_read $(port_file ${port}) diff --git a/hooks/zones/switch b/hooks/zones/switch index d00116f9..f1718e73 100755 --- a/hooks/zones/switch +++ b/hooks/zones/switch @@ -128,6 +128,7 @@ function _status() { # cli_print_fmt1 2 "Topology change count" \ # "$(stp_bridge_get_topology_change_count ${zone})" # cli_space + : else cli_print 2 "Disabled" cli_space diff --git a/man/network-route.8.in b/man/network-route.8.in index baaf12f4..de439399 100644 --- a/man/network-route.8.in +++ b/man/network-route.8.in @@ -4,7 +4,7 @@ network-route \- Network Route Configuration Control Program .SH SYNOPSIS -\fBnetwork [OPTIONS] route add [--gateway=..., --unreachable, --prohibit, --blackhole]\fR +\fBnetwork [OPTIONS] route add <--gateway=..., --unreachable, --prohibit, --blackhole> [--mtu=N]\fR .P \fBnetwork [OPTIONS] route remove \fR .P @@ -18,7 +18,7 @@ It is possible to create and remove static routes. .SH COMMANDS The \fBnetwork route\fR command offers various sub commands: -\fBadd [--gateway=..., --unreachable, --prohibit, --blackhole]\fR +\fBadd <--gateway=..., --unreachable, --prohibit, --blackhole> [--mtu=N]\fR .RS 4 A new route may be added by the \fBadd\fR command. It is always required to pass a valid network prefix (\fB\fR), which @@ -30,6 +30,9 @@ prefix is. .PP Use \fB--unreachable\fR, \fB--prohibit\fR, \fB--blackhole\fR can be used to create of that type. See \fBROUTE TYPES\fR below for more information about these options. +.PP +The optional \fB--mtu\fR parameter defines the MTU along the path to the +destination and must be an integer number. .RE .PP @@ -41,11 +44,12 @@ A route can be removed with this command. .RE .PP -\fBlist [--ipv6|--ipv4]\fR +\fBlist [--protocol=ipv6|ipv4]\fR .RS 4 Shows a list of all configured routes. .PP -Pass the protocol as shown above to filter. +Pass the protocol option to filter the output only for the given +protocol. .RE .PP -- 2.39.2