5 |
# get default settings |
# get default settings |
6 |
source /etc/conf.d/network |
source /etc/conf.d/network |
7 |
|
|
8 |
|
iface_wait_online() |
9 |
|
{ |
10 |
|
local timeout="$1" |
11 |
|
local iface="$2" |
12 |
|
|
13 |
|
(( timeout *= 10 )) |
14 |
|
|
15 |
|
while [ ! -e /sys/class/net/${iface} ] |
16 |
|
do |
17 |
|
(( timeout-- > 0 )) || return 1 |
18 |
|
echo "waiting 0.1 seconds for device '${iface}' - timeout->'${timeout}'" |
19 |
|
sleep 0.1 |
20 |
|
done |
21 |
|
|
22 |
|
return 0 |
23 |
|
} |
24 |
|
|
25 |
|
iface_has_link() |
26 |
|
{ |
27 |
|
local interface="$1" |
28 |
|
local flags |
29 |
|
|
30 |
|
[[ -n ${interface} ]] || return 2 |
31 |
|
interface="/sys/class/net/${interface}" |
32 |
|
[[ -d ${interface} ]] || return 2 |
33 |
|
flags=$(cat ${interface}/flags) |
34 |
|
echo $((${flags}|0x41)) > ${interface}/flags # 0x41: IFF_UP|IFF_RUNNING |
35 |
|
[ "$(cat ${interface}/carrier)" = 1 ] || return 1 |
36 |
|
} |
37 |
|
|
38 |
# read values from files |
# read values from files |
39 |
read_value() |
read_value() |
40 |
{ |
{ |
197 |
return 1 |
return 1 |
198 |
fi |
fi |
199 |
|
|
200 |
if [ ! -x /sbin/wpa_supplicant ] |
if [ ! -x $(type -P wpa_supplicant) ] |
201 |
then |
then |
202 |
echo "WPA: wpa_supplicant not installed. Aborting setup." |
echo "WPA: wpa_supplicant not installed. Aborting setup." |
203 |
return 1 |
return 1 |
458 |
source /etc/conf.d/net.${iface} || exit 1 |
source /etc/conf.d/net.${iface} || exit 1 |
459 |
checkconfig |
checkconfig |
460 |
|
|
461 |
|
# wait until the device is created |
462 |
|
iface_wait_online 5 "${iface}" || { echo "device '${iface}' does not exist"; continue; } |
463 |
|
|
464 |
# setup mac |
# setup mac |
465 |
if [[ -n ${FORCE_MAC_TO} ]] |
if [[ -n ${FORCE_MAC_TO} ]] |
466 |
then |
then |
474 |
fi |
fi |
475 |
|
|
476 |
# now configure wireless_extensions |
# now configure wireless_extensions |
477 |
[ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}" |
[ -x $(type -P iwconfig) ] && setup_wireless_extensions "${iface}" |
478 |
|
|
479 |
# activate the interface |
# activate the interface |
480 |
ifconfig "${iface}" up |
ifconfig "${iface}" up |
482 |
# setup static or dhcp |
# setup static or dhcp |
483 |
case ${NETWORKING} in |
case ${NETWORKING} in |
484 |
dhcp|DHCP) |
dhcp|DHCP) |
485 |
${DHCP_PROG} ${DHCP_START} "${iface}" ;; |
if iface_has_link "${iface}" |
486 |
|
then |
487 |
|
${DHCP_PROG} ${DHCP_START} "${iface}" |
488 |
|
else |
489 |
|
echo "Interface '${iface}' has no link. Not running '${DHCP_PROG}'." |
490 |
|
fi |
491 |
|
;; |
492 |
static|STATIC) |
static|STATIC) |
493 |
ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}" ;; |
ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}" ;; |
494 |
esac |
esac |