3 alias debug
=${DEBUG:-:}
5 # allow env to override nvram
8 get
) eval "echo \${NVRAM_$2:-\$(command nvram get $2)}";;
12 [ "$FAILSAFE" = "true" ] && .
/etc
/nvram.overrides
16 ifconfig
"$1" >&- 2>&- ||
17 [ "${1%%[0-9]}" = "br" ] ||
19 [ "${1%%[0-9]}" = "vlan" ] && (
21 hwname
=$
(nvram get vlan
${i}hwname
)
22 hwaddr
=$
(nvram get
${hwname}macaddr
)
23 [ -z "$hwaddr" ] && return 1
25 vif
=$
(ifconfig
-a |
awk '/^eth.*'$hwaddr'/ {print $1; exit}' IGNORECASE
=1)
26 debug
"# vlan$i => $vif"
28 $DEBUG ifconfig
$vif up
29 $DEBUG vconfig add
$vif $i 2>&-
32 { debug
"# missing interface '$1' ignored"; false
; }
36 if_proto
=$
(nvram get
${2}_proto
)
37 if=$
(nvram get
${2}_ifname
)
38 [ "${if%%[0-9]}" = "ppp" ] && if=$
(nvram get
${if_proto}_ifname
)
40 pidfile
=/var
/run
/${if}.pid
41 [ -f $pidfile ] && $DEBUG kill $
(cat $pidfile)
45 ip
=$
(nvram get
${2}_ipaddr
)
46 netmask
=$
(nvram get
${2}_netmask
)
47 gateway
=$
(nvram get
${2}_gateway
)
49 $DEBUG ifconfig
$if $ip ${netmask:+netmask $netmask} broadcast
+ up
50 ${gateway:+$DEBUG route add default gw $gateway}
52 [ -f /etc
/resolv.conf
] && return
54 debug
"# --- creating /etc/resolv.conf ---"
55 for dns
in $
(nvram get
${2}_dns
); do
56 echo "nameserver $dns" >> /etc
/resolv.conf
60 DHCP_IP
=$
(nvram get
${2}_ipaddr
)
61 DHCP_NETMASK
=$
(nvram get
${2}_netmask
)
62 $DEBUG ifconfig
$if $ip ${netmask:+netmask $netmask} broadcast
+ up
64 DHCP_ARGS
="-i $if ${DHCP_IP:+-r $DHCP_IP} -b -p $pidfile"
65 DHCP_HOSTNAME
=$
(nvram get
${2}_hostname
)
66 DHCP_HOSTNAME
=${DHCP_HOSTNAME%%.*}
67 [ -z $DHCP_HOSTNAME ] || DHCP_ARGS
="$DHCP_ARGS -H $DHCP_HOSTNAME"
68 [ "$if_proto" = "pptp" ] && DHCP_ARGS
="$DHCP_ARGS -n -q" || DHCP_ARGS
="$DHCP_ARGS -R &"
69 oldpid
=$
(cat $pidfile)
70 ${DEBUG:-eval} "udhcpc $DHCP_ARGS"
71 pidof udhcpc |
grep "$oldpid" >&- 2>&- && {
79 [ -x "/sbin/ifup.$1" ] && { $DEBUG /sbin
/ifup.
$1 ${2}; exit; }
80 echo "### ifup ${2}: ignored ${2}_proto=\"$1\" (not supported)"
88 c
=((c
>> 1)&0x55555555)+(c
&0x55555555),
89 c
=((c
>> 2)&0x33333333)+(c
&0x33333333),
90 c
=((c
>> 4)&0x0f0f0f0f)+(c
&0x0f0f0f0f),
91 c
=((c
>> 8)&0x00ff00ff)+(c
&0x00ff00ff),
92 c
=((c
>>16)&0x0000ffff)+(c
&0x0000ffff)
101 set $
(echo $1 |
tr '\.' ' ')
102 echo $
(($1<<24|$2<<16|$3<<8|$4))
106 echo $(($1>>24&255)).$
(($1>>16&255)).$
(($1>>8&255)).$
(($1&255))