#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2010 Michael Tremer & Christian Schmidt # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### . /usr/lib/network/header-port HOOK_SETTINGS="HOOK ADDRESS MIIMON MODE SLAVES" ADDRESS=$(mac_generate) SLAVES="" MIIMON=100 MODE="balance-rr" function hook_check() { assert isset ADDRESS assert ismac ADDRESS #assert isset SLAVES assert isinteger MIIMON } function hook_create() { hook_edit $@ } function hook_edit() { local port=${1} assert isset port shift while [ $# -gt 0 ]; do case "${1}" in --address=*) ADDRESS=$(cli_get_val ${1}) ;; --miimon=*) MIIMON=$(cli_get_val ${1}) ;; --mode=*) MODE=$(cli_get_val ${1}) ;; --slave=*) slave=$(cli_get_val ${1}) SLAVES="${SLAVES} ${slave}" ;; *) warning "Unknown argument '${1}'" ;; esac shift done DEVICE=${port} # XXX think this must move to _check() if ! isset DEVICE; then error "You must set a device name." exit ${EXIT_ERROR} fi if ! isset SLAVES; then error "You need to specify at least one slave port (e.g. --slave=port0)." exit ${EXIT_ERROR} fi local slave for slave in $(unquote ${SLAVES}); do if ! device_is_ethernet ${slave}; then error "Slave device '${slave}' is not an ethernet device." exit ${EXIT_ERROR} fi done # Remove any whitespace SLAVES=$(echo ${SLAVES}) port_settings_write "${port}" ${HOOK_SETTINGS} exit ${EXIT_OK} } function hook_up() { local device="${1}" assert isset device port_settings_read "${device}" ${HOOK_SETTINGS} if ! device_exists ${device}; then bonding_create "${device}" \ --address="${ADDRESS}" \ --mode="${MODE}" || exit ${EXIT_ERROR} fi device_set_address "${device}" "${ADDRESS}" bonding_set_miimon "${device}" "${MIIMON}" device_set_up "${device}" local slave for slave in $(unquote ${SLAVES}); do if ! device_exists ${slave}; then log WARNING "Cannot enslave '${slave}' to '${device}' as it is not available" continue fi bonding_enslave_device "${device}" "${slave}" done # Bring up the device. device_set_up "${device}" exit ${EXIT_OK} } function hook_down() { local device="${1}" bonding_remove "${device}" local slave for slave in ${SLAVES}; do device_set_down "${slave}" done exit ${EXIT_OK} }