1 /*
2  * Copyright (C) 2003 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * Copyright 2005 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 #if SOLARIS2 >= 10
16 #include "ip_lookup.h"
17 #else
18 #include "netinet/ip_lookup.h"
19 #endif
20 
21 typedef	struct	iphtent_s	{
22 	struct	iphtent_s	*ipe_next, **ipe_pnext;
23 	void		*ipe_ptr;
24 	sa_family_t	ipe_family;
25 	i6addr_t	ipe_addr;
26 	i6addr_t	ipe_mask;
27 	int		ipe_ref;
28 	union	{
29 		char	ipeu_char[16];
30 		u_long	ipeu_long;
31 		u_int	ipeu_int;
32 	}ipe_un;
33 } iphtent_t;
34 
35 #define	ipe_value	ipe_un.ipeu_int
36 #define	ipe_group	ipe_un.ipeu_char
37 
38 #define	IPE_HASH_FN(a, m, s)	(((a) * (m)) % (s))
39 
40 
41 typedef	struct	iphtable_s	{
42 	ipfrwlock_t	iph_rwlock;
43 	struct	iphtable_s	*iph_next, **iph_pnext;
44 	struct	iphtent_s	**iph_table;
45 	size_t	iph_size;		/* size of hash table */
46 	u_long	iph_seed;		/* hashing seed */
47 	u_32_t	iph_flags;
48 	u_int	iph_unit;		/* IPL_LOG* */
49 	u_int	iph_ref;
50 	u_int	iph_type;		/* lookup or group map  - IPHASH_* */
51 	u_int	iph_masks[4];		/* IPv4 or IPv6 netmasks in use */
52 	char	iph_name[FR_GROUPLEN];	/* hash table number */
53 } iphtable_t;
54 
55 
56 /* iph_type */
57 #define	IPHASH_LOOKUP	0
58 #define	IPHASH_GROUPMAP	1
59 #define	IPHASH_ANON	0x80000000
60 
61 
62 typedef	struct	iphtstat_s	{
63 	iphtable_t	*iphs_tables;
64 	u_long		iphs_numtables;
65 	u_long		iphs_numnodes;
66 	u_long		iphs_nomem;
67 	u_long		iphs_pad[16];
68 } iphtstat_t;
69 
70 
71 extern iphtable_t *ipf_htables[IPL_LOGSIZE];
72 
73 extern void fr_htable_unload __P((void));
74 extern int fr_newhtable __P((iplookupop_t *));
75 extern iphtable_t *fr_findhtable __P((int, char *));
76 extern int fr_removehtable __P((iplookupop_t *));
77 extern size_t fr_flushhtable __P((iplookupflush_t *));
78 extern int fr_addhtent __P((iphtable_t *, iphtent_t *));
79 extern int fr_delhtent __P((iphtable_t *, iphtent_t *));
80 extern void fr_derefhtable __P((iphtable_t *));
81 extern void fr_delhtable __P((iphtable_t *));
82 extern void *fr_iphmfindgroup __P((void *, int, void *));
83 extern int fr_iphmfindip __P((void *, int, void *));
84 extern int fr_gethtablestat __P((iplookupop_t *));
85 
86 #endif /* __IP_HTABLE_H__ */
87