|
@@ -69,26 +69,26 @@ mwan3_set_iface_iptables()
|
69
|
69
|
{
|
70
|
70
|
local local_net local_nets
|
71
|
71
|
|
72
|
|
- local_nets=$($IP route list dev $DEVICE scope link | awk '{print $1}' | egrep '[0-9]{1,3}(\.[0-9]{1,3}){3}')
|
73
|
|
-
|
74
|
72
|
if ! $IPT -S mwan3_iface_$INTERFACE &> /dev/null; then
|
75
|
73
|
$IPT -N mwan3_iface_$INTERFACE
|
76
|
74
|
fi
|
77
|
75
|
|
78
|
76
|
$IPT -F mwan3_iface_$INTERFACE
|
79
|
|
- $IPT -D mwan3_ifaces -i $DEVICE -m mark --mark 0x0/0xff00 -j mwan3_iface_$INTERFACE &> /dev/null
|
|
77
|
+ $IPT -D mwan3_ifaces -m mark --mark 0x0/0xff00 -j mwan3_iface_$INTERFACE &> /dev/null
|
80
|
78
|
|
81
|
79
|
if [ $ACTION == "ifup" ]; then
|
|
80
|
+ local_nets=$($IP route list dev $DEVICE scope link | awk '{print $1}' | egrep '[0-9]{1,3}(\.[0-9]{1,3}){3}')
|
|
81
|
+
|
82
|
82
|
if [ -n "$local_nets" ]; then
|
83
|
83
|
for local_net in $local_nets ; do
|
84
|
84
|
if [ $ACTION == "ifup" ]; then
|
85
|
|
- $IPT -I mwan3_iface_$INTERFACE -s $local_net -m mark --mark 0x0/0xff00 -m comment --comment "default" -j MARK --set-xmark 0xff00/0xff00
|
|
85
|
+ $IPT -I mwan3_iface_$INTERFACE -i $DEVICE -s $local_net -m mark --mark 0x0/0xff00 -m comment --comment "default" -j MARK --set-xmark 0xff00/0xff00
|
86
|
86
|
fi
|
87
|
87
|
done
|
88
|
88
|
fi
|
89
|
89
|
|
90
|
|
- $IPT -A mwan3_iface_$INTERFACE -m mark --mark 0x0/0xff00 -m comment --comment "$INTERFACE" -j MARK --set-xmark $(($iface_id*256))/0xff00
|
91
|
|
- $IPT -A mwan3_ifaces -i $DEVICE -m mark --mark 0x0/0xff00 -j mwan3_iface_$INTERFACE
|
|
90
|
+ $IPT -A mwan3_iface_$INTERFACE -i $DEVICE -m mark --mark 0x0/0xff00 -m comment --comment "$INTERFACE" -j MARK --set-xmark $(($iface_id*256))/0xff00
|
|
91
|
+ $IPT -A mwan3_ifaces -m mark --mark 0x0/0xff00 -j mwan3_iface_$INTERFACE
|
92
|
92
|
fi
|
93
|
93
|
|
94
|
94
|
if [ $ACTION == "ifdown" ]; then
|
|
@@ -112,13 +112,18 @@ mwan3_set_iface_rules()
|
112
|
112
|
$IP rule del pref $(($iface_id+2000))
|
113
|
113
|
done
|
114
|
114
|
|
|
115
|
+ while [ -n "$($IP rule list | awk '$1 == "2253:"')" ]; do
|
|
116
|
+ $IP rule del pref 2253
|
|
117
|
+ done
|
|
118
|
+
|
115
|
119
|
while [ -n "$($IP rule list | awk '$1 == "2254:"')" ]; do
|
116
|
120
|
$IP rule del pref 2254
|
117
|
121
|
done
|
118
|
122
|
|
119
|
123
|
[ $ACTION == "ifup" ] && $IP rule add pref $(($iface_id+1000)) iif $DEVICE lookup main
|
120
|
124
|
[ $ACTION == "ifup" ] && $IP rule add pref $(($iface_id+2000)) fwmark $(($iface_id*256))/0xff00 lookup $iface_id
|
121
|
|
- $IP rule add pref 2254 fwmark 0xfe00/0xff00 unreachable
|
|
125
|
+ $IP rule add pref 2253 fwmark 0xfd00/0xff00 blackhole
|
|
126
|
+ $IP rule add pref 2254 fwmark 0xfe00/0xff00 unreachable
|
122
|
127
|
}
|
123
|
128
|
|
124
|
129
|
mwan3_track()
|
|
@@ -205,10 +210,12 @@ mwan3_set_policy()
|
205
|
210
|
|
206
|
211
|
mwan3_set_policies_iptables()
|
207
|
212
|
{
|
208
|
|
- local lowest_metric policy total_weight
|
|
213
|
+ local last_resort lowest_metric policy total_weight
|
209
|
214
|
|
210
|
215
|
policy=$1
|
211
|
216
|
|
|
217
|
+ config_get last_resort $1 last_resort unreachable
|
|
218
|
+
|
212
|
219
|
if [ "$policy" != $(echo "$policy" | cut -c1-15) ]; then
|
213
|
220
|
$LOG warn "Policy $policy exceeds max of 15 chars. Not setting policy" && return 0
|
214
|
221
|
fi
|
|
@@ -218,7 +225,18 @@ mwan3_set_policies_iptables()
|
218
|
225
|
fi
|
219
|
226
|
|
220
|
227
|
$IPT -F mwan3_policy_$policy
|
221
|
|
- $IPT -A mwan3_policy_$policy -m mark --mark 0x0/0xff00 -m comment --comment "unreachable" -j MARK --set-xmark 0xfe00/0xff00
|
|
228
|
+
|
|
229
|
+ case "$last_resort" in
|
|
230
|
+ blackhole)
|
|
231
|
+ $IPT -A mwan3_policy_$policy -m mark --mark 0x0/0xff00 -m comment --comment "blackhole" -j MARK --set-xmark 0xfd00/0xff00
|
|
232
|
+ ;;
|
|
233
|
+ default)
|
|
234
|
+ $IPT -A mwan3_policy_$policy -m mark --mark 0x0/0xff00 -m comment --comment "default" -j MARK --set-xmark 0xff00/0xff00
|
|
235
|
+ ;;
|
|
236
|
+ *)
|
|
237
|
+ $IPT -A mwan3_policy_$policy -m mark --mark 0x0/0xff00 -m comment --comment "unreachable" -j MARK --set-xmark 0xfe00/0xff00
|
|
238
|
+ ;;
|
|
239
|
+ esac
|
222
|
240
|
|
223
|
241
|
lowest_metric=256
|
224
|
242
|
total_weight=0
|
|
@@ -242,6 +260,8 @@ mwan3_set_user_rules_iptables()
|
242
|
260
|
use_policy="MARK --set-xmark 0xff00/0xff00"
|
243
|
261
|
elif [ "$use_policy" == "unreachable" ]; then
|
244
|
262
|
use_policy="MARK --set-xmark 0xfe00/0xff00"
|
|
263
|
+ elif [ "$use_policy" == "blackhole" ]; then
|
|
264
|
+ use_policy="MARK --set-xmark 0xfd00/0xff00"
|
245
|
265
|
else
|
246
|
266
|
use_policy="mwan3_policy_$use_policy"
|
247
|
267
|
fi
|
|
@@ -279,7 +299,7 @@ mwan3_ifupdown()
|
279
|
299
|
sleep 1
|
280
|
300
|
let counter++
|
281
|
301
|
if [ "$counter" -ge 10 ]; then
|
282
|
|
- $LOG warn "Could not find gateway for interface $INTERFACE ($DEVICE)" && return 0
|
|
302
|
+ $LOG warn "Could not find gateway for interface $INTERFACE (${DEVICE:-unknown})" && return 0
|
283
|
303
|
fi
|
284
|
304
|
done
|
285
|
305
|
|
|
@@ -291,11 +311,11 @@ mwan3_ifupdown()
|
291
|
311
|
sleep 1
|
292
|
312
|
let counter++
|
293
|
313
|
if [ "$counter" -ge 60 ]; then
|
294
|
|
- $LOG warn "Timeout waiting for older hotplug processes to finish. $ACTION interface $INTERFACE ($DEVICE) aborted" && return 0
|
|
314
|
+ $LOG warn "Timeout waiting for older hotplug processes to finish. $ACTION interface $INTERFACE (${DEVICE:-unknown}) aborted" && return 0
|
295
|
315
|
fi
|
296
|
316
|
done
|
297
|
317
|
|
298
|
|
- $LOG notice "$ACTION interface $INTERFACE ($DEVICE)"
|
|
318
|
+ $LOG notice "$ACTION interface $INTERFACE (${DEVICE:-unknown})"
|
299
|
319
|
|
300
|
320
|
mwan3_set_general_iptables
|
301
|
321
|
mwan3_set_iface_iptables
|
|
@@ -308,10 +328,13 @@ mwan3_ifupdown()
|
308
|
328
|
config_foreach mwan3_set_user_rules_iptables rule
|
309
|
329
|
}
|
310
|
330
|
|
311
|
|
-[ -n "$DEVICE" ] || exit 0
|
|
331
|
+local IP IPT LOG
|
|
332
|
+
|
312
|
333
|
[ -n "$INTERFACE" ] || exit 0
|
313
|
334
|
|
314
|
|
-local IP IPT LOG
|
|
335
|
+if [ $ACTION == "ifup" ]; then
|
|
336
|
+ [ -n "$DEVICE" ] || exit 0
|
|
337
|
+fi
|
315
|
338
|
|
316
|
339
|
IP="/usr/sbin/ip -4"
|
317
|
340
|
IPT="/usr/sbin/iptables -t mangle -w"
|