HOOK_MANPAGE="network-zone-bridge"
-HOOK_SETTINGS="HOOK STP STP_FORWARD_DELAY STP_HELLO STP_MAXAGE"
-HOOK_SETTINGS="${HOOK_SETTINGS} STP_PRIORITY MAC MTU"
-
-HOOK_PORT_SETTINGS="COST PRIORITY"
+HOOK_SETTINGS=(
+ "ADDRESS"
+ "STP"
+ "STP_FORWARD_DELAY"
+ "STP_HELLO STP_MAXAGE"
+ "STP_PRIORITY"
+ "MTU"
+)
+
+HOOK_PORT_SETTINGS=(
+ "COST"
+ "PRIORITY"
+)
# Default values
-MAC=""
-MTU=1500
-STP="on"
-STP_FORWARD_DELAY=0
-STP_HELLO=2
-STP_MAXAGE=20
-STP_PRIORITY=512
+DEFAULT_STP="on"
+DEFAULT_STP_FORWARD_DELAY=0
+DEFAULT_STP_HELLO=2
+DEFAULT_STP_MAXAGE=20
+DEFAULT_STP_PRIORITY=512
hook_check_settings() {
- assert ismac MAC
+ assert ismac ADDRESS
+ assert isset MTU && assert mtu_is_valid "ethernet" "${MTU}"
+
+ # Spanning Tree Protocol
assert isbool STP
assert isinteger STP_HELLO
assert isinteger STP_FORWARD_DELAY
assert isinteger STP_PRIORITY
- assert isinteger MTU
}
hook_parse_cmdline() {
while [ $# -gt 0 ]; do
case "${1}" in
- --stp=*)
- STP=${1#--stp=}
+ --address=*)
+ ADDRESS="$(cli_get_val "${1}")"
+
+ if ! mac_is_valid "${ADDRESS}"; then
+ error "Invalid MAC address: ${ADDRESS}"
+ return ${EXIT_ERROR}
+ fi
;;
- --stp-hello=*)
- STP_HELLO=${1#--stp-hello=}
+
+ --mtu=*)
+ MTU="$(cli_get_val "${1}")"
+
+ if ! mtu_is_valid "ethernet" "${MTU}"; then
+ error "Invalid MTU: ${MTU}"
+ return ${EXIT_ERROR}
+ fi
;;
+
+ --stp=*)
+ STP="$(cli_get_val "${1}")"
+
+ if enabled STP; then
+ STP="on"
+ elif disabled STP; then
+ STP="off"
+ else
+ error "Invalid value for STP: ${STP}"
+ return ${EXIT_ERROR}
+ fi
+ ;;
+
--stp-forward-delay=*)
- STP_FORWARD_DELAY=${1#--stp-forward-delay=}
+ STP_FORWARD_DELAY="$(cli_get_val "${1}")"
+
+ if ! isinteger STP_FORWARD_DELAY; then
+ error "Invalid STP forwarding delay: ${STP_FORWARD_DELAY}"
+ return ${EXIT_ERROR}
+ fi
;;
- --stp-priority=*)
- STP_PRIORITY=${1#--stp-priority=}
+
+ --stp-hello=*)
+ STP_HELLO="$(cli_get_val "${1}")"
+
+ if ! isinteger STP_HELLO; then
+ error "Invalid STP hello time: ${STP_HELLO}"
+ return ${EXIT_ERROR}
+ fi
;;
- --mtu=*)
- MTU=${1#--mtu=}
+
+ --stp-max-age=*)
+ STP_MAXAGE="$(cli_get_val "${1}")"
+
+ if ! isinteger STP_MAXAGE; then
+ error "Invalid STP max age: ${STP_MAXAGE}"
+ return ${EXIT_ERROR}
+ fi
;;
- --mac=*)
- MAC=${1#--mac=}
+
+ --stp-priority=*)
+ STP_PRIORITY="$(cli_get_val "${1}")"
+
+ if ! isinteger STP_PRIORITY; then
+ error "Invalid STP priority: ${STP_PRIORITY}"
+ return ${EXIT_ERROR}
+ fi
;;
+
*)
- warning "Ignoring unknown option '${1}'"
+ error "Unknown argument: ${1}"
+ return ${EXIT_ERROR}
;;
esac
shift
done
- # Generate a random MAC address if the user passed no one
- isset MAC || MAC="$(mac_generate)"
+ # Generate a random MAC address if the user passed none
+ if ! isset ADDRESS; then
+ ADDRESS="$(mac_generate)"
+ fi
+
+ return ${EXIT_OK}
}
hook_up() {
# Create the bridge if it does not already exist.
if ! device_exists "${zone}"; then
bridge_create "${zone}" \
- --address="${MAC}" \
+ --address="${ADDRESS}" \
--mtu="${MTU}"
fi
# set our bridges to promisc mode.
device_set_promisc "${zone}" on
- # Bring up all ports
- zone_ports_create "${zone}"
- zone_ports_up "${zone}"
-
# Bring up all configurations
zone_configs_up "${zone}"
exit ${EXIT_OK}
}
-hook_hotplug() {
- local zone="${1}"
- assert isset zone
-
- case "$(hotplug_action)" in
- add)
- # Handle ports of this zone that have just been added
- if hotplug_event_interface_is_port_of_zone "${zone}"; then
- # Bring up the zone if it is enabled but not active, yet.
- if zone_is_enabled "${zone}" && ! zone_is_active "${zone}"; then
- zone_start "${zone}"
- fi
-
- hook_port_up "${zone}" "${INTERFACE}"
- fi
- ;;
- remove)
- # Handle ports of this zone that have just been removed
- if hotplug_event_interface_is_port_of_zone "${zone}"; then
- hook_port_down "${zone}" "${INTERFACE}"
- fi
- ;;
- *)
- exit ${EXIT_NOT_HANDLED}
- ;;
- esac
-
- exit ${EXIT_OK}
-}
-
hook_down() {
local zone="${1}"
assert isset zone
exit ${EXIT_OK}
}
+hook_hotplug() {
+ local zone="${1}"
+ assert isset zone
+
+ case "$(hotplug_action)" in
+ add)
+ # Attach all ports when zone is coming up
+ if hotplug_event_interface_is_zone "${zone}"; then
+ # Bring up all ports
+ local port
+ for port in $(zone_get_ports "${zone}"); do
+ log DEBUG "Trying to attach port ${port} to ${zone}"
+
+ hook_port_up "${zone}" "${port}"
+ done
+
+ # Handle ports of this zone that have just been added
+ elif hotplug_event_interface_is_port_of_zone "${zone}"; then
+ # Attach the device if the parent bridge is up
+ if zone_is_active "${zone}"; then
+ hook_port_up "${zone}" "${INTERFACE}"
+ fi
+ fi
+ ;;
+
+ remove)
+ if hotplug_event_interface_is_zone "${zone}"; then
+ # Bring down/destroy all ports
+ local port
+ for port in $(zone_get_ports "${zone}"); do
+ log DEBUG "Trying to detach port ${port} from ${zone}"
+
+ hook_port_down "${zone}" "${port}"
+ done
+
+ # Handle ports of this zone that have just been removed
+ elif hotplug_event_interface_is_port_of_zone "${zone}"; then
+ hook_port_down "${zone}" "${INTERFACE}"
+ fi
+ ;;
+
+ *)
+ exit ${EXIT_NOT_HANDLED}
+ ;;
+ esac
+
+ exit ${EXIT_OK}
+}
+
hook_check_port_settings() {
if isset COST; then
assert isinteger COST
PRIORITY="$(cli_get_val "${arg}")"
;;
esac
- done <<< "$(args $@)"
+ done <<< "$(args "$@")"
if ! zone_port_settings_write "${zone}" "${port}"; then
exit ${EXIT_ERROR}
}
hook_port_edit() {
- hook_port_attach $@
+ hook_port_attach "$@"
}
hook_port_up() {
if ! device_exists "${port}"; then
port_create "${port}"
- exit ${EXIT_OK}
+ return ${EXIT_OK}
fi
# Read configuration values
zone_port_settings_read "${zone}" "${port}" ${HOOK_PORT_SETTINGS}
+ # Make sure that the port is up
+ port_up "${port}"
+
# Attach the port to the bridge
bridge_attach_device "${zone}" "${port}"
stp_port_set_cost "${zone}" "${port}" "${COST}"
fi
- # TODO Apply priority (#10609)
-
- # Make sure that the port is up
- port_up "${port}"
+ if isset PRIORITY; then
+ stp_port_set_priority "${zone}" "${port}" "${PRIORITY}"
+ fi
- exit ${EXIT_OK}
+ return ${EXIT_OK}
}
hook_port_down() {
port_down "${port}"
fi
- exit ${EXIT_OK}
+ return ${EXIT_OK}
}
hook_port_status() {