3 alias debug
=${DEBUG:-true}
5 # allow env to override nvram
7 eval "echo \${$1:-\$(nvram get $1)}"
13 [ "${1%%[0-9]}" = "vlan" ] && {
15 hwname
=$
(nvram_get vlan
${i}hwname
)
16 hwaddr
=$
(nvram_get
${hwname}macaddr
)
17 [ -z "$hwaddr" ] && return 1
19 vif
=$
(ifconfig
-a |
awk '{IGNORECASE=1} /^eth.*'$hwaddr'/ {print $1; exit}')
20 debug
"# vlan$i: $hwname $hwaddr => $vif"
22 $DEBUG ifconfig
$vif up
23 $DEBUG vconfig add
$vif $i 2>/dev
/null
25 ifconfig
"$1" >/dev
/null
2>&1 ||
[ "${1%%[0-9]}" = "br" ]
29 debug
"### wifi $1 ###"
30 if=$
(awk 'gsub(":","") {print $1}' /proc
/net
/wireless
)
36 debug
"### ifup $type ###"
38 if=$
(nvram_get
${type}_ifname
)
39 if [ "${if%%[0-9]}" = "ppp" ]; then
40 if=$
(nvram_get pppoe_ifname
)
43 if_valid
$if ||
return
45 $DEBUG ifconfig
$if down
46 if [ "${if%%[0-9]}" = "br" ]; then
47 stp
=$
(nvram_get
${type}_stp
)
48 $DEBUG brctl delbr
$if
49 $DEBUG brctl addbr
$if
50 $DEBUG brctl setfd
$if 0
51 $DEBUG brctl stp
$if $stp
52 if_list
=$
(nvram_get
${type}_ifnames
)
53 for sif
in $if_list; do {
54 if_valid
$sif ||
continue
55 $DEBUG ifconfig
$sif 0.0.0.0 up
56 $DEBUG brctl addif
$if $sif
60 if_mac
=$
(nvram_get
${type}_hwaddr
)
61 ${if_mac:+$DEBUG ifconfig $if hw ether $if_mac}
63 if_proto
=$
(nvram_get
${type}_proto
)
66 if_ip
=$
(nvram_get
${type}_ipaddr
)
67 if_netmask
=$
(nvram_get
${type}_netmask
)
68 if_gateway
=$
(nvram_get
${type}_gateway
)
70 $DEBUG ifconfig
$if $if_ip ${if_netmask:+netmask $if_netmask} up
71 ${if_gateway:+$DEBUG route add default gw $if_gateway}
73 [ -f /etc
/resolv.conf
] && return
75 debug
"# --- creating /etc/resolv.conf ---"
76 for dns
in $
(nvram_get
${type}_dns
); do {
77 echo "nameserver $dns" >> /etc
/resolv.conf
81 pidfile
=/tmp
/dhcp-
${type}.pid
82 if [ -f $pidfile ]; then
83 $DEBUG kill $
(cat $pidfile)
85 ${DEBUG:-eval} "udhcpc -i $if -b -p $pidfile &"
88 if_username
=$
(nvram_get ppp_username
)
89 if_password
=$
(nvram_get ppp_passwd
)
90 if_redial
=$
(nvram_get ppp_redialperiod
)
91 if_idletime
=$
(nvram_get ppp_idletime
)
93 $DEBUG ifconfig
$if 0.0.0.0 up
95 $DEBUG /sbin
/pppoecd
$if -u $if_username -p $if_password -i 0 -I $if_redial -T $if_idletime -k
98 echo "### WARNING $if: $if_proto is not supported"
105 debug
"### ifdown $type ###"
106 if=$
(nvram_get
${type}_ifname
)
107 if_valid
$if && $DEBUG ifconfig
$if down