]> git.ipfire.org Git - people/ms/network.git/blob - functions.bonding
Add detection for wireless devices.
[people/ms/network.git] / functions.bonding
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
6 # #
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. #
11 # #
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. #
16 # #
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/>. #
19 # #
20 ###############################################################################
21
22 function bonding_init() {
23 if ! grep -q "^bonding" /proc/modules; then
24 modprobe bonding
25
26 bonding_remove bond0
27 fi
28 }
29
30 init_register bonding_init
31
32 function bonding_create() {
33 local device=${1}
34 local mac=${2}
35
36 [ -z "${mac}" ] && mac=$(mac_generate)
37
38 log INFO "Creating bonding device '${device}' (${mac})."
39
40 echo "+${device}" > /sys/class/net/bonding_masters
41 device_set_address ${device} ${mac}
42 }
43
44 function bonding_remove() {
45 local device=${1}
46 assert isset device
47
48 log INFO "Remove bonding device '${device}'."
49
50 device_set_down ${device}
51 echo "-${device}" > /sys/class/net/bonding_masters
52 }
53
54 function bonding_set_mode() {
55 local device=${1}
56 local mode=${2}
57
58 log INFO "Setting bonding mode on '${device}' '${mode}'."
59
60 echo "${mode}" > /sys/class/net/${device}/bonding/mode
61 }
62
63 function bonding_get_mode() {
64 local device=${1}
65
66 local mode mode_num
67 read mode mode_num < ${SYS_CLASS_NET}/${device}/bonding/mode
68 echo "${mode}"
69 }
70
71 function bonding_enslave_device() {
72 local device=${1}
73 local slave=${2}
74 shift 2
75
76 assert isset device
77 assert isset slave
78
79 log INFO "Enslaving slave '${slave}' to '${device}'."
80
81 device_set_down ${slave}
82 echo "+${slave}" > /sys/class/net/${device}/bonding/slaves
83 }
84
85 function bonding_get_slaves() {
86 local device=${1}
87
88 cat ${SYS_CLASS_NET}/${device}/bonding/slaves
89 }
90
91 function bonding_get_active_slave() {
92 local device=${1}
93
94 cat ${SYS_CLASS_NET}/${device}/bonding/active_slave
95 }
96
97 # XXX function bonding_get_lacp_rate?
98
99 function bonding_get_miimon() {
100 local device=${1}
101
102 cat ${SYS_CLASS_NET}/${device}/bonding/miimon
103 }
104
105 function bonding_set_miimon() {
106 local device=${1}
107 local miimon=${2}
108
109 echo "${miimon}" > ${SYS_CLASS_NET}/${device}/bonding/miimon
110 }
111
112 function bonding_device_print() {
113 local device=${1}
114
115 ethernet_device_print ${device}
116
117 echo # Empty line
118
119 printf "${DEVICE_PRINT_LINE1}" "Mode:" "$(bonding_get_mode ${device})"
120 printf "${DEVICE_PRINT_LINE1}" "Slaves:" "$(bonding_get_slaves ${device})"
121 }
122
123 function bonding_slave_get_master() {
124 local slave=${1}
125
126 assert isset slave
127 assert device_is_bonded ${slave}
128
129 local device
130 for device in $(devices_get_all); do
131 if device_is_bonding ${device} && listmatch ${slave} $(bonding_get_slaves ${device}); then
132 echo "${device}"
133 return ${EXIT_OK}
134 fi
135 done
136
137 return ${EXIT_ERROR}
138 }