Annotation of /trunk/initscripts/sysvinit/rc/network
Parent Directory | Revision Log
Revision 2307 -
(hide annotations)
(download)
Thu Jan 2 13:33:22 2014 UTC (10 years, 8 months ago) by niro
File size: 13769 byte(s)
Thu Jan 2 13:33:22 2014 UTC (10 years, 8 months ago) by niro
File size: 13769 byte(s)
-use rc_echo()
1 | niro | 2 | #!/bin/bash |
2 | niro | 931 | # $Id$ |
3 | niro | 2 | |
4 | #%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k | ||
5 | #%start: 20 | ||
6 | #%stop: 80 | ||
7 | |||
8 | #deps | ||
9 | #%needs: | ||
10 | #%before: | ||
11 | #%after: | ||
12 | |||
13 | niro | 781 | source /etc/conf.d/rc |
14 | niro | 20 | source ${rc_functions} |
15 | niro | 1363 | source /etc/conf.d/network |
16 | niro | 2 | |
17 | niro | 2305 | wait_online() |
18 | { | ||
19 | local timeout="1" | ||
20 | local iface="$2" | ||
21 | |||
22 | (( timeout *= 10 )) | ||
23 | |||
24 | while [ ! -e /sys/class/net/${iface} ] | ||
25 | do | ||
26 | (( timeout-- > 0 )) || return 1 | ||
27 | sleep 0.1 | ||
28 | done | ||
29 | |||
30 | return 0 | ||
31 | } | ||
32 | |||
33 | niro | 243 | # read values from files |
34 | read_value() | ||
35 | { | ||
36 | local var="$1" | ||
37 | local file="$2" | ||
38 | local value | ||
39 | |||
40 | # local all possible vars | ||
41 | # global | ||
42 | local ONBOOT | ||
43 | local NETWORKING | ||
44 | niro | 691 | |
45 | niro | 243 | # static |
46 | local IP | ||
47 | local NETMASK | ||
48 | local BROADCAST | ||
49 | local NETWORKING | ||
50 | local FORCE_MAC_TO | ||
51 | |||
52 | # dhcp | ||
53 | local DHCP_PROG | ||
54 | local DHCP_START | ||
55 | local DHCP_STOP | ||
56 | |||
57 | # default gw | ||
58 | local GATEWAY | ||
59 | local GATEWAY_IF | ||
60 | |||
61 | # wireless extensions | ||
62 | local WIRELESS_AP | ||
63 | local WIRELESS_AUTH_MODE | ||
64 | local WIRELESS_BITRATE | ||
65 | local WIRELESS_CHANNEL | ||
66 | local WIRELESS_DEFAULT_KEY | ||
67 | local WIRELESS_ESSID | ||
68 | local WIRELESS_FREQUENCY | ||
69 | local WIRELESS_KEY | ||
70 | local WIRELESS_KEY_ASCII | ||
71 | local WIRELESS_KEY_0 | ||
72 | local WIRELESS_KEY_1 | ||
73 | local WIRELESS_KEY_2 | ||
74 | local WIRELESS_KEY_3 | ||
75 | local WIRELESS_KEY_LENGTH | ||
76 | local WIRELESS_MODE | ||
77 | local WIRELESS_NICK | ||
78 | local WIRELESS_NWID | ||
79 | local WIRELESS_POWER | ||
80 | niro | 636 | local WIRELESS_WPA_DRIVER |
81 | niro | 243 | |
82 | niro | 636 | local BRIDGE_INTERFACES |
83 | local BRIDGE_STP | ||
84 | niro | 1092 | local BRIDGE_AGEING_TIME |
85 | local BRIDGE_PRIORITY | ||
86 | local BRIDGE_FORWARD_DELAY | ||
87 | local BRIDGE_HELLO_TIME | ||
88 | local BRIDGE_MAX_MESSAGE_AGE | ||
89 | local BRIDGE_PATH_COST | ||
90 | local BRIDGE_PORT_PRIORITY | ||
91 | niro | 636 | |
92 | niro | 243 | source ${file} |
93 | eval value=\$$(echo ${var}) | ||
94 | echo "${value}" | ||
95 | } | ||
96 | |||
97 | checkconfig() | ||
98 | { | ||
99 | niro | 636 | if [[ -z ${NETWORKING} ]] |
100 | niro | 2 | then |
101 | niro | 1258 | rc_echo "NETWORKING missing in net.${iface}, aborted" |
102 | niro | 2 | exit 1 |
103 | fi | ||
104 | |||
105 | niro | 20 | case "${NETWORKING}" in |
106 | niro | 2 | static) |
107 | niro | 636 | if [[ -z ${IP} ]] |
108 | niro | 2 | then |
109 | niro | 1258 | rc_echo "IP missing in net.${iface}, aborted" |
110 | niro | 2 | exit 1 |
111 | fi | ||
112 | |||
113 | niro | 636 | if [[ -z ${NETMASK} ]] |
114 | niro | 2 | then |
115 | niro | 1258 | rc_echo -n "NETMASK missing in net.${iface}, " |
116 | niro | 1363 | rc_echo "using ${DEFAULT_NETMASK}" |
117 | NETMASK="${DEFAULT_NETMASK}" | ||
118 | niro | 2 | fi |
119 | |||
120 | niro | 636 | if [[ -z ${BROADCAST} ]] |
121 | niro | 2 | then |
122 | niro | 1258 | rc_echo -n "BROADCAST missing in net.${iface}, " |
123 | rc_echo "using default address" | ||
124 | niro | 2 | fi |
125 | ;; | ||
126 | niro | 20 | |
127 | niro | 2 | dhcp) |
128 | niro | 636 | if [[ -z ${DHCP_PROG} ]] |
129 | niro | 2 | then |
130 | niro | 1258 | rc_echo -n "DHCP_PROG missing in net.${iface}," |
131 | niro | 1363 | rc_echo "using default programm ${DEFAULT_DHCP_PROG}" |
132 | DHCP_PROG="${DEFAULT_DHCP_PROG}" | ||
133 | niro | 2 | fi |
134 | niro | 1363 | [[ -z ${DHCP_START} ]] && DHCP_START="${DEFAULT_DHCP_START}" |
135 | [[ -z ${DHCP_STOP} ]] && DHCP_STOP="${DEFAULT_DHCP_STOP}" | ||
136 | niro | 2 | ;; |
137 | niro | 20 | |
138 | niro | 2 | esac |
139 | } | ||
140 | |||
141 | niro | 243 | # onboot_interface_list /path/to/files* |
142 | onboot_interface_list() | ||
143 | { | ||
144 | local file | ||
145 | local devices | ||
146 | local iface | ||
147 | niro | 2 | |
148 | niro | 243 | # get list of all devices |
149 | for file in $@ | ||
150 | do | ||
151 | niro | 1258 | iface="$(basename ${file} | sed s/net.//)" |
152 | |||
153 | # exclude backup files and exclude net.routes and net.sample too | ||
154 | case "${iface}" in | ||
155 | *~) continue ;; | ||
156 | routes) continue ;; | ||
157 | sample) continue ;; | ||
158 | esac | ||
159 | |||
160 | niro | 243 | if [[ $(read_value ONBOOT ${file}) = yes ]] |
161 | then | ||
162 | niro | 1258 | devices="${devices} ${iface}" |
163 | niro | 243 | fi |
164 | done | ||
165 | niro | 181 | |
166 | niro | 243 | echo "${devices}" |
167 | } | ||
168 | niro | 181 | |
169 | niro | 268 | config_wireless_wep() |
170 | { | ||
171 | local iface="$1" | ||
172 | |||
173 | if [[ -z ${iface} ]] | ||
174 | then | ||
175 | niro | 1258 | rc_echo "WEP: no \$iface given. Aborting setup." |
176 | niro | 268 | return 1 |
177 | fi | ||
178 | |||
179 | niro | 270 | ${CURS_UP} |
180 | ${SET_WWCOL} | ||
181 | niro | 1258 | rc_echo "[AUTH: WEP]" |
182 | niro | 270 | |
183 | niro | 268 | iwconfig "${iface}" enc on |
184 | [[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}" | ||
185 | [[ -n ${WIRELESS_KEY} ]] && iwconfig "${iface}" key "${WIRELESS_KEY}" | ||
186 | [[ -n ${WIRELESS_KEY_ASCII} ]] && iwconfig "${iface}" key s:"${WIRELESS_KEY_ASCII}" | ||
187 | } | ||
188 | |||
189 | config_wireless_wpa() | ||
190 | { | ||
191 | local iface="$1" | ||
192 | |||
193 | if [[ -z ${iface} ]] | ||
194 | then | ||
195 | niro | 1258 | rc_echo "WPA: no \$iface given. Aborting setup." |
196 | niro | 268 | return 1 |
197 | fi | ||
198 | |||
199 | niro | 2063 | if [ ! -x $(type -P wpa_supplicant) ] |
200 | niro | 268 | then |
201 | niro | 1258 | rc_echo "WPA: wpa_supplicant not installed. Aborting setup." |
202 | niro | 268 | return 1 |
203 | fi | ||
204 | |||
205 | niro | 270 | ${CURS_UP} |
206 | ${SET_WWCOL} | ||
207 | niro | 1258 | rc_echo "[AUTH: WPA]" |
208 | niro | 270 | |
209 | niro | 268 | # get default settings |
210 | [[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant | ||
211 | |||
212 | # check the configuration | ||
213 | niro | 2031 | [[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant/wpa_supplicant.auto |
214 | niro | 268 | [[ -z ${WIRELESS_WPA_SKEL} ]] && WIRELESS_WPA_SKEL=/etc/conf.d/wpa_supplicant.skel |
215 | |||
216 | niro | 872 | # use wext as default driver, do not abort here anymore |
217 | [[ -z ${WIRELESS_WPA_DRIVER} ]] && WIRELESS_WPA_DRIVER=wext | ||
218 | |||
219 | niro | 268 | # write a config with the settings from net.${iface} |
220 | # only wpa-psk ! all other needs manual setup | ||
221 | if [[ ${WIRELESS_WPA_AUTOCONF} = true ]] | ||
222 | then | ||
223 | # write default cfg from skeleton | ||
224 | cat ${WIRELESS_WPA_SKEL} > ${WIRELESS_WPA_CONFIG} | ||
225 | |||
226 | niro | 867 | local wpa_proto |
227 | case ${WIRELESS_AUTH_MODE} in | ||
228 | wpa) wpa_proto="WPA" ;; | ||
229 | wpa2) wpa_proto="WPA2" ;; | ||
230 | esac | ||
231 | |||
232 | niro | 268 | # setup the network entry |
233 | sed -i -e "s:@WIRELESS_ESSID@:${WIRELESS_ESSID}:g" \ | ||
234 | niro | 867 | -e "s:@WIRELESS_KEY@:${WIRELESS_KEY_ASCII}:g" \ |
235 | -e "s:@WIRELESS_AUTH_MODE@:${wpa_proto}:g" \ | ||
236 | niro | 268 | ${WIRELESS_WPA_CONFIG} |
237 | fi | ||
238 | |||
239 | niro | 275 | # remove old state dir |
240 | niro | 1665 | [ -d /run/wpa_supplicant ] && rm -rf /run/wpa_supplicant |
241 | niro | 275 | |
242 | niro | 268 | # now run the wpa_supplicant dameon |
243 | wpa_supplicant -B \ | ||
244 | -D"${WIRELESS_WPA_DRIVER}" \ | ||
245 | -c"${WIRELESS_WPA_CONFIG}" \ | ||
246 | -i"${iface}" \ | ||
247 | ${WIRELESS_WPA_OPTS} | ||
248 | niro | 270 | |
249 | # echo wait 5 seconds | ||
250 | niro | 1258 | rc_echo " Waiting 5 seconds to retrieve authentification reply ... " |
251 | niro | 270 | sleep 5 |
252 | niro | 268 | } |
253 | |||
254 | setup_wireless_extensions() | ||
255 | { | ||
256 | local iface="$1" | ||
257 | |||
258 | if [[ -z ${iface} ]] | ||
259 | then | ||
260 | niro | 1258 | rc_echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup." |
261 | niro | 268 | return 1 |
262 | fi | ||
263 | |||
264 | niro | 275 | if [[ -n ${WIRELESS_BITRATE} ]] || |
265 | [[ -n ${WIRELESS_CHANNEL} ]] || | ||
266 | [[ -n ${WIRELESS_ESSID} ]] || | ||
267 | [[ -n ${WIRELESS_FREQUENCY} ]] || | ||
268 | [[ -n ${WIRELESS_MODE} ]] || | ||
269 | [[ -n ${WIRELESS_NICK} ]] || | ||
270 | [[ -n ${WIRELESS_AUTH_MODE} ]] | ||
271 | then | ||
272 | niro | 1258 | rc_print "Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... " |
273 | niro | 275 | fi |
274 | niro | 270 | |
275 | niro | 268 | [[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}" |
276 | [[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}" | ||
277 | [[ -n ${WIRELESS_ESSID} ]] && iwconfig "${iface}" essid "${WIRELESS_ESSID}" | ||
278 | [[ -n ${WIRELESS_FREQUENCY} ]] && iwconfig "${iface}" freq "${WIRELESS_FREQUENCY}" | ||
279 | [[ -n ${WIRELESS_MODE} ]] && iwconfig "${iface}" mode "${WIRELESS_MODE}" | ||
280 | [[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}" | ||
281 | |||
282 | case "${WIRELESS_AUTH_MODE}" in | ||
283 | niro | 867 | wpa|wpa2) config_wireless_wpa "${iface}" ;; |
284 | wep|on) config_wireless_wep "${iface}" ;; | ||
285 | off) iwconfig "${iface}" enc off ;; | ||
286 | niro | 268 | esac |
287 | } | ||
288 | |||
289 | niro | 1092 | config_bridge_options() |
290 | { | ||
291 | local iface="$1" | ||
292 | local i | ||
293 | local port | ||
294 | local cost | ||
295 | local prio | ||
296 | |||
297 | # enable spanning-tree protocol | ||
298 | case ${BRIDGE_STP} in | ||
299 | on|off) brctl stp "${iface}" "${BRIDGE_STP}" ;; | ||
300 | niro | 1258 | *) rc_echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;; |
301 | niro | 1092 | esac |
302 | |||
303 | # configure ageing time | ||
304 | if [[ ! -z ${BRIDGE_AGEING_TIME} ]] | ||
305 | then | ||
306 | brctl setageing "${iface}" "${BRIDGE_AGEING_TIME}" | ||
307 | fi | ||
308 | |||
309 | # configure bridge priority | ||
310 | if [[ ! -z ${BRIDGE_PRIORITY} ]] | ||
311 | then | ||
312 | brctl setbridgeprio "${iface}" "${BRIDGE_PRIORITY}" | ||
313 | fi | ||
314 | |||
315 | # configure forward delay | ||
316 | if [[ ! -z ${BRIDGE_FORWARD_DELAY} ]] | ||
317 | then | ||
318 | brctl setfd "${iface}" "${BRIDGE_FORWARD_DELAY}" | ||
319 | fi | ||
320 | |||
321 | # configure hello time | ||
322 | if [[ ! -z ${BRIDGE_HELLO_TIME} ]] | ||
323 | then | ||
324 | brctl sethello "${iface}" "${BRIDGE_HELLO_TIME}" | ||
325 | fi | ||
326 | |||
327 | # configure maximal message age | ||
328 | if [[ ! -z ${BRIDGE_MAX_MESSAGE_AGE} ]] | ||
329 | then | ||
330 | brctl setmaxage "${iface}" "${BRIDGE_MAX_MESSAGE_AGE}" | ||
331 | fi | ||
332 | |||
333 | # configure path cost for every port | ||
334 | if [[ ! -z ${BRIDGE_PATH_COST} ]] | ||
335 | then | ||
336 | for i in ${BRIDGE_PATH_COST} | ||
337 | do | ||
338 | port="${i%=*}" | ||
339 | cost="${i#*=}" | ||
340 | [[ ! -z ${port} ]] && brctl pathcost "${iface}" "${port}" "${cost}" | ||
341 | done | ||
342 | fi | ||
343 | |||
344 | # configure port priority for every port | ||
345 | if [[ ! -z ${BRIDGE_PORT_PRIORITY} ]] | ||
346 | then | ||
347 | for i in ${BRIDGE_PORT_PRIORITY} | ||
348 | do | ||
349 | port="${i%=*}" | ||
350 | prio="${i#*=}" | ||
351 | [[ ! -z ${port} ]] && brctl setportprio "${iface}" "${port}" "${prio}" | ||
352 | done | ||
353 | fi | ||
354 | } | ||
355 | |||
356 | niro | 506 | config_bridge_devices() |
357 | { | ||
358 | local iface="$1" | ||
359 | local method="$2" | ||
360 | niro | 636 | local bport |
361 | niro | 506 | |
362 | if [[ -z ${iface} ]] | ||
363 | then | ||
364 | niro | 1258 | rc_echo "BRIDGE: no \$iface given. Aborting setup." |
365 | niro | 506 | return 1 |
366 | fi | ||
367 | |||
368 | if [[ -z ${method} ]] | ||
369 | then | ||
370 | niro | 1258 | rc_echo "BRIDGE: no \$method given. Aborting setup." |
371 | niro | 506 | return 1 |
372 | fi | ||
373 | |||
374 | # first check for brctl | ||
375 | niro | 2030 | if [[ -z $(type -P brctl) ]] |
376 | niro | 506 | then |
377 | niro | 1258 | rc_echo "brctl not found! Please install 'net-misc/bridge-utils'." |
378 | niro | 506 | return 1 |
379 | fi | ||
380 | |||
381 | # check the config | ||
382 | niro | 638 | if [[ -z ${BRIDGE_INTERFACES} ]] |
383 | niro | 506 | then |
384 | niro | 1258 | rc_echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup." |
385 | niro | 506 | return 1 |
386 | fi | ||
387 | |||
388 | case ${method} in | ||
389 | add) | ||
390 | # setup the bridge device | ||
391 | niro | 1092 | brctl addbr "${iface}" |
392 | niro | 636 | for bport in ${BRIDGE_INTERFACES} |
393 | do | ||
394 | # enter promiscous mode | ||
395 | niro | 1092 | ifconfig "${bport}" 0.0.0.0 promisc |
396 | niro | 636 | # now setup the bridge |
397 | niro | 1092 | brctl addif "${iface}" "${bport}" |
398 | niro | 636 | done |
399 | niro | 1092 | # configure all other options |
400 | config_bridge_options "${iface}" | ||
401 | niro | 506 | ;; |
402 | niro | 636 | |
403 | niro | 506 | remove) |
404 | niro | 636 | for bport in ${BRIDGE_INTERFACE} |
405 | do | ||
406 | # bring the interface down | ||
407 | niro | 1092 | ifconfig "${bport}" down |
408 | niro | 636 | # remove the interface from the bridge |
409 | niro | 1092 | brctl delif "${iface}" "${bport}" |
410 | niro | 636 | done |
411 | niro | 506 | # bring the bridge down |
412 | niro | 1092 | brctl delbr "${iface}" |
413 | niro | 506 | ;; |
414 | esac | ||
415 | niro | 636 | |
416 | niro | 506 | # unset the bridge variable to be safe |
417 | niro | 636 | unset BRIDGE_INTERFACES |
418 | niro | 506 | # continue to setup generic networking |
419 | } | ||
420 | |||
421 | config_routes() | ||
422 | { | ||
423 | local method="$1" | ||
424 | local message | ||
425 | |||
426 | # only add and del are allowed | ||
427 | case ${method} in | ||
428 | niro | 1258 | add) message="Adding" ;; |
429 | del) message="Removing" ;; | ||
430 | niro | 506 | *) |
431 | niro | 1258 | rc_echo "config_routes: unsupported \$method '${method}'." |
432 | niro | 506 | exit 1 |
433 | ;; | ||
434 | esac | ||
435 | |||
436 | # adds/delete user routes | ||
437 | if [[ -f /etc/conf.d/net.routes ]] | ||
438 | then | ||
439 | ( cat /etc/conf.d/net.routes; echo ) | # make sure there is a LF at the end | ||
440 | while read route | ||
441 | do | ||
442 | case "${route}" in | ||
443 | \#*|"") continue ;; | ||
444 | esac | ||
445 | niro | 1258 | rc_print "${message} route ${COLBLUE}${route}${COLDEFAULT} ..." |
446 | # do not esacpe ${route} or it breaks! | ||
447 | route "${method}" ${route} | ||
448 | niro | 506 | evaluate_retval |
449 | done | ||
450 | fi | ||
451 | } | ||
452 | |||
453 | niro | 243 | networking_start() |
454 | { | ||
455 | niro | 522 | local iface dns routes ALL_INTERFACES |
456 | niro | 243 | |
457 | niro | 522 | if [[ -z $1 ]] |
458 | then | ||
459 | niro | 1091 | ALL_INTERFACES=$(onboot_interface_list ${rc_network_settings}/net.*) |
460 | niro | 522 | else |
461 | niro | 1091 | if [[ -e ${rc_network_settings}/net.$1 ]] |
462 | niro | 522 | then |
463 | ALL_INTERFACES="$1" | ||
464 | else | ||
465 | ${FAILURE} | ||
466 | niro | 1258 | rc_echo "Interface $1 does not exist. Aborting" |
467 | niro | 522 | ${NORMAL} |
468 | exit 1 | ||
469 | fi | ||
470 | fi | ||
471 | |||
472 | niro | 243 | # get list of all devices |
473 | niro | 522 | for iface in ${ALL_INTERFACES} |
474 | niro | 243 | do |
475 | # checkconfig | ||
476 | niro | 1091 | source ${rc_network_settings}/net.${iface} || exit 1 |
477 | niro | 243 | checkconfig |
478 | |||
479 | niro | 2305 | # wait until the device is created |
480 | niro | 2307 | wait_online 5 "${iface}" || { rc_echo "device '${iface}' does not exist"; continue; } |
481 | niro | 2305 | |
482 | niro | 270 | # setup mac |
483 | niro | 955 | if [[ -n ${FORCE_MAC_TO} ]] |
484 | niro | 270 | then |
485 | niro | 1258 | rc_print "Faking MAC to ${FORCE_MAC_TO} for ${COLBLUE}${iface}${COLDEFAULT} ... " |
486 | niro | 270 | ifconfig "${iface}" hw ether "${FORCE_MAC_TO}" |
487 | evaluate_retval | ||
488 | fi | ||
489 | |||
490 | niro | 506 | # setup bridges |
491 | if [[ ${iface} = br[0-9]* ]] | ||
492 | then | ||
493 | niro | 1092 | config_bridge_devices "${iface}" add |
494 | niro | 506 | fi |
495 | |||
496 | niro | 270 | # now configure wireless_extensions |
497 | niro | 2101 | [ -x $(type -P iwconfig) ] && setup_wireless_extensions "${iface}" |
498 | niro | 270 | |
499 | niro | 1258 | rc_print "Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
500 | niro | 243 | |
501 | niro | 868 | # activate the interface |
502 | ifconfig "${iface}" up | ||
503 | |||
504 | niro | 243 | # setup static or dhcp |
505 | case ${NETWORKING} in | ||
506 | dhcp|DHCP) | ||
507 | ${CURS_UP} | ||
508 | ${SET_WWCOL} | ||
509 | niro | 1258 | rc_echo "[DHCP]" |
510 | niro | 1276 | loadproc ${DHCP_PROG} ${DHCP_START} "${iface}" |
511 | niro | 2 | ;; |
512 | niro | 243 | static|STATIC) |
513 | ${CURS_UP} | ||
514 | ${SET_WWCOL} | ||
515 | niro | 1258 | rc_echo "[STATIC]" |
516 | niro | 243 | ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}" |
517 | evaluate_retval | ||
518 | ;; | ||
519 | esac | ||
520 | niro | 2 | |
521 | niro | 243 | # setup def gw |
522 | if [[ -n ${GATEWAY} ]] | ||
523 | niro | 2 | then |
524 | niro | 1258 | rc_print "Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..." |
525 | niro | 1092 | route add default gateway "${GATEWAY}" metric 1 dev "${iface}" |
526 | niro | 2 | evaluate_retval |
527 | niro | 684 | |
528 | unset GATEWAY | ||
529 | niro | 2 | fi |
530 | |||
531 | niro | 245 | # setup /etc/resolv.conf |
532 | niro | 1090 | # add given nameserver |
533 | niro | 245 | if [[ -n ${NAMESERVER} ]] |
534 | then | ||
535 | niro | 1258 | rc_print "Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..." |
536 | niro | 1090 | |
537 | niro | 2306 | # wipe out the old one |
538 | niro | 1108 | echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf |
539 | # include head | ||
540 | if [ -f /etc/resolv.conf.head ] | ||
541 | then | ||
542 | cat /etc/resolv.conf.head >> /etc/resolv.conf | ||
543 | else | ||
544 | echo "# /etc/resolv.conf.head can replace this line" >> /etc/resolv.conf | ||
545 | fi | ||
546 | |||
547 | niro | 245 | for dns in ${NAMESERVER} |
548 | do | ||
549 | echo "nameserver ${dns}" >> /etc/resolv.conf | ||
550 | done | ||
551 | niro | 684 | |
552 | niro | 1108 | # include tail |
553 | if [ -f /etc/resolv.conf.tail ] | ||
554 | then | ||
555 | cat /etc/resolv.conf.tail >> /etc/resolv.conf | ||
556 | else | ||
557 | echo "# /etc/resolv.conf.tail can replace this line" >> /etc/resolv.conf | ||
558 | fi | ||
559 | |||
560 | niro | 684 | unset NAMESERVER |
561 | niro | 245 | fi |
562 | niro | 243 | done |
563 | niro | 506 | |
564 | # setup user routes | ||
565 | config_routes add | ||
566 | niro | 243 | } |
567 | niro | 2 | |
568 | niro | 243 | networking_stop() |
569 | { | ||
570 | niro | 522 | if [[ -z $1 ]] |
571 | then | ||
572 | niro | 1091 | ALL_INTERFACES=$(onboot_interface_list ${rc_network_settings}/net.*) |
573 | niro | 522 | else |
574 | niro | 1091 | if [[ -e ${rc_network_settings}/net.$1 ]] |
575 | niro | 522 | then |
576 | ALL_INTERFACES="$1" | ||
577 | else | ||
578 | ${FAILURE} | ||
579 | niro | 1258 | rc_echo "Interface $1 does not exist. Aborting" |
580 | niro | 522 | ${NORMAL} |
581 | exit 1 | ||
582 | fi | ||
583 | fi | ||
584 | |||
585 | niro | 243 | # get list of all devices |
586 | niro | 522 | for iface in ${ALL_INTERFACES} |
587 | niro | 243 | do |
588 | niro | 1091 | source ${rc_network_settings}/net.${iface} || exit 1 |
589 | niro | 243 | checkconfig |
590 | |||
591 | if [[ -n ${GATEWAY} ]] | ||
592 | niro | 2 | then |
593 | niro | 1258 | rc_print "Removing default gateway ..." |
594 | niro | 2 | route del -net default |
595 | evaluate_retval | ||
596 | fi | ||
597 | |||
598 | niro | 1258 | rc_print "Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
599 | ifconfig "${iface}" down | ||
600 | niro | 243 | evaluate_retval |
601 | niro | 2 | |
602 | niro | 506 | # remove bridges |
603 | if [[ ${iface} = br[0-9]* ]] | ||
604 | then | ||
605 | niro | 1092 | config_bridge_devices "${iface}" remove |
606 | niro | 506 | fi |
607 | |||
608 | niro | 243 | # shutdown dhcp-daemon |
609 | niro | 1276 | if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof $(basename ${DHCP_PROG})) ]] |
610 | niro | 243 | then |
611 | niro | 1258 | rc_print "Stopping the dhcp-daemon ..." |
612 | niro | 243 | ${CURS_UP} |
613 | ${SET_WWCOL} | ||
614 | niro | 1258 | rc_echo "[$(basename ${DHCP_PROG})]" |
615 | if [[ -z ${DHCP_STOP} ]] | ||
616 | then | ||
617 | killproc ${DHCP_PROG} | ||
618 | evaluate_retval | ||
619 | else | ||
620 | ${DHCP_PROG} ${DHCP_STOP} "${iface}" | ||
621 | evaluate_retval | ||
622 | fi | ||
623 | niro | 243 | fi |
624 | niro | 268 | |
625 | # shutdown wpa_supplicant daemon | ||
626 | if [[ -n $(pidof wpa_supplicant) ]] | ||
627 | then | ||
628 | killall wpa_supplicant | ||
629 | fi | ||
630 | niro | 243 | done |
631 | niro | 275 | |
632 | niro | 270 | # remove state dir |
633 | niro | 1665 | if [ -d /run/wpa_supplicant ] |
634 | niro | 270 | then |
635 | niro | 1665 | rm -rf /run/wpa_supplicant |
636 | niro | 270 | fi |
637 | niro | 506 | |
638 | # delete user routes | ||
639 | config_routes del | ||
640 | niro | 243 | } |
641 | niro | 2 | |
642 | niro | 243 | case $1 in |
643 | start) | ||
644 | niro | 522 | networking_start $2 |
645 | niro | 2 | update_svcstatus $1 |
646 | niro | 243 | splash svc_started "$(basename $0)" 0 |
647 | ;; | ||
648 | |||
649 | stop) | ||
650 | niro | 522 | networking_stop $2 |
651 | niro | 243 | update_svcstatus $1 |
652 | niro | 2 | splash svc_stopped "$(basename $0)" 0 |
653 | ;; | ||
654 | |||
655 | restart) | ||
656 | $0 stop | ||
657 | sleep 1 | ||
658 | $0 start | ||
659 | ;; | ||
660 | |||
661 | *) | ||
662 | niro | 1258 | rc_echo "Usage: $0 {start|stop|restart} [interface]" |
663 | niro | 2 | exit 1 |
664 | ;; | ||
665 | esac |
Properties
Name | Value |
---|---|
svn:executable | * |