1340279Svmaffione/*
2340279Svmaffione ** Copyright (c) 2015, Asim Jamshed, Robin Sommer, Seth Hall
3340279Svmaffione ** and the International Computer Science Institute. All rights reserved.
4340279Svmaffione **
5340279Svmaffione ** Redistribution and use in source and binary forms, with or without
6340279Svmaffione ** modification, are permitted provided that the following conditions are met:
7340279Svmaffione **
8340279Svmaffione ** (1) Redistributions of source code must retain the above copyright
9340279Svmaffione **     notice, this list of conditions and the following disclaimer.
10340279Svmaffione **
11340279Svmaffione ** (2) Redistributions in binary form must reproduce the above copyright
12340279Svmaffione **     notice, this list of conditions and the following disclaimer in the
13340279Svmaffione **     documentation and/or other materials provided with the distribution.
14340279Svmaffione **
15340279Svmaffione **
16340279Svmaffione ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17340279Svmaffione ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18340279Svmaffione ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19340279Svmaffione ** ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20340279Svmaffione ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21340279Svmaffione ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22340279Svmaffione ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23340279Svmaffione ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24340279Svmaffione ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25340279Svmaffione ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26340279Svmaffione ** POSSIBILITY OF SUCH DAMAGE.
27340279Svmaffione **/
28340279Svmaffione/* $FreeBSD: stable/11/tools/tools/netmap/pkt_hash.h 341434 2018-12-03 17:51:22Z vmaffione $ */
29340279Svmaffione#ifndef LB_PKT_HASH_H
30340279Svmaffione#define LB_PKT_HASH_H
31340279Svmaffione/*---------------------------------------------------------------------*/
32340279Svmaffione/**
33340279Svmaffione ** Packet header hashing function utility - This file contains functions
34340279Svmaffione ** that parse the packet headers and computes hash functions based on
35340279Svmaffione ** the header fields. Please see pkt_hash.c for more details...
36340279Svmaffione **/
37340279Svmaffione/*---------------------------------------------------------------------*/
38340279Svmaffione/* for type def'n */
39340279Svmaffione#include <stdint.h>
40340279Svmaffione/*---------------------------------------------------------------------*/
41340279Svmaffione#ifdef __GNUC__
42340279Svmaffione#define likely(x)       __builtin_expect(!!(x), 1)
43340279Svmaffione#define unlikely(x)     __builtin_expect(!!(x), 0)
44340279Svmaffione#else
45340279Svmaffione#define likely(x)       (x)
46340279Svmaffione#define unlikely(x)     (x)
47340279Svmaffione#endif
48340279Svmaffione
49340279Svmaffione#define HTONS(n) (((((unsigned short)(n) & 0xFF)) << 8) | \
50340279Svmaffione		  (((unsigned short)(n) & 0xFF00) >> 8))
51340279Svmaffione#define NTOHS(n) (((((unsigned short)(n) & 0xFF)) << 8) | \
52340279Svmaffione		  (((unsigned short)(n) & 0xFF00) >> 8))
53340279Svmaffione
54340279Svmaffione#define HTONL(n) (((((unsigned long)(n) & 0xFF)) << 24) | \
55340279Svmaffione        ((((unsigned long)(n) & 0xFF00)) << 8) | \
56340279Svmaffione        ((((unsigned long)(n) & 0xFF0000)) >> 8) | \
57340279Svmaffione		  ((((unsigned long)(n) & 0xFF000000)) >> 24))
58340279Svmaffione
59340279Svmaffione#define NTOHL(n) (((((unsigned long)(n) & 0xFF)) << 24) | \
60340279Svmaffione        ((((unsigned long)(n) & 0xFF00)) << 8) | \
61340279Svmaffione        ((((unsigned long)(n) & 0xFF0000)) >> 8) | \
62340279Svmaffione		  ((((unsigned long)(n) & 0xFF000000)) >> 24))
63340279Svmaffione/*---------------------------------------------------------------------*/
64340279Svmaffionetypedef struct vlanhdr {
65340279Svmaffione	uint16_t pri_cfi_vlan;
66340279Svmaffione	uint16_t proto;
67340279Svmaffione} vlanhdr;
68340279Svmaffione/*---------------------------------------------------------------------*/
69340279Svmaffione/**
70340279Svmaffione ** Analyzes the packet header of computes a corresponding
71340279Svmaffione ** hash function.
72340279Svmaffione **/
73340279Svmaffioneuint32_t
74340279Svmaffionepkt_hdr_hash(const unsigned char *buffer,
75340279Svmaffione	     uint8_t hash_split,
76340279Svmaffione	     uint8_t seed);
77340279Svmaffione/*---------------------------------------------------------------------*/
78340279Svmaffione#endif /* LB_PKT_HASH_H */
79340279Svmaffione
80