52 #ifndef HICN_VPP_PLUGIN
54 #define PREDICT_FALSE(x) (x)
55 #define PREDICT_TRUE(x) (x)
56 #define always_inline static inline
57 #define static_always_inline static inline
58 #define STRUCT_SIZE_OF(type, member) sizeof(((type *)0)->member)
61 #define STATIC_ASSERT(x)
64 #if INTPTR_MAX == INT64_MAX
65 #define log2_uword_bits 6
66 #elif INTPTR_MAX == INT32_MAX
67 #define log2_uword_bits 5
69 #error "Impossible to detect architecture"
72 #define uword_bits (1 << log2_uword_bits)
83 typedef uword ip_csum_t;
94 #define ATTR_INIT(key, value) .key = value
96 #define ATTR_INIT(key, value) value
101 #define __ORDER_LITTLE_ENDIAN__ 0x41424344UL
102 #define __ORDER_BIG_ENDIAN__ 0x44434241UL
103 #define __BYTE_ORDER__ ('ABCD')
106 #define WIN32_LEAN_AND_MEAN
111 #include <winsock2.h>
112 #include <ws2ipdef.h>
113 #include <Ws2tcpip.h>
116 #define strdup _strdup
117 #define __attribute__(A)
121 #define UIO_MAXIOV 16
122 #define IOV_MAX UIO_MAXIOV
135 #define PACKED( __Declaration__ ) __Declaration__ __attribute__((__packed__))
137 #define PACKED( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
145 #ifdef HICN_VPP_PLUGIN
147 #include <vnet/ip/ip4_packet.h>
148 #include <vnet/ip/ip6_packet.h>
151 #pragma GCC diagnostic ignored "-Waddress-of-packed-member"
154 #include <vnet/ip/ip46_address.h>
157 #pragma GCC diagnostic pop
164 #include <netinet/in.h>
170 struct in_addr as_inaddr;
178 struct in6_addr as_in6addr;
191 #define ip46_address_is_ip4(ip46) (((ip46)->pad[0] | (ip46)->pad[1] | (ip46)->pad[2]) == 0)
200 int get_addr_family (
const char *ip_address);
209 #ifndef HICN_VPP_PLUGIN
218 static_always_inline u16
219 ip_csum_fold (ip_csum_t c)
223 c = (c & (ip_csum_t) 0xffffffff) + (c >> (ip_csum_t) 32);
224 c = (c & 0xffff) + (c >> 16);
227 c = (c & 0xffff) + (c >> 16);
228 c = (c & 0xffff) + (c >> 16);
233 static_always_inline ip_csum_t
234 ip_csum_with_carry (ip_csum_t sum, ip_csum_t x)
236 ip_csum_t t = sum + x;
241 static_always_inline ip_csum_t
242 ip_csum_add_even (ip_csum_t c, ip_csum_t x)
255 static_always_inline ip_csum_t
256 ip_csum_sub_even (ip_csum_t c, ip_csum_t x)
258 return ip_csum_with_carry (c, x);
261 u32 cumulative_hash32 (
const void *data,
size_t len, u32 lastValue);
262 u32 hash32 (
const void *data,
size_t len);
263 u64 cumulative_hash64 (
const void *data,
size_t len, u64 lastValue);
264 u64 hash64 (
const void *data,
size_t len);
265 void hicn_packet_dump (
const uint8_t * buffer,
size_t len);
277 csum (
const void *addr,
size_t size, u16 init)
280 const u16 *bytes = (u16 *) addr;
285 size -=
sizeof (u16);
289 sum += *(
const u8 *) bytes;
291 sum = (sum >> 16) + (sum & 0xffff);
302 #define IPPROTO_ICMPV4 IPPROTO_ICMP
308 #define HICN_IP_VERSION(packet) ((hicn_header_t *)packet)->v4.ip.version
314 #define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
318 #define ntohll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))