Browse Source

Merge pull request #354 from Adze1502/master

mwan3: update to version 1.5-6
sbyx 10 years ago
parent
commit
5cc44195bf
3 changed files with 40 additions and 23 deletions
  1. 1
    1
      net/mwan3/Makefile
  2. 37
    14
      net/mwan3/files/etc/hotplug.d/iface/15-mwan3
  3. 2
    8
      net/mwan3/files/usr/sbin/mwan3

+ 1
- 1
net/mwan3/Makefile View File

@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
9 9
 
10 10
 PKG_NAME:=mwan3
11 11
 PKG_VERSION:=1.5
12
-PKG_RELEASE:=5
12
+PKG_RELEASE:=6
13 13
 PKG_MAINTAINER:=Jeroen Louwes <jeroen.louwes@gmail.com>
14 14
 PKG_LICENSE:=GPLv2
15 15
 

+ 37
- 14
net/mwan3/files/etc/hotplug.d/iface/15-mwan3 View File

@@ -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"

+ 2
- 8
net/mwan3/files/usr/sbin/mwan3 View File

@@ -21,8 +21,6 @@ IPT="/usr/sbin/iptables -t mangle -w"
21 21
 
22 22
 ifdown()
23 23
 {
24
-	local device
25
-
26 24
 	if [ -z "$1" ]; then
27 25
 		echo "Error: Expecting interface. Usage: mwan3 ifdown <interface>" && exit 0
28 26
 	fi
@@ -31,16 +29,12 @@ ifdown()
31 29
 		echo "Error: Too many arguments. Usage: mwan3 ifdown <interface>" && exit 0
32 30
 	fi
33 31
 
34
-	device=$(uci get -p /var/state network.$1.ifname) &> /dev/null
35
-	
36 32
 	if [ -e /var/run/mwan3track-$1.pid ] ; then
37 33
 		kill $(cat /var/run/mwan3track-$1.pid)
38 34
 		rm /var/run/mwan3track-$1.pid
39 35
 	fi
40 36
 
41
-	if [ -n "$device" ] ; then
42
-		ACTION=ifdown INTERFACE=$1 DEVICE=$device /sbin/hotplug-call iface
43
-	fi
37
+	ACTION=ifdown INTERFACE=$1 /sbin/hotplug-call iface
44 38
 }
45 39
 
46 40
 ifup()
@@ -121,7 +115,7 @@ policies()
121 115
 	local percent policy share total_weight weight iface
122 116
 
123 117
 	for policy in $($IPT -S | awk '{print $2}' | grep mwan3_policy_ | sort -u); do
124
-		echo "Policy $policy:" | sed 's/mwan3_policy_//g'
118
+		echo "Policy $policy:" | sed 's/mwan3_policy_//'
125 119
 
126 120
 		[ -n "$total_weight" ] || total_weight=$($IPT -S $policy | cut -s -d'"' -f2 | head -1 | awk '{print $3}')
127 121