Просмотр исходного кода

Merge pull request #2139 from Adze1502/master

mwan3: update to version 2.0-1
Hannu Nyman 9 лет назад
Родитель
Сommit
c1dc8cd0e4

+ 1
- 1
net/mwan3/Makefile Просмотреть файл

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

+ 35
- 111
net/mwan3/files/etc/config/mwan3 Просмотреть файл

@@ -1,60 +1,21 @@
1 1
 
2
-config interface 'wan1'
2
+config interface 'wan'
3 3
 	option enabled '1'
4 4
 	list track_ip '8.8.4.4'
5
-	option reliability '1'
6
-	option count '1'
7
-	option timeout '2'
8
-	option interval '5'
9
-	option down '3'
10
-	option up '8'
11
-
12
-config interface 'wan2'
13
-	option enabled '1'
14 5
 	list track_ip '8.8.8.8'
15
-	option reliability '1'
16
-	option count '1'
17
-	option timeout '2'
18
-	option interval '5'
19
-	option down '3'
20
-	option up '8'
21
-
22
-config interface 'wan3'
23
-	option enabled '1'
24 6
 	list track_ip '208.67.222.222'
25
-	option reliability '1'
7
+	list track_ip '208.67.220.220'
8
+	option reliability '2'
26 9
 	option count '1'
27 10
 	option timeout '2'
28 11
 	option interval '5'
29 12
 	option down '3'
30 13
 	option up '8'
31 14
 
32
-config interface 'wan1_v6'
33
-	option family 'ipv6'
34
-	option enabled '1'
35
-	list track_ip '2001:7b8:1::2'
36
-	option reliability '1'
37
-	option count '1'
38
-	option timeout '2'
39
-	option interval '5'
40
-	option down '3'
41
-	option up '8'
42
-
43
-config interface 'wan2_v6'
44
-	option family 'ipv6'
45
-	option enabled '1'
46
-	list track_ip '2001:7b8:2::2'
47
-	option reliability '1'
48
-	option count '1'
49
-	option timeout '2'
50
-	option interval '5'
51
-	option down '3'
52
-	option up '8'
53
-
54
-config interface 'wan3_v6'
55
-	option family 'ipv6'
56
-	option enabled '1'
57
-	list track_ip '2001:7b8:3::2'
15
+config interface 'wan2'
16
+	option enabled '0'
17
+	list track_ip '8.8.8.8'
18
+	list track_ip '208.67.220.220'
58 19
 	option reliability '1'
59 20
 	option count '1'
60 21
 	option timeout '2'
@@ -62,88 +23,51 @@ config interface 'wan3_v6'
62 23
 	option down '3'
63 24
 	option up '8'
64 25
 
65
-config member 'wan1_m1_w1'
66
-	option interface 'wan1'
26
+config member 'wan_m1_w3'
27
+	option interface 'wan'
67 28
 	option metric '1'
68
-	option weight '1'
29
+	option weight '3'
69 30
 
70
-config member 'wan2_m1_w1'
71
-	option interface 'wan2'
72
-	option metric '1'
73
-	option weight '1'
31
+config member 'wan_m2_w3'
32
+	option interface 'wan'
33
+	option metric '2'
34
+	option weight '3'
74 35
 
75
-config member 'wan3_m1_w1'
76
-	option interface 'wan3'
77
-	option metric '1'
78
-	option weight '1'
79
-
80
-config member 'wan1_v6_m1_w1'
81
-	option interface 'wan1_v6'
82
-	option metric '1'
83
-	option weight '1'
84
-
85
-config member 'wan2_v6_m1_w1'
86
-	option interface 'wan2_v6'
36
+config member 'wan2_m1_w2'
37
+	option interface 'wan2'
87 38
 	option metric '1'
88
-	option weight '1'
39
+	option weight '2'
89 40
 
90
-config member 'wan3_v6_m1_w1'
91
-	option interface 'wan3_v6'
92
-	option metric '1'
93
-	option weight '1'
41
+config member 'wan2_m2_w2'
42
+	option interface 'wan2'
43
+	option metric '2'
44
+	option weight '2'
94 45
 
95
-config policy 'wan1_only'
96
-	list use_member 'wan1_m1_w1'
46
+config policy 'wan_only'
47
+	list use_member 'wan_m1_w3'
97 48
 
98 49
 config policy 'wan2_only'
99
-	list use_member 'wan2_m1_w1'
50
+	list use_member 'wan2_m1_w2'
100 51
 
