sedlo |
Subversion Repositories: |
Rev 16 | Rev 17 | |
---|---|---|
Line 1... | Line 1... | |
#!/bin/bash |
#!/bin/bash | |
# author : Petr Simandl www.simandl.cz |
# author : Petr Simandl www.simandl.cz | |
# release date : 1/11/2006 |
# release date : 23/04/2007 | |
# name : sedlo |
# name : sedlo | |
# description : dynamic side routing tables tool |
# description : dynamic side routing tables tool | |
# license : GPL |
# license : GPL | |
|
| |
sl_version="0.0.4pre7" |
sl_version="0.0.4pre8" | |
|
| |
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 136... | Line 136... | |
s_checknodefru |
s_checknodefru | |
|
| |
#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 for ips" ; fi |
if [ $scm_info -gt 0 ]; then echo "Checking 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}'` | |
sl_rules=`$sl_ipcmd ru ls | $sl_grepcmd ^$sl_priorules":" | $sl_trcmd '[:blank:]' '*'` | ||
| ||
| ||
|
| |
#for all IPs we check and leave, change or create rule | ||
for sl_ip in $sl_ips |
for sl_ip in $sl_ips | |
do |
do | |
sl_ipn=`echo $sl_ip | $sl_awkcmd -F '*' '{print $1}'` |
sl_ipn=`echo $sl_ip | $sl_awkcmd -F '*' '{print $1}'` | |
sl_ipgws=`echo $sl_ip | $sl_awkcmd -F '*' '{print $2,$3,$4}'` |
sl_ipgws=`echo $sl_ip | $sl_awkcmd -F '*' '{print $2,$3,$4}'` | |
sl_ok="no" |
sl_ok="no" | |
#for all GWs we check rules | ||
for sl_ipgw in $sl_ipgws |
for sl_ipgw in $sl_ipgws | |
do |
do | |
sl_tbl=`$sl_ipcmd ro ls ta $sl_ipgw` |
sl_tbl=`$sl_ipcmd ro ls ta $sl_ipgw` | |
#check if table exists | ||
if [ "$sl_tbl x" != " x" ] && [ "$sl_ok" = "no" ] |
if [ "$sl_tbl x" != " x" ] && [ "$sl_ok" = "no" ] | |
then |
then | |
#we have IP and GW |
#we have IP and GW table | |
if [ $scm_info -gt 1 ]; then echo "Creating new rules to send $sl_ipn to table $sl_ipgw" ; fi |
#check if the rule alredady exists | |
$sl_ipcmd ru add from $sl_ipn lookup $sl_ipgw prio $sl_priorules |
sl_oldrule=`echo $sl_rules | $sl_trcmd " " "\n" | $sl_grepcmd "\*"$sl_ipn"\*"` | |
|
sl_exactrule=`echo $sl_oldrule | $sl_trcmd " " "\n" | $sl_grepcmd "\*"$sl_ipgw"\*"` | |
#this should make faster applying of new routing tables |
if [ "$sl_exactrule x" == " x" ] | |
$sl_ipcmd ro flush cache |
then | |
#exact rule doesn't exist so we check if an old rule for this IP is present | ||
if [ "$sl_oldrule x" != " x" ] | ||
then | ||
#some old rule(s) for IP is present so we delete it | ||
for sl_rule in $sl_oldrule | ||
do | ||
sl_ipgws=`echo $sl_rule | $sl_awkcmd -F '*' '{print $2,$3,$4,$5,$6,$7}'` | ||
if [ $scm_info -gt 0 ]; then echo "Deleting old rule $sl_ipgws" ; fi | ||
$sl_ipcmd ru del $sl_ipgws | ||
#this should make faster applying of new routing tables | ||
$sl_ipcmd ro flush cache | ||
done | ||
fi | ||
| ||
if [ $scm_info -gt 0 ]; then echo "Creating new rule to send $sl_ipn to table $sl_ipgw" ; fi | ||
$sl_ipcmd ru add from $sl_ipn lookup $sl_ipgw prio $sl_priorules | ||
| ||
else | ||
if [ $scm_info -gt 1 ]; then echo "Rule to send $sl_ipn to table $sl_ipgw already exists" ; fi | ||
fi | ||
sl_ok="yes" |
sl_ok="yes" | |
else |
else | |
#we have no table | ||
if [ "$sl_ok" = "no" ] |
if [ "$sl_ok" = "no" ] | |
then |
then | |
if [ $scm_info -gt 1 ]; then echo "For $sl_ipn table $sl_ipgw not used because it is empty" ; fi |
if [ $scm_info -gt 1 ]; then echo "For $sl_ipn table $sl_ipgw not used because it is empty" ; fi | |
else |
else | |
if [ $scm_info -gt 1 ]; then echo "For $sl_ipn table $sl_ipgw not used because it has lower priority" ; fi |
if [ $scm_info -gt 1 ]; then echo "For $sl_ipn table $sl_ipgw not used because it has lower priority" ; fi | |
fi |
fi | |
fi |
fi | |
done |
done | |
done |
done | |
|
| |
#finally we check all rules and if there is a rule without IP from config we delete it | ||
for sl_rule in $sl_rules | ||
do | ||
sl_iprule=`echo $sl_rule | $sl_awkcmd -F '*' '{print $3}'` | ||
sl_ipconf=`echo $sl_ips | $sl_trcmd " " "\n" | $sl_grepcmd "^"$sl_iprule"\*"` | ||
| ||
if [ "$sl_ipconf x" == " x" ] | ||
then | ||
#we have a rule without an IP in config so we delete this rule | ||
sl_ipgws=`echo $sl_rule | $sl_awkcmd -F '*' '{print $2,$3,$4,$5,$6,$7}'` | ||
if [ $scm_info -gt 0 ]; then echo "Deleting non config rule $sl_ipgws" ; fi | ||
$sl_ipcmd ru del $sl_ipgws | ||
#this should make faster applying of new routing tables | ||
$sl_ipcmd ro flush cache | ||
fi | ||
done | ||
|
| |
} # s_fillrules |
} # s_fillrules | |
|
| |
###################################################################### |
###################################################################### | |
# here we look into the main routing table for path to our iGWs |
# here we look into the main routing table for path to our iGWs |