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 init_register bonding_init
32 function bonding_create
() {
36 [ -z "${mac}" ] && mac
=$
(mac_generate
)
38 log INFO
"Creating bonding device '${device}' (${mac})."
40 echo "+${device}" > /sys
/class
/net
/bonding_masters
41 device_set_address
${device} ${mac}
44 function bonding_remove
() {
48 log INFO
"Remove bonding device '${device}'."
50 device_set_down
${device}
51 echo "-${device}" > /sys
/class
/net
/bonding_masters
54 function bonding_set_mode
() {
58 log INFO
"Setting bonding mode on '${device}' '${mode}'."
60 echo "${mode}" > /sys
/class
/net
/${device}/bonding
/mode
63 function bonding_get_mode
() {
67 read mode mode_num
< ${SYS_CLASS_NET}/${device}/bonding
/mode
71 function bonding_enslave_device
() {
79 log INFO
"Enslaving slave '${slave}' to '${device}'."
81 device_set_down
${slave}
82 echo "+${slave}" > /sys
/class
/net
/${device}/bonding
/slaves
85 function bonding_get_slaves
() {
88 cat ${SYS_CLASS_NET}/${device}/bonding
/slaves
91 function bonding_get_active_slave
() {
94 cat ${SYS_CLASS_NET}/${device}/bonding
/active_slave
97 # XXX function bonding_get_lacp_rate?
99 function bonding_get_miimon
() {
102 cat ${SYS_CLASS_NET}/${device}/bonding
/miimon
105 function bonding_set_miimon
() {
109 echo "${miimon}" > ${SYS_CLASS_NET}/${device}/bonding/miimon
112 function bonding_device_print() {
115 ethernet_device_print ${device}
119 printf "${DEVICE_PRINT_LINE1}" "Mode
:" "$
(bonding_get_mode
${device})"
120 printf "${DEVICE_PRINT_LINE1}" "Slaves
:" "$
(bonding_get_slaves
${device})"
123 function bonding_slave_get_master() {
127 assert device_is_bonded ${slave}
130 for device in $(devices_get_all); do
131 if device_is_bonding ${device} && listmatch ${slave} $(bonding_get_slaves ${device}); then