]> git.ipfire.org Git - people/stevee/network.git/blob - functions.bonding
DNS: Add RDNSS functionality.
[people/stevee/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 function bonding_create() {
31 local device=${1}
32 local mac=${2}
33
34 [ -z "${mac}" ] && mac=$(mac_generate)
35
36 # Initialize the bonding driver just
37 # when we need it.
38 bonding_init
39
40 log INFO "Creating bonding device '${device}' (${mac})."
41
42 echo "+${device}" > /sys/class/net/bonding_masters
43 device_set_address ${device} ${mac}
44 }
45
46 function bonding_remove() {
47 local device=${1}
48 assert isset device
49
50 log INFO "Remove bonding device '${device}'."
51
52 device_set_down ${device}
53 echo "-${device}" > /sys/class/net/bonding_masters
54 }
55
56 function bonding_set_mode() {
57 local device=${1}
58 local mode=${2}
59
60 log INFO "Setting bonding mode on '${device}' '${mode}'."
61
62 echo "${mode}" > /sys/class/net/${device}/bonding/mode
63 }
64
65 function bonding_get_mode() {
66 local device=${1}
67
68 local mode mode_num
69 read mode mode_num < ${SYS_CLASS_NET}/${device}/bonding/mode
70 echo "${mode}"
71 }
72
73 function bonding_enslave_device() {
74 local device=${1}
75 local slave=${2}
76 shift 2
77
78 assert isset device
79 assert isset slave
80
81 log INFO "Enslaving slave '${slave}' to '${device}'."
82
83 device_set_down ${slave}
84 echo "+${slave}" > /sys/class/net/${device}/bonding/slaves
85 }
86
87 function bonding_get_slaves() {
88 local device=${1}
89
90 cat ${SYS_CLASS_NET}/${device}/bonding/slaves
91 }
92
93 function bonding_get_active_slave() {
94 local device=${1}
95
96 cat ${SYS_CLASS_NET}/${device}/bonding/active_slave
97 }
98
99 # XXX function bonding_get_lacp_rate?
100
101 function bonding_get_miimon() {
102 local device=${1}
103
104 cat ${SYS_CLASS_NET}/${device}/bonding/miimon
105 }
106
107 function bonding_set_miimon() {
108 local device=${1}
109 local miimon=${2}
110
111 echo "${miimon}" > ${SYS_CLASS_NET}/${device}/bonding/miimon
112 }
113
114 function bonding_device_print() {
115 local device=${1}
116
117 ethernet_device_print ${device}
118
119 echo # Empty line
120
121 printf "${DEVICE_PRINT_LINE1}" "Mode:" "$(bonding_get_mode ${device})"
122 printf "${DEVICE_PRINT_LINE1}" "Slaves:" "$(bonding_get_slaves ${device})"
123 }
124
125 function bonding_slave_get_master() {
126 local slave=${1}
127
128 assert isset slave
129 assert device_is_bonded ${slave}
130
131 local device
132 for device in $(devices_get_all); do
133 if device_is_bonding ${device} && listmatch ${slave} $(bonding_get_slaves ${device}); then
134 echo "${device}"
135 return ${EXIT_OK}
136 fi
137 done
138
139 return ${EXIT_ERROR}
140 }