]>
git.ipfire.org Git - people/ms/network.git/blob - src/hooks/ports/ethernet
2db7f48811d4ab3b52f9664381e47dc77742b0d1
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 .
/usr
/lib
/network
/header-port
27 # Selectable speeds in MBit/s
28 VALID_SPEEDS
="10000 1000 100 10"
30 # We can run in full or half duplex
31 VALID_DUPLEXES
="full half"
33 # DEVICE equals the actual MAC address of the device.
34 # If ADDRESS is set, the device will get ADDRESS set for its MAC address.
36 HOOK_SETTINGS
="HOOK ADDRESS DEVICE DUPLEX MTU SPEED"
38 hook_check_settings
() {
41 if isset ADDRESS
; then
46 assert mtu_is_valid
"ethernet" "${MTU}"
50 assert isoneof DUPLEX
${VALID_DUPLEXES}
54 assert isoneof SPEED
${VALID_SPEEDS}
58 hook_parse_cmdline
() {
59 while [ $# -gt 0 ]; do
62 ADDRESS
="$(cli_get_val "${1}")"
64 if ! mac_is_valid
"${ADDRESS}"; then
65 error
"Invalid MAC address: ${ADDRESS}"
71 DUPLEX
="$(cli_get_val "${1}")"
73 if ! isoneof DUPLEX
${VALID_DUPLEXES}; then
74 error
"Invalid duplex mode: ${DUPLEX}"
80 MTU
="$(cli_get_val "${1}")"
82 if ! mtu_is_valid
"ethernet" "${MTU}"; then
83 error
"Invalid MTU: ${MTU}"
89 SPEED
="$(cli_get_val "${1}")"
91 if ! isoneof SPEED
${VALID_SPEEDS}; then
92 error
"Invalid speed: ${SPEED}"
98 error
"Unknown argument: ${1}"
113 local ${HOOK_SETTINGS}
114 if ! port_settings_read
"${port}" ${HOOK_SETTINGS}; then
115 log ERROR
"Could not read settings for port ${port}"
119 # Set MAC address, if needed
120 if isset ADDRESS
; then
121 device_set_address
"${port}" "${ADDRESS}"
126 device_set_mtu
"${port}" "${MTU}"
128 device_set_mtu
"${port}" "${DEFAULT_MTU}"
132 if isset DUPLEX
; then
133 device_set_duplex
"${port}" "${DUPLEX}"
138 device_set_speed
"${port}" "${SPEED}"
141 # Bring up the device
142 device_set_up
"${port}"
151 hook_hotplug_rename
() {
158 # Read in the conifguration file.
159 port_settings_read
"${port}" ${HOOK_SETTINGS}
161 # Get the current MAC address of the device.
162 local address
=$
(device_get_address
${device})
165 # Check if the address matches with the configuration.
166 if list_match
"${address}" ${DEVICE} ${ADDRESS}; then
167 log DEBUG "Device
'${device}' equals port
'${port}'.
"
171 log DEBUG "Device
'${device}' does not equal port
'${port}'.
"