]> git.proxmox.com Git - mirror_iproute2.git/blame - doc/actions/actions-general
add include/linux/hdlc/ioctl.h
[mirror_iproute2.git] / doc / actions / actions-general
CommitLineData
143969f2
SH
1
2This documented is slightly dated but should give you idea of how things
3work.
4
5What is it?
6-----------
7
8An extension to the filtering/classification architecture of Linux Traffic
9Control.
10Up to 2.6.8 the only action that could be "attached" to a filter was policing.
11i.e you could say something like:
12
13-----
14tc filter add dev lo parent ffff: protocol ip prio 10 u32 match ip src \
15127.0.0.1/32 flowid 1:1 police mtu 4000 rate 1500kbit burst 90k
16-----
17
18which implies "if a packet is seen on the ingress of the lo device with
19a source IP address of 127.0.0.1/32 we give it a classification id of 1:1 and
20we execute a policing action which rate limits its bandwidth utilization
21to 1.5Mbps".
22
23The new extensions allow for more than just policing actions to be added.
24They are also fully backward compatible. If you have a kernel that doesnt
25understand them, then the effect is null i.e if you have a newer tc
26but older kernel, the actions are not installed. Likewise if you
27have a newer kernel but older tc, obviously the tc will use current
28syntax which will work fine. Of course to get the required effect you need
29both newer tc and kernel. If you are reading this you have the
30right tc ;->
31
32A side effect is that we can now get stateless firewalling to work with tc.
33Essentially this is now an alternative to iptables.
34I wont go into details of my dislike for iptables at times, but
35scalability is one of the main issues; however, if you need stateful
36classification - use netfilter (for now).
37
38This stuff works on both ingress and egress qdiscs.
39
40Features
41--------
42
431) new additional syntax and actions enabled. Note old syntax is still valid.
44
45Essentially this is still the same syntax as tc with a new construct
46"action". The syntax is of the form:
47tc filter add <DEVICE> parent 1:0 protocol ip prio 10 <Filter description>
48flowid 1:1 action <ACTION description>*
49
50You can have as many actions as you want (within sensible reasoning).
51
52In the past the only real action was the policer; i.e you could do something
53along the lines of:
54tc filter add dev lo parent ffff: protocol ip prio 10 u32 \
55match ip src 127.0.0.1/32 flowid 1:1 \
56police mtu 4000 rate 1500kbit burst 90k
57
58Although you can still use the same syntax, now you can say:
59
60tc filter add dev lo parent 1:0 protocol ip prio 10 u32 \
61match ip src 127.0.0.1/32 flowid 1:1 \
62action police mtu 4000 rate 1500kbit burst 90k
63
64" generic Actions" (gact) at the moment are:
65{ drop, pass, reclassify, continue}
66(If you have others, no listed here give me a reason and we will add them)
67+drop says to drop the packet
a3572a76 68+pass and ok (are equivalent) says to accept it
143969f2
SH
69+reclassify requests for reclassification of the packet
70+continue requests for next lookup to match
71
722)In order to take advantage of some of the targets written by the
73iptables people, a classifier can have a packet being massaged by an
74iptable target. I have only tested with mangler targets up to now.
75(infact anything that is not in the mangling table is disabled right now)
76
77In terms of hooks:
78*ingress is mapped to pre-routing hook
79*egress is mapped to post-routing hook
80I dont see much value in the other hooks, if you see it and email me good
81reasons, the addition is trivial.
82
83Example syntax for iptables targets usage becomes:
84tc filter add ..... u32 <u32 syntax> action ipt -j <iptables target syntax>
85
86example:
87tc filter add dev lo parent ffff: protocol ip prio 8 u32 \
88match ip dst 127.0.0.8/32 flowid 1:12 \
89action ipt -j mark --set-mark 2
90
913) A feature i call pipe
92The motivation is derived from Unix pipe mechanism but applied to packets.
93Essentially take a matching packet and pass it through
94action1 | action2 | action3 etc.
95You could do something similar to this with the tc policer and the "continue"
96operator but this rather restricts it to just the policer and requires
97multiple rules (and lookups, hence quiet inefficient);
98
99as an example -- and please note that this is just an example _not_ The
100Word Youve Been Waiting For (yes i have had problems giving examples
101which ended becoming dogma in documents and people modifying them a little
102to look clever);
103
104i selected the metering rates to be small so that i can show better how
105things work.
106
107The script below does the following:
108- an incoming packet from 10.0.0.21 is first given a firewall mark of 1.
109
110- It is then metered to make sure it does not exceed its allocated rate of
1111Kbps. If it doesnt exceed rate, this is where we terminate action execution.
112
113- If it does exceed its rate, its "color" changes to a mark of 2 and it is
114then passed through a second meter.
115
116-The second meter is shared across all flows on that device [i am suprised
117that this seems to be not a well know feature of the policer; Bert was telling
118me that someone was writing a qdisc just to do sharing across multiple devices;
119it must be the summer heat again; weve had someone doing that every year around
120summer -- the key to sharing is to use a operator "index" in your policer
121rules (example "index 20"). All your rules have to use the same index to
122share.]
123
124-If the second meter is exceeded the color of the flow changes further to 3.
125
126-We then pass the packet to another meter which is shared across all devices
127in the system. If this meter is exceeded we drop the packet.
128
129Note the mark can be used further up the system to do things like policy
130or more interesting things on the egress.
131
132------------------ cut here -------------------------------
133#
134# Add an ingress qdisc on eth0
135tc qdisc add dev eth0 ingress
136#
137#if you see an incoming packet from 10.0.0.21
138tc filter add dev eth0 parent ffff: protocol ip prio 1 \
139u32 match ip src 10.0.0.21/32 flowid 1:15 \
140#
141# first give it a mark of 1
142action ipt -j mark --set-mark 1 index 2 \
143#
144# then pass it through a policer which allows 1kbps; if the flow
145# doesnt exceed that rate, this is where we stop, if it exceeds we
146# pipe the packet to the next action
147action police rate 1kbit burst 9k pipe \
148#
149# which marks the packet fwmark as 2 and pipes
150action ipt -j mark --set-mark 2 \
151#
152# next attempt to borrow b/width from a meter
153# used across all flows incoming on eth0("index 30")
154# and if that is exceeded we pipe to the next action
155action police index 30 mtu 5000 rate 1kbit burst 10k pipe \
156# mark it as fwmark 3 if exceeded
157action ipt -j mark --set-mark 3 \
158# and then attempt to borrow from a meter used by all devices in the
159# system. Should this be exceeded, drop the packet on the floor.
160action police index 20 mtu 5000 rate 1kbit burst 90k drop
161---------------------------------
162
163Now lets see the actions installed with
164"tc filter show parent ffff: dev eth0"
165
166-------- output -----------
167jroot# tc filter show parent ffff: dev eth0
168filter protocol ip pref 1 u32
169filter protocol ip pref 1 u32 fh 800: ht divisor 1
170filter protocol ip pref 1 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:15
171
172 action order 1: tablename: mangle hook: NF_IP_PRE_ROUTING
173 target MARK set 0x1 index 2
174
175 action order 2: police 1 action pipe rate 1Kbit burst 9Kb mtu 2Kb
176
177 action order 3: tablename: mangle hook: NF_IP_PRE_ROUTING
178 target MARK set 0x2 index 1
179
180 action order 4: police 30 action pipe rate 1Kbit burst 10Kb mtu 5000b
181
182 action order 5: tablename: mangle hook: NF_IP_PRE_ROUTING
183 target MARK set 0x3 index 3
184
185 action order 6: police 20 action drop rate 1Kbit burst 90Kb mtu 5000b
186
187 match 0a000015/ffffffff at 12
188-------------------------------
189
190Note the ordering of the actions is based on the order in which we entered
191them. In the future i will add explicit priorities.
192
193Now lets run a ping -f from 10.0.0.21 to this host; stop the ping after
194you see a few lines of dots
195
196----
197[root@jzny hadi]# ping -f 10.0.0.22
198PING 10.0.0.22 (10.0.0.22): 56 data bytes
199....................................................................................................................................................................................................................................................................................................................................................................................................................................................
200--- 10.0.0.22 ping statistics ---
2012248 packets transmitted, 1811 packets received, 19% packet loss
202round-trip min/avg/max = 0.7/9.3/20.1 ms
203-----------------------------
204
205Now lets take a look at the stats with "tc -s filter show parent ffff: dev eth0"
206
207--------------
208jroot# tc -s filter show parent ffff: dev eth0
209filter protocol ip pref 1 u32
210filter protocol ip pref 1 u32 fh 800: ht divisor 1
211filter protocol ip pref 1 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1
2125
213
214 action order 1: tablename: mangle hook: NF_IP_PRE_ROUTING
215 target MARK set 0x1 index 2
216 Sent 188832 bytes 2248 pkts (dropped 0, overlimits 0)
217
218 action order 2: police 1 action pipe rate 1Kbit burst 9Kb mtu 2Kb
219 Sent 188832 bytes 2248 pkts (dropped 0, overlimits 2122)
220
221 action order 3: tablename: mangle hook: NF_IP_PRE_ROUTING
222 target MARK set 0x2 index 1
223 Sent 178248 bytes 2122 pkts (dropped 0, overlimits 0)
224
225 action order 4: police 30 action pipe rate 1Kbit burst 10Kb mtu 5000b
226 Sent 178248 bytes 2122 pkts (dropped 0, overlimits 1945)
227
228 action order 5: tablename: mangle hook: NF_IP_PRE_ROUTING
229 target MARK set 0x3 index 3
230 Sent 163380 bytes 1945 pkts (dropped 0, overlimits 0)
231
232 action order 6: police 20 action drop rate 1Kbit burst 90Kb mtu 5000b
233 Sent 163380 bytes 1945 pkts (dropped 0, overlimits 437)
234
235 match 0a000015/ffffffff at 12
236-------------------------------
237
238Neat, eh?
239
240
241Wanna write an action module?
242------------------------------
243Its easy. Either look at the code or send me email. I will document at
244some point; will also accept documentation.
245
246TODO
247----
248
249Lotsa goodies/features coming. Requests also being accepted.
250At the moment the focus has been on getting the architecture in place.
251Expect new things in the spurious time i have to work on this
252(particularly around end of year when i have typically get time off
253from work).
254