linux/net/sched
Radu Rendec 543821c6f5 [PKT_SCHED] CLS_U32: Fix endianness problem with u32 classifier hash masks.
While trying to implement u32 hashes in my shaping machine I ran into
a possible bug in the u32 hash/bucket computing algorithm
(net/sched/cls_u32.c).

The problem occurs only with hash masks that extend over the octet
boundary, on little endian machines (where htonl() actually does
something).

Let's say that I would like to use 0x3fc0 as the hash mask. This means
8 contiguous "1" bits starting at b6. With such a mask, the expected
(and logical) behavior is to hash any address in, for instance,
192.168.0.0/26 in bucket 0, then any address in 192.168.0.64/26 in
bucket 1, then 192.168.0.128/26 in bucket 2 and so on.

This is exactly what would happen on a big endian machine, but on
little endian machines, what would actually happen with current
implementation is 0x3fc0 being reversed (into 0xc03f0000) by htonl()
in the userspace tool and then applied to 192.168.x.x in the u32
classifier. When shifting right by 16 bits (rank of first "1" bit in
the reversed mask) and applying the divisor mask (0xff for divisor
256), what would actually remain is 0x3f applied on the "168" octet of
the address.

One could say is this can be easily worked around by taking endianness
into account in userspace and supplying an appropriate mask (0xfc03)
that would be turned into contiguous "1" bits when reversed
(0x03fc0000). But the actual problem is the network address (inside
the packet) not being converted to host order, but used as a
host-order value when computing the bucket.

Let's say the network address is written as n31 n30 ... n0, with n0
being the least significant bit. When used directly (without any
conversion) on a little endian machine, it becomes n7 ... n0 n8 ..n15
etc in the machine's registers. Thus bits n7 and n8 would no longer be
adjacent and 192.168.64.0/26 and 192.168.128.0/26 would no longer be
consecutive.

The fix is to apply ntohl() on the hmask before computing fshift,
and in u32_hash_fold() convert the packet data to host order before
shifting down by fshift.

With helpful feedback from Jamal Hadi Salim and Jarek Poplawski.

Signed-off-by: David S. Miller <davem@davemloft.net>
2007-11-07 04:11:45 -08:00
..
act_api.c [NET_SCHED] protect action config/dump from irqs 2007-09-14 16:43:05 -07:00
act_gact.c
act_ipt.c [NETFILTER]: Replace sk_buff ** with sk_buff * 2007-10-15 12:26:29 -07:00
act_mirred.c [NET_CLS_ACT]: Use skb_act_clone 2007-10-26 02:47:54 -07:00
act_nat.c [PKT_SCHED]: Add stateless NAT 2007-10-10 16:53:11 -07:00
act_pedit.c
act_police.c [NET_SCHED]: Cleanup L2T macros and handle oversized packets 2007-10-10 16:49:20 -07:00
act_simple.c
cls_api.c [NET]: Make the device list and device lookups per namespace. 2007-10-10 16:49:10 -07:00
cls_basic.c
cls_fw.c
cls_route.c
cls_rsvp6.c
cls_rsvp.c
cls_rsvp.h
cls_tcindex.c
cls_u32.c [PKT_SCHED] CLS_U32: Fix endianness problem with u32 classifier hash masks. 2007-11-07 04:11:45 -08:00
em_cmp.c
em_meta.c Fix misspellings of "system", "controller", "interrupt" and "necessary". 2007-10-19 23:10:43 +02:00
em_nbyte.c
em_text.c
em_u32.c
ematch.c
Kconfig [NET]: QoS/Sched as menuconfig 2007-10-18 21:56:38 -07:00
Makefile [PKT_SCHED]: Add stateless NAT 2007-10-10 16:53:11 -07:00
sch_api.c [NET_SCHED]: Show timer resolution instead of clock resolution in /proc/net/psched 2007-10-10 16:55:59 -07:00
sch_atm.c
sch_blackhole.c
sch_cbq.c [NET_SCHED]: Cleanup L2T macros and handle oversized packets 2007-10-10 16:49:20 -07:00
sch_dsmark.c
sch_fifo.c
sch_generic.c [NET]: Fix possible dev_deactivate race condition 2007-10-18 22:37:58 -07:00
sch_gred.c
sch_hfsc.c
sch_htb.c [NET_SCHED]: Cleanup L2T macros and handle oversized packets 2007-10-10 16:49:20 -07:00
sch_ingress.c [NETFILTER]: Replace sk_buff ** with sk_buff * 2007-10-15 12:26:29 -07:00
sch_netem.c
sch_prio.c [PKT_SCHED]: Fix sch_prio.c build with CONFIG_NETDEVICES_MULTIQUEUE 2007-10-23 21:27:53 -07:00
sch_red.c
sch_sfq.c [SFQ]: Remove artificial limitation for queue limit. 2007-10-01 21:01:23 -07:00
sch_tbf.c [NET_SCHED]: Cleanup L2T macros and handle oversized packets 2007-10-10 16:49:20 -07:00
sch_teql.c [PKT_SCHED]: Fix OOPS when removing devices from a teql queuing discipline 2007-11-07 04:09:17 -08:00