#!/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 # Default MTU DEFAULT_MTU=1500 # Selectable speeds in MBit/s VALID_SPEEDS="10000 1000 100 10" # We can run in full or half duplex VALID_DUPLEXES="full half" # DEVICE equals the actual MAC address of the device. # If ADDRESS is set, the device will get ADDRESS set for its MAC address. HOOK_SETTINGS="HOOK ADDRESS DEVICE DUPLEX MTU SPEED" hook_check_settings() { assert ismac DEVICE if isset ADDRESS; then assert ismac ADDRESS fi if isset MTU; then assert mtu_is_valid "ethernet" "${MTU}" fi if isset DUPLEX; then assert isoneof DUPLEX ${VALID_DUPLEXES} fi if isset SPEED; then assert isoneof SPEED ${VALID_SPEEDS} fi } hook_parse_cmdline() { while [ $# -gt 0 ]; do case "${1}" in --address=*) ADDRESS="$(cli_get_val "${1}")" if ! mac_is_valid "${ADDRESS}"; then error "Invalid MAC address: ${ADDRESS}" return ${EXIT_ERROR} fi ;; --duplex=*) DUPLEX="$(cli_get_val "${1}")" if ! isoneof DUPLEX ${VALID_DUPLEXES}; then error "Invalid duplex mode: ${DUPLEX}" return ${EXIT_ERROR} fi ;; --mtu=*) MTU="$(cli_get_val "${1}")" if ! mtu_is_valid "ethernet" "${MTU}"; then error "Invalid MTU: ${MTU}" return ${EXIT_ERROR} fi ;; --speed=*) SPEED="$(cli_get_val "${1}")" if ! isoneof SPEED ${VALID_SPEEDS}; then error "Invalid speed: ${SPEED}" return ${EXIT_ERROR} fi ;; *) error "Unknown argument: ${1}" return ${EXIT_ERROR} ;; esac shift done } hook_create() { return ${EXIT_OK} } hook_up() { local port="${1}" local ${HOOK_SETTINGS} if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then log ERROR "Could not read settings for port ${port}" return ${EXIT_ERROR} fi # Set MAC address, if needed if isset ADDRESS; then device_set_address "${port}" "${ADDRESS}" fi # Set MTU if isset MTU; then device_set_mtu "${port}" "${MTU}" else device_set_mtu "${port}" "${DEFAULT_MTU}" fi # Set duplex mode if isset DUPLEX; then device_set_duplex "${port}" "${DUPLEX}" fi # Set speed if isset SPEED; then device_set_speed "${port}" "${SPEED}" fi # Bring up the device device_set_up "${port}" exit ${EXIT_OK} } hook_remove() { exit ${EXIT_OK} } hook_hotplug_rename() { local port=${1} assert isset port local device=${2} assert isset device # Read in the conifguration file. port_settings_read "${port}" ${HOOK_SETTINGS} # Get the current MAC address of the device. local address=$(device_get_address ${device}) assert isset address # Check if the address matches with the configuration. if list_match "${address}" ${DEVICE} ${ADDRESS}; then log DEBUG "Device '${device}' equals port '${port}'." exit ${EXIT_OK} fi log DEBUG "Device '${device}' does not equal port '${port}'." exit ${EXIT_ERROR} }