some more changes
[lartc.git] / lartc.db
blob754742db1e283c160cd38f042142bf60fcc5879e
1 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
2 <!-- $Id$ -->
3 <Book id="lartc">
4 <?dbhtml banner-text="Made possible by PowerDNS">
5 <?dbhtml banner-href="http://www.powerdns.com">
7   <bookinfo>
8     <Title>Linux Advanced Routing &amp; Traffic Control HOWTO</Title>
9     <authorgroup>
10       <author>
11         <FirstName>Bert</FirstName><Surname>Hubert</Surname>
12         <affiliation>
13           <orgname>Netherlabs BV</orgname>
14           <address><email>bert.hubert@netherlabs.nl</email></address>
15         </affiliation>
16         </author>
18      <collab>
19        <collabname>Gregory Maxwell</collabname>
20         <affiliation>
21           <address><email>greg@linuxpower.cx</email></address>
22         </affiliation>
23      </collab>
24   
25      <collab>
26        <collabname>Remco van Mook</collabname>
27         <affiliation>
28           <address><email>remco@virtu.nl</email></address>
29         </affiliation>
30      </collab>
31   
32      <collab>
33        <collabname>Martijn van Oosterhout</collabname>
34         <affiliation>
35           <address><email>kleptog@cupid.suninternet.com</email></address>
36         </affiliation>
37      </collab>
38   
39      <collab>
40        <collabname>Paul B Schroeder</collabname>
41         <affiliation>
42           <address><email>paulsch@us.ibm.com</email></address>
43         </affiliation>
44      </collab>
45   
46      <collab>
47        <collabname>Jasper Spaans</collabname>
48         <affiliation>
49           <address><email>jasper@spaans.ds9a.nl</email></address>
50         </affiliation>
51      </collab>
52       </authorgroup>
53   
54    <revhistory>
55      <revision>
56        <revnumber role="rcs">$Revision$</revnumber>
57        <date role="rcs">$Date$</date>
58        <revremark>DocBook Edition</revremark>
59      </revision>
60    </revhistory>
61                                    
62    <Abstract>
63      <Para>A very hands-on approach to <application>iproute2</application>,
64      traffic shaping and a bit of <application>netfilter</application>.
65      </para>
66    </Abstract>
67   
68 </bookinfo>
69 <toc></toc>
70 <chapter id="lartc.dedication">
71     <Title>Dedication</Title>
73     <Para>
74       This document is dedicated to lots of people, and is my attempt to do
75       something back. To list but a few:
76     </Para>
78     <Para>
80       <ItemizedList>
81         <ListItem>
82           <Para>
83             Rusty Russell
84           </Para>
85         </ListItem>
86         <ListItem>
88           <Para>
89             Alexey N. Kuznetsov
90           </Para>
91         </ListItem>
92         <ListItem>
93           
94           <Para>
95             The good folks from Google
96           </Para>
97         </ListItem>
98         <ListItem>
99           
100           <Para>
101             The staff of Casema Internet
102           </Para>
103         </ListItem>
105       </ItemizedList>
106         
107     </Para>
109   </chapter>
111   <chapter id="lartc.intro">
112     <Title>Introduction</Title>
114 <Para>
115 Welcome, gentle reader.
116 </Para>
118 <Para>
119       This document hopes to enlighten you on how to do more with Linux 2.2/2.4
120       routing. Unbeknownst to most users, you already run tools which allow you to
121       do spectacular things. Commands like <command>route</command> and 
122       <command>ifconfig</command> are actually
123       very thin wrappers for the very powerful iproute2 infrastructure.
124 </Para>
126     <Para>
127       I hope that this HOWTO will become as readable as the ones by Rusty Russell
128       of (amongst other things) netfilter fame.
129     </Para>
131     <Para>
132       You can always reach us by writing to the <ULink
133         URL="mailto:HOWTO@ds9a.nl"
134         >HOWTO team</ULink
135         >. However, please consider posting to the mailing
136       list (see the relevant section) if you have questions which are not directly
137       related to this HOWTO. We are no free helpdesk, but we often will answer questions
138       asked on the list.
139 </Para>
141 <Para>
142 Before losing your way in this HOWTO, if all you want to do is simple
143 traffic shaping, skip everything and head to the <citetitle><xref linkend="lartc.other"></citetitle> chapter, and read about CBQ.init.
144 </Para>
146 <Sect1 id="lartc.intro.disclaimer">
147 <Title>Disclaimer &amp; License</Title>
149 <Para>
150 This document is distributed in the hope that it will be useful,
151 but WITHOUT ANY WARRANTY; without even the implied warranty of
152 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
153 </Para>
155 <Para>
156 In short, if your STM-64 backbone breaks down and distributes pornography to
157 your most esteemed customers - it's never our fault. Sorry.
158 </Para>
160 <Para>
161 Copyright (c) 2002 by bert hubert, Gregory Maxwell, Martijn van
162 Oosterhout, Remco van Mook, Paul B. Schroeder and others. This material may
163 be distributed only subject to the terms and conditions set forth in the
164 Open Publication License, v1.0 or later (the latest version is presently
165 available at http://www.opencontent.org/openpub/).
166 </Para>
168 <Para>
169 Please freely copy and distribute (sell or give away) this document in any
170 format. It's requested that corrections and/or comments be forwarded to the
171 document maintainer. 
172 </Para>
174 <Para>
175 It is also requested that if you publish this HOWTO in hardcopy that you
176 send the authors some samples for <quote>review purposes</quote> :-) 
177 </Para>
179 </Sect1>
181 <Sect1 id="lartc.intro.prior">
182   <Title>Prior knowledge</Title>
184 <Para>
185 As the title implies, this is the <quote>Advanced</quote> HOWTO.
186 While by no means rocket science, some prior knowledge is assumed. 
187 </Para>
189 <Para>
190 Here are some other references which might help teach you more:
191 <VariableList>
192 <VarListEntry>
193   <Term>
194     <ULink URL="http://netfilter.samba.org/unreliable-guides/networking-concepts-HOWTO/index.html">
195       Rusty Russell's networking-concepts-HOWTO</ULink>
196   </Term>
197   <ListItem>
198     <Para>Very nice introduction, explaining what a network is, and how it is
199     connected to other networks.
200     </Para>
201   </ListItem>
202 </VarListEntry>
203 <VarListEntry>
204   <Term>Linux Networking-HOWTO (Previously the Net-3 HOWTO)</Term>
205   <ListItem>
206     <Para>Great stuff, although very verbose. It teaches you a lot of stuff 
207     that's already configured if you are able to connect to the Internet. 
208     Should be located in <filename>/usr/doc/HOWTO/NET3-4-HOWTO.txt</filename>
209  but can be also be found 
210     <ULink URL="http://www.linuxports.com/howto/networking">online</ULink>.
211     </Para>
212   </ListItem>
213 </VarListEntry>
214 </VariableList>
215 </Para>
217 </Sect1>
219 <Sect1 id="lartc.intro.linux">
220   <Title>What Linux can do for you</Title>
222 <Para>
223 A small list of things that are possible:
224 </Para>
226 <ItemizedList>
227 <ListItem>
228   <Para>Throttle bandwidth for certain computers
229   </Para>
230 </ListItem>
231 <ListItem>
232   <Para>Throttle bandwidth TO certain computers
233   </Para>
234 </ListItem>
235 <ListItem>
236   <Para>Help you to fairly share your bandwidth
237   </Para>
238 </ListItem>
239 <ListItem>
240   <Para>Protect your network from DoS attacks
241   </Para>
242 </ListItem>
243 <ListItem>
244   <Para>Protect the Internet from your customers
245   </Para>
246 </ListItem>
247 <ListItem>
248   <Para>Multiplex several servers as one, for load balancing or
249   enhanced availability
250   </Para>
251 </ListItem>
252 <ListItem>
253   <Para>Restrict access to your computers
254   </Para>
255 </ListItem>
256 <ListItem>
257   <Para>Limit access of your users to other hosts
258   </Para>
259 </ListItem>
260 <ListItem>
261   <Para>Do routing based on user id (yes!), MAC address, source IP
262   address, port, type of service, time of day or content
263   </Para>
264 </ListItem>
265 </ItemizedList>
267 <Para>
268 Currently, not many people are using these advanced features. This is for
269 several reasons. While the provided documentation is verbose, it is not very
270 hands-on. Traffic control is almost undocumented.
271 </Para>
273 </Sect1>
275 <Sect1 id="lartc.intro.houskeeping">
276   <Title>Housekeeping notes</Title>
278 <Para>
279 There are several things which should be noted about this document. While I
280 wrote most of it, I really don't want it to stay that way. I am a strong
281 believer in Open Source, so I encourage you to send feedback, updates,
282 patches etcetera. Do not hesitate to inform me of typos or plain old errors.
283 If my English sounds somewhat wooden, please realize that I'm not a native
284 speaker. Feel free to send suggestions.
285 </Para>
287 <Para>
288 If you feel to you are better qualified to maintain a section, or think that
289 you can author and maintain new sections, you are welcome to do so. The SGML
290 of this HOWTO is available via CVS, I very much envision more people
291 working on it.
292 </Para>
294 <Para>
295 In aid of this, you will find lots of FIXME notices. Patches are always
296 welcome! Wherever you find a FIXME, you should know that you are treading in
297 unknown territory. This is not to say that there are no errors elsewhere,
298 but be extra careful. If you have validated something, please let us know so
299 we can remove the FIXME notice.
300 </Para>
302 <Para>
303 About this HOWTO, I will take some liberties along the road. For example, I
304 postulate a 10Mbit Internet connection, while I know full well that those
305 are not very common.
306 </Para>
308 </Sect1>
310 <Sect1 id="lartc.intro.cvs">
311   <Title>Access, CVS &amp; submitting updates</Title>
313 <Para>
314 The canonical location for the HOWTO is 
315 <ULink URL="http://www.ds9a.nl/lartc">here</ULink>.
316 </Para>
318 <Para>
319 We now have anonymous CVS access available to the world at large. This is
320 good in a number of ways. You can easily upgrade to newer versions of this
321 HOWTO and submitting patches is no work at all.
322 </Para>
324 <Para>
325 Furthermore, it allows the authors to work on the source independently,
326 which is good too.
327 </Para>
329 <Screen width="80">
330 $ export CVSROOT=:pserver:anon@outpost.ds9a.nl:/var/cvsroot
331 $ cvs login
332 CVS password: [enter 'cvs' (without 's)]
333 $ cvs co 2.4routing
334 cvs server: Updating 2.4routing
335 U 2.4routing/lartc.db
336 </Screen>
338 <Para>
339 If you made changes and want to contribute them, run <userinput>
340 cvs -z3 diff -uBb</userinput>,
341 and mail the output to <email>howto@ds9a.nl</email>, we
342 can then integrate it easily. Thanks! Please make sure that you edit the
343 .db file, by the way, the other files are generated from that one. 
344 </Para>
346 <Para>
347 A Makefile is supplied which should help you create postscript, dvi, pdf,
348 html and plain text. You may need to install 
349 <application>docbook</application>, <application>docbook-utils</application>,
350 <application>ghostscript</application> and <application>tetex</application> 
351 to get all formats.
352 </Para>
354 <para>
355 Be careful not to edit 2.4routing.sgml! It contains an older version of the
356 HOWTO. The right file is lartc.db.
357 </para>
358 </Sect1>
360 <Sect1 id="lartc.intro.mlist">
361   <Title>Mailing list</Title>
363 <Para>
364 The authors receive an increasing amount of mail about this HOWTO. Because
365 of the clear interest of the community, it has been decided to start a
366 mailinglist where people can talk to each other about Advanced Routing and
367 Traffic Control. You can subscribe to the list
368 <ULink URL="http://mailman.ds9a.nl/mailman/listinfo/lartc">here</ULink>.
369 </Para>
371 <Para>
372 It should be pointed out that the authors are very hesitant of answering
373 questions not asked on the list. We would like the archive of the list to
374 become some kind of knowledge base. If you have a question, please search
375 the archive, and then post to the mailinglist.
376 </Para>
378 </Sect1>
380 <Sect1 id="lartc.intro.layout">
381   <Title>Layout of this document</Title>
383 <Para>
384 We will be doing interesting stuff almost immediately, which also means that
385 there will initially be parts that are explained incompletely or are not
386 perfect. Please gloss over these parts and assume that all will become clear.
387 </Para>
389 <Para>
390 Routing and filtering are two distinct things. Filtering is documented very
391 well by Rusty's HOWTOs, available here:
392 </Para>
394 <ItemizedList>
395 <ListItem>
396   <Para><ULink URL="http://netfilter.samba.org/unreliable-guides/">
397     Rusty's Remarkably Unreliable Guides</ULink>
398   </Para>
399 </ListItem>
400 </ItemizedList>
402 <Para>We will be focusing mostly on what is possible by combining netfilter
403 and iproute2.
404 </Para>
406 </Sect1>
408 </chapter>
410 <chapter id="lartc.iproute2">
411   <Title>Introduction to iproute2</Title>
413 <Sect1 id="lartc.iproute2.why">
414   <Title>Why iproute2?</Title>
416 <Para>
417 Most Linux distributions, and most UNIX's, currently use the 
418 venerable <command>arp</command>, <command>ifconfig</command> and 
419 <command>route</command> commands.
420 While these tools work, they show some unexpected behaviour under Linux 2.2 
421 and up.
422 For example, GRE tunnels are an integral part of routing these days, but 
423 require completely different tools.
424 </Para>
426 <Para>
427 With <application>iproute2</application>, tunnels are an integral part of 
428 the tool set.
429 </Para>
431 <Para>
432 The 2.2 and above Linux kernels include a completely redesigned network
433 subsystem. This new networking code brings Linux performance and a feature
434 set with little competition in the general OS arena. In fact, the new
435 routing, filtering, and classifying code is more featureful than the one
436 provided by many dedicated routers and firewalls and traffic shaping
437 products.
438 </Para>
440 <Para>
441 As new networking concepts have been invented, people have found ways to
442 plaster them on top of the existing framework in existing OSes. This
443 constant layering of cruft has lead to networking code that is filled with
444 strange behaviour, much like most human languages. In the past, Linux
445 emulated SunOS's handling of many of these things, which was not ideal.  
446 </Para>
448 <Para>
449 This new framework makes it possible to clearly express features
450 previously beyond Linux's reach.
451 </Para>
453 </Sect1>
455 <Sect1 id="lartc.iproute2.tour">
456   <Title>iproute2 tour</Title>
458 <Para>
459 Linux has a sophisticated system for bandwidth provisioning called Traffic
460 Control. This system supports various method for classifying, prioritizing,
461 sharing, and limiting both inbound and outbound traffic.
462 </Para>
464 <Para>
465 We'll start off with a tiny tour of iproute2 possibilities.
466 </Para>
468 </Sect1>
470 <Sect1 id="lartc.iproute2.package">
471   <Title>Prerequisites</Title>
473 <Para>
474 You should make sure that you have the userland tools installed. This
475 package is called 'iproute' on both RedHat and Debian, and may otherwise be
476 found at <filename>ftp://ftp.inr.ac.ru/ip-routing/iproute2-2.2.4-now-ss??????.tar.gz"</filename>. 
477 </Para>
479 <Para>
480 You can also try 
481 <ULink URL="ftp://ftp.inr.ac.ru/ip-routing/iproute2-current.tar.gz">here</ULink> 
482 for the latest version.
483 </Para>
485 <Para>
486 Some parts of iproute require you to have certain kernel options enabled. It
487 should also be noted that all releases of RedHat up to and including 6.2
488 come without most of the traffic control features in the default kernel. 
489 </Para>
491 <Para>
492 RedHat 7.2 has everything in by default.
493 </Para>
495 <Para>
496 Also make sure that you have netlink support, should you choose to roll your
497 own kernel. Iproute2 needs it.
498 </Para>
500 </Sect1>
502 <Sect1 id="lartc.iproute2.explore">
503   <Title>Exploring your current configuration</Title>
505 <Para>
506 This may come as a surprise, but iproute2 is already configured! The current
507 commands <command>ifconfig</command> and <command>route</command> are already using the advanced
508 syscalls, but mostly with very default (ie. boring) settings.
509 </Para>
511 <Para>
512 The <command>ip</command> tool is central, and we'll ask it to display our interfaces
513 for us.
514 </Para>
516 <Sect2>
517 <Title><command>ip</command> shows us our links</Title>
519 <Screen width="80">
520 [ahu@home ahu]$ ip link list
521 1: lo: &#60;LOOPBACK,UP&#62; mtu 3924 qdisc noqueue 
522     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
523 2: dummy: &#60;BROADCAST,NOARP&#62; mtu 1500 qdisc noop 
524     link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
525 3: eth0: &#60;BROADCAST,MULTICAST,PROMISC,UP&#62; mtu 1400 qdisc pfifo_fast qlen 100
526     link/ether 48:54:e8:2a:47:16 brd ff:ff:ff:ff:ff:ff
527 4: eth1: &#60;BROADCAST,MULTICAST,PROMISC,UP&#62; mtu 1500 qdisc pfifo_fast qlen 100
528     link/ether 00:e0:4c:39:24:78 brd ff:ff:ff:ff:ff:ff
529 3764: ppp0: &#60;POINTOPOINT,MULTICAST,NOARP,UP&#62; mtu 1492 qdisc pfifo_fast qlen 10
530     link/ppp 
532 </Screen>
534 <Para>
535 Your mileage may vary, but this is what it shows on my NAT router at
536 home. I'll only explain part of the output as not everything is directly
537 relevant.
538 </Para>
540 <Para>
541 We first see the loopback interface. While your computer may function
542 somewhat without one, I'd advise against it. The MTU size (Maximum Transfer
543 Unit) is 3924 octets, and it is not supposed to queue. Which makes sense
544 because the loopback interface is a figment of your kernel's imagination.
545 </Para>
547 <Para>
548 I'll skip the dummy interface for now, and it may not be present on your
549 computer. Then there are my two physical network interfaces, one at the side
550 of my cable modem, the other one serves my home ethernet segment.
551 Furthermore, we see a ppp0 interface.
552 </Para>
554 <Para>
555 Note the absence of IP addresses. iproute disconnects the concept of 'links'
556 and 'IP addresses'. With IP aliasing, the concept of 'the' IP address had
557 become quite irrelevant anyhow. 
558 </Para>
560 <Para>
561 It does show us the MAC addresses though, the hardware identifier of our
562 ethernet interfaces.
563 </Para>
565 </Sect2>
567 <Sect2>
568   <Title><command>ip</command> shows us our IP addresses</Title>
570 <Screen width="80">
571 [ahu@home ahu]$ ip address show        
572 1: lo: &#60;LOOPBACK,UP&#62; mtu 3924 qdisc noqueue 
573     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
574     inet 127.0.0.1/8 brd 127.255.255.255 scope host lo
575 2: dummy: &#60;BROADCAST,NOARP&#62; mtu 1500 qdisc noop 
576     link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
577 3: eth0: &#60;BROADCAST,MULTICAST,PROMISC,UP&#62; mtu 1400 qdisc pfifo_fast qlen 100
578     link/ether 48:54:e8:2a:47:16 brd ff:ff:ff:ff:ff:ff
579     inet 10.0.0.1/8 brd 10.255.255.255 scope global eth0
580 4: eth1: &#60;BROADCAST,MULTICAST,PROMISC,UP&#62; mtu 1500 qdisc pfifo_fast qlen 100
581     link/ether 00:e0:4c:39:24:78 brd ff:ff:ff:ff:ff:ff
582 3764: ppp0: &#60;POINTOPOINT,MULTICAST,NOARP,UP&#62; mtu 1492 qdisc pfifo_fast qlen 10
583     link/ppp 
584     inet 212.64.94.251 peer 212.64.94.1/32 scope global ppp0
585 </Screen>
587 <Para>
588 This contains more information. It shows all our addresses, and to which
589 cards they belong. 'inet' stands for Internet (IPv4). There are lots of other
590 address families, but these don't concern us right now.
591 </Para>
593 <Para>
594 Let's examine eth0 somewhat closer. It says that it is related to the inet
595 address '10.0.0.1/8'. What does this mean? The /8 stands for the number of
596 bits that are in the Network Address. There are 32 bits, so we have 24 bits
597 left that are part of our network. The first 8 bits of 10.0.0.1 correspond
598 to 10.0.0.0, our Network Address, and our netmask is 255.0.0.0.
599 </Para>
601 <Para>
602 The other bits are connected to this interface, so 10.250.3.13 is directly
603 available on eth0, as is 10.0.0.1 for example. 
604 </Para>
606 <Para>
607 With ppp0, the same concept goes, though the numbers are different. Its
608 address is 212.64.94.251, without a subnet mask. This means that we have a
609 point-to-point connection and that every address, with the exception of
610 212.64.94.251, is remote. There is more information, however. It tells us
611 that on the other side of the link there is, yet again, only one address,
612 212.64.94.1. The /32 tells us that there are no 'network bits'.
613 </Para>
615 <Para>
616 It is absolutely vital that you grasp these concepts. Refer to the
617 documentation mentioned at the beginning of this HOWTO if you have trouble.
618 </Para>
620 <Para>
621 You may also note 'qdisc', which stands for Queueing Discipline. This will
622 become vital later on. 
623 </Para>
625 </Sect2>
627 <Sect2>
628   <Title><command>ip</command> shows us our routes</Title>
630 <Para>
631 Well, we now know how to find 10.x.y.z addresses, and we are able to reach
632 212.64.94.1. This is not enough however, so we need instructions on how to
633 reach the world. The Internet is available via our ppp connection, and it
634 appears that 212.64.94.1 is willing to spread our packets around the
635 world, and deliver results back to us.
636 </Para>
638 <Screen width="80">
639 [ahu@home ahu]$ ip route show
640 212.64.94.1 dev ppp0  proto kernel  scope link  src 212.64.94.251 
641 10.0.0.0/8 dev eth0  proto kernel  scope link  src 10.0.0.1 
642 127.0.0.0/8 dev lo  scope link 
643 default via 212.64.94.1 dev ppp0 
644 </Screen>
646 <Para>
647 This is pretty much self explanatory. The first 4 lines of output explicitly
648 state what was already implied by <command>ip address show</command>, the last line
649 tells us that the rest of the world can be found via 212.64.94.1, our
650 default gateway. We can see that it is a gateway because of the word
651 via, which tells us that we need to send packets to 212.64.94.1, and that it
652 will take care of things.
653 </Para>
655 <Para>
656 For reference, this is what the old <command>route</command> utility shows us:
657 </Para>
659 <Screen width="80">
660 [ahu@home ahu]$ route -n
661 Kernel IP routing table
662 Destination     Gateway         Genmask         Flags Metric Ref    Use
663 Iface
664 212.64.94.1     0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
665 10.0.0.0        0.0.0.0         255.0.0.0       U     0      0        0 eth0
666 127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
667 0.0.0.0         212.64.94.1     0.0.0.0         UG    0      0        0 ppp0
668 </Screen>
670 </Sect2>
672 </Sect1>
674 <Sect1 id="lartc.iproute2.arp">
675   <Title>ARP</Title>
677 <Para>
678 ARP is the Address Resolution Protocol as described in
679 <ULink URL="http://www.faqs.org/rfcs/rfc826.html">RFC 826</ULink>.
680 ARP is used by a networked machine to resolve the hardware location/address of
681 another machine on the same
682 local network.  Machines on the Internet are generally known by their names
683 which resolve to IP
684 addresses.  This is how a machine on the foo.com network is able to communicate
685 with another machine which is on the bar.net network.  An IP address, though,
686 cannot tell you the physical location of a machine.  This is where ARP comes
687 into the picture.
688 </Para>
690 <Para>
691 Let's take a very simple example.  Suppose I have a network composed of several
692 machines.  Two of the machines which are currently on my network are foo
693 with an IP address of 10.0.0.1 and bar with an IP address of 10.0.0.2.
694 Now foo wants to ping bar to see that he is alive, but alas, foo has no idea
695 where bar is.  So when foo decides to ping bar he will need to send
696 out an ARP request.
697 This ARP request is akin to foo shouting out on the network "Bar (10.0.0.2)!
698 Where are you?"  As a result of this every machine on the network will hear
699 foo shouting, but only bar (10.0.0.2) will respond.  Bar will then send an
700 ARP reply directly back to foo which is akin
701 bar saying,
702 "Foo (10.0.0.1) I am here at 00:60:94:E9:08:12."  After this simple transaction
703 that's used to locate his friend on the network, foo is able to communicate
704 with bar until he (his arp cache) forgets where bar is (typically after
705 15 minutes on Unix).
706 </Para>
708 <Para>
709 Now let's see how this works.
710 You can view your machines current arp/neighbor cache/table like so:
711 </Para>
713 <Screen width="80">
714 [root@espa041 /home/src/iputils]# ip neigh show
715 9.3.76.42 dev eth0 lladdr 00:60:08:3f:e9:f9 nud reachable
716 9.3.76.1 dev eth0 lladdr 00:06:29:21:73:c8 nud reachable
717 </Screen>
719 <Para>
720 As you can see my machine espa041 (9.3.76.41) knows where to find espa042 
721 (9.3.76.42) and
722 espagate (9.3.76.1).  Now let's add another machine to the arp cache.
723 </Para>
725 <Screen width="80">
726 [root@espa041 /home/paulsch/.gnome-desktop]# ping -c 1 espa043
727 PING espa043.austin.ibm.com (9.3.76.43) from 9.3.76.41 : 56(84) bytes of data.
728 64 bytes from 9.3.76.43: icmp_seq=0 ttl=255 time=0.9 ms
730 --- espa043.austin.ibm.com ping statistics ---
731 1 packets transmitted, 1 packets received, 0% packet loss
732 round-trip min/avg/max = 0.9/0.9/0.9 ms
734 [root@espa041 /home/src/iputils]# ip neigh show
735 9.3.76.43 dev eth0 lladdr 00:06:29:21:80:20 nud reachable
736 9.3.76.42 dev eth0 lladdr 00:60:08:3f:e9:f9 nud reachable
737 9.3.76.1 dev eth0 lladdr 00:06:29:21:73:c8 nud reachable
738 </Screen>
740 <Para>
741 As a result of espa041 trying to contact espa043, espa043's hardware
742 address/location has now been added to the arp/neighbor cache.
743 So until the entry for
744 espa043 times out (as a result of no communication between the two) espa041
745 knows where to find espa043 and has no need to send an ARP request.
746 </Para>
748 <Para>
749 Now let's delete espa043 from our arp cache:
750 </Para>
752 <Screen width="80">
753 [root@espa041 /home/src/iputils]# ip neigh delete 9.3.76.43 dev eth0
754 [root@espa041 /home/src/iputils]# ip neigh show
755 9.3.76.43 dev eth0  nud failed
756 9.3.76.42 dev eth0 lladdr 00:60:08:3f:e9:f9 nud reachable
757 9.3.76.1 dev eth0 lladdr 00:06:29:21:73:c8 nud stale
758 </Screen>
760 <Para>
761 Now espa041 has again forgotten where to find espa043 and will need to send
762 another ARP request the next time he needs to communicate with espa043.
763 You can also see from the above output that espagate (9.3.76.1) has been
764 changed to the "stale" state.  This means that the location shown is still
765 valid, but it will have to be confirmed at the first transaction to that
766 machine.
767 </Para>
769 </Sect1>
771 </chapter>
773 <chapter id="lartc.rpdb">
774   <Title>Rules - routing policy database</Title>
776 <Para>
777 If you have a large router, you may well cater for the needs of different
778 people, who should be served differently. The routing policy database allows
779 you to do this by having multiple sets of routing tables. 
780 </Para>
782 <Para>
783 If you want to use this feature, make sure that your kernel is compiled with
784 the "IP: advanced router" and "IP: policy routing" features.
785 </Para>
787 <Para>
788 When the kernel needs to make a routing decision, it finds out which table
789 needs to be consulted. By default, there are three tables. The old 'route'
790 tool modifies the main and local tables, as does the ip tool (by default).
791 </Para>
793 <Para>The default rules:
794 </Para>
796 <Screen width="80">
797 [ahu@home ahu]$ ip rule list
798 0:      from all lookup local 
799 32766:  from all lookup main 
800 32767:  from all lookup default
801 </Screen>
803 <Para>
804 This lists the priority of all rules. We see that all rules apply to all
805 packets ('from all'). We've seen the 'main' table before, it is output by
806 <userinput>ip route ls</userinput>, but the 'local' and 'default' table are new.
807 </Para>
809 <Para>
810 If we want to do fancy things, we generate rules which point to different
811 tables which allow us to override system wide routing rules.
812 </Para>
814 <Para>
815 For the exact semantics on what the kernel does when there are more matching
816 rules, see Alexey's ip-cref documentation. 
817 </Para>
819 <Sect1 id="lartc.rpdb.simple">
820   <Title>Simple source policy routing</Title>
822 <Para>
823 Let's take a real example once again, I have 2 (actually 3, about time I
824 returned them) cable modems, connected to a Linux NAT ('masquerading')
825 router. People living here pay me to use the Internet. Suppose one of my
826 house mates only visits hotmail and wants to pay less. This is fine with me,
827 but they'll end up using the low-end cable modem.
828 </Para>
830 <Para>
831 The 'fast' cable modem is known as 212.64.94.251 and is a PPP link to
832 212.64.94.1. The 'slow' cable modem is known by various ip addresses,
833 212.64.78.148 in this example and is a link to 195.96.98.253.
834 </Para>
836 <Para>The local table:
837 </Para>
839 <Screen width="80">
840 [ahu@home ahu]$ ip route list table local
841 broadcast 127.255.255.255 dev lo  proto kernel  scope link  src 127.0.0.1 
842 local 10.0.0.1 dev eth0  proto kernel  scope host  src 10.0.0.1 
843 broadcast 10.0.0.0 dev eth0  proto kernel  scope link  src 10.0.0.1 
844 local 212.64.94.251 dev ppp0  proto kernel  scope host  src 212.64.94.251 
845 broadcast 10.255.255.255 dev eth0  proto kernel  scope link  src 10.0.0.1 
846 broadcast 127.0.0.0 dev lo  proto kernel  scope link  src 127.0.0.1 
847 local 212.64.78.148 dev ppp2  proto kernel  scope host  src 212.64.78.148 
848 local 127.0.0.1 dev lo  proto kernel  scope host  src 127.0.0.1 
849 local 127.0.0.0/8 dev lo  proto kernel  scope host  src 127.0.0.1 
850 </Screen>
852 <Para>
853 Lots of obvious things, but things that need to be specified somewhere.
854 Well, here they are. The default table is empty.
855 </Para>
857 <Para>Let's view the 'main' table:
858 </Para>
860 <Screen width="80">
861 [ahu@home ahu]$ ip route list table main 
862 195.96.98.253 dev ppp2  proto kernel  scope link  src 212.64.78.148 
863 212.64.94.1 dev ppp0  proto kernel  scope link  src 212.64.94.251 
864 10.0.0.0/8 dev eth0  proto kernel  scope link  src 10.0.0.1 
865 127.0.0.0/8 dev lo  scope link 
866 default via 212.64.94.1 dev ppp0 
867 </Screen>
869 <Para>
870 We now generate a new rule which we call 'John', for our hypothetical
871 house mate. Although we can work with pure numbers, it's far easier if we add
872 our tables to /etc/iproute2/rt_tables.
873 </Para>
875 <Screen width="80">
876 # echo 200 John &#62;&#62; /etc/iproute2/rt_tables
877 # ip rule add from 10.0.0.10 table John
878 # ip rule ls
879 0:      from all lookup local 
880 32765:  from 10.0.0.10 lookup John
881 32766:  from all lookup main 
882 32767:  from all lookup default
883 </Screen>
885 <Para>
886 Now all that is left is to generate John's table, and flush the route cache:
887 </Para>
889 <Screen width="80">
890 # ip route add default via 195.96.98.253 dev ppp2 table John
891 # ip route flush cache
892 </Screen>
894 <Para>
895 And we are done. It is left as an exercise for the reader to implement this
896 in ip-up.
897 </Para>
899 </Sect1>
901 <sect1 id="lartc.rpdb.multiple-links">
902   <title>Routing for multiple uplinks/providers</title>
903 <para>
904 A common configuration is the following, in which there are two providers
905 that connect a local network (or even a single machine) to the big Internet.
907 <screen>
908                                                                  ________
909                                           +------------+        /
910                                           |            |       |
911                             +-------------+ Provider 1 +-------
912         __                  |             |            |     /
913     ___/  \_         +------+-------+     +------------+    |
914   _/        \__      |     if1      |                      /
915  /             \     |              |                      |
916 | Local network -----+ Linux router |                      |     Internet
917  \_           __/    |              |                      |
918    \__     __/       |     if2      |                      \
919       \___/          +------+-------+     +------------+    |
920                             |             |            |     \
921                             +-------------+ Provider 2 +-------
922                                           |            |       |
923                                           +------------+        \________
924 </screen>
925 </para>
926 <para>
927 There are usually two questions given this setup.
928 </para>
929       <sect2><title>Split access</title>
930         <para>
931           The first is how to route answers to packets coming in over a
932           particular provider, say Provider 1, back out again over that same provider.
933         </para>
934         <para>
935           Let us first set some symbolical names. Let <command>$IF1</command> be the name of the
936           first interface (if1 in the picture above) and <command>$IF2</command> the name of the
937           second interface. Then let <command>$IP1</command> be the IP address associated with
938           <command>$IF1</command> and <command>$IP2</command> the IP address associated with
939           <command>$IF2</command>. Next, let <command>$P1</command> be the IP address of the gateway at
940           Provider 1, and <command>$P2</command> the IP address of the gateway at provider 2.
941           Finally, let <command>$P1_NET</command> be the IP network <command>$P1</command> is in,
942           and <command>$P2_NET</command> the IP network <command>$P2</command> is in.
943         </para>
944         <para>
945           One creates two additional routing tables, say <command>T1</command> and <command>T2</command>.
946           These are added in /etc/iproute2/rt_tables. Then you set up routing in
947           these tables as follows:
948         </para>
949         <para>
950         <screen>
951           ip route add $P1_NET dev $IF1 src $IP1 table T1
952           ip route add default via $P1 table T1
953           ip route add $P2_NET dev $IF2 src $IP2 table T2
954           ip route add default via $P2 table T2
955         </screen>
956           
957           Nothing spectacular, just build a route to the gateway and build a
958           default route via that gateway, as you would do in the case of a single
959           upstream provider, but put the routes in a separate table per provider.
960           Note that the network route suffices, as it tells you how to find any host
961           in that network, which includes the gateway, as specified above.
962         </para>
963         <para>
964           Next you set up the main routing table. It is a good idea to route
965           things to the direct neighbour through the interface connected to that
966           neighbour. Note the `src' arguments, they make sure the right outgoing IP
967           address is chosen.
969           <screen>
970             ip route add $P1_NET dev $IF1 src $IP1
971             ip route add $P2_NET dev $IF2 src $IP2
972           </screen>
974           Then, your preference for default route:
975           
976           <screen>
977             ip route add default via $P1
978           </screen>
980           Next, you set up the routing rules. These actually choose what routing table
981           to route with. You want to make sure that you route out a given
982           interface if you already have the corresponding source address:
983           
984           <screen>
985             ip rule add from $IP1 table T1
986             ip rule add from $IP2 table T2
987           </screen>
989           This set of commands makes sure all answers to traffic coming in on a
990           particular interface get answered from that interface.
991         </para>
992         <para>
993           Now, this is just the very basic setup. It will work for all processes
994           running on the router itself, and for the local network, if it is
995           masqueraded. If it is not, then you either have IP space from both providers
996           or you are going to want to masquerade to one of the two providers. In both
997           cases you will want to add rules selecting which provider to route out from
998           based on the IP address of the machine in the local network.
999         </para>
1000       </sect2>
1001       <sect2><title>Load balancing</title>
1002         <para>
1003           The second question is how to balance traffic going out over the two providers.
1004           This is actually not hard if you already have set up split access as above.
1005           </para>
1006         <para>
1007           Instead of choosing one of the two providers as your default route,
1008           you now set up the default route to be a multipath route. In the default
1009           kernel this will balance routes over the two providers. It is done
1010           as follows (once more building on the example in the section on
1011           split-access):
1013           <screen>
1014             ip route add default scope global nexthop via $P1 dev $IF1 weight 1 \
1015             nexthop via $P2 dev $IF2 weight 1
1016           </screen>
1018           This will balance the routes over both providers. The <command>weight</command>
1019           parameters can be tweaked to favor one provider over the other.
1020         </para>
1021         <para>
1022           Note that balancing will not be perfect, as it is route based, and routes
1023           are cached. This means that routes to often-used sites will always
1024           be over the same provider.
1025         </para>
1026         <para>
1027           Furthermore, if you really want to do this, you probably also want to look
1028           at Julian Anastasov's patches at <ulink
1029             url="http://www.linuxvirtualserver.org/~julian/#routes">http://www.linuxvirtualserver.org/~julian/#routes
1030             </ulink>, Julian's route patch page. They will make things nicer to work with.
1031         </para>
1032       </sect2>
1033     </sect1>
1034   </chapter>
1036 <chapter id="lartc.tunnel">
1037    <Title>GRE and other tunnels</Title>
1039 <Para>
1040 There are 3 kinds of tunnels in Linux. There's IP in IP tunneling, GRE tunneling and tunnels that live outside the kernel (like, for example PPTP). 
1041 </Para>
1043 <Sect1 id="lartc.tunnel.remarks">
1044   <Title>A few general remarks about tunnels:</Title>
1046 <Para>
1047 Tunnels can be used to do some very unusual and very cool stuff. They can
1048 also make things go horribly wrong when you don't configure them right.
1049 Don't point your default route to a tunnel device unless you know
1050 <Emphasis>EXACTLY</Emphasis> what you are doing :-). Furthermore, tunneling increases
1051 overhead, because it needs an extra set of IP headers. Typically this is 20
1052 bytes per packet, so if the normal packet size (MTU) on a network is 1500
1053 bytes, a packet that is sent through a tunnel can only be 1480 bytes big.
1054 This is not necessarily a problem, but be sure to read up on IP packet
1055 fragmentation/reassembly when you plan to connect large networks with
1056 tunnels. Oh, and of course, the fastest way to dig a tunnel is to dig at
1057 both sides.
1058 </Para>
1060 </Sect1>
1062 <Sect1 id="lartc.tunnel.ip-ip">
1063   <Title>IP in IP tunneling</Title>
1065 <Para>
1066 This kind of tunneling has been available in Linux for a long time. It requires 2 kernel modules,
1067 ipip.o and new_tunnel.o.
1068 </Para>
1070 <Para>
1071 Let's say you have 3 networks: Internal networks A and B, and intermediate network C (or let's say, Internet). 
1072 So we have network A:
1073 </Para>
1075 <Screen width="80">
1076 network 10.0.1.0
1077 netmask 255.255.255.0
1078 router  10.0.1.1
1079 </Screen>
1081 <Para>The router has address 172.16.17.18 on network C.
1082 </Para>
1084 <Para>and network B:
1085 </Para>
1087 <Screen width="80">
1088 network 10.0.2.0
1089 netmask 255.255.255.0
1090 router  10.0.2.1
1091 </Screen>
1093 <Para>The router has address 172.19.20.21 on network C.
1094 </Para>
1096 <Para>
1097 As far as network C is concerned, we assume that it will pass any packet sent
1098 from A to B and vice versa. You might even use the Internet for this.
1099 </Para>
1101 <Para>Here's what you do:
1102 </Para>
1104 <Para>First, make sure the modules are installed:
1105 </Para>
1107 <Screen width="80">
1108 insmod ipip.o
1109 insmod new_tunnel.o
1110 </Screen>
1112 <Para>Then, on the router of network A, you do the following:
1113 </Para>
1115 <Screen width="80">
1116 ifconfig tunl0 10.0.1.1 pointopoint 172.19.20.21
1117 route add -net 10.0.2.0 netmask 255.255.255.0 dev tunl0
1118 </Screen>
1120 <Para>And on the router of network B:
1121 </Para>
1123 <Screen width="80">
1124 ifconfig tunl0 10.0.2.1 pointopoint 172.16.17.18
1125 route add -net 10.0.1.0 netmask 255.255.255.0 dev tunl0
1126 </Screen>
1128 <Para>And if you're finished with your tunnel:
1129 </Para>
1131 <Screen width="80">
1132 ifconfig tunl0 down
1133 </Screen>
1135 <Para>Presto, you're done. You can't forward broadcast or IPv6 traffic through
1136 an IP-in-IP tunnel, though. You just connect 2 IPv4 networks that normally wouldn't be able to talk to each other, that's all. As far as compatibility goes, this code has been around a long time, so it's compatible all the way back to 1.3 kernels. Linux IP-in-IP tunneling doesn't work with other Operating Systems or routers, as far as I know. It's simple, it works. Use it if you have to, otherwise use GRE.
1137 </Para>
1139 </Sect1>
1141 <Sect1 id="lartc.tunnel.gre">
1142   <Title>GRE tunneling</Title>
1144 <Para>
1145 GRE is a tunneling protocol that was originally developed by Cisco, and it
1146 can do a few more things than IP-in-IP tunneling. For example, you can also
1147 transport multicast traffic and IPv6 through a GRE tunnel.
1148 </Para>
1150 <Para>
1151 In Linux, you'll need the ip_gre.o module.
1152 </Para>
1154 <Sect2>
1155 <Title>IPv4 Tunneling</Title>
1157 <Para>
1158 Let's do IPv4 tunneling first:
1159 </Para>
1161 <Para>
1162 Let's say you have 3 networks: Internal networks A and B, and intermediate network C (or let's say, Internet). 
1163 </Para>
1165 <Para>
1166 So we have network A:
1168 <Screen width="80">
1169 network 10.0.1.0
1170 netmask 255.255.255.0
1171 router  10.0.1.1
1172 </Screen>
1174 The router has address 172.16.17.18 on network C.
1175 Let's call this network neta (ok, hardly original)
1176 </Para>
1178 <Para>
1179 and network B:
1181 <Screen width="80">
1182 network 10.0.2.0
1183 netmask 255.255.255.0
1184 router  10.0.2.1
1185 </Screen>
1187 The router has address 172.19.20.21 on network C.
1188 Let's call this network netb (still not original)
1189 </Para>
1191 <Para>
1192 As far as network C is concerned, we assume that it will pass any packet sent
1193 from A to B and vice versa. How and why, we do not care.
1194 </Para>
1196 <Para>On the router of network A, you do the following:
1197 </Para>
1199 <Screen width="80">
1200 ip tunnel add netb mode gre remote 172.19.20.21 local 172.16.17.18 ttl 255
1201 ip link set netb up
1202 ip addr add 10.0.1.1 dev netb
1203 ip route add 10.0.2.0/24 dev netb
1204 </Screen>
1206 <Para>
1207 Let's discuss this for a bit. In line 1, we added a tunnel device, and
1208 called it netb (which is kind of obvious because that's where we want it to
1209 go). Furthermore we told it to use the GRE protocol (mode gre), that the
1210 remote address is 172.19.20.21 (the router at the other end), that our
1211 tunneling packets should originate from 172.16.17.18 (which allows your
1212 router to have several IP addresses on network C and let you decide which
1213 one to use for tunneling) and that the TTL field of the packet should be set
1214 to 255 (ttl 255).
1215 </Para>
1217 <Para>
1218 The second line enables the device.
1219 </Para>
1221 <Para>
1222 In the third line we gave the newly born interface netb the address
1223 10.0.1.1. This is OK for smaller networks, but when you're starting up a
1224 mining expedition (LOTS of tunnels), you might want to consider using
1225 another IP range for tunneling interfaces (in this example, you could use
1226 10.0.3.0).
1227 </Para>
1229 <Para>
1230 In the fourth line we set the route for network B. Note the different notation for the netmask. If you're not familiar with this notation, here's how it works: you write out the netmask in binary form, and you count all the ones. If you don't know how to do that, just remember that 255.0.0.0 is /8, 255.255.0.0 is /16 and 255.255.255.0 is /24. Oh, and 255.255.254.0 is /23, in case you were wondering.
1231 </Para>
1233 <Para>
1234 But enough about this, let's go on with the router of network B.
1236 <Screen>
1237 ip tunnel add neta mode gre remote 172.16.17.18 local 172.19.20.21 ttl 255
1238 ip link set neta up
1239 ip addr add 10.0.2.1 dev neta
1240 ip route add 10.0.1.0/24 dev neta
1241 </Screen>
1243 And when you want to remove the tunnel on router A:
1245 <Screen>
1246 ip link set netb down
1247 ip tunnel del netb
1248 </Screen>
1250 Of course, you can replace netb with neta for router B.
1251 </Para>
1253 </Sect2>
1255 <Sect2>
1256 <Title>IPv6 Tunneling</Title>
1258 <Para>
1259 See Section 6 for a short bit about IPv6 Addresses.
1260 </Para>
1262 <Para>
1263 On with the tunnels.
1264 </Para>
1266 <Para>
1267 Let's assume that you have the following IPv6 network, and you want to connect it to 6bone, or a friend.
1268 </Para>
1270 <Para>
1272 <Screen>
1273 Network 3ffe:406:5:1:5:a:2:1/96
1274 </Screen>
1276 Your IPv4 address is 172.16.17.18, and the 6bone router has IPv4 address 172.22.23.24. 
1277 </Para>
1279 <Para>
1281 <Screen>
1282 ip tunnel add sixbone mode sit remote 172.22.23.24 local 172.16.17.18 ttl 255
1283 ip link set sixbone up
1284 ip addr add 3ffe:406:5:1:5:a:2:1/96 dev sixbone
1285 ip route add 3ffe::/15 dev sixbone 
1286 </Screen>
1288 </Para>
1290 <Para>
1291 Let's discuss this. In the first line, we created a tunnel device called sixbone. We gave it mode sit (which is IPv6 in IPv4 tunneling) and told it where to go to (remote) and where to come from (local). TTL is set to maximum, 255. Next, we made the device active (up). After that, we added our own network address, and set a route for 3ffe::/15 (which is currently all of 6bone) through the tunnel.
1292 </Para>
1294 <Para>
1295 GRE tunnels are currently the preferred type of tunneling. It's a standard that is also widely adopted outside the Linux community and therefore a Good Thing.
1296 </Para>
1298 </Sect2>
1300 </Sect1>
1302 <Sect1 id="lartc.tunnel.userland">
1303   <Title>Userland tunnels</Title>
1305 <Para>
1306 There are literally dozens of implementations of tunneling outside the kernel. Best known are of course PPP and PPTP, but there are lots more (some proprietary, some secure, some that don't even use IP) and that is really beyond the scope of this HOWTO.
1307 </Para>
1309 </Sect1>
1311 </chapter>
1313 <chapter id="lartc.ipv6-tunnel">
1314 <Title>IPv6 tunneling with Cisco and/or 6bone</Title>
1316 <Para>
1317 By Marco Davids &lt;marco@sara.nl&gt;
1318 </Para>
1320 <Para>
1321 NOTE to maintainer:
1322 </Para>
1324 <Para>
1325 As far as I am concerned, this IPv6-IPv4 tunneling is not per definition
1326 GRE tunneling. You could tunnel IPv6 over IPv4 by means of GRE tunnel devices
1327 (GRE tunnels ANY to IPv4), but the device used here ("sit") only tunnels
1328 IPv6 over IPv4 and is therefore something different.
1329 </Para>
1331 <Sect1 id="lartc.tunnel-ipv6.addressing">
1332   <Title>IPv6 Tunneling</Title>
1334 <Para>
1335 This is another application of the tunneling capabilities of Linux. It is
1336 popular among the IPv6 early adopters, or pioneers if you like.
1337 The 'hands-on' example described below is certainly not the only way
1338 to do IPv6 tunneling. However, it is the method that is often used to tunnel
1339 between Linux and a Cisco IPv6 capable router and experience tells us that
1340 this is just the thing many people are after. Ten to one this applies to
1341 you too ;-)
1342 </Para>
1344 <Para>
1345 A short bit about IPv6 addresses:
1346 </Para>
1348 <Para>
1349 IPv6 addresses are, compared to IPv4 addresses, really big: 128 bits
1350 against 32 bits. And this provides us just with the thing we need: many, many
1351 IP-addresses: 340,282,266,920,938,463,463,374,607,431,768,211,465 to be
1352 precise. Apart from this, IPv6 (or IPng, for IP Next Generation) is supposed
1353 to provide for smaller routing tables on the Internet's backbone routers,
1354 simpler configuration of equipment, better security at the IP level and
1355 better support for QoS.
1356 </Para>
1358 <Para>
1359 An example: 2002:836b:9820:0000:0000:0000:836b:9886
1360 </Para>
1362 <Para>
1363 Writing down IPv6 addresses can be quite a burden. Therefore, to make
1364 life easier there are some rules:
1365 </Para>
1367 <Para>
1369 <ItemizedList>
1370 <ListItem>
1372 <Para>
1373 Don't use leading zeroes. Same as in IPv4.
1375 </Para>
1376 </ListItem>
1377 <ListItem>
1379 <Para>
1380 Use colons to separate every 16 bits or two bytes.
1382 </Para>
1383 </ListItem>
1384 <ListItem>
1386 <Para>
1387 When you have lots of consecutive zeroes,
1388 you can write this down as ::. You can only do this once in an
1389 address and only for quantities of 16 bits, though.
1390 </Para>
1391 </ListItem>
1393 </ItemizedList>
1395 </Para>
1397 <Para>
1398 The address 2002:836b:9820:0000:0000:0000:836b:9886 can be written down
1399 as 2002:836b:9820::836b:9886, which is somewhat friendlier.
1400 </Para>
1402 <Para>
1403 Another example, the address 3ffe:0000:0000:0000:0000:0020:34A1:F32C can be
1404 written down as 3ffe::20:34A1:F32C, which is a lot shorter.
1405 </Para>
1407 <Para>
1408 IPv6 is intended to be the successor of the current IPv4. Because it
1409 is relatively new technology, there is no worldwide native IPv6 network
1410 yet. To be able to move forward swiftly, the 6bone was introduced. 
1411 </Para>
1413 <Para>
1414 Native IPv6 networks are connected to each other by encapsulating the IPv6
1415 protocol in IPv4 packets and sending them over the existing IPv4 infrastructure
1416 from one IPv6 site to another. 
1417 </Para>
1419 <Para>
1420 That is precisely where the tunnel steps in.
1421 </Para>
1423 <Para>
1424 To be able to use IPv6, we should have a kernel that supports it. There
1425 are many good documents on how to achieve this. But it all comes down to
1426 a few steps:
1428 <ItemizedList>
1429 <ListItem>
1431 <Para>
1432 Get yourself a recent Linux distribution, with suitable glibc.
1433 </Para>
1434 </ListItem>
1435 <ListItem>
1437 <Para>
1438 Then get yourself an up-to-date kernel source.
1439 </Para>
1440 </ListItem>
1442 </ItemizedList>
1444 If you are all set, then you can go ahead and compile an IPv6 capable
1445 kernel:
1447 <ItemizedList>
1448 <ListItem>
1450 <Para>
1451 Go to /usr/src/linux and type:
1452 </Para>
1453 </ListItem>
1454 <ListItem>
1456 <Para>
1457 make menuconfig
1458 </Para>
1459 </ListItem>
1460 <ListItem>
1462 <Para>
1463 Choose "Networking Options"
1464 </Para>
1465 </ListItem>
1466 <ListItem>
1468 <Para>
1469 Select "The IPv6 protocol", "IPv6: enable EUI-64 token format", "IPv6:
1470 disable provider based addresses"
1471 </Para>
1472 </ListItem>
1474 </ItemizedList>
1476 HINT: Don't go for the 'module' option. Often this won't work well.
1477 </Para>
1479 <Para>
1480 In other words, compile IPv6 as 'built-in' in your kernel.
1481 You can then save your config like usual and go ahead with compiling
1482 the kernel.
1483 </Para>
1485 <Para>
1486 HINT: Before doing so, consider editing the Makefile:
1487 EXTRAVERSION = -x ; --&#62; ; EXTRAVERSION = -x-IPv6
1488 </Para>
1490 <Para>
1491 There is a lot of good documentation about compiling and installing
1492 a kernel, however this document is about something else. If you run into
1493 problems at this stage, go and look for documentation about compiling a
1494 Linux kernel according to your own specifications.
1495 </Para>
1497 <Para>
1498 The file /usr/src/linux/README might be a good start.
1499 After you accomplished all this, and rebooted with your brand new kernel,
1500 you might want to issue an '/sbin/ifconfig -a' and notice the brand 
1501 new 'sit0-device'. SIT stands for Simple Internet Transition. You may give
1502 yourself a compliment; you are now one major step closer to IP, the Next
1503 Generation ;-)
1504 </Para>
1506 <Para>
1507 Now on to the next step. You want to connect your host, or maybe even
1508 your entire LAN to another IPv6 capable network. This might be the "6bone"
1509 that is setup especially for this particular purpose.
1510 </Para>
1512 <Para>
1513 Let's assume that you have the following IPv6 network: 3ffe:604:6:8::/64 and
1514 you want to connect it to 6bone, or a friend. Please note that the /64
1515 subnet notation works just like with regular IP addresses.
1516 </Para>
1518 <Para>
1519 Your IPv4 address is 145.100.24.181 and the 6bone router has IPv4 address
1520 145.100.1.5
1521 </Para>
1523 <Screen width="80">
1524 # ip tunnel add sixbone mode sit remote 145.100.1.5 [local 145.100.24.181 ttl 255]
1525 # ip link set sixbone up
1526 # ip addr add 3FFE:604:6:7::2/126 dev sixbone
1527 # ip route add 3ffe::0/16 dev sixbone
1528 </Screen>
1530 <Para>
1531 Let's discuss this. In the first line, we created a tunnel device called
1532 sixbone. We gave it mode sit (which is IPv6 in IPv4 tunneling) and told it
1533 where to go to (remote) and where to come from (local). TTL is set to
1534 maximum, 255. 
1535 </Para>
1537 <Para>
1538 Next, we made the device active (up). After that, we added our own network
1539 address, and set a route for 3ffe::/15 (which is currently all of 6bone)
1540 through the tunnel. If the particular machine you run this on is your IPv6
1541 gateway, then consider adding the following lines:
1542 </Para>
1544 <Screen width="80">
1545 # echo 1 &#62;/proc/sys/net/ipv6/conf/all/forwarding
1546 # /usr/local/sbin/radvd
1547 </Screen>
1549 <Para>
1550 The latter, radvd is -like zebra- a router advertisement daemon, to
1551 support IPv6's autoconfiguration features. Search for it with your favourite
1552 search-engine if you like.
1553 You can check things like this:
1554 </Para>
1556 <Screen width="80">
1557 # /sbin/ip -f inet6 addr
1558 </Screen>
1560 <Para>
1561 If you happen to have radvd running on your IPv6 gateway and boot your
1562 IPv6 capable Linux on a machine on your local LAN, you would be able to
1563 enjoy the benefits of IPv6 autoconfiguration:
1564 </Para>
1566 <Screen width="80">
1567 # /sbin/ip -f inet6 addr
1568 1: lo: &lt;LOOPBACK,UP&gt; mtu 3924 qdisc noqueue inet6 ::1/128 scope host
1570 3: eth0: &lt;BROADCAST,MULTICAST,UP&gt; mtu 1500 qdisc pfifo_fast qlen 100
1571 inet6 3ffe:604:6:8:5054:4cff:fe01:e3d6/64 scope global dynamic
1572 valid_lft forever preferred_lft 604646sec inet6 fe80::5054:4cff:fe01:e3d6/10 
1573 scope link
1574 </Screen>
1576 <Para>
1577 You could go ahead and configure your bind for IPv6 addresses. The A
1578 type has an equivalent for IPv6: AAAA. The in-addr.arpa's equivalent is:
1579 ip6.int. There's a lot of information available on this topic.
1580 </Para>
1582 <Para>
1583 There is an increasing number of IPv6-aware applications available,
1584 including secure shell, telnet, inetd, Mozilla the browser, Apache the
1585 webserver and a lot of others. But this is all outside the scope of this
1586 Routing document ;-)
1587 </Para>
1589 <Para>
1590 On the Cisco side the configuration would be something like this:
1592 <Screen>
1594 interface Tunnel1
1595 description IPv6 tunnel
1596 no ip address
1597 no ip directed-broadcast
1598 ipv6 enable
1599 ipv6 address 3FFE:604:6:7::1/126
1600 tunnel source Serial0
1601 tunnel destination 145.100.24.181
1602 tunnel mode ipv6ip
1604 ipv6 route 3FFE:604:6:8::/64 Tunnel1
1605 </Screen>
1607 But if you don't have a Cisco at your disposal, try one of the many
1608 IPv6 tunnel brokers available on the Internet. They are willing to configure
1609 their Cisco with an extra tunnel for you. Mostly by means of a friendly
1610 web interface. Search for "ipv6 tunnel broker" on your favourite search engine.
1611 </Para>
1613 </Sect1>
1615 </chapter>
1617 <chapter id="lartc.ipsec">
1618 <Title>IPsec: secure IP over the Internet</Title>
1620 <Para>
1621 FIXME: editor vacancy.
1622 In the meantime, see: <ULink URL="http://www.freeswan.org/">
1623   The FreeS/WAN project</ULink>.
1624 Another IPSec implementation for Linux is Cerberus,
1625 by NIST. However, their web pages have not been updated in over a year,
1626 and their version tended to trail well behind the current Linux kernel.
1627 USAGI, an alternative IPv6 implementation for Linux, also includes an
1628 IPSec implementation, but that might only be for IPv6.
1629 </Para>
1631 </chapter>
1633 <chapter id="lartc.multicast">
1634 <Title>Multicast routing</Title>
1636 <Para>
1637 FIXME: Editor Vacancy!
1638 </Para>
1640 <Para>
1641 The Multicast-HOWTO is ancient (relatively-speaking) and may be inaccurate
1642 or misleading in places, for that reason.
1643 </Para>
1645 <Para>
1646 Before you can do any multicast routing, you need to configure the Linux
1647 kernel to support the type of multicast routing you want to do. This, in
1648 turn, requires you to decide what type of multicast routing you expect to
1649 be using. There are essentially four "common" types - DVMRP (the Multicast
1650 version of the RIP unicast protocol), MOSPF (the same, but for OSPF), PIM-SM
1651 ("Protocol Independent Multicasting - Sparse Mode", which assumes that users
1652 of any multicast group are spread out, rather than clumped) and PIM-DM (the
1653 same, but "Dense Mode", which assumes that there will be significant clumps
1654 of users of the same multicast group).
1655 </Para>
1657 <Para>
1658 In the Linux kernel, you will notice that these options don't appear. This is
1659 because the protocol itself is handled by a routing application, such as
1660 Zebra, mrouted, or pimd. However, you still have to have a good idea of which
1661 you're going to use, to select the right options in the kernel.
1662 </Para>
1664 <Para>
1665 For all multicast routing, you will definitely need to enable "multicasting"
1666 and "multicast routing". For DVMRP and MOSPF, this is sufficient. If you are
1667 going to use PIM, you must also enable PIMv1 or PIMv2, depending on whether
1668 the network you are connecting to uses version 1 or 2 of the PIM protocol.
1669 </Para>
1671 <Para>
1672 Once you have all that sorted out, and your new Linux kernel compiled, you
1673 will see that the IP protocols listed, at boot time, now include IGMP. This
1674 is a protocol for managing multicast groups. At the time of writing, Linux
1675 supports IGMP versions 1 and 2 only, although version 3 does exist and has
1676 been documented. This doesn't really affect us that much, as IGMPv3 is still
1677 new enough that the extra capabilities of IGMPv3 aren't going to be that
1678 much use. Because IGMP deals with groups, only the features present in the
1679 simplest version of IGMP over the entire group are going to be used. For the
1680 most part, that will be IGMPv2, although IGMPv1 is sill going to be
1681 encountered.
1682 </Para>
1684 <Para>
1685 So far, so good. We've enabled multicasting. Now, we have to tell the Linux
1686 kernel to actually do something with it, so we can start routing. This means
1687 adding the Multicast virtual network to the router table:
1688 </Para>
1690 <Para>
1691 ip route add 224.0.0.0/4 dev eth0
1692 </Para>
1694 <Para>
1695 (Assuming, of course, that you're multicasting over eth0! Substitute the
1696 device of your choice, for this.)
1697 </Para>
1699 <Para>
1700 Now, tell Linux to forward packets...
1701 </Para>
1703 <Para>
1704 echo 1 &#62; /proc/sys/net/ipv4/ip_forward
1705 </Para>
1707 <Para>
1708 At this point, you may be wondering if this is ever going to do anything. So,
1709 to test our connection, we ping the default group, 224.0.0.1, to see if anyone
1710 is alive. All machines on your LAN with multicasting enabled <Emphasis>should</Emphasis>
1711 respond, but nothing else. You'll notice that none of the machines that
1712 respond have an IP address of 224.0.0.1. What a surprise! :) This is a group
1713 address (a "broadcast" to subscribers), and all members of the group will
1714 respond with their own address, not the group address.
1715 </Para>
1717 <Para>
1718 ping -c 2 224.0.0.1
1719 </Para>
1721 <Para>
1722 At this point, you're ready to do actual multicast routing. Well, assuming
1723 that you have two networks to route between.
1724 </Para>
1726 <Para>
1727 (To Be Continued!)
1728 </Para>
1730 </chapter>
1732 <chapter id="lartc.qdisc">
1733 <Title>Queueing Disciplines for Bandwidth Management</Title>
1735 <Para>
1736 Now, when I discovered this, it <Emphasis>really</Emphasis> blew me away. Linux 2.2/2.4
1737 comes with everything to manage bandwidth in ways comparable to high-end
1738 dedicated bandwidth management systems.
1739 </Para>
1741 <Para>
1742 Linux even goes far beyond what Frame and ATM provide. 
1743 </Para>
1745 <Para>Just to prevent confusion, <command>tc</command> uses the following 
1746 rules for bandwith specification:
1748 <literallayout class='monospaced'>
1749 mbps = 1024 kbps = 1024 * 1024 bps =&#62; byte/s
1750 mbit = 1024 kbit =&#62; kilo bit/s.
1751 mb = 1024 kb = 1024 * 1024 b =&#62; byte
1752 mbit = 1024 kbit =&#62; kilo bit.
1753 </literallayout>
1755 Internally, the number is stored in bps and b.
1756 </Para>
1758 <Para>But when <command>tc</command> prints the rate, it uses following :
1759 </Para>
1761 <literallayout class='monospaced'>
1762 1Mbit = 1024 Kbit = 1024 * 1024 bps =&#62; bit/s
1763 </literallayout>
1765 <Sect1 id="lartc.qdisc.explain">
1766   <Title>Queues and Queueing Disciplines explained</Title>
1768 <Para>
1769 With queueing we determine the way in which data is <Emphasis>SENT</Emphasis>.
1770 It is important to realise that we can only shape data that we transmit.
1771 </Para>
1773 <Para>
1774 With the way the Internet works, we have no direct control of what people
1775 send us. It's a bit like your (physical!) mailbox at home. There is no way
1776 you can influence the world to modify the amount of mail they send you,
1777 short of contacting everybody.
1778 </Para>
1780 <Para>
1781 However, the Internet is mostly based on TCP/IP which has a few features
1782 that help us. TCP/IP has no way of knowing the capacity of the network
1783 between two hosts, so it just starts sending data faster and faster ('slow
1784 start') and when packets start getting lost, because there is no room to
1785 send them, it will slow down. In fact it is a bit smarter than this, but
1786 more about that later.
1787 </Para>
1789 <Para>
1790 This is the equivalent of not reading half of your mail, and hoping that
1791 people will stop sending it to you. With the difference that it works for
1792 the Internet :-)
1793 </Para>
1795 <Para>
1796 If you have a router and wish to prevent certain hosts within your network
1797 from downloading too fast, you need to do your shaping on the *inner* interface
1798 of your router, the one that sends data to your own computers.
1799 </Para>
1801 <Para>
1802 You also have to be sure you are controlling the bottleneck of the link.
1803 If you have a 100Mbit NIC and you have a router that has a 256kbit link,
1804 you have to make sure you are not sending more data than your router can
1805 handle.  Otherwise, it will be the router who is controlling the link and
1806 shaping the available bandwith. We need to 'own the queue' so to speak, and
1807 be the slowest link in the chain. Luckily this is easily possible.
1808 </Para>
1810 </Sect1>
1812 <Sect1 id="lartc.qdisc.classless">
1813   <Title>Simple, classless Queueing Disciplines</Title>
1815 <Para>
1816 As said, with queueing disciplines, we change the way data is sent.
1817 Classless queueing disciplines are those that, by and large accept data and
1818 only reschedule, delay or drop it.
1819 </Para>
1821 <Para>
1822 These can be used to shape traffic for an entire interface, without any
1823 subdivisions. It is vital that you understand this part of queueing before
1824 we go on the the classful qdisc-containing-qdiscs!
1825 </Para>
1827 <Para>
1828 By far the most widely used discipline is the pfifo_fast qdisc - this is the
1829 default. This also explains why these advanced features are so robust. They
1830 are nothing more than 'just another queue'.
1831 </Para>
1833 <Para>
1834 Each of these queues has specific strengths and weaknesses. Not all of them
1835 may be as well tested.
1836 </Para>
1838 <Sect2>
1839 <Title>pfifo_fast</Title>
1841 <Para>
1842 This queue is, as the name says, First In, First Out, which means that no
1843 packet receives special treatment. At least, not quite. This queue has 3 so
1844 called 'bands'. Within each band, FIFO rules apply. However, as long as
1845 there are packets waiting in band 0, band 1 won't be processed. Same goes
1846 for band 1 and band 2.
1847 </Para>
1849 <Para>
1850 The kernel honors the so called Type of Service flag of packets, and takes
1851 care to insert 'minimum delay' packets in band 0. 
1852 </Para>
1854 <Para>
1855 Do not confuse this classless simple qdisc with the classful PRIO one!
1856 Although they behave similarly, pfifo_fast is classless and you cannot add
1857 other qdiscs to it with the tc command.
1858 </Para>
1860 <Sect3>
1861 <Title>Parameters &amp; usage</Title>
1863 <Para>
1864 You can't configure the pfifo_fast qdisc as it is the hardwired default.
1865 This is how it is configured by default:
1866 <VariableList>
1868 <VarListEntry>
1869 <Term>priomap</Term>
1870 <ListItem>
1871 <Para>
1872 Determines how packet priorities, as assigned by the kernel, map to bands.
1873 Mapping occurs based on the TOS octet of the packet, which looks like this:
1874 </Para>
1876 <Para>
1878 <Screen>
1879    0     1     2     3     4     5     6     7
1880 +-----+-----+-----+-----+-----+-----+-----+-----+
1881 |                 |                       |     |
1882 |   PRECEDENCE    |          TOS          | MBZ |
1883 |                 |                       |     |
1884 +-----+-----+-----+-----+-----+-----+-----+-----+
1885 </Screen>
1887 </Para>
1889 <Para>
1890 The four TOS bits (the 'TOS field') are defined as:
1892 <Screen>
1893 Binary Decimcal  Meaning
1894 -----------------------------------------
1895 1000   8         Minimize delay (md)
1896 0100   4         Maximize throughput (mt)
1897 0010   2         Maximize reliability (mr)
1898 0001   1         Minimize monetary cost (mmc)
1899 0000   0         Normal Service
1900 </Screen>
1902 </Para>
1904 <Para>
1905 As there is 1 bit to the right of these four bits, the actual value of the
1906 TOS field is double the value of the TOS bits. Tcpdump -v -v shows you the
1907 value of the entire TOS field, not just the four bits. It is the value you
1908 see in the first column of this table:
1909 </Para>
1911 <Para>
1913 <Screen>
1914 TOS     Bits  Means                    Linux Priority    Band
1915 ------------------------------------------------------------
1916 0x0     0     Normal Service           0 Best Effort     1
1917 0x2     1     Minimize Monetary Cost   1 Filler          2
1918 0x4     2     Maximize Reliability     0 Best Effort     1
1919 0x6     3     mmc+mr                   0 Best Effort     1
1920 0x8     4     Maximize Throughput      2 Bulk            2
1921 0xa     5     mmc+mt                   2 Bulk            2
1922 0xc     6     mr+mt                    2 Bulk            2
1923 0xe     7     mmc+mr+mt                2 Bulk            2
1924 0x10    8     Minimize Delay           6 Interactive     0
1925 0x12    9     mmc+md                   6 Interactive     0
1926 0x14    10    mr+md                    6 Interactive     0
1927 0x16    11    mmc+mr+md                6 Interactive     0
1928 0x18    12    mt+md                    4 Int. Bulk       1
1929 0x1a    13    mmc+mt+md                4 Int. Bulk       1
1930 0x1c    14    mr+mt+md                 4 Int. Bulk       1
1931 0x1e    15    mmc+mr+mt+md             4 Int. Bulk       1
1932 </Screen>
1934 </Para>
1936 <Para>
1937 Lots of numbers. The second column contains the value of the relevant four
1938 TOS bits, followed by their translated meaning. For example, 15 stands for a
1939 packet wanting Minimal Monetary Cost, Maximum Reliability, Maximum
1940 Throughput AND Minimum Delay. I would call this a 'Dutch Packet'.
1941 </Para>
1943 <Para>
1944 The fourth column lists the way the Linux kernel interprets the TOS bits, by
1945 showing to which Priority they are mapped. 
1946 </Para>
1948 <Para>
1949 The last column shows the result of the default priomap. On the command line,
1950 the default priomap looks like this:
1952 <Screen>
1953 1, 2, 2, 2, 1, 2, 0, 0 , 1, 1, 1, 1, 1, 1, 1, 1
1954 </Screen>
1956 </Para>
1958 <Para>
1959 This means that priority 4, for example, gets mapped to band number 1. The
1960 priomap also allows you to list higher priorities (&gt; 7) which do not
1961 correspond to TOS mappings, but which are set by other means.
1962 </Para>
1964 <Para>
1965 This table from RFC 1349 (read it for more details) tells you how
1966 applications might very well set their TOS bits:
1968 <Screen>
1969 TELNET                   1000           (minimize delay)
1971         Control          1000           (minimize delay)
1972         Data             0100           (maximize throughput)
1974 TFTP                     1000           (minimize delay)
1976 SMTP 
1977         Command phase    1000           (minimize delay)
1978         DATA phase       0100           (maximize throughput)
1980 Domain Name Service
1981         UDP Query        1000           (minimize delay)
1982         TCP Query        0000
1983         Zone Transfer    0100           (maximize throughput)
1985 NNTP                     0001           (minimize monetary cost)
1987 ICMP
1988         Errors           0000
1989         Requests         0000 (mostly)
1990         Responses        &#60;same as request&#62; (mostly)
1991 </Screen>
1993 </Para></ListItem>
1994 </VarListEntry>
1995 <VarListEntry>
1996 <Term>txqueuelen</Term>
1997 <ListItem>
1998 <Para>
1999 The length of this queue is gleaned from the interface configuration, which
2000 you can see and set with ifconfig and ip. To set the queue length to 10,
2001 execute: ifconfig eth0 txqueuelen 10
2002 </Para>
2004 <Para>
2005 You can't set this parameter with tc!
2006 </Para></ListItem>
2007 </VarListEntry>
2008 </VariableList>
2009 </Para>
2011 </Sect3>
2013 </Sect2>
2015 <Sect2>
2016 <Title>Token Bucket Filter</Title>
2018 <Para>
2019 The Token Bucket Filter (TBF) is a simple qdisc that only passes packets
2020 arriving at a rate which is not exceeding some administratively set rate, but
2021 with the possibility to allow short bursts in excess of this rate.
2022 </Para>
2024 <Para>
2025 TBF is very precise, network- and processor friendly. It should be your
2026 first choice if you simply want to slow an interface down!
2027 </Para>
2029 <Para>
2030 The TBF implementation consists of a buffer (bucket), constantly filled by
2031 some virtual pieces of information called tokens, at a specific rate (token
2032 rate). The most important parameter of the bucket is its size, that is the
2033 number of tokens it can store.
2034 </Para>
2036 <Para>
2037 Each arriving token collects one incoming data packet from the data queue
2038 and is then deleted from the bucket. Associating this algorithm
2039 with the two flows -- token and data, gives us three possible scenarios:
2040 </Para>
2042 <Para>
2044 <ItemizedList>
2045 <ListItem>
2047 <Para>
2048  The data arrives in TBF at a rate that's <Emphasis>equal</Emphasis> to the rate
2049 of incoming tokens. In this case each incoming packet has its matching token
2050 and passes the queue without delay.
2052 </Para>
2053 </ListItem>
2054 <ListItem>
2056 <Para>
2057  The data arrives in TBF at a rate that's <Emphasis>smaller</Emphasis> than the
2058 token rate. Only a part of the tokens are deleted at output of each data packet
2059 that's sent out the queue, so the tokens accumulate, up to the bucket size.
2060 The unused tokens can then be used to send data a a speed that's exceeding the
2061 standard token rate, in case short data bursts occur.
2063 </Para>
2064 </ListItem>
2065 <ListItem>
2067 <Para>
2068  The data arrives in TBF at a rate <Emphasis>bigger</Emphasis> than the token rate.
2069 This means that the bucket will soon be devoid of tokens, which causes the
2070 TBF to throttle itself for a while. This is called an 'overlimit situation'.
2071 If packets keep coming in, packets will start to get dropped.
2072 </Para>
2073 </ListItem>
2075 </ItemizedList>
2077 </Para>
2079 <Para>
2080 The last scenario is very important, because it allows to
2081 administratively shape the bandwidth available to data that's passing
2082 the filter.
2083 </Para>
2085 <Para>
2086 The accumulation of tokens allows a short burst of overlimit data to be
2087 still passed without loss, but any lasting overload will cause packets to be
2088 constantly delayed, and then dropped.
2089 </Para>
2091 <Para>
2092 Please note that in the actual implementation, tokens correspond to bytes,
2093 not packets.
2094 </Para>
2096 <Sect3>
2097 <Title>Parameters &amp; usage</Title>
2099 <Para>
2100 Even though you will probably not need to change them, tbf has some knobs
2101 available. First the parameters that are always available:
2102 <VariableList>
2104 <VarListEntry>
2105 <Term>limit or latency</Term>
2106 <ListItem>
2107 <Para>
2108 Limit is the number of bytes that can be queued waiting for tokens to become
2109 available. You can also specify this the other way around by setting the
2110 latency parameter, which specifies the maximum amount of time a packet can
2111 sit in the TBF. The latter calculation takes into account the size of the
2112 bucket, the rate and possibly the peakrate (if set).
2113 </Para></ListItem>
2114 </VarListEntry>
2115 <VarListEntry>
2116 <Term>burst/buffer/maxburst</Term>
2117 <ListItem>
2118 <Para>
2119 Size of the bucket, in bytes. This is the maximum amount of bytes that
2120 tokens can be available for instantaneously. In general, larger shaping
2121 rates require a larger buffer. For 10mbit/s on Intel, you need at least
2122 10kbyte buffer if you want to reach your configured rate!
2123 </Para>
2125 <Para>
2126 If your buffer is too small, packets may be dropped because more tokens
2127 arrive per timer tick than fit in your bucket.
2128 </Para></ListItem>
2129 </VarListEntry>
2130 <VarListEntry>
2131 <Term>mpu</Term>
2132 <ListItem>
2133 <Para>
2134 A zero-sized packet does not use zero bandwidth. For ethernet, no packet
2135 uses less than 64 bytes. The Minimum Packet Unit determines the minimal
2136 token usage for a packet.
2137 </Para></ListItem>
2138 </VarListEntry>
2139 <VarListEntry>
2140 <Term>rate</Term>
2141 <ListItem>
2142 <Para>
2143 The speedknob. See remarks above about limits!
2144 </Para></ListItem>
2145 </VarListEntry>
2146 </VariableList>
2147 </Para>
2149 <Para>
2150 If the bucket contains tokens and is allowed to empty, by default it does so
2151 at infinite speed. If this is unacceptable, use the following parameters:
2152 </Para>
2154 <Para>
2155 <VariableList>
2157 <VarListEntry>
2158 <Term>peakrate</Term>
2159 <ListItem>
2160 <Para>
2161 If tokens are available, and packets arrive, they are sent out immediately
2162 by default, at 'lightspeed' so to speak. That may not be what you want,
2163 especially if you have a large bucket. 
2164 </Para>
2166 <Para>
2167 The peakrate can be used to specify how quickly the bucket is allowed to be
2168 depleted. If doing everything by the book, this is achieved by releasing a
2169 packet, and then wait just long enough, and release the next. We calculated
2170 our waits so we send just at peakrate.
2171 </Para>
2173 <Para>
2174 However, due to de default 10ms timer resolution of Unix, with 10.000 bits
2175 average packets, we are limited to 1mbit/s of peakrate!
2176 </Para></ListItem>
2177 </VarListEntry>
2178 <VarListEntry>
2179 <Term>mtu/minburst</Term>
2180 <ListItem>
2181 <Para>
2182 The 1mbit/s peakrate is not very useful if your regular rate is more than
2183 that. A higher peakrate is possible by sending out more packets per
2184 timertick, which effectively means that we create a second bucket!
2185 </Para>
2187 <Para>
2188 This second bucket defaults to a single packet, which is not a bucket at
2189 all.
2190 </Para>
2192 <Para>
2193 To calculate the maximum possible peakrate, multiply the configured mtu by
2194 100 (or more correctly, HZ, which is 100 on Intel, 1024 on Alpha).
2195 </Para></ListItem>
2196 </VarListEntry>
2197 </VariableList>
2198 </Para>
2200 </Sect3>
2202 <Sect3>
2203 <Title>Sample configuration</Title>
2205 <Para>
2206 A simple but *very* useful configuration is this:
2208 <Screen>
2209 # tc qdisc add dev ppp0 root tbf rate 220kbit latency 50ms burst 1540
2210 </Screen>
2212 </Para>
2214 <Para>
2215 Ok, why is this useful? If you have a networking device with a large queue,
2216 like a DSL modem or a cable modem, and you talk to it over a fast device,
2217 like over an ethernet interface, you will find that uploading absolutely
2218 destroys interactivity.
2219 </Para>
2221 <Para>
2222 This is because uploading will fill the queue in the modem, which is
2223 probably *huge* because this helps actually achieving good data throughput
2224 uploading. But this is not what you want, you want to have the queue not too
2225 big so interactivity remains and you can still do other stuff while sending
2226 data.
2227 </Para>
2229 <Para>
2230 The line above slows down sending to a rate that does not lead to a queue in
2231 the modem - the queue will be in Linux, where we can control it to a limited
2232 size.
2233 </Para>
2235 <Para>
2236 Change 220kbit to your uplink's *actual* speed, minus a few percent. If you
2237 have a really fast modem, raise 'burst' a bit. 
2238 </Para>
2240 </Sect3>
2242 </Sect2>
2244 <Sect2 id="lartc.sfq">
2245 <Title>Stochastic Fairness Queueing</Title>
2247 <Para>
2248 Stochastic Fairness Queueing (SFQ) is a simple implementation of the fair
2249 queueing algorithms family. It's less accurate than others, but it also
2250 requires less calculations while being almost perfectly fair.
2251 </Para>
2253 <Para>
2254 The key word in SFQ is conversation (or flow), which mostly corresponds to a
2255 TCP session or a UDP stream. Traffic is divided into a pretty large number
2256 of FIFO queues, one for each conversation. Traffic is then sent in a round
2257 robin fashion, giving each session the chance to send data in turn.
2258 </Para>
2260 <Para>
2261 This leads to very fair behaviour and disallows any single conversation from
2262 drowning out the rest. SFQ is called 'Stochastic' because it doesn't really
2263 allocate a queue for each session, it has an algorithm which divides traffic
2264 over a limited number of queues using a hashing algorithm. 
2265 </Para>
2267 <Para>
2268 Because of the hash, multiple sessions might end up in the same bucket, which
2269 would halve each session's chance of sending a packet, thus halving the
2270 effective speed available. To prevent this situation from becoming
2271 noticeable, SFQ changes its hashing algorithm quite often so that any two
2272 colliding sessions will only do so for a small number of seconds.
2273 </Para>
2275 <Para>
2276 It is important to note that SFQ is only useful in case your actual outgoing
2277 interface is really full! If it isn't then there will be no queue on your
2278 linux machine and hence no effect. Later on we will describe how to combine
2279 SFQ with other qdiscs to get a best-of-both worlds situation.
2280 </Para>
2282 <Para>
2283 Specifically, setting SFQ on the ethernet interface heading to your
2284 cable modem or DSL router is pointless without further shaping!
2285 </Para>
2287 <Sect3>
2288 <Title>Parameters &amp; usage</Title>
2290 <Para>
2291 The SFQ is pretty much self tuning:
2292 <VariableList>
2294 <VarListEntry>
2295 <Term>perturb</Term>
2296 <ListItem>
2297 <Para>
2298 Reconfigure hashing once this many seconds. If unset, hash will never be
2299 reconfigured. Not recommended. 10 seconds is probably a good value.
2300 </Para></ListItem>
2301 </VarListEntry>
2302 <VarListEntry>
2303 <Term>quantum</Term>
2304 <ListItem>
2305 <Para>
2306 Amount of bytes a stream is allowed to dequeue before the next queue gets a
2307 turn. Defaults to 1 maximum sized packet (MTU-sized). Do not set below the
2308 MTU!
2309 </Para></ListItem>
2310 </VarListEntry>
2311 </VariableList>
2312 </Para>
2314 </Sect3>
2316 <Sect3>
2317 <Title>Sample configuration</Title>
2319 <Para>
2320 If you have a device which has identical link speed and actual available
2321 rate, like a phone modem, this configuration will help promote fairness:
2323 <Screen>
2324 # tc qdisc add dev ppp0 root sfq perturb 10
2325 # tc -s -d qdisc ls
2326 qdisc sfq 800c: dev ppp0 quantum 1514b limit 128p flows 128/1024 perturb 10sec 
2327  Sent 4812 bytes 62 pkts (dropped 0, overlimits 0) 
2328 </Screen>
2330 </Para>
2332 <Para>
2333 The number 800c: is the automatically assigned handle number, limit means
2334 that 128 packets can wait in this queue. There are 1024 hashbuckets
2335 available for accounting, of which 128 can be active at a time (no more
2336 packets fit in the queue!) Once every 10 seconds, the hashes are
2337 reconfigured.
2338 </Para>
2340 </Sect3>
2342 </Sect2>
2344 </Sect1>
2346 <Sect1 id="lartc.qdisc.advice">
2347   <Title>Advice for when to use which queue</Title>
2349 <Para>
2350 Summarizing, these are the simple queues that actually manage traffic by
2351 reordering, slowing or dropping packets.
2352 </Para>
2354 <Para>
2355 The following tips may help in choosing which queue to use. It mentions some
2356 qdiscs described in the
2357 <citetitle><xref linkend="lartc.adv-qdisc"></citetitle> chapter.
2358 </Para>
2360 <ItemizedList>
2361 <ListItem>
2362 <Para>
2363 To purely slow down outgoing traffic, use the Token Bucket Filter. Works up
2364 to huge bandwidths, if you scale the bucket.
2365 </Para>
2366 </ListItem>
2367 <ListItem>
2369 <Para>
2370 If your link is truly full and you want to make sure that no single session
2371 can dominate your outgoing bandwidth, use Stochastical Fairness Queueing.
2372 </Para>
2373 </ListItem>
2374 <ListItem>
2376 <Para>
2377 If you have a big backbone and know what you are doing, consider Random
2378 Early Drop (see Advanced chapter).
2379 </Para>
2380 </ListItem>
2381 <ListItem>
2383 <Para>
2384 To 'shape' incoming traffic which you are not forwarding, use the Ingress
2385 Policer. Incoming shaping is called 'policing', by the way, not 'shaping'.  
2386 </Para>
2387 </ListItem>
2388 <ListItem>
2390 <Para>
2391 If you *are* forwarding it, use a TBF on the interface you are forwarding
2392 the data to. Unless you want to shape traffic that may go out over several
2393 interfaces, in which case the only common factor is the incoming interface.
2394 In that case use the Ingress Policer.
2395 </Para>
2396 </ListItem>
2397 <ListItem>
2399 <Para>
2400 If you don't want to shape, but only want to see if your interface is so
2401 loaded that it has to queue, use the pfifo queue (not pfifo_fast). It lacks
2402 internal bands but does account the size of its backlog.
2403 </Para>
2404 </ListItem>
2405 <ListItem>
2406 <Para>
2407 Finally - you can also do <quote>social shaping</quote>.
2408 You may not always be able to use technology to achieve what you want.
2409 Users experience technical constraints as hostile.
2410 A kind word may also help with getting your bandwidth to be divided right!
2411 </Para>
2412 </ListItem>
2413 </ItemizedList>
2415 </Sect1>
2417 <Sect1 id="lartc.qdisc.terminology">
2418   <Title>Terminology</Title>
2420 <Para>
2421 To properly understand more complicated configurations it is necessary to
2422 explain a few concepts first. Because of the complexity and he relative
2423 youth of the subject, a lot of different words are used when people in fact
2424 mean the same thing.
2425 </Para>
2427 <Para>
2428 The following is loosely based on 
2429 <filename>draft-ietf-diffserv-model-06.txt</filename>,
2430 <citetitle>An Informal Management Model for Diffserv Routers</citetitle>.
2431 It can currently be found at 
2432 <ulink url="http://www.ietf.org/internet-drafts/draft-ietf-diffserv-model-06.txt">
2433   http://www.ietf.org/internet-drafts/draft-ietf-diffserv-model-06.txt
2434 </ulink>.
2435 </Para>
2437 <Para>
2438 Read it for the strict definitions of the terms used.
2439 <VariableList>
2441 <VarListEntry>
2442 <Term>Queueing Discipline</Term>
2443 <ListItem>
2444 <Para>
2445 An algorithm that manages the queue of a device, either incoming (ingress)
2446 or outgoing (egress).
2447 </Para></ListItem>
2448 </VarListEntry>
2449 <VarListEntry>
2450 <Term>Classless qdisc</Term>
2451 <ListItem>
2452 <Para>
2453 A qdisc with no configurable internal subdivisions. 
2454 </Para></ListItem>
2455 </VarListEntry>
2456 <VarListEntry>
2457 <Term>Classful qdisc</Term>
2458 <ListItem>
2459 <Para>
2460 A classful qdisc contains multiple classes. Each of these classes contains a
2461 further qdisc, which may again be classful, but need not be. According to
2462 the strict definition, pfifo_fast *is* classful, because it contains three
2463 bands which are, in fact, classes. However, from the user's configuration
2464 perspective, it is classless as the classes can't be touched with the tc
2465 tool. 
2466 </Para></ListItem>
2467 </VarListEntry>
2468 <VarListEntry>
2469 <Term>Classes</Term>
2470 <ListItem>
2471 <Para>
2472 A classful qdisc may have many classes, which each are internal to the
2473 qdisc. Each of these classes may contain a real qdisc.
2474 </Para></ListItem>
2475 </VarListEntry>
2476 <VarListEntry>
2477 <Term>Classifier</Term>
2478 <ListItem>
2479 <Para>
2480 Each classful qdisc needs to determine to which class it needs to send a
2481 packet. This is done using the classifier.
2482 </Para></ListItem>
2483 </VarListEntry>
2484 <VarListEntry>
2485 <Term>Filter</Term>
2486 <ListItem>
2487 <Para>
2488 Classification can be performed using filters. A filter contains a number of
2489 conditions which if matched, make the filter match.
2490 </Para></ListItem>
2491 </VarListEntry>
2492 <VarListEntry>
2493 <Term>Scheduling</Term>
2494 <ListItem>
2495 <Para>
2496 A qdisc may, with the help of a classifier, decide that some packets need to
2497 go out earlier than others. This process is called Scheduling, and is
2498 performed for example by the pfifo_fast qdisc mentioned earlier. Scheduling
2499 is also called 'reordering', but this is confusing.
2500 </Para></ListItem>
2501 </VarListEntry>
2502 <VarListEntry>
2503 <Term>Shaping</Term>
2504 <ListItem>
2505 <Para>
2506 The process of delaying packets before they go out to make traffic confirm
2507 to a configured maximum rate. Shaping is performed on egress. Colloquially, 
2508 dropping packets to slow traffic down is also often called Shaping.
2509 </Para></ListItem>
2510 </VarListEntry>
2511 <VarListEntry>
2512 <Term>Policing</Term>
2513 <ListItem>
2514 <Para>
2515 Delaying or dropping packets in order to make traffic stay below a
2516 configured bandwidth. In Linux, policing can only drop a packet and not
2517 delay it - there is no 'ingress queue'.
2518 </Para></ListItem>
2519 </VarListEntry>
2520 <VarListEntry>
2521 <Term>Work-Conserving</Term>
2522 <ListItem>
2523 <Para>
2524 A work-conserving qdisc always delivers a packet if one is available. In
2525 other words, it never delays a packet if the network adaptor is ready to
2526 send one (in the case of an egress qdisc).
2527 </Para></ListItem>
2528 </VarListEntry>
2529 <VarListEntry>
2530 <Term>non-Work-Conserving</Term>
2531 <ListItem>
2532 <Para>
2533 Some queues, like for example the Token Bucket Filter, may need to hold on
2534 to a packet for a certain time in order to limit the bandwidth. This means
2535 that they sometimes refuse to give up a packet, even though they have one
2536 available.
2537 </Para></ListItem>
2538 </VarListEntry>
2539 </VariableList>
2540 </Para>
2542 <Para>
2543 Now that we have our terminology straight, let's see where all these things
2544 are.
2545 </Para>
2547 <Para>
2549 <Screen width="80">
2550                 Userspace programs
2551                      ^
2552                      |
2553      +---------------+-----------------------------------------+
2554      |               Y                                         |
2555      |    -------&#62; IP Stack                                    |
2556      |   |              |                                      |
2557      |   |              Y                                      |
2558      |   |              Y                                      |
2559      |   ^              |                                      |
2560      |   |  / ----------&#62; Forwarding -&#62;                        |
2561      |   ^ /                           |                       |
2562      |   |/                            Y                       |
2563      |   |                             |                       |
2564      |   ^                             Y          /-qdisc1-\   |
2565      |   |                            Egress     /--qdisc2--\  |
2566   ---&#62;-&#62;Ingress                       Classifier ---qdisc3---- | -&#62;
2567      |   Qdisc                                   \__qdisc4__/  |
2568      |                                            \-qdiscN_/   |
2569      |                                                         |
2570      +----------------------------------------------------------+
2571 </Screen>
2573 Thanks to Jamal Hadi Salim for this ASCII representation.
2574 </Para>
2576 <Para>
2577 The big block represents the kernel. The leftmost arrow represents traffic
2578 entering your machine from the network. It is then fed to the Ingress
2579 Qdisc which may apply Filters to a packet, and decide to drop it. This
2580 is called 'Policing'.
2581 </Para>
2583 <Para>
2584 This happens at a very early stage, before it has seen a lot of the kernel.
2585 It is therefore a very good place to drop traffic very early, without
2586 consuming a lot of CPU power.
2587 </Para>
2589 <Para>
2590 If the packet is allowed to continue, it may be destined for a local
2591 application, in which case it enters the IP stack in order to be processed,
2592 and handed over to a userspace program. The packet may also be forwarded
2593 without entering an application, in which case it is destined for egress.
2594 Userspace programs may also deliver data, which is then examined and
2595 forwarded to the Egress Classifier.
2596 </Para>
2598 <Para>
2599 There it is investigated and enqueued to any of a number of qdiscs. In the
2600 unconfigured default case, there is only one egress qdisc installed, the
2601 pfifo_fast, which always receives the packet. This is called 'enqueueing'.
2602 </Para>
2604 <Para>
2605 The packet now sits in the qdisc, waiting for the kernel to ask for
2606 it for transmission over the network interface. This is called 'dequeueing'.
2607 </Para>
2609 <Para>
2610 This picture also holds in case there is only one network adaptor - the
2611 arrows entering and leaving the kernel should not be taken too literally.
2612 Each network adaptor has both ingress and egress hooks.
2613 </Para>
2615 </Sect1>
2617 <Sect1 id="lartc.qdisc.classful">
2618   <Title>Classful Queueing Disciplines</Title>
2620 <Para>
2621 Classful qdiscs are very useful if you have different kinds of traffic which
2622 should have differing treatment. One of the classful qdiscs is called 'CBQ'
2623 , 'Class Based Queueing' and it is so widely mentioned that people identify
2624 queueing with classes solely with CBQ, but this is not the case.
2625 </Para>
2627 <Para>
2628 CBQ is merely the oldest kid on the block - and also the most complex one.
2629 It may not always do what you want.  This may come as something of a shock
2630 to many who fell for the 'sendmail effect', which teaches us that any
2631 complex technology which doesn't come with documentation must be the best
2632 available.
2633 </Para>
2635 <Para>
2636 More about CBQ and its alternatives shortly.
2637 </Para>
2639 <Sect2>
2640 <Title>Flow within classful qdiscs &amp; classes</Title>
2642 <Para>
2643 When traffic enters a classful qdisc, it needs to be sent to any of the
2644 classes within - it needs to be 'classified'. To determine what to do with a
2645 packet, the so called 'filters' are consulted. It is important to know that
2646 the filters are called from within a qdisc, and not the other way around!
2647 </Para>
2649 <Para>
2650 The filters attached to that qdisc then return with a decision, and the
2651 qdisc uses this to enqueue the packet into one of the classes. Each subclass
2652 may try other filters to see if further instructions apply. If not, the
2653 class enqueues the packet to the qdisc it contains.
2654 </Para>
2656 <Para>
2657 Besides containing other qdiscs, most classful qdiscs also perform shaping.
2658 This is useful to perform both packet scheduling (with SFQ, for example) and
2659 rate control. You need this in cases where you have a high speed
2660 interface (for example, ethernet) to a slower device (a cable modem).
2661 </Para>
2663 <Para>
2664 If you were only to run SFQ, nothing would happen, as packets enter &amp;
2665 leave your router without delay: the output interface is far faster than
2666 your actual link speed. There is no queue to schedule then.
2667 </Para>
2669 </Sect2>
2671 <Sect2>
2672 <Title>The qdisc family: roots, handles, siblings and parents</Title>
2674 <Para>
2675 Each interface has one egress 'root qdisc', by default the earlier mentioned
2676 classless pfifo_fast queueing discipline. Each qdisc can be assigned a
2677 handle, which can be used by later configuration statements to refer to that
2678 qdisc. Besides an egress qdisc, an interface may also have an ingress, which
2679 polices traffic coming in.
2680 </Para>
2682 <Para>
2683 The handles of these qdiscs consist of two parts, a major number and a minor
2684 number. It is habitual to name the root qdisc '1:', which is equal to '1:0'.
2685 The minor number of a qdisc is always 0. 
2686 </Para>
2688 <Para>
2689 Classes need to have the same major number as their parent. 
2690 </Para>
2692 <Sect3>
2693 <Title>How filters are used to classify traffic </Title>
2695 <Para>
2696 Recapping, a typical hierarchy might look like this:
2698 <Screen>
2699                     root 1:
2700                       |
2701                     _1:1_
2702                    /  |  \
2703                   /   |   \
2704                  /    |    \
2705                10:   11:   12:
2706               /   \       /   \
2707            10:1  10:2   12:1  12:2
2708 </Screen>
2710 </Para>
2712 <Para>
2713 But don't let this tree fool you! You should *not* imagine the kernel to be
2714 at the apex of the tree and the network below, that is just not the case.
2715 Packets get enqueued and dequeued at the root qdisc, which is the only thing
2716 the kernel talks to. 
2717 </Para>
2719 <Para>
2720 A packet might get classified in a chain like this:
2721 </Para>
2723 <Para>
2724 1: -&#62; 1:1 -&#62; 12: -&#62; 12:2
2725 </Para>
2727 <Para>
2728 The packet now resides in a queue in a qdisc attached to class 12:2. In this
2729 example, a filter was attached to each 'node' in the tree, each choosing a
2730 branch to take next. This can make sense. However, this is also possible:
2731 </Para>
2733 <Para>
2734 1: -&#62; 12:2
2735 </Para>
2737 <Para>
2738 In this case, a filter attached to the root decided to send the packet
2739 directly to 12:2.
2740 </Para>
2742 </Sect3>
2744 <Sect3>
2745 <Title>How packets are dequeued to the hardware</Title>
2747 <Para>
2748 When the kernel decides that it needs to extract packets to send to the
2749 interface, the root qdisc 1: gets a dequeue request, which is passed to
2750 1:1, which is in turn passed to 10:, 11: and 12:, which each query their
2751 siblings, and try to dequeue() from them. In this case, the kernel needs to
2752 walk the entire tree, because only 12:2 contains a packet. 
2753 </Para>
2755 <Para>
2756 In short, nested classes ONLY talk to their parent qdiscs, never to an
2757 interface. Only the root qdisc gets dequeued by the kernel!
2758 </Para>
2760 <Para>
2761 The upshot of this is that classes never get dequeued faster than their
2762 parents allow. And this is exactly what we want: this way we can have SFQ in
2763 an inner class, which doesn't do any shaping, only scheduling, and have a
2764 shaping outer qdisc, which does the shaping.
2765 </Para>
2767 </Sect3>
2769 </Sect2>
2771 <Sect2>
2772 <Title>The PRIO qdisc</Title>
2774 <Para>
2775 The PRIO qdisc doesn't actually shape, it only subdivides traffic based on
2776 how you configured your filters. You can consider the PRIO qdisc a kind
2777 of pfifo_fast on steroids, whereby each band is a separate class instead of
2778 a simple FIFO.
2779 </Para>
2781 <Para>
2782 When a packet is enqueued to the PRIO qdisc, a class is chosen based on the
2783 filter commands you gave. By default, three classes are created. These
2784 classes by default contain pure FIFO qdiscs with no internal
2785 structure, but you can replace these by any qdisc you have available.
2786 </Para>
2788 <Para>
2789 Whenever a packet needs to be dequeued, class :1 is tried first. Higher
2790 classes are only used if lower bands all did not give up a packet.
2791 </Para>
2793 <Para>
2794 This qdisc is very useful in case you want to prioritize certain kinds of
2795 traffic without using only TOS-flags but using all the power of the tc
2796 filters. It can also contain more all qdiscs, whereas pfifo_fast is limited
2797 to simple fifo qdiscs.
2798 </Para>
2800 <Para>
2801 Because it doesn't actually shape, the same warning as for SFQ holds: either
2802 use it only if your physical link is really full or wrap it inside a
2803 classful qdisc that does shape. The last holds for almost all cable modems
2804 and DSL devices.
2805 </Para>
2807 <Para>
2808 In formal words, the PRIO qdisc is a Work-Conserving scheduler.
2809 </Para>
2811 <Sect3>
2812 <Title>PRIO parameters &amp; usage</Title>
2814 <Para>
2815 The following parameters are recognized by tc:
2816 <VariableList>
2818 <VarListEntry>
2819 <Term>bands</Term>
2820 <ListItem>
2821 <Para>
2822 Number of bands to create. Each band is in fact a class. If you change this
2823 number, you must also change:
2824 </Para></ListItem>
2825 </VarListEntry>
2826 <VarListEntry>
2827 <Term>priomap</Term>
2828 <ListItem>
2829 <Para>
2830 If you do not provide tc filters to classify traffic, the PRIO qdisc looks
2831 at the TC_PRIO priority to decide how to enqueue traffic. 
2832 </Para>
2834 <Para>
2835 This works just like with the pfifo_fast qdisc mentioned earlier, see there
2836 for lots of detail.
2837 </Para></ListItem>
2838 </VarListEntry>
2839 </VariableList>
2840 The bands are classes, and are called major:1 to major:3 by default, so if
2841 your PRIO qdisc is called 12:, tc filter traffic to 12:1 to grant it more
2842 priority.
2843 </Para>
2845 <Para>
2846 Reiterating, band 0 goes to minor number 1! Band 1 to minor number 2, etc.
2847 </Para>
2849 </Sect3>
2851 <Sect3>
2852 <Title>Sample configuration</Title>
2854 <Para>
2855 We will create this tree:
2857 <Screen>
2858      root 1: prio
2859        /   |   \
2860      1:1  1:2  1:3
2861       |    |    |
2862      10:  20:  30:
2863      sfq  tbf  sfq
2864 band  0    1    2
2865 </Screen>
2867 </Para>
2869 <Para>
2870 Bulk traffic will go to 30:, interactive traffic to 20: or 10:.
2871 </Para>
2873 <Para>
2874 Command lines:
2876 <Screen>
2877 # tc qdisc add dev eth0 root handle 1: prio 
2878 ## This *instantly* creates classes 1:1, 1:2, 1:3
2879   
2880 # tc qdisc add dev eth0 parent 1:1 handle 10: sfq
2881 # tc qdisc add dev eth0 parent 1:2 handle 20: tbf rate 20kbit buffer 1600 limit 3000
2882 # tc qdisc add dev eth0 parent 1:3 handle 30: sfq                                
2883 </Screen>
2885 </Para>
2887 <Para>
2888 Now let's see what we created:
2890 <Screen>
2891 # tc -s qdisc ls dev eth0 
2892 qdisc sfq 30: quantum 1514b 
2893  Sent 0 bytes 0 pkts (dropped 0, overlimits 0) 
2895  qdisc tbf 20: rate 20Kbit burst 1599b lat 667.6ms 
2896  Sent 0 bytes 0 pkts (dropped 0, overlimits 0) 
2898  qdisc sfq 10: quantum 1514b 
2899  Sent 132 bytes 2 pkts (dropped 0, overlimits 0) 
2901  qdisc prio 1: bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
2902  Sent 174 bytes 3 pkts (dropped 0, overlimits 0) 
2903 </Screen>
2905 As you can see, band 0 has already had some traffic, and one packet was sent
2906 while running this command!
2907 </Para>
2909 <Para>
2910 We now do some bulk data transfer with a tool that properly sets TOS flags,
2911 and take another look:
2913 <Screen>
2914 # scp tc ahu@10.0.0.11:./
2915 ahu@10.0.0.11's password: 
2916 tc                   100% |*****************************|   353 KB    00:00    
2917 # tc -s qdisc ls dev eth0
2918 qdisc sfq 30: quantum 1514b 
2919  Sent 384228 bytes 274 pkts (dropped 0, overlimits 0) 
2921  qdisc tbf 20: rate 20Kbit burst 1599b lat 667.6ms 
2922  Sent 2640 bytes 20 pkts (dropped 0, overlimits 0) 
2924  qdisc sfq 10: quantum 1514b 
2925  Sent 2230 bytes 31 pkts (dropped 0, overlimits 0) 
2927  qdisc prio 1: bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
2928  Sent 389140 bytes 326 pkts (dropped 0, overlimits 0) 
2929 </Screen>
2931 As you can see, all traffic went to handle 30:, which is the lowest priority
2932 band, just as intended. Now to verify that interactive traffic goes to
2933 higher bands, we create some interactive traffic:
2934 </Para>
2936 <Para>
2938 <Screen>
2939 # tc -s qdisc ls dev eth0
2940 qdisc sfq 30: quantum 1514b 
2941  Sent 384228 bytes 274 pkts (dropped 0, overlimits 0) 
2943  qdisc tbf 20: rate 20Kbit burst 1599b lat 667.6ms 
2944  Sent 2640 bytes 20 pkts (dropped 0, overlimits 0) 
2946  qdisc sfq 10: quantum 1514b 
2947  Sent 14926 bytes 193 pkts (dropped 0, overlimits 0) 
2949  qdisc prio 1: bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
2950  Sent 401836 bytes 488 pkts (dropped 0, overlimits 0) 
2951 </Screen>
2953 </Para>
2955 <Para>
2956 It worked - all additional traffic has gone to 10:, which is our highest
2957 priority qdisc. No traffic was sent to the lowest priority, which previously
2958 received our entire scp.
2959 </Para>
2961 </Sect3>
2963 </Sect2>
2965 <Sect2>
2966 <Title>The famous CBQ qdisc</Title>
2968 <Para>
2969 As said before, CBQ is the most complex qdisc available, the most hyped, the
2970 least understood, and probably the trickiest one to get right. This is not
2971 because the authors are evil or incompetent, far from it, it's just that the
2972 CBQ algorithm isn't all that precise and doesn't really match the way Linux
2973 works.
2974 </Para>
2976 <Para>
2977 Besides being classful, CBQ is also a shaper and it is in that aspect that
2978 it really doesn't work very well. It should work like this. If you try to
2979 shape a 10mbit/s connection to 1mbit/s, the link should be idle 90&percnt; of the
2980 time. If it isn't, we need to throttle so that it IS idle 90&percnt; of the time.
2981 </Para>
2983 <Para>
2984 This is pretty hard to measure, so CBQ  instead derives the idle time from
2985 the number of microseconds that elapse between requests from the hardware
2986 layer for more data. Combined, this can be used to approximate how full or
2987 empty the link is.
2988 </Para>
2990 <Para>
2991 This is rather circumspect and doesn't always arrive at proper results. For
2992 example, what if the actual link speed of an interface that is not really
2993 able to transmit the full 100mbit/s of data, perhaps because of a badly
2994 implemented driver? A PCMCIA network card will also never achieve 100mbit/s
2995 because of the way the bus is designed - again, how do we calculate the idle
2996 time?
2997 </Para>
2999 <Para>
3000 It gets even worse if we consider not-quite-real network devices like PPP
3001 over Ethernet or PPTP over TCP/IP. The effective bandwidth in that case is
3002 probably determined by the efficiency of pipes to userspace - which is huge.
3003 </Para>
3005 <Para>
3006 People who have done measurements discover that CBQ is not always very
3007 accurate and sometimes completely misses the mark.
3008 </Para>
3010 <Para>
3011 In many circumstances however it works well. With the documentation provided
3012 here, you should be able to configure it to work well in most cases.
3013 </Para>
3015 <Sect3>
3016 <Title>CBQ shaping in detail</Title>
3018 <Para>
3019 As said before, CBQ works by making sure that the link is idle just long
3020 enough to bring down the real bandwidth to the configured rate. To do so, it
3021 calculates the time that should pass between average packets. 
3022 </Para>
3024 <Para>
3025 During operations, the effective idletime is measured using an exponential
3026 weighted moving average (EWMA), which considers recent packets to be
3027 exponentially more important than past ones. The UNIX loadaverage is
3028 calculated in the same way.
3029 </Para>
3031 <Para>
3032 The calculated idle time is subtracted from the EWMA measured one, the
3033 resulting number is called 'avgidle'. A perfectly loaded link has an avgidle
3034 of zero: packets arrive exactly once every calculated interval.  
3035 </Para>
3037 <Para>
3038 An overloaded link has a negative avgidle and if it gets too negative, CBQ
3039 shuts down for a while and is then 'overlimit'.
3040 </Para>
3042 <Para>
3043 Conversely, an idle link might amass a huge avgidle, which would then allow
3044 infinite bandwidths after a few hours of silence. To prevent this, avgidle is
3045 capped at maxidle.
3046 </Para>
3048 <Para>
3049 If overlimit, in theory, the CBQ could throttle itself for exactly the
3050 amount of time that was calculated to pass between packets, and then pass
3051 one packet, and throttle again. But see the 'minburst' parameter below.
3052 </Para>
3054 <Para>
3055 These are parameters you can specify in order to configure shaping:
3056 <VariableList>
3058 <VarListEntry>
3059 <Term>avpkt</Term>
3060 <ListItem>
3061 <Para>
3062 Average size of a packet, measured in bytes. Needed for calculating maxidle,
3063 which is derived from maxburst, which is specified in packets.
3064 </Para></ListItem>
3065 </VarListEntry>
3066 <VarListEntry>
3067 <Term>bandwidth</Term>
3068 <ListItem>
3069 <Para>
3070 The physical bandwidth of your device, needed for idle time
3071 calculations.
3072 </Para></ListItem>
3073 </VarListEntry>
3074 <VarListEntry>
3075 <Term>cell</Term>
3076 <ListItem>
3077 <Para>
3078 The time a packet takes to be transmitted over a device may grow in steps,
3079 based on the packet size. An 800 and an 806 size packet may take just as long
3080 to send, for example - this sets the granularity. Most often set to '8'.
3081 Must be an integral power of two.
3082 </Para></ListItem>
3083 </VarListEntry>
3084 <VarListEntry>
3085 <Term>maxburst</Term>
3086 <ListItem>
3087 <Para>
3088 This number of packets is used to calculate maxidle so that when avgidle is
3089 at maxidle, this number of average packets can be burst before avgidle drops
3090 to 0. Set it higher to be more tolerant of bursts. You can't set maxidle
3091 directly, only via this parameter.
3092 </Para></ListItem>
3093 </VarListEntry>
3094 <VarListEntry>
3095 <Term>minburst</Term>
3096 <ListItem>
3097 <Para>
3098 As mentioned before, CBQ needs to throttle in case of overlimit. The ideal
3099 solution is to do so for exactly the calculated idle time, and pass 1
3100 packet. However, Unix kernels generally have a hard time scheduling events
3101 shorter than 10ms, so it is better to throttle for a longer period, and then
3102 pass minburst packets in one go, and then sleep minburst times longer.
3103 </Para>
3105 <Para>
3106 The time to wait is called the offtime. Higher values of minburst lead to
3107 more accurate shaping in the long term, but to bigger bursts at millisecond
3108 timescales.
3109 </Para></ListItem>
3110 </VarListEntry>
3111 <VarListEntry>
3112 <Term>minidle</Term>
3113 <ListItem>
3114 <Para>
3115 If avgidle is below 0, we are overlimits and need to wait until avgidle will
3116 be big enough to send one packet. To prevent a sudden burst from shutting
3117 down the link for a prolonged period of time, avgidle is reset to minidle if
3118 it gets too low.
3119 </Para>
3121 <Para>
3122 Minidle is specified in negative microseconds, so 10 means that avgidle is
3123 capped at -10us.
3124 </Para></ListItem>
3125 </VarListEntry>
3126 <VarListEntry>
3127 <Term>mpu</Term>
3128 <ListItem>
3129 <Para>
3130 Minimum packet size - needed because even a zero size packet is padded
3131 to 64 bytes on ethernet, and so takes a certain time to transmit. CBQ needs
3132 to know this to accurately calculate the idle time.
3133 </Para></ListItem>
3134 </VarListEntry>
3135 <VarListEntry>
3136 <Term>rate</Term>
3137 <ListItem>
3138 <Para>
3139 Desired rate of traffic leaving this qdisc - this is the 'speed knob'!
3140 </Para></ListItem>
3141 </VarListEntry>
3142 </VariableList>
3143 </Para>
3145 <Para>
3146 Internally, CBQ has a lot of fine tuning. For example, classes which are
3147 known not to have data enqueued to them aren't queried. Overlimit classes
3148 are penalized by lowering their effective priority. All very smart &amp;
3149 complicated.
3150 </Para>
3152 </Sect3>
3154 <Sect3>
3155 <Title>CBQ classful behaviour</Title>
3157 <Para>
3158 Besides shaping, using the aforementioned idletime approximations, CBQ also
3159 acts like the PRIO queue in the sense that classes can have differing
3160 priorities and that lower priority numbers will be polled before the higher
3161 priority ones.
3162 </Para>
3164 <Para>
3165 Each time a packet is requested by the hardware layer to be sent out to the
3166 network, a weighted round robin process ('WRR') starts, beginning with the
3167 lower priority classes.
3168 </Para>
3170 <Para>
3171 These are then grouped and queried if they have data available. If so, it is
3172 returned. After a class has been allowed to dequeue a number of bytes, the
3173 next class within that priority is tried.
3174 </Para>
3176 <Para>
3177 The following parameters control the WRR process:
3178 <VariableList>
3180 <VarListEntry>
3181 <Term>allot</Term>
3182 <ListItem>
3183 <Para>
3184 When the outer CBQ is asked for a packet to send out on the interface, it
3185 will try all inner qdiscs (in the classes) in turn, in order of 
3186 the 'priority' parameter. Each time a class gets its turn, it can only send out
3187 a limited amount of data. 'Allot' is the base unit of this amount. See 
3188 the 'weight' parameter for more information.
3189 </Para></ListItem>
3190 </VarListEntry>
3191 <VarListEntry>
3192 <Term>prio</Term>
3193 <ListItem>
3194 <Para>
3195 The CBQ can also act like the PRIO device. Inner classes with lower priority
3196 are tried first and as long as they have traffic, other classes are not
3197 polled for traffic.
3198 </Para></ListItem>
3199 </VarListEntry>
3200 <VarListEntry>
3201 <Term>weight</Term>
3202 <ListItem>
3203 <Para>
3204 Weight helps in the Weighted Round Robin process. Each class gets a chance
3205 to send in turn. If you have classes with significantly more bandwidth than
3206 other classes, it makes sense to allow them to send more data in one round
3207 than the others.
3208 </Para>
3210 <Para>
3211 A CBQ adds up all weights under a class, and normalizes them, so you can use
3212 arbitrary numbers: only the ratios are important. People have been 
3213 using 'rate/10' as a rule of thumb and it appears to work well. The renormalized
3214 weight is multiplied by the 'allot' parameter to determine how much data can
3215 be sent in one round. 
3216 </Para></ListItem>
3217 </VarListEntry>
3218 </VariableList>
3219 </Para>
3221 <Para>
3222 Please note that all classes within an CBQ hierarchy need to share the same
3223 major number!
3224 </Para>
3226 </Sect3>
3228 <Sect3>
3229 <Title>CBQ parameters that determine link sharing &amp; borrowing</Title>
3231 <Para>
3232 Besides purely limiting certain kinds of traffic, it is also possible to
3233 specify which classes can borrow capacity from other classes or, conversely,
3234 lend out bandwidth.
3235 </Para>
3237 <Para>
3238 <VariableList>
3240 <VarListEntry>
3241 <Term>Isolated/sharing</Term>
3242 <ListItem>
3243 <Para>
3244 A class that is configured with 'isolated' will not lend out bandwidth to
3245 sibling classes. Use this if you have competing or mutually-unfriendly
3246 agencies on your link who do want to give each other freebies.
3247 </Para>
3249 <Para>
3250 The control program tc also knows about 'sharing', which is the reverse 
3251 of 'isolated'.
3252 </Para></ListItem>
3253 </VarListEntry>
3254 <VarListEntry>
3255 <Term>bounded/borrow</Term>
3256 <ListItem>
3257 <Para>
3258 A class can also be 'bounded', which means that it will not try to borrow
3259 bandwidth from sibling classes. tc also knows about 'borrow', which is the
3260 reverse of 'bounded'.
3261 </Para></ListItem>
3262 </VarListEntry>
3263 </VariableList>
3264 A typical situation might be where you have two agencies on your link which
3265 are both 'isolated' and 'bounded', which means that they are really limited
3266 to their assigned rate, and also won't allow each other to borrow.
3267 </Para>
3269 <Para>
3270 Within such an agency class, there might be other classes which are allowed
3271 to swap bandwidth.
3272 </Para>
3274 </Sect3>
3276 <Sect3>
3277 <Title>Sample configuration</Title>
3279 <Para>
3280 This configuration limits webserver traffic to 5mbit and SMTP traffic to 3
3281 mbit. Together, they may not get more than 6mbit. We have a 100mbit NIC and
3282 the classes may borrow bandwidth from each other.
3284 <Screen>
3285 # tc qdisc add dev eth0 root handle 1:0 cbq bandwidth 100Mbit         \
3286   avpkt 1000 cell 8
3287 # tc class add dev eth0 parent 1:0 classid 1:1 cbq bandwidth 100Mbit  \
3288   rate 6Mbit weight 0.6Mbit prio 8 allot 1514 cell 8 maxburst 20      \
3289   avpkt 1000 bounded
3290 </Screen>
3292 This part installs the root and the customary 1:0 class. The 1:1 class is
3293 bounded, so the total bandwidth can't exceed 6mbit.
3294 </Para>
3296 <Para>
3297 As said before, CBQ requires a *lot* of knobs. All parameters are explained
3298 above, however. The corresponding HTB configuration is lots simpler.
3299 </Para>
3301 <Para>
3303 <Screen>
3304 # tc class add dev eth0 parent 1:1 classid 1:3 cbq bandwidth 100Mbit  \
3305   rate 5Mbit weight 0.5Mbit prio 5 allot 1514 cell 8 maxburst 20      \
3306   avpkt 1000                       
3307 # tc class add dev eth0 parent 1:1 classid 1:4 cbq bandwidth 100Mbit  \
3308   rate 3Mbit weight 0.3Mbit prio 5 allot 1514 cell 8 maxburst 20      \
3309   avpkt 1000
3310 </Screen>
3312 </Para>
3314 <Para>
3315 These are our two classes. Note how we scale the weight with the configured
3316 rate. Both classes are not bounded, but they are connected to class 1:1
3317 which is bounded.  So the sum of bandwith of the 2 classes will never be
3318 more than 6mbit. The classids need to be within the same major number as
3319 the parent CBQ, by the way!
3320 </Para>
3322 <Para>
3324 <Screen>
3325 # tc qdisc add dev eth0 parent 1:3 handle 30: sfq
3326 # tc qdisc add dev eth0 parent 1:4 handle 40: sfq
3327 </Screen>
3329 </Para>
3331 <Para>
3332 Both classes have a FIFO qdisc by default.  But we replaced these with an SFQ
3333 queue so each flow of data is treated equally.
3335 <Screen>
3336 # tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip \
3337   sport 80 0xffff flowid 1:3
3338 # tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip \
3339   sport 25 0xffff flowid 1:4
3340 </Screen>
3342 </Para>
3344 <Para>
3345 These commands, attached directly to the root, send traffic to the right
3346 qdiscs.
3347 </Para>
3349 <Para>
3350 Note that we use 'tc class add' to CREATE classes within a qdisc, but that
3351 we use 'tc qdisc add' to actually add qdiscs to these classes.
3352 </Para>
3354 <Para>
3355 You may wonder what happens to traffic that is not classified by any of the
3356 two rules. It appears that in this case, data will then be processed within
3357 1:0, and be unlimited. 
3358 </Para>
3360 <Para>
3361 If SMTP+web together try to exceed the set limit of 6mbit/s, bandwidth will
3362 be divided according to the weight parameter, giving 5/8 of traffic to  the
3363 webserver and 3/8 to the mail server.
3364 </Para>
3366 <Para>
3367 With this configuration you can also say that webserver traffic will always
3368 get at minimum 5/8 * 6 mbit = 3.75 mbit.
3369 </Para>
3371 </Sect3>
3373 <Sect3>
3374 <Title>Other CBQ parameters: split &amp; defmap</Title>
3376 <Para>
3377 As said before, a classful qdisc needs to call filters to determine
3378 which class a packet will be enqueued to. 
3379 </Para>
3381 <Para>
3382 Besides calling the filter, CBQ offers other options, defmap &amp; split.
3383 This is pretty complicated to understand, and it is not vital. But as this
3384 is the only known place where defmap &amp; split are properly explained, I'm
3385 doing my best. 
3386 </Para>
3388 <Para>
3389 As you will often want to filter on the Type of Service field only, a special
3390 syntax is provided. Whenever the CBQ needs to figure out where a packet
3391 needs to be enqueued, it checks if this node is a 'split node'. If so, one
3392 of the sub-qdiscs has indicated that it wishes to receive all packets with
3393 a certain configured priority, as might be derived from the TOS field, or
3394 socket options set by applications.
3395 </Para>
3397 <Para>
3398 The packets' priority bits are or-ed with the defmap field to see if a match
3399 exists. In other words, this is a short-hand way of creating a very fast
3400 filter, which only matches certain priorities. A defmap of ff (hex) will
3401 match everything, a map of 0 nothing. A sample configuration may help make
3402 things clearer:
3403 </Para>
3405 <Para>
3407 <Screen>
3408 # tc qdisc add dev eth1 root handle 1: cbq bandwidth 10Mbit allot 1514 \
3409   cell 8 avpkt 1000 mpu 64
3411 # tc class add dev eth1 parent 1:0 classid 1:1 cbq bandwidth 10Mbit    \
3412   rate 10Mbit allot 1514 cell 8 weight 1Mbit prio 8 maxburst 20        \
3413   avpkt 1000
3414 </Screen>
3416 Standard CBQ preamble. I never get used to the sheer amount of numbers
3417 required!
3418 </Para>
3420 <Para>
3421 Defmap refers to TC_PRIO bits, which are defined as follows:
3422 </Para>
3424 <Para>
3426 <Screen>
3427 TC_PRIO..          Num  Corresponds to TOS
3428 -------------------------------------------------
3429 BESTEFFORT         0    Maximize Reliablity        
3430 FILLER             1    Minimize Cost              
3431 BULK               2    Maximize Throughput (0x8)  
3432 INTERACTIVE_BULK   4                               
3433 INTERACTIVE        6    Minimize Delay (0x10)      
3434 CONTROL            7                               
3435 </Screen>
3437 </Para>
3439 <Para>
3440 The TC_PRIO.. number corresponds to bits, counted from the right. See the
3441 pfifo_fast section for more details how TOS bits are converted to
3442 priorities.
3443 </Para>
3445 <Para>
3446 Now the interactive and the bulk classes:
3447 </Para>
3449 <Para>
3451 <Screen>
3452 # tc class add dev eth1 parent 1:1 classid 1:2 cbq bandwidth 10Mbit     \
3453   rate 1Mbit allot 1514 cell 8 weight 100Kbit prio 3 maxburst 20        \
3454   avpkt 1000 split 1:0 defmap c0
3456 # tc class add dev eth1 parent 1:1 classid 1:3 cbq bandwidth 10Mbit     \
3457   rate 8Mbit allot 1514 cell 8 weight 800Kbit prio 7 maxburst 20        \
3458   avpkt 1000 split 1:0 defmap 3f
3459 </Screen>
3461 </Para>
3463 <Para>
3464 The 'split qdisc' is 1:0, which is where the choice will be made. C0 is
3465 binary for 11000000, 3F for 00111111, so these two together will match
3466 everything. The first class matches bits 7 &#38; 6, and thus corresponds 
3467 to 'interactive' and 'control' traffic. The second class matches the rest.
3468 </Para>
3470 <Para>
3471 Node 1:0 now has a table like this:
3473 <Screen>
3474 priority        send to
3475 0               1:3
3476 1               1:3
3477 2               1:3
3478 3               1:3
3479 4               1:3
3480 5               1:3
3481 6               1:2
3482 7               1:2
3483 </Screen>
3485 </Para>
3487 <Para>
3488 For additional fun, you can also pass a 'change mask', which indicates
3489 exactly which priorities you wish to change. You only need to use this if you
3490 are running 'tc class change'. For example, to add best effort traffic to
3491 1:2, we could run this:
3492 </Para>
3494 <Para>
3496 <Screen>
3497 # tc class change dev eth1 classid 1:2 cbq defmap 01/01
3498 </Screen>
3500 </Para>
3502 <Para>
3503 The priority map over at 1:0 now looks like this:
3504 </Para>
3506 <Para>
3508 <Screen>
3509 priority        send to
3510 0               1:2
3511 1               1:3
3512 2               1:3
3513 3               1:3
3514 4               1:3
3515 5               1:3
3516 6               1:2
3517 7               1:2
3518 </Screen>
3520 </Para>
3522 <Para>
3523 FIXME: did not test 'tc class change', only looked at the source.
3524 </Para>
3526 </Sect3>
3528 </Sect2>
3530 <Sect2>
3531 <Title>Hierarchical Token Bucket </Title>
3533 <Para>
3534 Martin Devera (&lt;devik&gt;) rightly realised that CBQ is complex and does
3535 not seem optimized for many typical situations. His Hierarchical approach is
3536 well suited for setups where you have a fixed amount of bandwidth which you
3537 want to divide for different purposes, giving each purpose a guaranteed
3538 bandwidth, with the possibility of specifying how much bandwidth can be
3539 borrowed.
3540 </Para>
3542 <Para>
3543 HTB works just like CBQ but does not resort to idle time calculations to
3544 shape. Instead, it is a classful Token Bucket Filter - hence the name. It
3545 has only a few parameters, which are well documented on his 
3546 <ULink
3547 URL="http://luxik.cdi.cz/~devik/qos/htb/"
3548 >site</ULink
3550 </Para>
3552 <Para>
3553 As your HTB configuration gets more complex, your configuration scales
3554 well. With CBQ it is already complex even in simple cases! HTB3 (check
3555 <ulink url="http://luxik.cdi.cz/~devik/qos/htb/">its homepage</ulink> for
3556 details on HTB versions) is now part of the official kernel sources 
3557 (from 2.4.20-pre1 and 2.5.31 onwards). However, maybe you still need to
3558 get a HTB3 patched version of 'tc': HTB kernel and userspace parts must
3559 be the same major version, or 'tc' will not work with HTB.
3561 </Para>
3563 <Para>
3564 If you already have a modern kernel, or are in a position to patch your 
3565 kernel, by all means consider HTB.
3566 </para>
3569 <Sect3>
3570 <Title>Sample configuration</Title>
3572 <Para>
3573 Functionally almost identical to the CBQ sample configuration above:
3574 </Para>
3576 <Para>
3578 <Screen>
3579 # tc qdisc add dev eth0 root handle 1: htb default 30
3581 # tc class add dev eth0 parent 1: classid 1:1 htb rate 6mbit burst 15k
3583 # tc class add dev eth0 parent 1:1 classid 1:10 htb rate 5mbit burst 15k
3584 # tc class add dev eth0 parent 1:1 classid 1:20 htb rate 3mbit ceil 6mbit burst 15k
3585 # tc class add dev eth0 parent 1:1 classid 1:30 htb rate 1kbit ceil 6mbit burst 15k
3586 </Screen>
3588 </Para>
3590 <Para>
3591 The author then recommends SFQ for beneath these classes:
3593 <Screen>
3594 # tc qdisc add dev eth0 parent 1:10 handle 10: sfq perturb 10
3595 # tc qdisc add dev eth0 parent 1:20 handle 20: sfq perturb 10
3596 # tc qdisc add dev eth0 parent 1:30 handle 30: sfq perturb 10
3597 </Screen>
3599 </Para>
3601 <Para>
3602 Add the filters which direct traffic to the right classes:
3604 <Screen>
3605 # U32="tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32"
3606 # $U32 match ip dport 80 0xffff flowid 1:10
3607 # $U32 match ip sport 25 0xffff flowid 1:20
3608 </Screen>
3610 And that's it - no unsightly unexplained numbers, no undocumented
3611 parameters. 
3612 </Para>
3614 <Para>
3615 HTB certainly looks wonderful - if 10: and 20: both have their guaranteed
3616 bandwidth, and more is left to divide, they borrow in a 5:3 ratio, just as
3617 you would expect.
3618 </Para>
3620 <Para>
3621 Unclassified traffic gets routed to 30:, which has little bandwidth of its
3622 own but can borrow everything that is left over. Because we chose SFQ
3623 internally, we get fairness thrown in for free!
3624 </Para>
3626 </Sect3>
3628 </Sect2>
3630 </Sect1>
3632 <Sect1 id="lartc.qdisc.filters">
3633   <Title>Classifying packets with filters</Title>
3635 <Para>
3636 To determine which class shall process a packet, the so-called 'classifier
3637 chain' is called each time a choice needs to be made. This chain consists of
3638 all filters attached to the classful qdisc that needs to decide.
3639 </Para>
3641 <Para>To reiterate the tree, which is not a tree:
3642 </Para>
3644 <Screen width="80">
3645                     root 1:
3646                       |
3647                     _1:1_
3648                    /  |  \
3649                   /   |   \
3650                  /    |    \
3651                10:   11:   12:
3652               /   \       /   \
3653            10:1  10:2   12:1  12:2
3654 </Screen>
3656 <Para>
3657 When enqueueing a packet, at each branch the filter chain is consulted for a
3658 relevant instruction. A typical setup might be to have a filter in 1:1 that
3659 directs a packet to 12: and a filter on 12: that sends the packet to 12:2.
3660 </Para>
3662 <Para>
3663 You might also attach this latter rule to 1:1, but you can make efficiency
3664 gains by having more specific tests lower in the chain.
3665 </Para>
3667 <Para>
3668 You can't filter a packet 'upwards', by the way. Also, with HTB, you should
3669 attach all filters to the root!
3670 </Para>
3672 <Para>
3673 And again - packets are only enqueued downwards! When they are dequeued,
3674 they go up again, where the interface lives. They do NOT fall off the end of
3675 the tree to the network adaptor!
3676 </Para>
3678 <Sect2>
3679 <Title>Some simple filtering examples</Title>
3681 <Para>
3682 As explained in the Classifier chapter, you can match on literally anything,
3683 using a very complicated syntax. To start, we will show how to do the
3684 obvious things, which luckily are quite easy.
3685 </Para>
3687 <Para>
3688 Let's say we have a PRIO qdisc called '10:' which contains three classes, and
3689 we want to assign all traffic from and to port 22 to the highest priority
3690 band, the filters would be:
3691 </Para>
3693 <Para>
3695 <Screen>
3696 # tc filter add dev eth0 protocol ip parent 10: prio 1 u32 match \ 
3697   ip dport 22 0xffff flowid 10:1
3698 # tc filter add dev eth0 protocol ip parent 10: prio 1 u32 match \
3699   ip sport 80 0xffff flowid 10:1
3700 # tc filter add dev eth0 protocol ip parent 10: prio 2 flowid 10:2
3701 </Screen>
3703 </Para>
3705 <Para>
3706 What does this say? It says: attach to eth0, node 10: a  priority 1 u32
3707 filter that matches on IP destination port 22 *exactly* and send it to band
3708 10:1. And it then repeats the same for source port 80. The last command says
3709 that anything unmatched so far should go to band 10:2, the next-highest
3710 priority.
3711 </Para>
3713 <Para>
3714 You need to add 'eth0', or whatever your interface is called, because each
3715 interface has a unique namespace of handles.
3716 </Para>
3718 <Para>
3719 To select on an IP address, use this:
3721 <Screen>
3722 # tc filter add dev eth0 parent 10:0 protocol ip prio 1 u32 \ 
3723   match ip dst 4.3.2.1/32 flowid 10:1
3724 # tc filter add dev eth0 parent 10:0 protocol ip prio 1 u32 \
3725   match ip src 1.2.3.4/32 flowid 10:1
3726 # tc filter add dev eth0 protocol ip parent 10: prio 2      \
3727   flowid 10:2
3728 </Screen>
3730 </Para>
3732 <Para>
3733 This assigns traffic to 4.3.2.1 and traffic from 1.2.3.4 to the highest
3734 priority queue, and the rest to the next-highest one.
3735 </Para>
3737 <Para>
3738 You can concatenate matches, to match on traffic from 1.2.3.4 and from port
3739 80, do this:
3741 <Screen>
3742 # tc filter add dev eth0 parent 10:0 protocol ip prio 1 u32 match ip src 4.3.2.1/32
3743   match ip sport 80 0xffff flowid 10:1
3744 </Screen>
3746 </Para>
3748 </Sect2>
3750 <Sect2 id="lartc.filtering.simple">
3751 <Title>All the filtering commands you will normally need</Title>
3753 <Para>
3754 Most shaping commands presented here start with this preamble:
3756 <Screen>
3757 # tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 ..
3758 </Screen>
3760 These are the so called 'u32' matches, which can match on ANY part of a
3761 packet.
3762 <VariableList>
3764 <VarListEntry>
3765 <Term>On source/destination address</Term>
3766 <ListItem>
3767 <Para>
3768 Source mask 'match ip src 1.2.3.0/24', destination mask 'match ip dst
3769 4.3.2.0/24'. To match a single host, use /32, or omit the mask.
3770 </Para></ListItem>
3771 </VarListEntry>
3772 <VarListEntry>
3773 <Term>On source/destination port, all IP protocols</Term>
3774 <ListItem>
3775 <Para>
3776 Source: 'match ip sport 80 0xffff', 'match ip dport 0xffff'
3777 </Para></ListItem>
3778 </VarListEntry>
3779 <VarListEntry>
3780 <Term>On ip protocol (tcp, udp, icmp, gre, ipsec)</Term>
3781 <ListItem>
3782 <Para>
3783 Use the numbers from /etc/protocols, for example, icmp is 1: 'match ip
3784 protocol 1 0xff'. 
3785 </Para></ListItem>
3786 </VarListEntry>
3787 <VarListEntry>
3788 <Term>On fwmark</Term>
3789 <ListItem>
3790 <Para>
3791 You can mark packets with either ipchains and have that mark survive routing
3792 across interfaces. This is really useful to for example only shape traffic on
3793 eth1 that came in on eth0. Syntax: 
3794 &num; tc filter add dev eth1 protocol ip parent 1:0 prio 1 handle 6 fw flowid 1:1
3795 Note that this is not a u32 match!
3796 </Para>
3798 <Para>
3799 You can place a mark like this:
3801 <Screen>
3802 # iptables -A PREROUTING -t mangle -i eth0 -j MARK --set-mark 6
3803 </Screen>
3805 The number 6 is arbitrary.
3806 </Para>
3808 <Para>
3809 If you don't want to understand the full tc filter syntax, just use
3810 iptables, and only learn to select on fwmark.
3811 </Para></ListItem>
3812 </VarListEntry>
3813 <VarListEntry>
3814 <Term>On the TOS field</Term>
3815 <ListItem>
3816 <Para>
3817 To select interactive, minimum delay traffic:
3819 <Screen>
3820 # tc filter add dev ppp0 parent 1:0 protocol ip prio 10 u32 \
3821       match ip tos 0x10 0xff \
3822      flowid 1:4
3823 </Screen>
3825 Use 0x08 0xff for bulk traffic.
3826 </Para></ListItem>
3827 </VarListEntry>
3828 </VariableList>
3829 </Para>
3831 <Para>
3832 For more filtering commands, see the Advanced Filters chapter.
3833 </Para>
3835 </Sect2>
3837 </Sect1>
3838 <Sect1 id="lartc.imq">
3839 <Title>The Intermediate queueing device (IMQ)</Title>
3841 <Para>
3842 The Intermediate queueing device is not a qdisc but its usage is tightly bound
3843 to qdiscs. Within linux, qdiscs are attached to network devices and everything
3844 that is queued to the device is first queued to the qdisc. From this concept,
3845 two limitations arise:
3846 </Para>
3848 <Para>
3849 1. Only egress shaping is possible (an ingress qdisc exists, but its
3850 possibilities are very limited compared to classful qdiscs).
3851 </Para>
3853 <Para>
3854 2. A qdisc can only see traffic of one interface, global limitations can't be
3855 placed.
3856 </Para>
3858 <Para>
3859 IMQ is there to help solve those two limitations. In short, you can put 
3860 everything you choose in a qdisc. Specially marked packets get intercepted
3861 in netfilter NF_IP_PRE_ROUTING and NF_IP_POST_ROUTING hooks and pass through
3862 the qdisc attached to an imq device. An iptables target is used for marking
3863 the packets.
3864 </Para>
3866 <Para>
3867 This enables you to do ingress shaping as you can just mark packets coming in from somewhere and/or treat interfaces as classes to set global limits.
3868 You can also do lots of other stuff like just putting your http traffic in a
3869 qdisc, put new connection requests in a qdisc, ...
3870 </Para>
3872 <Sect2>
3873 <Title>Sample configuration</Title>
3875 <Para>
3876 The first thing that might come to mind is use ingress shaping to give yourself
3877 a high guaranteed bandwidth. ;)
3878 Configuration is just like with any other interface:
3880 <Screen>
3881 tc qdisc add dev imq0 root handle 1: htb default 20
3883 tc class add dev imq0 parent 1: classid 1:1 htb rate 2mbit burst 15k
3885 tc class add dev imq0 parent 1:1 classid 1:10 htb rate 1mbit
3886 tc class add dev imq0 parent 1:1 classid 1:20 htb rate 1mbit
3888 tc qdisc add dev imq0 parent 1:10 handle 10: pfifo
3889 tc qdisc add dev imq0 parent 1:20 handle 20: sfq
3891 tc filter add dev imq0 parent 10:0 protocol ip prio 1 u32 match \
3892                 ip dst 10.0.0.230/32 flowid 1:10
3893 </Screen>
3895 In this example u32 is used for classification. Other classifiers should work as
3896 expected.
3897 Next traffic has to be selected and marked to be enqueued to imq0.
3899 <Screen>
3900 iptables -t mangle -A PREROUTING -i eth0 -j IMQ --todev 0
3902 ip link set imq0 up
3903 </Screen>
3905 </Para>
3907 <Para>
3908 The IMQ iptables targets is valid in the PREROUTING and POSTROUTING chains of
3909 the mangle table. It's syntax is 
3911 <Screen>
3912 IMQ [ --todev n ]       n : number of imq device
3913 </Screen>
3915 An ip6tables target is also provided.
3916 </Para>
3918 <Para>
3919 Please note traffic is not enqueued when the target is hit but afterwards.
3920 The exact location where traffic enters the imq device depends on the
3921 direction of the traffic (in/out).
3922 These are the predefined netfilter hooks used by iptables:
3924 <Screen>
3925 enum nf_ip_hook_priorities {
3926         NF_IP_PRI_FIRST = INT_MIN,
3927         NF_IP_PRI_CONNTRACK = -200,
3928         NF_IP_PRI_MANGLE = -150,
3929         NF_IP_PRI_NAT_DST = -100,
3930         NF_IP_PRI_FILTER = 0,
3931         NF_IP_PRI_NAT_SRC = 100,
3932         NF_IP_PRI_LAST = INT_MAX,
3934 </Screen>
3936 </Para>
3938 <Para>
3939 For ingress traffic, imq registers itself with NF_IP_PRI_MANGLE + 1 priority
3940 which means packets enter the imq device directly after the mangle PREROUTING
3941 chain has been passed.
3942 </Para>
3944 <Para>
3945 For egress imq uses NF_IP_PRI_LAST which honours the fact that packets dropped
3946 by the filter table won't occupy bandwidth.
3947 </Para>
3949 <Para>
3950 The patches and some more information can be found at the
3951 <ULink
3952 URL="http://luxik.cdi.cz/~patrick/imq/"
3953 >imq site</ULink>.
3954 </Para>
3956 </Sect2>
3958 </Sect1>
3960 </chapter>
3962 <chapter id="lartc.loadshare">
3963 <Title>Load sharing over multiple interfaces</Title>
3965 <Para>
3966 There are several ways of doing this. One of the easiest and straightforward
3967 ways is 'TEQL' - "True" (or "trivial") link equalizer. Like most things
3968 having to do with queueing, load sharing goes both ways. Both ends of a link
3969 may need to participate for full effect.
3970 </Para>
3972 <Para>
3973 Imagine this situation:
3974 </Para>
3976 <Para>
3978 <Screen>
3979                  +-------+   eth1   +-------+
3980                  |       |==========|       |
3981  'network 1' ----|   A   |          |   B   |---- 'network 2'
3982                  |       |==========|       |
3983                  +-------+   eth2   +-------+
3984 </Screen>
3986 </Para>
3988 <Para>
3989 A and B are routers, and for the moment we'll assume both run Linux. If
3990 traffic is going from network 1 to network 2, router A needs to distribute
3991 the packets over both links to B. Router B needs to be configured to accept
3992 this. Same goes the other way around, when packets go from network 2 to
3993 network 1, router B needs to send the packets over both eth1 and eth2.
3994 </Para>
3996 <Para>
3997 The distributing part is done by a 'TEQL' device, like this (it couldn't be
3998 easier):
3999 </Para>
4001 <Para>
4003 <Screen>
4004 # tc qdisc add dev eth1 root teql0
4005 # tc qdisc add dev eth2 root teql0
4006 # ip link set dev teql0 up
4007 </Screen>
4009 </Para>
4011 <Para>
4012 Don't forget the 'ip link set up' command!
4013 </Para>
4015 <Para>
4016 This needs to be done on both hosts. The device teql0 is basically a
4017 roundrobbin distributor over eth1 and eth2, for sending packets. No data
4018 ever comes in over an teql device, that just appears on the 'raw' eth1 and
4019 eth2.
4020 </Para>
4022 <Para>
4023 But now we just have devices, we also need proper routing. One way to do
4024 this is to assign a /31 network to both links, and a /31 to the teql0 device
4025 as well:
4026 </Para>
4028 <Para>
4029 FIXME: does this need something like 'nobroadcast'? A /31 is too small to
4030 house a network address and a broadcast address - if this doesn't work as
4031 planned, try a /30, and adjust the ip addresses accordingly. You might even
4032 try to make eth1 and eth2 do without an IP address!
4033 </Para>
4035 <Para>
4036 On router A:
4038 <Screen>
4039 # ip addr add dev eth1 10.0.0.0/31
4040 # ip addr add dev eth2 10.0.0.2/31
4041 # ip addr add dev teql0 10.0.0.4/31
4042 </Screen>
4044 </Para>
4046 <Para>
4047 On router B:
4049 <Screen>
4050 # ip addr add dev eth1 10.0.0.1/31
4051 # ip addr add dev eth2 10.0.0.3/31
4052 # ip addr add dev teql0 10.0.0.5/31
4053 </Screen>
4055 </Para>
4057 <Para>
4058 Router A should now be able to ping 10.0.0.1, 10.0.0.3 and 10.0.0.5 over the
4059 2 real links and the 1 equalized device. Router B should be able to ping
4060 10.0.0.0, 10.0.0.2 and 10.0.0.4 over the links.
4061 </Para>
4063 <Para>
4064 If this works, Router A should make 10.0.0.5 its route for reaching network
4065 2, and Router B should make 10.0.0.4 its route for reaching network 1. For
4066 the special case where network 1 is your network at home, and network 2 is
4067 the Internet, Router A should make 10.0.0.5 its default gateway.
4068 </Para>
4070 <Sect1 id="lartc.loadshare.caveats">
4071   <Title>Caveats</Title>
4073 <Para>
4074 Nothing is as easy as it seems. eth1 and eth2 on both router A and B need to
4075 have return path filtering turned off, because they will otherwise drop
4076 packets destined for ip addresses other than their own:
4077 </Para>
4079 <Para>
4081 <Screen>
4082 # echo 0 &#62; /proc/net/ipv4/conf/eth1/rp_filter
4083 # echo 0 &#62; /proc/net/ipv4/conf/eth2/rp_filter
4084 </Screen>
4086 </Para>
4088 <Para>
4089 Then there is the nasty problem of packet reordering. Let's say 6 packets
4090 need to be sent from A to B - eth1 might get 1, 3 and 5. eth2 would then do
4091 2, 4 and 6. In an ideal world, router B would receive this in order, 1, 2,
4092 3, 4, 5, 6. But the possibility is very real that the kernel gets it like
4093 this: 2, 1, 4, 3, 6, 5. The problem is that this confuses TCP/IP. While not
4094 a problem for links carrying many different TCP/IP sessions, you won't be
4095 able to to a bundle multiple links and get to ftp a single file lots faster,
4096 except when your receiving or sending OS is Linux, which is not easily
4097 shaken by some simple reordering.
4098 </Para>
4100 <Para>
4101 However, for lots of applications, link load balancing is a great idea.
4102 </Para>
4104 </Sect1>
4105 <Sect1 id="lartc.loadshare.other">
4106   <Title>Other possibilities</Title>
4107 <para>
4108 William Stearns has used an advanced tunneling setup to achieve good use of
4109 multiple, unrelated, internet connections together. It can be found on
4110 <ULink
4111 URL="http://www.stearns.org/tunnel/">his tunneling page</ULink>.
4112 </para>
4113 <para>
4114 The HOWTO may feature more about this in the future.
4115 </para>
4116 </Sect1>
4117 </chapter>
4119 <chapter id="lartc.netfilter">
4120 <Title>Netfilter &amp; iproute - marking packets</Title>
4122 <Para>
4123 So far we've seen how iproute works, and netfilter was mentioned a few
4124 times. This would be a good time to browse through <ULink
4125 URL="http://netfilter.samba.org/unreliable-guides/"
4126 >Rusty's Remarkably Unreliable Guides</ULink
4127 >. Netfilter itself
4128 can be found <ULink
4129 URL="http://netfilter.filewatcher.org/"
4130 >here</ULink
4132 </Para>
4134 <Para>
4135 Netfilter allows us to filter packets, or mangle their headers. One special
4136 feature is that we can mark a packet with a number. This is done with the
4137 --set-mark facility. 
4138 </Para>
4140 <Para>
4141 As an example, this command marks all packets destined for port 25, outgoing
4142 mail:
4143 </Para>
4145 <Para>
4147 <Screen>
4148 # iptables -A PREROUTING -i eth0 -t mangle -p tcp --dport 25 \
4149  -j MARK --set-mark 1
4150 </Screen>
4152 </Para>
4154 <Para>
4155 Let's say that we have multiple connections, one that is fast (and
4156 expensive, per megabyte) and one that is slower, but flat fee. We would most
4157 certainly like outgoing mail to go via the cheap route.
4158 </Para>
4160 <Para>
4161 We've already marked the packets with a '1', we now instruct the routing
4162 policy database to act on this:
4163 </Para>
4165 <Para>
4167 <Screen>
4168 # echo 201 mail.out &#62;&#62; /etc/iproute2/rt_tables
4169 # ip rule add fwmark 1 table mail.out
4170 # ip rule ls
4171 0:      from all lookup local 
4172 32764:  from all fwmark        1 lookup mail.out 
4173 32766:  from all lookup main 
4174 32767:  from all lookup default 
4175 </Screen>
4177 </Para>
4179 <Para>
4180 Now we generate the mail.out table with a route to the slow but cheap link:
4182 <Screen>
4183 # /sbin/ip route add default via 195.96.98.253 dev ppp0 table mail.out
4184 </Screen>
4186 </Para>
4188 <Para>
4189 And we are done. Should we want to make exceptions, there are lots of ways
4190 to achieve this. We can modify the netfilter statement to exclude certain
4191 hosts, or we can insert a rule with a lower priority that points to the main
4192 table for our excepted hosts.
4193 </Para>
4195 <Para>
4196 We can also use this feature to honour TOS bits by marking packets with a
4197 different type of service with different numbers, and creating rules to act
4198 on that. This way you can even dedicate, say, an ISDN line to interactive
4199 sessions.
4200 </Para>
4202 <Para>
4203 Needless to say, this also works fine on a host that's doing NAT
4204 ('masquerading').
4205 </Para>
4207 <Para>
4208 IMPORTANT: We received a report that MASQ and SNAT at least collide
4209 with marking packets. Rusty Russell explains it in
4210 <ULink
4211 URL="http://lists.samba.org/pipermail/netfilter/2000-November/006089.html"
4212 >this posting</ULink
4213 >. Turn off the reverse path filter to make it work
4214 properly.
4215 </Para>
4217 <Para>
4218 Note: to mark packets, you need to have some options enabled in your
4219 kernel:
4220 </Para>
4222 <Para>
4224 <Screen>
4225 IP: advanced router (CONFIG_IP_ADVANCED_ROUTER) [Y/n/?]
4226 IP: policy routing (CONFIG_IP_MULTIPLE_TABLES) [Y/n/?]
4227 IP: use netfilter MARK value as routing key (CONFIG_IP_ROUTE_FWMARK) [Y/n/?]
4228 </Screen>
4230 </Para>
4232 <Para>
4233 See also the <xref linkend="lartc.cookbook.squid"> in the
4234 <citetitle><xref linkend="lartc.cookbook"></citetitle>.
4235 </Para>
4237 </chapter>
4239 <chapter id="lartc.adv-filter"
4240   xreflabel="Advanced filters for (re-)classifying packets">
4241   <Title>Advanced filters for (re-)classifying packets</Title>
4243 <Para>
4244 As explained in the section on classful queueing disciplines, filters are
4245 needed to classify packets into any of the sub-queues. These filters are
4246 called from within the classful qdisc.
4247 </Para>
4249 <Para>
4250 Here is an incomplete list of classifiers available:
4251 <VariableList>
4253 <VarListEntry>
4254 <Term>fw</Term>
4255 <ListItem>
4256 <Para>
4257 Bases the decision on how the firewall has marked the packet. This can be
4258 the easy way out if you don't want to learn tc filter syntax. See the
4259 Queueing chapter for details.
4260 </Para></ListItem>
4261 </VarListEntry>
4262 <VarListEntry>
4263 <Term>u32</Term>
4264 <ListItem>
4265 <Para>
4266 Bases the decision on fields within the packet (i.e. source IP address, etc)
4267 </Para></ListItem>
4268 </VarListEntry>
4269 <VarListEntry>
4270 <Term>route</Term>
4271 <ListItem>
4272 <Para>
4273 Bases the decision on which route the packet will be routed by
4274 </Para></ListItem>
4275 </VarListEntry>
4276 <VarListEntry>
4277 <Term>rsvp, rsvp6</Term>
4278 <ListItem>
4279 <Para>
4280 Routes packets based on <ULink
4281 URL="http://www.isi.edu/div7/rsvp/overview.html"
4282 >RSVP </ULink
4283 >. Only useful
4284 on networks you control - the Internet does not respect RSVP.
4285 </Para></ListItem>
4286 </VarListEntry>
4287 <VarListEntry>
4288 <Term>tcindex</Term>
4289 <ListItem>
4290 <Para>
4291 Used in the DSMARK qdisc, see the relevant section.
4292 </Para></ListItem>
4293 </VarListEntry>
4294 </VariableList>
4295 </Para>
4297 <Para>
4298 Note that in general there are many ways in which you can classify packet
4299 and that it generally comes down to preference as to which system you wish
4300 to use.
4301 </Para>
4303 <Para>
4304 Classifiers in general accept a few arguments in common. They are listed
4305 here for convenience:
4306 </Para>
4308 <Para>
4309 <VariableList>
4311 <VarListEntry>
4312 <Term>protocol</Term>
4313 <ListItem>
4314 <Para>
4315 The protocol this classifier will accept. Generally you will only be
4316 accepting only IP traffic. Required.
4317 </Para></ListItem>
4318 </VarListEntry>
4319 <VarListEntry>
4320 <Term>parent</Term>
4321 <ListItem>
4322 <Para>
4323 The handle this classifier is to be attached to. This handle must be
4324 an already existing class. Required.
4325 </Para></ListItem>
4326 </VarListEntry>
4327 <VarListEntry>
4328 <Term>prio</Term>
4329 <ListItem>
4330 <Para>
4331 The priority of this classifier. Lower numbers get tested first.
4332 </Para></ListItem>
4333 </VarListEntry>
4334 <VarListEntry>
4335 <Term>handle</Term>
4336 <ListItem>
4337 <Para>
4338 This handle means different things to different filters.
4339 </Para></ListItem>
4340 </VarListEntry>
4341 </VariableList>
4342 </Para>
4344 <Para>
4345 All the following sections will assume you are trying to shape the traffic
4346 going to <Literal remap="tt">HostA</Literal>. They will assume that the root class has been
4347 configured on 1: and that the class you want to send the selected traffic to
4348 is 1:1.
4349 </Para>
4351 <Sect1 id="lartc.adv-filter.u32">
4352   <Title>The <option>u32</option> classifier</Title>
4354 <Para>
4355 The U32 filter is the most advanced filter available in the current
4356 implementation. It entirely based on hashing tables, which make it
4357 robust when there are many filter rules.
4358 </Para>
4360 <Para>
4361 In its simplest form the U32 filter is a list of records, each
4362 consisting of two fields: a selector and an action. The selectors,
4363 described below, are compared with the currently processed IP packet
4364 until the first match occurs, and then the associated action is performed.
4365 The simplest type of action would be directing the packet into defined
4366 CBQ class.
4367 </Para>
4369 <Para>
4370 The command line of <Literal remap="tt">tc filter</Literal> program, used to configure the filter,
4371 consists of three parts: filter specification, a selector and an action.
4372 The filter specification can be defined as:
4373 </Para>
4375 <Para>
4377 <Screen>
4378 tc filter add dev IF [ protocol PROTO ]
4379                      [ (preference|priority) PRIO ]
4380                      [ parent CBQ ]
4381 </Screen>
4383 </Para>
4385 <Para>
4386 The <Literal remap="tt">protocol</Literal> field describes protocol that the filter will be
4387 applied to. We will only discuss case of <Literal remap="tt">ip</Literal> protocol. The
4388 <Literal remap="tt">preference</Literal> field (<Literal remap="tt">priority</Literal> can be used alternatively)
4389 sets the priority of currently defined filter. This is important, since
4390 you can have several filters (lists of rules) with different priorities.
4391 Each list will be passed in the order the rules were added, then list with
4392 lower priority (higher preference number) will be processed. The <Literal remap="tt">parent</Literal>
4393 field defines the CBQ tree top (e.g. 1:0), the filter should be attached
4395 </Para>
4397 <Para>
4398 The options described above apply to all filters, not only U32.
4399 </Para>
4401 <Sect2>
4402 <Title>U32 selector </Title>
4404 <Para>
4405 The U32 selector contains definition of the pattern, that will be matched
4406 to the currently processed packet. Precisely, it defines which bits are
4407 to be matched in the packet header and nothing more, but this simple
4408 method is very powerful. Let's take a look at the following examples,
4409 taken directly from a pretty complex, real-world filter:
4410 </Para>
4412 <Para>
4414 <Screen>
4415 # tc filter add dev eth0 protocol ip parent 1:0 pref 10 u32 \
4416   match u32 00100000 00ff0000 at 0 flowid 1:10
4417 </Screen>
4419 </Para>
4421 <Para>
4422 For now, leave the first line alone - all these parameters describe
4423 the filter's hash tables. Focus on the selector line, containing
4424 <Literal remap="tt">match</Literal> keyword. This selector will match to IP headers, whose
4425 second byte will be 0x10 (0010). As you can guess, the 00ff number is
4426 the match mask, telling the filter exactly which bits to match. Here
4427 it's 0xff, so the byte will match if it's exactly 0x10. The <Literal remap="tt">at</Literal>
4428 keyword means that the match is to be started at specified offset (in
4429 bytes) -- in this case it's beginning of the packet.  Translating all
4430 that to human language, the packet will match if its Type of Service
4431 field will have `low delay' bits set. Let's analyze another rule:
4432 </Para>
4434 <Para>
4436 <Screen>
4437 # tc filter add dev eth0 protocol ip parent 1:0 pref 10 u32 \
4438   match u32 00000016 0000ffff at nexthdr+0 flowid 1:10
4439 </Screen>
4441 </Para>
4443 <Para>
4444 The <Literal remap="tt">nexthdr</Literal> option means next header encapsulated in the IP packet,
4445 i.e. header of upper-layer protocol. The match will also start here
4446 at the beginning of the next header. The match should occur in the
4447 second, 32-bit word of the header. In TCP and UDP protocols this field
4448 contains packet's destination port. The number is given in big-endian
4449 format, i.e. older bits first, so we simply read 0x0016 as 22 decimal,
4450 which stands for SSH service if this was TCP. As you guess, this match
4451 is ambiguous without a context, and we will discuss this later.
4452 </Para>
4454 <Para>
4455 Having understood all the above, we will find the following selector
4456 quite easy to read: <Literal remap="tt">match c0a80100 ffffff00 at 16</Literal>. What we
4457 got here is a three byte match at 17-th byte, counting from the IP
4458 header start. This will match for packets with destination address
4459 anywhere in 192.168.1/24 network. After analyzing the examples, we
4460 can summarize what we have learned.
4461 </Para>
4463 </Sect2>
4465 <Sect2>
4466 <Title>General selectors</Title>
4468 <Para>
4469 General selectors define the pattern, mask and offset the pattern
4470 will be matched to the packet contents. Using the general selectors
4471 you can match virtually any single bit in the IP (or upper layer)
4472 header. They are more difficult to write and read, though, than
4473 specific selectors that described below. The general selector syntax
4475 </Para>
4477 <Para>
4479 <Screen>
4480 match [ u32 | u16 | u8 ] PATTERN MASK [ at OFFSET | nexthdr+OFFSET]
4481 </Screen>
4483 </Para>
4485 <Para>
4486 One of the keywords <Literal remap="tt">u32</Literal>, <Literal remap="tt">u16</Literal> or <Literal remap="tt">u8</Literal> specifies
4487 length of the pattern in bits. PATTERN and MASK should follow, of length
4488 defined by the previous keyword. The OFFSET parameter is the offset,
4489 in bytes, to start matching. If <Literal remap="tt">nexthdr+</Literal> keyword is given,
4490 the offset is relative to start of the upper layer header.
4491 </Para>
4493 <Para>
4494 Some examples:
4495 </Para>
4497 <Para>
4499 <Screen>
4500 # tc filter add dev ppp14 parent 1:0 prio 10 u32 \
4501      match u8 64 0xff at 8 \
4502      flowid 1:4
4503 </Screen>
4505 </Para>
4507 <Para>
4508 Packet will match to this rule, if its time to live (TTL) is 64.
4509 TTL is the field starting just after 8-th byte of the IP header.
4510 </Para>
4512 <Para>
4514 <Screen>
4515 # tc filter add dev ppp14 parent 1:0 prio 10 u32 \
4516      match u8 0x10 0xff at nexthdr+13 \
4517      protocol tcp \
4518      flowid 1:3 
4519 </Screen>
4521 </Para>
4523 <Para>
4524 FIXME: it has been pointed out that this syntax does not work currently.
4525 </Para>
4527 <Para>
4528 Use this to match ACKs on packets smaller than 64 bytes:
4529 </Para>
4531 <Para>
4533 <Screen>
4534 ## match acks the hard way,
4535 ## IP protocol 6,
4536 ## IP header length 0x5(32 bit words),
4537 ## IP Total length 0x34 (ACK + 12 bytes of TCP options)
4538 ## TCP ack set (bit 5, offset 33)
4539 # tc filter add dev ppp14 parent 1:0 protocol ip prio 10 u32 \
4540             match ip protocol 6 0xff \
4541             match u8 0x05 0x0f at 0 \
4542             match u16 0x0000 0xffc0 at 2 \
4543             match u8 0x10 0xff at 33 \
4544             flowid 1:3
4545 </Screen>
4547 </Para>
4549 <Para>
4550 This rule will only match TCP packets with ACK bit set, and no further
4551 payload. Here we can see an example of using two selectors, the final result
4552 will be logical AND of their results. If we take a look at TCP header
4553 diagram, we can see that the ACK bit is second older bit (0x10) in the 14-th
4554 byte of the TCP header (<Literal remap="tt">at nexthdr+13</Literal>).  As for the second
4555 selector, if we'd like to make our life harder, we could write <Literal remap="tt">match u8
4556 0x06 0xff at 9</Literal> instead of using the specific selector <Literal remap="tt">protocol
4557 tcp</Literal>, because 6 is the number of TCP protocol, present in 10-th byte of
4558 the IP header. On the other hand, in this example we couldn't use any
4559 specific selector for the first match - simply because there's no specific
4560 selector to match TCP ACK bits.
4561 </Para>
4563 </Sect2>
4565 <Sect2>
4566 <Title>Specific selectors</Title>
4568 <Para>
4569 The following table contains a list of all specific selectors 
4570 the author of this section has found in the <Literal remap="tt">tc</Literal> program
4571 source code. They simply make your life easier and increase readability
4572 of your filter's configuration.
4573 </Para>
4575 <Para>
4576 FIXME: table placeholder - the table is in separate file ,,selector.html''
4577 </Para>
4579 <Para>
4580 FIXME: it's also still in Polish :-(
4581 </Para>
4583 <Para>
4584 FIXME: must be sgml'ized
4585 </Para>
4587 <Para>
4588 Some examples:
4589 </Para>
4591 <Para>
4593 <Screen>
4594 # tc filter add dev ppp0 parent 1:0 prio 10 u32 \
4595      match ip tos 0x10 0xff \
4596      flowid 1:4
4597 </Screen>
4599 </Para>
4601 <Para>
4602 FIXME: tcp dst match does not work as described below:
4603 </Para>
4605 <Para>
4606 The above rule will match packets which have the TOS field set to 0x10.
4607 The TOS field starts at second byte of the packet and is one byte big,
4608 so we could write an equivalent general selector: <Literal remap="tt">match u8 0x10 0xff
4609 at 1</Literal>. This gives us hint to the internals of U32 filter -- the
4610 specific rules are always translated to general ones, and in this
4611 form they are stored in the kernel memory. This leads to another conclusion
4612 -- the <Literal remap="tt">tcp</Literal> and <Literal remap="tt">udp</Literal> selectors are exactly the same
4613 and this is why you can't use single <Literal remap="tt">match tcp dst 53 0xffff</Literal>
4614 selector to match TCP packets sent to given port -- they will also
4615 match UDP packets sent to this port. You must remember to also specify
4616 the protocol and end up with the following rule:
4617 </Para>
4619 <Para>
4621 <Screen>
4622 # tc filter add dev ppp0 parent 1:0 prio 10 u32 \
4623         match tcp dst 53 0xffff \
4624         match ip protocol 0x6 0xff \
4625         flowid 1:2
4626 </Screen>
4628 </Para>
4630 </Sect2>
4632 </Sect1>
4634 <Sect1 id="lartc.adv-filter.route">
4635   <Title>The <option>route</option> classifier</Title>
4637 <Para>
4638 This classifier filters based on the results of the routing tables. When a
4639 packet that is traversing through the classes reaches one that is marked
4640 with the "route" filter, it splits the packets up based on information in
4641 the routing table.
4642 </Para>
4644 <Para>
4646 <Screen>
4647 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 route
4648 </Screen>
4650 </Para>
4652 <Para>
4653 Here we add a route classifier onto the parent node 1:0 with priority 100. 
4654 When a packet reaches this node (which, since it is the root, will happen
4655 immediately) it will consult the routing table and if one matches will
4656 send it to the given class and give it a priority of 100. Then, to finally
4657 kick it into action, you add the appropriate routing entry:
4658 </Para>
4660 <Para>
4661 The trick here is to define 'realm' based on either destination or source. 
4662 The way to do it is like this:
4663 </Para>
4665 <Para>
4667 <Screen>
4668 # ip route add Host/Network via Gateway dev Device realm RealmNumber
4669 </Screen>
4671 </Para>
4673 <Para>
4674 For instance, we can define our destination network 192.168.10.0 with a realm
4675 number 10:
4676 </Para>
4678 <Para>
4680 <Screen>
4681 # ip route add 192.168.10.0/24 via 192.168.10.1 dev eth1 realm 10
4682 </Screen>
4683   
4684 </Para>
4686 <Para>
4687 When adding route filters, we can use realm numbers to represent the
4688 networks or hosts and specify how the routes match the filters.
4689 </Para>
4691 <Para>
4693 <Screen>
4694 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 \
4695   route to 10 classid 1:10
4696 </Screen>
4697   
4698 </Para>
4700 <Para>
4701 The above rule says packets going to the network 192.168.10.0 match class id
4702 1:10.
4703 </Para>
4705 <Para>
4706 Route filter can also be used to match source routes. For example, there is 
4707 a subnetwork attached to the Linux router on eth2.
4708 </Para>
4710 <Para>
4712 <Screen>
4713 # ip route add 192.168.2.0/24 dev eth2 realm 2
4714 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 \
4715   route from 2 classid 1:2
4716 </Screen>
4718 </Para>
4720 <Para>
4721 Here the filter specifies that packets from the subnetwork 192.168.2.0
4722 (realm 2) will match class id 1:2.
4723 </Para>
4725 </Sect1>
4727 <Sect1 id="lartc.adv-filter.policing">
4728   <Title>Policing filters</Title>
4730 <Para>
4731 To make even more complicated setups possible, you can have filters that
4732 only match up to a certain bandwidth. You can declare a filter to entirely
4733 cease matching above a certain rate, or only to not match only the bandwidth
4734 exceeding a certain rate.
4735 </Para>
4737 <Para>
4738 So if you decided to police at 4mbit/s, but 5mbit/s of traffic is present,
4739 you can stop matching either the entire 5mbit/s, or only not match 1mbit/s,
4740 and do send 4mbit/s to the configured class.
4741 </Para>
4743 <Para>
4744 If bandwidth exceeds the configured rate, you can drop a packet, reclassify
4745 it, or see if another filter will match it.
4746 </Para>
4748 <Sect2>
4749 <Title>Ways to police</Title>
4751 <Para>
4752 There are basically two ways to police. If you compiled the kernel 
4753 with 'Estimators', the kernel can measure for each filter how much traffic
4754 it is passing, more or less. These estimators are very easy on the CPU, as
4755 they simply count 25 times per second how many data has been passed, and
4756 calculate the bitrate from that.
4757 </Para>
4759 <Para>
4760 The other way works again via a Token Bucket Filter, this time living within
4761 your filter. The TBF only matches traffic UP TO your configured bandwidth,
4762 if more is offered, only the excess is subject to the configured overlimit
4763 action.
4764 </Para>
4766 <Sect3>
4767 <Title>With the kernel estimator</Title>
4769 <Para>
4770 This is very simple and has only one parameter: avrate. Either the flow
4771 remains below avrate, and the filter classifies the traffic to the classid
4772 configured, or your rate exceeds it in which case the specified action is
4773 taken, which is 'reclassify' by default.
4774 </Para>
4776 <Para>
4777 The kernel uses an Exponential Weighted Moving Average for your bandwidth
4778 which makes it less sensitive to short bursts.
4779 </Para>
4781 </Sect3>
4783 <Sect3>
4784 <Title>With Token Bucket Filter</Title>
4786 <Para>
4787 Uses the following parameters:
4789 <ItemizedList>
4790 <ListItem>
4792 <Para>
4793 buffer/maxburst
4794 </Para>
4795 </ListItem>
4796 <ListItem>
4798 <Para>
4799 mtu/minburst
4800 </Para>
4801 </ListItem>
4802 <ListItem>
4804 <Para>
4806 </Para>
4807 </ListItem>
4808 <ListItem>
4810 <Para>
4811 rate
4812 </Para>
4813 </ListItem>
4815 </ItemizedList>
4817 </Para>
4819 <Para>
4820 Which behave mostly identical to those described in the Token Bucket Filter
4821 section. Please note however that if you set the mtu of a TBF policer too
4822 low, *no* packets will pass, whereas the egress TBF qdisc will just pass
4823 them slower.
4824 </Para>
4826 <Para>
4827 Another difference is that a policer can only let a packet pass, or drop it.
4828 It cannot delay hold on to it in order to delay it.
4829 </Para>
4831 </Sect3>
4833 </Sect2>
4835 <Sect2>
4836 <Title>Overlimit actions</Title>
4838 <Para>
4839 If your filter decides that it is overlimit, it can take 'actions'.
4840 Currently, three actions are available:
4841 <VariableList>
4843 <VarListEntry>
4844 <Term>continue</Term>
4845 <ListItem>
4846 <Para>
4847 Causes this filter not to match, but perhaps other filters will.
4848 </Para></ListItem>
4849 </VarListEntry>
4850 <VarListEntry>
4851 <Term>drop</Term>
4852 <ListItem>
4853 <Para>
4854 This is a very fierce option which simply discards traffic exceeding a
4855 certain rate. It is often used in the ingress policer and has limited uses.
4856 For example, you may have a name server that falls over if offered more than
4857 5mbit/s of packets, in which case an ingress filter could be used to make
4858 sure no more is ever offered.
4859 </Para></ListItem>
4860 </VarListEntry>
4861 <VarListEntry>
4862 <Term>Pass/OK</Term>
4863 <ListItem>
4864 <Para>
4865 Pass on traffic ok. Might be used to disable a complicated filter, but leave
4866 it in place.
4867 </Para></ListItem>
4868 </VarListEntry>
4869 <VarListEntry>
4870 <Term>reclassify</Term>
4871 <ListItem>
4872 <Para>
4873 Most often comes down to reclassification to Best Effort. This is the
4874 default action.
4875 </Para></ListItem>
4876 </VarListEntry>
4877 </VariableList>
4878 </Para>
4880 </Sect2>
4882 <Sect2>
4883 <Title>Examples</Title>
4885 <Para>
4886 The only real example known is mentioned in the 'Protecting your host 
4887 from SYN floods' section. 
4888 </Para>
4890 <Para>
4891 FIXME: if you have used this, please share your experience with us
4892 </Para>
4894 </Sect2>
4896 </Sect1>
4898 <Sect1 id="lartc.adv-filter.hashing">
4899 <Title>Hashing filters for very fast massive filtering</Title>
4901 <Para>
4902 If you have a need for thousands of rules, for example if you have a lot of
4903 clients or computers, all with different QoS specifications, you may find
4904 that the kernel spends a lot of time matching all those rules.
4905 </Para>
4907 <Para>
4908 By default, all filters reside in one big chain which is matched in
4909 descending order of priority. If you have 1000 rules, 1000 checks may be
4910 needed to determine what to do with a packet.
4911 </Para>
4913 <Para>
4914 Matching would go much quicker if you would have 256 chains with each four
4915 rules - if you could divide packets over those 256 chains, so that the right
4916 rule will be there.
4917 </Para>
4919 <Para>
4920 Hashing makes this possible. Let's say you have 1024 cable modem customers in
4921 your network, with IP addresses ranging from 1.2.0.0 to 1.2.3.255, and each
4922 has to go in another bin, for example 'lite', 'regular' and 'premium'. You
4923 would then have 1024 rules like this:
4924 </Para>
4926 <Para>
4928 <Screen>
4929 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
4930   1.2.0.0 classid 1:1
4931 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
4932   1.2.0.1 classid 1:1
4934 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
4935   1.2.3.254 classid 1:3
4936 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
4937   1.2.3.255 classid 1:2
4938 </Screen>
4940 </Para>
4942 <Para>
4943 To speed this up, we can use the last part of the IP address as a 'hash
4944 key'. We then get 256 tables, the first of which looks like this:
4946 <Screen>
4947 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
4948   1.2.0.0 classid 1:1
4949 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
4950   1.2.1.0 classid 1:1
4951 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
4952   1.2.2.0 classid 1:3
4953 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
4954   1.2.3.0 classid 1:2
4955 </Screen>
4957 </Para>
4959 <Para>
4960 The next one starts like this:
4962 <Screen>
4963 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
4964   1.2.0.1 classid 1:1
4966 </Screen>
4968 </Para>
4970 <Para>
4971 This way, only four checks are needed at most, two on average. 
4972 </Para>
4974 <Para>
4975 Configuration is pretty complicated, but very worth it by the time you have
4976 this many rules. First we make a filter root, then we create a table with
4977 256 entries:
4979 <Screen>
4980 # tc filter add dev eth1 parent 1:0 prio 5 protocol ip u32
4981 # tc filter add dev eth1 parent 1:0 prio 5 handle 2: protocol ip u32 divisor 256
4982 </Screen>
4984 </Para>
4986 <Para>
4987 Now we add some rules to entries in the created table:
4988 </Para>
4990 <Para>
4992 <Screen>
4993 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 2:7b: \
4994         match ip src 1.2.0.123 flowid 1:1
4995 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 2:7b: \
4996         match ip src 1.2.1.123 flowid 1:2
4997 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 2:7b: \
4998         match ip src 1.2.3.123 flowid 1:3
4999 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 2:7b: \
5000         match ip src 1.2.4.123 flowid 1:2
5001 </Screen>
5003 This is entry 123, which contains matches for 1.2.0.123, 1.2.1.123,
5004 1.2.2.123, 1.2.3.123, and sends them to 1:1, 1:2, 1:3 and 1:2 respectively.
5005 Note that we need to specify our hash bucket in hex, 0x7b is 123.
5006 </Para>
5008 <Para>
5009 Next create a 'hashing filter' that directs traffic to the right entry in
5010 the hashing table:
5012 <Screen>
5013 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 800:: \
5014         match ip src 1.2.0.0/16 \
5015         hashkey mask 0x000000ff at 12 \
5016         link 2:
5017 </Screen>
5019 Ok, some numbers need explaining. The default hash table is called 800:: and
5020 all filtering starts there. Then we select the source address, which lives
5021 as position 12, 13, 14 and 15 in the IP header, and indicate that we are
5022 only interested in the last part. This we send to hash table 2:, which we
5023 created earlier.
5024 </Para>
5026 <Para>
5027 It is quite complicated, but it does work in practice and performance will
5028 be staggering. Note that this example could be improved to the ideal case
5029 where each chain contains 1 filter!
5030 </Para>
5032 </Sect1>
5034 </chapter>
5036 <chapter id="lartc.kernel">
5037 <Title>Kernel network parameters </Title>
5039 <Para>
5041 The kernel has lots of parameters which
5042 can be tuned for different circumstances. While, as usual, the default
5043 parameters serve 99&percnt; of installations very well, we don't call this the
5044 Advanced HOWTO for the fun of it!
5045 </Para>
5047 <Para>
5048 The interesting bits are in /proc/sys/net, take a look there. Not everything
5049 will be documented here initially, but we're working on it.
5050 </Para>
5052 <Para>
5053 In the meantime you may want to have a look at the Linux-Kernel sources;
5054 read the file Documentation/filesystems/proc.txt. Most of the
5055 features are explained there.
5056 </Para>
5058 <Para>
5059 (FIXME)
5060 </Para>
5062 <Sect1 id="lartc.kernel.rpf"
5063   xreflabel="Reverse Path Filtering">
5064   <Title>Reverse Path Filtering</Title>
5066 <Para>
5067 By default, routers route everything, even packets which 'obviously' don't
5068 belong on your network. A common example is private IP space escaping onto
5069 the Internet. If you have an interface with a route of 195.96.96.0/24 to it,
5070 you do not expect packets from 212.64.94.1 to arrive there.
5071 </Para>
5073 <Para>
5074 Lots of people will want to turn this feature off, so the kernel hackers
5075 have made it easy. There are files in /proc where you can tell
5076 the kernel to do this for you. The method is called "Reverse Path
5077 Filtering". Basically, if the reply to this packet wouldn't go out the
5078 interface this packet came in, then this is a bogus packet and should be
5079 ignored.
5080 </Para>
5082 <Para>
5083 The following fragment will turn this on for all current and future
5084 interfaces.
5085 </Para>
5087 <Para>
5089 <Screen>
5090 # for i in /proc/sys/net/ipv4/conf/*/rp_filter ; do
5091 &gt;  echo 2 &#62; $i 
5092 &gt; done
5093 </Screen>
5095 </Para>
5097 <Para>
5098 Going by the example above, if a packet arrived on the Linux router on eth1
5099 claiming to come from the Office+ISP subnet, it would be dropped. Similarly,
5100 if a packet came from the Office subnet, claiming to be from somewhere
5101 outside your firewall, it would be dropped also.
5102 </Para>
5104 <Para>
5105 The above is full reverse path filtering. The default is to only filter
5106 based on IPs that are on directly connected networks. This is because the
5107 full filtering breaks in the case of asymmetric routing (where packets come
5108 in one way and go out another, like satellite traffic, or if you have
5109 dynamic (bgp, ospf, rip) routes in your network. The data comes down
5110 through the satellite dish and replies go back through normal land-lines).
5111 </Para>
5113 <Para>
5114 If this exception applies to you (and you'll probably know if it does) you
5115 can simply turn off the rp_filter on the interface where the
5116 satellite data comes in. If you want to see if any packets are being
5117 dropped, the log_martians file in the same directory will tell
5118 the kernel to log them to your syslog.
5119 </Para>
5121 <Para>
5123 <Screen>
5124 # echo 1 &#62;/proc/sys/net/ipv4/conf/&#60;interfacename&#62;/log_martians
5125 </Screen>
5127 </Para>
5129 <Para>
5130 FIXME: is setting the conf/&lcub;default,all&rcub;/* files enough? - martijn
5131 </Para>
5133 </Sect1>
5135 <Sect1 id="lartc.kernel.obscure">
5136   <Title>Obscure settings</Title>
5138 <Para>
5139 Ok, there are a lot of parameters which can be modified. We try to list them
5140 all. Also documented (partly) in Documentation/ip-sysctl.txt.
5141 </Para>
5143 <Para>
5144 Some of these settings have different defaults based on whether you 
5145 answered 'Yes' to 'Configure as router and not host' while compiling your
5146 kernel.
5147 </Para>
5149 <Sect2>
5150 <Title>Generic ipv4</Title>
5152 <Para>
5153 As a generic note, most rate limiting features don't work on loopback, so
5154 don't test them locally. The limits are supplied in 'jiffies', and are
5155 enforced using the earlier mentioned token bucket filter.
5156 </Para>
5158 <Para>
5159 The kernel has an internal clock which runs at 'HZ' ticks (or 'jiffies') per
5160 second. On Intel, 'HZ' is mostly 100. So setting a *_rate file to, say 50,
5161 would allow for 2 packets per second. The token bucket filter is also
5162 configured to allow for a burst of at most 6 packets, if enough tokens have
5163 been earned.
5164 </Para>
5166 <Para>
5167 Several entries in the following list have been copied from
5168 /usr/src/linux/Documentation/networking/ip-sysctl.txt, written by Alexey
5169 Kuznetsov &lt;kuznet@ms2.inr.ac.ru&gt; and Andi Kleen &lt;ak@muc.de&gt;
5170 <VariableList>
5172 <VarListEntry>
5173 <Term>/proc/sys/net/ipv4/icmp_destunreach_rate</Term>
5174 <ListItem>
5175 <Para>
5176 If the kernel decides that it can't deliver a packet, it will drop it, and
5177 send the source of the packet an ICMP notice to this effect.
5178 </Para></ListItem>
5179 </VarListEntry>
5180 <VarListEntry>
5181 <Term>/proc/sys/net/ipv4/icmp_echo_ignore_all</Term>
5182 <ListItem>
5183 <Para>
5184 Don't act on echo packets at all. Please don't set this by default, but if
5185 you are used as a relay in a DoS attack, it may be useful.
5186 </Para></ListItem>
5187 </VarListEntry>
5188 <VarListEntry>
5189 <Term>/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts &lsqb;Useful&rsqb;</Term>
5190 <ListItem>
5191 <Para>
5192 If you ping the broadcast address of a network, all hosts are supposed to
5193 respond. This makes for a dandy denial-of-service tool. Set this to 1 to
5194 ignore these broadcast messages.
5195 </Para></ListItem>
5196 </VarListEntry>
5197 <VarListEntry>
5198 <Term>/proc/sys/net/ipv4/icmp_echoreply_rate</Term>
5199 <ListItem>
5200 <Para>
5201 The rate at which echo replies are sent to any one destination.
5202 </Para></ListItem>
5203 </VarListEntry>
5204 <VarListEntry>
5205 <Term>/proc/sys/net/ipv4/icmp_ignore_bogus_error_responses</Term>
5206 <ListItem>
5207 <Para>
5208 Set this to ignore ICMP errors caused by hosts in the network reacting badly
5209 to frames sent to what they perceive to be the broadcast address.
5210 </Para></ListItem>
5211 </VarListEntry>
5212 <VarListEntry>
5213 <Term>/proc/sys/net/ipv4/icmp_paramprob_rate</Term>
5214 <ListItem>
5215 <Para>
5216 A relatively unknown ICMP message, which is sent in response to incorrect
5217 packets with broken IP or TCP headers. With this file you can control the
5218 rate at which it is sent.
5219 </Para></ListItem>
5220 </VarListEntry>
5221 <VarListEntry>
5222 <Term>/proc/sys/net/ipv4/icmp_timeexceed_rate</Term>
5223 <ListItem>
5224 <Para>
5225 This the famous cause of the 'Solaris middle star' in traceroutes. Limits
5226 number of ICMP Time Exceeded messages sent. 
5227 </Para></ListItem>
5228 </VarListEntry>
5229 <VarListEntry>
5230 <Term>/proc/sys/net/ipv4/igmp_max_memberships</Term>
5231 <ListItem>
5232 <Para>
5233 Maximum number of listening igmp (multicast) sockets on the host.
5234 FIXME: Is this true?
5235 </Para></ListItem>
5236 </VarListEntry>
5237 <VarListEntry>
5238 <Term>/proc/sys/net/ipv4/inet_peer_gc_maxtime</Term>
5239 <ListItem>
5240 <Para>
5241 FIXME: Add a little explanation about the inet peer storage?
5243 Minimum interval between garbage collection passes.  This interval is in
5244 effect under low (or absent) memory pressure on the pool. Measured in
5245 jiffies.
5246 </Para></ListItem>
5247 </VarListEntry>
5248 <VarListEntry>
5249 <Term>/proc/sys/net/ipv4/inet_peer_gc_mintime</Term>
5250 <ListItem>
5251 <Para>
5252 Minimum interval between garbage collection passes.  This interval is in
5253 effect under high memory pressure on the pool. Measured in jiffies.
5254 </Para></ListItem>
5255 </VarListEntry>
5256 <VarListEntry>
5257 <Term>/proc/sys/net/ipv4/inet_peer_maxttl</Term>
5258 <ListItem>
5259 <Para>
5260 Maximum time-to-live of entries.  Unused entries will expire after this
5261 period of time if there is no memory pressure on the pool (i.e. when the
5262 number of entries in the pool is very small). Measured in jiffies.
5263 </Para></ListItem>
5264 </VarListEntry>
5265 <VarListEntry>
5266 <Term>/proc/sys/net/ipv4/inet_peer_minttl</Term>
5267 <ListItem>
5268 <Para>
5269 Minimum time-to-live of entries.  Should be enough to cover fragment
5270 time-to-live on the reassembling side.  This minimum time-to-live
5271 is guaranteed if the pool size is less than inet_peer_threshold.
5272 Measured in jiffies.
5273 </Para></ListItem>
5274 </VarListEntry>
5275 <VarListEntry>
5276 <Term>/proc/sys/net/ipv4/inet_peer_threshold</Term>
5277 <ListItem>
5278 <Para>
5279 The approximate size of the INET peer storage.  Starting from this threshold
5280 entries will be thrown aggressively.  This threshold also determines
5281 entries' time-to-live and time intervals between garbage collection passes. 
5282 More entries, less time-to-live, less GC interval.
5283 </Para></ListItem>
5284 </VarListEntry>
5285 <VarListEntry>
5286 <Term>/proc/sys/net/ipv4/ip_autoconfig</Term>
5287 <ListItem>
5288 <Para>
5289 This file contains the number one if the host received its IP configuration by
5290 RARP, BOOTP, DHCP or a similar mechanism. Otherwise it is zero.
5291 </Para></ListItem>
5292 </VarListEntry>
5293 <VarListEntry>
5294 <Term>/proc/sys/net/ipv4/ip_default_ttl</Term>
5295 <ListItem>
5296 <Para>
5297 Time To Live of packets. Set to a safe 64. Raise it if you have a huge
5298 network. Don't do so for fun - routing loops cause much more damage that
5299 way. You might even consider lowering it in some circumstances.
5300 </Para></ListItem>
5301 </VarListEntry>
5302 <VarListEntry>
5303 <Term>/proc/sys/net/ipv4/ip_dynaddr</Term>
5304 <ListItem>
5305 <Para>
5306 You need to set this if you use dial-on-demand with a dynamic interface
5307 address. Once your demand interface comes up, any local TCP sockets which haven't seen replies will be rebound to have the right address. This solves the problem that the
5308 connection that brings up your interface itself does not work, but the
5309 second try does.
5310 </Para></ListItem>
5311 </VarListEntry>
5312 <VarListEntry>
5313 <Term>/proc/sys/net/ipv4/ip_forward</Term>
5314 <ListItem>
5315 <Para>
5316 If the kernel should attempt to forward packets. Off by default.
5317 </Para></ListItem>
5318 </VarListEntry>
5319 <VarListEntry>
5320 <Term>/proc/sys/net/ipv4/ip_local_port_range</Term>
5321 <ListItem>
5322 <Para>
5323 Range of local ports for outgoing connections. Actually quite small by
5324 default, 1024 to 4999.
5325 </Para></ListItem>
5326 </VarListEntry>
5327 <VarListEntry>
5328 <Term>/proc/sys/net/ipv4/ip_no_pmtu_disc</Term>
5329 <ListItem>
5330 <Para>
5331 Set this if you want to disable Path MTU discovery - a technique to
5332 determine the largest Maximum Transfer Unit possible on your path. See also
5333 the section on Path MTU discovery in the 
5334 <citetitle><xref linkend="lartc.cookbook"></citetitle> chapter.
5335 </Para></ListItem>
5336 </VarListEntry>
5337 <VarListEntry>
5338 <Term>/proc/sys/net/ipv4/ipfrag_high_thresh</Term>
5339 <ListItem>
5340 <Para>
5341 Maximum memory used to reassemble IP fragments. When 
5342 ipfrag_high_thresh bytes of memory is allocated for this purpose,
5343 the fragment handler will toss packets until ipfrag_low_thresh
5344 is reached.
5345 </Para></ListItem>
5346 </VarListEntry>
5347 <VarListEntry>
5348 <Term>/proc/sys/net/ipv4/ip_nonlocal_bind</Term>
5349 <ListItem>
5350 <Para>
5351 Set this if you want your applications to be able to bind to an address
5352 which doesn't belong to a device on your system. This can be useful when
5353 your machine is on a non-permanent (or even dynamic) link, so your services
5354 are able to start up and bind to a specific address when your link is down.
5355 </Para></ListItem>
5356 </VarListEntry>
5357 <VarListEntry>
5358 <Term>/proc/sys/net/ipv4/ipfrag_low_thresh</Term>
5359 <ListItem>
5360 <Para>
5361 Minimum memory used to reassemble IP fragments.
5362 </Para></ListItem>
5363 </VarListEntry>
5364 <VarListEntry>
5365 <Term>/proc/sys/net/ipv4/ipfrag_time</Term>
5366 <ListItem>
5367 <Para>
5368 Time in seconds to keep an IP fragment in memory.
5369 </Para></ListItem>
5370 </VarListEntry>
5371 <VarListEntry>
5372 <Term>/proc/sys/net/ipv4/tcp_abort_on_overflow</Term>
5373 <ListItem>
5374 <Para>
5375 A boolean flag controlling the behaviour under lots of incoming connections.
5376 When enabled, this causes the kernel to actively send RST packets when a
5377 service is overloaded.
5378 </Para></ListItem>
5379 </VarListEntry>
5380 <VarListEntry>
5381 <Term>/proc/sys/net/ipv4/tcp_fin_timeout</Term>
5382 <ListItem>
5383 <Para>
5384 Time to hold socket in state FIN-WAIT-2, if it was closed by our side. Peer
5385 can be broken and never close its side, or even died unexpectedly. Default
5386 value is 60sec. Usual value used in 2.2 was 180 seconds, you may restore it,
5387 but remember that if your machine is even underloaded WEB server, you risk
5388 to overflow memory with kilotons of dead sockets, FIN-WAIT-2 sockets are
5389 less dangerous than FIN-WAIT-1, because they eat maximum 1.5K of memory, but
5390 they tend to live longer. Cf. tcp_max_orphans.
5391 </Para></ListItem>
5392 </VarListEntry>
5393 <VarListEntry>
5394 <Term>/proc/sys/net/ipv4/tcp_keepalive_time</Term>
5395 <ListItem>
5396 <Para>
5397 How often TCP sends out keepalive messages when keepalive is enabled. 
5399 Default: 2hours.
5400 </Para></ListItem>
5401 </VarListEntry>
5402 <VarListEntry>
5403 <Term>/proc/sys/net/ipv4/tcp_keepalive_intvl</Term>
5404 <ListItem>
5405 <Para>
5406 How frequent probes are retransmitted, when a probe isn't acknowledged. 
5408 Default: 75 seconds.
5409 </Para></ListItem>
5410 </VarListEntry>
5411 <VarListEntry>
5412 <Term>/proc/sys/net/ipv4/tcp_keepalive_probes</Term>
5413 <ListItem>
5414 <Para>
5415 How many keepalive probes TCP will send, until it decides that the
5416 connection is broken. 
5418 Default value: 9. 
5420 Multiplied with tcp_keepalive_intvl, this gives the time a link can be
5421 non-responsive after a keepalive has been sent.
5422 </Para></ListItem>
5423 </VarListEntry>
5424 <VarListEntry>
5425 <Term>/proc/sys/net/ipv4/tcp_max_orphans</Term>
5426 <ListItem>
5427 <Para>
5428 Maximal number of TCP sockets not attached to any user file handle, held by
5429 system. If this number is exceeded orphaned connections are reset
5430 immediately and warning is printed. This limit exists only to prevent simple
5431 DoS attacks, you _must_ not rely on this or lower the limit artificially,
5432 but rather increase it (probably, after increasing installed memory), if
5433 network conditions require more than default value, and tune network
5434 services to linger and kill such states more aggressively. Let me remind you
5435 again: each orphan eats up to &nbsp;64K of unswappable memory.
5436 </Para></ListItem>
5437 </VarListEntry>
5438 <VarListEntry>
5439 <Term>/proc/sys/net/ipv4/tcp_orphan_retries</Term>
5440 <ListItem>
5441 <Para>
5442 How may times to retry before killing TCP connection, closed by our side.
5443 Default value 7 corresponds to &nbsp;50sec-16min depending on RTO. If your machine
5444 is a loaded WEB server, you should think about lowering this value, such
5445 sockets may consume significant resources. Cf. tcp_max_orphans.
5446 </Para></ListItem>
5447 </VarListEntry>
5448 <VarListEntry>
5449 <Term>/proc/sys/net/ipv4/tcp_max_syn_backlog</Term>
5450 <ListItem>
5451 <Para>
5452 Maximal number of remembered connection requests, which still did not
5453 receive an acknowledgment from connecting client. Default value is 1024 for
5454 systems with more than 128Mb of memory, and 128 for low memory machines. If
5455 server suffers of overload, try to increase this number. Warning! If you
5456 make it greater than 1024, it would be better to change TCP_SYNQ_HSIZE in
5457 include/net/tcp.h to keep TCP_SYNQ_HSIZE*16&#60;=tcp_max_syn_backlog and to
5458 recompile kernel.
5459 </Para></ListItem>
5460 </VarListEntry>
5461 <VarListEntry>
5462 <Term>/proc/sys/net/ipv4/tcp_max_tw_buckets</Term>
5463 <ListItem>
5464 <Para>
5465 Maximal number of timewait sockets held by system simultaneously. If this
5466 number is exceeded time-wait socket is immediately destroyed and warning is
5467 printed. This limit exists only to prevent simple DoS attacks, you _must_
5468 not lower the limit artificially, but rather increase it (probably, after
5469 increasing installed memory), if network conditions require more than
5470 default value.
5471 </Para></ListItem>
5472 </VarListEntry>
5473 <VarListEntry>
5474 <Term>/proc/sys/net/ipv4/tcp_retrans_collapse</Term>
5475 <ListItem>
5476 <Para>
5477 Bug-to-bug compatibility with some broken printers.
5478 On retransmit try to send bigger packets to work around bugs in
5479 certain TCP stacks.
5480 </Para></ListItem>
5481 </VarListEntry>
5482 <VarListEntry>
5483 <Term>/proc/sys/net/ipv4/tcp_retries1</Term>
5484 <ListItem>
5485 <Para>
5486 How many times to retry before deciding that something is wrong
5487 and it is necessary to report this suspicion to network layer.
5488 Minimal RFC value is 3, it is default, which corresponds
5489 to &nbsp;3sec-8min depending on RTO.
5490 </Para></ListItem>
5491 </VarListEntry>
5492 <VarListEntry>
5493 <Term>/proc/sys/net/ipv4/tcp_retries2</Term>
5494 <ListItem>
5495 <Para>
5496 How may times to retry before killing alive TCP connection.
5497 <ULink
5498 URL="http://www.ietf.org/rfc/rfc1122.txt"
5499 >RFC 1122</ULink
5501 says that the limit should be longer than 100 sec.
5502 It is too small number. Default value 15 corresponds to &nbsp;13-30min
5503 depending on RTO.
5504 </Para></ListItem>
5505 </VarListEntry>
5506 <VarListEntry>
5507 <Term>/proc/sys/net/ipv4/tcp_rfc1337</Term>
5508 <ListItem>
5509 <Para>
5510 This boolean enables a fix for 'time-wait assassination hazards in tcp', described
5511 in RFC 1337. If enabled, this causes the kernel to drop RST packets for
5512 sockets in the time-wait state.
5514 Default: 0
5515 </Para></ListItem>
5516 </VarListEntry>
5517 <VarListEntry>
5518 <Term>/proc/sys/net/ipv4/tcp_sack</Term>
5519 <ListItem>
5520 <Para>
5521 Use Selective ACK which can be used to signify that specific packets are
5522 missing - therefore helping fast recovery.
5523 </Para></ListItem>
5524 </VarListEntry>
5525 <VarListEntry>
5526 <Term>/proc/sys/net/ipv4/tcp_stdurg</Term>
5527 <ListItem>
5528 <Para>
5529 Use the Host requirements interpretation of the TCP urg pointer
5530 field. 
5532 Most hosts use the older BSD interpretation, so if you turn this on
5533 Linux might not communicate correctly with them. 
5535 Default: FALSE 
5536 </Para></ListItem>
5537 </VarListEntry>
5538 <VarListEntry>
5539 <Term>/proc/sys/net/ipv4/tcp_syn_retries</Term>
5540 <ListItem>
5541 <Para>
5542 Number of SYN packets the kernel will send before giving up on the new
5543 connection.
5544 </Para></ListItem>
5545 </VarListEntry>
5546 <VarListEntry>
5547 <Term>/proc/sys/net/ipv4/tcp_synack_retries</Term>
5548 <ListItem>
5549 <Para>
5550 To open the other side of the connection, the kernel sends a SYN with a
5551 piggybacked ACK on it, to acknowledge the earlier received SYN. This is part
5552 2 of the threeway handshake. This setting determines the number of SYN+ACK
5553 packets sent before the kernel gives up on the connection.
5554 </Para></ListItem>
5555 </VarListEntry>
5556 <VarListEntry>
5557 <Term>/proc/sys/net/ipv4/tcp_timestamps</Term>
5558 <ListItem>
5559 <Para>
5560 Timestamps are used, amongst other things, to protect against wrapping
5561 sequence numbers. A 1 gigabit link might conceivably re-encounter a previous
5562 sequence number with an out-of-line value, because it was of a previous
5563 generation. The timestamp will let it recognize this 'ancient packet'.
5564 </Para></ListItem>
5565 </VarListEntry>
5566 <VarListEntry>
5567 <Term>/proc/sys/net/ipv4/tcp_tw_recycle</Term>
5568 <ListItem>
5569 <Para>
5570 Enable fast recycling TIME-WAIT sockets. Default value is 1.
5571 It should not be changed without advice/request of technical experts.
5572 </Para></ListItem>
5573 </VarListEntry>
5574 <VarListEntry>
5575 <Term>/proc/sys/net/ipv4/tcp_window_scaling</Term>
5576 <ListItem>
5577 <Para>
5578 TCP/IP normally allows windows up to 65535 bytes big. For really fast
5579 networks, this may not be enough. The window scaling options allows for
5580 almost gigabyte windows, which is good for high bandwidth*delay products.
5581 </Para></ListItem>
5582 </VarListEntry>
5583 </VariableList>
5584 </Para>
5586 </Sect2>
5588 <Sect2>
5589 <Title>Per device settings</Title>
5591 <Para>
5592 DEV can either stand for a real interface, or for 'all' or 'default'.
5593 Default also changes settings for interfaces yet to be created.
5594 <VariableList>
5596 <VarListEntry>
5597 <Term>/proc/sys/net/ipv4/conf/DEV/accept_redirects</Term>
5598 <ListItem>
5599 <Para>
5600 If a router decides that you are using it for a wrong purpose (ie, it needs
5601 to resend your packet on the same interface), it will send us a ICMP
5602 Redirect. This is a slight security risk however, so you may want to turn it
5603 off, or use secure redirects.
5604 </Para></ListItem>
5605 </VarListEntry>
5606 <VarListEntry>
5607 <Term>/proc/sys/net/ipv4/conf/DEV/accept_source_route</Term>
5608 <ListItem>
5609 <Para>
5610 Not used very much anymore. You used to be able to give a packet a list of
5611 IP addresses it should visit on its way. Linux can be made to honor this IP
5612 option.
5613 </Para></ListItem>
5614 </VarListEntry>
5615 <VarListEntry>
5616 <Term>/proc/sys/net/ipv4/conf/DEV/bootp_relay</Term>
5617 <ListItem>
5618 <Para>
5619 Accept packets  with source address 0.b.c.d with destinations not to this host
5620 as local ones. It is supposed that a BOOTP relay daemon will catch and forward
5621 such packets.
5622 </Para>
5624 <Para>
5625 The default  is  0,  since this feature is not implemented yet (kernel version
5626 2.2.12).
5627 </Para></ListItem>
5628 </VarListEntry>
5629 <VarListEntry>
5630 <Term>/proc/sys/net/ipv4/conf/DEV/forwarding</Term>
5631 <ListItem>
5632 <Para>
5633 Enable or disable IP forwarding on this interface.
5634 </Para></ListItem>
5635 </VarListEntry>
5636 <VarListEntry>
5637 <Term>/proc/sys/net/ipv4/conf/DEV/log_martians</Term>
5638 <ListItem>
5639 <Para>
5640 See the section on 
5641 <citetitle><xref linkend="lartc.kernel.rpf"></citetitle>.
5642 </Para></ListItem>
5643 </VarListEntry>
5644 <VarListEntry>
5645 <Term>/proc/sys/net/ipv4/conf/DEV/mc_forwarding</Term>
5646 <ListItem>
5647 <Para>
5648 If we do multicast forwarding on this interface
5649 </Para></ListItem>
5650 </VarListEntry>
5651 <VarListEntry>
5652 <Term>/proc/sys/net/ipv4/conf/DEV/proxy_arp</Term>
5653 <ListItem>
5654 <Para>
5655 If you set this to 1, this interface will respond to ARP requests for
5656 addresses the kernel has routes to. Can be very useful when building 'ip
5657 pseudo bridges'. Do take care that your netmasks are very correct before
5658 enabling this! Also be aware that the rp_filter, mentioned elsewhere, also
5659 operates on ARP queries!
5660 </Para></ListItem>
5661 </VarListEntry>
5662 <VarListEntry>
5663 <Term>/proc/sys/net/ipv4/conf/DEV/rp_filter</Term>
5664 <ListItem>
5665 <Para>
5666 See the section on 
5667 <citetitle><xref linkend="lartc.kernel.rpf"></citetitle>.
5668 </Para></ListItem>
5669 </VarListEntry>
5670 <VarListEntry>
5671 <Term>/proc/sys/net/ipv4/conf/DEV/secure_redirects</Term>
5672 <ListItem>
5673 <Para>
5674 Accept ICMP  redirect  messages  only  for gateways, listed in default gateway
5675 list. Enabled by default.
5676 </Para></ListItem>
5677 </VarListEntry>
5678 <VarListEntry>
5679 <Term>/proc/sys/net/ipv4/conf/DEV/send_redirects</Term>
5680 <ListItem>
5681 <Para>
5682 If we send the above mentioned redirects.
5683 </Para></ListItem>
5684 </VarListEntry>
5685 <VarListEntry>
5686 <Term>/proc/sys/net/ipv4/conf/DEV/shared_media</Term>
5687 <ListItem>
5688 <Para>
5689 If it  is  not  set  the kernel does not assume that different subnets on this
5690 device can communicate directly. Default setting is 'yes'.
5691 </Para></ListItem>
5692 </VarListEntry>
5693 <VarListEntry>
5694 <Term>/proc/sys/net/ipv4/conf/DEV/tag</Term>
5695 <ListItem>
5696 <Para>
5697 FIXME: fill this in
5698 </Para></ListItem>
5699 </VarListEntry>
5700 </VariableList>
5701 </Para>
5703 </Sect2>
5705 <Sect2>
5706 <Title>Neighbor policy</Title>
5708 <Para>
5709 Dev can either stand for a real interface, or for 'all' or 'default'.
5710 Default also changes settings for interfaces yet to be created.
5711 <VariableList>
5713 <VarListEntry>
5714 <Term>/proc/sys/net/ipv4/neigh/DEV/anycast_delay</Term>
5715 <ListItem>
5716 <Para>
5717 Maximum for  random  delay  of  answers  to  neighbor solicitation messages in
5718 jiffies (1/100  sec). Not yet implemented (Linux does not have anycast support
5719 yet).
5720 </Para></ListItem>
5721 </VarListEntry>
5722 <VarListEntry>
5723 <Term>/proc/sys/net/ipv4/neigh/DEV/app_solicit</Term>
5724 <ListItem>
5725 <Para>
5726 Determines the  number of requests to send to the user level ARP daemon. Use 0
5727 to turn off.
5728 </Para></ListItem>
5729 </VarListEntry>
5730 <VarListEntry>
5731 <Term>/proc/sys/net/ipv4/neigh/DEV/base_reachable_time</Term>
5732 <ListItem>
5733 <Para>
5734 A base  value  used for computing the random reachable time value as specified
5735 in RFC2461.
5736 </Para></ListItem>
5737 </VarListEntry>
5738 <VarListEntry>
5739 <Term>/proc/sys/net/ipv4/neigh/DEV/delay_first_probe_time</Term>
5740 <ListItem>
5741 <Para>
5742 Delay for  the  first  time  probe  if  the  neighbor  is  reachable.  (see
5743 gc_stale_time)
5744 </Para></ListItem>
5745 </VarListEntry>
5746 <VarListEntry>
5747 <Term>/proc/sys/net/ipv4/neigh/DEV/gc_stale_time</Term>
5748 <ListItem>
5749 <Para>
5750 Determines how  often  to  check  for stale ARP entries. After an ARP entry is
5751 stale it  will  be resolved again (which is useful when an IP address migrates
5752 to another  machine).  When  ucast_solicit is greater than 0 it first tries to
5753 send an  ARP  packet  directly  to  the  known  host  When  that  fails  and
5754 mcast_solicit is greater than 0, an ARP request is broadcast.
5755 </Para></ListItem>
5756 </VarListEntry>
5757 <VarListEntry>
5758 <Term>/proc/sys/net/ipv4/neigh/DEV/locktime</Term>
5759 <ListItem>
5760 <Para>
5761 An ARP/neighbor  entry  is only replaced with a new one if the old is at least
5762 locktime old. This prevents ARP cache thrashing.
5763 </Para></ListItem>
5764 </VarListEntry>
5765 <VarListEntry>
5766 <Term>/proc/sys/net/ipv4/neigh/DEV/mcast_solicit</Term>
5767 <ListItem>
5768 <Para>
5769 Maximum number of retries for multicast solicitation.
5770 </Para></ListItem>
5771 </VarListEntry>
5772 <VarListEntry>
5773 <Term>/proc/sys/net/ipv4/neigh/DEV/proxy_delay</Term>
5774 <ListItem>
5775 <Para>
5776 Maximum time  (real  time is random &lsqb;0..proxytime]) before answering to an ARP
5777 request for  which  we have an proxy ARP entry. In some cases, this is used to
5778 prevent network flooding.
5779 </Para></ListItem>
5780 </VarListEntry>
5781 <VarListEntry>
5782 <Term>/proc/sys/net/ipv4/neigh/DEV/proxy_qlen</Term>
5783 <ListItem>
5784 <Para>
5785 Maximum queue length of the delayed proxy arp timer. (see proxy_delay).
5786 </Para></ListItem>
5787 </VarListEntry>
5788 <VarListEntry>
5789 <Term>/proc/sys/net/ipv4/neigh/DEV/retrans_time</Term>
5790 <ListItem>
5791 <Para>
5792 The time,  expressed  in  jiffies  (1/100 sec), between retransmitted Neighbor
5793 Solicitation messages.  Used  for  address  resolution  and  to determine if a
5794 neighbor is unreachable.
5795 </Para></ListItem>
5796 </VarListEntry>
5797 <VarListEntry>
5798 <Term>/proc/sys/net/ipv4/neigh/DEV/ucast_solicit</Term>
5799 <ListItem>
5800 <Para>
5801 Maximum number of retries for unicast solicitation.
5802 </Para></ListItem>
5803 </VarListEntry>
5804 <VarListEntry>
5805 <Term>/proc/sys/net/ipv4/neigh/DEV/unres_qlen</Term>
5806 <ListItem>
5807 <Para>
5808 Maximum queue  length  for a pending arp request - the number of packets which
5809 are accepted from other layers while the ARP address is still resolved.
5810 </Para></ListItem>
5811 </VarListEntry>
5812 <VarListEntry>
5813 <Term>Internet QoS: Architectures and Mechanisms for Quality of Service,
5814 Zheng Wang, ISBN 1-55860-608-4</Term>
5815 <ListItem>
5816 <Para>
5817 Hardcover textbook covering topics
5818 related to Quality of Service. Good for understanding basic concepts.
5819 </Para></ListItem>
5820 </VarListEntry>
5821 </VariableList>
5822 </Para>
5824 </Sect2>
5826 <Sect2>
5827 <Title>Routing settings</Title>
5829 <Para>
5830 <VariableList>
5832 <VarListEntry>
5833 <Term>/proc/sys/net/ipv4/route/error_burst</Term>
5834 <ListItem>
5835 <Para>
5836 These parameters  are used to limit the warning messages written to the kernel
5837 log from  the  routing  code.  The  higher the error_cost factor is, the fewer
5838 messages will  be written. Error_burst controls when messages will be dropped.
5839 The default settings limit warning messages to one every five seconds.
5840 </Para></ListItem>
5841 </VarListEntry>
5842 <VarListEntry>
5843 <Term>/proc/sys/net/ipv4/route/error_cost</Term>
5844 <ListItem>
5845 <Para>
5846 These parameters  are used to limit the warning messages written to the kernel
5847 log from  the  routing  code.  The  higher the error_cost factor is, the fewer
5848 messages will  be written. Error_burst controls when messages will be dropped.
5849 The default settings limit warning messages to one every five seconds.
5850 </Para></ListItem>
5851 </VarListEntry>
5852 <VarListEntry>
5853 <Term>/proc/sys/net/ipv4/route/flush</Term>
5854 <ListItem>
5855 <Para>
5856 Writing to this file results in a flush of the routing cache.
5857 </Para></ListItem>
5858 </VarListEntry>
5859 <VarListEntry>
5860 <Term>/proc/sys/net/ipv4/route/gc_elasticity</Term>
5861 <ListItem>
5862 <Para>
5863 Values to  control  the  frequency  and  behavior  of  the  garbage collection
5864 algorithm for the routing cache. This can be important for when doing
5865 fail over. At least gc_timeout seconds will elapse before Linux will skip
5866 to another route because the previous one has died. By default set to 300,
5867 you may want to lower it if you want to have a speedy fail over.
5868 </Para>
5870 <Para>
5871 Also see <ULink
5872 URL="http://mailman.ds9a.nl/pipermail/lartc/2002q1/002667.html"
5873 >this post</ULink
5874 > by Ard van Breemen.
5875 </Para></ListItem>
5876 </VarListEntry>
5877 <VarListEntry>
5878 <Term>/proc/sys/net/ipv4/route/gc_interval</Term>
5879 <ListItem>
5880 <Para>
5881 See /proc/sys/net/ipv4/route/gc_elasticity.
5882 </Para></ListItem>
5883 </VarListEntry>
5884 <VarListEntry>
5885 <Term>/proc/sys/net/ipv4/route/gc_min_interval</Term>
5886 <ListItem>
5887 <Para>
5888 See /proc/sys/net/ipv4/route/gc_elasticity.
5889 </Para></ListItem>
5890 </VarListEntry>
5891 <VarListEntry>
5892 <Term>/proc/sys/net/ipv4/route/gc_thresh</Term>
5893 <ListItem>
5894 <Para>
5895 See /proc/sys/net/ipv4/route/gc_elasticity.
5896 </Para></ListItem>
5897 </VarListEntry>
5898 <VarListEntry>
5899 <Term>/proc/sys/net/ipv4/route/gc_timeout</Term>
5900 <ListItem>
5901 <Para>
5902 See /proc/sys/net/ipv4/route/gc_elasticity.
5903 </Para></ListItem>
5904 </VarListEntry>
5905 <VarListEntry>
5906 <Term>/proc/sys/net/ipv4/route/max_delay</Term>
5907 <ListItem>
5908 <Para>
5909 Delays for flushing the routing cache.
5910 </Para></ListItem>
5911 </VarListEntry>
5912 <VarListEntry>
5913 <Term>/proc/sys/net/ipv4/route/max_size</Term>
5914 <ListItem>
5915 <Para>
5916 Maximum size  of  the routing cache. Old entries will be purged once the cache
5917 reached has this size.
5918 </Para></ListItem>
5919 </VarListEntry>
5920 <VarListEntry>
5921 <Term>/proc/sys/net/ipv4/route/min_adv_mss</Term>
5922 <ListItem>
5923 <Para>
5924 FIXME: fill this in
5925 </Para></ListItem>
5926 </VarListEntry>
5927 <VarListEntry>
5928 <Term>/proc/sys/net/ipv4/route/min_delay</Term>
5929 <ListItem>
5930 <Para>
5931 Delays for flushing the routing cache.
5932 </Para></ListItem>
5933 </VarListEntry>
5934 <VarListEntry>
5935 <Term>/proc/sys/net/ipv4/route/min_pmtu</Term>
5936 <ListItem>
5937 <Para>
5938 FIXME: fill this in
5939 </Para></ListItem>
5940 </VarListEntry>
5941 <VarListEntry>
5942 <Term>/proc/sys/net/ipv4/route/mtu_expires</Term>
5943 <ListItem>
5944 <Para>
5945 FIXME: fill this in
5946 </Para></ListItem>
5947 </VarListEntry>
5948 <VarListEntry>
5949 <Term>/proc/sys/net/ipv4/route/redirect_load</Term>
5950 <ListItem>
5951 <Para>
5952 Factors which  determine  if  more ICMP redirects should be sent to a specific
5953 host. No  redirects  will be sent once the load limit or the maximum number of
5954 redirects has been reached.
5955 </Para></ListItem>
5956 </VarListEntry>
5957 <VarListEntry>
5958 <Term>/proc/sys/net/ipv4/route/redirect_number</Term>
5959 <ListItem>
5960 <Para>
5961 See /proc/sys/net/ipv4/route/redirect_load.
5962 </Para></ListItem>
5963 </VarListEntry>
5964 <VarListEntry>
5965 <Term>/proc/sys/net/ipv4/route/redirect_silence</Term>
5966 <ListItem>
5967 <Para>
5968 Timeout for redirects. After this period redirects will be sent again, even if
5969 this has been stopped, because the load or number limit has been reached.
5970 </Para></ListItem>
5971 </VarListEntry>
5972 </VariableList>
5973 </Para>
5975 </Sect2>
5977 </Sect1>
5979 </chapter>
5981 <chapter id="lartc.adv-qdisc">
5982   <Title>Advanced &amp; less common queueing disciplines</Title>
5984 <Para>
5985 Should you find that you have needs not addressed by the queues mentioned
5986 earlier, the kernel contains some other more specialized queues mentioned here.
5987 </Para>
5989 <Sect1 id="lartc.adv-qdisc.bfifo-pfifo">
5990   <Title><literal>bfifo</literal>/<literal>pfifo</literal></Title>
5992 <Para>
5993 These classless queues are even simpler than pfifo_fast in that they lack
5994 the internal bands - all traffic is really equal. They have one important
5995 benefit though, they have some statistics. So even if you don't need shaping
5996 or prioritizing, you can use this qdisc to determine the backlog on your
5997 interface.
5998 </Para>
6000 <Para>
6001 pfifo has a length measured in packets, bfifo in bytes. 
6002 </Para>
6004 <Sect2>
6005 <Title>Parameters &amp; usage</Title>
6007 <Para>
6008 <VariableList>
6010 <VarListEntry>
6011 <Term>limit</Term>
6012 <ListItem>
6013 <Para>
6014 Specifies the length of the queue. Measured in bytes for bfifo, in packets
6015 for pfifo. Defaults to the interface txqueuelen (see pfifo_fast chapter)
6016 packets long or txqueuelen*mtu bytes for bfifo.
6017 </Para></ListItem>
6018 </VarListEntry>
6019 </VariableList>
6020 </Para>
6022 </Sect2>
6024 </Sect1>
6026 <Sect1 id="lartc.adv-qdisc.csz">
6027   <Title>Clark-Shenker-Zhang algorithm (CSZ)</Title>
6029 <Para>
6030 This is so theoretical that not even Alexey (the main CBQ author) claims to
6031 understand it. From his source:
6032 </Para>
6034 <blockquote>
6035 <Para>
6036 David D. Clark, Scott Shenker and Lixia Zhang
6037 <citetitle>Supporting Real-Time Applications in an Integrated Services Packet
6038 Network: Architecture and Mechanism</citetitle>.
6039 </Para>
6041 <Para>
6042 As I understand it, the main idea is to create WFQ flows for each guaranteed
6043 service and to allocate the rest of bandwith to dummy flow-0. Flow-0
6044 comprises the predictive services and the best effort traffic; it is handled
6045 by a priority scheduler with the highest priority band allocated for
6046 predictive services, and the rest --- to the best effort packets.
6047 </Para>
6049 <Para>
6050 Note that in CSZ flows are NOT limited to their bandwidth.  It is supposed
6051 that the flow passed admission control at the edge of the QoS network and it
6052 doesn't need further shaping. Any attempt to improve the flow or to shape it
6053 to a token bucket at intermediate hops will introduce undesired delays and
6054 raise jitter.
6055 </Para>
6057 <Para>
6058 At the moment CSZ is the only scheduler that provides true guaranteed
6059 service. Another schemes (including CBQ) do not provide guaranteed delay and
6060 randomize jitter."
6061 </Para>
6063 <Para>
6064 Does not currently seem like a good candidate to use, unless you've read and
6065 understand the article mentioned.
6066 </Para>
6067 </blockquote>
6069 </Sect1>
6071 <Sect1 id="lartc.adv-qdisc.dsmark"
6072   xreflabel="DSMARK">
6073   <Title>DSMARK</Title>
6075   <abstract>
6076     <Para>
6077       <author><firstname>Esteve</firstname><surname>Camps</surname></author>
6078       <address><email>marvin@grn.es</email></address>
6079       This text is an extract from my thesis on
6080       <citetitle>QoS Support in Linux</citetitle>, September 2000.
6081     </Para>
6082   </abstract>
6084 <Para>Source documents:
6085 </para>
6087 <ItemizedList>
6088 <ListItem>
6089   <Para>
6090     <ULink URL="ftp://icaftp.epfl.ch/pub/linux/diffserv/misc/dsid-01.txt.gz">
6091       Draft-almesberger-wajhak-diffserv-linux-01.txt</ULink>.
6092   </Para>
6093 </ListItem>
6094 <ListItem>
6095   <Para>Examples in iproute2 distribution.
6096   </Para>
6097 </ListItem>
6098 <ListItem>
6099   <Para>
6100     <ULink URL="http://www.qosforum.com/white-papers/qosprot_v3.pdf">
6101       White Paper-QoS protocols and architectures</ULink> and
6102     <ULink URL="http://www.qosforum.com/docs/faq">
6103       IP QoS Frequently Asked Questions</ULink> both by 
6104     <citetitle>Quality of Service Forum</citetitle>.
6105   </Para>
6106 </ListItem>
6107 </ItemizedList>
6109 <Para>
6110 This chapter was written by Esteve Camps &lt;esteve@hades.udg.es&gt;.
6111 </Para>
6113 <Sect2>
6114 <Title>Introduction</Title>
6116 <Para>
6117 First of all, first of all, it would be a great idea for you to read RFCs
6118 written about this (RFC2474, RFC2475, RFC2597 and RFC2598) at 
6119 <ULink URL="http://www.ietf.org/html.charters/diffserv-charter.html">
6120   IETF DiffServ working Group web site</ULink> and
6121 <ULink URL="http://diffserv.sf.net/">
6122   Werner Almesberger web site</ULink>
6123 (he wrote the code to support Differentiated Services on Linux).
6124 </Para>
6126 </Sect2>
6128 <Sect2>
6129 <Title>What is Dsmark related to?</Title>
6131 <Para>
6132 Dsmark is a queueing discipline that offers the capabilities needed in
6133 Differentiated Services (also called DiffServ or, simply, DS). DiffServ is
6134 one of two actual QoS architectures (the other one is called Integrated
6135 Services) that is based on a value carried by packets in the DS field of the
6136 IP header.
6137 </Para>
6139 <Para>
6140 One of the first solutions in IP designed to offer some QoS level was
6141 the Type of Service field (TOS byte) in IP header. By changing that value,
6142 we could choose a high/low level of throughput, delay or reliability.
6143 But this didn't provide sufficient flexibility to the needs of new
6144 services (such as real-time applications, interactive applications and
6145 others). After this, new architectures appeared. One of these was DiffServ
6146 which kept TOS bits and renamed DS field.
6147 </Para>
6149 </Sect2>
6151 <Sect2>
6152 <Title>Differentiated Services guidelines</Title>
6154 <Para>
6155 Differentiated Services is group-oriented. I mean, we don't know anything
6156 about flows (this will be the Integrated Services purpose); we know about
6157 flow aggregations and we will apply different behaviours depending on which
6158 aggregation a packet belongs to.
6159 </Para>
6161 <Para>
6162 When a packet arrives to an edge node (entry node to a DiffServ domain)
6163 entering to a DiffServ Domain we'll have to policy, shape and/or mark those
6164 packets (marking refers to assigning a value to the DS field. It's just like the
6165 cows :-) ). This will be the mark/value that the internal/core nodes on our
6166 DiffServ Domain will look at to determine which behaviour or QoS level
6167 apply.
6168 </Para>
6170 <Para>
6171 As you can deduce, Differentiated Services involves a domain on which
6172 all DS rules will have to be applied. In fact you can think I
6173 will classify all the packets entering my domain. Once they enter my
6174 domain they will be subjected to the rules that my classification dictates
6175 and every traversed node will apply that QoS level.
6176 </Para>
6178 <Para>
6179 In fact, you can apply your own policies into your local domains, but some
6180 <Emphasis>Service Level Agreements</Emphasis> should be considered when connecting to
6181 other DS domains.
6182 </Para>
6184 <Para>
6185 At this point, you maybe have a lot of questions. DiffServ is more than I've
6186 explained. In fact, you can understand that I can not resume more than 3
6187 RFCs in just 50 lines :-).
6188 </Para>
6190 </Sect2>
6192 <Sect2>
6193 <Title>Working with Dsmark</Title>
6195 <Para>
6196 As the DiffServ bibliography specifies, we differentiate boundary nodes and
6197 interior nodes. These are two important points in the traffic path. Both
6198 types perform a classification when the packets arrive. Its result may be
6199 used in different places along the DS process before the packet is released
6200 to the network. It's just because of this that the diffserv code supplies an
6201 structure called sk_buff, including a new field called skb-&gt;tc_index
6202 where we'll store the result of initial classification that may be used in
6203 several points in DS treatment.
6204 </Para>
6206 <Para>
6207 The skb-&gt;tc_index value will be initially set by the DSMARK qdisc,
6208 retrieving it from the DS field in IP header of every received packet.
6209 Besides, cls_tcindex classifier will read all or part of skb-&gt;tcindex
6210 value and use it to select classes.
6211 </Para>
6213 <Para>
6214 But, first of all, take a look at DSMARK qdisc command and its parameters:
6216 <Screen>
6217 ... dsmark indices INDICES [ default_index DEFAULT_INDEX ] [ set_tc_index ]
6218 </Screen>
6220 What do these parameters mean?
6222 <ItemizedList>
6223 <ListItem>
6225 <Para>
6226 <Emphasis remap="bf">indices</Emphasis>: size of table of (mask,value) pairs. Maximum value is 2&circ;n, where n&gt;=0.
6227 </Para>
6228 </ListItem>
6229 <ListItem>
6231 <Para>
6232 <Emphasis remap="bf">Default_index</Emphasis>: the default table entry index if classifier finds no match.
6233 </Para>
6234 </ListItem>
6235 <ListItem>
6237 <Para>
6238 <Emphasis remap="bf">Set_tc_index</Emphasis>: instructs dsmark discipline to retrieve the DS field and store it onto skb-&gt;tc_index.
6239 </Para>
6240 </ListItem>
6242 </ItemizedList>
6244 Let's see the DSMARK process.
6245 </Para>
6247 </Sect2>
6249 <Sect2>
6250 <Title>How SCH_DSMARK works.</Title>
6252 <Para>
6253 This qdisc will apply the next steps:
6255 <ItemizedList>
6256 <ListItem>
6258 <Para>
6259 If we have declared set_tc_index option in qdisc command, DS field is retrieved and stored onto
6260 skb-&gt;tc_index variable.
6261 </Para>
6262 </ListItem>
6263 <ListItem>
6265 <Para>
6266 Classifier is invoked. The classifier will be executed and it will return a class ID that will be stored in
6267 skb-&gt;tc_index variable.If no filter matches are found, we consider the default_index option to be the
6268 classId to store. If neither set_tc_index nor default_index has been declared results may be
6269 unpredictable.
6270 </Para>
6271 </ListItem>
6272 <ListItem>
6274 <Para>
6275 After been sent to internal qdiscs where you can reuse the result of the filter, the classid returned by
6276 the internal qdisc is stored into skb-&gt;tc_index. We will use this value in the future to index a mask-
6277 value table. The final result to assign to the packet will be that resulting from next operation:
6279 <Screen>
6280 New_Ds_field = ( Old_DS_field &#38; mask ) | value
6281 </Screen>
6284 </Para>
6285 </ListItem>
6286 <ListItem>
6288 <Para>
6289 Thus, new value will result from "anding" ds_field and mask values and next, this result "ORed" with
6290 value parameter. See next diagram to understand all this process:
6291 </Para>
6292 </ListItem>
6294 </ItemizedList>
6297 <Screen>
6298                          skb-&gt;ihp-&gt;tos
6299 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - &gt;
6300      |                                                       |     ^
6301      | -- If you declare set_tc_index, we set DS             |     |  &lt;-----May change
6302      |    value into skb-&gt;tc_index variable                  |     |O       DS field
6303      |                                                      A|     |R
6304    +-|-+      +------+    +---+-+    Internal   +-+     +---N|-----|----+
6305    | | |      | tc   |---&gt;|   | |--&gt;  . . .  --&gt;| |     |   D|     |    |
6306    | | |-----&gt;|index |---&gt;|   | |     Qdisc     | |----&gt;|    v     |    |
6307    | | |      |filter|---&gt;| | | +---------------+ |   ----&gt;(mask,value) |
6308 --&gt;| O |      +------+    +-|-+--------------^----+  /  |  (.  ,  .)    |
6309    | | |          ^         |                |       |  |  (.  ,  .)    |
6310    | | +----------|---------|----------------|-------|--+  (.  ,  .)    |
6311    | | sch_dsmark |         |                |       |                  |
6312    +-|------------|---------|----------------|-------|------------------+
6313      |            |         | &lt;- tc_index -&gt; |       |
6314      |            |(read)   |    may change  |       |  &lt;--------------Index to the
6315      |            |         |                |       |                    (mask,value)
6316      v            |         v                v       |                    pairs table
6317 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -&gt;
6318                          skb-&gt;tc_index
6319 </Screen>
6321 </Para>
6323 <Para>
6324 How to do marking? Just change the mask and value of the class you want to remark. See next line of code:
6326 <Screen>
6327 tc class change dev eth0 classid 1:1 dsmark mask 0x3 value 0xb8
6328 </Screen>
6330 This changes the (mask,value) pair in hash table, to remark packets belonging to class 1:1.You have to "change" this values
6331 because of default values that (mask,value) gets initially (see table below).
6332 </Para>
6334 <Para>
6335 Now, we'll explain how TC_INDEX filter works and how fits into this. Besides, TCINDEX filter can be
6336 used in other configurations rather than those including DS services.
6337 </Para>
6339 </Sect2>
6341 <Sect2>
6342 <Title>TC_INDEX Filter</Title>
6344 <Para>
6345 This is the basic command to declare a TC_INDEX filter:
6347 <Screen>
6348 ... tcindex [ hash SIZE ] [ mask MASK ] [ shift SHIFT ]
6349             [ pass_on | fall_through ]
6350             [ classid CLASSID ] [ police POLICE_SPEC ]
6351 </Screen>
6353 Next, we show the example used to explain TC_INDEX operation mode. Pay attention to bolded words:
6356 tc qdisc add dev eth0 handle 1:0 root dsmark indices 64 <Emphasis remap="bf">set_tc_index</Emphasis>
6358 tc filter add dev eth0 parent 1:0 protocol ip prio 1 tcindex <Emphasis remap="bf">mask 0xfc  shift 2</Emphasis>
6360 tc qdisc add dev eth0 parent 1:0 handle 2:0 cbq bandwidth 10Mbit cell 8 avpkt 1000 mpu 64
6362 &num; EF traffic class
6364 tc class add dev eth0 parent 2:0 classid 2:1 cbq bandwidth 10Mbit rate 1500Kbit avpkt 1000 prio 1 bounded isolated allot 1514 weight 1 maxburst 10
6366 &num; Packet fifo qdisc for EF traffic
6368 tc qdisc add dev eth0 parent 2:1 pfifo limit 5
6370 tc filter add dev eth0 parent 2:0 protocol ip prio 1 <Emphasis remap="bf">handle 0x2e</Emphasis> tcindex <Emphasis remap="bf">classid 2:1 pass_on</Emphasis>
6374 (This code is not complete. It's just an extract from EFCBQ example included in iproute2 distribution).
6375 </Para>
6377 <Para>
6378 First of all, suppose we receive a packet marked as EF .  If you read RFC2598, you'll see that DSCP
6379 recommended value for EF traffic is 101110. This means that DS field will be 10111000 (remember that
6380 less significant bits in TOS byte are not used in DS) or 0xb8 in hexadecimal codification.
6381 </Para>
6383 <Para>
6385 <Screen>
6386               TC INDEX
6387               FILTER
6388    +---+      +-------+    +---+-+    +------+                +-+    +-------+
6389    |   |      |       |    |   | |    |FILTER|  +-+    +-+    | |    |       |
6390    |   |-----&gt;| MASK  | -&gt; |   | | -&gt; |HANDLE|-&gt;| |    | | -&gt; | | -&gt; |       |
6391    |   |  .   | =0xfc |    |   | |    |0x2E  |  | +----+ |    | |    |       |
6392    |   |  .   |       |    |   | |    +------+  +--------+    | |    |       |
6393    |   |  .   |       |    |   | |                            | |    |       |
6394 --&gt;|   |  .   | SHIFT |    |   | |                            | |    |       |--&gt;
6395    |   |  .   | =2    |    |   | +----------------------------+ |    |       |
6396    |   |      |       |    |   |       CBQ 2:0                  |    |       |
6397    |   |      +-------+    +---+--------------------------------+    |       |
6398    |   |                                                             |       |
6399    |   +-------------------------------------------------------------+       |
6400    |                          DSMARK 1:0                                     |
6401    +-------------------------------------------------------------------------+
6403 </Screen>
6405 </Para>
6407 <Para>
6408 The packet arrives, then, set with 0xb8 value at DS field. As we explained before, dsmark qdisc identified
6409 by 1:0 id in the example, retrieves DS field and store it in skb-&gt;tc_index variable.
6410 Next step in the example will correspond to the filter associated to this qdisc (second line in the example).
6411 This will perform next operations:
6413 <Screen>
6414 Value1 = skb-&#62;tc_index &#38; MASK
6415 Key = Value1 &#62;&#62; SHIFT
6416 </Screen>
6418 </Para>
6420 <Para>
6421 In the example, MASK=0xFC i SHIFT=2.
6423 <Screen>
6424 Value1 = 10111000 &#38; 11111100 = 10111000
6425 Key = 10111000 &#62;&#62; 2 = 00101110 -&#62; 0x2E in hexadecimal
6426 </Screen>
6428 </Para>
6430 <Para>
6431 The returned value will correspond to a qdisc internal filter handle (in the example, identifier 2:0). If a
6432 filter with this id exists, policing and metering conditions will be verified (in case that filter includes this)
6433 and the classid will be returned (in our example, classid 2:1) and stored in skb-&gt;tc_index variable.
6434 </Para>
6436 <Para>
6437 But if any filter with that identifier is found, the result will depend on fall_through flag declaration. If so,
6438 value key is returned as classid. If not, an error is returned and process continues with the rest filters. Be
6439 careful if you use fall_through flag; this can be done if a simple relation exists between values
6441 of skb-&gt;tc_index variable and class id's.
6442 </Para>
6444 <Para>
6445 The latest parameters to comment on are hash and pass_on. The first one
6446 relates to hash table size. Pass_on will be used to indicate that if no classid
6447 equal to the result of this filter is found, try next filter.
6448 The default action is fall_through (look at next table).
6449 </Para>
6451 <Para>
6452 Finally, let's see which possible values can be set to all this TCINDEX parameters:
6454 <Screen>
6455 TC Name                 Value           Default
6456 -----------------------------------------------------------------
6457 Hash                    1...0x10000     Implementation dependent
6458 Mask                    0...0xffff      0xffff
6459 Shift                   0...15          0
6460 Fall through / Pass_on  Flag            Fall_through
6461 Classid                 Major:minor     None
6462 Police                  .....           None
6463 </Screen>
6465 </Para>
6467 <Para>
6468 This kind of filter is very powerful. It's necessary to explore all possibilities. Besides, this filter is not only used in DiffServ configurations.
6469 You can use it as any other kind of filter.
6470 </Para>
6472 <Para>
6473 I recommend you to look at all DiffServ examples included in iproute2 distribution. I promise I will try to
6474 complement this text as soon as I can. Besides, all I have explained is the result of a lot of tests.
6475 I would thank you tell me if I'm wrong in any point.
6476 </Para>
6478 </Sect2>
6480 </Sect1>
6482 <Sect1 id="lartc.adv-qdisc.ingress">
6483   <Title>Ingress qdisc</Title>
6485 <Para>
6486 All qdiscs discussed so far are egress qdiscs. Each interface however can
6487 also have an ingress qdisc which is not used to send packets
6488 out to the network adaptor. Instead, it allows you to apply tc filters to
6489 packets coming in over the interface, regardless of whether they have a local
6490 destination or are to be forwarded.
6491 </Para>
6493 <Para>
6494 As the tc filters contain a full Token Bucket Filter implementation, and are
6495 also able to match on the kernel flow estimator, there is a lot of
6496 functionality available. This effectively allows you to police incoming
6497 traffic, before it even enters the IP stack.
6498 </Para>
6500 <Sect2>
6501 <Title>Parameters &amp; usage</Title>
6503 <Para>
6504 The ingress qdisc itself does not require any parameters. It differs from
6505 other qdiscs in that it does not occupy the root of a device. Attach it like
6506 this:
6508 <Screen>
6509 # tc qdisc add dev eth0 ingress
6510 </Screen>
6512 This allows you to have other, sending, qdiscs on your device besides the
6513 ingress qdisc. 
6514 </Para>
6516 <Para>
6517 For a contrived example how the ingress qdisc could be used, see the
6518 Cookbook.
6519 </Para>
6521 </Sect2>
6523 </Sect1>
6525 <Sect1 id="lartc.adv-qdisc.red">
6526   <Title>Random Early Detection (RED)</Title>
6528 <Para>
6529 This section is meant as an introduction to backbone routing, which often
6530 involves &lt;100 megabit bandwidths, which requires a different approach than
6531 your ADSL modem at home.
6532 </Para>
6534 <Para>
6535 The normal behaviour of router queues on the Internet is called tail-drop.
6536 Tail-drop works by queueing up to a certain amount, then dropping all traffic
6537 that 'spills over'. This is very unfair, and also leads to retransmit 
6538 synchronization. When retransmit synchronization occurs, the sudden burst
6539 of drops from a router that has reached its fill will cause a delayed burst
6540 of retransmits, which will over fill the congested router again. 
6541 </Para>
6543 <Para>
6544 In order to cope with transient congestion on links, backbone routers will
6545 often implement large queues. Unfortunately, while these queues are good for
6546 throughput, they can substantially increase latency and cause TCP
6547 connections to behave very burstily during congestion.
6548 </Para>
6550 <Para>
6551 These issues with tail-drop are becoming increasingly troublesome on the
6552 Internet because the use of network unfriendly applications is increasing.
6553 The Linux kernel offers us RED, short for Random Early Detect, also called
6554 Random Early Drop, as that is how it works.
6555 </Para>
6557 <Para>
6558 RED isn't a cure-all for this, applications which inappropriately fail to 
6559 implement exponential backoff still get an unfair share of the bandwidth,
6560 however, with RED they do not cause as much harm to the throughput and
6561 latency of other connections.
6562 </Para>
6564 <Para>
6565 RED statistically drops packets from flows before it reaches its hard
6566 limit. This causes a congested backbone link to slow more gracefully, and
6567 prevents retransmit synchronization. This also helps TCP find its 'fair'
6568 speed faster by allowing some packets to get dropped sooner keeping queue
6569 sizes low and latency under control. The probability of a packet being
6570 dropped from a particular connection is proportional to its bandwidth usage
6571 rather than the number of packets it transmits. 
6572 </Para>
6574 <Para>
6575 RED is a good queue for backbones, where you can't afford the 
6576 complexity of per-session state tracking needed by fairness queueing.
6577 </Para>
6579 <Para>
6580 In order to use RED, you must decide on three parameters: Min, Max, and
6581 burst. Min sets the minimum queue size in bytes before dropping will begin,
6582 Max is a soft maximum that the algorithm will attempt to stay under, and
6583 burst sets the maximum number of packets that can 'burst through'.
6584 </Para>
6586 <Para>
6587 You should set the min by calculating that highest acceptable base queueing 
6588 latency you wish, and multiply it by your bandwidth. For instance, on my 
6589 64kbit/s ISDN link, I might want a base queueing latency of 200ms so I set
6590 min to 1600 bytes. Setting min too small will degrade throughput and too
6591 large will degrade latency. Setting a small min is not a replacement for
6592 reducing the MTU on a slow link to improve interactive response.
6593 </Para>
6595 <Para>
6596 You should make max at least twice min to prevent synchronization. On slow
6597 links with small Min's it might be wise to make max perhaps four or
6598 more times large then min.
6599 </Para>
6601 <Para>
6602 Burst controls how the RED algorithm responds to bursts. Burst must be set
6603 larger then min/avpkt. Experimentally, I've found (min+min+max)/(3*avpkt) to
6604 work ok.
6605 </Para>
6607 <Para>
6608 Additionally, you need to set limit and avpkt. Limit is a safety value, after
6609 there are limit bytes in the queue, RED 'turns into' tail-drop. I typical set
6610 limit to eight times max. Avpkt should be your average packet size. 1000
6611 works OK on high speed Internet links with a 1500byte MTU. 
6612 </Para>
6614 <Para>
6615 Read <ULink
6616 URL="http://www.aciri.org/floyd/papers/red/red.html"
6617 >the paper on RED queueing</ULink
6618 > by Sally Floyd and Van Jacobson for technical
6619 information.
6620 </Para>
6622 </Sect1>
6624 <Sect1 id="lartc.adv-qdisc.gred">
6625 <Title>Generic Random Early Detection</Title>
6627 <Para>
6628 Not a lot is known about GRED. It looks like GRED with several internal
6629 queues, whereby the internal queue is chosen based on the Diffserv tcindex
6630 field. According to a slide found
6631 <ULink URL="http://www.davin.ottawa.on.ca/ols/img22.htm">here</ULink>,
6632 it contains the capabilities of Cisco's 'Distributed Weighted RED', as well 
6633 as Dave Clark's RIO.
6634 </Para>
6636 <Para>
6637 Each virtual queue can have its own Drop Parameters specified.
6638 </Para>
6640 <Para>
6641 FIXME: get Jamal or Werner to tell us more
6642 </Para>
6644 </Sect1>
6646 <Sect1 id="lartc.adv-qdisc.vc-atm">
6647   <Title>VC/ATM emulation</Title>
6649 <Para>
6650 This is quite a major effort by Werner Almesberger to allow you to build
6651 Virtual Circuits over TCP/IP sockets. A Virtual Circuit is a concept from
6652 ATM network theory. 
6653 </Para>
6655 <Para>
6656 For more information, see the <ULink
6657 URL="http://linux-atm.sourceforge.net/"
6658 >ATM on Linux homepage</ULink
6659 >. 
6660 </Para>
6662 </Sect1>
6664 <Sect1 id="lartc.adv-qdisc.wrr">
6665   <Title>Weighted Round Robin (WRR)</Title>
6667 <Para>
6668 This qdisc is not included in the standard kernels but can be downloaded from 
6669 <ULink URL="http://wipl-wrr.dkik.dk/wrr/">here</ULink>. 
6670 Currently the qdisc is only tested with Linux 2.2 kernels but it will 
6671 probably work with 2.4/2.5 kernels too.
6672 </Para>
6674 <Para>
6675 The WRR qdisc distributes bandwidth between its classes using the weighted 
6676 round robin scheme. That is, like the CBQ qdisc it contains classes 
6677 into which arbitrary qdiscs can be plugged. All classes which have sufficient 
6678 demand will get bandwidth proportional to the weights associated with the classes.
6679 The weights can be set manually using the <Literal remap="tt">tc</Literal> program. But they
6680 can also be made automatically decreasing for classes transferring much data.
6681 </Para>
6683 <Para>
6684 The qdisc has a built-in classifier which assigns packets coming from or 
6685 sent to different machines to different classes. Either the MAC or IP and 
6686 either source or destination addresses can be used. The MAC address can only 
6687 be used when the Linux box is acting as an ethernet bridge, however. The 
6688 classes are automatically assigned to machines based on the packets seen.
6689 </Para>
6691 <Para>
6692 The qdisc can be very useful at sites such as dorms where a lot of unrelated 
6693 individuals share an Internet connection. A set of scripts setting up a 
6694 relevant behavior for such a site is a central part of the WRR distribution.
6695 </Para>
6697 </Sect1>
6699 </chapter>
6701 <chapter id="lartc.cookbook"
6702   xreflabel="Cookbook">
6703   <Title>Cookbook</Title>
6705 <Para>
6706 This section contains 'cookbook' entries which may help you solve problems.
6707 A cookbook is no replacement for understanding however, so try and comprehend
6708 what is going on. 
6709 </Para>
6711 <Sect1 id="lartc.cookbook.sla">
6712 <Title>Running multiple sites with different SLAs</Title>
6714 <Para>
6715 You can do this in several ways. Apache has some support for this with a
6716 module, but we'll show how Linux can do this for you, and do so for other
6717 services as well. These commands are stolen from a presentation by Jamal
6718 Hadi that's referenced below.
6719 </Para>
6721 <Para>
6722 Let's say we have two customers, with http, ftp and streaming audio, and we
6723 want to sell them a limited amount of bandwidth. We do so on the server itself.
6724 </Para>
6726 <Para>
6727 Customer A should have at most 2 megabits, customer B has paid for 5
6728 megabits. We separate our customers by creating virtual IP addresses on our
6729 server.
6730 </Para>
6732 <Para>
6734 <Screen>
6735 # ip address add 188.177.166.1 dev eth0
6736 # ip address add 188.177.166.2 dev eth0
6737 </Screen>
6739 </Para>
6741 <Para>
6742 It is up to you to attach the different servers to the right IP address. All
6743 popular daemons have support for this.
6744 </Para>
6746 <Para>
6747 We first attach a CBQ qdisc to eth0:
6749 <Screen>
6750 # tc qdisc add dev eth0 root handle 1: cbq bandwidth 10Mbit cell 8 avpkt 1000 \
6751   mpu 64
6752 </Screen>
6754 </Para>
6756 <Para>
6757 We then create classes for our customers:
6758 </Para>
6760 <Para>
6762 <Screen>
6763 # tc class add dev eth0 parent 1:0 classid 1:1 cbq bandwidth 10Mbit rate \
6764   2MBit avpkt 1000 prio 5 bounded isolated allot 1514 weight 1 maxburst 21
6765 # tc class add dev eth0 parent 1:0 classid 1:2 cbq bandwidth 10Mbit rate \
6766   5Mbit avpkt 1000 prio 5 bounded isolated allot 1514 weight 1 maxburst 21
6767 </Screen>
6769 </Para>
6771 <Para>
6772 Then we add filters for our two classes:
6774 <Screen>
6775 ##FIXME: Why this line, what does it do?, what is a divisor?:
6776 ##FIXME: A divisor has something to do with a hash table, and the number of
6777 ##       buckets - ahu
6778 # tc filter add dev eth0 parent 1:0 protocol ip prio 5 handle 1: u32 divisor 1
6779 # tc filter add dev eth0 parent 1:0 prio 5 u32 match ip src 188.177.166.1
6780   flowid 1:1
6781 # tc filter add dev eth0 parent 1:0 prio 5 u32 match ip src 188.177.166.2
6782   flowid 1:2
6783 </Screen>
6785 </Para>
6787 <Para>
6788 And we're done.
6789 </Para>
6791 <Para>
6792 FIXME: why no token bucket filter? is there a default pfifo_fast fallback
6793 somewhere?
6794 </Para>
6796 </Sect1>
6798 <Sect1 id="lartc.cookbook.synflood-protect"
6799   xreflabel="Protecting your host from SYN floods">
6800   <Title>Protecting your host from SYN floods</Title>
6802 <Para>
6803 From Alexey's iproute documentation, adapted to netfilter and with more
6804 plausible paths. If you use this, take care to adjust the numbers to
6805 reasonable values for your system.
6806 </Para>
6808 <Para>
6809 If you want to protect an entire network, skip this script, which is best
6810 suited for a single host.
6811 </Para>
6813 <Para>
6814 It appears that you need the very latest version of the iproute2 tools to
6815 get this to work with 2.4.0.
6816 </Para>
6818 <Para>
6820 <Screen>
6821 #! /bin/sh -x
6823 # sample script on using the ingress capabilities
6824 # this script shows how one can rate limit incoming SYNs
6825 # Useful for TCP-SYN attack protection. You can use
6826 # IPchains to have more powerful additions to the SYN (eg 
6827 # in addition the subnet)
6829 #path to various utilities;
6830 #change to reflect yours.
6832 TC=/sbin/tc
6833 IP=/sbin/ip
6834 IPTABLES=/sbin/iptables
6835 INDEV=eth2
6837 # tag all incoming SYN packets through $INDEV as mark value 1
6838 ############################################################ 
6839 $iptables -A PREROUTING -i $INDEV -t mangle -p tcp --syn \
6840   -j MARK --set-mark 1
6841 ############################################################ 
6843 # install the ingress qdisc on the ingress interface
6844 ############################################################ 
6845 $TC qdisc add dev $INDEV handle ffff: ingress
6846 ############################################################ 
6850 # SYN packets are 40 bytes (320 bits) so three SYNs equals
6851 # 960 bits (approximately 1kbit); so we rate limit below
6852 # the incoming SYNs to 3/sec (not very useful really; but
6853 #serves to show the point - JHS
6854 ############################################################ 
6855 $TC filter add dev $INDEV parent ffff: protocol ip prio 50 handle 1 fw \
6856 police rate 1kbit burst 40 mtu 9k drop flowid :1
6857 ############################################################ 
6861 echo "---- qdisc parameters Ingress  ----------"
6862 $TC qdisc ls dev $INDEV
6863 echo "---- Class parameters Ingress  ----------"
6864 $TC class ls dev $INDEV
6865 echo "---- filter parameters Ingress ----------"
6866 $TC filter ls dev $INDEV parent ffff:
6868 #deleting the ingress qdisc
6869 #$TC qdisc del $INDEV ingress
6870 </Screen>
6872 </Para>
6874 </Sect1>
6876 <Sect1 id="lartc.cookbook.icmp-ratelimit">
6877   <Title>Rate limit ICMP to prevent dDoS</Title>
6879 <Para>
6880 Recently, distributed denial of service attacks have become a major nuisance
6881 on the Internet. By properly filtering and rate limiting your network, you can
6882 both prevent becoming a casualty or the cause of these attacks.
6883 </Para>
6885 <Para>
6886 You should filter your networks so that you do not allow non-local IP source
6887 addressed packets to leave your network. This stops people from anonymously
6888 sending junk to the Internet. 
6889 </Para>
6891 <Para>
6892 Rate limiting goes much as shown earlier. To refresh your memory, our
6893 ASCIIgram again:
6894 </Para>
6896 <Para>
6898 <Screen>
6899 [The Internet] ---&#60;E3, T3, whatever&#62;--- [Linux router] --- [Office+ISP]
6900                                       eth1          eth0
6901 </Screen>
6903 </Para>
6905 <Para>
6906 We first set up the prerequisite parts:
6907 </Para>
6909 <Para>
6911 <Screen>
6912 # tc qdisc add dev eth0 root handle 10: cbq bandwidth 10Mbit avpkt 1000
6913 # tc class add dev eth0 parent 10:0 classid 10:1 cbq bandwidth 10Mbit rate \
6914   10Mbit allot 1514 prio 5 maxburst 20 avpkt 1000
6915 </Screen>
6917 </Para>
6919 <Para>
6920 If you have 100Mbit, or more, interfaces, adjust these numbers. Now you need
6921 to determine how much ICMP traffic you want to allow. You can perform
6922 measurements with tcpdump, by having it write to a file for a while, and
6923 seeing how much ICMP passes your network. Do not forget to raise the
6924 snapshot length!
6925 </Para>
6927 <Para>
6928 If measurement is impractical, you might want to choose 5&percnt; of your available
6929 bandwidth. Let's set up our class:
6931 <Screen>
6932 # tc class add dev eth0 parent 10:1 classid 10:100 cbq bandwidth 10Mbit rate \
6933   100Kbit allot 1514 weight 800Kbit prio 5 maxburst 20 avpkt 250 \
6934   bounded
6935 </Screen>
6937 </Para>
6939 <Para>
6940 This limits at 100Kbit. Now we need a filter to assign ICMP traffic to this
6941 class:
6943 <Screen>
6944 # tc filter add dev eth0 parent 10:0 protocol ip prio 100 u32 match ip
6945   protocol 1 0xFF flowid 10:100
6947 </Screen>
6949 </Para>
6951 </Sect1>
6953 <Sect1 id="lartc.cookbook.interactive-prio">
6954 <Title>Prioritizing interactive traffic</Title>
6956 <Para>
6957 If lots of data is coming down your link, or going up for that matter, and
6958 you are trying to do some maintenance via telnet or ssh, this may not go too
6959 well. Other packets are blocking your keystrokes. Wouldn't it be great if
6960 there were a way for your interactive packets to sneak past the bulk
6961 traffic? Linux can do this for you!
6962 </Para>
6964 <Para>
6965 As before, we need to handle traffic going both ways. Evidently, this works
6966 best if there are Linux boxes on both ends of your link, although other
6967 UNIX's are able to do this. Consult your local Solaris/BSD guru for this.
6968 </Para>
6970 <Para>
6971 The standard pfifo_fast scheduler has 3 different 'bands'. Traffic in band 0
6972 is transmitted first, after which traffic in band 1 and 2 gets considered.
6973 It is vital that our interactive traffic be in band 0!
6974 </Para>
6976 <Para>
6977 We blatantly adapt from the (soon to be obsolete) ipchains HOWTO:
6978 </Para>
6980 <Para>
6981 There are four seldom-used bits in the IP header, called the Type of Service
6982 (TOS) bits. They effect the way packets are treated; the four bits are
6983 "Minimum Delay", "Maximum Throughput", "Maximum Reliability" and "Minimum
6984 Cost". Only one of these bits is allowed to be set. Rob van Nieuwkerk, the
6985 author of the ipchains TOS-mangling code, puts it as follows:
6986 </Para>
6988 <Para>
6990 <Screen>
6991 Especially the "Minimum Delay" is important for me. I switch it on for
6992 "interactive" packets in my upstream (Linux) router. I'm
6993 behind a 33k6 modem link. Linux prioritizes packets in 3 queues. This
6994 way I get acceptable interactive performance while doing bulk
6995 downloads at the same time. 
6996 </Screen>
6998 </Para>
7000 <Para>
7001 The most common use is to set telnet &#38; ftp control connections to "Minimum
7002 Delay" and FTP data to "Maximum Throughput". This would be
7003 done as follows, on your upstream router:
7004 </Para>
7006 <Para>
7008 <Screen>
7009 # iptables -A PREROUTING -t mangle -p tcp --sport telnet \
7010   -j TOS --set-tos Minimize-Delay
7011 # iptables -A PREROUTING -t mangle -p tcp --sport ftp \
7012   -j TOS --set-tos Minimize-Delay
7013 # iptables -A PREROUTING -t mangle -p tcp --sport ftp-data \
7014   -j TOS --set-tos Maximize-Throughput
7015 </Screen>
7017 </Para>
7019 <Para>
7020 Now, this only works for data going from your telnet foreign host to your
7021 local computer. The other way around appears to be done for you, ie, telnet,
7022 ssh &#38; friends all set the TOS field on outgoing packets automatically.
7023 </Para>
7025 <Para>
7026 Should you have an application that does not do this, you can always do it 
7027 with netfilter. On your local box:
7028 </Para>
7030 <Para>
7032 <Screen>
7033 # iptables -A OUTPUT -t mangle -p tcp --dport telnet \
7034   -j TOS --set-tos Minimize-Delay
7035 # iptables -A OUTPUT -t mangle -p tcp --dport ftp \
7036   -j TOS --set-tos Minimize-Delay
7037 # iptables -A OUTPUT -t mangle -p tcp --dport ftp-data \
7038   -j TOS --set-tos Maximize-Throughput
7039 </Screen>
7041 </Para>
7043     </Sect1>
7045     <Sect1 id="lartc.cookbook.squid">
7046       <Title>Transparent web-caching using <application>netfilter</application>,
7047         <application>iproute2</application>, <application>ipchains</application> and 
7048         <application>squid</application></Title>
7049       
7050       <Para>
7051         This section was sent in by reader Ram Narula from Internet for Education
7052         (Thailand).
7053       </Para>
7054       
7055       <Para>
7056         The regular technique in accomplishing this in Linux
7057         is probably with use of ipchains AFTER making sure
7058         that the "outgoing" port 80(web) traffic gets routed through
7059         the server running squid.
7060       </Para>
7062       <Para>
7063         There are 3 common methods to make sure "outgoing"
7064         port 80 traffic gets routed to the server running squid
7065         and 4th one is being introduced here.
7066       </Para>
7067       
7068       <Para>
7069         <VariableList>
7070           <VarListEntry>
7071             <Term>Making the gateway router do it.</Term>
7072             <ListItem>
7073               <Para>
7074                 If you can tell your gateway router to 
7075                 match packets that has outgoing destination port
7076                 of 80 to be sent to the IP address of squid server.
7077               </Para>
7078               
7079               <Para>
7080                 BUT
7081               </Para>
7083               <Para>
7084                 This would put additional load on the router and
7085                 some commercial routers might not even support this.
7086               </Para>
7087             </ListItem>
7088           </VarListEntry>
7089           <VarListEntry>
7090             <Term>Using a Layer 4 switch.</Term>
7091             <ListItem>
7092               <Para>
7093                 Layer 4 switches can handle this without any problem.
7094               </Para>
7095               
7096               <Para>
7097                 BUT
7098               </Para>
7099               
7100               <Para>
7101                 The cost for this equipment is usually very high. Typical
7102                 layer 4 switch would normally cost more than
7103                 a typical router+good linux server.
7104               </Para>
7105             </ListItem>
7106           </VarListEntry>
7107           <VarListEntry>
7108             <Term>Using cache server as network's gateway.</Term>
7109             <ListItem>
7110               <Para>
7111                 You can force ALL traffic through cache server.
7112               </Para>
7113               <Para>
7114                 BUT
7115               </Para>
7116               <Para>
7117                 This is quite risky because Squid does utilize lots of CPU power which might
7118                 result in slower over-all network performance or the server itself might crash and no one on the
7119                 network will be able to access the Internet if that occurs.
7120               </Para>
7121             </ListItem>
7122           </VarListEntry>
7123           <VarListEntry>
7124             <Term>Linux+NetFilter router.</Term>
7125             <ListItem>
7126               <Para>
7127                 By using NetFilter another technique can be implemented
7128                 which is using NetFilter for "mark"ing the packets
7129                 with destination port 80 and using iproute2 to
7130                 route the "mark"ed packets to the Squid server.
7131               </Para>
7132             </ListItem>
7133           </VarListEntry>
7134         </VariableList>
7135         <Screen>
7136 |----------------|
7137 | Implementation |
7138 |----------------|
7140  Addresses used
7141  10.0.0.1 naret (NetFilter server)
7142  10.0.0.2 silom (Squid server)
7143  10.0.0.3 donmuang (Router connected to the Internet)
7144  10.0.0.4 kaosarn (other server on network)
7145  10.0.0.5 RAS
7146  10.0.0.0/24 main network
7147  10.0.0.0/19 total network
7149 |---------------|
7150 |Network diagram|
7151 |---------------|
7153 Internet
7155 donmuang
7157 ------------hub/switch----------
7158 |        |             |       |
7159 naret   silom        kaosarn  RAS etc.
7160         </Screen>
7162         First, make all traffic pass through naret by making sure it is the default gateway except for silom.
7163         Silom's default gateway has to be donmuang (10.0.0.3) or this would create web traffic loop.
7164       </Para>
7165       <Para>
7166         (all servers on my network had 10.0.0.1 as the default gateway  which was the former IP address of donmuang router so what I did
7167         was changed the IP address of donmuang to 10.0.0.3 and gave naret ip address of 10.0.0.1)
7168       </Para>
7169       <Para>
7170         <Screen>
7171 Silom
7172 -----
7173 -setup squid and ipchains 
7174         </Screen>
7175       </Para>
7176       <Para>
7177         Setup Squid server on silom, make sure it does support  transparent caching/proxying, the default port is usually
7178         3128, so all traffic for port 80 has to be redirected to port 3128 locally. This can be done by using ipchains with the following:
7179       </Para>
7180       <Para>
7181         <Screen>
7182 silom# ipchains -N allow1
7183 silom# ipchains -A allow1 -p TCP -s 10.0.0.0/19 -d 0/0 80 -j REDIRECT 3128
7184 silom# ipchains -I input -j allow1
7185         </Screen>
7186       </Para>
7187       <Para>
7188 Or, in netfilter lingo:
7189         <Screen>
7190 silom# iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
7191         </Screen>
7192       </Para>
7193       <Para>
7194         (note: you might have other entries as well)
7195       </Para>
7196       <Para>
7197         For more information on setting Squid server please refer to Squid FAQ page on <ULink
7198           URL="http://squid.nlanr.net">http://squid.nlanr.net</ULink>).
7199       </Para>
7200       <Para>
7201         Make sure ip forwarding is enabled on this server and the default gateway for this server is donmuang router (NOT naret).
7202       </Para>
7203       <Para>
7204         <Screen>
7205 Naret
7206 -----
7207 -setup iptables and iproute2
7208 -disable icmp REDIRECT messages (if needed)
7209         </Screen>
7210       </Para>
7211       <Para>
7212         <OrderedList>
7213           <ListItem>
7214             <Para>
7215               "Mark" packets of destination port 80 with value 2
7216               <Screen>
7217 naret# iptables -A PREROUTING -i eth0 -t mangle -p tcp --dport 80 \
7218  -j MARK --set-mark 2
7219               </Screen>
7220             </Para>
7221           </ListItem>
7222           <ListItem>
7223             <Para>
7224               Setup iproute2 so it will route packets with "mark" 2 to silom
7225               <Screen>
7226 naret# echo 202 www.out &#62;&#62; /etc/iproute2/rt_tables
7227 naret# ip rule add fwmark 2 table www.out
7228 naret# ip route add default via 10.0.0.2 dev eth0 table www.out
7229 naret# ip route flush cache
7230               </Screen>
7231             </para>
7232             <Para>
7233               If donmuang and naret is on the same subnet then naret should not send out icmp REDIRECT messages.
7234               In this case it is, so icmp REDIRECTs has to be disabled by:
7235               <Screen>
7236 naret# echo 0 &#62; /proc/sys/net/ipv4/conf/all/send_redirects
7237 naret# echo 0 &#62; /proc/sys/net/ipv4/conf/default/send_redirects
7238 naret# echo 0 &#62; /proc/sys/net/ipv4/conf/eth0/send_redirects
7239               </Screen>
7240             </Para>
7241           </ListItem>
7242         </OrderedList>
7243       </Para>
7244       <Para>
7245         The setup is complete, check the configuration
7246       </Para>
7247       <Para>
7248         <Screen>
7249 On naret:
7251 naret# iptables -t mangle -L
7252 Chain PREROUTING (policy ACCEPT)
7253 target     prot opt source               destination         
7254 MARK       tcp  --  anywhere             anywhere           tcp dpt:www MARK set 0x2 
7256 Chain OUTPUT (policy ACCEPT)
7257 target     prot opt source               destination         
7259 naret# ip rule ls
7260 0:      from all lookup local 
7261 32765:  from all fwmark        2 lookup www.out 
7262 32766:  from all lookup main 
7263 32767:  from all lookup default 
7265 naret# ip route list table www.out
7266 default via 203.114.224.8 dev eth0 
7268 naret# ip route   
7269 10.0.0.1 dev eth0  scope link 
7270 10.0.0.0/24 dev eth0  proto kernel  scope link  src 10.0.0.1
7271 127.0.0.0/8 dev lo  scope link 
7272 default via 10.0.0.3 dev eth0 
7274 (make sure silom belongs to one of the above lines, in this case
7275 it's the line with 10.0.0.0/24)
7277 |------|
7278 |-DONE-|
7279 |------|
7280         </Screen>
7281       </Para>
7282       <Sect2>
7283 <Title>Traffic flow diagram after implementation</Title>
7285 <Screen width="80">
7287 |-----------------------------------------|
7288 |Traffic flow diagram after implementation|
7289 |-----------------------------------------|
7291 INTERNET
7295 -----------------donmuang router---------------------
7296 /\                                      /\         ||
7297 ||                                      ||         ||
7298 ||                                      \/         ||
7299 naret                                  silom       ||
7300 *destination port 80 traffic=========&#62;(cache)      ||
7301 /\                                      ||         ||
7302 ||                                      \/         \/
7303 \\===================================kaosarn, RAS, etc.
7305 </Screen>
7307 <Para>
7308 Note that the network is asymmetric as there is one extra hop on 
7309 general outgoing path.
7310 </Para>
7312 <Para>
7314 <Screen>
7315 Here is run down for packet traversing the network from kaosarn
7316 to and from the Internet.
7318 For web/http traffic:
7319 kaosarn http request-&#62;naret-&#62;silom-&#62;donmuang-&#62;internet
7320 http replies from Internet-&#62;donmuang-&#62;silom-&#62;kaosarn
7322 For non-web/http requests(eg. telnet):
7323 kaosarn outgoing data-&#62;naret-&#62;donmuang-&#62;internet
7324 incoming data from Internet-&#62;donmuang-&#62;kaosarn
7325 </Screen>
7327 </Para>
7329 </Sect2>
7331 </Sect1>
7333 <Sect1 id="lartc.cookbook.mtu-discovery">
7334 <Title>Circumventing Path MTU Discovery issues with per route MTU settings</Title>
7336 <Para>
7337 For sending bulk data, the Internet generally works better when using larger
7338 packets. Each packet implies a routing decision, when sending a 1 megabyte
7339 file, this can either mean around 700 packets when using packets that are as
7340 large as possible, or 4000 if using the smallest default.
7341 </Para>
7343 <Para>
7344 However, not all parts of the Internet support full 1460 bytes of payload
7345 per packet. It is therefore necessary to try and find the largest packet
7346 that will 'fit', in order to optimize a connection.
7347 </Para>
7349 <Para>
7350 This process is called 'Path MTU Discovery', where MTU stands for 'Maximum
7351 Transfer Unit.' 
7352 </Para>
7354 <Para>
7355 When a router encounters a packet that's too big too send in one piece, AND
7356 it has been flagged with the "Don't Fragment" bit, it returns an ICMP
7357 message stating that it was forced to drop a packet because of this. The
7358 sending host acts on this hint by sending smaller packets, and by iterating
7359 it can find the optimum packet size for a connection over a certain path.
7360 </Para>
7362 <Para>
7363 This used to work well until the Internet was discovered by hooligans who do
7364 their best to disrupt communications. This in turn lead administrators to
7365 either block or shape ICMP traffic in a misguided attempt to improve
7366 security or robustness of their Internet service.
7367 </Para>
7369 <Para>
7370 What has happened now is that Path MTU Discovery is working less and less
7371 well and fails for certain routes, which leads to strange TCP/IP sessions
7372 which die after a while.
7373 </Para>
7375 <Para>
7376 Although I have no proof for this, two sites who I used to have this problem
7377 with both run Alteon Acedirectors before the affected systems - perhaps
7378 somebody more knowledgeable can provide clues as to why this happens.
7379 </Para>
7381 <Sect2>
7382 <Title>Solution</Title>
7384 <Para>
7385 When you encounter sites that suffer from this problem, you can disable Path
7386 MTU discovery by setting it manually. Koos van den Hout, slightly edited,
7387 writes:
7388 </Para>
7390 <blockquote>
7391 <Para>
7392 The following problem: I set the mtu/mru of my leased line running ppp to
7393 296 because it's only 33k6 and I cannot influence the queueing on the
7394 other side. At 296, the response to a key press is within a reasonable
7395 time frame.
7396 </Para>
7398 <Para>
7399 And, on my side I have a masqrouter running (of course) Linux.
7400 </Para>
7402 <Para>
7403 Recently I split 'server' and 'router' so most applications are run on a
7404 different machine than the routing happens on.
7405 </Para>
7407 <Para>
7408 I then had trouble logging into irc. Big panic! Some digging did find
7409 out that I got connected to irc, even showed up as 'connected' on irc
7410 but I did not receive the motd from irc. I checked what could be wrong
7411 and noted that I already had some previous trouble reaching certain
7412 websites related to the MTU, since I had no trouble reaching them when
7413 the MTU was 1500, the problem just showed when the MTU was set to 296.
7414 Since irc servers block about every kind of traffic not needed for their
7415 immediate operation, they also block icmp. 
7416 </Para>
7418 <Para>
7419 I managed to convince the operators of a webserver that this was the cause
7420 of a problem, but the irc server operators were not going to fix this.
7421 </Para>
7423 <Para>
7424 So, I had to make sure outgoing masqueraded traffic started with the lower
7425 mtu of the outside link. But I want local ethernet traffic to have the
7426 normal mtu (for things like nfs traffic).
7427 </Para>
7429 <Para>Solution:
7430 </Para>
7432 <Screen width="80">
7433 ip route add default via 10.0.0.1 mtu 296
7434 </Screen>
7436 <Para>
7437 (10.0.0.1 being the default gateway, the inside address of the
7438 masquerading router)
7439 </Para>
7440 </blockquote>
7442 <Para>
7443 In general, it is possible to override PMTU Discovery by setting specific
7444 routes. For example, if only a certain subnet is giving problems, this
7445 should help:
7446 </Para>
7448 <Screen width="80">
7449 ip route add 195.96.96.0/24 via 10.0.0.1 mtu 1000
7450 </Screen>
7452 </Sect2>
7454 </Sect1>
7456 <Sect1 id="lartc.cookbook.mtu-mss">
7457   <Title>Circumventing Path MTU Discovery issues with MSS Clamping
7458   (for ADSL, cable, PPPoE &amp; PPtP users)</Title>
7460 <Para>
7461 As explained above, Path MTU Discovery doesn't work as well as it should
7462 anymore. If you know for a fact that a hop somewhere in your network has a
7463 limited (&lt;1500) MTU, you cannot rely on PMTU Discovery finding this out.
7464 </Para>
7466 <Para>
7467 Besides MTU, there is yet another way to set the maximum packet size, the so
7468 called Maximum Segment Size. This is a field in the TCP Options part of a
7469 SYN packet.
7470 </Para>
7472 <Para>
7473 Recent Linux kernels, and a few PPPoE drivers (notably, the excellent
7474 Roaring Penguin one), feature the possibility to 'clamp the MSS'. 
7475 </Para>
7477 <Para>
7478 The good thing about this is that by setting the MSS value, you are telling
7479 the remote side unequivocally 'do not ever try to send me packets bigger
7480 than this value'. No ICMP traffic is needed to get this to work.
7481 </Para>
7483 <Para>
7484 The bad thing is that it's an obvious hack - it breaks 'end to end' by
7485 modifying packets. Having said that, we use this trick in many places and it
7486 works like a charm.
7487 </Para>
7489 <Para>
7490 In order for this to work you need at least iptables-1.2.1a and Linux 2.4.3
7491 or higher. The basic command line is:
7493 <Screen>
7494 # iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS  --clamp-mss-to-pmtu
7495 </Screen>
7497 </Para>
7499 <Para>
7500 This calculates the proper MSS for your link. If you are feeling brave, or
7501 think that you know best, you can also do something like this:
7502 </Para>
7504 <Para>
7506 <Screen>
7507 # iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 128
7508 </Screen>
7510 </Para>
7512 <Para>
7513 This sets the MSS of passing SYN packets to 128. Use this if you have VoIP
7514 with tiny packets, and huge http packets which are causing chopping in your
7515 voice calls.
7516 </Para>
7518 </Sect1>
7520 <Sect1 id="lartc.cookbook.ultimate-tc">
7521 <Title>The Ultimate Traffic Conditioner: Low Latency, Fast Up &amp; Downloads</Title>
7523 <Para>
7524 Note: This script has recently been upgraded and previously only worked for
7525 Linux clients in your network! So you might want to update if you have
7526 Windows machines or Macs in your network and noticed that they were not able
7527 to download faster while others were uploading.
7528 </Para>
7530 <Para>
7531 I attempted to create the holy grail:
7532 <VariableList>
7534 <VarListEntry>
7535 <Term>Maintain low latency for interactive traffic at all times</Term>
7536 <ListItem>
7537 <Para>
7538 This means that downloading or uploading files should not disturb SSH or
7539 even telnet. These are the most important things, even 200ms latency is
7540 sluggish to work over.
7541 </Para></ListItem>
7542 </VarListEntry>
7543 <VarListEntry>
7544 <Term>Allow 'surfing' at reasonable speeds while up or downloading</Term>
7545 <ListItem>
7546 <Para>
7547 Even though http is 'bulk' traffic, other traffic should not drown it out 
7548 too much.
7549 </Para></ListItem>
7550 </VarListEntry>
7551 <VarListEntry>
7552 <Term>Make sure uploads don't harm downloads, and the other way around</Term>
7553 <ListItem>
7554 <Para>
7555 This is a much observed phenomenon where upstream traffic simply destroys
7556 download speed.
7557 </Para></ListItem>
7558 </VarListEntry>
7559 </VariableList>
7560 It turns out that all this is possible, at the cost of a tiny bit of
7561 bandwidth. The reason that uploads, downloads and ssh hurt each other is the
7562 presence of large queues in many domestic access devices like cable or DSL
7563 modems.
7564 </Para>
7566 <Para>
7567 The next section explains in depth what causes the delays, and how we can
7568 fix them. You can safely skip it and head straight for the script if you
7569 don't care how the magic is performed.
7570 </Para>
7572 <Sect2>
7573 <Title>Why it doesn't work well by default</Title>
7575 <Para>
7576 ISPs know that they are benchmarked solely on how fast people can download.
7577 Besides available bandwidth, download speed is influenced heavily by packet
7578 loss, which seriously hampers TCP/IP performance. Large queues can help
7579 prevent packet loss, and speed up downloads. So ISPs configure large queues.
7580 </Para>
7582 <Para>
7583 These large queues however damage interactivity. A keystroke must first
7584 travel the upstream queue, which may be seconds (!) long and go to your
7585 remote host. It is then displayed, which leads to a packet coming back, which
7586 must then traverse the downstream queue, located at your ISP, before it
7587 appears on your screen.
7588 </Para>
7590 <Para>
7591 This HOWTO teaches you how to mangle and process the queue in many ways, but
7592 sadly, not all queues are accessible to us. The queue over at the ISP is
7593 completely off-limits, whereas the upstream queue probably lives inside your
7594 cable modem or DSL device. You may or may not be able to configure it. Most
7595 probably not.
7596 </Para>
7598 <Para>
7599 So, what next? As we can't control either of those queues, they must be
7600 eliminated, and moved to your Linux router. Luckily this is possible.
7601 </Para>
7603 <Para>
7604 <VariableList>
7606 <VarListEntry>
7607 <Term>Limit upload speed</Term>
7608 <ListItem>
7609 <Para>
7610 By limiting our upload speed to slightly less than the truly available rate,
7611 no queues are built up in our modem. The queue is now moved to Linux.
7612 </Para></ListItem>
7613 </VarListEntry>
7614 <VarListEntry>
7615 <Term>Limit download speed</Term>
7616 <ListItem>
7617 <Para>
7618 This is slightly trickier as we can't really influence how fast the internet
7619 ships us data. We can however drop packets that are coming in too fast,
7620 which causes TCP/IP to slow down to just the rate we want. Because we don't 
7621 want to drop traffic unnecessarily, we configure a 'burst' size we allow at
7622 higher speed.
7623 </Para></ListItem>
7624 </VarListEntry>
7625 </VariableList>
7626 </Para>
7628 <Para>
7629 Now, once we have done this, we have eliminated the downstream queue totally
7630 (except for short bursts), and gain the ability to manage the upstream queue
7631 with all the power Linux offers.
7632 </Para>
7634 <Para>
7635 What remains to be done is to make sure interactive traffic jumps to the
7636 front of the upstream queue. To make sure that uploads don't hurt downloads,
7637 we also move ACK packets to the front of the queue. This is what normally
7638 causes the huge slowdown observed when generating bulk traffic both ways.
7639 The ACKnowledgements for downstream traffic must compete with upstream
7640 traffic, and get delayed in the process.
7641 </Para>
7643 <Para>
7644 If we do all this we get the following measurements using an excellent ADSL
7645 connection from xs4all in the Netherlands:
7646 </Para>
7648 <Para>
7650 <Screen>
7651 Baseline latency:
7652 round-trip min/avg/max = 14.4/17.1/21.7 ms
7654 Without traffic conditioner, while downloading:
7655 round-trip min/avg/max = 560.9/573.6/586.4 ms
7657 Without traffic conditioner, while uploading:
7658 round-trip min/avg/max = 2041.4/2332.1/2427.6 ms
7660 With conditioner, during 220kbit/s upload:
7661 round-trip min/avg/max = 15.7/51.8/79.9 ms
7663 With conditioner, during 850kbit/s download:
7664 round-trip min/avg/max = 20.4/46.9/74.0 ms
7666 When uploading, downloads proceed at ~80% of the available speed. Uploads
7667 at around 90%. Latency then jumps to 850 ms, still figuring out why.
7668 </Screen>
7670 </Para>
7672 <Para>
7673 What you can expect from this script depends a lot on your actual uplink
7674 speed. When uploading at full speed, there will always be a single packet
7675 ahead of your keystroke. That is the lower limit to the latency you can
7676 achieve - divide your MTU by your upstream speed to calculate. Typical
7677 values will be somewhat higher than that. Lower your MTU for better effects!
7678 </Para>
7680 <Para>
7681 Next, two versions of this script, one with Devik's excellent HTB, the other
7682 with CBQ which is in each Linux kernel, unlike HTB. Both are tested and work
7683 well.
7684 </Para>
7686 </Sect2>
7688 <Sect2>
7689 <Title>The actual script (CBQ)</Title>
7691 <Para>
7692 Works on all kernels. Within the CBQ
7693 qdisc we place two Stochastic Fairness Queues that make sure that multiple
7694 bulk streams don't drown each other out.
7695 </Para>
7697 <Para>
7698 Downstream traffic is policed using a tc filter containing a Token Bucket
7699 Filter.
7700 </Para>
7702 <Para>
7703 You might improve on this script by adding 'bounded' to the line that starts
7704 with 'tc class add .. classid 1:20'. If you lowered your MTU, also lower the
7705 allot &amp; avpkt numbers!
7706 </Para>
7708 <Para>
7710 <Screen>
7711 #!/bin/bash 
7713 # The Ultimate Setup For Your Internet Connection At Home
7716 # Set the following values to somewhat less than your actual download
7717 # and uplink speed. In kilobits
7718 DOWNLINK=800
7719 UPLINK=220
7720 DEV=ppp0
7722 # clean existing down- and uplink qdiscs, hide errors
7723 tc qdisc del dev $DEV root    2&#62; /dev/null &#62; /dev/null
7724 tc qdisc del dev $DEV ingress 2&#62; /dev/null &#62; /dev/null
7726 ###### uplink
7728 # install root CBQ
7730 tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 10mbit 
7732 # shape everything at $UPLINK speed - this prevents huge queues in your
7733 # DSL modem which destroy latency:
7734 # main class
7736 tc class add dev $DEV parent 1: classid 1:1 cbq rate ${UPLINK}kbit \
7737 allot 1500 prio 5 bounded isolated 
7739 # high prio class 1:10:
7741 tc class add dev $DEV parent 1:1 classid 1:10 cbq rate ${UPLINK}kbit \
7742    allot 1600 prio 1 avpkt 1000
7744 # bulk and default class 1:20 - gets slightly less traffic, 
7745 #  and a lower priority:
7747 tc class add dev $DEV parent 1:1 classid 1:20 cbq rate $[9*$UPLINK/10]kbit \
7748    allot 1600 prio 2 avpkt 1000
7750 # both get Stochastic Fairness:
7751 tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
7752 tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
7754 # start filters
7755 # TOS Minimum Delay (ssh, NOT scp) in 1:10:
7756 tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
7757       match ip tos 0x10 0xff  flowid 1:10
7759 # ICMP (ip protocol 1) in the interactive class 1:10 so we 
7760 # can do measurements &#38; impress our friends:
7761 tc filter add dev $DEV parent 1:0 protocol ip prio 11 u32 \
7762         match ip protocol 1 0xff flowid 1:10
7764 # To speed up downloads while an upload is going on, put ACK packets in
7765 # the interactive class:
7767 tc filter add dev $DEV parent 1: protocol ip prio 12 u32 \
7768    match ip protocol 6 0xff \
7769    match u8 0x05 0x0f at 0 \
7770    match u16 0x0000 0xffc0 at 2 \
7771    match u8 0x10 0xff at 33 \
7772    flowid 1:10
7774 # rest is 'non-interactive' ie 'bulk' and ends up in 1:20
7776 tc filter add dev $DEV parent 1: protocol ip prio 13 u32 \
7777    match ip dst 0.0.0.0/0 flowid 1:20
7779 ########## downlink #############
7780 # slow downloads down to somewhat less than the real speed  to prevent 
7781 # queuing at our ISP. Tune to see how high you can set it.
7782 # ISPs tend to have *huge* queues to make sure big downloads are fast
7784 # attach ingress policer:
7786 tc qdisc add dev $DEV handle ffff: ingress
7788 # filter *everything* to it (0.0.0.0/0), drop everything that's
7789 # coming in too fast:
7791 tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
7792    0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1
7793 </Screen>
7795 If you want this script to be run by ppp on connect, copy it to
7796 /etc/ppp/ip-up.d.
7797 </Para>
7799 <Para>
7800 If the last two lines give an error, update your tc tool to a newer version!
7801 </Para>
7803 </Sect2>
7805 <Sect2>
7806 <Title>The actual script (HTB)</Title>
7808 <Para>
7809 The following script achieves all goals using the wonderful HTB queue, see
7810 the relevant chapter. Well worth patching your kernel for! 
7812 <Screen>
7813 #!/bin/bash
7815 # The Ultimate Setup For Your Internet Connection At Home
7818 # Set the following values to somewhat less than your actual download
7819 # and uplink speed. In kilobits
7820 DOWNLINK=800
7821 UPLINK=220
7822 DEV=ppp0
7824 # clean existing down- and uplink qdiscs, hide errors
7825 tc qdisc del dev $DEV root    2&#62; /dev/null &#62; /dev/null
7826 tc qdisc del dev $DEV ingress 2&#62; /dev/null &#62; /dev/null
7828 ###### uplink
7830 # install root HTB, point default traffic to 1:20:
7832 tc qdisc add dev $DEV root handle 1: htb default 20
7834 # shape everything at $UPLINK speed - this prevents huge queues in your
7835 # DSL modem which destroy latency:
7837 tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit burst 6k
7839 # high prio class 1:10:
7841 tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit \
7842    burst 6k prio 1
7844 # bulk &#38; default class 1:20 - gets slightly less traffic, 
7845 # and a lower priority:
7847 tc class add dev $DEV parent 1:1 classid 1:20 htb rate $[9*$UPLINK/10]kbit \
7848    burst 6k prio 2
7850 # both get Stochastic Fairness:
7851 tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
7852 tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
7854 # TOS Minimum Delay (ssh, NOT scp) in 1:10:
7855 tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
7856       match ip tos 0x10 0xff  flowid 1:10
7858 # ICMP (ip protocol 1) in the interactive class 1:10 so we 
7859 # can do measurements &#38; impress our friends:
7860 tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
7861         match ip protocol 1 0xff flowid 1:10
7863 # To speed up downloads while an upload is going on, put ACK packets in
7864 # the interactive class:
7866 tc filter add dev $DEV parent 1: protocol ip prio 10 u32 \
7867    match ip protocol 6 0xff \
7868    match u8 0x05 0x0f at 0 \
7869    match u16 0x0000 0xffc0 at 2 \
7870    match u8 0x10 0xff at 33 \
7871    flowid 1:10
7873 # rest is 'non-interactive' ie 'bulk' and ends up in 1:20
7876 ########## downlink #############
7877 # slow downloads down to somewhat less than the real speed  to prevent 
7878 # queuing at our ISP. Tune to see how high you can set it.
7879 # ISPs tend to have *huge* queues to make sure big downloads are fast
7881 # attach ingress policer:
7883 tc qdisc add dev $DEV handle ffff: ingress
7885 # filter *everything* to it (0.0.0.0/0), drop everything that's
7886 # coming in too fast:
7888 tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
7889    0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1
7890 </Screen>
7892 </Para>
7894 <Para>
7895 If you want this script to be run by ppp on connect, copy it to
7896 /etc/ppp/ip-up.d.
7897 </Para>
7899 <Para>
7900 If the last two lines give an error, update your tc tool to a newer version!
7901 </Para>
7903 </Sect2>
7905     </Sect1>
7906     <sect1 id="lartc.ratelimit.single"><title>Rate limiting a single host or netmask</title>
7907       <para>
7908         Although this is described in stupendous details elsewhere and in our manpages, this question gets asked a lot and 
7909         happily there is a simple answer that does not need full comprehension of traffic control.
7910       </para>
7911       <para>
7912         This three line script does the trick:
7913       </para>
7914       <para>
7915         <screen>
7916           tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 10mbit 
7918           tc class add dev $DEV parent 1: classid 1:1 cbq rate 512kbit \
7919           allot 1500 prio 5 bounded isolated 
7921           tc filter add dev $DEV parent 1: protocol ip prio 16 u32 \
7922           match ip dst 195.96.96.97 flowid 1:1
7923         </screen>
7924       </para>
7925       <para>
7926         The first line installs a class based queue on your interface, and tells the kernel that for calculations,
7927         it can be assumed to be a 10mbit interface. If you get this wrong, no real harm is done. But getting it right will 
7928         make everything more precise.
7929       </para>
7930       <para>
7931         The second line creates a 512kbit class with some reasonable defaults. For details, see the cbq manpages and
7932         <xref linkend="lartc.qdisc">.
7933       </para>
7934       <para>
7935         The last line tells which traffic should go to the shaped class. Traffic not matched by this rule is NOT shaped. To make more 
7936         complicated matches (subnets, source ports, destination ports), see <xref linkend="lartc.filtering.simple">.
7937       </para>
7938       <para>
7939         If you changed anything and want to reload the script, execute 'tc qdisc del dev $DEV root' to clean up your existing
7940         configuration.
7941       </para>
7942       <para>
7943         The script can further be improved by adding a last optional line 'tc qdisc add dev $DEV parent 1:1 sfq perturb 10'. See 
7944         <xref linkend="lartc.sfq"> for details on what this does.
7945       </para>
7946     </sect1>
7947 </chapter>
7949 <chapter id="lartc.bridging">
7950   <Title>Building bridges, and pseudo-bridges with Proxy ARP</Title>
7952 <Para>
7953 Bridges are devices which can be installed in a network without any
7954 reconfiguration. A network switch is basically a many-port bridge. A bridge
7955 is often a 2-port switch. Linux does however support multiple interfaces in
7956 a bridge, making it a true switch.
7957 </Para>
7959 <Para>
7960 Bridges are often deployed when confronted with a broken network that needs
7961 to be fixed without any alterations. Because the bridge is a layer-2 device,
7962 one layer below IP, routers and servers are not aware of its existence.
7963 This means that you can transparently block or modify certain packets, or do
7964 shaping.
7965 </Para>
7967 <Para>
7968 Another good thing is that a bridge can often be replaced by a cross cable
7969 or a hub, should it break down.
7970 </Para>
7972 <Para>
7973 The bad news is that a bridge can cause great confusion unless it is very
7974 well documented. It does not appear in traceroutes, but somehow packets
7975 disappear or get changed from point A to point B ('this network is
7976 HAUNTED!'). You should also wonder if an organization that 'does not want to
7977 change anything' is doing the right thing.
7978 </Para>
7980 <Para>
7981 The Linux 2.4/2.5 bridge is documented on
7982 <ULink URL=" http://bridge.sourceforge.net/">this page</ULink>.
7983 </Para>
7985 <Sect1 id="lartc.bridging.iptables">
7986   <Title>State of bridging and iptables</Title>
7988 <Para>
7989 As of Linux 2.4.14, bridging and iptables do not 'see' each other without
7990 help. If you bridge packets from eth0 to eth1, they do not 'pass' by
7991 iptables. This means that you cannot do filtering, or NAT or mangling or
7992 whatever.
7993 </Para>
7995 <Para>
7996 There are several projects going on to fix this, the truly right one is by
7997 the author of the Linux 2.4 bridging code, Lennert Buytenhek. He recently
7998 informed us that as of bridge-nf 0.0.2 (see the url above), the code is
7999 stable and usable in production environments.  He is now asking the kernel
8000 people if and how the patch can be merged, stay tuned!
8001 </Para>
8003 </Sect1>
8005 <Sect1 id="lartc.bridging.shaping">
8006   <Title>Bridging and shaping</Title>
8008 <Para>
8009 This does work as advertised. Be sure to figure out which side each
8010 interface is on, otherwise you might be shaping outbound traffic in your
8011 internal interface, which won't work. Use tcpdump if needed.
8012 </Para>
8014 </Sect1>
8016 <Sect1 id="lartc.bridging.proxy-arp">
8017   <Title>Pseudo-bridges with Proxy-ARP</Title>
8019 <Para>
8020 If you just want to implement a Pseudo-bridge, skip down a few sections 
8021 to 'Implementing it', but it is wise to read a bit about how it works in
8022 practice.
8023 </Para>
8025 <Para>
8026 A Pseudo-bridge works a bit differently. By default, a bridge passes packets
8027 unaltered from one interface to the other. It only looks at the hardware
8028 address of packets to determine what goes where. This in turn means that you
8029 can bridge traffic that Linux does not understand, as long as it has an
8030 hardware address it does.
8031 </Para>
8033 <Para>
8034 A 'Pseudo-bridge' works differently and looks more like a hidden router than
8035 a bridge, but like a bridge, it has little impact on network design.
8036 </Para>
8038 <Para>
8039 An advantage of the fact that it is not a bridge lies in the fact that
8040 packets really pass through the kernel, and can be filtered, changed,
8041 redirected or rerouted. 
8042 </Para>
8044 <Para>
8045 A real bridge can also be made to perform these feats, but it needs special
8046 code, like the Ethernet Frame Diverter, or the above mentioned patch.
8047 </Para>
8049 <Para>
8050 Another advantage of a pseudo-bridge is that it does not pass packets it
8051 does not understand - thus cleaning your network of a lot of cruft. In cases
8052 where you need this cruft (like SAP packets, or Netbeui), use a real bridge.
8053 </Para>
8055 <Sect2>
8056 <Title>ARP &amp; Proxy-ARP</Title>
8058 <Para>
8059 When a host wants to talk to another host on the same physical network
8060 segment, it sends out an Address Resolution Protocol packet, which, somewhat
8061 simplified, reads like this 'who has 10.0.0.1, tell 10.0.0.7'. In response
8062 to this, 10.0.0.1 replies with a short 'here' packet.
8063 </Para>
8065 <Para>
8066 10.0.0.7 then sends packets to the hardware address mentioned in the 'here' 
8067 packet. It caches this hardware address for a relatively long time, and
8068 after the cache expires, it re-asks the question.
8069 </Para>
8071 <Para>
8072 When building a Pseudo-bridge, we instruct the bridge to reply to these ARP
8073 packets, which causes the hosts in the network to send its packets to the
8074 bridge. The bridge then processes these packets, and sends them to the
8075 relevant interface.
8076 </Para>
8078 <Para>
8079 So, in short, whenever a host on one side of the bridge asks for the
8080 hardware address of a host on the other, the bridge replies with a packet
8081 that says 'hand it to me'.
8082 </Para>
8084 <Para>
8085 This way, all data traffic gets transmitted to the right place, and always
8086 passes through the bridge.
8087 </Para>
8089 </Sect2>
8091 <Sect2>
8092 <Title>Implementing it</Title>
8094 <Para>
8095 In the bad old days, it used to be possible to instruct the Linux Kernel to
8096 perform 'proxy-ARP' for just any subnet. So, to configure a pseudo-bridge,
8097 you would have to specify both the proper routes to both sides of the bridge
8098 AND create matching proxy-ARP rules. This is bad in that it requires a lot
8099 of typing, but also because it easily allows you to make mistakes which make
8100 your bridge respond to ARP queries for networks it does not know how to
8101 route.
8102 </Para>
8104 <Para>
8105 With Linux 2.4/2.5 (and possibly 2.2), this possibility has been withdrawn and
8106 has been replaced by a flag in the /proc directory, called 'proxy_arp'. The
8107 procedure for building a pseudo-bridge is then:
8108 </Para>
8110 <Para>
8112 <OrderedList>
8113 <ListItem>
8115 <Para>
8116 Assign an IP address to both interfaces, the 'left' and the 'right'
8118 </Para>
8119 </ListItem>
8120 <ListItem>
8122 <Para>
8123 Create routes so your machine knows which hosts reside on the left,
8124 and which on the right
8125 </Para>
8126 </ListItem>
8127 <ListItem>
8129 <Para>
8130 Turn on proxy-ARP on both interfaces, echo 1 &#62;
8131 /proc/sys/net/ipv4/conf/ethL/proxy_arp, echo 1 &#62;
8132 /proc/sys/net/ipv4/conf/ethR/proxy_arp, where L and R stand for the numbers
8133 of your interfaces on the left and on the right side
8134 </Para>
8135 </ListItem>
8137 </OrderedList>
8139 </Para>
8141 <Para>
8142 Also, do not forget to turn on the ip_forwarding flag! When converting from
8143 a true bridge, you may find that this flag was turned off as it is not
8144 needed when bridging.
8145 </Para>
8147 <Para>
8148 Another thing you might note when converting is that you need to clear the
8149 arp cache of computers in the network - the arp cache might contain old
8150 pre-bridge hardware addresses which are no longer correct.
8151 </Para>
8153 <Para>
8154 On a Cisco, this is done using the command 'clear arp-cache', under
8155 Linux, use 'arp -d ip.address'. You can also wait for the cache to expire
8156 manually, which can take rather long.
8157 </Para>
8158 <para>
8159 You can speed this up using the wonderful 'arping' tool, which on many
8160 distributions is part of the 'iputils' package. Using 'arping' you can send
8161 out unsolicited ARP messages so as to update remote arp caches. 
8162 </para>
8163 <para>
8164 This is a very powerful technique that is also used by 'black hats' to
8165 subvert your routing!
8166 </para>
8167 <note>
8168 <para>
8169 On Linux 2.4, you may need to execute 
8170 'echo 1 &gt; /proc/sys/net/ipv4/ip_nonlocal_bind' before being able to send
8171 out unsolicited ARP messages!
8172 </para>
8173 </note>
8174 <Para>
8175 You may also discover that your network was misconfigured if you are/were of
8176 the habit of specifying routes without netmasks. To explain, some versions
8177 of route may have guessed your netmask right in the past, or guessed wrong
8178 without you noticing. When doing surgical routing like described above, it
8179 is *vital* that you check your netmasks! 
8180 </Para>
8182 </Sect2>
8184 </Sect1>
8186 </chapter>
8188 <chapter id="lartc.dynamic-routing">
8189   <Title>Dynamic routing - OSPF and BGP</Title>
8191 <Para>
8192 Once your network starts to get really big, or you start to consider 'the
8193 internet' as your network, you need tools which dynamically route your data.
8194 Sites are often connected to each other with multiple links, and more are
8195 popping up all the time. 
8196 </Para>
8198 <Para>
8199 The Internet has mostly standardized on OSPF and BGP4 (rfc1771).
8200 Linux supports both, by way of <application>gated</application> and 
8201 <application>zebra</application>
8202 </Para>
8204 <Para>
8205 While currently not within the scope of this document, we would like to
8206 point you to the definitive works:
8207 </Para>
8209 <Para>
8210 Overview:
8211 </Para>
8213 <Para>
8214 Cisco Systems
8215 <ULink
8216 URL="http://www.cisco.com/univercd/cc/td/doc/cisintwk/idg4/nd2003.htm"
8217 >Designing large-scale IP Internetworks</ULink
8219 </Para>
8221 <Para>
8222 For OSPF:
8223 </Para>
8225 <Para>
8226 Moy, John T.
8227 "OSPF.  The anatomy of an Internet routing protocol"
8228 Addison Wesley. Reading, MA. 1998.
8229 </Para>
8231 <Para>
8232 Halabi has also written a good guide to OSPF routing design, but this
8233 appears to have been dropped from the Cisco web site.
8234 </Para>
8236 <Para>
8237 For BGP:
8238 </Para>
8240 <Para>
8241 Halabi, Bassam
8242 "Internet routing architectures"
8243 Cisco Press (New Riders Publishing). Indianapolis, IN. 1997.
8244 </Para>
8246 <Para>
8247 also
8248 </Para>
8250 <Para>
8251 Cisco Systems
8252 </Para>
8254 <Para>
8255 <ULink
8256 URL="http://www.cisco.com/univercd/cc/td/doc/cisintwk/ics/icsbgp4.htm"
8257 >Using the Border Gateway Protocol for interdomain routing</ULink
8259 </Para>
8261 <Para>
8262 Although the examples are Cisco-specific, they are remarkably similar
8263 to the configuration language in Zebra :-)
8264 </Para>
8266 </chapter>
8268 <chapter id="lartc.other"
8269   xreflabel="Other possibilities">
8270   <Title>Other possibilities</Title>
8272 <Para>
8273 This chapter is a list of projects having to do with advanced Linux routing
8274 &amp; traffic shaping. Some of these links may deserve chapters of their
8275 own, some are documented very well of themselves, and don't need more HOWTO.
8276 </Para>
8278 <Para>
8279 <VariableList>
8281 <VarListEntry>
8282 <Term>802.1Q VLAN Implementation for Linux <ULink
8283 URL="http://scry.wanfear.com/~greear/vlan.html"
8284 >(site)</ULink
8285 ></Term>
8286 <ListItem>
8287 <Para>
8288 VLANs are a very cool way to segregate your
8289 networks in a more virtual than physical way. Good information on VLANs can
8290 be found <ULink
8291 URL="ftp://ftp.netlab.ohio-state.edu/pub/jain/courses/cis788-97/virtual_lans/index.htm"
8292 >here</ULink
8293 >. With this implementation, you can have your Linux box talk
8294 VLANs with machines like Cisco Catalyst, 3Com: &lcub;Corebuilder, Netbuilder II,
8295 SuperStack II switch 630&rcub;, Extreme Ntwks Summit 48, Foundry: &lcub;ServerIronXL,
8296 FastIron&rcub;.
8297 </Para>
8299 <Para>
8300 A great HOWTO about VLANs can be found <ULink
8301 URL="http://scry.wanfear.com/~greear/vlan/cisco_howto.html"
8302 >here</ULink
8304 </Para>
8306 <Para>
8307 Update: has been included in the kernel as of 2.4.14 (perhaps 13).
8308 </Para></ListItem>
8309 </VarListEntry>
8310 <VarListEntry>
8311 <Term>Alternate 802.1Q VLAN Implementation for Linux <ULink
8312 URL="http://vlan.sourceforge.net "
8313 >(site)</ULink
8314 ></Term>
8315 <ListItem>
8316 <Para>
8317 Alternative VLAN implementation for linux. This project was started out of
8318 disagreement with the 'established' VLAN project's architecture and coding
8319 style, resulting in a cleaner overall design.
8320 </Para></ListItem>
8321 </VarListEntry>
8322 <VarListEntry>
8323 <Term>Linux Virtual Server <ULink
8324 URL="http://www.LinuxVirtualServer.org/"
8325 >(site)</ULink
8326 ></Term>
8327 <ListItem>
8328 <Para>
8329 These people are brilliant. The Linux Virtual Server is a highly scalable and
8330 highly available server built on a cluster of real servers, with the load
8331 balancer running on the Linux operating system. The architecture of the
8332 cluster is transparent to end users. End users only see a single virtual
8333 server.
8334 </Para>
8336 <Para>
8337 In short whatever you need to load balance, at whatever level of traffic, LVS
8338 will have a way of doing it. Some of their techniques are positively evil!
8339 For example, they let several machines have the same IP address on a
8340 segment, but turn off ARP on them. Only the LVS machine does ARP - it then
8341 decides which of the backend hosts should handle an incoming packet, and
8342 sends it directly to the right MAC address of the backend server. Outgoing
8343 traffic will flow directly to the router, and not via the LVS machine, which
8344 does therefor not need to see your 5Gbit/s of content flowing to the world,
8345 and cannot be a bottleneck.
8346 </Para>
8348 <Para>
8349 The LVS is implemented as a kernel patch in Linux 2.0 and 2.2, but as a
8350 Netfilter module in 2.4/2.5, so it does not need kernel patches! Their 2.4
8351 support is still in early development, so beat on it and give feedback or
8352 send patches.
8353 </Para></ListItem>
8354 </VarListEntry>
8355 <VarListEntry>
8356 <Term>CBQ.init <ULink
8357 URL="ftp://ftp.equinox.gu.net/pub/linux/cbq/"
8358 >(site)</ULink
8359 ></Term>
8360 <ListItem>
8361 <Para>
8362 Configuring CBQ can be a bit daunting, especially if all you want to do is
8363 shape some computers behind a router. CBQ.init can help you configure Linux
8364 with a simplified syntax.
8365 </Para>
8367 <Para>
8368 For example, if you want all computers in your 192.168.1.0/24 subnet
8369 (on 10mbit eth1) to be limited to 28kbit/s download speed, put
8370 this in the CBQ.init configuration file:
8371 </Para>
8373 <Para>
8375 <Screen>
8376 DEVICE=eth1,10Mbit,1Mbit
8377 RATE=28Kbit
8378 WEIGHT=2Kbit
8379 PRIO=5
8380 RULE=192.168.1.0/24
8381 </Screen>
8383 </Para>
8385 <Para>
8386 By all means use this program if the 'how and why' don't interest you.
8387 We're using CBQ.init in production and it works very well. It can even do
8388 some more advanced things, like time dependent shaping. The documentation is
8389 embedded in the script, which explains why you can't find a README.
8390 </Para></ListItem>
8391 </VarListEntry>
8392 <VarListEntry>
8393 <Term>Chronox easy shaping scripts <ULink
8394 URL="http://www.chronox.de"
8395 >(site)</ULink
8396 ></Term>
8397 <ListItem>
8398 <Para>
8399 Stephan Mueller (smueller@chronox.de) wrote two useful scripts, 'limit.conn'
8400 and 'shaper'. The first one allows you to easily throttle a single download
8401 session, like this:
8402 </Para>
8404 <Para>
8406 <Screen>
8407 # limit.conn -s SERVERIP -p SERVERPORT -l LIMIT
8408 </Screen>
8410 </Para>
8412 <Para>
8413 It works on Linux 2.2 and 2.4/2.5.
8414 </Para>
8416 <Para>
8417 The second script is more complicated, and can be used to make lots of
8418 different queues based on iptables rules, which are used to mark packets
8419 which are then shaped.
8420 </Para></ListItem>
8421 </VarListEntry>
8422 <VarListEntry>
8423 <Term>Virtual Router
8424 Redundancy Protocol implementation <ULink
8425 URL="http://w3.arobas.net/~jetienne/vrrpd/index.html"
8426 >(site)</ULink
8427 ></Term>
8428 <ListItem>
8429 <Para>
8430 This is purely for redundancy. Two machines with their own IP address and
8431 MAC Address together create a third IP Address and MAC Address, which is
8432 virtual. Originally intended purely for routers, which need constant MAC
8433 addresses, it also works for other servers.
8434 </Para>
8436 <Para>
8437 The beauty of this approach is the incredibly easy configuration. No kernel
8438 compiling or patching required, all userspace.
8439 </Para>
8441 <Para>
8442 Just run this on all machines participating in a service:
8444 <Screen>
8445 # vrrpd -i eth0 -v 50 10.0.0.22
8446 </Screen>
8448 </Para>
8450 <Para>
8451 And you are in business! 10.0.0.22 is now carried by one of your servers,
8452 probably the first one to run the vrrp daemon. Now disconnect that computer
8453 from the network and very rapidly one of the other computers will assume the
8454 10.0.0.22 address, as well as the MAC address.
8455 </Para>
8457 <Para>
8458 I tried this over here and had it up and running in 1 minute. For some
8459 strange reason it decided to drop my default gateway, but the -n flag
8460 prevented that.
8461 </Para>
8463 <Para>
8464 This is a 'live' fail over:
8465 </Para>
8467 <Para>
8469 <Screen>
8470 64 bytes from 10.0.0.22: icmp_seq=3 ttl=255 time=0.2 ms
8471 64 bytes from 10.0.0.22: icmp_seq=4 ttl=255 time=0.2 ms
8472 64 bytes from 10.0.0.22: icmp_seq=5 ttl=255 time=16.8 ms
8473 64 bytes from 10.0.0.22: icmp_seq=6 ttl=255 time=1.8 ms
8474 64 bytes from 10.0.0.22: icmp_seq=7 ttl=255 time=1.7 ms
8475 </Screen>
8477 </Para>
8479 <Para>
8480 Not *one* ping packet was lost! Just after packet 4, I disconnected my P200
8481 from the network, and my 486 took over, which you can see from the higher
8482 latency.
8483 </Para></ListItem>
8484 </VarListEntry>
8485 </VariableList>
8486 </Para>
8488 </chapter>
8490 <chapter id="lartc.further">
8491   <Title>Further reading</Title>
8493 <Para>
8494 <VariableList>
8496 <VarListEntry>
8497 <Term><ULink
8498 URL="http://snafu.freedom.org/linux2.2/iproute-notes.html"
8499 >http://snafu.freedom.org/linux2.2/iproute-notes.html</ULink
8500 ></Term>
8501 <ListItem>
8502 <Para>
8503 Contains lots of technical information, comments from the kernel
8504 </Para></ListItem>
8505 </VarListEntry>
8506 <VarListEntry>
8507 <Term><ULink
8508 URL="http://www.davin.ottawa.on.ca/ols/"
8509 >http://www.davin.ottawa.on.ca/ols/</ULink
8510 ></Term>
8511 <ListItem>
8512 <Para>
8513 Slides by Jamal Hadi Salim, one of the authors of Linux traffic control
8514 </Para></ListItem>
8515 </VarListEntry>
8516 <VarListEntry>
8517 <Term><ULink
8518 URL="http://defiant.coinet.com/iproute2/ip-cref/"
8519 >http://defiant.coinet.com/iproute2/ip-cref/</ULink
8520 ></Term>
8521 <ListItem>
8522 <Para>
8523 HTML version of Alexeys LaTeX documentation - explains part of iproute2 in
8524 great detail
8525 </Para></ListItem>
8526 </VarListEntry>
8527 <VarListEntry>
8528 <Term><ULink
8529 URL="http://www.aciri.org/floyd/cbq.html"
8530 >http://www.aciri.org/floyd/cbq.html</ULink
8531 ></Term>
8532 <ListItem>
8533 <Para>
8534 Sally Floyd has a good page on CBQ, including her original papers. None of
8535 it is Linux specific, but it does a fair job discussing the theory and uses
8536 of CBQ.
8537 Very technical stuff, but good reading for those so inclined. 
8538 </Para></ListItem>
8539 </VarListEntry>
8540 <VarListEntry>
8541 <Term>Differentiated Services on Linux</Term>
8542 <ListItem>
8543 <Para>
8544 This <ULink
8545 URL="ftp://icaftp.epfl.ch/pub/linux/diffserv/misc/dsid-01.txt.gz"
8546 >document</ULink
8547 > by Werner Almesberger, Jamal Hadi Salim and Alexey
8548 Kuznetsov describes DiffServ facilities in the Linux kernel, amongst which
8549 are TBF, GRED, the DSMARK qdisc and the tcindex classifier.
8550 </Para></ListItem>
8551 </VarListEntry>
8552 <VarListEntry>
8553 <Term><ULink
8554 URL="http://ceti.pl/~kravietz/cbq/NET4_tc.html"
8555 >http://ceti.pl/~kravietz/cbq/NET4_tc.html</ULink
8556 ></Term>
8557 <ListItem>
8558 <Para>
8559 Yet another HOWTO, this time in Polish! You can copy/paste command lines
8560 however, they work just the same in every language. The author is
8561 cooperating with us and may soon author sections of this HOWTO.
8562 </Para></ListItem>
8563 </VarListEntry>
8564 <VarListEntry>
8565 <Term><ULink
8566 URL="http://www.cisco.com/univercd/cc/td/doc/product/software/ios111/cc111/car.htm"
8567 >IOS Committed Access Rate</ULink
8568 ></Term>
8569 <ListItem>
8570 <Para>
8571 <Anchor id="CAR">
8572 From the helpful folks of Cisco who have the laudable habit of putting
8573 their documentation online. Cisco syntax is different but the concepts are
8574 the same, except that we can do more and do it without routers the price of
8575 cars :-)
8576 </Para></ListItem>
8577 </VarListEntry>
8578 <VarListEntry>
8579 <Term>Docum experimental site<ULink
8580 URL="http://www.docum.org"
8581 >(site)</ULink
8582 ></Term>
8583 <ListItem>
8584 <Para>
8585 Stef Coene is busy convincing his boss to sell Linux support, and so he is
8586 experimenting a lot, especially with managing bandwidth. His site has a lot
8587 of practical information, examples, tests and also points out some CBQ/tc bugs. 
8588 </Para>
8589 </ListItem>
8590 </VarListEntry>
8591 <VarListEntry>
8592 <Term>TCP/IP Illustrated, volume 1, W. Richard Stevens, ISBN 0-201-63346-9</Term>
8593 <ListItem>
8594 <Para>
8595 Required reading if you truly want to understand TCP/IP. Entertaining as
8596 well.
8597 </Para>
8598 </ListItem>
8599 </VarListEntry>
8600 </VariableList> 
8601 </Para>
8603 </chapter>
8605 <chapter id="lartc.ack">
8606 <Title>Acknowledgements </Title>
8608 <Para>
8610 It is our goal to list everybody who has contributed to this HOWTO, or
8611 helped us demystify how things work. While there are currently no plans
8612 for a Netfilter type scoreboard, we do like to recognize the people who are
8613 helping.
8614 </Para>
8616 <Para>
8618 <ItemizedList spacing="compact">
8619 <ListItem>
8621    <Para>
8622    <author><firstname>Junk</firstname><surname>Alins</surname></author>
8623    <address><email>juanjo@mat.upc.es</email></address>
8624    </Para>
8625   </ListItem>
8626   <ListItem>
8627    <Para>
8628    <author><firstname>Joe</firstname><surname>Van Andel</surname></author>
8629    </Para>
8630   </ListItem>
8632   <ListItem>
8633    <Para>
8634    <author><firstname>Michael</firstname><othername>T.</othername>
8635      <surname>Babcock</surname></author>
8636    <address><email>mbabcock@fibrespeed.net</email></address>
8637    </Para>
8638   </ListItem>
8641   <ListItem>
8642    <Para>
8643    <author><firstname>Christopher</firstname>
8644      <surname>Barton</surname></author>
8645    <address><email>cpbarton%uiuc.edu</email></address>
8646    </Para>
8647   </ListItem>
8650   <ListItem>
8651    <Para>
8652    <author><firstname>Ard</firstname><surname>van Breemen</surname></author>
8653    <address><email>ard&percnt;kwaak.net</email></address>
8654   </Para>
8655   </ListItem>
8656   <ListItem>
8657    <Para>
8658    <author><firstname>Ron</firstname><surname>Brinker</surname></author>
8659    <address><email>service&percnt;emcis.com</email></address>
8660    </Para>
8661   </ListItem>
8662   <ListItem>
8663    <Para>
8664    <author><firstname>?ukasz</firstname><surname>Bromirski</surname></author>
8665    <address><email>l.bromirski@mr0vka.eu.org</email></address>
8666    </Para>
8667   </ListItem>
8668   <ListItem>
8669    <Para>
8670    <author><firstname>Lennert</firstname><surname>Buytenhek</surname></author>
8671    <address><email>buytenh@gnu.org</email></address>
8672    </Para>
8673   </ListItem>
8674   <ListItem>
8675    <Para>
8676    <author><firstname>Esteve</firstname><surname>Camps</surname></author>
8677    <address><email>esteve@hades.udg.es</email></address>
8678    </Para>
8679   </ListItem>
8680   <ListItem>
8681    <Para>
8682    <author><firstname>Stef</firstname><surname>Coene</surname></author>
8683    <address><email>stef.coene@docum.org</email></address>
8684    </Para>
8685   </ListItem>
8686   <ListItem>
8687    <Para>
8688    <author><firstname>Don</firstname><surname>Cohen</surname></author>
8689    <address><email>don-lartc&percnt;isis.cs3-inc.com</email></address>
8690    </Para>
8691   </ListItem>
8692   <ListItem>
8693    <Para>
8694    <author><firstname>Jonathan</firstname><surname>Corbet</surname></author>
8695    <address><email>lwn&percnt;lwn.net</email></address>
8696    </Para>
8697   </ListItem>
8698   <ListItem>
8699    <Para>
8700    <author><firstname>Gerry</firstname><surname>Creager</surname>
8701      <othername>N5JXS</othername></author>
8702    <address><email>gerry&percnt;cs.tamu.edu</email></address>
8703    </Para>
8704   </ListItem>
8705   <ListItem>
8706    <Para>
8707    <author><firstname>Marco</firstname><surname>Davids</surname></author>
8708    <address><email>marco@sara.nl</email></address>
8709    </Para>
8710   </ListItem>
8711   <ListItem>
8712    <Para>
8713    <author><firstname>Jonathan</firstname><surname>Day</surname></author>
8714    <address><email>jd9812@my-deja.com</email></address>
8715    </Para>
8716   </ListItem>
8717   <ListItem>
8718    <Para>
8719    <author><firstname>Martin</firstname><surname>Devera</surname>
8720      <othername>aka devik</othername></author>
8721    <address><email>devik@cdi.cz</email></address>
8722   </Para>
8723   </ListItem>
8726   <ListItem>
8727    <Para>
8728    <author><firstname>Stephan</firstname><othername>"Kobold"</othername>
8729      <surname>Gehring</surname></author>
8730    <address><email>Stephan.Gehring@bechtle.de</email></address>
8731   </Para>
8732   </ListItem>
8733   <ListItem>
8734    <Para>
8735    <author><firstname>Jacek</firstname><surname>Glinkowski</surname></author>
8736    <address><email>jglinkow&percnt;hns.com</email></address>
8737   </Para>
8738   </ListItem>
8739   <ListItem>
8740    <Para>
8741    <author><firstname>Andrea</firstname><surname>Glorioso</surname></author>
8742    <address><email>sama&percnt;perchetopi.org</email></address>
8743   </Para>
8744   </ListItem>
8745   <ListItem>
8746    <Para>
8747    <author><firstname>Nadeem</firstname><surname>Hasan</surname></author>
8748    <address><email>nhasan@usa.net</email></address>
8749    </Para>
8750   </ListItem>
8751   <ListItem>
8752    <Para>
8753    <author><firstname>Erik</firstname><surname>Hensema</surname></author>
8754    <address><email>erik&percnt;hensema.xs4all.nl</email></address>
8755    </Para>
8756   </ListItem>
8757   <ListItem>
8758    <Para>
8759    <author><firstname>Vik</firstname><surname>Heyndrickx</surname></author>
8760    <address><email>vik.heyndrickx@edchq.com</email></address>
8761    </Para>
8762   </ListItem>
8763   <ListItem>
8764    <Para>
8765    <author><firstname>Spauldo</firstname><surname>Da Hippie</surname></author>
8766    <address><email>spauldo&percnt;usa.net</email></address>
8767    </Para>
8768   </ListItem>
8769   <ListItem>
8770    <Para>
8771    <author><firstname>Koos</firstname><surname>van den Hout</surname></author>
8772    <address><email>koos@kzdoos.xs4all.nl</email></address>
8773    </Para>
8774   </ListItem>
8775   <ListItem>
8777 <Para>
8778 Stefan Huelbrock &lt;shuelbrock&percnt;datasystems.de&gt;
8779 </Para>
8780 </ListItem>
8781 <ListItem>
8783 <Para>
8784 Alexander W. Janssen &lt;yalla&percnt;ynfonatic.de&gt;
8785 </Para>
8786 </ListItem>
8787 <ListItem>
8789 <Para>
8790 Gareth John &lt;gdjohn&percnt;zepler.org&gt;
8791 </Para>
8792 </ListItem>
8794   <ListItem>
8795    <Para>
8796    <author><firstname>Dave</firstname><surname>Johnson</surname></author>
8797    <address><email>dj@www.uk.linux.org</email></address>
8798    </Para>
8799   </ListItem>
8802 <ListItem>
8804 <Para>
8805 Martin Josefsson &lt;gandalf&percnt;wlug.westbo.se&gt;
8806 </Para>
8807 </ListItem>
8808 <ListItem>
8810 <Para>
8811 Andi Kleen &lt;ak&percnt;suse.de&gt;
8812 </Para>
8813 </ListItem>
8814 <ListItem>
8816 <Para>
8817 Andreas J. Koenig &lt;andreas.koenig&percnt;anima.de&gt;
8818 </Para>
8819 </ListItem>
8820 <ListItem>
8822 <Para>
8823 Pawel Krawczyk &lt;kravietz&percnt;alfa.ceti.pl&gt;
8824 </Para>
8825 </ListItem>
8826 <ListItem>
8828 <Para>
8829 Amit Kucheria &lt;amitk@ittc.ku.edu&gt;
8830 </Para>
8831 </ListItem>
8832 <ListItem>
8834 <Para>
8835 Edmund Lau &lt;edlau&percnt;ucf.ics.uci.edu&gt;
8836 </Para>
8837 </ListItem>
8838 <ListItem>
8840 <Para>
8841 Philippe Latu &lt;philippe.latu&percnt;linux-france.org&gt;
8842 </Para>
8843 </ListItem>
8844 <ListItem>
8846 <Para>
8847 Arthur van Leeuwen &lt;arthurvl&percnt;sci.kun.nl&gt;
8848 </Para>
8849 </ListItem>
8850   <ListItem>
8851    <Para>
8852    <author><firstname>Jose Luis Domingo</firstname><surname>Lopez</surname>
8853      </author>
8854    <address><email>jdomingo@24x7linux.com</email></address>
8855   </Para>
8856   </ListItem>
8857 <ListItem>
8859 <Para>
8860 Jason Lunz &lt;j@cc.gatech.edu&gt;
8861 </Para>
8862 </ListItem>
8863 <ListItem>
8865 <Para>
8866 Stuart Lynne &lt;sl@fireplug.net&gt;
8867 </Para>
8868 </ListItem>
8869 <ListItem>
8871 <Para>
8872 Alexey Mahotkin &lt;alexm@formulabez.ru&gt;
8873 </Para>
8874 </ListItem>
8875 <ListItem>
8877 <Para>
8878 Predrag Malicevic &lt;pmalic@ieee.org&gt;
8879 </Para>
8880 </ListItem>
8881 <listitem>
8882 <para>
8883 Patrick McHardy &lt;kaber@trash.net&gt;
8884 </para>
8885 </ListItem>
8887 <ListItem>
8890 <Para>
8891 Andreas Mohr &lt;andi&percnt;lisas.de&gt;
8892 </Para>
8893 </ListItem>
8894 <ListItem>
8896 <Para>
8897 Andrew Morton &lt;akpm@zip.com.au&gt;
8898 </Para>
8899 </ListItem>
8900 <ListItem>
8902 <Para>
8903 Wim van der Most 
8904 </Para>
8905 </ListItem>
8906 <ListItem>
8908 <Para>
8909 Stephan Mueller &lt;smueller@chronox.de&gt;
8910 </Para>
8911 </ListItem>
8912 <ListItem>
8914 <Para>
8915 Togan Muftuoglu &lt;toganm&percnt;yahoo.com&gt;
8916 </Para>
8917 </ListItem>
8918 <ListItem>
8920 <Para>
8921 Chris Murray &lt;cmurray@stargate.ca&gt;
8922 </Para>
8923 </ListItem>
8924 <ListItem>
8926 <Para>
8927 Patrick Nagelschmidt &lt;dto&percnt;gmx.net&gt;
8928 </Para>
8929 </ListItem>
8930 <ListItem>
8932 <Para>
8933 Ram Narula &lt;ram@princess1.net&gt;
8934 </Para>
8935 </ListItem>
8936 <ListItem>
8938 <Para>
8939 Jorge Novo &lt;jnovo@educanet.net&gt;
8940 </Para>
8941 </ListItem>
8942 <ListItem>
8944 <Para>
8945 Patrik &lt;ph@kurd.nu&gt;
8946 </Para>
8947 </ListItem>
8949 <listitem><para>P?l Osgy?ny &lt;oplab%westel900.net&gt;</para></listitem>
8951 <ListItem>
8953 <Para>
8954 Lutz Pre&szlig;ler &lt;Lutz.Pressler&percnt;SerNet.DE&gt;
8955 </Para>
8956 </ListItem>
8957 <ListItem>
8959 <Para>
8960 Jason Pyeron &lt;jason&percnt;pyeron.com&gt;
8961 </Para>
8962 </ListItem>
8963 <ListItem>
8965 <Para>
8966 Rusty Russell &lt;rusty&percnt;rustcorp.com.au&gt;
8967 </Para>
8968 </ListItem>
8969 <ListItem>
8971 <Para>
8972 Mihai RUSU &lt;dizzy&percnt;roedu.net&gt;
8973 </Para>
8974 </ListItem>
8975 <ListItem>
8977 <Para>
8978 Jamal Hadi Salim &lt;hadi&percnt;cyberus.ca&gt;
8979 </Para>
8980 </ListItem>
8981 <ListItem>
8983 <Para>
8984 David Sauer &lt;davids&percnt;penguin.cz&gt;
8985 </Para>
8986 </ListItem>
8987 <ListItem>
8989 <Para>
8990 Sheharyar Suleman Shaikh &lt;sss23@drexel.edu&gt;
8991 </Para>
8992 </ListItem>
8993 <ListItem>
8995 <Para>
8996 Stewart Shields &lt;MourningBlade&percnt;bigfoot.com&gt;
8997 </Para>
8998 </ListItem>
8999 <ListItem>
9001 <Para>
9002 Nick Silberstein &lt;nhsilber&percnt;yahoo.com&gt;
9003 </Para>
9004 </ListItem>
9005 <ListItem>
9007 <Para>
9008 Konrads Smelkov &lt;konrads@interbaltika.com&gt;
9009 </Para>
9010 </ListItem>
9011 <ListItem>
9013 <Para>
9014 <author><firstname>William</firstname><surname>Stearns</surname></author>
9015 <address><email>wstearns@pobox.com</email></address>
9016 </Para>
9017 </ListItem>
9019 <ListItem>
9020 <Para>
9021 Andreas Steinmetz &lt;ast&percnt;domdv.de&gt;
9022 </Para>
9023 </ListItem>
9024 <ListItem>
9026 <Para>
9027 Jason Tackaberry &lt;tack@linux.com&gt;
9028 </Para>
9029 </ListItem>
9030 <ListItem>
9032 <Para>
9033 Charles Tassell &lt;ctassell&percnt;isn.net&gt;
9034 </Para>
9035 </ListItem>
9036 <ListItem>
9038 <Para>
9039 Glen Turner &lt;glen.turner&percnt;aarnet.edu.au&gt;
9040 </Para>
9041 </ListItem>
9043 <ListItem>
9044 <Para>
9045 Tea Sponsor: Eric Veldhuyzen &lt;eric&percnt;terra.nu&gt; 
9046 </Para>
9047 </ListItem>
9049 <ListItem>
9050 <Para>
9051 Song Wang &lt;wsong@ece.uci.edu&gt;
9052 </Para>
9053 </ListItem>
9055   <ListItem>
9056    <Para>
9057    <author><firstname>Lazar</firstname><surname>Yanackiev</surname></author>
9058    <address><email>Lyanackiev%gmx.net</email></address>
9059    </Para>
9060   </ListItem>
9062 </ItemizedList>
9064 </Para>
9066 </chapter>
9068 </Book>