enable eth0 by default with highest priority, monitor ethenet state changes

pull/1283/head
johndi3 2024-01-27 09:00:04 +08:00
parent 4b58adc412
commit f444114ea6
3 changed files with 38 additions and 4 deletions

View File

@ -11,7 +11,6 @@ set_wireless() {
elif $path/modem "$dev"; then elif $path/modem "$dev"; then
ifup usb0 ifup usb0
fi fi
[ -e /sys/class/net/eth0 ] && ifconfig eth0 "${net:-192.168.2.10}"
} }
case "$1" in case "$1" in
@ -20,8 +19,10 @@ case "$1" in
ifup lo ifup lo
if [ -n "$dev" ]; then if [ -n "$dev" ]; then
set_wireless set_wireless
else fi
if [ -e /sys/class/net/eth0 ]; then
ifup eth0 ifup eth0
/usr/sbin/interface_monitor.sh eth0 &
fi fi
;; ;;

View File

@ -0,0 +1,25 @@
#!/bin/sh
monitor_interface () {
local fileoperstate=/sys/class/net/"$1"/operstate
local state oldstate=$(cat "$fileoperstate")
while sleep 2; do
state=$(cat "$fileoperstate")
if [ "$oldstate" = "$state" ]; then
continue
fi
oldstate="$state"
echo "interface $1 is $state"
case "$state" in
down | lowerlayerdown)
kill -12 `cat /var/run/udhcpc.$1.pid`
;;
up)
kill -10 `cat /var/run/udhcpc.$1.pid`
;;
esac
done
}
monitor_interface "$1"

View File

@ -54,7 +54,8 @@ case "$1" in
if [ -x /usr/sbin/avahi-autoipd ]; then if [ -x /usr/sbin/avahi-autoipd ]; then
/usr/sbin/avahi-autoipd -c $interface || /usr/sbin/avahi-autoipd -wD $interface --no-chroot /usr/sbin/avahi-autoipd -c $interface || /usr/sbin/avahi-autoipd -wD $interface --no-chroot
fi fi
/sbin/ifconfig $interface $(fw_printenv -n ipaddr || echo -n 192.168.1.10) netmask $(fw_printenv -n netmask || echo -n 255.255.255.0) up #/sbin/ifconfig $interface $(fw_printenv -n ipaddr || echo -n 192.168.1.10) netmask $(fw_printenv -n netmask || echo -n 255.255.255.0) up
/sbin/ifconfig $interface up
;; ;;
renew|bound) renew|bound)
@ -73,7 +74,14 @@ case "$1" in
done done
for i in $router ; do for i in $router ; do
route add default gw $i dev $interface if [ $interface = "eth0" ]; then
metric=0
elif [ $interface = "wlan0" ]; then
metric=10
else
metric=20
fi
route add default gw $i dev $interface metric $metric
done done
fi fi