101
-config policy 'wan3_only'
102
-	list use_member 'wan3_m1_w1'
103
-
104
-config policy 'wan1_v6_only'
105
-	list use_member 'wan1_v6_m1_w1'
106
-
107
-config policy 'wan2_v6_only'
108
-	list use_member 'wan2_v6_m1_w1'
52
+config policy 'balanced'
53
+	list use_member 'wan_m1_w3'
54
+	list use_member 'wan2_m1_w2'
109 55
 
110
-config policy 'wan3_v6_only'
111
-	list use_member 'wan3_v6_m1_w1'
56
+config policy 'wan_wan2'
57
+	list use_member 'wan_m1_w3'
58
+	list use_member 'wan2_m2_w2'
112 59
 
113
-config policy 'balanced'
114
-	list use_member 'wan1_m1_w1'
115
-	list use_member 'wan2_m1_w1'
116
-	list use_member 'wan3_m1_w1'
117
-	list use_member 'wan1_v6_m1_w1'
118
-	list use_member 'wan2_v6_m1_w1'
119
-	list use_member 'wan3_v6_m1_w1'
60
+config policy 'wan2_wan'
61
+	list use_member 'wan_m2_w3'
62
+	list use_member 'wan2_m1_w2'
120 63
 
121 64
 config rule 'https'
122
-	option src_ip '2001:3::/64'
65
+	option sticky '1'
123 66
 	option dest_port '443'
124 67
 	option proto 'tcp'
125 68
 	option use_policy 'balanced'
126 69
 
127
-config rule 'https2'
128
-	option dest_port '19443'
129
-	option proto 'tcp'
130
-	option use_policy 'balanced'
131
-	option sticky '1'
132
-
133
-config rule 'igs'
134
-	option proto 'icmp'
135
-	option family 'ipv4'
136
-	option sticky '1'
137
-	option ipset 'google'
138
-	option use_policy 'balanced'
139
-
140
-config rule 'i6gs'
141
-	option proto 'icmpv6'
142
-	option family 'ipv6'
143
-	option sticky '1'
144
-	option ipset 'google'
145
-	option use_policy 'balanced'
146
-
147 70
 config rule 'default_rule'
71
+	option dest_ip '0.0.0.0/0'
148 72
 	option use_policy 'balanced'
149 73
 

+ 21
- 8
net/mwan3/files/etc/hotplug.d/iface/15-mwan3 Просмотреть файл

@@ -1,5 +1,14 @@
1 1
 #!/bin/sh
2 2
 
3
+. /lib/functions.sh
4
+. /lib/functions/network.sh
5
+. /lib/mwan3/mwan3.sh
6
+
7
+config_load mwan3
8
+
9
+config_get enabled $INTERFACE enabled 0
10
+[ "$enabled" == "1" ] || exit 0
11
+
3 12
 [ "$ACTION" == "ifup" -o "$ACTION" == "ifdown" ] || exit 1
4 13
 [ -n "$INTERFACE" ] || exit 2
5 14
 
@@ -13,14 +22,17 @@ fi
13 22
 [ -x /usr/sbin/ip6tables ] || exit 7
14 23
 [ -x /usr/bin/logger ] || exit 8
15 24
 
16
-. /lib/functions.sh
17
-. /lib/functions/network.sh
18
-. /lib/mwan3/mwan3.sh
25
+local family gateway
19 26
 
20
-config_load mwan3
27
+config_get family $INTERFACE family ipv4
21 28
 
22
-config_get enabled $INTERFACE enabled 0
23
-[ "$enabled" == "1" ] || exit 0
29
+if [ "$family" == "ipv4" ]; then
30
+	network_get_gateway gateway $INTERFACE
31
+elif [ "$family" == "ipv6" ]; then
32
+	network_get_gateway6 gateway $INTERFACE
33
+fi
34
+
35
+[ -n "$gateway" ] || exit 9
24 36
 
25 37
 $LOG notice "$ACTION interface $INTERFACE (${DEVICE:-unknown})"
26 38
 
@@ -34,6 +46,7 @@ case "$ACTION" in
34 46
 		mwan3_create_iface_iptables $INTERFACE $DEVICE
35 47
 		mwan3_create_iface_route $INTERFACE $DEVICE
36 48
 		mwan3_track $INTERFACE $DEVICE
49
+		mwan3_set_policies_iptables
37 50
 		mwan3_set_user_rules
38 51
 	;;
39 52
 	ifdown)
@@ -41,9 +54,9 @@ case "$ACTION" in
41 54
 		mwan3_delete_iface_iptables $INTERFACE
42 55
 		mwan3_delete_iface_route $INTERFACE
43 56
 		mwan3_delete_iface_ipset_entries $INTERFACE
57
+		mwan3_set_policies_iptables
58
+		mwan3_set_user_rules
44 59
 	;;
45 60
 esac
46 61
 
47
-config_foreach mwan3_create_policies_iptables policy
48
-
49 62
 exit 0

