Commit cab8d7bc authored by Vitaly Lipatov's avatar Vitaly Lipatov

update router scripts

parent 85dcdaa6
...@@ -6,14 +6,18 @@ ip route replace default via 212.176.192.226 ...@@ -6,14 +6,18 @@ ip route replace default via 212.176.192.226
# Use Ekvant as main defaul # Use Ekvant as main defaul
ip route replace default scope global table common via 212.176.192.226 ip route replace default scope global table common via 212.176.192.226
./set_hop.sh
ip route replace default scope global table hop nexthop via 212.176.192.226 weight 40 nexthop via 85.235.198.25 weight 60
# torrent client # torrent client
ip rule del from 91.232.225.21 lookup hop ip rule del from 91.232.225.21 lookup hop
ip rule del from 91.232.225.21 lookup hop ip rule del from 91.232.225.21 lookup hop
ip rule add from 91.232.225.21 lookup hop ip rule add from 91.232.225.21 lookup hop
# 91.232.225.60-69 lazy-kun
#ip rule del from 91.232.225.21 lookup hop
#ip rule del from 91.232.225.21 lookup hop
#ip rule add from 91.232.225.21 lookup hop
# de01 # de01
ip rule del to 144.76.183.114 lookup hop ip rule del to 144.76.183.114 lookup hop
ip rule del to 144.76.183.114 lookup hop ip rule del to 144.76.183.114 lookup hop
...@@ -23,3 +27,5 @@ ip rule add to 144.76.183.114 lookup hop ...@@ -23,3 +27,5 @@ ip rule add to 144.76.183.114 lookup hop
ip rule del to 85.143.133.46 lookup hop ip rule del to 85.143.133.46 lookup hop
ip rule del to 85.143.133.46 lookup hop ip rule del to 85.143.133.46 lookup hop
ip rule add to 85.143.133.46 lookup hop ip rule add to 85.143.133.46 lookup hop
#./transmission.sh --no-alt-speed
...@@ -94,6 +94,48 @@ apply_state() ...@@ -94,6 +94,48 @@ apply_state()
esac esac
} }
OLDALTSPEED=
OLDAVERAGE=
OLDMAINLOAD=
calc_distance()
{
local DISTANCE=$(($1-$2))
[ $DISTANCE -ge 0 ] || DISTANCE=$((-$DISTANCE))
echo "$DISTANCE"
}
check_and_wait()
{
# AVERAGE and MAINLOAD
# note: sleep 10 inside
eval $(./get_traffic.sh)
DISTANCE=$(calc_distance "$OLDMAINLOAD" "$MAINLOAD")
if [ "$DISTANCE" -ge 20 ] ; then
write_log "$(date) set main procent to $MAINLOAD for hop route table"
./set_hop.sh $MAINLOAD
OLDMAINLOAD=$MAINLOAD
fi
if [ "$STATE" != "both" ] || [ "$AVERAGE" -ge 170 ] ; then
ALTSPEED=1
else
ALTSPEED=0
fi
if [ "$OLDALTSPEED" != "$ALTSPEED" ] ; then
if [ "$ALTSPEED" = 1 ] ; then
write_log "$(date) average speed is too hi $AVERAGE, enable alt speed"
./transmission.sh --alt-speed
else
write_log "$(date) average speed is normal $AVERAGE, disable alt speed"
./transmission.sh --no-alt-speed
fi
OLDALTSPEED="$ALTSPEED"
fi
}
main_cycle() main_cycle()
{ {
...@@ -108,7 +150,8 @@ while true ; do ...@@ -108,7 +150,8 @@ while true ; do
write_log "$(date) State changed to $NEWSTATE (Ekvant: $SHEKVANT-$SBEKVANT, Prometey: $SHPROMETEY-$SBPROMETEY)" write_log "$(date) State changed to $NEWSTATE (Ekvant: $SHEKVANT-$SBEKVANT, Prometey: $SHPROMETEY-$SBPROMETEY)"
STATE=$NEWSTATE STATE=$NEWSTATE
fi fi
sleep 7 #sleep 7
check_and_wait
done done
} }
......
#!/bin/sh #!/bin/sh
cd /home/lav/z-i || exit cd /home/lav/z-i || exit
git pull git pull >/dev/null
#cat dump.csv |cut -f1 -d';'|tr '|' '\n'| tr -d ' '|sort -u #cat dump.csv |cut -f1 -d';'|tr '|' '\n'| tr -d ' '|sort -u
cat dump.csv |cut -f1 -d';'|tr '|' '\n'| tr -d ' '|sort -u|sed '$d' cat dump.csv |cut -f1 -d';'|tr '|' '\n'| tr -d ' '|sed '1d'|sort -u
#!/bin/sh
set_tr()
{
# rx 4.85 Mbit/s 7066 packets/s
# tx 95.42 Mbit/s 7769 packets/s
vnstat -tr -i "$1" | grep Mbit | sed -e 's| *\([rt]x\) *\([0-9][0-9]*\)\..*|\1=\2|g'
}
eval $(set_tr inet)
RX_INET=$rx
TX_INET=$tx
eval $(set_tr inet2)
RX_INET2=$rx
TX_INET2=$tx
#echo $RX_INET $RX_INET2
#echo $TX_INET $TX_INET2
#echo $(($RX_INET+$RX_INET2)) $(($TX_INET+$TX_INET2))
TXAVERAGE=$(($TX_INET2+$TX_INET))
MAINLOAD=$((($TX_INET2-$TX_INET)/2+50))
# round to 10
#MAINLOAD=$((($MAINLOAD/10)*10))
echo "AVERAGE=$TXAVERAGE"
echo "MAINLOAD=$MAINLOAD"
echo "TX_INET=$TX_INET"
echo "TX_INET2=$TX_INET2"
echo "RX_INET=$RX_INET"
echo "RX_INET2=$RX_INET2"
...@@ -10,4 +10,4 @@ ip route replace default scope global table hop via 212.176.192.226 ...@@ -10,4 +10,4 @@ ip route replace default scope global table hop via 212.176.192.226
# TODO: enable shaper for torrent and our remote backup servers # TODO: enable shaper for torrent and our remote backup servers
./slow_transmission.sh #./transmission.sh --alt-speed
...@@ -8,4 +8,4 @@ ip route replace default scope global table common via 85.235.198.25 ...@@ -8,4 +8,4 @@ ip route replace default scope global table common via 85.235.198.25
ip route replace default scope global table hop via 85.235.198.25 ip route replace default scope global table hop via 85.235.198.25
./slow_transmission.sh #./transmission.sh --alt-speed
#!/bin/sh
./check_connectivity.sh stop
monit -v validate all
#!/bin/sh
[ -n "$1" ] && MAINLOAD="$1" || MAINLOAD=40
RESERLOAD=$((100-$MAINLOAD))
ip route replace default scope global table hop nexthop via 212.176.192.226 weight $MAINLOAD nexthop via 85.235.198.25 weight $RESERLOAD
#!/bin/sh #!/bin/sh
transmission-remote http://tr.lav.eterhost.ru:9091/transmission --auth lav:nah9suaB --alt-speed # --alt-speed
transmission-remote http://tr.lav.eterhost.ru:9091/transmission --auth lav:nah9suaB $@
# Does not work: # Does not work:
# Unexpected response: <h1>404: Not Found</h1>/transmission//rpc/idsb4ItPI # Unexpected response: <h1>404: Not Found</h1>/transmission//rpc/idsb4ItPI
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
cd $(dirname $0) || exit cd $(dirname $0) || exit
SETNAME=rkz SETNAME=rkz
ipset destroy $SETNAME.tmp || exit ipset destroy $SETNAME.tmp
ipset create $SETNAME.tmp hash:ip || exit ipset create $SETNAME.tmp hash:ip || exit
#ip rule show | grep "lookup openroute" | sed -e "s|.*:||g" | sed -e "s|lookup|table|g" | while read str ; do #ip rule show | grep "lookup openroute" | sed -e "s|.*:||g" | sed -e "s|lookup|table|g" | while read str ; do
...@@ -19,6 +19,6 @@ ipset swap $SETNAME.tmp $SETNAME ...@@ -19,6 +19,6 @@ ipset swap $SETNAME.tmp $SETNAME
# initial # initial
if ! iptables -L -t mangle | grep -q $SETNAME ; then if ! iptables -L -t mangle | grep -q $SETNAME ; then
iptables -t mangle -A PREROUTING -m set --match-set $SETNAME dst -j MARK --set-mark 5 iptables -t mangle -A PREROUTING -i our -m set --match-set $SETNAME dst -j MARK --set-mark 5
ip rule add fwmark 5 table openroute ip rule add fwmark 5 table openroute
fi fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment