aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xexamples/var_service/fw/run48
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
4service="${PWD##*/}" 4user="root"
5rundir="/var/run/service/$service" 5reset_all_netdevs=true
6 6preferred_default_route_iface="if"
7user=root 7extif="if"
8extif=if 8ext_open_tcp="22 80 88" # space-separated
9ext_open_tcp="21 22 80" # space-separated
10 9
11# Make ourself one-shot 10# Make ourself one-shot
12sv o . 11sv 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
15service=`basename $PWD`
16rundir="/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
71date '+%Y-%m-%d %H:%M:%S' 73date '+%Y-%m-%d %H:%M:%S'
72 74
73
74echo; echo "* Reading IP config" 75echo; echo "* Reading IP config"
75cfg=-1 76cfg=-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
88echo; echo "* Resetting address and routing info" 89echo; echo "* Resetting address and routing info"
89doit ip a f dev lo 90if $reset_all_netdevs; then
90i=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"
93let i++; done 94 doit ip r f dev "$if" root 0/0
95 done
96else
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
102fi
94 103
95echo; echo "* Configuring addresses" 104echo; echo "* Configuring addresses"
96doit ip a a dev lo 127.0.0.1/8 scope host 105doit ip a a dev lo 127.0.0.1/8 scope host
@@ -103,7 +112,22 @@ i=0; while test "${if[$i]}"; do
103let i++; done 112let i++; done
104 113
105echo; echo "* Configuring routes" 114echo; 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.
119if 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
128fi
106i=0; while test "${if[$i]}"; do 129i=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