+ 27
- 22
net/mwan3/files/lib/mwan3/mwan3.sh Просмотреть файл

@@ -512,24 +512,35 @@ mwan3_create_policies_iptables()
512 512
 	config_list_foreach $1 use_member mwan3_set_policy
513 513
 }
514 514
 
515
+mwan3_set_policies_iptables()
516
+{
517
+	config_foreach mwan3_create_policies_iptables policy
518
+}
519
+
515 520
 mwan3_set_sticky_iptables()
516 521
 {
517
-	local id
522
+	local id iface
518 523
 
519
-	mwan3_get_iface_id id $1
524
+	for iface in $($IPT4 -S $policy | cut -s -d'"' -f2 | awk '{print $1}'); do
520 525
 
521
-	[ -n "$id" ] || return 0
526
+		if [ "$iface" == "$1" ]; then
522 527
 
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
+			mwan3_get_iface_id id $1
528 529
 
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
530
+			[ -n "$id" ] || return 0
531
+
532
+			$IPS -! create mwan3_sticky_v4_$rule hash:ip,mark markmask 0xff00 timeout $timeout
533
+			$IPS -! create mwan3_sticky_v6_$rule hash:ip,mark markmask 0xff00 timeout $timeout family inet6
534
+			$IPS -! create mwan3_sticky_$rule list:set
535
+			$IPS -! add mwan3_sticky_$rule mwan3_sticky_v4_$rule
536
+			$IPS -! add mwan3_sticky_$rule mwan3_sticky_v6_$rule
537
+
538
+			for IPT in "$IPT4" "$IPT6"; do
539
+				if [ -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" -a -n "$($IPT -S mwan3_iface_out_$1 2> /dev/null)" ]; then
540
+					$IPT -I mwan3_rule_$rule -m mark --mark $(($id*256))/0xff00 -m set ! --match-set mwan3_sticky_$rule src,src -j MARK --set-xmark 0x0/0xff00
541
+					$IPT -I mwan3_rule_$rule -m mark --mark 0/0xff00 -j MARK --set-xmark $(($id*256))/0xff00
542
+				fi
543
+			done
533 544
 		fi
534 545
 	done
535 546
 }
@@ -556,14 +567,6 @@ mwan3_set_user_iptables_rule()
556 567
 	fi
557 568
 
558 569
 	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 570
 		ipset="-m set --match-set $ipset dst"
568 571
 	fi
569 572
 
@@ -579,8 +582,6 @@ mwan3_set_user_iptables_rule()
579 582
 
580 583
 				policy="mwan3_policy_$use_policy"
581 584
 
582
-				config_foreach mwan3_set_sticky_iptables interface
583
-
584 585
 				for IPT in "$IPT4" "$IPT6"; do
585 586
 					if ! $IPT -S $policy &> /dev/null; then
586 587
 						$IPT -N $policy
@@ -591,7 +592,11 @@ mwan3_set_user_iptables_rule()
591 592
 					fi
592 593
 
593 594
 					$IPT -F mwan3_rule_$1
595
+				done
594 596
 
597
+				config_foreach mwan3_set_sticky_iptables interface
598
+
599
+				for IPT in "$IPT4" "$IPT6"; do
595 600
 					$IPT -A mwan3_rule_$1 -m mark --mark 0/0xff00 -j $policy
596 601
 					$IPT -A mwan3_rule_$1 -m mark ! --mark 0xfc00/0xfc00 -j SET --del-set mwan3_sticky_$rule src,src
597 602
 					$IPT -A mwan3_rule_$1 -m mark ! --mark 0xfc00/0xfc00 -j SET --add-set mwan3_sticky_$rule src,src

+ 8
- 2
net/mwan3/files/usr/sbin/mwan3 Просмотреть файл

@@ -84,8 +84,10 @@ policies()
84 84
 {
85 85
 	echo "Current ipv4 policies:"
86 86
 	mwan3_report_policies_v4
87
+	echo -e
87 88
 	echo "Current ipv6 policies:"
88 89
 	mwan3_report_policies_v6
90
+	echo -e
89 91
 }
90 92
 
91 93
 connected()
@@ -154,8 +156,12 @@ stop()
154 156
 		done
155 157
 	done
156 158
 
157
-	for ipset in $($IPS -n list | sort | grep mwan3); do
158
-		$IPS destroy $ipset
159
+	for ipset in $($IPS -n list | grep mwan3_); do
160
+		$IPS -q destroy $ipset
161
+	done
162
+
163
+	for ipset in $($IPS -n list | grep mwan3 | grep -E '_v4|_v6'); do
164
+		$IPS -q destroy $ipset
159 165
 	done
160 166
 }
161 167