summaryrefslogtreecommitdiffstats
path: root/package/base-files/default
diff options
context:
space:
mode:
Diffstat (limited to 'package/base-files/default')
-rwxr-xr-xpackage/base-files/default/etc/functions.sh15
-rw-r--r--package/base-files/default/etc/hotplug.d/net/01-wds5
-rw-r--r--package/base-files/default/etc/hotplug.d/usb/01-mount49
-rwxr-xr-xpackage/base-files/default/sbin/hotplug11
-rwxr-xr-xpackage/base-files/default/sbin/ifdown12
-rwxr-xr-xpackage/base-files/default/usr/share/udhcpc/default.script73
6 files changed, 124 insertions, 41 deletions
diff --git a/package/base-files/default/etc/functions.sh b/package/base-files/default/etc/functions.sh
index bc9767f49..9cfc80235 100755
--- a/package/base-files/default/etc/functions.sh
+++ b/package/base-files/default/etc/functions.sh
@@ -41,12 +41,14 @@ do_ifup() {
$DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up
${gateway:+$DEBUG route add default gw $gateway}
- [ -f /etc/resolv.conf ] && return
-
- debug "# --- creating /etc/resolv.conf ---"
- for dns in $(nvram get ${2}_dns); do
- echo "nameserver $dns" >> /etc/resolv.conf
- done
+ [ -f /etc/resolv.conf ] || {
+ debug "# --- creating /etc/resolv.conf ---"
+ for dns in $(nvram get ${2}_dns); do
+ echo "nameserver $dns" >> /etc/resolv.conf
+ done
+ }
+
+ env -i ACTION="ifup" INTERFACE="${2}" PROTO=static /sbin/hotplug "iface" &
;;
dhcp)
DHCP_IP=$(nvram get ${2}_ipaddr)
@@ -64,6 +66,7 @@ do_ifup() {
sleep 1
kill -9 $oldpid
}
+ # hotplug events are handled by /usr/share/udhcpc/default.script
;;
none|"")
;;
diff --git a/package/base-files/default/etc/hotplug.d/net/01-wds b/package/base-files/default/etc/hotplug.d/net/01-wds
new file mode 100644
index 000000000..38bd69667
--- /dev/null
+++ b/package/base-files/default/etc/hotplug.d/net/01-wds
@@ -0,0 +1,5 @@
+[ "${INTERFACE%%[0-9]*}" = "wds" ] && {
+ ifconfig $INTERFACE 0.0.0.0 up
+ /usr/sbin/brctl addif br0 $INTERFACE
+}
+
diff --git a/package/base-files/default/etc/hotplug.d/usb/01-mount b/package/base-files/default/etc/hotplug.d/usb/01-mount
new file mode 100644
index 000000000..c28ada204
--- /dev/null
+++ b/package/base-files/default/etc/hotplug.d/usb/01-mount
@@ -0,0 +1,49 @@
+mount_storage() {
+ cd /dev/discs
+ for dev in disc*; do
+ [ -f /tmp/.${dev}_id ] || {
+ echo ${INTERFACE}${PRODUCT} > /tmp/.${dev}_id
+ mount | grep /mnt/${dev} || (
+ [ -d /mnt/. ] || {
+ mkdir -p /tmp/mnt
+ ln -s /tmp/mnt /
+ }
+ cd $dev
+ for part in part*; do
+ path=/mnt/${dev}_${part##*part}
+ mkdir -p ${path}
+ mount ${part} ${path}
+ done
+ )
+ }
+ done
+}
+
+umount_storage() {
+ for tmp in /tmp/.*_id; do
+ id=$(cat $tmp 2>&-)
+ [ "${INTERFACE}${PRODUCT}" = "$id" ] && {
+ rm -f $tmp
+ disc=${tmp##*disc}
+ disc=${disc%%_id}
+ for disc in /mnt/disc${disc}*; do
+ umount -f $disc || umount -l $disc
+ done
+ }
+ done
+}
+
+[ -f /proc/bus/usb/devices ] || mount -t usbfs none /proc/bus/usb
+
+case "$ACTION" in
+ add)
+ case "${INTERFACE%%/*}" in
+ 8) mount_storage ;;
+ esac
+ ;;
+ remove)
+ case "${INTERFACE%%/*}" in
+ 8) umount_storage ;;
+ esac
+ ;;
+esac
diff --git a/package/base-files/default/sbin/hotplug b/package/base-files/default/sbin/hotplug
new file mode 100755
index 000000000..57ee969cf
--- /dev/null
+++ b/package/base-files/default/sbin/hotplug
@@ -0,0 +1,11 @@
+#!/bin/sh
+PATH=/bin:/sbin:/usr/bin:/usr/sbin
+LOGNAME=root
+USER=root
+export PATH LOGNAME USER
+
+[ \! -z "$1" -a -d /etc/hotplug.d/$1 ] && {
+ for script in $(ls /etc/hotplug.d/$1/* 2>&-); do (
+ [ -f $script ] && . $script
+ ); done
+}
diff --git a/package/base-files/default/sbin/ifdown b/package/base-files/default/sbin/ifdown
index 147136949..f2f8bbfe8 100755
--- a/package/base-files/default/sbin/ifdown
+++ b/package/base-files/default/sbin/ifdown
@@ -1,13 +1,19 @@
-#!/bin/ash
+#!/bin/sh
[ $# = 0 ] && { echo " $0 <group>"; exit; }
. /etc/functions.sh
-. /etc/network.overrides
+. /etc/network.overrides
[ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network
+
type=$1
debug "### ifdown $type ###"
+
if=$(nvram get ${type}_ifname)
proto=$(nvram get ${type}_proto)
if_valid $if && $DEBUG ifconfig $if down
kill $(cat /var/run/${if}.pid 2>&-) 2>&-
-[ "$if" = "ppp0" ] && killall pppd
killall ifup.$proto >&- 2>&-
+case "$proto" in
+ pptp|pppoe) killall pppd >&- 2>&- ;;
+ static) env -i ACTION="ifdown" INTERFACE="$if" PROTO=static /sbin/hotplug "iface" ;;
+esac
+
diff --git a/package/base-files/default/usr/share/udhcpc/default.script b/package/base-files/default/usr/share/udhcpc/default.script
index 0c08985e7..9fac6286c 100755
--- a/package/base-files/default/usr/share/udhcpc/default.script
+++ b/package/base-files/default/usr/share/udhcpc/default.script
@@ -1,42 +1,51 @@
#!/bin/sh
-# udhcpc script edited by Tim Riker <Tim@Rikers.org>
-# (slightly modified for OpenWrt)
-
[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
RESOLV_CONF="/tmp/resolv.conf"
-case "$1" in
- deconfig)
- ifconfig $interface 0.0.0.0
- ;;
-
- renew|bound)
- ifconfig $interface $ip \
- netmask ${subnet:-255.255.255.0} \
- broadcast ${broadcast:-+}
-
- if [ -n "$router" ] ; then
- echo "deleting routers"
- while route del default gw 0.0.0.0 dev $interface ; do
- :
- done
-
- for i in $router ; do
- route add default gw $i dev $interface
- done
- fi
-
- echo -n > $RESOLV_CONF
- ${domain:+echo search $domain} >> $RESOLV_CONF
- for i in $dns ; do
- echo adding dns $i
- echo nameserver $i >> $RESOLV_CONF
+hotplug_event() {
+ nvram show 2>&- | grep _proto=dhcp | {
+ while :; do
+ read FOO
+ [ -z "$FOO" ] && break
+ FOO="${FOO%%_*}"
+ [ "$(nvram get ${FOO}_ifname)" = "${interface}" ] || continue
+ env -i ACTION="$1" INTERFACE="${FOO}" PROTO=dhcp /sbin/hotplug iface
+ done
+ }
+}
+case "$1" in
+ deconfig)
+ ifconfig $interface 0.0.0.0
+ hotplug_event ifdown
+ ;;
+ renew|bound)
+ ifconfig $interface $ip \
+ netmask ${subnet:-255.255.255.0} \
+ broadcast ${broadcast:-+}
+
+ if [ -n "$router" ] ; then
+ echo "deleting routers"
+ while route del default gw 0.0.0.0 dev $interface ; do :; done
+
+ for i in $router ; do
+ route add default gw $i dev $interface
+ done
+ fi
+
+ echo -n > $RESOLV_CONF
+ ${domain:+echo search $domain} >> $RESOLV_CONF
+ for i in $dns ; do
+ echo adding dns $i
+ echo nameserver $i >> $RESOLV_CONF
+ done
+
+ hotplug_event ifup
+
# user rules
[ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
-
- done
- ;;
+ ;;
esac
+
exit 0