xref: /illumos-gate/usr/src/uts/common/inet/ipf/netinet/ip_htable.h (revision 9a016c63ca347047a236dff12f0da83aac8981d1)
1 /*
2  * Copyright (C) 2003 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * Copyright 2006 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 	void		*ipe_ptr;
20 	sa_family_t	ipe_family;
21 	i6addr_t	ipe_addr;
22 	i6addr_t	ipe_mask;
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 	size_t	iph_size;		/* size of hash table */
42 	u_long	iph_seed;		/* hashing seed */
43 	u_32_t	iph_flags;
44 	u_int	iph_unit;		/* IPL_LOG* */
45 	u_int	iph_ref;
46 	u_int	iph_type;		/* lookup or group map  - IPHASH_* */
47 	u_int	iph_masks[4];		/* IPv4 or IPv6 netmasks in use */
48 	char	iph_name[FR_GROUPLEN];	/* hash table number */
49 } iphtable_t;
50 
51 
52 /* iph_type */
53 #define	IPHASH_LOOKUP	0
54 #define	IPHASH_GROUPMAP	1
55 #define	IPHASH_ANON	0x80000000
56 
57 
58 typedef	struct	iphtstat_s	{
59 	iphtable_t	*iphs_tables;
60 	u_long		iphs_numtables;
61 	u_long		iphs_numnodes;
62 	u_long		iphs_nomem;
63 	u_long		iphs_pad[16];
64 } iphtstat_t;
65 
66 
67 extern iphtable_t *ipf_htables[IPL_LOGSIZE];
68 
69 extern void fr_htable_unload __P((void));
70 extern int fr_newhtable __P((iplookupop_t *));
71 extern iphtable_t *fr_findhtable __P((int, char *));
72 extern int fr_removehtable __P((iplookupop_t *));
73 extern size_t fr_flushhtable __P((iplookupflush_t *));
74 extern int fr_addhtent __P((iphtable_t *, iphtent_t *));
75 extern int fr_delhtent __P((iphtable_t *, iphtent_t *));
76 extern void fr_derefhtable __P((iphtable_t *));
77 extern void fr_delhtable __P((iphtable_t *));
78 extern void *fr_iphmfindgroup __P((void *, int, void *));
79 extern int fr_iphmfindip __P((void *, int, void *));
80 extern int fr_gethtablestat __P((iplookupop_t *));
81 
82 #endif /* __IP_HTABLE_H__ */
83