]>
git.ipfire.org Git - people/arne_f/network.git/blob - 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 function bonding_init
() {
23 if ! grep -q "^bonding" /proc
/modules
; then
30 function bonding_create
() {
34 # Make sure the bonding is initialized
37 [ -z "${mac}" ] && mac
=$
(mac_generate
)
39 log INFO
"Creating bonding device '${device}' (${mac})."
41 echo "+${device}" > /sys
/class
/net
/bonding_masters
42 device_set_address
${device} ${mac}
43 device_set_up
${device}
46 function bonding_remove
() {
47 local device
=$
(devicify
${1})
51 log INFO
"Remove bonding device '${device}'."
53 device_set_down
${device}
54 echo "-${device}" > /sys
/class
/net
/bonding_masters
57 function bonding_set_mode
() {
61 log INFO
"Setting bonding mode on '${device}' '${mode}'."
63 echo "${mode}" > /sys
/class
/net
/${device}/bonding
/mode
66 function bonding_get_mode
() {
70 read mode mode_num
< ${SYS_CLASS_NET}/${device}/bonding
/mode
74 function bonding_enslave_device
() {
75 local device
=$
(devicify
${1})
76 local slave
=$
(devicify
${2})
82 log INFO
"Enslaving slave '${slave}' to '${device}'."
84 device_set_down
${slave}
85 echo "+${slave}" > /sys
/class
/net
/${device}/bonding
/slaves
88 function bonding_get_slaves
() {
91 cat ${SYS_CLASS_NET}/${device}/bonding
/slaves
94 function bonding_get_active_slave
() {
97 cat ${SYS_CLASS_NET}/${device}/bonding
/active_slave
100 # XXX function bonding_get_lacp_rate?
102 function bonding_get_miimon
() {
105 cat ${SYS_CLASS_NET}/${device}/bonding
/miimon
108 function bonding_set_miimon
() {
112 echo "${miimon}" > ${SYS_CLASS_NET}/${device}/bonding/miimon
115 function bonding_device_print() {
118 ethernet_device_print ${device}
122 printf "${DEVICE_PRINT_LINE1}" "Mode
:" "$
(bonding_get_mode
${device})"
123 printf "${DEVICE_PRINT_LINE1}" "Slaves
:" "$
(bonding_get_slaves
${device})"
126 function bonding_slave_get_master() {
130 assert device_is_bonded ${slave}
133 for device in $(devices_get_all); do
134 if device_is_bonding ${device} && listmatch ${slave} $(bonding_get_slaves ${device}); then