2005-11-19 03:17:20 +00:00
|
|
|
#!/bin/sh
|
|
|
|
find_name()
|
|
|
|
{
|
2006-04-05 02:09:22 +00:00
|
|
|
for ifname in lan wan wifi ${ifnames}; do
|
2005-11-19 03:17:20 +00:00
|
|
|
IFTYPE="${ifname}"
|
2006-04-05 02:09:22 +00:00
|
|
|
eval "IFPROTO=\"\${${IFTYPE}_proto}\""
|
|
|
|
eval "IFACE=\"\${${IFTYPE}_ifname}\""
|
2005-11-19 19:04:15 +00:00
|
|
|
case "$IFPROTO" in
|
|
|
|
""|none);;
|
|
|
|
static|dhcp)
|
|
|
|
[ "${IFACE}" = "$INTERFACE" ] && return 0
|
|
|
|
[ "${IFACE%%[0-9]*}" = "br" ] && {
|
2006-04-05 02:09:22 +00:00
|
|
|
eval "ifs=\"\${${IFTYPE}_ifnames}\""
|
|
|
|
for part in $ifs; do
|
2005-11-19 19:04:15 +00:00
|
|
|
[ "$part" = "$INTERFACE" ] && return 0
|
|
|
|
done
|
|
|
|
}
|
|
|
|
;;
|
2006-04-05 02:09:22 +00:00
|
|
|
pppoa)
|
|
|
|
[ "$INTERFACE" = "atm0" \
|
|
|
|
-a -x /sbin/ifup.${IFPROTO} ] && return 0
|
|
|
|
;;
|
2005-11-19 19:04:15 +00:00
|
|
|
*)
|
2006-04-05 02:09:22 +00:00
|
|
|
eval "device=\"\${${IFTYPE}_device}\""
|
|
|
|
[ "$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"
|
2006-04-05 02:09:22 +00:00
|
|
|
eval "if_proto=\"\${${2}_proto}\""
|
2005-11-19 03:17:20 +00:00
|
|
|
|
|
|
|
pidfile=/var/run/${if}.pid
|
|
|
|
[ -f $pidfile ] && $DEBUG kill $(cat $pidfile)
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
static)
|
2006-04-05 02:09:22 +00:00
|
|
|
eval "ip=\"\${${2}_ipaddr}\""
|
|
|
|
eval "ip6=\"\${${2}_ip6addr}\""
|
|
|
|
eval "netmask=\"\${${2}_netmask}\""
|
|
|
|
eval "gateway=\"\${${2}_gateway}\""
|
|
|
|
eval "dns=\"\${${2}_dns}\""
|
2005-11-19 03:17:20 +00:00
|
|
|
|
|
|
|
$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 ---"
|
2006-04-05 02:09:22 +00:00
|
|
|
for ns in $dns; do
|
|
|
|
echo "nameserver $ns" >> /tmp/resolv.conf
|
2005-11-19 03:17:20 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
env -i ACTION="ifup" INTERFACE="${2}" PROTO=static /sbin/hotplug "iface" &
|
|
|
|
;;
|
|
|
|
dhcp)
|
2006-04-05 02:09:22 +00:00
|
|
|
eval "ip=\"\${${2}_ipaddr}\""
|
|
|
|
eval "netmask=\"\${${2}_netmask}\""
|
|
|
|
eval "hostname=\"\${${2}_hostname}\""
|
|
|
|
|
2005-11-19 03:17:20 +00:00
|
|
|
$DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up
|
|
|
|
|
2006-04-05 02:09:22 +00:00
|
|
|
args="-i $if ${ip:+-r $ip} -b -p $pidfile"
|
|
|
|
hostname="${hostname%%.*}"
|
|
|
|
args="$args${hostname:+ -H $hostname}"
|
|
|
|
[ "$if_proto" = "pptp" ] && args="$args -n -q" || args="$args -R &"
|
|
|
|
${DEBUG:-eval} "udhcpc $args"
|
2005-11-19 03:17:20 +00:00
|
|
|
# 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()
|
|
|
|
{
|
|
|
|
[ -z "$IFTYPE" -o -z "$IFPROTO" ] && {
|
|
|
|
find_name || {
|
|
|
|
case "${INTERFACE%%[0-9]*}" in
|
|
|
|
wds)
|
2006-04-05 02:09:22 +00:00
|
|
|
for ifname in lan wifi; do
|
|
|
|
eval "if=\"\${${ifname}_ifname}\""
|
|
|
|
[ -z "$IFPROTO" ] && [ "$if" = "br0" ] && {
|
|
|
|
eval "IFPROTO=\"\${${2}_proto}\""
|
2005-11-19 03:17:20 +00:00
|
|
|
IFTYPE="${tmp}"
|
|
|
|
}
|
|
|
|
done
|
|
|
|
[ -z "$IFPROTO" ] && return 0
|
|
|
|
;;
|
|
|
|
atm)
|
2006-04-05 02:09:22 +00:00
|
|
|
for tmp in lan wan wifi ${ifnames}; do
|
|
|
|
eval "if_proto=\"\${${2}_proto}\""
|
|
|
|
[ "$if_proto" = "pppoa" ] && {
|
2005-11-19 03:17:20 +00:00
|
|
|
do_ifup "pppoa" "$tmp" "$INTERFACE"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case "${INTERFACE%%[0-9]*}" in
|
|
|
|
ppp|atm);;
|
|
|
|
*)
|
2006-04-05 02:09:22 +00:00
|
|
|
eval "mac=\"\${${IFTYPE}_hwaddr}\""
|
2005-11-19 03:17:20 +00:00
|
|
|
${mac:+$DEBUG ifconfig $INTERFACE down hw ether $mac}
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2006-04-05 02:09:22 +00:00
|
|
|
eval "if=\"\${${IFTYPE}_ifname}\""
|
2005-11-19 03:17:20 +00:00
|
|
|
if [ "${if%%[0-9]}" = "br" ]; then
|
|
|
|
if_valid "$INTERFACE" && {
|
|
|
|
ifconfig "$if" 2>&- >&- || {
|
2006-04-05 02:09:22 +00:00
|
|
|
eval "stp=\"\${${IFTYPE}_stp}\""
|
2005-11-19 03:17:20 +00:00
|
|
|
$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
|
2006-01-31 11:36:01 +00:00
|
|
|
$DEBUG brctl addif "$if" "$INTERFACE"
|
|
|
|
$DEBUG ifconfig "$INTERFACE" allmulti
|
2005-11-19 03:17:20 +00:00
|
|
|
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() {
|
2006-04-05 02:09:22 +00:00
|
|
|
[ -z "$IFTYPE" -o -z "$IFPROTO" ] && {
|
|
|
|
find_name || return 0
|
|
|
|
}
|
2005-11-19 03:17:20 +00:00
|
|
|
|
|
|
|
[ "${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
|