diff options
-rwxr-xr-x | examples/var_service/fw/run | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/examples/var_service/fw/run b/examples/var_service/fw/run index 81c7f2e7c..871a70545 100755 --- a/examples/var_service/fw/run +++ b/examples/var_service/fw/run | |||
@@ -1,18 +1,20 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # (using bashism: arrays) | 2 | # (using bashism: arrays) |
3 | 3 | ||
4 | service="${PWD##*/}" | 4 | user="root" |
5 | rundir="/var/run/service/$service" | 5 | reset_all_netdevs=true |
6 | 6 | preferred_default_route_iface="if" | |
7 | user=root | 7 | extif="if" |
8 | extif=if | 8 | ext_open_tcp="22 80 88" # space-separated |
9 | ext_open_tcp="21 22 80" # space-separated | ||
10 | 9 | ||
11 | # Make ourself one-shot | 10 | # Make ourself one-shot |
12 | sv o . | 11 | sv o . |
13 | # Debug | 12 | # Debug |
14 | #date '+%Y-%m-%d %H:%M:%S' >>"$0.log" | 13 | #date '+%Y-%m-%d %H:%M:%S' >>"$0.log" |
15 | 14 | ||
15 | service=`basename $PWD` | ||
16 | rundir="/var/run/service/$service" | ||
17 | |||
16 | ### filter This is the default table (if no -t option is passed). It contains | 18 | ### filter This is the default table (if no -t option is passed). It contains |
17 | ### the built-in chains INPUT (for packets coming into the box itself), | 19 | ### the built-in chains INPUT (for packets coming into the box itself), |
18 | ### FORWARD (for packets being routed through the box), and OUTPUT (for | 20 | ### FORWARD (for packets being routed through the box), and OUTPUT (for |
@@ -70,7 +72,6 @@ ln -s "$rundir" rundir | |||
70 | # Timestamping | 72 | # Timestamping |
71 | date '+%Y-%m-%d %H:%M:%S' | 73 | date '+%Y-%m-%d %H:%M:%S' |
72 | 74 | ||
73 | |||
74 | echo; echo "* Reading IP config" | 75 | echo; echo "* Reading IP config" |
75 | cfg=-1 | 76 | cfg=-1 |
76 | # static cfg dhcp,zeroconf etc | 77 | # static cfg dhcp,zeroconf etc |
@@ -86,11 +87,19 @@ echo; echo "* Configuring hardware" | |||
86 | #doit ethtool -K if rx off tx off sg off tso off | 87 | #doit ethtool -K if rx off tx off sg off tso off |
87 | 88 | ||
88 | echo; echo "* Resetting address and routing info" | 89 | echo; echo "* Resetting address and routing info" |
89 | doit ip a f dev lo | 90 | if $reset_all_netdevs; then |
90 | i=0; while test "${if[$i]}"; do | 91 | devs=`sed -n 's/ //g;s/:.*$//p' </proc/net/dev` |
91 | doit ip a f dev "${if[$i]}" | 92 | for if in $devs; do |
92 | doit ip r f dev "${if[$i]}" root 0/0 | 93 | doit ip a f dev "$if" |
93 | let i++; done | 94 | doit ip r f dev "$if" root 0/0 |
95 | done | ||
96 | else | ||
97 | doit ip a f dev lo | ||
98 | i=0; while test "${if[$i]}"; do | ||
99 | doit ip a f dev "${if[$i]}" | ||
100 | doit ip r f dev "${if[$i]}" root 0/0 | ||
101 | let i++; done | ||
102 | fi | ||
94 | 103 | ||
95 | echo; echo "* Configuring addresses" | 104 | echo; echo "* Configuring addresses" |
96 | doit ip a a dev lo 127.0.0.1/8 scope host | 105 | doit ip a a dev lo 127.0.0.1/8 scope host |
@@ -103,7 +112,22 @@ i=0; while test "${if[$i]}"; do | |||
103 | let i++; done | 112 | let i++; done |
104 | 113 | ||
105 | echo; echo "* Configuring routes" | 114 | echo; echo "* Configuring routes" |
115 | # If several ifaces are configured via DHCP, they often both have 0/0 route. | ||
116 | # They have no way of knowing that this route is offered on more than one iface. | ||
117 | # Often, it's desirable to prefer one iface: say, wired eth over wireless. | ||
118 | # if preferred_default_route_iface is not set, 0/0 route will be assigned randomly. | ||
119 | if test "$preferred_default_route_iface"; then | ||
120 | i=0; while test "${if[$i]}"; do | ||
121 | if test "${if[$i]}" = "$preferred_default_route_iface" \ | ||
122 | && test "${net[$i]}" = "0/0" \ | ||
123 | && test "${gw[$i]}"; then | ||
124 | echo "+ default route through ${if[$i]}, ${gw[$i]}:" | ||
125 | doit ip r a "${net[$i]}" via "${gw[$i]}" | ||
126 | fi | ||
127 | let i++; done | ||
128 | fi | ||
106 | i=0; while test "${if[$i]}"; do | 129 | i=0; while test "${if[$i]}"; do |
130 | #echo $i:"${if[$i]}" | ||
107 | if test "${net[$i]}" && test "${gw[$i]}"; then | 131 | if test "${net[$i]}" && test "${gw[$i]}"; then |
108 | doit ip r a "${net[$i]}" via "${gw[$i]}" | 132 | doit ip r a "${net[$i]}" via "${gw[$i]}" |
109 | fi | 133 | fi |