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
24 # DEVICE equals the actual MAC address of the device.
25 # If ADDRESS is set, the device will get ADDRESS set for its MAC address.
27 HOOK_SETTINGS
="HOOK ADDRESS ADVERTISED_LINK_SPEEDS DEVICE MTU"
29 hook_check_settings
() {
32 if isset ADDRESS
; then
37 assert mtu_is_valid
"ethernet" "${MTU}"
42 for mode
in ${MODES}; do
43 assert
[ -n "${DEVICE_LINK_SPEEDS[${mode}]}" ]
48 hook_parse_cmdline
() {
49 while [ $# -gt 0 ]; do
52 ADDRESS
="$(cli_get_val "${1}")"
54 if ! mac_is_valid
"${ADDRESS}"; then
55 error
"Invalid MAC address: ${ADDRESS}"
60 --advertised-link-speeds=*)
61 ADVERTISED_LINK_SPEEDS
="$(cli_get_val "${1}")"
64 for speed
in ${ADVERTISED_LINK_SPEEDS}; do
65 if [ -z "${DEVICE_LINK_SPEEDS[${speed}]}" ]; then
66 error
"Unsupported link speed: ${speed}"
73 MTU
="$(cli_get_val "${1}")"
75 if ! mtu_is_valid
"ethernet" "${MTU}"; then
76 error
"Invalid MTU: ${MTU}"
82 error
"Unknown argument: ${1}"
97 local ${HOOK_SETTINGS}
98 if ! port_settings_read
"${port}" ${HOOK_SETTINGS}; then
99 log ERROR
"Could not read settings for port ${port}"
103 # Set MAC address, if needed
104 if isset ADDRESS
; then
105 device_set_address
"${port}" "${ADDRESS}"
110 device_set_mtu
"${port}" "${MTU}"
112 device_set_mtu
"${port}" "${DEFAULT_MTU}"
116 if isset ADVERTISED_LINK_SPEEDS
; then
117 device_advertise_link_speeds
"${port}" ${ADVERTISED_LINK_SPEEDS}
120 # Enable hardware offloading
121 device_auto_offloading
"${port}"
123 # Bring up the device
124 device_set_up
"${port}"
133 hook_hotplug_rename
() {
140 # Read in the conifguration file.
141 port_settings_read
"${port}" ${HOOK_SETTINGS}
143 # Get the current MAC address of the device.
144 local address
=$
(device_get_address
${device})
147 # Check if the address matches with the configuration.
148 if list_match
"${address}" ${DEVICE} ${ADDRESS}; then
149 log DEBUG "Device
'${device}' equals port
'${port}'.
"
153 log DEBUG "Device
'${device}' does not equal port
'${port}'.
"