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