jablonka.czprosek.czf

sedlo

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

Show entire file Ignore whitespace

Rev 10 Rev 11
Line 1... Line 1...
#!/bin/bash #!/bin/bash
# author : Petr Simandl www.simandl.cz # author : Petr Simandl www.simandl.cz
# release date : 26/01/2006 # release date : 06/08/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.4pre1" sl_version="0.0.4pre2"
   
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 156... Line 156...
#if myigw then fill table for local gateway with single ip from config #if myigw then fill table for local gateway with single ip from config
if [ "$sl_igwtype x" = "myigw x" ] if [ "$sl_igwtype x" = "myigw x" ]
then then
sl_igwgt=$sl_igwip sl_igwgt=$sl_igwip
fi fi
   
  #testing if the igw has not a route in global routing table
if [ "$sl_igwgt x" = " x" ] if [ "$sl_igwgt x" = " x" ]
then then
if [ $scm_info -gt 1 ]; then echo "Route not found for igw $sl_igwn - leaving table as is" ; fi if [ $scm_info -gt 1 ]; then echo "Route not found for igw $sl_igwn" ; fi
  sl_myigw=`cat $sl_sedlocnf | $sl_grepcmd "^myigw" | $sl_grepcmd $sl_igwn | $sl_awkcmd '{print $3}'`
  #testing if the igw without route is in local config
  #if not we go to flush its table and set flag to redo rules
  if [ "$sl_myigw x" = " x" ]
  then
  #getting num of routes of igw
  sl_igwnr=`$sl_ipcmd ro ls ta all | $sl_grepcmd -c $sl_igwn`
  if [ "$sl_igwnr x" = "0 x" ]
  then
  if [ $scm_info -gt 1 ]; then echo "Igw $sl_igwn is already empty - no action taken" ; fi
  else
  if [ $scm_info -gt 1 ]; then echo "Igw $sl_igwn will be flushed and rules rearranged" ; fi
  $sl_ipcmd ro fl ta $sl_igwn
  #because this igw dissapeared we set a flag for rules recreation
  sl_diffigw=1
  fi
  else
  echo "Igw $sl_igwn found in local config - leaving table as is"
  fi
   
else else
sl_tbl=`$sl_ipcmd ro ls ta $sl_igwn` sl_tbl=`$sl_ipcmd ro ls ta $sl_igwn`
if [ "$sl_tbl x" != " x" ] if [ "$sl_tbl x" != " x" ]
then then
$sl_ipcmd ro fl ta $sl_igwn $sl_ipcmd ro fl ta $sl_igwn
Line 190... Line 211...
# because there is space enough and after reboot table will not be created # because there is space enough and after reboot table will not be created
s_mktables() s_mktables()
{ {
if [ $scm_info -gt 0 ]; then echo "Checking 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 210... Line 230...
then then
sl_ok="yes" sl_ok="yes"
echo "$sl_cnt $sl_igw" >> $sl_rttab echo "$sl_cnt $sl_igw" >> $sl_rttab
fi fi
sl_cnt=$(($sl_cnt - 1 )) sl_cnt=$(($sl_cnt - 1 ))
done done
  # a new table was created so we should set a flag for rules creation
  sl_difftbl=1
else else
if [ $scm_info -gt 1 ]; then echo "Table found for $sl_igw no action taken" ; fi if [ $scm_info -gt 1 ]; then echo "Table found for $sl_igw no action taken" ; fi
fi fi
done done
   
} # s_mktables } # s_mktables
   
###################################################################### ######################################################################
s_getcfg() s_getcfg()
{ {
Line 275... Line 296...
if [ $scm_info -gt 0 ]; then echo "New config is different than the old one" ; fi if [ $scm_info -gt 0 ]; then echo "New config is different than the old one" ; fi
else else
if [ $scm_info -gt 0 ]; then echo "New config is the same as the old one" ; fi if [ $scm_info -gt 0 ]; then echo "New config is the same as the old one" ; fi
fi fi
   
# to detect first start after reboot or rule flushig we compare config with rule number # showing number of rules in config and system
# when we have less rules than ips in config then  
sl_numru=`ip ru ls | grep -c lookup` sl_numru=`ip ru ls | grep -c lookup`
sl_numip=`grep -c ^ip $sl_sedlocache/$sl_nmcnf` sl_numip=`grep -c ^ip $sl_sedlocache/$sl_nmcnf`
sl_numru=$(($sl_numru - 3 )) sl_numru=$(($sl_numru - 3 ))
if [ $sl_numip -gt $sl_numru ] if [ $sl_numip -gt $sl_numru ]
then then
if [ $scm_info -gt 0 ]; then echo "We have less rules ($sl_numru) than new config has ips ($sl_numip)" ; fi if [ $scm_info -gt 0 ]; then echo "We have less rules ($sl_numru) than new config has ips ($sl_numip)" ; fi
sl_diffcfg="1" # sl_diffcfg="1"
else else
if [ $scm_info -gt 0 ]; then echo "We have $sl_numru rules and $sl_numip ips" ; fi if [ $scm_info -gt 0 ]; then echo "We have $sl_numru rules and $sl_numip ips" ; fi
fi fi
   
} }
Line 332... Line 352...
echo -v malo upovidany echo -v malo upovidany
echo -vv hodne upovidany echo -vv hodne upovidany
echo -nogetcfg zajisti ze se nedude znovu nacitat konfigurace a pouzije se predchozi z cache echo -nogetcfg zajisti ze se nedude znovu nacitat konfigurace a pouzije se predchozi z cache
echo -report vypise prehled pravidel a tabulek echo -report vypise prehled pravidel a tabulek
echo -flru odstrani vsechny pravidla echo -flru odstrani vsechny pravidla
  echo -force bezpodminecne znovu obnovi vsechny pravidla
} # s_help } # s_help
   
###################################################################### ######################################################################
###################################################################### ######################################################################
   
sl_unknown="" sl_unknown=""
scm_nogetcfg=0 scm_nogetcfg=0
scm_flru=0 scm_flru=0
scm_info=0 scm_info=0
  scm_force=0
  sl_diffigw=0
  sl_difftbl=0
   
# parsing input parameters # parsing input parameters
while [ "a$1" != "a" ] while [ "a$1" != "a" ]
do do
case $1 in case $1 in
Line 360... Line 384...
s_report s_report
exit 0 exit 0
;; ;;
-flru) -flru)
scm_flru=1 scm_flru=1
  shift
  ;;
  -force)
  scm_force=1
shift shift
;; ;;
-help) -help)
s_help s_help
exit 0 exit 0
Line 402... Line 430...
   
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
  #echo $sl_difftbl
  #echo $sl_diffcfg
  #echo $sl_diffigw
  #echo $scm_force
   
if [ $sl_diffcfg -gt 0 ] #flushing and filling rules is done only when
  #new table is created
  #config is changed
  #some igw dissapears or appears
  #-force command line parameter was used
  if [ $sl_difftbl -gt 0 ] || [ $sl_diffcfg -gt 0 ] || [ $sl_diffigw -gt 0 ] || [ $scm_force -gt 0 ]
then then
s_fillrules s_fillrules
fi fi
   
exit 0 exit 0
   
   
   

Powered by WebSVN 2.2.1