xref: /illumos-gate/usr/src/uts/common/inet/ipf/netinet/ip_htable.h (revision ed093b41a93e8563e6e1e5dae0768dda2a7bcc27)
1 /*
2  * Copyright (C) 2003 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
7  */
8 
9 #ifndef __IP_HTABLE_H__
10 #define __IP_HTABLE_H__
11 
12 #include "netinet/ip_lookup.h"
13 
14 typedef	struct	iphtent_s	{
15 	struct	iphtent_s	*ipe_next, **ipe_pnext;
16 	struct	iphtent_s	*ipe_snext, **ipe_psnext;
17 	void		*ipe_ptr;
18 	sa_family_t	ipe_family;
19 	i6addr_t	ipe_addr;
20 	i6addr_t	ipe_mask;
21 	U_QUAD_T	ipe_hits;
22 	U_QUAD_T	ipe_bytes;
23 	int		ipe_ref;
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_HASH_FN(a, m, s)	(((a) * (m)) % (s))
35 
36 
37 typedef	struct	iphtable_s	{
38 	ipfrwlock_t	iph_rwlock;
39 	struct	iphtable_s	*iph_next, **iph_pnext;
40 	struct	iphtent_s	**iph_table;
41 	struct	iphtent_s	*iph_list;
42 	size_t	iph_size;		/* size of hash table */
43 	u_long	iph_seed;		/* hashing seed */
44 	u_32_t	iph_flags;
45 	u_int	iph_unit;		/* IPL_LOG* */
46 	u_int	iph_ref;
47 	u_int	iph_type;		/* lookup or group map  - IPHASH_* */
48 	u_int	iph_masks[4];		/* IPv4 or IPv6 netmasks in use */
49 	char	iph_name[FR_GROUPLEN];	/* hash table number */
50 } iphtable_t;
51 
52 
53 /* iph_type */
54 #define	IPHASH_LOOKUP	0
55 #define	IPHASH_GROUPMAP	1
56 #define	IPHASH_ANON	0x80000000
57 
58 
59 typedef	struct	iphtstat_s	{
60 	iphtable_t	*iphs_tables;
61 	u_long		iphs_numtables;
62 	u_long		iphs_numnodes;
63 	u_long		iphs_nomem;
64 	u_long		iphs_pad[16];
65 } iphtstat_t;
66 
67 
68 extern void fr_htable_unload __P((ipf_stack_t *));
69 extern int fr_newhtable __P((iplookupop_t *, ipf_stack_t *));
70 extern iphtable_t *fr_findhtable __P((int, char *, ipf_stack_t *));
71 extern int fr_removehtable __P((iplookupop_t *, ipf_stack_t *));
72 extern size_t fr_flushhtable __P((iplookupflush_t *, ipf_stack_t *));
73 extern int fr_addhtent __P((iphtable_t *, iphtent_t *, ipf_stack_t *));
74 extern int fr_delhtent __P((iphtable_t *, iphtent_t *, ipf_stack_t *));
75 extern void fr_derefhtable __P((iphtable_t *, ipf_stack_t *));
76 extern void fr_derefhtent __P((iphtent_t *));
77 extern void fr_delhtable __P((iphtable_t *, ipf_stack_t *));
78 extern void *fr_iphmfindgroup __P((void *, int, void *, ipf_stack_t *));
79 extern int fr_iphmfindip __P((void *, int, void *, fr_info_t *, ipf_stack_t *));
80 extern int fr_gethtablestat __P((iplookupop_t *, ipf_stack_t *));
81 extern int fr_htable_getnext __P((ipftoken_t *, ipflookupiter_t *, ipf_stack_t *));
82 extern void fr_htable_iterderef __P((u_int, int, void *, ipf_stack_t *));
83 
84 #endif /* __IP_HTABLE_H__ */
85