diff options
author | Felix Fietkau <nbd@openwrt.org> | 2007-06-16 00:01:33 +0000 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2007-06-16 00:01:33 +0000 |
commit | 4f16e9cc3e2c187d19b24785a55ce30a892efd68 (patch) | |
tree | 2f0c604247fa6fd86171a5e3398a4a662f99cb06 /package | |
parent | 8e2643a8b517b0ff5030f05020c48fc7bc0e85c2 (diff) | |
download | upstream-4f16e9cc3e2c187d19b24785a55ce30a892efd68.tar.gz upstream-4f16e9cc3e2c187d19b24785a55ce30a892efd68.tar.bz2 upstream-4f16e9cc3e2c187d19b24785a55ce30a892efd68.zip |
keep track of the network interface states (stored in uci format in /var/state/network, overlay over /etc/config/network)
SVN-Revision: 7643
Diffstat (limited to 'package')
-rw-r--r-- | package/base-files/files/etc/hotplug.d/iface/00-netstate | 6 | ||||
-rwxr-xr-x | package/base-files/files/etc/init.d/boot | 1 | ||||
-rwxr-xr-x | package/base-files/files/lib/network/config.sh | 10 | ||||
-rwxr-xr-x | package/base-files/files/sbin/ifdown | 6 | ||||
-rwxr-xr-x | package/base-files/files/usr/share/udhcpc/default.script | 8 | ||||
-rwxr-xr-x | package/ppp/files/etc/ppp/ip-down | 16 | ||||
-rwxr-xr-x | package/ppp/files/etc/ppp/ip-up | 14 |
7 files changed, 53 insertions, 8 deletions
diff --git a/package/base-files/files/etc/hotplug.d/iface/00-netstate b/package/base-files/files/etc/hotplug.d/iface/00-netstate new file mode 100644 index 0000000000..fce5472cf2 --- /dev/null +++ b/package/base-files/files/etc/hotplug.d/iface/00-netstate @@ -0,0 +1,6 @@ +[ ifup = "$ACTION" ] && { + uci set "/var/state/network.$INTERFACE.up=1" + [ -z "$DEVICE" ] || { + uci set "/var/state/network.$INTERFACE.ifname=$DEVICE" + } +} diff --git a/package/base-files/files/etc/init.d/boot b/package/base-files/files/etc/init.d/boot index 7181f8b004..02519fbbc7 100755 --- a/package/base-files/files/etc/init.d/boot +++ b/package/base-files/files/etc/init.d/boot @@ -35,6 +35,7 @@ start() { mkdir -p /var/run mkdir -p /var/log mkdir -p /var/lock + mkdir -p /var/state touch /var/log/wtmp touch /var/log/lastlog ln -s /tmp/resolv.conf.auto /tmp/resolv.conf diff --git a/package/base-files/files/lib/network/config.sh b/package/base-files/files/lib/network/config.sh index 8e19a6e996..c6d909fd0a 100755 --- a/package/base-files/files/lib/network/config.sh +++ b/package/base-files/files/lib/network/config.sh @@ -74,9 +74,7 @@ prepare_interface() { # if we're called for the bridge interface itself, don't bother trying # to create any interfaces here. The scripts have already done that, otherwise # the bridge interface wouldn't exist. - [ "br-$config" = "$iface" ] && return 0; - - [ -f "$iface" ] && return 0; + [ "br-$config" = "$iface" -o -f "$iface" ] && return 0; ifconfig "$iface" 2>/dev/null >/dev/null && { # make sure the interface is removed from any existing bridge and brought down @@ -155,9 +153,11 @@ setup_interface() { [ -z "$ip6addr" ] || $DEBUG ifconfig "$iface" add "$ip6addr" [ -z "$gateway" ] || $DEBUG route add default gw "$gateway" [ -z "$bcast" ] || $DEBUG ifconfig "$iface" broadcast "$bcast" - [ -z "$dns" -o -f /tmp/resolv.conf.auto ] || { + [ -z "$dns" ] || { for ns in $dns; do - echo "nameserver $ns" >> /tmp/resolv.conf.auto + grep "$ns" /tmp/resolv.conf.auto 2>/dev/null >/dev/null || { + echo "nameserver $ns" >> /tmp/resolv.conf.auto + } done } diff --git a/package/base-files/files/sbin/ifdown b/package/base-files/files/sbin/ifdown index 8ec568ff6b..f8ce81bcbd 100755 --- a/package/base-files/files/sbin/ifdown +++ b/package/base-files/files/sbin/ifdown @@ -10,6 +10,12 @@ config_load network exit } + +# remove the interface's network state +FILE=/var/state/network.$$ +grep -v "^config_set '$1' " /var/state/network > "$FILE" +mv "$FILE" /var/state/network + include /lib/network scan_interfaces diff --git a/package/base-files/files/usr/share/udhcpc/default.script b/package/base-files/files/usr/share/udhcpc/default.script index 53bb6999f6..a3a696be70 100755 --- a/package/base-files/files/usr/share/udhcpc/default.script +++ b/package/base-files/files/usr/share/udhcpc/default.script @@ -13,7 +13,13 @@ hotplug_event() { config_get proto $ifc proto [ "$proto" = "dhcp" ] || continue - + [ ifup = "$1" ] && { + uci set "/var/state/network.$ifc.ipaddr=$ip" + uci set "/var/state/network.$ifc.netmask=${subnet:-255.255.255.0}" + uci set "/var/state/network.$ifc.dnsdomain=$domain" + uci set "/var/state/network.$ifc.dns=$dns" + uci set "/var/state/network.$ifc.gateway=$router" + } env -i ACTION="$1" INTERFACE="$ifc" DEVICE="$ifname" PROTO=dhcp /sbin/hotplug-call iface done } diff --git a/package/ppp/files/etc/ppp/ip-down b/package/ppp/files/etc/ppp/ip-down index 814948e0bd..f3d63a019a 100755 --- a/package/ppp/files/etc/ppp/ip-down +++ b/package/ppp/files/etc/ppp/ip-down @@ -1,5 +1,19 @@ #!/bin/sh -[ -z "$6" ] || env -i ACTION="ifdown" INTERFACE="$6" DEVICE="$1" PROTO=ppp /sbin/hotplug-call "iface" +PPP_IFACE="$1" +PPP_TTY="$2" +PPP_SPEED="$3" +PPP_LOCAL="$4" +PPP_REMOTE="$5" +PPP_IPPARAM="$6" +export PPP_IFACE PPP_TTY PPP_SPEED PPP_LOCAL PPP_REMOTE PPP_IPPARAM +[ -z "$PPP_IPPARAM" ] || { + env -i ACTION="ifdown" INTERFACE="$PPP_IPPARAM" DEVICE="$PPP_IFACE" PROTO=ppp /sbin/hotplug-call "iface" + + # remove the interface's network state + FILE=/var/state/network.$$ + grep -v "^config_set '$PPP_IPPARAM' " /var/state/network > "$FILE" + mv "$FILE" /var/state/network +} [ -d /etc/ppp/ip-down.d ] && { for SCRIPT in /etc/ppp/ip-down.d/* diff --git a/package/ppp/files/etc/ppp/ip-up b/package/ppp/files/etc/ppp/ip-up index 22b65e8a09..a50137f5d4 100755 --- a/package/ppp/files/etc/ppp/ip-up +++ b/package/ppp/files/etc/ppp/ip-up @@ -1,5 +1,17 @@ #!/bin/sh -[ -z "$6" ] || env -i ACTION="ifup" INTERFACE="$6" DEVICE="$1" PROTO=ppp /sbin/hotplug-call "iface" +PPP_IFACE="$1" +PPP_TTY="$2" +PPP_SPEED="$3" +PPP_LOCAL="$4" +PPP_REMOTE="$5" +PPP_IPPARAM="$6" +export PPP_IFACE PPP_TTY PPP_SPEED PPP_LOCAL PPP_REMOTE PPP_IPPARAM +[ -z "$PPP_IPPARAM" ] || env -i ACTION="ifup" INTERFACE="$PPP_IPPARAM" DEVICE="$PPP_IFACE" PROTO=ppp /sbin/hotplug-call "iface" +[ -z "$PPP_IPPARAM" -o -z "$PPP_LOCAL" ] || { + uci set "/var/state/network.$PPP_IPPARAM.ipaddr=$PPP_LOCAL" + uci set "/var/state/network.$PPP_IPPARAM.gateway=$PPP_REMOTE" +} + [ -d /etc/ppp/ip-up.d ] && { for SCRIPT in /etc/ppp/ip-up.d/* |