jablonka.czprosek.czf

sedlo

Subversion Repositories:
[/] [trunk/] [sedlo] - Diff between revs 9 and 10

Show entire file Ignore whitespace

Rev 9 Rev 10
Line 1... Line 1...
#!/bin/bash #!/bin/bash
# author : Petr Simandl www.simandl.cz # author : Petr Simandl www.simandl.cz
# release date : 07/09/2004 # release date : 26/01/2006
# name : sedlo # name : sedlo
# description : dynamic side routing tables tool # description : dynamic side routing tables tool
# license : GPL # license : GPL
   
sl_version="0.0.3pre9" sl_version="0.0.4pre1"
   
PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
   
sl_nmcnf="sedlo.conf" sl_nmcnf="sedlo.conf"
sl_sedlocnf="/etc/$sl_nmcnf" sl_sedlocnf="/etc/$sl_nmcnf"
Line 25... Line 25...
sl_wgetcmd=`which wget` sl_wgetcmd=`which wget`
sl_hnmcmd=`which hostname` sl_hnmcmd=`which hostname`
sl_awkcmd=`which awk` sl_awkcmd=`which awk`
sl_catcmd=`which cat` sl_catcmd=`which cat`
sl_grepcmd=`which grep` sl_grepcmd=`which grep`
  sl_diffcmd=`which diff`
   
if [ -e $sl_sedlocnf ] if [ -e $sl_sedlocnf ]
then then
sl_nop=1 sl_nop=1
else else
Line 77... Line 78...
$sl_ipcmd ro flush cache $sl_ipcmd ro flush cache
   
} # s_flru } # s_flru
   
###################################################################### ######################################################################
  # here we get each ip and we create a rule to send this ip to a
  # certain table
  # this routine can be skipped when the number of ips and ip directions
  # are still the same = old and new configs are the same
