lkml.org 
[lkml]   [2002]   [Mar]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: TCP hashing function
On Fri, Mar 29, 2002 at 12:08:18AM -0800, Neil Spring wrote:
> On Thu, Mar 28, 2002 at 08:11:27PM -0500, Marek Zawadzki wrote:
> > Hello,
>
> > static __inline__ int dcp_hashfn(__u32 laddr, __u16 lport,
> > __u32 faddr, __u16 fport)
> > {
> > int h = ((laddr ^ lport) ^ (faddr ^ fport));
> > h ^= h>>16;
> > h ^= h>>8;
> > /* make it always < size : */
> > return h & (MY_HTABLE_SIZE - 1); /* MY_HT... = 128 */
> > }
> >
> > Although I am treating it as a blackbox and it works fine for me, my
> > professor pointed the following about this function:
>
> If you're a student, you should probably try to figure
> this out for yourself; it's the only way to learn.

Add one to the homework on the list tally.

> > If both IP addresses have the same upper 16 bits (like 155.246.10.5 and
> > 155.246.120.30), then the 1st 4-way XOR will put 16 bits of zero in h.
> > Then "h ^= h>>16" will preserve the upper 16 bits as zero. Then
> > "h ^= h>>8" will preserve the upper 24 bits!
> > [...]

Look at the size and see why it doesn't matter.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:25    [W:0.035 / U:1.416 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site