sedlo |
Subversion Repositories: |
Rev 7 | Rev 8 | |
---|---|---|
Line 3... | Line 3... | |
# release date : 07/09/2004 |
# release date : 07/09/2004 | |
# name : sedlo |
# name : sedlo | |
# description : dynamic side routing tables tool |
# description : dynamic side routing tables tool | |
# license : GPL |
# license : GPL | |
|
| |
sl_version="0.0.3pre6" |
#changelog | |
# - ip ro fl ca | ||
# - myigw | ||
| ||
sl_version="0.0.3pre7" | ||
|
| |
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 45... | Line 49... | |
fi |
fi | |
|
| |
sl_murlcfg=`cat $sl_sedlocnf | grep "^mcnf" | uniq | awk '{print $2}'` |
sl_murlcfg=`cat $sl_sedlocnf | grep "^mcnf" | uniq | awk '{print $2}'` | |
|
| |
###################################################################### |
###################################################################### | |
s_flqq() |
s_maru() | |
{ |
{ | |
if [ $scm_info -gt 0 ]; then echo "Managing rules" ; fi |
if [ $scm_info -gt 0 ]; then echo "Managing rules" ; fi | |
|
||
|
| |
sl_rules=`($sl_ipcmd ru ls | $sl_grepcmd -v "from all lookup" | $sl_awkcmd '{print $3"*ru"}' ; \ |
sl_rules=`($sl_ipcmd ru ls | $sl_grepcmd -v "from all lookup" | $sl_awkcmd '{print $3"*ru"}' ; \ | |
$sl_catcmd $sl_sedlocache/$sl_nmcnf | $sl_grepcmd "^ip" | $sl_awkcmd '{print $2"*ip"}') | sort | uniq` |
$sl_catcmd $sl_sedlocache/$sl_nmcnf | $sl_grepcmd "^ip" | $sl_awkcmd '{print $2"*ip"}') | sort | uniq` | |
|
| |
sl_merged=`echo $sl_rules $sl_ips | sort | uniq` |
sl_merged=`echo $sl_rules $sl_ips | sort | uniq` | |
|
| |
echo $sl_merged |
echo $sl_merged | |
|
| |
} # s_flru |
} # s_maru | |
###################################################################### |
###################################################################### | |
s_flru() |
s_flru() | |
{ |
{ | |
if [ $scm_info -gt 0 ]; then echo "Flushing all rules" ; fi |
if [ $scm_info -gt 0 ]; then echo "Flushing all rules" ; fi | |
|
| |
Line 71... | Line 74... | |
do |
do | |
# sl_ipn=`echo $sl_rule | $sl_awkcmd -F '*' '{print $2}'` |
# sl_ipn=`echo $sl_rule | $sl_awkcmd -F '*' '{print $2}'` | |
sl_ipgws=`echo $sl_rule | $sl_awkcmd -F '*' '{print $2,$3,$4,$5,$6,$7}'` |
sl_ipgws=`echo $sl_rule | $sl_awkcmd -F '*' '{print $2,$3,$4,$5,$6,$7}'` | |
$sl_ipcmd ru del $sl_ipgws |
$sl_ipcmd ru del $sl_ipgws | |
done |
done | |
| ||
#this should make faster applying of new routing tables | ||
$sl_ipcmd ro flush cache | ||
|
| |
} # s_flru |
} # s_flru | |
| ||
###################################################################### |
###################################################################### | |
s_fillrules() |
s_fillrules() | |
{ |
{ | |
| ||
#flush old rules before filling new ones | ||
#not so nice solution - it is planned to change just what's necessary | ||
#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" ; 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}'` | |
Line 107... | Line 118... | |
fi |
fi | |
done |
done | |
done |
done | |
|
| |
$sl_ipcmd ru add from $sl_ipnodef to $sl_ipnodef lookup main |
$sl_ipcmd ru add from $sl_ipnodef to $sl_ipnodef lookup main | |
| ||
#this should make faster applying of new routing tables | ||
$sl_ipcmd ro flush cache | ||
|
| |
} # s_fillrules |
} # s_fillrules | |
| ||
###################################################################### |
###################################################################### | |
s_filltables() |
s_filltables() | |
{ |
{ | |
if [ $scm_info -gt 0 ]; then echo "Filling tables" ; fi |
if [ $scm_info -gt 0 ]; then echo "Filling tables" ; fi | |
|
| |
Line 142... | Line 157... | |
$sl_ipcmd ro add 0.0.0.0/1 via $sl_igwgt ta $sl_igwn |
$sl_ipcmd ro add 0.0.0.0/1 via $sl_igwgt ta $sl_igwn | |
$sl_ipcmd ro add 128.0.0.0/1 via $sl_igwgt ta $sl_igwn |
$sl_ipcmd ro add 128.0.0.0/1 via $sl_igwgt ta $sl_igwn | |
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 | |
done |
done | |
| ||
#this should make faster applying of new routing tables | ||
$sl_ipcmd ro flush cache | ||
|
| |
} # s_filltables |
} # s_filltables | |
| ||
###################################################################### |
###################################################################### | |
s_mktables() |
s_mktables() | |
{ |
{ | |
if [ $scm_info -gt 0 ]; then echo "Creating tables " ; fi |
if [ $scm_info -gt 0 ]; then echo "Creating tables " ; fi | |
sl_igws=`$sl_catcmd $sl_sedlocache/$sl_nmcnf | $sl_grepcmd "^igw" | $sl_awkcmd '{print $3}'` |
sl_igws=`$sl_catcmd $sl_sedlocache/$sl_nmcnf | $sl_grepcmd "^igw" | $sl_awkcmd '{print $3}'` | |
Line 174... | Line 193... | |
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() | |
{ |
{ | |
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 $sl_murlcfg -O "$sl_sedlocache/$sl_nmcnf.main.tmp" -q |
wget -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 accepted" ; fi | |
else |
else | |
if [ $scm_info -gt 1 ]; then echo "Main config not accepted - using cached config" ; fi |
if [ $scm_info -gt 1 ]; then echo "Main config not downloaded - cached config will be used" ; fi | |
echo -n "Main config not found " > $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 |
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 | |
Line 205... | Line 225... | |
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 | |
cat $sl_file | grep "^ip" | $sl_trcmd ';' '#' | awk '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6}' >> $sl_sedlocache/$sl_nmcnf |
cat $sl_file | grep "^ip" | $sl_trcmd ';' '#' | awk '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6}' >> $sl_sedlocache/$sl_nmcnf | |
done |
done | |
| ||
#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_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 | |
|
| |
} |
} | |
| ||
###################################################################### |
###################################################################### | |
s_version() |
s_version() | |
{ |
{ | |
echo sedlo $sl_version |
echo sedlo $sl_version | |
} # s_version |
} # s_version | |
| ||
###################################################################### |
###################################################################### | |
s_report() |
s_report() | |
{ |
{ | |
echo "##### SEDLO #####" |
echo "##### SEDLO #####" | |
echo "date : `date`" |
echo "date : `date`" | |
Line 228... | Line 254... | |
echo "##### TABLES #####" |
echo "##### TABLES #####" | |
cat $sl_rttab |
cat $sl_rttab | |
echo "##### RULES #####" |
echo "##### RULES #####" | |
$sl_ipcmd ru ls |
$sl_ipcmd ru ls | |
} # s_report |
} # s_report | |
| ||
###################################################################### |
###################################################################### | |
s_help() |
s_help() | |
{ |
{ | |
echo Pouziti: sedlo [param] |
echo Pouziti: sedlo [param] | |
echo param: |
echo param: | |
Line 241... | Line 268... | |
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 | |
} # s_help |
} # s_help | |
| ||
###################################################################### |
###################################################################### | |
###################################################################### |
###################################################################### | |
|
| |
sl_unknown="" |
sl_unknown="" | |
scm_nogetcfg=0 |
scm_nogetcfg=0 |