updated on Wed Jan 25 08:34:36 UTC 2012
[aur-mirror.git] / netcfg-bonding / bonding
blob6649e567e9b7f7b76bd7b7ba6cdc5da0d10f97be
1 #! /bin/bash
2 . /usr/lib/network/network
4 wait_for_link() {
5 # Returns 0 when a link is detected, 1 otherwise
6 for i in {1..10}; do
7 sleep .2
8 if ip link show $1|grep -q "state UP"; then
9 return 0
11 done
12 return 1
15 bonding_up() {
16 load_profile $1
18 let slaves_up=0
20 # Add the master interface
21 ip link set $INTERFACE up || return 1
23 # Add slaves
24 for S in $SLAVES; do
25 ifenslave -d $INTERFACE $S &>/dev/null
26 ip link set $S up || return 1
27 ifenslave $INTERFACE $S || return 1
28 if [[ $slaves_up -eq 0 ]]; then
29 let timeout=0
30 until ! ip link show $S|grep -q "state UP"; do
31 sleep 0.5
32 let timeout++
33 if [[ $timeout -eq 5 ]]; then
34 report_fail "Slave $S is down"
35 break
36 fi
37 done
38 if ! ip link show $S|grep -q "state UP"; then
39 let slaves_up++
42 done
44 # If no slave is up, abort
45 if [[ $slaves_up -eq 0 ]]; then
46 report_fail "No slave up"
47 return 1
50 # Wait for the bonding interface to be up
51 while ! ip link show $INTERFACE|grep -q "state UP"; do
52 sleep .2
53 done
55 # Now do as if it were a simple ethernet interface
56 /usr/lib/network/connections/ethernet-iproute up $1
59 bonding_down() {
60 load_profile $1
62 # Remove slaves
63 for S in $SLAVES; do
64 ifenslave -d $INTERFACE $S
65 ip link set $S down || return 1
66 done
68 /usr/lib/network/connections/ethernet-iproute down $1
71 bonding_$1 $2
72 exit $?