1 /*        $NetBSD: ip_htable.h,v 1.1.1.2 2012/07/22 13:44:17 darrenr Exp $      */
2 
3 #ifndef __IP_HTABLE_H__
4 #define __IP_HTABLE_H__
5 
6 #include "netinet/ip_lookup.h"
7 
8 typedef   struct    iphtent_s {
9           struct    iphtent_s *ipe_next, **ipe_pnext;
10           struct    iphtent_s *ipe_hnext, **ipe_phnext;
11           struct    iphtent_s *ipe_dnext, **ipe_pdnext;
12           struct    iphtable_s          *ipe_owner;
13           void                *ipe_ptr;
14           i6addr_t  ipe_addr;
15           i6addr_t  ipe_mask;
16           U_QUAD_T  ipe_hits;
17           U_QUAD_T  ipe_bytes;
18           u_long              ipe_die;
19           int                 ipe_uid;
20           int                 ipe_ref;
21           int                 ipe_unit;
22           char                ipe_family;
23           char                ipe_xxx[3];
24           union     {
25                     char      ipeu_char[16];
26                     u_long    ipeu_long;
27                     u_int     ipeu_int;
28           } ipe_un;
29 } iphtent_t;
30 
31 #define   ipe_value ipe_un.ipeu_int
32 #define   ipe_group ipe_un.ipeu_char
33 
34 #define   IPE_V4_HASH_FN(a, m, s)       ((((m) ^ (a)) - 1 - ((a) >> 8)) % (s))
35 #define   IPE_V6_HASH_FN(a, m, s)       (((((m)[0] ^ (a)[0]) - ((a)[0] >> 8)) + \
36                                           (((m)[1] & (a)[1]) - ((a)[1] >> 8)) + \
37                                           (((m)[2] & (a)[2]) - ((a)[2] >> 8)) + \
38                                           (((m)[3] & (a)[3]) - ((a)[3] >> 8))) % (s))
39 
40 typedef   struct    iphtable_s          {
41           ipfrwlock_t         iph_rwlock;
42           struct    iphtable_s          *iph_next, **iph_pnext;
43           struct    iphtent_s **iph_table;
44           struct    iphtent_s *iph_list;
45           struct    iphtent_s **iph_tail;
46 #ifdef USE_INET6
47           ipf_v6_masktab_t    iph_v6_masks;
48 #endif
49           ipf_v4_masktab_t    iph_v4_masks;
50           size_t    iph_size;           /* size of hash table */
51           u_long    iph_seed;           /* hashing seed */
52           u_32_t    iph_flags;
53           u_int     iph_unit;           /* IPL_LOG* */
54           u_int     iph_ref;
55           u_int     iph_type;           /* lookup or group map  - IPHASH_* */
56           u_int     iph_maskset[4];               /* netmasks in use */
57           char      iph_name[FR_GROUPLEN];        /* hash table number */
58 } iphtable_t;
59 
60 /* iph_type */
61 #define   IPHASH_LOOKUP       0
62 #define   IPHASH_GROUPMAP     1
63 #define   IPHASH_DELETE       2
64 #define   IPHASH_ANON         0x80000000
65 
66 
67 typedef   struct    iphtstat_s          {
68           iphtable_t          *iphs_tables;
69           u_long              iphs_numtables;
70           u_long              iphs_numnodes;
71           u_long              iphs_nomem;
72           u_long              iphs_pad[16];
73 } iphtstat_t;
74 
75 
76 extern void *ipf_iphmfindgroup __P((ipf_main_softc_t *, void *, void *));
77 extern iphtable_t *ipf_htable_find __P((void *, int, char *));
78 extern ipf_lookup_t ipf_htable_backend;
79 #ifndef _KERNEL
80 extern    void      ipf_htable_dump __P((ipf_main_softc_t *, void *));
81 #endif
82 
83 #endif /* __IP_HTABLE_H__ */
84