blob: 6095c746faf593b5a94490ce5e59ea35e7476f5c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# Copyright (c) 2004-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# Contributed by Roy Marples (uberlord@gentoo.org)
# void bonding_depend(void)
#
# Sets up the dependancies for the module
bonding_depend() {
before interface macchanger
functions interface_exists interface_up interface_down \
interface_del_addresses
}
# void bonding_expose(void)
#
# Expose variables that can be configured
bonding_expose() {
variables slaves
}
# bool bonding_check_installed(void)
#
# Returns 0 if ifenslave is installed, otherwise 1
bonding_check_installed() {
[[ -x /sbin/ifenslave ]] && return 0
${1:-false} && eerror "For link aggregation (bonding) support, emerge net-misc/ifenslave"
return 1
}
# bonding_exists(char *interface)
#
# Returns 0 if we are a bonded interface, otherwise 1
bonding_exists() {
[[ -f "/proc/net/bonding/$1" ]]
}
# bool bonding_post_start(char *iface)
#
# Bonds the interface
bonding_pre_start() {
local iface="$1" s ifvar="$(bash_variable "$1")"
local -a slaves
slaves="slaves_${ifvar}[@]"
[[ -z ${!slaves} ]] && return 0
slaves=( "${!slaves}" )
# Support space seperated slaves
[[ ${#slaves[@]} == 1 ]] && slaves=( ${slaves} )
interface_exists "${iface}" true || return 1
if ! bonding_exists "${iface}" ; then
eerror "${iface} is not capable of bonding"
return 1
fi
ebegin "Adding slaves to ${iface}"
eindent
einfo "${slaves[@]}"
# Check that our slaves exist
for s in "${slaves[@]}" ; do
interface_exists "${s}" true || return 1
done
# Must force the slaves to a particular state before adding them
for s in "${slaves[@]}" ; do
interface_del_addresses "${s}"
interface_up "${s}"
done
# now force the master to up
interface_up "${iface}"
# finally add in slaves
eoutdent
/sbin/ifenslave "${iface}" ${slaves[@]} >/dev/null
eend $?
return 0 #important
}
# bool bonding_stop(void)
# Unbonds bonded interfaces
#
# Always returns 0 (true)
bonding_stop() {
local iface="$1" slaves s
# return silently if this is not a bonding interface
! bonding_exists "${iface}" && return 0
# don't trust the config, get the active list instead
slaves="$( \
sed -n -e 's/^Slave Interface: //p' "/proc/net/bonding/${iface}" \
| xargs \
)"
[[ -z ${slaves} ]] && return 0
# remove all slaves
ebegin "Removing slaves from ${iface}"
eindent
einfo "${slaves}"
eoutdent
/sbin/ifenslave -d "${iface}" ${slaves}
# reset all slaves
for s in ${slaves}; do
if interface_exists "${s}" ; then
interface_del_addresses "${s}"
interface_down "${s}"
fi
done
eend 0
return 0
}
# vim: set ft=sh ts=4 :
|