Lines 15-21
Link Here
|
15 |
# |
15 |
# |
16 |
# Expose variables that can be configured |
16 |
# Expose variables that can be configured |
17 |
bonding_expose() { |
17 |
bonding_expose() { |
18 |
variables slaves |
18 |
variables slaves bonding |
19 |
} |
19 |
} |
20 |
|
20 |
|
21 |
# bool bonding_check_installed(void) |
21 |
# bool bonding_check_installed(void) |
Lines 23-28
Link Here
|
23 |
# Returns 0 if ifenslave is installed, otherwise 1 |
23 |
# Returns 0 if ifenslave is installed, otherwise 1 |
24 |
bonding_check_installed() { |
24 |
bonding_check_installed() { |
25 |
[[ -x /sbin/ifenslave ]] && return 0 |
25 |
[[ -x /sbin/ifenslave ]] && return 0 |
|
|
26 |
[[ -f /sys/class/net/bonding_masters ]] && return 0 |
26 |
${1:-false} && eerror "For link aggregation (bonding) support, emerge net-misc/ifenslave" |
27 |
${1:-false} && eerror "For link aggregation (bonding) support, emerge net-misc/ifenslave" |
27 |
return 1 |
28 |
return 1 |
28 |
} |
29 |
} |
Lines 38-45
Link Here
|
38 |
# |
39 |
# |
39 |
# Bonds the interface |
40 |
# Bonds the interface |
40 |
bonding_pre_start() { |
41 |
bonding_pre_start() { |
41 |
local iface="$1" s= ifvar=$(bash_variable "$1") |
42 |
local iface="$1" s= ifvar=$(bash_variable "$1") b= retval=0 |
42 |
local -a slaves=() |
43 |
local -a slaves=() bonding=() |
43 |
|
44 |
|
44 |
slaves="slaves_${ifvar}[@]" |
45 |
slaves="slaves_${ifvar}[@]" |
45 |
[[ -z ${!slaves} ]] && return 0 |
46 |
[[ -z ${!slaves} ]] && return 0 |
Lines 48-53
Link Here
|
48 |
# Support space seperated slaves |
49 |
# Support space seperated slaves |
49 |
[[ ${#slaves[@]} == 1 ]] && slaves=( ${slaves} ) |
50 |
[[ ${#slaves[@]} == 1 ]] && slaves=( ${slaves} ) |
50 |
|
51 |
|
|
|
52 |
bonding="bonding_${ifvar}[@]" |
53 |
bonding=( "${!bonding}" ) |
54 |
|
55 |
# Support space seperated bonding options |
56 |
[[ ${#bonding[@]} == 1 ]] && bonding=( ${bonding} ) |
57 |
|
58 |
# Check for bonding support, otherwise load module |
59 |
if test ! -d /proc/net/bonding ; then |
60 |
if modprobe bonding ; then |
61 |
# Loading the bonding module can automatically create bonds |
62 |
# We don't want that. |
63 |
if [ -d /sys/class/net/${iface} ] ; then |
64 |
einfo "Bringing ${iface} down, as bonding probably created it" |
65 |
interface_down "${iface}" && { |
66 |
ebegin "Waiting 5 seconds for bonding to settle"; |
67 |
sleep 5; |
68 |
eend 0; |
69 |
} |
70 |
fi |
71 |
else |
72 |
eerror "Cannot load the bonding module" |
73 |
return 1 |
74 |
fi |
75 |
fi |
76 |
|
77 |
# Check for bonding_ifvar config |
78 |
if test -n ${bonding} ; then |
79 |
if test -f /sys/class/net/bonding_masters ; then |
80 |
# Create bond |
81 |
echo "+${iface}" > /sys/class/net/bonding_masters 2> /dev/null |
82 |
# Wait for bond to settle |
83 |
sleep 4 |
84 |
# Set options |
85 |
for b in "${bonding[@]}" ; do |
86 |
echo ${b/*=/} > /sys/class/net/${iface}/bonding/${b/=*/} 2> /dev/null |
87 |
done |
88 |
else |
89 |
# Complain if bonding_masters doesn't exist |
90 |
eerror "bonding module older than 3.0.0 (or bonding not available), sysfs support not available" |
91 |
fi |
92 |
fi |
93 |
|
51 |
|
94 |
|
52 |
if ! bonding_exists "${iface}" ; then |
95 |
if ! bonding_exists "${iface}" ; then |
Lines 67-73
Link Here
|
67 |
# Must force the slaves to a particular state before adding them |
110 |
# Must force the slaves to a particular state before adding them |
68 |
for s in "${slaves[@]}" ; do |
111 |
for s in "${slaves[@]}" ; do |
69 |
interface_del_addresses "${s}" |
112 |
interface_del_addresses "${s}" |
70 |
interface_up "${s}" |
113 |
test -n ${bonding} && interface_down "${s}" || interface_up "${s}" |
71 |
done |
114 |
done |
72 |
|
115 |
|
73 |
# now force the master to up |
116 |
# now force the master to up |
Lines 75-82
Link Here
|
75 |
|
118 |
|
76 |
# finally add in slaves |
119 |
# finally add in slaves |
77 |
eoutdent |
120 |
eoutdent |
78 |
/sbin/ifenslave "${iface}" ${slaves[@]} >/dev/null |
121 |
if test -n ${bonding} ; then |
79 |
eend $? |
122 |
for s in "${slaves[@]}" ; do |
|
|
123 |
echo "+${s}" > /sys/class/net/${iface}/bonding/slaves |
124 |
ret=$? |
125 |
[[ ${retval} = 0 ]] && retval=${ret} |
126 |
done |
127 |
# Set options again, as some don't work earlier |
128 |
for b in "${bonding[@]}" ; do |
129 |
echo ${b/*=/} > /sys/class/net/${iface}/bonding/${b/=*/} 2> /dev/null |
130 |
done |
131 |
else |
132 |
/sbin/ifenslave "${iface}" ${slaves[@]} >/dev/null |
133 |
retval=$? |
134 |
fi |
135 |
eend $retval |
80 |
|
136 |
|
81 |
return 0 #important |
137 |
return 0 #important |
82 |
} |
138 |
} |
Lines 103-109
Link Here
|
103 |
eindent |
159 |
eindent |
104 |
einfo "${slaves}" |
160 |
einfo "${slaves}" |
105 |
eoutdent |
161 |
eoutdent |
106 |
/sbin/ifenslave -d "${iface}" ${slaves} |
162 |
if test -n "$(cat /sys/class/net/bonding_masters)" ; then |
|
|
163 |
for s in ${slaves}; do |
164 |
echo "-${s}" > /sys/class/net/${iface}/bonding/slaves |
165 |
done |
166 |
else |
167 |
/sbin/ifenslave -d "${iface}" ${slaves} |
168 |
fi |
107 |
|
169 |
|
108 |
# reset all slaves |
170 |
# reset all slaves |
109 |
for s in ${slaves}; do |
171 |
for s in ${slaves}; do |
Lines 112-117
Link Here
|
112 |
interface_down "${s}" |
174 |
interface_down "${s}" |
113 |
fi |
175 |
fi |
114 |
done |
176 |
done |
|
|
177 |
echo "-${iface}" > /sys/class/net/bonding_masters |
178 |
# Wait for bond to settle |
179 |
sleep 4 |
115 |
|
180 |
|
116 |
eend 0 |
181 |
eend 0 |
117 |
return 0 |
182 |
return 0 |