added IMQ
[lartc.git] / lartc.db
blobe64e13ea84e03ae8c58ec8003d06d97d6cf229f5
1 <!DOCTYPE book PUBLIC "-//Davenport//DTD DocBook V3.0//EN">
3 <Book>
5 <bookinfo>
6 <Title>Linux Advanced Routing &amp; Traffic Control HOWTO</Title>
7     <authorgroup>
8       <AUTHOR>
9         <FirstName>bert</FirstName><Surname>hubert</Surname>
10         <affiliation>
11           <orgname>
12             Netherlabs BV
13           </orgname>
14           <address><email>bert.hubert@netherlabs.nl</email></address>
15         </affiliation>
16       </author>
17       <author>
18         <firstname>Gregory</FirstName>
19         <Surname>Maxwell</Surname>
20         <affiliation>
21           <address><email>greg@linuxpower.cx</email></address>
22         </affiliation>
23       </author>
25       <author>
26         <firstname>Remco</FirstName>
27         <Surname>van Mook</Surname>
28         <affiliation>
29           <address><email>remco@virtu.nl</email></address>
30         </affiliation>
31       </author>
33       <author>
34         <firstname>Martijn</FirstName>
35         <Surname>van Oosterhout</Surname>
36         <affiliation>
37           <address><email>kleptog@cupid.suninternet.com</email></address>
38         </affiliation>
39       </author>
41       <author>
42         <firstname>Paul</FirstName>
43         <othername>B</othername>
44         <Surname>Schroeder</Surname>
45         <affiliation>
46           <address><email>paulsch@us.ibm.com</email></address>
47         </affiliation>
48       </author>
50       <author>
51         <firstname>Jasper</FirstName>
52         <Surname>Spaans</Surname>
53         <affiliation>
54           <address><email>jasper@spaans.ds9a.nl</email></address>
55         </affiliation>
56       </author>
57     </authorgroup>
59 <Abstract>
61 <Para>
62 A very hands-on approach to iproute2, traffic shaping and a bit of
63 netfilter.
64 </para>
65 <para>
66  Verison v1.0.0 $Date$
67 </Para>
69 </Abstract>
71 </bookinfo>
72 <toc></toc>
73 <chapter>
74 <Title>Dedication</Title>
76 <Para>
77 This document is dedicated to lots of people, and is my attempt to do
78 something back. To list but a few:
79 </Para>
81 <Para>
83 <ItemizedList>
84 <ListItem>
86 <Para>
87 Rusty Russell
88 </Para>
89 </ListItem>
90 <ListItem>
92 <Para>
93 Alexey N. Kuznetsov
94 </Para>
95 </ListItem>
96 <ListItem>
98 <Para>
99 The good folks from Google
100 </Para>
101 </ListItem>
102 <ListItem>
104 <Para>
105 The staff of Casema Internet
106 </Para>
107 </ListItem>
109 </ItemizedList>
110         
111 </Para>
113 </chapter>
115 <chapter>
116 <Title>Introduction</Title>
118 <Para>
119 Welcome, gentle reader.
120 </Para>
122 <Para>
123 This document hopes to enlighten you on how to do more with Linux 2.2/2.4
124 routing. Unbeknownst to most users, you already run tools which allow you to
125 do spectacular things. Commands like 'route' and 'ifconfig' are actually
126 very thin wrappers for the very powerful iproute2 infrastructure.
127 </Para>
129 <Para>
130 I hope that this HOWTO will become as readable as the ones by Rusty Russell
131 of (amongst other things) netfilter fame.
132 </Para>
134 <Para>
135 You can always reach us by writing to the <ULink
136 URL="mailto:HOWTO@ds9a.nl"
137 >HOWTO team</ULink
138 >. However, please consider posting to the mailing
139 list (see the relevant section) if you have questions which are not directly
140 related to this HOWTO.
141 </Para>
143 <Para>
144 Before losing your way in this HOWTO, if all you want to do is simple
145 traffic shaping, skip everything and head to the 'Other possibilties'
146 chapter, and read about CBQ.init.
147 </Para>
149 <Sect1>
150 <Title>Disclaimer &amp; License</Title>
152 <Para>
153 This document is distributed in the hope that it will be useful,
154 but WITHOUT ANY WARRANTY; without even the implied warranty of
155 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
156 </Para>
158 <Para>
159 In short, if your STM-64 backbone breaks down and distributes pornography to
160 your most esteemed customers - it's never our fault. Sorry.
161 </Para>
163 <Para>
164 Copyright (c) 2001 by bert hubert, Gregory Maxwell, Martijn van
165 Oosterhout, Remco van Mook, Paul B. Schroeder and others. This material may
166 be distributed only subject to the terms and conditions set forth in the
167 Open Publication License, v1.0 or later (the latest version is presently
168 available at http://www.opencontent.org/openpub/).
169 </Para>
171 <Para>
172 Please freely copy and distribute (sell or give away) this document in any
173 format. It's requested that corrections and/or comments be fowarded to the
174 document maintainer. 
175 </Para>
177 <Para>
178 It is also requested that if you publish this HOWTO in hardcopy that you
179 send the authors some samples for 'review purposes' :-) 
180 </Para>
182 </Sect1>
184 <Sect1>
185 <Title>Prior knowledge</Title>
187 <Para>
188 As the title implies, this is the 'Advanced' HOWTO. While by no means rocket
189 science, some prior knowledge is assumed. 
190 </Para>
192 <Para>
193 Here are some other references which might help teach you more:
194 <VariableList>
196 <VarListEntry>
197 <Term><ULink
198 URL="http://netfilter.samba.org/unreliable-guides/networking-concepts-HOWTO/index.html"
199 >Rusty Russell's networking-concepts-HOWTO</ULink
200 ></Term>
201 <ListItem>
202 <Para>
203 Very nice introduction, explaining what a network is, and how it is
204 connected to other networks
205 </Para>
206 </VarListEntry>
207 <VarListEntry>
208 <Term>Linux Networking-HOWTO (Previously the Net-3 HOWTO)</Term>
209 <ListItem>
210 <Para>
211 Great stuff, although very verbose. It teaches you a lot of stuff that's
212 already configured if you are able to connect to the Internet. 
213 Should be located in /usr/doc/HOWTO/NET3-4-HOWTO.txt
214  but can be also be found 
215 <ULink
216 URL="http://www.linuxports.com/howto/networking"
217 >online</ULink
219 </Para>
220 </VarListEntry>
221 </VariableList>
222 </Para>
224 </Sect1>
226 <Sect1>
227 <Title>What Linux can do for you</Title>
229 <Para>
230 A small list of things that are possible:
231 </Para>
233 <Para>
235 <ItemizedList>
236 <ListItem>
238 <Para>
239 Throttle bandwidth for certain computers
240 </Para>
241 </ListItem>
242 <ListItem>
244 <Para>
245 Throttle bandwidth TO certain computers
246 </Para>
247 </ListItem>
248 <ListItem>
250 <Para>
251 Help you to fairly share your bandwidth
252 </Para>
253 </ListItem>
254 <ListItem>
256 <Para>
257 Protect your network from DoS attacks
258 </Para>
259 </ListItem>
260 <ListItem>
262 <Para>
263 Protect the Internet from your customers
264 </Para>
265 </ListItem>
266 <ListItem>
268 <Para>
269 Multiplex several servers as one, for load balancing or
270 enhanced availability
271 </Para>
272 </ListItem>
273 <ListItem>
275 <Para>
276 Restrict access to your computers
277 </Para>
278 </ListItem>
279 <ListItem>
281 <Para>
282 Limit access of your users to other hosts
283 </Para>
284 </ListItem>
285 <ListItem>
287 <Para>
288 Do routing based on user id (yes!), MAC address, source IP
289 address, port, type of service, time of day or content
290 </Para>
291 </ListItem>
293 </ItemizedList>
295 </Para>
297 <Para>
298 Currently, not many people are using these advanced features. This is for
299 several reasons. While the provided documentation is verbose, it is not very
300 hands-on. Traffic control is almost undocumented.
301 </Para>
303 </Sect1>
305 <Sect1>
306 <Title>Housekeeping notes</Title>
308 <Para>
309 There are several things which should be noted about this document. While I
310 wrote most of it, I really don't want it to stay that way. I am a strong
311 believer in Open Source, so I encourage you to send feedback, updates,
312 patches etcetera. Do not hesitate to inform me of typos or plain old errors.
313 If my English sounds somewhat wooden, please realise that I'm not a native
314 speaker. Feel free to send suggestions.
315 </Para>
317 <Para>
318 If you feel to you are better qualified to maintain a section, or think that
319 you can author and maintain new sections, you are welcome to do so. The SGML
320 of this HOWTO is available via CVS, I very much envision more people
321 working on it.
322 </Para>
324 <Para>
325 In aid of this, you will find lots of FIXME notices. Patches are always
326 welcome! Wherever you find a FIXME, you should know that you are treading in
327 unknown territory. This is not to say that there are no errors elsewhere,
328 but be extra careful. If you have validated something, please let us know so
329 we can remove the FIXME notice.
330 </Para>
332 <Para>
333 About this HOWTO, I will take some liberties along the road. For example, I
334 postulate a 10Mbit Internet connection, while I know full well that those
335 are not very common.
336 </Para>
338 </Sect1>
340 <Sect1>
341 <Title>Access, CVS &amp; submitting updates</Title>
343 <Para>
344 The canonical location for the HOWTO is <ULink
345 URL="http://www.ds9a.nl/lartc"
346 >here</ULink
348 </Para>
350 <Para>
351 We now have anonymous CVS access available to the world at large. This is
352 good in a number of ways. You can easily upgrade to newer versions of this
353 HOWTO and submitting patches is no work at all.
354 </Para>
356 <Para>
357 Furthermore, it allows the authors to work on the source independently,
358 which is good too.
359 </Para>
361 <Para>
363 <Screen>
364 $ export CVSROOT=:pserver:anon@outpost.ds9a.nl:/var/cvsroot
365 $ cvs login
366 CVS password: [enter 'cvs' (without 's)]
367 $ cvs co 2.4routing
368 cvs server: Updating 2.4routing
369 U 2.4routing/2.4routing.sgml
370 </Screen>
372 </Para>
374 <Para>
375 If you spot an error, or want to add something, just fix it locally, and run
376 cvs diff -u, and send the result off to us.
377 </Para>
379 <Para>
380 A Makefile is supplied which should help you create postscript, dvi, pdf,
381 html and plain text. You may need to install sgml-tools, ghostscript and
382 tetex to get all formats.
383 </Para>
385 </Sect1>
387 <Sect1>
388 <Title>Mailing list</Title>
390 <Para>
391 <Anchor id="MLIST">
392 The authors receive an increasing amount of mail about this HOWTO. Because
393 of the clear interest of the community, it has been decided to start a
394 mailinglist where people can talk to each other about Advanced Routing and
395 Traffic Control. You can subscribe to the list
396 <ULink
397 URL="http://mailman.ds9a.nl/mailman/listinfo/lartc"
398 >here</ULink
400 </Para>
402 <Para>
403 It should be pointed out that the authors are very hesitant of answering
404 questions not asked on the list. We would like the archive of the list to
405 become some kind of knowledge base. If you have a question, please search
406 the archive, and then post to the mailinglist.
407 </Para>
409 </Sect1>
411 <Sect1>
412 <Title>Layout of this document</Title>
414 <Para>
415 We will be doing interesting stuff almost immediately, which also means that
416 there will initially be parts that are explained incompletely or are not
417 perfect. Please gloss over these parts and assume that all will become clear.
418 </Para>
420 <Para>
421 Routing and filtering are two distinct things. Filtering is documented very
422 well by Rusty's HOWTOs, available here:
423 </Para>
425 <Para>
427 <ItemizedList>
428 <ListItem>
430 <Para>
431 <ULink
432 URL="http://netfilter.samba.org/unreliable-guides/"
433 >Rusty's Remarkably Unreliable Guides</ULink
435 </Para>
436 </ListItem>
438 </ItemizedList>
440 </Para>
442 <Para>
443 We will be focusing mostly on what is possible by combining netfilter and
444 iproute2.
445 </Para>
447 </Sect1>
449 </chapter>
451 <chapter>
452 <Title>Introduction to iproute2</Title>
454 <Sect1>
455 <Title>Why iproute2?</Title>
457 <Para>
458 Most Linux distributions, and most UNIX's, currently use the 
459 venerable 'arp', 'ifconfig' and 'route' commands. While these tools work,
460 they show some unexpected behaviour under Linux 2.2 and up. For example, GRE
461 tunnels are an integral part of routing these days, but require completely
462 different tools.
463 </Para>
465 <Para>
466 With iproute2, tunnels are an integral part of the tool set.
467 </Para>
469 <Para>
470 The 2.2 and above Linux kernels include a completely redesigned network
471 subsystem. This new networking code brings Linux performance and a feature
472 set with little competition in the general OS arena. In fact, the new
473 routing, filtering, and classifying code is more featureful than the one
474 provided by many dedicated routers and firewalls and traffic shaping
475 products.
476 </Para>
478 <Para>
479 As new networking concepts have been invented, people have found ways to
480 plaster them on top of the existing framework in existing OSes. This
481 constant layering of cruft has lead to networking code that is filled with
482 strange behaviour, much like most human languages. In the past, Linux
483 emulated SunOS's handling of many of these things, which was not ideal.  
484 </Para>
486 <Para>
487 This new framework makes it possible to clearly express features
488 previously beyond Linux's reach.
489 </Para>
491 </Sect1>
493 <Sect1>
494 <Title>iproute2 tour</Title>
496 <Para>
497 Linux has a sophisticated system for bandwidth provisioning called Traffic
498 Control. This system supports various method for classifying, prioritizing,
499 sharing, and limiting both inbound and outbound traffic.
500 </Para>
502 <Para>
503 We'll start off with a tiny tour of iproute2 possibilities.
504 </Para>
506 </Sect1>
508 <Sect1>
509 <Title>Prerequisites</Title>
511 <Para>
512 You should make sure that you have the userland tools installed. This
513 package is called 'iproute' on both RedHat and Debian, and may otherwise be
514 found at <Literal remap="tt">ftp://ftp.inr.ac.ru/ip-routing/iproute2-2.2.4-now-ss??????.tar.gz"</Literal>. 
515 </Para>
517 <Para>
518 You can also try <ULink
519 URL="ftp://ftp.inr.ac.ru/ip-routing/iproute2-current.tar.gz"
520 >here</ULink
522 for the latest version.
523 </Para>
525 <Para>
526 Some parts of iproute require you to have certain kernel options enabled. It
527 should also be noted that all releases of RedHat up to and including 6.2
528 come without most of the traffic control features in the default kernel. 
529 </Para>
531 <Para>
532 RedHat 7.2 has everything in by default.
533 </Para>
535 <Para>
536 Also make sure that you have netlink support, should you choose to roll your
537 own kernel. Iproute2 needs it.
538 </Para>
540 </Sect1>
542 <Sect1>
543 <Title>Exploring your current configuration</Title>
545 <Para>
546 This may come as a surprise, but iproute2 is already configured! The current
547 commands <Literal remap="tt">ifconfig</Literal> and <Literal remap="tt">route</Literal> are already using the advanced
548 syscalls, but mostly with very default (ie. boring) settings.
549 </Para>
551 <Para>
552 The <Literal remap="tt">ip</Literal> tool is central, and we'll ask it to display our interfaces
553 for us.
554 </Para>
556 <Sect2>
557 <Title><Literal remap="tt">ip</Literal> shows us our links</Title>
559 <Para>
561 <Screen>
562 [ahu@home ahu]$ ip link list
563 1: lo: &#60;LOOPBACK,UP&#62; mtu 3924 qdisc noqueue 
564     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
565 2: dummy: &#60;BROADCAST,NOARP&#62; mtu 1500 qdisc noop 
566     link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
567 3: eth0: &#60;BROADCAST,MULTICAST,PROMISC,UP&#62; mtu 1400 qdisc pfifo_fast qlen 100
568     link/ether 48:54:e8:2a:47:16 brd ff:ff:ff:ff:ff:ff
569 4: eth1: &#60;BROADCAST,MULTICAST,PROMISC,UP&#62; mtu 1500 qdisc pfifo_fast qlen 100
570     link/ether 00:e0:4c:39:24:78 brd ff:ff:ff:ff:ff:ff
571 3764: ppp0: &#60;POINTOPOINT,MULTICAST,NOARP,UP&#62; mtu 1492 qdisc pfifo_fast qlen 10
572     link/ppp 
574 </Screen>
576 </Para>
578 <Para>
579 Your mileage may vary, but this is what it shows on my NAT router at
580 home. I'll only explain part of the output as not everything is directly
581 relevant.
582 </Para>
584 <Para>
585 We first see the loopback interface. While your computer may function
586 somewhat without one, I'd advise against it. The MTU size (Maximum Transfer
587 Unit) is 3924 octets, and it is not supposed to queue. Which makes sense
588 because the loopback interface is a figment of your kernel's imagination.
589 </Para>
591 <Para>
592 I'll skip the dummy interface for now, and it may not be present on your
593 computer. Then there are my two physical network interfaces, one at the side
594 of my cable modem, the other one serves my home ethernet segment.
595 Furthermore, we see a ppp0 interface.
596 </Para>
598 <Para>
599 Note the absence of IP addresses. iproute disconnects the concept of 'links'
600 and 'IP addresses'. With IP aliasing, the concept of 'the' IP address had
601 become quite irrelevant anyhow. 
602 </Para>
604 <Para>
605 It does show us the MAC addresses though, the hardware identifier of our
606 ethernet interfaces.
607 </Para>
609 </Sect2>
611 <Sect2>
612 <Title><Literal remap="tt">ip</Literal> shows us our IP addresses</Title>
614 <Para>
616 <Screen>
617 [ahu@home ahu]$ ip address show        
618 1: lo: &#60;LOOPBACK,UP&#62; mtu 3924 qdisc noqueue 
619     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
620     inet 127.0.0.1/8 brd 127.255.255.255 scope host lo
621 2: dummy: &#60;BROADCAST,NOARP&#62; mtu 1500 qdisc noop 
622     link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
623 3: eth0: &#60;BROADCAST,MULTICAST,PROMISC,UP&#62; mtu 1400 qdisc pfifo_fast qlen 100
624     link/ether 48:54:e8:2a:47:16 brd ff:ff:ff:ff:ff:ff
625     inet 10.0.0.1/8 brd 10.255.255.255 scope global eth0
626 4: eth1: &#60;BROADCAST,MULTICAST,PROMISC,UP&#62; mtu 1500 qdisc pfifo_fast qlen 100
627     link/ether 00:e0:4c:39:24:78 brd ff:ff:ff:ff:ff:ff
628 3764: ppp0: &#60;POINTOPOINT,MULTICAST,NOARP,UP&#62; mtu 1492 qdisc pfifo_fast qlen 10
629     link/ppp 
630     inet 212.64.94.251 peer 212.64.94.1/32 scope global ppp0
631 </Screen>
633 </Para>
635 <Para>
636 This contains more information. It shows all our addresses, and to which
637 cards they belong. 'inet' stands for Internet (IPv4). There are lots of other
638 address families, but these don't concern us right now.
639 </Para>
641 <Para>
642 Let's examine eth0 somewhat closer. It says that it is related to the inet
643 address '10.0.0.1/8'. What does this mean? The /8 stands for the number of
644 bits that are in the Network Address. There are 32 bits, so we have 24 bits
645 left that are part of our network. The first 8 bits of 10.0.0.1 correspond
646 to 10.0.0.0, our Network Address, and our netmask is 255.0.0.0.
647 </Para>
649 <Para>
650 The other bits are connected to this interface, so 10.250.3.13 is directly
651 available on eth0, as is 10.0.0.1 for example. 
652 </Para>
654 <Para>
655 With ppp0, the same concept goes, though the numbers are different. Its
656 address is 212.64.94.251, without a subnet mask. This means that we have a
657 point-to-point connection and that every address, with the exception of
658 212.64.94.251, is remote. There is more information, however. It tells us
659 that on the other side of the link there is, yet again, only one address,
660 212.64.94.1. The /32 tells us that there are no 'network bits'.
661 </Para>
663 <Para>
664 It is absolutely vital that you grasp these concepts. Refer to the
665 documentation mentioned at the beginning of this HOWTO if you have trouble.
666 </Para>
668 <Para>
669 You may also note 'qdisc', which stands for Queueing Discipline. This will
670 become vital later on. 
671 </Para>
673 </Sect2>
675 <Sect2>
676 <Title><Literal remap="tt">ip</Literal> shows us our routes</Title>
678 <Para>
679 Well, we now know how to find 10.x.y.z addresses, and we are able to reach
680 212.64.94.1. This is not enough however, so we need instructions on how to
681 reach the world. The Internet is available via our ppp connection, and it
682 appears that 212.64.94.1 is willing to spread our packets around the
683 world, and deliver results back to us.
684 </Para>
686 <Para>
688 <Screen>
689 [ahu@home ahu]$ ip route show
690 212.64.94.1 dev ppp0  proto kernel  scope link  src 212.64.94.251 
691 10.0.0.0/8 dev eth0  proto kernel  scope link  src 10.0.0.1 
692 127.0.0.0/8 dev lo  scope link 
693 default via 212.64.94.1 dev ppp0 
694 </Screen>
696 </Para>
698 <Para>
699 This is pretty much self explanatory. The first 4 lines of output explicitly
700 state what was already implied by <Literal remap="tt">ip address show</Literal>, the last line
701 tells us that the rest of the world can be found via 212.64.94.1, our
702 default gateway. We can see that it is a gateway because of the word
703 via, which tells us that we need to send packets to 212.64.94.1, and that it
704 will take care of things.
705 </Para>
707 <Para>
708 For reference, this is what the old 'route' utility shows us:
710 <Screen>
711 [ahu@home ahu]$ route -n
712 Kernel IP routing table
713 Destination     Gateway         Genmask         Flags Metric Ref    Use
714 Iface
715 212.64.94.1     0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
716 10.0.0.0        0.0.0.0         255.0.0.0       U     0      0        0 eth0
717 127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
718 0.0.0.0         212.64.94.1     0.0.0.0         UG    0      0        0 ppp0
719 </Screen>
721 </Para>
723 </Sect2>
725 </Sect1>
727 <Sect1>
728 <Title>ARP</Title>
730 <Para>
731 ARP is the Address Resolution Protocol as described in
732 <ULink
733 URL="http://www.faqs.org/rfcs/rfc826.html"
734 >RFC 826</ULink
736 ARP is used by a networked machine to resolve the hardware location/address of
737 another machine on the same
738 local network.  Machines on the Internet are generally known by their names
739 which resolve to IP
740 addresses.  This is how a machine on the foo.com network is able to communicate
741 with another machine which is on the bar.net network.  An IP address, though,
742 cannot tell you the physical location of a machine.  This is where ARP comes
743 into the picture.
744 </Para>
746 <Para>
747 Let's take a very simple example.  Suppose I have a network composed of several
748 machines.  Two of the machines which are currently on my network are foo
749 with an IP address of 10.0.0.1 and bar with an IP address of 10.0.0.2.
750 Now foo wants to ping bar to see that he is alive, but alas, foo has no idea
751 where bar is.  So when foo decides to ping bar he will need to send
752 out an ARP request.
753 This ARP request is akin to foo shouting out on the network "Bar (10.0.0.2)!
754 Where are you?"  As a result of this every machine on the network will hear
755 foo shouting, but only bar (10.0.0.2) will respond.  Bar will then send an
756 ARP reply directly back to foo which is akin
757 bar saying,
758 "Foo (10.0.0.1) I am here at 00:60:94:E9:08:12."  After this simple transaction
759 that's used to locate his friend on the network, foo is able to communicate
760 with bar until he (his arp cache) forgets where bar is (typically after
761 15 minutes on Unix).
762 </Para>
764 <Para>
765 Now let's see how this works.
766 You can view your machines current arp/neighbor cache/table like so:
768 <Screen>
769 [root@espa041 /home/src/iputils]# ip neigh show
770 9.3.76.42 dev eth0 lladdr 00:60:08:3f:e9:f9 nud reachable
771 9.3.76.1 dev eth0 lladdr 00:06:29:21:73:c8 nud reachable
772 </Screen>
774 </Para>
776 <Para>
777 As you can see my machine espa041 (9.3.76.41) knows where to find espa042 
778 (9.3.76.42) and
779 espagate (9.3.76.1).  Now let's add another machine to the arp cache.
780 </Para>
782 <Para>
784 <Screen>
785 [root@espa041 /home/paulsch/.gnome-desktop]# ping -c 1 espa043
786 PING espa043.austin.ibm.com (9.3.76.43) from 9.3.76.41 : 56(84) bytes of data.
787 64 bytes from 9.3.76.43: icmp_seq=0 ttl=255 time=0.9 ms
789 --- espa043.austin.ibm.com ping statistics ---
790 1 packets transmitted, 1 packets received, 0% packet loss
791 round-trip min/avg/max = 0.9/0.9/0.9 ms
793 [root@espa041 /home/src/iputils]# ip neigh show
794 9.3.76.43 dev eth0 lladdr 00:06:29:21:80:20 nud reachable
795 9.3.76.42 dev eth0 lladdr 00:60:08:3f:e9:f9 nud reachable
796 9.3.76.1 dev eth0 lladdr 00:06:29:21:73:c8 nud reachable
797 </Screen>
799 </Para>
801 <Para>
802 As a result of espa041 trying to contact espa043, espa043's hardware
803 address/location has now been added to the arp/neighbor cache.
804 So until the entry for
805 espa043 times out (as a result of no communication between the two) espa041
806 knows where to find espa043 and has no need to send an ARP request.
807 </Para>
809 <Para>
810 Now let's delete espa043 from our arp cache:
811 </Para>
813 <Para>
815 <Screen>
816 [root@espa041 /home/src/iputils]# ip neigh delete 9.3.76.43 dev eth0
817 [root@espa041 /home/src/iputils]# ip neigh show
818 9.3.76.43 dev eth0  nud failed
819 9.3.76.42 dev eth0 lladdr 00:60:08:3f:e9:f9 nud reachable
820 9.3.76.1 dev eth0 lladdr 00:06:29:21:73:c8 nud stale
821 </Screen>
823 </Para>
825 <Para>
826 Now espa041 has again forgotten where to find espa043 and will need to send
827 another ARP request the next time he needs to communicate with espa043.
828 You can also see from the above output that espagate (9.3.76.1) has been
829 changed to the "stale" state.  This means that the location shown is still
830 valid, but it will have to be confirmed at the first transaction to that
831 machine.
832 </Para>
834 </Sect1>
836 </chapter>
838 <chapter>
839 <Title>Rules - routing policy database</Title>
841 <Para>
842 If you have a large router, you may well cater for the needs of different
843 people, who should be served differently. The routing policy database allows
844 you to do this by having multiple sets of routing tables. 
845 </Para>
847 <Para>
848 If you want to use this feature, make sure that your kernel is compiled with
849 the "IP: advanced router" and "IP: policy routing" features.
850 </Para>
852 <Para>
853 When the kernel needs to make a routing decision, it finds out which table
854 needs to be consulted. By default, there are three tables. The old 'route'
855 tool modifies the main and local tables, as does the ip tool (by default).
856 </Para>
858 <Para>
859 The default rules:
861 <Screen>
862 [ahu@home ahu]$ ip rule list
863 0:      from all lookup local 
864 32766:  from all lookup main 
865 32767:  from all lookup default
866 </Screen>
868 </Para>
870 <Para>
871 This lists the priority of all rules. We see that all rules apply to all
872 packets ('from all'). We've seen the 'main' table before, it is output by
873 <Literal remap="tt">ip route ls</Literal>, but the 'local' and 'default' table are new.
874 </Para>
876 <Para>
877 If we want to do fancy things, we generate rules which point to different
878 tables which allow us to override system wide routing rules.
879 </Para>
881 <Para>
882 For the exact semantics on what the kernel does when there are more matching
883 rules, see Alexey's ip-cref documentation. 
884 </Para>
886 <Sect1>
887 <Title>Simple source policy routing</Title>
889 <Para>
890 Let's take a real example once again, I have 2 (actually 3, about time I
891 returned them) cable modems, connected to a Linux NAT ('masquerading')
892 router. People living here pay me to use the Internet. Suppose one of my
893 house mates only visits hotmail and wants to pay less. This is fine with me,
894 but they'll end up using the low-end cable modem.
895 </Para>
897 <Para>
898 The 'fast' cable modem is known as 212.64.94.251 and is a PPP link to
899 212.64.94.1. The 'slow' cable modem is known by various ip addresses,
900 212.64.78.148 in this example and is a link to 195.96.98.253.
901 </Para>
903 <Para>
904 The local table:
906 <Screen>
907 [ahu@home ahu]$ ip route list table local
908 broadcast 127.255.255.255 dev lo  proto kernel  scope link  src 127.0.0.1 
909 local 10.0.0.1 dev eth0  proto kernel  scope host  src 10.0.0.1 
910 broadcast 10.0.0.0 dev eth0  proto kernel  scope link  src 10.0.0.1 
911 local 212.64.94.251 dev ppp0  proto kernel  scope host  src 212.64.94.251 
912 broadcast 10.255.255.255 dev eth0  proto kernel  scope link  src 10.0.0.1 
913 broadcast 127.0.0.0 dev lo  proto kernel  scope link  src 127.0.0.1 
914 local 212.64.78.148 dev ppp2  proto kernel  scope host  src 212.64.78.148 
915 local 127.0.0.1 dev lo  proto kernel  scope host  src 127.0.0.1 
916 local 127.0.0.0/8 dev lo  proto kernel  scope host  src 127.0.0.1 
917 </Screen>
919 </Para>
921 <Para>
922 Lots of obvious things, but things that need to be specified somewhere.
923 Well, here they are. The default table is empty.
924 </Para>
926 <Para>
927 Let's view the 'main' table:
929 <Screen>
930 [ahu@home ahu]$ ip route list table main 
931 195.96.98.253 dev ppp2  proto kernel  scope link  src 212.64.78.148 
932 212.64.94.1 dev ppp0  proto kernel  scope link  src 212.64.94.251 
933 10.0.0.0/8 dev eth0  proto kernel  scope link  src 10.0.0.1 
934 127.0.0.0/8 dev lo  scope link 
935 default via 212.64.94.1 dev ppp0 
936 </Screen>
938 </Para>
940 <Para>
941 We now generate a new rule which we call 'John', for our hypothetical
942 house mate. Although we can work with pure numbers, it's far easier if we add
943 our tables to /etc/iproute2/rt_tables.
944 </Para>
946 <Para>
948 <Screen>
949 # echo 200 John &#62;&#62; /etc/iproute2/rt_tables
950 # ip rule add from 10.0.0.10 table John
951 # ip rule ls
952 0:      from all lookup local 
953 32765:  from 10.0.0.10 lookup John
954 32766:  from all lookup main 
955 32767:  from all lookup default
956 </Screen>
958 </Para>
960 <Para>
961 Now all that is left is to generate John's table, and flush the route cache:
963 <Screen>
964 # ip route add default via 195.96.98.253 dev ppp2 table John
965 # ip route flush cache
966 </Screen>
968 </Para>
970 <Para>
971 And we are done. It is left as an exercise for the reader to implement this
972 in ip-up.
973 </Para>
975 </Sect1>
976 <sect1><title>Routing for multiple uplinks/providers</title>
977 <para>
978 A common configuration is the following, in which there are two providers
979 that connect a local network (or even a single machine) to the big Internet.
981 <screen>
982                                                                  ________
983                                           +------------+        /
984                                           |            |       |
985                             +-------------+ Provider 1 +-------
986         __                  |             |            |     /
987     ___/  \_         +------+-------+     +------------+    |
988   _/        \__      |     if1      |                      /
989  /             \     |              |                      |
990 | Local network -----+ Linux router |                      |     Internet
991  \_           __/    |              |                      |
992    \__     __/       |     if2      |                      \
993       \___/          +------+-------+     +------------+    |
994                             |             |            |     \
995                             +-------------+ Provider 2 +-------
996                                           |            |       |
997                                           +------------+        \________
998 </screen>
1000 There are usually two questions given this setup.
1002       <sect2><title>Split access</title>
1003         <para>
1004           The first is how to route answers to packets coming in over a
1005           particular provider, say Provider 1, back out again over that same provider.
1006         </para>
1007         <para>
1008           Let us first set some symbolical names. Let <command>$IF1</command> be the name of the
1009           first interface (if1 in the picture above) and <command>$IF2</command> the name of the
1010           second interface. Then let <command>$IP1</command> be the IP address associated with
1011           <command>$IF1</command> and <command>$IP2</command> the IP address associated with
1012           <command>$IF2</command>. Next, let <command>$P1</command> be the IP address of the gateway at
1013           Provider 1, and <command>$P2</command> the IP address of the gateway at provider 2.
1014           Finally, let <command>$P1_NET</command> be the IP network <command>$P1</command> is in,
1015           and <command>$P2_NET</command> the IP network <command>$P2</command> is in.
1016         </para>
1017         <para>
1018           One creates two additional routing tables, say <command>T1</command> and <command>T2</command>.
1019           These are added in /etc/iproute2/rt_tables. Then you set up routing in
1020           these tables as follows:
1021         </para>
1022         <para>
1023         <screen>
1024           ip route add $P1_NET dev $IF1 src $IP1 table T1
1025           ip route add default via $P1 table T1
1026           ip route add $P2_NET dev $IF2 src $IP2 table T2
1027           ip route add default via $P2 table T2
1028         </screen>
1029           
1030           Nothing spectacular, just build a route to the gateway and build a
1031           default route via that gateway, as you would do in the case of a single
1032           upstream provider, but put the routes in a seperate table per provider.
1033           Note that the network route suffices, as it tells you how to find any host
1034           in that network, which includes the gateway, as specified above.
1035         </para>
1036         <para>
1037           Next you set up the main routing table. It is a good idea to route
1038           things to the direct neighbour through the interface connected to that
1039           neighbour. Note the `src' arguments, they make sure the right outgoing IP
1040           address is chosen.
1042           <screen>
1043             ip route add $P1_NET dev $IF1 src $IP1
1044             ip route add $P2_NET dev $IF2 src $IP2
1045           </screen>
1047           Then, your preference for default route:
1048           
1049           <screen>
1050             ip route add default via $P1
1051           </screen>
1053           Next, you set up the routing rules. These actually choose what routing table
1054           to route with. You want to make sure that you route out a given
1055           interface if you already have the corresponding source address:
1056           
1057           <screen>
1058             ip rule add from $IP1 table T1
1059             ip rule add from $IP2 table T2
1060           </screen>
1062           This set of commands makes sure all answers to traffic coming in on a
1063           particular interface get answered from that interface.
1064         </para>
1065         <para>
1066           Now, this is just the very basic setup. It will work for all processes
1067           running on the router itself, and for the local network, if it is
1068           masqueraded. If it is not, then you either have IP space from both providers
1069           or you are going to want to masquerade to one of the two providers. In both
1070           cases you will want to add rules selecting which provider to route out from
1071           based on the IP address of the machine in the local network.
1072       </sect2>
1073       <sect2><title>Load balancing</title>
1074         <para>
1075           The second question is how to balance traffic going out over the two providers.
1076           This is actually not hard if you already have set up split access as above.
1077           </para>
1078         <para>
1079           Instead of choosing one of the two providers as your default route,
1080           you now set up the default route to be a multipath route. In the default
1081           kernel this will balance routes over the two providers. It is done
1082           as follows (once more building on the example in the section on
1083           split-access):
1085           <screen>
1086             ip route add default scope global nexthop via $P1 dev $IF1 weight 1 \
1087             nexthop via $P2 dev $IF2 weight 1
1088           </screen>
1090           This will balance the routes over both providers. The <command>weight</command>
1091           parameters can be tweaked to favor one provider over the other.
1092         </para>
1093         <para>
1094           Note that balancing will not be perfect, as it is route based, and routes
1095           are cached. This means that routes to often-used sites will always
1096           be over the same provider.
1097         </para>
1098         <para>
1099           Furthermore, if you really want to do this, you probably also want to look
1100           at Julian Anastasov's patches at <ulink
1101             url="http://www.linuxvirtualserver.org/~julian/#routes">http://www.linuxvirtualserver.org/~julian/#routes
1102             </ulink>, Julian's route patch page. They will make things nicer to work with.
1103         </para>
1104       </sect2>
1105     </sect1>
1106   </chapter>
1108 <chapter>
1109 <Title>GRE and other tunnels</Title>
1111 <Para>
1112 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). 
1113 </Para>
1115 <Sect1>
1116 <Title>A few general remarks about tunnels:</Title>
1118 <Para>
1119 Tunnels can be used to do some very unusual and very cool stuff. They can
1120 also make things go horribly wrong when you don't configure them right.
1121 Don't point your default route to a tunnel device unless you know
1122 <Emphasis remap="bf">exactly</Emphasis> what you are doing :-). Furthermore, tunneling increases
1123 overhead, because it needs an extra set of IP headers. Typically this is 20
1124 bytes per packet, so if the normal packet size (MTU) on a network is 1500
1125 bytes, a packet that is sent through a tunnel can only be 1480 bytes big.
1126 This is not necessarily a problem, but be sure to read up on IP packet
1127 fragmentation/reassembly when you plan to connect large networks with
1128 tunnels. Oh, and of course, the fastest way to dig a tunnel is to dig at
1129 both sides.
1130 </Para>
1132 </Sect1>
1134 <Sect1>
1135 <Title>IP in IP tunneling</Title>
1137 <Para>
1138 This kind of tunneling has been available in Linux for a long time. It requires 2 kernel modules,
1139 ipip.o and new_tunnel.o.
1140 </Para>
1142 <Para>
1143 Let's say you have 3 networks: Internal networks A and B, and intermediate network C (or let's say, Internet). 
1144 So we have network A:
1145 </Para>
1147 <Para>
1149 <Screen>
1150 network 10.0.1.0
1151 netmask 255.255.255.0
1152 router  10.0.1.1
1153 </Screen>
1155 The router has address 172.16.17.18 on network C.
1156 </Para>
1158 <Para>
1159 and network B:
1161 <Screen>
1162 network 10.0.2.0
1163 netmask 255.255.255.0
1164 router  10.0.2.1
1165 </Screen>
1167 The router has address 172.19.20.21 on network C.
1168 </Para>
1170 <Para>
1171 As far as network C is concerned, we assume that it will pass any packet sent
1172 from A to B and vice versa. You might even use the Internet for this.
1173 </Para>
1175 <Para>
1176 Here's what you do:
1177 </Para>
1179 <Para>
1180 First, make sure the modules are installed:
1181 </Para>
1183 <Para>
1185 <Screen>
1186 insmod ipip.o
1187 insmod new_tunnel.o
1188 </Screen>
1190 Then, on the router of network A, you do the following:
1192 <Screen>
1193 ifconfig tunl0 10.0.1.1 pointopoint 172.19.20.21
1194 route add -net 10.0.2.0 netmask 255.255.255.0 dev tunl0
1195 </Screen>
1197 And on the router of network B:
1199 <Screen>
1200 ifconfig tunl0 10.0.2.1 pointopoint 172.16.17.18
1201 route add -net 10.0.1.0 netmask 255.255.255.0 dev tunl0
1202 </Screen>
1204 And if you're finished with your tunnel:
1206 <Screen>
1207 ifconfig tunl0 down
1208 </Screen>
1210 Presto, you're done. You can't forward broadcast or IPv6 traffic through
1211 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.
1212 </Para>
1214 </Sect1>
1216 <Sect1>
1217 <Title>GRE tunneling</Title>
1219 <Para>
1220 GRE is a tunneling protocol that was originally developed by Cisco, and it
1221 can do a few more things than IP-in-IP tunneling. For example, you can also
1222 transport multicast traffic and IPv6 through a GRE tunnel.
1223 </Para>
1225 <Para>
1226 In Linux, you'll need the ip_gre.o module.
1227 </Para>
1229 <Sect2>
1230 <Title>IPv4 Tunneling</Title>
1232 <Para>
1233 Let's do IPv4 tunneling first:
1234 </Para>
1236 <Para>
1237 Let's say you have 3 networks: Internal networks A and B, and intermediate network C (or let's say, Internet). 
1238 </Para>
1240 <Para>
1241 So we have network A:
1243 <Screen>
1244 network 10.0.1.0
1245 netmask 255.255.255.0
1246 router  10.0.1.1
1247 </Screen>
1249 The router has address 172.16.17.18 on network C.
1250 Let's call this network neta (ok, hardly original)
1251 </Para>
1253 <Para>
1254 and network B:
1256 <Screen>
1257 network 10.0.2.0
1258 netmask 255.255.255.0
1259 router  10.0.2.1
1260 </Screen>
1262 The router has address 172.19.20.21 on network C.
1263 Let's call this network netb (still not original)
1264 </Para>
1266 <Para>
1267 As far as network C is concerned, we assume that it will pass any packet sent
1268 from A to B and vice versa. How and why, we do not care.
1269 </Para>
1271 <Para>
1272 On the router of network A, you do the following:
1274 <Screen>
1275 ip tunnel add netb mode gre remote 172.19.20.21 local 172.16.17.18 ttl 255
1276 ip link set netb up
1277 ip addr add 10.0.1.1 dev netb
1278 ip route add 10.0.2.0/24 dev netb
1279 </Screen>
1281 </Para>
1283 <Para>
1284 Let's discuss this for a bit. In line 1, we added a tunnel device, and
1285 called it netb (which is kind of obvious because that's where we want it to
1286 go). Furthermore we told it to use the GRE protocol (mode gre), that the
1287 remote address is 172.19.20.21 (the router at the other end), that our
1288 tunneling packets should originate from 172.16.17.18 (which allows your
1289 router to have several IP addresses on network C and let you decide which
1290 one to use for tunneling) and that the TTL field of the packet should be set
1291 to 255 (ttl 255).
1292 </Para>
1294 <Para>
1295 The second line enables the device.
1296 </Para>
1298 <Para>
1299 In the third line we gave the newly born interface netb the address
1300 10.0.1.1. This is OK for smaller networks, but when you're starting up a
1301 mining expedition (LOTS of tunnels), you might want to consider using
1302 another IP range for tunneling interfaces (in this example, you could use
1303 10.0.3.0).
1304 </Para>
1306 <Para>
1307 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.
1308 </Para>
1310 <Para>
1311 But enough about this, let's go on with the router of network B.
1313 <Screen>
1314 ip tunnel add neta mode gre remote 172.16.17.18 local 172.19.20.21 ttl 255
1315 ip link set neta up
1316 ip addr add 10.0.2.1 dev neta
1317 ip route add 10.0.1.0/24 dev neta
1318 </Screen>
1320 And when you want to remove the tunnel on router A:
1322 <Screen>
1323 ip link set netb down
1324 ip tunnel del netb
1325 </Screen>
1327 Of course, you can replace netb with neta for router B.
1328 </Para>
1330 </Sect2>
1332 <Sect2>
1333 <Title>IPv6 Tunneling</Title>
1335 <Para>
1336 See Section 6 for a short bit about IPv6 Addresses.
1337 </Para>
1339 <Para>
1340 On with the tunnels.
1341 </Para>
1343 <Para>
1344 Let's assume that you have the following IPv6 network, and you want to connect it to 6bone, or a friend.
1345 </Para>
1347 <Para>
1349 <Screen>
1350 Network 3ffe:406:5:1:5:a:2:1/96
1351 </Screen>
1353 Your IPv4 address is 172.16.17.18, and the 6bone router has IPv4 address 172.22.23.24. 
1354 </Para>
1356 <Para>
1358 <Screen>
1359 ip tunnel add sixbone mode sit remote 172.22.23.24 local 172.16.17.18 ttl 255
1360 ip link set sixbone up
1361 ip addr add 3ffe:406:5:1:5:a:2:1/96 dev sixbone
1362 ip route add 3ffe::/15 dev sixbone 
1363 </Screen>
1365 </Para>
1367 <Para>
1368 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.
1369 </Para>
1371 <Para>
1372 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.
1373 </Para>
1375 </Sect2>
1377 </Sect1>
1379 <Sect1>
1380 <Title>Userland tunnels</Title>
1382 <Para>
1383 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.
1384 </Para>
1386 </Sect1>
1388 </chapter>
1390 <chapter>
1391 <Title>IPv6 tunneling with Cisco and/or 6bone</Title>
1393 <Para>
1394 By Marco Davids &lt;marco@sara.nl&gt;
1395 </Para>
1397 <Para>
1398 NOTE to maintainer:
1399 </Para>
1401 <Para>
1402 As far as I am concerned, this IPv6-IPv4 tunneling is not per definition
1403 GRE tunneling. You could tunnel IPv6 over IPv4 by means of GRE tunnel devices
1404 (GRE tunnels ANY to IPv4), but the device used here ("sit") only tunnels
1405 IPv6 over IPv4 and is therefore something different.
1406 </Para>
1408 <Sect1>
1409 <Title>IPv6 Tunneling</Title>
1411 <Para>
1412 This is another application of the tunneling capabilities of Linux. It is
1413 popular among the IPv6 early adopters, or pioneers if you like.
1414 The 'hands-on' example described below is certainly not the only way
1415 to do IPv6 tunneling. However, it is the method that is often used to tunnel
1416 between Linux and a Cisco IPv6 capable router and experience tells us that
1417 this is just the thing many people are after. Ten to one this applies to
1418 you too ;-)
1419 </Para>
1421 <Para>
1422 A short bit about IPv6 addresses:
1423 </Para>
1425 <Para>
1426 IPv6 addresses are, compared to IPv4 addresses, really big: 128 bits
1427 against 32 bits. And this provides us just with the thing we need: many, many
1428 IP-addresses: 340,282,266,920,938,463,463,374,607,431,768,211,465 to be
1429 precise. Apart from this, IPv6 (or IPng, for IP Next Generation) is supposed
1430 to provide for smaller routing tables on the Internet's backbone routers,
1431 simpler configuration of equipment, better security at the IP level and
1432 better support for QoS.
1433 </Para>
1435 <Para>
1436 An example: 2002:836b:9820:0000:0000:0000:836b:9886
1437 </Para>
1439 <Para>
1440 Writing down IPv6 addresses can be quite a burden. Therefore, to make
1441 life easier there are some rules:
1442 </Para>
1444 <Para>
1446 <ItemizedList>
1447 <ListItem>
1449 <Para>
1450 Don't use leading zeroes. Same as in IPv4.
1452 </Para>
1453 </ListItem>
1454 <ListItem>
1456 <Para>
1457 Use colons to separate every 16 bits or two bytes.
1459 </Para>
1460 </ListItem>
1461 <ListItem>
1463 <Para>
1464 When you have lots of consecutive zeroes,
1465 you can write this down as ::. You can only do this once in an
1466 address and only for quantities of 16 bits, though.
1467 </Para>
1468 </ListItem>
1470 </ItemizedList>
1472 </Para>
1474 <Para>
1475 The address 2002:836b:9820:0000:0000:0000:836b:9886 can be written down
1476 as 2002:836b:9820::836b:9886, which is somewhat friendlier.
1477 </Para>
1479 <Para>
1480 Another example, the address 3ffe:0000:0000:0000:0000:0020:34A1:F32C can be
1481 written down as 3ffe::20:34A1:F32C, which is a lot shorter.
1482 </Para>
1484 <Para>
1485 IPv6 is intended to be the successor of the current IPv4. Because it
1486 is relatively new technology, there is no worldwide native IPv6 network
1487 yet. To be able to move forward swiftly, the 6bone was introduced. 
1488 </Para>
1490 <Para>
1491 Native IPv6 networks are connected to each other by encapsulating the IPv6
1492 protocol in IPv4 packets and sending them over the existing IPv4 infrastructure
1493 from one IPv6 site to another. 
1494 </Para>
1496 <Para>
1497 That is precisely where the tunnel steps in.
1498 </Para>
1500 <Para>
1501 To be able to use IPv6, we should have a kernel that supports it. There
1502 are many good documents on how to achieve this. But it all comes down to
1503 a few steps:
1505 <ItemizedList>
1506 <ListItem>
1508 <Para>
1509 Get yourself a recent Linux distribution, with suitable glibc.
1510 </Para>
1511 </ListItem>
1512 <ListItem>
1514 <Para>
1515 Then get yourself an up-to-date kernel source.
1516 </Para>
1517 </ListItem>
1519 </ItemizedList>
1521 If you are all set, then you can go ahead and compile an IPv6 capable
1522 kernel:
1524 <ItemizedList>
1525 <ListItem>
1527 <Para>
1528 Go to /usr/src/linux and type:
1529 </Para>
1530 </ListItem>
1531 <ListItem>
1533 <Para>
1534 make menuconfig
1535 </Para>
1536 </ListItem>
1537 <ListItem>
1539 <Para>
1540 Choose "Networking Options"
1541 </Para>
1542 </ListItem>
1543 <ListItem>
1545 <Para>
1546 Select "The IPv6 protocol", "IPv6: enable EUI-64 token format", "IPv6:
1547 disable provider based addresses"
1548 </Para>
1549 </ListItem>
1551 </ItemizedList>
1553 HINT: Don't go for the 'module' option. Often this won't work well.
1554 </Para>
1556 <Para>
1557 In other words, compile IPv6 as 'built-in' in your kernel.
1558 You can then save your config like usual and go ahead with compiling
1559 the kernel.
1560 </Para>
1562 <Para>
1563 HINT: Before doing so, consider editing the Makefile:
1564 EXTRAVERSION = -x ; --&#62; ; EXTRAVERSION = -x-IPv6
1565 </Para>
1567 <Para>
1568 There is a lot of good documentation about compiling and installing
1569 a kernel, however this document is about something else. If you run into
1570 problems at this stage, go and look for documentation about compiling a
1571 Linux kernel according to your own specifications.
1572 </Para>
1574 <Para>
1575 The file /usr/src/linux/README might be a good start.
1576 After you acomplished all this, and rebooted with your brand new kernel,
1577 you might want to issue an '/sbin/ifconfig -a' and notice the brand 
1578 new 'sit0-device'. SIT stands for Simple Internet Transition. You may give
1579 yourself a compliment; you are now one major step closer to IP, the Next
1580 Generation ;-)
1581 </Para>
1583 <Para>
1584 Now on to the next step. You want to connect your host, or maybe even
1585 your entire LAN to another IPv6 capable network. This might be the "6bone"
1586 that is setup especially for this particular purpose.
1587 </Para>
1589 <Para>
1590 Let's assume that you have the following IPv6 network: 3ffe:604:6:8::/64 and
1591 you want to connect it to 6bone, or a friend. Please note that the /64
1592 subnet notation works just like with regular IP adresses.
1593 </Para>
1595 <Para>
1596 Your IPv4 address is 145.100.24.181 and the 6bone router has IPv4 address
1597 145.100.1.5
1599 <Screen>
1600 # ip tunnel add sixbone mode sit remote 145.100.1.5 [local 145.100.24.181 ttl 255]
1601 # ip link set sixbone up
1602 # ip addr add 3FFE:604:6:7::2/126 dev sixbone
1603 # ip route add 3ffe::0/16 dev sixbone
1604 </Screen>
1606 </Para>
1608 <Para>
1609 Let's discuss this. In the first line, we created a tunnel device called
1610 sixbone. We gave it mode sit (which is IPv6 in IPv4 tunneling) and told it
1611 where to go to (remote) and where to come from (local). TTL is set to
1612 maximum, 255. 
1613 </Para>
1615 <Para>
1616 Next, we made the device active (up). After that, we added our own network
1617 address, and set a route for 3ffe::/15 (which is currently all of 6bone)
1618 through the tunnel. If the particular machine you run this on is your IPv6
1619 gateway, then consider adding the following lines:
1620 </Para>
1622 <Para>
1624 <Screen>
1625 # echo 1 &#62;/proc/sys/net/ipv6/conf/all/forwarding
1626 # /usr/local/sbin/radvd
1627 </Screen>
1629 The latter, radvd is -like zebra- a router advertisement daemon, to
1630 support IPv6's autoconfiguration features. Search for it with your favourite
1631 search-engine if you like.
1632 You can check things like this:
1633 </Para>
1635 <Para>
1637 <Screen>
1638 # /sbin/ip -f inet6 addr
1639 </Screen>
1641 </Para>
1643 <Para>
1644 If you happen to have radvd running on your IPv6 gateway and boot your
1645 IPv6 capable Linux on a machine on your local LAN, you would be able to
1646 enjoy the benefits of IPv6 autoconfiguration:
1648 <Screen>
1649 # /sbin/ip -f inet6 addr
1650 1: lo: &lt;LOOPBACK,UP&gt; mtu 3924 qdisc noqueue inet6 ::1/128 scope host
1652 3: eth0: &lt;BROADCAST,MULTICAST,UP&gt; mtu 1500 qdisc pfifo_fast qlen 100
1653 inet6 3ffe:604:6:8:5054:4cff:fe01:e3d6/64 scope global dynamic
1654 valid_lft forever preferred_lft 604646sec inet6 fe80::5054:4cff:fe01:e3d6/10 
1655 scope link
1656 </Screen>
1658 </Para>
1660 <Para>
1661 You could go ahead and configure your bind for IPv6 addresses. The A
1662 type has an equivalent for IPv6: AAAA. The in-addr.arpa's equivalent is:
1663 ip6.int. There's a lot of information available on this topic.
1664 </Para>
1666 <Para>
1667 There is an increasing number of IPv6-aware applications available,
1668 including secure shell, telnet, inetd, Mozilla the browser, Apache the
1669 websever and a lot of others. But this is all outside the scope of this
1670 Routing document ;-)
1671 </Para>
1673 <Para>
1674 On the Cisco side the configuration would be something like this:
1676 <Screen>
1678 interface Tunnel1
1679 description IPv6 tunnel
1680 no ip address
1681 no ip directed-broadcast
1682 ipv6 enable
1683 ipv6 address 3FFE:604:6:7::1/126
1684 tunnel source Serial0
1685 tunnel destination 145.100.24.181
1686 tunnel mode ipv6ip
1688 ipv6 route 3FFE:604:6:8::/64 Tunnel1
1689 </Screen>
1691 But if you don't have a Cisco at your disposal, try one of the many
1692 IPv6 tunnel brokers available on the Internet. They are willing to configure
1693 their Cisco with an extra tunnel for you. Mostly by means of a friendly
1694 web interface. Search for "ipv6 tunnel broker" on your favourite search engine.
1695 </Para>
1697 </Sect1>
1699 </chapter>
1701 <chapter>
1702 <Title>IPsec: secure IP over the Internet</Title>
1704 <Para>
1705 FIXME: editor vacancy.
1706 In the meantime, see: <ULink
1707 URL="http://www.freeswan.org/"
1708 >The FreeS/WAN project</ULink
1709 >. Another IPSec implementation for Linux is Cerberus,
1710 by NIST. However, their web pages have not been updated in over a year,
1711 and their version tended to trail well behind the current Linux kernel.
1712 USAGI, an alternative IPv6 implementation for Linux, also includes an
1713 IPSec implementation, but that might only be for IPv6.
1714 </Para>
1716 </chapter>
1718 <chapter>
1719 <Title>Multicast routing</Title>
1721 <Para>
1722 FIXME: Editor Vacancy!
1723 </Para>
1725 <Para>
1726 The Multicast-HOWTO is ancient (relatively-speaking) and may be inaccurate
1727 or misleading in places, for that reason.
1728 </Para>
1730 <Para>
1731 Before you can do any multicast routing, you need to configure the Linux
1732 kernel to support the type of multicast routing you want to do. This, in
1733 turn, requires you to decide what type of multicast routing you expect to
1734 be using. There are essentially four "common" types - DVMRP (the Multicast
1735 version of the RIP unicast protocol), MOSPF (the same, but for OSPF), PIM-SM
1736 ("Protocol Independent Multicasting - Sparse Mode", which assumes that users
1737 of any multicast group are spread out, rather than clumped) and PIM-DM (the
1738 same, but "Dense Mode", which assumes that there will be significant clumps
1739 of users of the same multicast group).
1740 </Para>
1742 <Para>
1743 In the Linux kernel, you will notice that these options don't appear. This is
1744 because the protocol itself is handled by a routing application, such as
1745 Zebra, mrouted, or pimd. However, you still have to have a good idea of which
1746 you're going to use, to select the right options in the kernel.
1747 </Para>
1749 <Para>
1750 For all multicast routing, you will definitely need to enable "multicasting"
1751 and "multicast routing". For DVMRP and MOSPF, this is sufficient. If you are
1752 going to use PIM, you must also enable PIMv1 or PIMv2, depending on whether
1753 the network you are connecting to uses version 1 or 2 of the PIM protocol.
1754 </Para>
1756 <Para>
1757 Once you have all that sorted out, and your new Linux kernel compiled, you
1758 will see that the IP protocols listed, at boot time, now include IGMP. This
1759 is a protocol for managing multicast groups. At the time of writing, Linux
1760 supports IGMP versions 1 and 2 only, although version 3 does exist and has
1761 been documented. This doesn't really affect us that much, as IGMPv3 is still
1762 new enough that the extra capabilities of IGMPv3 aren't going to be that
1763 much use. Because IGMP deals with groups, only the features present in the
1764 simplest version of IGMP over the entire group are going to be used. For the
1765 most part, that will be IGMPv2, although IGMPv1 is sill going to be
1766 encountered.
1767 </Para>
1769 <Para>
1770 So far, so good. We've enabled multicasting. Now, we have to tell the Linux
1771 kernel to actually do something with it, so we can start routing. This means
1772 adding the Multicast virtual network to the router table:
1773 </Para>
1775 <Para>
1776 ip route add 224.0.0.0/4 dev eth0
1777 </Para>
1779 <Para>
1780 (Assuming, of course, that you're multicasting over eth0! Substitute the
1781 device of your choice, for this.)
1782 </Para>
1784 <Para>
1785 Now, tell Linux to forward packets...
1786 </Para>
1788 <Para>
1789 echo 1 &#62; /proc/sys/net/ipv4/ip_forward
1790 </Para>
1792 <Para>
1793 At this point, you may be wondering if this is ever going to do anything. So,
1794 to test our connection, we ping the default group, 224.0.0.1, to see if anyone
1795 is alive. All machines on your LAN with multicasting enabled <Emphasis>should</Emphasis>
1796 respond, but nothing else. You'll notice that none of the machines that
1797 respond have an IP address of 224.0.0.1. What a surprise! :) This is a group
1798 address (a "broadcast" to subscribers), and all members of the group will
1799 respond with their own address, not the group address.
1800 </Para>
1802 <Para>
1803 ping -c 2 224.0.0.1
1804 </Para>
1806 <Para>
1807 At this point, you're ready to do actual multicast routing. Well, assuming
1808 that you have two networks to route between.
1809 </Para>
1811 <Para>
1812 (To Be Continued!)
1813 </Para>
1815 </chapter>
1817 <chapter>
1818 <Title>Queueing Disciplines for Bandwidth Management</Title>
1820 <Para>
1821 Now, when I discovered this, it <Emphasis>really</Emphasis> blew me away. Linux 2.2/2.4
1822 comes with everything to manage bandwidth in ways comparable to high-end
1823 dedicated bandwidth management systems.
1824 </Para>
1826 <Para>
1827 Linux even goes far beyond what Frame and ATM provide. 
1828 </Para>
1830 <Para>
1831 Just to prevent confusion, tc uses the following rules for bandwith
1832 specification:
1834 <Screen>
1836 mbps = 1024 kbps = 1024 * 1024 bps =&#62; byte/s
1837 mbit = 1024 kbit =&#62; kilo bit/s.
1838 mb = 1024 kb = 1024 * 1024 b =&#62; byte
1839 mbit = 1024 kbit =&#62; kilo bit.
1840 </Screen>
1842 Internally, the number is stored in bps and b.
1843 </Para>
1845 <Para>
1846 But when tc prints the rate, it uses following :
1848 <Screen>
1849 1Mbit = 1024 Kbit = 1024 * 1024 bps =&#62; bit/s
1850 </Screen>
1852 </Para>
1854 <Sect1>
1855 <Title>Queues and Queueing Disciplines explained</Title>
1857 <Para>
1858 With queueing we determine the way in which data is <Emphasis>sent</Emphasis>. It is
1859 important to realise that we can only shape data that we transmit.
1860 </Para>
1862 <Para>
1863 With the way the Internet works, we have no direct control of what people
1864 send us. It's a bit like your (physical!) mailbox at home. There is no way
1865 you can influence the world to modify the amount of mail they send you,
1866 short of contacting everybody.
1867 </Para>
1869 <Para>
1870 However, the Internet is mostly based on TCP/IP which has a few features
1871 that help us. TCP/IP has no way of knowing the capacity of the network
1872 between two hosts, so it just starts sending data faster and faster ('slow
1873 start') and when packets start getting lost, because there is no room to
1874 send them, it will slow down. In fact it is a bit smarter than this, but
1875 more about that later.
1876 </Para>
1878 <Para>
1879 This is the equivalent of not reading half of your mail, and hoping that
1880 people will stop sending it to you. With the difference that it works for
1881 the Internet :-)
1882 </Para>
1884 <Para>
1885 If you have a router and wish to prevent certain hosts within your network
1886 from downloading too fast, you need to do your shaping on the *inner* interface
1887 of your router, the one that sends data to your own computers.
1888 </Para>
1890 <Para>
1891 You also have to be sure you are controlling the bottleneck of the link.
1892 If you have a 100Mbit NIC and you have a router that has a 256kbit link,
1893 you have to make sure you are not sending more data than your router can
1894 handle.  Othewise, it will be the router who is controlling the link and
1895 shaping the available bandwith. We need to 'own the queue' so to speak, and
1896 be the slowest link in the chain. Luckily this is easily possible.
1897 </Para>
1899 </Sect1>
1901 <Sect1>
1902 <Title>Simple, classless Queueing Disciplines</Title>
1904 <Para>
1905 As said, with queueing disciplines, we change the way data is sent.
1906 Classless queueing disciplines are those that, by and large accept data and
1907 only reschedule, delay or drop it.
1908 </Para>
1910 <Para>
1911 These can be used to shape traffic for an entire interface, without any
1912 subdivisions. It is vital that you understand this part of queueing before
1913 we go on the the classful qdisc-containing-qdiscs!
1914 </Para>
1916 <Para>
1917 By far the most widely used discipline is the pfifo_fast qdisc - this is the
1918 default. This also explains why these advanced features are so robust. They
1919 are nothing more than 'just another queue'.
1920 </Para>
1922 <Para>
1923 Each of these queues has specific strengths and weaknesses. Not all of them
1924 may be as well tested.
1925 </Para>
1927 <Sect2>
1928 <Title>pfifo_fast</Title>
1930 <Para>
1931 This queue is, as the name says, First In, First Out, which means that no
1932 packet receives special treatment. At least, not quite. This queue has 3 so
1933 called 'bands'. Within each band, FIFO rules apply. However, as long as
1934 there are packets waiting in band 0, band 1 won't be processed. Same goes
1935 for band 1 and band 2.
1936 </Para>
1938 <Para>
1939 The kernel honors the so called Type of Service flag of packets, and takes
1940 care to insert 'minimum delay' packets in band 0. 
1941 </Para>
1943 <Para>
1944 Do not confuse this classless simple qdisc with the classful PRIO one!
1945 Although they behave similarly, pfifo_fast is classless and you cannot add
1946 other qdiscs to it with the tc command.
1947 </Para>
1949 <Sect3>
1950 <Title>Parameters &amp; usage</Title>
1952 <Para>
1953 You can't configure the pfifo_fast qdisc as it is the hardwired default.
1954 This is how it is configured by default:
1955 <VariableList>
1957 <VarListEntry>
1958 <Term>priomap</Term>
1959 <ListItem>
1960 <Para>
1961 Determines how packet priorities, as assigned by the kernel, map to bands.
1962 Mapping occurs based on the TOS octet of the packet, which looks like this:
1963 </Para>
1965 <Para>
1967 <Screen>
1968    0     1     2     3     4     5     6     7
1969 +-----+-----+-----+-----+-----+-----+-----+-----+
1970 |                 |                       |     |
1971 |   PRECEDENCE    |          TOS          | MBZ |
1972 |                 |                       |     |
1973 +-----+-----+-----+-----+-----+-----+-----+-----+
1974 </Screen>
1976 </Para>
1978 <Para>
1979 The four TOS bits (the 'TOS field') are defined as:
1981 <Screen>
1982 Binary Decimcal  Meaning
1983 -----------------------------------------
1984 1000   8         Minimize delay (md)
1985 0100   4         Maximize throughput (mt)
1986 0010   2         Maximize reliability (mr)
1987 0001   1         Minimize monetary cost (mmc)
1988 0000   0         Normal Service
1989 </Screen>
1991 </Para>
1993 <Para>
1994 As there is 1 bit to the right of these four bits, the actual value of the
1995 TOS field is double the value of the TOS bits. Tcpdump -v -v shows you the
1996 value of the entire TOS field, not just the four bits. It is the value you
1997 see in the first column of this table:
1998 </Para>
2000 <Para>
2002 <Screen>
2003 TOS     Bits  Means                    Linux Priority    Band
2004 ------------------------------------------------------------
2005 0x0     0     Normal Service           0 Best Effort     1
2006 0x2     1     Minimize Monetary Cost   1 Filler          2
2007 0x4     2     Maximize Reliability     0 Best Effort     1
2008 0x6     3     mmc+mr                   0 Best Effort     1
2009 0x8     4     Maximize Throughput      2 Bulk            2
2010 0xa     5     mmc+mt                   2 Bulk            2
2011 0xc     6     mr+mt                    2 Bulk            2
2012 0xe     7     mmc+mr+mt                2 Bulk            2
2013 0x10    8     Minimize Delay           6 Interactive     0
2014 0x12    9     mmc+md                   6 Interactive     0
2015 0x14    10    mr+md                    6 Interactive     0
2016 0x16    11    mmc+mr+md                6 Interactive     0
2017 0x18    12    mt+md                    4 Int. Bulk       1
2018 0x1a    13    mmc+mt+md                4 Int. Bulk       1
2019 0x1c    14    mr+mt+md                 4 Int. Bulk       1
2020 0x1e    15    mmc+mr+mt+md             4 Int. Bulk       1
2021 </Screen>
2023 </Para>
2025 <Para>
2026 Lots of numbers. The second column contains the value of the relevant four
2027 TOS bits, followed by their translated meaning. For example, 15 stands for a
2028 packet wanting Minimal Montetary Cost, Maximum Reliability, Maximum
2029 Throughput AND Minimum Delay. I would call this a 'Dutch Packet'.
2030 </Para>
2032 <Para>
2033 The fourth column lists the way the Linux kernel interprets the TOS bits, by
2034 showing to which Priority they are mapped. 
2035 </Para>
2037 <Para>
2038 The last column shows the result of the default priomap. On the commandline,
2039 the default priomap looks like this:
2041 <Screen>
2042 1, 2, 2, 2, 1, 2, 0, 0 , 1, 1, 1, 1, 1, 1, 1, 1
2043 </Screen>
2045 </Para>
2047 <Para>
2048 This means that priority 4, for example, gets mapped to band number 1. The
2049 priomap also allows you to list higher priorities (&gt; 7) which do not
2050 correspond to TOS mappings, but which are set by other means.
2051 </Para>
2053 <Para>
2054 This table from RFC 1349 (read it for more details) tells you how
2055 applications might very well set their TOS bits:
2057 <Screen>
2058 TELNET                   1000           (minimize delay)
2060         Control          1000           (minimize delay)
2061         Data             0100           (maximize throughput)
2063 TFTP                     1000           (minimize delay)
2065 SMTP 
2066         Command phase    1000           (minimize delay)
2067         DATA phase       0100           (maximize throughput)
2069 Domain Name Service
2070         UDP Query        1000           (minimize delay)
2071         TCP Query        0000
2072         Zone Transfer    0100           (maximize throughput)
2074 NNTP                     0001           (minimize monetary cost)
2076 ICMP
2077         Errors           0000
2078         Requests         0000 (mostly)
2079         Responses        &#60;same as request&#62; (mostly)
2080 </Screen>
2082 </Para>
2083 </VarListEntry>
2084 <VarListEntry>
2085 <Term>txqueuelen</Term>
2086 <ListItem>
2087 <Para>
2088 The length of this queue is gleaned from the interface configuration, which
2089 you can see and set with ifconfig and ip. To set the queue length to 10,
2090 execute: ifconfig eth0 txqueuelen 10
2091 </Para>
2093 <Para>
2094 You can't set this parameter with tc!
2095 </Para>
2096 </VarListEntry>
2097 </VariableList>
2098 </Para>
2100 </Sect3>
2102 </Sect2>
2104 <Sect2>
2105 <Title>Token Bucket Filter</Title>
2107 <Para>
2108 The Token Bucket Filter (TBF) is a simple qdisc that only passes packets
2109 arriving at a rate which is not exceeding some administratively set rate, but
2110 with the possibility to allow short bursts in excess of this rate.
2111 </Para>
2113 <Para>
2114 TBF is very precise, network- and processor friendly. It should be your
2115 first choice if you simply want to slow an interface down!
2116 </Para>
2118 <Para>
2119 The TBF implementation consists of a buffer (bucket), constantly filled by
2120 some virtual pieces of information called tokens, at a specific rate (token
2121 rate). The most important parameter of the bucket is its size, that is the
2122 number of tokens it can store.
2123 </Para>
2125 <Para>
2126 Each arriving token collects one incoming data packet from the data queue
2127 and is then deleted from the bucket. Associating this algorithm
2128 with the two flows -- token and data, gives us three possible scenarios:
2129 </Para>
2131 <para>
2133 To use the TBF, make sure that you have compiled TBF support (under
2134 networking options -> QoS &amp; fair queueing -> TBF queue) in the linux
2135 kernel, to make the token bucket filter work.
2137 </para>
2139 <Para>
2141 <ItemizedList>
2142 <ListItem>
2144 <Para>
2145  The data arrives in TBF at a rate that's <Emphasis>equal</Emphasis> to the rate
2146 of incoming tokens. In this case each incoming packet has its matching token
2147 and passes the queue without delay.
2149 </Para>
2150 </ListItem>
2151 <ListItem>
2153 <Para>
2154  The data arrives in TBF at a rate that's <Emphasis>smaller</Emphasis> than the
2155 token rate. Only a part of the tokens are deleted at output of each data packet
2156 that's sent out the queue, so the tokens accumulate, up to the bucket size.
2157 The unused tokens can then be used to send data a a speed that's exceeding the
2158 standard token rate, in case short data bursts occur.
2160 </Para>
2161 </ListItem>
2162 <ListItem>
2164 <Para>
2165  The data arrives in TBF at a rate <Emphasis>bigger</Emphasis> than the token rate.
2166 This means that the bucket will soon be devoid of tokens, which causes the
2167 TBF to throttle itself for a while. This is called an 'overlimit situation'.
2168 If packets keep coming in, packets will start to get dropped.
2169 </Para>
2170 </ListItem>
2172 </ItemizedList>
2174 </Para>
2176 <Para>
2177 The last scenario is very important, because it allows to
2178 administratively shape the bandwidth available to data that's passing
2179 the filter.
2180 </Para>
2182 <Para>
2183 The accumulation of tokens allows a short burst of overlimit data to be
2184 still passed without loss, but any lasting overload will cause packets to be
2185 constantly delayed, and then dropped.
2186 </Para>
2188 <Para>
2189 Please note that in the actual implementation, tokens correspond to bytes,
2190 not packets.
2191 </Para>
2193 <Sect3>
2194 <Title>Parameters &amp; usage</Title>
2196 <Para>
2197 Even though you will probably not need to change them, tbf has some knobs
2198 available. First the parameters that are always available:
2199 <VariableList>
2201 <VarListEntry>
2202 <Term>limit or latency</Term>
2203 <ListItem>
2204 <Para>
2205 Limit is the number of bytes that can be queued waiting for tokens to become
2206 available. You can also specify this the other way around by setting the
2207 latency parameter, which specifies the maximum amount of time a packet can
2208 sit in the TBF. The latter calculation takes into account the size of the
2209 bucket, the rate and possibly the peakrate (if set).
2210 </Para>
2211 </VarListEntry>
2212 <VarListEntry>
2213 <Term>burst/buffer/maxburst</Term>
2214 <ListItem>
2215 <Para>
2216 Size of the bucket, in bytes. This is the maximum amount of bytes that
2217 tokens can be available for instantaneously. In general, larger shaping
2218 rates require a larger buffer. For 10mbit/s on Intel, you need at least
2219 10kbyte buffer if you want to reach your configured rate!
2220 </Para>
2222 <Para>
2223 If your buffer is too small, packets may be dropped because more tokens
2224 arrive per timer tick than fit in your bucket.
2225 </Para>
2226 </VarListEntry>
2227 <VarListEntry>
2228 <Term>mpu</Term>
2229 <ListItem>
2230 <Para>
2231 A zero-sized packet does not use zero bandwidth. For ethernet, no packet
2232 uses less than 64 bytes. The Minimum Packet Unit determines the minimal
2233 token usage for a packet.
2234 </Para>
2235 </VarListEntry>
2236 <VarListEntry>
2237 <Term>rate</Term>
2238 <ListItem>
2239 <Para>
2240 The speedknob. See remarks above about limits!
2241 </Para>
2242 </VarListEntry>
2243 </VariableList>
2244 </Para>
2246 <Para>
2247 If the bucket contains tokens and is allowed to empty, by default it does so
2248 at infinite speed. If this is unacceptable, use the following parameters:
2249 </Para>
2251 <Para>
2252 <VariableList>
2254 <VarListEntry>
2255 <Term>peakrate</Term>
2256 <ListItem>
2257 <Para>
2258 If tokens are available, and packets arrive, they are sent out immediately
2259 by default, at 'lightspeed' so to speak. That may not be what you want,
2260 especially if you have a large bucket. 
2261 </Para>
2263 <Para>
2264 The peakrate can be used to specify how quickly the bucket is allowed to be
2265 depleted. If doing everything by the book, this is achieved by releasing a
2266 packet, and then wait just long enough, and release the next. We calculated
2267 our waits so we send just at peakrate.
2268 </Para>
2270 <Para>
2271 However, due to de default 10ms timer resolution of Unix, with 10.000 bits
2272 average packets, we are limited to 1mbit/s of peakrate!
2273 </Para>
2274 </VarListEntry>
2275 <VarListEntry>
2276 <Term>mtu/minburst</Term>
2277 <ListItem>
2278 <Para>
2279 The 1mbit/s peakrate is not very useful if your regular rate is more than
2280 that. A higher peakrate is possible by sending out more packets per
2281 timertick, which effectively means that we create a second bucket!
2282 </Para>
2284 <Para>
2285 This second bucket defaults to a single packet, which is not a bucket at
2286 all.
2287 </Para>
2289 <Para>
2290 To calculate the maximum possible peakrate, multiply the configured mtu by
2291 100 (or more correctly, HZ, which is 100 on intel, 1024 on Alpha).
2292 </Para>
2293 </VarListEntry>
2294 </VariableList>
2295 </Para>
2297 </Sect3>
2299 <Sect3>
2300 <Title>Sample configuration</Title>
2302 <Para>
2303 A simple but *very* useful configuration is this:
2305 <Screen>
2306 # tc qdisc add dev ppp0 root tbf rate 220kbit latency 50ms burst 1540
2307 </Screen>
2309 </Para>
2311 <Para>
2312 Ok, why is this useful? If you have a networking device with a large queue,
2313 like a DSL modem or a cablemodem, and you talk to it over a fast device,
2314 like over an ethernet interface, you will find that uploading absolutely
2315 destroys interactivity.
2316 </Para>
2318 <Para>
2319 This is because uploading will fill the queue in the modem, which is
2320 probably *huge* because this helps actually achieving good data throughput
2321 uploading. But this is not what you want, you want to have the queue not too
2322 big so interactivity remains and you can still do other stuff while sending
2323 data.
2324 </Para>
2326 <Para>
2327 The line above slows down sending to a rate that does not lead to a queue in
2328 the modem - the queue will be in Linux, where we can control it to a limited
2329 size.
2330 </Para>
2332 <Para>
2333 Change 220kbit to your uplink's *actual* speed, minus a few percent. If you
2334 have a really fast modem, raise 'burst' a bit. 
2335 </Para>
2337 </Sect3>
2339 </Sect2>
2341 <Sect2>
2342 <Title>Stochastic Fairness Queueing</Title>
2344 <Para>
2345 Stochastic Fairness Queueing (SFQ) is a simple implementation of the fair
2346 queueing algorithms family. It's less accurate than others, but it also
2347 requires less calculations while being almost perfectly fair.
2348 </Para>
2350 <Para>
2351 The key word in SFQ is conversation (or flow), which mostly corresponds to a
2352 TCP session or a UDP stream. Traffic is divided into a pretty large number
2353 of FIFO queues, one for each conversation. Traffic is then sent in a round
2354 robin fashion, giving each session the chance to send data in turn.
2355 </Para>
2357 <Para>
2358 This leads to very fair behaviour and disallows any single conversation from
2359 drowning out the rest. SFQ is called 'Stochastic' because it doesn't really
2360 allocate a queue for each session, it has an algorithm which divides traffic
2361 over a limited number of queues using a hashing algorithm. 
2362 </Para>
2364 <Para>
2365 Because of the hash, multiple sessions might end up in the same bucket, which
2366 would halve each session's chance of sending a packet, thus halving the
2367 effective speed available. To prevent this situation from becoming
2368 noticeable, SFQ changes its hashing algorithm quite often so that any two
2369 colliding sessions will only do so for a small number of seconds.
2370 </Para>
2372 <Para>
2373 It is important to note that SFQ is only useful in case your actual outgoing
2374 interface is really full! If it isn't then there will be no queue on your
2375 linux machine and hence no effect. Later on we will describe how to combine
2376 SFQ with other qdiscs to get a best-of-both worlds situation.
2377 </Para>
2379 <Para>
2380 Specifically, setting SFQ on the ethernet interface heading to your
2381 cablemodem or DSL router is pointless without further shaping!
2382 </Para>
2384 <Sect3>
2385 <Title>Parameters &amp; usage</Title>
2387 <Para>
2388 The SFQ is pretty much selftuning:
2389 <VariableList>
2391 <VarListEntry>
2392 <Term>perturb</Term>
2393 <ListItem>
2394 <Para>
2395 Reconfigure hashing once this many seconds. If unset, hash will never be
2396 reconfigured. Not recommended. 10 seconds is probably a good value.
2397 </Para>
2398 </VarListEntry>
2399 <VarListEntry>
2400 <Term>quantum</Term>
2401 <ListItem>
2402 <Para>
2403 Amount of bytes a stream is allowed to dequeue before the next queue gets a
2404 turn. Defaults to 1 maximum sized packet (MTU-sized). Do not set below the
2405 MTU!
2406 </Para>
2407 </VarListEntry>
2408 </VariableList>
2409 </Para>
2411 </Sect3>
2413 <Sect3>
2414 <Title>Sample configuration</Title>
2416 <Para>
2417 If you have a device which has identical link speed and actual available
2418 rate, like a phone modem, this configuration will help promote fairness:
2420 <Screen>
2421 # tc qdisc add dev ppp0 root sfq perturb 10
2422 # tc -s -d qdisc ls
2423 qdisc sfq 800c: dev ppp0 quantum 1514b limit 128p flows 128/1024 perturb 10sec 
2424  Sent 4812 bytes 62 pkts (dropped 0, overlimits 0) 
2425 </Screen>
2427 </Para>
2429 <Para>
2430 The number 800c: is the automatically assigned handle number, limit means
2431 that 128 packets can wait in this queue. There are 1024 hashbuckets
2432 available for accounting, of which 128 can be active at a time (no more
2433 packets fit in the queue!) Once every 10 seconds, the hashes are
2434 reconfigured.
2435 </Para>
2437 </Sect3>
2439 </Sect2>
2441 </Sect1>
2443 <Sect1>
2444 <Title>Advice for when to use which queue</Title>
2446 <Para>
2447 Summarizing, these are the simple queues that actually manage traffic by
2448 reordering, slowing or dropping packets.
2449 </Para>
2451 <Para>
2452 The following tips may help in chosing which queue to use. It mentions some
2453 qdiscs described in the 'Advanced &amp; less common queueing disciplines'.
2454 </Para>
2456 <Para>
2458 <ItemizedList>
2459 <ListItem>
2461 <Para>
2462 To purely slow down outgoing traffic, use the Token Bucket Filter. Works up
2463 to huge bandwidths, if you scale the bucket.
2464 </Para>
2465 </ListItem>
2466 <ListItem>
2468 <Para>
2469 If your link is truly full and you want to make sure that no single session
2470 can dominate your outgoing bandwidth, use Stochastical Fairness Queueing.
2471 </Para>
2472 </ListItem>
2473 <ListItem>
2475 <Para>
2476 If you have a big backbone and know what you are doing, consider Random
2477 Early Drop (see Advanced chapter).
2478 </Para>
2479 </ListItem>
2480 <ListItem>
2482 <Para>
2483 To 'shape' incoming traffic which you are not forwarding, use the Ingress
2484 Policer. Incoming shaping is called 'policing', by the way, not 'shaping'.  
2485 </Para>
2486 </ListItem>
2487 <ListItem>
2489 <Para>
2490 If you *are* forwarding it, use a TBF on the interface you are forwarding
2491 the data to. Unless you want to shape traffic that may go out over several
2492 interfaces, in which case the only common factor is the incoming interface.
2493 In that case use the Ingress Policer.
2494 </Para>
2495 </ListItem>
2496 <ListItem>
2498 <Para>
2499 If you don't want to shape, but only want to see if your interface is so
2500 loaded that it has to queue, use the pfifo queue (not pfifo_fast). It lacks
2501 internal bands but does account the size of its backlog.
2502 </Para>
2503 </ListItem>
2504 <ListItem>
2506 <Para>
2507 Finally - you can also do 'social shaping'. You may not always be able to
2508 use technology to achieve what you want. Users experience technical
2509 constraints as hostile. A kind word may also help with getting your
2510 bandwidth to be divided right!
2511 </Para>
2512 </ListItem>
2514 </ItemizedList>
2516 </Para>
2518 </Sect1>
2520 <Sect1>
2521 <Title>Terminology </Title>
2523 <Para>
2524 To properly understand more complicated configurations it is necessary to
2525 explain a few concepts first. Because of the complexity and he relative
2526 youth of the subject, a lot of different words are used when people in fact
2527 mean the same thing.
2528 </Para>
2530 <Para>
2531 The following is loosely based on draft-ietf-diffserv-model-06.txt, 'An
2532 Informal Management Model for Diffserv Routers'. It can currently be found
2533 at http://www.ietf.org/internet-drafts/draft-ietf-diffserv-model-06.txt.
2534 </Para>
2536 <Para>
2537 Read it for the strict definitions of the terms used.
2538 <VariableList>
2540 <VarListEntry>
2541 <Term>Queueing Discipline</Term>
2542 <ListItem>
2543 <Para>
2544 An algorithm that manages the queue of a device, either incoming (ingress)
2545 or outgoing (egress).
2546 </Para>
2547 </VarListEntry>
2548 <VarListEntry>
2549 <Term>Classless qdisc</Term>
2550 <ListItem>
2551 <Para>
2552 A qdisc with no configurable internal subdivisions. 
2553 </Para>
2554 </VarListEntry>
2555 <VarListEntry>
2556 <Term>Classful qdisc</Term>
2557 <ListItem>
2558 <Para>
2559 A classful qdisc contains multiple classes. Each of these classes contains a
2560 further qdisc, which may again be classful, but need not be. According to
2561 the strict definition, pfifo_fast *is* classful, because it contains three
2562 bands which are, in fact, classes. However, from the user's configuration
2563 perspective, it is classless as the classes can't be touched with the tc
2564 tool. 
2565 </Para>
2566 </VarListEntry>
2567 <VarListEntry>
2568 <Term>Classes</Term>
2569 <ListItem>
2570 <Para>
2571 A classful qdisc may have many classes, which each are internal to the
2572 qdisc. Each of these classes may contain a real qdisc.
2573 </Para>
2574 </VarListEntry>
2575 <VarListEntry>
2576 <Term>Classifier</Term>
2577 <ListItem>
2578 <Para>
2579 Each classful qdisc needs to determine to which class it needs to send a
2580 packet. This is done using the classifier.
2581 </Para>
2582 </VarListEntry>
2583 <VarListEntry>
2584 <Term>Filter</Term>
2585 <ListItem>
2586 <Para>
2587 Classification can be performed using filters. A filter contains a number of
2588 conditions which if matched, make the filter match.
2589 </Para>
2590 </VarListEntry>
2591 <VarListEntry>
2592 <Term>Scheduling</Term>
2593 <ListItem>
2594 <Para>
2595 A qdisc may, with the help of a classifier, decide that some packets need to
2596 go out earlier than others. This process is called Scheduling, and is
2597 performed for example by the pfifo_fast qdisc mentioned earlier. Scheduling
2598 is also called 'reordering', but this is confusing.
2599 </Para>
2600 </VarListEntry>
2601 <VarListEntry>
2602 <Term>Shaping</Term>
2603 <ListItem>
2604 <Para>
2605 The process of delaying packets before they go out to make traffic confirm
2606 to a configured maximum rate. Shaping is performed on egress. Colloquially, 
2607 dropping packets to slow traffic down is also often called Shaping.
2608 </Para>
2609 </VarListEntry>
2610 <VarListEntry>
2611 <Term>Policing</Term>
2612 <ListItem>
2613 <Para>
2614 Delaying or dropping packets in order to make traffic stay below a
2615 configured bandwidth. In Linux, policing can only drop a packet and not
2616 delay it - there is no 'ingress queue'.
2617 </Para>
2618 </VarListEntry>
2619 <VarListEntry>
2620 <Term>Work-Conserving</Term>
2621 <ListItem>
2622 <Para>
2623 A work-conserving qdisc always delivers a packet if one is available. In
2624 other words, it never delays a packet if the network adaptor is ready to
2625 send one (in the case of an egress qdisc).
2626 </Para>
2627 </VarListEntry>
2628 <VarListEntry>
2629 <Term>non-Work-Conserving</Term>
2630 <ListItem>
2631 <Para>
2632 Some queues, like for example the Token Bucket Filter, may need to hold on
2633 to a packet for a certain time in order to limit the bandwidth. This means
2634 that they sometimes refuse to give up a packet, even though they have one
2635 available.
2636 </Para>
2637 </VarListEntry>
2638 </VariableList>
2639 </Para>
2641 <Para>
2642 Now that we have our terminology straight, let's see where all these things
2643 are.
2644 </Para>
2646 <Para>
2648 <Screen>
2649                 Userspace programs
2650                      ^
2651                      |
2652      +---------------+-----------------------------------------+
2653      |               Y                                         |
2654      |    -------&#62; IP Stack                                    |
2655      |   |              |                                      |
2656      |   |              Y                                      |
2657      |   |              Y                                      |
2658      |   ^              |                                      |
2659      |   |  / ----------&#62; Forwarding -&#62;                        |
2660      |   ^ /                           |                       |
2661      |   |/                            Y                       |
2662      |   |                             |                       |
2663      |   ^                             Y          /-qdisc1-\   |
2664      |   |                            Egress     /--qdisc2--\  |
2665   ---&#62;-&#62;Ingress                       Classifier ---qdisc3---- | -&#62;
2666      |   Qdisc                                   \__qdisc4__/  |
2667      |                                            \-qdiscN_/   |
2668      |                                                         |
2669      +----------------------------------------------------------+
2670 </Screen>
2672 Thanks to Jamal Hadi Salim for this ascii representation.
2673 </Para>
2675 <Para>
2676 The big block represents the kernel. The leftmost arrow represents traffic
2677 entering your machine from the network. It is then fed to the Ingress
2678 Qdisc which may apply Filters to a packet, and decide to drop it. This
2679 is called 'Policing'.
2680 </Para>
2682 <Para>
2683 This happens at a very early stage, before it has seen a lot of the kernel.
2684 It is therefore a very good place to drop traffic very early, without
2685 consuming a lot of CPU power.
2686 </Para>
2688 <Para>
2689 If the packet is allowed to continue, it may be destined for a local
2690 application, in which case it enters the IP stack in order to be processed,
2691 and handed over to a userspace program. The packet may also be forwarded
2692 without entering an application, in which case it is destined for egress.
2693 Userspace programs may also deliver data, which is then examined and
2694 forwarded to the Egress Classifier.
2695 </Para>
2697 <Para>
2698 There it is investigated and enqueued to any of a number of qdiscs. In the
2699 unconfigured default case, there is only one egress qdisc installed, the
2700 pfifo_fast, which always receives the packet. This is called 'enqueueing'.
2701 </Para>
2703 <Para>
2704 The packet now sits in the qdisc, waiting for the kernel to ask for
2705 it for transmission over the network interface. This is called 'dequeueing'.
2706 </Para>
2708 <Para>
2709 This picture also holds in case there is only one network adaptor - the
2710 arrows entering and leaving the kernel should not be taken too literally.
2711 Each network adaptor has both ingress and egress hooks.
2712 </Para>
2714 </Sect1>
2716 <Sect1>
2717 <Title>Classful Queueing Disciplines</Title>
2719 <Para>
2720 Classful qdiscs are very useful if you have different kinds of traffic which
2721 should have differing treatment. One of the classful qdiscs is called 'CBQ'
2722 , 'Class Based Queueing' and it is so widely mentioned that people identify
2723 queueing with classes solely with CBQ, but this is not the case.
2724 </Para>
2726 <Para>
2727 CBQ is merely the oldest kid on the block - and also the most complex one.
2728 It may not always do what you want.  This may come as something of a shock
2729 to many who fell for the 'sendmail effect', which teaches us that any
2730 complex technology which doesn't come with documentation must be the best
2731 available.
2732 </Para>
2734 <Para>
2735 More about CBQ and its alternatives shortly.
2736 </Para>
2738 <Sect2>
2739 <Title>Flow within classful qdiscs &amp; classes</Title>
2741 <Para>
2742 When traffic enters a classful qdisc, it needs to be sent to any of the
2743 classes within - it needs to be 'classified'. To determine what to do with a
2744 packet, the so called 'filters' are consulted. It is important to know that
2745 the filters are called from within a qdisc, and not the other way around!
2746 </Para>
2748 <Para>
2749 The filters attached to that qdisc then return with a decision, and the
2750 qdisc uses this to enqueue the packet into one of the classes. Each subclass
2751 may try other filters to see if further instructions apply. If not, the
2752 class enqueues the packet to the qdisc it contains.
2753 </Para>
2755 <Para>
2756 Besides containing other qdiscs, most classful qdiscs also perform shaping.
2757 This is useful to perform both packet scheduling (with SFQ, for example) and
2758 rate control. You need this in cases where you have a high speed
2759 interface (for example, ethernet) to a slower device (a cable modem).
2760 </Para>
2762 <Para>
2763 If you were only to run SFQ, nothing would happen, as packets enter &amp;
2764 leave your router without delay: the output interface is far faster than
2765 your actual link speed. There is no queue to schedule then.
2766 </Para>
2768 </Sect2>
2770 <Sect2>
2771 <Title>The qdisc family: roots, handles, siblings and parents</Title>
2773 <Para>
2774 Each interface has one egress 'root qdisc', by default the earlier mentioned
2775 classless pfifo_fast queueing discipline. Each qdisc can be assigned a
2776 handle, which can be used by later configuration statements to refer to that
2777 qdisc. Besides an egress qdisc, an interface may also have an ingress, which
2778 polices traffic coming in.
2779 </Para>
2781 <Para>
2782 The handles of these qdiscs consist of two parts, a major number and a minor
2783 number. It is habitual to name the root qdisc '1:', which is equal to '1:0'.
2784 The minor number of a qdisc is always 0. 
2785 </Para>
2787 <Para>
2788 Classes need to have the same major number as their parent. 
2789 </Para>
2791 <Sect3>
2792 <Title>How filters are used to classify traffic </Title>
2794 <Para>
2795 Recapping, a typical hierarchy might look like this:
2797 <Screen>
2798                     root 1:
2799                       |
2800                     _1:1_
2801                    /  |  \
2802                   /   |   \
2803                  /    |    \
2804                10:   11:   12:
2805               /   \       /   \
2806            10:1  10:2   12:1  12:2
2807 </Screen>
2809 </Para>
2811 <Para>
2812 But don't let this tree fool you! You should *not* imagine the kernel to be
2813 at the apex of the tree and the network below, that is just not the case.
2814 Packets get enqueued and dequeued at the root qdisc, which is the only thing
2815 the kernel talks to. 
2816 </Para>
2818 <Para>
2819 A packet might get classified in a chain like this:
2820 </Para>
2822 <Para>
2823 1: -&#62; 1:1 -&#62; 12: -&#62; 12:2
2824 </Para>
2826 <Para>
2827 The packet now resides in a queue in a qdisc attached to class 12:2. In this
2828 example, a filter was attached to each 'node' in the tree, each chosing a
2829 branch to take next. This can make sense. However, this is also possible:
2830 </Para>
2832 <Para>
2833 1: -&#62; 12:2
2834 </Para>
2836 <Para>
2837 In this case, a filter attached to the root decided to send the packet
2838 directly to 12:2.
2839 </Para>
2841 </Sect3>
2843 <Sect3>
2844 <Title>How packets are dequeued to the hardware</Title>
2846 <Para>
2847 When the kernel decides that it needs to extract packets to send to the
2848 interface, the root qdisc 1: gets a dequeue request, which is passed to
2849 1:1, which is in turn passed to 10:, 11: and 12:, which each query their
2850 siblings, and try to dequeue() from them. In this case, the kernel needs to
2851 walk the entire tree, because only 12:2 contains a packet. 
2852 </Para>
2854 <Para>
2855 In short, nested classes ONLY talk to their parent qdiscs, never to an
2856 interface. Only the root qdisc gets dequeued by the kernel!
2857 </Para>
2859 <Para>
2860 The upshot of this is that classes never get dequeued faster than their
2861 parents allow. And this is exactly what we want: this way we can have SFQ in
2862 an inner class, which doesn't do any shaping, only scheduling, and have a
2863 shaping outer qdisc, which does the shaping.
2864 </Para>
2866 </Sect3>
2868 </Sect2>
2870 <Sect2>
2871 <Title>The PRIO qdisc</Title>
2873 <Para>
2874 The PRIO qdisc doesn't actually shape, it only subdivides traffic based on
2875 how you configured your filters. You can consider the PRIO qdisc a kind
2876 of pfifo_fast on stereoids, whereby each band is a separate class instead of
2877 a simple FIFO.
2878 </Para>
2880 <Para>
2881 When a packet is enqueued to the PRIO qdisc, a class is chosen based on the
2882 filter commands you gave. By default, three classes are created. These
2883 classes by default contain pure FIFO qdiscs with no internal
2884 structure, but you can replace these by any qdisc you have available.
2885 </Para>
2887 <Para>
2888 Whenever a packet needs to be dequeued, class :1 is tried first. Higher
2889 classes are only used if lower bands all did not give up a packet.
2890 </Para>
2892 <Para>
2893 This qdisc is very useful in case you want to prioritize certain kinds of
2894 traffic without using only TOS-flags but using all the power of the tc
2895 filters. It can also contain more all qdiscs, whereas pfifo_fast is limited
2896 to simple fifo qdiscs.
2897 </Para>
2899 <Para>
2900 Because it doesn't actually shape, the same warning as for SFQ holds: either
2901 use it only if your physical link is really full or wrap it inside a
2902 classful qdisc that does shape. The last holds for almost all cablemodems
2903 and DSL devices.
2904 </Para>
2906 <Para>
2907 In formal words, the PRIO qdisc is a Work-Conserving scheduler.
2908 </Para>
2910 <Sect3>
2911 <Title>PRIO parameters &amp; usage</Title>
2913 <Para>
2914 The following parameters are recognized by tc:
2915 <VariableList>
2917 <VarListEntry>
2918 <Term>bands</Term>
2919 <ListItem>
2920 <Para>
2921 Number of bands to create. Each band is in fact a class. If you change this
2922 number, you must also change:
2923 </Para>
2924 </VarListEntry>
2925 <VarListEntry>
2926 <Term>priomap</Term>
2927 <ListItem>
2928 <Para>
2929 If you do not provide tc filters to classify traffic, the PRIO qdisc looks
2930 at the TC_PRIO priority to decide how to enqueue traffic. 
2931 </Para>
2933 <Para>
2934 This works just like with the pfifo_fast qdisc mentioned earlier, see there
2935 for lots of detail.
2936 </Para>
2937 </VarListEntry>
2938 </VariableList>
2939 The bands are classes, and are called major:1 to major:3 by default, so if
2940 your PRIO qdisc is called 12:, tc filter traffic to 12:1 to grant it more
2941 priority.
2942 </Para>
2944 <Para>
2945 Reiterating, band 0 goes to minor number 1! Band 1 to minor number 2, etc.
2946 </Para>
2948 </Sect3>
2950 <Sect3>
2951 <Title>Sample configuration</Title>
2953 <Para>
2954 We will create this tree:
2956 <Screen>
2957      root 1: prio
2958        /   |   \
2959      1:1  1:2  1:3
2960       |    |    |
2961      10:  20:  30:
2962      sfq  tbf  sfq
2963 band  0    1    2
2964 </Screen>
2966 </Para>
2968 <Para>
2969 Bulk traffic will go to 30:, interactive traffic to 20: or 10:.
2970 </Para>
2972 <Para>
2973 Commandlines:
2975 <Screen>
2976 # tc qdisc add dev eth0 root handle 1: prio 
2977 ## This *instantly* creates classes 1:1, 1:2, 1:3
2978   
2979 # tc qdisc add dev eth0 parent 1:1 handle 10: sfq
2980 # tc qdisc add dev eth0 parent 1:2 handle 20: tbf rate 20kbit buffer 1600 limit 3000
2981 # tc qdisc add dev eth0 parent 1:3 handle 30: sfq                                
2982 </Screen>
2984 </Para>
2986 <Para>
2987 Now lets's see what we created:
2989 <Screen>
2990 # tc -s qdisc ls dev eth0 
2991 qdisc sfq 30: quantum 1514b 
2992  Sent 0 bytes 0 pkts (dropped 0, overlimits 0) 
2994  qdisc tbf 20: rate 20Kbit burst 1599b lat 667.6ms 
2995  Sent 0 bytes 0 pkts (dropped 0, overlimits 0) 
2997  qdisc sfq 10: quantum 1514b 
2998  Sent 132 bytes 2 pkts (dropped 0, overlimits 0) 
3000  qdisc prio 1: bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
3001  Sent 174 bytes 3 pkts (dropped 0, overlimits 0) 
3002 </Screen>
3004 As you can see, band 0 has already had some traffic, and one packet was sent
3005 while running this command!
3006 </Para>
3008 <Para>
3009 We now do some bulk data transfer with a tool that properly sets TOS flags,
3010 and take another look:
3012 <Screen>
3013 # scp tc ahu@10.0.0.11:./
3014 ahu@10.0.0.11's password: 
3015 tc                   100% |*****************************|   353 KB    00:00    
3016 # tc -s qdisc ls dev eth0
3017 qdisc sfq 30: quantum 1514b 
3018  Sent 384228 bytes 274 pkts (dropped 0, overlimits 0) 
3020  qdisc tbf 20: rate 20Kbit burst 1599b lat 667.6ms 
3021  Sent 2640 bytes 20 pkts (dropped 0, overlimits 0) 
3023  qdisc sfq 10: quantum 1514b 
3024  Sent 2230 bytes 31 pkts (dropped 0, overlimits 0) 
3026  qdisc prio 1: bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
3027  Sent 389140 bytes 326 pkts (dropped 0, overlimits 0) 
3028 </Screen>
3030 As you can see, all traffic went to handle 30:, which is the lowest priority
3031 band, just as intended. Now to verify that interactive traffic goes to
3032 higher bands, we create some interactive traffic:
3033 </Para>
3035 <Para>
3037 <Screen>
3038 # tc -s qdisc ls dev eth0
3039 qdisc sfq 30: quantum 1514b 
3040  Sent 384228 bytes 274 pkts (dropped 0, overlimits 0) 
3042  qdisc tbf 20: rate 20Kbit burst 1599b lat 667.6ms 
3043  Sent 2640 bytes 20 pkts (dropped 0, overlimits 0) 
3045  qdisc sfq 10: quantum 1514b 
3046  Sent 14926 bytes 193 pkts (dropped 0, overlimits 0) 
3048  qdisc prio 1: bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
3049  Sent 401836 bytes 488 pkts (dropped 0, overlimits 0) 
3050 </Screen>
3052 </Para>
3054 <Para>
3055 It worked - all additional traffic has gone to 10:, which is our highest
3056 priority qdisc. No traffic was sent to the lowest priority, which previously
3057 received our entire scp.
3058 </Para>
3060 </Sect3>
3062 </Sect2>
3064 <Sect2>
3065 <Title>The famous CBQ qdisc</Title>
3067 <Para>
3068 As said before, CBQ is the most complex qdisc available, the most hyped, the
3069 least understood, and probably the trickiest one to get right. This is not
3070 because the authors are evil or incompetent, far from it, it's just that the
3071 CBQ algorithm isn't all that precise and doesn't really match the way Linux
3072 works.
3073 </Para>
3075 <Para>
3076 Besides being classful, CBQ is also a shaper and it is in that aspect that
3077 it really doesn't work very well. It should work like this. If you try to
3078 shape a 10mbit/s connection to 1mbit/s, the link should be idle 90&percnt; of the
3079 time. If it isn't, we need to throttle so that it IS idle 90&percnt; of the time.
3080 </Para>
3082 <Para>
3083 This is pretty hard to measure, so CBQ  instead derives the idle time from
3084 the number of microseconds that elapse between requests from the hardware
3085 layer for more data. Combined, this can be used to approximate how full or
3086 empty the link is.
3087 </Para>
3089 <Para>
3090 This is rather circumspect and doesn't always arrive at proper results. For
3091 example, what if the actual link speed of an interface that is not really
3092 able to transmit the full 100mbit/s of data, perhaps because of a badly
3093 implemented driver? A PCMCIA network card will also never achieve 100mbit/s
3094 because of the way the bus is designed - again, how do we calculate the idle
3095 time?
3096 </Para>
3098 <Para>
3099 It gets even worse if we consider not-quite-real network devices like PPP
3100 over Ethernet or PPTP over TCP/IP. The effective bandwidth in that case is
3101 probably determined by the efficiency of pipes to userspace - which is huge.
3102 </Para>
3104 <Para>
3105 People who have done measurements discover that CBQ is not always very
3106 accurate and sometimes completely misses the mark.
3107 </Para>
3109 <Para>
3110 In many circumstances however it works well. With the documentation provided
3111 here, you should be able to configure it to work well in most cases.
3112 </Para>
3114 <Sect3>
3115 <Title>CBQ shaping in detail</Title>
3117 <Para>
3118 As said before, CBQ works by making sure that the link is idle just long
3119 enough to bring down the real bandwidth to the configured rate. To do so, it
3120 calculates the time that should pass between average packets. 
3121 </Para>
3123 <Para>
3124 During operations, the effective idletime is measured using an exponential
3125 weighted moving average (EWMA), which considers recent packets to be
3126 exponentially more important than past ones. The unix loadaverage is
3127 calculated in the same way.
3128 </Para>
3130 <Para>
3131 The calculated idle time is substracted from the EWMA measured one, the
3132 resulting number is called 'avgidle'. A perfectly loaded link has an avgidle
3133 of zero: packets arrive exactly once every calculated interval.  
3134 </Para>
3136 <Para>
3137 An overloaded link has a negative avgidle and if it gets too negative, CBQ
3138 shuts down for a while and is then 'overlimit'.
3139 </Para>
3141 <Para>
3142 Conversely, an idle link might amass a huge avgidle, which would then allow
3143 infinite bandwidths after a few hours of silence. To prevent this, avgidle is
3144 capped at maxidle.
3145 </Para>
3147 <Para>
3148 If overlimit, in theory, the CBQ could throttle itself for exactly the
3149 amount of time that was calculated to pass between packets, and then pass
3150 one packet, and throttle again. But see the 'minburst' parameter below.
3151 </Para>
3153 <Para>
3154 These are parameters you can specify in order to configure shaping:
3155 <VariableList>
3157 <VarListEntry>
3158 <Term>avpkt</Term>
3159 <ListItem>
3160 <Para>
3161 Average size of a packet, measured in bytes. Needed for calculating maxidle,
3162 which is derived from maxburst, which is specified in packets.
3163 </Para>
3164 </VarListEntry>
3165 <VarListEntry>
3166 <Term>bandwidth</Term>
3167 <ListItem>
3168 <Para>
3169 The physical bandwidth of your device, needed for idle time
3170 calculations.
3171 </Para>
3172 </VarListEntry>
3173 <VarListEntry>
3174 <Term>cell</Term>
3175 <ListItem>
3176 <Para>
3177 The time a packet takes to be transmitted over a device may grow in steps,
3178 based on the packet size. An 800 and an 806 size packet may take just as long
3179 to send, for example - this sets the granularity. Most often set to '8'.
3180 Must be an integral power of two.
3181 </Para>
3182 </VarListEntry>
3183 <VarListEntry>
3184 <Term>maxburst</Term>
3185 <ListItem>
3186 <Para>
3187 This number of packets is used to calculate maxidle so that when avgidle is
3188 at maxidle, this number of average packets can be burst before avgidle drops
3189 to 0. Set it higher to be more tolerant of bursts. You can't set maxidle
3190 directly, only via this parameter.
3191 </Para>
3192 </VarListEntry>
3193 <VarListEntry>
3194 <Term>minburst</Term>
3195 <ListItem>
3196 <Para>
3197 As mentioned before, CBQ needs to throttle in case of overlimit. The ideal
3198 solution is to do so for exactly the calculated idle time, and pass 1
3199 packet. However, Unix kernels generally have a hard time scheduling events
3200 shorter than 10ms, so it is better to throttle for a longer period, and then
3201 pass minburst packets in one go, and then sleep minburst times longer.
3202 </Para>
3204 <Para>
3205 The time to wait is called the offtime. Higher values of minburst lead to
3206 more accurate shaping in the long term, but to bigger bursts at millisecond
3207 timescales.
3208 </Para>
3209 </VarListEntry>
3210 <VarListEntry>
3211 <Term>minidle</Term>
3212 <ListItem>
3213 <Para>
3214 If avgidle is below 0, we are overlimits and need to wait until avgidle will
3215 be big enough to send one packet. To prevent a sudden burst from shutting
3216 down the link for a prolonged period of time, avgidle is reset to minidle if
3217 it gets too low.
3218 </Para>
3220 <Para>
3221 Minidle is specified in negative microseconds, so 10 means that avgidle is
3222 capped at -10us.
3223 </Para>
3224 </VarListEntry>
3225 <VarListEntry>
3226 <Term>mpu</Term>
3227 <ListItem>
3228 <Para>
3229 Mininum packet size - needed because even a zero size packet is padded
3230 to 64 bytes on ethernet, and so takes a certain time to transmit. CBQ needs
3231 to know this to accurately calculate the idle time.
3232 </Para>
3233 </VarListEntry>
3234 <VarListEntry>
3235 <Term>rate</Term>
3236 <ListItem>
3237 <Para>
3238 Desired rate of traffic leaving this qdisc - this is the 'speed knob'!
3239 </Para>
3240 </VarListEntry>
3241 </VariableList>
3242 </Para>
3244 <Para>
3245 Internally, CBQ has a lot of finetuning. For example, classes which are
3246 known not to have data enqueued to them aren't queried. Overlimit classes
3247 are penalized by lowering their effective priority. All very smart &amp;
3248 complicated.
3249 </Para>
3251 </Sect3>
3253 <Sect3>
3254 <Title>CBQ classful behaviour</Title>
3256 <Para>
3257 Besides shaping, using the aforementioned idletime approximations, CBQ also
3258 acts like the PRIO queue in the sense that classes can have differing
3259 priorities and that lower priority numbers will be polled before the higher
3260 priority ones.
3261 </Para>
3263 <Para>
3264 Each time a packet is requested by the hardware layer to be sent out to the
3265 network, a weighted round robin process ('WRR') starts, beginning with the
3266 lower priority classes.
3267 </Para>
3269 <Para>
3270 These are then grouped and queried if they have data available. If so, it is
3271 returned. After a class has been allowed to dequeue a number of bytes, the
3272 next class within that priority is tried.
3273 </Para>
3275 <Para>
3276 The following parameters control the WRR process:
3277 <VariableList>
3279 <VarListEntry>
3280 <Term>allot</Term>
3281 <ListItem>
3282 <Para>
3283 When the outer cbq is asked for a packet to send out on the interface, it
3284 will try all inner qdiscs (in the classes) in turn, in order of 
3285 the 'priority' parameter. Each time a class gets its turn, it can only send out
3286 a limited amount of data. 'Allot' is the base unit of this amount. See 
3287 the 'weight' parameter for more information.
3288 </Para>
3289 </VarListEntry>
3290 <VarListEntry>
3291 <Term>prio</Term>
3292 <ListItem>
3293 <Para>
3294 The CBQ can also act like the PRIO device. Inner classes with lower priority
3295 are tried first and as long as they have traffic, other classes are not
3296 polled for traffic.
3297 </Para>
3298 </VarListEntry>
3299 <VarListEntry>
3300 <Term>weight</Term>
3301 <ListItem>
3302 <Para>
3303 Weight helps in the Weighted Round Robin process. Each class gets a chance
3304 to send in turn. If you have classes with significantly more bandwidth than
3305 other classes, it makes sense to allow them to send more data in one round
3306 than the others.
3307 </Para>
3309 <Para>
3310 A CBQ adds up all weights under a class, and normalizes them, so you can use
3311 arbitrary numbers: only the ratios are important. People have been 
3312 using 'rate/10' as a rule of thumb and it appears to work well. The renormalized
3313 weight is multiplied by the 'allot' parameter to determine how much data can
3314 be sent in one round. 
3315 </Para>
3316 </VarListEntry>
3317 </VariableList>
3318 </Para>
3320 <Para>
3321 Please note that all classes within an CBQ hierarchy need to share the same
3322 major number!
3323 </Para>
3325 </Sect3>
3327 <Sect3>
3328 <Title>CBQ parameters that determine link sharing &amp; borrowing</Title>
3330 <Para>
3331 Besides purely limiting certain kinds of traffic, it is also possible to
3332 specify which classes can borrow capacity from other classes or, conversely,
3333 lend out bandwidth.
3334 </Para>
3336 <Para>
3337 <VariableList>
3339 <VarListEntry>
3340 <Term>Isolated/sharing</Term>
3341 <ListItem>
3342 <Para>
3343 A class that is configured with 'isolated' will not lend out bandwidth to
3344 sibling classes. Use this if you have competing or mutually-unfriendly
3345 agencies on your link who do want to give eachother freebies.
3346 </Para>
3348 <Para>
3349 The control program tc also knows about 'sharing', which is the reverse 
3350 of 'isolated'.
3351 </Para>
3352 </VarListEntry>
3353 <VarListEntry>
3354 <Term>bounded/borrow</Term>
3355 <ListItem>
3356 <Para>
3357 A class can also be 'bounded', which means that it will not try to borrow
3358 bandwidth from sibling classes. tc also knows about 'borrow', which is the
3359 reverse of 'bounded'.
3360 </Para>
3361 </VarListEntry>
3362 </VariableList>
3363 A typical situation might be where you have two agencies on your link which
3364 are both 'isolated' and 'bounded', which means that they are really limited
3365 to their assigned rate, and also won't allow each other to borrow.
3366 </Para>
3368 <Para>
3369 Within such an agency class, there might be other classes which are allowed
3370 to swap bandwidth.
3371 </Para>
3373 </Sect3>
3375 <Sect3>
3376 <Title>Sample configuration</Title>
3378 <Para>
3379 This configuration limits webserver traffic to 5mbit and smtp traffic to 3
3380 mbit. Together, they may not get more than 6mbit. We have a 100mbit NIC and
3381 the classes may borrow bandwidth from each other.
3383 <Screen>
3384 # tc qdisc add dev eth0 root handle 1:0 cbq bandwidth 100Mbit         \
3385   avpkt 1000 cell 8
3386 # tc class add dev eth0 parent 1:0 classid 1:1 cbq bandwidth 100Mbit  \
3387   rate 6Mbit weight 0.6Mbit prio 8 allot 1514 cell 8 maxburst 20      \
3388   avpkt 1000 bounded
3389 </Screen>
3391 This part installs the root and the customary 1:0 class. The 1:1 class is
3392 bounded, so the total bandwidth can't exceed 6mbit.
3393 </Para>
3395 <Para>
3396 As said before, CBQ requires a *lot* of knobs. All parameters are explained
3397 above, however. The corresponding HTB configuration is lots simpler.
3398 </Para>
3400 <Para>
3402 <Screen>
3403 # tc class add dev eth0 parent 1:1 classid 1:3 cbq bandwidth 100Mbit  \
3404   rate 5Mbit weight 0.5Mbit prio 5 allot 1514 cell 8 maxburst 20      \
3405   avpkt 1000                       
3406 # tc class add dev eth0 parent 1:1 classid 1:4 cbq bandwidth 100Mbit  \
3407   rate 3Mbit weight 0.3Mbit prio 5 allot 1514 cell 8 maxburst 20      \
3408   avpkt 1000
3409 </Screen>
3411 </Para>
3413 <Para>
3414 These are our two classes. Note how we scale the weight with the configured
3415 rate. Both classes are not bounded, but they are connected to class 1:1
3416 which is bounded.  So the sum of bandwith of the 2 classes will never be
3417 more than 6mbit. The classid's need to be within the same major number as
3418 the parent CBQ, by the way!
3419 </Para>
3421 <Para>
3423 <Screen>
3424 # tc qdisc add dev eth0 parent 1:3 handle 30: sfq
3425 # tc qdisc add dev eth0 parent 1:4 handle 40: sfq
3426 </Screen>
3428 </Para>
3430 <Para>
3431 Both classes have a FIFO qdisc by default.  But we replaced these with an SFQ
3432 queue so each flow of data is treated equally.
3434 <Screen>
3435 # tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip \
3436   sport 80 0xffff flowid 1:3
3437 # tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip \
3438   sport 25 0xffff flowid 1:4
3439 </Screen>
3441 </Para>
3443 <Para>
3444 These commands, attached directly to the root, send traffic to the right
3445 qdiscs.
3446 </Para>
3448 <Para>
3449 Note that we use 'tc class add' to CREATE classes within a qdisc, but that
3450 we use 'tc qdisc add' to actually add qdiscs to these classes.
3451 </Para>
3453 <Para>
3454 You may wonder what happens to traffic that is not classified by any of the
3455 two rules. It appears that in this case, data will then be processed within
3456 1:0, and be unlimited. 
3457 </Para>
3459 <Para>
3460 If smtp+web together try to exceed the set limit of 6mbit/s, bandwidth will
3461 be divided according to the weight parameter, giving 5/8 of traffic to  the
3462 webserver and 3/8 to the mailserver.
3463 </Para>
3465 <Para>
3466 With this configuratien you can also say that webserver traffic will always
3467 get at minimum 5/8 * 6 mbit = 3.75 mbit.
3468 </Para>
3470 </Sect3>
3472 <Sect3>
3473 <Title>Other CBQ parameters: split &amp; defmap</Title>
3475 <Para>
3476 As said before, a classful qdisc needs to call filters to determine
3477 which class a packet will be enqueued to. 
3478 </Para>
3480 <Para>
3481 Besides calling the filter, CBQ offers other options, defmap &amp; split.
3482 This is pretty complicated to understand, and it is not vital. But as this
3483 is the only known place where defmap &amp; split are properly explained, I'm
3484 doing my best. 
3485 </Para>
3487 <Para>
3488 As you will often want to filter on the Type of Service field only, a special
3489 syntax is provided. Whenever the CBQ needs to figure out where a packet
3490 needs to be enqueued, it checks if this node is a 'split node'. If so, one
3491 of the sub-qdiscs has indicated that it wishes to receive all packets with
3492 a certain configured priority, as might be derived from the TOS field, or
3493 socket options set by applications.
3494 </Para>
3496 <Para>
3497 The packets' priority bits are or-ed with the defmap field to see if a match
3498 exists. In other words, this is a short-hand way of creating a very fast
3499 filter, which only matches certain priorities. A defmap of ff (hex) will
3500 match everything, a map of 0 nothing. A sample configuration may help make
3501 things clearer:
3502 </Para>
3504 <Para>
3506 <Screen>
3507 # tc qdisc add dev eth1 root handle 1: cbq bandwidth 10Mbit allot 1514 \
3508   cell 8 avpkt 1000 mpu 64
3510 # tc class add dev eth1 parent 1:0 classid 1:1 cbq bandwidth 10Mbit    \
3511   rate 10Mbit allot 1514 cell 8 weight 1Mbit prio 8 maxburst 20        \
3512   avpkt 1000
3513 </Screen>
3515 Standard CBQ preamble. I never get used to the sheer amount of numbers
3516 required!
3517 </Para>
3519 <Para>
3520 Defmap refers to TC_PRIO bits, which are defined as follows:
3521 </Para>
3523 <Para>
3525 <Screen>
3526 TC_PRIO..          Num  Corresponds to TOS
3527 -------------------------------------------------
3528 BESTEFFORT         0    Maximize Reliablity        
3529 FILLER             1    Minimize Cost              
3530 BULK               2    Maximize Throughput (0x8)  
3531 INTERACTIVE_BULK   4                               
3532 INTERACTIVE        6    Minimize Delay (0x10)      
3533 CONTROL            7                               
3534 </Screen>
3536 </Para>
3538 <Para>
3539 The TC_PRIO.. number corresponds to bits, counted from the right. See the
3540 pfifo_fast section for more details how TOS bits are converted to
3541 priorities.
3542 </Para>
3544 <Para>
3545 Now the interactive and the bulk classes:
3546 </Para>
3548 <Para>
3550 <Screen>
3551 # tc class add dev eth1 parent 1:1 classid 1:2 cbq bandwidth 10Mbit     \
3552   rate 1Mbit allot 1514 cell 8 weight 100Kbit prio 3 maxburst 20        \
3553   avpkt 1000 split 1:0 defmap c0
3555 # tc class add dev eth1 parent 1:1 classid 1:3 cbq bandwidth 10Mbit     \
3556   rate 8Mbit allot 1514 cell 8 weight 800Kbit prio 7 maxburst 20        \
3557   avpkt 1000 split 1:0 defmap 3f
3558 </Screen>
3560 </Para>
3562 <Para>
3563 The 'split qdisc' is 1:0, which is where the choice will be made. C0 is
3564 binary for 11000000, 3F for 00111111, so these two together will match
3565 everything. The first class matches bits 7 &#38; 6, and thus corresponds 
3566 to 'interactive' and 'control' traffic. The second class matches the rest.
3567 </Para>
3569 <Para>
3570 Node 1:0 now has a table like this:
3572 <Screen>
3573 priority        send to
3574 0               1:3
3575 1               1:3
3576 2               1:3
3577 3               1:3
3578 4               1:3
3579 5               1:3
3580 6               1:2
3581 7               1:2
3582 </Screen>
3584 </Para>
3586 <Para>
3587 For additional fun, you can also pass a 'change mask', which indicates
3588 exactly which priorities you wish to change. You only need to use this if you
3589 are running 'tc class change'. For example, to add best effort traffic to
3590 1:2, we could run this:
3591 </Para>
3593 <Para>
3595 <Screen>
3596 # tc class change dev eth1 classid 1:2 cbq defmap 01/01
3597 </Screen>
3599 </Para>
3601 <Para>
3602 The priority map over at 1:0 now looks like this:
3603 </Para>
3605 <Para>
3607 <Screen>
3608 priority        send to
3609 0               1:2
3610 1               1:3
3611 2               1:3
3612 3               1:3
3613 4               1:3
3614 5               1:3
3615 6               1:2
3616 7               1:2
3617 </Screen>
3619 </Para>
3621 <Para>
3622 FIXME: did not test 'tc class change', only looked at the source.
3623 </Para>
3625 </Sect3>
3627 </Sect2>
3629 <Sect2>
3630 <Title>Hierarchical Token Bucket </Title>
3632 <Para>
3633 Martin Devera (&lt;devik&gt;) rightly realised that CBQ is complex and does
3634 not seem optimized for many typical situations. His Hierarchial approach is
3635 well suited for setups where you have a fixed amount of bandwidth which you
3636 want to divide for different purposes, giving each purpose a guaranteed
3637 bandwidth, with the possibility of specifying how much bandwidth can be
3638 borrowed.
3639 </Para>
3641 <Para>
3642 HTB works just like CBQ but does not resort to idle time calculations to
3643 shape. Instead, it is a classful Token Bucket Filter - hence the name. It
3644 has only a few parameters, which are well documented on his 
3645 <ULink
3646 URL="http://luxik.cdi.cz/~devik/qos/htb/"
3647 >site</ULink
3649 </Para>
3651 <Para>
3652 As your HTB configuration gets more complex, your configuration scales
3653 well. With CBQ it is already complex even in simple cases! HTB is not yet a
3654 part of the standard kernel, but it should soon be!
3655 </Para>
3657 <Para>
3658 If you are in a position to patch your kernel, by all means consider HTB.
3659 </Para>
3661 <Sect3>
3662 <Title>Sample configuration</Title>
3664 <Para>
3665 Functionally almost identical to the CBQ sample configuration above:
3666 </Para>
3668 <Para>
3670 <Screen>
3671 # tc qdisc add dev eth0 root handle 1: htb default 30
3673 # tc class add dev eth0 parent 1: classid 1:1 htb rate 6mbit burst 15k
3675 # tc class add dev eth0 parent 1:1 classid 1:10 htb rate 5mbit burst 15k
3676 # tc class add dev eth0 parent 1:1 classid 1:20 htb rate 3mbit ceil 6mbit burst 15k
3677 # tc class add dev eth0 parent 1:1 classid 1:30 htb rate 1kbit ceil 6mbit burst 15k
3678 </Screen>
3680 </Para>
3682 <Para>
3683 The author then recommends SFQ for beneath these classes:
3685 <Screen>
3686 # tc qdisc add dev eth0 parent 1:10 handle 10: sfq perturb 10
3687 # tc qdisc add dev eth0 parent 1:20 handle 20: sfq perturb 10
3688 # tc qdisc add dev eth0 parent 1:30 handle 30: sfq perturb 10
3689 </Screen>
3691 </Para>
3693 <Para>
3694 Add the filters which direct traffic to the right classes:
3696 <Screen>
3697 # U32="tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32"
3698 # $U32 match ip dport 80 0xffff flowid 1:10
3699 # $U32 match ip sport 25 0xffff flowid 1:20
3700 </Screen>
3702 And that's it - no unsightly unexplained numbers, no undocumented
3703 parameters. 
3704 </Para>
3706 <Para>
3707 HTB certainly looks wonderful - if 10: and 20: both have their guaranteed
3708 bandwidth, and more is left to divide, they borrow in a 5:3 ratio, just as
3709 you would expect.
3710 </Para>
3712 <Para>
3713 Unclassified traffic gets routed to 30:, which has little bandwidth of its
3714 own but can borrow everything that is left over. Because we chose SFQ
3715 internally, we get fairness thrown in for free!
3716 </Para>
3718 </Sect3>
3720 </Sect2>
3722 </Sect1>
3724 <Sect1>
3725 <Title>Classifying packets with filters</Title>
3727 <Para>
3728 To determine which class shall process a packet, the so-called 'classifier
3729 chain' is called each time a choice needs to be made. This chain consists of
3730 all filters attached to the classful qdisc that needs to decide.
3731 </Para>
3733 <Para>
3734 To reiterate the tree, which is not a tree:
3736 <Screen>
3737                     root 1:
3738                       |
3739                     _1:1_
3740                    /  |  \
3741                   /   |   \
3742                  /    |    \
3743                10:   11:   12:
3744               /   \       /   \
3745            10:1  10:2   12:1  12:2
3746 </Screen>
3748 </Para>
3750 <Para>
3751 When enqueueing a packet, at each branch the filter chain is consulted for a
3752 relevant instruction. A typical setup might be to have a filter in 1:1 that
3753 directs a packet to 12: and a filter on 12: that sends the packet to 12:2.
3754 </Para>
3756 <Para>
3757 You might also attach this latter rule to 1:1, but you can make efficiency
3758 gains by having more specific tests lower in the chain.
3759 </Para>
3761 <Para>
3762 You can't filter a packet 'upwards', by the way. Also, with HTB, you should
3763 attach all filters to the root!
3764 </Para>
3766 <Para>
3767 And again - packets are only enqueued downwards! When they are dequeued,
3768 they go up again, where the interface lives. They do NOT fall off the end of
3769 the tree to the network adaptor!
3770 </Para>
3772 <Sect2>
3773 <Title>Some simple filtering examples</Title>
3775 <Para>
3776 As explained in the Classifier chapter, you can match on literally anything,
3777 using a very complicated syntax. To start, we will show how to do the
3778 obvious things, which luckily are quite easy.
3779 </Para>
3781 <Para>
3782 Let's say we have a PRIO qdisc called '10:' which contains three classes, and
3783 we want to assign all traffic from and to port 22 to the highest priority
3784 band, the filters would be:
3785 </Para>
3787 <Para>
3789 <Screen>
3790 # tc filter add dev eth0 protocol ip parent 10: prio 1 u32 match \ 
3791   ip dport 22 0xffff flowid 10:1
3792 # tc filter add dev eth0 protocol ip parent 10: prio 1 u32 match \
3793   ip sport 80 0xffff flowid 10:1
3794 # tc filter add dev eth0 protocol ip parent 10: prio 2 flowid 10:2
3795 </Screen>
3797 </Para>
3799 <Para>
3800 What does this say? It says: attach to eth0, node 10: a  priority 1 u32
3801 filter that matches on IP destination port 22 *exactly* and send it to band
3802 10:1. And it then repeats the same for source port 80. The last command says
3803 that anything unmatched so far should go to band 10:2, the next-highest
3804 priority.
3805 </Para>
3807 <Para>
3808 You need to add 'eth0', or whatever your interface is called, because each
3809 interface has a unique namespace of handles.
3810 </Para>
3812 <Para>
3813 To select on an IP address, use this:
3815 <Screen>
3816 # tc filter add dev eth0 parent 10:0 protocol ip prio 1 u32 \ 
3817   match ip dst 4.3.2.1/32 flowid 10:1
3818 # tc filter add dev eth0 parent 10:0 protocol ip prio 1 u32 \
3819   match ip src 1.2.3.4/32 flowid 10:1
3820 # tc filter add dev eth0 protocol ip parent 10: prio 2      \
3821   flowid 10:2
3822 </Screen>
3824 </Para>
3826 <Para>
3827 This assigns traffic to 4.3.2.1 and traffic from 1.2.3.4 to the highest
3828 priority queue, and the rest to the next-highest one.
3829 </Para>
3831 <Para>
3832 You can concatenate matches, to match on traffic from 1.2.3.4 and from port
3833 80, do this:
3835 <Screen>
3836 # tc filter add dev eth0 parent 10:0 protocol ip prio 1 u32 match ip src 4.3.2.1/32
3837   match ip sport 80 0xffff flowid 10:1
3838 </Screen>
3840 </Para>
3842 </Sect2>
3844 <Sect2>
3845 <Title>All the filtering commands you will normally need</Title>
3847 <Para>
3848 Most shaping commands presented here start with this preamble:
3850 <Screen>
3851 # tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 ..
3852 </Screen>
3854 These are the so called 'u32' matches, which can match on ANY part of a
3855 packet.
3856 <VariableList>
3858 <VarListEntry>
3859 <Term>On source/destination address</Term>
3860 <ListItem>
3861 <Para>
3862 Source mask 'match ip src 1.2.3.0/24', destination mask 'match ip dst
3863 4.3.2.0/24'. To match a single host, use /32, or omit the mask.
3864 </Para>
3865 </VarListEntry>
3866 <VarListEntry>
3867 <Term>On source/destination port, all IP protocols</Term>
3868 <ListItem>
3869 <Para>
3870 Source: 'match ip sport 80 0xffff', 'match ip dport 0xffff'
3871 </Para>
3872 </VarListEntry>
3873 <VarListEntry>
3874 <Term>On ip protocol (tcp, udp, icmp, gre, ipsec)</Term>
3875 <ListItem>
3876 <Para>
3877 Use the numbers from /etc/protocols, for example, icmp is 1: 'match ip
3878 protocol 1 0xff'. 
3879 </Para>
3880 </VarListEntry>
3881 <VarListEntry>
3882 <Term>On fwmark</Term>
3883 <ListItem>
3884 <Para>
3885 You can mark packets with either ipchains and have that mark survive routing
3886 across interfaces. This is really useful to for example only shape traffic on
3887 eth1 that came in on eth0. Syntax: 
3888 &num; tc filter add dev eth1 protocol ip parent 1:0 prio 1 handle 6 fw flowid 1:1
3889 Note that this is not a u32 match!
3890 </Para>
3892 <Para>
3893 You can place a mark like this:
3895 <Screen>
3896 # iptables -A PREROUTING -t mangle -i eth0 -j MARK --set-mark 6
3897 </Screen>
3899 The number 6 is arbitrary.
3900 </Para>
3902 <Para>
3903 If you don't want to understand the full tc filter syntax, just use
3904 iptables, and only learn to select on fwmark.
3905 </Para>
3906 </VarListEntry>
3907 <VarListEntry>
3908 <Term>On the TOS field</Term>
3909 <ListItem>
3910 <Para>
3911 To select interactive, minimum delay traffic:
3913 <Screen>
3914 # tc filter add dev ppp0 parent 1:0 protocol ip prio 10 u32 \
3915       match ip tos 0x10 0xff \
3916      flowid 1:4
3917 </Screen>
3919 Use 0x08 0xff for bulk traffic.
3920 </Para>
3921 </VarListEntry>
3922 </VariableList>
3923 </Para>
3925 <Para>
3926 For more filtering commands, see the Advanced Filters chapter.
3927 </Para>
3929 </Sect2>
3931 </Sect1>
3932 <Sect1>
3933 <Title>The Intermediate queueing device (IMQ)</Title>
3935 <Para>
3936 The Intermediate queueing device is not a qdisc but its usage is tightly bound
3937 to qdiscs. Within linux, qdiscs are attached to network devices and everything
3938 that is queued to the device is first queued to the qdisc. From this concept,
3939 two limitations arise:
3940 </Para>
3942 <Para>
3943 1. Only egress shaping is possible (an ingress qdisc exists, but its
3944 possibilities are very limited compared to classful qdiscs).
3945 </Para>
3947 <Para>
3948 2. A qdisc can only see traffic of one interface, global limitations can't be
3949 placed.
3950 </Para>
3952 <Para>
3953 IMQ is there to help solve those two limitations. In short, you can put 
3954 everything you choose in a qdisc. Specially marked packets get intercepted
3955 in netfilter NF_IP_PRE_ROUTING and NF_IP_POST_ROUTING hooks and pass through
3956 the qdisc attached to an imq device. An iptables target is used for marking
3957 the packets.
3958 </Para>
3960 <Para>
3961 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.
3962 You can also do lots of other stuff like just putting your http traffic in a
3963 qdisc, put new connection requests in a qdisc, ...
3964 </Para>
3966 <Sect2>
3967 <Title>Sample configuration</Title>
3969 <Para>
3970 The first thing that might come to mind is use ingress shaping to give yourself
3971 a high guaranteed bandwidth. ;)
3972 Configuration is just like with any other interface:
3974 <Screen>
3975 tc qdisc add dev imq0 root handle 1: htb default 20
3977 tc class add dev imq0 parent 1: classid 1:1 htb rate 2mbit burst 15k
3979 tc class add dev imq0 parent 1:1 classid 1:10 htb rate 1mbit
3980 tc class add dev imq0 parent 1:1 classid 1:20 htb rate 1mbit
3982 tc qdisc add dev imq0 parent 1:10 handle 10: pfifo
3983 tc qdisc add dev imq0 parent 1:20 handle 20: sfq
3985 tc filter add dev imq0 parent 10:0 protocol ip prio 1 u32 match \
3986                 ip dst 10.0.0.230/32 flowid 1:10
3987 </Screen>
3989 In this example u32 is used for classification. Other classifiers should work as
3990 expected.
3991 Next traffic has to be selected and marked to be enqueued to imq0.
3993 <Screen>
3994 iptables -t mangle -A PREROUTING -i eth0 -j IMQ --todev 0
3996 ip link set imq0 up
3997 </Screen>
3999 </Para>
4001 <Para>
4002 The IMQ iptables targets is valid in the PREROUTING and POSTROUTING chains of
4003 the mangle table. It's syntax is 
4005 <Screen>
4006 IMQ [ --todev n ]       n : number of imq device
4007 </Screen>
4009 An ip6tables target is also provided.
4010 </Para>
4012 <Para>
4013 Please note traffic is not enqueued when the target is hit but afterwards.
4014 The exact location where traffic enters the imq device depends on the
4015 direction of the traffic (in/out).
4016 These are the predefined netfilter hooks used by iptables:
4018 <Screen>
4019 enum nf_ip_hook_priorities {
4020         NF_IP_PRI_FIRST = INT_MIN,
4021         NF_IP_PRI_CONNTRACK = -200,
4022         NF_IP_PRI_MANGLE = -150,
4023         NF_IP_PRI_NAT_DST = -100,
4024         NF_IP_PRI_FILTER = 0,
4025         NF_IP_PRI_NAT_SRC = 100,
4026         NF_IP_PRI_LAST = INT_MAX,
4028 </Screen>
4030 </Para>
4032 <Para>
4033 For ingress traffic, imq registers itself with NF_IP_PRI_MANGLE + 1 priority
4034 which means packets enter the imq device directly after the mangle PREROUTING
4035 chain has been passed.
4036 </Para>
4038 <Para>
4039 For egress imq uses NF_IP_PRI_LAST which honours the fact that packets dropped
4040 by the filter table won't occupy bandwidth.
4041 </Para>
4043 <Para>
4044 The patches and some more information can be found at the
4045 <ULink
4046 URL="http://luxik.cdi.cz/~patrick/imq/"
4047 >imq site</ULink>.
4048 </Para>
4050 </Sect2>
4052 </Sect1>
4054 </chapter>
4056 <chapter>
4057 <Title>Loadsharing over multiple interfaces</Title>
4059 <Para>
4060 There are several ways of doing this. One of the easiest and straightforward
4061 ways is 'TEQL' - "True" (or "trivial") link equalizer. Like most things
4062 having to do with queueing, loadsharing goes both ways. Both ends of a link
4063 may need to participate for full effect.
4064 </Para>
4066 <Para>
4067 Imagine this situation:
4068 </Para>
4070 <Para>
4072 <Screen>
4073                  +-------+   eth1   +-------+
4074                  |       |==========|       |
4075  'network 1' ----|   A   |          |   B   |---- 'network 2'
4076                  |       |==========|       |
4077                  +-------+   eth2   +-------+
4078 </Screen>
4080 </Para>
4082 <Para>
4083 A and B are routers, and for the moment we'll assume both run Linux. If
4084 traffic is going from network 1 to network 2, router A needs to distribute
4085 the packets over both links to B. Router B needs to be configured to accept
4086 this. Same goes the other way around, when packets go from network 2 to
4087 network 1, router B needs to send the packets over both eth1 and eth2.
4088 </Para>
4090 <Para>
4091 The distributing part is done by a 'TEQL' device, like this (it couldn't be
4092 easier):
4093 </Para>
4095 <Para>
4097 <Screen>
4098 # tc qdisc add dev eth1 root teql0
4099 # tc qdisc add dev eth2 root teql0
4100 # ip link set dev teql0 up
4101 </Screen>
4103 </Para>
4105 <Para>
4106 Don't forget the 'ip link set up' command!
4107 </Para>
4109 <Para>
4110 This needs to be done on both hosts. The device teql0 is basically a
4111 roundrobbin distributor over eth1 and eth2, for sending packets. No data
4112 ever comes in over an teql device, that just appears on the 'raw' eth1 and
4113 eth2.
4114 </Para>
4116 <Para>
4117 But now we just have devices, we also need proper routing. One way to do
4118 this is to assign a /31 network to both links, and a /31 to the teql0 device
4119 as well:
4120 </Para>
4122 <Para>
4123 FIXME: does this need something like 'nobroadcast'? A /31 is too small to
4124 house a network address and a broadcast address - if this doesn't work as
4125 planned, try a /30, and adjust the ip adresses accordingly. You might even
4126 try to make eth1 and eth2 do without an IP address!
4127 </Para>
4129 <Para>
4130 On router A:
4132 <Screen>
4133 # ip addr add dev eth1 10.0.0.0/31
4134 # ip addr add dev eth2 10.0.0.2/31
4135 # ip addr add dev teql0 10.0.0.4/31
4136 </Screen>
4138 </Para>
4140 <Para>
4141 On router B:
4143 <Screen>
4144 # ip addr add dev eth1 10.0.0.1/31
4145 # ip addr add dev eth2 10.0.0.3/31
4146 # ip addr add dev teql0 10.0.0.5/31
4147 </Screen>
4149 </Para>
4151 <Para>
4152 Router A should now be able to ping 10.0.0.1, 10.0.0.3 and 10.0.0.5 over the
4153 2 real links and the 1 equalized device. Router B should be able to ping
4154 10.0.0.0, 10.0.0.2 and 10.0.0.4 over the links.
4155 </Para>
4157 <Para>
4158 If this works, Router A should make 10.0.0.5 its route for reaching network
4159 2, and Router B should make 10.0.0.4 its route for reaching network 1. For
4160 the special case where network 1 is your network at home, and network 2 is
4161 the Internet, Router A should make 10.0.0.5 its default gateway.
4162 </Para>
4164 <Sect1>
4165 <Title>Caveats</Title>
4167 <Para>
4168 Nothing is as easy as it seems. eth1 and eth2 on both router A and B need to
4169 have return path filtering turned off, because they will otherwise drop
4170 packets destined for ip addresses other than their own:
4171 </Para>
4173 <Para>
4175 <Screen>
4176 # echo 0 &#62; /proc/net/ipv4/conf/eth1/rp_filter
4177 # echo 0 &#62; /proc/net/ipv4/conf/eth2/rp_filter
4178 </Screen>
4180 </Para>
4182 <Para>
4183 Then there is the nasty problem of packet reordering. Let's say 6 packets
4184 need to be sent from A to B - eth1 might get 1, 3 and 5. eth2 would then do
4185 2, 4 and 6. In an ideal world, router B would receive this in order, 1, 2,
4186 3, 4, 5, 6. But the possibility is very real that the kernel gets it like
4187 this: 2, 1, 4, 3, 6, 5. The problem is that this confuses TCP/IP. While not
4188 a problem for links carrying many different TCP/IP sessions, you won't be
4189 able to to a bundle multiple links and get to ftp a single file lots faster,
4190 except when your receiving or sending OS is Linux, which is not easily
4191 shaken by some simple reordering.
4192 </Para>
4194 <Para>
4195 However, for lots of applications, link loadbalancing is a great idea.
4196 </Para>
4198 </Sect1>
4200 </chapter>
4202 <chapter>
4203 <Title>Netfilter &amp; iproute - marking packets</Title>
4205 <Para>
4206 So far we've seen how iproute works, and netfilter was mentioned a few
4207 times. This would be a good time to browse through <ULink
4208 URL="http://netfilter.samba.org/unreliable-guides/"
4209 >Rusty's Remarkably Unreliable Guides</ULink
4210 >. Netfilter itself
4211 can be found <ULink
4212 URL="http://netfilter.filewatcher.org/"
4213 >here</ULink
4215 </Para>
4217 <Para>
4218 Netfilter allows us to filter packets, or mangle their headers. One special
4219 feature is that we can mark a packet with a number. This is done with the
4220 --set-mark facility. 
4221 </Para>
4223 <Para>
4224 As an example, this command marks all packets destined for port 25, outgoing
4225 mail:
4226 </Para>
4228 <Para>
4230 <Screen>
4231 # iptables -A PREROUTING -i eth0 -t mangle -p tcp --dport 25 \
4232  -j MARK --set-mark 1
4233 </Screen>
4235 </Para>
4237 <Para>
4238 Let's say that we have multiple connections, one that is fast (and
4239 expensive, per megabyte) and one that is slower, but flat fee. We would most
4240 certainly like outgoing mail to go via the cheap route.
4241 </Para>
4243 <Para>
4244 We've already marked the packets with a '1', we now instruct the routing
4245 policy database to act on this:
4246 </Para>
4248 <Para>
4250 <Screen>
4251 # echo 201 mail.out &#62;&#62; /etc/iproute2/rt_tables
4252 # ip rule add fwmark 1 table mail.out
4253 # ip rule ls
4254 0:      from all lookup local 
4255 32764:  from all fwmark        1 lookup mail.out 
4256 32766:  from all lookup main 
4257 32767:  from all lookup default 
4258 </Screen>
4260 </Para>
4262 <Para>
4263 Now we generate the mail.out table with a route to the slow but cheap link:
4265 <Screen>
4266 # /sbin/ip route add default via 195.96.98.253 dev ppp0 table mail.out
4267 </Screen>
4269 </Para>
4271 <Para>
4272 And we are done. Should we want to make exceptions, there are lots of ways
4273 to achieve this. We can modify the netfilter statement to exclude certain
4274 hosts, or we can insert a rule with a lower priority that points to the main
4275 table for our excepted hosts.
4276 </Para>
4278 <Para>
4279 We can also use this feature to honour TOS bits by marking packets with a
4280 different type of service with different numbers, and creating rules to act
4281 on that. This way you can even dedicate, say, an ISDN line to interactive
4282 sessions.
4283 </Para>
4285 <Para>
4286 Needless to say, this also works fine on a host that's doing NAT
4287 ('masquerading').
4288 </Para>
4290 <Para>
4291 IMPORTANT: We received a report that MASQ and SNAT at least collide
4292 with marking packets. Rusty Russell explains it in
4293 <ULink
4294 URL="http://lists.samba.org/pipermail/netfilter/2000-November/006089.html"
4295 >this posting</ULink
4296 >. Turn off the reverse path filter to make it work
4297 properly.
4298 </Para>
4300 <Para>
4301 Note: to mark packets, you need to have some options enabled in your
4302 kernel:
4303 </Para>
4305 <Para>
4307 <Screen>
4308 IP: advanced router (CONFIG_IP_ADVANCED_ROUTER) [Y/n/?]
4309  IP: policy routing (CONFIG_IP_MULTIPLE_TABLES) [Y/n/?]
4310   IP: use netfilter MARK value as routing key (CONFIG_IP_ROUTE_FWMARK) [Y/n/?]
4311 </Screen>
4313 </Para>
4315 <Para>
4316 See also the Squid bit in the Cookbook.
4317 </Para>
4319 </chapter>
4321 <chapter>
4322 <Title>Advanced filters for (re-)classifying packets</Title>
4324 <Para>
4325 As explained in the section on classful queueing disciplines, filters are
4326 needed to classify packets into any of the sub-queues. These filters are
4327 called from within the classful qdisc.
4328 </Para>
4330 <Para>
4331 Here is an incomplete list of classifiers available:
4332 <VariableList>
4334 <VarListEntry>
4335 <Term>fw</Term>
4336 <ListItem>
4337 <Para>
4338 Bases the decision on how the firewall has marked the packet. This can be
4339 the easy way out if you don't want to learn tc filter syntax. See the
4340 Queueing chapter for details.
4341 </Para>
4342 </VarListEntry>
4343 <VarListEntry>
4344 <Term>u32</Term>
4345 <ListItem>
4346 <Para>
4347 Bases the decision on fields within the packet (i.e. source IP address, etc)
4348 </Para>
4349 </VarListEntry>
4350 <VarListEntry>
4351 <Term>route</Term>
4352 <ListItem>
4353 <Para>
4354 Bases the decision on which route the packet will be routed by
4355 </Para>
4356 </VarListEntry>
4357 <VarListEntry>
4358 <Term>rsvp, rsvp6</Term>
4359 <ListItem>
4360 <Para>
4361 Routes packets based on <ULink
4362 URL="http://www.isi.edu/div7/rsvp/overview.html"
4363 >RSVP </ULink
4364 >. Only useful
4365 on networks you control - the Internet does not respect RSVP.
4366 </Para>
4367 </VarListEntry>
4368 <VarListEntry>
4369 <Term>tcindex</Term>
4370 <ListItem>
4371 <Para>
4372 Used in the DSMARK qdisc, see the relevant section.
4373 </Para>
4374 </VarListEntry>
4375 </VariableList>
4376 </Para>
4378 <Para>
4379 Note that in general there are many ways in which you can classify packet
4380 and that it generally comes down to preference as to which system you wish
4381 to use.
4382 </Para>
4384 <Para>
4385 Classifiers in general accept a few arguments in common. They are listed
4386 here for convenience:
4387 </Para>
4389 <Para>
4390 <VariableList>
4392 <VarListEntry>
4393 <Term>protocol</Term>
4394 <ListItem>
4395 <Para>
4396 The protocol this classifier will accept. Generally you will only be
4397 accepting only IP traffic. Required.
4398 </Para>
4399 </VarListEntry>
4400 <VarListEntry>
4401 <Term>parent</Term>
4402 <ListItem>
4403 <Para>
4404 The handle this classifier is to be attached to. This handle must be
4405 an already existing class. Required.
4406 </Para>
4407 </VarListEntry>
4408 <VarListEntry>
4409 <Term>prio</Term>
4410 <ListItem>
4411 <Para>
4412 The priority of this classifier. Lower numbers get tested first.
4413 </Para>
4414 </VarListEntry>
4415 <VarListEntry>
4416 <Term>handle</Term>
4417 <ListItem>
4418 <Para>
4419 This handle means different things to different filters.
4420 </Para>
4421 </VarListEntry>
4422 </VariableList>
4423 </Para>
4425 <Para>
4426 All the following sections will assume you are trying to shape the traffic
4427 going to <Literal remap="tt">HostA</Literal>. They will assume that the root class has been
4428 configured on 1: and that the class you want to send the selected traffic to
4429 is 1:1.
4430 </Para>
4432 <Sect1>
4433 <Title>The "u32" classifier</Title>
4435 <Para>
4436 The U32 filter is the most advanced filter available in the current
4437 implementation. It entirely based on hashing tables, which make it
4438 robust when there are many filter rules.
4439 </Para>
4441 <Para>
4442 In its simplest form the U32 filter is a list of records, each
4443 consisting of two fields: a selector and an action. The selectors,
4444 described below, are compared with the currently processed IP packet
4445 until the first match occurs, and then the associated action is performed.
4446 The simplest type of action would be directing the packet into defined
4447 CBQ class.
4448 </Para>
4450 <Para>
4451 The commandline of <Literal remap="tt">tc filter</Literal> program, used to configure the filter,
4452 consists of three parts: filter specification, a selector and an action.
4453 The filter specification can be defined as:
4454 </Para>
4456 <Para>
4458 <Screen>
4459 tc filter add dev IF [ protocol PROTO ]
4460                      [ (preference|priority) PRIO ]
4461                      [ parent CBQ ]
4462 </Screen>
4464 </Para>
4466 <Para>
4467 The <Literal remap="tt">protocol</Literal> field describes protocol that the filter will be
4468 applied to. We will only discuss case of <Literal remap="tt">ip</Literal> protocol. The
4469 <Literal remap="tt">preference</Literal> field (<Literal remap="tt">priority</Literal> can be used alternatively)
4470 sets the priority of currently defined filter. This is important, since
4471 you can have several filters (lists of rules) with different priorities.
4472 Each list will be passed in the order the rules were added, then list with
4473 lower priority (higher preference number) will be processed. The <Literal remap="tt">parent</Literal>
4474 field defines the CBQ tree top (e.g. 1:0), the filter should be attached
4476 </Para>
4478 <Para>
4479 The options decribed above apply to all filters, not only U32.
4480 </Para>
4482 <Sect2>
4483 <Title>U32 selector </Title>
4485 <Para>
4486 The U32 selector contains definition of the pattern, that will be matched
4487 to the currently processed packet. Precisely, it defines which bits are
4488 to be matched in the packet header and nothing more, but this simple
4489 method is very powerful. Let's take a look at the following examples,
4490 taken directly from a pretty complex, real-world filter:
4491 </Para>
4493 <Para>
4495 <Screen>
4496 # tc filter add dev eth0 protocol ip parent 1:0 pref 10 u32 \
4497   match u32 00100000 00ff0000 at 0 flowid 1:10
4498 </Screen>
4500 </Para>
4502 <Para>
4503 For now, leave the first line alone - all these parameters describe
4504 the filter's hash tables. Focus on the selector line, containing
4505 <Literal remap="tt">match</Literal> keyword. This selector will match to IP headers, whose
4506 second byte will be 0x10 (0010). As you can guess, the 00ff number is
4507 the match mask, telling the filter exactly which bits to match. Here
4508 it's 0xff, so the byte will match if it's exactly 0x10. The <Literal remap="tt">at</Literal>
4509 keyword means that the match is to be started at specified offset (in
4510 bytes) -- in this case it's beginning of the packet.  Translating all
4511 that to human language, the packet will match if its Type of Service
4512 field will have `low delay' bits set. Let's analyze another rule:
4513 </Para>
4515 <Para>
4517 <Screen>
4518 # tc filter add dev eth0 protocol ip parent 1:0 pref 10 u32 \
4519   match u32 00000016 0000ffff at nexthdr+0 flowid 1:10
4520 </Screen>
4522 </Para>
4524 <Para>
4525 The <Literal remap="tt">nexthdr</Literal> option means next header encapsulated in the IP packet,
4526 i.e. header of upper-layer protocol. The match will also start here
4527 at the beginning of the next header. The match should occur in the
4528 second, 32-bit word of the header. In TCP and UDP protocols this field
4529 contains packet's destination port. The number is given in big-endian
4530 format, i.e. older bits first, so we simply read 0x0016 as 22 decimal,
4531 which stands for SSH service if this was TCP. As you guess, this match
4532 is ambigous without a context, and we will discuss this later.
4533 </Para>
4535 <Para>
4536 Having understood all the above, we will find the following selector
4537 quite easy to read: <Literal remap="tt">match c0a80100 ffffff00 at 16</Literal>. What we
4538 got here is a three byte match at 17-th byte, counting from the IP
4539 header start. This will match for packets with destination address
4540 anywhere in 192.168.1/24 network. After analyzing the examples, we
4541 can summarize what we have learnt.
4542 </Para>
4544 </Sect2>
4546 <Sect2>
4547 <Title>General selectors</Title>
4549 <Para>
4550 General selectors define the pattern, mask and offset the pattern
4551 will be matched to the packet contents. Using the general selectors
4552 you can match virtually any single bit in the IP (or upper layer)
4553 header. They are more difficult to write and read, though, than
4554 specific selectors that described below. The general selector syntax
4556 </Para>
4558 <Para>
4560 <Screen>
4561 match [ u32 | u16 | u8 ] PATTERN MASK [ at OFFSET | nexthdr+OFFSET]
4562 </Screen>
4564 </Para>
4566 <Para>
4567 One of the keywords <Literal remap="tt">u32</Literal>, <Literal remap="tt">u16</Literal> or <Literal remap="tt">u8</Literal> specifies
4568 length of the pattern in bits. PATTERN and MASK should follow, of length
4569 defined by the previous keyword. The OFFSET parameter is the offset,
4570 in bytes, to start matching. If <Literal remap="tt">nexthdr+</Literal> keyword is given,
4571 the offset is relative to start of the upper layer header.
4572 </Para>
4574 <Para>
4575 Some examples:
4576 </Para>
4578 <Para>
4580 <Screen>
4581 # tc filter add dev ppp14 parent 1:0 prio 10 u32 \
4582      match u8 64 0xff at 8 \
4583      flowid 1:4
4584 </Screen>
4586 </Para>
4588 <Para>
4589 Packet will match to this rule, if its time to live (TTL) is 64.
4590 TTL is the field starting just after 8-th byte of the IP header.
4591 </Para>
4593 <Para>
4595 <Screen>
4596 # tc filter add dev ppp14 parent 1:0 prio 10 u32 \
4597      match u8 0x10 0xff at nexthdr+13 \
4598      protocol tcp \
4599      flowid 1:3 
4600 </Screen>
4602 </Para>
4604 <Para>
4605 FIXME: it has been pointed out that this syntax does not work currently.
4606 </Para>
4608 <Para>
4609 Use this to match ACKs on packets smaller than 64 bytes:
4610 </Para>
4612 <Para>
4614 <Screen>
4615 ## match acks the hard way,
4616 ## IP protocol 6,
4617 ## IP header length 0x5(32 bit words),
4618 ## IP Total length 0x34 (ACK + 12 bytes of TCP options)
4619 ## TCP ack set (bit 5, offset 33)
4620 # tc filter add dev ppp14 parent 1:0 protocol ip prio 10 u32 \
4621             match ip protocol 6 0xff \
4622             match u8 0x05 0x0f at 0 \
4623             match u16 0x0000 0xffc0 at 2 \
4624             match u8 0x10 0xff at 33 \
4625             flowid 1:3
4626 </Screen>
4628 </Para>
4630 <Para>
4631 This rule will only match TCP packets with ACK bit set, and no further
4632 payload. Here we can see an example of using two selectors, the final result
4633 will be logical AND of their results. If we take a look at TCP header
4634 diagram, we can see that the ACK bit is second older bit (0x10) in the 14-th
4635 byte of the TCP header (<Literal remap="tt">at nexthdr+13</Literal>).  As for the second
4636 selector, if we'd like to make our life harder, we could write <Literal remap="tt">match u8
4637 0x06 0xff at 9</Literal> instead of using the specific selector <Literal remap="tt">protocol
4638 tcp</Literal>, because 6 is the number of TCP protocol, present in 10-th byte of
4639 the IP header. On the other hand, in this example we couldn't use any
4640 specific selector for the first match - simply because there's no specific
4641 selector to match TCP ACK bits.
4642 </Para>
4644 </Sect2>
4646 <Sect2>
4647 <Title>Specific selectors</Title>
4649 <Para>
4650 The following table contains a list of all specific selectors 
4651 the author of this section has found in the <Literal remap="tt">tc</Literal> program
4652 source code. They simply make your life easier and increase readability
4653 of your filter's configuration.
4654 </Para>
4656 <Para>
4657 FIXME: table placeholder - the table is in separate file ,,selector.html''
4658 </Para>
4660 <Para>
4661 FIXME: it's also still in Polish :-(
4662 </Para>
4664 <Para>
4665 FIXME: must be sgml'ized
4666 </Para>
4668 <Para>
4669 Some examples:
4670 </Para>
4672 <Para>
4674 <Screen>
4675 # tc filter add dev ppp0 parent 1:0 prio 10 u32 \
4676      match ip tos 0x10 0xff \
4677      flowid 1:4
4678 </Screen>
4680 </Para>
4682 <Para>
4683 FIXME: tcp dst match does not work as described below:
4684 </Para>
4686 <Para>
4687 The above rule will match packets which have the TOS field set to 0x10.
4688 The TOS field starts at second byte of the packet and is one byte big,
4689 so we could write an equivalent general selector: <Literal remap="tt">match u8 0x10 0xff
4690 at 1</Literal>. This gives us hint to the internals of U32 filter -- the
4691 specific rules are always translated to general ones, and in this
4692 form they are stored in the kernel memory. This leads to another conclusion
4693 -- the <Literal remap="tt">tcp</Literal> and <Literal remap="tt">udp</Literal> selectors are exactly the same
4694 and this is why you can't use single <Literal remap="tt">match tcp dst 53 0xffff</Literal>
4695 selector to match TCP packets sent to given port -- they will also
4696 match UDP packets sent to this port. You must remember to also specify
4697 the protocol and end up with the following rule:
4698 </Para>
4700 <Para>
4702 <Screen>
4703 # tc filter add dev ppp0 parent 1:0 prio 10 u32 \
4704         match tcp dst 53 0xffff \
4705         match ip protocol 0x6 0xff \
4706         flowid 1:2
4707 </Screen>
4709 </Para>
4711 </Sect2>
4713 </Sect1>
4715 <Sect1>
4716 <Title>The "route" classifier</Title>
4718 <Para>
4719 This classifier filters based on the results of the routing tables. When a
4720 packet that is traversing through the classes reaches one that is marked
4721 with the "route" filter, it splits the packets up based on information in
4722 the routing table.
4723 </Para>
4725 <Para>
4727 <Screen>
4728 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 route
4729 </Screen>
4731 </Para>
4733 <Para>
4734 Here we add a route classifier onto the parent node 1:0 with priority 100. 
4735 When a packet reaches this node (which, since it is the root, will happen
4736 immediately) it will consult the routing table and if one matches will
4737 send it to the given class and give it a priority of 100. Then, to finally
4738 kick it into action, you add the appropriate routing entry:
4739 </Para>
4741 <Para>
4742 The trick here is to define 'realm' based on either destination or source. 
4743 The way to do it is like this:
4744 </Para>
4746 <Para>
4748 <Screen>
4749 # ip route add Host/Network via Gateway dev Device realm RealmNumber
4750 </Screen>
4752 </Para>
4754 <Para>
4755 For instance, we can define our destination network 192.168.10.0 with a realm
4756 number 10:
4757 </Para>
4759 <Para>
4761 <Screen>
4762 # ip route add 192.168.10.0/24 via 192.168.10.1 dev eth1 realm 10
4763 </Screen>
4764   
4765 </Para>
4767 <Para>
4768 When adding route filters, we can use realm numbers to represent the
4769 networks or hosts and specify how the routes match the filters.
4770 </Para>
4772 <Para>
4774 <Screen>
4775 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 \
4776   route to 10 classid 1:10
4777 </Screen>
4778   
4779 </Para>
4781 <Para>
4782 The above rule says packets going to the network 192.168.10.0 match class id
4783 1:10.
4784 </Para>
4786 <Para>
4787 Route filter can also be used to match source routes. For example, there is 
4788 a subnetwork attached to the Linux router on eth2.
4789 </Para>
4791 <Para>
4793 <Screen>
4794 # ip route add 192.168.2.0/24 dev eth2 realm 2
4795 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 \
4796   route from 2 classid 1:2
4797 </Screen>
4799 </Para>
4801 <Para>
4802 Here the filter specifies that packets from the subnetwork 192.168.2.0
4803 (realm 2) will match class id 1:2.
4804 </Para>
4806 </Sect1>
4808 <Sect1>
4809 <Title>Policing filters</Title>
4811 <Para>
4812 To make even more complicated setups possible, you can have filters that
4813 only match up to a certain bandwidth. You can declare a filter to entirely
4814 cease matching above a certain rate, or only to not match only the bandwidth
4815 exceeding a certain rate.
4816 </Para>
4818 <Para>
4819 So if you decided to police at 4mbit/s, but 5mbit/s of traffic is present,
4820 you can stop matching either the entire 5mbit/s, or only not match 1mbit/s,
4821 and do send 4mbit/s to the configured class.
4822 </Para>
4824 <Para>
4825 If bandwidth exceeds the configured rate, you can drop a packet, reclassify
4826 it, or see if another filter will match it.
4827 </Para>
4829 <Sect2>
4830 <Title>Ways to police</Title>
4832 <Para>
4833 There are basically two ways to police. If you compiled the kernel 
4834 with 'Estimators', the kernel can measure for each filter how much traffic
4835 it is passing, more or less. These estimators are very easy on the CPU, as
4836 they simply count 25 times per second how many data has been passed, and
4837 calculate the bitrate from that.
4838 </Para>
4840 <Para>
4841 The other way works again via a Token Bucket Filter, this time living within
4842 your filter. The TBF only matches traffic UP TO your configured bandwidth,
4843 if more is offered, only the excess is subject to the configured overlimit
4844 action.
4845 </Para>
4847 <Sect3>
4848 <Title>With the kernel estimator</Title>
4850 <Para>
4851 This is very simple and has only one parameter: avrate. Either the flow
4852 remains below avrate, and the filter classifies the traffic to the classid
4853 configured, or your rate exceeds it in which case the specified action is
4854 taken, which is 'reclassify' by default.
4855 </Para>
4857 <Para>
4858 The kernel uses an Exponential Weighted Moving Average for your bandwidth
4859 which makes it less sensitive to short bursts.
4860 </Para>
4862 </Sect3>
4864 <Sect3>
4865 <Title>With Token Bucket Filter</Title>
4867 <Para>
4868 Uses the following parameters:
4870 <ItemizedList>
4871 <ListItem>
4873 <Para>
4874 buffer/maxburst
4875 </Para>
4876 </ListItem>
4877 <ListItem>
4879 <Para>
4880 mtu/minburst
4881 </Para>
4882 </ListItem>
4883 <ListItem>
4885 <Para>
4887 </Para>
4888 </ListItem>
4889 <ListItem>
4891 <Para>
4892 rate
4893 </Para>
4894 </ListItem>
4896 </ItemizedList>
4898 </Para>
4900 <Para>
4901 Which behave mostly identical to those described in the Token Bucket Filter
4902 section. Please note however that if you set the mtu of a TBF policer too
4903 low, *no* packets will pass, whereas the egress TBF qdisc will just pass
4904 them slower.
4905 </Para>
4907 <Para>
4908 Another difference is that a policer can only let a packet pass, or drop it.
4909 It cannot delay hold on to it in order to delay it.
4910 </Para>
4912 </Sect3>
4914 </Sect2>
4916 <Sect2>
4917 <Title>Overlimit actions</Title>
4919 <Para>
4920 If your filter decides that it is overlimit, it can take 'actions'.
4921 Currently, three actions are available:
4922 <VariableList>
4924 <VarListEntry>
4925 <Term>continue</Term>
4926 <ListItem>
4927 <Para>
4928 Causes this filter not to match, but perhaps other filters will.
4929 </Para>
4930 </VarListEntry>
4931 <VarListEntry>
4932 <Term>drop</Term>
4933 <ListItem>
4934 <Para>
4935 This is a very fierce option which simply discards traffic exceeding a
4936 certain rate. It is often used in the ingress policer and has limited uses.
4937 For example, you may have a nameserver that falls over if offered more than
4938 5mbit/s of packets, in which case an ingress filter could be used to make
4939 sure no more is ever offered.
4940 </Para>
4941 </VarListEntry>
4942 <VarListEntry>
4943 <Term>Pass/OK</Term>
4944 <ListItem>
4945 <Para>
4946 Pass on traffic ok. Might be used to disable a complicated filter, but leave
4947 it in place.
4948 </Para>
4949 </VarListEntry>
4950 <VarListEntry>
4951 <Term>reclassify</Term>
4952 <ListItem>
4953 <Para>
4954 Most often comes down to reclassification to Best Effort. This is the
4955 default action.
4956 </Para>
4957 </VarListEntry>
4958 </VariableList>
4959 </Para>
4961 </Sect2>
4963 <Sect2>
4964 <Title>Examples</Title>
4966 <Para>
4967 The only real example known is mentioned in the 'Protecting your host 
4968 from SYN floods' section. 
4969 </Para>
4971 <Para>
4972 FIXME: if you have used this, please share your experience with us
4973 </Para>
4975 </Sect2>
4977 </Sect1>
4979 <Sect1>
4980 <Title>Hashing filters for very fast massive filtering</Title>
4982 <Para>
4983 If you have a need for thousands of rules, for example if you have a lot of
4984 clients or computers, all with different QoS specifications, you may find
4985 that the kernel spends a lot of time matching all those rules.
4986 </Para>
4988 <Para>
4989 By default, all filters reside in one big chain which is matched in
4990 descending order of priority. If you have 1000 rules, 1000 checks may be
4991 needed to determine what to do with a packet.
4992 </Para>
4994 <Para>
4995 Matching would go much quicker if you would have 256 chains with each four
4996 rules - if you could divide packets over those 256 chains, so that the right
4997 rule will be there.
4998 </Para>
5000 <Para>
5001 Hashing makes this possible. Let's say you have 1024 cablemodem customers in
5002 your network, with IP addresses ranging from 1.2.0.0 to 1.2.3.255, and each
5003 has to go in another bin, for example 'lite', 'regular' and 'premium'. You
5004 would then have 1024 rules like this:
5005 </Para>
5007 <Para>
5009 <Screen>
5010 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5011   1.2.0.0 classid 1:1
5012 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5013   1.2.0.1 classid 1:1
5015 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5016   1.2.3.254 classid 1:3
5017 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5018   1.2.3.255 classid 1:2
5019 </Screen>
5021 </Para>
5023 <Para>
5024 To speed this up, we can use the last part of the IP address as a 'hash
5025 key'. We then get 256 tables, the first of which looks like this:
5027 <Screen>
5028 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5029   1.2.0.0 classid 1:1
5030 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5031   1.2.1.0 classid 1:1
5032 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5033   1.2.2.0 classid 1:3
5034 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5035   1.2.3.0 classid 1:2
5036 </Screen>
5038 </Para>
5040 <Para>
5041 The next one starts like this:
5043 <Screen>
5044 # tc filter add dev eth1 parent 1:0 protocol ip prio 100 match ip src \
5045   1.2.0.1 classid 1:1
5047 </Screen>
5049 </Para>
5051 <Para>
5052 This way, only four checks are needed at most, two on average. 
5053 </Para>
5055 <Para>
5056 Configuration is pretty complicated, but very worth it by the time you have
5057 this many rules. First we make a filter root, then we create a table with
5058 256 entries:
5060 <Screen>
5061 # tc filter add dev eth1 parent 1:0 prio 5 protocol ip u32
5062 # tc filter add dev eth1 parent 1:0 prio 5 handle 2: protocol ip u32 divisor 256
5063 </Screen>
5065 </Para>
5067 <Para>
5068 Now we add some rules to entries in the created table:
5069 </Para>
5071 <Para>
5073 <Screen>
5074 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 2:7b: \
5075         match ip src 1.2.0.123 flowid 1:1
5076 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 2:7b: \
5077         match ip src 1.2.1.123 flowid 1:2
5078 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 2:7b: \
5079         match ip src 1.2.3.123 flowid 1:3
5080 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 2:7b: \
5081         match ip src 1.2.4.123 flowid 1:2
5082 </Screen>
5084 This is entry 123, which contains matches for 1.2.0.123, 1.2.1.123,
5085 1.2.2.123, 1.2.3.123, and sends them to 1:1, 1:2, 1:3 and 1:2 respectively.
5086 Note that we need to specify our hash bucket in hex, 0x7b is 123.
5087 </Para>
5089 <Para>
5090 Next create a 'hashing filter' that directs traffic to the right entry in
5091 the hashing table:
5093 <Screen>
5094 # tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 ht 800:: \
5095         match ip src 1.2.0.0/16 \
5096         hashkey mask 0x000000ff at 12 \
5097         link 2:
5098 </Screen>
5100 Ok, some numbers need explaining. The default hash table is called 800:: and
5101 all filtering starts there. Then we select the source address, which lives
5102 as position 12, 13, 14 and 15 in the IP header, and indicate that we are
5103 only interested in the last part. This we send to hash table 2:, which we
5104 created earlier.
5105 </Para>
5107 <Para>
5108 It is quite complicated, but it does work in practice and performance will
5109 be staggering. Note that this example could be improved to the ideal case
5110 where each chain contains 1 filter!
5111 </Para>
5113 </Sect1>
5115 </chapter>
5117 <chapter>
5118 <Title>Kernel network parameters </Title>
5120 <Para>
5122 The kernel has lots of parameters which
5123 can be tuned for different circumstances. While, as usual, the default
5124 parameters serve 99&percnt; of installations very well, we don't call this the
5125 Advanced HOWTO for the fun of it!
5126 </Para>
5128 <Para>
5129 The interesting bits are in /proc/sys/net, take a look there. Not everything
5130 will be documented here initially, but we're working on it.
5131 </Para>
5133 <Para>
5134 In the meantime you may want to have a look at the Linux-Kernel sources;
5135 read the file Documentation/filesystems/proc.txt. Most of the
5136 features are explained there.
5137 </Para>
5139 <Para>
5140 (FIXME)
5141 </Para>
5143 <Sect1>
5144 <Title>Reverse Path Filtering</Title>
5146 <Para>
5147 By default, routers route everything, even packets which 'obviously' don't
5148 belong on your network. A common example is private IP space escaping onto
5149 the Internet. If you have an interface with a route of 195.96.96.0/24 to it,
5150 you do not expect packets from 212.64.94.1 to arrive there.
5151 </Para>
5153 <Para>
5154 Lots of people will want to turn this feature off, so the kernel hackers
5155 have made it easy. There are files in /proc where you can tell
5156 the kernel to do this for you. The method is called "Reverse Path
5157 Filtering". Basically, if the reply to this packet wouldn't go out the
5158 interface this packet came in, then this is a bogus packet and should be
5159 ignored.
5160 </Para>
5162 <Para>
5163 The following fragment will turn this on for all current and future
5164 interfaces.
5165 </Para>
5167 <Para>
5169 <Screen>
5170 # for i in /proc/sys/net/ipv4/conf/*/rp_filter ; do
5171 &gt;  echo 1 &#62; $i 
5172 &gt; done
5173 </Screen>
5175 </Para>
5177 <Para>
5178 Going by the example above, if a packet arrived on the Linux router on eth1
5179 claiming to come from the Office+ISP subnet, it would be dropped. Similarly,
5180 if a packet came from the Office subnet, claiming to be from somewhere
5181 outside your firewall, it would be dropped also.
5182 </Para>
5184 <Para>
5185 The above is full reverse path filtering. The default is to only filter
5186 based on IPs that are on directly connected networks. This is because the
5187 full filtering breaks in the case of asymmetric routing (where packets come
5188 in one way and go out another, like satellite traffic, or if you have
5189 dynamic (bgp, ospf, rip) routes in your network. The data comes down
5190 through the satellite dish and replies go back through normal land-lines).
5191 </Para>
5193 <Para>
5194 If this exception applies to you (and you'll probably know if it does) you
5195 can simply turn off the rp_filter on the interface where the
5196 satellite data comes in. If you want to see if any packets are being
5197 dropped, the log_martians file in the same directory will tell
5198 the kernel to log them to your syslog.
5199 </Para>
5201 <Para>
5203 <Screen>
5204 # echo 1 &#62;/proc/sys/net/ipv4/conf/&#60;interfacename&#62;/log_martians
5205 </Screen>
5207 </Para>
5209 <Para>
5210 FIXME: is setting the conf/&lcub;default,all&rcub;/* files enough? - martijn
5211 </Para>
5213 </Sect1>
5215 <Sect1>
5216 <Title>Obscure settings</Title>
5218 <Para>
5219 Ok, there are a lot of parameters which can be modified. We try to list them
5220 all. Also documented (partly) in Documentation/ip-sysctl.txt.
5221 </Para>
5223 <Para>
5224 Some of these settings have different defaults based on whether you 
5225 answered 'Yes' to 'Configure as router and not host' while compiling your
5226 kernel.
5227 </Para>
5229 <Sect2>
5230 <Title>Generic ipv4</Title>
5232 <Para>
5233 As a generic note, most rate limiting features don't work on loopback, so
5234 don't test them locally. The limits are supplied in 'jiffies', and are
5235 enforced using the earlier mentioned token bucket filter.
5236 </Para>
5238 <Para>
5239 The kernel has an internal clock which runs at 'HZ' ticks (or 'jiffies') per
5240 second. On intel, 'HZ' is mostly 100. So setting a *_rate file to, say 50,
5241 would allow for 2 packets per second. The token bucket filter is also
5242 configured to allow for a burst of at most 6 packets, if enough tokens have
5243 been earned.
5244 </Para>
5246 <Para>
5247 Several entries in the following list have been copied from
5248 /usr/src/linux/Documentation/networking/ip-sysctl.txt, written by Alexey
5249 Kuznetsov &lt;kuznet@ms2.inr.ac.ru&gt; and Andi Kleen &lt;ak@muc.de&gt;
5250 <VariableList>
5252 <VarListEntry>
5253 <Term>/proc/sys/net/ipv4/icmp_destunreach_rate</Term>
5254 <ListItem>
5255 <Para>
5256 If the kernel decides that it can't deliver a packet, it will drop it, and
5257 send the source of the packet an ICMP notice to this effect.
5258 </Para>
5259 </VarListEntry>
5260 <VarListEntry>
5261 <Term>/proc/sys/net/ipv4/icmp_echo_ignore_all</Term>
5262 <ListItem>
5263 <Para>
5264 Don't act on echo packets at all. Please don't set this by default, but if
5265 you are used as a relay in a DoS attack, it may be useful.
5266 </Para>
5267 </VarListEntry>
5268 <VarListEntry>
5269 <Term>/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts &lsqb;Useful&rsqb;</Term>
5270 <ListItem>
5271 <Para>
5272 If you ping the broadcast address of a network, all hosts are supposed to
5273 respond. This makes for a dandy denial-of-service tool. Set this to 1 to
5274 ignore these broadcast messages.
5275 </Para>
5276 </VarListEntry>
5277 <VarListEntry>
5278 <Term>/proc/sys/net/ipv4/icmp_echoreply_rate</Term>
5279 <ListItem>
5280 <Para>
5281 The rate at which echo replies are sent to any one destination.
5282 </Para>
5283 </VarListEntry>
5284 <VarListEntry>
5285 <Term>/proc/sys/net/ipv4/icmp_ignore_bogus_error_responses</Term>
5286 <ListItem>
5287 <Para>
5288 Set this to ignore ICMP errors caused by hosts in the network reacting badly
5289 to frames sent to what they perceive to be the broadcast address.
5290 </Para>
5291 </VarListEntry>
5292 <VarListEntry>
5293 <Term>/proc/sys/net/ipv4/icmp_paramprob_rate</Term>
5294 <ListItem>
5295 <Para>
5296 A relatively unknown ICMP message, which is sent in response to incorrect
5297 packets with broken IP or TCP headers. With this file you can control the
5298 rate at which it is sent.
5299 </Para>
5300 </VarListEntry>
5301 <VarListEntry>
5302 <Term>/proc/sys/net/ipv4/icmp_timeexceed_rate</Term>
5303 <ListItem>
5304 <Para>
5305 This the famous cause of the 'Solaris middle star' in traceroutes. Limits
5306 number of ICMP Time Exceeded messages sent. 
5307 </Para>
5308 </VarListEntry>
5309 <VarListEntry>
5310 <Term>/proc/sys/net/ipv4/igmp_max_memberships</Term>
5311 <ListItem>
5312 <Para>
5313 Maximum number of listening igmp (multicast) sockets on the host.
5314 FIXME: Is this true?
5315 </Para>
5316 </VarListEntry>
5317 <VarListEntry>
5318 <Term>/proc/sys/net/ipv4/inet_peer_gc_maxtime</Term>
5319 <ListItem>
5320 <Para>
5321 FIXME: Add a little explanation about the inet peer storage?
5323 Minimum interval between garbage collection passes.  This interval is in
5324 effect under low (or absent) memory pressure on the pool. Measured in
5325 jiffies.
5326 </Para>
5327 </VarListEntry>
5328 <VarListEntry>
5329 <Term>/proc/sys/net/ipv4/inet_peer_gc_mintime</Term>
5330 <ListItem>
5331 <Para>
5332 Minimum interval between garbage collection passes.  This interval is in
5333 effect under high memory pressure on the pool. Measured in jiffies.
5334 </Para>
5335 </VarListEntry>
5336 <VarListEntry>
5337 <Term>/proc/sys/net/ipv4/inet_peer_maxttl</Term>
5338 <ListItem>
5339 <Para>
5340 Maximum time-to-live of entries.  Unused entries will expire after this
5341 period of time if there is no memory pressure on the pool (i.e. when the
5342 number of entries in the pool is very small). Measured in jiffies.
5343 </Para>
5344 </VarListEntry>
5345 <VarListEntry>
5346 <Term>/proc/sys/net/ipv4/inet_peer_minttl</Term>
5347 <ListItem>
5348 <Para>
5349 Minimum time-to-live of entries.  Should be enough to cover fragment
5350 time-to-live on the reassembling side.  This minimum time-to-live
5351 is guaranteed if the pool size is less than inet_peer_threshold.
5352 Measured in jiffies.
5353 </Para>
5354 </VarListEntry>
5355 <VarListEntry>
5356 <Term>/proc/sys/net/ipv4/inet_peer_threshold</Term>
5357 <ListItem>
5358 <Para>
5359 The approximate size of the INET peer storage.  Starting from this threshold
5360 entries will be thrown aggressively.  This threshold also determines
5361 entries' time-to-live and time intervals between garbage collection passes. 
5362 More entries, less time-to-live, less GC interval.
5363 </Para>
5364 </VarListEntry>
5365 <VarListEntry>
5366 <Term>/proc/sys/net/ipv4/ip_autoconfig</Term>
5367 <ListItem>
5368 <Para>
5369 This file contains the number one if the host received its IP configuration by
5370 RARP, BOOTP, DHCP or a similar mechanism. Otherwise it is zero.
5371 </Para>
5372 </VarListEntry>
5373 <VarListEntry>
5374 <Term>/proc/sys/net/ipv4/ip_default_ttl</Term>
5375 <ListItem>
5376 <Para>
5377 Time To Live of packets. Set to a safe 64. Raise it if you have a huge
5378 network. Don't do so for fun - routing loops cause much more damage that
5379 way. You might even consider lowering it in some circumstances.
5380 </Para>
5381 </VarListEntry>
5382 <VarListEntry>
5383 <Term>/proc/sys/net/ipv4/ip_dynaddr</Term>
5384 <ListItem>
5385 <Para>
5386 You need to set this if you use dial-on-demand with a dynamic interface
5387 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
5388 connection that brings up your interface itself does not work, but the
5389 second try does.
5390 </Para>
5391 </VarListEntry>
5392 <VarListEntry>
5393 <Term>/proc/sys/net/ipv4/ip_forward</Term>
5394 <ListItem>
5395 <Para>
5396 If the kernel should attempt to forward packets. Off by default.
5397 </Para>
5398 </VarListEntry>
5399 <VarListEntry>
5400 <Term>/proc/sys/net/ipv4/ip_local_port_range</Term>
5401 <ListItem>
5402 <Para>
5403 Range of local ports for outgoing connections. Actually quite small by
5404 default, 1024 to 4999.
5405 </Para>
5406 </VarListEntry>
5407 <VarListEntry>
5408 <Term>/proc/sys/net/ipv4/ip_no_pmtu_disc</Term>
5409 <ListItem>
5410 <Para>
5411 Set this if you want to disable Path MTU discovery - a technique to
5412 determine the largest Maximum Transfer Unit possible on your path. See also
5413 the section on Path MTU discovery in the cookbook chapter.
5414 </Para>
5415 </VarListEntry>
5416 <VarListEntry>
5417 <Term>/proc/sys/net/ipv4/ipfrag_high_thresh</Term>
5418 <ListItem>
5419 <Para>
5420 Maximum memory used to reassemble IP fragments. When 
5421 ipfrag_high_thresh bytes of memory is allocated for this purpose,
5422 the fragment handler will toss packets until ipfrag_low_thresh
5423 is reached.
5424 </Para>
5425 </VarListEntry>
5426 <VarListEntry>
5427 <Term>/proc/sys/net/ipv4/ip_nonlocal_bind</Term>
5428 <ListItem>
5429 <Para>
5430 Set this if you want your applications to be able to bind to an address
5431 which doesn't belong to a device on your system. This can be useful when
5432 your machine is on a non-permanent (or even dynamic) link, so your services
5433 are able to start up and bind to a specific address when your link is down.
5434 </Para>
5435 </VarListEntry>
5436 <VarListEntry>
5437 <Term>/proc/sys/net/ipv4/ipfrag_low_thresh</Term>
5438 <ListItem>
5439 <Para>
5440 Minimum memory used to reassemble IP fragments.
5441 </Para>
5442 </VarListEntry>
5443 <VarListEntry>
5444 <Term>/proc/sys/net/ipv4/ipfrag_time</Term>
5445 <ListItem>
5446 <Para>
5447 Time in seconds to keep an IP fragment in memory.
5448 </Para>
5449 </VarListEntry>
5450 <VarListEntry>
5451 <Term>/proc/sys/net/ipv4/tcp_abort_on_overflow</Term>
5452 <ListItem>
5453 <Para>
5454 A boolean flag controlling the behaviour under lots of incoming connections.
5455 When enabled, this causes the kernel to actively send RST packets when a
5456 service is overloaded.
5457 </Para>
5458 </VarListEntry>
5459 <VarListEntry>
5460 <Term>/proc/sys/net/ipv4/tcp_fin_timeout</Term>
5461 <ListItem>
5462 <Para>
5463 Time to hold socket in state FIN-WAIT-2, if it was closed by our side. Peer
5464 can be broken and never close its side, or even died unexpectedly. Default
5465 value is 60sec. Usual value used in 2.2 was 180 seconds, you may restore it,
5466 but remember that if your machine is even underloaded WEB server, you risk
5467 to overflow memory with kilotons of dead sockets, FIN-WAIT-2 sockets are
5468 less dangerous than FIN-WAIT-1, because they eat maximum 1.5K of memory, but
5469 they tend to live longer. Cf. tcp_max_orphans.
5470 </Para>
5471 </VarListEntry>
5472 <VarListEntry>
5473 <Term>/proc/sys/net/ipv4/tcp_keepalive_time</Term>
5474 <ListItem>
5475 <Para>
5476 How often TCP sends out keepalive messages when keepalive is enabled. 
5478 Default: 2hours.
5479 </Para>
5480 </VarListEntry>
5481 <VarListEntry>
5482 <Term>/proc/sys/net/ipv4/tcp_keepalive_intvl</Term>
5483 <ListItem>
5484 <Para>
5485 How frequent probes are retransmitted, when a probe isn't acknowledged. 
5487 Default: 75 seconds.
5488 </Para>
5489 </VarListEntry>
5490 <VarListEntry>
5491 <Term>/proc/sys/net/ipv4/tcp_keepalive_probes</Term>
5492 <ListItem>
5493 <Para>
5494 How many keepalive probes TCP will send, until it decides that the
5495 connection is broken. 
5497 Default value: 9. 
5499 Multiplied with tcp_keepalive_intvl, this gives the time a link can be
5500 nonresponsive after a keepalive has been sent.
5501 </Para>
5502 </VarListEntry>
5503 <VarListEntry>
5504 <Term>/proc/sys/net/ipv4/tcp_max_orphans</Term>
5505 <ListItem>
5506 <Para>
5507 Maximal number of TCP sockets not attached to any user file handle, held by
5508 system. If this number is exceeded orphaned connections are reset
5509 immediately and warning is printed. This limit exists only to prevent simple
5510 DoS attacks, you _must_ not rely on this or lower the limit artificially,
5511 but rather increase it (probably, after increasing installed memory), if
5512 network conditions require more than default value, and tune network
5513 services to linger and kill such states more aggressively. Let me remind you
5514 again: each orphan eats up to &nbsp;64K of unswappable memory.
5515 </Para>
5516 </VarListEntry>
5517 <VarListEntry>
5518 <Term>/proc/sys/net/ipv4/tcp_orphan_retries</Term>
5519 <ListItem>
5520 <Para>
5521 How may times to retry before killing TCP connection, closed by our side.
5522 Default value 7 corresponds to &nbsp;50sec-16min depending on RTO. If your machine
5523 is a loaded WEB server, you should think about lowering this value, such
5524 sockets may consume significant resources. Cf. tcp_max_orphans.
5525 </Para>
5526 </VarListEntry>
5527 <VarListEntry>
5528 <Term>/proc/sys/net/ipv4/tcp_max_syn_backlog</Term>
5529 <ListItem>
5530 <Para>
5531 Maximal number of remembered connection requests, which still did not
5532 receive an acknowledgement from connecting client. Default value is 1024 for
5533 systems with more than 128Mb of memory, and 128 for low memory machines. If
5534 server suffers of overload, try to increase this number. Warning! If you
5535 make it greater than 1024, it would be better to change TCP_SYNQ_HSIZE in
5536 include/net/tcp.h to keep TCP_SYNQ_HSIZE*16&#60;=tcp_max_syn_backlog and to
5537 recompile kernel.
5538 </Para>
5539 </VarListEntry>
5540 <VarListEntry>
5541 <Term>/proc/sys/net/ipv4/tcp_max_tw_buckets</Term>
5542 <ListItem>
5543 <Para>
5544 Maximal number of timewait sockets held by system simultaneously. If this
5545 number is exceeded time-wait socket is immediately destroyed and warning is
5546 printed. This limit exists only to prevent simple DoS attacks, you _must_
5547 not lower the limit artificially, but rather increase it (probably, after
5548 increasing installed memory), if network conditions require more than
5549 default value.
5550 </Para>
5551 </VarListEntry>
5552 <VarListEntry>
5553 <Term>/proc/sys/net/ipv4/tcp_retrans_collapse</Term>
5554 <ListItem>
5555 <Para>
5556 Bug-to-bug compatibility with some broken printers.
5557 On retransmit try to send bigger packets to work around bugs in
5558 certain TCP stacks.
5559 </Para>
5560 </VarListEntry>
5561 <VarListEntry>
5562 <Term>/proc/sys/net/ipv4/tcp_retries1</Term>
5563 <ListItem>
5564 <Para>
5565 How many times to retry before deciding that something is wrong
5566 and it is necessary to report this suspection to network layer.
5567 Minimal RFC value is 3, it is default, which corresponds
5568 to &nbsp;3sec-8min depending on RTO.
5569 </Para>
5570 </VarListEntry>
5571 <VarListEntry>
5572 <Term>/proc/sys/net/ipv4/tcp_retries2</Term>
5573 <ListItem>
5574 <Para>
5575 How may times to retry before killing alive TCP connection.
5576 <ULink
5577 URL="http://www.ietf.org/rfc/rfc1122.txt"
5578 >RFC 1122</ULink
5580 says that the limit should be longer than 100 sec.
5581 It is too small number. Default value 15 corresponds to &nbsp;13-30min
5582 depending on RTO.
5583 </Para>
5584 </VarListEntry>
5585 <VarListEntry>
5586 <Term>/proc/sys/net/ipv4/tcp_rfc1337</Term>
5587 <ListItem>
5588 <Para>
5589 This boolean enables a fix for 'time-wait assassination hazards in tcp', described
5590 in RFC 1337. If enabled, this causes the kernel to drop RST packets for
5591 sockets in the time-wait state.
5593 Default: 0
5594 </Para>
5595 </VarListEntry>
5596 <VarListEntry>
5597 <Term>/proc/sys/net/ipv4/tcp_sack</Term>
5598 <ListItem>
5599 <Para>
5600 Use Selective ACK which can be used to signify that specific packets are
5601 missing - therefore helping fast recovery.
5602 </Para>
5603 </VarListEntry>
5604 <VarListEntry>
5605 <Term>/proc/sys/net/ipv4/tcp_stdurg</Term>
5606 <ListItem>
5607 <Para>
5608 Use the Host requirements interpretation of the TCP urg pointer
5609 field. 
5611 Most hosts use the older BSD interpretation, so if you turn this on
5612 Linux might not communicate correctly with them. 
5614 Default: FALSE 
5615 </Para>
5616 </VarListEntry>
5617 <VarListEntry>
5618 <Term>/proc/sys/net/ipv4/tcp_syn_retries</Term>
5619 <ListItem>
5620 <Para>
5621 Number of SYN packets the kernel will send before giving up on the new
5622 connection.
5623 </Para>
5624 </VarListEntry>
5625 <VarListEntry>
5626 <Term>/proc/sys/net/ipv4/tcp_synack_retries</Term>
5627 <ListItem>
5628 <Para>
5629 To open the other side of the connection, the kernel sends a SYN with a
5630 piggybacked ACK on it, to acknowledge the earlier received SYN. This is part
5631 2 of the threeway handshake. This setting determines the number of SYN+ACK
5632 packets sent before the kernel gives up on the connection.
5633 </Para>
5634 </VarListEntry>
5635 <VarListEntry>
5636 <Term>/proc/sys/net/ipv4/tcp_timestamps</Term>
5637 <ListItem>
5638 <Para>
5639 Timestamps are used, amongst other things, to protect against wrapping
5640 sequence numbers. A 1 gigabit link might conceivably re-encounter a previous
5641 sequence number with an out-of-line value, because it was of a previous
5642 generation. The timestamp will let it recognise this 'ancient packet'.
5643 </Para>
5644 </VarListEntry>
5645 <VarListEntry>
5646 <Term>/proc/sys/net/ipv4/tcp_tw_recycle</Term>
5647 <ListItem>
5648 <Para>
5649 Enable fast recycling TIME-WAIT sockets. Default value is 1.
5650 It should not be changed without advice/request of technical experts.
5651 </Para>
5652 </VarListEntry>
5653 <VarListEntry>
5654 <Term>/proc/sys/net/ipv4/tcp_window_scaling</Term>
5655 <ListItem>
5656 <Para>
5657 TCP/IP normally allows windows up to 65535 bytes big. For really fast
5658 networks, this may not be enough. The window scaling options allows for
5659 almost gigabyte windows, which is good for high bandwidth*delay products.
5660 </Para>
5661 </VarListEntry>
5662 </VariableList>
5663 </Para>
5665 </Sect2>
5667 <Sect2>
5668 <Title>Per device settings</Title>
5670 <Para>
5671 DEV can either stand for a real interface, or for 'all' or 'default'.
5672 Default also changes settings for interfaces yet to be created.
5673 <VariableList>
5675 <VarListEntry>
5676 <Term>/proc/sys/net/ipv4/conf/DEV/accept_redirects</Term>
5677 <ListItem>
5678 <Para>
5679 If a router decides that you are using it for a wrong purpose (ie, it needs
5680 to resend your packet on the same interface), it will send us a ICMP
5681 Redirect. This is a slight security risk however, so you may want to turn it
5682 off, or use secure redirects.
5683 </Para>
5684 </VarListEntry>
5685 <VarListEntry>
5686 <Term>/proc/sys/net/ipv4/conf/DEV/accept_source_route</Term>
5687 <ListItem>
5688 <Para>
5689 Not used very much anymore. You used to be able to give a packet a list of
5690 IP addresses it should visit on its way. Linux can be made to honor this IP
5691 option.
5692 </Para>
5693 </VarListEntry>
5694 <VarListEntry>
5695 <Term>/proc/sys/net/ipv4/conf/DEV/bootp_relay</Term>
5696 <ListItem>
5697 <Para>
5698 Accept packets  with source address 0.b.c.d with destinations not to this host
5699 as local ones. It is supposed that a BOOTP relay daemon will catch and forward
5700 such packets.
5701 </Para>
5703 <Para>
5704 The default  is  0,  since this feature is not implemented yet (kernel version
5705 2.2.12).
5706 </Para>
5707 </VarListEntry>
5708 <VarListEntry>
5709 <Term>/proc/sys/net/ipv4/conf/DEV/forwarding</Term>
5710 <ListItem>
5711 <Para>
5712 Enable or disable IP forwarding on this interface.
5713 </Para>
5714 </VarListEntry>
5715 <VarListEntry>
5716 <Term>/proc/sys/net/ipv4/conf/DEV/log_martians</Term>
5717 <ListItem>
5718 <Para>
5719 See the section on reverse path filters.
5720 </Para>
5721 </VarListEntry>
5722 <VarListEntry>
5723 <Term>/proc/sys/net/ipv4/conf/DEV/mc_forwarding</Term>
5724 <ListItem>
5725 <Para>
5726 If we do multicast forwarding on this interface
5727 </Para>
5728 </VarListEntry>
5729 <VarListEntry>
5730 <Term>/proc/sys/net/ipv4/conf/DEV/proxy_arp</Term>
5731 <ListItem>
5732 <Para>
5733 If you set this to 1, this interface will respond to ARP requests for
5734 addresses the kernel has routes to. Can be very useful when building 'ip
5735 pseudo bridges'. Do take care that your netmasks are very correct before
5736 enabling this! Also be aware that the rp_filter, mentioned elsewhere, also
5737 operates on ARP queries!
5738 </Para>
5739 </VarListEntry>
5740 <VarListEntry>
5741 <Term>/proc/sys/net/ipv4/conf/DEV/rp_filter</Term>
5742 <ListItem>
5743 <Para>
5744 See the section on reverse path filters.
5745 </Para>
5746 </VarListEntry>
5747 <VarListEntry>
5748 <Term>/proc/sys/net/ipv4/conf/DEV/secure_redirects</Term>
5749 <ListItem>
5750 <Para>
5751 Accept ICMP  redirect  messages  only  for gateways, listed in default gateway
5752 list. Enabled by default.
5753 </Para>
5754 </VarListEntry>
5755 <VarListEntry>
5756 <Term>/proc/sys/net/ipv4/conf/DEV/send_redirects</Term>
5757 <ListItem>
5758 <Para>
5759 If we send the above mentioned redirects.
5760 </Para>
5761 </VarListEntry>
5762 <VarListEntry>
5763 <Term>/proc/sys/net/ipv4/conf/DEV/shared_media</Term>
5764 <ListItem>
5765 <Para>
5766 If it  is  not  set  the kernel does not assume that different subnets on this
5767 device can communicate directly. Default setting is 'yes'.
5768 </Para>
5769 </VarListEntry>
5770 <VarListEntry>
5771 <Term>/proc/sys/net/ipv4/conf/DEV/tag</Term>
5772 <ListItem>
5773 <Para>
5774 FIXME: fill this in
5775 </Para>
5776 </VarListEntry>
5777 </VariableList>
5778 </Para>
5780 </Sect2>
5782 <Sect2>
5783 <Title>Neighbor policy</Title>
5785 <Para>
5786 Dev can either stand for a real interface, or for 'all' or 'default'.
5787 Default also changes settings for interfaces yet to be created.
5788 <VariableList>
5790 <VarListEntry>
5791 <Term>/proc/sys/net/ipv4/neigh/DEV/anycast_delay</Term>
5792 <ListItem>
5793 <Para>
5794 Maximum for  random  delay  of  answers  to  neighbor solicitation messages in
5795 jiffies (1/100  sec). Not yet implemented (Linux does not have anycast support
5796 yet).
5797 </Para>
5798 </VarListEntry>
5799 <VarListEntry>
5800 <Term>/proc/sys/net/ipv4/neigh/DEV/app_solicit</Term>
5801 <ListItem>
5802 <Para>
5803 Determines the  number of requests to send to the user level ARP daemon. Use 0
5804 to turn off.
5805 </Para>
5806 </VarListEntry>
5807 <VarListEntry>
5808 <Term>/proc/sys/net/ipv4/neigh/DEV/base_reachable_time</Term>
5809 <ListItem>
5810 <Para>
5811 A base  value  used for computing the random reachable time value as specified
5812 in RFC2461.
5813 </Para>
5814 </VarListEntry>
5815 <VarListEntry>
5816 <Term>/proc/sys/net/ipv4/neigh/DEV/delay_first_probe_time</Term>
5817 <ListItem>
5818 <Para>
5819 Delay for  the  first  time  probe  if  the  neighbor  is  reachable.  (see
5820 gc_stale_time)
5821 </Para>
5822 </VarListEntry>
5823 <VarListEntry>
5824 <Term>/proc/sys/net/ipv4/neigh/DEV/gc_stale_time</Term>
5825 <ListItem>
5826 <Para>
5827 Determines how  often  to  check  for stale ARP entries. After an ARP entry is
5828 stale it  will  be resolved again (which is useful when an IP address migrates
5829 to another  machine).  When  ucast_solicit is greater than 0 it first tries to
5830 send an  ARP  packet  directly  to  the  known  host  When  that  fails  and
5831 mcast_solicit is greater than 0, an ARP request is broadcasted.
5832 </Para>
5833 </VarListEntry>
5834 <VarListEntry>
5835 <Term>/proc/sys/net/ipv4/neigh/DEV/locktime</Term>
5836 <ListItem>
5837 <Para>
5838 An ARP/neighbor  entry  is only replaced with a new one if the old is at least
5839 locktime old. This prevents ARP cache thrashing.
5840 </Para>
5841 </VarListEntry>
5842 <VarListEntry>
5843 <Term>/proc/sys/net/ipv4/neigh/DEV/mcast_solicit</Term>
5844 <ListItem>
5845 <Para>
5846 Maximum number of retries for multicast solicitation.
5847 </Para>
5848 </VarListEntry>
5849 <VarListEntry>
5850 <Term>/proc/sys/net/ipv4/neigh/DEV/proxy_delay</Term>
5851 <ListItem>
5852 <Para>
5853 Maximum time  (real  time is random &lsqb;0..proxytime]) before answering to an ARP
5854 request for  which  we have an proxy ARP entry. In some cases, this is used to
5855 prevent network flooding.
5856 </Para>
5857 </VarListEntry>
5858 <VarListEntry>
5859 <Term>/proc/sys/net/ipv4/neigh/DEV/proxy_qlen</Term>
5860 <ListItem>
5861 <Para>
5862 Maximum queue length of the delayed proxy arp timer. (see proxy_delay).
5863 </Para>
5864 </VarListEntry>
5865 <VarListEntry>
5866 <Term>/proc/sys/net/ipv4/neigh/DEV/retrans_time</Term>
5867 <ListItem>
5868 <Para>
5869 The time,  expressed  in  jiffies  (1/100 sec), between retransmitted Neighbor
5870 Solicitation messages.  Used  for  address  resolution  and  to determine if a
5871 neighbor is unreachable.
5872 </Para>
5873 </VarListEntry>
5874 <VarListEntry>
5875 <Term>/proc/sys/net/ipv4/neigh/DEV/ucast_solicit</Term>
5876 <ListItem>
5877 <Para>
5878 Maximum number of retries for unicast solicitation.
5879 </Para>
5880 </VarListEntry>
5881 <VarListEntry>
5882 <Term>/proc/sys/net/ipv4/neigh/DEV/unres_qlen</Term>
5883 <ListItem>
5884 <Para>
5885 Maximum queue  length  for a pending arp request - the number of packets which
5886 are accepted from other layers while the ARP address is still resolved.
5887 </Para>
5888 </VarListEntry>
5889 <VarListEntry>
5890 <Term>Internet QoS: Architectures and Mechanisms for Quality of Service,
5891 Zheng Wang, ISBN 1-55860-608-4</Term>
5892 <ListItem>
5893 <Para>
5894 Hardcover textbook covering topics
5895 related to Quality of Service. Good for understanding basic concepts.
5896 </Para>
5897 </VarListEntry>
5898 </VariableList>
5899 </Para>
5901 </Sect2>
5903 <Sect2>
5904 <Title>Routing settings</Title>
5906 <Para>
5907 <VariableList>
5909 <VarListEntry>
5910 <Term>/proc/sys/net/ipv4/route/error_burst</Term>
5911 <ListItem>
5912 <Para>
5913 These parameters  are used to limit the warning messages written to the kernel
5914 log from  the  routing  code.  The  higher the error_cost factor is, the fewer
5915 messages will  be written. Error_burst controls when messages will be dropped.
5916 The default settings limit warning messages to one every five seconds.
5917 </Para>
5918 </VarListEntry>
5919 <VarListEntry>
5920 <Term>/proc/sys/net/ipv4/route/error_cost</Term>
5921 <ListItem>
5922 <Para>
5923 These parameters  are used to limit the warning messages written to the kernel
5924 log from  the  routing  code.  The  higher the error_cost factor is, the fewer
5925 messages will  be written. Error_burst controls when messages will be dropped.
5926 The default settings limit warning messages to one every five seconds.
5927 </Para>
5928 </VarListEntry>
5929 <VarListEntry>
5930 <Term>/proc/sys/net/ipv4/route/flush</Term>
5931 <ListItem>
5932 <Para>
5933 Writing to this file results in a flush of the routing cache.
5934 </Para>
5935 </VarListEntry>
5936 <VarListEntry>
5937 <Term>/proc/sys/net/ipv4/route/gc_elasticity</Term>
5938 <ListItem>
5939 <Para>
5940 Values to  control  the  frequency  and  behavior  of  the  garbage collection
5941 algorithm for the routing cache. This can be important for when doing
5942 failover. At least gc_timeout seconds will elapse before Linux will skip
5943 to another route because the previous one has died. By default set to 300,
5944 you may want to lower it if you want to have a speedy failover.
5945 </Para>
5947 <Para>
5948 Also see <ULink
5949 URL="http://mailman.ds9a.nl/pipermail/lartc/2002q1/002667.html"
5950 >this post</ULink
5951 > by Ard van Breemen.
5952 </Para>
5953 </VarListEntry>
5954 <VarListEntry>
5955 <Term>/proc/sys/net/ipv4/route/gc_interval</Term>
5956 <ListItem>
5957 <Para>
5958 See /proc/sys/net/ipv4/route/gc_elasticity.
5959 </Para>
5960 </VarListEntry>
5961 <VarListEntry>
5962 <Term>/proc/sys/net/ipv4/route/gc_min_interval</Term>
5963 <ListItem>
5964 <Para>
5965 See /proc/sys/net/ipv4/route/gc_elasticity.
5966 </Para>
5967 </VarListEntry>
5968 <VarListEntry>
5969 <Term>/proc/sys/net/ipv4/route/gc_thresh</Term>
5970 <ListItem>
5971 <Para>
5972 See /proc/sys/net/ipv4/route/gc_elasticity.
5973 </Para>
5974 </VarListEntry>
5975 <VarListEntry>
5976 <Term>/proc/sys/net/ipv4/route/gc_timeout</Term>
5977 <ListItem>
5978 <Para>
5979 See /proc/sys/net/ipv4/route/gc_elasticity.
5980 </Para>
5981 </VarListEntry>
5982 <VarListEntry>
5983 <Term>/proc/sys/net/ipv4/route/max_delay</Term>
5984 <ListItem>
5985 <Para>
5986 Delays for flushing the routing cache.
5987 </Para>
5988 </VarListEntry>
5989 <VarListEntry>
5990 <Term>/proc/sys/net/ipv4/route/max_size</Term>
5991 <ListItem>
5992 <Para>
5993 Maximum size  of  the routing cache. Old entries will be purged once the cache
5994 reached has this size.
5995 </Para>
5996 </VarListEntry>
5997 <VarListEntry>
5998 <Term>/proc/sys/net/ipv4/route/min_adv_mss</Term>
5999 <ListItem>
6000 <Para>
6001 FIXME: fill this in
6002 </Para>
6003 </VarListEntry>
6004 <VarListEntry>
6005 <Term>/proc/sys/net/ipv4/route/min_delay</Term>
6006 <ListItem>
6007 <Para>
6008 Delays for flushing the routing cache.
6009 </Para>
6010 </VarListEntry>
6011 <VarListEntry>
6012 <Term>/proc/sys/net/ipv4/route/min_pmtu</Term>
6013 <ListItem>
6014 <Para>
6015 FIXME: fill this in
6016 </Para>
6017 </VarListEntry>
6018 <VarListEntry>
6019 <Term>/proc/sys/net/ipv4/route/mtu_expires</Term>
6020 <ListItem>
6021 <Para>
6022 FIXME: fill this in
6023 </Para>
6024 </VarListEntry>
6025 <VarListEntry>
6026 <Term>/proc/sys/net/ipv4/route/redirect_load</Term>
6027 <ListItem>
6028 <Para>
6029 Factors which  determine  if  more ICPM redirects should be sent to a specific
6030 host. No  redirects  will be sent once the load limit or the maximum number of
6031 redirects has been reached.
6032 </Para>
6033 </VarListEntry>
6034 <VarListEntry>
6035 <Term>/proc/sys/net/ipv4/route/redirect_number</Term>
6036 <ListItem>
6037 <Para>
6038 See /proc/sys/net/ipv4/route/redirect_load.
6039 </Para>
6040 </VarListEntry>
6041 <VarListEntry>
6042 <Term>/proc/sys/net/ipv4/route/redirect_silence</Term>
6043 <ListItem>
6044 <Para>
6045 Timeout for redirects. After this period redirects will be sent again, even if
6046 this has been stopped, because the load or number limit has been reached.
6047 </Para>
6048 </VarListEntry>
6049 </VariableList>
6050 </Para>
6052 </Sect2>
6054 </Sect1>
6056 </chapter>
6058 <chapter>
6059 <Title>Advanced &amp; less common queueing disciplines</Title>
6061 <Para>
6062 Should you find that you have needs not addressed by the queues mentioned
6063 earlier, the kernel contains some other more specialized queues mentioned here.
6064 </Para>
6066 <Sect1>
6067 <Title>bfifo/pfifo</Title>
6069 <Para>
6070 These classless queues are even simpler than pfifo_fast in that they lack
6071 the internal bands - all traffic is really equal. They have one important
6072 benefit though, they have some statistics. So even if you don't need shaping
6073 or prioritizing, you can use this qdisc to determine the backlog on your
6074 interface.
6075 </Para>
6077 <Para>
6078 pfifo has a length measured in packets, bfifo in bytes. 
6079 </Para>
6081 <Sect2>
6082 <Title>Parameters &amp; usage</Title>
6084 <Para>
6085 <VariableList>
6087 <VarListEntry>
6088 <Term>limit</Term>
6089 <ListItem>
6090 <Para>
6091 Specifies the length of the queue. Measured in bytes for bfifo, in packets
6092 for pfifo. Defaults to the interface txqueuelen (see pfifo_fast chapter)
6093 packets long or txqueuelen*mtu bytes for bfifo.
6094 </Para>
6095 </VarListEntry>
6096 </VariableList>
6097 </Para>
6099 </Sect2>
6101 </Sect1>
6103 <Sect1>
6104 <Title>Clark-Shenker-Zhang algorithm (CSZ)</Title>
6106 <Para>
6107 This is so theoretical that not even Alexey (the main CBQ author) claims to
6108 understand it. From his source:
6109 </Para>
6111 <Para>
6112 "David D. Clark, Scott Shenker and Lixia Zhang
6113 Supporting Real-Time Applications in an Integrated Services Packet
6114 Network: Architecture and Mechanism.
6115 </Para>
6117 <Para>
6118 As I understand it, the main idea is to create WFQ flows for each guaranteed
6119 service and to allocate the rest of bandwith to dummy flow-0. Flow-0
6120 comprises the predictive services and the best effort traffic; it is handled
6121 by a priority scheduler with the highest priority band allocated for
6122 predictive services, and the rest --- to the best effort packets.
6123 </Para>
6125 <Para>
6126 Note that in CSZ flows are NOT limited to their bandwidth.  It is supposed
6127 that the flow passed admission control at the edge of the QoS network and it
6128 doesn't need further shaping. Any attempt to improve the flow or to shape it
6129 to a token bucket at intermediate hops will introduce undesired delays and
6130 raise jitter.
6131 </Para>
6133 <Para>
6134 At the moment CSZ is the only scheduler that provides true guaranteed
6135 service. Another schemes (including CBQ) do not provide guaranteed delay and
6136 randomize jitter."
6137 </Para>
6139 <Para>
6140 Does not currently seem like a good canidate to use, unless you've read and
6141 understand the article mentioned.
6142 </Para>
6144 </Sect1>
6146 <Sect1>
6147 <Title>DSMARK</Title>
6149 <Para>
6150 Esteve Camps Chust &lt;marvin@grn.es&gt;
6152 This text is an extract from my thesis on "QoS Support in Linux", September 2000.
6154 </Para>
6156 <Para>
6157 Source documents:
6160 <ItemizedList>
6161 <ListItem>
6163 <Para>
6164 <ULink
6165 URL="http://ica1www.epfl.ch/~almesber"
6166 >Draft-almesberger-wajhak-diffserv-linux-01.txt</ULink
6168 </Para>
6169 </ListItem>
6170 <ListItem>
6172 <Para>
6173 Examples in iproute2 distribution.
6174 </Para>
6175 </ListItem>
6176 <ListItem>
6178 <Para>
6179 <ULink
6180 URL="http://www.qosforum.com/white-papers/qosprot_v3.pdf"
6181 >White Paper-QoS protocols and architectures</ULink
6182 > and
6183 <ULink
6184 URL="http://www.qosforum.com/docs/faq"
6185 >IP QoS Frequently Asked Questions</ULink
6186 > both by <Emphasis>Quality of Service Forum</Emphasis>.
6187 </Para>
6188 </ListItem>
6190 </ItemizedList>
6192 </Para>
6194 <Para>
6195 This chapter was written by Esteve Camps &lt;esteve@hades.udg.es&gt;.
6196 </Para>
6198 <Sect2>
6199 <Title>Introduction</Title>
6201 <Para>
6202 First of all, first of all, it would be a great idea for you to read RFCs
6203 written about this (RFC2474, RFC2475, RFC2597 and RFC2598) at <ULink
6204 URL="http://www.ietf.org/html.charters/diffserv-charter.html"
6205 >IETF DiffServ working Group web site</ULink
6206 > and <ULink
6207 URL="http://ica1www.epfl.ch/~almesber"
6208 >Werner Almesberger web site</ULink
6210 (he wrote the code to support Differentiated Services on Linux).
6211 </Para>
6213 </Sect2>
6215 <Sect2>
6216 <Title>What is Dsmark related to?</Title>
6218 <Para>
6219 Dsmark is a queueing discipline that offers the capabilities needed in
6220 Differentiated Services (also called DiffServ or, simply, DS). DiffServ is
6221 one of two actual QoS architectures (the other one is called Integrated
6222 Services) that is based on a value carried by packets in the DS field of the
6223 IP header.
6224 </Para>
6226 <Para>
6227 One of the first solutions in IP designed to offer some QoS level was
6228 the Type of Service field (TOS byte) in IP header. By changing that value,
6229 we could choose a high/low level of throughput, delay or reliability.
6230 But this didn't provide sufficient flexibility to the needs of new
6231 services (such as real-time applications, interactive applications and
6232 others). After this, new architectures appeared. One of these was DiffServ
6233 which kept TOS bits and renamed DS field.
6234 </Para>
6236 </Sect2>
6238 <Sect2>
6239 <Title>Differentiated Services guidelines</Title>
6241 <Para>
6242 Differentiated Services is group-oriented. I mean, we don't know anything
6243 about flows (this will be the Integrated Services purpose); we know about
6244 flow aggregations and we will apply different behaviours depending on which
6245 aggregation a packet belongs to.
6246 </Para>
6248 <Para>
6249 When a packet arrives to an edge node (entry node to a DiffServ domain)
6250 entering to a DiffServ Domain we'll have to policy, shape and/or mark those
6251 packets (marking refers to assigning a value to the DS field. It's just like the
6252 cows :-) ). This will be the mark/value that the internal/core nodes on our
6253 DiffServ Domain will look at to determine which behaviour or QoS level
6254 apply.
6255 </Para>
6257 <Para>
6258 As you can deduce, Differentiated Services involves a domain on which
6259 all DS rules will have to be applied. In fact you can think I
6260 will classify all the packets entering my domain. Once they enter my
6261 domain they will be subjected to the rules that my classification dictates
6262 and every traversed node will apply that QoS level.
6263 </Para>
6265 <Para>
6266 In fact, you can apply your own policies into your local domains, but some
6267 <Emphasis>Service Level Agreements</Emphasis> should be considered when connecting to
6268 other DS domains.
6269 </Para>
6271 <Para>
6272 At this point, you maybe have a lot of questions. DiffServ is more than I've
6273 explained. In fact, you can understand that I can not resume more than 3
6274 RFC's in just 50 lines :-).
6275 </Para>
6277 </Sect2>
6279 <Sect2>
6280 <Title>Working with Dsmark</Title>
6282 <Para>
6283 As the DiffServ bibliography specifies, we differentiate boundary nodes and
6284 interior nodes. These are two important points in the traffic path. Both
6285 types perform a classification when the packets arrive. Its result may be
6286 used in different places along the DS process before the packet is released
6287 to the network. It's just because of this that the diffserv code supplies an
6288 structure called sk_buff, including a new field called skb-&gt;tc_index
6289 where we'll store the result of initial classification that may be used in
6290 several points in DS treatment.
6291 </Para>
6293 <Para>
6294 The skb-&gt;tc_index value will be initially set by the DSMARK qdisc,
6295 retrieving it from the DS field in IP header of every received packet.
6296 Besides, cls_tcindex classifier will read all or part of skb-&gt;tcindex
6297 value and use it to select classes.
6298 </Para>
6300 <Para>
6301 But, first of all, take a look at DSMARK qdisc command and its parameters:
6303 <Screen>
6304 ... dsmark indices INDICES [ default_index DEFAULT_INDEX ] [ set_tc_index ]
6305 </Screen>
6307 What do these parameters mean?
6309 <ItemizedList>
6310 <ListItem>
6312 <Para>
6313 <Emphasis remap="bf">indices</Emphasis>: size of table of (mask,value) pairs. Maximum value is 2&circ;n, where n&gt;=0.
6314 </Para>
6315 </ListItem>
6316 <ListItem>
6318 <Para>
6319 <Emphasis remap="bf">Default_index</Emphasis>: the default table entry index if classifier finds no match.
6320 </Para>
6321 </ListItem>
6322 <ListItem>
6324 <Para>
6325 <Emphasis remap="bf">Set_tc_index</Emphasis>: instructs dsmark discipline to retrieve the DS field and store it onto skb-&gt;tc_index.
6326 </Para>
6327 </ListItem>
6329 </ItemizedList>
6331 Let's see the DSMARK process.
6332 </Para>
6334 </Sect2>
6336 <Sect2>
6337 <Title>How SCH_DSMARK works.</Title>
6339 <Para>
6340 This qdisc will apply the next steps:
6342 <ItemizedList>
6343 <ListItem>
6345 <Para>
6346 If we have declared set_tc_index option in qdisc command, DS field is retrieved and stored onto
6347 skb-&gt;tc_index variable.
6348 </Para>
6349 </ListItem>
6350 <ListItem>
6352 <Para>
6353 Classifier is invoked. The classifier will be executed and it will return a class ID that will be stored in
6354 skb-&gt;tc_index variable.If no filter matches are found, we consider the default_index option to be the
6355 classId to store. If neither set_tc_index nor default_index has been declared results may be
6356 impredictibles.
6357 </Para>
6358 </ListItem>
6359 <ListItem>
6361 <Para>
6362 After been sent to internal qdisc's where you can reuse the result of the filter, the classid returned by
6363 the internal qdisc is stored into skb-&gt;tc_index. We will use this value in the future to index a mask-
6364 value table. The final result to assign to the packet will be that resulting from next operation:
6366 <Screen>
6367 New_Ds_field = ( Old_DS_field &#38; mask ) | value
6368 </Screen>
6371 </Para>
6372 </ListItem>
6373 <ListItem>
6375 <Para>
6376 Thus, new value will result from "anding" ds_field and mask values and next, this result "ORed" with
6377 value parameter. See next diagram to understand all this process:
6378 </Para>
6379 </ListItem>
6381 </ItemizedList>
6384 <Screen>
6385                          skb-&gt;ihp-&gt;tos
6386 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - &gt;
6387      |                                                       |     ^
6388      | -- If you declare set_tc_index, we set DS             |     |  &lt;-----May change
6389      |    value into skb-&gt;tc_index variable                  |     |O       DS field
6390      |                                                      A|     |R
6391    +-|-+      +------+    +---+-+    Internal   +-+     +---N|-----|----+
6392    | | |      | tc   |---&gt;|   | |--&gt;  . . .  --&gt;| |     |   D|     |    |
6393    | | |-----&gt;|index |---&gt;|   | |     Qdisc     | |----&gt;|    v     |    |
6394    | | |      |filter|---&gt;| | | +---------------+ |   ----&gt;(mask,value) |
6395 --&gt;| O |      +------+    +-|-+--------------^----+  /  |  (.  ,  .)    |
6396    | | |          ^         |                |       |  |  (.  ,  .)    |
6397    | | +----------|---------|----------------|-------|--+  (.  ,  .)    |
6398    | | sch_dsmark |         |                |       |                  |
6399    +-|------------|---------|----------------|-------|------------------+
6400      |            |         | &lt;- tc_index -&gt; |       |
6401      |            |(read)   |    may change  |       |  &lt;--------------Index to the
6402      |            |         |                |       |                    (mask,value)
6403      v            |         v                v       |                    pairs table
6404 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -&gt;
6405                          skb-&gt;tc_index
6406 </Screen>
6408 </Para>
6410 <Para>
6411 How to do marking? Just change the mask and value of the class you want to remark. See next line of code:
6413 <Screen>
6414 tc class change dev eth0 classid 1:1 dsmark mask 0x3 value 0xb8
6415 </Screen>
6417 This changes the (mask,value) pair in hash table, to remark packets belonging to class 1:1.You have to "change" this values
6418 because of default values that (mask,value) gets initially (see table below).
6419 </Para>
6421 <Para>
6422 Now, we'll explain how TC_INDEX filter works and how fits into this. Besides, TCINDEX filter can be
6423 used in other configurations rather than those including DS services.
6424 </Para>
6426 </Sect2>
6428 <Sect2>
6429 <Title>TC_INDEX Filter</Title>
6431 <Para>
6432 This is the basic command to declare a TC_INDEX filter:
6434 <Screen>
6435 ... tcindex [ hash SIZE ] [ mask MASK ] [ shift SHIFT ]
6436             [ pass_on | fall_through ]
6437             [ classid CLASSID ] [ police POLICE_SPEC ]
6438 </Screen>
6440 Next, we show the example used to explain TC_INDEX operation mode. Pay attention to bolded words:
6443 tc qdisc add dev eth0 handle 1:0 root dsmark indices 64 <Emphasis remap="bf">set_tc_index</Emphasis>
6445 tc filter add dev eth0 parent 1:0 protocol ip prio 1 tcindex <Emphasis remap="bf">mask 0xfc  shift 2</Emphasis>
6447 tc qdisc add dev eth0 parent 1:0 handle 2:0 cbq bandwidth 10Mbit cell 8 avpkt 1000 mpu 64
6449 &num; EF traffic class
6451 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
6453 &num; Packet fifo qdisc for EF traffic
6455 tc qdisc add dev eth0 parent 2:1 pfifo limit 5
6457 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>
6461 (This code is not complete. It's just an extract from EFCBQ example included in iproute2 distribution).
6462 </Para>
6464 <Para>
6465 First of all, suppose we receive a packet marked as EF .  If you read RFC2598, you'll see that DSCP
6466 recommended value for EF traffic is 101110. This means that DS field will be 10111000 (remember that
6467 less signifiant bits in TOS byte are not used in DS) or 0xb8 in hexadecimal codification.
6468 </Para>
6470 <Para>
6472 <Screen>
6473               TC INDEX
6474               FILTER
6475    +---+      +-------+    +---+-+    +------+                +-+    +-------+
6476    |   |      |       |    |   | |    |FILTER|  +-+    +-+    | |    |       |
6477    |   |-----&gt;| MASK  | -&gt; |   | | -&gt; |HANDLE|-&gt;| |    | | -&gt; | | -&gt; |       |
6478    |   |  .   | =0xfc |    |   | |    |0x2E  |  | +----+ |    | |    |       |
6479    |   |  .   |       |    |   | |    +------+  +--------+    | |    |       |
6480    |   |  .   |       |    |   | |                            | |    |       |
6481 --&gt;|   |  .   | SHIFT |    |   | |                            | |    |       |--&gt;
6482    |   |  .   | =2    |    |   | +----------------------------+ |    |       |
6483    |   |      |       |    |   |       CBQ 2:0                  |    |       |
6484    |   |      +-------+    +---+--------------------------------+    |       |
6485    |   |                                                             |       |
6486    |   +-------------------------------------------------------------+       |
6487    |                          DSMARK 1:0                                     |
6488    +-------------------------------------------------------------------------+
6490 </Screen>
6492 </Para>
6494 <Para>
6495 The packet arrives, then, set with 0xb8 value at DS field. As we explained before, dsmark qdisc identified
6496 by 1:0 id in the example, retrieves DS field and store it in skb-&gt;tc_index variable.
6497 Next step in the example will correspond to the filter associated to this qdisc (second line in the example).
6498 This will perform next operations:
6500 <Screen>
6501 Value1 = skb-&#62;tc_index &#38; MASK
6502 Key = Value1 &#62;&#62; SHIFT
6503 </Screen>
6505 </Para>
6507 <Para>
6508 In the example, MASK=0xFC i SHIFT=2.
6510 <Screen>
6511 Value1 = 10111000 &#38; 11111100 = 10111000
6512 Key = 10111000 &#62;&#62; 2 = 00101110 -&#62; 0x2E in hexadecimal
6513 </Screen>
6515 </Para>
6517 <Para>
6518 The returned value will correspond to a qdisc interal filter handle (in the example, identifier 2:0). If a
6519 filter with this id exists, policing and metering conditions will be verified (in case that filter includes this)
6520 and the classid will be returned (in our example, classid 2:1) and stored in skb-&gt;tc_index variable.
6521 </Para>
6523 <Para>
6524 But if any filter with that identifier is found, the result will depend on fall_through flag declaration. If so,
6525 value key is returned as classid. If not, an error is returned and process continues with the rest filters. Be
6526 careful if you use fall_through flag; this can be done if a simple relation exists between values
6528 of skb-&gt;tc_index variable and class id's.
6529 </Para>
6531 <Para>
6532 The latest parameters to comment on are hash and pass_on. The first one
6533 relates to hash table size. Pass_on will be used to indicate that if no classid
6534 equal to the result of this filter is found, try next filter.
6535 The default action is fall_through (look at next table).
6536 </Para>
6538 <Para>
6539 Finally, let's see which possible values can be set to all this TCINDEX parameters:
6541 <Screen>
6542 TC Name                 Value           Default
6543 -----------------------------------------------------------------
6544 Hash                    1...0x10000     Implementation dependent
6545 Mask                    0...0xffff      0xffff
6546 Shift                   0...15          0
6547 Fall through / Pass_on  Flag            Fall_through
6548 Classid                 Major:minor     None
6549 Police                  .....           None
6550 </Screen>
6552 </Para>
6554 <Para>
6555 This kind of filter is very powerful. It's necessary to explore all possibilities. Besides, this filter is not only used in DiffServ configurations.
6556 You can use it as any other kind of filter.
6557 </Para>
6559 <Para>
6560 I recommend you to look at all DiffServ examples included in iproute2 distribution. I promise I will try to
6561 complement this text as soon as I can. Besides, all I have explained is the result of a lot of tests.
6562 I would thank you tell me if I'm wrong in any point.
6563 </Para>
6565 </Sect2>
6567 </Sect1>
6569 <Sect1>
6570 <Title>Ingress qdisc</Title>
6572 <Para>
6574 All qdiscs discussed so far are egress qdiscs. Each interface however can
6575 also have an ingress qdisc which is not used to send packets
6576 out to the network adaptor. Instead, it allows you to apply tc filters to
6577 packets coming in over the interface, regardless of whether they have a local
6578 destination or are to be forwarded.
6579 </Para>
6581 <Para>
6582 As the tc filters contain a full Token Bucket Filter implementation, and are
6583 also able to match on the kernel flow estimator, there is a lot of
6584 functionality available. This effectively allows you to police incoming
6585 traffic, before it even enters the IP stack.
6586 </Para>
6588 <Sect2>
6589 <Title>Parameters &amp; usage</Title>
6591 <Para>
6592 The ingress qdisc itself does not require any parameters. It differs from
6593 other qdiscs in that it does not occupy the root of a device. Attach it like
6594 this:
6596 <Screen>
6597 # tc qdisc add dev eth0 ingress
6598 </Screen>
6600 This allows you to have other, sending, qdiscs on your device besides the
6601 ingress qdisc. 
6602 </Para>
6604 <Para>
6605 For a contrived example how the ingress qdisc could be used, see the
6606 Cookbook.
6607 </Para>
6609 </Sect2>
6611 </Sect1>
6613 <Sect1>
6614 <Title>Random Early Detection (RED)</Title>
6616 <Para>
6617 This section is meant as an introduction to backbone routing, which often
6618 involves &lt;100 megabit bandwidths, which requires a different approach than
6619 your ADSL modem at home.
6620 </Para>
6622 <Para>
6623 The normal behaviour of router queues on the Internet is called tail-drop.
6624 Tail-drop works by queueing up to a certain amount, then dropping all traffic
6625 that 'spills over'. This is very unfair, and also leads to retransmit 
6626 synchronisation. When retransmit synchronisation occurs, the sudden burst
6627 of drops from a router that has reached its fill will cause a delayed burst
6628 of retransmits, which will over fill the congested router again. 
6629 </Para>
6631 <Para>
6632 In order to cope with transient congestion on links, backbone routers will
6633 often implement large queues. Unfortunately, while these queues are good for
6634 throughput, they can substantially increase latency and cause TCP
6635 connections to behave very bursty during congestion.
6636 </Para>
6638 <Para>
6639 These issues with tail-drop are becoming increasingly troublesome on the
6640 Internet because the use of network unfriendly applications is increasing.
6641 The Linux kernel offers us RED, short for Random Early Detect, also called
6642 Random Early Drop, as that is how it works.
6643 </Para>
6645 <Para>
6646 RED isn't a cure-all for this, applications which inappropriately fail to 
6647 implement exponential backoff still get an unfair share of the bandwidth,
6648 however, with RED they do not cause as much harm to the throughput and
6649 latency of other connections.
6650 </Para>
6652 <Para>
6653 RED statistically drops packets from flows before it reaches its hard
6654 limit. This causes a congested backbone link to slow more gracefully, and
6655 prevents retransmit synchronisation. This also helps TCP find its 'fair'
6656 speed faster by allowing some packets to get dropped sooner keeping queue
6657 sizes low and latency under control. The probability of a packet being
6658 dropped from a particular connection is proportional to its bandwidth usage
6659 rather than the number of packets it transmits. 
6660 </Para>
6662 <Para>
6663 RED is a good queue for backbones, where you can't afford the 
6664 complexity of per-session state tracking needed by fairness queueing.
6665 </Para>
6667 <Para>
6668 In order to use RED, you must decide on three parameters: Min, Max, and
6669 burst. Min sets the minimum queue size in bytes before dropping will begin,
6670 Max is a soft maximum that the algorithm will attempt to stay under, and
6671 burst sets the maximum number of packets that can 'burst through'.
6672 </Para>
6674 <Para>
6675 You should set the min by calculating that highest acceptable base queueing 
6676 latency you wish, and multiply it by your bandwidth. For instance, on my 
6677 64kbit/s ISDN link, I might want a base queueing latency of 200ms so I set
6678 min to 1600 bytes. Setting min too small will degrade throughput and too
6679 large will degrade latency. Setting a small min is not a replacement for
6680 reducing the MTU on a slow link to improve interactive response.
6681 </Para>
6683 <Para>
6684 You should make max at least twice min to prevent synchronisation. On slow
6685 links with small min's it might be wise to make max perhaps four or
6686 more times large then min.
6687 </Para>
6689 <Para>
6690 Burst controls how the RED algorithm responds to bursts. Burst must be set
6691 larger then min/avpkt. Experimentally, I've found (min+min+max)/(3*avpkt) to
6692 work okay.
6693 </Para>
6695 <Para>
6696 Additionally, you need to set limit and avpkt. Limit is a safety value, after
6697 there are limit bytes in the queue, RED 'turns into' tail-drop. I typical set
6698 limit to eight times max. Avpkt should be your average packet size. 1000
6699 works okay on high speed Internet links with a 1500byte MTU. 
6700 </Para>
6702 <Para>
6703 Read <ULink
6704 URL="http://www.aciri.org/floyd/papers/red/red.html"
6705 >the paper on RED queueing</ULink
6706 > by Sally Floyd and Van Jacobson for technical
6707 information.
6708 </Para>
6710 </Sect1>
6712 <Sect1>
6713 <Title>Generic Random Early Detection</Title>
6715 <Para>
6716 Not a lot is known about GRED. It looks like GRED with several internal
6717 queues, whereby the internal queue is chosen based on the Diffserv tcindex
6718 field. According to a slide found <ULink
6719 URL="http://www.davin.ottawa.on.ca/ols/img22.htm"
6720 >here</ULink
6721 >, it contains
6722 the capabilities of Cisco's 'Distributed Weighted RED', as well as Dave
6723 Clark's RIO.
6724 </Para>
6726 <Para>
6727 Each virtual queue can have its own Drop Parameters specified.
6728 </Para>
6730 <Para>
6731 FIXME: get Jamal or Werner to tell us more
6732 </Para>
6734 </Sect1>
6736 <Sect1>
6737 <Title>VC/ATM emulation</Title>
6739 <Para>
6740 This is quite a major effort by Werner Almesberger to allow you to build
6741 Virtual Circuits over TCP/IP sockets. A Virtual Circuit is a concept from
6742 ATM network theory. 
6743 </Para>
6745 <Para>
6746 For more information, see the <ULink
6747 URL="http://linux-atm.sourceforge.net/"
6748 >ATM on Linux homepage</ULink
6749 >. 
6750 </Para>
6752 </Sect1>
6754 <Sect1>
6755 <Title>Weighted Round Robin (WRR)</Title>
6757 <Para>
6758 This qdisc is not included in the standard kernels but can be downloaded from 
6759 <ULink
6760 URL="http://wipl-wrr.dkik.dk/wrr/"
6761 >&#65533;</ULink
6762 >. 
6763 Currently the qdisc is only tested with Linux 2.2 kernels but it will 
6764 probably work with 2.4/2.5 kernels too.
6765 </Para>
6767 <Para>
6768 The WRR qdisc distributes bandwidth between its classes using the weighted 
6769 round robin scheme. That is, like the CBQ qdisc it contains classes 
6770 into which arbitrary qdiscs can be plugged. All classes which have sufficient 
6771 demand will get bandwidth proportional to the weights associated with the classes.
6772 The weights can be set manually using the <Literal remap="tt">tc</Literal> program. But they
6773 can also be made automatically decreasing for classes transferring much data.
6774 </Para>
6776 <Para>
6777 The qdisc has a built-in classifier which assigns packets coming from or 
6778 sent to different machines to different classes. Either the MAC or IP and 
6779 either source or destination addresses can be used. The MAC address can only 
6780 be used when the Linux box is acting as an ethernet bridge, however. The 
6781 classes are automatically assigned to machines based on the packets seen.
6782 </Para>
6784 <Para>
6785 The qdisc can be very useful at sites such as dorms where a lot of unrelated 
6786 individuals share an Internet connection. A set of scripts setting up a 
6787 relevant behavior for such a site is a central part of the WRR distribution.
6788 </Para>
6790 </Sect1>
6792 </chapter>
6794 <chapter>
6795 <Title>Cookbook</Title>
6797 <Para>
6798 This section contains 'cookbook' entries which may help you solve problems.
6799 A cookbook is no replacement for understanding however, so try and comprehend
6800 what is going on. 
6801 </Para>
6803 <Sect1>
6804 <Title>Running multiple sites with different SLAs</Title>
6806 <Para>
6807 You can do this in several ways. Apache has some support for this with a
6808 module, but we'll show how Linux can do this for you, and do so for other
6809 services as well. These commands are stolen from a presentation by Jamal
6810 Hadi that's referenced below.
6811 </Para>
6813 <Para>
6814 Let's say we have two customers, with http, ftp and streaming audio, and we
6815 want to sell them a limited amount of bandwidth. We do so on the server itself.
6816 </Para>
6818 <Para>
6819 Customer A should have at most 2 megabits, customer B has paid for 5
6820 megabits. We separate our customers by creating virtual IP addresses on our
6821 server.
6822 </Para>
6824 <Para>
6826 <Screen>
6827 # ip address add 188.177.166.1 dev eth0
6828 # ip address add 188.177.166.2 dev eth0
6829 </Screen>
6831 </Para>
6833 <Para>
6834 It is up to you to attach the different servers to the right IP address. All
6835 popular daemons have support for this.
6836 </Para>
6838 <Para>
6839 We first attach a CBQ qdisc to eth0:
6841 <Screen>
6842 # tc qdisc add dev eth0 root handle 1: cbq bandwidth 10Mbit cell 8 avpkt 1000 \
6843   mpu 64
6844 </Screen>
6846 </Para>
6848 <Para>
6849 We then create classes for our customers:
6850 </Para>
6852 <Para>
6854 <Screen>
6855 # tc class add dev eth0 parent 1:0 classid 1:1 cbq bandwidth 10Mbit rate \
6856   2MBit avpkt 1000 prio 5 bounded isolated allot 1514 weight 1 maxburst 21
6857 # tc class add dev eth0 parent 1:0 classid 1:2 cbq bandwidth 10Mbit rate \
6858   5Mbit avpkt 1000 prio 5 bounded isolated allot 1514 weight 1 maxburst 21
6859 </Screen>
6861 </Para>
6863 <Para>
6864 Then we add filters for our two classes:
6866 <Screen>
6867 ##FIXME: Why this line, what does it do?, what is a divisor?:
6868 ##FIXME: A divisor has something to do with a hash table, and the number of
6869 ##       buckets - ahu
6870 # tc filter add dev eth0 parent 1:0 protocol ip prio 5 handle 1: u32 divisor 1
6871 # tc filter add dev eth0 parent 1:0 prio 5 u32 match ip src 188.177.166.1
6872   flowid 1:1
6873 # tc filter add dev eth0 parent 1:0 prio 5 u32 match ip src 188.177.166.2
6874   flowid 1:2
6875 </Screen>
6877 </Para>
6879 <Para>
6880 And we're done.
6881 </Para>
6883 <Para>
6884 FIXME: why no token bucket filter? is there a default pfifo_fast fallback
6885 somewhere?
6886 </Para>
6888 </Sect1>
6890 <Sect1>
6891 <Title>Protecting your host from SYN floods </Title>
6893 <Para>
6894 From Alexey's iproute documentation, adapted to netfilter and with more
6895 plausible paths. If you use this, take care to adjust the numbers to
6896 reasonable values for your system.
6897 </Para>
6899 <Para>
6900 If you want to protect an entire network, skip this script, which is best
6901 suited for a single host.
6902 </Para>
6904 <Para>
6905 It appears that you need the very latest version of the iproute2 tools to
6906 get this to work with 2.4.0.
6907 </Para>
6909 <Para>
6911 <Screen>
6912 #! /bin/sh -x
6914 # sample script on using the ingress capabilities
6915 # this script shows how one can rate limit incoming SYNs
6916 # Useful for TCP-SYN attack protection. You can use
6917 # IPchains to have more powerful additions to the SYN (eg 
6918 # in addition the subnet)
6920 #path to various utilities;
6921 #change to reflect yours.
6923 TC=/sbin/tc
6924 IP=/sbin/ip
6925 IPTABLES=/sbin/iptables
6926 INDEV=eth2
6928 # tag all incoming SYN packets through $INDEV as mark value 1
6929 ############################################################ 
6930 $iptables -A PREROUTING -i $INDEV -t mangle -p tcp --syn \
6931   -j MARK --set-mark 1
6932 ############################################################ 
6934 # install the ingress qdisc on the ingress interface
6935 ############################################################ 
6936 $TC qdisc add dev $INDEV handle ffff: ingress
6937 ############################################################ 
6941 # SYN packets are 40 bytes (320 bits) so three SYNs equals
6942 # 960 bits (approximately 1kbit); so we rate limit below
6943 # the incoming SYNs to 3/sec (not very useful really; but
6944 #serves to show the point - JHS
6945 ############################################################ 
6946 $TC filter add dev $INDEV parent ffff: protocol ip prio 50 handle 1 fw \
6947 police rate 1kbit burst 40 mtu 9k drop flowid :1
6948 ############################################################ 
6952 echo "---- qdisc parameters Ingress  ----------"
6953 $TC qdisc ls dev $INDEV
6954 echo "---- Class parameters Ingress  ----------"
6955 $TC class ls dev $INDEV
6956 echo "---- filter parameters Ingress ----------"
6957 $TC filter ls dev $INDEV parent ffff:
6959 #deleting the ingress qdisc
6960 #$TC qdisc del $INDEV ingress
6961 </Screen>
6963 </Para>
6965 </Sect1>
6967 <Sect1>
6968 <Title>Ratelimit ICMP to prevent dDoS</Title>
6970 <Para>
6971 Recently, distributed denial of service attacks have become a major nuisance
6972 on the Internet. By properly filtering and ratelimiting your network, you can
6973 both prevent becoming a casualty or the cause of these attacks.
6974 </Para>
6976 <Para>
6977 You should filter your networks so that you do not allow non-local IP source
6978 addressed packets to leave your network. This stops people from anonymously
6979 sending junk to the Internet. 
6980 </Para>
6982 <Para>
6983 Rate limiting goes much as shown earlier. To refresh your memory, our
6984 ASCIIgram again:
6985 </Para>
6987 <Para>
6989 <Screen>
6990 [The Internet] ---&#60;E3, T3, whatever&#62;--- [Linux router] --- [Office+ISP]
6991                                       eth1          eth0
6992 </Screen>
6994 </Para>
6996 <Para>
6997 We first set up the prerequisite parts:
6998 </Para>
7000 <Para>
7002 <Screen>
7003 # tc qdisc add dev eth0 root handle 10: cbq bandwidth 10Mbit avpkt 1000
7004 # tc class add dev eth0 parent 10:0 classid 10:1 cbq bandwidth 10Mbit rate \
7005   10Mbit allot 1514 prio 5 maxburst 20 avpkt 1000
7006 </Screen>
7008 </Para>
7010 <Para>
7011 If you have 100Mbit, or more, interfaces, adjust these numbers. Now you need
7012 to determine how much ICMP traffic you want to allow. You can perform
7013 measurements with tcpdump, by having it write to a file for a while, and
7014 seeing how much ICMP passes your network. Do not forget to raise the
7015 snapshot length!
7016 </Para>
7018 <Para>
7019 If measurement is impractical, you might want to choose 5&percnt; of your available
7020 bandwidth. Let's set up our class:
7022 <Screen>
7023 # tc class add dev eth0 parent 10:1 classid 10:100 cbq bandwidth 10Mbit rate \
7024   100Kbit allot 1514 weight 800Kbit prio 5 maxburst 20 avpkt 250 \
7025   bounded
7026 </Screen>
7028 </Para>
7030 <Para>
7031 This limits at 100Kbit. Now we need a filter to assign ICMP traffic to this
7032 class:
7034 <Screen>
7035 # tc filter add dev eth0 parent 10:0 protocol ip prio 100 u32 match ip
7036   protocol 1 0xFF flowid 10:100
7038 </Screen>
7040 </Para>
7042 </Sect1>
7044 <Sect1>
7045 <Title>Prioritizing interactive traffic</Title>
7047 <Para>
7048 If lots of data is coming down your link, or going up for that matter, and
7049 you are trying to do some maintenance via telnet or ssh, this may not go too
7050 well. Other packets are blocking your keystrokes. Wouldn't it be great if
7051 there were a way for your interactive packets to sneak past the bulk
7052 traffic? Linux can do this for you!
7053 </Para>
7055 <Para>
7056 As before, we need to handle traffic going both ways. Evidently, this works
7057 best if there are Linux boxes on both ends of your link, although other
7058 UNIX's are able to do this. Consult your local Solaris/BSD guru for this.
7059 </Para>
7061 <Para>
7062 The standard pfifo_fast scheduler has 3 different 'bands'. Traffic in band 0
7063 is transmitted first, after which traffic in band 1 and 2 gets considered.
7064 It is vital that our interactive traffic be in band 0!
7065 </Para>
7067 <Para>
7068 We blatantly adapt from the (soon to be obsolete) ipchains HOWTO:
7069 </Para>
7071 <Para>
7072 There are four seldom-used bits in the IP header, called the Type of Service
7073 (TOS) bits. They effect the way packets are treated; the four bits are
7074 "Minimum Delay", "Maximum Throughput", "Maximum Reliability" and "Minimum
7075 Cost". Only one of these bits is allowed to be set. Rob van Nieuwkerk, the
7076 author of the ipchains TOS-mangling code, puts it as follows:
7077 </Para>
7079 <Para>
7081 <Screen>
7082 Especially the "Minimum Delay" is important for me. I switch it on for
7083 "interactive" packets in my upstream (Linux) router. I'm
7084 behind a 33k6 modem link. Linux prioritizes packets in 3 queues. This
7085 way I get acceptable interactive performance while doing bulk
7086 downloads at the same time. 
7087 </Screen>
7089 </Para>
7091 <Para>
7092 The most common use is to set telnet &#38; ftp control connections to "Minimum
7093 Delay" and FTP data to "Maximum Throughput". This would be
7094 done as follows, on your upstream router:
7095 </Para>
7097 <Para>
7099 <Screen>
7100 # iptables -A PREROUTING -t mangle -p tcp --sport telnet \
7101   -j TOS --set-tos Minimize-Delay
7102 # iptables -A PREROUTING -t mangle -p tcp --sport ftp \
7103   -j TOS --set-tos Minimize-Delay
7104 # iptables -A PREROUTING -t mangle -p tcp --sport ftp-data \
7105   -j TOS --set-tos Maximize-Throughput
7106 </Screen>
7108 </Para>
7110 <Para>
7111 Now, this only works for data going from your telnet foreign host to your
7112 local computer. The other way around appears to be done for you, ie, telnet,
7113 ssh &#38; friends all set the TOS field on outgoing packets automatically.
7114 </Para>
7116 <Para>
7117 Should you have an application that does not do this, you can always do it 
7118 with netfilter. On your local box:
7119 </Para>
7121 <Para>
7123 <Screen>
7124 # iptables -A OUTPUT -t mangle -p tcp --dport telnet \
7125   -j TOS --set-tos Minimize-Delay
7126 # iptables -A OUTPUT -t mangle -p tcp --dport ftp \
7127   -j TOS --set-tos Minimize-Delay
7128 # iptables -A OUTPUT -t mangle -p tcp --dport ftp-data \
7129   -j TOS --set-tos Maximize-Throughput
7130 </Screen>
7132 </Para>
7134 </Sect1>
7136 <Sect1>
7137 <Title>Transparent web-caching using netfilter, iproute2, ipchains and squid</Title>
7139 <Para>
7140 <Anchor id="SQUID">
7141 This section was sent in by reader Ram Narula from Internet for Education
7142 (Thailand).
7143 </Para>
7145 <Para>
7146 The regular technique in accomplishing this in Linux
7147 is probably with use of ipchains AFTER making sure
7148 that the "outgoing" port 80(web) traffic gets routed through
7149 the server running squid.
7150 </Para>
7152 <Para>
7153 There are 3 common methods to make sure "outgoing"
7154 port 80 traffic gets routed to the server running squid
7155 and 4th one is being introduced here.
7156 </Para>
7158 <Para>
7159 <VariableList>
7161 <VarListEntry>
7162 <Term>Making the gateway router do it.</Term>
7163 <ListItem>
7164 <Para>
7165 If you can tell your gateway router to 
7166 match packets that has outgoing destination port
7167 of 80 to be sent to the IP address of squid server.
7168 </Para>
7170 <Para>
7172 </Para>
7174 <Para>
7175 This would put additional load on the router and
7176 some commercial routers might not even support this.
7177 </Para>
7178 </VarListEntry>
7179 <VarListEntry>
7180 <Term>Using a Layer 4 switch.</Term>
7181 <ListItem>
7182 <Para>
7183 Layer 4 switches can handle this without any problem.
7184 </Para>
7186 <Para>
7188 </Para>
7190 <Para>
7191 The cost for this equipment is usually very high. Typical
7192 layer 4 switch would normally cost more than
7193 a typical router+good linux server.
7194 </Para>
7195 </VarListEntry>
7196 <VarListEntry>
7197 <Term>Using cache server as network's gateway.</Term>
7198 <ListItem>
7199 <Para>
7200 You can force ALL traffic through cache server.
7201 </Para>
7203 <Para>
7205 </Para>
7207 <Para>
7208 This is quite risky because Squid does
7209 utilize lots of cpu power which might
7210 result in slower over-all network performance
7211 or the server itself might crash and no one on the
7212 network will be able to access the Internet if
7213 that occurs.
7214 </Para>
7215 </VarListEntry>
7216 <VarListEntry>
7217 <Term>Linux+NetFilter router.</Term>
7218 <ListItem>
7219 <Para>
7220 By using NetFilter another technique can be implemented
7221 which is using NetFilter for "mark"ing the packets
7222 with destination port 80 and using iproute2 to
7223 route the "mark"ed packets to the Squid server.
7224 </Para>
7225 </VarListEntry>
7226 </VariableList>
7228 <Screen>
7229 |----------------|
7230 | Implementation |
7231 |----------------|
7233  Addresses used
7234  10.0.0.1 naret (NetFilter server)
7235  10.0.0.2 silom (Squid server)
7236  10.0.0.3 donmuang (Router connected to the Internet)
7237  10.0.0.4 kaosarn (other server on network)
7238  10.0.0.5 RAS
7239  10.0.0.0/24 main network
7240  10.0.0.0/19 total network
7242 |---------------|
7243 |Network diagram|
7244 |---------------|
7246 Internet
7248 donmuang
7250 ------------hub/switch----------
7251 |        |             |       |
7252 naret   silom        kaosarn  RAS etc.
7253 </Screen>
7255 First, make all traffic pass through naret by making
7256 sure it is the default gateway except for silom.
7257 Silom's default gateway has to be donmuang (10.0.0.3) or
7258 this would create web traffic loop.
7259 </Para>
7261 <Para>
7262 (all servers on my network had 10.0.0.1 as the default gateway
7263 which was the former IP address of donmuang router so what I did
7264 was changed the IP address of donmuang to 10.0.0.3 and gave
7265 naret ip address of 10.0.0.1)
7266 </Para>
7268 <Para>
7270 <Screen>
7271 Silom
7272 -----
7273 -setup squid and ipchains 
7274 </Screen>
7276 </Para>
7278 <Para>
7279 Setup Squid server on silom, make sure it does support
7280 transparent caching/proxying, the default port is usually
7281 3128, so all traffic for port 80 has to be redirected to port
7282 3128 locally. This can be done by using ipchains with the following:
7283 </Para>
7285 <Para>
7287 <Screen>
7288 silom# ipchains -N allow1
7289 silom# ipchains -A allow1 -p TCP -s 10.0.0.0/19 -d 0/0 80 -j REDIRECT 3128
7290 silom# ipchains -I input -j allow1
7291 </Screen>
7293 </Para>
7295 <Para>
7297 </Para>
7299 <Para>
7300 Or, in netfilter lingo:
7302 <Screen>
7303 silom# iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
7304 </Screen>
7306 </Para>
7308 <Para>
7309 (note: you might have other entries as well)
7310 </Para>
7312 <Para>
7313 For more information on setting Squid server please refer
7314 to Squid faq page on <ULink
7315 URL="http://squid.nlanr.net"
7316 >http://squid.nlanr.net</ULink
7318 </Para>
7320 <Para>
7321 Make sure ip forwarding is enabled on this server and the default
7322 gateway for this server is donmuang router (NOT naret).
7323 </Para>
7325 <Para>
7327 <Screen>
7328 Naret
7329 -----
7330 -setup iptables and iproute2
7331 -disable icmp REDIRECT messages (if needed)
7332 </Screen>
7334 </Para>
7336 <Para>
7338 <OrderedList>
7339 <ListItem>
7341 <Para>
7342 "Mark" packets of destination port 80 with value 2
7344 <Screen>
7346 naret# iptables -A PREROUTING -i eth0 -t mangle -p tcp --dport 80 \
7347  -j MARK --set-mark 2
7348 </Screen>
7350 </Para>
7351 </ListItem>
7352 <ListItem>
7353 <Para>
7354 Setup iproute2 so it will route packets with "mark" 2 to silom
7356 <Screen>
7357 naret# echo 202 www.out &#62;&#62; /etc/iproute2/rt_tables
7358 naret# ip rule add fwmark 2 table www.out
7359 naret# ip route add default via 10.0.0.2 dev eth0 table www.out
7360 naret# ip route flush cache
7362 </Screen>
7365 <Para>
7366 If donmuang and naret is on the same subnet then
7367 naret should not send out icmp REDIRECT messages.
7368 In this case it is, so icmp REDIRECTs has to be
7369 disabled by:
7371 <Screen>
7372 naret# echo 0 &#62; /proc/sys/net/ipv4/conf/all/send_redirects
7373 naret# echo 0 &#62; /proc/sys/net/ipv4/conf/default/send_redirects
7374 naret# echo 0 &#62; /proc/sys/net/ipv4/conf/eth0/send_redirects
7376 </Screen>
7378 </Para>
7379 </ListItem>
7381 </OrderedList>
7383 </Para>
7385 <Para>
7386 The setup is complete, check the configuration
7387 </Para>
7389 <Para>
7391 <Screen>
7392 On naret:
7394 naret# iptables -t mangle -L
7395 Chain PREROUTING (policy ACCEPT)
7396 target     prot opt source               destination         
7397 MARK       tcp  --  anywhere             anywhere           tcp dpt:www MARK set 0x2 
7399 Chain OUTPUT (policy ACCEPT)
7400 target     prot opt source               destination         
7402 naret# ip rule ls
7403 0:      from all lookup local 
7404 32765:  from all fwmark        2 lookup www.out 
7405 32766:  from all lookup main 
7406 32767:  from all lookup default 
7408 naret# ip route list table www.out
7409 default via 203.114.224.8 dev eth0 
7411 naret# ip route   
7412 10.0.0.1 dev eth0  scope link 
7413 10.0.0.0/24 dev eth0  proto kernel  scope link  src 10.0.0.1
7414 127.0.0.0/8 dev lo  scope link 
7415 default via 10.0.0.3 dev eth0 
7417 (make sure silom belongs to one of the above lines, in this case
7418 it's the line with 10.0.0.0/24)
7420 |------|
7421 |-DONE-|
7422 |------|
7425 </Screen>
7427 </Para>
7429 <Sect2>
7430 <Title>Traffic flow diagram after implementation</Title>
7432 <Para>
7434 <Screen>
7436 |-----------------------------------------|
7437 |Traffic flow diagram after implementation|
7438 |-----------------------------------------|
7440 INTERNET
7444 -----------------donmuang router---------------------
7445 /\                                      /\         ||
7446 ||                                      ||         ||
7447 ||                                      \/         ||
7448 naret                                  silom       ||
7449 *destination port 80 traffic=========&#62;(cache)      ||
7450 /\                                      ||         ||
7451 ||                                      \/         \/
7452 \\===================================kaosarn, RAS, etc.
7454 </Screen>
7456 </Para>
7458 <Para>
7459 Note that the network is asymmetric as there is one extra hop on 
7460 general outgoing path.
7461 </Para>
7463 <Para>
7465 <Screen>
7466 Here is run down for packet traversing the network from kaosarn
7467 to and from the Internet.
7469 For web/http traffic:
7470 kaosarn http request-&#62;naret-&#62;silom-&#62;donmuang-&#62;internet
7471 http replies from Internet-&#62;donmuang-&#62;silom-&#62;kaosarn
7473 For non-web/http requests(eg. telnet):
7474 kaosarn outgoing data-&#62;naret-&#62;donmuang-&#62;internet
7475 incoming data from Internet-&#62;donmuang-&#62;kaosarn
7476 </Screen>
7478 </Para>
7480 </Sect2>
7482 </Sect1>
7484 <Sect1>
7485 <Title>Circumventing Path MTU Discovery issues with per route MTU settings</Title>
7487 <Para>
7488 For sending bulk data, the Internet generally works better when using larger
7489 packets. Each packet implies a routing decision, when sending a 1 megabyte
7490 file, this can either mean around 700 packets when using packets that are as
7491 large as possible, or 4000 if using the smallest default.
7492 </Para>
7494 <Para>
7495 However, not all parts of the Internet support full 1460 bytes of payload
7496 per packet. It is therefore necessary to try and find the largest packet
7497 that will 'fit', in order to optimize a connection.
7498 </Para>
7500 <Para>
7501 This process is called 'Path MTU Discovery', where MTU stands for 'Maximum
7502 Transfer Unit.' 
7503 </Para>
7505 <Para>
7506 When a router encounters a packet that's too big too send in one piece, AND
7507 it has been flagged with the "Don't Fragment" bit, it returns an ICMP
7508 message stating that it was forced to drop a packet because of this. The
7509 sending host acts on this hint by sending smaller packets, and by iterating
7510 it can find the optimum packet size for a connection over a certain path.
7511 </Para>
7513 <Para>
7514 This used to work well until the Internet was discovered by hooligans who do
7515 their best to disrupt communications. This in turn lead administrators to
7516 either block or shape ICMP traffic in a misguided attempt to improve
7517 security or robustness of their Internet service.
7518 </Para>
7520 <Para>
7521 What has happened now is that Path MTU Discovery is working less and less
7522 well and fails for certain routes, which leads to strange TCP/IP sessions
7523 which die after a while.
7524 </Para>
7526 <Para>
7527 Although I have no proof for this, two sites who I used to have this problem
7528 with both run Alteon Acedirectors before the affected systems - perhaps
7529 somebody more knowledgeable can provide clues as to why this happens.
7530 </Para>
7532 <Sect2>
7533 <Title>Solution</Title>
7535 <Para>
7536 When you encounter sites that suffer from this problem, you can disable Path
7537 MTU discovery by setting it manually. Koos van den Hout, slightly edited,
7538 writes:
7539 </Para>
7541 <Para>
7543 <Screen>
7544 <msgtext>
7545 <Para>
7546 The following problem: I set the mtu/mru of my leased line running ppp to
7547 296 because it's only 33k6 and I cannot influence the queueing on the
7548 other side. At 296, the response to a keypress is within a reasonable
7549 timeframe.
7550 </Para>
7552 <Para>
7553 And, on my side I have a masqrouter running (of course) Linux.
7554 </Para>
7556 <Para>
7557 Recently I split 'server' and 'router' so most applications are run on a
7558 different machine than the routing happens on.
7559 </Para>
7561 <Para>
7562 I then had trouble logging into irc. Big panic! Some digging did find
7563 out that I got connected to irc, even showed up as 'connected' on irc
7564 but I did not receive the motd from irc. I checked what could be wrong
7565 and noted that I already had some previous trouble reaching certain
7566 websites related to the MTU, since I had no trouble reaching them when
7567 the MTU was 1500, the problem just showed when the MTU was set to 296.
7568 Since irc servers block about every kind of traffic not needed for their
7569 immediate operation, they also block icmp. 
7570 </Para>
7572 <Para>
7573 I managed to convince the operators of a webserver that this was the cause
7574 of a problem, but the irc server operators were not going to fix this.
7575 </Para>
7577 <Para>
7578 So, I had to make sure outgoing masqueraded traffic started with the lower
7579 mtu of the outside link. But I want local ethernet traffic to have the
7580 normal mtu (for things like nfs traffic).
7581 </Para>
7583 <Para>
7584 Solution:
7586 <Screen>
7587 ip route add default via 10.0.0.1 mtu 296
7588 </Screen>
7590 </Para>
7592 <Para>
7593 (10.0.0.1 being the default gateway, the inside address of the
7594 masquerading router)
7595 </Para>
7596 </msgtext>
7597 </Screen>
7599 </Para>
7601 <Para>
7602 In general, it is possible to override PMTU Discovery by setting specific
7603 routes. For example, if only a certain subnet is giving problems, this
7604 should help:
7605 </Para>
7607 <Para>
7609 <Screen>
7610 ip route add 195.96.96.0/24 via 10.0.0.1 mtu 1000
7611 </Screen>
7613 </Para>
7615 </Sect2>
7617 </Sect1>
7619 <Sect1>
7620 <Title>Circumventing Path MTU Discovery issues with MSS Clamping (for ADSL,
7621 cable, PPPoE &amp; PPtP users)</Title>
7623 <Para>
7624 As explained above, Path MTU Discovery doesn't work as well as it should
7625 anymore. If you know for a fact that a hop somewhere in your network has a
7626 limited (&lt;1500) MTU, you cannot rely on PMTU Discovery finding this out.
7627 </Para>
7629 <Para>
7630 Besides MTU, there is yet another way to set the maximum packet size, the so
7631 called Maximum Segment Size. This is a field in the TCP Options part of a
7632 SYN packet.
7633 </Para>
7635 <Para>
7636 Recent Linux kernels, and a few pppoe drivers (notably, the excellent
7637 Roaring Penguin one), feature the possibility to 'clamp the MSS'. 
7638 </Para>
7640 <Para>
7641 The good thing about this is that by setting the MSS value, you are telling
7642 the remote side unequivocally 'do not ever try to send me packets bigger
7643 than this value'. No ICMP traffic is needed to get this to work.
7644 </Para>
7646 <Para>
7647 The bad thing is that it's an obvious hack - it breaks 'end to end' by
7648 modifying packets. Having said that, we use this trick in many places and it
7649 works like a charm.
7650 </Para>
7652 <Para>
7653 In order for this to work you need at least iptables-1.2.1a and Linux 2.4.3
7654 or higher. The basic commandline is:
7656 <Screen>
7657 # iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS  --clamp-mss-to-pmtu
7658 </Screen>
7660 </Para>
7662 <Para>
7663 This calculates the proper MSS for your link. If you are feeling brave, or
7664 think that you know best, you can also do something like this:
7665 </Para>
7667 <Para>
7669 <Screen>
7670 # iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 128
7671 </Screen>
7673 </Para>
7675 <Para>
7676 This sets the MSS of passing SYN packets to 128. Use this if you have VoIP
7677 with tiny packets, and huge http packets which are causing chopping in your
7678 voice calls.
7679 </Para>
7681 </Sect1>
7683 <Sect1>
7684 <Title>The Ultimate Traffic Conditioner: Low Latency, Fast Up &amp; Downloads</Title>
7686 <Para>
7687 Note: This script has recently been upgraded and previously only worked for
7688 Linux clients in your network! So you might want to update if you have
7689 Windows machines or Macs in your network and noticed that they were not able
7690 to download faster while others were uploading.
7691 </Para>
7693 <Para>
7694 I attempted to create the holy grail:
7695 <VariableList>
7697 <VarListEntry>
7698 <Term>Maintain low latency for interfactive traffic at all times</Term>
7699 <ListItem>
7700 <Para>
7701 This means that downloading or uploading files should not disturb SSH or
7702 even telnet. These are the most important things, even 200ms latency is
7703 sluggish to work over.
7704 </Para>
7705 </VarListEntry>
7706 <VarListEntry>
7707 <Term>Allow 'surfing' at reasonable speeds while up or downloading</Term>
7708 <ListItem>
7709 <Para>
7710 Even though http is 'bulk' traffic, other traffic should not drown it out 
7711 too much.
7712 </Para>
7713 </VarListEntry>
7714 <VarListEntry>
7715 <Term>Make sure uploads don't harm downloads, and the other way around</Term>
7716 <ListItem>
7717 <Para>
7718 This is a much observed phenomenon where upstream traffic simply destroys
7719 download speed.
7720 </Para>
7721 </VarListEntry>
7722 </VariableList>
7723 It turns out that all this is possible, at the cost of a tiny bit of
7724 bandwidth. The reason that uploads, downloads and ssh hurt eachother is the
7725 presence of large queues in many domestic access devices like cable or DSL
7726 modems.
7727 </Para>
7729 <Para>
7730 The next section explains in depth what causes the delays, and how we can
7731 fix them. You can safely skip it and head straight for the script if you
7732 don't care how the magic is performed.
7733 </Para>
7735 <Sect2>
7736 <Title>Why it doesn't work well by default</Title>
7738 <Para>
7739 ISPs know that they are benchmarked solely on how fast people can download.
7740 Besides available bandwidth, download speed is influenced heavily by packet
7741 loss, which seriously hampers TCP/IP performance. Large queues can help
7742 prevent packetloss, and speed up downloads. So ISPs configure large queues.
7743 </Para>
7745 <Para>
7746 These large queues however damage interactivity. A keystroke must first
7747 travel the upstream queue, which may be seconds (!) long and go to your
7748 remote host. It is then displayed, which leads to a packet coming back, which
7749 must then traverse the downstream queue, located at your ISP, before it
7750 appears on your screen.
7751 </Para>
7753 <Para>
7754 This HOWTO teaches you how to mangle and process the queue in many ways, but
7755 sadly, not all queues are accessible to us. The queue over at the ISP is
7756 completely off-limits, whereas the upstream queue probably lives inside your
7757 cable modem or DSL device. You may or may not be able to configure it. Most
7758 probably not.
7759 </Para>
7761 <Para>
7762 So, what next? As we can't control either of those queues, they must be
7763 eliminated, and moved to your Linux router. Luckily this is possible.
7764 </Para>
7766 <Para>
7767 <VariableList>
7769 <VarListEntry>
7770 <Term>Limit upload speed</Term>
7771 <ListItem>
7772 <Para>
7773 By limiting our upload speed to slightly less than the truly available rate,
7774 no queues are built up in our modem. The queue is now moved to Linux.
7775 </Para>
7776 </VarListEntry>
7777 <VarListEntry>
7778 <Term>Limit download speed</Term>
7779 <ListItem>
7780 <Para>
7781 This is slightly trickier as we can't really influence how fast the internet
7782 ships us data. We can however drop packets that are coming in too fast,
7783 which causes TCP/IP to slow down to just the rate we want. Because we don't 
7784 want to drop traffic unnecessarily, we configure a 'burst' size we allow at
7785 higher speed.
7786 </Para>
7787 </VarListEntry>
7788 </VariableList>
7789 </Para>
7791 <Para>
7792 Now, once we have done this, we have eliminated the downstream queue totally
7793 (except for short bursts), and gain the ability to manage the upstream queue
7794 with all the power Linux offers.
7795 </Para>
7797 <Para>
7798 What remains to be done is to make sure interactive traffic jumps to the
7799 front of the upstream queue. To make sure that uploads don't hurt downloads,
7800 we also move ACK packets to the front of the queue. This is what normally
7801 causes the huge slowdown observed when generating bulk traffic both ways.
7802 The ACKnowledgements for downstream traffic must compete with upstream
7803 traffic, and get delayed in the process.
7804 </Para>
7806 <Para>
7807 If we do all this we get the following measurements using an excellent ADSL
7808 connection from xs4all in the Netherlands:
7809 </Para>
7811 <Para>
7813 <Screen>
7814 Baseline latency:
7815 round-trip min/avg/max = 14.4/17.1/21.7 ms
7817 Without traffic conditioner, while downloading:
7818 round-trip min/avg/max = 560.9/573.6/586.4 ms
7820 Without traffic conditioner, while uploading:
7821 round-trip min/avg/max = 2041.4/2332.1/2427.6 ms
7823 With conditioner, during 220kbit/s upload:
7824 round-trip min/avg/max = 15.7/51.8/79.9 ms
7826 With conditioner, during 850kbit/s download:
7827 round-trip min/avg/max = 20.4/46.9/74.0 ms
7829 When uploading, downloads proceed at ~80% of the available speed. Uploads
7830 at around 90%. Latency then jumps to 850 ms, still figuring out why.
7831 </Screen>
7833 </Para>
7835 <Para>
7836 What you can expect from this script depends a lot on your actual uplink
7837 speed. When uploading at full speed, there will always be a single packet
7838 ahead of your keystroke. That is the lower limit to the latency you can
7839 achieve - divide your MTU by your upstream speed to calculate. Typical
7840 values will be somewhat higher than that. Lower your MTU for better effects!
7841 </Para>
7843 <Para>
7844 Next, two versions of this script, one with Devik's excellent HTB, the other
7845 with CBQ which is in each Linux kernel, unlike HTB. Both are tested and work
7846 well.
7847 </Para>
7849 </Sect2>
7851 <Sect2>
7852 <Title>The actual script (CBQ)</Title>
7854 <Para>
7855 Works on all kernels. Within the CBQ
7856 qdisc we place two Stochastic Fairness Queues that make sure that multiple
7857 bulk streams don't drown each other out.
7858 </Para>
7860 <Para>
7861 Downstream traffic is policed using a tc filter containing a Token Bucket
7862 Filter.
7863 </Para>
7865 <Para>
7866 You might improve on this script by adding 'bounded' to the line that starts
7867 with 'tc class add .. classid 1:20'. If you lowered your MTU, also lower the
7868 allot &amp; avpkt numbers!
7869 </Para>
7871 <Para>
7873 <Screen>
7874 #!/bin/bash 
7876 # The Ultimate Setup For Your Internet Connection At Home
7879 # Set the following values to somewhat less than your actual download
7880 # and uplink speed. In kilobits
7881 DOWNLINK=800
7882 UPLINK=220
7883 DEV=ppp0
7885 # clean existing down- and uplink qdiscs, hide errors
7886 tc qdisc del dev $DEV root    2&#62; /dev/null &#62; /dev/null
7887 tc qdisc del dev $DEV ingress 2&#62; /dev/null &#62; /dev/null
7889 ###### uplink
7891 # install root CBQ
7893 tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 10mbit 
7895 # shape everything at $UPLINK speed - this prevents huge queues in your
7896 # DSL modem which destroy latency:
7897 # main class
7899 tc class add dev $DEV parent 1: classid 1:1 cbq rate ${UPLINK}kbit \
7900 allot 1500 prio 5 bounded isolated 
7902 # high prio class 1:10:
7904 tc class add dev $DEV parent 1:1 classid 1:10 cbq rate ${UPLINK}kbit \
7905    allot 1600 prio 1 avpkt 1000
7907 # bulk and default class 1:20 - gets slightly less traffic, 
7908 #  and a lower priority:
7910 tc class add dev $DEV parent 1:1 classid 1:20 cbq rate $[9*$UPLINK/10]kbit \
7911    allot 1600 prio 2 avpkt 1000
7913 # both get Stochastic Fairness:
7914 tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
7915 tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
7917 # start filters
7918 # TOS Minimum Delay (ssh, NOT scp) in 1:10:
7919 tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
7920       match ip tos 0x10 0xff  flowid 1:10
7922 # ICMP (ip protocol 1) in the interactive class 1:10 so we 
7923 # can do measurements &#38; impress our friends:
7924 tc filter add dev $DEV parent 1:0 protocol ip prio 11 u32 \
7925         match ip protocol 1 0xff flowid 1:10
7927 # To speed up downloads while an upload is going on, put ACK packets in
7928 # the interactive class:
7930 tc filter add dev $DEV parent 1: protocol ip prio 12 u32 \
7931    match ip protocol 6 0xff \
7932    match u8 0x05 0x0f at 0 \
7933    match u16 0x0000 0xffc0 at 2 \
7934    match u8 0x10 0xff at 33 \
7935    flowid 1:10
7937 # rest is 'non-interactive' ie 'bulk' and ends up in 1:20
7939 tc filter add dev $DEV parent 1: protocol ip prio 13 u32 \
7940    match ip dst 0.0.0.0/0 flowid 1:20
7942 ########## downlink #############
7943 # slow downloads down to somewhat less than the real speed  to prevent 
7944 # queuing at our ISP. Tune to see how high you can set it.
7945 # ISPs tend to have *huge* queues to make sure big downloads are fast
7947 # attach ingress policer:
7949 tc qdisc add dev $DEV handle ffff: ingress
7951 # filter *everything* to it (0.0.0.0/0), drop everything that's
7952 # coming in too fast:
7954 tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
7955    0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1
7956 </Screen>
7958 If you want this script to be run by ppp on connect, copy it to
7959 /etc/ppp/ip-up.d.
7960 </Para>
7962 <Para>
7963 If the last two lines give an error, update your tc tool to a newer version!
7964 </Para>
7966 </Sect2>
7968 <Sect2>
7969 <Title>The actual script (HTB)</Title>
7971 <Para>
7972 The following script achieves all goals using the wonderful HTB queue, see
7973 the relevant chapter. Well worth patching your kernel for! 
7975 <Screen>
7976 #!/bin/bash
7978 # The Ultimate Setup For Your Internet Connection At Home
7981 # Set the following values to somewhat less than your actual download
7982 # and uplink speed. In kilobits
7983 DOWNLINK=800
7984 UPLINK=220
7985 DEV=ppp0
7987 # clean existing down- and uplink qdiscs, hide errors
7988 tc qdisc del dev $DEV root    2&#62; /dev/null &#62; /dev/null
7989 tc qdisc del dev $DEV ingress 2&#62; /dev/null &#62; /dev/null
7991 ###### uplink
7993 # install root HTB, point default traffic to 1:20:
7995 tc qdisc add dev $DEV root handle 1: htb default 20
7997 # shape everything at $UPLINK speed - this prevents huge queues in your
7998 # DSL modem which destroy latency:
8000 tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit burst 6k
8002 # high prio class 1:10:
8004 tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit \
8005    burst 6k prio 1
8007 # bulk &#38; default class 1:20 - gets slightly less traffic, 
8008 # and a lower priority:
8010 tc class add dev $DEV parent 1:1 classid 1:20 htb rate $[9*$UPLINK/10]kbit \
8011    burst 6k prio 2
8013 # both get Stochastic Fairness:
8014 tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
8015 tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
8017 # TOS Minimum Delay (ssh, NOT scp) in 1:10:
8018 tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
8019       match ip tos 0x10 0xff  flowid 1:10
8021 # ICMP (ip protocol 1) in the interactive class 1:10 so we 
8022 # can do measurements &#38; impress our friends:
8023 tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
8024         match ip protocol 1 0xff flowid 1:10
8026 # To speed up downloads while an upload is going on, put ACK packets in
8027 # the interactive class:
8029 tc filter add dev $DEV parent 1: protocol ip prio 10 u32 \
8030    match ip protocol 6 0xff \
8031    match u8 0x05 0x0f at 0 \
8032    match u16 0x0000 0xffc0 at 2 \
8033    match u8 0x10 0xff at 33 \
8034    flowid 1:10
8036 # rest is 'non-interactive' ie 'bulk' and ends up in 1:20
8039 ########## downlink #############
8040 # slow downloads down to somewhat less than the real speed  to prevent 
8041 # queuing at our ISP. Tune to see how high you can set it.
8042 # ISPs tend to have *huge* queues to make sure big downloads are fast
8044 # attach ingress policer:
8046 tc qdisc add dev $DEV handle ffff: ingress
8048 # filter *everything* to it (0.0.0.0/0), drop everything that's
8049 # coming in too fast:
8051 tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
8052    0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1
8053 </Screen>
8055 </Para>
8057 <Para>
8058 If you want this script to be run by ppp on connect, copy it to
8059 /etc/ppp/ip-up.d.
8060 </Para>
8062 <Para>
8063 If the last two lines give an error, update your tc tool to a newer version!
8064 </Para>
8066 </Sect2>
8068 </Sect1>
8070 </chapter>
8072 <chapter>
8073 <Title>Building bridges, and pseudo-bridges with Proxy ARP</Title>
8075 <Para>
8076 Bridges are devices which can be installed in a network without any
8077 reconfiguration. A network switch is basically a many-port bridge. A bridge
8078 is often a 2-port switch. Linux does however support multiple interfaces in
8079 a bridge, making it a true switch.
8080 </Para>
8082 <Para>
8083 Bridges are often deployed when confronted with a broken network that needs
8084 to be fixed without any alterations. Because the bridge is a layer-2 device,
8085 one layer below IP, routers and servers are not aware of its existence.
8086 This means that you can transparently block or modify certain packets, or do
8087 shaping.
8088 </Para>
8090 <Para>
8091 Another good thing is that a bridge can often be replaced by a cross cable
8092 or a hub, should it break down.
8093 </Para>
8095 <Para>
8096 The bad news is that a bridge can cause great confusion unless it is very
8097 well documented. It does not appear in traceroutes, but somehow packets
8098 disappear or get changed from point A to point B ('this network is
8099 HAUNTED!'). You should also wonder if an organization that 'does not want to
8100 change anything' is doing the right thing.
8101 </Para>
8103 <Para>
8104 The Linux 2.4/2.5 bridge is documented on
8105 </Para>
8107 <Para>
8108 <ULink
8109 URL=" http://bridge.sourceforge.net/"
8110 >this page</ULink
8112 </Para>
8114 <Sect1>
8115 <Title>State of bridging and iptables</Title>
8117 <Para>
8118 As of Linux 2.4.14, bridging and iptables do not 'see' each other without
8119 help. If you bridge packets from eth0 to eth1, they do not 'pass' by
8120 iptables. This means that you cannot do filtering, or NAT or mangling or
8121 whatever.
8122 </Para>
8124 <Para>
8125 There are several projects going on to fix this, the truly right one is by
8126 the author of the Linux 2.4 bridging code, Lennert Buytenhek. He recently
8127 informed us that as of bridge-nf 0.0.2 (see the url above), the code is
8128 stable and usable in production environments.  He is now asking the kernel
8129 people if and how the patch can be merged, stay tuned!
8130 </Para>
8132 </Sect1>
8134 <Sect1>
8135 <Title>Bridging and shaping</Title>
8137 <Para>
8138 This does work as advertised. Be sure to figure out which side each
8139 interface is on, otherwise you might be shaping outbound traffic in your
8140 internal interface, which won't work. Use tcpdump if needed.
8141 </Para>
8143 </Sect1>
8145 <Sect1>
8146 <Title>Pseudo-bridges with Proxy-ARP</Title>
8148 <Para>
8149 If you just want to implement a Pseudo-bridge, skip down a few sections 
8150 to 'Implementing it', but it is wise to read a bit about how it works in
8151 practice.
8152 </Para>
8154 <Para>
8155 A Pseudo-bridge works a bit differently. By default, a bridge passes packets
8156 unaltered from one interface to the other. It only looks at the hardware
8157 address of packets to determine what goes where. This in turn means that you
8158 can bridge traffic that Linux does not understand, as long as it has an
8159 hardware address it does.
8160 </Para>
8162 <Para>
8163 A 'Pseudo-bridge' works differently and looks more like a hidden router than
8164 a bridge, but like a bridge, it has little impact on network design.
8165 </Para>
8167 <Para>
8168 An advantage of the fact that it is not a brige lies in the fact that
8169 packets really pass through the kernel, and can be filtered, changed,
8170 redirected or rerouted. 
8171 </Para>
8173 <Para>
8174 A real bridge can also be made to perform these feats, but it needs special
8175 code, like the Ethernet Frame Diverter, or the above mentioned patch.
8176 </Para>
8178 <Para>
8179 Another advantage of a pseudo-bridge is that it does not pass packets it
8180 does not understand - thus cleaning your network of a lot of cruft. In cases
8181 where you need this cruft (like SAP packets, or Netbeui), use a real bridge.
8182 </Para>
8184 <Sect2>
8185 <Title>ARP &amp; Proxy-ARP</Title>
8187 <Para>
8188 When a host wants to talk to another host on the same physical network
8189 segment, it sends out an Address Resolution Protocol packet, which, somewhat
8190 simplified, reads like this 'who has 10.0.0.1, tell 10.0.0.7'. In response
8191 to this, 10.0.0.1 replies with a short 'here' packet.
8192 </Para>
8194 <Para>
8195 10.0.0.7 then sends packets to the hardware address mentioned in the 'here' 
8196 packet. It caches this hardware address for a relatively long time, and
8197 after the cache expires, it reasks the question.
8198 </Para>
8200 <Para>
8201 When building a Pseudo-bridge, we instruct the bridge to reply to these ARP
8202 packets, which causes the hosts in the network to send its packets to the
8203 bridge. The brige then processes these packets, and sends them to the
8204 relevant interface.
8205 </Para>
8207 <Para>
8208 So, in short, whenever a host on one side of the bridge asks for the
8209 hardware address of a host on the other, the bridge replies with a packet
8210 that says 'hand it to me'.
8211 </Para>
8213 <Para>
8214 This way, all data traffic gets transmitted to the right place, and always
8215 passes through the bridge.
8216 </Para>
8218 </Sect2>
8220 <Sect2>
8221 <Title>Implementing it</Title>
8223 <Para>
8224 In the bad old days, it used to be possible to instruct the Linux Kernel to
8225 perform 'proxy-ARP' for just any subnet. So, to configure a pseudo-bridge,
8226 you would have to specify both the proper routes to both sides of the bridge
8227 AND create matching proxy-ARP rules. This is bad in that it requires a lot
8228 of typing, but also because it easily allows you to make mistakes which make
8229 your bridge respond to ARP queries for networks it does not know how to
8230 route.
8231 </Para>
8233 <Para>
8234 With Linux 2.4/2.5 (and possibly 2.2), this possibility has been withdrawn and
8235 has been replaced by a flag in the /proc directory, called 'proxy_arp'. The
8236 procedure for building a pseudo-bridge is then:
8237 </Para>
8239 <Para>
8241 <OrderedList>
8242 <ListItem>
8244 <Para>
8245 Assign an IP address to both interfaces, the 'left' and the 'right'
8247 </Para>
8248 </ListItem>
8249 <ListItem>
8251 <Para>
8252 Create routes so your machine knows which hosts reside on the left,
8253 and which on the right
8254 </Para>
8255 </ListItem>
8256 <ListItem>
8258 <Para>
8259 Turn on proxy-ARP on both interfaces, echo 1 &#62;
8260 /proc/sys/net/ipv4/conf/ethL/proxy_arp, echo 1 &#62;
8261 /proc/sys/net/ipv4/conf/ethR/proxy_arp, where L and R stand for the numbers
8262 of your interfaces on the left and on the right side
8263 </Para>
8264 </ListItem>
8266 </OrderedList>
8268 </Para>
8270 <Para>
8271 Also, do not forget to turn on the ip_forwarding flag! When converting from
8272 a true bridge, you may find that this flag was turned off as it is not
8273 needed when bridging.
8274 </Para>
8276 <Para>
8277 Another thing you might note when converting is that you need to clear the
8278 arp cache of computers in the network - the arp cache might contain old
8279 pre-bridge hardware addresses which are no longer correct.
8280 </Para>
8282 <Para>
8283 On a Cisco, this is done using the command 'clear arp-cache', under
8284 Linux, use 'arp -d ip.address'. You can also wait for the cache to expire
8285 manually, which can take rather long.
8286 </Para>
8288 <Para>
8289 You may also discover that your network was misconfigured if you are/were of
8290 the habit of specifying routes without netmasks. To explain, some versions
8291 of route may have guessed your netmask right in the past, or guessed wrong
8292 without you noticing. When doing surgical routing like described above, it
8293 is *vital* that you check your netmasks! 
8294 </Para>
8296 </Sect2>
8298 </Sect1>
8300 </chapter>
8302 <chapter>
8303 <Title>Dynamic routing - OSPF and BGP</Title>
8305 <Para>
8306 Once your network starts to get really big, or you start to consider 'the
8307 internet' as your network, you need tools which dynamically route your data.
8308 Sites are often connected to each other with multiple links, and more are
8309 popping up all the time. 
8310 </Para>
8312 <Para>
8313 The Internet has mostly standardised on OSPF and BGP4 (rfc1771). Linux
8314 supports both, by way of <Literal remap="tt">gated</Literal> and <Literal remap="tt">zebra</Literal>
8315 </Para>
8317 <Para>
8318 While currently not within the scope of this document, we would like to
8319 point you to the definitive works:
8320 </Para>
8322 <Para>
8323 Overview:
8324 </Para>
8326 <Para>
8327 Cisco Systems
8328 <ULink
8329 URL="http://www.cisco.com/univercd/cc/td/doc/cisintwk/idg4/nd2003.htm"
8330 >Designing large-scale IP Internetworks</ULink
8332 </Para>
8334 <Para>
8335 For OSPF:
8336 </Para>
8338 <Para>
8339 Moy, John T.
8340 "OSPF.  The anatomy of an Internet routing protocol"
8341 Addison Wesley. Reading, MA. 1998.
8342 </Para>
8344 <Para>
8345 Halabi has also written a good guide to OSPF routing design, but this
8346 appears to have been dropped from the Cisco web site.
8347 </Para>
8349 <Para>
8350 For BGP:
8351 </Para>
8353 <Para>
8354 Halabi, Bassam
8355 "Internet routing architectures"
8356 Cisco Press (New Riders Publishing). Indianapolis, IN. 1997.
8357 </Para>
8359 <Para>
8360 also
8361 </Para>
8363 <Para>
8364 Cisco Systems
8365 </Para>
8367 <Para>
8368 <ULink
8369 URL="http://www.cisco.com/univercd/cc/td/doc/cisintwk/ics/icsbgp4.htm"
8370 >Using the Border Gateway Protocol for interdomain routing</ULink
8372 </Para>
8374 <Para>
8375 Although the examples are Cisco-specific, they are remarkably similar
8376 to the configuration language in Zebra :-)
8377 </Para>
8379 </chapter>
8381 <chapter>
8382 <Title>Other possibilities </Title>
8384 <Para>
8385 This chapter is a list of projects having to do with advanced Linux routing
8386 &amp; traffic shaping. Some of these links may deserve chapters of their
8387 own, some are documented very well of themselves, and don't need more HOWTO.
8388 </Para>
8390 <Para>
8391 <VariableList>
8393 <VarListEntry>
8394 <Term>802.1Q VLAN Implementation for Linux <ULink
8395 URL="http://scry.wanfear.com/~greear/vlan.html"
8396 >(site)</ULink
8397 ></Term>
8398 <ListItem>
8399 <Para>
8400 VLANs are a very cool way to segregate your
8401 networks in a more virtual than physical way. Good information on VLANs can
8402 be found <ULink
8403 URL="ftp://ftp.netlab.ohio-state.edu/pub/jain/courses/cis788-97/virtual_lans/index.htm"
8404 >here</ULink
8405 >. With this implementation, you can have your Linux box talk
8406 VLANs with machines like Cisco Catalyst, 3Com: &lcub;Corebuilder, Netbuilder II,
8407 SuperStack II switch 630&rcub;, Extreme Ntwks Summit 48, Foundry: &lcub;ServerIronXL,
8408 FastIron&rcub;.
8409 </Para>
8411 <Para>
8412 A great HOWTO about VLANs can be found <ULink
8413 URL="http://scry.wanfear.com/~greear/vlan/cisco_howto.html"
8414 >here</ULink
8416 </Para>
8418 <Para>
8419 Update: has been included in the kernel as of 2.4.14 (perhaps 13).
8420 </Para>
8421 </VarListEntry>
8422 <VarListEntry>
8423 <Term>Alternate 802.1Q VLAN Implementation for Linux <ULink
8424 URL="http://vlan.sourceforge.net "
8425 >(site)</ULink
8426 ></Term>
8427 <ListItem>
8428 <Para>
8429 Alternative VLAN implementation for linux. This project was started out of
8430 disagreement with the 'established' VLAN project's architecture and coding
8431 style, resulting in a cleaner overall design.
8432 </Para>
8433 </VarListEntry>
8434 <VarListEntry>
8435 <Term>Linux Virtual Server <ULink
8436 URL="http://www.LinuxVirtualServer.org/"
8437 >(site)</ULink
8438 ></Term>
8439 <ListItem>
8440 <Para>
8441 These people are brilliant. The Linux Virtual Server is a highly scalable and
8442 highly available server built on a cluster of real servers, with the load
8443 balancer running on the Linux operating system. The architecture of the
8444 cluster is transparent to end users. End users only see a single virtual
8445 server.
8446 </Para>
8448 <Para>
8449 In short whatever you need to loadbalance, at whatever level of traffic, LVS
8450 will have a way of doing it. Some of their techniques are positively evil!
8451 For example, they let several machines have the same IP address on a
8452 segment, but turn off ARP on them. Only the LVS machine does ARP - it then
8453 decides which of the backend hosts should handle an incoming packet, and
8454 sends it directly to the right MAC address of the backend server. Outgoing
8455 traffic will flow directly to the router, and not via the LVS machine, which
8456 does therefor not need to see your 5Gbit/s of content flowing to the world,
8457 and cannot be a bottleneck.
8458 </Para>
8460 <Para>
8461 The LVS is implemented as a kernel patch in Linux 2.0 and 2.2, but as a
8462 Netfilter module in 2.4/2.5, so it does not need kernel patches! Their 2.4
8463 support is still in early development, so beat on it and give feedback or
8464 send patches.
8465 </Para>
8466 </VarListEntry>
8467 <VarListEntry>
8468 <Term>CBQ.init <ULink
8469 URL="ftp://ftp.equinox.gu.net/pub/linux/cbq/"
8470 >(site)</ULink
8471 ></Term>
8472 <ListItem>
8473 <Para>
8474 Configuring CBQ can be a bit daunting, especially if all you want to do is
8475 shape some computers behind a router. CBQ.init can help you configure Linux
8476 with a simplified syntax.
8477 </Para>
8479 <Para>
8480 For example, if you want all computers in your 192.168.1.0/24 subnet
8481 (on 10mbit eth1) to be limited to 28kbit/s download speed, put
8482 this in the CBQ.init configuration file:
8483 </Para>
8485 <Para>
8487 <Screen>
8488 DEVICE=eth1,10Mbit,1Mbit
8489 RATE=28Kbit
8490 WEIGHT=2Kbit
8491 PRIO=5
8492 RULE=192.168.1.0/24
8493 </Screen>
8495 </Para>
8497 <Para>
8498 By all means use this program if the 'how and why' don't interest you.
8499 We're using CBQ.init in production and it works very well. It can even do
8500 some more advanced things, like time dependent shaping. The documentation is
8501 embedded in the script, which explains why you can't find a README.
8502 </Para>
8503 </VarListEntry>
8504 <VarListEntry>
8505 <Term>Chronox easy shaping scripts <ULink
8506 URL="http://www.chronox.de"
8507 >(site)</ULink
8508 ></Term>
8509 <ListItem>
8510 <Para>
8511 Stephan Mueller (smueller@chronox.de) wrote two useful scripts, 'limit.conn'
8512 and 'shaper'. The first one allows you to easily throttle a single download
8513 session, like this:
8514 </Para>
8516 <Para>
8518 <Screen>
8519 # limit.conn -s SERVERIP -p SERVERPORT -l LIMIT
8520 </Screen>
8522 </Para>
8524 <Para>
8525 It works on Linux 2.2 and 2.4/2.5.
8526 </Para>
8528 <Para>
8529 The second script is more complicated, and can be used to make lots of
8530 different queues based on iptables rules, which are used to mark packets
8531 which are then shaped.
8532 </Para>
8533 </VarListEntry>
8534 <VarListEntry>
8535 <Term>Virtual Router
8536 Redundancy Protocol implementation <ULink
8537 URL="http://w3.arobas.net/~jetienne/vrrpd/index.html"
8538 >(site)</ULink
8539 ></Term>
8540 <ListItem>
8541 <Para>
8542 This is purely for redundancy. Two machines with their own IP address and
8543 MAC Address together create a third IP Address and MAC Address, which is
8544 virtual. Originally intended purely for routers, which need constant MAC
8545 addresses, it also works for other servers.
8546 </Para>
8548 <Para>
8549 The beauty of this approach is the incredibly easy configuration. No kernel
8550 compiling or patching required, all userspace.
8551 </Para>
8553 <Para>
8554 Just run this on all machines participating in a service:
8556 <Screen>
8557 # vrrpd -i eth0 -v 50 10.0.0.22
8558 </Screen>
8560 </Para>
8562 <Para>
8563 And you are in business! 10.0.0.22 is now carried by one of your servers,
8564 probably the first one to run the vrrp daemon. Now disconnect that computer
8565 from the network and very rapidly one of the other computers will assume the
8566 10.0.0.22 address, as well as the MAC address.
8567 </Para>
8569 <Para>
8570 I tried this over here and had it up and running in 1 minute. For some
8571 strange reason it decided to drop my default gateway, but the -n flag
8572 prevented that.
8573 </Para>
8575 <Para>
8576 This is a 'live' failover:
8577 </Para>
8579 <Para>
8581 <Screen>
8582 64 bytes from 10.0.0.22: icmp_seq=3 ttl=255 time=0.2 ms
8583 64 bytes from 10.0.0.22: icmp_seq=4 ttl=255 time=0.2 ms
8584 64 bytes from 10.0.0.22: icmp_seq=5 ttl=255 time=16.8 ms
8585 64 bytes from 10.0.0.22: icmp_seq=6 ttl=255 time=1.8 ms
8586 64 bytes from 10.0.0.22: icmp_seq=7 ttl=255 time=1.7 ms
8587 </Screen>
8589 </Para>
8591 <Para>
8592 Not *one* ping packet was lost! Just after packet 4, I disconnected my P200
8593 from the network, and my 486 took over, which you can see from the higher
8594 latency.
8595 </Para>
8596 </VarListEntry>
8597 </VariableList>
8598 </Para>
8600 </chapter>
8602 <chapter>
8603 <Title>Further reading</Title>
8605 <Para>
8606 <VariableList>
8608 <VarListEntry>
8609 <Term><ULink
8610 URL="http://snafu.freedom.org/linux2.2/iproute-notes.html"
8611 >http://snafu.freedom.org/linux2.2/iproute-notes.html</ULink
8612 ></Term>
8613 <ListItem>
8614 <Para>
8615 Contains lots of technical information, comments from the kernel
8616 </Para>
8617 </VarListEntry>
8618 <VarListEntry>
8619 <Term><ULink
8620 URL="http://www.davin.ottawa.on.ca/ols/"
8621 >http://www.davin.ottawa.on.ca/ols/</ULink
8622 ></Term>
8623 <ListItem>
8624 <Para>
8625 Slides by Jamal Hadi Salim, one of the authors of Linux traffic control
8626 </Para>
8627 </VarListEntry>
8628 <VarListEntry>
8629 <Term><ULink
8630 URL="http://defiant.coinet.com/iproute2/ip-cref/"
8631 >http://defiant.coinet.com/iproute2/ip-cref/</ULink
8632 ></Term>
8633 <ListItem>
8634 <Para>
8635 HTML version of Alexeys LaTeX documentation - explains part of iproute2 in
8636 great detail
8637 </Para>
8638 </VarListEntry>
8639 <VarListEntry>
8640 <Term><ULink
8641 URL="http://www.aciri.org/floyd/cbq.html"
8642 >http://www.aciri.org/floyd/cbq.html</ULink
8643 ></Term>
8644 <ListItem>
8645 <Para>
8646 Sally Floyd has a good page on CBQ, including her original papers. None of
8647 it is Linux specific, but it does a fair job discussing the theory and uses
8648 of CBQ.
8649 Very technical stuff, but good reading for those so inclined. 
8650 </Para>
8651 </VarListEntry>
8652 <VarListEntry>
8653 <Term>Differentiated Services on Linux</Term>
8654 <ListItem>
8655 <Para>
8656 This <ULink
8657 URL="ftp://icaftp.epfl.ch/pub/linux/diffserv/misc/dsid-01.txt.gz"
8658 >document</ULink
8659 > by Werner Almesberger, Jamal Hadi Salim and Alexey
8660 Kuznetsov describes DiffServ facilities in the Linux kernel, amongst which
8661 are TBF, GRED, the DSMARK qdisc and the tcindex classifyer.
8662 </Para>
8663 </VarListEntry>
8664 <VarListEntry>
8665 <Term><ULink
8666 URL="http://ceti.pl/~kravietz/cbq/NET4_tc.html"
8667 >http://ceti.pl/~kravietz/cbq/NET4_tc.html</ULink
8668 ></Term>
8669 <ListItem>
8670 <Para>
8671 Yet another HOWTO, this time in Polish! You can copy/paste command lines
8672 however, they work just the same in every language. The author is
8673 cooperating with us and may soon author sections of this HOWTO.
8674 </Para>
8675 </VarListEntry>
8676 <VarListEntry>
8677 <Term><ULink
8678 URL="http://www.cisco.com/univercd/cc/td/doc/product/software/ios111/cc111/car.htm"
8679 >IOS Committed Access Rate</ULink
8680 ></Term>
8681 <ListItem>
8682 <Para>
8683 <Anchor id="CAR">
8684 From the helpful folks of Cisco who have the laudable habit of putting
8685 their documentation online. Cisco syntax is different but the concepts are
8686 the same, except that we can do more and do it without routers the price of
8687 cars :-)
8688 </Para>
8689 </VarListEntry>
8690 <VarListEntry>
8691 <Term>Docum experimental site<ULink
8692 URL="http://www.docum.org"
8693 >(site)</ULink
8694 ></Term>
8695 <ListItem>
8696 <Para>
8697 Stef Coene is busy convincing his boss to sell Linux support, and so he is
8698 experimenting a lot, especially with managing bandwidth. His site has a lot
8699 of practical information, examples, tests and also points out some CBQ/tc bugs. 
8700 </Para>
8701 </VarListEntry>
8702 <VarListEntry>
8703 <Term>TCP/IP Illustrated, volume 1, W. Richard Stevens, ISBN 0-201-63346-9</Term>
8704 <ListItem>
8705 <Para>
8706 Required reading if you truly want to understand TCP/IP. Entertaining as
8707 well.
8708 </Para>
8709 </VarListEntry>
8710 </VariableList> 
8711 </Para>
8713 </chapter>
8715 <chapter>
8716 <Title>Acknowledgements </Title>
8718 <Para>
8720 It is our goal to list everybody who has contributed to this HOWTO, or
8721 helped us demystify how things work. While there are currently no plans
8722 for a Netfilter type scoreboard, we do like to recognise the people who are
8723 helping.
8724 </Para>
8726 <Para>
8728 <ItemizedList>
8729 <listitem>
8730 <para>
8731 Dave Aaldering &lt;dave%puddingonline.com&gt;
8732 </para>
8733 </ListItem>
8736 <ListItem>
8738 <Para>
8739 Juanjo Alins &lt;juanjo&percnt;mat.upc.es&gt;
8740 </Para>
8741 </ListItem>
8743 <ListItem>
8745 <Para>
8746 Joe Van Andel
8747 </Para>
8748 </ListItem>
8750 <ListItem>
8752 <Para>
8753 Michael T. Babcock &lt;mbabcock@fibrespeed.net&gt;
8754 </Para>
8755 </ListItem>
8756 <ListItem>
8758 <Para>
8759 Ard van Breemen &lt;ard&percnt;kwaak.net&gt;
8760 </Para>
8761 </ListItem>
8762 <ListItem>
8764 <Para>
8765 Ron Brinker &lt;service&percnt;emcis.com&gt;
8766 </Para>
8767 </ListItem>
8768 <ListItem>
8770 <Para>
8771 ?ukasz Bromirski &lt;L.Bromirski@prosys.com.pl&gt;
8772 </Para>
8773 </ListItem>
8774 <ListItem>
8776 <Para>
8777 Lennert Buytenhek &lt;buytenh@gnu.org&gt;
8778 </Para>
8779 </ListItem>
8780 <ListItem>
8782 <Para>
8783 Esteve Camps &lt;esteve@hades.udg.es&gt;
8784 </Para>
8785 </ListItem>
8786 <ListItem>
8788 <Para>
8789 Stef Coene &lt;stef.coene@docum.org&gt;
8790 </Para>
8791 </ListItem>
8792 <ListItem>
8794 <Para>
8795 Don Cohen &lt;don-lartc&percnt;isis.cs3-inc.com&gt;
8796 </Para>
8797 </ListItem>
8798 <ListItem>
8800 <Para>
8801 Jonathan Corbet &lt;lwn&percnt;lwn.net&gt;
8802 </Para>
8803 </ListItem>
8804 <ListItem>
8806 <Para>
8807 Gerry Creager N5JXS &lt;gerry&percnt;cs.tamu.edu&gt;
8808 </Para>
8809 </ListItem>
8810 <ListItem>
8812 <Para>
8813 Marco Davids &lt;marco@sara.nl&gt;
8814 </Para>
8815 </ListItem>
8816 <ListItem>
8818 <Para>
8819 Jonathan Day &lt;jd9812@my-deja.com&gt;
8820 </Para>
8821 </ListItem>
8822 <ListItem>
8824 <Para>
8825 Martin Devera aka devik &lt;devik@cdi.cz&gt;
8826 </Para>
8827 </ListItem>
8828 <ListItem>
8830 <Para>
8831 Stephan "Kobold" Gehring &lt;Stephan.Gehring@bechtle.de&gt;
8832 </Para>
8833 </ListItem>
8834 <ListItem>
8836 <Para>
8837 Jacek Glinkowski &lt;jglinkow&percnt;hns.com&gt;
8838 </Para>
8839 </ListItem>
8840 <ListItem>
8842 <Para>
8843 Andrea Glorioso &lt;sama&percnt;perchetopi.org&gt;
8844 </Para>
8845 </ListItem>
8846 <ListItem>
8848 <Para>
8849 Nadeem Hasan &lt;nhasan@usa.net&gt;
8850 </Para>
8851 </ListItem>
8852 <ListItem>
8854 <Para>
8855 Erik Hensema &lt;erik&percnt;hensema.xs4all.nl&gt;
8856 </Para>
8857 </ListItem>
8858 <ListItem>
8860 <Para>
8861 Vik Heyndrickx &lt;vik.heyndrickx@edchq.com&gt;
8862 </Para>
8863 </ListItem>
8864 <ListItem>
8866 <Para>
8867 Spauldo Da Hippie &lt;spauldo&percnt;usa.net&gt;
8868 </Para>
8869 </ListItem>
8870 <ListItem>
8872 <Para>
8873 Koos van den Hout &lt;koos@kzdoos.xs4all.nl&gt;
8874 </Para>
8875 </ListItem>
8876 <ListItem>
8878 <Para>
8879 Stefan Huelbrock &lt;shuelbrock&percnt;datasystems.de&gt;
8880 </Para>
8881 </ListItem>
8882 <ListItem>
8884 <Para>
8885 Alexander W. Janssen &lt;yalla&percnt;ynfonatic.de&gt;
8886 </Para>
8887 </ListItem>
8888 <ListItem>
8890 <Para>
8891 Gareth John &lt;gdjohn&percnt;zepler.org&gt;
8892 </Para>
8893 </ListItem>
8894 <ListItem>
8896 <Para>
8897 Martin Josefsson &lt;gandalf&percnt;wlug.westbo.se&gt;
8898 </Para>
8899 </ListItem>
8900 <ListItem>
8902 <Para>
8903 Andi Kleen &lt;ak&percnt;suse.de&gt;
8904 </Para>
8905 </ListItem>
8906 <ListItem>
8908 <Para>
8909 Andreas J. Koenig &lt;andreas.koenig&percnt;anima.de&gt;
8910 </Para>
8911 </ListItem>
8912 <ListItem>
8914 <Para>
8915 Pawel Krawczyk &lt;kravietz&percnt;alfa.ceti.pl&gt;
8916 </Para>
8917 </ListItem>
8918 <ListItem>
8920 <Para>
8921 Amit Kucheria &lt;amitk@ittc.ku.edu&gt;
8922 </Para>
8923 </ListItem>
8924 <ListItem>
8926 <Para>
8927 Edmund Lau &lt;edlau&percnt;ucf.ics.uci.edu&gt;
8928 </Para>
8929 </ListItem>
8930 <ListItem>
8932 <Para>
8933 Philippe Latu &lt;philippe.latu&percnt;linux-france.org&gt;
8934 </Para>
8935 </ListItem>
8936 <ListItem>
8938 <Para>
8939 Arthur van Leeuwen &lt;arthurvl&percnt;sci.kun.nl&gt;
8940 </Para>
8941 </ListItem>
8942 <ListItem>
8944 <Para>
8945 Jason Lunz &lt;j@cc.gatech.edu&gt;
8946 </Para>
8947 </ListItem>
8948 <ListItem>
8950 <Para>
8951 Stuart Lynne &lt;sl@fireplug.net&gt;
8952 </Para>
8953 </ListItem>
8954 <ListItem>
8956 <Para>
8957 Alexey Mahotkin &lt;alexm@formulabez.ru&gt;
8958 </Para>
8959 </ListItem>
8960 <ListItem>
8962 <Para>
8963 Predrag Malicevic &lt;pmalic@ieee.org&gt;
8964 </Para>
8965 </ListItem>
8966 <listitem>
8967 <para>
8968 Patrick McHardy &lt;kaber@trash.net&gt;
8969 </para>
8970 </ListItem>
8972 <ListItem>
8975 <Para>
8976 Andreas Mohr &lt;andi&percnt;lisas.de&gt;
8977 </Para>
8978 </ListItem>
8979 <ListItem>
8981 <Para>
8982 Andrew Morton &lt;akpm@zip.com.au&gt;
8983 </Para>
8984 </ListItem>
8985 <ListItem>
8987 <Para>
8988 Wim van der Most 
8989 </Para>
8990 </ListItem>
8991 <ListItem>
8993 <Para>
8994 Stephan Mueller &lt;smueller@chronox.de&gt;
8995 </Para>
8996 </ListItem>
8997 <ListItem>
8999 <Para>
9000 Togan Muftuoglu &lt;toganm&percnt;yahoo.com&gt;
9001 </Para>
9002 </ListItem>
9003 <ListItem>
9005 <Para>
9006 Chris Murray &lt;cmurray@stargate.ca&gt;
9007 </Para>
9008 </ListItem>
9009 <ListItem>
9011 <Para>
9012 Patrick Nagelschmidt &lt;dto&percnt;gmx.net&gt;
9013 </Para>
9014 </ListItem>
9015 <ListItem>
9017 <Para>
9018 Ram Narula &lt;ram@princess1.net&gt;
9019 </Para>
9020 </ListItem>
9021 <ListItem>
9023 <Para>
9024 Jorge Novo &lt;jnovo@educanet.net&gt;
9025 </Para>
9026 </ListItem>
9027 <ListItem>
9029 <Para>
9030 Patrik &lt;ph@kurd.nu&gt;
9031 </Para>
9032 </ListItem>
9034 <listitem><para>P?l Osgy?ny &lt;oplab%westel900.net&gt;</para></listitem>
9036 <ListItem>
9038 <Para>
9039 Lutz Pre&szlig;ler &lt;Lutz.Pressler&percnt;SerNet.DE&gt;
9040 </Para>
9041 </ListItem>
9042 <ListItem>
9044 <Para>
9045 Jason Pyeron &lt;jason&percnt;pyeron.com&gt;
9046 </Para>
9047 </ListItem>
9048 <ListItem>
9050 <Para>
9051 Rusty Russell &lt;rusty&percnt;rustcorp.com.au&gt;
9052 </Para>
9053 </ListItem>
9054 <ListItem>
9056 <Para>
9057 Mihai RUSU &lt;dizzy&percnt;roedu.net&gt;
9058 </Para>
9059 </ListItem>
9060 <ListItem>
9062 <Para>
9063 Jamal Hadi Salim &lt;hadi&percnt;cyberus.ca&gt;
9064 </Para>
9065 </ListItem>
9066 <ListItem>
9068 <Para>
9069 David Sauer &lt;davids&percnt;penguin.cz&gt;
9070 </Para>
9071 </ListItem>
9072 <ListItem>
9074 <Para>
9075 Sheharyar Suleman Shaikh &lt;sss23@drexel.edu&gt;
9076 </Para>
9077 </ListItem>
9078 <ListItem>
9080 <Para>
9081 Stewart Shields &lt;MourningBlade&percnt;bigfoot.com&gt;
9082 </Para>
9083 </ListItem>
9084 <ListItem>
9086 <Para>
9087 Nick Silberstein &lt;nhsilber&percnt;yahoo.com&gt;
9088 </Para>
9089 </ListItem>
9090 <ListItem>
9092 <Para>
9093 Dragan Simic &lt;dsimic%oracle.urc.bl.ac.yu&gt;
9094 </Para>
9095 </ListItem>
9096 <ListItem>
9099 <Para>
9100 Konrads Smelkov &lt;konrads@interbaltika.com&gt;
9101 </Para>
9102 </ListItem>
9103 <ListItem>
9105 <Para>
9106 Andreas Steinmetz &lt;ast&percnt;domdv.de&gt;
9107 </Para>
9108 </ListItem>
9111 <listitem>
9112 <para>
9113 Olli Suihkonen &lt;olli.suihkonen%micsom.com&gt;
9114 </para>
9115 </ListItem>
9117 <ListItem>
9118 <Para>
9119 Jason Tackaberry &lt;tack@linux.com&gt;
9120 </Para>
9121 </ListItem>
9122 <ListItem>
9124 <Para>
9125 Charles Tassell &lt;ctassell&percnt;isn.net&gt;
9126 </Para>
9127 </ListItem>
9128 <ListItem>
9130 <Para>
9131 Glen Turner &lt;glen.turner&percnt;aarnet.edu.au&gt;
9132 </Para>
9133 </ListItem>
9134 <ListItem>
9136 <Para>
9137 Tea Sponsor: Eric Veldhuyzen &lt;eric&percnt;terra.nu&gt; 
9138 </Para>
9139 </ListItem>
9140 <ListItem>
9142 <Para>
9143 Song Wang &lt;wsong@ece.uci.edu&gt;
9144 </Para>
9145 </listitem>
9147 <listitem>
9148 <para>
9149 Tijs Zwinkels &lt;tijszwinkels%home.nl&gt;
9150 </para>
9151 </ListItem>
9157 </ItemizedList>
9159 </Para>
9161 </chapter>
9163 </Book>