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 HOOK_SETTINGS
="HOOK ADDRESS MIIMON MODE SLAVES"
26 ADDRESS
=$
(mac_generate
)
31 function hook_check
() {
36 assert isinteger MIIMON
43 function hook_edit
() {
48 while [ $# -gt 0 ]; do
51 ADDRESS
=$
(cli_get_val
${1})
54 MIIMON
=$
(cli_get_val
${1})
57 MODE
=$
(cli_get_val
${1})
60 slave
=$
(cli_get_val
${1})
61 SLAVES
="${SLAVES} ${slave}"
64 warning
"Unknown argument '${1}'"
72 # XXX think this must move to _check()
73 if ! isset DEVICE
; then
74 error
"You must set a device name."
78 if ! isset SLAVES
; then
79 error
"You need to specify at least one slave port (e.g. --slave=port0)."
84 for slave
in $
(unquote
${SLAVES}); do
85 if ! device_is_ethernet_compatible
${slave}; then
86 error
"The slave device '${slave}' is not able to transport ethernet frames"
91 # Remove any whitespace
92 SLAVES
=$
(echo ${SLAVES})
94 port_settings_write
"${port}" ${HOOK_SETTINGS}
99 function hook_create
() {
103 # Exit silently if the device already exists
104 device_exists
"${port}" && exit ${EXIT_OK}
106 port_settings_read
"${port}" ${HOOK_SETTINGS}
108 # Create the bonding devices
109 bonding_create
"${port}" \
110 --address="${ADDRESS}" \
111 --mode="${MODE}" ||
exit ${EXIT_ERROR}
113 bonding_set_miimon
"${port}" "${MIIMON}"
118 function hook_remove
() {
122 port_settings_read
"${port}" ${HOOK_SETTINGS}
124 # Remove the bonding device
125 if device_exists
"${port}"; then
126 bonding_remove
"${port}"
134 port_settings_read
"${port}" ${HOOK_SETTINGS}
136 # Execute the default action
137 hook_default_up
"${port}"
139 # Bring up all slaves
141 for slave
in $
(unquote
${SLAVES}); do
146 function hook_down
() {
150 port_settings_read
"${port}" ${HOOK_SETTINGS}
152 # Bring down all slaves
154 for slave
in $
(unquote
${SLAVES}); do
158 # Execute the default action
159 hook_default_down
"${port}"
162 function hook_hotplug
() {
166 case "$(hotplug_action)" in
168 # Handle events of the same interface
169 if hotplug_event_port_is_interface
"${port}"; then
171 port_settings_read
"${port}" ${HOOK_SETTINGS}
173 # Bring up all slaves
174 # Attach those which already exist and try to create
175 # those which don't exist yet. They will be attached
176 # in their own hotplug event.
178 for slave
in $
(unquote
${SLAVES}); do
179 if device_exists
"${slave}"; then
180 bonding_enslave_device
"${port}" "${slave}"
182 port_create
"${slave}"
188 # Handle slave devices that have just been created and
190 elif hotplug_event_interface_is_slave_of_port
"${port}"; then
191 bonding_enslave_device
"${port}" "${INTERFACE}"
193 # If the parent device has been set up, we will
194 # bring up the slave device as well.
195 if device_is_up
"${port}"; then
196 port_up
"${INTERFACE}"
204 if hotplug_event_port_is_interface
"${port}"; then
205 # Bring down all slaves after the parent device went away
207 for slave
in $
(port_get_slaves
"${port}"); do
208 port_remove
"${slave}"
216 exit ${EXIT_NOT_HANDLED}