Преглед изворни кода

wshaper: import from packages

Import the current wshaper package and add myself as maintainer.

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Jo-Philipp Wich пре 10 година
родитељ
комит
1fa58a1b1a
4 измењених фајлова са 232 додато и 0 уклоњено
  1. 57
    0
      net/wshaper/Makefile
  2. 4
    0
      net/wshaper/files/wshaper.config
  3. 161
    0
      net/wshaper/files/wshaper.htb
  4. 10
    0
      net/wshaper/files/wshaper.init

+ 57
- 0
net/wshaper/Makefile Прегледај датотеку

@@ -0,0 +1,57 @@
1
+#
2
+# Copyright (C) 2007-2011 OpenWrt.org
3
+#
4
+# This is free software, licensed under the GNU General Public License v2.
5
+# See /LICENSE for more information.
6
+#
7
+
8
+include $(TOPDIR)/rules.mk
9
+
10
+PKG_NAME:=wshaper
11
+PKG_VERSION:=0.2
12
+PKG_RELEASE:=2
13
+
14
+PKG_MAINTAINER:=Jo-Philipp Wich <jow@openwrt.org>
15
+
16
+PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
17
+
18
+include $(INCLUDE_DIR)/package.mk
19
+
20
+define Package/wshaper
21
+  SECTION:=net
22
+  CATEGORY:=Network
23
+  DEPENDS:=+kmod-sched +tc
24
+  TITLE:=wshaper
25
+  URL:=http://lartc.org/wondershaper/
26
+  PKGARCH:=all
27
+endef
28
+
29
+define Package/wshaper/description
30
+ A script to do traffing shaping with the HTB algorithm.
31
+ Wshaper attempts to:
32
+ * Maintain low latency for interfactive traffic at all times
33
+ * Allow 'surfing' at reasonable speeds while up or downloading
34
+ * Make sure uploads don't harm downloads, and the other way around
35
+endef
36
+
37
+define Build/Prepare
38
+endef
39
+
40
+define Build/Configure
41
+endef
42
+
43
+define Build/Compile
44
+endef
45
+
46
+define Package/wshaper/install
47
+	$(INSTALL_DIR) $(1)/usr/sbin/ $(1)/etc/init.d $(1)/etc/config
48
+	$(INSTALL_BIN) ./files/wshaper.htb $(1)/usr/sbin/
49
+	$(INSTALL_BIN) ./files/wshaper.init $(1)/etc/init.d/wshaper
50
+	$(INSTALL_DATA) ./files/wshaper.config $(1)/etc/config/wshaper
51
+endef
52
+
53
+define Package/wshaper/conffiles
54
+/etc/config/wshaper
55
+endef
56
+
57
+$(eval $(call BuildPackage,wshaper))

+ 4
- 0
net/wshaper/files/wshaper.config Прегледај датотеку

@@ -0,0 +1,4 @@
1
+config 'wshaper' 'settings'
2
+	option 'network' 'wan'
3
+	option 'downlink' '2000'
4
+	option 'uplink' '240'

+ 161
- 0
net/wshaper/files/wshaper.htb Прегледај датотеку