s_fillrules() s_fillrules()
{ {
   
#flush old rules before filling new ones #flush old rules before filling new ones
#not so nice solution - it is planned to change just what's necessary #not so nice solution - it is planned to change just what's necessary
#by s_maru #by s_maru
s_flru s_flru
   
if [ $scm_info -gt 0 ]; then echo "Creating rules" ; fi if [ $scm_info -gt 0 ]; then echo "Creating rules for ips" ; fi
   
sl_ips=`$sl_catcmd $sl_sedlocache/$sl_nmcnf | $sl_grepcmd "^ip" | $sl_awkcmd '{print $2"*"$4"*"$5"*"$6}'` sl_ips=`$sl_catcmd $sl_sedlocache/$sl_nmcnf | $sl_grepcmd "^ip" | $sl_awkcmd '{print $2"*"$4"*"$5"*"$6}'`
   
for sl_ip in $sl_ips for sl_ip in $sl_ips
do do
Line 121... Line 126...
$sl_ipcmd ro flush cache $sl_ipcmd ro flush cache
   
} # s_fillrules } # s_fillrules
   
###################################################################### ######################################################################
  # here we look into the main routing table for path to our iGWs
  # and we fill these tables with two halves default nets that
  # point to appropriate direction
  # this routine can be skipped when the routing table is the same
s_filltables() s_filltables()
{ {
  if [ $scm_info -gt 0 ]; then echo "Checking main routing table" ; fi
   
if [ $scm_info -gt 0 ]; then echo "Filling tables" ; fi if [ $scm_info -gt 0 ]; then echo "Filling tables" ; fi
   
sl_igws=`$sl_catcmd $sl_sedlocache/$sl_nmcnf | $sl_grepcmd -E "^igw|^myigw" | $sl_awkcmd '{print $3"*"$2"*"$1}'` sl_igws=`$sl_catcmd $sl_sedlocache/$sl_nmcnf | $sl_grepcmd -E "^igw|^myigw" | $sl_awkcmd '{print $3"*"$2"*"$1}'`
   
for sl_igw in $sl_igws for sl_igw in $sl_igws
Line 165... Line 176...
else else
if [ $scm_info -gt 1 ]; then echo "Table filled for igw $sl_igwn" ; fi if [ $scm_info -gt 1 ]; then echo "Table filled for igw $sl_igwn" ; fi
fi fi
fi fi
done done
   
#this should make faster applying of new routing tables  
$sl_ipcmd ro flush cache  
   
} # s_filltables } # s_filltables
   
###################################################################### ######################################################################
  # filling rttab with tables from config
  # only new tables are created with a new uniq number that is not important because
  # usually we handle tables just by their names
  # this routine acts only when a new iGW appears - only adding a table is supported
  # no deleting is implemented because it seems to be not necessary to delete an old table
  # because there is space enough and after reboot table will not be created
s_mktables() s_mktables()
{ {
if [ $scm_info -gt 0 ]; then echo "Creating tables " ; fi if [ $scm_info -gt 0 ]; then echo "Checking tables" ; fi
   
  if [ $scm_info -gt 0 ]; then echo "Creating tables" ; fi
sl_igws=`$sl_catcmd $sl_sedlocache/$sl_nmcnf | $sl_grepcmd -E "^igw|^myigw" | $sl_awkcmd '{print $3}'` sl_igws=`$sl_catcmd $sl_sedlocache/$sl_nmcnf | $sl_grepcmd -E "^igw|^myigw" | $sl_awkcmd '{print $3}'`
for sl_igw in $sl_igws for sl_igw in $sl_igws
do do
sl_igwrttb=`$sl_catcmd $sl_rttab | $sl_awkcmd '{print $2}' | $sl_grepcmd $sl_igw ` sl_igwrttb=`$sl_catcmd $sl_rttab | $sl_awkcmd '{print $2}' | $sl_grepcmd $sl_igw `
if [ "$sl_igwrttb x" = " x" ] if [ "$sl_igwrttb x" = " x" ]
Line 209... Line 225...
{ {
if [ $scm_info -gt 0 ]; then echo "Getting config" ; fi if [ $scm_info -gt 0 ]; then echo "Getting config" ; fi
if [ $scm_info -gt 1 ]; then echo "Using main config $sl_murlcfg" ; fi if [ $scm_info -gt 1 ]; then echo "Using main config $sl_murlcfg" ; fi
if [ $scm_info -gt 1 ]; then echo "Using local config $sl_sedlocnf" ; fi if [ $scm_info -gt 1 ]; then echo "Using local config $sl_sedlocnf" ; fi
   
wget -q -t 3 $sl_murlcfg -O "$sl_sedlocache/$sl_nmcnf.main.tmp" rm -f "$sl_sedlocache/$sl_nmcnf.main.tmp"
   
  $sl_wgetcmd -q -t 3 $sl_murlcfg -O "$sl_sedlocache/$sl_nmcnf.main.tmp"
   
if [ -s $sl_sedlocache/$sl_nmcnf.main.tmp ] if [ -s $sl_sedlocache/$sl_nmcnf.main.tmp ]
then then
date > $sl_sedlocache/last_getcnf.txt date > $sl_sedlocache/last_getcnf.txt
cp $sl_sedlocache/$sl_nmcnf.main.tmp $sl_sedlocache/$sl_nmcnf.main cp $sl_sedlocache/$sl_nmcnf.main.tmp $sl_sedlocache/$sl_nmcnf.main
if [ $scm_info -gt 1 ]; then echo "Main config accepted" ; fi if [ $scm_info -gt 1 ]; then echo "Main config downloaded and accepted" ; fi
else else
if [ $scm_info -gt 1 ]; then echo "Main config not downloaded - cached config will be used" ; fi if [ $scm_info -gt 1 ]; then echo "Main config not downloaded - cached config will be used" ; fi
echo -n "Main config not downloaded " > $sl_sedlocache/last_getcnf.txt echo -n "Main config not downloaded " > $sl_sedlocache/last_getcnf.txt
date >> $sl_sedlocache/last_getcnf.txt date >> $sl_sedlocache/last_getcnf.txt
  fi
   
  # before generating a new cached config we store the old one for
  # comparison with the new one
  rm -f "$sl_sedlocache/$sl_nmcnf.old"
  if [ -s $sl_sedlocache/$sl_nmcnf ]
  then
  cp $sl_sedlocache/$sl_nmcnf $sl_sedlocache/$sl_nmcnf.old
  else
  touch $sl_sedlocache/$sl_nmcnf.old
fi fi
   
# preparing cached config from local and main # preparing cached config from local and main
# the local config should be processed as the second to have # the local config should be processed as the second to have
# higher priority for rules from local config # higher priority for rules from local config
   
echo "# generated file" > $sl_sedlocache/$sl_nmcnf echo "# generated file" > $sl_sedlocache/$sl_nmcnf
for sl_file in `ls $sl_sedlocache/$sl_nmcnf.main ; ls $sl_sedlocnf` for sl_file in `ls $sl_sedlocache/$sl_nmcnf.main ; ls $sl_sedlocnf`
do do
cat $sl_file | grep "^mcnf" | $sl_trcmd ';' '#' | awk '{print $1"\t"$2}' >> $sl_sedlocache/$sl_nmcnf cat $sl_file | grep "^mcnf" | $sl_trcmd ';' '#' | awk '{print $1"\t"$2}' >> $sl_sedlocache/$sl_nmcnf
cat $sl_file | grep "^igw" | $sl_trcmd ';' '#' | awk '{print $1"\t"$2"\t"$3}' >> $sl_sedlocache/$sl_nmcnf cat $sl_file | grep "^igw" | $sl_trcmd ';' '#' | awk '{print $1"\t"$2"\t"$3}' >> $sl_sedlocache/$sl_nmcnf
Line 239... Line 266...
#local gateways taken from local config #local gateways taken from local config
cat $sl_sedlocnf | grep "^myigw" | $sl_trcmd ';' '#' | awk '{print $1"\t"$2"\t"$3}' >> $sl_sedlocache/$sl_nmcnf cat $sl_sedlocnf | grep "^myigw" | $sl_trcmd ';' '#' | awk '{print $1"\t"$2"\t"$3}' >> $sl_sedlocache/$sl_nmcnf
   
#cat $sl_sedlocache/$sl_nmcnf | sort | uniq > $sl_sedlocache/$sl_nmcnf.uniq #cat $sl_sedlocache/$sl_nmcnf | sort | uniq > $sl_sedlocache/$sl_nmcnf.uniq
#mv $sl_sedlocache/$sl_nmcnf.uniq $sl_sedlocache/$sl_nmcnf #mv $sl_sedlocache/$sl_nmcnf.uniq $sl_sedlocache/$sl_nmcnf
   
  sl_diffcfg=`diff $sl_sedlocache/$sl_nmcnf $sl_sedlocache/$sl_nmcnf.old | grep -c .`
  if [ $sl_diffcfg -gt 0 ]
  then
  if [ $scm_info -gt 0 ]; then echo "New config is different than the old one" ; fi
  else
  if [ $scm_info -gt 0 ]; then echo "New config is the same as the old one" ; fi
  fi
   
  # to detect first start after reboot or rule flushig we compare config with rule number
  # when we have less rules than ips in config then
  sl_numru=`ip ru ls | grep -c lookup`
  sl_numip=`grep -c ^ip $sl_sedlocache/$sl_nmcnf`
  sl_numru=$(($sl_numru - 3 ))
  if [ $sl_numip -gt $sl_numru ]
  then
  if [ $scm_info -gt 0 ]; then echo "We have less rules ($sl_numru) than new config has ips ($sl_numip)" ; fi
  sl_diffcfg="1"
  else
  if [ $scm_info -gt 0 ]; then echo "We have $sl_numru rules and $sl_numip ips" ; fi
  fi
   
} }
   
###################################################################### ######################################################################
s_version() s_version()
Line 354... Line 402...
   
if [ $scm_nogetcfg -eq 0 ] if [ $scm_nogetcfg -eq 0 ]
then then
s_getcfg s_getcfg
fi fi
   
   
s_mktables s_mktables
s_filltables s_filltables
s_fillrules  
  if [ $sl_diffcfg -gt 0 ]
  then
  s_fillrules
  fi
   
exit 0 exit 0
   
   
   

Powered by WebSVN 2.2.1