Commit 49ca73cd authored by Vitaly Lipatov's avatar Vitaly Lipatov

add router scripts

parent 605a71da
#!/bin/sh
# use Ekvant as default until we do not fix nexthop issue
ip route replace default via 212.176.192.226
# 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 hop nexthop via 212.176.192.226 weight 40 nexthop via 85.235.198.25 weight 60
# 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 add from 91.232.225.21 lookup hop
#!/bin/sh
cd $(dirname $0)
# ya.ru google.com
HOSTS="93.158.134.3 173.194.71.139"
# return false if both failed
check_hosts()
{
local iface="$1"
for try in 1 2 3 ; do
for h in $HOSTS ; do
ping -q -I $iface -c 1 -W 1 $h >/dev/null && return
done
done
return 1
}
check_bird()
{
local ST=$(birdc show protocols "$1") || return
echo "$ST" | grep -q Established
}
STATE=both
set_state()
{
# Ekvant failed
if ! check_hosts 212.176.192.225 ; then
NEWSTATE=prometey
return
fi
# Prometey
if ! check_hosts 85.235.198.26 ; then
NEWSTATE=ekvant
return
fi
NEWSTATE=both
}
set_state_by_bgp()
{
[ "$NEWSTATE" = "both" ] || return
local SEKVANT=
local SPROMETEY=
check_bird bgpAS2854 && SEKVANT=ok
check_bird bgpAS35000 && SPROMETEY=ok
[ "$SEKVANT$SPROMETEY" = "okok" ] && return
[ "$SEKVANT$SPROMETEY" = "" ] && NEWSTATE=none && return
[ "$SEKVANT" = "ok" ] && NEWSTATE=ekvant && return
[ "$SPROMETEY" = "ok" ] && NEWSTATE=prometey && return
}
./both_provs.sh
while true ; do
set_state
set_state_by_bgp
if [ "$STATE" != "$NEWSTATE" ] ; then
case "$NEWSTATE" in
prometey)
./only_prometey.sh
;;
ekvant)
./only_ekvant.sh
;;
both)
./both_provs.sh
;;
none)
echo "Sorry, no connection!" >&2
;;
*)
echo "Unknown state" >&2
exit 1
;;
esac
echo "State changed to $NEWSTATE"
STATE=$NEWSTATE
fi
sleep 7
done
#!/bin/sh
# HACK: local rule
ip route replace default via 212.176.192.226
# Ekvant exports default to us, but we will repeat it
ip route replace default scope global table common via 212.176.192.226
# remove hops for 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
#!/bin/sh
# HACK: local rule
ip route replace default via 85.235.198.25
# Prometey does not export default route for us
ip route replace default scope global table common via 85.235.198.25
# remove hops for 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
#!/bin/sh
# update eepm and use eepm clean
rm -vf /var/cache/apt/*.bin
rm -vf /var/lib/apt/lists/*pkglist*
rm -vf /var/lib/apt/lists/*release*
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