3 alias debug
=${DEBUG:-:}
7 ifconfig
"$1" >&- 2>&- ||
8 [ "${1%%[0-9]}" = "br" ] ||
10 [ "${1%%[0-9]}" = "vlan" ] && (
12 hwname
=$
(nvram get vlan
${i}hwname
)
13 hwaddr
=$
(nvram get
${hwname}macaddr
)
14 [ -z "$hwaddr" ] && return 1
16 vif
=$
(ifconfig
-a |
awk '/^eth.*'$hwaddr'/ {print $1; exit}' IGNORECASE
=1)
17 debug
"# vlan$i => $vif"
19 $DEBUG ifconfig
$vif up
20 $DEBUG vconfig add
$vif $i 2>&-
23 { debug
"# missing interface '$1' ignored"; false
; }
27 if_proto
=$
(nvram get
${2}_proto
)
28 if=$
(nvram get
${2}_ifname
)
29 [ "${if%%[0-9]}" = "ppp" ] && if=$
(nvram get
${2}_device
)
31 pidfile
=/var
/run
/${if}.pid
32 [ -f $pidfile ] && $DEBUG kill $
(cat $pidfile)
36 ip
=$
(nvram get
${2}_ipaddr
)
37 netmask
=$
(nvram get
${2}_netmask
)
38 gateway
=$
(nvram get
${2}_gateway
)
39 mtu
=$
(nvram get
${2}_mtu
)
40 static_route
=$
(nvram get
${2}_static_route
)
42 $DEBUG ifconfig
$if $ip ${netmask:+netmask $netmask} ${mtu:+mtu $(($mtu))} broadcast
+ up
43 ${gateway:+$DEBUG route add default gw $gateway}
45 [ -n "$static_route" ] && {
46 for route
in $static_route; do {
47 eval "set $(echo $route | sed 's/:/ /g')"
48 if [ "$2" = "255.255.255.255" ]; then
51 $DEBUG route add
${opt:-"-net"} $1 netmask
$2 gw
$3 metric
$4
55 [ -f /etc
/resolv.conf
] ||
{
56 debug
"# --- creating /etc/resolv.conf ---"
57 for dns
in $
(nvram get
${2}_dns
); do
58 echo "nameserver $dns" >> /etc
/resolv.conf
62 env
-i ACTION
="ifup" INTERFACE
="${2}" PROTO
=static
/sbin
/hotplug
"iface" &
65 DHCP_IP
=$
(nvram get
${2}_ipaddr
)
66 DHCP_NETMASK
=$
(nvram get
${2}_netmask
)
67 mtu
=$
(nvram get
${2}_mtu
)
68 $DEBUG ifconfig
$if $ip ${netmask:+netmask $netmask} ${mtu:+mtu $(($mtu))} broadcast
+ up
70 DHCP_ARGS
="-i $if ${DHCP_IP:+-r $DHCP_IP} -b -p $pidfile"
71 DHCP_HOSTNAME
=$
(nvram get
${2}_hostname
)
72 DHCP_HOSTNAME
=${DHCP_HOSTNAME%%.*}
73 [ -z $DHCP_HOSTNAME ] || DHCP_ARGS
="$DHCP_ARGS -H $DHCP_HOSTNAME"
74 [ "$if_proto" = "pptp" ] && DHCP_ARGS
="$DHCP_ARGS -n -q" || DHCP_ARGS
="$DHCP_ARGS -R &"
75 [ -r $pidfile ] && oldpid
=$
(cat $pidfile 2>&-)
76 ${DEBUG:-eval} "udhcpc $DHCP_ARGS"
77 [ -n "$oldpid" ] && pidof udhcpc |
grep "$oldpid" >&- 2>&- && {
81 # hotplug events are handled by /usr/share/udhcpc/default.script
86 [ -x "/sbin/ifup.$1" ] && { $DEBUG /sbin
/ifup.
$1 ${2}; exit; }
87 echo "### ifup ${2}: ignored ${2}_proto=\"$1\" (not supported)"