/[vps]/baselayout-vserver/branches/baselayout-1_12/net-scripts/net/clip.sh
Gentoo

Contents of /baselayout-vserver/branches/baselayout-1_12/net-scripts/net/clip.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 436 - (show annotations) (download) (as text)
Sun Aug 27 18:14:39 2006 UTC (12 years ago) by phreak
File MIME type: text/x-sh
File size: 7966 byte(s)
Merging r2213
1 # Copyright (c) 2005-2006 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # Contributed by Giampaolo Tomassoni <g.tomassoni@libero.it>
4
5 # int atmclip_svc_start(char *name, char *desc)
6 #
7 # This starts a service. Albeit atmsigd, ilmid and atmarpd do allow for back-
8 # grounding through the -b option, its usage causes them to be sensible to
9 # SIGHUP, which is sent to all daemons when console detaches right after
10 # startup. This is probably due to the fact that these programs don't detach
11 # themself from the controlling terminal when backgrounding... The only way I
12 # see to overcame this is to use the --background option in start-stop-daemon,
13 # which is reported as a "last resort" method, but it acts correctly about this.
14 atmclip_svc_start() {
15 ebegin "Starting $2 Daemon ($1)"
16 start-stop-daemon --start \
17 --background \
18 --make-pidfile --pidfile "/var/run/$1.pid" \
19 --exec "/usr/sbin/$1" -- -l syslog
20 eend $?
21 }
22
23 # int atmclip_svcs_start()
24 #
25 # This starts the whole set of atm services needed by clip
26 atmclip_svcs_start() {
27 einfo "First CLIP instance: starting ATM CLIP daemons"
28 eindent
29
30 if [[ ${clip_full:-yes} == "yes" ]]; then
31 atmclip_svc_start atmsigd "Signaling" && \
32 atmclip_svc_start ilmid "Integrated Local Management Interface" && \
33 atmclip_svc_start atmarpd "Address Resolution Protocol"
34 else
35 atmclip_svc_start atmarpd "Address Resolution Protocol"
36 fi
37
38 local r=$?
39
40 eoutdent
41 return ${r}
42 }
43
44 # void atmclip_svc_stop(char *name, char* desc)
45 #
46 atmclip_svc_stop() {
47 ebegin "Stopping $2 Daemon ($1)"
48 start-stop-daemon --stop \
49 --retry \
50 --pidfile "/var/run/$1.pid" \
51 --exec "/usr/sbin/$1"
52 eend $?
53 }
54
55 # void atmclip_svcs_stop()
56 #
57 atmclip_svcs_stop() {
58 einfo "Last CLIP instance: stopping ATM CLIP daemons"
59 eindent
60
61 # Heartake operation!
62 sync
63
64 atmclip_svc_stop atmarpd "Address Resolution Protocol"
65 if [[ ${clip_full:-yes} == "yes" ]]; then
66 atmclip_svc_stop ilmid "Integrated Local Management Interface"
67 atmclip_svc_stop atmsigd "Signaling"
68 fi
69
70 eoutdent
71 }
72
73
74 # bool are_atmclip_svcs_running()
75 #
76 are_atmclip_svcs_running() {
77 is_daemon_running atmarpd || return 1
78 if [[ ${clip_full:-yes} == "yes" ]]; then
79 is_daemon_running ilmid || return 1
80 is_daemon_running atmsigd || return 1
81 fi
82
83 return 0
84 }
85
86 atmarp() {
87 /usr/sbin/atmarp "$@"
88 }
89
90
91 # void clip_depend(void)
92 #
93 # Sets up the dependancies for this module
94 clip_depend() {
95 before interface
96 provide clip
97 functions interface_down interface_up interface_exists is_daemon_running
98 variables clip
99 }
100
101
102 # bool clip_check_installed(void)
103 #
104 # Returns true if the kernel clip module and linux-atm tools are installed,
105 # otherwise false. Please note that I'm checking for the presence of some
106 # daemons which are not needed in case you set "clip_full=no". They are part of
107 # the linux-atm package anyway, so it shouldn't hurt to check them too out.
108 clip_check_installed() {
109 local x
110 for x in atmsigd ilmid atmarpd atmarp ; do
111 if [[ ! -x "/usr/sbin/${x}" ]] ; then
112 ${1:-false} && eerror "You need first to emerge net-dialup/linux-atm"
113 return 1
114 fi
115 done
116
117 return 0
118 }
119
120 # bool clip_pre_start(char *iface)
121 #
122 # Start the CLIP daemons
123 # Create the interface by calling atmarp -c
124 #
125 # Returns 0 (true) when successful, non-zero otherwise
126 clip_pre_start() {
127 local iface="$1" ifvar=$(bash_variable "$1")
128 local x="clip_$ifvar[@]"
129 local -a opts=( "${!x}" )
130
131 [[ -z ${opts} ]] && return 0
132 clip_check_installed || return 1
133
134 if [[ ! -r /proc/net/atm/arp ]] ; then
135 modprobe clip && sleep 2
136 if [[ ! -r /proc/net/atm/arp ]] ; then
137 eerror "You need first to enable kernel support for ATM CLIP"
138 return 1
139 fi
140 fi
141
142 local started_here
143 if ! are_atmclip_svcs_running ; then
144 atmclip_svcs_start || return 1
145 started_here=1
146 fi
147
148 if ! interface_exists "${iface}" ; then
149 ebegin "Creating CLIP interface ${iface}"
150 atmarp -c "${iface}"
151 eend $?
152
153 if [[ $? != "0" && ! -z ${started_here} ]]; then
154 atmclip_svcs_stop
155 return 1
156 fi
157 fi
158
159 return 0
160 }
161
162 # bool clip_post_start(char *iface)
163 #
164 # Basically we create PVCs here.
165 clip_post_start() {
166 local iface="$1" ifvar=$(bash_variable "$1") i
167 local x="clip_$ifvar[@]"
168 local -a opts=( "${!x}" )
169
170 [[ -z ${opts} ]] && return 0
171 clip_check_installed || return 1
172 are_atmclip_svcs_running || return 1
173
174 # The atm tools (atmarpd?) are silly enough that they would not work with
175 # iproute2 interface setup as opposed to the ifconfig one.
176 # The workaround is to temporarily toggle the interface state from up
177 # to down and then up again, without touching its address. This (should)
178 # work with both iproute2 and ifconfig.
179 interface_down "${iface}"
180 interface_up "${iface}"
181
182 # Now the real thing: create a PVC with our peer(s).
183 # There are cases in which the ATM interface is not yet
184 # ready to establish new VCCs. In that cases, atmarp would
185 # fail. Here we allow 10 retries to happen every 2 seconds before
186 # reporting problems. Also, when no defined VC can be established,
187 # we stop the ATM daemons.
188 local has_failures i
189 for (( i=0; i<${#opts[@]}; i++ )); do
190 set -- ${opts[${i}]}
191 local peerip="$1"; shift
192 local ifvpivci="$1"; shift
193
194 ebegin "Creating PVC ${ifvpivci} for peer ${peerip}"
195
196 local nleftretries emsg ecode
197 for ((nleftretries=10; nleftretries > 0; nleftretries--)); do
198 emsg=$(atmarp -s "${peerip}" "${ifvpivci}" "$@" 2>&1)
199 ecode=$?
200 [[ ${ecode} == "0" ]] && break
201 sleep 2
202 done
203
204 eend ${ecode}
205
206 if [[ ${ecode} != "0" ]]; then
207 eerror "Creation failed for PVC ${ifvpivci}: ${emsg}"
208 has_failures=1
209 fi
210 done
211
212 if [[ -n ${has_failures} ]]; then
213 clip_pre_stop "${iface}"
214 clip_post_stop "${iface}"
215 return 1
216 else
217 return 0
218 fi
219 }
220
221 # bool clip_pre_stop(char *iface)
222 #
223 # Here we basicly undo the PVC creation previously created through the
224 # clip_post_start function. When we establish a new PVC, a corresponding line
225 # is added to the /proc/net/atm/arp file, so we inspect it to extract all the
226 # outstanding PVCs of this interface.
227 clip_pre_stop() {
228 local iface="$1" ifvar=$(bash_variable "$1") i
229 local x="clip_$ifvar[@]"
230 local -a opts=( "${!x}" )
231
232 [[ -z ${opts} ]] && return 0
233
234 are_atmclip_svcs_running || return 0
235
236 # We remove all the PVCs which may have been created by
237 # clip_post_start for this interface. This shouldn't be
238 # needed by the ATM stack, but sometimes I got a panic
239 # killing CLIP daemons without previously vacuuming
240 # every active CLIP PVCs.
241 # The linux 2.6's ATM stack is really a mess...
242 local itf t encp idle ipaddr left
243 einfo "Removing PVCs on this interface"
244 eindent
245 {
246 read left && \
247 while read itf t encp idle ipaddr left ; do
248 if [[ ${itf} == "${iface}" ]]; then
249 ebegin "Removing PVC to ${ipaddr}"
250 atmarp -d "${ipaddr}"
251 eend $?
252 fi
253 done
254 } < /proc/net/atm/arp
255 eoutdent
256 }
257
258 # bool clip_post_stop(char *iface)
259 #
260 # Here we should teorically delete the interface previously created in the
261 # clip_pre_start function, but there is no way to "undo" an interface creation.
262 # We can just leave the interface down. "ifconfig -a" will still list it...
263 # Also, here we can stop the ATM CLIP daemons if there is no other CLIP PVC
264 # outstanding. We check this condition by inspecting the /proc/net/atm/arp file.
265 clip_post_stop() {
266 local iface="$1" ifvar=$( bash_variable "$1" ) i
267 local x="clip_$ifvar[@]"
268 local -a opts=( "${!x}" )
269
270 [[ -z ${opts} ]] && return 0
271
272 are_atmclip_svcs_running || return 0
273
274 local itf left hasothers
275 {
276 read left && \
277 while read itf left ; do
278 if [[ ${itf} != "${iface}" ]] ; then
279 hasothers=1
280 break
281 fi
282 done
283 } < /proc/net/atm/arp
284
285 if [[ -z ${hasothers} ]] ; then
286 atmclip_svcs_stop || return 1
287 fi
288 }
289
290 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20