]>
git.ipfire.org Git - people/stevee/network.git/blob - src/functions/functions.bonding
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 BONDING_ALLOWED_MODES
="balance-rr active-backup balance-xor broadcast 802.3ad \
23 balance-tlb balance-alb"
24 BONDING_MASTERS
="/sys/class/net/bonding_masters"
36 local mode
="balance-rr"
38 while [ $# -gt 0 ]; do
41 address
=$
(cli_get_val
${1})
44 mode
=$
(cli_get_val
${1})
47 error
"Unrecognized argument: ${1}"
54 if isset address
; then
55 if ! ismac address
; then
56 log ERROR
"Invalid mac address: ${address}"
61 if ! list_match
"${mode}" ${BONDING_ALLOWED_MODES}; then
62 log ERROR
"Bonding mode is not supported: ${mode}"
63 log ERROR
"Valid modes are: ${BONDING_ALLOWED_MODES}"
67 # Initialize the bonding driver just
71 # Create the bonding device.
72 fwrite
"${BONDING_MASTERS}" "+${device}"
75 if [ ${ret} -eq ${EXIT_OK} ]; then
76 log DEBUG
"Successfully created bonding device '${device}'"
78 log ERROR
"Could not create bonding device '${device}'"
82 # Set the mode of the bonding device.
83 bonding_set_mode
"${device}" "${mode}"
85 if isset address
; then
86 device_set_address
"${device}" "${address}"
96 if ! device_exists
${device}; then
100 # Set device down if not already done.
101 device_set_down
${device}
104 fwrite
"${BONDING_MASTERS}" "-${device}"
107 if [ ${ret} -eq ${EXIT_OK} ]; then
108 log DEBUG
"Successfully removed bonding device '${device}'"
110 log ERROR
"Could not remove bonding device '${device}'"
122 read mode mode_num
< ${SYS_CLASS_NET}/${device}/bonding
/mode
132 if fwrite
"${SYS_CLASS_NET}/${device}/bonding/mode" "${mode}"; then
133 log DEBUG
"Set mode of bond '${device}' to '${mode}'"
135 log ERROR
"Could not set mode of bond '${device}' to '${mode}'"
142 bonding_enslave_device
() {
151 # Slave must be down to be enslaved.
152 device_set_down
${device}
154 if device_is_up
${device}; then
155 log ERROR
"Cannot enslave '${slave}' because it cannot be set down."
160 fwrite
"${SYS_CLASS_NET}/${device}/bonding/slaves" "+${slave}"
163 if [ ${ret} -eq ${EXIT_OK} ]; then
164 log DEBUG
"Successfully enslaved '${slave}' to '${device}'"
166 log ERROR
"Could not enslave '${slave}' to '${device}'"
173 bonding_get_slaves
() {
179 while [ $# -gt 0 ]; do
185 error
"Unrecognized argument: ${1}"
192 fread
${SYS_CLASS_NET}/${device}/bonding/${file}
197 bonding_get_lacp_rate
() {
202 read -r rate rateno \
203 < ${SYS_CLASS_NET}/${device}/bonding
/lacp_rate
209 bonding_get_miimon
() {
213 fread
${SYS_CLASS_NET}/${device}/bonding
/miimon
216 bonding_set_miimon
() {
223 print
"${miimon}" > ${SYS_CLASS_NET}/${device}/bonding/miimon
226 bonding_slave_get_master() {
230 device_is_bonded ${slave} || return ${EXIT_ERROR}
232 local master=$(fread ${SYS_CLASS_NET}/${slave}/master/ifindex)
233 if isset master; then
234 device_ifindex_to_name ${master}