2005-11-19 03:17:20 +00:00
|
|
|
#!/bin/sh
|
|
|
|
setup_eth()
|
|
|
|
{
|
2006-01-14 02:31:36 +00:00
|
|
|
for part in $(nvram get unused_ifnames); do
|
|
|
|
[ "$part" = "$INTERFACE" ] && exit 0
|
2006-01-11 16:13:25 +00:00
|
|
|
done
|
2005-11-19 03:17:20 +00:00
|
|
|
ifconfig "$INTERFACE" up 2>&- >&-
|
|
|
|
}
|
|
|
|
|
|
|
|
find_name()
|
|
|
|
{
|
|
|
|
pppoa_ifname="atm0" # hack for ppp over atm, which has no ${proto}_ifname
|
|
|
|
interfaces="lan wan wifi $(nvram get ifnames)"
|
|
|
|
for ifname in $interfaces; do
|
|
|
|
IFTYPE="${ifname}"
|
|
|
|
IFPROTO="$(nvram get ${IFTYPE}_proto)"
|
|
|
|
IFACE="$(nvram get ${IFTYPE}_ifname)"
|
2005-11-19 19:04:15 +00:00
|
|
|
case "$IFPROTO" in
|
|
|
|
""|none);;
|
|
|
|
static|dhcp)
|
|
|
|
[ "${IFACE}" = "$INTERFACE" ] && return 0
|
|
|
|
[ "${IFACE%%[0-9]*}" = "br" ] && {
|
|
|
|
for part in $(nvram get ${IFTYPE}_ifnames); do
|
|
|
|
[ "$part" = "$INTERFACE" ] && return 0
|
|
|
|
done
|
|
|
|
}
|
|
|
|
;;
|
|
|
|
*)
|
2006-01-16 03:14:59 +00:00
|
|
|
[ "$(nvram get ${IFTYPE}_device)" = "$INTERFACE" \
|
2005-11-19 19:04:15 +00:00
|
|
|
-a -x /sbin/ifup.${IFPROTO} ] && return 0
|
|
|
|
;;
|
|
|
|
esac
|
2005-11-19 03:17:20 +00:00
|
|
|
done
|
|
|
|
IFACE=""
|
|
|
|
IFTYPE=""
|
|
|
|
IFPROTO=""
|
|
|
|
return 255
|
|
|
|
}
|
|
|
|
|
|
|
|
do_ifup() {
|
|
|
|
if="$3"
|
|
|
|
if_proto="$(nvram get ${2}_proto)"
|
|
|
|
|
|
|
|
pidfile=/var/run/${if}.pid
|
|
|
|
[ -f $pidfile ] && $DEBUG kill $(cat $pidfile)
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
static)
|
|
|
|
ip=$(nvram get ${2}_ipaddr)
|
2006-01-10 21:20:09 +00:00
|
|
|
ip6=$(nvram get ${2}_ip6addr)
|
2005-11-19 03:17:20 +00:00
|
|
|
netmask=$(nvram get ${2}_netmask)
|
|
|
|
gateway=$(nvram get ${2}_gateway)
|
|
|
|
|
|
|
|
$DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up
|
2006-01-10 21:20:09 +00:00
|
|
|
[ -n "$ip6" ] && $DEBUG ifconfig $if add $ip6
|
|
|
|
|
2005-11-19 03:17:20 +00:00
|
|
|
${gateway:+$DEBUG route add default gw $gateway}
|
|
|
|
|
2006-01-10 21:16:46 +00:00
|
|
|
[ -f /tmp/resolv.conf ] || {
|
|
|
|
debug "# --- creating /tmp/resolv.conf ---"
|
2005-11-19 03:17:20 +00:00
|
|
|
for dns in $(nvram get ${2}_dns); do
|
2006-01-10 21:16:46 +00:00
|
|
|
echo "nameserver $dns" >> /tmp/resolv.conf
|
2005-11-19 03:17:20 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
env -i ACTION="ifup" INTERFACE="${2}" PROTO=static /sbin/hotplug "iface" &
|
|
|
|
;;
|
|
|
|
dhcp)
|
|
|
|
DHCP_IP=$(nvram get ${2}_ipaddr)
|
|
|
|
DHCP_NETMASK=$(nvram get ${2}_netmask)
|
|
|
|
$DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up
|
|
|
|
|
|
|
|
DHCP_ARGS="-i $if ${DHCP_IP:+-r $DHCP_IP} -b -p $pidfile"
|
|
|
|
DHCP_HOSTNAME=$(nvram get ${2}_hostname)
|
|
|
|
DHCP_HOSTNAME=${DHCP_HOSTNAME%%.*}
|
|
|
|
[ -z $DHCP_HOSTNAME ] || DHCP_ARGS="$DHCP_ARGS -H $DHCP_HOSTNAME"
|
|
|
|
[ "$if_proto" = "pptp" ] && DHCP_ARGS="$DHCP_ARGS -n -q" || DHCP_ARGS="$DHCP_ARGS -R &"
|
|
|
|
${DEBUG:-eval} "udhcpc $DHCP_ARGS"
|
|
|
|
# hotplug events are handled by /usr/share/udhcpc/default.script
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -x "/sbin/ifup.$1" ]; then
|
|
|
|
( $DEBUG . /sbin/ifup.$1 ${2} $3 )
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
do_register()
|
|
|
|
{
|
|
|
|
case "${INTERFACE%%[0-9]*}" in
|
|
|
|
eth) setup_eth;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[ -z "$IFTYPE" -o -z "$IFPROTO" ] && {
|
|
|
|
find_name || {
|
|
|
|
case "${INTERFACE%%[0-9]*}" in
|
|
|
|
wds)
|
|
|
|
for tmp in lan wifi; do
|
|
|
|
[ -z "$IFPROTO" ] && [ "$(nvram get ${tmp}_ifname)" = "br0" ] && {
|
|
|
|
IFPROTO="$(nvram get ${tmp}_proto)"
|
|
|
|
IFTYPE="${tmp}"
|
|
|
|
}
|
|
|
|
done
|
|
|
|
[ -z "$IFPROTO" ] && return 0
|
|
|
|
;;
|
|
|
|
atm)
|
|
|
|
for tmp in lan wan wifi $(nvram get ifnames); do
|
|
|
|
[ "$(nvram get ${tmp}_proto)" = "pppoa" ] && {
|
|
|
|
do_ifup "pppoa" "$tmp" "$INTERFACE"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case "${INTERFACE%%[0-9]*}" in
|
|
|
|
ppp|atm);;
|
|
|
|
*)
|
|
|
|
mac=$(nvram get ${IFTYPE}_hwaddr)
|
|
|
|
${mac:+$DEBUG ifconfig $INTERFACE down hw ether $mac}
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if="$(nvram get ${IFTYPE}_ifname)"
|
|
|
|
if [ "${if%%[0-9]}" = "br" ]; then
|
|
|
|
if_valid "$INTERFACE" && {
|
|
|
|
ifconfig "$if" 2>&- >&- || {
|
|
|
|
stp=$(nvram get ${IFTYPE}_stp)
|
|
|
|
$DEBUG brctl addbr "$if"
|
|
|
|
$DEBUG brctl setfd "$if" 0
|
|
|
|
$DEBUG brctl stp "$if" "${stp:-0}"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$INTERFACE" != "$if" ]; then
|
|
|
|
$DEBUG ifconfig "$INTERFACE" 0.0.0.0 up
|
|
|
|
brctl addif "$if" "$INTERFACE"
|
|
|
|
else
|
|
|
|
do_ifup "$IFPROTO" "$IFTYPE" "$if"
|
|
|
|
fi
|
|
|
|
}
|
2005-11-19 19:04:15 +00:00
|
|
|
else
|
|
|
|
[ "${INTERFACE%%[0-9]*}" = "ppp" ] || do_ifup "$IFPROTO" "$IFTYPE" "$if"
|
2005-11-19 03:17:20 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
do_unregister() {
|
|
|
|
[ -z "$IFTYPE" -o -z "$IFPROTO" ] && find_name
|
|
|
|
[ -z "$IFTYPE" -o -z "$IFPROTO" ] && return 0
|
|
|
|
|
|
|
|
[ "${IFACE%%[0-9]*}" = "br" ] && {
|
|
|
|
if [ "$INTERFACE" != "$IFACE" ]; then
|
|
|
|
brctl delif "$IFACE" "$INTERFACE" 2>&- >&-
|
|
|
|
else
|
|
|
|
brctl delbr "$IFACE" 2>&- >&-
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$IFPROTO" in
|
|
|
|
pppoe|pppoa|pptp)
|
2005-11-19 14:53:21 +00:00
|
|
|
killall pppd 2>&- >&-
|
2005-11-19 03:17:20 +00:00
|
|
|
;;
|
|
|
|
dhcp)
|
|
|
|
[ -f /var/run/${INTERFACE}.pid ] && kill "$(cat /var/run/${INTERFACE}.pid)" 2>&- >&-
|
|
|
|
;;
|
|
|
|
esac
|
2005-11-19 19:04:15 +00:00
|
|
|
|
|
|
|
[ "${INTERFACE%%[0-9]*}" = "atm" ] || ifconfig "$INTERFACE" 0.0.0.0 down 2>&-
|
2005-11-19 03:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case "$ACTION" in
|
2005-12-17 02:11:04 +00:00
|
|
|
add|register) do_register;;
|
|
|
|
remove|unregister) do_unregister;;
|
2005-11-19 03:17:20 +00:00
|
|
|
esac
|