/[baselayout]/trunk/net.Linux/clip.sh
Gentoo

Contents of /trunk/net.Linux/clip.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2670 - (show annotations) (download) (as text)
Mon Apr 30 13:19:26 2007 UTC (7 years, 6 months ago) by uberlord
File MIME type: text/x-sh
File size: 5787 byte(s)
Stop using the [ -z "$@" ] test, use [ $# = 0 ] instead, #176554.
1 # Copyright 2005-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 clip_depend() {
5 program /usr/sbin/atmsigd
6 before interface
7 }
8
9 _config_vars="$_config_vars clip"
10
11 # This starts a service. Albeit atmsigd, ilmid and atmarpd do allow for back-
12 # grounding through the -b option, its usage causes them to be sensible to
13 # SIGHUP, which is sent to all daemons when console detaches right after
14 # startup. This is probably due to the fact that these programs don't detach
15 # themself from the controlling terminal when backgrounding... The only way I
16 # see to overcame this is to use the --background option in start-stop-daemon,
17 # which is reported as a "last resort" method, but it acts correctly about this.
18 atmclip_svc_start() {
19 ebegin "Starting $2 Daemon ($1)"
20 start-stop-daemon --start \
21 --background \
22 --make-pidfile --pidfile "/var/run/$1.pid" \
23 --exec "/usr/sbin/$1" -- -l syslog
24 eend $?
25 }
26
27 atmclip_svcs_start() {
28 einfo "First CLIP instance: starting ATM CLIP daemons"
29 eindent
30
31 if [ "${clip_full:-yes}" = "yes" ]; then
32 atmclip_svc_start atmsigd "Signaling" && \
33 atmclip_svc_start ilmid "Integrated Local Management Interface" && \
34 atmclip_svc_start atmarpd "Address Resolution Protocol"
35 else
36 atmclip_svc_start atmarpd "Address Resolution Protocol"
37 fi
38
39 local r=$?
40
41 eoutdent
42 return ${r}
43 }
44
45 atmclip_svc_stop() {
46 ebegin "Stopping $2 Daemon ($1)"
47 start-stop-daemon --stop --quiet \
48 --pidfile "/var/run/$1.pid" \
49 --exec "/usr/sbin/$1"
50 eend $?
51 }
52
53 atmclip_svcs_stop() {
54 einfo "Last CLIP instance: stopping ATM CLIP daemons"
55 eindent
56
57 # Heartake operation!
58 sync
59
60 atmclip_svc_stop atmarpd "Address Resolution Protocol"
61 if [ "${clip_full:-yes}" = "yes" ]; then
62 atmclip_svc_stop ilmid "Integrated Local Management Interface"
63 atmclip_svc_stop atmsigd "Signaling"
64 fi
65
66 eoutdent
67 }
68
69 are_atmclip_svcs_running() {
70
71 start-stop-daemon --quiet --test --stop --pidfile /var/run/atmarpd.pid || return 1
72
73 if [ "${clip_full:-yes}" = "yes" ]; then
74 start-stop-daemon --quiet --test --stop --pidfile /var/run/ilmid.pid || return 1
75 start-stop-daemon --quiet --test --stop --pidfile /var/run/atmsigd.pid || return 1
76 fi
77
78 return 0
79 }
80
81 clip_pre_start() {
82 eval $(_get_array "clip_${IFVAR}")
83 [ $# = 0 ] && return 0
84
85 if [ ! -r /proc/net/atm/arp ] ; then
86 modprobe clip && sleep 2
87 if [ ! -r /proc/net/atm/arp ] ; then
88 eerror "You need first to enable kernel support for ATM CLIP"
89 return 1
90 fi
91 fi
92
93 local started_here=
94 if ! are_atmclip_svcs_running ; then
95 atmclip_svcs_start || return 1
96 started_here=1
97 fi
98
99 if ! _exists ; then
100 ebegin "Creating CLIP interface ${IFACE}"
101 atmarp -c "${IFACE}"
102 if ! eend $? ; then
103 [ -z "${started_here}" ] && atmclip_svcs_stop
104 return 1
105 fi
106 fi
107
108 return 0
109 }
110
111 clip_post_start() {
112 eval $(_get_array "clip_${IFVAR}")
113 [ $# = 0 ] && return 0
114
115 are_atmclip_svcs_running || return 1
116
117 # The atm tools (atmarpd?) are silly enough that they would not work with
118 # iproute2 interface setup as opposed to the ifconfig one.
119 # The workaround is to temporarily toggle the interface state from up
120 # to down and then up again, without touching its address. This (should)
121 # work with both iproute2 and ifconfig.
122 _down
123 _up
124
125 # Now the real thing: create a PVC with our peer(s).
126 # There are cases in which the ATM interface is not yet
127 # ready to establish new VCCs. In that cases, atmarp would
128 # fail. Here we allow 10 retries to happen every 2 seconds before
129 # reporting problems. Also, when no defined VC can be established,
130 # we stop the ATM daemons.
131 local has_failures= i=
132 for i in "$@" ; do
133 set -- ${i}
134 local peerip="$1"; shift
135 local ifvpivci="$1"; shift
136 ebegin "Creating PVC ${ifvpivci} for peer ${peerip}"
137
138 local nleftretries=10 emsg= ecode=
139 while [ ${nleftretries} -gt 0 ] ; do
140 nleftretries=$((${nleftretries} - 1))
141 emsg="$(atmarp -s "${peerip}" "${ifvpivci}" "$@" 2>&1)"
142 ecode=$? && break
143 sleep 2
144 done
145
146 if ! eend ${ecode} ; then
147 eerror "Creation failed for PVC ${ifvpivci}: ${emsg}"
148 has_failures=1
149 fi
150 done
151
152 if [ -n "${has_failures}" ]; then
153 clip_pre_stop "${iface}"
154 clip_post_stop "${iface}"
155 return 1
156 else
157 return 0
158 fi
159 }
160
161 clip_pre_stop() {
162 are_atmclip_svcs_running || return 0
163
164 # We remove all the PVCs which may have been created by
165 # clip_post_start for this interface. This shouldn't be
166 # needed by the ATM stack, but sometimes I got a panic
167 # killing CLIP daemons without previously vacuuming
168 # every active CLIP PVCs.
169 # The linux 2.6's ATM stack is really a mess...
170 local itf= t= encp= idle= ipaddr= left=
171 einfo "Removing PVCs on this interface"
172 eindent
173 {
174 read left && \
175 while read itf t encp idle ipaddr left ; do
176 if [ "${itf}" = "${IFACE}" ]; then
177 ebegin "Removing PVC to ${ipaddr}"
178 atmarp -d "${ipaddr}"
179 eend $?
180 fi
181 done
182 } < /proc/net/atm/arp
183 eoutdent
184 }
185
186 # Here we should teorically delete the interface previously created in the
187 # clip_pre_start function, but there is no way to "undo" an interface creation.
188 # We can just leave the interface down. "ifconfig -a" will still list it...
189 # Also, here we can stop the ATM CLIP daemons if there is no other CLIP PVC
190 # outstanding. We check this condition by inspecting the /proc/net/atm/arp file.
191 clip_post_stop() {
192 are_atmclip_svcs_running || return 0
193
194 local itf= left= hasothers=
195 {
196 read left && \
197 while read itf left ; do
198 if [ "${itf}" != "${IFACE}" ] ; then
199 hasothers=1
200 break
201 fi
202 done
203 } < /proc/net/atm/arp
204
205 if [ -z "${hasothers}" ] ; then
206 atmclip_svcs_stop || return 1
207 fi
208 }
209
210 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20