1 | 7 | simandl | #!/bin/bash |
2 | | | # author : Petr Simandl www.simandl.cz |
3 | 15 | simandl | # release date : 1/11/2006 |
4 | 7 | simandl | # name : sedlo |
5 | | | # description : dynamic side routing tables tool |
6 | | | # license : GPL |
7 | | | |
8 | 16 | simandl | sl_version="0.0.4pre7" |
9 | 7 | simandl | |
10 | | | PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin |
11 | | | |
12 | | | sl_nmcnf="sedlo.conf" |
13 | | | sl_sedlocnf="/etc/$sl_nmcnf" |
14 | | | sl_sedlocache="/var/cache/sedlo" |
15 | | | |
16 | | | sl_rttab="/etc/iproute2/rt_tables" |
17 | | | sl_rtnmin=110 |
18 | | | sl_rtnmax=200 |
19 | 16 | simandl | #all traffic that is handled as internal (CZF traffic) |
20 | 7 | simandl | sl_ipnodef="10.0.0.0/8" |
21 | 16 | simandl | #this will specify rupriority in rule table |
22 | | | sl_priorules=10000 |
23 | | | #no default traffic will have rule at higher priority |
24 | | | sl_prionodef=$(($sl_priorules - 1)) |
25 | 7 | simandl | |
26 | | | slm_unknown="Nezname parametry : " |
27 | | | |
28 | | | sl_ipcmd=`which ip` |
29 | | | sl_trcmd=`which tr` |
30 | | | sl_wgetcmd=`which wget` |
31 | | | sl_hnmcmd=`which hostname` |
32 | | | sl_awkcmd=`which awk` |
33 | | | sl_catcmd=`which cat` |
34 | | | sl_grepcmd=`which grep` |
35 | 10 | simandl | sl_diffcmd=`which diff` |
36 | 7 | simandl | |
37 | | | if [ -e $sl_sedlocnf ] |
38 | | | then |
39 | | | sl_nop=1 |
40 | | | else |
41 | | | echo "$sl_sedlocnf not found" |
42 | | | exit 1 |
43 | | | fi |
44 | | | |
45 | | | if [ -e $sl_rttab ] |
46 | | | then |
47 | | | sl_nop=1 |
48 | | | else |
49 | | | echo "$sl_rttab not found" |
50 | | | exit 1 |
51 | | | fi |
52 | | | |
53 | 9 | simandl | sl_murlcfg=`cat $sl_sedlocnf | grep "^mcnf" | uniq | awk '{print $2" "$3" "$4}'` |
54 | 7 | simandl | |
55 | | | ###################################################################### |
56 | 8 | simandl | s_maru() |
57 | 7 | simandl | { |
58 | | | if [ $scm_info -gt 0 ]; then echo "Managing rules" ; fi |
59 | | | |
60 | | | sl_rules=`($sl_ipcmd ru ls | $sl_grepcmd -v "from all lookup" | $sl_awkcmd '{print $3"*ru"}' ; \ |
61 | | | $sl_catcmd $sl_sedlocache/$sl_nmcnf | $sl_grepcmd "^ip" | $sl_awkcmd '{print $2"*ip"}') | sort | uniq` |
62 | | | |
63 | | | sl_merged=`echo $sl_rules $sl_ips | sort | uniq` |
64 | | | |
65 | | | echo $sl_merged |
66 | | | |
67 | 8 | simandl | } # s_maru |
68 | 16 | simandl | |
69 | 7 | simandl | ###################################################################### |
70 | 16 | simandl | #this will delete all rules at sl_prionodef an sl_priorules priorities |
71 | | | s_flruall() |
72 | | | { |
73 | | | if [ $scm_info -gt 0 ]; then echo "Flushing all rules" ; fi |
74 | | | |
75 | | | sl_rules=`$sl_ipcmd ru ls | $sl_grepcmd "^"$sl_prionodef":" | $sl_trcmd '[:blank:]' '*'` |
76 | | | for sl_rule in $sl_rules |
77 | | | do |
78 | | | sl_ipgws=`echo $sl_rule | $sl_awkcmd -F '*' '{print $2,$3,$4,$5,$6,$7}'` |
79 | | | $sl_ipcmd ru del $sl_ipgws |
80 | | | #this should make faster applying of new routing tables |
81 | | | $sl_ipcmd ro flush cache |
82 | | | done |
83 | | | |
84 | | | sl_rules=`$sl_ipcmd ru ls | $sl_grepcmd "^"$sl_priorules":" | $sl_trcmd '[:blank:]' '*'` |
85 | | | for sl_rule in $sl_rules |
86 | | | do |
87 | | | sl_ipgws=`echo $sl_rule | $sl_awkcmd -F '*' '{print $2,$3,$4,$5,$6,$7}'` |
88 | | | $sl_ipcmd ru del $sl_ipgws |
89 | | | #this should make faster applying of new routing tables |
90 | | | $sl_ipcmd ro flush cache |
91 | | | done |
92 | | | |
93 | | | } # s_flruall |
94 | | | |
95 | | | ###################################################################### |
96 | 7 | simandl | s_flru() |
97 | | | { |
98 | | | if [ $scm_info -gt 0 ]; then echo "Flushing all rules" ; fi |
99 | | | |
100 | 16 | simandl | sl_rules=`$sl_ipcmd ru ls | $sl_grepcmd ^$sl_priorules":" | $sl_trcmd '[:blank:]' '*'` |
101 | 7 | simandl | |
102 | | | for sl_rule in $sl_rules |
103 | | | do |
104 | | | sl_ipgws=`echo $sl_rule | $sl_awkcmd -F '*' '{print $2,$3,$4,$5,$6,$7}'` |
105 | | | $sl_ipcmd ru del $sl_ipgws |
106 | 16 | simandl | #this should make faster applying of new routing tables |
107 | | | $sl_ipcmd ro flush cache |
108 | 7 | simandl | done |
109 | | | |
110 | | | } # s_flru |
111 | 8 | simandl | |
112 | 7 | simandl | ###################################################################### |
113 | 16 | simandl | s_checknodefru() |
114 | | | { |
115 | | | #checking if we have present nodef rule and if not we create it |
116 | | | sl_nodefrule=`$sl_ipcmd ru ls | $sl_grepcmd "^"$sl_prionodef":" | $sl_trcmd '[:blank:]' '*'` |
117 | | | #echo $sl_nodefrule |
118 | | | if [ "$sl_nodefrule x" == " x" ] |
119 | | | then |
120 | | | if [ $scm_info -gt 0 ]; then echo "Creating rule for nodef route" ; fi |
121 | | | $sl_ipcmd ru add from $sl_ipnodef to $sl_ipnodef lookup main prio $sl_prionodef |
122 | | | echo "delam novou" |
123 | | | fi |
124 | | | |
125 | | | } |
126 | | | |
127 | | | ###################################################################### |
128 | 10 | simandl | # here we get each ip and we create a rule to send this ip to a |
129 | | | # certain table |
130 | | | # this routine can be skipped when the number of ips and ip directions |
131 | | | # are still the same = old and new configs are the same |
132 | 7 | simandl | s_fillrules() |
133 | | | { |
134 | 8 | simandl | |
135 | 16 | simandl | #this will check no default rule if exists and if not it will be created |
136 | | | s_checknodefru |
137 | | | |
138 | 8 | simandl | #flush old rules before filling new ones |
139 | | | #not so nice solution - it is planned to change just what's necessary |
140 | | | #by s_maru |
141 | 7 | simandl | s_flru |
142 | | | |
143 | 10 | simandl | if [ $scm_info -gt 0 ]; then echo "Creating rules for ips" ; fi |
144 | 7 | simandl | |
145 | | | sl_ips=`$sl_catcmd $sl_sedlocache/$sl_nmcnf | $sl_grepcmd "^ip" | $sl_awkcmd '{print $2"*"$4"*"$5"*"$6}'` |
146 | | | |
147 | | | for sl_ip in $sl_ips |
148 | | | do |
149 | | | sl_ipn=`echo $sl_ip | $sl_awkcmd -F '*' '{print $1}'` |
150 | | | sl_ipgws=`echo $sl_ip | $sl_awkcmd -F '*' '{print $2,$3,$4}'` |
151 | | | sl_ok="no" |
152 | | | for sl_ipgw in $sl_ipgws |
153 | | | do |
154 | | | sl_tbl=`$sl_ipcmd ro ls ta $sl_ipgw` |
155 | | | if [ "$sl_tbl x" != " x" ] && [ "$sl_ok" = "no" ] |
156 | | | then |
157 | 16 | simandl | #we have IP and GW |
158 | 7 | simandl | if [ $scm_info -gt 1 ]; then echo "Creating new rules to send $sl_ipn to table $sl_ipgw" ; fi |
159 | 16 | simandl | $sl_ipcmd ru add from $sl_ipn lookup $sl_ipgw prio $sl_priorules |
160 | | | |
161 | | | #this should make faster applying of new routing tables |
162 | | | $sl_ipcmd ro flush cache |
163 | 7 | simandl | sl_ok="yes" |
164 | | | else |
165 | | | if [ "$sl_ok" = "no" ] |
166 | | | then |
167 | | | if [ $scm_info -gt 1 ]; then echo "For $sl_ipn table $sl_ipgw not used because it is empty" ; fi |
168 | | | else |
169 | 16 | simandl | if [ $scm_info -gt 1 ]; then echo "For $sl_ipn table $sl_ipgw not used because it has lower priority" ; fi |
170 | 7 | simandl | fi |
171 | | | fi |
172 | | | done |
173 | | | done |
174 | | | |
175 | | | |
176 | | | } # s_fillrules |
177 | 8 | simandl | |
178 | 7 | simandl | ###################################################################### |
179 | 10 | simandl | # here we look into the main routing table for path to our iGWs |
180 | | | # and we fill these tables with two halves default nets that |
181 | | | # point to appropriate direction |
182 | | | # this routine can be skipped when the routing table is the same |
183 | 7 | simandl | s_filltables() |
184 | | | { |
185 | 10 | simandl | if [ $scm_info -gt 0 ]; then echo "Checking main routing table" ; fi |
186 | | | |
187 | 7 | simandl | if [ $scm_info -gt 0 ]; then echo "Filling tables" ; fi |
188 | | | |
189 | 9 | simandl | sl_igws=`$sl_catcmd $sl_sedlocache/$sl_nmcnf | $sl_grepcmd -E "^igw|^myigw" | $sl_awkcmd '{print $3"*"$2"*"$1}'` |
190 | 7 | simandl | |
191 | | | for sl_igw in $sl_igws |
192 | | | do |
193 | | | sl_igwn=`echo $sl_igw | $sl_awkcmd -F '*' '{print $1}'` |
194 | | | sl_igwip=`echo $sl_igw | $sl_awkcmd -F '*' '{print $2}'` |
195 | 9 | simandl | sl_igwtype=`echo $sl_igw | $sl_awkcmd -F '*' '{print $3}'` |
196 | 15 | simandl | |
197 | 14 | simandl | #oprava falesneho routovani na lokalni iface - pokud jsme lokalni igw tak se nema najit ip |
198 | | | #protoze cesta dal neni - jsme totiz uz na lokalnim iface |
199 | 15 | simandl | #head je tam proto ze se pro prespolni(a bgp) muze objevit vice rout s ruznou metrikou tak vezmem jen prvni (head) |
200 | | | #s nejmensi metrikou (sort) |
201 | | | sl_igwgt=`$sl_ipcmd ro ls | $sl_grepcmd -v "proto kernel" | $sl_grepcmd "^$sl_igwip " | sort | $sl_awkcmd '{print $3}' | head -n 1` |
202 | 7 | simandl | |
203 | 9 | simandl | # equal cost multipath detection - just first IP is taken as way to igw |
204 | 7 | simandl | if [ "$sl_igwgt x" = "zebra x" ] |
205 | | | then |
206 | | | sl_igwgt=`$sl_ipcmd ro ls | $sl_grepcmd -A 1 "^$sl_igwip " | $sl_grepcmd "nexthop" | $sl_awkcmd '{print $3}'` |
207 | | | fi |
208 | | | |
209 | 9 | simandl | #if myigw then fill table for local gateway with single ip from config |
210 | | | if [ "$sl_igwtype x" = "myigw x" ] |
211 | | | then |
212 | | | sl_igwgt=$sl_igwip |
213 | | | fi |
214 | 11 | simandl | #testing if the igw has not a route in global routing table |
215 | 7 | simandl | if [ "$sl_igwgt x" = " x" ] |
216 | | | then |
217 | 11 | simandl | if [ $scm_info -gt 1 ]; then echo "Route not found for igw $sl_igwn" ; fi |
218 | | | sl_myigw=`cat $sl_sedlocnf | $sl_grepcmd "^myigw" | $sl_grepcmd $sl_igwn | $sl_awkcmd '{print $3}'` |
219 | | | #testing if the igw without route is in local config |
220 | | | #if not we go to flush its table and set flag to redo rules |
221 | | | if [ "$sl_myigw x" = " x" ] |
222 | | | then |
223 | | | #getting num of routes of igw |
224 | 13 | simandl | sl_igwnr=`$sl_ipcmd ro ls ta all | $sl_grepcmd -c "table ${sl_igwn} "` |
225 | 11 | simandl | if [ "$sl_igwnr x" = "0 x" ] |
226 | | | then |
227 | 12 | simandl | if [ $scm_info -gt 1 ]; then echo "Table $sl_igwn is already empty - no action taken" ; fi |
228 | 11 | simandl | else |
229 | 12 | simandl | if [ $scm_info -gt 1 ]; then echo "Table $sl_igwn will be flushed and rules rearranged" ; fi |
230 | 11 | simandl | $sl_ipcmd ro fl ta $sl_igwn |
231 | | | #because this igw dissapeared we set a flag for rules recreation |
232 | | | sl_diffigw=1 |
233 | | | fi |
234 | | | else |
235 | 13 | simandl | if [ $scm_info -gt 1 ]; then echo "Igw $sl_igwn found in local config - leaving table as is" ; fi |
236 | 11 | simandl | fi |
237 | 7 | simandl | else |
238 | | | sl_tbl=`$sl_ipcmd ro ls ta $sl_igwn` |
239 | 12 | simandl | #if the table is empty we fill it and we set flag for rules recreation |
240 | | | if [ "$sl_tbl x" = " x" ] |
241 | 7 | simandl | then |
242 | 12 | simandl | sl_diffigw=1 |
243 | | | $sl_ipcmd ro add 0.0.0.0/1 via $sl_igwgt ta $sl_igwn |
244 | | | $sl_ipcmd ro add 128.0.0.0/1 via $sl_igwgt ta $sl_igwn |
245 | | | if [ "$sl_igwtype x" = "myigw x" ] |
246 | | | then |
247 | | | if [ $scm_info -gt 1 ]; then echo "Table $sl_igwn filled with default myigw $sl_igwgt" ; fi |
248 | | | else |
249 | | | if [ $scm_info -gt 1 ]; then echo "Table $sl_igwn filled with default gw $sl_igwgt" ; fi |
250 | | | fi |
251 | | | #the table is not empty so we check if routes are the same |
252 | 9 | simandl | else |
253 | 12 | simandl | #picking default gateway from the table |
254 | | | sl_igwogt=`$sl_ipcmd ro ls ta $sl_igwn | $sl_awkcmd '{print $3}' | uniq` |
255 | | | #checking if the old default is same as the new one |
256 | | | if [ "$sl_igwogt x" = "$sl_igwgt x" ] |
257 | | | then |
258 | | | if [ $scm_info -gt 1 ]; then echo "Table $sl_igwn will not be changed and default is $sl_igwgt" ; fi |
259 | | | else |
260 | | | #the new default is different so we will flush the table, fill new default |
261 | 15 | simandl | if [ $scm_info -gt 1 ]; then echo "Table $sl_igwn will be rewritten to default $sl_igwgt" ; fi |
262 | 12 | simandl | #flushing old default route in the table |
263 | | | $sl_ipcmd ro fl ta $sl_igwn |
264 | | | #filling new default |
265 | | | $sl_ipcmd ro add 0.0.0.0/1 via $sl_igwgt ta $sl_igwn |
266 | | | $sl_ipcmd ro add 128.0.0.0/1 via $sl_igwgt ta $sl_igwn |
267 | | | fi |
268 | 9 | simandl | fi |
269 | 7 | simandl | fi |
270 | | | done |
271 | | | |
272 | | | } # s_filltables |
273 | 8 | simandl | |
274 | 7 | simandl | ###################################################################### |
275 | 10 | simandl | # filling rttab with tables from config |
276 | | | # only new tables are created with a new uniq number that is not important because |
277 | | | # usually we handle tables just by their names |
278 | | | # this routine acts only when a new iGW appears - only adding a table is supported |
279 | | | # no deleting is implemented because it seems to be not necessary to delete an old table |
280 | | | # because there is space enough and after reboot table will not be created |
281 | 7 | simandl | s_mktables() |
282 | | | { |
283 | 10 | simandl | if [ $scm_info -gt 0 ]; then echo "Checking tables" ; fi |
284 | | | |
285 | 9 | simandl | sl_igws=`$sl_catcmd $sl_sedlocache/$sl_nmcnf | $sl_grepcmd -E "^igw|^myigw" | $sl_awkcmd '{print $3}'` |
286 | 7 | simandl | for sl_igw in $sl_igws |
287 | | | do |
288 | | | sl_igwrttb=`$sl_catcmd $sl_rttab | $sl_awkcmd '{print $2}' | $sl_grepcmd $sl_igw ` |
289 | | | if [ "$sl_igwrttb x" = " x" ] |
290 | | | then |
291 | | | if [ $scm_info -gt 1 ]; then echo "Creating table for $sl_igw" ; fi |
292 | | | sl_cnt="$sl_rtnmax" |
293 | | | sl_ok="no" |
294 | | | until [ "$sl_cnt" -eq "$sl_rtnmin" ] || [ "$sl_ok" = "yes" ] |
295 | | | do |
296 | | | #space is used to recognized two and three digit numbers |
297 | | | sl_igwrttb=`cat $sl_rttab | awk '{print $1" "}' | grep "$sl_cnt " ` |
298 | | | if [ "$sl_igwrttb x" = " x" ] |
299 | | | then |
300 | | | sl_ok="yes" |
301 | | | echo "$sl_cnt $sl_igw" >> $sl_rttab |
302 | | | fi |
303 | | | sl_cnt=$(($sl_cnt - 1 )) |
304 | 11 | simandl | done |
305 | | | # a new table was created so we should set a flag for rules creation |
306 | | | sl_difftbl=1 |
307 | 7 | simandl | else |
308 | | | if [ $scm_info -gt 1 ]; then echo "Table found for $sl_igw no action taken" ; fi |
309 | | | fi |
310 | 9 | simandl | done |
311 | 7 | simandl | } # s_mktables |
312 | 8 | simandl | |
313 | 7 | simandl | ###################################################################### |
314 | | | s_getcfg() |
315 | | | { |
316 | | | if [ $scm_info -gt 0 ]; then echo "Getting config" ; fi |
317 | | | if [ $scm_info -gt 1 ]; then echo "Using main config $sl_murlcfg" ; fi |
318 | | | if [ $scm_info -gt 1 ]; then echo "Using local config $sl_sedlocnf" ; fi |
319 | | | |
320 | 10 | simandl | rm -f "$sl_sedlocache/$sl_nmcnf.main.tmp" |
321 | 7 | simandl | |
322 | 10 | simandl | $sl_wgetcmd -q -t 3 $sl_murlcfg -O "$sl_sedlocache/$sl_nmcnf.main.tmp" |
323 | | | |
324 | 7 | simandl | if [ -s $sl_sedlocache/$sl_nmcnf.main.tmp ] |
325 | | | then |
326 | | | date > $sl_sedlocache/last_getcnf.txt |
327 | | | cp $sl_sedlocache/$sl_nmcnf.main.tmp $sl_sedlocache/$sl_nmcnf.main |
328 | 10 | simandl | if [ $scm_info -gt 1 ]; then echo "Main config downloaded and accepted" ; fi |
329 | 7 | simandl | else |
330 | 8 | simandl | if [ $scm_info -gt 1 ]; then echo "Main config not downloaded - cached config will be used" ; fi |
331 | | | echo -n "Main config not downloaded " > $sl_sedlocache/last_getcnf.txt |
332 | 7 | simandl | date >> $sl_sedlocache/last_getcnf.txt |
333 | | | fi |
334 | | | |
335 | 10 | simandl | # before generating a new cached config we store the old one for |
336 | | | # comparison with the new one |
337 | | | rm -f "$sl_sedlocache/$sl_nmcnf.old" |
338 | | | if [ -s $sl_sedlocache/$sl_nmcnf ] |
339 | | | then |
340 | | | cp $sl_sedlocache/$sl_nmcnf $sl_sedlocache/$sl_nmcnf.old |
341 | | | else |
342 | | | touch $sl_sedlocache/$sl_nmcnf.old |
343 | | | fi |
344 | | | |
345 | 7 | simandl | # preparing cached config from local and main |
346 | | | # the local config should be processed as the second to have |
347 | | | # higher priority for rules from local config |
348 | | | echo "# generated file" > $sl_sedlocache/$sl_nmcnf |
349 | | | for sl_file in `ls $sl_sedlocache/$sl_nmcnf.main ; ls $sl_sedlocnf` |
350 | | | do |
351 | | | cat $sl_file | grep "^mcnf" | $sl_trcmd ';' '#' | awk '{print $1"\t"$2}' >> $sl_sedlocache/$sl_nmcnf |
352 | | | cat $sl_file | grep "^igw" | $sl_trcmd ';' '#' | awk '{print $1"\t"$2"\t"$3}' >> $sl_sedlocache/$sl_nmcnf |
353 | | | cat $sl_file | grep "^ip" | $sl_trcmd ';' '#' | awk '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6}' >> $sl_sedlocache/$sl_nmcnf |
354 | | | done |
355 | 8 | simandl | |
356 | | | #local gateways taken from local config |
357 | | | cat $sl_sedlocnf | grep "^myigw" | $sl_trcmd ';' '#' | awk '{print $1"\t"$2"\t"$3}' >> $sl_sedlocache/$sl_nmcnf |
358 | | | |
359 | 7 | simandl | #cat $sl_sedlocache/$sl_nmcnf | sort | uniq > $sl_sedlocache/$sl_nmcnf.uniq |
360 | | | #mv $sl_sedlocache/$sl_nmcnf.uniq $sl_sedlocache/$sl_nmcnf |
361 | | | |
362 | 10 | simandl | sl_diffcfg=`diff $sl_sedlocache/$sl_nmcnf $sl_sedlocache/$sl_nmcnf.old | grep -c .` |
363 | | | if [ $sl_diffcfg -gt 0 ] |
364 | | | then |
365 | | | if [ $scm_info -gt 0 ]; then echo "New config is different than the old one" ; fi |
366 | | | else |
367 | | | if [ $scm_info -gt 0 ]; then echo "New config is the same as the old one" ; fi |
368 | | | fi |
369 | | | |
370 | 11 | simandl | # showing number of rules in config and system |
371 | 10 | simandl | sl_numru=`ip ru ls | grep -c lookup` |
372 | | | sl_numip=`grep -c ^ip $sl_sedlocache/$sl_nmcnf` |
373 | | | sl_numru=$(($sl_numru - 3 )) |
374 | | | if [ $sl_numip -gt $sl_numru ] |
375 | | | then |
376 | | | if [ $scm_info -gt 0 ]; then echo "We have less rules ($sl_numru) than new config has ips ($sl_numip)" ; fi |
377 | 11 | simandl | # sl_diffcfg="1" |
378 | 10 | simandl | else |
379 | | | if [ $scm_info -gt 0 ]; then echo "We have $sl_numru rules and $sl_numip ips" ; fi |
380 | | | fi |
381 | | | |
382 | 7 | simandl | } |
383 | 8 | simandl | |
384 | 7 | simandl | ###################################################################### |
385 | | | s_version() |
386 | | | { |
387 | | | echo sedlo $sl_version |
388 | | | } # s_version |
389 | 8 | simandl | |
390 | 7 | simandl | ###################################################################### |
391 | | | s_report() |
392 | | | { |
393 | 9 | simandl | echo Content-type: text/html |
394 | | | echo |
395 | | | echo "Sedlo na routeru `hostname`" |
396 | | | echo "<pre>" |
397 | 7 | simandl | echo "##### SEDLO #####" |
398 | | | echo "date : `date`" |
399 | | | echo "version : $sl_version" |
400 | | | echo "local_config : $sl_sedlocnf" |
401 | 9 | simandl | echo "main_config : <a href=\"$sl_murlcfg\">$sl_murlcfg</a>" |
402 | 7 | simandl | echo "last update : `cat $sl_sedlocache/last_getcnf.txt`" |
403 | | | echo "##### TABLES #####" |
404 | | | cat $sl_rttab |
405 | 9 | simandl | echo ; echo "##### DEFAULT ROUTES IN TABLES #####" |
406 | | | $sl_ipcmd ro ls ta all | $sl_grepcmd table | $sl_grepcmd -v local | $sl_trcmd " " "\t" |
407 | | | echo ; echo "##### RULES FOR IPS #####" |
408 | | | $sl_ipcmd ru ls | $sl_trcmd " " "\t" |
409 | | | echo "</pre>" |
410 | 7 | simandl | } # s_report |
411 | 8 | simandl | |
412 | 9 | simandl | |
413 | | | |
414 | 7 | simandl | ###################################################################### |
415 | | | s_help() |
416 | | | { |
417 | | | echo Pouziti: sedlo [param] |
418 | | | echo param: |
419 | | | echo -V vypise verzi |
420 | | | echo -help vypise napovedu |
421 | | | echo -v malo upovidany |
422 | | | echo -vv hodne upovidany |
423 | | | echo -nogetcfg zajisti ze se nedude znovu nacitat konfigurace a pouzije se predchozi z cache |
424 | | | echo -report vypise prehled pravidel a tabulek |
425 | | | echo -flru odstrani vsechny pravidla |
426 | 11 | simandl | echo -force bezpodminecne znovu obnovi vsechny pravidla |
427 | 7 | simandl | } # s_help |
428 | 8 | simandl | |
429 | 7 | simandl | ###################################################################### |
430 | | | ###################################################################### |
431 | | | |
432 | | | sl_unknown="" |
433 | | | scm_nogetcfg=0 |
434 | | | scm_flru=0 |
435 | | | scm_info=0 |
436 | 11 | simandl | scm_force=0 |
437 | | | sl_diffigw=0 |
438 | | | sl_difftbl=0 |
439 | 7 | simandl | |
440 | | | # parsing input parameters |
441 | | | while [ "a$1" != "a" ] |
442 | | | do |
443 | | | case $1 in |
444 | | | -V) |
445 | | | s_version |
446 | | | exit 0 |
447 | | | ;; |
448 | | | -h) |
449 | | | s_help |
450 | | | exit 0 |
451 | | | ;; |
452 | | | -report) |
453 | | | s_report |
454 | | | exit 0 |
455 | | | ;; |
456 | | | -flru) |
457 | | | scm_flru=1 |
458 | | | shift |
459 | | | ;; |
460 | 11 | simandl | -force) |
461 | | | scm_force=1 |
462 | | | shift |
463 | | | ;; |
464 | 7 | simandl | -help) |
465 | | | s_help |
466 | | | exit 0 |
467 | | | ;; |
468 | | | -nogetcfg) |
469 | | | scm_nogetcfg=1 |
470 | | | shift |
471 | | | ;; |
472 | | | -v) |
473 | | | scm_info=1 |
474 | | | shift |
475 | | | ;; |
476 | | | -vv) |
477 | | | scm_info=2 |
478 | | | shift |
479 | | | ;; |
480 | | | *) |
481 | | | sl_unknown="$sl_unknown$1 " |
482 | | | shift |
483 | | | esac |
484 | | | done |
485 | | | |
486 | | | # printing the list of bad parameters (if there are some) |
487 | | | if [ "a$sl_unknown" != "a" ] |
488 | | | then |
489 | | | echo "$slm_unknown $sl_unknown" |
490 | | | s_help |
491 | | | exit 0 |
492 | | | fi |
493 | | | |
494 | | | if [ $scm_flru -eq 1 ] |
495 | | | then |
496 | 16 | simandl | s_flruall |
497 | 7 | simandl | exit 0 |
498 | | | fi |
499 | | | |
500 | | | if [ $scm_nogetcfg -eq 0 ] |
501 | | | then |
502 | | | s_getcfg |
503 | | | fi |
504 | | | |
505 | | | s_mktables |
506 | | | s_filltables |
507 | 15 | simandl | #toto je pro ladici ucely |
508 | 11 | simandl | #echo $sl_difftbl |
509 | | | #echo $sl_diffcfg |
510 | | | #echo $sl_diffigw |
511 | | | #echo $scm_force |
512 | 13 | simandl | #exit 0 |
513 | 15 | simandl | |
514 | 11 | simandl | #flushing and filling rules is done only when |
515 | | | #new table is created |
516 | | | #config is changed |
517 | | | #some igw dissapears or appears |
518 | | | #-force command line parameter was used |
519 | | | if [ $sl_difftbl -gt 0 ] || [ $sl_diffcfg -gt 0 ] || [ $sl_diffigw -gt 0 ] || [ $scm_force -gt 0 ] |
520 | 10 | simandl | then |
521 | | | s_fillrules |
522 | | | fi |
523 | | | |
524 | 16 | simandl | |
525 | 7 | simandl | exit 0 |