28#include <sys/fnv_hash.h>
30#include <net/ethernet.h>
31#include <net/infiniband.h>
33#if defined(INET) || defined(INET6)
34#include <netinet/in.h>
38#include <netinet/ip.h>
42#include <netinet/ip6.h>
47 const u_int len,
void *
buf)
50 if (m->m_pkthdr.len < (off + len)) {
52 }
else if (m->m_len < (off + len)) {
56 return (mtod(m,
char *) + off);
65 return (fnv_32_buf(&seed,
sizeof(seed), FNV1_32_INIT));
74 return (fnv_32_buf(&seed,
sizeof(seed), FNV1_32_INIT));
79 uint32_t p,
int off,
const uint16_t etype)
81#if defined(INET) || defined(INET6)
95 const struct ip6_hdr *ip6;
104 if (
flags & MBUF_HASHFLAG_L3) {
105 p = fnv_32_buf(&ip->ip_src,
sizeof(
struct in_addr), p);
106 p = fnv_32_buf(&ip->ip_dst,
sizeof(
struct in_addr), p);
108 if (
flags & MBUF_HASHFLAG_L4) {
109 const uint32_t *ports;
116 iphlen = ip->ip_hl << 2;
117 if (iphlen <
sizeof(*ip))
121 off,
sizeof(*ports), &
buf);
124 p = fnv_32_buf(ports,
sizeof(*ports), p);
137 if (
flags & MBUF_HASHFLAG_L3) {
138 p = fnv_32_buf(&ip6->ip6_src,
sizeof(
struct in6_addr), p);
139 p = fnv_32_buf(&ip6->ip6_dst,
sizeof(
struct in6_addr), p);
141 if (
flags & MBUF_HASHFLAG_L4) {
145 flow = ip6->ip6_flow & IPV6_FLOWLABEL_MASK;
146 p = fnv_32_buf(&flow,
sizeof(flow), p);
161 struct ether_vlan_header vlan;
163 const struct ether_header *eh;
164 const struct ether_vlan_header *vlan;
171 eh = mtod(m,
struct ether_header *);
172 etype = ntohs(eh->ether_type);
173 if (
flags & MBUF_HASHFLAG_L2) {
174 p = fnv_32_buf(&eh->ether_shost, ETHER_ADDR_LEN, p);
175 p = fnv_32_buf(&eh->ether_dhost, ETHER_ADDR_LEN, p);
178 if ((m->m_flags & M_VLANTAG) && (
flags & MBUF_HASHFLAG_L2)) {
179 p = fnv_32_buf(&m->m_pkthdr.ether_vtag,
180 sizeof(m->m_pkthdr.ether_vtag), p);
181 }
else if (etype == ETHERTYPE_VLAN) {
186 if (
flags & MBUF_HASHFLAG_L2)
187 p = fnv_32_buf(&vlan->evl_tag,
sizeof(vlan->evl_tag), p);
188 etype = ntohs(vlan->evl_proto);
189 off +=
sizeof(*vlan) -
sizeof(*eh);
198 const struct infiniband_header *ibh;
205 ibh = mtod(m,
struct infiniband_header *);
206 etype = ntohs(ibh->ib_protocol);
207 if (
flags & MBUF_HASHFLAG_L2)
208 p = fnv_32_buf(&ibh->ib_hwaddr, INFINIBAND_ADDR_LEN, p);
void m_copydata(const struct mbuf *m, int off, int len, caddr_t cp)
static uint32_t m_tcpip_hash(const uint32_t flags, const struct mbuf *m, uint32_t p, int off, const uint16_t etype)
uint32_t m_infiniband_tcpip_hash(const uint32_t flags, const struct mbuf *m, uint32_t p)
uint32_t m_ether_tcpip_hash_init(void)
uint32_t m_infiniband_tcpip_hash_init(void)
static const void * m_common_hash_gethdr(const struct mbuf *m, const u_int off, const u_int len, void *buf)
uint32_t m_ether_tcpip_hash(const uint32_t flags, const struct mbuf *m, uint32_t p)