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
26 "ADVERTISED_LINK_SPEEDS"
32 hook_check_settings
() {
35 # Invalid MAC addresses are not allowed
36 assert not isoneof DEVICE
00:00:00:00:00:00 ff
:ff
:ff
:ff
:ff
:ff
38 if isset ADDRESS
; then
43 assert mtu_is_valid
"ethernet" "${MTU}"
48 for mode
in ${MODES}; do
49 assert
[ -n "${DEVICE_LINK_SPEEDS[${mode}]}" ]
54 hook_parse_cmdline
() {
55 while [ $# -gt 0 ]; do
58 ADDRESS
="$(cli_get_val "${1}")"
60 if ! mac_is_valid
"${ADDRESS}"; then
61 error
"Invalid MAC address: ${ADDRESS}"
66 --advertised-link-speeds=*)
67 ADVERTISED_LINK_SPEEDS
="$(cli_get_val "${1}")"
70 for speed
in ${ADVERTISED_LINK_SPEEDS}; do
71 if [ -z "${DEVICE_LINK_SPEEDS[${speed}]}" ]; then
72 error
"Unsupported link speed: ${speed}"
79 MTU
="$(cli_get_val "${1}")"
81 if ! mtu_is_valid
"ethernet" "${MTU}"; then
82 error
"Invalid MTU: ${MTU}"
88 OFFLOADING
="$(cli_get_val "${1}")"
90 if enabled OFFLOADING
; then
92 elif disabled OFFLOADING
; then
95 error
"Invalid value for offloading: ${OFFLOADING}"
101 error
"Unknown argument: ${1}"
109 # This function is only called automatically by hotplug to create
110 # a new ethernet port.
118 local DEVICE
="$(device_get_address "${device}")"
120 if ! port_settings_write
"${port}"; then
121 log ERROR
"Could not write settings for port ${port}"
135 local ${HOOK_SETTINGS[*]}
136 if ! port_settings_read
"${port}"; then
137 log ERROR
"Could not read settings for port ${port}"
141 # Set MAC address, if needed
142 if isset ADDRESS
; then
143 device_set_address
"${port}" "${ADDRESS}"
148 device_set_mtu
"${port}" "${MTU}"
150 device_set_mtu
"${port}" "${DEFAULT_MTU}"
154 if isset ADVERTISED_LINK_SPEEDS
; then
155 device_advertise_link_speeds
"${port}" ${ADVERTISED_LINK_SPEEDS}
158 # Auto-enable or disable hardware offloading
159 if ! isset OFFLOADING || enabled OFFLOADING
; then
160 offloading_auto
"${port}"
162 offloading_disable_all
"${port}"
165 # Bring up the device
166 device_set_up
"${port}"
175 hook_hotplug_rename
() {
176 hook_hotplug_rename_by_address
"$@"