keep track of the network interface states (stored in uci format in /var/state/network, overlay over /etc/config/network)

SVN-Revision: 7643
This commit is contained in:
Felix Fietkau
2007-06-16 00:01:33 +00:00
parent 8e2643a8b5
commit 4f16e9cc3e
7 changed files with 53 additions and 8 deletions

View File

@@ -0,0 +1,6 @@
[ ifup = "$ACTION" ] && {
uci set "/var/state/network.$INTERFACE.up=1"
[ -z "$DEVICE" ] || {
uci set "/var/state/network.$INTERFACE.ifname=$DEVICE"
}
}

View File

@@ -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

View File

@@ -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
}

View File

@@ -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

View File

@@ -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
}