|
@@ -0,0 +1,803 @@
|
|
1
|
+#!/bin/sh
|
|
2
|
+
|
|
3
|
+local IP4 IP6 IPS IPT4 IPT6 LOG
|
|
4
|
+
|
|
5
|
+IP4="/usr/bin/ip -4"
|
|
6
|
+IP6="/usr/bin/ip -6"
|
|
7
|
+IPS="/usr/sbin/ipset"
|
|
8
|
+IPT4="/usr/sbin/iptables -t mangle -w"
|
|
9
|
+IPT6="/usr/sbin/ip6tables -t mangle -w"
|
|
10
|
+LOG="/usr/bin/logger -t mwan3 -p"
|
|
11
|
+
|
|
12
|
+mwan3_get_iface_id()
|
|
13
|
+{
|
|
14
|
+ local _tmp _iface _iface_count
|
|
15
|
+
|
|
16
|
+ _iface="$2"
|
|
17
|
+
|
|
18
|
+ mwan3_get_id()
|
|
19
|
+ {
|
|
20
|
+ let _iface_count++
|
|
21
|
+ [ "$1" == "$_iface" ] && _tmp=$_iface_count
|
|
22
|
+ }
|
|
23
|
+ config_foreach mwan3_get_id interface
|
|
24
|
+ export "$1=$_tmp"
|
|
25
|
+}
|
|
26
|
+
|
|
27
|
+mwan3_set_connected_iptables()
|
|
28
|
+{
|
|
29
|
+ local connected_network_v4 connected_network_v6
|
|
30
|
+
|
|
31
|
+ $IPS -! create mwan3_connected_v4 hash:net
|
|
32
|
+ $IPS create mwan3_connected_v4_temp hash:net
|
|
33
|
+
|
|
34
|
+ for connected_network_v4 in $($IP4 route | awk '{print $1}' | egrep '[0-9]{1,3}(\.[0-9]{1,3}){3}'); do
|
|
35
|
+ $IPS -! add mwan3_connected_v4_temp $connected_network_v4
|
|
36
|
+ done
|
|
37
|
+
|
|
38
|
+ for connected_network_v4 in $($IP4 route list table 0 | awk '{print $2}' | egrep '[0-9]{1,3}(\.[0-9]{1,3}){3}'); do
|
|
39
|
+ $IPS -! add mwan3_connected_v4_temp $connected_network_v4
|
|
40
|
+ done
|
|
41
|
+
|
|
42
|
+ $IPS add mwan3_connected_v4_temp 224.0.0.0/3
|
|
43
|
+
|
|
44
|
+ $IPS swap mwan3_connected_v4_temp mwan3_connected_v4
|
|
45
|
+ $IPS destroy mwan3_connected_v4_temp
|
|
46
|
+
|
|
47
|
+ $IPS -! create mwan3_connected_v6 hash:net family inet6
|
|
48
|
+ $IPS create mwan3_connected_v6_temp hash:net family inet6
|
|
49
|
+
|
|
50
|
+ for connected_network_v6 in $($IP6 route | awk '{print $1}' | egrep '([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])'); do
|
|
51
|
+ $IPS -! add mwan3_connected_v6_temp $connected_network_v6
|
|
52
|
+ done
|
|
53
|
+
|
|
54
|
+ $IPS swap mwan3_connected_v6_temp mwan3_connected_v6
|
|
55
|
+ $IPS destroy mwan3_connected_v6_temp
|
|
56
|
+
|
|
57
|
+ $IPS -! create mwan3_connected list:set
|
|
58
|
+ $IPS -! add mwan3_connected mwan3_connected_v4
|
|
59
|
+ $IPS -! add mwan3_connected mwan3_connected_v6
|
|
60
|
+}
|
|
61
|
+
|
|
62
|
+mwan3_set_general_rules()
|
|
63
|
+{
|
|
64
|
+ local IP
|
|
65
|
+
|
|
66
|
+ for IP in "$IP4" "$IP6"; do
|
|
67
|
+
|
|
68
|
+ if [ -z "$($IP rule list | awk '$1 == "2253:"')" ]; then
|
|
69
|
+ $IP rule add pref 2253 fwmark 0xfd00/0xff00 blackhole
|
|
70
|
+ fi
|
|
71
|
+
|
|
72
|
+ if [ -z "$($IP rule list | awk '$1 == "2254:"')" ]; then
|
|
73
|
+ $IP rule add pref 2254 fwmark 0xfe00/0xff00 unreachable
|
|
74
|
+ fi
|
|
75
|
+ done
|
|
76
|
+}
|
|
77
|
+
|
|
78
|
+mwan3_set_general_iptables()
|
|
79
|
+{
|
|
80
|
+ local IPT
|
|
81
|
+
|
|
82
|
+ for IPT in "$IPT4" "$IPT6"; do
|
|
83
|
+
|
|
84
|
+ if ! $IPT -S mwan3_ifaces_in &> /dev/null; then
|
|
85
|
+ $IPT -N mwan3_ifaces_in
|
|
86
|
+ fi
|
|
87
|
+
|
|
88
|
+ if ! $IPT -S mwan3_ifaces_out &> /dev/null; then
|
|
89
|
+ $IPT -N mwan3_ifaces_out
|
|
90
|
+ fi
|
|
91
|
+
|
|
92
|
+ if ! $IPT -S mwan3_connected &> /dev/null; then
|
|
93
|
+ $IPT -N mwan3_connected
|
|
94
|
+ $IPS -! create mwan3_connected list:set
|
|
95
|
+ $IPT -A mwan3_connected -m set --match-set mwan3_connected dst -j MARK --set-xmark 0xff00/0xff00
|
|
96
|
+ fi
|
|
97
|
+
|
|
98
|
+ if ! $IPT -S mwan3_rules &> /dev/null; then
|
|
99
|
+ $IPT -N mwan3_rules
|
|
100
|
+ fi
|
|
101
|
+
|
|
102
|
+ if ! $IPT -S mwan3_hook &> /dev/null; then
|
|
103
|
+ $IPT -N mwan3_hook
|
|
104
|
+ $IPT -A mwan3_hook -j CONNMARK --restore-mark --nfmask 0xff00 --ctmask 0xff00
|
|
105
|
+ $IPT -A mwan3_hook -m mark --mark 0x0/0xff00 -j mwan3_ifaces_in
|
|
106
|
+ $IPT -A mwan3_hook -m mark --mark 0x0/0xff00 -j mwan3_ifaces_out
|
|
107
|
+ $IPT -A mwan3_hook -m mark --mark 0x0/0xff00 -j mwan3_connected
|
|
108
|
+ $IPT -A mwan3_hook -m mark --mark 0x0/0xff00 -j mwan3_rules
|
|
109
|
+ $IPT -A mwan3_hook -j CONNMARK --save-mark --nfmask 0xff00 --ctmask 0xff00
|
|
110
|
+ $IPT -A mwan3_hook -m mark ! --mark 0xff00/0xff00 -j mwan3_connected
|
|
111
|
+ fi
|
|
112
|
+
|
|
113
|
+ if ! $IPT -S PREROUTING | grep mwan3_hook &> /dev/null; then
|
|
114
|
+ $IPT -A PREROUTING -j mwan3_hook
|
|
115
|
+ fi
|
|
116
|
+
|
|
117
|
+ if ! $IPT -S OUTPUT | grep mwan3_hook &> /dev/null; then
|
|
118
|
+ $IPT -A OUTPUT -j mwan3_hook
|
|
119
|
+ fi
|
|
120
|
+ done
|
|
121
|
+}
|
|
122
|
+
|
|
123
|
+mwan3_create_iface_iptables()
|
|
124
|
+{
|
|
125
|
+ local id family src_ip src_ipv6
|
|
126
|
+
|
|
127
|
+ config_get family $1 family ipv4
|
|
128
|
+ mwan3_get_iface_id id $1
|
|
129
|
+
|
|
130
|
+ [ -n "$id" ] || return 0
|
|
131
|
+
|
|
132
|
+ if [ "$family" == "ipv4" ]; then
|
|
133
|
+
|
|
134
|
+ network_get_ipaddr src_ip $1
|
|
135
|
+
|
|
136
|
+ $IPS -! create mwan3_connected list:set
|
|
137
|
+
|
|
138
|
+ if ! $IPT4 -S mwan3_ifaces_in &> /dev/null; then
|
|
139
|
+ $IPT4 -N mwan3_ifaces_in
|
|
140
|
+ fi
|
|
141
|
+
|
|
142
|
+ if ! $IPT4 -S mwan3_ifaces_out &> /dev/null; then
|
|
143
|
+ $IPT4 -N mwan3_ifaces_out
|
|
144
|
+ fi
|
|
145
|
+
|
|
146
|
+ if ! $IPT4 -S mwan3_iface_in_$1 &> /dev/null; then
|
|
147
|
+ $IPT4 -N mwan3_iface_in_$1
|
|
148
|
+ fi
|
|
149
|
+
|
|
150
|
+ if ! $IPT4 -S mwan3_iface_out_$1 &> /dev/null; then
|
|
151
|
+ $IPT4 -N mwan3_iface_out_$1
|
|
152
|
+ fi
|
|
153
|
+
|
|
154
|
+ $IPT4 -F mwan3_iface_in_$1
|
|
155
|
+ $IPT4 -A mwan3_iface_in_$1 -i $2 -m set --match-set mwan3_connected src -m mark --mark 0x0/0xff00 -m comment --comment "default" -j MARK --set-xmark 0xff00/0xff00
|
|
156
|
+ $IPT4 -A mwan3_iface_in_$1 -i $2 -m mark --mark 0x0/0xff00 -m comment --comment "$1" -j MARK --set-xmark $(($id*256))/0xff00
|
|
157
|
+
|
|
158
|
+ $IPT4 -D mwan3_ifaces_in -m mark --mark 0x0/0xff00 -j mwan3_iface_in_$1 &> /dev/null
|
|
159
|
+ $IPT4 -A mwan3_ifaces_in -m mark --mark 0x0/0xff00 -j mwan3_iface_in_$1
|
|
160
|
+
|
|
161
|
+ $IPT4 -F mwan3_iface_out_$1
|
|
162
|
+ $IPT4 -A mwan3_iface_out_$1 -s $src_ip -m mark --mark 0x0/0xff00 -m comment --comment "$1" -j MARK --set-xmark $(($id*256))/0xff00
|
|
163
|
+
|
|
164
|
+ $IPT4 -D mwan3_ifaces_out -m mark --mark 0x0/0xff00 -j mwan3_iface_out_$1 &> /dev/null
|
|
165
|
+ $IPT4 -A mwan3_ifaces_out -m mark --mark 0x0/0xff00 -j mwan3_iface_out_$1
|
|
166
|
+ fi
|
|
167
|
+
|
|
168
|
+ if [ "$family" == "ipv6" ]; then
|
|
169
|
+
|
|
170
|
+ network_get_ipaddr6 src_ipv6 $1
|
|
171
|
+
|
|
172
|
+ $IPS -! create mwan3_connected_v6 hash:net family inet6
|
|
173
|
+
|
|
174
|
+ if ! $IPT6 -S mwan3_ifaces_in &> /dev/null; then
|
|
175
|
+ $IPT6 -N mwan3_ifaces_in
|
|
176
|
+ fi
|
|
177
|
+
|
|
178
|
+ if ! $IPT6 -S mwan3_ifaces_out &> /dev/null; then
|
|
179
|
+ $IPT6 -N mwan3_ifaces_out
|
|
180
|
+ fi
|
|
181
|
+
|
|
182
|
+ if ! $IPT6 -S mwan3_iface_in_$1 &> /dev/null; then
|
|
183
|
+ $IPT6 -N mwan3_iface_in_$1
|
|
184
|
+ fi
|
|
185
|
+
|
|
186
|
+ if ! $IPT6 -S mwan3_iface_out_$1 &> /dev/null; then
|
|
187
|
+ $IPT6 -N mwan3_iface_out_$1
|
|
188
|
+ fi
|
|
189
|
+
|
|
190
|
+ $IPT6 -F mwan3_iface_in_$1
|
|
191
|
+ $IPT6 -A mwan3_iface_in_$1 -i $2 -m set --match-set mwan3_connected_v6 src -m mark --mark 0x0/0xff00 -m comment --comment "default" -j MARK --set-xmark 0xff00/0xff00
|
|
192
|
+ $IPT6 -A mwan3_iface_in_$1 -i $2 -m mark --mark 0x0/0xff00 -m comment --comment "$1" -j MARK --set-xmark $(($id*256))/0xff00
|
|
193
|
+
|
|
194
|
+ $IPT6 -D mwan3_ifaces_in -m mark --mark 0x0/0xff00 -j mwan3_iface_in_$1 &> /dev/null
|
|
195
|
+ $IPT6 -A mwan3_ifaces_in -m mark --mark 0x0/0xff00 -j mwan3_iface_in_$1
|
|
196
|
+
|
|
197
|
+ $IPT6 -F mwan3_iface_out_$1
|
|
198
|
+ $IPT6 -A mwan3_iface_out_$1 -s $src_ipv6 -m mark --mark 0x0/0xff00 -m comment --comment "$1" -j MARK --set-xmark $(($id*256))/0xff00
|
|
199
|
+
|
|
200
|
+ $IPT6 -D mwan3_ifaces_out -m mark --mark 0x0/0xff00 -j mwan3_iface_out_$1 &> /dev/null
|
|
201
|
+ $IPT6 -A mwan3_ifaces_out -m mark --mark 0x0/0xff00 -j mwan3_iface_out_$1
|
|
202
|
+ fi
|
|
203
|
+}
|
|
204
|
+
|
|
205
|
+mwan3_delete_iface_iptables()
|
|
206
|
+{
|
|
207
|
+ config_get family $1 family ipv4
|
|
208
|
+
|
|
209
|
+ if [ "$family" == "ipv4" ]; then
|
|
210
|
+
|
|
211
|
+ $IPT4 -D mwan3_ifaces_in -m mark --mark 0x0/0xff00 -j mwan3_iface_in_$1 &> /dev/null
|
|
212
|
+ $IPT4 -F mwan3_iface_in_$1 &> /dev/null
|
|
213
|
+ $IPT4 -X mwan3_iface_in_$1 &> /dev/null
|
|
214
|
+
|
|
215
|
+ $IPT4 -D mwan3_ifaces_out -m mark --mark 0x0/0xff00 -j mwan3_iface_out_$1 &> /dev/null
|
|
216
|
+ $IPT4 -F mwan3_iface_out_$1 &> /dev/null
|
|
217
|
+ $IPT4 -X mwan3_iface_out_$1 &> /dev/null
|
|
218
|
+ fi
|
|
219
|
+
|
|
220
|
+ if [ "$family" == "ipv6" ]; then
|
|
221
|
+
|
|
222
|
+ $IPT6 -D mwan3_ifaces_in -m mark --mark 0x0/0xff00 -j mwan3_iface_in_$1 &> /dev/null
|
|
223
|
+ $IPT6 -F mwan3_iface_in_$1 &> /dev/null
|
|
224
|
+ $IPT6 -X mwan3_iface_in_$1 &> /dev/null
|
|
225
|
+
|
|
226
|
+ $IPT6 -D mwan3_ifaces_out -m mark --mark 0x0/0xff00 -j mwan3_iface_out_$1 &> /dev/null
|
|
227
|
+ $IPT6 -F mwan3_iface_out_$1 &> /dev/null
|
|
228
|
+ $IPT6 -X mwan3_iface_out_$1 &> /dev/null
|
|
229
|
+ fi
|
|
230
|
+}
|
|
231
|
+
|
|
232
|
+mwan3_create_iface_route()
|
|
233
|
+{
|
|
234
|
+ local id route_args
|
|
235
|
+
|
|
236
|
+ config_get family $1 family ipv4
|
|
237
|
+ mwan3_get_iface_id id $1
|
|
238
|
+
|
|
239
|
+ [ -n "$id" ] || return 0
|
|
240
|
+
|
|
241
|
+ if [ "$family" == "ipv4" ]; then
|
|
242
|
+
|
|
243
|
+ network_get_gateway route_args $1
|
|
244
|
+ route_args="via $route_args dev $2"
|
|
245
|
+
|
|
246
|
+ $IP4 route flush table $id
|
|
247
|
+ $IP4 route add table $id default $route_args
|
|
248
|
+ fi
|
|
249
|
+
|
|
250
|
+ if [ "$family" == "ipv6" ]; then
|
|
251
|
+
|
|
252
|
+ network_get_gateway6 route_args $1
|
|
253
|
+ route_args="via $route_args dev $2"
|
|
254
|
+
|
|
255
|
+ $IP6 route flush table $id
|
|
256
|
+ $IP6 route add table $id default $route_args
|
|
257
|
+ fi
|
|
258
|
+}
|
|
259
|
+
|
|
260
|
+mwan3_delete_iface_route()
|
|
261
|
+{
|
|
262
|
+ local id
|
|
263
|
+
|
|
264
|
+ config_get family $1 family ipv4
|
|
265
|
+ mwan3_get_iface_id id $1
|
|
266
|
+
|
|
267
|
+ [ -n "$id" ] || return 0
|
|
268
|
+
|
|
269
|
+ if [ "$family" == "ipv4" ]; then
|
|
270
|
+ $IP4 route flush table $id
|
|
271
|
+ fi
|
|
272
|
+
|
|
273
|
+ if [ "$family" == "ipv6" ]; then
|
|
274
|
+ $IP6 route flush table $id
|
|
275
|
+ fi
|
|
276
|
+}
|
|
277
|
+
|
|
278
|
+mwan3_create_iface_rules()
|
|
279
|
+{
|
|
280
|
+ local id family
|
|
281
|
+
|
|
282
|
+ config_get family $1 family ipv4
|
|
283
|
+ mwan3_get_iface_id id $1
|
|
284
|
+
|
|
285
|
+ [ -n "$id" ] || return 0
|
|
286
|
+
|
|
287
|
+ if [ "$family" == "ipv4" ]; then
|
|
288
|
+
|
|
289
|
+ while [ -n "$($IP4 rule list | awk '$1 == "'$(($id+1000)):'"')" ]; do
|
|
290
|
+ $IP4 rule del pref $(($id+1000))
|
|
291
|
+ done
|
|
292
|
+
|
|
293
|
+ while [ -n "$($IP4 rule list | awk '$1 == "'$(($id+2000)):'"')" ]; do
|
|
294
|
+ $IP4 rule del pref $(($id+2000))
|
|
295
|
+ done
|
|
296
|
+
|
|
297
|
+ $IP4 rule add pref $(($id+1000)) iif $2 lookup main
|
|
298
|
+ $IP4 rule add pref $(($id+2000)) fwmark $(($id*256))/0xff00 lookup $id
|
|
299
|
+ fi
|
|
300
|
+
|
|
301
|
+ if [ "$family" == "ipv6" ]; then
|
|
302
|
+
|
|
303
|
+ while [ -n "$($IP6 rule list | awk '$1 == "'$(($id+1000)):'"')" ]; do
|
|
304
|
+ $IP6 rule del pref $(($id+1000))
|
|
305
|
+ done
|
|
306
|
+
|
|
307
|
+ while [ -n "$($IP6 rule list | awk '$1 == "'$(($id+2000)):'"')" ]; do
|
|
308
|
+ $IP6 rule del pref $(($id+2000))
|
|
309
|
+ done
|
|
310
|
+
|
|
311
|
+ $IP6 rule add pref $(($id+1000)) iif $2 lookup main
|
|
312
|
+ $IP6 rule add pref $(($id+2000)) fwmark $(($id*256))/0xff00 lookup $id
|
|
313
|
+ fi
|
|
314
|
+}
|
|
315
|
+
|
|
316
|
+mwan3_delete_iface_rules()
|
|
317
|
+{
|
|
318
|
+ local id family
|
|
319
|
+
|
|
320
|
+ config_get family $1 family ipv4
|
|
321
|
+ mwan3_get_iface_id id $1
|
|
322
|
+
|
|
323
|
+ [ -n "$id" ] || return 0
|
|
324
|
+
|
|
325
|
+ if [ "$family" == "ipv4" ]; then
|
|
326
|
+
|
|
327
|
+ while [ -n "$($IP4 rule list | awk '$1 == "'$(($id+1000)):'"')" ]; do
|
|
328
|
+ $IP4 rule del pref $(($id+1000))
|
|
329
|
+ done
|
|
330
|
+
|
|
331
|
+ while [ -n "$($IP4 rule list | awk '$1 == "'$(($id+2000)):'"')" ]; do
|
|
332
|
+ $IP4 rule del pref $(($id+2000))
|
|
333
|
+ done
|
|
334
|
+ fi
|
|
335
|
+
|
|
336
|
+ if [ "$family" == "ipv6" ]; then
|
|
337
|
+
|
|
338
|
+ while [ -n "$($IP6 rule list | awk '$1 == "'$(($id+1000)):'"')" ]; do
|
|
339
|
+ $IP6 rule del pref $(($id+1000))
|
|
340
|
+ done
|
|
341
|
+
|
|
342
|
+ while [ -n "$($IP6 rule list | awk '$1 == "'$(($id+2000)):'"')" ]; do
|
|
343
|
+ $IP6 rule del pref $(($id+2000))
|
|
344
|
+ done
|
|
345
|
+ fi
|
|
346
|
+}
|
|
347
|
+
|
|
348
|
+mwan3_delete_iface_ipset_entries()
|
|
349
|
+{
|
|
350
|
+ local id setname entry
|
|
351
|
+
|
|
352
|
+ mwan3_get_iface_id id $1
|
|
353
|
+
|
|
354
|
+ [ -n "$id" ] || return 0
|
|
355
|
+
|
|
356
|
+ for setname in $(ipset -n list | grep ^mwan3_sticky_); do
|
|
357
|
+ for entry in $(ipset list $setname | grep "$(echo $(($id*256)) | awk '{ printf "0x%08x", $1; }')" | cut -d ' ' -f 1); do
|
|
358
|
+ $IPS del $setname $entry
|
|
359
|
+ done
|
|
360
|
+ done
|
|
361
|
+}
|
|
362
|
+
|
|
363
|
+mwan3_track()
|
|
364
|
+{
|
|
365
|
+ local track_ip track_ips reliability count timeout interval down up
|
|
366
|
+
|
|
367
|
+ mwan3_list_track_ips()
|
|
368
|
+ {
|
|
369
|
+ track_ips="$1 $track_ips"
|
|
370
|
+ }
|
|
371
|
+ config_list_foreach $1 track_ip mwan3_list_track_ips
|
|
372
|
+
|
|
373
|
+ if [ -e /var/run/mwan3track-$1.pid ] ; then
|
|
374
|
+ kill $(cat /var/run/mwan3track-$1.pid) &> /dev/null
|
|
375
|
+ rm /var/run/mwan3track-$1.pid &> /dev/null
|
|
376
|
+ fi
|
|
377
|
+
|
|
378
|
+ if [ -n "$track_ips" ]; then
|
|
379
|
+ config_get reliability $1 reliability 1
|
|
380
|
+ config_get count $1 count 1
|
|
381
|
+ config_get timeout $1 timeout 4
|
|
382
|
+ config_get interval $1 interval 10
|
|
383
|
+ config_get down $1 down 5
|
|
384
|
+ config_get up $1 up 5
|
|
385
|
+
|
|
386
|
+ [ -x /usr/sbin/mwan3track ] && /usr/sbin/mwan3track $1 $2 $reliability $count $timeout $interval $down $up $track_ips &
|
|
387
|
+ fi
|
|
388
|
+}
|
|
389
|
+
|
|
390
|
+mwan3_set_policy()
|
|
391
|
+{
|
|
392
|
+ local iface_count id iface family metric probability weight
|
|
393
|
+
|
|
394
|
+ config_get iface $1 interface
|
|
395
|
+ config_get metric $1 metric 1
|
|
396
|
+ config_get weight $1 weight 1
|
|
397
|
+
|
|
398
|
+ [ -n "$iface" ] || return 0
|
|
399
|
+
|
|
400
|
+ mwan3_get_iface_id id $iface
|
|
401
|
+
|
|
402
|
+ [ -n "$id" ] || return 0
|
|
403
|
+
|
|
404
|
+ config_get family $iface family ipv4
|
|
405
|
+
|
|
406
|
+ if [ "$family" == "ipv4" ]; then
|
|
407
|
+
|
|
408
|
+ if [ -n "$($IP4 route list table $id)" ]; then
|
|
409
|
+ if [ "$metric" -lt "$lowest_metric_v4" ]; then
|
|
410
|
+
|
|
411
|
+ total_weight_v4=$weight
|
|
412
|
+ $IPT4 -F mwan3_policy_$policy
|
|
413
|
+ $IPT4 -A mwan3_policy_$policy -m mark --mark 0x0/0xff00 -m comment --comment "$iface $weight $weight" -j MARK --set-xmark $(($id*256))/0xff00
|
|
414
|
+
|
|
415
|
+ lowest_metric_v4=$metric
|
|
416
|
+
|
|
417
|
+ elif [ "$metric" -eq "$lowest_metric_v4" ]; then
|
|
418
|
+
|
|
419
|
+ total_weight_v4=$(($total_weight_v4+$weight))
|
|
420
|
+ probability=$(($weight*1000/$total_weight_v4))
|
|
421
|
+
|
|
422
|
+ if [ "$probability" -lt 10 ]; then
|
|
423
|
+ probability="0.00$probability"
|
|
424
|
+ elif [ $probability -lt 100 ]; then
|
|
425
|
+ probability="0.0$probability"
|
|
426
|
+ elif [ $probability -lt 1000 ]; then
|
|
427
|
+ probability="0.$probability"
|
|
428
|
+ else
|
|
429
|
+ probability="1"
|
|
430
|
+ fi
|
|
431
|
+
|
|
432
|
+ probability="-m statistic --mode random --probability $probability"
|
|
433
|
+
|
|
434
|
+ $IPT4 -I mwan3_policy_$policy -m mark --mark 0x0/0xff00 $probability -m comment --comment "$iface $weight $total_weight_v4" -j MARK --set-xmark $(($id*256))/0xff00
|
|
435
|
+ fi
|
|
436
|
+ fi
|
|
437
|
+ fi
|
|
438
|
+
|
|
439
|
+ if [ "$family" == "ipv6" ]; then
|
|
440
|
+
|
|
441
|
+ if [ -n "$($IP6 route list table $id)" ]; then
|
|
442
|
+ if [ "$metric" -lt "$lowest_metric_v6" ]; then
|
|
443
|
+
|
|
444
|
+ total_weight_v6=$weight
|
|
445
|
+ $IPT6 -F mwan3_policy_$policy
|
|
446
|
+ $IPT6 -A mwan3_policy_$policy -m mark --mark 0x0/0xff00 -m comment --comment "$iface $weight $weight" -j MARK --set-xmark $(($id*256))/0xff00
|
|
447
|
+
|
|
448
|
+ lowest_metric_v6=$metric
|
|
449
|
+
|
|
450
|
+ elif [ "$metric" -eq "$lowest_metric_v6" ]; then
|
|
451
|
+
|
|
452
|
+ total_weight_v6=$(($total_weight_v6+$weight))
|
|
453
|
+ probability=$(($weight*1000/$total_weight_v6))
|
|
454
|
+
|
|
455
|
+ if [ "$probability" -lt 10 ]; then
|
|
456
|
+ probability="0.00$probability"
|
|
457
|
+ elif [ $probability -lt 100 ]; then
|
|
458
|
+ probability="0.0$probability"
|
|
459
|
+ elif [ $probability -lt 1000 ]; then
|
|
460
|
+ probability="0.$probability"
|
|
461
|
+ else
|
|
462
|
+ probability="1"
|
|
463
|
+ fi
|
|
464
|
+
|
|
465
|
+ probability="-m statistic --mode random --probability $probability"
|
|
466
|
+
|
|
467
|
+ $IPT6 -I mwan3_policy_$policy -m mark --mark 0x0/0xff00 $probability -m comment --comment "$iface $weight $total_weight_v6" -j MARK --set-xmark $(($id*256))/0xff00
|
|
468
|
+ fi
|
|
469
|
+ fi
|
|
470
|
+ fi
|
|
471
|
+}
|
|
472
|
+
|
|
473
|
+mwan3_create_policies_iptables()
|
|
474
|
+{
|
|
475
|
+ local last_resort lowest_metric_v4 lowest_metric_v6 total_weight_v4 total_weight_v6 policy IPT
|
|
476
|
+
|
|
477
|
+ policy="$1"
|
|
478
|
+
|
|
479
|
+ config_get last_resort $1 last_resort unreachable
|
|
480
|
+
|
|
481
|
+ if [ "$1" != $(echo "$1" | cut -c1-15) ]; then
|
|
482
|
+ $LOG warn "Policy $1 exceeds max of 15 chars. Not setting policy" && return 0
|
|
483
|
+ fi
|
|
484
|
+
|
|
485
|
+ for IPT in "$IPT4" "$IPT6"; do
|
|
486
|
+
|
|
487
|
+ if ! $IPT -S mwan3_policy_$1 &> /dev/null; then
|
|
488
|
+ $IPT -N mwan3_policy_$1
|
|
489
|
+ fi
|
|
490
|
+
|
|
491
|
+ $IPT -F mwan3_policy_$1
|
|
492
|
+
|
|
493
|
+ case "$last_resort" in
|
|
494
|
+ blackhole)
|
|
495
|
+ $IPT -A mwan3_policy_$1 -m mark --mark 0x0/0xff00 -m comment --comment "blackhole" -j MARK --set-xmark 0xfd00/0xff00
|
|
496
|
+ ;;
|
|
497
|
+ default)
|
|
498
|
+ $IPT -A mwan3_policy_$1 -m mark --mark 0x0/0xff00 -m comment --comment "default" -j MARK --set-xmark 0xff00/0xff00
|
|
499
|
+ ;;
|
|
500
|
+ *)
|
|
501
|
+ $IPT -A mwan3_policy_$1 -m mark --mark 0x0/0xff00 -m comment --comment "unreachable" -j MARK --set-xmark 0xfe00/0xff00
|
|
502
|
+ ;;
|
|
503
|
+ esac
|
|
504
|
+ done
|
|
505
|
+
|
|
506
|
+ lowest_metric_v4=256
|
|
507
|
+ total_weight_v4=0
|
|
508
|
+
|
|
509
|
+ lowest_metric_v6=256
|
|
510
|
+ total_weight_v6=0
|
|
511
|
+
|
|
512
|
+ config_list_foreach $1 use_member mwan3_set_policy
|
|
513
|
+}
|
|
514
|
+
|
|
515
|
+mwan3_set_sticky_iptables()
|
|
516
|
+{
|
|
517
|
+ local id
|
|
518
|
+
|
|
519
|
+ mwan3_get_iface_id id $1
|
|
520
|
+
|
|
521
|
+ [ -n "$id" ] || return 0
|
|
522
|
+
|
|
523
|
+ $IPS -! create mwan3_sticky_v4_$rule hash:ip,mark markmask 0xff00 timeout $timeout
|
|
524
|
+ $IPS -! create mwan3_sticky_v6_$rule hash:ip,mark markmask 0xff00 timeout $timeout family inet6
|
|
525
|
+ $IPS -! create mwan3_sticky_$rule list:set
|
|
526
|
+ $IPS -! add mwan3_sticky_$rule mwan3_sticky_v4_$rule
|
|
527
|
+ $IPS -! add mwan3_sticky_$rule mwan3_sticky_v6_$rule
|
|
528
|
+
|
|
529
|
+ for IPT in "$IPT4" "$IPT6"; do
|
|
530
|
+ if [ -n "$($IPT -S mwan3_iface_$1 2> /dev/null)" ]; then
|
|
531
|
+ $IPT -I mwan3_rule_$rule -m set ! --match-set mwan3_sticky_$rule src,src -j MARK --set-xmark 0x0/0xff00
|
|
532
|
+ $IPT -I mwan3_rule_$rule -m mark --mark 0/0xff00 -j MARK --set-xmark $(($id*256))/0xff00
|
|
533
|
+ fi
|
|
534
|
+ done
|
|
535
|
+}
|
|
536
|
+
|
|
537
|
+mwan3_set_user_iptables_rule()
|
|
538
|
+{
|
|
539
|
+ local ipset family proto policy src_ip src_port sticky dest_ip dest_port use_policy timeout rule policy IPT
|
|
540
|
+
|
|
541
|
+ rule="$1"
|
|
542
|
+
|
|
543
|
+ config_get sticky $1 sticky 0
|
|
544
|
+ config_get timeout $1 timeout 600
|
|
545
|
+ config_get ipset $1 ipset
|
|
546
|
+ config_get proto $1 proto all
|
|
547
|
+ config_get src_ip $1 src_ip 0.0.0.0/0
|
|
548
|
+ config_get src_port $1 src_port 0:65535
|
|
549
|
+ config_get dest_ip $1 dest_ip 0.0.0.0/0
|
|
550
|
+ config_get dest_port $1 dest_port 0:65535
|
|
551
|
+ config_get use_policy $1 use_policy
|
|
552
|
+ config_get family $1 family any
|
|
553
|
+
|
|
554
|
+ if [ "$1" != $(echo "$1" | cut -c1-15) ]; then
|
|
555
|
+ $LOG warn "Rule $1 exceeds max of 15 chars. Not setting rule" && return 0
|
|
556
|
+ fi
|
|
557
|
+
|
|
558
|
+ if [ -n "$ipset" ]; then
|
|
559
|
+ if [ -z "$($IPS -n list $ipset 2> /dev/null)" ]; then
|
|
560
|
+ $IPS create $ipset list:set
|
|
561
|
+ $IPS create v4_$ipset hash:ip timeout 3600
|
|
562
|
+ $IPS create v6_$ipset hash:ip timeout 3600 family inet6
|
|
563
|
+ $IPS add $ipset v4_$ipset
|
|
564
|
+ $IPS add $ipset v6_$ipset
|
|
565
|
+ fi
|
|
566
|
+
|
|
567
|
+ ipset="-m set --match-set $ipset dst"
|
|
568
|
+ fi
|
|
569
|
+
|
|
570
|
+ if [ -n "$use_policy" ]; then
|
|
571
|
+ if [ "$use_policy" == "default" ]; then
|
|
572
|
+ policy="MARK --set-xmark 0xff00/0xff00"
|
|
573
|
+ elif [ "$use_policy" == "unreachable" ]; then
|
|
574
|
+ policy="MARK --set-xmark 0xfe00/0xff00"
|
|
575
|
+ elif [ "$use_policy" == "blackhole" ]; then
|
|
576
|
+ policy="MARK --set-xmark 0xfd00/0xff00"
|
|
577
|
+ else
|
|
578
|
+ if [ "$sticky" -eq 1 ]; then
|
|
579
|
+
|
|
580
|
+ policy="mwan3_policy_$use_policy"
|
|
581
|
+
|
|
582
|
+ config_foreach mwan3_set_sticky_iptables interface
|
|
583
|
+
|
|
584
|
+ for IPT in "$IPT4" "$IPT6"; do
|
|
585
|
+ if ! $IPT -S $policy &> /dev/null; then
|
|
586
|
+ $IPT -N $policy
|
|
587
|
+ fi
|
|
588
|
+
|
|
589
|
+ if ! $IPT -S mwan3_rule_$1 &> /dev/null; then
|
|
590
|
+ $IPT -N mwan3_rule_$1
|
|
591
|
+ fi
|
|
592
|
+
|
|
593
|
+ $IPT -F mwan3_rule_$1
|
|
594
|
+
|
|
595
|
+ $IPT -A mwan3_rule_$1 -m mark --mark 0/0xff00 -j $policy
|
|
596
|
+ $IPT -A mwan3_rule_$1 -m mark ! --mark 0xfc00/0xfc00 -j SET --del-set mwan3_sticky_$rule src,src
|
|
597
|
+ $IPT -A mwan3_rule_$1 -m mark ! --mark 0xfc00/0xfc00 -j SET --add-set mwan3_sticky_$rule src,src
|
|
598
|
+ done
|
|
599
|
+
|
|
600
|
+ policy="mwan3_rule_$1"
|
|
601
|
+ else
|
|
602
|
+ policy="mwan3_policy_$use_policy"
|
|
603
|
+
|
|
604
|
+ for IPT in "$IPT4" "$IPT6"; do
|
|
605
|
+ if ! $IPT -S $policy &> /dev/null; then
|
|
606
|
+ $IPT -N $policy
|
|
607
|
+ fi
|
|
608
|
+ done
|
|
609
|
+
|
|
610
|
+ fi
|
|
611
|
+ fi
|
|
612
|
+
|
|
613
|
+ if [ "$family" == "any" ]; then
|
|
614
|
+
|
|
615
|
+ for IPT in "$IPT4" "$IPT6"; do
|
|
616
|
+ case $proto in
|
|
617
|
+ tcp|udp)
|
|
618
|
+ $IPT -A mwan3_rules -p $proto -s $src_ip -d $dest_ip $ipset -m multiport --sports $src_port -m multiport --dports $dest_port -m mark --mark 0/0xff00 -m comment --comment "$1" -j $policy &> /dev/null
|
|
619
|
+ ;;
|
|
620
|
+ *)
|
|
621
|
+ $IPT -A mwan3_rules -p $proto -s $src_ip -d $dest_ip $ipset -m mark --mark 0/0xff00 -m comment --comment "$1" -j $policy &> /dev/null
|
|
622
|
+ ;;
|
|
623
|
+ esac
|
|
624
|
+ done
|
|
625
|
+
|
|
626
|
+ elif [ "$family" == "ipv4" ]; then
|
|
627
|
+
|
|
628
|
+ case $proto in
|
|
629
|
+ tcp|udp)
|
|
630
|
+ $IPT4 -A mwan3_rules -p $proto -s $src_ip -d $dest_ip $ipset -m multiport --sports $src_port -m multiport --dports $dest_port -m mark --mark 0/0xff00 -m comment --comment "$1" -j $policy &> /dev/null
|
|
631
|
+ ;;
|
|
632
|
+ *)
|
|
633
|
+ $IPT4 -A mwan3_rules -p $proto -s $src_ip -d $dest_ip $ipset -m mark --mark 0/0xff00 -m comment --comment "$1" -j $policy &> /dev/null
|
|
634
|
+ ;;
|
|
635
|
+ esac
|
|
636
|
+
|
|
637
|
+ elif [ "$family" == "ipv6" ]; then
|
|
638
|
+
|
|
639
|
+ case $proto in
|
|
640
|
+ tcp|udp)
|
|
641
|
+ $IPT6 -A mwan3_rules -p $proto -s $src_ip -d $dest_ip $ipset -m multiport --sports $src_port -m multiport --dports $dest_port -m mark --mark 0/0xff00 -m comment --comment "$1" -j $policy &> /dev/null
|
|
642
|
+ ;;
|
|
643
|
+ *)
|
|
644
|
+ $IPT6 -A mwan3_rules -p $proto -s $src_ip -d $dest_ip $ipset -m mark --mark 0/0xff00 -m comment --comment "$1" -j $policy &> /dev/null
|
|
645
|
+ ;;
|
|
646
|
+ esac
|
|
647
|
+ fi
|
|
648
|
+ fi
|
|
649
|
+}
|
|
650
|
+
|
|
651
|
+mwan3_set_user_rules()
|
|
652
|
+{
|
|
653
|
+ local IPT
|
|
654
|
+
|
|
655
|
+ for IPT in "$IPT4" "$IPT6"; do
|
|
656
|
+
|
|
657
|
+ if ! $IPT -S mwan3_rules &> /dev/null; then
|
|
658
|
+ $IPT -N mwan3_rules
|
|
659
|
+ fi
|
|
660
|
+
|
|
661
|
+ $IPT -F mwan3_rules
|
|
662
|
+ done
|
|
663
|
+
|
|
664
|
+ config_foreach mwan3_set_user_iptables_rule rule
|
|
665
|
+}
|
|
666
|
+
|
|
667
|
+mwan3_report_iface_status()
|
|
668
|
+{
|
|
669
|
+ local device result track_ips tracking IP IPT
|
|
670
|
+
|
|
671
|
+ mwan3_get_iface_id id $1
|
|
672
|
+ network_get_device device $1
|
|
673
|
+ config_get enabled "$1" enabled 0
|
|
674
|
+ config_get family "$1" family ipv4
|
|
675
|
+
|
|
676
|
+ if [ "$family" == "ipv4" ]; then
|
|
677
|
+ IP="$IP4"
|
|
678
|
+ IPT="$IPT4"
|
|
679
|
+ fi
|
|
680
|
+
|
|
681
|
+ if [ "$family" == "ipv6" ]; then
|
|
682
|
+ IP="$IP6"
|
|
683
|
+ IPT="$IPT6"
|
|
684
|
+ fi
|
|
685
|
+
|
|
686
|
+ if [ -z "$id" -o -z "$device" ]; then
|
|
687
|
+ result="unknown"
|
|
688
|
+ elif [ -n "$($IP rule | awk '$1 == "'$(($id+1000)):'"')"i -a -n "$($IP rule | awk '$1 == "'$(($id+2000)):'"')" -a -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" -a -n "$($IPT -S mwan3_iface_out_$1 2> /dev/null)" -a -n "$($IP route list table $id default dev $device 2> /dev/null)" ]; then
|
|
689
|
+ result="online"
|
|
690
|
+ elif [ -n "$($IP rule | awk '$1 == "'$(($id+1000)):'"')" -o -n "$($IP rule | awk '$1 == "'$(($id+2000)):'"')" -o -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" -o -n "$($IPT -S mwan3_iface_out_$1 2> /dev/null)" -o -n "$($IP route list table $id default dev $device 2> /dev/null)" ]; then
|
|
691
|
+ result="error"
|
|
692
|
+ else
|
|
693
|
+ if [ "$enabled" == "1" ]; then
|
|
694
|
+ result="offline"
|
|
695
|
+ else
|
|
696
|
+ result="disabled"
|
|
697
|
+ fi
|
|
698
|
+ fi
|
|
699
|
+
|
|
700
|
+ mwan3_list_track_ips()
|
|
701
|
+ {
|
|
702
|
+ track_ips="$1 $track_ips"
|
|
703
|
+ }
|
|
704
|
+ config_list_foreach $1 track_ip mwan3_list_track_ips
|
|
705
|
+
|
|
706
|
+ if [ -n "$track_ips" ]; then
|
|
707
|
+ if [ -n "$(ps -w | grep mwan3track | grep -v grep | sed '/.*\/usr\/sbin\/mwan3track \([^ ]*\) .*$/!d;s//\1/' | awk '$1 == "'$1'"')" ]; then
|
|
708
|
+ tracking="active"
|
|
709
|
+ else
|
|
710
|
+ tracking="down"
|
|
711
|
+ fi
|
|
712
|
+ else
|
|
713
|
+ tracking="not enabled"
|
|
714
|
+ fi
|
|
715
|
+
|
|
716
|
+ echo " interface $1 is $result and tracking is $tracking"
|
|
717
|
+}
|
|
718
|
+
|
|
719
|
+mwan3_report_policies_v4()
|
|
720
|
+{
|
|
721
|
+ local percent policy share total_weight weight iface
|
|
722
|
+
|
|
723
|
+ for policy in $($IPT4 -S | awk '{print $2}' | grep mwan3_policy_ | sort -u); do
|
|
724
|
+ echo "$policy:" | sed 's/mwan3_policy_//'
|
|
725
|
+
|
|
726
|
+ [ -n "$total_weight" ] || total_weight=$($IPT4 -S $policy | cut -s -d'"' -f2 | head -1 | awk '{print $3}')
|
|
727
|
+
|
|
728
|
+ if [ ! -z "${total_weight##*[!0-9]*}" ]; then
|
|
729
|
+ for iface in $($IPT4 -S $policy | cut -s -d'"' -f2 | awk '{print $1}'); do
|
|
730
|
+ weight=$($IPT4 -S $policy | cut -s -d'"' -f2 | awk '$1 == "'$iface'"' | awk '{print $2}')
|
|
731
|
+ percent=$(($weight*100/$total_weight))
|
|
732
|
+ echo " $iface ($percent%)"
|
|
733
|
+ done
|
|
734
|
+ else
|
|
735
|
+ echo " $($IPT4 -S $policy | sed '/.*--comment \([^ ]*\) .*$/!d;s//\1/;q')"
|
|
736
|
+ fi
|
|
737
|
+
|
|
738
|
+ unset total_weight
|
|
739
|
+
|
|
740
|
+ echo -e
|
|
741
|
+ done
|
|
742
|
+}
|
|
743
|
+
|
|
744
|
+mwan3_report_policies_v6()
|
|
745
|
+{
|
|
746
|
+ local percent policy share total_weight weight iface
|
|
747
|
+
|
|
748
|
+ for policy in $($IPT6 -S | awk '{print $2}' | grep mwan3_policy_ | sort -u); do
|
|
749
|
+ echo "$policy:" | sed 's/mwan3_policy_//'
|
|
750
|
+
|
|
751
|
+ [ -n "$total_weight" ] || total_weight=$($IPT6 -S $policy | cut -s -d'"' -f2 | head -1 | awk '{print $3}')
|
|
752
|
+
|
|
753
|
+ if [ ! -z "${total_weight##*[!0-9]*}" ]; then
|
|
754
|
+ for iface in $($IPT6 -S $policy | cut -s -d'"' -f2 | awk '{print $1}'); do
|
|
755
|
+ weight=$($IPT6 -S $policy | cut -s -d'"' -f2 | awk '$1 == "'$iface'"' | awk '{print $2}')
|
|
756
|
+ percent=$(($weight*100/$total_weight))
|
|
757
|
+ echo " $iface ($percent%)"
|
|
758
|
+ done
|
|
759
|
+ else
|
|
760
|
+ echo " $($IPT6 -S $policy | sed '/.*--comment \([^ ]*\) .*$/!d;s//\1/;q')"
|
|
761
|
+ fi
|
|
762
|
+
|
|
763
|
+ unset total_weight
|
|
764
|
+
|
|
765
|
+ echo -e
|
|
766
|
+ done
|
|
767
|
+}
|
|
768
|
+
|
|
769
|
+mwan3_report_connected_v4()
|
|
770
|
+{
|
|
771
|
+ local address
|
|
772
|
+
|
|
773
|
+ if [ -n "$($IPT4 -S mwan3_connected 2> /dev/null)" ]; then
|
|
774
|
+ for address in $($IPS list mwan3_connected_v4 | egrep '[0-9]{1,3}(\.[0-9]{1,3}){3}'); do
|
|
775
|
+ echo " $address"
|
|
776
|
+ done
|
|
777
|
+ fi
|
|
778
|
+}
|
|
779
|
+
|
|
780
|
+mwan3_report_connected_v6()
|
|
781
|
+{
|
|
782
|
+ local address
|
|
783
|
+
|
|
784
|
+ if [ -n "$($IPT6 -S mwan3_connected 2> /dev/null)" ]; then
|
|
785
|
+ for address in $($IPS list mwan3_connected_v6 | egrep '([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])'); do
|
|
786
|
+ echo " $address"
|
|
787
|
+ done
|
|
788
|
+ fi
|
|
789
|
+}
|
|
790
|
+
|
|
791
|
+mwan3_report_rules_v4()
|
|
792
|
+{
|
|
793
|
+ if [ -n "$($IPT4 -S mwan3_rules 2> /dev/null)" ]; then
|
|
794
|
+ $IPT4 -L mwan3_rules -n -v 2> /dev/null | tail -n+3 | sed 's/mark.*//' | sed 's/mwan3_policy_/- /' | sed 's/mwan3_rule_/S /'
|
|
795
|
+ fi
|
|
796
|
+}
|
|
797
|
+
|
|
798
|
+mwan3_report_rules_v6()
|
|
799
|
+{
|
|
800
|
+ if [ -n "$($IPT6 -S mwan3_rules 2> /dev/null)" ]; then
|
|
801
|
+ $IPT6 -L mwan3_rules -n -v 2> /dev/null | tail -n+3 | sed 's/mark.*//' | sed 's/mwan3_policy_/- /' | sed 's/mwan3_rule_/S /'
|
|
802
|
+ fi
|
|
803
|
+}
|