xref: /illumos-gate/usr/src/uts/common/inet/ipf/netinet/ip_htable.h (revision 002c70ff32f5df6f93c15f88d351ce26443e6ee7)
1 /*
2  * Copyright (C) 2003 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
7  * Use is subject to license terms.
8  */
9 
10 #pragma ident	"%Z%%M%	%I%	%E% SMI"
11 
12 #ifndef __IP_HTABLE_H__
13 #define __IP_HTABLE_H__
14 
15 #include "netinet/ip_lookup.h"
16 
17 typedef	struct	iphtent_s	{
18 	struct	iphtent_s	*ipe_next, **ipe_pnext;
19 	struct	iphtent_s	*ipe_snext, **ipe_psnext;
20 	void		*ipe_ptr;
21 	sa_family_t	ipe_family;
22 	i6addr_t	ipe_addr;
23 	i6addr_t	ipe_mask;
24 	int		ipe_ref;
25 	union	{
26 		char	ipeu_char[16];
27 		u_long	ipeu_long;
28 		u_int	ipeu_int;
29 	}ipe_un;
30 } iphtent_t;
31 
32 #define	ipe_value	ipe_un.ipeu_int
33 #define	ipe_group	ipe_un.ipeu_char
34 
35 #define	IPE_HASH_FN(a, m, s)	(((a) * (m)) % (s))
36 
37 
38 typedef	struct	iphtable_s	{
39 	ipfrwlock_t	iph_rwlock;
40 	struct	iphtable_s	*iph_next, **iph_pnext;
41 	struct	iphtent_s	**iph_table;
42 	struct	iphtent_s	*iph_list;
43 	size_t	iph_size;		/* size of hash table */
44 	u_long	iph_seed;		/* hashing seed */
45 	u_32_t	iph_flags;
46 	u_int	iph_unit;		/* IPL_LOG* */
47 	u_int	iph_ref;
48 	u_int	iph_type;		/* lookup or group map  - IPHASH_* */
49 	u_int	iph_masks[4];		/* IPv4 or IPv6 netmasks in use */
50 	char	iph_name[FR_GROUPLEN];	/* hash table number */
51 } iphtable_t;
52 
53 
54 /* iph_type */
55 #define	IPHASH_LOOKUP	0
56 #define	IPHASH_GROUPMAP	1
57 #define	IPHASH_ANON	0x80000000
58 
59 
60 typedef	struct	iphtstat_s	{
61 	iphtable_t	*iphs_tables;
62 	u_long		iphs_numtables;
63 	u_long		iphs_numnodes;
64 	u_long		iphs_nomem;
65 	u_long		iphs_pad[16];
66 } iphtstat_t;
67 
68 
69 extern void fr_htable_unload __P((ipf_stack_t *));
70 extern int fr_newhtable __P((iplookupop_t *, ipf_stack_t *));
71 extern iphtable_t *fr_findhtable __P((int, char *, ipf_stack_t *));
72 extern int fr_removehtable __P((iplookupop_t *, ipf_stack_t *));
73 extern size_t fr_flushhtable __P((iplookupflush_t *, ipf_stack_t *));
74 extern int fr_addhtent __P((iphtable_t *, iphtent_t *, ipf_stack_t *));
75 extern int fr_delhtent __P((iphtable_t *, iphtent_t *, ipf_stack_t *));
76 extern void fr_derefhtable __P((iphtable_t *, ipf_stack_t *));
77 extern void fr_derefhtent __P((iphtent_t *));
78 extern void fr_delhtable __P((iphtable_t *, ipf_stack_t *));
79 extern void *fr_iphmfindgroup __P((void *, int, void *, ipf_stack_t *));
80 extern int fr_iphmfindip __P((void *, int, void *, ipf_stack_t *));
81 extern int fr_gethtablestat __P((iplookupop_t *, ipf_stack_t *));
82 extern int fr_htable_getnext __P((ipftoken_t *, ipflookupiter_t *, ipf_stack_t *));
83 extern void fr_htable_iterderef __P((u_int, int, void *, ipf_stack_t *));
84 
85 #endif /* __IP_HTABLE_H__ */
86