/[vps]/baselayout-vserver/trunk/net-scripts/init.d/net.lo
Gentoo

Diff of /baselayout-vserver/trunk/net-scripts/init.d/net.lo

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 235 Revision 236
10 10
11# For pcmcia users. note that pcmcia must be added to the same 11# For pcmcia users. note that pcmcia must be added to the same
12# runlevel as the net.* script that needs it. 12# runlevel as the net.* script that needs it.
13depend() { 13depend() {
14 need localmount 14 need localmount
15 use pcmcia usb isdn wlan 15 use isapnp isdn pcmcia usb wlan
16 16
17 # Load any custom depend functions for the given interface 17 # Load any custom depend functions for the given interface
18 # For example, br0 may need eth0 and eth1 18 # For example, br0 may need eth0 and eth1
19 local iface="${myservice#*.}" 19 local iface="${myservice#*.}"
20 [[ $(type -t "depend_${iface}") == "function" ]] && depend_${iface} 20 [[ $(type -t "depend_${iface}") == "function" ]] && depend_${iface}
58# 58#
59# Does the minimum checking on a module - even when forcing 59# Does the minimum checking on a module - even when forcing
60module_load_minimum() { 60module_load_minimum() {
61 local f="$1" MODULE="${1##*/}" 61 local f="$1" MODULE="${1##*/}"
62 62
63 if [[ ! -f ${f} ]]; then 63 if [[ ! -f ${f} ]] ; then
64 eerror "${f} does not exist" 64 eerror "${f} does not exist"
65 return 1 65 return 1
66 fi 66 fi
67 67
68 if ! source "${f}" ; then 68 if ! source "${f}" ; then
101 # the module name, for example iproute2_ 101 # the module name, for example iproute2_
102 102
103 j="${#MODULES[@]}" 103 j="${#MODULES[@]}"
104 loaded_interface=false 104 loaded_interface=false
105 for (( i=0; i<j; i++ )); do 105 for (( i=0; i<j; i++ )); do
106 if [[ ${MODULES[i]##*/} == "interface" ]]; then 106 if [[ ${MODULES[i]##*/} == "interface" ]] ; then
107 eerror "interface is a reserved name - cannot load a module called interface" 107 eerror "interface is a reserved name - cannot load a module called interface"
108 return 1 108 return 1
109 fi 109 fi
110 110
111 ( 111 (
112 u=0; 112 u=0;
113 module_load_minimum "${MODULES[i]}" || u=1; 113 module_load_minimum "${MODULES[i]}" || u=1;
114 if [[ ${u} == 0 ]]; then 114 if [[ ${u} == 0 ]] ; then
115 inst="${MODULES[i]##*/}_check_installed"; 115 inst="${MODULES[i]##*/}_check_installed";
116 if is_function "${inst}" ; then 116 if is_function "${inst}" ; then
117 ${inst} false || u=1; 117 ${inst} false || u=1;
118 fi 118 fi
119 fi 119 fi
120 exit "${u}"; 120 exit "${u}";
121 ) 121 )
122 122
123 if [[ $? == 0 ]]; then 123 if [[ $? == 0 ]] ; then
124 source "${MODULES[i]}" 124 source "${MODULES[i]}"
125 MODULES[i]="${MODULES[i]##*/}" 125 MODULES[i]="${MODULES[i]##*/}"
126 else 126 else
127 unset MODULES[i] 127 unset MODULES[i]
128 fi 128 fi
186 # way, ignore this setting so that the default dhcp 186 # way, ignore this setting so that the default dhcp
187 # module will be used. 187 # module will be used.
188 [[ ${umods[i]} == "dhcp" ]] && continue 188 [[ ${umods[i]} == "dhcp" ]] && continue
189 189
190 # We remove any modules we explicitly don't want 190 # We remove any modules we explicitly don't want
191 if [[ ${umods[i]} == "!"* ]]; then 191 if [[ ${umods[i]} == "!"* ]] ; then
192 for (( j=0; j<nmods; j++ )); do 192 for (( j=0; j<nmods; j++ )); do
193 [[ -z ${MODULES[j]} ]] && continue 193 [[ -z ${MODULES[j]} ]] && continue
194 if [[ ${umods[i]:1} == "${MODULES[j]}" \ 194 if [[ ${umods[i]:1} == "${MODULES[j]}" \
195 || ${umods[i]:1} == "${PROVIDES[j]}" ]]; then 195 || ${umods[i]:1} == "${PROVIDES[j]}" ]] ; then
196 # We may need to setup a class wrapper for it even though 196 # We may need to setup a class wrapper for it even though
197 # we don't use it directly 197 # we don't use it directly
198 # However, we put it into an array and wrap later as 198 # However, we put it into an array and wrap later as
199 # another module may provide the same thing 199 # another module may provide the same thing
200 ${MODULES[j]}_check_installed \ 200 ${MODULES[j]}_check_installed \
215 # used instead. 215 # used instead.
216 (( i < ${#umods[@]} - ${#pmods[@]} )) || continue 216 (( i < ${#umods[@]} - ${#pmods[@]} )) || continue
217 217
218 # The function may not exist because the modules software is 218 # The function may not exist because the modules software is
219 # not installed. Load the module and report its error 219 # not installed. Load the module and report its error
220 if [[ -e "${MODULES_DIR}/${umods[i]}" ]]; then 220 if [[ -e "${MODULES_DIR}/${umods[i]}" ]] ; then
221 source "${MODULES_DIR}/${umods[i]}" 221 source "${MODULES_DIR}/${umods[i]}"
222 is_function "${umods[i]}_check_installed" \ 222 is_function "${umods[i]}_check_installed" \
223 && ${umods[i]}_check_installed true 223 && ${umods[i]}_check_installed true
224 else 224 else
225 eerror "The module \"${umods[i]}\" does not exist" 225 eerror "The module \"${umods[i]}\" does not exist"
226 fi 226 fi
227 return 1 227 return 1
228 fi 228 fi
229 229
230 if is_function "${umods[i]}_provide" ; then 230 if is_function "${umods[i]}_provide" ; then
231 mod=$( ${umods[i]}_provide ) 231 mod="$(${umods[i]}_provide )"
232 else 232 else
233 mod="${umods[i]}" 233 mod="${umods[i]}"
234 fi 234 fi
235 for (( j=0; j<nmods; j++ )); do 235 for (( j=0; j<nmods; j++ )); do
236 [[ -z ${MODULES[j]} ]] && continue 236 [[ -z ${MODULES[j]} ]] && continue
237 if [[ ${PROVIDES[j]} == "${mod}" && ${umods[i]} != "${MODULES[j]}" ]]; then 237 if [[ ${PROVIDES[j]} == "${mod}" && ${umods[i]} != "${MODULES[j]}" ]] ; then
238 # We don't have a match - now ensure that we still provide an 238 # We don't have a match - now ensure that we still provide an
239 # alternative. This is to handle our preferred modules. 239 # alternative. This is to handle our preferred modules.
240 for (( l=0; l<nmods; l++ )); do 240 for (( l=0; l<nmods; l++ )); do
241 [[ ${l} == "${j}" || -z ${MODULES[l]} ]] && continue 241 [[ ${l} == "${j}" || -z ${MODULES[l]} ]] && continue
242 if [[ ${PROVIDES[l]} == "${mod}" ]]; then 242 if [[ ${PROVIDES[l]} == "${mod}" ]] ; then
243 unset MODULES[j] 243 unset MODULES[j]
244 unset PROVIDES[j] 244 unset PROVIDES[j]
245 break 245 break
246 fi 246 fi
247 done 247 done
278 for ((i=0; i<nmods; i++)); do 278 for ((i=0; i<nmods; i++)); do
279 dead[i]="false" 279 dead[i]="false"
280 if [[ ${MODULES[i]} != "${PROVIDES[i]}" ]] ; then 280 if [[ ${MODULES[i]} != "${PROVIDES[i]}" ]] ; then
281 local provided=false 281 local provided=false
282 for ((j=0; j<${#provide[@]}; j++)); do 282 for ((j=0; j<${#provide[@]}; j++)); do
283 if [[ ${provide[j]} == "${PROVIDES[i]}" ]]; then 283 if [[ ${provide[j]} == "${PROVIDES[i]}" ]] ; then
284 provide_list[j]="${provide_list[j]} ${MODULES[i]}" 284 provide_list[j]="${provide_list[j]} ${MODULES[i]}"
285 provided=true 285 provided=true
286 fi 286 fi
287 done 287 done
288 if ! ${provided}; then 288 if ! ${provided}; then
299 after[i]=" ${after[i]} $(${MODULES[i]}_after) " 299 after[i]=" ${after[i]} $(${MODULES[i]}_after) "
300 fi 300 fi
301 if is_function "${MODULES[i]}_before" ; then 301 if is_function "${MODULES[i]}_before" ; then
302 for m in $(${MODULES[i]}_before); do 302 for m in $(${MODULES[i]}_before); do
303 for ((j=0; j<nmods; j++)) ; do 303 for ((j=0; j<nmods; j++)) ; do
304 if [[ ${PROVIDES[j]} == "${m}" ]]; then 304 if [[ ${PROVIDES[j]} == "${m}" ]] ; then
305 after[j]=" ${after[j]} ${MODULES[i]} " 305 after[j]=" ${after[j]} ${MODULES[i]} "
306 break 306 break
307 fi 307 fi
308 done 308 done
309 done 309 done
310 fi 310 fi
311 done 311 done
312 312
313 # Replace the after list modules with real modules 313 # Replace the after list modules with real modules
314 for ((i=0; i<nmods; i++)); do 314 for ((i=0; i<nmods; i++)); do
315 if [[ -n ${after[i]} ]]; then 315 if [[ -n ${after[i]} ]] ; then
316 for ((j=0; j<${#provide[@]}; j++)); do 316 for ((j=0; j<${#provide[@]}; j++)); do
317 after[i]="${after[i]// ${provide[j]} / ${provide_list[j]} }" 317 after[i]="${after[i]// ${provide[j]} / ${provide_list[j]} }"
318 done 318 done
319 fi 319 fi
320 done 320 done
355 if is_function "${MODULES[i]}_need" ; then 355 if is_function "${MODULES[i]}_need" ; then
356 for needmod in $( ${MODULES[i]}_need ); do 356 for needmod in $( ${MODULES[i]}_need ); do
357 missingdeps=true 357 missingdeps=true
358 for (( j=0; j<nmods; j++ )); do 358 for (( j=0; j<nmods; j++ )); do
359 if [[ ${needmod} == "${MODULES[j]}" \ 359 if [[ ${needmod} == "${MODULES[j]}" \
360 || ${needmod} == "${PROVIDES[j]}" ]]; then 360 || ${needmod} == "${PROVIDES[j]}" ]] ; then
361 missingdeps=false 361 missingdeps=false
362 break 362 break
363 fi 363 fi
364 done 364 done
365 if ${missingdeps} ; then 365 if ${missingdeps} ; then
402 local iface="$1" starting="${2:-true}" MODULE p=false i j k 402 local iface="$1" starting="${2:-true}" MODULE p=false i j k
403 local -a x 403 local -a x
404 local RC_INDENTATION="${RC_INDENTATION}" 404 local RC_INDENTATION="${RC_INDENTATION}"
405 local -a PROVIDES WRAP_MODULES 405 local -a PROVIDES WRAP_MODULES
406 406
407 if [[ ${iface} != "lo" ]]; then 407 if [[ ${iface} != "lo" ]] ; then
408 x="modules_force_${iface}[@]" 408 x="modules_force_${iface}[@]"
409 [[ -n ${!x} ]] && modules_force=( "${!x}" ) 409 [[ -n ${!x} ]] && modules_force=( "${!x}" )
410 if [[ -n ${modules_force} ]]; then 410 if [[ -n ${modules_force} ]] ; then
411 ewarn "WARNING: You are forcing modules!" 411 ewarn "WARNING: You are forcing modules!"
412 ewarn "Do not complain or file bugs if things start breaking" 412 ewarn "Do not complain or file bugs if things start breaking"
413 report=true 413 report=true
414 fi 414 fi
415 fi 415 fi
416 416
417 veinfo "Loading networking modules for ${iface}" 417 veinfo "Loading networking modules for ${iface}"
418 eindent 418 eindent
419 419
420 if [[ -z ${modules_force} ]]; then 420 if [[ -z ${modules_force} ]] ; then
421 modules_load_auto || return 1 421 modules_load_auto || return 1
422 else 422 else
423 j="${#modules_force[@]}" 423 j="${#modules_force[@]}"
424 for (( i=0; i<j; i++ )); do 424 for (( i=0; i<j; i++ )); do
425 module_load_minimum "${MODULES_DIR}/${modules_force[i]}" || return 1 425 module_load_minimum "${MODULES_DIR}/${modules_force[i]}" || return 1
437 MODULE="${MODULES[i]}" 437 MODULE="${MODULES[i]}"
438 ${MODULE}_depend 438 ${MODULE}_depend
439 439
440 # If no provide is given, assume module name 440 # If no provide is given, assume module name
441 if is_function "${MODULES[i]}_provide" ; then 441 if is_function "${MODULES[i]}_provide" ; then
442 PROVIDES[i]=$( ${MODULES[i]}_provide ) 442 PROVIDES[i]="$(${MODULES[i]}_provide)"
443 else 443 else
444 PROVIDES[i]="${MODULES[i]}" 444 PROVIDES[i]="${MODULES[i]}"
445 fi 445 fi
446 done 446 done
447 447
448 if [[ -n ${modules_force[@]} ]]; then 448 if [[ -n ${modules_force[@]} ]] ; then
449 # Strip any duplicate modules providing the same thing 449 # Strip any duplicate modules providing the same thing
450 j="${#MODULES[@]}" 450 j="${#MODULES[@]}"
451 for (( i=0; i<j-1; i++ )); do 451 for (( i=0; i<j-1; i++ )); do
452 [[ -z ${MODULES[i]} ]] && continue 452 [[ -z ${MODULES[i]} ]] && continue
453 for (( k=i+1; k<j; k++ )); do 453 for (( k=i+1; k<j; k++ )); do
454 if [[ ${PROVIDES[i]} == ${PROVIDES[k]} ]]; then 454 if [[ ${PROVIDES[i]} == ${PROVIDES[k]} ]] ; then
455 unset MODULES[k] 455 unset MODULES[k]
456 unset PROVIDES[k] 456 unset PROVIDES[k]
457 fi 457 fi
458 done 458 done
459 done 459 done
463 if ${starting}; then 463 if ${starting}; then
464 modules_check_user "${iface}" || return 1 464 modules_check_user "${iface}" || return 1
465 else 465 else
466 # Always prefer iproute2 for taking down interfaces 466 # Always prefer iproute2 for taking down interfaces
467 if is_function iproute2_provide ; then 467 if is_function iproute2_provide ; then
468 function_wrap iproute2 $(iproute2_provide) 468 function_wrap iproute2 "$(iproute2_provide)"
469 fi 469 fi
470 fi 470 fi
471 fi 471 fi
472 472
473 # Wrap our modules 473 # Wrap our modules
478 j="${#WRAP_MODULES[@]}" 478 j="${#WRAP_MODULES[@]}"
479 for (( i=0; i<j; i++ )); do 479 for (( i=0; i<j; i++ )); do
480 function_wrap ${WRAP_MODULES[i]} 480 function_wrap ${WRAP_MODULES[i]}
481 done 481 done
482 482
483 if [[ -z ${modules_force[@]} ]]; then 483 if [[ -z ${modules_force[@]} ]] ; then
484 modules_check_installed || return 1 484 modules_check_installed || return 1
485 modules_sort || return 1 485 modules_sort || return 1
486 fi 486 fi
487 487
488 veinfo "modules: ${MODULES[@]}" 488 veinfo "modules: ${MODULES[@]}"
505 local -a config fallback fallback_route conf a b 505 local -a config fallback fallback_route conf a b
506 local ifvar=$( bash_variable "$1" ) i j 506 local ifvar=$( bash_variable "$1" ) i j
507 507
508 # Try and work out a metric for the interface if we're on auto 508 # Try and work out a metric for the interface if we're on auto
509 x="metric_${ifvar}" 509 x="metric_${ifvar}"
510 if [[ -z ${!x} ]]; then 510 if [[ -z ${!x} ]] ; then
511 if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then 511 if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then
512 eval "metric_${ifvar}=\""$( calculate_metric ${iface} )"\"" 512 eval "metric_${ifvar}=\"$(calculate_metric ${iface})\""
513 else 513 else
514 eval "metric_${ifvar}=0" 514 eval "metric_${ifvar}=0"
515 fi 515 fi
516 fi 516 fi
517 517
526 # fallbacks expand to the same number as config or there will be 526 # fallbacks expand to the same number as config or there will be
527 # trouble! 527 # trouble!
528 a="config_${ifvar}[@]" 528 a="config_${ifvar}[@]"
529 a=( "${!a}" ) 529 a=( "${!a}" )
530 for (( i=0; i<${#a[@]}; i++ )); do 530 for (( i=0; i<${#a[@]}; i++ )); do
531 eval b=( $( expand_parameters "${a[i]}" ) ) 531 eval b=( $(expand_parameters "${a[i]}") )
532 config=( "${config[@]}" "${b[@]}" ) 532 config=( "${config[@]}" "${b[@]}" )
533 done 533 done
534 534
535 a="fallback_${ifvar}[@]" 535 a="fallback_${ifvar}[@]"
536 a=( "${!a}" ) 536 a=( "${!a}" )
537 for (( i=0; i<${#a[@]}; i++ )); do 537 for (( i=0; i<${#a[@]}; i++ )); do
538 eval b=( $( expand_parameters "${a[i]}" ) ) 538 eval b=( $(expand_parameters "${a[i]}") )
539 fallback=( "${fallback[@]}" "${b[@]}" ) 539 fallback=( "${fallback[@]}" "${b[@]}" )
540 done 540 done
541 541
542 # We don't expand routes 542 # We don't expand routes
543 fallback_route="fallback_route_${ifvar}[@]" 543 fallback_route="fallback_route_${ifvar}[@]"
544 fallback_route=( "${!fallback_route}" ) 544 fallback_route=( "${!fallback_route}" )
545 545
546 # We must support old configs 546 # We must support old configs
547 if [[ -z ${config} ]]; then 547 if [[ -z ${config} ]] ; then
548 interface_get_old_config "${iface}" || return 1 548 interface_get_old_config "${iface}" || return 1
549 if [[ -n ${config} ]]; then 549 if [[ -n ${config} ]] ; then
550 ewarn "You are using a depreciated configuration syntax for ${iface}" 550 ewarn "You are using a depreciated configuration syntax for ${iface}"
551 ewarn "You are advised to read /etc/conf.d/net.example and upgrade it accordingly" 551 ewarn "You are advised to read /etc/conf.d/net.example and upgrade it accordingly"
552 fi 552 fi
553 fi 553 fi
554 554
555 # Handle "noop" correctly 555 # Handle "noop" correctly
556 if [[ ${config[0]} == "noop" ]]; then 556 if [[ ${config[0]} == "noop" ]] ; then
557 if interface_is_up "${iface}" true ; then 557 if interface_is_up "${iface}" true ; then
558 einfo "Keeping current configuration for ${iface}" 558 einfo "Keeping current configuration for ${iface}"
559 eend 0 559 eend 0
560 return 0 560 return 0
561 fi 561 fi
564 config=( "${config[@]:1}" ) 564 config=( "${config[@]:1}" )
565 fi 565 fi
566 566
567 # Provide a default of DHCP if no configuration is set and we're auto 567 # Provide a default of DHCP if no configuration is set and we're auto
568 # Otherwise a default of NULL 568 # Otherwise a default of NULL
569 if [[ -z ${config} ]]; then 569 if [[ -z ${config} ]] ; then
570# if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then 570# if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then
571 ewarn "Configuration not set for ${iface} - assuming DHCP" 571 ewarn "Configuration not set for ${iface} - assuming DHCP"
572 if is_function "dhcp_start" ; then 572 if is_function "dhcp_start" ; then
573 config=( "dhcp" ) 573 config=( "dhcp" )
574 else 574 else
575 eerror "No DHCP client installed" 575 eerror "No DHCP client installed"
584 einfo "Bringing up ${iface}" 584 einfo "Bringing up ${iface}"
585 eindent 585 eindent
586 for (( config_counter=0; config_counter<${#config[@]}; config_counter++ )); do 586 for (( config_counter=0; config_counter<${#config[@]}; config_counter++ )); do
587 # Handle null and noop correctly 587 # Handle null and noop correctly
588 if [[ ${config[config_counter]} == "null" \ 588 if [[ ${config[config_counter]} == "null" \
589 || ${config[config_counter]} == "noop" ]]; then 589 || ${config[config_counter]} == "noop" ]] ; then
590 eend 0 590 eend 0
591 config_worked=true 591 config_worked=true
592 continue 592 continue
593 fi 593 fi
594 594
603 ${conf[0]}_start "${iface}" ; x=$? 603 ${conf[0]}_start "${iface}" ; x=$?
604 eoutdent 604 eoutdent
605 [[ ${x} == 0 ]] && config_worked=true && continue 605 [[ ${x} == 0 ]] && config_worked=true && continue
606 # We need to test to see if it's an IP address or a function 606 # We need to test to see if it's an IP address or a function
607 # We do this by testing if the 1st character is a digit 607 # We do this by testing if the 1st character is a digit
608 elif [[ ${conf[0]:0:1} == [[:digit:]] || ${conf[0]} == *:* ]]; then 608 elif [[ ${conf[0]:0:1} == [[:digit:]] || ${conf[0]} == *:* ]] ; then
609 x="0" 609 x="0"
610 if [[ ${RC_AUTO_INTERFACE} == "yes" ]] \ 610 if [[ ${RC_AUTO_INTERFACE} == "yes" ]] \
611 && is_function arping_address_exists ; then 611 && is_function arping_address_exists ; then
612 if arping_address_exists "${iface}" "${conf[0]}" ; then 612 if arping_address_exists "${iface}" "${conf[0]}" ; then
613 eerror "${conf[0]%%/*} already taken on ${iface}" 613 eerror "${conf[0]%%/*} already taken on ${iface}"
622 else 622 else
623 eerror "No loaded modules provide \"${conf[0]}\" (${conf[0]}_start)" 623 eerror "No loaded modules provide \"${conf[0]}\" (${conf[0]}_start)"
624 fi 624 fi
625 fi 625 fi
626 626
627 if [[ -n ${fallback[config_counter]} ]]; then 627 if [[ -n ${fallback[config_counter]} ]] ; then
628 einfo "Trying fallback configuration" 628 einfo "Trying fallback configuration"
629 config[config_counter]="${fallback[config_counter]}" 629 config[config_counter]="${fallback[config_counter]}"
630 fallback[config_counter]="" 630 fallback[config_counter]=""
631 631
632 # Do we have a fallback route? 632 # Do we have a fallback route?
633 if [[ -n ${fallback_route[config_counter]} ]]; then 633 if [[ -n ${fallback_route[config_counter]} ]] ; then
634 x="fallback_route[config_counter]" 634 x="fallback_route[config_counter]"
635 eval "routes_${ifvar}=( \"\${!x}\" )" 635 eval "routes_${ifvar}=( \"\${!x}\" )"
636 fallback_route[config_counter]="" 636 fallback_route[config_counter]=""
637 fi 637 fi
638 638
674 eindent 674 eindent
675 675
676 # Collect list of aliases for this interface. 676 # Collect list of aliases for this interface.
677 # List will be in reverse order. 677 # List will be in reverse order.
678 if interface_exists "${iface}" ; then 678 if interface_exists "${iface}" ; then
679 aliases=$( interface_get_aliases_rev "${iface}" ) 679 aliases="$(interface_get_aliases_rev "${iface}")"
680 fi 680 fi
681 681
682 # Stop aliases before primary interface. 682 # Stop aliases before primary interface.
683 # Note this must be done in reverse order, since ifconfig eth0:1 683 # Note this must be done in reverse order, since ifconfig eth0:1
684 # will remove eth0:2, etc. It might be sufficient to simply remove 684 # will remove eth0:2, etc. It might be sufficient to simply remove
698 # Delete all the addresses for this alias 698 # Delete all the addresses for this alias
699 interface_del_addresses "${i}" 699 interface_del_addresses "${i}"
700 700
701 # Do final shut down of this alias 701 # Do final shut down of this alias
702 if [[ ${IN_BACKGROUND} != "true" \ 702 if [[ ${IN_BACKGROUND} != "true" \
703 && ${RC_DOWN_INTERFACE} == "yes" ]]; then 703 && ${RC_DOWN_INTERFACE} == "yes" ]] ; then
704 ebegin "Shutting down ${i}" 704 ebegin "Shutting down ${i}"
705 interface_iface_stop "${i}" 705 interface_iface_stop "${i}"
706 eend "$?" 706 eend "$?"
707 fi 707 fi
708 done 708 done
722# Returns 0 (success) unless preup or iface_start returns 1 (failure). 722# Returns 0 (success) unless preup or iface_start returns 1 (failure).
723# Ignores the return value from postup. 723# Ignores the return value from postup.
724# We cannot check that the device exists ourselves as modules like 724# We cannot check that the device exists ourselves as modules like
725# tuntap make create it. 725# tuntap make create it.
726run_start() { 726run_start() {
727 local iface="$1" IFVAR=$( bash_variable "$1" ) 727 local iface="$1" IFVAR="$(bash_variable "$1")"
728 728
729 # We do this so users can specify additional addresses for lo if they 729 # We do this so users can specify additional addresses for lo if they
730 # need too - additional routes too 730 # need too - additional routes too
731 # However, no extra modules are loaded as they are just not needed 731 # However, no extra modules are loaded as they are just not needed
732 if [[ ${iface} == "lo" ]]; then 732 if [[ ${iface} == "lo" ]] ; then
733 metric_lo="0" 733 metric_lo="0"
734 config_lo=( "127.0.0.1/8 brd 127.255.255.255" "${config_lo[@]}" ) 734 config_lo=( "127.0.0.1/8 brd 127.255.255.255" "${config_lo[@]}" )
735 routes_lo=( "127.0.0.0/8" "${routes_lo[@]}" ) 735 routes_lo=( "127.0.0.0/8" "${routes_lo[@]}" )
736 fi 736 fi
737 737
770 [[ ${config[0]} == "noop" ]] \ 770 [[ ${config[0]} == "noop" ]] \
771 && eval "config_${IFVAR}=( "\"\$\{config\[@\]:1\}\"" )" 771 && eval "config_${IFVAR}=( "\"\$\{config\[@\]:1\}\"" )"
772 772
773 # There may be existing ip address info - so we strip it 773 # There may be existing ip address info - so we strip it
774 if [[ ${RC_INTERFACE_KEEP_CONFIG} != "yes" \ 774 if [[ ${RC_INTERFACE_KEEP_CONFIG} != "yes" \
775 && ${IN_BACKGROUND} != "true" ]]; then 775 && ${IN_BACKGROUND} != "true" ]] ; then
776 interface_del_addresses "${iface}" 776 interface_del_addresses "${iface}"
777 fi 777 fi
778 778
779 # Start the interface 779 # Start the interface
780 if ! iface_start "${iface}" ; then 780 if ! iface_start "${iface}" ; then
781 if [[ ${IN_BACKGROUND} != "true" ]]; then 781 if [[ ${IN_BACKGROUND} != "true" ]] ; then
782 interface_exists "${iface}" && interface_down "${iface}" 782 interface_exists "${iface}" && interface_down "${iface}"
783 fi 783 fi
784 eend 1 784 eend 1
785 return 1 785 return 1
786 fi 786 fi
804# 804#
805# Brings down ${iface}. If predown call returns non-zero, then 805# Brings down ${iface}. If predown call returns non-zero, then
806# stop returns non-zero to indicate failure bringing down device. 806# stop returns non-zero to indicate failure bringing down device.
807# In all other cases stop returns 0 to indicate success. 807# In all other cases stop returns 0 to indicate success.
808run_stop() { 808run_stop() {
809 local iface="$1" IFVAR=$( bash_variable "$1" ) x 809 local iface="$1" IFVAR="$(bash_variable "$1")" x
810 810
811 # Load our ESSID variable so users can use it in predown() instead 811 # Load our ESSID variable so users can use it in predown() instead
812 # of having to write code. 812 # of having to write code.
813 local ESSID=$( get_options "ESSID" ) ESSIDVAR 813 local ESSID="$(get_options ESSID)" ESSIDVAR
814 [[ -n ${ESSID} ]] && ESSIDVAR=$( bash_variable "${ESSID}" ) 814 [[ -n ${ESSID} ]] && ESSIDVAR="$(bash_variable "${ESSID}")"
815 815
816 # Call user-defined predown function if it exists 816 # Call user-defined predown function if it exists
817 if is_function predown ; then 817 if is_function predown ; then
818 einfo "Running predown function" 818 einfo "Running predown function"
819 eindent 819 eindent
853 local iface="$1" cmd="$2" r=1 RC_INDENTATION="${RC_INDENTATION}" 853 local iface="$1" cmd="$2" r=1 RC_INDENTATION="${RC_INDENTATION}"
854 local starting=true 854 local starting=true
855 local -a MODULES mods 855 local -a MODULES mods
856 local IN_BACKGROUND="${IN_BACKGROUND}" 856 local IN_BACKGROUND="${IN_BACKGROUND}"
857 857
858 if [[ ${IN_BACKGROUND} == "true" || ${IN_BACKGROUND} == "1" ]]; then 858 if [[ ${IN_BACKGROUND} == "true" || ${IN_BACKGROUND} == "1" ]] ; then
859 IN_BACKGROUND=true 859 IN_BACKGROUND=true
860 else 860 else
861 IN_BACKGROUND=false 861 IN_BACKGROUND=false
862 fi 862 fi
863 863
870 870
871 # We force lo to only use these modules for a major speed boost 871 # We force lo to only use these modules for a major speed boost
872 [[ ${iface} == "lo" ]] && modules_force=( "iproute2" "ifconfig" "system" ) 872 [[ ${iface} == "lo" ]] && modules_force=( "iproute2" "ifconfig" "system" )
873 873
874 if modules_load "${iface}" "${starting}" ; then 874 if modules_load "${iface}" "${starting}" ; then
875 if [[ ${cmd} == "stop" ]]; then 875 if [[ ${cmd} == "stop" ]] ; then
876 # Reverse the module list for stopping 876 # Reverse the module list for stopping
877 mods=( "${MODULES[@]}" ) 877 mods=( "${MODULES[@]}" )
878 for ((i = 0; i < ${#mods[@]}; i++)); do 878 for ((i = 0; i < ${#mods[@]}; i++)); do
879 MODULES[i]=${mods[((${#mods[@]} - i - 1))]} 879 MODULES[i]=${mods[((${#mods[@]} - i - 1))]}
880 done 880 done
893 run_start "${iface}" && r=0 893 run_start "${iface}" && r=0
894 fi 894 fi
895 fi 895 fi
896 896
897 # Only apply best state if we're on auto 897 # Only apply best state if we're on auto
898 if [[ ${r} == "0" ]]; then 898 if [[ ${r} == "0" ]] ; then
899 local siface="" 899 local siface=""
900 if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then 900 if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then
901 siface=$( select_best_interface ) 901 siface="$(select_best_interface)"
902 if [[ -n ${siface} ]]; then 902 if [[ -n ${siface} ]] ; then
903 einfo "Selecting best interface: ${siface}" 903 einfo "Selecting best interface: ${siface}"
904 fi 904 fi
905 elif [[ ${cmd} == "start" ]]; then 905 elif [[ ${cmd} == "start" ]] ; then
906 siface="${iface}" 906 siface="${iface}"
907 fi 907 fi
908 [[ -n ${siface} ]] && apply_state "${siface}" 908 [[ -n ${siface} ]] && apply_state "${siface}"
909 else 909 else
910 if [[ ${cmd} == "start" ]]; then 910 if [[ ${cmd} == "start" ]] ; then
911 # Call user-defined failup if it exists 911 # Call user-defined failup if it exists
912 if is_function failup ; then 912 if is_function failup ; then
913 einfo "Running failup function" 913 einfo "Running failup function"
914 eindent 914 eindent
915 ( failup "${iface}" ) 915 ( failup "${iface}" )
936# Move a config file from /etc to ${netdir} and creates a link if needed. 936# Move a config file from /etc to ${netdir} and creates a link if needed.
937# This enables net-scripts to control the config file for interface management 937# This enables net-scripts to control the config file for interface management
938# and allow /etc to become read only. 938# and allow /etc to become read only.
939link_file() { 939link_file() {
940 local file="$1" 940 local file="$1"
941 local link=$( readlink "/etc/${file}" 2>/dev/null ) 941 local link="$(readlink "/etc/${file}" 2>/dev/null)"
942 if [[ ${link} != "${netdir}/${file}" ]]; then 942 if [[ ${link} != "${netdir}/${file}" ]] ; then
943 if [[ -f "/etc/${file}" ]]; then 943 if [[ -f "/etc/${file}" ]] ; then
944 vewarn "Moving /etc/${file} to ${netdir}/${file} and creating link" 944 vewarn "Moving /etc/${file} to ${netdir}/${file} and creating link"
945 mv "/etc/${file}" "${netdir}" 945 mv "/etc/${file}" "${netdir}"
946 ln -snf "${netdir}/${file}" "/etc/${file}" 946 ln -snf "${netdir}/${file}" "/etc/${file}"
947 fi 947 fi
948 fi 948 fi
951# bool start(void) 951# bool start(void)
952# 952#
953# Start entry point so that we only have one function 953# Start entry point so that we only have one function
954# which localises variables and unsets functions 954# which localises variables and unsets functions
955start() { 955start() {
956 if [[ ${IN_HOTPLUG} == "1" ]]; then 956 if [[ ${IN_HOTPLUG} == "1" ]] ; then
957 # If we've been called by hotplug, check if we have 957 # If we've been called by hotplug, check if we have
958 # a policy for the interface for not starting 958 # a policy for the interface for not starting
959 local x ifvar=$( bash_variable "${IFACE}" ) 959 local x ifvar="$(bash_variable "${IFACE}")"
960 x="hotplug_${ifvar}" 960 x="hotplug_${ifvar}"
961 if [[ ${!x} == "no" || ${!x} == "false" ]]; then 961 if [[ ${!x} == "no" || ${!x} == "false" ]] ; then
962 eerror "Not starting interface ${IFACE} due to hotplug policy" 962 eerror "Not starting interface ${IFACE} due to hotplug policy"
963 unset -f exit 963 unset -f exit
964 mark_service_stopped "net.${IFACE}" 964 mark_service_stopped "net.${IFACE}"
965 exit 1 965 exit 1
966 fi 966 fi
967 fi 967 fi
968 968
969 if [[ ! -d "${statedir}/${IFACE}" ]]; then 969 if [[ ! -d "${statedir}/${IFACE}" ]] ; then
970 if ! mkdir -m 0755 -p "${statedir}/${IFACE}" ; then 970 if ! mkdir -m 0755 -p "${statedir}/${IFACE}" ; then
971 eerror "Unable to create state directory!" 971 eerror "Unable to create state directory!"
972 return 1 972 return 1
973 fi 973 fi
974 fi 974 fi
975 975
976 if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then 976 if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then
977 link_file "resolv.conf" 977 link_file "resolv.conf"
978 link_file "ntp.conf" 978 link_file "ntp.conf"
979 link_file "yp.conf" 979 link_file "yp.conf"
980 fi 980 fi
981 981

Legend:
Removed from v.235  
changed lines
  Added in v.236

  ViewVC Help
Powered by ViewVC 1.1.20