From 0bb68e81eca839c8eed0c629b403ac558ea662e6 Mon Sep 17 00:00:00 2001 From: nbd Date: Mon, 7 Nov 2005 01:12:51 +0000 Subject: add hotplug stuff to trunk/ git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@2364 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/Makefile | 13 +--- package/base-files/default/etc/functions.sh | 15 +++-- .../base-files/default/etc/hotplug.d/net/01-wds | 5 ++ .../base-files/default/etc/hotplug.d/usb/01-mount | 49 +++++++++++++++ package/base-files/default/sbin/hotplug | 11 ++++ package/base-files/default/sbin/ifdown | 12 +++- .../default/usr/share/udhcpc/default.script | 73 ++++++++++++---------- package/base-files/files/hotplug | 6 -- package/base-files/ipkg/hotplug.control | 4 -- 9 files changed, 126 insertions(+), 62 deletions(-) create mode 100644 package/base-files/default/etc/hotplug.d/net/01-wds create mode 100644 package/base-files/default/etc/hotplug.d/usb/01-mount create mode 100755 package/base-files/default/sbin/hotplug delete mode 100755 package/base-files/files/hotplug delete mode 100644 package/base-files/ipkg/hotplug.control (limited to 'package/base-files') diff --git a/package/base-files/Makefile b/package/base-files/Makefile index 5f300f284..adf2ffbb5 100644 --- a/package/base-files/Makefile +++ b/package/base-files/Makefile @@ -3,7 +3,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=base-files -PKG_RELEASE:=4 +PKG_RELEASE:=6 PKG_BUILD_DIR:=$(BUILD_DIR)/base-files REV:=${shell svn info | grep Revision | cut -d ' ' -f 2} @@ -16,9 +16,6 @@ include $(TOPDIR)/package/rules.mk IDIR_BASE:=$(PKG_BUILD_DIR)/base-files IPKG_BASE:=$(PACKAGE_DIR)/$(PKG_NAME)_$(PKG_RELEASE)_$(ARCH).ipk -IDIR_HOTPLUG:=$(PKG_BUILD_DIR)/hotplug -IPKG_HOTPLUG:=$(PACKAGE_DIR)/hotplug_$(PKG_RELEASE)_$(ARCH).ipk - UCLIBC_VERSION:=${shell cat $(STAGING_DIR)/uclibc_version} IDIR_UCLIBC:=$(PKG_BUILD_DIR)/uclibc IPKG_UCLIBC:=$(PACKAGE_DIR)/uclibc_$(UCLIBC_VERSION)-$(PKG_RELEASE)_$(ARCH).ipk @@ -27,7 +24,7 @@ LIBGCC_VERSION:=${shell cat $(STAGING_DIR)/gcc_version} IDIR_LIBGCC:=$(PKG_BUILD_DIR)/libgcc IPKG_LIBGCC:=$(PACKAGE_DIR)/libgcc_$(LIBGCC_VERSION)-$(PKG_RELEASE)_$(ARCH).ipk -PACKAGES:=$(IPKG_BASE) $(IPKG_UCLIBC) $(IPKG_LIBGCC) $(IPKG_HOTPLUG) +PACKAGES:=$(IPKG_BASE) $(IPKG_UCLIBC) $(IPKG_LIBGCC) $(PKG_BUILD_DIR)/.prepared: mkdir -p $(PKG_BUILD_DIR) $(PACKAGE_DIR) @@ -74,12 +71,6 @@ $(IPKG_LIBGCC): -$(STRIP) $(IDIR_LIBGCC)/lib/* $(IPKG_BUILD) $(IDIR_LIBGCC) $(PACKAGE_DIR) -$(IPKG_HOTPLUG): - $(SCRIPT_DIR)/make-ipkg-dir.sh $(IDIR_HOTPLUG) ipkg/hotplug.control $(PKG_RELEASE) $(ARCH) - mkdir -p $(IDIR_HOTPLUG)/sbin - install -m0755 files/hotplug $(IDIR_HOTPLUG)/sbin - $(IPKG_BUILD) $(IDIR_HOTPLUG) $(PACKAGE_DIR) - package-clean: rm -f $(PACKAGES) 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 "; 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 -# (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 diff --git a/package/base-files/files/hotplug b/package/base-files/files/hotplug deleted file mode 100755 index 74134e848..000000000 --- a/package/base-files/files/hotplug +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/ash -# $Id$ -[ "${INTERFACE%%[0-9]*}" = "wds" ] && { - ifconfig $INTERFACE 0.0.0.0 up - /usr/sbin/brctl addif br0 $INTERFACE -} diff --git a/package/base-files/ipkg/hotplug.control b/package/base-files/ipkg/hotplug.control deleted file mode 100644 index 5266e85d6..000000000 --- a/package/base-files/ipkg/hotplug.control +++ /dev/null @@ -1,4 +0,0 @@ -Package: hotplug -Priority: optional -Section: net -Description: Hotplug script for WDS -- cgit v1.2.3