Changeset View
Changeset View
Standalone View
Standalone View
sys/netpfil/ipfw/ip_fw_table_algo.c
Show All 38 Lines | |||||
#endif /* INET */ | #endif /* INET */ | ||||
#include "opt_inet6.h" | #include "opt_inet6.h" | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/libkern.h> | |||||
#include <sys/rwlock.h> | #include <sys/rwlock.h> | ||||
#include <sys/rmlock.h> | #include <sys/rmlock.h> | ||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#include <net/if.h> /* ip_fw.h requires IFNAMSIZ */ | #include <net/if.h> /* ip_fw.h requires IFNAMSIZ */ | ||||
#include <net/radix.h> | #include <net/radix.h> | ||||
#include <net/route.h> | #include <net/route.h> | ||||
#include <net/route/nhop.h> | #include <net/route/nhop.h> | ||||
▲ Show 20 Lines • Show All 3,085 Lines • ▼ Show 20 Lines | cmp_flow_ent(struct fhashentry *a, struct fhashentry *b, size_t sz) | ||||
kb = (uint64_t *)(&b->next + 1); | kb = (uint64_t *)(&b->next + 1); | ||||
if (*ka == *kb && (memcmp(a + 1, b + 1, sz) == 0)) | if (*ka == *kb && (memcmp(a + 1, b + 1, sz) == 0)) | ||||
return (1); | return (1); | ||||
return (0); | return (0); | ||||
} | } | ||||
#define UPDATE_CRC(c, x) (c) = calculate_crc32c((c), (const char*)&(x), sizeof(x)) | |||||
static __inline uint32_t | static __inline uint32_t | ||||
hash_flow4(struct fhashentry4 *f, int hsize) | hash_flow4(struct fhashentry4 *f, int hsize) | ||||
{ | { | ||||
uint32_t i; | uint32_t i = ~0u; | ||||
i = (f->dip.s_addr) ^ (f->sip.s_addr) ^ (f->e.dport) ^ (f->e.sport); | UPDATE_CRC(i, f->sip); | ||||
UPDATE_CRC(i, f->dip); | |||||
UPDATE_CRC(i, f->e.sport); | |||||
UPDATE_CRC(i, f->e.dport); | |||||
UPDATE_CRC(i, f->e.proto); | |||||
return (i % (hsize - 1)); | return (i % (hsize - 1)); | ||||
} | } | ||||
static __inline uint32_t | static __inline uint32_t | ||||
hash_flow6(struct fhashentry6 *f, int hsize) | hash_flow6(struct fhashentry6 *f, int hsize) | ||||
{ | { | ||||
uint32_t i; | uint32_t i = ~0u; | ||||
i = (f->dip6.__u6_addr.__u6_addr32[2]) ^ | UPDATE_CRC(i, f->sip6); | ||||
(f->dip6.__u6_addr.__u6_addr32[3]) ^ | UPDATE_CRC(i, f->dip6); | ||||
(f->sip6.__u6_addr.__u6_addr32[2]) ^ | UPDATE_CRC(i, f->e.sport); | ||||
(f->sip6.__u6_addr.__u6_addr32[3]) ^ | UPDATE_CRC(i, f->e.dport); | ||||
(f->e.dport) ^ (f->e.sport); | UPDATE_CRC(i, f->e.proto); | ||||
return (i % (hsize - 1)); | return (i % (hsize - 1)); | ||||
} | } | ||||
#undef UPDATE_CRC | |||||
static uint32_t | static uint32_t | ||||
hash_flow_ent(struct fhashentry *ent, uint32_t size) | hash_flow_ent(struct fhashentry *ent, uint32_t size) | ||||
{ | { | ||||
uint32_t hash; | uint32_t hash; | ||||
if (ent->af == AF_INET) { | if (ent->af == AF_INET) { | ||||
hash = hash_flow4((struct fhashentry4 *)ent, size); | hash = hash_flow4((struct fhashentry4 *)ent, size); | ||||
▲ Show 20 Lines • Show All 866 Lines • Show Last 20 Lines |