Before you begin

I once again suggest you to try the new patch version that eliminates the necessity of modifying the patch source code. You should only use this patch if you are doing the traffic shaping on the same machine where SQUID is working. In such cases you can gain a little bandwidth (no options field in the packets). If you have a more complex topology (DMZ, for instance) try the new version - it is mote versatile.

Implementation

This patch is extremely simple in design and any suggestions and improvements are welcome. Currently there is no other way to configure the qdisc handle that will dequeue the HIT type of traffic, except hardcode it in the patch. The current handle is 1:60 and it can be set before or after patching SQUID's source. All you have to do is change this line (in the .diff file of the patch or in the patched file client_side.c from SQUID's source tree):

unsigned long priority = 0x00010060;

,to the value of your qdisc handle that will accept the HIT packets. For example, if your handle is 1A:999, the value for priority should be 0x001A0999.

A more complete QoS example

LANDEV=eth1
TC=/sbin/tc
DOWNLINK=506

$TC qdisc add dev $LANDEV root handle 1: htb default 10

$TC class add dev $LANDEV parent 1: classid 1:1 htb rate ${DOWNLINK}kbit
$TC class add dev $LANDEV parent 1: classid 1:60 htb rate 1kbit ceil 100mbit

$TC class add dev $LANDEV parent 1:1 classid 1:10 htb \
rate $[2*$DOWNLINK/10]kbit ceil ${DOWNLINK}kbit

$TC class add dev $LANDEV parent 1:1 classid 1:20 htb \
rate $[3*$DOWNLINK/10]kbit ceil ${DOWNLINK}kbit

$TC class add dev $LANDEV parent 1:1 classid 1:30 htb \
rate $[5*$DOWNLINK/10]kbit ceil ${DOWNLINK}kbit

$TC qdisc add dev $LANDEV parent 1:10 handle 10: sfq perturb 10
$TC qdisc add dev $LANDEV parent 1:20 handle 20: sfq perturb 10
$TC qdisc add dev $LANDEV parent 1:30 handle 30: sfq perturb 10

This example sets up 4 classes. Three of them (1:10,1:20,1:30) impose the QoS groups within the LAN. They all get SFQ qdisc. The forth class is a special one. Its handle is 1:60 - the one setup in SQUID's patch. This class has a very low rate (only 1 kbit), but its ceil is the maximum possible bandwidth. The low rate and high ceil makes all trafic destined to this handle to go out of $LANDEV device with wire speed, without disturbing the ratios between the other three classes in times of congestions. This class (1:60) is served by the default FIFO qdisc associated with the $LANDEV device.

The associated filters that send traffic to 1:10,1:20 and 1:30 are not shown since they are irrelevant here.

INSTALL

1. Download SQUID 2.5 STABLE source (squid-2.5.STABLE-3 and STABLE-4 are tested to work with this patch).
2. Go to your favourite temporary directory and decompress the source:
tar -zxvf squid-2.5.STABLE3.tar.gz

or, for the bzip2 archive:

tar -jxvf squid-2.5.STABLE3.tar.bz2
3. Change to SQUID's source directory and apply the patch (this assumes you have downloaded the patch one directory above SQUID's source):
cd squid-2.5.STABLE3
patch -p1 < ../squid-2.5.STABLE3-hit_prio.diff
4. Follow SQUID's INSTALL guide to configure, compile and install the engine.
5. Create the appropriate QoS classes and qdiscs. If you do not create the class that is setup in the patch, the HIT type of traffic will go to the default class.
6. Start SQUID, and generate some traffic. After a while you should see packets being queued to the specified HIT class. Use this command to observe:
tc -s class show dev eth1
where you substitute eth1 with your internal (where the clients are connected) device name.

7. Drink a beer or two. Write me an e-mail if it worked.