MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ip_hash

Function ip_hash

freebsd/netgraph/ng_pipe.c:564–579  ·  view source on GitHub ↗

* 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... */

Source from the content-addressed store, hash-verified

562 * folks have found out to be a good and efficient IP hash function...
563 */
564static int
565ip_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.

Callers 1

ngp_rcvdataFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected