]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/htb-init/htb-init-0.8.5/htb.init+ingress+predef+verbose.diff
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / htb-init / htb-init-0.8.5 / htb.init+ingress+predef+verbose.diff
1 --- htb.init-v0.8.5     2004-10-25 11:01:42.000000000 +0200
2 +++ htb 2004-10-25 18:26:29.720551256 +0200
3 @@ -27,6 +27,12 @@
4  #
5  # VERSION HISTORY
6  # ---------------
7 +#      - Bruno Randolf <bruno.randolf at 4g-systems.biz>
8 +#        - added ingress limiting
9 +#        - added predefined PREDEF filter rules
10 +#        - added PROTOCOL filter rule
11 +#        - added TOS filter rule
12 +#        - added VERBOSE option
13  # v0.8.5- Nathan Shafer <nicodemus at users.sourceforge.net>
14  #        - allow symlins to class files
15  #      - Seth J. Blank <antifreeze at users.sourceforge.net>
16 @@ -175,6 +181,14 @@
17  #      fairness but allows HTB to be used on very fast network devices.
18  #      This is turned off by default.
19  #
20 +# INGRESS=<speed>                              optional
21 +# INGRESS=900Kbit
22 +#
23 +#      This parameters activates the limiting of incoming traffic. 
24 +#      Everything exceeding this rate will be dropped. This can be
25 +#      useful to keep the queues of DSL modems empty to allow
26 +#      low latency interactive traffic.
27 +#
28  ### HTB class parameters
29  #
30  # The following are parameters for HTB classes and are expected
31 @@ -334,6 +348,17 @@
32  #      use multiple MARK fields per config.
33  #
34  #
35 +#
36 +# PREDEF=ack|icmp|ssh-interactive|ssh-scp
37 +#
38 +#      This are some predefined u32 filters.
39 +#      * ack: small acknowledgement packets
40 +#      * icmp: icmp packets
41 +#      * ssh-interactive: interactive SSH sessions (not scp)
42 +#      * ssh-scp: ssh file transfer (scp)
43 +#
44 +#
45 +#
46  # Note:        Rules for different filter types can be combined. Attention must be
47  #      paid to the priority of filter rules, which can be set below through
48  #      the PRIO_{RULE,MARK,REALM} variables.
49 @@ -427,15 +452,17 @@
50  
51  ### Modules to probe for. Uncomment the last HTB_PROBE
52  ### line if you have QoS support compiled into kernel
53 -HTB_PROBE="sch_htb sch_sfq cls_fw cls_u32 cls_route"
54 +HTB_PROBE="sch_htb sch_sfq cls_fw cls_u32 cls_route sch_ingress"
55  #HTB_PROBE=""
56  
57  ### Config keywords
58 -HTB_QDISC="DEFAULT\|DCACHE\|R2Q"
59 +HTB_QDISC="DEFAULT\|DCACHE\|R2Q\|INGRESS"
60  HTB_CLASS="RATE\|CEIL\|BURST\|CBURST\|PRIO\|LEAF\|MTU"
61  HTB_CLASS="$HTB_CLASS\|PRIO_RULE\|PRIO_MARK\|PRIO_REALM"
62  HTB_CLASS="$HTB_CLASS\|LIMIT\|QUANTUM\|PERTURB"
63  
64 +### uncomment to print some info while setting up
65 +#VERBOSE="yes"
66  
67  #############################################################################
68  ############################# SUPPORT FUNCTIONS #############################
69 @@ -565,6 +592,7 @@
70  ### Remove root class from device $1
71  htb_device_off () {
72         tc qdisc del dev $1 root 2> /dev/null
73 +       tc qdisc del dev $1 ingress 2> /dev/null
74  } # htb_device_off
75  
76  
77 @@ -605,7 +633,7 @@
78  
79  ### Display traffic control setup
80  htb_show () {
81 -       for dev in `all_device_list`; do
82 +       for dev in `htb_device_list`; do
83                 [ `tc qdisc show dev $dev| wc -l` -eq 0 ] && continue
84                 echo -e "### $dev: queueing disciplines\n"
85                 tc $1 qdisc show dev $dev; echo
86 @@ -701,6 +729,10 @@
87                 echo "$TC $@"
88         } # tc
89  
90 +       print () {
91 +               echo "[ -n \"\$VERBOSE\" ] && echo '$@'"
92 +       }
93 +       
94  elif [ -n "$HTB_DEBUG" ]; then
95         echo -e "# `date`" > $HTB_DEBUG
96  
97 @@ -715,6 +747,11 @@
98                 echo -e "\n# tc $@" >> $HTB_DEBUG
99                 $TC "$@" 2>&1 | tee -a $HTB_DEBUG
100         } # tc
101 +       
102 +       print () {
103 +               echo -e "\n# [ -n \"\$VERBOSE\" ] && echo '$@'" >> $HTB_DEBUG
104 +               [ -n "$VERBOSE" ] && echo "$@"
105 +       }
106  else
107         # default wrappers
108         
109 @@ -725,6 +762,11 @@
110         tc () {
111                 $TC "$@"
112         } # tc
113 +       
114 +       print () {
115 +               [ -n "$VERBOSE" ] && echo "$@"
116 +       }
117 +
118  fi # ip/tc wrappers
119  
120  
121 @@ -768,6 +810,7 @@
122  [ -z "$DEVICES" ] && htb_failure "no configured devices found!"
123  
124  for dev in $DEVICES; do
125 +       print "setting up $dev..."
126         ### Retrieve root qdisc options
127         DEFAULT=""; DCACHE=""; R2Q=""
128         eval `htb_filter_file $dev| grep "^\($HTB_QDISC\)="`
129 @@ -781,6 +824,15 @@
130         default ${DEFAULT:-0} ${R2Q:+r2q $R2Q} $DCACHE ||
131                 htb_fail_off "failed to set root qdisc on $dev!"
132  
133 +       # attach ingress filter
134 +       if [ "$INGRESS" != "" ]; then
135 +               print " shaping incoming traffic to $INGRESS"
136 +               tc qdisc add dev $dev handle ffff: ingress
137 +               # drop everything that's coming in too fast:
138 +               tc filter add dev $dev parent ffff: protocol ip prio 50 u32 match ip src \
139 +               0.0.0.0/0 police rate ${INGRESS} burst 10k drop flowid :1
140 +       fi
141 +       
142         [ "$1" = "compile" ] && echo
143  done # dev
144  
145 @@ -789,6 +841,8 @@
146  for classfile in `htb_class_list`; do
147         htb_load_class $classfile
148  
149 +       print " class $CLASS (rate: $RATE, ceil: $CEIL)"
150 +       
151         ### Create the class
152         tc class add dev $DEVICE parent 1:$PARENT classid 1:$CLASS \
153         htb rate $RATE ${CEIL:+ceil $CEIL} ${BURST:+burst $BURST} \
154 @@ -813,6 +867,7 @@
155  
156         ### Create fw filter for MARK fields
157         for mark in `htb_cfile_rules MARK`; do
158 +               print "  mark $mark"
159                 ### Attach fw filter to root class
160                 tc filter add dev $DEVICE parent 1:0 protocol ip \
161                 prio $PRIO_MARK handle $mark fw classid 1:$CLASS
162 @@ -827,6 +882,7 @@
163                 ### Convert asterisks to empty strings
164                 SREALM=${SREALM#\*}; DREALM=${DREALM#\*}
165  
166 +               print "  realm $SREALM $DREALM"
167                 ### Attach route filter to the root class
168                 tc filter add dev $DEVICE parent 1:0 protocol ip \
169                 prio $PRIO_REALM route ${SREALM:+from $SREALM} \
170 @@ -870,12 +926,68 @@
171  
172                 ### Uncomment the following if you want to see parsed rules
173                 #echo "$rule: $u32_s $u32_d"
174 +               print "  source: $SRC dest: $DST"
175  
176                 ### Attach u32 filter to the appropriate class
177                 tc filter add dev $DEVICE parent 1:0 protocol ip \
178                 prio $PRIO_RULE u32 $u32_s $u32_d classid 1:$CLASS
179         done ### rule
180  
181 +       ### Create u32 filter for TOS fields
182 +       for tos in `htb_cfile_rules TOS`; do
183 +               ### Attach to root class
184 +               print "  tos $tos"
185 +               tc filter add dev $DEVICE parent 1:0 protocol ip \
186 +               prio $PRIO_RULE u32 match ip tos $tos 0xff classid 1:$CLASS
187 +       done ### tos
188 +       
189 +       ### Create u32 filter for PROTOCOL fields
190 +       for p in `htb_cfile_rules PROTOCOL`; do
191 +               ### Attach to root class
192 +               print "  protocol $p"
193 +               tc filter add dev $DEVICE parent 1:0 protocol ip \
194 +               prio $PRIO_RULE u32 match ip protocol $p 0xff classid 1:$CLASS
195 +        done ### protocol
196 +
197 +       ### some predefined u32 filters for convenience
198 +       for a in `htb_cfile_rules PREDEF`; do
199 +               case "$a" in
200 +               "ack")
201 +                       print "  ACK"
202 +                       # IP protocol 6,
203 +                       # IP header length 0x5(32 bit words),
204 +                       # IP Total length 0x34 (ACK + 12 bytes of TCP options)
205 +                       # TCP ack set (bit 5, offset 33)
206 +                       tc filter add dev $DEVICE parent 1:0 protocol ip \
207 +                       prio $PRIO_RULE u32 \
208 +                       match ip protocol 6 0xff \
209 +                       match u8 0x05 0x0f at 0 \
210 +                       match u16 0x0000 0xffc0 at 2 \
211 +                       match u8 0x10 0xff at 33 \
212 +                       classid 1:$CLASS
213 +                       ;;
214 +               "icmp")
215 +                       print "  ICMP"
216 +                       tc filter add dev $DEVICE parent 1:0 protocol ip \
217 +                       prio $PRIO_RULE u32 match ip protocol 1 0xff classid 1:$CLASS
218 +                       ;;
219 +               "ssh-interactive")
220 +                       print "  ssh-interactive"
221 +                       tc filter add dev $DEVICE parent 1:0 protocol ip \
222 +                       prio $PRIO_RULE u32 \
223 +                       match ip dport 22 0xffff \
224 +                       match ip tos 0x10 0xff classid 1:$CLASS
225 +                       ;;
226 +               "ssh-scp")
227 +                       print "  scp"
228 +                       tc filter add dev $DEVICE parent 1:0 protocol ip \
229 +                       prio $PRIO_RULE u32 \
230 +                       match ip dport 22 0xffff \
231 +                       match ip tos 0x08 0xff classid 1:$CLASS
232 +                       ;;
233 +               esac
234 +       done
235 +       
236         [ "$1" = "compile" ] && echo
237  done ### classfile
238  ;;