]>
git.ipfire.org Git - people/arne_f/network.git/blob - hooks/ports/bonding
9e0443539590575263dbb73c18e91fea33a92b29
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 .
/lib
/network
/header-port
24 HOOK_SETTINGS
="HOOK DEVICE_MAC MIIMON MODE SLAVES"
26 DEVICE_MAC
=$
(mac_generate
)
30 assert isset DEVICE_MAC
31 assert ismac DEVICE_MAC
34 assert isinteger MIIMON
45 while [ $# -gt 0 ]; do
48 DEVICE_MAC
=${1#--mac=}
58 SLAVES
="${SLAVES} $(macify ${slave})"
61 warning
"Unknown argument '${1}'"
69 # XXX think this must move to _check()
70 if ! isset DEVICE
; then
71 error
"You must set a device name."
75 if ! isset SLAVES
; then
76 error
"You need to specify at least one slave port (e.g. --slave=port0)."
81 for slave
in ${SLAVES}; do
82 if ! device_is_real $
(devicify
${slave}); then
83 error
"Slave device '${slave}' is not an ethernet device."
88 # Remove any whitespace
89 SLAVES
=$
(echo ${SLAVES})
91 config_write $
(port_file
${port}) ${HOOK_SETTINGS}
99 config_read $
(port_file
${device})
101 if device_exists
${device}; then
102 log DEBUG
"Bonding device '${device}' does already exist."
104 device_set_address
${DEVICE_MAC}
105 device_set_up
${device}
110 bonding_create
${device} ${DEVICE_MAC}
112 if [ -n "${MODE}" ]; then
113 bonding_set_mode
${device} ${MODE}
116 bonding_set_miimon
${device} ${MIIMON}
119 for slave
in ${SLAVES}; do
120 if ! device_exists $
(devicify
${slave}); then
121 warning_log
"${device}: configured slave '${slave}' is not available."
125 slave
=$
(devicify
${slave})
128 bonding_enslave_device
${device} ${slave}
137 bonding_remove
${device}
140 for slave
in ${SLAVES}; do
141 device_set_down
${slave}
155 local status
=$
(device_get_status
${port})
156 printf "${DEVICE_PRINT_LINE1}" "Status:" "$(echo -ne ${STATUS_COLOUR[${status}]}${STATUS_TEXT[${status}]}${COLOUR_NORMAL})"
158 cli_headline
" Ethernet information:"
159 printf "${DEVICE_PRINT_LINE1}" "Address:" $
(device_get_address
${port})
160 printf "${DEVICE_PRINT_LINE1}" "MTU:" $
(device_get_mtu
${port})
161 printf "${DEVICE_PRINT_LINE1}" "Promisc mode:" $
(device_is_promisc
${port} && echo "yes" ||
echo "no")
163 if device_is_bonded
${port}; then
164 cli_headline
" Bonding information:"
166 local master
=$
(bonding_slave_get_master
${port})
167 printf "${DEVICE_PRINT_LINE1}" "Master:" "${master}"
170 if [ "$(bonding_get_active_slave ${master})" = "${port}" ]; then
175 printf "${DEVICE_PRINT_LINE1}" "Active slave:" "${active}"
178 if device_is_bonding
${port}; then
179 cli_headline
" Bonding information:"
181 printf "${DEVICE_PRINT_LINE1}" "Mode:" "$(bonding_get_mode ${port})"
186 local slave_active
=$
(bonding_get_active_slave
${port})
187 for slave
in $
(bonding_get_slaves
${port}); do
188 printf "${DEVICE_PRINT_LINE1}" "Slave$([ "${slave}" = "${slave_active}" ] && echo " (active)"):" "${slave}"
192 cli_headline
" Statistics:"
193 printf "${DEVICE_PRINT_LINE1}" "Received:" \
194 "$(beautify_bytes $(device_get_rx_bytes ${port})) ($(device_get_rx_packets ${port}) packets)"
195 printf "${DEVICE_PRINT_LINE1}" "Sent:" \
196 "$(beautify_bytes $(device_get_tx_bytes ${port})) ($(device_get_tx_packets ${port}) packets)"