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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations) (download)
Sat Sep 3 16:10:27 2005 UTC (9 years, 3 months ago) by hollow
File size: 2755 byte(s)
import initial baselayout sources (1.12.0_pre8)
1 #!/bin/bash
2 # Copyright (c) 2004-2005 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 # char* bonding_provides(void)
8 #
9 # Returns a string to change module definition for starting up
10 bonding_provides() {
11 echo "bonding"
12 }
13
14 # void bonding_depend(void)
15 #
16 # Sets up the dependancies for the module
17 bonding_depend() {
18 after interface
19 before vlan dhcp apipa
20 }
21
22 # bool bonding_check_installed(void)
23 #
24 # Returns 1 if ifenslave is installed, otherwise 0
25 bonding_check_installed() {
26 [[ -x /sbin/ifenslave ]] && return 0
27 ${1:-false} && eerror "For link aggregation (bonding) support, emerge net-misc/ifenslave"
28 return 1
29 }
30
31 # bool bonding_check_depends(void)
32 #
33 # Checks to see if we have the needed functions
34 bonding_check_depends() {
35 local f
36
37 for f in interface_exists interface_up interface_down interface_del_addresses; do
38 [[ $( type -t "${f}" ) == "function" ]] && continue
39 eerror "bonding: missing required function ${f}\n"
40 return 1
41 done
42
43 return 0
44 }
45
46 # bool bonding_post_start(char *iface)
47 #
48 # Bonds the interface
49 bonding_pre_start() {
50 local iface="$1" slaves s ifvar=$( bash_variable "$1" )
51
52 eval slaves=\"\$\{slaves_${ifvar}\[@\]\}\"
53 [[ -z ${slaves} ]] && return 0
54
55 interface_exists "${iface}" true || return 1
56
57 if [[ ! -f "/proc/net/bonding/${iface}" ]]; then
58 eerror "${iface} is not capable of bonding"
59 return 1
60 fi
61
62 ebegin "Adding slaves to ${iface}"
63 eindent
64 einfo "${slaves}"
65
66 # Check that our slaves exist
67 for s in ${slaves}; do
68 interface_exists "${s}" && continue
69 ewarn "interface ${s} does not exist"
70 return 1
71 done
72
73 # Must force the slaves to a particular state before adding them
74 for s in ${slaves}; do
75 interface_del_addresses "${s}"
76 interface_up "${s}"
77 done
78
79 # now force the master to up
80 interface_up "${iface}"
81
82 # finally add in slaves
83 eoutdent
84 /sbin/ifenslave "${iface}" ${slaves} >/dev/null
85 eend $?
86
87 return 0 #important
88 }
89
90 # bool bonding_pre_stop(void)
91 # Unbonds bonded interfaces
92 #
93 # Always returns 0 (true)
94 bonding_pre_stop() {
95 local iface="$1" slaves s
96
97 bonding_check_installed || return 0
98
99 # return silently if this is not a bonding interface
100 [[ ! -f "/proc/net/bonding/${iface}" ]] && return 0
101
102 # don't trust the config, get the active list instead
103 slaves=$( sed -n -e 's/^Slave Interface: //p' "/proc/net/bonding/${iface}" )
104 [[ -z ${slaves} ]] && return 0
105
106 # remove all slaves
107 ebegin "Removing slaves from ${iface}"
108 eindent
109 einfo "${slaves}"
110 eoutdent
111 /sbin/ifenslave -d "${iface}" ${slaves} &>${devnull}
112
113 # reset all slaves
114 for s in ${slaves}; do
115 if interface_exists "${s}" ; then
116 interface_del_addresses "${s}"
117 interface_down "${s}"
118 fi
119 done
120
121 eend 0
122 return 0
123 }
124
125 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20