* Compute a hash signature for a packet. This function suffers from the * NIH sindrome, so probably it would be wise to look around what other * folks have found out to be a good and efficient IP hash function... */
| 562 | * folks have found out to be a good and efficient IP hash function... |
| 563 | */ |
| 564 | static int |
| 565 | ip_hash(struct mbuf *m, int offset) |
| 566 | { |
| 567 | u_int64_t i; |
| 568 | struct ip *ip = (struct ip *)(mtod(m, u_char *) + offset); |
| 569 | |
| 570 | if (m->m_len < sizeof(struct ip) + offset || |
| 571 | ip->ip_v != 4 || ip->ip_hl << 2 != sizeof(struct ip)) |
| 572 | return 0; |
| 573 | |
| 574 | i = ((u_int64_t) ip->ip_src.s_addr ^ |
| 575 | ((u_int64_t) ip->ip_src.s_addr << 13) ^ |
| 576 | ((u_int64_t) ip->ip_dst.s_addr << 7) ^ |
| 577 | ((u_int64_t) ip->ip_dst.s_addr << 19)); |
| 578 | return (i ^ (i >> 32)); |
| 579 | } |
| 580 | |
| 581 | /* |
| 582 | * Receive data on a hook - both in upstream and downstream direction. |