其他分享
首页 > 其他分享> > devmode & ethdetect.sh

devmode & ethdetect.sh

作者:互联网

devmode & ethdetect.sh

 

/etc/init.d/devmode

#!/bin/sh /etc/rc.common

START=99

USE_PROCD=1
NAME=devmode
PROG=/sbin/devmode.sh

start_service() {
    iptables -t mangle -D FORWARD  -p icmp -j DSCP --set-dscp-class EF  
    iptables -t mangle -D FORWARD  -p icmp -j DSCP --set-dscp 7
    iptables -t mangle -A FORWARD  -p icmp -j DSCP --set-dscp-class EF
    iptables -t mangle -A FORWARD  -p icmp -j DSCP --set-dscp 7
#        procd_open_instance
#        procd_set_param command "$PROG"
#        procd_close_instance
config_load devmode
config_get mode devmode  mode 

echo $mode

case $mode in
    "nac")
        /etc/init.d/nac start

    ;;
    "auto")
        if [ -e "/dev/ttyUSB0" ] && [ -e "/dev/ttyUSB1" ] && [ -e "/dev/ttyUSB2" ] && [ -e "/dev/ttyUSB3" ] ; then
                uci set devmode.devmode.mode="nac"
                #uci set nac.NAC.nas="0.0.0.0"
                uci commit devmode
                /bin/cp -rf /etc/config/network.br.dhcp /etc/config/network
                /bin/cp -rf /etc/config/dhcp.nat /etc/config/dhcp
                /bin/cp -rf /etc/config/firewall.nat /etc/config/firewall
                /bin/cp -rf /etc/config/wan_backup.nat /etc/config/wan_backup
        else
            uci set devmode.devmode.mode="nac"
            uci commit devmode
            /bin/cp -rf /etc/config/network.nat.dhcp /etc/config/network
            /bin/cp -rf /etc/config/dhcp.nat /etc/config/dhcp
            /bin/cp -rf /etc/config/firewall.nat /etc/config/firewall
            uci commit network    
            uci set wan_backup.policy.enable='0'
            uci commit wan_backup
            sleep 5
            uci  delete network.4G
            uci commit network    
            sleep 5
            reboot

                                
        fi

            uci commit devmode
            sleep 5
            reboot        
        ;;
#    "direct")
#            /etc/init.d/nac stop        
#        ;;

    "auto_nat")
        uci set devmode.devmode.mode="nac"
        uci commit devmode
        /bin/cp -rf /etc/config/network.nat.dhcp /etc/config/network
        /bin/cp -rf /etc/config/dhcp.nat /etc/config/dhcp
        /bin/cp -rf /etc/config/firewall.nat /etc/config/firewall
        uci commit network    
        uci set wan_backup.policy.enable='0'
        uci commit wan_backup
        sleep 5
        uci  delete network.4G
        uci commit network    
        sleep 5
        reboot
        ;;
    "auto_bridge")
        uci set devmode.devmode.mode="nac"
        uci commit nac
        /bin/cp -rf /etc/config/network.br.dhcp /etc/config/network
        /bin/cp -rf /etc/config/dhcp.nat /etc/config/dhcp
        /bin/cp -rf /etc/config/firewall.nat /etc/config/firewall
        sleep 10
        reboot

        ;;

esac


##    /sbin/ethdetect.sh  &
}

 

/sbin/ethdetect.sh

#!/bin/sh
WAN_IF="eth0"
LAN_IF="eth1"
MAX=5
last_recv=0
last_send=0

sleep 120

mach=`uname -m`
if [ "$mach" == "x86_64" ]; then
        exit;
fi


while [ 1 ];do
        run_flag=`ifconfig $WAN_IF|grep RUNNING`
         
        #echo $run_flag

        if [ -n  "$run_flag" ];then
                echo "running"
                #wan_recv=`cat /proc/net/dev | grep $WAN_IF | cut -d " " -f4`
                wan_recv=`cat  /sys/devices/platform/ag71xx.0/net/eth0/statistics/rx_bytes`
                wan_send=`cat  /sys/devices/platform/ag71xx.0/net/eth0/statistics/tx_bytes`

                echo "$last_recv ------ $wan_recv"
                echo "$last_send ------ $wan_send"

                if [[ $last_recv -lt  $wan_recv ]]; then
                    ##echo aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    last_recv=$wan_recv
                    last_send=$wan_send
                    count=0
                else
                    if [[ $last_send  -lt  $wan_send ]]; then
                        last_recv=$wan_recv
                        count=$((count+1))
                        ##echo "count=$count"
                        #ifconfig $WAN_IF up

                        if [ $count -gt  $MAX ]; then
                            count=0
                                #echo  "down"
                            ifconfig eth0  down
                            #ifconfig br-lan  up
                            ethtool -s  eth0 speed 10 duplex half
                            ethtool  -s  eth0  speed 100    duplex full
                            ifconfig $WAN_IF up
                            linestatus=`curl -s "http://localhost:14150/getlinestatus"`
                            if [ $linestatus -eq  0 ]; then
                                #route del default
                                gateway=`uci get network.SATELLITE.gateway`
                                route add default gw $gateway
                                ip route  add 192.168.16.0/24 via  $gateway
                                ip route  add 172.20.0.50/32 via  $gateway     
                            else
                                gateway=`uci get network.SATELLITE.gateway`
                                ip route  del 192.168.16.0/24 via  $gateway
                                ip route  add 192.168.16.0/24 via  $gateway
                                ip route  del 172.20.0.50/32 via  $gateway
                                ip route  add 172.20.0.50/32 via  $gateway                               
                            fi
                            killall  -9 udhcpc                   
                        fi
                    fi
                fi
      #  else
      #         echo "down"
        fi


sleep 2
done

 

=============== End

 

标签:bin,wan,devmode,etc,sh,config,ethdetect,uci
来源: https://www.cnblogs.com/lsgxeva/p/13759155.html