@@ -0,0 +1,161 @@
1
+#!/bin/sh
2
+# Wonder Shaper
3
+# please read the README before filling out these values 
4
+#
5
+# Set the following values to somewhat less than your actual download
6
+# and uplink speed. In kilobits. Also set the device that is to be shaped.
7
+
8
+# All config needs to be done in /etc/config/wshaper
9
+
10
+. /lib/functions.sh
11
+config_load wshaper
12
+for s in downlink uplink network nopriohostdst nopriohostsrc noprioportdst noprioportsrc; do
13
+	config_get $s settings $s
14
+done
15
+
16
+device=$(uci_get_state network "$network" ifname "$network")
17
+[ -z "$device" ] && logger -t wondershaper "Error: Could not find the device for network $network, aborting." && exit 1
18
+[ -z "$downlink" ] && logger -t wondershaper "Error: Downlink speed not set, aborting." && exit 1
19
+[ -z "$uplink" ] && logger -t wondershaper "Error: Uplink speed not set, aborting." && exit 1
20
+
21
+MODULES='sch_ingress sch_sfq sch_htb cls_u32 act_police'
22
+DOWNLINK="$downlink"
23
+UPLINK="$uplink"
24
+DEV="$device"
25
+
26
+# low priority OUTGOING traffic - you can leave this blank if you want
27
+# low priority source netmasks
28
+NOPRIOHOSTSRC="$nopriohostsrc"
29
+
30
+# low priority destination netmasks
31
+NOPRIOHOSTDST="$nopriohostdst"
32
+
33
+# low priority source ports
34
+NOPRIOPORTSRC="$noprioportsrc"
35
+
36
+# low priority destination ports
37
+NOPRIOPORTDST="$noprioportdst"
38
+
39
+if [ "$1" = "status" ]
40
+then
41
+	tc -s qdisc ls dev $DEV
42
+	tc -s class ls dev $DEV
43
+	exit
44
+fi
45
+
46
+
47
+# clean existing down- and uplink qdiscs, hide errors
48
+tc qdisc del dev $DEV root    2> /dev/null > /dev/null
49
+tc qdisc del dev $DEV ingress 2> /dev/null > /dev/null
50
+
51
+if [ "$1" = "stop" ] 
52
+then 
53
+	for i in $MODULES ; do
54
+		rmmod $i
55
+	done
56
+	exit
57
+fi
58
+
59
+for i in $MODULES ; do
60
+        insmod $i
61
+done
62
+
63
+###### uplink
64
+
65
+# install root HTB, point default traffic to 1:20:
66
+
67
+tc qdisc add dev $DEV root handle 1: htb default 20
68
+
69
+# shape everything at $UPLINK speed - this prevents huge queues in your
70
+# DSL modem which destroy latency:
71
+
72
+tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit burst 6k
73
+
74
+# high prio class 1:10:
75
+
76
+tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit \
77
+   burst 6k prio 1
78
+
79
+# bulk & default class 1:20 - gets slightly less traffic, 
80
+# and a lower priority:
81
+
82
+tc class add dev $DEV parent 1:1 classid 1:20 htb rate $((9*$UPLINK/10))kbit \
83
+   burst 6k prio 2
84
+
85
+tc class add dev $DEV parent 1:1 classid 1:30 htb rate $((8*$UPLINK/10))kbit \
86
+   burst 6k prio 2
87
+
88
+# all get Stochastic Fairness:
89
+tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
90
+tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
91
+tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10
92
+
93
+# TOS Minimum Delay (ssh, NOT scp) in 1:10:
94
+
95
+tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
96
+      match ip tos 0x10 0xff  flowid 1:10
97
+
98
+# ICMP (ip protocol 1) in the interactive class 1:10 so we 
99
+# can do measurements & impress our friends:
100
+tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
101
+        match ip protocol 1 0xff flowid 1:10
102
+
103
+# To speed up downloads while an upload is going on, put ACK packets in
104
+# the interactive class:
105
+
106
+tc filter add dev $DEV parent 1: protocol ip prio 10 u32 \
107
+   match ip protocol 6 0xff \
108
+   match u8 0x05 0x0f at 0 \
109
+   match u16 0x0000 0xffc0 at 2 \
110
+   match u8 0x10 0xff at 33 \
111
+   flowid 1:10
112
+
113
+# rest is 'non-interactive' ie 'bulk' and ends up in 1:20
114
+
115
+# some traffic however suffers a worse fate
116
+for a in $NOPRIOPORTDST
117
+do
118
+	tc filter add dev $DEV parent 1: protocol ip prio 14 u32 \
119
+	   match ip dport $a 0xffff flowid 1:30
120
+done
121
+
122
+for a in $NOPRIOPORTSRC
123
+do
124
+ 	tc filter add dev $DEV parent 1: protocol ip prio 15 u32 \
125
+	   match ip sport $a 0xffff flowid 1:30
126
+done
127
+
128
+for a in $NOPRIOHOSTSRC
129
+do
130
+ 	tc filter add dev $DEV parent 1: protocol ip prio 16 u32 \
131
+	   match ip src $a flowid 1:30
132
+done
133
+
134
+for a in $NOPRIOHOSTDST
135
+do
136
+ 	tc filter add dev $DEV parent 1: protocol ip prio 17 u32 \
137
+	   match ip dst $a flowid 1:30
138
+done
139
+
140
+# rest is 'non-interactive' ie 'bulk' and ends up in 1:20
141
+
142
+tc filter add dev $DEV parent 1: protocol ip prio 18 u32 \
143
+   match ip dst 0.0.0.0/0 flowid 1:20
144
+
145
+
146
+########## downlink #############
147
+# slow downloads down to somewhat less than the real speed  to prevent 
148
+# queuing at our ISP. Tune to see how high you can set it.
149
+# ISPs tend to have *huge* queues to make sure big downloads are fast
150
+#
151
+# attach ingress policer:
152
+
153
+tc qdisc add dev $DEV handle ffff: ingress
154
+
155
+# filter *everything* to it (0.0.0.0/0), drop everything that's
156
+# coming in too fast:
157
+
158
+tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
159
+   0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1
160
+
161
+logger -t wondershaper "Wondershaper was started on device $device."

+ 10
- 0
net/wshaper/files/wshaper.init Прегледај датотеку

@@ -0,0 +1,10 @@
1
+#!/bin/sh /etc/rc.common
2
+
3
+START=45
4
+start() {
5
+	wshaper.htb
6
+}
7
+
8
+stop() {
9
+	wshaper.htb stop
10
+}