Debian Codegraph @

src/res/configlets/dd-wrt-nvram/routing_functions

raw
1 ## -*- mode: shell-script; -*-
2 ##
3 ## To be able to make changes to the part of configuration created
4 ## from this configlet you need to copy this file to the directory
5 ## fwbuilder/configlets/linux24/ in your home directory and modify it.
6 ## Double "##" comments are removed during processing but single "#"
7 ## comments are be retained and appear in the generated script. Empty
8 ## lines are removed as well.
9 ##
10 ## Configlets support simple macro language with these constructs:
11 ## {{$var}} is variable expansion
12 ## {{if var}} is conditional operator.
13 ##
14
15 ## The recent versions of DD-WRT V24 preSP2 Build 13064 and newer are
16 ## missing modprobe and mktemp. This configlet does not use mktemp to
17 ## create temporary file
18
19 # ============== ROUTING RULES ==============
20
21 TMPDIRNAME="/tmp/.fwbuilder.tempdir.$$"
22 TMPFILENAME="$TMPDIRNAME/.fwbuilder.out"
23 (umask 077 && mkdir $TMPDIRNAME) || exit 1
24
25 #
26 # This function stops stdout redirection
27 # and sends previously saved output to terminal
28 restore_script_output()
29 {
30 exec 1>&3 2>&1
31 cat $TMPFILENAME
32 rm -rf $TMPDIRNAME
33 }
34
35 # if any routing rule fails we do our best to prevent freezing the firewall
36 route_command_error()
37 {
38 echo "Error: Routing rule $1 couldn't be activated"
39 echo "Recovering previous routing configuration..."
40 # delete current routing rules
41 $IP route show | while read route ; do $IP route del $route ; done
42 # restore old routing rules
43 (IFS="
44 "; for route in $oldRoutes; do (IFS=' '; $IP route add $route); done)
45 echo "...done"
46 restore_script_output
47 epilog_commands
48 exit 1
49 }
50
51 # redirect output to prevent ssh session from stalling
52 exec 3>&1
53 exec 1> $TMPFILENAME
54 exec 2>&1
55
56 # store previous routing configuration (sort: 'via' GW has to be
57 # inserted after device routes)
58 oldRoutes=$($IP route show | sort -k 2)
59
60 echo "Deleting routing rules previously set by user space processes..."
61 $IP route show | grep -v {{$proto_filter}} | \
62 while read route ; do $IP route del $route ; done
63
64 echo "Activating non-ecmp routing rules..."
65