more
[lartc.git] / lartc.db
blob1319f602cedb1f7d6fe0642ee77c9368b374c91e
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>
1619     <Para>
1620       There are two kinds of IPSEC available for Linux these days. For 2.2 and 2.4, there is FreeS/WAN. They
1621       have <ULink URL="http://www.freeswan.org/">an official site</ulink> and <ulink url="http://www.freeswan.ca">
1622         an unofficial one</ulink> that is actually maintained. FreeS/WAN has traditionally not been merged with
1623       the mainline kernel for a number of reasons. Most often mentioned are 'political' issues with Americans
1624       working on crypto tainting its exportability. Furthermore, it does not integrate too well with the Linux kernel,
1625       leading it to be a bad candidate for actual merging. 
1626     </para>
1627     <para>
1628       Additionally, many parties have voiced worries about the quality of the code.
1629     </para>
1630     <para>
1631       As of Linux 2.5.47, there is a native IPSEC implementation in the kernel. It was written by Alexey Kuznetsov and
1632       Dave Miller, inspired by the work of the USAGI IPv6 group. With its merge, James Morris' CrypoAPI also became 
1633       part of the kernel - it does the actual crypting.
1634     </para>
1635     <para>
1636       This HOWTO will only document the 2.5+ version of IPSEC. FreeS/WAN is recommended for Linux 2.4 users for now, but be aware
1637       that its configuration wil differ from the native IPSEC.
1638     </para>
1639     <para>
1640       <note>
1641         <para>
1642           As this is written, 2.5.47 has not even been released! A lot of what follows is likely to change. To try this with 2.5.46,
1643           fetch patches from the linux kernel mailinglist. Crude userspace utilities are <ulink url="ftp://ftp.inr.ac.ru/ip-routing/ipsec">
1644             here</ulink>. Compiling these userspace utilities requires editing the GNUMakefiles in there to point them at your
1645           2.5.x kernel. This situation is expected to improve rapidly however.
1646         </para>
1647       </note>
1648       <warning>
1649         <para>
1650           The author of this chapter is a complete DNSSEC nitwit! If you find the inevitable mistakes, please email
1651           bert hubert <email>ahu@ds9a.nl</email>.
1652         </para>
1653       </warning>
1654     </Para>
1655     <para>
1656       First, we'll show how to setup secure communication between two hosts. This sample can be made much
1657       more complicated and powerful and we'll only do that, but only in a later section.
1658     </para>
1659     <sect1 id="lartc.ipsec.intro"><title>Intro with Manual Keying</title>
1660       <para>
1661         IPSEC is a complicated subject. A lot of information is available online, this HOWTO will concentrate on getting you
1662         up and running and explaining the basic principles.
1663       </para>
1664       <para>
1665         <note>
1666           <para>
1667             Many iptables configurations drop IPSEC packets! To pass IPSEC, use: 'iptables -A xxx -p 50' and 'iptables -A xxx -p 51'
1668           </para>
1669         </note>
1670       </para>
1671       <para>
1672         IPSEC offers a secure version of the Internet Protocol. Security in this context means two different things: encryption and authentication. 
1673         A naive vision of security offers only encryption but it can easily be shown that is insufficient - you may be communicating encyphered,
1674         but no guarantee is offered that the remote party is the one you expect it to be.
1675       </para>
1676       <para>
1677         IPSEC supports 'Encapsulated Security Payload' (ESP) for encryption and 'Authentication Header' (AH) for authenticating the remote partner.
1678         You can configure both of them, or decided to do only either.
1679       </para>
1680       <para>
1681         Both ESP and AH rely on security associations. A security association (SA) consists of a source, a destination and an instruction. A sample 
1682         authentication SA may look like this:
1683         <screen>
1684           add 10.0.0.11 10.0.0.216 ah 15700 -A hmac-md5 "1234567890123456";
1685         </screen>
1686         This says 'traffic going from 10.0.0.11 to 10.0.0.216 that needs an AH can be signed using HMAC-MD5 using secret 1234567890123456'. This instruction
1687         is labelled with SPI ('Security Parameter Index') id '15700', more about that later.
1688         The interesting bit about SAs is that they are symmetrical. Both sides of a conversation share exactly the same SA, it is not mirrored on the
1689         other side. Do note however that there is no 'autoreverse' rule - this SA only describes a possible authentication from 10.0.0.11 to 
1690         10.0.0.216. For two-way traffic, two SAs are needed.
1691       </para>
1692       <para>
1693         A sample ESP SA:
1694         <screen>
1695 add 10.0.0.11 10.0.0.216 esp 15701 -E 3des-cbc "123456789012123456789012";
1696         </screen>
1697         This says 'traffic going from 10.0.0.11 to 10.0.0.216 that needs encryption can be encyphered using 3des-cbc with key 123456789012123456789012'. The
1698         SPI id is '15701'.
1699       </para>
1700       <para>
1701         So far, we've seen that SAs describe possible instructions, but do not in fact describe policy as to when these need to be used. In fact,
1702         there could be an arbitrary number of nearly identical SAs with only differing SPI ids. Incidentally, SPI stands for Security Parameter Index.
1703         To do actual crypto, we need to describe a policy. This policy can include things as 'use ipsec if available' or 'drop traffic unless we have ispec'.
1704       </para>
1705       <para>
1706         A typical simple Security Policy (SP) looks like this:
1707         <screen>
1708 spdadd 10.0.0.216 10.0.0.11 any -P out ipsec
1709    esp/transport//require
1710    ah/transport//require;
1711         </screen>
1712         If entered on host 10.0.0.216, this means that all traffic going out to 10.0.0.11 must be encrypted 
1713         and be wrapped in an AH authenticating header. Note that this does not describe which SA is to be used,
1714         that is left as an exercise for the kernel to determine.
1715       </para>
1716       <para>
1717         Outgoing packets are however labelled with the SA SPI ids the kernel used for encryption and authentication 
1718         so the remote can lookup the corresponding verification and decryption instruction.
1719       </para>
1720       <para>
1721         What follows is a very simple configuration for talking from host 10.0.0.216 to 10.0.0.11 using 
1722         encryption and authentication. Note that the reverse path is plaintext in this first version and that
1723         this configuration should not be deployed.
1724       </para>
1725       <para>
1726         On host 10.0.0.216:
1727         <screen>
1728 #!/sbin/setkey -f
1729 add 10.0.0.216 10.0.0.11 ah 24500 -A hmac-md5 "1234567890123456";          
1730 add 10.0.0.216 10.0.0.11 esp 24501 -E 3des-cbc "123456789012123456789012";
1732 spdadd 10.0.0.216 10.0.0.11 any -P out ipsec
1733    esp/transport//required
1734    ah/transport//required;
1735         </screen>
1736       </para>
1737       <para>
1738         On host 10.0.0.11, the same Security Associations, no Security Policy:
1739         <screen>
1740 #!/sbin/setkey -f
1741 add 10.0.0.216 10.0.0.11 ah 24500 -A hmac-md5 "1234567890123456";
1742 add 10.0.0.216 10.0.0.11 esp 24501 -E 3des-cbc "123456789012123456789012";
1743         </screen>
1744       </para>
1745       <para>
1746         With the above configuration in place (these files can be executed if 'setkey' is installed in /sbin),
1747         'ping 10.0.0.11' from 10.0.0.216 looks like this using tcpdump:
1748         <screen>
1749 22:37:52 10.0.0.216 &gt; 10.0.0.11: AH(spi=0x00005fb4,seq=0xa): ESP(spi=0x00005fb5,seq=0xa) (DF)
1750 22:37:52 10.0.0.11 &gt; 10.0.0.216: icmp: echo reply
1751         </screen>
1752         Note how the ping back from 10.0.0.11 is indeed plainly visible. The forward ping cannot be read by tcpdump
1753         of course, but it does show the Security Parameter Index of AH and ESP, which tells 10.0.0.11 how to 
1754         verify the authenticity of our packet and how to decrypt it.
1755       </para>
1756       <para>
1757         A few things must be mentioned however. The configuration above is shown in a lot of IPSEC examples and it is very dangerous.
1758         The problem is that the above contains policy on how 10.0.0.216 should treat packets going to 10.0.0.11, and that it explains how 10.0.0.11
1759         should treat those packets but it does NOT instruct 10.0.0.11 to discard unauthenticated or unencrypted traffic! 
1760       </para>
1761       <para>
1762         Anybody can now insert spoofed and completely unencrypted data and 10.0.0.11 will accept it. To remedy the above, we need an incoming 
1763         Security Policy on 10.0.0.11, as follows:
1764         <screen>
1765 #!/sbin/setkey -f 
1766 spdadd 10.0.0.216 10.0.0.11 any -P IN ipsec
1767    esp/transport//require
1768    ah/transport//require;
1769         </screen>
1770         This instructs 10.0.0.11 that any traffic coming to it from 10.0.0.216 is required to have valid ESP and AH.
1771       </para>
1772       <para>
1773         Now, to complete this configuration, we need return traffic to be encrypted and authenticated as well of course. The full configuration on
1774         10.0.0.216:
1775         <screen>
1776 #!/sbin/setkey -f
1777 flush;
1778 spdflush;
1780 # AH
1781 add 10.0.0.11 10.0.0.216 ah 15700 -A hmac-md5 "1234567890123456";
1782 add 10.0.0.216 10.0.0.11 ah 24500 -A hmac-md5 "1234567890123456";
1784 # ESP
1785 add 10.0.0.11 10.0.0.216 esp 15701 -E 3des-cbc "123456789012123456789012";
1786 add 10.0.0.216 10.0.0.11 esp 24501 -E 3des-cbc "123456789012123456789012";
1788 spdadd 10.0.0.216 10.0.0.11 any -P out ipsec
1789            esp/transport//require
1790            ah/transport//require;
1792 spdadd 10.0.0.11 10.0.0.216 any -P in ipsec
1793            esp/transport//require
1794            ah/transport//require;
1795           
1796         </screen>
1797       </para>
1798       <para>
1799         And on 10.0.0.11:
1800         <screen>
1801 #!/sbin/setkey -f
1802 flush;
1803 spdflush;
1805 # AH
1806 add 10.0.0.11 10.0.0.216 ah 15700 -A hmac-md5 "1234567890123456";
1807 add 10.0.0.216 10.0.0.11 ah 24500 -A hmac-md5 "1234567890123456";
1809 # ESP
1810 add 10.0.0.11 10.0.0.216 esp 15701 -E 3des-cbc "123456789012123456789012";
1811 add 10.0.0.216 10.0.0.11 esp 24501 -E 3des-cbc "123456789012123456789012";
1814 spdadd 10.0.0.11 10.0.0.216 any -P out ipsec
1815            esp/transport//require
1816            ah/transport//require;
1818 spdadd 10.0.0.216 10.0.0.11 any -P in ipsec
1819            esp/transport//require
1820            ah/transport//require;
1822         </screen>
1823       </para>
1824       <para>
1825         Note that in this example we used identical keys for both directions of traffic. This is not in any way required however.
1826       </para>
1827       <para>
1828         To examine the configuration we just created, 
1829     </sect1>
1830     <sect1 id="lartc.ipsec.automatic.keying"><title>Automatic keying</title>
1831       <para>
1832         In the previous section, encryption was configured using simple shared secrets. In other words, to remain secure,
1833         we need to transfer our encryption configuration over a trusted channel. If we were to configure the remote host 
1834         over telnet, any third party would know our shared secret and the setup would not be secure.
1835       </para>
1836       <para>
1837         Furthermore, because the secret is shared, it is not a secret. The remote can't do a lot with our secret, but we do 
1838         need to make sure that we use a different secret for communicating with all our partners. This requires a large number of keys,
1839         if there are 10 parties, this needs at least 50 different secrets. 
1840       </para>
1841       <para>
1842         Besides the symmetric key problem, there is also the need for key rollover. If a third party manages to sniff enough traffic,
1843         it may be in a position to reverse engineer the key. This is prevented by moving to a new key every once in a while but that is
1844         a process that needs to be automated.
1845       </para>
1846       <para>
1847         Another problem is that with manual keying as described above we exactly define the algorithms and key lengths used, something
1848         that requires a lot of coordination with the remote party. It is desireable to be able to have the ability to describe a 
1849         broader key policy such as 'We can do 3DES and Blowfish with at least the following key lengths'.
1850       </para>
1851       <para>
1852         To solve these isses, IPSEC provides Internet Key Exchange to automatically exchange randomly generated keys which are
1853         transmitted using asymmetric encryption technology, according to negotiated algorithm details.
1854       </para>
1855       <para>
1856         The Linux 2.5 IPSEC implementation works with the KAME 'racoon' IKE daemon.
1857       </para>
1858       <para>
1859         FIXME: write more
1860       </para>
1861     </sect1>
1862     <sect1 id="lartc.ipsec.tunnel"><title>IPSEC tunnels</title>
1863       <para>
1864         So far, we've only seen IPSEC in so called 'transport' mode where both endpoints understand IPSEC directly. As this is often not
1865         the case, it is often necessary to have only routers understand IPSEC, and have them do the work for the hosts behind them. 
1866         This is called 'tunnel mode'.
1867       </para>
1868       <para>
1869         Setting this up is a breeze. To tunnel all traffic to 130.161.0.0/16 from 10.0.0.216 via 10.0.0.11, we issue the following on
1870         10.0.0.216:
1871 <screen>
1872 #!/sbin/setkey -f
1873 flush;
1874 spdflush;
1876 add 10.0.0.216 10.0.0.11 esp 34501
1877         -m tunnel
1878         -E 3des-cbc "123456789012123456789012";
1880 spdadd 10.0.0.0/24 130.161.0.0/16 any -P out ipsec
1881            esp/tunnel/10.0.0.216-10.0.0.11/require;
1882 </screen>
1883         Note the '-m tunnel', it is vitally important! This first configures an ESP encryption SA between our tunnel endpoints,
1884         10.0.0.216 and 10.0.0.11. 
1885       </para>
1886       <para>
1887         Next the actual tunnel is configured. It instructs the kernel to encrypt all traffic it has to route from 10.0.0.0/24 to
1888         130.161.0.0. Furthermore, this traffic then has to be shipped to 10.0.0.11.
1889       </para>
1890       <para>
1891         10.0.0.11 also needs some configuration:
1892 <screen>
1893 #!/sbin/setkey -f
1894 flush;
1895 spdflush;
1897 add 10.0.0.216 10.0.0.11 esp 34501
1898         -m tunnel
1899         -E 3des-cbc "123456789012123456789012";
1901 spdadd 10.0.0.0/24 130.161.0.0/16 any -P in ipsec
1902            esp/tunnel/10.0.0.216-10.0.0.11/require;
1903 </screen>
1904         Note that this is exactly identical, except for the change from '-P out' to '-P in'. As with earlier examples,
1905         we've now only configured traffic going one way. Completing the other half of the tunnel is left as an
1906         exercise for the reader.
1907       </para>
1908       <para>
1909         Another name for this setup is 'proxy ESP', which is somewhat clearer.
1910       </para>
1911       <para>
1912         <note>
1913           <para>
1914             The IPSEC tunnel needs to have IP Forwarding enabled in the kernel!
1915           </para>
1916         </note>
1917       </para>
1918     </sect1>
1919   </chapter>
1921 <chapter id="lartc.multicast">
1922 <Title>Multicast routing</Title>
1924 <Para>
1925 FIXME: Editor Vacancy!
1926 </Para>
1928 <Para>
1929 The Multicast-HOWTO is ancient (relatively-speaking) and may be inaccurate
1930 or misleading in places, for that reason.
1931 </Para>
1933 <Para>
1934 Before you can do any multicast routing, you need to configure the Linux
1935 kernel to support the type of multicast routing you want to do. This, in
1936 turn, requires you to decide what type of multicast routing you expect to
1937 be using. There are essentially four "common" types - DVMRP (the Multicast
1938 version of the RIP unicast protocol), MOSPF (the same, but for OSPF), PIM-SM
1939 ("Protocol Independent Multicasting - Sparse Mode", which assumes that users
1940 of any multicast group are spread out, rather than clumped) and PIM-DM (the
1941 same, but "Dense Mode", which assumes that there will be significant clumps
1942 of users of the same multicast group).
1943 </Para>
1945 <Para>
1946 In the Linux kernel, you will notice that these options don't appear. This is
1947 because the protocol itself is handled by a routing application, such as
1948 Zebra, mrouted, or pimd. However, you still have to have a good idea of which
1949 you're going to use, to select the right options in the kernel.
1950 </Para>
1952 <Para>
1953 For all multicast routing, you will definitely need to enable "multicasting"
1954 and "multicast routing". For DVMRP and MOSPF, this is sufficient. If you are
1955 going to use PIM, you must also enable PIMv1 or PIMv2, depending on whether
1956 the network you are connecting to uses version 1 or 2 of the PIM protocol.
1957 </Para>
1959 <Para>
1960 Once you have all that sorted out, and your new Linux kernel compiled, you
1961 will see that the IP protocols listed, at boot time, now include IGMP. This
1962 is a protocol for managing multicast groups. At the time of writing, Linux
1963 supports IGMP versions 1 and 2 only, although version 3 does exist and has
1964 been documented. This doesn't really affect us that much, as IGMPv3 is still
1965 new enough that the extra capabilities of IGMPv3 aren't going to be that
1966 much use. Because IGMP deals with groups, only the features present in the
1967 simplest version of IGMP over the entire group are going to be used. For the
1968 most part, that will be IGMPv2, although IGMPv1 is sill going to be
1969 encountered.
1970 </Para>
1972 <Para>
1973 So far, so good. We've enabled multicasting. Now, we have to tell the Linux
1974 kernel to actually do something with it, so we can start routing. This means
1975 adding the Multicast virtual network to the router table:
1976 </Para>
1978 <Para>
1979 ip route add 224.0.0.0/4 dev eth0
1980 </Para>
1982 <Para>
1983 (Assuming, of course, that you're multicasting over eth0! Substitute the
1984 device of your choice, for this.)
1985 </Para>
1987 <Para>
1988 Now, tell Linux to forward packets...
1989 </Para>
1991 <Para>
1992 echo 1 &#62; /proc/sys/net/ipv4/ip_forward
1993 </Para>
1995 <Para>
1996 At this point, you may be wondering if this is ever going to do anything. So,
1997 to test our connection, we ping the default group, 224.0.0.1, to see if anyone
1998 is alive. All machines on your LAN with multicasting enabled <Emphasis>should</Emphasis>
1999 respond, but nothing else. You'll notice that none of the machines that
2000 respond have an IP address of 224.0.0.1. What a surprise! :) This is a group
2001 address (a "broadcast" to subscribers), and all members of the group will
2002 respond with their own address, not the group address.
2003 </Para>
2005 <Para>
2006 ping -c 2 224.0.0.1
2007 </Para>
2009 <Para>
2010 At this point, you're ready to do actual multicast routing. Well, assuming
2011 that you have two networks to route between.
2012 </Para>
2014 <Para>
2015 (To Be Continued!)
2016 </Para>
2018 </chapter>
2020 <chapter id="lartc.qdisc">
2021 <Title>Queueing Disciplines for Bandwidth Management</Title>
2023 <Para>
2024 Now, when I discovered this, it <Emphasis>really</Emphasis> blew me away. Linux 2.2/2.4
2025 comes with everything to manage bandwidth in ways comparable to high-end
2026 dedicated bandwidth management systems.
2027 </Para>
2029 <Para>
2030 Linux even goes far beyond what Frame and ATM provide. 
2031 </Para>
2033 <Para>Just to prevent confusion, <command>tc</command> uses the following 
2034 rules for bandwith specification:
2036 <literallayout class='monospaced'>
2037 mbps = 1024 kbps = 1024 * 1024 bps =&#62; byte/s
2038 mbit = 1024 kbit =&#62; kilo bit/s.
2039 mb = 1024 kb = 1024 * 1024 b =&#62; byte
2040 mbit = 1024 kbit =&#62; kilo bit.
2041 </literallayout>
2043 Internally, the number is stored in bps and b.
2044 </Para>
2046 <Para>But when <command>tc</command> prints the rate, it uses following :
2047 </Para>
2049 <literallayout class='monospaced'>
2050 1Mbit = 1024 Kbit = 1024 * 1024 bps =&#62; byte/s
2051 </literallayout>
2053 <Sect1 id="lartc.qdisc.explain">
2054   <Title>Queues and Queueing Disciplines explained</Title>
2056 <Para>
2057 With queueing we determine the way in which data is <Emphasis>SENT</Emphasis>.
2058 It is important to realise that we can only shape data that we transmit.
2059 </Para>
2061 <Para>
2062 With the way the Internet works, we have no direct control of what people
2063 send us. It's a bit like your (physical!) mailbox at home. There is no way
2064 you can influence the world to modify the amount of mail they send you,
2065 short of contacting everybody.
2066 </Para>
2068 <Para>
2069 However, the Internet is mostly based on TCP/IP which has a few features
2070 that help us. TCP/IP has no way of knowing the capacity of the network
2071 between two hosts, so it just starts sending data faster and faster ('slow
2072 start') and when packets start getting lost, because there is no room to
2073 send them, it will slow down. In fact it is a bit smarter than this, but
2074 more about that later.
2075 </Para>
2077 <Para>
2078 This is the equivalent of not reading half of your mail, and hoping that
2079 people will stop sending it to you. With the difference that it works for
2080 the Internet :-)
2081 </Para>
2083 <Para>
2084 If you have a router and wish to prevent certain hosts within your network
2085 from downloading too fast, you need to do your shaping on the *inner* interface
2086 of your router, the one that sends data to your own computers.
2087 </Para>
2089 <Para>
2090 You also have to be sure you are controlling the bottleneck of the link.
2091 If you have a 100Mbit NIC and you have a router that has a 256kbit link,
2092 you have to make sure you are not sending more data than your router can
2093 handle.  Otherwise, it will be the router who is controlling the link and
2094 shaping the available bandwith. We need to 'own the queue' so to speak, and
2095 be the slowest link in the chain. Luckily this is easily possible.
2096 </Para>
2098 </Sect1>
2100 <Sect1 id="lartc.qdisc.classless">
2101   <Title>Simple, classless Queueing Disciplines</Title>
2103 <Para>
2104 As said, with queueing disciplines, we change the way data is sent.
2105 Classless queueing disciplines are those that, by and large accept data and
2106 only reschedule, delay or drop it.
2107 </Para>
2109 <Para>
2110 These can be used to shape traffic for an entire interface, without any
2111 subdivisions. It is vital that you understand this part of queueing before
2112 we go on the the classful qdisc-containing-qdiscs!
2113 </Para>
2115 <Para>
2116 By far the most widely used discipline is the pfifo_fast qdisc - this is the
2117 default. This also explains why these advanced features are so robust. They
2118 are nothing more than 'just another queue'.
2119 </Para>
2121 <Para>
2122 Each of these queues has specific strengths and weaknesses. Not all of them
2123 may be as well tested.
2124 </Para>
2126 <Sect2>
2127 <Title>pfifo_fast</Title>
2129 <Para>
2130 This queue is, as the name says, First In, First Out, which means that no
2131 packet receives special treatment. At least, not quite. This queue has 3 so
2132 called 'bands'. Within each band, FIFO rules apply. However, as long as
2133 there are packets waiting in band 0, band 1 won't be processed. Same goes
2134 for band 1 and band 2.
2135 </Para>
2137 <Para>
2138 The kernel honors the so called Type of Service flag of packets, and takes
2139 care to insert 'minimum delay' packets in band 0. 
2140 </Para>
2142 <Para>
2143 Do not confuse this classless simple qdisc with the classful PRIO one!
2144 Although they behave similarly, pfifo_fast is classless and you cannot add
2145 other qdiscs to it with the tc command.
2146 </Para>
2148 <Sect3>
2149 <Title>Parameters &amp; usage</Title>
2151 <Para>
2152 You can't configure the pfifo_fast qdisc as it is the hardwired default.
2153 This is how it is configured by default:
2154 <VariableList>
2156 <VarListEntry>
2157 <Term>priomap</Term>
2158 <ListItem>
2159 <Para>
2160 Determines how packet priorities, as assigned by the kernel, map to bands.
2161 Mapping occurs based on the TOS octet of the packet, which looks like this:
2162 </Para>
2164 <Para>
2166 <Screen>
2167    0     1     2     3     4     5     6     7
2168 +-----+-----+-----+-----+-----+-----+-----+-----+
2169 |                 |                       |     |
2170 |   PRECEDENCE    |          TOS          | MBZ |
2171 |                 |                       |     |
2172 +-----+-----+-----+-----+-----+-----+-----+-----+
2173 </Screen>
2175 </Para>
2177 <Para>
2178 The four TOS bits (the 'TOS field') are defined as:
2180 <Screen>
2181 Binary Decimcal  Meaning
2182 -----------------------------------------
2183 1000   8         Minimize delay (md)
2184 0100   4         Maximize throughput (mt)
2185 0010   2         Maximize reliability (mr)
2186 0001   1         Minimize monetary cost (mmc)
2187 0000   0         Normal Service
2188 </Screen>
2190 </Para>
2192 <Para>
2193 As there is 1 bit to the right of these four bits, the actual value of the
2194 TOS field is double the value of the TOS bits. Tcpdump -v -v shows you the
2195 value of the entire TOS field, not just the four bits. It is the value you
2196 see in the first column of this table:
2197 </Para>
2199 <Para>
2201 <Screen>
2202 TOS     Bits  Means                    Linux Priority    Band
2203 ------------------------------------------------------------
2204 0x0     0     Normal Service           0 Best Effort     1
2205 0x2     1     Minimize Monetary Cost   1 Filler          2
2206 0x4     2     Maximize Reliability     0 Best Effort     1
2207 0x6     3     mmc+mr                   0 Best Effort     1
2208 0x8     4     Maximize Throughput      2 Bulk            2
2209 0xa     5     mmc+mt                   2 Bulk            2
2210 0xc     6     mr+mt                    2 Bulk            2
2211 0xe     7     mmc+mr+mt                2 Bulk            2
2212 0x10    8     Minimize Delay           6 Interactive     0
2213 0x12    9     mmc+md                   6 Interactive     0
2214 0x14    10    mr+md                    6 Interactive     0
2215 0x16    11    mmc+mr+md                6 Interactive     0
2216 0x18    12    mt+md                    4 Int. Bulk       1
2217 0x1a    13    mmc+mt+md                4 Int. Bulk       1
2218 0x1c    14    mr+mt+md                 4 Int. Bulk       1
2219 0x1e    15    mmc+mr+mt+md             4 Int. Bulk       1
2220 </Screen>
2222 </Para>
2224 <Para>
2225 Lots of numbers. The second column contains the value of the relevant four
2226 TOS bits, followed by their translated meaning. For example, 15 stands for a
2227 packet wanting Minimal Monetary Cost, Maximum Reliability, Maximum
2228 Throughput AND Minimum Delay. I would call this a 'Dutch Packet'.
2229 </Para>
2231 <Para>
2232 The fourth column lists the way the Linux kernel interprets the TOS bits, by
2233 showing to which Priority they are mapped. 
2234 </Para>
2236 <Para>
2237 The last column shows the result of the default priomap. On the command line,
2238 the default priomap looks like this:
2240 <Screen>
2241 1, 2, 2, 2, 1, 2, 0, 0 , 1, 1, 1, 1, 1, 1, 1, 1
2242 </Screen>
2244 </Para>
2246 <Para>
2247 This means that priority 4, for example, gets mapped to band number 1. The
2248 priomap also allows you to list higher priorities (&gt; 7) which do not
2249 correspond to TOS mappings, but which are set by other means.
2250 </Para>
2252 <Para>
2253 This table from RFC 1349 (read it for more details) tells you how
2254 applications might very well set their TOS bits:
2256 <Screen>
2257 TELNET                   1000           (minimize delay)
2259         Control          1000           (minimize delay)
2260         Data             0100           (maximize throughput)
2262 TFTP                     1000           (minimize delay)
2264 SMTP 
2265         Command phase    1000           (minimize delay)
2266         DATA phase       0100           (maximize throughput)
2268 Domain Name Service
2269         UDP Query        1000           (minimize delay)
2270         TCP Query        0000
2271         Zone Transfer    0100           (maximize throughput)
2273 NNTP                     0001           (minimize monetary cost)
2275 ICMP
2276         Errors           0000
2277         Requests         0000 (mostly)
2278         Responses        &#60;same as request&#62; (mostly)
2279 </Screen>
2281 </Para></ListItem>
2282 </VarListEntry>
2283 <VarListEntry>
2284 <Term>txqueuelen</Term>
2285 <ListItem>
2286 <Para>
2287 The length of this queue is gleaned from the interface configuration, which
2288 you can see and set with ifconfig and ip. To set the queue length to 10,
2289 execute: ifconfig eth0 txqueuelen 10
2290 </Para>
2292 <Para>
2293 You can't set this parameter with tc!
2294 </Para></ListItem>
2295 </VarListEntry>
2296 </VariableList>
2297 </Para>
2299 </Sect3>
2301 </Sect2>
2303 <Sect2>
2304 <Title>Token Bucket Filter</Title>
2306 <Para>
2307 The Token Bucket Filter (TBF) is a simple qdisc that only passes packets
2308 arriving at a rate which is not exceeding some administratively set rate, but
2309 with the possibility to allow short bursts in excess of this rate.
2310 </Para>
2312 <Para>
2313 TBF is very precise, network- and processor friendly. It should be your
2314 first choice if you simply want to slow an interface down!
2315 </Para>
2317 <Para>
2318 The TBF implementation consists of a buffer (bucket), constantly filled by
2319 some virtual pieces of information called tokens, at a specific rate (token
2320 rate). The most important parameter of the bucket is its size, that is the
2321 number of tokens it can store.
2322 </Para>
2324 <Para>
2325 Each arriving token collects one incoming data packet from the data queue
2326 and is then deleted from the bucket. Associating this algorithm
2327 with the two flows -- token and data, gives us three possible scenarios:
2328 </Para>
2330 <Para>
2332 <ItemizedList>
2333 <ListItem>
2335 <Para>
2336  The data arrives in TBF at a rate that's <Emphasis>equal</Emphasis> to the rate
2337 of incoming tokens. In this case each incoming packet has its matching token
2338 and passes the queue without delay.
2340 </Para>
2341 </ListItem>
2342 <ListItem>
2344 <Para>
2345  The data arrives in TBF at a rate that's <Emphasis>smaller</Emphasis> than the
2346 token rate. Only a part of the tokens are deleted at output of each data packet
2347 that's sent out the queue, so the tokens accumulate, up to the bucket size.
2348 The unused tokens can then be used to send data a a speed that's exceeding the
2349 standard token rate, in case short data bursts occur.
2351 </Para>
2352 </ListItem>
2353 <ListItem>
2355 <Para>
2356  The data arrives in TBF at a rate <Emphasis>bigger</Emphasis> than the token rate.
2357 This means that the bucket will soon be devoid of tokens, which causes the
2358 TBF to throttle itself for a while. This is called an 'overlimit situation'.
2359 If packets keep coming in, packets will start to get dropped.
2360 </Para>
2361 </ListItem>
2363 </ItemizedList>
2365 </Para>
2367 <Para>
2368 The last scenario is very important, because it allows to
2369 administratively shape the bandwidth available to data that's passing
2370 the filter.
2371 </Para>
2373 <Para>
2374 The accumulation of tokens allows a short burst of overlimit data to be
2375 still passed without loss, but any lasting overload will cause packets to be
2376 constantly delayed, and then dropped.
2377 </Para>
2379 <Para>
2380 Please note that in the actual implementation, tokens correspond to bytes,
2381 not packets.
2382 </Para>
2384 <Sect3>
2385 <Title>Parameters &amp; usage</Title>
2387 <Para>
2388 Even though you will probably not need to change them, tbf has some knobs
2389 available. First the parameters that are always available:
2390 <VariableList>
2392 <VarListEntry>
2393 <Term>limit or latency</Term>
2394 <ListItem>
2395 <Para>
2396 Limit is the number of bytes that can be queued waiting for tokens to become
2397 available. You can also specify this the other way around by setting the
2398 latency parameter, which specifies the maximum amount of time a packet can
2399 sit in the TBF. The latter calculation takes into account the size of the
2400 bucket, the rate and possibly the peakrate (if set).
2401 </Para></ListItem>
2402 </VarListEntry>
2403 <VarListEntry>
2404 <Term>burst/buffer/maxburst</Term>
2405 <ListItem>
2406 <Para>
2407 Size of the bucket, in bytes. This is the maximum amount of bytes that
2408 tokens can be available for instantaneously. In general, larger shaping
2409 rates require a larger buffer. For 10mbit/s on Intel, you need at least
2410 10kbyte buffer if you want to reach your configured rate!
2411 </Para>
2413 <Para>
2414 If your buffer is too small, packets may be dropped because more tokens
2415 arrive per timer tick than fit in your bucket.
2416 </Para></ListItem>
2417 </VarListEntry>
2418 <VarListEntry>
2419 <Term>mpu</Term>
2420 <ListItem>
2421 <Para>
2422 A zero-sized packet does not use zero bandwidth. For ethernet, no packet
2423 uses less than 64 bytes. The Minimum Packet Unit determines the minimal
2424 token usage for a packet.
2425 </Para></ListItem>
2426 </VarListEntry>
2427 <VarListEntry>
2428 <Term>rate</Term>
2429 <ListItem>
2430 <Para>
2431 The speedknob. See remarks above about limits!
2432 </Para></ListItem>
2433 </VarListEntry>
2434 </VariableList>
2435 </Para>
2437 <Para>
2438 If the bucket contains tokens and is allowed to empty, by default it does so
2439 at infinite speed. If this is unacceptable, use the following parameters:
2440 </Para>
2442 <Para>
2443 <VariableList>
2445 <VarListEntry>
2446 <Term>peakrate</Term>
2447 <ListItem>
2448 <Para>
2449 If tokens are available, and packets arrive, they are sent out immediately
2450 by default, at 'lightspeed' so to speak. That may not be what you want,
2451 especially if you have a large bucket. 
2452 </Para>
2454 <Para>
2455 The peakrate can be used to specify how quickly the bucket is allowed to be
2456 depleted. If doing everything by the book, this is achieved by releasing a
2457 packet, and then wait just long enough, and release the next. We calculated
2458 our waits so we send just at peakrate.
2459 </Para>
2461 <Para>
2462 However, due to de default 10ms timer resolution of Unix, with 10.000 bits
2463 average packets, we are limited to 1mbit/s of peakrate!
2464 </Para></ListItem>
2465 </VarListEntry>
2466 <VarListEntry>
2467 <Term>mtu/minburst</Term>
2468 <ListItem>
2469 <Para>
2470 The 1mbit/s peakrate is not very useful if your regular rate is more than
2471 that. A higher peakrate is possible by sending out more packets per
2472 timertick, which effectively means that we create a second bucket!
2473 </Para>
2475 <Para>
2476 This second bucket defaults to a single packet, which is not a bucket at
2477 all.
2478 </Para>
2480 <Para>
2481 To calculate the maximum possible peakrate, multiply the configured mtu by
2482 100 (or more correctly, HZ, which is 100 on Intel, 1024 on Alpha).
2483 </Para></ListItem>
2484 </VarListEntry>
2485 </VariableList>
2486 </Para>
2488 </Sect3>
2490 <Sect3>
2491 <Title>Sample configuration</Title>
2493 <Para>
2494 A simple but *very* useful configuration is this:
2496 <Screen>
2497 # tc qdisc add dev ppp0 root tbf rate 220kbit latency 50ms burst 1540
2498 </Screen>
2500 </Para>
2502 <Para>
2503 Ok, why is this useful? If you have a networking device with a large queue,
2504 like a DSL modem or a cable modem, and you talk to it over a fast device,
2505 like over an ethernet interface, you will find that uploading absolutely
2506 destroys interactivity.
2507 </Para>
2509 <Para>
2510 This is because uploading will fill the queue in the modem, which is
2511 probably *huge* because this helps actually achieving good data throughput
2512 uploading. But this is not what you want, you want to have the queue not too
2513 big so interactivity remains and you can still do other stuff while sending
2514 data.
2515 </Para>
2517 <Para>
2518 The line above slows down sending to a rate that does not lead to a queue in
2519 the modem - the queue will be in Linux, where we can control it to a limited
2520 size.
2521 </Para>
2523 <Para>
2524 Change 220kbit to your uplink's *actual* speed, minus a few percent. If you
2525 have a really fast modem, raise 'burst' a bit. 
2526 </Para>
2528 </Sect3>
2530 </Sect2>
2532 <Sect2 id="lartc.sfq">
2533 <Title>Stochastic Fairness Queueing</Title>
2535 <Para>
2536 Stochastic Fairness Queueing (SFQ) is a simple implementation of the fair
2537 queueing algorithms family. It's less accurate than others, but it also
2538 requires less calculations while being almost perfectly fair.
2539 </Para>
2541 <Para>
2542 The key word in SFQ is conversation (or flow), which mostly corresponds to a
2543 TCP session or a UDP stream. Traffic is divided into a pretty large number
2544 of FIFO queues, one for each conversation. Traffic is then sent in a round
2545 robin fashion, giving each session the chance to send data in turn.
2546 </Para>
2548 <Para>
2549 This leads to very fair behaviour and disallows any single conversation from
2550 drowning out the rest. SFQ is called 'Stochastic' because it doesn't really
2551 allocate a queue for each session, it has an algorithm which divides traffic
2552 over a limited number of queues using a hashing algorithm. 
2553 </Para>
2555 <Para>
2556 Because of the hash, multiple sessions might end up in the same bucket, which
2557 would halve each session's chance of sending a packet, thus halving the
2558 effective speed available. To prevent this situation from becoming
2559 noticeable, SFQ changes its hashing algorithm quite often so that any two
2560 colliding sessions will only do so for a small number of seconds.
2561 </Para>
2563 <Para>
2564 It is important to note that SFQ is only useful in case your actual outgoing
2565 interface is really full! If it isn't then there will be no queue on your
2566 linux machine and hence no effect. Later on we will describe how to combine
2567 SFQ with other qdiscs to get a best-of-both worlds situation.
2568 </Para>
2570 <Para>
2571 Specifically, setting SFQ on the ethernet interface heading to your
2572 cable modem or DSL router is pointless without further shaping!
2573 </Para>
2575 <Sect3>
2576 <Title>Parameters &amp; usage</Title>
2578 <Para>
2579 The SFQ is pretty much self tuning:
2580 <VariableList>
2582 <VarListEntry>
2583 <Term>perturb</Term>
2584 <ListItem>
2585 <Para>
2586 Reconfigure hashing once this many seconds. If unset, hash will never be
2587 reconfigured. Not recommended. 10 seconds is probably a good value.
2588 </Para></ListItem>
2589 </VarListEntry>
2590 <VarListEntry>
2591 <Term>quantum</Term>
2592 <ListItem>
2593 <Para>
2594 Amount of bytes a stream is allowed to dequeue before the next queue gets a
2595 turn. Defaults to 1 maximum sized packet (MTU-sized). Do not set below the
2596 MTU!
2597 </Para></ListItem>
2598 </VarListEntry>
2599 </VariableList>
2600 </Para>
2602 </Sect3>
2604 <Sect3>
2605 <Title>Sample configuration</Title>
2607 <Para>
2608 If you have a device which has identical link speed and actual available
2609 rate, like a phone modem, this configuration will help promote fairness:
2611 <Screen>
2612 # tc qdisc add dev ppp0 root sfq perturb 10
2613 # tc -s -d qdisc ls
2614 qdisc sfq 800c: dev ppp0 quantum 1514b limit 128p flows 128/1024 perturb 10sec 
2615  Sent 4812 bytes 62 pkts (dropped 0, overlimits 0) 
2616 </Screen>
2618 </Para>
2620 <Para>
2621 The number 800c: is the automatically assigned handle number, limit means
2622 that 128 packets can wait in this queue. There are 1024 hashbuckets
2623 available for accounting, of which 128 can be active at a time (no more
2624 packets fit in the queue!) Once every 10 seconds, the hashes are
2625 reconfigured.
2626 </Para>
2628 </Sect3>
2630 </Sect2>
2632 </Sect1>
2634 <Sect1 id="lartc.qdisc.advice">
2635   <Title>Advice for when to use which queue</Title>
2637 <Para>
2638 Summarizing, these are the simple queues that actually manage traffic by
2639 reordering, slowing or dropping packets.
2640 </Para>
2642 <Para>
2643 The following tips may help in choosing which queue to use. It mentions some
2644 qdiscs described in the
2645 <citetitle><xref linkend="lartc.adv-qdisc"></citetitle> chapter.
2646 </Para>
2648 <ItemizedList>
2649 <ListItem>
2650 <Para>
2651 To purely slow down outgoing traffic, use the Token Bucket Filter. Works up
2652 to huge bandwidths, if you scale the bucket.
2653 </Para>
2654 </ListItem>
2655 <ListItem>
2657 <Para>
2658 If your link is truly full and you want to make sure that no single session
2659 can dominate your outgoing bandwidth, use Stochastical Fairness Queueing.
2660 </Para>
2661 </ListItem>
2662 <ListItem>
2664 <Para>
2665 If you have a big backbone and know what you are doing, consider Random
2666 Early Drop (see Advanced chapter).
2667 </Para>
2668 </ListItem>
2669 <ListItem>
2671 <Para>
2672 To 'shape' incoming traffic which you are not forwarding, use the Ingress
2673 Policer. Incoming shaping is called 'policing', by the way, not 'shaping'.  
2674 </Para>
2675 </ListItem>
2676 <ListItem>
2678 <Para>
2679 If you *are* forwarding it, use a TBF on the interface you are forwarding
2680 the data to. Unless you want to shape traffic that may go out over several
2681 interfaces, in which case the only common factor is the incoming interface.
2682 In that case use the Ingress Policer.
2683 </Para>
2684 </ListItem>
2685 <ListItem>
2687 <Para>
2688 If you don't want to shape, but only want to see if your interface is so
2689 loaded that it has to queue, use the pfifo queue (not pfifo_fast). It lacks
2690 internal bands but does account the size of its backlog.
2691 </Para>
2692 </ListItem>
2693 <ListItem>
2694 <Para>
2695 Finally - you can also do <quote>social shaping</quote>.
2696 You may not always be able to use technology to achieve what you want.
2697 Users experience technical constraints as hostile.
2698 A kind word may also help with getting your bandwidth to be divided right!
2699 </Para>
2700 </ListItem>
2701 </ItemizedList>
2703 </Sect1>
2705 <Sect1 id="lartc.qdisc.terminology">
2706   <Title>Terminology</Title>
2708 <Para>
2709 To properly understand more complicated configurations it is necessary to
2710 explain a few concepts first. Because of the complexity and he relative
2711 youth of the subject, a lot of different words are used when people in fact
2712 mean the same thing.
2713 </Para>
2715 <Para>
2716 The following is loosely based on 
2717 <filename>draft-ietf-diffserv-model-06.txt</filename>,
2718 <citetitle>An Informal Management Model for Diffserv Routers</citetitle>.
2719 It can currently be found at 
2720 <ulink url="http://www.ietf.org/internet-drafts/draft-ietf-diffserv-model-06.txt">
2721   http://www.ietf.org/internet-drafts/draft-ietf-diffserv-model-06.txt
2722 </ulink>.
2723 </Para>
2725 <Para>
2726 Read it for the strict definitions of the terms used.
2727 <VariableList>
2729 <VarListEntry>
2730 <Term>Queueing Discipline</Term>
2731 <ListItem>
2732 <Para>
2733 An algorithm that manages the queue of a device, either incoming (ingress)
2734 or outgoing (egress).
2735 </Para></ListItem>
2736 </VarListEntry>
2737 <VarListEntry>
2738 <Term>Classless qdisc</Term>
2739 <ListItem>
2740 <Para>
2741 A qdisc with no configurable internal subdivisions. 
2742 </Para></ListItem>
2743 </VarListEntry>
2744 <VarListEntry>
2745 <Term>Classful qdisc</Term>
2746 <ListItem>
2747 <Para>
2748 A classful qdisc contains multiple classes. Each of these classes contains a
2749 further qdisc, which may again be classful, but need not be. According to
2750 the strict definition, pfifo_fast *is* classful, because it contains three
2751 bands which are, in fact, classes. However, from the user's configuration
2752 perspective, it is classless as the classes can't be touched with the tc
2753 tool. 
2754 </Para></ListItem>
2755 </VarListEntry>
2756 <VarListEntry>
2757 <Term>Classes</Term>
2758 <ListItem>
2759 <Para>
2760 A classful qdisc may have many classes, which each are internal to the
2761 qdisc. Each of these classes may contain a real qdisc.
2762 </Para></ListItem>
2763 </VarListEntry>
2764 <VarListEntry>
2765 <Term>Classifier</Term>
2766 <ListItem>
2767 <Para>
2768 Each classful qdisc needs to determine to which class it needs to send a
2769 packet. This is done using the classifier.
2770 </Para></ListItem>
2771 </VarListEntry>
2772 <VarListEntry>
2773 <Term>Filter</Term>
2774 <ListItem>
2775 <Para>
2776 Classification can be performed using filters. A filter contains a number of
2777 conditions which if matched, make the filter match.
2778 </Para></ListItem>
2779 </VarListEntry>
2780 <VarListEntry>
2781 <Term>Scheduling</Term>
2782 <ListItem>
2783 <Para>
2784 A qdisc may, with the help of a classifier, decide that some packets need to
2785 go out earlier than others. This process is called Scheduling, and is
2786 performed for example by the pfifo_fast qdisc mentioned earlier. Scheduling
2787 is also called 'reordering', but this is confusing.
2788 </Para></ListItem>
2789 </VarListEntry>
2790 <VarListEntry>
2791 <Term>Shaping</Term>
2792 <ListItem>
2793 <Para>
2794 The process of delaying packets before they go out to make traffic confirm
2795 to a configured maximum rate. Shaping is performed on egress. Colloquially, 
2796 dropping packets to slow traffic down is also often called Shaping.
2797 </Para></ListItem>
2798 </VarListEntry>
2799 <VarListEntry>
2800 <Term>Policing</Term>
2801 <ListItem>
2802 <Para>
2803 Delaying or dropping packets in order to make traffic stay below a
2804 configured bandwidth. In Linux, policing can only drop a packet and not
2805 delay it - there is no 'ingress queue'.
2806 </Para></ListItem>
2807 </VarListEntry>
2808 <VarListEntry>
2809 <Term>Work-Conserving</Term>
2810 <ListItem>
2811 <Para>
2812 A work-conserving qdisc always delivers a packet if one is available. In
2813 other words, it never delays a packet if the network adaptor is ready to
2814 send one (in the case of an egress qdisc).
2815 </Para></ListItem>
2816 </VarListEntry>
2817 <VarListEntry>
2818 <Term>non-Work-Conserving</Term>
2819 <ListItem>
2820 <Para>
2821 Some queues, like for example the Token Bucket Filter, may need to hold on
2822 to a packet for a certain time in order to limit the bandwidth. This means
2823 that they sometimes refuse to give up a packet, even though they have one
2824 available.
2825 </Para></ListItem>
2826 </VarListEntry>
2827 </VariableList>
2828 </Para>
2830 <Para>
2831 Now that we have our terminology straight, let's see where all these things
2832 are.
2833 </Para>
2835 <Para>
2837 <Screen width="80">
2838                 Userspace programs
2839                      ^
2840                      |
2841      +---------------+-----------------------------------------+
2842      |               Y                                         |
2843      |    -------&#62; IP Stack                                    |
2844      |   |              |                                      |
2845      |   |              Y                                      |
2846      |   |              Y                                      |
2847      |   ^              |                                      |
2848      |   |  / ----------&#62; Forwarding -&#62;                        |
2849      |   ^ /                           |                       |
2850      |   |/                            Y                       |
2851      |   |                             |                       |
2852      |   ^                             Y          /-qdisc1-\   |
2853      |   |                            Egress     /--qdisc2--\  |
2854   ---&#62;-&#62;Ingress                       Classifier ---qdisc3---- | -&#62;
2855      |   Qdisc                                   \__qdisc4__/  |
2856      |                                            \-qdiscN_/   |
2857      |                                                         |
2858      +----------------------------------------------------------+
2859 </Screen>
2861 Thanks to Jamal Hadi Salim for this ASCII representation.
2862 </Para>
2864 <Para>
2865 The big block represents the kernel. The leftmost arrow represents traffic
2866 entering your machine from the network. It is then fed to the Ingress
2867 Qdisc which may apply Filters to a packet, and decide to drop it. This
2868 is called 'Policing'.
2869 </Para>
2871 <Para>
2872 This happens at a very early stage, before it has seen a lot of the kernel.
2873 It is therefore a very good place to drop traffic very early, without
2874 consuming a lot of CPU power.
2875 </Para>
2877 <Para>
2878 If the packet is allowed to continue, it may be destined for a local
2879 application, in which case it enters the IP stack in order to be processed,
2880 and handed over to a userspace program. The packet may also be forwarded
2881 without entering an application, in which case it is destined for egress.
2882 Userspace programs may also deliver data, which is then examined and
2883 forwarded to the Egress Classifier.
2884 </Para>
2886 <Para>
2887 There it is investigated and enqueued to any of a number of qdiscs. In the
2888 unconfigured default case, there is only one egress qdisc installed, the
2889 pfifo_fast, which always receives the packet. This is called 'enqueueing'.
2890 </Para>
2892 <Para>
2893 The packet now sits in the qdisc, waiting for the kernel to ask for
2894 it for transmission over the network interface. This is called 'dequeueing'.
2895 </Para>
2897 <Para>
2898 This picture also holds in case there is only one network adaptor - the
2899 arrows entering and leaving the kernel should not be taken too literally.
2900 Each network adaptor has both ingress and egress hooks.
2901 </Para>
2903 </Sect1>
2905 <Sect1 id="lartc.qdisc.classful">
2906   <Title>Classful Queueing Disciplines</Title>
2908 <Para>
2909 Classful qdiscs are very useful if you have different kinds of traffic which
2910 should have differing treatment. One of the classful qdiscs is called 'CBQ'
2911 , 'Class Based Queueing' and it is so widely mentioned that people identify
2912 queueing with classes solely with CBQ, but this is not the case.
2913 </Para>
2915 <Para>
2916 CBQ is merely the oldest kid on the block - and also the most complex one.
2917 It may not always do what you want.  This may come as something of a shock
2918 to many who fell for the 'sendmail effect', which teaches us that any
2919 complex technology which doesn't come with documentation must be the best
2920 available.
2921 </Para>
2923 <Para>
2924 More about CBQ and its alternatives shortly.
2925 </Para>
2927 <Sect2>
2928 <Title>Flow within classful qdiscs &amp; classes</Title>
2930 <Para>
2931 When traffic enters a classful qdisc, it needs to be sent to any of the
2932 classes within - it needs to be 'classified'. To determine what to do with a
2933 packet, the so called 'filters' are consulted. It is important to know that
2934 the filters are called from within a qdisc, and not the other way around!
2935 </Para>
2937 <Para>
2938 The filters attached to that qdisc then return with a decision, and the
2939 qdisc uses this to enqueue the packet into one of the classes. Each subclass
2940 may try other filters to see if further instructions apply. If not, the
2941 class enqueues the packet to the qdisc it contains.
2942 </Para>
2944 <Para>
2945 Besides containing other qdiscs, most classful qdiscs also perform shaping.
2946 This is useful to perform both packet scheduling (with SFQ, for example) and
2947 rate control. You need this in cases where you have a high speed
2948 interface (for example, ethernet) to a slower device (a cable modem).
2949 </Para>
2951 <Para>
2952 If you were only to run SFQ, nothing would happen, as packets enter &amp;
2953 leave your router without delay: the output interface is far faster than
2954 your actual link speed. There is no queue to schedule then.
2955 </Para>
2957 </Sect2>
2959 <Sect2>
2960 <Title>The qdisc family: roots, handles, siblings and parents</Title>
2962 <Para>
2963 Each interface has one egress 'root qdisc', by default the earlier mentioned
2964 classless pfifo_fast queueing discipline. Each qdisc can be assigned a
2965 handle, which can be used by later configuration statements to refer to that
2966 qdisc. Besides an egress qdisc, an interface may also have an ingress, which
2967 polices traffic coming in.
2968 </Para>
2970 <Para>
2971 The handles of these qdiscs consist of two parts, a major number and a minor
2972 number. It is habitual to name the root qdisc '1:', which is equal to '1:0'.
2973 The minor number of a qdisc is always 0. 
2974 </Para>
2976 <Para>
2977 Classes need to have the same major number as their parent. 
2978 </Para>
2980 <Sect3>
2981 <Title>How filters are used to classify traffic </Title>
2983 <Para>
2984 Recapping, a typical hierarchy might look like this:
2986 <Screen>
2987                     root 1:
2988                       |
2989                     _1:1_
2990                    /  |  \
2991                   /   |   \
2992                  /    |    \
2993                10:   11:   12:
2994               /   \       /   \
2995            10:1  10:2   12:1  12:2
2996 </Screen>
2998 </Para>
3000 <Para>
3001 But don't let this tree fool you! You should *not* imagine the kernel to be
3002 at the apex of the tree and the network below, that is just not the case.
3003 Packets get enqueued and dequeued at the root qdisc, which is the only thing
3004 the kernel talks to. 
3005 </Para>
3007 <Para>
3008 A packet might get classified in a chain like this:
3009 </Para>
3011 <Para>
3012 1: -&#62; 1:1 -&#62; 12: -&#62; 12:2
3013 </Para>
3015 <Para>
3016 The packet now resides in a queue in a qdisc attached to class 12:2. In this
3017 example, a filter was attached to each 'node' in the tree, each choosing a
3018 branch to take next. This can make sense. However, this is also possible:
3019 </Para>
3021 <Para>
3022 1: -&#62; 12:2
3023 </Para>
3025 <Para>
3026 In this case, a filter attached to the root decided to send the packet
3027 directly to 12:2.
3028 </Para>
3030 </Sect3>
3032 <Sect3>
3033 <Title>How packets are dequeued to the hardware</Title>
3035 <Para>
3036 When the kernel decides that it needs to extract packets to send to the
3037 interface, the root qdisc 1: gets a dequeue request, which is passed to
3038 1:1, which is in turn passed to 10:, 11: and 12:, which each query their
3039 siblings, and try to dequeue() from them. In this case, the kernel needs to
3040 walk the entire tree, because only 12:2 contains a packet. 
3041 </Para>
3043 <Para>
3044 In short, nested classes ONLY talk to their parent qdiscs, never to an
3045 interface. Only the root qdisc gets dequeued by the kernel!
3046 </Para>
3048 <Para>
3049 The upshot of this is that classes never get dequeued faster than their
3050 parents allow. And this is exactly what we want: this way we can have SFQ in
3051 an inner class, which doesn't do any shaping, only scheduling, and have a
3052 shaping outer qdisc, which does the shaping.
3053 </Para>
3055 </Sect3>
3057 </Sect2>
3059 <Sect2>
3060 <Title>The PRIO qdisc</Title>
3062 <Para>
3063 The PRIO qdisc doesn't actually shape, it only subdivides traffic based on
3064 how you configured your filters. You can consider the PRIO qdisc a kind
3065 of pfifo_fast on steroids, whereby each band is a separate class instead of
3066 a simple FIFO.
3067 </Para>
3069 <Para>
3070 When a packet is enqueued to the PRIO qdisc, a class is chosen based on the
3071 filter commands you gave. By default, three classes are created. These
3072 classes by default contain pure FIFO qdiscs with no internal
3073 structure, but you can replace these by any qdisc you have available.
3074 </Para>
3076 <Para>
3077 Whenever a packet needs to be dequeued, class :1 is tried first. Higher
3078 classes are only used if lower bands all did not give up a packet.
3079 </Para>
3081 <Para>
3082 This qdisc is very useful in case you want to prioritize certain kinds of
3083 traffic without using only TOS-flags but using all the power of the tc
3084 filters. It can also contain more all qdiscs, whereas pfifo_fast is limited
3085 to simple fifo qdiscs.
3086 </Para>
3088 <Para>
3089 Because it doesn't actually shape, the same warning as for SFQ holds: either
3090 use it only if your physical link is really full or wrap it inside a
3091 classful qdisc that does shape. The last holds for almost all cable modems
3092 and DSL devices.
3093 </Para>
3095 <Para>
3096 In formal words, the PRIO qdisc is a Work-Conserving scheduler.
3097 </Para>
3099 <Sect3>
3100 <Title>PRIO parameters &amp; usage</Title>
3102 <Para>
3103 The following parameters are recognized by tc:
3104 <VariableList>
3106 <VarListEntry>
3107 <Term>bands</Term>
3108 <ListItem>
3109 <Para>
3110 Number of bands to create. Each band is in fact a class. If you change this
3111 number, you must also change:
3112 </Para></ListItem>
3113 </VarListEntry>
3114 <VarListEntry>
3115 <Term>priomap</Term>
3116 <ListItem>
3117 <Para>
3118 If you do not provide tc filters to classify traffic, the PRIO qdisc looks
3119 at the TC_PRIO priority to decide how to enqueue traffic. 
3120 </Para>
3122 <Para>
3123 This works just like with the pfifo_fast qdisc mentioned earlier, see there
3124 for lots of detail.
3125 </Para></ListItem>
3126 </VarListEntry>
3127 </VariableList>
3128 The bands are classes, and are called major:1 to major:3 by default, so if
3129 your PRIO qdisc is called 12:, tc filter traffic to 12:1 to grant it more
3130 priority.
3131 </Para>
3133 <Para>
3134 Reiterating, band 0 goes to minor number 1! Band 1 to minor number 2, etc.
3135 </Para>
3137 </Sect3>
3139 <Sect3>
3140 <Title>Sample configuration</Title>
3142 <Para>
3143 We will create this tree:
3145 <Screen>
3146      root 1: prio
3147        /   |   \
3148      1:1  1:2  1:3
3149       |    |    |
3150      10:  20:  30:
3151      sfq  tbf  sfq
3152 band  0    1    2
3153 </Screen>
3155 </Para>
3157 <Para>
3158 Bulk traffic will go to 30:, interactive traffic to 20: or 10:.
3159 </Para>
3161 <Para>
3162 Command lines:
3164 <Screen>
3165 # tc qdisc add dev eth0 root handle 1: prio 
3166 ## This *instantly* creates classes 1:1, 1:2, 1:3
3167   
3168 # tc qdisc add dev eth0 parent 1:1 handle 10: sfq
3169 # tc qdisc add dev eth0 parent 1:2 handle 20: tbf rate 20kbit buffer 1600 limit 3000
3170 # tc qdisc add dev eth0 parent 1:3 handle 30: sfq                                
3171 </Screen>
3173 </Para>
3175 <Para>
3176 Now let's see what we created:
3178 <Screen>
3179 # tc -s qdisc ls dev eth0 
3180 qdisc sfq 30: quantum 1514b 
3181  Sent 0 bytes 0 pkts (dropped 0, overlimits 0) 
3183  qdisc tbf 20: rate 20Kbit burst 1599b lat 667.6ms 
3184  Sent 0 bytes 0 pkts (dropped 0, overlimits 0) 
3186  qdisc sfq 10: quantum 1514b 
3187  Sent 132 bytes 2 pkts (dropped 0, overlimits 0) 
3189  qdisc prio 1: bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
3190  Sent 174 bytes 3 pkts (dropped 0, overlimits 0) 
3191 </Screen>
3193 As you can see, band 0 has already had some traffic, and one packet was sent
3194 while running this command!
3195 </Para>
3197 <Para>
3198 We now do some bulk data transfer with a tool that properly sets TOS flags,
3199 and take another look:
3201 <Screen>
3202 # scp tc ahu@10.0.0.11:./
3203 ahu@10.0.0.11's password: 
3204 tc                   100% |*****************************|   353 KB    00:00    
3205 # tc -s qdisc ls dev eth0
3206 qdisc sfq 30: quantum 1514b 
3207  Sent 384228 bytes 274 pkts (dropped 0, overlimits 0) 
3209  qdisc tbf 20: rate 20Kbit burst 1599b lat 667.6ms 
3210  Sent 2640 bytes 20 pkts (dropped 0, overlimits 0) 
3212  qdisc sfq 10: quantum 1514b 
3213  Sent 2230 bytes 31 pkts (dropped 0, overlimits 0) 
3215  qdisc prio 1: bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
3216  Sent 389140 bytes 326 pkts (dropped 0, overlimits 0) 
3217 </Screen>
3219 As you can see, all traffic went to handle 30:, which is the lowest priority
3220 band, just as intended. Now to verify that interactive traffic goes to
3221 higher bands, we create some interactive traffic:
3222 </Para>
3224 <Para>
3226 <Screen>
3227 # tc -s qdisc ls dev eth0
3228 qdisc sfq 30: quantum 1514b 
3229  Sent 384228 bytes 274 pkts (dropped 0, overlimits 0) 
3231  qdisc tbf 20: rate 20Kbit burst 1599b lat 667.6ms 
3232  Sent 2640 bytes 20 pkts (dropped 0, overlimits 0) 
3234  qdisc sfq 10: quantum 1514b 
3235  Sent 14926 bytes 193 pkts (dropped 0, overlimits 0) 
3237  qdisc prio 1: bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
3238  Sent 401836 bytes 488 pkts (dropped 0, overlimits 0) 
3239 </Screen>
3241 </Para>
3243 <Para>
3244 It worked - all additional traffic has gone to 10:, which is our highest
3245 priority qdisc. No traffic was sent to the lowest priority, which previously
3246 received our entire scp.
3247 </Para>
3249 </Sect3>
3251 </Sect2>
3253 <Sect2>
3254 <Title>The famous CBQ qdisc</Title>
3256 <Para>
3257 As said before, CBQ is the most complex qdisc available, the most hyped, the
3258 least understood, and probably the trickiest one to get right. This is not
3259 because the authors are evil or incompetent, far from it, it's just that the
3260 CBQ algorithm isn't all that precise and doesn't really match the way Linux
3261 works.
3262 </Para>
3264 <Para>
3265 Besides being classful, CBQ is also a shaper and it is in that aspect that
3266 it really doesn't work very well. It should work like this. If you try to
3267 shape a 10mbit/s connection to 1mbit/s, the link should be idle 90&percnt; of the
3268 time. If it isn't, we need to throttle so that it IS idle 90&percnt; of the time.
3269 </Para>
3271 <Para>
3272 This is pretty hard to measure, so CBQ  instead derives the idle time from
3273 the number of microseconds that elapse between requests from the hardware
3274 layer for more data. Combined, this can be used to approximate how full or
3275 empty the link is.
3276 </Para>
3278 <Para>
3279 This is rather circumspect and doesn't always arrive at proper results. For
3280 example, what if the actual link speed of an interface that is not really
3281 able to transmit the full 100mbit/s of data, perhaps because of a badly
3282 implemented driver? A PCMCIA network card will also never achieve 100mbit/s
3283 because of the way the bus is designed - again, how do we calculate the idle
3284 time?
3285 </Para>
3287 <Para>
3288 It gets even worse if we consider not-quite-real network devices like PPP
3289 over Ethernet or PPTP over TCP/IP. The effective bandwidth in that case is
3290 probably determined by the efficiency of pipes to userspace - which is huge.
3291 </Para>
3293 <Para>
3294 People who have done measurements discover that CBQ is not always very
3295 accurate and sometimes completely misses the mark.
3296 </Para>
3298 <Para>
3299 In many circumstances however it works well. With the documentation provided
3300 here, you should be able to configure it to work well in most cases.
3301 </Para>
3303 <Sect3>
3304 <Title>CBQ shaping in detail</Title>
3306 <Para>
3307 As said before, CBQ works by making sure that the link is idle just long
3308 enough to bring down the real bandwidth to the configured rate. To do so, it
3309 calculates the time that should pass between average packets. 
3310 </Para>
3312 <Para>
3313 During operations, the effective idletime is measured using an exponential
3314 weighted moving average (EWMA), which considers recent packets to be
3315 exponentially more important than past ones. The UNIX loadaverage is
3316 calculated in the same way.
3317 </Para>
3319 <Para>
3320 The calculated idle time is subtracted from the EWMA measured one, the
3321 resulting number is called 'avgidle'. A perfectly loaded link has an avgidle
3322 of zero: packets arrive exactly once every calculated interval.  
3323 </Para>
3325 <Para>
3326 An overloaded link has a negative avgidle and if it gets too negative, CBQ
3327 shuts down for a while and is then 'overlimit'.
3328 </Para>
3330 <Para>
3331 Conversely, an idle link might amass a huge avgidle, which would then allow
3332 infinite bandwidths after a few hours of silence. To prevent this, avgidle is
3333 capped at maxidle.
3334 </Para>
3336 <Para>
3337 If overlimit, in theory, the CBQ could throttle itself for exactly the
3338 amount of time that was calculated to pass between packets, and then pass
3339 one packet, and throttle again. But see the 'minburst' parameter below.
3340 </Para>
3342 <Para>
3343 These are parameters you can specify in order to configure shaping:
3344 <VariableList>
3346 <VarListEntry>
3347 <Term>avpkt</Term>
3348 <ListItem>
3349 <Para>
3350 Average size of a packet, measured in bytes. Needed for calculating maxidle,
3351 which is derived from maxburst, which is specified in packets.
3352 </Para></ListItem>
3353 </VarListEntry>
3354 <VarListEntry>
3355 <Term>bandwidth</Term>
3356 <ListItem>
3357 <Para>
3358 The physical bandwidth of your device, needed for idle time
3359 calculations.
3360 </Para></ListItem>
3361 </VarListEntry>
3362 <VarListEntry>
3363 <Term>cell</Term>
3364 <ListItem>
3365 <Para>
3366 The time a packet takes to be transmitted over a device may grow in steps,
3367 based on the packet size. An 800 and an 806 size packet may take just as long
3368 to send, for example - this sets the granularity. Most often set to '8'.
3369 Must be an integral power of two.
3370 </Para></ListItem>
3371 </VarListEntry>
3372 <VarListEntry>
3373 <Term>maxburst</Term>
3374 <ListItem>
3375 <Para>
3376 This number of packets is used to calculate maxidle so that when avgidle is
3377 at maxidle, this number of average packets can be burst before avgidle drops
3378 to 0. Set it higher to be more tolerant of bursts. You can't set maxidle
3379 directly, only via this parameter.
3380 </Para></ListItem>
3381 </VarListEntry>
3382 <VarListEntry>
3383 <Term>minburst</Term>
3384 <ListItem>
3385 <Para>
3386 As mentioned before, CBQ needs to throttle in case of overlimit. The ideal
3387 solution is to do so for exactly the calculated idle time, and pass 1
3388 packet. However, Unix kernels generally have a hard time scheduling events
3389 shorter than 10ms, so it is better to throttle for a longer period, and then
3390 pass minburst packets in one go, and then sleep minburst times longer.
3391 </Para>
3393 <Para>
3394 The time to wait is called the offtime. Higher values of minburst lead to
3395 more accurate shaping in the long term, but to bigger bursts at millisecond
3396 timescales.
3397 </Para></ListItem>
3398 </VarListEntry>
3399 <VarListEntry>
3400 <Term>minidle</Term>
3401 <ListItem>
3402 <Para>
3403 If avgidle is below 0, we are overlimits and need to wait until avgidle will
3404 be big enough to send one packet. To prevent a sudden burst from shutting
3405 down the link for a prolonged period of time, avgidle is reset to minidle if
3406 it gets too low.
3407 </Para>
3409 <Para>
3410 Minidle is specified in negative microseconds, so 10 means that avgidle is
3411 capped at -10us.
3412 </Para></ListItem>
3413 </VarListEntry>
3414 <VarListEntry>
3415 <Term>mpu</Term>
3416 <ListItem>
3417 <Para>
3418 Minimum packet size - needed because even a zero size packet is padded
3419 to 64 bytes on ethernet, and so takes a certain time to transmit. CBQ needs
3420 to know this to accurately calculate the idle time.
3421 </Para></ListItem>
3422 </VarListEntry>
3423 <VarListEntry>
3424 <Term>rate</Term>
3425 <ListItem>
3426 <Para>
3427 Desired rate of traffic leaving this qdisc - this is the 'speed knob'!
3428 </Para></ListItem>
3429 </VarListEntry>
3430 </VariableList>
3431 </Para>
3433 <Para>
3434 Internally, CBQ has a lot of fine tuning. For example, classes which are
3435 known not to have data enqueued to them aren't queried. Overlimit classes
3436 are penalized by lowering their effective priority. All very smart &amp;
3437 complicated.
3438 </Para>
3440 </Sect3>
3442 <Sect3>
3443 <Title>CBQ classful behaviour</Title>
3445 <Para>
3446 Besides shaping, using the aforementioned idletime approximations, CBQ also
3447 acts like the PRIO queue in the sense that classes can have differing
3448 priorities and that lower priority numbers will be polled before the higher
3449 priority ones.
3450 </Para>
3452 <Para>
3453 Each time a packet is requested by the hardware layer to be sent out to the
3454 network, a weighted round robin process ('WRR') starts, beginning with the
3455 lower priority classes.
3456 </Para>
3458 <Para>
3459 These are then grouped and queried if they have data available. If so, it is
3460 returned. After a class has been allowed to dequeue a number of bytes, the
3461 next class within that priority is tried.
3462 </Para>
3464 <Para>
3465 The following parameters control the WRR process:
3466 <VariableList>
3468 <VarListEntry>
3469 <Term>allot</Term>
3470 <ListItem>
3471 <Para>
3472 When the outer CBQ is asked for a packet to send out on the interface, it
3473 will try all inner qdiscs (in the classes) in turn, in order of 
3474 the 'priority' parameter. Each time a class gets its turn, it can only send out
3475 a limited amount of data. 'Allot' is the base unit of this amount. See 
3476 the 'weight' parameter for more information.
3477 </Para></ListItem>
3478 </VarListEntry>
3479 <VarListEntry>
3480 <Term>prio</Term>
3481 <ListItem>
3482 <Para>
3483 The CBQ can also act like the PRIO device. Inner classes with lower priority
3484 are tried first and as long as they have traffic, other classes are not
3485 polled for traffic.
3486 </Para></ListItem>
3487 </VarListEntry>
3488 <VarListEntry>
3489 <Term>weight</Term>
3490 <ListItem>
3491 <Para>
3492 Weight helps in the Weighted Round Robin process. Each class gets a chance
3493 to send in turn. If you have classes with significantly more bandwidth than
3494 other classes, it makes sense to allow them to send more data in one round
3495 than the others.
3496 </Para>
3498 <Para>
3499 A CBQ adds up all weights under a class, and normalizes them, so you can use
3500 arbitrary numbers: only the ratios are important. People have been 
3501 using 'rate/10' as a rule of thumb and it appears to work well. The renormalized
3502 weight is multiplied by the 'allot' parameter to determine how much data can
3503 be sent in one round. 
3504 </Para></ListItem>
3505 </VarListEntry>
3506 </VariableList>
3507 </Para>
3509 <Para>
3510 Please note that all classes within an CBQ hierarchy need to share the same
3511 major number!
3512 </Para>
3514 </Sect3>
3516 <Sect3>
3517 <Title>CBQ parameters that determine link sharing &amp; borrowing</Title>
3519 <Para>
3520 Besides purely limiting certain kinds of traffic, it is also possible to
3521 specify which classes can borrow capacity from other classes or, conversely,
3522 lend out bandwidth.
3523 </Para>
3525 <Para>
3526 <VariableList>
3528 <VarListEntry>
3529 <Term>Isolated/sharing</Term>
3530 <ListItem>
3531 <Para>
3532 A class that is configured with 'isolated' will not lend out bandwidth to
3533 sibling classes. Use this if you have competing or mutually-unfriendly
3534 agencies on your link who do want to give each other freebies.
3535 </Para>
3537 <Para>
3538 The control program tc also knows about 'sharing', which is the reverse 
3539 of 'isolated'.
3540 </Para></ListItem>
3541 </VarListEntry>
3542 <VarListEntry>
3543 <Term>bounded/borrow</Term>
3544 <ListItem>
3545 <Para>
3546 A class can also be 'bounded', which means that it will not try to borrow
3547 bandwidth from sibling classes. tc also knows about 'borrow', which is the
3548 reverse of 'bounded'.
3549 </Para></ListItem>
3550 </VarListEntry>
3551 </VariableList>
3552 A typical situation might be where you have two agencies on your link which
3553 are both 'isolated' and 'bounded', which means that they are really limited
3554 to their assigned rate, and also won't allow each other to borrow.
3555 </Para>
3557 <Para>
3558 Within such an agency class, there might be other classes which are allowed
3559 to swap bandwidth.
3560 </Para>
3562 </Sect3>
3564 <Sect3>
3565 <Title>Sample configuration</Title>
3567 <Para>
3568 This configuration limits webserver traffic to 5mbit and SMTP traffic to 3
3569 mbit. Together, they may not get more than 6mbit. We have a 100mbit NIC and
3570 the classes may borrow bandwidth from each other.
3572 <Screen>
3573 # tc qdisc add dev eth0 root handle 1:0 cbq bandwidth 100Mbit         \
3574   avpkt 1000 cell 8
3575 # tc class add dev eth0 parent 1:0 classid 1:1 cbq bandwidth 100Mbit  \
3576   rate 6Mbit weight 0.6Mbit prio 8 allot 1514 cell 8 maxburst 20      \
3577   avpkt 1000 bounded
3578 </Screen>
3580 This part installs the root and the customary 1:0 class. The 1:1 class is
3581 bounded, so the total bandwidth can't exceed 6mbit.
3582 </Para>
3584 <Para>
3585 As said before, CBQ requires a *lot* of knobs. All parameters are explained
3586 above, however. The corresponding HTB configuration is lots simpler.
3587 </Para>
3589 <Para>
3591 <Screen>
3592 # tc class add dev eth0 parent 1:1 classid 1:3 cbq bandwidth 100Mbit  \
3593   rate 5Mbit weight 0.5Mbit prio 5 allot 1514 cell 8 maxburst 20      \
3594   avpkt 1000                       
3595 # tc class add dev eth0 parent 1:1 classid 1:4 cbq bandwidth 100Mbit  \
3596   rate 3Mbit weight 0.3Mbit prio 5 allot 1514 cell 8 maxburst 20      \
3597   avpkt 1000
3598 </Screen>
3600 </Para>
3602 <Para>
3603 These are our two classes. Note how we scale the weight with the configured
3604 rate. Both classes are not bounded, but they are connected to class 1:1
3605 which is bounded.  So the sum of bandwith of the 2 classes will never be
3606 more than 6mbit. The classids need to be within the same major number as
3607 the parent CBQ, by the way!
3608 </Para>
3610 <Para>
3612 <Screen>
3613 # tc qdisc add dev eth0 parent 1:3 handle 30: sfq
3614 # tc qdisc add dev eth0 parent 1:4 handle 40: sfq
3615 </Screen>
3617 </Para>
3619 <Para>
3620 Both classes have a FIFO qdisc by default.  But we replaced these with an SFQ
3621 queue so each flow of data is treated equally.
3623 <Screen>
3624 # tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip \
3625   sport 80 0xffff flowid 1:3
3626 # tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip \
3627   sport 25 0xffff flowid 1:4
3628 </Screen>
3630 </Para>
3632 <Para>
3633 These commands, attached directly to the root, send traffic to the right
3634 qdiscs.
3635 </Para>
3637 <Para>
3638 Note that we use 'tc class add' to CREATE classes within a qdisc, but that
3639 we use 'tc qdisc add' to actually add qdiscs to these classes.
3640 </Para>
3642 <Para>
3643 You may wonder what happens to traffic that is not classified by any of the
3644 two rules. It appears that in this case, data will then be processed within
3645 1:0, and be unlimited. 
3646 </Para>
3648 <Para>
3649 If SMTP+web together try to exceed the set limit of 6mbit/s, bandwidth will
3650 be divided according to the weight parameter, giving 5/8 of traffic to  the
3651 webserver and 3/8 to the mail server.
3652 </Para>
3654 <Para>
3655 With this configuration you can also say that webserver traffic will always
3656 get at minimum 5/8 * 6 mbit = 3.75 mbit.
3657 </Para>
3659 </Sect3>
3661 <Sect3>
3662 <Title>Other CBQ parameters: split &amp; defmap</Title>
3664 <Para>
3665 As said before, a classful qdisc needs to call filters to determine
3666 which class a packet will be enqueued to. 
3667 </Para>
3669 <Para>
3670 Besides calling the filter, CBQ offers other options, defmap &amp; split.
3671 This is pretty complicated to understand, and it is not vital. But as this
3672 is the only known place where defmap &amp; split are properly explained, I'm
3673 doing my best. 
3674 </Para>
3676 <Para>
3677 As you will often want to filter on the Type of Service field only, a special
3678 syntax is provided. Whenever the CBQ needs to figure out where a packet
3679 needs to be enqueued, it checks if this node is a 'split node'. If so, one
3680 of the sub-qdiscs has indicated that it wishes to receive all packets with
3681 a certain configured priority, as might be derived from the TOS field, or
3682 socket options set by applications.
3683 </Para>
3685 <Para>
3686 The packets' priority bits are or-ed with the defmap field to see if a match
3687 exists. In other words, this is a short-hand way of creating a very fast
3688 filter, which only matches certain priorities. A defmap of ff (hex) will
3689 match everything, a map of 0 nothing. A sample configuration may help make
3690 things clearer:
3691 </Para>
3693 <Para>
3695 <Screen>
3696 # tc qdisc add dev eth1 root handle 1: cbq bandwidth 10Mbit allot 1514 \
3697   cell 8 avpkt 1000 mpu 64
3699 # tc class add dev eth1 parent 1:0 classid 1:1 cbq bandwidth 10Mbit    \
3700   rate 10Mbit allot 1514 cell 8 weight 1Mbit prio 8 maxburst 20        \
3701   avpkt 1000
3702 </Screen>
3704 Standard CBQ preamble. I never get used to the sheer amount of numbers
3705 required!
3706 </Para>
3708 <Para>
3709 Defmap refers to TC_PRIO bits, which are defined as follows:
3710 </Para>
3712 <Para>
3714 <Screen>
3715 TC_PRIO..          Num  Corresponds to TOS
3716 -------------------------------------------------
3717 BESTEFFORT         0    Maximize Reliablity        
3718 FILLER             1    Minimize Cost              
3719 BULK               2    Maximize Throughput (0x8)  
3720 INTERACTIVE_BULK   4                               
3721 INTERACTIVE        6    Minimize Delay (0x10)      
3722 CONTROL            7                               
3723 </Screen>
3725 </Para>
3727 <Para>
3728 The TC_PRIO.. number corresponds to bits, counted from the right. See the
3729 pfifo_fast section for more details how TOS bits are converted to
3730 priorities.
3731 </Para>
3733 <Para>
3734 Now the interactive and the bulk classes:
3735 </Para>
3737 <Para>
3739 <Screen>
3740 # tc class add dev eth1 parent 1:1 classid 1:2 cbq bandwidth 10Mbit     \
3741   rate 1Mbit allot 1514 cell 8 weight 100Kbit prio 3 maxburst 20        \
3742   avpkt 1000 split 1:0 defmap c0
3744 # tc class add dev eth1 parent 1:1 classid 1:3 cbq bandwidth 10Mbit     \
3745   rate 8Mbit allot 1514 cell 8 weight 800Kbit prio 7 maxburst 20        \
3746   avpkt 1000 split 1:0 defmap 3f
3747 </Screen>
3749 </Para>
3751 <Para>
3752 The 'split qdisc' is 1:0, which is where the choice will be made. C0 is
3753 binary for 11000000, 3F for 00111111, so these two together will match
3754 everything. The first class matches bits 7 &#38; 6, and thus corresponds 
3755 to 'interactive' and 'control' traffic. The second class matches the rest.
3756 </Para>
3758 <Para>
3759 Node 1:0 now has a table like this:
3761 <Screen>
3762 priority        send to
3763 0               1:3
3764 1               1:3
3765 2               1:3
3766 3               1:3
3767 4               1:3
3768 5               1:3
3769 6               1:2
3770 7               1:2
3771 </Screen>
3773 </Para>
3775 <Para>
3776 For additional fun, you can also pass a 'change mask', which indicates
3777 exactly which priorities you wish to change. You only need to use this if you
3778 are running 'tc class change'. For example, to add best effort traffic to
3779 1:2, we could run this:
3780 </Para>
3782 <Para>
3784 <Screen>
3785 # tc class change dev eth1 classid 1:2 cbq defmap 01/01
3786 </Screen>
3788 </Para>
3790 <Para>
3791 The priority map over at 1:0 now looks like this:
3792 </Para>
3794 <Para>
3796 <Screen>
3797 priority        send to
3798 0               1:2
3799 1               1:3
3800 2               1:3
3801 3               1:3
3802 4               1:3
3803 5               1:3
3804 6               1:2
3805 7               1:2
3806 </Screen>
3808 </Para>
3810 <Para>
3811 FIXME: did not test 'tc class change', only looked at the source.
3812 </Para>
3814 </Sect3>
3816 </Sect2>
3818 <Sect2>
3819 <Title>Hierarchical Token Bucket </Title>
3821 <Para>
3822 Martin Devera (&lt;devik&gt;) rightly realised that CBQ is complex and does
3823 not seem optimized for many typical situations. His Hierarchical approach is
3824 well suited for setups where you have a fixed amount of bandwidth which you
3825 want to divide for different purposes, giving each purpose a guaranteed
3826 bandwidth, with the possibility of specifying how much bandwidth can be
3827 borrowed.
3828 </Para>
3830 <Para>
3831 HTB works just like CBQ but does not resort to idle time calculations to
3832 shape. Instead, it is a classful Token Bucket Filter - hence the name. It
3833 has only a few parameters, which are well documented on his 
3834 <ULink
3835 URL="http://luxik.cdi.cz/~devik/qos/htb/"
3836 >site</ULink
3838 </Para>
3840 <Para>
3841 As your HTB configuration gets more complex, your configuration scales
3842 well. With CBQ it is already complex even in simple cases! HTB3 (check
3843 <ulink url="http://luxik.cdi.cz/~devik/qos/htb/">its homepage</ulink> for
3844 details on HTB versions) is now part of the official kernel sources 
3845 (from 2.4.20-pre1 and 2.5.31 onwards). However, maybe you still need to
3846 get a HTB3 patched version of 'tc': HTB kernel and userspace parts must
3847 be the same major version, or 'tc' will not work with HTB.
3849 </Para>
3851 <Para>
3852 If you already have a modern kernel, or are in a position to patch your 
3853 kernel, by all means consider HTB.
3854 </para>
3857 <Sect3>
3858 <Title>Sample configuration</Title>
3860 <Para>
3861 Functionally almost identical to the CBQ sample configuration above:
3862 </Para>
3864 <Para>
3866 <Screen>
3867 # tc qdisc add dev eth0 root handle 1: htb default 30
3869 # tc class add dev eth0 parent 1: classid 1:1 htb rate 6mbit burst 15k
3871 # tc class add dev eth0 parent 1:1 classid 1:10 htb rate 5mbit burst 15k
3872 # tc class add dev eth0 parent 1:1 classid 1:20 htb rate 3mbit ceil 6mbit burst 15k
3873 # tc class add dev eth0 parent 1:1 classid 1:30 htb rate 1kbit ceil 6mbit burst 15k
3874 </Screen>
3876 </Para>
3878 <Para>
3879 The author then recommends SFQ for beneath these classes:
3881 <Screen>
3882 # tc qdisc add dev eth0 parent 1:10 handle 10: sfq perturb 10
3883 # tc qdisc add dev eth0 parent 1:20 handle 20: sfq perturb 10
3884 # tc qdisc add dev eth0 parent 1:30 handle 30: sfq perturb 10
3885 </Screen>
3887 </Para>
3889 <Para>
3890 Add the filters which direct traffic to the right classes:
3892 <Screen>
3893 # U32="tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32"
3894 # $U32 match ip dport 80 0xffff flowid 1:10
3895 # $U32 match ip sport 25 0xffff flowid 1:20
3896 </Screen>
3898 And that's it - no unsightly unexplained numbers, no undocumented
3899 parameters. 
3900 </Para>
3902 <Para>
3903 HTB certainly looks wonderful - if 10: and 20: both have their guaranteed
3904 bandwidth, and more is left to divide, they borrow in a 5:3 ratio, just as
3905 you would expect.
3906 </Para>
3908 <Para>
3909 Unclassified traffic gets routed to 30:, which has little bandwidth of its
3910 own but can borrow everything that is left over. Because we chose SFQ
3911 internally, we get fairness thrown in for free!
3912 </Para>
3914 </Sect3>
3916 </Sect2>
3918 </Sect1>
3920 <Sect1 id="lartc.qdisc.filters">
3921   <Title>Classifying packets with filters</Title>
3923 <Para>
3924 To determine which class shall process a packet, the so-called 'classifier
3925 chain' is called each time a choice needs to be made. This chain consists of
3926 all filters attached to the classful qdisc that needs to decide.
3927 </Para>
3929 <Para>To reiterate the tree, which is not a tree:
3930 </Para>
3932 <Screen width="80">
3933                     root 1:
3934                       |
3935                     _1:1_
3936                    /  |  \
3937                   /   |   \
3938                  /    |    \
3939                10:   11:   12:
3940               /   \       /   \
3941            10:1  10:2   12:1  12:2
3942 </Screen>
3944 <Para>
3945 When enqueueing a packet, at each branch the filter chain is consulted for a
3946 relevant instruction. A typical setup might be to have a filter in 1:1 that
3947 directs a packet to 12: and a filter on 12: that sends the packet to 12:2.
3948 </Para>
3950 <Para>
3951 You might also attach this latter rule to 1:1, but you can make efficiency
3952 gains by having more specific tests lower in the chain.
3953 </Para>
3955 <Para>
3956 You can't filter a packet 'upwards', by the way. Also, with HTB, you should
3957 attach all filters to the root!
3958 </Para>
3960 <Para>
3961 And again - packets are only enqueued downwards! When they are dequeued,
3962 they go up again, where the interface lives. They do NOT fall off the end of
3963 the tree to the network adaptor!
3964 </Para>
3966 <Sect2>
3967 <Title>Some simple filtering examples</Title>
3969 <Para>
3970 As explained in the Classifier chapter, you can match on literally anything,
3971 using a very complicated syntax. To start, we will show how to do the
3972 obvious things, which luckily are quite easy.
3973 </Para>
3975 <Para>
3976 Let's say we have a PRIO qdisc called '10:' which contains three classes, and
3977 we want to assign all traffic from and to port 22 to the highest priority
3978 band, the filters would be:
3979 </Para>
3981 <Para>
3983 <Screen>
3984 # tc filter add dev eth0 protocol ip parent 10: prio 1 u32 match \ 
3985   ip dport 22 0xffff flowid 10:1
3986 # tc filter add dev eth0 protocol ip parent 10: prio 1 u32 match \
3987   ip sport 80 0xffff flowid 10:1
3988 # tc filter add dev eth0 protocol ip parent 10: prio 2 flowid 10:2
3989 </Screen>
3991 </Para>
3993 <Para>
3994 What does this say? It says: attach to eth0, node 10: a  priority 1 u32
3995 filter that matches on IP destination port 22 *exactly* and send it to band
3996 10:1. And it then repeats the same for source port 80. The last command says
3997 that anything unmatched so far should go to band 10:2, the next-highest
3998 priority.
3999 </Para>
4001 <Para>
4002 You need to add 'eth0', or whatever your interface is called, because each
4003 interface has a unique namespace of handles.
4004 </Para>
4006 <Para>
4007 To select on an IP address, use this:
4009 <Screen>
4010 # tc filter add dev eth0 parent 10:0 protocol ip prio 1 u32 \ 
4011   match ip dst 4.3.2.1/32 flowid 10:1
4012 # tc filter add dev eth0 parent 10:0 protocol ip prio 1 u32 \
4013   match ip src 1.2.3.4/32 flowid 10:1
4014 # tc filter add dev eth0 protocol ip parent 10: prio 2      \
4015   flowid 10:2
4016 </Screen>
4018 </Para>
4020 <Para>
4021 This assigns traffic to 4.3.2.1 and traffic from 1.2.3.4 to the highest
4022 priority queue, and the rest to the next-highest one.
4023 </Para>
4025 <Para>
4026 You can concatenate matches, to match on traffic from 1.2.3.4 and from port
4027 80, do this:
4029 <Screen>
4030 # tc filter add dev eth0 parent 10:0 protocol ip prio 1 u32 match ip src 4.3.2.1/32
4031   match ip sport 80 0xffff flowid 10:1
4032 </Screen>
4034 </Para>
4036 </Sect2>
4038 <Sect2 id="lartc.filtering.simple">
4039 <Title>All the filtering commands you will normally need</Title>
4041 <Para>
4042 Most shaping commands presented here start with this preamble:
4044 <Screen>
4045 # tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 ..
4046 </Screen>
4048 These are the so called 'u32' matches, which can match on ANY part of a
4049 packet.
4050 <VariableList>
4052 <VarListEntry>
4053 <Term>On source/destination address</Term>
4054 <ListItem>
4055 <Para>
4056 Source mask 'match ip src 1.2.3.0/24', destination mask 'match ip dst
4057 4.3.2.0/24'. To match a single host, use /32, or omit the mask.
4058 </Para></ListItem>
4059 </VarListEntry>
4060 <VarListEntry>
4061 <Term>On source/destination port, all IP protocols</Term>
4062 <ListItem>
4063 <Para>
4064 Source: 'match ip sport 80 0xffff', 'match ip dport 0xffff'
4065 </Para></ListItem>
4066 </VarListEntry>
4067 <VarListEntry>
4068 <Term>On ip protocol (tcp, udp, icmp, gre, ipsec)</Term>
4069 <ListItem>
4070 <Para>
4071 Use the numbers from /etc/protocols, for example, icmp is 1: 'match ip
4072 protocol 1 0xff'. 
4073 </Para></ListItem>
4074 </VarListEntry>
4075 <VarListEntry>
4076 <Term>On fwmark</Term>
4077 <ListItem>
4078 <Para>
4079 You can mark packets with either ipchains and have that mark survive routing
4080 across interfaces. This is really useful to for example only shape traffic on
4081 eth1 that came in on eth0. Syntax: 
4082 &num; tc filter add dev eth1 protocol ip parent 1:0 prio 1 handle 6 fw flowid 1:1
4083 Note that this is not a u32 match!
4084 </Para>
4086 <Para>
4087 You can place a mark like this:
4089 <Screen>
4090 # iptables -A PREROUTING -t mangle -i eth0 -j MARK --set-mark 6
4091 </Screen>
4093 The number 6 is arbitrary.
4094 </Para>
4096 <Para>
4097 If you don't want to understand the full tc filter syntax, just use
4098 iptables, and only learn to select on fwmark.
4099 </Para></ListItem>
4100 </VarListEntry>
4101 <VarListEntry>
4102 <Term>On the TOS field</Term>
4103 <ListItem>
4104 <Para>
4105 To select interactive, minimum delay traffic:
4107 <Screen>
4108 # tc filter add dev ppp0 parent 1:0 protocol ip prio 10 u32 \
4109       match ip tos 0x10 0xff \
4110      flowid 1:4
4111 </Screen>
4113 Use 0x08 0xff for bulk traffic.
4114 </Para></ListItem>
4115 </VarListEntry>
4116 </VariableList>
4117 </Para>
4119 <Para>
4120 For more filtering commands, see the Advanced Filters chapter.
4121 </Para>
4123 </Sect2>
4125 </Sect1>
4126 <Sect1 id="lartc.imq">
4127 <Title>The Intermediate queueing device (IMQ)</Title>
4129 <Para>
4130 The Intermediate queueing device is not a qdisc but its usage is tightly bound
4131 to qdiscs. Within linux, qdiscs are attached to network devices and everything
4132 that is queued to the device is first queued to the qdisc. From this concept,
4133 two limitations arise:
4134 </Para>
4136 <Para>
4137 1. Only egress shaping is possible (an ingress qdisc exists, but its
4138 possibilities are very limited compared to classful qdiscs).
4139 </Para>
4141 <Para>
4142 2. A qdisc can only see traffic of one interface, global limitations can't be
4143 placed.
4144 </Para>
4146 <Para>
4147 IMQ is there to help solve those two limitations. In short, you can put 
4148 everything you choose in a qdisc. Specially marked packets get intercepted
4149 in netfilter NF_IP_PRE_ROUTING and NF_IP_POST_ROUTING hooks and pass through
4150 the qdisc attached to an imq device. An iptables target is used for marking
4151 the packets.
4152 </Para>
4154 <Para>
4155 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.
4156 You can also do lots of other stuff like just putting your http traffic in a
4157 qdisc, put new connection requests in a qdisc, ...
4158 </Para>
4160 <Sect2>
4161 <Title>Sample configuration</Title>
4163 <Para>
4164 The first thing that might come to mind is use ingress shaping to give yourself
4165 a high guaranteed bandwidth. ;)
4166 Configuration is just like with any other interface:
4168 <Screen>
4169 tc qdisc add dev imq0 root handle 1: htb default 20
4171 tc class add dev imq0 parent 1: classid 1:1 htb rate 2mbit burst 15k
4173 tc class add dev imq0 parent 1:1 classid 1:10 htb rate 1mbit
4174 tc class add dev imq0 parent 1:1 classid 1:20 htb rate 1mbit
4176 tc qdisc add dev imq0 parent 1:10 handle 10: pfifo
4177 tc qdisc add dev imq0 parent 1:20 handle 20: sfq
4179 tc filter add dev imq0 parent 10:0 protocol ip prio 1 u32 match \
4180                 ip dst 10.0.0.230/32 flowid 1:10
4181 </Screen>
4183 In this example u32 is used for classification. Other classifiers should work as
4184 expected.
4185 Next traffic has to be selected and marked to be enqueued to imq0.
4187 <Screen>
4188 iptables -t mangle -A PREROUTING -i eth0 -j IMQ --todev 0
4190 ip link set imq0 up
4191 </Screen>
4193 </Para>
4195 <Para>
4196 The IMQ iptables targets is valid in the PREROUTING and POSTROUTING chains of
4197 the mangle table. It's syntax is 
4199 <Screen>
4200 IMQ [ --todev n ]       n : number of imq device
4201 </Screen>
4203 An ip6tables target is also provided.
4204 </Para>
4206 <Para>
4207 Please note traffic is not enqueued when the target is hit but afterwards.
4208 The exact location where traffic enters the imq device depends on the
4209 direction of the traffic (in/out).
4210 These are the predefined netfilter hooks used by iptables:
4212 <Screen>
4213 enum nf_ip_hook_priorities {
4214         NF_IP_PRI_FIRST = INT_MIN,
4215         NF_IP_PRI_CONNTRACK = -200,
4216         NF_IP_PRI_MANGLE = -150,
4217         NF_IP_PRI_NAT_DST = -100,
4218         NF_IP_PRI_FILTER = 0,
4219         NF_IP_PRI_NAT_SRC = 100,
4220         NF_IP_PRI_LAST = INT_MAX,
4222 </Screen>
4224 </Para>
4226 <Para>
4227 For ingress traffic, imq registers itself with NF_IP_PRI_MANGLE + 1 priority
4228 which means packets enter the imq device directly after the mangle PREROUTING
4229 chain has been passed.
4230 </Para>
4232 <Para>
4233 For egress imq uses NF_IP_PRI_LAST which honours the fact that packets dropped
4234 by the filter table won't occupy bandwidth.
4235 </Para>
4237 <Para>
4238 The patches and some more information can be found at the
4239 <ULink
4240 URL="http://luxik.cdi.cz/~patrick/imq/"
4241 >imq site</ULink>.
4242 </Para>
4244 </Sect2>
4246 </Sect1>
4248 </chapter>
4250 <chapter id="lartc.loadshare">
4251 <Title>Load sharing over multiple interfaces</Title>
4253 <Para>
4254 There are several ways of doing this. One of the easiest and straightforward
4255 ways is 'TEQL' - "True" (or "trivial") link equalizer. Like most things
4256 having to do with queueing, load sharing goes both ways. Both ends of a link
4257 may need to participate for full effect.
4258 </Para>
4260 <Para>
4261 Imagine this situation:
4262 </Para>
4264 <Para>
4266 <Screen>
4267                  +-------+   eth1   +-------+
4268                  |       |==========|       |
4269  'network 1' ----|   A   |          |   B   |---- 'network 2'
4270                  |       |==========|       |
4271                  +-------+   eth2   +-------+
4272 </Screen>
4274 </Para>
4276 <Para>
4277 A and B are routers, and for the moment we'll assume both run Linux. If
4278 traffic is going from network 1 to network 2, router A needs to distribute
4279 the packets over both links to B. Router B needs to be configured to accept
4280 this. Same goes the other way around, when packets go from network 2 to
4281 network 1, router B needs to send the packets over both eth1 and eth2.
4282 </Para>
4284 <Para>
4285 The distributing part is done by a 'TEQL' device, like this (it couldn't be
4286 easier):
4287 </Para>
4289 <Para>
4291 <Screen>
4292 # tc qdisc add dev eth1 root teql0
4293 # tc qdisc add dev eth2 root teql0
4294 # ip link set dev teql0 up
4295 </Screen>
4297 </Para>
4299 <Para>
4300 Don't forget the 'ip link set up' command!
4301 </Para>
4303 <Para>
4304 This needs to be done on both hosts. The device teql0 is basically a
4305 roundrobbin distributor over eth1 and eth2, for sending packets. No data
4306 ever comes in over an teql device, that just appears on the 'raw' eth1 and
4307 eth2.
4308 </Para>
4310 <Para>
4311 But now we just have devices, we also need proper routing. One way to do
4312 this is to assign a /31 network to both links, and a /31 to the teql0 device
4313 as well:
4314 </Para>
4316 <Para>
4317 FIXME: does this need something like 'nobroadcast'? A /31 is too small to
4318 house a network address and a broadcast address - if this doesn't work as
4319 planned, try a /30, and adjust the ip addresses accordingly. You might even
4320 try to make eth1 and eth2 do without an IP address!
4321 </Para>
4323 <Para>
4324 On router A:
4326 <Screen>
4327 # ip addr add dev eth1 10.0.0.0/31
4328 # ip addr add dev eth2 10.0.0.2/31
4329 # ip addr add dev teql0 10.0.0.4/31
4330 </Screen>
4332 </Para>
4334 <Para>
4335 On router B:
4337 <Screen>
4338 # ip addr add dev eth1 10.0.0.1/31
4339 # ip addr add dev eth2 10.0.0.3/31
4340 # ip addr add dev teql0 10.0.0.5/31
4341 </Screen>
4343 </Para>
4345 <Para>
4346 Router A should now be able to ping 10.0.0.1, 10.0.0.3 and 10.0.0.5 over the
4347 2 real links and the 1 equalized device. Router B should be able to ping
4348 10.0.0.0, 10.0.0.2 and 10.0.0.4 over the links.
4349 </Para>
4351 <Para>
4352 If this works, Router A should make 10.0.0.5 its route for reaching network
4353 2, and Router B should make 10.0.0.4 its route for reaching network 1. For
4354 the special case where network 1 is your network at home, and network 2 is
4355 the Internet, Router A should make 10.0.0.5 its default gateway.
4356 </Para>
4358 <Sect1 id="lartc.loadshare.caveats">
4359   <Title>Caveats</Title>
4361 <Para>
4362 Nothing is as easy as it seems. eth1 and eth2 on both router A and B need to
4363 have return path filtering turned off, because they will otherwise drop
4364 packets destined for ip addresses other than their own:
4365 </Para>
4367 <Para>
4369 <Screen>
4370 # echo 0 &#62; /proc/net/ipv4/conf/eth1/rp_filter
4371 # echo 0 &#62; /proc/net/ipv4/conf/eth2/rp_filter
4372 </Screen>
4374 </Para>
4376 <Para>
4377 Then there is the nasty problem of packet reordering. Let's say 6 packets
4378 need to be sent from A to B - eth1 might get 1, 3 and 5. eth2 would then do
4379 2, 4 and 6. In an ideal world, router B would receive this in order, 1, 2,
4380 3, 4, 5, 6. But the possibility is very real that the kernel gets it like
4381 this: 2, 1, 4, 3, 6, 5. The problem is that this confuses TCP/IP. While not
4382 a problem for links carrying many different TCP/IP sessions, you won't be
4383 able to to a bundle multiple links and get to ftp a single file lots faster,
4384 except when your receiving or sending OS is Linux, which is not easily
4385 shaken by some simple reordering.
4386 </Para>
4388 <Para>
4389 However, for lots of applications, link load balancing is a great idea.
4390 </Para>
4392 </Sect1>
4393 <Sect1 id="lartc.loadshare.other">
4394   <Title>Other possibilities</Title>
4395 <para>
4396 William Stearns has used an advanced tunneling setup to achieve good use of
4397 multiple, unrelated, internet connections together. It can be found on
4398 <ULink
4399 URL="http://www.stearns.org/tunnel/">his tunneling page</ULink>.
4400 </para>
4401 <para>
4402 The HOWTO may feature more about this in the future.
4403 </para>
4404 </Sect1>
4405 </chapter>
4407 <chapter id="lartc.netfilter">
4408 <Title>Netfilter &amp; iproute - marking packets</Title>
4410 <Para>
4411 So far we've seen how iproute works, and netfilter was mentioned a few
4412 times. This would be a good time to browse through <ULink
4413 URL="http://netfilter.samba.org/unreliable-guides/"
4414 >Rusty's Remarkably Unreliable Guides</ULink
4415 >. Netfilter itself
4416 can be found <ULink
4417 URL="http://netfilter.filewatcher.org/"
4418 >here</ULink
4420 </Para>
4422 <Para>
4423 Netfilter allows us to filter packets, or mangle their headers. One special
4424 feature is that we can mark a packet with a number. This is done with the
4425 --set-mark facility. 
4426 </Para>
4428 <Para>
4429 As an example, this command marks all packets destined for port 25, outgoing
4430 mail:
4431 </Para>
4433 <Para>
4435 <Screen>
4436 # iptables -A PREROUTING -i eth0 -t mangle -p tcp --dport 25 \
4437  -j MARK --set-mark 1
4438 </Screen>
4440 </Para>
4442 <Para>
4443 Let's say that we have multiple connections, one that is fast (and
4444 expensive, per megabyte) and one that is slower, but flat fee. We would most
4445 certainly like outgoing mail to go via the cheap route.
4446 </Para>
4448 <Para>
4449 We've already marked the packets with a '1', we now instruct the routing
4450 policy database to act on this:
4451 </Para>
4453 <Para>
4455 <Screen>
4456 # echo 201 mail.out &#62;&#62; /etc/iproute2/rt_tables
4457 # ip rule add fwmark 1 table mail.out
4458 # ip rule ls
4459 0:      from all lookup local 
4460 32764:  from all fwmark        1 lookup mail.out 
4461 32766:  from all lookup main 
4462 32767:  from all lookup default 
4463 </Screen>
4465 </Para>
4467 <Para>
4468 Now we generate the mail.out table with a route to the slow but cheap link:
4470 <Screen>
4471 # /sbin/ip route add default via 195.96.98.253 dev ppp0 table mail.out
4472 </Screen>
4474 </Para>
4476 <Para>
4477 And we are done. Should we want to make exceptions, there are lots of ways
4478 to achieve this. We can modify the netfilter statement to exclude certain
4479 hosts, or we can insert a rule with a lower priority that points to the main
4480 table for our excepted hosts.
4481 </Para>
4483 <Para>
4484 We can also use this feature to honour TOS bits by marking packets with a
4485 different type of service with different numbers, and creating rules to act
4486 on that. This way you can even dedicate, say, an ISDN line to interactive
4487 sessions.
4488 </Para>
4490 <Para>
4491 Needless to say, this also works fine on a host that's doing NAT
4492 ('masquerading').
4493 </Para>
4495 <Para>
4496 IMPORTANT: We received a report that MASQ and SNAT at least collide
4497 with marking packets. Rusty Russell explains it in
4498 <ULink
4499 URL="http://lists.samba.org/pipermail/netfilter/2000-November/006089.html"
4500 >this posting</ULink
4501 >. Turn off the reverse path filter to make it work
4502 properly.
4503 </Para>
4505 <Para>
4506 Note: to mark packets, you need to have some options enabled in your
4507 kernel:
4508 </Para>
4510 <Para>
4512 <Screen>
4513 IP: advanced router (CONFIG_IP_ADVANCED_ROUTER) [Y/n/?]
4514 IP: policy routing (CONFIG_IP_MULTIPLE_TABLES) [Y/n/?]
4515 IP: use netfilter MARK value as routing key (CONFIG_IP_ROUTE_FWMARK) [Y/n/?]
4516 </Screen>
4518 </Para>
4520 <Para>
4521 See also the <xref linkend="lartc.cookbook.squid"> in the
4522 <citetitle><xref linkend="lartc.cookbook"></citetitle>.
4523 </Para>
4525 </chapter>
4527 <chapter id="lartc.adv-filter"
4528   xreflabel="Advanced filters for (re-)classifying packets">
4529   <Title>Advanced filters for (re-)classifying packets</Title>
4531 <Para>
4532 As explained in the section on classful queueing disciplines, filters are
4533 needed to classify packets into any of the sub-queues. These filters are
4534 called from within the classful qdisc.
4535 </Para>
4537 <Para>
4538 Here is an incomplete list of classifiers available:
4539 <VariableList>
4541 <VarListEntry>
4542 <Term>fw</Term>
4543 <ListItem>
4544 <Para>
4545 Bases the decision on how the firewall has marked the packet. This can be
4546 the easy way out if you don't want to learn tc filter syntax. See the
4547 Queueing chapter for details.
4548 </Para></ListItem>
4549 </VarListEntry>
4550 <VarListEntry>
4551 <Term>u32</Term>
4552 <ListItem>
4553 <Para>
4554 Bases the decision on fields within the packet (i.e. source IP address, etc)
4555 </Para></ListItem>
4556 </VarListEntry>
4557 <VarListEntry>
4558 <Term>route</Term>
4559 <ListItem>
4560 <Para>
4561 Bases the decision on which route the packet will be routed by
4562 </Para></ListItem>
4563 </VarListEntry>
4564 <VarListEntry>
4565 <Term>rsvp, rsvp6</Term>
4566 <ListItem>
4567 <Para>
4568 Routes packets based on <ULink
4569 URL="http://www.isi.edu/div7/rsvp/overview.html"
4570 >RSVP </ULink
4571 >. Only useful
4572 on networks you control - the Internet does not respect RSVP.
4573 </Para></ListItem>
4574 </VarListEntry>
4575 <VarListEntry>
4576 <Term>tcindex</Term>
4577 <ListItem>
4578 <Para>
4579 Used in the DSMARK qdisc, see the relevant section.
4580 </Para></ListItem>
4581 </VarListEntry>
4582 </VariableList>
4583 </Para>
4585 <Para>
4586 Note that in general there are many ways in which you can classify packet
4587 and that it generally comes down to preference as to which system you wish
4588 to use.
4589 </Para>
4591 <Para>
4592 Classifiers in general accept a few arguments in common. They are listed
4593 here for convenience:
4594 </Para>
4596 <Para>
4597 <VariableList>
4599 <VarListEntry>
4600 <Term>protocol</Term>
4601 <ListItem>
4602 <Para>
4603 The protocol this classifier will accept. Generally you will only be
4604 accepting only IP traffic. Required.
4605 </Para></ListItem>
4606 </VarListEntry>
4607 <VarListEntry>
4608 <Term>parent</Term>
4609 <ListItem>
4610 <Para>
4611 The handle this classifier is to be attached to. This handle must be
4612 an already existing class. Required.
4613 </Para></ListItem>
4614 </VarListEntry>
4615 <VarListEntry>
4616 <Term>prio</Term>
4617 <ListItem>
4618 <Para>
4619 The priority of this classifier. Lower numbers get tested first.
4620 </Para></ListItem>
4621 </VarListEntry>
4622 <VarListEntry>
4623 <Term>handle</Term>
4624 <ListItem>
4625 <Para>
4626 This handle means different things to different filters.
4627 </Para></ListItem>
4628 </VarListEntry>
4629 </VariableList>
4630 </Para>
4632 <Para>
4633 All the following sections will assume you are trying to shape the traffic
4634 going to <Literal remap="tt">HostA</Literal>. They will assume that the root class has been
4635 configured on 1: and that the class you want to send the selected traffic to
4636 is 1:1.
4637 </Para>
4639 <Sect1 id="lartc.adv-filter.u32">
4640   <Title>The <option>u32</option> classifier</Title>
4642 <Para>
4643 The U32 filter is the most advanced filter available in the current
4644 implementation. It entirely based on hashing tables, which make it
4645 robust when there are many filter rules.
4646 </Para>
4648 <Para>
4649 In its simplest form the U32 filter is a list of records, each
4650 consisting of two fields: a selector and an action. The selectors,
4651 described below, are compared with the currently processed IP packet
4652 until the first match occurs, and then the associated action is performed.
4653 The simplest type of action would be directing the packet into defined
4654 CBQ class.
4655 </Para>
4657 <Para>
4658 The command line of <Literal remap="tt">tc filter</Literal> program, used to configure the filter,
4659 consists of three parts: filter specification, a selector and an action.
4660 The filter specification can be defined as:
4661 </Para>
4663 <Para>
4665 <Screen>
4666 tc filter add dev IF [ protocol PROTO ]
4667                      [ (preference|priority) PRIO ]
4668                      [ parent CBQ ]
4669 </Screen>
4671 </Para>
4673 <Para>
4674 The <Literal remap="tt">protocol</Literal> field describes protocol that the filter will be
4675 applied to. We will only discuss case of <Literal remap="tt">ip</Literal> protocol. The
4676 <Literal remap="tt">preference</Literal> field (<Literal remap="tt">priority</Literal> can be used alternatively)
4677 sets the priority of currently defined filter. This is important, since
4678 you can have several filters (lists of rules) with different priorities.
4679 Each list will be passed in the order the rules were added, then list with
4680 lower priority (higher preference number) will be processed. The <Literal remap="tt">parent</Literal>
4681 field defines the CBQ tree top (e.g. 1:0), the filter should be attached
4683 </Para>
4685 <Para>
4686 The options described above apply to all filters, not only U32.
4687 </Para>
4689 <Sect2>
4690 <Title>U32 selector </Title>
4692 <Para>
4693 The U32 selector contains definition of the pattern, that will be matched
4694 to the currently processed packet. Precisely, it defines which bits are
4695 to be matched in the packet header and nothing more, but this simple
4696 method is very powerful. Let's take a look at the following examples,
4697 taken directly from a pretty complex, real-world filter:
4698 </Para>
4700 <Para>
4702 <Screen>
4703 # tc filter add dev eth0 protocol ip parent 1:0 pref 10 u32 \
4704   match u32 00100000 00ff0000 at 0 flowid 1:10
4705 </Screen>
4707 </Para>
4709 <Para>
4710 For now, leave the first line alone - all these parameters describe
4711 the filter's hash tables. Focus on the selector line, containing
4712 <Literal remap="tt">match</Literal> keyword. This selector will match to IP headers, whose
4713 second byte will be 0x10 (0010). As you can guess, the 00ff number is
4714 the match mask, telling the filter exactly which bits to match. Here
4715 it's 0xff, so the byte will match if it's exactly 0x10. The <Literal remap="tt">at</Literal>
4716 keyword means that the match is to be started at specified offset (in
4717 bytes) -- in this case it's beginning of the packet.  Translating all
4718 that to human language, the packet will match if its Type of Service
4719 field will have `low delay' bits set. Let's analyze another rule:
4720 </Para>
4722 <Para>
4724 <Screen>
4725 # tc filter add dev eth0 protocol ip parent 1:0 pref 10 u32 \
4726   match u32 00000016 0000ffff at nexthdr+0 flowid 1:10
4727 </Screen>
4729 </Para>
4731 <Para>
4732 The <Literal remap="tt">nexthdr</Literal> option means next header encapsulated in the IP packet,
4733 i.e. header of upper-layer protocol. The match will also start here
4734 at the beginning of the next header. The match should occur in the
4735 second, 32-bit word of the header. In TCP and UDP protocols this field
4736 contains packet's destination port. The number is given in big-endian
4737 format, i.e. older bits first, so we simply read 0x0016 as 22 decimal,
4738 which stands for SSH service if this was TCP. As you guess, this match
4739 is ambiguous without a context, and we will discuss this later.
4740 </Para>
4742 <Para>
4743 Having understood all the above, we will find the following selector
4744 quite easy to read: <Literal remap="tt">match c0a80100 ffffff00 at 16</Literal>. What we
4745 got here is a three byte match at 17-th byte, counting from the IP
4746 header start. This will match for packets with destination address
4747 anywhere in 192.168.1/24 network. After analyzing the examples, we
4748 can summarize what we have learned.
4749 </Para>
4751 </Sect2>
4753 <Sect2>
4754 <Title>General selectors</Title>
4756 <Para>
4757 General selectors define the pattern, mask and offset the pattern
4758 will be matched to the packet contents. Using the general selectors
4759 you can match virtually any single bit in the IP (or upper layer)
4760 header. They are more difficult to write and read, though, than
4761 specific selectors that described below. The general selector syntax
4763 </Para>
4765 <Para>
4767 <Screen>
4768 match [ u32 | u16 | u8 ] PATTERN MASK [ at OFFSET | nexthdr+OFFSET]
4769 </Screen>
4771 </Para>
4773 <Para>
4774 One of the keywords <Literal remap="tt">u32</Literal>, <Literal remap="tt">u16</Literal> or <Literal remap="tt">u8</Literal> specifies
4775 length of the pattern in bits. PATTERN and MASK should follow, of length
4776 defined by the previous keyword. The OFFSET parameter is the offset,
4777 in bytes, to start matching. If <Literal remap="tt">nexthdr+</Literal> keyword is given,
4778 the offset is relative to start of the upper layer header.
4779 </Para>
4781 <Para>
4782 Some examples:
4783 </Para>
4785 <Para>
4787 <Screen>
4788 # tc filter add dev ppp14 parent 1:0 prio 10 u32 \
4789      match u8 64 0xff at 8 \
4790      flowid 1:4
4791 </Screen>
4793 </Para>
4795 <Para>
4796 Packet will match to this rule, if its time to live (TTL) is 64.
4797 TTL is the field starting just after 8-th byte of the IP header.
4798 </Para>
4800 <Para>
4802 <Screen>
4803 # tc filter add dev ppp14 parent 1:0 prio 10 u32 \
4804      match u8 0x10 0xff at nexthdr+13 \
4805      protocol tcp \
4806      flowid 1:3 
4807 </Screen>
4809 </Para>
4811 <Para>
4812 FIXME: it has been pointed out that this syntax does not work currently.
4813 </Para>
4815 <Para>
4816 Use this to match ACKs on packets smaller than 64 bytes:
4817 </Para>
4819 <Para>
4821 <Screen>
4822 ## match acks the hard way,
4823 ## IP protocol 6,
4824 ## IP header length 0x5(32 bit words),
4825 ## IP Total length 0x34 (ACK + 12 bytes of TCP options)
4826 ## TCP ack set (bit 5, offset 33)
4827 # tc filter add dev ppp14 parent 1:0 protocol ip prio 10 u32 \
4828             match ip protocol 6 0xff \
4829             match u8 0x05 0x0f at 0 \
4830             match u16 0x0000 0xffc0 at 2 \
4831             match u8 0x10 0xff at 33 \
4832             flowid 1:3
4833 </Screen>
4835 </Para>
4837 <Para>
4838 This rule will only match TCP packets with ACK bit set, and no further
4839 payload. Here we can see an example of using two selectors, the final result
4840 will be logical AND of their results. If we take a look at TCP header
4841 diagram, we can see that the ACK bit is second older bit (0x10) in the 14-th
4842 byte of the TCP header (<Literal remap="tt">at nexthdr+13</Literal>).  As for the second
4843 selector, if we'd like to make our life harder, we could write <Literal remap="tt">match u8
4844 0x06 0xff at 9</Literal> instead of using the specific selector <Literal remap="tt">protocol
4845 tcp</Literal>, because 6 is the number of TCP protocol, present in 10-th byte of
4846 the IP header. On the other hand, in this example we couldn't use any
4847 specific selector for the first match - simply because there's no specific
4848 selector to match TCP ACK bits.
4849 </Para>
4851 </Sect2>
4853 <Sect2>
4854 <Title>Specific selectors</Title>
4856 <Para>
4857 The following table contains a list of all specific selectors 
4858 the author of this section has found in the <Literal remap="tt">tc</Literal> program
4859 source code. They simply make your life easier and increase readability
4860 of your filter's configuration.
4861 </Para>
4863 <Para>
4864 FIXME: table placeholder - the table is in separate file ,,selector.html''
4865 </Para>
4867 <Para>
4868 FIXME: it's also still in Polish :-(
4869 </Para>
4871 <Para>
4872 FIXME: must be sgml'ized
4873 </Para>
4875 <Para>
4876 Some examples:
4877 </Para>
4879 <Para>
4881 <Screen>
4882 # tc filter add dev ppp0 parent 1:0 prio 10 u32 \
4883      match ip tos 0x10 0xff \
4884      flowid 1:4
4885 </Screen>
4887 </Para>
4889 <Para>
4890 FIXME: tcp dst match does not work as described below:
4891 </Para>
4893 <Para>
4894 The above rule will match packets which have the TOS field set to 0x10.
4895 The TOS field starts at second byte of the packet and is one byte big,
4896 so we could write an equivalent general selector: <Literal remap="tt">match u8 0x10 0xff
4897 at 1</Literal>. This gives us hint to the internals of U32 filter -- the
4898 specific rules are always translated to general ones, and in this
4899 form they are stored in the kernel memory. This leads to another conclusion
4900 -- the <Literal remap="tt">tcp</Literal> and <Literal remap="tt">udp</Literal> selectors are exactly the same
4901 and this is why you can't use single <Literal remap="tt">match tcp dst 53 0xffff</Literal>
4902 selector to match TCP packets sent to given port -- they will also
4903 match UDP packets sent to this port. You must remember to also specify
4904 the protocol and end up with the following rule:
4905 </Para>
4907 <Para>
4909 <Screen>
4910 # tc filter add dev ppp0 parent 1:0 prio 10 u32 \
4911         match tcp dst 53 0xffff \
4912         match ip protocol 0x6 0xff \
4913         flowid 1:2
4914 </Screen>
4916 </Para>
4918 </Sect2>
4920 </Sect1>
4922 <Sect1 id="lartc.adv-filter.route">
4923   <Title>The <option>route</option> classifier</Title>
4925 <Para>
4926 This classifier filters based on the results of the routing tables. When a
4927 packet that is traversing through the classes reaches one that is marked
4928 with the "route" filter, it splits the packets up based on information in
4929 the routing table.
4930 </Para>
4932 <Para>
4934 <Screen>
4935 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 route
4936 </Screen>
4938 </Para>
4940 <Para>
4941 Here we add a route classifier onto the parent node 1:0 with priority 100. 
4942 When a packet reaches this node (which, since it is the root, will happen
4943 immediately) it will consult the routing table and if one matches will
4944 send it to the given class and give it a priority of 100. Then, to finally
4945 kick it into action, you add the appropriate routing entry:
4946 </Para>
4948 <Para>
4949 The trick here is to define 'realm' based on either destination or source. 
4950 The way to do it is like this:
4951 </Para>
4953 <Para>
4955 <Screen>
4956 # ip route add Host/Network via Gateway dev Device realm RealmNumber
4957 </Screen>
4959 </Para>
4961 <Para>
4962 For instance, we can define our destination network 192.168.10.0 with a realm
4963 number 10:
4964 </Para>
4966 <Para>
4968 <Screen>
4969 # ip route add 192.168.10.0/24 via 192.168.10.1 dev eth1 realm 10
4970 </Screen>
4971   
4972 </Para>
4974 <Para>
4975 When adding route filters, we can use realm numbers to represent the
4976 networks or hosts and specify how the routes match the filters.
4977 </Para>
4979 <Para>
4981 <Screen>
4982 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 \
4983   route to 10 classid 1:10
4984 </Screen>
4985   
4986 </Para>
4988 <Para>
4989 The above rule says packets going to the network 192.168.10.0 match class id
4990 1:10.
4991 </Para>
4993 <Para>
4994 Route filter can also be used to match source routes. For example, there is 
4995 a subnetwork attached to the Linux router on eth2.
4996 </Para>
4998 <Para>
5000 <Screen>
5001 # ip route add 192.168.2.0/24 dev eth2 realm 2
5002 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 \
5003   route from 2 classid 1:2
5004 </Screen>
5006 </Para>
5008 <Para>
5009 Here the filter specifies that packets from the subnetwork 192.168.2.0
5010 (realm 2) will match class id 1:2.
5011 </Para>
5013 </Sect1>
5015 <Sect1 id="lartc.adv-filter.policing">
5016   <Title>Policing filters</Title>
5018 <Para>
5019 To make even more complicated setups possible, you can have filters that
5020 only match up to a certain bandwidth. You can declare a filter to entirely
5021 cease matching above a certain rate, or only to not match only the bandwidth
5022 exceeding a certain rate.
5023 </Para>
5025 <Para>
5026 So if you decided to police at 4mbit/s, but 5mbit/s of traffic is present,
5027 you can stop matching either the entire 5mbit/s, or only not match 1mbit/s,
5028 and do send 4mbit/s to the configured class.
5029 </Para>
5031 <Para>
5032 If bandwidth exceeds the configured rate, you can drop a packet, reclassify
5033 it, or see if another filter will match it.
5034 </Para>
5036 <Sect2>
5037 <Title>Ways to police</Title>
5039 <Para>
5040 There are basically two ways to police. If you compiled the kernel 
5041 with 'Estimators', the kernel can measure for each filter how much traffic
5042 it is passing, more or less. These estimators are very easy on the CPU, as
5043 they simply count 25 times per second how many data has been passed, and
5044 calculate the bitrate from that.
5045 </Para>
5047 <Para>
5048 The other way works again via a Token Bucket Filter, this time living within
5049 your filter. The TBF only matches traffic UP TO your configured bandwidth,
5050 if more is offered, only the excess is subject to the configured overlimit
5051 action.
5052 </Para>
5054 <Sect3>
5055 <Title>With the kernel estimator</Title>
5057 <Para>
5058 This is very simple and has only one parameter: avrate. Either the flow
5059 remains below avrate, and the filter classifies the traffic to the classid
5060 configured, or your rate exceeds it in which case the specified action is
5061 taken, which is 'reclassify' by default.
5062 </Para>
5064 <Para>
5065 The kernel uses an Exponential Weighted Moving Average for your bandwidth
5066 which makes it less sensitive to short bursts.
5067 </Para>
5069 </Sect3>
5071 <Sect3>
5072 <Title>With Token Bucket Filter</Title>
5074 <Para>
5075 Uses the following parameters:
5077 <ItemizedList>
5078 <ListItem>
5080 <Para>
5081 buffer/maxburst
5082 </Para>
5083 </ListItem>
5084 <ListItem>
5086 <Para>
5087 mtu/minburst
5088 </Para>
5089 </ListItem>
5090 <ListItem>
5092 <Para>
5094 </Para>
5095 </ListItem>
5096 <ListItem>
5098 <Para>
5099 rate
5100 </Para>
5101 </ListItem>
5103 </ItemizedList>
5105 </Para>
5107 <Para>
5108 Which behave mostly identical to those described in the Token Bucket Filter
5109 section. Please note however that if you set the mtu of a TBF policer too
5110 low, *no* packets will pass, whereas the egress TBF qdisc will just pass
5111 them slower.
5112 </Para>
5114 <Para>
5115 Another difference is that a policer can only let a packet pass, or drop it.
5116 It cannot delay hold on to it in order to delay it.
5117 </Para>
5119 </Sect3>
5121 </Sect2>
5123 <Sect2>
5124 <Title>Overlimit actions</Title>
5126 <Para>
5127 If your filter decides that it is overlimit, it can take 'actions'.
5128 Currently, three actions are available:
5129 <VariableList>
5131 <VarListEntry>
5132 <Term>continue</Term>
5133 <ListItem>
5134 <Para>
5135 Causes this filter not to match, but perhaps other filters will.
5136 </Para></ListItem>
5137 </VarListEntry>
5138 <VarListEntry>
5139 <Term>drop</Term>
5140 <ListItem>
5141 <Para>
5142 This is a very fierce option which simply discards traffic exceeding a
5143 certain rate. It is often used in the ingress policer and has limited uses.
5144 For example, you may have a name server that falls over if offered more than
5145 5mbit/s of packets, in which case an ingress filter could be used to make
5146 sure no more is ever offered.
5147 </Para></ListItem>
5148 </VarListEntry>
5149 <VarListEntry>
5150 <Term>Pass/OK</Term>
5151 <ListItem>
5152 <Para>
5153 Pass on traffic ok. Might be used to disable a complicated filter, but leave
5154 it in place.
5155 </Para></ListItem>
5156 </VarListEntry>
5157 <VarListEntry>
5158 <Term>reclassify</Term>
5159 <ListItem>
5160 <Para>
5161 Most often comes down to reclassification to Best Effort. This is the
5162 default action.
5163 </Para></ListItem>
5164 </VarListEntry>
5165 </VariableList>
5166 </Para>
5168 </Sect2>
5170 <Sect2>
5171 <Title>Examples</Title>
5173 <Para>
5174 The only real example known is mentioned in the 'Protecting your host 
5175 from SYN floods' section. 
5176 </Para>
5178 <Para>
5179 FIXME: if you have used this, please share your experience with us
5180 </Para>
5182 </Sect2>
5184 </Sect1>
5186 <Sect1 id="lartc.adv-filter.hashing">
5187 <Title>Hashing filters for very fast massive filtering</Title>
5189 <Para>
5190 If you have a need for thousands of rules, for example if you have a lot of
5191 clients or computers, all with different QoS specifications, you may find
5192 that the kernel spends a lot of time matching all those rules.
5193 </Para>
5195 <Para>
5196 By default, all filters reside in one big chain which is matched in
5197 descending order of priority. If you have 1000 rules, 1000 checks may be
5198 needed to determine what to do with a packet.
5199 </Para>
5201 <Para>
5202 Matching would go much quicker if you would have 256 chains with each four
5203 rules - if you could divide packets over those 256 chains, so that the right
5204 rule will be there.
5205 </Para>
5207 <Para>
5208 Hashing makes this possible. Let's say you have 1024 cable modem customers in
5209 your network, with IP addresses ranging from 1.2.0.0 to 1.2.3.255, and each
5210 has to go in another bin, for example 'lite', 'regular' and 'premium'. You
5211 would then have 1024 rules like this:
5212 </Para>
5214 <Para>
5216 <Screen>
5217 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5218   1.2.0.0 classid 1:1
5219 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5220   1.2.0.1 classid 1:1
5222 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5223   1.2.3.254 classid 1:3
5224 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5225   1.2.3.255 classid 1:2
5226 </Screen>
5228 </Para>
5230 <Para>
5231 To speed this up, we can use the last part of the IP address as a 'hash
5232 key'. We then get 256 tables, the first of which looks like this:
5234 <Screen>
5235 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5236   1.2.0.0 classid 1:1
5237 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5238   1.2.1.0 classid 1:1
5239 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5240   1.2.2.0 classid 1:3
5241 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5242   1.2.3.0 classid 1:2
5243 </Screen>
5245 </Para>
5247 <Para>
5248 The next one starts like this:
5250 <Screen>
5251 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5252   1.2.0.1 classid 1:1
5254 </Screen>
5256 </Para>
5258 <Para>
5259 This way, only four checks are needed at most, two on average. 
5260 </Para>
5262 <Para>
5263 Configuration is pretty complicated, but very worth it by the time you have
5264 this many rules. First we make a filter root, then we create a table with
5265 256 entries:
5267 <Screen>
5268 # tc filter add dev eth1 parent 1:0 prio 5 protocol ip u32
5269 # tc filter add dev eth1 parent 1:0 prio 5 handle 2: protocol ip u32 divisor 256
5270 </Screen>
5272 </Para>
5274 <Para>
5275 Now we add some rules to entries in the created table:
5276 </Para>
5278 <Para>
5280 <Screen>
5281 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 2:7b: \
5282         match ip src 1.2.0.123 flowid 1:1
5283 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 2:7b: \
5284         match ip src 1.2.1.123 flowid 1:2
5285 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 2:7b: \
5286         match ip src 1.2.3.123 flowid 1:3
5287 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 2:7b: \
5288         match ip src 1.2.4.123 flowid 1:2
5289 </Screen>
5291 This is entry 123, which contains matches for 1.2.0.123, 1.2.1.123,
5292 1.2.2.123, 1.2.3.123, and sends them to 1:1, 1:2, 1:3 and 1:2 respectively.
5293 Note that we need to specify our hash bucket in hex, 0x7b is 123.
5294 </Para>
5296 <Para>
5297 Next create a 'hashing filter' that directs traffic to the right entry in
5298 the hashing table:
5300 <Screen>
5301 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 800:: \
5302         match ip src 1.2.0.0/16 \
5303         hashkey mask 0x000000ff at 12 \
5304         link 2:
5305 </Screen>
5307 Ok, some numbers need explaining. The default hash table is called 800:: and
5308 all filtering starts there. Then we select the source address, which lives
5309 as position 12, 13, 14 and 15 in the IP header, and indicate that we are
5310 only interested in the last part. This we send to hash table 2:, which we
5311 created earlier.
5312 </Para>
5314 <Para>
5315 It is quite complicated, but it does work in practice and performance will
5316 be staggering. Note that this example could be improved to the ideal case
5317 where each chain contains 1 filter!
5318 </Para>
5320 </Sect1>
5322 </chapter>
5324 <chapter id="lartc.kernel">
5325 <Title>Kernel network parameters </Title>
5327 <Para>
5329 The kernel has lots of parameters which
5330 can be tuned for different circumstances. While, as usual, the default
5331 parameters serve 99&percnt; of installations very well, we don't call this the
5332 Advanced HOWTO for the fun of it!
5333 </Para>
5335 <Para>
5336 The interesting bits are in /proc/sys/net, take a look there. Not everything
5337 will be documented here initially, but we're working on it.
5338 </Para>
5340 <Para>
5341 In the meantime you may want to have a look at the Linux-Kernel sources;
5342 read the file Documentation/filesystems/proc.txt. Most of the
5343 features are explained there.
5344 </Para>
5346 <Para>
5347 (FIXME)
5348 </Para>
5350 <Sect1 id="lartc.kernel.rpf"
5351   xreflabel="Reverse Path Filtering">
5352   <Title>Reverse Path Filtering</Title>
5354 <Para>
5355 By default, routers route everything, even packets which 'obviously' don't
5356 belong on your network. A common example is private IP space escaping onto
5357 the Internet. If you have an interface with a route of 195.96.96.0/24 to it,
5358 you do not expect packets from 212.64.94.1 to arrive there.
5359 </Para>
5361 <Para>
5362 Lots of people will want to turn this feature off, so the kernel hackers
5363 have made it easy. There are files in /proc where you can tell
5364 the kernel to do this for you. The method is called "Reverse Path
5365 Filtering". Basically, if the reply to this packet wouldn't go out the
5366 interface this packet came in, then this is a bogus packet and should be
5367 ignored.
5368 </Para>
5370 <Para>
5371 The following fragment will turn this on for all current and future
5372 interfaces.
5373 </Para>
5375 <Para>
5377 <Screen>
5378 # for i in /proc/sys/net/ipv4/conf/*/rp_filter ; do
5379 &gt;  echo 2 &#62; $i 
5380 &gt; done
5381 </Screen>
5383 </Para>
5385 <Para>
5386 Going by the example above, if a packet arrived on the Linux router on eth1
5387 claiming to come from the Office+ISP subnet, it would be dropped. Similarly,
5388 if a packet came from the Office subnet, claiming to be from somewhere
5389 outside your firewall, it would be dropped also.
5390 </Para>
5392 <Para>
5393 The above is full reverse path filtering. The default is to only filter
5394 based on IPs that are on directly connected networks. This is because the
5395 full filtering breaks in the case of asymmetric routing (where packets come
5396 in one way and go out another, like satellite traffic, or if you have
5397 dynamic (bgp, ospf, rip) routes in your network. The data comes down
5398 through the satellite dish and replies go back through normal land-lines).
5399 </Para>
5401 <Para>
5402 If this exception applies to you (and you'll probably know if it does) you
5403 can simply turn off the rp_filter on the interface where the
5404 satellite data comes in. If you want to see if any packets are being
5405 dropped, the log_martians file in the same directory will tell
5406 the kernel to log them to your syslog.
5407 </Para>
5409 <Para>
5411 <Screen>
5412 # echo 1 &#62;/proc/sys/net/ipv4/conf/&#60;interfacename&#62;/log_martians
5413 </Screen>
5415 </Para>
5417 <Para>
5418 FIXME: is setting the conf/&lcub;default,all&rcub;/* files enough? - martijn
5419 </Para>
5421 </Sect1>
5423 <Sect1 id="lartc.kernel.obscure">
5424   <Title>Obscure settings</Title>
5426 <Para>
5427 Ok, there are a lot of parameters which can be modified. We try to list them
5428 all. Also documented (partly) in Documentation/ip-sysctl.txt.
5429 </Para>
5431 <Para>
5432 Some of these settings have different defaults based on whether you 
5433 answered 'Yes' to 'Configure as router and not host' while compiling your
5434 kernel.
5435 </Para>
5437 <para>
5438 Oskar Andreasson also has a page on all these flags and it appears to be
5439 better than ours, so also check 
5440 <ulink url="http://ipsysctl-tutorial.frozentux.net/">
5441 http://ipsysctl-tutorial.frozentux.net/</ulink>.
5442 </para>
5444 <Sect2>
5445 <Title>Generic ipv4</Title>
5447 <Para>
5448 As a generic note, most rate limiting features don't work on loopback, so
5449 don't test them locally. The limits are supplied in 'jiffies', and are
5450 enforced using the earlier mentioned token bucket filter.
5451 </Para>
5453 <Para>
5454 The kernel has an internal clock which runs at 'HZ' ticks (or 'jiffies') per
5455 second. On Intel, 'HZ' is mostly 100. So setting a *_rate file to, say 50,
5456 would allow for 2 packets per second. The token bucket filter is also
5457 configured to allow for a burst of at most 6 packets, if enough tokens have
5458 been earned.
5459 </Para>
5461 <Para>
5462 Several entries in the following list have been copied from
5463 /usr/src/linux/Documentation/networking/ip-sysctl.txt, written by Alexey
5464 Kuznetsov &lt;kuznet@ms2.inr.ac.ru&gt; and Andi Kleen &lt;ak@muc.de&gt;
5465 <VariableList>
5467 <VarListEntry>
5468 <Term>/proc/sys/net/ipv4/icmp_destunreach_rate</Term>
5469 <ListItem>
5470 <Para>
5471 If the kernel decides that it can't deliver a packet, it will drop it, and
5472 send the source of the packet an ICMP notice to this effect.
5473 </Para></ListItem>
5474 </VarListEntry>
5475 <VarListEntry>
5476 <Term>/proc/sys/net/ipv4/icmp_echo_ignore_all</Term>
5477 <ListItem>
5478 <Para>
5479 Don't act on echo packets at all. Please don't set this by default, but if
5480 you are used as a relay in a DoS attack, it may be useful.
5481 </Para></ListItem>
5482 </VarListEntry>
5483 <VarListEntry>
5484 <Term>/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts &lsqb;Useful&rsqb;</Term>
5485 <ListItem>
5486 <Para>
5487 If you ping the broadcast address of a network, all hosts are supposed to
5488 respond. This makes for a dandy denial-of-service tool. Set this to 1 to
5489 ignore these broadcast messages.
5490 </Para></ListItem>
5491 </VarListEntry>
5492 <VarListEntry>
5493 <Term>/proc/sys/net/ipv4/icmp_echoreply_rate</Term>
5494 <ListItem>
5495 <Para>
5496 The rate at which echo replies are sent to any one destination.
5497 </Para></ListItem>
5498 </VarListEntry>
5499 <VarListEntry>
5500 <Term>/proc/sys/net/ipv4/icmp_ignore_bogus_error_responses</Term>
5501 <ListItem>
5502 <Para>
5503 Set this to ignore ICMP errors caused by hosts in the network reacting badly
5504 to frames sent to what they perceive to be the broadcast address.
5505 </Para></ListItem>
5506 </VarListEntry>
5507 <VarListEntry>
5508 <Term>/proc/sys/net/ipv4/icmp_paramprob_rate</Term>
5509 <ListItem>
5510 <Para>
5511 A relatively unknown ICMP message, which is sent in response to incorrect
5512 packets with broken IP or TCP headers. With this file you can control the
5513 rate at which it is sent.
5514 </Para></ListItem>
5515 </VarListEntry>
5516 <VarListEntry>
5517 <Term>/proc/sys/net/ipv4/icmp_timeexceed_rate</Term>
5518 <ListItem>
5519 <Para>
5520 This the famous cause of the 'Solaris middle star' in traceroutes. Limits
5521 number of ICMP Time Exceeded messages sent. 
5522 </Para></ListItem>
5523 </VarListEntry>
5524 <VarListEntry>
5525 <Term>/proc/sys/net/ipv4/igmp_max_memberships</Term>
5526 <ListItem>
5527 <Para>
5528 Maximum number of listening igmp (multicast) sockets on the host.
5529 FIXME: Is this true?
5530 </Para></ListItem>
5531 </VarListEntry>
5532 <VarListEntry>
5533 <Term>/proc/sys/net/ipv4/inet_peer_gc_maxtime</Term>
5534 <ListItem>
5535 <Para>
5536 FIXME: Add a little explanation about the inet peer storage?
5538 Minimum interval between garbage collection passes.  This interval is in
5539 effect under low (or absent) memory pressure on the pool. Measured in
5540 jiffies.
5541 </Para></ListItem>
5542 </VarListEntry>
5543 <VarListEntry>
5544 <Term>/proc/sys/net/ipv4/inet_peer_gc_mintime</Term>
5545 <ListItem>
5546 <Para>
5547 Minimum interval between garbage collection passes.  This interval is in
5548 effect under high memory pressure on the pool. Measured in jiffies.
5549 </Para></ListItem>
5550 </VarListEntry>
5551 <VarListEntry>
5552 <Term>/proc/sys/net/ipv4/inet_peer_maxttl</Term>
5553 <ListItem>
5554 <Para>
5555 Maximum time-to-live of entries.  Unused entries will expire after this
5556 period of time if there is no memory pressure on the pool (i.e. when the
5557 number of entries in the pool is very small). Measured in jiffies.
5558 </Para></ListItem>
5559 </VarListEntry>
5560 <VarListEntry>
5561 <Term>/proc/sys/net/ipv4/inet_peer_minttl</Term>
5562 <ListItem>
5563 <Para>
5564 Minimum time-to-live of entries.  Should be enough to cover fragment
5565 time-to-live on the reassembling side.  This minimum time-to-live
5566 is guaranteed if the pool size is less than inet_peer_threshold.
5567 Measured in jiffies.
5568 </Para></ListItem>
5569 </VarListEntry>
5570 <VarListEntry>
5571 <Term>/proc/sys/net/ipv4/inet_peer_threshold</Term>
5572 <ListItem>
5573 <Para>
5574 The approximate size of the INET peer storage.  Starting from this threshold
5575 entries will be thrown aggressively.  This threshold also determines
5576 entries' time-to-live and time intervals between garbage collection passes. 
5577 More entries, less time-to-live, less GC interval.
5578 </Para></ListItem>
5579 </VarListEntry>
5580 <VarListEntry>
5581 <Term>/proc/sys/net/ipv4/ip_autoconfig</Term>
5582 <ListItem>
5583 <Para>
5584 This file contains the number one if the host received its IP configuration by
5585 RARP, BOOTP, DHCP or a similar mechanism. Otherwise it is zero.
5586 </Para></ListItem>
5587 </VarListEntry>
5588 <VarListEntry>
5589 <Term>/proc/sys/net/ipv4/ip_default_ttl</Term>
5590 <ListItem>
5591 <Para>
5592 Time To Live of packets. Set to a safe 64. Raise it if you have a huge
5593 network. Don't do so for fun - routing loops cause much more damage that
5594 way. You might even consider lowering it in some circumstances.
5595 </Para></ListItem>
5596 </VarListEntry>
5597 <VarListEntry>
5598 <Term>/proc/sys/net/ipv4/ip_dynaddr</Term>
5599 <ListItem>
5600 <Para>
5601 You need to set this if you use dial-on-demand with a dynamic interface
5602 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
5603 connection that brings up your interface itself does not work, but the
5604 second try does.
5605 </Para></ListItem>
5606 </VarListEntry>
5607 <VarListEntry>
5608 <Term>/proc/sys/net/ipv4/ip_forward</Term>
5609 <ListItem>
5610 <Para>
5611 If the kernel should attempt to forward packets. Off by default.
5612 </Para></ListItem>
5613 </VarListEntry>
5614 <VarListEntry>
5615 <Term>/proc/sys/net/ipv4/ip_local_port_range</Term>
5616 <ListItem>
5617 <Para>
5618 Range of local ports for outgoing connections. Actually quite small by
5619 default, 1024 to 4999.
5620 </Para></ListItem>
5621 </VarListEntry>
5622 <VarListEntry>
5623 <Term>/proc/sys/net/ipv4/ip_no_pmtu_disc</Term>
5624 <ListItem>
5625 <Para>
5626 Set this if you want to disable Path MTU discovery - a technique to
5627 determine the largest Maximum Transfer Unit possible on your path. See also
5628 the section on Path MTU discovery in the 
5629 <citetitle><xref linkend="lartc.cookbook"></citetitle> chapter.
5630 </Para></ListItem>
5631 </VarListEntry>
5632 <VarListEntry>
5633 <Term>/proc/sys/net/ipv4/ipfrag_high_thresh</Term>
5634 <ListItem>
5635 <Para>
5636 Maximum memory used to reassemble IP fragments. When 
5637 ipfrag_high_thresh bytes of memory is allocated for this purpose,
5638 the fragment handler will toss packets until ipfrag_low_thresh
5639 is reached.
5640 </Para></ListItem>
5641 </VarListEntry>
5642 <VarListEntry>
5643 <Term>/proc/sys/net/ipv4/ip_nonlocal_bind</Term>
5644 <ListItem>
5645 <Para>
5646 Set this if you want your applications to be able to bind to an address
5647 which doesn't belong to a device on your system. This can be useful when
5648 your machine is on a non-permanent (or even dynamic) link, so your services
5649 are able to start up and bind to a specific address when your link is down.
5650 </Para></ListItem>
5651 </VarListEntry>
5652 <VarListEntry>
5653 <Term>/proc/sys/net/ipv4/ipfrag_low_thresh</Term>
5654 <ListItem>
5655 <Para>
5656 Minimum memory used to reassemble IP fragments.
5657 </Para></ListItem>
5658 </VarListEntry>
5659 <VarListEntry>
5660 <Term>/proc/sys/net/ipv4/ipfrag_time</Term>
5661 <ListItem>
5662 <Para>
5663 Time in seconds to keep an IP fragment in memory.
5664 </Para></ListItem>
5665 </VarListEntry>
5666 <VarListEntry>
5667 <Term>/proc/sys/net/ipv4/tcp_abort_on_overflow</Term>
5668 <ListItem>
5669 <Para>
5670 A boolean flag controlling the behaviour under lots of incoming connections.
5671 When enabled, this causes the kernel to actively send RST packets when a
5672 service is overloaded.
5673 </Para></ListItem>
5674 </VarListEntry>
5675 <VarListEntry>
5676 <Term>/proc/sys/net/ipv4/tcp_fin_timeout</Term>
5677 <ListItem>
5678 <Para>
5679 Time to hold socket in state FIN-WAIT-2, if it was closed by our side. Peer
5680 can be broken and never close its side, or even died unexpectedly. Default
5681 value is 60sec. Usual value used in 2.2 was 180 seconds, you may restore it,
5682 but remember that if your machine is even underloaded WEB server, you risk
5683 to overflow memory with kilotons of dead sockets, FIN-WAIT-2 sockets are
5684 less dangerous than FIN-WAIT-1, because they eat maximum 1.5K of memory, but
5685 they tend to live longer. Cf. tcp_max_orphans.
5686 </Para></ListItem>
5687 </VarListEntry>
5688 <VarListEntry>
5689 <Term>/proc/sys/net/ipv4/tcp_keepalive_time</Term>
5690 <ListItem>
5691 <Para>
5692 How often TCP sends out keepalive messages when keepalive is enabled. 
5694 Default: 2hours.
5695 </Para></ListItem>
5696 </VarListEntry>
5697 <VarListEntry>
5698 <Term>/proc/sys/net/ipv4/tcp_keepalive_intvl</Term>
5699 <ListItem>
5700 <Para>
5701 How frequent probes are retransmitted, when a probe isn't acknowledged. 
5703 Default: 75 seconds.
5704 </Para></ListItem>
5705 </VarListEntry>
5706 <VarListEntry>
5707 <Term>/proc/sys/net/ipv4/tcp_keepalive_probes</Term>
5708 <ListItem>
5709 <Para>
5710 How many keepalive probes TCP will send, until it decides that the
5711 connection is broken. 
5713 Default value: 9. 
5715 Multiplied with tcp_keepalive_intvl, this gives the time a link can be
5716 non-responsive after a keepalive has been sent.
5717 </Para></ListItem>
5718 </VarListEntry>
5719 <VarListEntry>
5720 <Term>/proc/sys/net/ipv4/tcp_max_orphans</Term>
5721 <ListItem>
5722 <Para>
5723 Maximal number of TCP sockets not attached to any user file handle, held by
5724 system. If this number is exceeded orphaned connections are reset
5725 immediately and warning is printed. This limit exists only to prevent simple
5726 DoS attacks, you _must_ not rely on this or lower the limit artificially,
5727 but rather increase it (probably, after increasing installed memory), if
5728 network conditions require more than default value, and tune network
5729 services to linger and kill such states more aggressively. Let me remind you
5730 again: each orphan eats up to &nbsp;64K of unswappable memory.
5731 </Para></ListItem>
5732 </VarListEntry>
5733 <VarListEntry>
5734 <Term>/proc/sys/net/ipv4/tcp_orphan_retries</Term>
5735 <ListItem>
5736 <Para>
5737 How may times to retry before killing TCP connection, closed by our side.
5738 Default value 7 corresponds to &nbsp;50sec-16min depending on RTO. If your machine
5739 is a loaded WEB server, you should think about lowering this value, such
5740 sockets may consume significant resources. Cf. tcp_max_orphans.
5741 </Para></ListItem>
5742 </VarListEntry>
5743 <VarListEntry>
5744 <Term>/proc/sys/net/ipv4/tcp_max_syn_backlog</Term>
5745 <ListItem>
5746 <Para>
5747 Maximal number of remembered connection requests, which still did not
5748 receive an acknowledgment from connecting client. Default value is 1024 for
5749 systems with more than 128Mb of memory, and 128 for low memory machines. If
5750 server suffers of overload, try to increase this number. Warning! If you
5751 make it greater than 1024, it would be better to change TCP_SYNQ_HSIZE in
5752 include/net/tcp.h to keep TCP_SYNQ_HSIZE*16&#60;=tcp_max_syn_backlog and to
5753 recompile kernel.
5754 </Para></ListItem>
5755 </VarListEntry>
5756 <VarListEntry>
5757 <Term>/proc/sys/net/ipv4/tcp_max_tw_buckets</Term>
5758 <ListItem>
5759 <Para>
5760 Maximal number of timewait sockets held by system simultaneously. If this
5761 number is exceeded time-wait socket is immediately destroyed and warning is
5762 printed. This limit exists only to prevent simple DoS attacks, you _must_
5763 not lower the limit artificially, but rather increase it (probably, after
5764 increasing installed memory), if network conditions require more than
5765 default value.
5766 </Para></ListItem>
5767 </VarListEntry>
5768 <VarListEntry>
5769 <Term>/proc/sys/net/ipv4/tcp_retrans_collapse</Term>
5770 <ListItem>
5771 <Para>
5772 Bug-to-bug compatibility with some broken printers.
5773 On retransmit try to send bigger packets to work around bugs in
5774 certain TCP stacks.
5775 </Para></ListItem>
5776 </VarListEntry>
5777 <VarListEntry>
5778 <Term>/proc/sys/net/ipv4/tcp_retries1</Term>
5779 <ListItem>
5780 <Para>
5781 How many times to retry before deciding that something is wrong
5782 and it is necessary to report this suspicion to network layer.
5783 Minimal RFC value is 3, it is default, which corresponds
5784 to &nbsp;3sec-8min depending on RTO.
5785 </Para></ListItem>
5786 </VarListEntry>
5787 <VarListEntry>
5788 <Term>/proc/sys/net/ipv4/tcp_retries2</Term>
5789 <ListItem>
5790 <Para>
5791 How may times to retry before killing alive TCP connection.
5792 <ULink
5793 URL="http://www.ietf.org/rfc/rfc1122.txt"
5794 >RFC 1122</ULink
5796 says that the limit should be longer than 100 sec.
5797 It is too small number. Default value 15 corresponds to &nbsp;13-30min
5798 depending on RTO.
5799 </Para></ListItem>
5800 </VarListEntry>
5801 <VarListEntry>
5802 <Term>/proc/sys/net/ipv4/tcp_rfc1337</Term>
5803 <ListItem>
5804 <Para>
5805 This boolean enables a fix for 'time-wait assassination hazards in tcp', described
5806 in RFC 1337. If enabled, this causes the kernel to drop RST packets for
5807 sockets in the time-wait state.
5809 Default: 0
5810 </Para></ListItem>
5811 </VarListEntry>
5812 <VarListEntry>
5813 <Term>/proc/sys/net/ipv4/tcp_sack</Term>
5814 <ListItem>
5815 <Para>
5816 Use Selective ACK which can be used to signify that specific packets are
5817 missing - therefore helping fast recovery.
5818 </Para></ListItem>
5819 </VarListEntry>
5820 <VarListEntry>
5821 <Term>/proc/sys/net/ipv4/tcp_stdurg</Term>
5822 <ListItem>
5823 <Para>
5824 Use the Host requirements interpretation of the TCP urg pointer
5825 field. 
5827 Most hosts use the older BSD interpretation, so if you turn this on
5828 Linux might not communicate correctly with them. 
5830 Default: FALSE 
5831 </Para></ListItem>
5832 </VarListEntry>
5833 <VarListEntry>
5834 <Term>/proc/sys/net/ipv4/tcp_syn_retries</Term>
5835 <ListItem>
5836 <Para>
5837 Number of SYN packets the kernel will send before giving up on the new
5838 connection.
5839 </Para></ListItem>
5840 </VarListEntry>
5841 <VarListEntry>
5842 <Term>/proc/sys/net/ipv4/tcp_synack_retries</Term>
5843 <ListItem>
5844 <Para>
5845 To open the other side of the connection, the kernel sends a SYN with a
5846 piggybacked ACK on it, to acknowledge the earlier received SYN. This is part
5847 2 of the threeway handshake. This setting determines the number of SYN+ACK
5848 packets sent before the kernel gives up on the connection.
5849 </Para></ListItem>
5850 </VarListEntry>
5851 <VarListEntry>
5852 <Term>/proc/sys/net/ipv4/tcp_timestamps</Term>
5853 <ListItem>
5854 <Para>
5855 Timestamps are used, amongst other things, to protect against wrapping
5856 sequence numbers. A 1 gigabit link might conceivably re-encounter a previous
5857 sequence number with an out-of-line value, because it was of a previous
5858 generation. The timestamp will let it recognize this 'ancient packet'.
5859 </Para></ListItem>
5860 </VarListEntry>
5861 <VarListEntry>
5862 <Term>/proc/sys/net/ipv4/tcp_tw_recycle</Term>
5863 <ListItem>
5864 <Para>
5865 Enable fast recycling TIME-WAIT sockets. Default value is 1.
5866 It should not be changed without advice/request of technical experts.
5867 </Para></ListItem>
5868 </VarListEntry>
5869 <VarListEntry>
5870 <Term>/proc/sys/net/ipv4/tcp_window_scaling</Term>
5871 <ListItem>
5872 <Para>
5873 TCP/IP normally allows windows up to 65535 bytes big. For really fast
5874 networks, this may not be enough. The window scaling options allows for
5875 almost gigabyte windows, which is good for high bandwidth*delay products.
5876 </Para></ListItem>
5877 </VarListEntry>
5878 </VariableList>
5879 </Para>
5881 </Sect2>
5883 <Sect2>
5884 <Title>Per device settings</Title>
5886 <Para>
5887 DEV can either stand for a real interface, or for 'all' or 'default'.
5888 Default also changes settings for interfaces yet to be created.
5889 <VariableList>
5891 <VarListEntry>
5892 <Term>/proc/sys/net/ipv4/conf/DEV/accept_redirects</Term>
5893 <ListItem>
5894 <Para>
5895 If a router decides that you are using it for a wrong purpose (ie, it needs
5896 to resend your packet on the same interface), it will send us a ICMP
5897 Redirect. This is a slight security risk however, so you may want to turn it
5898 off, or use secure redirects.
5899 </Para></ListItem>
5900 </VarListEntry>
5901 <VarListEntry>
5902 <Term>/proc/sys/net/ipv4/conf/DEV/accept_source_route</Term>
5903 <ListItem>
5904 <Para>
5905 Not used very much anymore. You used to be able to give a packet a list of
5906 IP addresses it should visit on its way. Linux can be made to honor this IP
5907 option.
5908 </Para></ListItem>
5909 </VarListEntry>
5910 <VarListEntry>
5911 <Term>/proc/sys/net/ipv4/conf/DEV/bootp_relay</Term>
5912 <ListItem>
5913 <Para>
5914 Accept packets  with source address 0.b.c.d with destinations not to this host
5915 as local ones. It is supposed that a BOOTP relay daemon will catch and forward
5916 such packets.
5917 </Para>
5919 <Para>
5920 The default  is  0,  since this feature is not implemented yet (kernel version
5921 2.2.12).
5922 </Para></ListItem>
5923 </VarListEntry>
5924 <VarListEntry>
5925 <Term>/proc/sys/net/ipv4/conf/DEV/forwarding</Term>
5926 <ListItem>
5927 <Para>
5928 Enable or disable IP forwarding on this interface.
5929 </Para></ListItem>
5930 </VarListEntry>
5931 <VarListEntry>
5932 <Term>/proc/sys/net/ipv4/conf/DEV/log_martians</Term>
5933 <ListItem>
5934 <Para>
5935 See the section on 
5936 <citetitle><xref linkend="lartc.kernel.rpf"></citetitle>.
5937 </Para></ListItem>
5938 </VarListEntry>
5939 <VarListEntry>
5940 <Term>/proc/sys/net/ipv4/conf/DEV/mc_forwarding</Term>
5941 <ListItem>
5942 <Para>
5943 If we do multicast forwarding on this interface
5944 </Para></ListItem>
5945 </VarListEntry>
5946 <VarListEntry>
5947 <Term>/proc/sys/net/ipv4/conf/DEV/proxy_arp</Term>
5948 <ListItem>
5949 <Para>
5950 If you set this to 1, this interface will respond to ARP requests for
5951 addresses the kernel has routes to. Can be very useful when building 'ip
5952 pseudo bridges'. Do take care that your netmasks are very correct before
5953 enabling this! Also be aware that the rp_filter, mentioned elsewhere, also
5954 operates on ARP queries!
5955 </Para></ListItem>
5956 </VarListEntry>
5957 <VarListEntry>
5958 <Term>/proc/sys/net/ipv4/conf/DEV/rp_filter</Term>
5959 <ListItem>
5960 <Para>
5961 See the section on 
5962 <citetitle><xref linkend="lartc.kernel.rpf"></citetitle>.
5963 </Para></ListItem>
5964 </VarListEntry>
5965 <VarListEntry>
5966 <Term>/proc/sys/net/ipv4/conf/DEV/secure_redirects</Term>
5967 <ListItem>
5968 <Para>
5969 Accept ICMP  redirect  messages  only  for gateways, listed in default gateway
5970 list. Enabled by default.
5971 </Para></ListItem>
5972 </VarListEntry>
5973 <VarListEntry>
5974 <Term>/proc/sys/net/ipv4/conf/DEV/send_redirects</Term>
5975 <ListItem>
5976 <Para>
5977 If we send the above mentioned redirects.
5978 </Para></ListItem>
5979 </VarListEntry>
5980 <VarListEntry>
5981 <Term>/proc/sys/net/ipv4/conf/DEV/shared_media</Term>
5982 <ListItem>
5983 <Para>
5984 If it  is  not  set  the kernel does not assume that different subnets on this
5985 device can communicate directly. Default setting is 'yes'.
5986 </Para></ListItem>
5987 </VarListEntry>
5988 <VarListEntry>
5989 <Term>/proc/sys/net/ipv4/conf/DEV/tag</Term>
5990 <ListItem>
5991 <Para>
5992 FIXME: fill this in
5993 </Para></ListItem>
5994 </VarListEntry>
5995 </VariableList>
5996 </Para>
5998 </Sect2>
6000 <Sect2>
6001 <Title>Neighbor policy</Title>
6003 <Para>
6004 Dev can either stand for a real interface, or for 'all' or 'default'.
6005 Default also changes settings for interfaces yet to be created.
6006 <VariableList>
6008 <VarListEntry>
6009 <Term>/proc/sys/net/ipv4/neigh/DEV/anycast_delay</Term>
6010 <ListItem>
6011 <Para>
6012 Maximum for  random  delay  of  answers  to  neighbor solicitation messages in
6013 jiffies (1/100  sec). Not yet implemented (Linux does not have anycast support
6014 yet).
6015 </Para></ListItem>
6016 </VarListEntry>
6017 <VarListEntry>
6018 <Term>/proc/sys/net/ipv4/neigh/DEV/app_solicit</Term>
6019 <ListItem>
6020 <Para>
6021 Determines the  number of requests to send to the user level ARP daemon. Use 0
6022 to turn off.
6023 </Para></ListItem>
6024 </VarListEntry>
6025 <VarListEntry>
6026 <Term>/proc/sys/net/ipv4/neigh/DEV/base_reachable_time</Term>
6027 <ListItem>
6028 <Para>
6029 A base  value  used for computing the random reachable time value as specified
6030 in RFC2461.
6031 </Para></ListItem>
6032 </VarListEntry>
6033 <VarListEntry>
6034 <Term>/proc/sys/net/ipv4/neigh/DEV/delay_first_probe_time</Term>
6035 <ListItem>
6036 <Para>
6037 Delay for  the  first  time  probe  if  the  neighbor  is  reachable.  (see
6038 gc_stale_time)
6039 </Para></ListItem>
6040 </VarListEntry>
6041 <VarListEntry>
6042 <Term>/proc/sys/net/ipv4/neigh/DEV/gc_stale_time</Term>
6043 <ListItem>
6044 <Para>
6045 Determines how  often  to  check  for stale ARP entries. After an ARP entry is
6046 stale it  will  be resolved again (which is useful when an IP address migrates
6047 to another  machine).  When  ucast_solicit is greater than 0 it first tries to
6048 send an  ARP  packet  directly  to  the  known  host  When  that  fails  and
6049 mcast_solicit is greater than 0, an ARP request is broadcast.
6050 </Para></ListItem>
6051 </VarListEntry>
6052 <VarListEntry>
6053 <Term>/proc/sys/net/ipv4/neigh/DEV/locktime</Term>
6054 <ListItem>
6055 <Para>
6056 An ARP/neighbor  entry  is only replaced with a new one if the old is at least
6057 locktime old. This prevents ARP cache thrashing.
6058 </Para></ListItem>
6059 </VarListEntry>
6060 <VarListEntry>
6061 <Term>/proc/sys/net/ipv4/neigh/DEV/mcast_solicit</Term>
6062 <ListItem>
6063 <Para>
6064 Maximum number of retries for multicast solicitation.
6065 </Para></ListItem>
6066 </VarListEntry>
6067 <VarListEntry>
6068 <Term>/proc/sys/net/ipv4/neigh/DEV/proxy_delay</Term>
6069 <ListItem>
6070 <Para>
6071 Maximum time  (real  time is random &lsqb;0..proxytime]) before answering to an ARP
6072 request for  which  we have an proxy ARP entry. In some cases, this is used to
6073 prevent network flooding.
6074 </Para></ListItem>
6075 </VarListEntry>
6076 <VarListEntry>
6077 <Term>/proc/sys/net/ipv4/neigh/DEV/proxy_qlen</Term>
6078 <ListItem>
6079 <Para>
6080 Maximum queue length of the delayed proxy arp timer. (see proxy_delay).
6081 </Para></ListItem>
6082 </VarListEntry>
6083 <VarListEntry>
6084 <Term>/proc/sys/net/ipv4/neigh/DEV/retrans_time</Term>
6085 <ListItem>
6086 <Para>
6087 The time,  expressed  in  jiffies  (1/100 sec), between retransmitted Neighbor
6088 Solicitation messages.  Used  for  address  resolution  and  to determine if a
6089 neighbor is unreachable.
6090 </Para></ListItem>
6091 </VarListEntry>
6092 <VarListEntry>
6093 <Term>/proc/sys/net/ipv4/neigh/DEV/ucast_solicit</Term>
6094 <ListItem>
6095 <Para>
6096 Maximum number of retries for unicast solicitation.
6097 </Para></ListItem>
6098 </VarListEntry>
6099 <VarListEntry>
6100 <Term>/proc/sys/net/ipv4/neigh/DEV/unres_qlen</Term>
6101 <ListItem>
6102 <Para>
6103 Maximum queue  length  for a pending arp request - the number of packets which
6104 are accepted from other layers while the ARP address is still resolved.
6105 </Para></ListItem>
6106 </VarListEntry>
6107 <VarListEntry>
6108 <Term>Internet QoS: Architectures and Mechanisms for Quality of Service,
6109 Zheng Wang, ISBN 1-55860-608-4</Term>
6110 <ListItem>
6111 <Para>
6112 Hardcover textbook covering topics
6113 related to Quality of Service. Good for understanding basic concepts.
6114 </Para></ListItem>
6115 </VarListEntry>
6116 </VariableList>
6117 </Para>
6119 </Sect2>
6121 <Sect2>
6122 <Title>Routing settings</Title>
6124 <Para>
6125 <VariableList>
6127 <VarListEntry>
6128 <Term>/proc/sys/net/ipv4/route/error_burst</Term>
6129 <ListItem>
6130 <Para>
6131 These parameters  are used to limit the warning messages written to the kernel
6132 log from  the  routing  code.  The  higher the error_cost factor is, the fewer
6133 messages will  be written. Error_burst controls when messages will be dropped.
6134 The default settings limit warning messages to one every five seconds.
6135 </Para></ListItem>
6136 </VarListEntry>
6137 <VarListEntry>
6138 <Term>/proc/sys/net/ipv4/route/error_cost</Term>
6139 <ListItem>
6140 <Para>
6141 These parameters  are used to limit the warning messages written to the kernel
6142 log from  the  routing  code.  The  higher the error_cost factor is, the fewer
6143 messages will  be written. Error_burst controls when messages will be dropped.
6144 The default settings limit warning messages to one every five seconds.
6145 </Para></ListItem>
6146 </VarListEntry>
6147 <VarListEntry>
6148 <Term>/proc/sys/net/ipv4/route/flush</Term>
6149 <ListItem>
6150 <Para>
6151 Writing to this file results in a flush of the routing cache.
6152 </Para></ListItem>
6153 </VarListEntry>
6154 <VarListEntry>
6155 <Term>/proc/sys/net/ipv4/route/gc_elasticity</Term>
6156 <ListItem>
6157 <Para>
6158 Values to  control  the  frequency  and  behavior  of  the  garbage collection
6159 algorithm for the routing cache. This can be important for when doing
6160 fail over. At least gc_timeout seconds will elapse before Linux will skip
6161 to another route because the previous one has died. By default set to 300,
6162 you may want to lower it if you want to have a speedy fail over.
6163 </Para>
6165 <Para>
6166 Also see <ULink
6167 URL="http://mailman.ds9a.nl/pipermail/lartc/2002q1/002667.html"
6168 >this post</ULink
6169 > by Ard van Breemen.
6170 </Para></ListItem>
6171 </VarListEntry>
6172 <VarListEntry>
6173 <Term>/proc/sys/net/ipv4/route/gc_interval</Term>
6174 <ListItem>
6175 <Para>
6176 See /proc/sys/net/ipv4/route/gc_elasticity.
6177 </Para></ListItem>
6178 </VarListEntry>
6179 <VarListEntry>
6180 <Term>/proc/sys/net/ipv4/route/gc_min_interval</Term>
6181 <ListItem>
6182 <Para>
6183 See /proc/sys/net/ipv4/route/gc_elasticity.
6184 </Para></ListItem>
6185 </VarListEntry>
6186 <VarListEntry>
6187 <Term>/proc/sys/net/ipv4/route/gc_thresh</Term>
6188 <ListItem>
6189 <Para>
6190 See /proc/sys/net/ipv4/route/gc_elasticity.
6191 </Para></ListItem>
6192 </VarListEntry>
6193 <VarListEntry>
6194 <Term>/proc/sys/net/ipv4/route/gc_timeout</Term>
6195 <ListItem>
6196 <Para>
6197 See /proc/sys/net/ipv4/route/gc_elasticity.
6198 </Para></ListItem>
6199 </VarListEntry>
6200 <VarListEntry>
6201 <Term>/proc/sys/net/ipv4/route/max_delay</Term>
6202 <ListItem>
6203 <Para>
6204 Delays for flushing the routing cache.
6205 </Para></ListItem>
6206 </VarListEntry>
6207 <VarListEntry>
6208 <Term>/proc/sys/net/ipv4/route/max_size</Term>
6209 <ListItem>
6210 <Para>
6211 Maximum size  of  the routing cache. Old entries will be purged once the cache
6212 reached has this size.
6213 </Para></ListItem>
6214 </VarListEntry>
6215 <VarListEntry>
6216 <Term>/proc/sys/net/ipv4/route/min_adv_mss</Term>
6217 <ListItem>
6218 <Para>
6219 FIXME: fill this in
6220 </Para></ListItem>
6221 </VarListEntry>
6222 <VarListEntry>
6223 <Term>/proc/sys/net/ipv4/route/min_delay</Term>
6224 <ListItem>
6225 <Para>
6226 Delays for flushing the routing cache.
6227 </Para></ListItem>
6228 </VarListEntry>
6229 <VarListEntry>
6230 <Term>/proc/sys/net/ipv4/route/min_pmtu</Term>
6231 <ListItem>
6232 <Para>
6233 FIXME: fill this in
6234 </Para></ListItem>
6235 </VarListEntry>
6236 <VarListEntry>
6237 <Term>/proc/sys/net/ipv4/route/mtu_expires</Term>
6238 <ListItem>
6239 <Para>
6240 FIXME: fill this in
6241 </Para></ListItem>
6242 </VarListEntry>
6243 <VarListEntry>
6244 <Term>/proc/sys/net/ipv4/route/redirect_load</Term>
6245 <ListItem>
6246 <Para>
6247 Factors which  determine  if  more ICMP redirects should be sent to a specific
6248 host. No  redirects  will be sent once the load limit or the maximum number of
6249 redirects has been reached.
6250 </Para></ListItem>
6251 </VarListEntry>
6252 <VarListEntry>
6253 <Term>/proc/sys/net/ipv4/route/redirect_number</Term>
6254 <ListItem>
6255 <Para>
6256 See /proc/sys/net/ipv4/route/redirect_load.
6257 </Para></ListItem>
6258 </VarListEntry>
6259 <VarListEntry>
6260 <Term>/proc/sys/net/ipv4/route/redirect_silence</Term>
6261 <ListItem>
6262 <Para>
6263 Timeout for redirects. After this period redirects will be sent again, even if
6264 this has been stopped, because the load or number limit has been reached.
6265 </Para></ListItem>
6266 </VarListEntry>
6267 </VariableList>
6268 </Para>
6270 </Sect2>
6272 </Sect1>
6274 </chapter>
6276 <chapter id="lartc.adv-qdisc">
6277   <Title>Advanced &amp; less common queueing disciplines</Title>
6279 <Para>
6280 Should you find that you have needs not addressed by the queues mentioned
6281 earlier, the kernel contains some other more specialized queues mentioned here.
6282 </Para>
6284 <Sect1 id="lartc.adv-qdisc.bfifo-pfifo">
6285   <Title><literal>bfifo</literal>/<literal>pfifo</literal></Title>
6287 <Para>
6288 These classless queues are even simpler than pfifo_fast in that they lack
6289 the internal bands - all traffic is really equal. They have one important
6290 benefit though, they have some statistics. So even if you don't need shaping
6291 or prioritizing, you can use this qdisc to determine the backlog on your
6292 interface.
6293 </Para>
6295 <Para>
6296 pfifo has a length measured in packets, bfifo in bytes. 
6297 </Para>
6299 <Sect2>
6300 <Title>Parameters &amp; usage</Title>
6302 <Para>
6303 <VariableList>
6305 <VarListEntry>
6306 <Term>limit</Term>
6307 <ListItem>
6308 <Para>
6309 Specifies the length of the queue. Measured in bytes for bfifo, in packets
6310 for pfifo. Defaults to the interface txqueuelen (see pfifo_fast chapter)
6311 packets long or txqueuelen*mtu bytes for bfifo.
6312 </Para></ListItem>
6313 </VarListEntry>
6314 </VariableList>
6315 </Para>
6317 </Sect2>
6319 </Sect1>
6321 <Sect1 id="lartc.adv-qdisc.csz">
6322   <Title>Clark-Shenker-Zhang algorithm (CSZ)</Title>
6324 <Para>
6325 This is so theoretical that not even Alexey (the main CBQ author) claims to
6326 understand it. From his source:
6327 </Para>
6329 <blockquote>
6330 <Para>
6331 David D. Clark, Scott Shenker and Lixia Zhang
6332 <citetitle>Supporting Real-Time Applications in an Integrated Services Packet
6333 Network: Architecture and Mechanism</citetitle>.
6334 </Para>
6336 <Para>
6337 As I understand it, the main idea is to create WFQ flows for each guaranteed
6338 service and to allocate the rest of bandwith to dummy flow-0. Flow-0
6339 comprises the predictive services and the best effort traffic; it is handled
6340 by a priority scheduler with the highest priority band allocated for
6341 predictive services, and the rest --- to the best effort packets.
6342 </Para>
6344 <Para>
6345 Note that in CSZ flows are NOT limited to their bandwidth.  It is supposed
6346 that the flow passed admission control at the edge of the QoS network and it
6347 doesn't need further shaping. Any attempt to improve the flow or to shape it
6348 to a token bucket at intermediate hops will introduce undesired delays and
6349 raise jitter.
6350 </Para>
6352 <Para>
6353 At the moment CSZ is the only scheduler that provides true guaranteed
6354 service. Another schemes (including CBQ) do not provide guaranteed delay and
6355 randomize jitter."
6356 </Para>
6358 <Para>
6359 Does not currently seem like a good candidate to use, unless you've read and
6360 understand the article mentioned.
6361 </Para>
6362 </blockquote>
6364 </Sect1>
6366 <Sect1 id="lartc.adv-qdisc.dsmark"
6367   xreflabel="DSMARK">
6368   <Title>DSMARK</Title>
6370   <abstract>
6371     <Para>
6372       <author><firstname>Esteve</firstname><surname>Camps</surname></author>
6373       <address><email>marvin@grn.es</email></address>
6374       This text is an extract from my thesis on
6375       <citetitle>QoS Support in Linux</citetitle>, September 2000.
6376     </Para>
6377   </abstract>
6379 <Para>Source documents:
6380 </para>
6382 <ItemizedList>
6383 <ListItem>
6384   <Para>
6385     <ULink URL="ftp://icaftp.epfl.ch/pub/linux/diffserv/misc/dsid-01.txt.gz">
6386       Draft-almesberger-wajhak-diffserv-linux-01.txt</ULink>.
6387   </Para>
6388 </ListItem>
6389 <ListItem>
6390   <Para>Examples in iproute2 distribution.
6391   </Para>
6392 </ListItem>
6393 <ListItem>
6394   <Para>
6395     <ULink URL="http://www.qosforum.com/white-papers/qosprot_v3.pdf">
6396       White Paper-QoS protocols and architectures</ULink> and
6397     <ULink URL="http://www.qosforum.com/docs/faq">
6398       IP QoS Frequently Asked Questions</ULink> both by 
6399     <citetitle>Quality of Service Forum</citetitle>.
6400   </Para>
6401 </ListItem>
6402 </ItemizedList>
6404 <Para>
6405 This chapter was written by Esteve Camps &lt;esteve@hades.udg.es&gt;.
6406 </Para>
6408 <Sect2>
6409 <Title>Introduction</Title>
6411 <Para>
6412 First of all, first of all, it would be a great idea for you to read RFCs
6413 written about this (RFC2474, RFC2475, RFC2597 and RFC2598) at 
6414 <ULink URL="http://www.ietf.org/html.charters/diffserv-charter.html">
6415   IETF DiffServ working Group web site</ULink> and
6416 <ULink URL="http://diffserv.sf.net/">
6417   Werner Almesberger web site</ULink>
6418 (he wrote the code to support Differentiated Services on Linux).
6419 </Para>
6421 </Sect2>
6423 <Sect2>
6424 <Title>What is Dsmark related to?</Title>
6426 <Para>
6427 Dsmark is a queueing discipline that offers the capabilities needed in
6428 Differentiated Services (also called DiffServ or, simply, DS). DiffServ is
6429 one of two actual QoS architectures (the other one is called Integrated
6430 Services) that is based on a value carried by packets in the DS field of the
6431 IP header.
6432 </Para>
6434 <Para>
6435 One of the first solutions in IP designed to offer some QoS level was
6436 the Type of Service field (TOS byte) in IP header. By changing that value,
6437 we could choose a high/low level of throughput, delay or reliability.
6438 But this didn't provide sufficient flexibility to the needs of new
6439 services (such as real-time applications, interactive applications and
6440 others). After this, new architectures appeared. One of these was DiffServ
6441 which kept TOS bits and renamed DS field.
6442 </Para>
6444 </Sect2>
6446 <Sect2>
6447 <Title>Differentiated Services guidelines</Title>
6449 <Para>
6450 Differentiated Services is group-oriented. I mean, we don't know anything
6451 about flows (this will be the Integrated Services purpose); we know about
6452 flow aggregations and we will apply different behaviours depending on which
6453 aggregation a packet belongs to.
6454 </Para>
6456 <Para>
6457 When a packet arrives to an edge node (entry node to a DiffServ domain)
6458 entering to a DiffServ Domain we'll have to policy, shape and/or mark those
6459 packets (marking refers to assigning a value to the DS field. It's just like the
6460 cows :-) ). This will be the mark/value that the internal/core nodes on our
6461 DiffServ Domain will look at to determine which behaviour or QoS level
6462 apply.
6463 </Para>
6465 <Para>
6466 As you can deduce, Differentiated Services involves a domain on which
6467 all DS rules will have to be applied. In fact you can think I
6468 will classify all the packets entering my domain. Once they enter my
6469 domain they will be subjected to the rules that my classification dictates
6470 and every traversed node will apply that QoS level.
6471 </Para>
6473 <Para>
6474 In fact, you can apply your own policies into your local domains, but some
6475 <Emphasis>Service Level Agreements</Emphasis> should be considered when connecting to
6476 other DS domains.
6477 </Para>
6479 <Para>
6480 At this point, you maybe have a lot of questions. DiffServ is more than I've
6481 explained. In fact, you can understand that I can not resume more than 3
6482 RFCs in just 50 lines :-).
6483 </Para>
6485 </Sect2>
6487 <Sect2>
6488 <Title>Working with Dsmark</Title>
6490 <Para>
6491 As the DiffServ bibliography specifies, we differentiate boundary nodes and
6492 interior nodes. These are two important points in the traffic path. Both
6493 types perform a classification when the packets arrive. Its result may be
6494 used in different places along the DS process before the packet is released
6495 to the network. It's just because of this that the diffserv code supplies an
6496 structure called sk_buff, including a new field called skb-&gt;tc_index
6497 where we'll store the result of initial classification that may be used in
6498 several points in DS treatment.
6499 </Para>
6501 <Para>
6502 The skb-&gt;tc_index value will be initially set by the DSMARK qdisc,
6503 retrieving it from the DS field in IP header of every received packet.
6504 Besides, cls_tcindex classifier will read all or part of skb-&gt;tcindex
6505 value and use it to select classes.
6506 </Para>
6508 <Para>
6509 But, first of all, take a look at DSMARK qdisc command and its parameters:
6511 <Screen>
6512 ... dsmark indices INDICES [ default_index DEFAULT_INDEX ] [ set_tc_index ]
6513 </Screen>
6515 What do these parameters mean?
6517 <ItemizedList>
6518 <ListItem>
6520 <Para>
6521 <Emphasis remap="bf">indices</Emphasis>: size of table of (mask,value) pairs. Maximum value is 2&circ;n, where n&gt;=0.
6522 </Para>
6523 </ListItem>
6524 <ListItem>
6526 <Para>
6527 <Emphasis remap="bf">Default_index</Emphasis>: the default table entry index if classifier finds no match.
6528 </Para>
6529 </ListItem>
6530 <ListItem>
6532 <Para>
6533 <Emphasis remap="bf">Set_tc_index</Emphasis>: instructs dsmark discipline to retrieve the DS field and store it onto skb-&gt;tc_index.
6534 </Para>
6535 </ListItem>
6537 </ItemizedList>
6539 Let's see the DSMARK process.
6540 </Para>
6542 </Sect2>
6544 <Sect2>
6545 <Title>How SCH_DSMARK works.</Title>
6547 <Para>
6548 This qdisc will apply the next steps:
6550 <ItemizedList>
6551 <ListItem>
6553 <Para>
6554 If we have declared set_tc_index option in qdisc command, DS field is retrieved and stored onto
6555 skb-&gt;tc_index variable.
6556 </Para>
6557 </ListItem>
6558 <ListItem>
6560 <Para>
6561 Classifier is invoked. The classifier will be executed and it will return a class ID that will be stored in
6562 skb-&gt;tc_index variable.If no filter matches are found, we consider the default_index option to be the
6563 classId to store. If neither set_tc_index nor default_index has been declared results may be
6564 unpredictable.
6565 </Para>
6566 </ListItem>
6567 <ListItem>
6569 <Para>
6570 After been sent to internal qdiscs where you can reuse the result of the filter, the classid returned by
6571 the internal qdisc is stored into skb-&gt;tc_index. We will use this value in the future to index a mask-
6572 value table. The final result to assign to the packet will be that resulting from next operation:
6574 <Screen>
6575 New_Ds_field = ( Old_DS_field &#38; mask ) | value
6576 </Screen>
6579 </Para>
6580 </ListItem>
6581 <ListItem>
6583 <Para>
6584 Thus, new value will result from "anding" ds_field and mask values and next, this result "ORed" with
6585 value parameter. See next diagram to understand all this process:
6586 </Para>
6587 </ListItem>
6589 </ItemizedList>
6592 <Screen>
6593                          skb-&gt;ihp-&gt;tos
6594 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - &gt;
6595      |                                                       |     ^
6596      | -- If you declare set_tc_index, we set DS             |     |  &lt;-----May change
6597      |    value into skb-&gt;tc_index variable                  |     |O       DS field
6598      |                                                      A|     |R
6599    +-|-+      +------+    +---+-+    Internal   +-+     +---N|-----|----+
6600    | | |      | tc   |---&gt;|   | |--&gt;  . . .  --&gt;| |     |   D|     |    |
6601    | | |-----&gt;|index |---&gt;|   | |     Qdisc     | |----&gt;|    v     |    |
6602    | | |      |filter|---&gt;| | | +---------------+ |   ----&gt;(mask,value) |
6603 --&gt;| O |      +------+    +-|-+--------------^----+  /  |  (.  ,  .)    |
6604    | | |          ^         |                |       |  |  (.  ,  .)    |
6605    | | +----------|---------|----------------|-------|--+  (.  ,  .)    |
6606    | | sch_dsmark |         |                |       |                  |
6607    +-|------------|---------|----------------|-------|------------------+
6608      |            |         | &lt;- tc_index -&gt; |       |
6609      |            |(read)   |    may change  |       |  &lt;--------------Index to the
6610      |            |         |                |       |                    (mask,value)
6611      v            |         v                v       |                    pairs table
6612 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -&gt;
6613                          skb-&gt;tc_index
6614 </Screen>
6616 </Para>
6618 <Para>
6619 How to do marking? Just change the mask and value of the class you want to remark. See next line of code:
6621 <Screen>
6622 tc class change dev eth0 classid 1:1 dsmark mask 0x3 value 0xb8
6623 </Screen>
6625 This changes the (mask,value) pair in hash table, to remark packets belonging to class 1:1.You have to "change" this values
6626 because of default values that (mask,value) gets initially (see table below).
6627 </Para>
6629 <Para>
6630 Now, we'll explain how TC_INDEX filter works and how fits into this. Besides, TCINDEX filter can be
6631 used in other configurations rather than those including DS services.
6632 </Para>
6634 </Sect2>
6636 <Sect2>
6637 <Title>TC_INDEX Filter</Title>
6639 <Para>
6640 This is the basic command to declare a TC_INDEX filter:
6642 <Screen>
6643 ... tcindex [ hash SIZE ] [ mask MASK ] [ shift SHIFT ]
6644             [ pass_on | fall_through ]
6645             [ classid CLASSID ] [ police POLICE_SPEC ]
6646 </Screen>
6648 Next, we show the example used to explain TC_INDEX operation mode. Pay attention to bolded words:
6651 tc qdisc add dev eth0 handle 1:0 root dsmark indices 64 <Emphasis remap="bf">set_tc_index</Emphasis>
6653 tc filter add dev eth0 parent 1:0 protocol ip prio 1 tcindex <Emphasis remap="bf">mask 0xfc  shift 2</Emphasis>
6655 tc qdisc add dev eth0 parent 1:0 handle 2:0 cbq bandwidth 10Mbit cell 8 avpkt 1000 mpu 64
6657 &num; EF traffic class
6659 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
6661 &num; Packet fifo qdisc for EF traffic
6663 tc qdisc add dev eth0 parent 2:1 pfifo limit 5
6665 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>
6669 (This code is not complete. It's just an extract from EFCBQ example included in iproute2 distribution).
6670 </Para>
6672 <Para>
6673 First of all, suppose we receive a packet marked as EF .  If you read RFC2598, you'll see that DSCP
6674 recommended value for EF traffic is 101110. This means that DS field will be 10111000 (remember that
6675 less significant bits in TOS byte are not used in DS) or 0xb8 in hexadecimal codification.
6676 </Para>
6678 <Para>
6680 <Screen>
6681               TC INDEX
6682               FILTER
6683    +---+      +-------+    +---+-+    +------+                +-+    +-------+
6684    |   |      |       |    |   | |    |FILTER|  +-+    +-+    | |    |       |
6685    |   |-----&gt;| MASK  | -&gt; |   | | -&gt; |HANDLE|-&gt;| |    | | -&gt; | | -&gt; |       |
6686    |   |  .   | =0xfc |    |   | |    |0x2E  |  | +----+ |    | |    |       |
6687    |   |  .   |       |    |   | |    +------+  +--------+    | |    |       |
6688    |   |  .   |       |    |   | |                            | |    |       |
6689 --&gt;|   |  .   | SHIFT |    |   | |                            | |    |       |--&gt;
6690    |   |  .   | =2    |    |   | +----------------------------+ |    |       |
6691    |   |      |       |    |   |       CBQ 2:0                  |    |       |
6692    |   |      +-------+    +---+--------------------------------+    |       |
6693    |   |                                                             |       |
6694    |   +-------------------------------------------------------------+       |
6695    |                          DSMARK 1:0                                     |
6696    +-------------------------------------------------------------------------+
6698 </Screen>
6700 </Para>
6702 <Para>
6703 The packet arrives, then, set with 0xb8 value at DS field. As we explained before, dsmark qdisc identified
6704 by 1:0 id in the example, retrieves DS field and store it in skb-&gt;tc_index variable.
6705 Next step in the example will correspond to the filter associated to this qdisc (second line in the example).
6706 This will perform next operations:
6708 <Screen>
6709 Value1 = skb-&#62;tc_index &#38; MASK
6710 Key = Value1 &#62;&#62; SHIFT
6711 </Screen>
6713 </Para>
6715 <Para>
6716 In the example, MASK=0xFC i SHIFT=2.
6718 <Screen>
6719 Value1 = 10111000 &#38; 11111100 = 10111000
6720 Key = 10111000 &#62;&#62; 2 = 00101110 -&#62; 0x2E in hexadecimal
6721 </Screen>
6723 </Para>
6725 <Para>
6726 The returned value will correspond to a qdisc internal filter handle (in the example, identifier 2:0). If a
6727 filter with this id exists, policing and metering conditions will be verified (in case that filter includes this)
6728 and the classid will be returned (in our example, classid 2:1) and stored in skb-&gt;tc_index variable.
6729 </Para>
6731 <Para>
6732 But if any filter with that identifier is found, the result will depend on fall_through flag declaration. If so,
6733 value key is returned as classid. If not, an error is returned and process continues with the rest filters. Be
6734 careful if you use fall_through flag; this can be done if a simple relation exists between values
6736 of skb-&gt;tc_index variable and class id's.
6737 </Para>
6739 <Para>
6740 The latest parameters to comment on are hash and pass_on. The first one
6741 relates to hash table size. Pass_on will be used to indicate that if no classid
6742 equal to the result of this filter is found, try next filter.
6743 The default action is fall_through (look at next table).
6744 </Para>
6746 <Para>
6747 Finally, let's see which possible values can be set to all this TCINDEX parameters:
6749 <Screen>
6750 TC Name                 Value           Default
6751 -----------------------------------------------------------------
6752 Hash                    1...0x10000     Implementation dependent
6753 Mask                    0...0xffff      0xffff
6754 Shift                   0...15          0
6755 Fall through / Pass_on  Flag            Fall_through
6756 Classid                 Major:minor     None
6757 Police                  .....           None
6758 </Screen>
6760 </Para>
6762 <Para>
6763 This kind of filter is very powerful. It's necessary to explore all possibilities. Besides, this filter is not only used in DiffServ configurations.
6764 You can use it as any other kind of filter.
6765 </Para>
6767 <Para>
6768 I recommend you to look at all DiffServ examples included in iproute2 distribution. I promise I will try to
6769 complement this text as soon as I can. Besides, all I have explained is the result of a lot of tests.
6770 I would thank you tell me if I'm wrong in any point.
6771 </Para>
6773 </Sect2>
6775 </Sect1>
6777 <Sect1 id="lartc.adv-qdisc.ingress">
6778   <Title>Ingress qdisc</Title>
6780 <Para>
6781 All qdiscs discussed so far are egress qdiscs. Each interface however can
6782 also have an ingress qdisc which is not used to send packets
6783 out to the network adaptor. Instead, it allows you to apply tc filters to
6784 packets coming in over the interface, regardless of whether they have a local
6785 destination or are to be forwarded.
6786 </Para>
6788 <Para>
6789 As the tc filters contain a full Token Bucket Filter implementation, and are
6790 also able to match on the kernel flow estimator, there is a lot of
6791 functionality available. This effectively allows you to police incoming
6792 traffic, before it even enters the IP stack.
6793 </Para>
6795 <Sect2>
6796 <Title>Parameters &amp; usage</Title>
6798 <Para>
6799 The ingress qdisc itself does not require any parameters. It differs from
6800 other qdiscs in that it does not occupy the root of a device. Attach it like
6801 this:
6803 <Screen>
6804 # tc qdisc add dev eth0 ingress
6805 </Screen>
6807 This allows you to have other, sending, qdiscs on your device besides the
6808 ingress qdisc. 
6809 </Para>
6811 <Para>
6812 For a contrived example how the ingress qdisc could be used, see the
6813 Cookbook.
6814 </Para>
6816 </Sect2>
6818 </Sect1>
6820 <Sect1 id="lartc.adv-qdisc.red">
6821   <Title>Random Early Detection (RED)</Title>
6823 <Para>
6824 This section is meant as an introduction to backbone routing, which often
6825 involves &lt;100 megabit bandwidths, which requires a different approach than
6826 your ADSL modem at home.
6827 </Para>
6829 <Para>
6830 The normal behaviour of router queues on the Internet is called tail-drop.
6831 Tail-drop works by queueing up to a certain amount, then dropping all traffic
6832 that 'spills over'. This is very unfair, and also leads to retransmit 
6833 synchronization. When retransmit synchronization occurs, the sudden burst
6834 of drops from a router that has reached its fill will cause a delayed burst
6835 of retransmits, which will over fill the congested router again. 
6836 </Para>
6838 <Para>
6839 In order to cope with transient congestion on links, backbone routers will
6840 often implement large queues. Unfortunately, while these queues are good for
6841 throughput, they can substantially increase latency and cause TCP
6842 connections to behave very burstily during congestion.
6843 </Para>
6845 <Para>
6846 These issues with tail-drop are becoming increasingly troublesome on the
6847 Internet because the use of network unfriendly applications is increasing.
6848 The Linux kernel offers us RED, short for Random Early Detect, also called
6849 Random Early Drop, as that is how it works.
6850 </Para>
6852 <Para>
6853 RED isn't a cure-all for this, applications which inappropriately fail to 
6854 implement exponential backoff still get an unfair share of the bandwidth,
6855 however, with RED they do not cause as much harm to the throughput and
6856 latency of other connections.
6857 </Para>
6859 <Para>
6860 RED statistically drops packets from flows before it reaches its hard
6861 limit. This causes a congested backbone link to slow more gracefully, and
6862 prevents retransmit synchronization. This also helps TCP find its 'fair'
6863 speed faster by allowing some packets to get dropped sooner keeping queue
6864 sizes low and latency under control. The probability of a packet being
6865 dropped from a particular connection is proportional to its bandwidth usage
6866 rather than the number of packets it transmits. 
6867 </Para>
6869 <Para>
6870 RED is a good queue for backbones, where you can't afford the 
6871 complexity of per-session state tracking needed by fairness queueing.
6872 </Para>
6874 <Para>
6875 In order to use RED, you must decide on three parameters: Min, Max, and
6876 burst. Min sets the minimum queue size in bytes before dropping will begin,
6877 Max is a soft maximum that the algorithm will attempt to stay under, and
6878 burst sets the maximum number of packets that can 'burst through'.
6879 </Para>
6881 <Para>
6882 You should set the min by calculating that highest acceptable base queueing 
6883 latency you wish, and multiply it by your bandwidth. For instance, on my 
6884 64kbit/s ISDN link, I might want a base queueing latency of 200ms so I set
6885 min to 1600 bytes. Setting min too small will degrade throughput and too
6886 large will degrade latency. Setting a small min is not a replacement for
6887 reducing the MTU on a slow link to improve interactive response.
6888 </Para>
6890 <Para>
6891 You should make max at least twice min to prevent synchronization. On slow
6892 links with small Min's it might be wise to make max perhaps four or
6893 more times large then min.
6894 </Para>
6896 <Para>
6897 Burst controls how the RED algorithm responds to bursts. Burst must be set
6898 larger then min/avpkt. Experimentally, I've found (min+min+max)/(3*avpkt) to
6899 work ok.
6900 </Para>
6902 <Para>
6903 Additionally, you need to set limit and avpkt. Limit is a safety value, after
6904 there are limit bytes in the queue, RED 'turns into' tail-drop. I typical set
6905 limit to eight times max. Avpkt should be your average packet size. 1000
6906 works OK on high speed Internet links with a 1500byte MTU. 
6907 </Para>
6909 <Para>
6910 Read <ULink
6911 URL="http://www.aciri.org/floyd/papers/red/red.html"
6912 >the paper on RED queueing</ULink
6913 > by Sally Floyd and Van Jacobson for technical
6914 information.
6915 </Para>
6917 </Sect1>
6919 <Sect1 id="lartc.adv-qdisc.gred">
6920 <Title>Generic Random Early Detection</Title>
6922 <Para>
6923 Not a lot is known about GRED. It looks like GRED with several internal
6924 queues, whereby the internal queue is chosen based on the Diffserv tcindex
6925 field. According to a slide found
6926 <ULink URL="http://www.davin.ottawa.on.ca/ols/img22.htm">here</ULink>,
6927 it contains the capabilities of Cisco's 'Distributed Weighted RED', as well 
6928 as Dave Clark's RIO.
6929 </Para>
6931 <Para>
6932 Each virtual queue can have its own Drop Parameters specified.
6933 </Para>
6935 <Para>
6936 FIXME: get Jamal or Werner to tell us more
6937 </Para>
6939 </Sect1>
6941 <Sect1 id="lartc.adv-qdisc.vc-atm">
6942   <Title>VC/ATM emulation</Title>
6944 <Para>
6945 This is quite a major effort by Werner Almesberger to allow you to build
6946 Virtual Circuits over TCP/IP sockets. A Virtual Circuit is a concept from
6947 ATM network theory. 
6948 </Para>
6950 <Para>
6951 For more information, see the <ULink
6952 URL="http://linux-atm.sourceforge.net/"
6953 >ATM on Linux homepage</ULink
6954 >. 
6955 </Para>
6957 </Sect1>
6959 <Sect1 id="lartc.adv-qdisc.wrr">
6960   <Title>Weighted Round Robin (WRR)</Title>
6962 <Para>
6963 This qdisc is not included in the standard kernels but can be downloaded from 
6964 <ULink URL="http://wipl-wrr.dkik.dk/wrr/">here</ULink>. 
6965 Currently the qdisc is only tested with Linux 2.2 kernels but it will 
6966 probably work with 2.4/2.5 kernels too.
6967 </Para>
6969 <Para>
6970 The WRR qdisc distributes bandwidth between its classes using the weighted 
6971 round robin scheme. That is, like the CBQ qdisc it contains classes 
6972 into which arbitrary qdiscs can be plugged. All classes which have sufficient 
6973 demand will get bandwidth proportional to the weights associated with the classes.
6974 The weights can be set manually using the <Literal remap="tt">tc</Literal> program. But they
6975 can also be made automatically decreasing for classes transferring much data.
6976 </Para>
6978 <Para>
6979 The qdisc has a built-in classifier which assigns packets coming from or 
6980 sent to different machines to different classes. Either the MAC or IP and 
6981 either source or destination addresses can be used. The MAC address can only 
6982 be used when the Linux box is acting as an ethernet bridge, however. The 
6983 classes are automatically assigned to machines based on the packets seen.
6984 </Para>
6986 <Para>
6987 The qdisc can be very useful at sites such as dorms where a lot of unrelated 
6988 individuals share an Internet connection. A set of scripts setting up a 
6989 relevant behavior for such a site is a central part of the WRR distribution.
6990 </Para>
6992 </Sect1>
6994 </chapter>
6996 <chapter id="lartc.cookbook"
6997   xreflabel="Cookbook">
6998   <Title>Cookbook</Title>
7000 <Para>
7001 This section contains 'cookbook' entries which may help you solve problems.
7002 A cookbook is no replacement for understanding however, so try and comprehend
7003 what is going on. 
7004 </Para>
7006 <Sect1 id="lartc.cookbook.sla">
7007 <Title>Running multiple sites with different SLAs</Title>
7009 <Para>
7010 You can do this in several ways. Apache has some support for this with a
7011 module, but we'll show how Linux can do this for you, and do so for other
7012 services as well. These commands are stolen from a presentation by Jamal
7013 Hadi that's referenced below.
7014 </Para>
7016 <Para>
7017 Let's say we have two customers, with http, ftp and streaming audio, and we
7018 want to sell them a limited amount of bandwidth. We do so on the server itself.
7019 </Para>
7021 <Para>
7022 Customer A should have at most 2 megabits, customer B has paid for 5
7023 megabits. We separate our customers by creating virtual IP addresses on our
7024 server.
7025 </Para>
7027 <Para>
7029 <Screen>
7030 # ip address add 188.177.166.1 dev eth0
7031 # ip address add 188.177.166.2 dev eth0
7032 </Screen>
7034 </Para>
7036 <Para>
7037 It is up to you to attach the different servers to the right IP address. All
7038 popular daemons have support for this.
7039 </Para>
7041 <Para>
7042 We first attach a CBQ qdisc to eth0:
7044 <Screen>
7045 # tc qdisc add dev eth0 root handle 1: cbq bandwidth 10Mbit cell 8 avpkt 1000 \
7046   mpu 64
7047 </Screen>
7049 </Para>
7051 <Para>
7052 We then create classes for our customers:
7053 </Para>
7055 <Para>
7057 <Screen>
7058 # tc class add dev eth0 parent 1:0 classid 1:1 cbq bandwidth 10Mbit rate \
7059   2MBit avpkt 1000 prio 5 bounded isolated allot 1514 weight 1 maxburst 21
7060 # tc class add dev eth0 parent 1:0 classid 1:2 cbq bandwidth 10Mbit rate \
7061   5Mbit avpkt 1000 prio 5 bounded isolated allot 1514 weight 1 maxburst 21
7062 </Screen>
7064 </Para>
7066 <Para>
7067 Then we add filters for our two classes:
7069 <Screen>
7070 ##FIXME: Why this line, what does it do?, what is a divisor?:
7071 ##FIXME: A divisor has something to do with a hash table, and the number of
7072 ##       buckets - ahu
7073 # tc filter add dev eth0 parent 1:0 protocol ip prio 5 handle 1: u32 divisor 1
7074 # tc filter add dev eth0 parent 1:0 prio 5 u32 match ip src 188.177.166.1
7075   flowid 1:1
7076 # tc filter add dev eth0 parent 1:0 prio 5 u32 match ip src 188.177.166.2
7077   flowid 1:2
7078 </Screen>
7080 </Para>
7082 <Para>
7083 And we're done.
7084 </Para>
7086 <Para>
7087 FIXME: why no token bucket filter? is there a default pfifo_fast fallback
7088 somewhere?
7089 </Para>
7091 </Sect1>
7093 <Sect1 id="lartc.cookbook.synflood-protect"
7094   xreflabel="Protecting your host from SYN floods">
7095   <Title>Protecting your host from SYN floods</Title>
7097 <Para>
7098 From Alexey's iproute documentation, adapted to netfilter and with more
7099 plausible paths. If you use this, take care to adjust the numbers to
7100 reasonable values for your system.
7101 </Para>
7103 <Para>
7104 If you want to protect an entire network, skip this script, which is best
7105 suited for a single host.
7106 </Para>
7108 <Para>
7109 It appears that you need the very latest version of the iproute2 tools to
7110 get this to work with 2.4.0.
7111 </Para>
7113 <Para>
7115 <Screen>
7116 #! /bin/sh -x
7118 # sample script on using the ingress capabilities
7119 # this script shows how one can rate limit incoming SYNs
7120 # Useful for TCP-SYN attack protection. You can use
7121 # IPchains to have more powerful additions to the SYN (eg 
7122 # in addition the subnet)
7124 #path to various utilities;
7125 #change to reflect yours.
7127 TC=/sbin/tc
7128 IP=/sbin/ip
7129 IPTABLES=/sbin/iptables
7130 INDEV=eth2
7132 # tag all incoming SYN packets through $INDEV as mark value 1
7133 ############################################################ 
7134 $iptables -A PREROUTING -i $INDEV -t mangle -p tcp --syn \
7135   -j MARK --set-mark 1
7136 ############################################################ 
7138 # install the ingress qdisc on the ingress interface
7139 ############################################################ 
7140 $TC qdisc add dev $INDEV handle ffff: ingress
7141 ############################################################ 
7145 # SYN packets are 40 bytes (320 bits) so three SYNs equals
7146 # 960 bits (approximately 1kbit); so we rate limit below
7147 # the incoming SYNs to 3/sec (not very useful really; but
7148 #serves to show the point - JHS
7149 ############################################################ 
7150 $TC filter add dev $INDEV parent ffff: protocol ip prio 50 handle 1 fw \
7151 police rate 1kbit burst 40 mtu 9k drop flowid :1
7152 ############################################################ 
7156 echo "---- qdisc parameters Ingress  ----------"
7157 $TC qdisc ls dev $INDEV
7158 echo "---- Class parameters Ingress  ----------"
7159 $TC class ls dev $INDEV
7160 echo "---- filter parameters Ingress ----------"
7161 $TC filter ls dev $INDEV parent ffff:
7163 #deleting the ingress qdisc
7164 #$TC qdisc del $INDEV ingress
7165 </Screen>
7167 </Para>
7169 </Sect1>
7171 <Sect1 id="lartc.cookbook.icmp-ratelimit">
7172   <Title>Rate limit ICMP to prevent dDoS</Title>
7174 <Para>
7175 Recently, distributed denial of service attacks have become a major nuisance
7176 on the Internet. By properly filtering and rate limiting your network, you can
7177 both prevent becoming a casualty or the cause of these attacks.
7178 </Para>
7180 <Para>
7181 You should filter your networks so that you do not allow non-local IP source
7182 addressed packets to leave your network. This stops people from anonymously
7183 sending junk to the Internet. 
7184 </Para>
7186 <Para>
7187 Rate limiting goes much as shown earlier. To refresh your memory, our
7188 ASCIIgram again:
7189 </Para>
7191 <Para>
7193 <Screen>
7194 [The Internet] ---&#60;E3, T3, whatever&#62;--- [Linux router] --- [Office+ISP]
7195                                       eth1          eth0
7196 </Screen>
7198 </Para>
7200 <Para>
7201 We first set up the prerequisite parts:
7202 </Para>
7204 <Para>
7206 <Screen>
7207 # tc qdisc add dev eth0 root handle 10: cbq bandwidth 10Mbit avpkt 1000
7208 # tc class add dev eth0 parent 10:0 classid 10:1 cbq bandwidth 10Mbit rate \
7209   10Mbit allot 1514 prio 5 maxburst 20 avpkt 1000
7210 </Screen>
7212 </Para>
7214 <Para>
7215 If you have 100Mbit, or more, interfaces, adjust these numbers. Now you need
7216 to determine how much ICMP traffic you want to allow. You can perform
7217 measurements with tcpdump, by having it write to a file for a while, and
7218 seeing how much ICMP passes your network. Do not forget to raise the
7219 snapshot length!
7220 </Para>
7222 <Para>
7223 If measurement is impractical, you might want to choose 5&percnt; of your available
7224 bandwidth. Let's set up our class:
7226 <Screen>
7227 # tc class add dev eth0 parent 10:1 classid 10:100 cbq bandwidth 10Mbit rate \
7228   100Kbit allot 1514 weight 800Kbit prio 5 maxburst 20 avpkt 250 \
7229   bounded
7230 </Screen>
7232 </Para>
7234 <Para>
7235 This limits at 100Kbit. Now we need a filter to assign ICMP traffic to this
7236 class:
7238 <Screen>
7239 # tc filter add dev eth0 parent 10:0 protocol ip prio 100 u32 match ip
7240   protocol 1 0xFF flowid 10:100
7242 </Screen>
7244 </Para>
7246 </Sect1>
7248 <Sect1 id="lartc.cookbook.interactive-prio">
7249 <Title>Prioritizing interactive traffic</Title>
7251 <Para>
7252 If lots of data is coming down your link, or going up for that matter, and
7253 you are trying to do some maintenance via telnet or ssh, this may not go too
7254 well. Other packets are blocking your keystrokes. Wouldn't it be great if
7255 there were a way for your interactive packets to sneak past the bulk
7256 traffic? Linux can do this for you!
7257 </Para>
7259 <Para>
7260 As before, we need to handle traffic going both ways. Evidently, this works
7261 best if there are Linux boxes on both ends of your link, although other
7262 UNIX's are able to do this. Consult your local Solaris/BSD guru for this.
7263 </Para>
7265 <Para>
7266 The standard pfifo_fast scheduler has 3 different 'bands'. Traffic in band 0
7267 is transmitted first, after which traffic in band 1 and 2 gets considered.
7268 It is vital that our interactive traffic be in band 0!
7269 </Para>
7271 <Para>
7272 We blatantly adapt from the (soon to be obsolete) ipchains HOWTO:
7273 </Para>
7275 <Para>
7276 There are four seldom-used bits in the IP header, called the Type of Service
7277 (TOS) bits. They effect the way packets are treated; the four bits are
7278 "Minimum Delay", "Maximum Throughput", "Maximum Reliability" and "Minimum
7279 Cost". Only one of these bits is allowed to be set. Rob van Nieuwkerk, the
7280 author of the ipchains TOS-mangling code, puts it as follows:
7281 </Para>
7283 <Para>
7285 <Screen>
7286 Especially the "Minimum Delay" is important for me. I switch it on for
7287 "interactive" packets in my upstream (Linux) router. I'm
7288 behind a 33k6 modem link. Linux prioritizes packets in 3 queues. This
7289 way I get acceptable interactive performance while doing bulk
7290 downloads at the same time. 
7291 </Screen>
7293 </Para>
7295 <Para>
7296 The most common use is to set telnet &#38; ftp control connections to "Minimum
7297 Delay" and FTP data to "Maximum Throughput". This would be
7298 done as follows, on your upstream router:
7299 </Para>
7301 <Para>
7303 <Screen>
7304 # iptables -A PREROUTING -t mangle -p tcp --sport telnet \
7305   -j TOS --set-tos Minimize-Delay
7306 # iptables -A PREROUTING -t mangle -p tcp --sport ftp \
7307   -j TOS --set-tos Minimize-Delay
7308 # iptables -A PREROUTING -t mangle -p tcp --sport ftp-data \
7309   -j TOS --set-tos Maximize-Throughput
7310 </Screen>
7312 </Para>
7314 <Para>
7315 Now, this only works for data going from your telnet foreign host to your
7316 local computer. The other way around appears to be done for you, ie, telnet,
7317 ssh &#38; friends all set the TOS field on outgoing packets automatically.
7318 </Para>
7320 <Para>
7321 Should you have an application that does not do this, you can always do it 
7322 with netfilter. On your local box:
7323 </Para>
7325 <Para>
7327 <Screen>
7328 # iptables -A OUTPUT -t mangle -p tcp --dport telnet \
7329   -j TOS --set-tos Minimize-Delay
7330 # iptables -A OUTPUT -t mangle -p tcp --dport ftp \
7331   -j TOS --set-tos Minimize-Delay
7332 # iptables -A OUTPUT -t mangle -p tcp --dport ftp-data \
7333   -j TOS --set-tos Maximize-Throughput
7334 </Screen>
7336 </Para>
7338     </Sect1>
7340     <Sect1 id="lartc.cookbook.squid">
7341       <Title>Transparent web-caching using <application>netfilter</application>,
7342         <application>iproute2</application>, <application>ipchains</application> and 
7343         <application>squid</application></Title>
7344       
7345       <Para>
7346         This section was sent in by reader Ram Narula from Internet for Education
7347         (Thailand).
7348       </Para>
7349       
7350       <Para>
7351         The regular technique in accomplishing this in Linux
7352         is probably with use of ipchains AFTER making sure
7353         that the "outgoing" port 80(web) traffic gets routed through
7354         the server running squid.
7355       </Para>
7357       <Para>
7358         There are 3 common methods to make sure "outgoing"
7359         port 80 traffic gets routed to the server running squid
7360         and 4th one is being introduced here.
7361       </Para>
7362       
7363       <Para>
7364         <VariableList>
7365           <VarListEntry>
7366             <Term>Making the gateway router do it.</Term>
7367             <ListItem>
7368               <Para>
7369                 If you can tell your gateway router to 
7370                 match packets that has outgoing destination port
7371                 of 80 to be sent to the IP address of squid server.
7372               </Para>
7373               
7374               <Para>
7375                 BUT
7376               </Para>
7378               <Para>
7379                 This would put additional load on the router and
7380                 some commercial routers might not even support this.
7381               </Para>
7382             </ListItem>
7383           </VarListEntry>
7384           <VarListEntry>
7385             <Term>Using a Layer 4 switch.</Term>
7386             <ListItem>
7387               <Para>
7388                 Layer 4 switches can handle this without any problem.
7389               </Para>
7390               
7391               <Para>
7392                 BUT
7393               </Para>
7394               
7395               <Para>
7396                 The cost for this equipment is usually very high. Typical
7397                 layer 4 switch would normally cost more than
7398                 a typical router+good linux server.
7399               </Para>
7400             </ListItem>
7401           </VarListEntry>
7402           <VarListEntry>
7403             <Term>Using cache server as network's gateway.</Term>
7404             <ListItem>
7405               <Para>
7406                 You can force ALL traffic through cache server.
7407               </Para>
7408               <Para>
7409                 BUT
7410               </Para>
7411               <Para>
7412                 This is quite risky because Squid does utilize lots of CPU power which might
7413                 result in slower over-all network performance or the server itself might crash and no one on the
7414                 network will be able to access the Internet if that occurs.
7415               </Para>
7416             </ListItem>
7417           </VarListEntry>
7418           <VarListEntry>
7419             <Term>Linux+NetFilter router.</Term>
7420             <ListItem>
7421               <Para>
7422                 By using NetFilter another technique can be implemented
7423                 which is using NetFilter for "mark"ing the packets
7424                 with destination port 80 and using iproute2 to
7425                 route the "mark"ed packets to the Squid server.
7426               </Para>
7427             </ListItem>
7428           </VarListEntry>
7429         </VariableList>
7430         <Screen>
7431 |----------------|
7432 | Implementation |
7433 |----------------|
7435  Addresses used
7436  10.0.0.1 naret (NetFilter server)
7437  10.0.0.2 silom (Squid server)
7438  10.0.0.3 donmuang (Router connected to the Internet)
7439  10.0.0.4 kaosarn (other server on network)
7440  10.0.0.5 RAS
7441  10.0.0.0/24 main network
7442  10.0.0.0/19 total network
7444 |---------------|
7445 |Network diagram|
7446 |---------------|
7448 Internet
7450 donmuang
7452 ------------hub/switch----------
7453 |        |             |       |
7454 naret   silom        kaosarn  RAS etc.
7455         </Screen>
7457         First, make all traffic pass through naret by making sure it is the default gateway except for silom.
7458         Silom's default gateway has to be donmuang (10.0.0.3) or this would create web traffic loop.
7459       </Para>
7460       <Para>
7461         (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
7462         was changed the IP address of donmuang to 10.0.0.3 and gave naret ip address of 10.0.0.1)
7463       </Para>
7464       <Para>
7465         <Screen>
7466 Silom
7467 -----
7468 -setup squid and ipchains 
7469         </Screen>
7470       </Para>
7471       <Para>
7472         Setup Squid server on silom, make sure it does support  transparent caching/proxying, the default port is usually
7473         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:
7474       </Para>
7475       <Para>
7476         <Screen>
7477 silom# ipchains -N allow1
7478 silom# ipchains -A allow1 -p TCP -s 10.0.0.0/19 -d 0/0 80 -j REDIRECT 3128
7479 silom# ipchains -I input -j allow1
7480         </Screen>
7481       </Para>
7482       <Para>
7483 Or, in netfilter lingo:
7484         <Screen>
7485 silom# iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
7486         </Screen>
7487       </Para>
7488       <Para>
7489         (note: you might have other entries as well)
7490       </Para>
7491       <Para>
7492         For more information on setting Squid server please refer to Squid FAQ page on <ULink
7493           URL="http://squid.nlanr.net">http://squid.nlanr.net</ULink>).
7494       </Para>
7495       <Para>
7496         Make sure ip forwarding is enabled on this server and the default gateway for this server is donmuang router (NOT naret).
7497       </Para>
7498       <Para>
7499         <Screen>
7500 Naret
7501 -----
7502 -setup iptables and iproute2
7503 -disable icmp REDIRECT messages (if needed)
7504         </Screen>
7505       </Para>
7506       <Para>
7507         <OrderedList>
7508           <ListItem>
7509             <Para>
7510               "Mark" packets of destination port 80 with value 2
7511               <Screen>
7512 naret# iptables -A PREROUTING -i eth0 -t mangle -p tcp --dport 80 \
7513  -j MARK --set-mark 2
7514               </Screen>
7515             </Para>
7516           </ListItem>
7517           <ListItem>
7518             <Para>
7519               Setup iproute2 so it will route packets with "mark" 2 to silom
7520               <Screen>
7521 naret# echo 202 www.out &#62;&#62; /etc/iproute2/rt_tables
7522 naret# ip rule add fwmark 2 table www.out
7523 naret# ip route add default via 10.0.0.2 dev eth0 table www.out
7524 naret# ip route flush cache
7525               </Screen>
7526             </para>
7527             <Para>
7528               If donmuang and naret is on the same subnet then naret should not send out icmp REDIRECT messages.
7529               In this case it is, so icmp REDIRECTs has to be disabled by:
7530               <Screen>
7531 naret# echo 0 &#62; /proc/sys/net/ipv4/conf/all/send_redirects
7532 naret# echo 0 &#62; /proc/sys/net/ipv4/conf/default/send_redirects
7533 naret# echo 0 &#62; /proc/sys/net/ipv4/conf/eth0/send_redirects
7534               </Screen>
7535             </Para>
7536           </ListItem>
7537         </OrderedList>
7538       </Para>
7539       <Para>
7540         The setup is complete, check the configuration
7541       </Para>
7542       <Para>
7543         <Screen>
7544 On naret:
7546 naret# iptables -t mangle -L
7547 Chain PREROUTING (policy ACCEPT)
7548 target     prot opt source               destination         
7549 MARK       tcp  --  anywhere             anywhere           tcp dpt:www MARK set 0x2 
7551 Chain OUTPUT (policy ACCEPT)
7552 target     prot opt source               destination         
7554 naret# ip rule ls
7555 0:      from all lookup local 
7556 32765:  from all fwmark        2 lookup www.out 
7557 32766:  from all lookup main 
7558 32767:  from all lookup default 
7560 naret# ip route list table www.out
7561 default via 203.114.224.8 dev eth0 
7563 naret# ip route   
7564 10.0.0.1 dev eth0  scope link 
7565 10.0.0.0/24 dev eth0  proto kernel  scope link  src 10.0.0.1
7566 127.0.0.0/8 dev lo  scope link 
7567 default via 10.0.0.3 dev eth0 
7569 (make sure silom belongs to one of the above lines, in this case
7570 it's the line with 10.0.0.0/24)
7572 |------|
7573 |-DONE-|
7574 |------|
7575         </Screen>
7576       </Para>
7577       <Sect2>
7578 <Title>Traffic flow diagram after implementation</Title>
7580 <Screen width="80">
7582 |-----------------------------------------|
7583 |Traffic flow diagram after implementation|
7584 |-----------------------------------------|
7586 INTERNET
7590 -----------------donmuang router---------------------
7591 /\                                      /\         ||
7592 ||                                      ||         ||
7593 ||                                      \/         ||
7594 naret                                  silom       ||
7595 *destination port 80 traffic=========&#62;(cache)      ||
7596 /\                                      ||         ||
7597 ||                                      \/         \/
7598 \\===================================kaosarn, RAS, etc.
7600 </Screen>
7602 <Para>
7603 Note that the network is asymmetric as there is one extra hop on 
7604 general outgoing path.
7605 </Para>
7607 <Para>
7609 <Screen>
7610 Here is run down for packet traversing the network from kaosarn
7611 to and from the Internet.
7613 For web/http traffic:
7614 kaosarn http request-&#62;naret-&#62;silom-&#62;donmuang-&#62;internet
7615 http replies from Internet-&#62;donmuang-&#62;silom-&#62;kaosarn
7617 For non-web/http requests(eg. telnet):
7618 kaosarn outgoing data-&#62;naret-&#62;donmuang-&#62;internet
7619 incoming data from Internet-&#62;donmuang-&#62;kaosarn
7620 </Screen>
7622 </Para>
7624 </Sect2>
7626 </Sect1>
7628 <Sect1 id="lartc.cookbook.mtu-discovery">
7629 <Title>Circumventing Path MTU Discovery issues with per route MTU settings</Title>
7631 <Para>
7632 For sending bulk data, the Internet generally works better when using larger
7633 packets. Each packet implies a routing decision, when sending a 1 megabyte
7634 file, this can either mean around 700 packets when using packets that are as
7635 large as possible, or 4000 if using the smallest default.
7636 </Para>
7638 <Para>
7639 However, not all parts of the Internet support full 1460 bytes of payload
7640 per packet. It is therefore necessary to try and find the largest packet
7641 that will 'fit', in order to optimize a connection.
7642 </Para>
7644 <Para>
7645 This process is called 'Path MTU Discovery', where MTU stands for 'Maximum
7646 Transfer Unit.' 
7647 </Para>
7649 <Para>
7650 When a router encounters a packet that's too big too send in one piece, AND
7651 it has been flagged with the "Don't Fragment" bit, it returns an ICMP
7652 message stating that it was forced to drop a packet because of this. The
7653 sending host acts on this hint by sending smaller packets, and by iterating
7654 it can find the optimum packet size for a connection over a certain path.
7655 </Para>
7657 <Para>
7658 This used to work well until the Internet was discovered by hooligans who do
7659 their best to disrupt communications. This in turn lead administrators to
7660 either block or shape ICMP traffic in a misguided attempt to improve
7661 security or robustness of their Internet service.
7662 </Para>
7664 <Para>
7665 What has happened now is that Path MTU Discovery is working less and less
7666 well and fails for certain routes, which leads to strange TCP/IP sessions
7667 which die after a while.
7668 </Para>
7670 <Para>
7671 Although I have no proof for this, two sites who I used to have this problem
7672 with both run Alteon Acedirectors before the affected systems - perhaps
7673 somebody more knowledgeable can provide clues as to why this happens.
7674 </Para>
7676 <Sect2>
7677 <Title>Solution</Title>
7679 <Para>
7680 When you encounter sites that suffer from this problem, you can disable Path
7681 MTU discovery by setting it manually. Koos van den Hout, slightly edited,
7682 writes:
7683 </Para>
7685 <blockquote>
7686 <Para>
7687 The following problem: I set the mtu/mru of my leased line running ppp to
7688 296 because it's only 33k6 and I cannot influence the queueing on the
7689 other side. At 296, the response to a key press is within a reasonable
7690 time frame.
7691 </Para>
7693 <Para>
7694 And, on my side I have a masqrouter running (of course) Linux.
7695 </Para>
7697 <Para>
7698 Recently I split 'server' and 'router' so most applications are run on a
7699 different machine than the routing happens on.
7700 </Para>
7702 <Para>
7703 I then had trouble logging into irc. Big panic! Some digging did find
7704 out that I got connected to irc, even showed up as 'connected' on irc
7705 but I did not receive the motd from irc. I checked what could be wrong
7706 and noted that I already had some previous trouble reaching certain
7707 websites related to the MTU, since I had no trouble reaching them when
7708 the MTU was 1500, the problem just showed when the MTU was set to 296.
7709 Since irc servers block about every kind of traffic not needed for their
7710 immediate operation, they also block icmp. 
7711 </Para>
7713 <Para>
7714 I managed to convince the operators of a webserver that this was the cause
7715 of a problem, but the irc server operators were not going to fix this.
7716 </Para>
7718 <Para>
7719 So, I had to make sure outgoing masqueraded traffic started with the lower
7720 mtu of the outside link. But I want local ethernet traffic to have the
7721 normal mtu (for things like nfs traffic).
7722 </Para>
7724 <Para>Solution:
7725 </Para>
7727 <Screen width="80">
7728 ip route add default via 10.0.0.1 mtu 296
7729 </Screen>
7731 <Para>
7732 (10.0.0.1 being the default gateway, the inside address of the
7733 masquerading router)
7734 </Para>
7735 </blockquote>
7737 <Para>
7738 In general, it is possible to override PMTU Discovery by setting specific
7739 routes. For example, if only a certain subnet is giving problems, this
7740 should help:
7741 </Para>
7743 <Screen width="80">
7744 ip route add 195.96.96.0/24 via 10.0.0.1 mtu 1000
7745 </Screen>
7747 </Sect2>
7749 </Sect1>
7751 <Sect1 id="lartc.cookbook.mtu-mss">
7752   <Title>Circumventing Path MTU Discovery issues with MSS Clamping
7753   (for ADSL, cable, PPPoE &amp; PPtP users)</Title>
7755 <Para>
7756 As explained above, Path MTU Discovery doesn't work as well as it should
7757 anymore. If you know for a fact that a hop somewhere in your network has a
7758 limited (&lt;1500) MTU, you cannot rely on PMTU Discovery finding this out.
7759 </Para>
7761 <Para>
7762 Besides MTU, there is yet another way to set the maximum packet size, the so
7763 called Maximum Segment Size. This is a field in the TCP Options part of a
7764 SYN packet.
7765 </Para>
7767 <Para>
7768 Recent Linux kernels, and a few PPPoE drivers (notably, the excellent
7769 Roaring Penguin one), feature the possibility to 'clamp the MSS'. 
7770 </Para>
7772 <Para>
7773 The good thing about this is that by setting the MSS value, you are telling
7774 the remote side unequivocally 'do not ever try to send me packets bigger
7775 than this value'. No ICMP traffic is needed to get this to work.
7776 </Para>
7778 <Para>
7779 The bad thing is that it's an obvious hack - it breaks 'end to end' by
7780 modifying packets. Having said that, we use this trick in many places and it
7781 works like a charm.
7782 </Para>
7784 <Para>
7785 In order for this to work you need at least iptables-1.2.1a and Linux 2.4.3
7786 or higher. The basic command line is:
7788 <Screen>
7789 # iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS  --clamp-mss-to-pmtu
7790 </Screen>
7792 </Para>
7794 <Para>
7795 This calculates the proper MSS for your link. If you are feeling brave, or
7796 think that you know best, you can also do something like this:
7797 </Para>
7799 <Para>
7801 <Screen>
7802 # iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 128
7803 </Screen>
7805 </Para>
7807 <Para>
7808 This sets the MSS of passing SYN packets to 128. Use this if you have VoIP
7809 with tiny packets, and huge http packets which are causing chopping in your
7810 voice calls.
7811 </Para>
7813 </Sect1>
7815 <Sect1 id="lartc.cookbook.ultimate-tc">
7816 <Title>The Ultimate Traffic Conditioner: Low Latency, Fast Up &amp; Downloads</Title>
7818 <Para>
7819 Note: This script has recently been upgraded and previously only worked for
7820 Linux clients in your network! So you might want to update if you have
7821 Windows machines or Macs in your network and noticed that they were not able
7822 to download faster while others were uploading.
7823 </Para>
7825 <Para>
7826 I attempted to create the holy grail:
7827 <VariableList>
7829 <VarListEntry>
7830 <Term>Maintain low latency for interactive traffic at all times</Term>
7831 <ListItem>
7832 <Para>
7833 This means that downloading or uploading files should not disturb SSH or
7834 even telnet. These are the most important things, even 200ms latency is
7835 sluggish to work over.
7836 </Para></ListItem>
7837 </VarListEntry>
7838 <VarListEntry>
7839 <Term>Allow 'surfing' at reasonable speeds while up or downloading</Term>
7840 <ListItem>
7841 <Para>
7842 Even though http is 'bulk' traffic, other traffic should not drown it out 
7843 too much.
7844 </Para></ListItem>
7845 </VarListEntry>
7846 <VarListEntry>
7847 <Term>Make sure uploads don't harm downloads, and the other way around</Term>
7848 <ListItem>
7849 <Para>
7850 This is a much observed phenomenon where upstream traffic simply destroys
7851 download speed.
7852 </Para></ListItem>
7853 </VarListEntry>
7854 </VariableList>
7855 It turns out that all this is possible, at the cost of a tiny bit of
7856 bandwidth. The reason that uploads, downloads and ssh hurt each other is the
7857 presence of large queues in many domestic access devices like cable or DSL
7858 modems.
7859 </Para>
7861 <Para>
7862 The next section explains in depth what causes the delays, and how we can
7863 fix them. You can safely skip it and head straight for the script if you
7864 don't care how the magic is performed.
7865 </Para>
7867 <Sect2>
7868 <Title>Why it doesn't work well by default</Title>
7870 <Para>
7871 ISPs know that they are benchmarked solely on how fast people can download.
7872 Besides available bandwidth, download speed is influenced heavily by packet
7873 loss, which seriously hampers TCP/IP performance. Large queues can help
7874 prevent packet loss, and speed up downloads. So ISPs configure large queues.
7875 </Para>
7877 <Para>
7878 These large queues however damage interactivity. A keystroke must first
7879 travel the upstream queue, which may be seconds (!) long and go to your
7880 remote host. It is then displayed, which leads to a packet coming back, which
7881 must then traverse the downstream queue, located at your ISP, before it
7882 appears on your screen.
7883 </Para>
7885 <Para>
7886 This HOWTO teaches you how to mangle and process the queue in many ways, but
7887 sadly, not all queues are accessible to us. The queue over at the ISP is
7888 completely off-limits, whereas the upstream queue probably lives inside your
7889 cable modem or DSL device. You may or may not be able to configure it. Most
7890 probably not.
7891 </Para>
7893 <Para>
7894 So, what next? As we can't control either of those queues, they must be
7895 eliminated, and moved to your Linux router. Luckily this is possible.
7896 </Para>
7898 <Para>
7899 <VariableList>
7901 <VarListEntry>
7902 <Term>Limit upload speed</Term>
7903 <ListItem>
7904 <Para>
7905 By limiting our upload speed to slightly less than the truly available rate,
7906 no queues are built up in our modem. The queue is now moved to Linux.
7907 </Para></ListItem>
7908 </VarListEntry>
7909 <VarListEntry>
7910 <Term>Limit download speed</Term>
7911 <ListItem>
7912 <Para>
7913 This is slightly trickier as we can't really influence how fast the internet
7914 ships us data. We can however drop packets that are coming in too fast,
7915 which causes TCP/IP to slow down to just the rate we want. Because we don't 
7916 want to drop traffic unnecessarily, we configure a 'burst' size we allow at
7917 higher speed.
7918 </Para></ListItem>
7919 </VarListEntry>
7920 </VariableList>
7921 </Para>
7923 <Para>
7924 Now, once we have done this, we have eliminated the downstream queue totally
7925 (except for short bursts), and gain the ability to manage the upstream queue
7926 with all the power Linux offers.
7927 </Para>
7929 <Para>
7930 What remains to be done is to make sure interactive traffic jumps to the
7931 front of the upstream queue. To make sure that uploads don't hurt downloads,
7932 we also move ACK packets to the front of the queue. This is what normally
7933 causes the huge slowdown observed when generating bulk traffic both ways.
7934 The ACKnowledgements for downstream traffic must compete with upstream
7935 traffic, and get delayed in the process.
7936 </Para>
7938 <Para>
7939 If we do all this we get the following measurements using an excellent ADSL
7940 connection from xs4all in the Netherlands:
7941 </Para>
7943 <Para>
7945 <Screen>
7946 Baseline latency:
7947 round-trip min/avg/max = 14.4/17.1/21.7 ms
7949 Without traffic conditioner, while downloading:
7950 round-trip min/avg/max = 560.9/573.6/586.4 ms
7952 Without traffic conditioner, while uploading:
7953 round-trip min/avg/max = 2041.4/2332.1/2427.6 ms
7955 With conditioner, during 220kbit/s upload:
7956 round-trip min/avg/max = 15.7/51.8/79.9 ms
7958 With conditioner, during 850kbit/s download:
7959 round-trip min/avg/max = 20.4/46.9/74.0 ms
7961 When uploading, downloads proceed at ~80% of the available speed. Uploads
7962 at around 90%. Latency then jumps to 850 ms, still figuring out why.
7963 </Screen>
7965 </Para>
7967 <Para>
7968 What you can expect from this script depends a lot on your actual uplink
7969 speed. When uploading at full speed, there will always be a single packet
7970 ahead of your keystroke. That is the lower limit to the latency you can
7971 achieve - divide your MTU by your upstream speed to calculate. Typical
7972 values will be somewhat higher than that. Lower your MTU for better effects!
7973 </Para>
7975 <Para>
7976 Next, two versions of this script, one with Devik's excellent HTB, the other
7977 with CBQ which is in each Linux kernel, unlike HTB. Both are tested and work
7978 well.
7979 </Para>
7981 </Sect2>
7983 <Sect2>
7984 <Title>The actual script (CBQ)</Title>
7986 <Para>
7987 Works on all kernels. Within the CBQ
7988 qdisc we place two Stochastic Fairness Queues that make sure that multiple
7989 bulk streams don't drown each other out.
7990 </Para>
7992 <Para>
7993 Downstream traffic is policed using a tc filter containing a Token Bucket
7994 Filter.
7995 </Para>
7997 <Para>
7998 You might improve on this script by adding 'bounded' to the line that starts
7999 with 'tc class add .. classid 1:20'. If you lowered your MTU, also lower the
8000 allot &amp; avpkt numbers!
8001 </Para>
8003 <Para>
8005 <Screen>
8006 #!/bin/bash 
8008 # The Ultimate Setup For Your Internet Connection At Home
8011 # Set the following values to somewhat less than your actual download
8012 # and uplink speed. In kilobits
8013 DOWNLINK=800
8014 UPLINK=220
8015 DEV=ppp0
8017 # clean existing down- and uplink qdiscs, hide errors
8018 tc qdisc del dev $DEV root    2&#62; /dev/null &#62; /dev/null
8019 tc qdisc del dev $DEV ingress 2&#62; /dev/null &#62; /dev/null
8021 ###### uplink
8023 # install root CBQ
8025 tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 10mbit 
8027 # shape everything at $UPLINK speed - this prevents huge queues in your
8028 # DSL modem which destroy latency:
8029 # main class
8031 tc class add dev $DEV parent 1: classid 1:1 cbq rate ${UPLINK}kbit \
8032 allot 1500 prio 5 bounded isolated 
8034 # high prio class 1:10:
8036 tc class add dev $DEV parent 1:1 classid 1:10 cbq rate ${UPLINK}kbit \
8037    allot 1600 prio 1 avpkt 1000
8039 # bulk and default class 1:20 - gets slightly less traffic, 
8040 #  and a lower priority:
8042 tc class add dev $DEV parent 1:1 classid 1:20 cbq rate $[9*$UPLINK/10]kbit \
8043    allot 1600 prio 2 avpkt 1000
8045 # both get Stochastic Fairness:
8046 tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
8047 tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
8049 # start filters
8050 # TOS Minimum Delay (ssh, NOT scp) in 1:10:
8051 tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
8052       match ip tos 0x10 0xff  flowid 1:10
8054 # ICMP (ip protocol 1) in the interactive class 1:10 so we 
8055 # can do measurements &#38; impress our friends:
8056 tc filter add dev $DEV parent 1:0 protocol ip prio 11 u32 \
8057         match ip protocol 1 0xff flowid 1:10
8059 # To speed up downloads while an upload is going on, put ACK packets in
8060 # the interactive class:
8062 tc filter add dev $DEV parent 1: protocol ip prio 12 u32 \
8063    match ip protocol 6 0xff \
8064    match u8 0x05 0x0f at 0 \
8065    match u16 0x0000 0xffc0 at 2 \
8066    match u8 0x10 0xff at 33 \
8067    flowid 1:10
8069 # rest is 'non-interactive' ie 'bulk' and ends up in 1:20
8071 tc filter add dev $DEV parent 1: protocol ip prio 13 u32 \
8072    match ip dst 0.0.0.0/0 flowid 1:20
8074 ########## downlink #############
8075 # slow downloads down to somewhat less than the real speed  to prevent 
8076 # queuing at our ISP. Tune to see how high you can set it.
8077 # ISPs tend to have *huge* queues to make sure big downloads are fast
8079 # attach ingress policer:
8081 tc qdisc add dev $DEV handle ffff: ingress
8083 # filter *everything* to it (0.0.0.0/0), drop everything that's
8084 # coming in too fast:
8086 tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
8087    0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1
8088 </Screen>
8090 If you want this script to be run by ppp on connect, copy it to
8091 /etc/ppp/ip-up.d.
8092 </Para>
8094 <Para>
8095 If the last two lines give an error, update your tc tool to a newer version!
8096 </Para>
8098 </Sect2>
8100 <Sect2>
8101 <Title>The actual script (HTB)</Title>
8103 <Para>
8104 The following script achieves all goals using the wonderful HTB queue, see
8105 the relevant chapter. Well worth patching your kernel for! 
8107 <Screen>
8108 #!/bin/bash
8110 # The Ultimate Setup For Your Internet Connection At Home
8113 # Set the following values to somewhat less than your actual download
8114 # and uplink speed. In kilobits
8115 DOWNLINK=800
8116 UPLINK=220
8117 DEV=ppp0
8119 # clean existing down- and uplink qdiscs, hide errors
8120 tc qdisc del dev $DEV root    2&#62; /dev/null &#62; /dev/null
8121 tc qdisc del dev $DEV ingress 2&#62; /dev/null &#62; /dev/null
8123 ###### uplink
8125 # install root HTB, point default traffic to 1:20:
8127 tc qdisc add dev $DEV root handle 1: htb default 20
8129 # shape everything at $UPLINK speed - this prevents huge queues in your
8130 # DSL modem which destroy latency:
8132 tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit burst 6k
8134 # high prio class 1:10:
8136 tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit \
8137    burst 6k prio 1
8139 # bulk &#38; default class 1:20 - gets slightly less traffic, 
8140 # and a lower priority:
8142 tc class add dev $DEV parent 1:1 classid 1:20 htb rate $[9*$UPLINK/10]kbit \
8143    burst 6k prio 2
8145 # both get Stochastic Fairness:
8146 tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
8147 tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
8149 # TOS Minimum Delay (ssh, NOT scp) in 1:10:
8150 tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
8151       match ip tos 0x10 0xff  flowid 1:10
8153 # ICMP (ip protocol 1) in the interactive class 1:10 so we 
8154 # can do measurements &#38; impress our friends:
8155 tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
8156         match ip protocol 1 0xff flowid 1:10
8158 # To speed up downloads while an upload is going on, put ACK packets in
8159 # the interactive class:
8161 tc filter add dev $DEV parent 1: protocol ip prio 10 u32 \
8162    match ip protocol 6 0xff \
8163    match u8 0x05 0x0f at 0 \
8164    match u16 0x0000 0xffc0 at 2 \
8165    match u8 0x10 0xff at 33 \
8166    flowid 1:10
8168 # rest is 'non-interactive' ie 'bulk' and ends up in 1:20
8171 ########## downlink #############
8172 # slow downloads down to somewhat less than the real speed  to prevent 
8173 # queuing at our ISP. Tune to see how high you can set it.
8174 # ISPs tend to have *huge* queues to make sure big downloads are fast
8176 # attach ingress policer:
8178 tc qdisc add dev $DEV handle ffff: ingress
8180 # filter *everything* to it (0.0.0.0/0), drop everything that's
8181 # coming in too fast:
8183 tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
8184    0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1
8185 </Screen>
8187 </Para>
8189 <Para>
8190 If you want this script to be run by ppp on connect, copy it to
8191 /etc/ppp/ip-up.d.
8192 </Para>
8194 <Para>
8195 If the last two lines give an error, update your tc tool to a newer version!
8196 </Para>
8198 </Sect2>
8200     </Sect1>
8201     <sect1 id="lartc.ratelimit.single"><title>Rate limiting a single host or netmask</title>
8202       <para>
8203         Although this is described in stupendous details elsewhere and in our manpages, this question gets asked a lot and 
8204         happily there is a simple answer that does not need full comprehension of traffic control.
8205       </para>
8206       <para>
8207         This three line script does the trick:
8208       </para>
8209       <para>
8210         <screen>
8211           tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 10mbit 
8213           tc class add dev $DEV parent 1: classid 1:1 cbq rate 512kbit \
8214           allot 1500 prio 5 bounded isolated 
8216           tc filter add dev $DEV parent 1: protocol ip prio 16 u32 \
8217           match ip dst 195.96.96.97 flowid 1:1
8218         </screen>
8219       </para>
8220       <para>
8221         The first line installs a class based queue on your interface, and tells the kernel that for calculations,
8222         it can be assumed to be a 10mbit interface. If you get this wrong, no real harm is done. But getting it right will 
8223         make everything more precise.
8224       </para>
8225       <para>
8226         The second line creates a 512kbit class with some reasonable defaults. For details, see the cbq manpages and
8227         <xref linkend="lartc.qdisc">.
8228       </para>
8229       <para>
8230         The last line tells which traffic should go to the shaped class. Traffic not matched by this rule is NOT shaped. To make more 
8231         complicated matches (subnets, source ports, destination ports), see <xref linkend="lartc.filtering.simple">.
8232       </para>
8233       <para>
8234         If you changed anything and want to reload the script, execute 'tc qdisc del dev $DEV root' to clean up your existing
8235         configuration.
8236       </para>
8237       <para>
8238         The script can further be improved by adding a last optional line 'tc qdisc add dev $DEV parent 1:1 sfq perturb 10'. See 
8239         <xref linkend="lartc.sfq"> for details on what this does.
8240       </para>
8241     </sect1>
8242 </chapter>
8244 <chapter id="lartc.bridging">
8245   <Title>Building bridges, and pseudo-bridges with Proxy ARP</Title>
8247 <Para>
8248 Bridges are devices which can be installed in a network without any
8249 reconfiguration. A network switch is basically a many-port bridge. A bridge
8250 is often a 2-port switch. Linux does however support multiple interfaces in
8251 a bridge, making it a true switch.
8252 </Para>
8254 <Para>
8255 Bridges are often deployed when confronted with a broken network that needs
8256 to be fixed without any alterations. Because the bridge is a layer-2 device,
8257 one layer below IP, routers and servers are not aware of its existence.
8258 This means that you can transparently block or modify certain packets, or do
8259 shaping.
8260 </Para>
8262 <Para>
8263 Another good thing is that a bridge can often be replaced by a cross cable
8264 or a hub, should it break down.
8265 </Para>
8267 <Para>
8268 The bad news is that a bridge can cause great confusion unless it is very
8269 well documented. It does not appear in traceroutes, but somehow packets
8270 disappear or get changed from point A to point B ('this network is
8271 HAUNTED!'). You should also wonder if an organization that 'does not want to
8272 change anything' is doing the right thing.
8273 </Para>
8275 <Para>
8276 The Linux 2.4/2.5 bridge is documented on
8277 <ULink URL=" http://bridge.sourceforge.net/">this page</ULink>.
8278 </Para>
8280 <Sect1 id="lartc.bridging.iptables">
8281   <Title>State of bridging and iptables</Title>
8283 <Para>
8284 As of Linux 2.4.20, bridging and iptables do not 'see' each other without
8285 help. If you bridge packets from eth0 to eth1, they do not 'pass' by
8286 iptables. This means that you cannot do filtering, or NAT or mangling or
8287 whatever. In Linux 2.5.45 and higher, this is fixed.
8288 </Para>
8289 <para>
8290 You may also see 'ebtables' mentioned which is yet another project - it
8291 allows you to do wild things as MACNAT and 'brouting'. It is truly scary.
8292 </Sect1>
8294 <Sect1 id="lartc.bridging.shaping">
8295   <Title>Bridging and shaping</Title>
8297 <Para>
8298 This does work as advertised. Be sure to figure out which side each
8299 interface is on, otherwise you might be shaping outbound traffic in your
8300 internal interface, which won't work. Use tcpdump if needed.
8301 </Para>
8303 </Sect1>
8305 <Sect1 id="lartc.bridging.proxy-arp">
8306   <Title>Pseudo-bridges with Proxy-ARP</Title>
8308 <Para>
8309 If you just want to implement a Pseudo-bridge, skip down a few sections 
8310 to 'Implementing it', but it is wise to read a bit about how it works in
8311 practice.
8312 </Para>
8314 <Para>
8315 A Pseudo-bridge works a bit differently. By default, a bridge passes packets
8316 unaltered from one interface to the other. It only looks at the hardware
8317 address of packets to determine what goes where. This in turn means that you
8318 can bridge traffic that Linux does not understand, as long as it has an
8319 hardware address it does.
8320 </Para>
8322 <Para>
8323 A 'Pseudo-bridge' works differently and looks more like a hidden router than
8324 a bridge, but like a bridge, it has little impact on network design.
8325 </Para>
8327 <Para>
8328 An advantage of the fact that it is not a bridge lies in the fact that
8329 packets really pass through the kernel, and can be filtered, changed,
8330 redirected or rerouted. 
8331 </Para>
8333 <Para>
8334 A real bridge can also be made to perform these feats, but it needs special
8335 code, like the Ethernet Frame Diverter, or the above mentioned patch.
8336 </Para>
8338 <Para>
8339 Another advantage of a pseudo-bridge is that it does not pass packets it
8340 does not understand - thus cleaning your network of a lot of cruft. In cases
8341 where you need this cruft (like SAP packets, or Netbeui), use a real bridge.
8342 </Para>
8344 <Sect2>
8345 <Title>ARP &amp; Proxy-ARP</Title>
8347 <Para>
8348 When a host wants to talk to another host on the same physical network
8349 segment, it sends out an Address Resolution Protocol packet, which, somewhat
8350 simplified, reads like this 'who has 10.0.0.1, tell 10.0.0.7'. In response
8351 to this, 10.0.0.1 replies with a short 'here' packet.
8352 </Para>
8354 <Para>
8355 10.0.0.7 then sends packets to the hardware address mentioned in the 'here' 
8356 packet. It caches this hardware address for a relatively long time, and
8357 after the cache expires, it re-asks the question.
8358 </Para>
8360 <Para>
8361 When building a Pseudo-bridge, we instruct the bridge to reply to these ARP
8362 packets, which causes the hosts in the network to send its packets to the
8363 bridge. The bridge then processes these packets, and sends them to the
8364 relevant interface.
8365 </Para>
8367 <Para>
8368 So, in short, whenever a host on one side of the bridge asks for the
8369 hardware address of a host on the other, the bridge replies with a packet
8370 that says 'hand it to me'.
8371 </Para>
8373 <Para>
8374 This way, all data traffic gets transmitted to the right place, and always
8375 passes through the bridge.
8376 </Para>
8378 </Sect2>
8380 <Sect2>
8381 <Title>Implementing it</Title>
8383 <Para>
8384 In the bad old days, it used to be possible to instruct the Linux Kernel to
8385 perform 'proxy-ARP' for just any subnet. So, to configure a pseudo-bridge,
8386 you would have to specify both the proper routes to both sides of the bridge
8387 AND create matching proxy-ARP rules. This is bad in that it requires a lot
8388 of typing, but also because it easily allows you to make mistakes which make
8389 your bridge respond to ARP queries for networks it does not know how to
8390 route.
8391 </Para>
8393 <Para>
8394 With Linux 2.4/2.5 (and possibly 2.2), this possibility has been withdrawn and
8395 has been replaced by a flag in the /proc directory, called 'proxy_arp'. The
8396 procedure for building a pseudo-bridge is then:
8397 </Para>
8399 <Para>
8401 <OrderedList>
8402 <ListItem>
8404 <Para>
8405 Assign an IP address to both interfaces, the 'left' and the 'right'
8407 </Para>
8408 </ListItem>
8409 <ListItem>
8411 <Para>
8412 Create routes so your machine knows which hosts reside on the left,
8413 and which on the right
8414 </Para>
8415 </ListItem>
8416 <ListItem>
8418 <Para>
8419 Turn on proxy-ARP on both interfaces, echo 1 &#62;
8420 /proc/sys/net/ipv4/conf/ethL/proxy_arp, echo 1 &#62;
8421 /proc/sys/net/ipv4/conf/ethR/proxy_arp, where L and R stand for the numbers
8422 of your interfaces on the left and on the right side
8423 </Para>
8424 </ListItem>
8426 </OrderedList>
8428 </Para>
8430 <Para>
8431 Also, do not forget to turn on the ip_forwarding flag! When converting from
8432 a true bridge, you may find that this flag was turned off as it is not
8433 needed when bridging.
8434 </Para>
8436 <Para>
8437 Another thing you might note when converting is that you need to clear the
8438 arp cache of computers in the network - the arp cache might contain old
8439 pre-bridge hardware addresses which are no longer correct.
8440 </Para>
8442 <Para>
8443 On a Cisco, this is done using the command 'clear arp-cache', under
8444 Linux, use 'arp -d ip.address'. You can also wait for the cache to expire
8445 manually, which can take rather long.
8446 </Para>
8447 <para>
8448 You can speed this up using the wonderful 'arping' tool, which on many
8449 distributions is part of the 'iputils' package. Using 'arping' you can send
8450 out unsolicited ARP messages so as to update remote arp caches. 
8451 </para>
8452 <para>
8453 This is a very powerful technique that is also used by 'black hats' to
8454 subvert your routing!
8455 </para>
8456 <note>
8457 <para>
8458 On Linux 2.4, you may need to execute 
8459 'echo 1 &gt; /proc/sys/net/ipv4/ip_nonlocal_bind' before being able to send
8460 out unsolicited ARP messages!
8461 </para>
8462 </note>
8463 <Para>
8464 You may also discover that your network was misconfigured if you are/were of
8465 the habit of specifying routes without netmasks. To explain, some versions
8466 of route may have guessed your netmask right in the past, or guessed wrong
8467 without you noticing. When doing surgical routing like described above, it
8468 is *vital* that you check your netmasks! 
8469 </Para>
8471 </Sect2>
8473 </Sect1>
8475 </chapter>
8477 <chapter id="lartc.dynamic-routing">
8478   <Title>Dynamic routing - OSPF and BGP</Title>
8480 <Para>
8481 Once your network starts to get really big, or you start to consider 'the
8482 internet' as your network, you need tools which dynamically route your data.
8483 Sites are often connected to each other with multiple links, and more are
8484 popping up all the time. 
8485 </Para>
8487 <Para>
8488 The Internet has mostly standardized on OSPF and BGP4 (rfc1771).
8489 Linux supports both, by way of <application>gated</application> and 
8490 <application>zebra</application>
8491 </Para>
8493 <Para>
8494 While currently not within the scope of this document, we would like to
8495 point you to the definitive works:
8496 </Para>
8498 <Para>
8499 Overview:
8500 </Para>
8502 <Para>
8503 Cisco Systems
8504 <ULink
8505 URL="http://www.cisco.com/univercd/cc/td/doc/cisintwk/idg4/nd2003.htm"
8506 >Designing large-scale IP Internetworks</ULink
8508 </Para>
8510 <Para>
8511 For OSPF:
8512 </Para>
8514 <Para>
8515 Moy, John T.
8516 "OSPF.  The anatomy of an Internet routing protocol"
8517 Addison Wesley. Reading, MA. 1998.
8518 </Para>
8520 <Para>
8521 Halabi has also written a good guide to OSPF routing design, but this
8522 appears to have been dropped from the Cisco web site.
8523 </Para>
8525 <Para>
8526 For BGP:
8527 </Para>
8529 <Para>
8530 Halabi, Bassam
8531 "Internet routing architectures"
8532 Cisco Press (New Riders Publishing). Indianapolis, IN. 1997.
8533 </Para>
8535 <Para>
8536 also
8537 </Para>
8539 <Para>
8540 Cisco Systems
8541 </Para>
8543 <Para>
8544 <ULink
8545 URL="http://www.cisco.com/univercd/cc/td/doc/cisintwk/ics/icsbgp4.htm"
8546 >Using the Border Gateway Protocol for interdomain routing</ULink
8548 </Para>
8550 <Para>
8551 Although the examples are Cisco-specific, they are remarkably similar
8552 to the configuration language in Zebra :-)
8553 </Para>
8555 </chapter>
8557 <chapter id="lartc.other"
8558   xreflabel="Other possibilities">
8559   <Title>Other possibilities</Title>
8561 <Para>
8562 This chapter is a list of projects having to do with advanced Linux routing
8563 &amp; traffic shaping. Some of these links may deserve chapters of their
8564 own, some are documented very well of themselves, and don't need more HOWTO.
8565 </Para>
8567 <Para>
8568 <VariableList>
8570 <VarListEntry>
8571 <Term>802.1Q VLAN Implementation for Linux <ULink
8572 URL="http://scry.wanfear.com/~greear/vlan.html"
8573 >(site)</ULink
8574 ></Term>
8575 <ListItem>
8576 <Para>
8577 VLANs are a very cool way to segregate your
8578 networks in a more virtual than physical way. Good information on VLANs can
8579 be found <ULink
8580 URL="ftp://ftp.netlab.ohio-state.edu/pub/jain/courses/cis788-97/virtual_lans/index.htm"
8581 >here</ULink
8582 >. With this implementation, you can have your Linux box talk
8583 VLANs with machines like Cisco Catalyst, 3Com: &lcub;Corebuilder, Netbuilder II,
8584 SuperStack II switch 630&rcub;, Extreme Ntwks Summit 48, Foundry: &lcub;ServerIronXL,
8585 FastIron&rcub;.
8586 </Para>
8588 <Para>
8589 A great HOWTO about VLANs can be found <ULink
8590 URL="http://scry.wanfear.com/~greear/vlan/cisco_howto.html"
8591 >here</ULink
8593 </Para>
8595 <Para>
8596 Update: has been included in the kernel as of 2.4.14 (perhaps 13).
8597 </Para></ListItem>
8598 </VarListEntry>
8599 <VarListEntry>
8600 <Term>Alternate 802.1Q VLAN Implementation for Linux <ULink
8601 URL="http://vlan.sourceforge.net "
8602 >(site)</ULink
8603 ></Term>
8604 <ListItem>
8605 <Para>
8606 Alternative VLAN implementation for linux. This project was started out of
8607 disagreement with the 'established' VLAN project's architecture and coding
8608 style, resulting in a cleaner overall design.
8609 </Para></ListItem>
8610 </VarListEntry>
8611 <VarListEntry>
8612 <Term>Linux Virtual Server <ULink
8613 URL="http://www.LinuxVirtualServer.org/"
8614 >(site)</ULink
8615 ></Term>
8616 <ListItem>
8617 <Para>
8618 These people are brilliant. The Linux Virtual Server is a highly scalable and
8619 highly available server built on a cluster of real servers, with the load
8620 balancer running on the Linux operating system. The architecture of the
8621 cluster is transparent to end users. End users only see a single virtual
8622 server.
8623 </Para>
8625 <Para>
8626 In short whatever you need to load balance, at whatever level of traffic, LVS
8627 will have a way of doing it. Some of their techniques are positively evil!
8628 For example, they let several machines have the same IP address on a
8629 segment, but turn off ARP on them. Only the LVS machine does ARP - it then
8630 decides which of the backend hosts should handle an incoming packet, and
8631 sends it directly to the right MAC address of the backend server. Outgoing
8632 traffic will flow directly to the router, and not via the LVS machine, which
8633 does therefor not need to see your 5Gbit/s of content flowing to the world,
8634 and cannot be a bottleneck.
8635 </Para>
8637 <Para>
8638 The LVS is implemented as a kernel patch in Linux 2.0 and 2.2, but as a
8639 Netfilter module in 2.4/2.5, so it does not need kernel patches! Their 2.4
8640 support is still in early development, so beat on it and give feedback or
8641 send patches.
8642 </Para></ListItem>
8643 </VarListEntry>
8644 <VarListEntry>
8645 <Term>CBQ.init <ULink
8646 URL="ftp://ftp.equinox.gu.net/pub/linux/cbq/"
8647 >(site)</ULink
8648 ></Term>
8649 <ListItem>
8650 <Para>
8651 Configuring CBQ can be a bit daunting, especially if all you want to do is
8652 shape some computers behind a router. CBQ.init can help you configure Linux
8653 with a simplified syntax.
8654 </Para>
8656 <Para>
8657 For example, if you want all computers in your 192.168.1.0/24 subnet
8658 (on 10mbit eth1) to be limited to 28kbit/s download speed, put
8659 this in the CBQ.init configuration file:
8660 </Para>
8662 <Para>
8664 <Screen>
8665 DEVICE=eth1,10Mbit,1Mbit
8666 RATE=28Kbit
8667 WEIGHT=2Kbit
8668 PRIO=5
8669 RULE=192.168.1.0/24
8670 </Screen>
8672 </Para>
8674 <Para>
8675 By all means use this program if the 'how and why' don't interest you.
8676 We're using CBQ.init in production and it works very well. It can even do
8677 some more advanced things, like time dependent shaping. The documentation is
8678 embedded in the script, which explains why you can't find a README.
8679 </Para></ListItem>
8680 </VarListEntry>
8681 <VarListEntry>
8682 <Term>Chronox easy shaping scripts <ULink
8683 URL="http://www.chronox.de"
8684 >(site)</ULink
8685 ></Term>
8686 <ListItem>
8687 <Para>
8688 Stephan Mueller (smueller@chronox.de) wrote two useful scripts, 'limit.conn'
8689 and 'shaper'. The first one allows you to easily throttle a single download
8690 session, like this:
8691 </Para>
8693 <Para>
8695 <Screen>
8696 # limit.conn -s SERVERIP -p SERVERPORT -l LIMIT
8697 </Screen>
8699 </Para>
8701 <Para>
8702 It works on Linux 2.2 and 2.4/2.5.
8703 </Para>
8705 <Para>
8706 The second script is more complicated, and can be used to make lots of
8707 different queues based on iptables rules, which are used to mark packets
8708 which are then shaped.
8709 </Para></ListItem>
8710 </VarListEntry>
8711 <VarListEntry>
8712 <Term>Virtual Router
8713 Redundancy Protocol implementation <ULink
8714 URL="http://w3.arobas.net/~jetienne/vrrpd/index.html"
8715 >(site)</ULink
8716 ></Term>
8717 <ListItem>
8718 <Para>
8719 This is purely for redundancy. Two machines with their own IP address and
8720 MAC Address together create a third IP Address and MAC Address, which is
8721 virtual. Originally intended purely for routers, which need constant MAC
8722 addresses, it also works for other servers.
8723 </Para>
8725 <Para>
8726 The beauty of this approach is the incredibly easy configuration. No kernel
8727 compiling or patching required, all userspace.
8728 </Para>
8730 <Para>
8731 Just run this on all machines participating in a service:
8733 <Screen>
8734 # vrrpd -i eth0 -v 50 10.0.0.22
8735 </Screen>
8737 </Para>
8739 <Para>
8740 And you are in business! 10.0.0.22 is now carried by one of your servers,
8741 probably the first one to run the vrrp daemon. Now disconnect that computer
8742 from the network and very rapidly one of the other computers will assume the
8743 10.0.0.22 address, as well as the MAC address.
8744 </Para>
8746 <Para>
8747 I tried this over here and had it up and running in 1 minute. For some
8748 strange reason it decided to drop my default gateway, but the -n flag
8749 prevented that.
8750 </Para>
8752 <Para>
8753 This is a 'live' fail over:
8754 </Para>
8756 <Para>
8758 <Screen>
8759 64 bytes from 10.0.0.22: icmp_seq=3 ttl=255 time=0.2 ms
8760 64 bytes from 10.0.0.22: icmp_seq=4 ttl=255 time=0.2 ms
8761 64 bytes from 10.0.0.22: icmp_seq=5 ttl=255 time=16.8 ms
8762 64 bytes from 10.0.0.22: icmp_seq=6 ttl=255 time=1.8 ms
8763 64 bytes from 10.0.0.22: icmp_seq=7 ttl=255 time=1.7 ms
8764 </Screen>
8766 </Para>
8768 <Para>
8769 Not *one* ping packet was lost! Just after packet 4, I disconnected my P200
8770 from the network, and my 486 took over, which you can see from the higher
8771 latency.
8772 </Para></ListItem>
8773 </VarListEntry>
8774 </VariableList>
8775 </Para>
8777 </chapter>
8779 <chapter id="lartc.further">
8780   <Title>Further reading</Title>
8782 <Para>
8783 <VariableList>
8785 <VarListEntry>
8786 <Term><ULink
8787 URL="http://snafu.freedom.org/linux2.2/iproute-notes.html"
8788 >http://snafu.freedom.org/linux2.2/iproute-notes.html</ULink
8789 ></Term>
8790 <ListItem>
8791 <Para>
8792 Contains lots of technical information, comments from the kernel
8793 </Para></ListItem>
8794 </VarListEntry>
8795 <VarListEntry>
8796 <Term><ULink
8797 URL="http://www.davin.ottawa.on.ca/ols/"
8798 >http://www.davin.ottawa.on.ca/ols/</ULink
8799 ></Term>
8800 <ListItem>
8801 <Para>
8802 Slides by Jamal Hadi Salim, one of the authors of Linux traffic control
8803 </Para></ListItem>
8804 </VarListEntry>
8805 <VarListEntry>
8806 <Term><ULink
8807 URL="http://defiant.coinet.com/iproute2/ip-cref/"
8808 >http://defiant.coinet.com/iproute2/ip-cref/</ULink
8809 ></Term>
8810 <ListItem>
8811 <Para>
8812 HTML version of Alexeys LaTeX documentation - explains part of iproute2 in
8813 great detail
8814 </Para></ListItem>
8815 </VarListEntry>
8816 <VarListEntry>
8817 <Term><ULink
8818 URL="http://www.aciri.org/floyd/cbq.html"
8819 >http://www.aciri.org/floyd/cbq.html</ULink
8820 ></Term>
8821 <ListItem>
8822 <Para>
8823 Sally Floyd has a good page on CBQ, including her original papers. None of
8824 it is Linux specific, but it does a fair job discussing the theory and uses
8825 of CBQ.
8826 Very technical stuff, but good reading for those so inclined. 
8827 </Para></ListItem>
8828 </VarListEntry>
8829 <VarListEntry>
8830 <Term>Differentiated Services on Linux</Term>
8831 <ListItem>
8832 <Para>
8833 This <ULink
8834 URL="ftp://icaftp.epfl.ch/pub/linux/diffserv/misc/dsid-01.txt.gz"
8835 >document</ULink
8836 > by Werner Almesberger, Jamal Hadi Salim and Alexey
8837 Kuznetsov describes DiffServ facilities in the Linux kernel, amongst which
8838 are TBF, GRED, the DSMARK qdisc and the tcindex classifier.
8839 </Para></ListItem>
8840 </VarListEntry>
8841 <VarListEntry>
8842 <Term><ULink
8843 URL="http://ceti.pl/~kravietz/cbq/NET4_tc.html"
8844 >http://ceti.pl/~kravietz/cbq/NET4_tc.html</ULink
8845 ></Term>
8846 <ListItem>
8847 <Para>
8848 Yet another HOWTO, this time in Polish! You can copy/paste command lines
8849 however, they work just the same in every language. The author is
8850 cooperating with us and may soon author sections of this HOWTO.
8851 </Para></ListItem>
8852 </VarListEntry>
8853 <VarListEntry>
8854 <Term><ULink
8855 URL="http://www.cisco.com/univercd/cc/td/doc/product/software/ios111/cc111/car.htm"
8856 >IOS Committed Access Rate</ULink
8857 ></Term>
8858 <ListItem>
8859 <Para>
8860 <Anchor id="CAR">
8861 From the helpful folks of Cisco who have the laudable habit of putting
8862 their documentation online. Cisco syntax is different but the concepts are
8863 the same, except that we can do more and do it without routers the price of
8864 cars :-)
8865 </Para></ListItem>
8866 </VarListEntry>
8867 <VarListEntry>
8868 <Term>Docum experimental site<ULink
8869 URL="http://www.docum.org"
8870 >(site)</ULink
8871 ></Term>
8872 <ListItem>
8873 <Para>
8874 Stef Coene is busy convincing his boss to sell Linux support, and so he is
8875 experimenting a lot, especially with managing bandwidth. His site has a lot
8876 of practical information, examples, tests and also points out some CBQ/tc bugs. 
8877 </Para>
8878 </ListItem>
8879 </VarListEntry>
8880 <VarListEntry>
8881 <Term>TCP/IP Illustrated, volume 1, W. Richard Stevens, ISBN 0-201-63346-9</Term>
8882 <ListItem>
8883 <Para>
8884 Required reading if you truly want to understand TCP/IP. Entertaining as
8885 well.
8886 </Para>
8887 </ListItem>
8888 </VarListEntry>
8889 </VariableList> 
8890 </Para>
8892 </chapter>
8894 <chapter id="lartc.ack">
8895 <Title>Acknowledgements </Title>
8897 <Para>
8899 It is our goal to list everybody who has contributed to this HOWTO, or
8900 helped us demystify how things work. While there are currently no plans
8901 for a Netfilter type scoreboard, we do like to recognize the people who are
8902 helping.
8903 </Para>
8905 <Para>
8907 <ItemizedList spacing="compact">
8908 <ListItem>
8910    <Para>
8911    <author><firstname>Junk</firstname><surname>Alins</surname></author>
8912    <address><email>juanjo@mat.upc.es</email></address>
8913    </Para>
8914   </ListItem>
8915   <ListItem>
8916    <Para>
8917    <author><firstname>Joe</firstname><surname>Van Andel</surname></author>
8918    </Para>
8919   </ListItem>
8921   <ListItem>
8922    <Para>
8923    <author><firstname>Michael</firstname><othername>T.</othername>
8924      <surname>Babcock</surname></author>
8925    <address><email>mbabcock@fibrespeed.net</email></address>
8926    </Para>
8927   </ListItem>
8930   <ListItem>
8931    <Para>
8932    <author><firstname>Christopher</firstname>
8933      <surname>Barton</surname></author>
8934    <address><email>cpbarton%uiuc.edu</email></address>
8935    </Para>
8936   </ListItem>
8939   <ListItem>
8940    <Para>
8941    <author><firstname>Ard</firstname><surname>van Breemen</surname></author>
8942    <address><email>ard&percnt;kwaak.net</email></address>
8943   </Para>
8944   </ListItem>
8945   <ListItem>
8946    <Para>
8947    <author><firstname>Ron</firstname><surname>Brinker</surname></author>
8948    <address><email>service&percnt;emcis.com</email></address>
8949    </Para>
8950   </ListItem>
8951   <ListItem>
8952    <Para>
8953    <author><firstname>?ukasz</firstname><surname>Bromirski</surname></author>
8954    <address><email>l.bromirski@mr0vka.eu.org</email></address>
8955    </Para>
8956   </ListItem>
8957   <ListItem>
8958    <Para>
8959    <author><firstname>Lennert</firstname><surname>Buytenhek</surname></author>
8960    <address><email>buytenh@gnu.org</email></address>
8961    </Para>
8962   </ListItem>
8963   <ListItem>
8964    <Para>
8965    <author><firstname>Esteve</firstname><surname>Camps</surname></author>
8966    <address><email>esteve@hades.udg.es</email></address>
8967    </Para>
8968   </ListItem>
8969   <ListItem>
8970    <Para>
8971    <author><firstname>Stef</firstname><surname>Coene</surname></author>
8972    <address><email>stef.coene@docum.org</email></address>
8973    </Para>
8974   </ListItem>
8975   <ListItem>
8976    <Para>
8977    <author><firstname>Don</firstname><surname>Cohen</surname></author>
8978    <address><email>don-lartc&percnt;isis.cs3-inc.com</email></address>
8979    </Para>
8980   </ListItem>
8981   <ListItem>
8982    <Para>
8983    <author><firstname>Jonathan</firstname><surname>Corbet</surname></author>
8984    <address><email>lwn&percnt;lwn.net</email></address>
8985    </Para>
8986   </ListItem>
8987   <ListItem>
8988    <Para>
8989    <author><firstname>Gerry</firstname><surname>Creager</surname>
8990      <othername>N5JXS</othername></author>
8991    <address><email>gerry&percnt;cs.tamu.edu</email></address>
8992    </Para>
8993   </ListItem>
8994   <ListItem>
8995    <Para>
8996    <author><firstname>Marco</firstname><surname>Davids</surname></author>
8997    <address><email>marco@sara.nl</email></address>
8998    </Para>
8999   </ListItem>
9000   <ListItem>
9001    <Para>
9002    <author><firstname>Jonathan</firstname><surname>Day</surname></author>
9003    <address><email>jd9812@my-deja.com</email></address>
9004    </Para>
9005   </ListItem>
9006   <ListItem>
9007    <Para>
9008    <author><firstname>Martin</firstname><surname>Devera</surname>
9009      <othername>aka devik</othername></author>
9010    <address><email>devik@cdi.cz</email></address>
9011   </Para>
9012   </ListItem>
9015   <ListItem>
9016    <Para>
9017    <author><firstname>Stephan</firstname><othername>"Kobold"</othername>
9018      <surname>Gehring</surname></author>
9019    <address><email>Stephan.Gehring@bechtle.de</email></address>
9020   </Para>
9021   </ListItem>
9022   <ListItem>
9023    <Para>
9024    <author><firstname>Jacek</firstname><surname>Glinkowski</surname></author>
9025    <address><email>jglinkow&percnt;hns.com</email></address>
9026   </Para>
9027   </ListItem>
9028   <ListItem>
9029    <Para>
9030    <author><firstname>Andrea</firstname><surname>Glorioso</surname></author>
9031    <address><email>sama&percnt;perchetopi.org</email></address>
9032   </Para>
9033   </ListItem>
9034   <ListItem>
9035    <Para>
9036    <author><firstname>Nadeem</firstname><surname>Hasan</surname></author>
9037    <address><email>nhasan@usa.net</email></address>
9038    </Para>
9039   </ListItem>
9040   <ListItem>
9041    <Para>
9042    <author><firstname>Erik</firstname><surname>Hensema</surname></author>
9043    <address><email>erik&percnt;hensema.xs4all.nl</email></address>
9044    </Para>
9045   </ListItem>
9046   <ListItem>
9047    <Para>
9048    <author><firstname>Vik</firstname><surname>Heyndrickx</surname></author>
9049    <address><email>vik.heyndrickx@edchq.com</email></address>
9050    </Para>
9051   </ListItem>
9052   <ListItem>
9053    <Para>
9054    <author><firstname>Spauldo</firstname><surname>Da Hippie</surname></author>
9055    <address><email>spauldo&percnt;usa.net</email></address>
9056    </Para>
9057   </ListItem>
9058   <ListItem>
9059    <Para>
9060    <author><firstname>Koos</firstname><surname>van den Hout</surname></author>
9061    <address><email>koos@kzdoos.xs4all.nl</email></address>
9062    </Para>
9063   </ListItem>
9064   <ListItem>
9066 <Para>
9067 Stefan Huelbrock &lt;shuelbrock&percnt;datasystems.de&gt;
9068 </Para>
9069 </ListItem>
9070 <ListItem>
9072 <Para>
9073 Alexander W. Janssen &lt;yalla&percnt;ynfonatic.de&gt;
9074 </Para>
9075 </ListItem>
9076 <ListItem>
9078 <Para>
9079 Gareth John &lt;gdjohn&percnt;zepler.org&gt;
9080 </Para>
9081 </ListItem>
9083   <ListItem>
9084    <Para>
9085    <author><firstname>Dave</firstname><surname>Johnson</surname></author>
9086    <address><email>dj@www.uk.linux.org</email></address>
9087    </Para>
9088   </ListItem>
9091 <ListItem>
9093 <Para>
9094 Martin Josefsson &lt;gandalf&percnt;wlug.westbo.se&gt;
9095 </Para>
9096 </ListItem>
9097 <ListItem>
9099 <Para>
9100 Andi Kleen &lt;ak&percnt;suse.de&gt;
9101 </Para>
9102 </ListItem>
9103 <ListItem>
9105 <Para>
9106 Andreas J. Koenig &lt;andreas.koenig&percnt;anima.de&gt;
9107 </Para>
9108 </ListItem>
9109 <ListItem>
9111 <Para>
9112 Pawel Krawczyk &lt;kravietz&percnt;alfa.ceti.pl&gt;
9113 </Para>
9114 </ListItem>
9115 <ListItem>
9117 <Para>
9118 Amit Kucheria &lt;amitk@ittc.ku.edu&gt;
9119 </Para>
9120 </ListItem>
9121 <ListItem>
9123 <Para>
9124 Edmund Lau &lt;edlau&percnt;ucf.ics.uci.edu&gt;
9125 </Para>
9126 </ListItem>
9127 <ListItem>
9129 <Para>
9130 Philippe Latu &lt;philippe.latu&percnt;linux-france.org&gt;
9131 </Para>
9132 </ListItem>
9133 <ListItem>
9135 <Para>
9136 Arthur van Leeuwen &lt;arthurvl&percnt;sci.kun.nl&gt;
9137 </Para>
9138 </ListItem>
9139   <ListItem>
9140    <Para>
9141    <author><firstname>Jose Luis Domingo</firstname><surname>Lopez</surname>
9142      </author>
9143    <address><email>jdomingo@24x7linux.com</email></address>
9144   </Para>
9145   </ListItem>
9146 <ListItem>
9148 <Para>
9149 Jason Lunz &lt;j@cc.gatech.edu&gt;
9150 </Para>
9151 </ListItem>
9152 <ListItem>
9154 <Para>
9155 Stuart Lynne &lt;sl@fireplug.net&gt;
9156 </Para>
9157 </ListItem>
9158 <ListItem>
9160 <Para>
9161 Alexey Mahotkin &lt;alexm@formulabez.ru&gt;
9162 </Para>
9163 </ListItem>
9164 <ListItem>
9166 <Para>
9167 Predrag Malicevic &lt;pmalic@ieee.org&gt;
9168 </Para>
9169 </ListItem>
9170 <listitem>
9171 <para>
9172 Patrick McHardy &lt;kaber@trash.net&gt;
9173 </para>
9174 </ListItem>
9176 <ListItem>
9179 <Para>
9180 Andreas Mohr &lt;andi&percnt;lisas.de&gt;
9181 </Para>
9182 </ListItem>
9183 <ListItem>
9185 <Para>
9186 Andrew Morton &lt;akpm@zip.com.au&gt;
9187 </Para>
9188 </ListItem>
9189 <ListItem>
9191 <Para>
9192 Wim van der Most 
9193 </Para>
9194 </ListItem>
9195 <ListItem>
9197 <Para>
9198 Stephan Mueller &lt;smueller@chronox.de&gt;
9199 </Para>
9200 </ListItem>
9201 <ListItem>
9203 <Para>
9204 Togan Muftuoglu &lt;toganm&percnt;yahoo.com&gt;
9205 </Para>
9206 </ListItem>
9207 <ListItem>
9209 <Para>
9210 Chris Murray &lt;cmurray@stargate.ca&gt;
9211 </Para>
9212 </ListItem>
9213 <ListItem>
9215 <Para>
9216 Patrick Nagelschmidt &lt;dto&percnt;gmx.net&gt;
9217 </Para>
9218 </ListItem>
9219 <ListItem>
9221 <Para>
9222 Ram Narula &lt;ram@princess1.net&gt;
9223 </Para>
9224 </ListItem>
9225 <ListItem>
9227 <Para>
9228 Jorge Novo &lt;jnovo@educanet.net&gt;
9229 </Para>
9230 </ListItem>
9231 <ListItem>
9233 <Para>
9234 Patrik &lt;ph@kurd.nu&gt;
9235 </Para>
9236 </ListItem>
9238 <listitem><para>P?l Osgy?ny &lt;oplab%westel900.net&gt;</para></listitem>
9240 <ListItem>
9242 <Para>
9243 Lutz Pre&szlig;ler &lt;Lutz.Pressler&percnt;SerNet.DE&gt;
9244 </Para>
9245 </ListItem>
9246 <ListItem>
9248 <Para>
9249 Jason Pyeron &lt;jason&percnt;pyeron.com&gt;
9250 </Para>
9251 </ListItem>
9252 <ListItem>
9254 <Para>
9255 Rusty Russell &lt;rusty&percnt;rustcorp.com.au&gt;
9256 </Para>
9257 </ListItem>
9258 <ListItem>
9260 <Para>
9261 Mihai RUSU &lt;dizzy&percnt;roedu.net&gt;
9262 </Para>
9263 </ListItem>
9264 <ListItem>
9266 <Para>
9267 Jamal Hadi Salim &lt;hadi&percnt;cyberus.ca&gt;
9268 </Para>
9269 </ListItem>
9271 <ListItem>
9272 <Para>
9273 Ren? Serral &lt;rserral%ac.upc.es&gt; 
9274 </Para>
9275 </ListItem>
9278 <ListItem>
9279 <Para>
9280 David Sauer &lt;davids&percnt;penguin.cz&gt;
9281 </Para>
9282 </ListItem>
9283 <ListItem>
9285 <Para>
9286 Sheharyar Suleman Shaikh &lt;sss23@drexel.edu&gt;
9287 </Para>
9288 </ListItem>
9289 <ListItem>
9291 <Para>
9292 Stewart Shields &lt;MourningBlade&percnt;bigfoot.com&gt;
9293 </Para>
9294 </ListItem>
9295 <ListItem>
9297 <Para>
9298 Nick Silberstein &lt;nhsilber&percnt;yahoo.com&gt;
9299 </Para>
9300 </ListItem>
9301 <ListItem>
9303 <Para>
9304 Konrads Smelkov &lt;konrads@interbaltika.com&gt;
9305 </Para>
9306 </ListItem>
9307 <ListItem>
9309 <Para>
9310 <author><firstname>William</firstname><surname>Stearns</surname></author>
9311 <address><email>wstearns@pobox.com</email></address>
9312 </Para>
9313 </ListItem>
9315 <ListItem>
9316 <Para>
9317 Andreas Steinmetz &lt;ast&percnt;domdv.de&gt;
9318 </Para>
9319 </ListItem>
9320 <ListItem>
9322 <Para>
9323 Jason Tackaberry &lt;tack@linux.com&gt;
9324 </Para>
9325 </ListItem>
9326 <ListItem>
9328 <Para>
9329 Charles Tassell &lt;ctassell&percnt;isn.net&gt;
9330 </Para>
9331 </ListItem>
9332 <ListItem>
9334 <Para>
9335 Glen Turner &lt;glen.turner&percnt;aarnet.edu.au&gt;
9336 </Para>
9337 </ListItem>
9339 <ListItem>
9340 <Para>
9341 Tea Sponsor: Eric Veldhuyzen &lt;eric&percnt;terra.nu&gt; 
9342 </Para>
9343 </ListItem>
9347 <ListItem>
9348 <Para>
9349 Song Wang &lt;wsong@ece.uci.edu&gt;
9350 </Para>
9351 </ListItem>
9353   <ListItem>
9354    <Para>
9355    <author><firstname>Lazar</firstname><surname>Yanackiev</surname></author>
9356    <address><email>Lyanackiev%gmx.net</email></address>
9357    </Para>
9358   </ListItem>
9360 </ItemizedList>
9362 </Para>
9364 </chapter>
9366 </Book>