keep track of the network interface states (stored in uci format in /var/state/networ...
authorFelix Fietkau <nbd@openwrt.org>
Sat, 16 Jun 2007 00:01:33 +0000 (00:01 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 16 Jun 2007 00:01:33 +0000 (00:01 +0000)
SVN-Revision: 7643

package/base-files/files/etc/hotplug.d/iface/00-netstate [new file with mode: 0644]
package/base-files/files/etc/init.d/boot
package/base-files/files/lib/network/config.sh
package/base-files/files/sbin/ifdown
package/base-files/files/usr/share/udhcpc/default.script
package/ppp/files/etc/ppp/ip-down
package/ppp/files/etc/ppp/ip-up

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 (file)
index 0000000..fce5472
--- /dev/null
@@ -0,0 +1,6 @@
+[ ifup = "$ACTION" ] && {
+       uci set "/var/state/network.$INTERFACE.up=1"
+       [ -z "$DEVICE" ] || {
+               uci set "/var/state/network.$INTERFACE.ifname=$DEVICE"
+       }
+}
index 7181f8b0043781713be9fde4bc1e03571a04d88c..02519fbbc77a9f1110b52d190f5eb1970d6cab7a 100755 (executable)
@@ -35,6 +35,7 @@ start() {
        mkdir -p /var/run
        mkdir -p /var/log
        mkdir -p /var/lock
        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
        touch /var/log/wtmp
        touch /var/log/lastlog
        ln -s /tmp/resolv.conf.auto /tmp/resolv.conf
index 8e19a6e99671816c7fa1492f2110ab3fbf146a63..c6d909fd0aaf25b6a34b9f173dbd4707c430fe83 100755 (executable)
@@ -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.
        # 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
        
        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 "$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
                                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
                        }
 
                                done
                        }
 
index 8ec568ff6b5ad08498617129e4fd58f6c3ed4944..f8ce81bcbdcfcbce8de811420112d6d58fbbc7cc 100755 (executable)
        config_load network
        exit
 }
        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
 
 include /lib/network
 scan_interfaces
 
index 53bb6999f6aa13dcde0f4551cf5b4dc05707f000..a3a696be70a5c361dcf282a6672a5898fe7f6358 100755 (executable)
@@ -13,7 +13,13 @@ hotplug_event() {
 
                config_get proto $ifc proto
                [ "$proto" = "dhcp" ] || continue
 
                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
 }
                env -i ACTION="$1" INTERFACE="$ifc" DEVICE="$ifname" PROTO=dhcp /sbin/hotplug-call iface
        done
 }
index 814948e0bda4a53600b9b417eb10e32c5de5a431..f3d63a019af89859541203a13d8950a1b52f2109 100755 (executable)
@@ -1,5 +1,19 @@
 #!/bin/sh
 #!/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/*
 
 [ -d /etc/ppp/ip-down.d ] && {
        for SCRIPT in /etc/ppp/ip-down.d/*
index 22b65e8a09de9f13fe3259ba3a968c813674e234..a50137f5d4aff42342df5d1bca8ffbe2a0a261b8 100755 (executable)
@@ -1,5 +1,17 @@
 #!/bin/sh
 #!/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/*
 
 [ -d /etc/ppp/ip-up.d ] && {
        for SCRIPT in /etc/ppp/ip-up.d/*