/[vps]/baselayout-vserver/trunk/net-scripts/net.modules.d/bonding
Gentoo

Contents of /baselayout-vserver/trunk/net-scripts/net.modules.d/bonding

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20