17663b816Sml /*
27663b816Sml  * Copyright (C) 2003 by Darren Reed.
37663b816Sml  *
47663b816Sml  * See the IPFILTER.LICENCE file for details on licencing.
57663b816Sml  *
6*de22af4eSJohn Ojemann  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
77663b816Sml  */
87663b816Sml 
97c478bd9Sstevel@tonic-gate #ifndef __IP_HTABLE_H__
107c478bd9Sstevel@tonic-gate #define __IP_HTABLE_H__
117c478bd9Sstevel@tonic-gate 
127c478bd9Sstevel@tonic-gate #include "netinet/ip_lookup.h"
137c478bd9Sstevel@tonic-gate 
147c478bd9Sstevel@tonic-gate typedef	struct	iphtent_s	{
157c478bd9Sstevel@tonic-gate 	struct	iphtent_s	*ipe_next, **ipe_pnext;
16f4b3ec61Sdh 	struct	iphtent_s	*ipe_snext, **ipe_psnext;
177c478bd9Sstevel@tonic-gate 	void		*ipe_ptr;
187663b816Sml 	sa_family_t	ipe_family;
197c478bd9Sstevel@tonic-gate 	i6addr_t	ipe_addr;
207c478bd9Sstevel@tonic-gate 	i6addr_t	ipe_mask;
21*de22af4eSJohn Ojemann 	U_QUAD_T	ipe_hits;
22*de22af4eSJohn Ojemann 	U_QUAD_T	ipe_bytes;
237c478bd9Sstevel@tonic-gate 	int		ipe_ref;
247c478bd9Sstevel@tonic-gate 	union	{
257c478bd9Sstevel@tonic-gate 		char	ipeu_char[16];
267c478bd9Sstevel@tonic-gate 		u_long	ipeu_long;
277c478bd9Sstevel@tonic-gate 		u_int	ipeu_int;
287c478bd9Sstevel@tonic-gate 	}ipe_un;
297c478bd9Sstevel@tonic-gate } iphtent_t;
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #define	ipe_value	ipe_un.ipeu_int
327c478bd9Sstevel@tonic-gate #define	ipe_group	ipe_un.ipeu_char
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #define	IPE_HASH_FN(a, m, s)	(((a) * (m)) % (s))
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate typedef	struct	iphtable_s	{
387c478bd9Sstevel@tonic-gate 	ipfrwlock_t	iph_rwlock;
397c478bd9Sstevel@tonic-gate 	struct	iphtable_s	*iph_next, **iph_pnext;
407c478bd9Sstevel@tonic-gate 	struct	iphtent_s	**iph_table;
41f4b3ec61Sdh 	struct	iphtent_s	*iph_list;
427c478bd9Sstevel@tonic-gate 	size_t	iph_size;		/* size of hash table */
437c478bd9Sstevel@tonic-gate 	u_long	iph_seed;		/* hashing seed */
447c478bd9Sstevel@tonic-gate 	u_32_t	iph_flags;
457c478bd9Sstevel@tonic-gate 	u_int	iph_unit;		/* IPL_LOG* */
467c478bd9Sstevel@tonic-gate 	u_int	iph_ref;
477c478bd9Sstevel@tonic-gate 	u_int	iph_type;		/* lookup or group map  - IPHASH_* */
487663b816Sml 	u_int	iph_masks[4];		/* IPv4 or IPv6 netmasks in use */
497c478bd9Sstevel@tonic-gate 	char	iph_name[FR_GROUPLEN];	/* hash table number */
507c478bd9Sstevel@tonic-gate } iphtable_t;
517c478bd9Sstevel@tonic-gate 
527663b816Sml 
537c478bd9Sstevel@tonic-gate /* iph_type */
547c478bd9Sstevel@tonic-gate #define	IPHASH_LOOKUP	0
557c478bd9Sstevel@tonic-gate #define	IPHASH_GROUPMAP	1
567c478bd9Sstevel@tonic-gate #define	IPHASH_ANON	0x80000000
577c478bd9Sstevel@tonic-gate 
587663b816Sml 
597663b816Sml typedef	struct	iphtstat_s	{
607663b816Sml 	iphtable_t	*iphs_tables;
617663b816Sml 	u_long		iphs_numtables;
627663b816Sml 	u_long		iphs_numnodes;
637663b816Sml 	u_long		iphs_nomem;
647663b816Sml 	u_long		iphs_pad[16];
657663b816Sml } iphtstat_t;
667663b816Sml 
677663b816Sml 
68f4b3ec61Sdh extern void fr_htable_unload __P((ipf_stack_t *));
69f4b3ec61Sdh extern int fr_newhtable __P((iplookupop_t *, ipf_stack_t *));
70f4b3ec61Sdh extern iphtable_t *fr_findhtable __P((int, char *, ipf_stack_t *));
71f4b3ec61Sdh extern int fr_removehtable __P((iplookupop_t *, ipf_stack_t *));
72f4b3ec61Sdh extern size_t fr_flushhtable __P((iplookupflush_t *, ipf_stack_t *));
73f4b3ec61Sdh extern int fr_addhtent __P((iphtable_t *, iphtent_t *, ipf_stack_t *));
74f4b3ec61Sdh extern int fr_delhtent __P((iphtable_t *, iphtent_t *, ipf_stack_t *));
75f4b3ec61Sdh extern void fr_derefhtable __P((iphtable_t *, ipf_stack_t *));
76f4b3ec61Sdh extern void fr_derefhtent __P((iphtent_t *));
77f4b3ec61Sdh extern void fr_delhtable __P((iphtable_t *, ipf_stack_t *));
78f4b3ec61Sdh extern void *fr_iphmfindgroup __P((void *, int, void *, ipf_stack_t *));
79*de22af4eSJohn Ojemann extern int fr_iphmfindip __P((void *, int, void *, fr_info_t *, ipf_stack_t *));
80f4b3ec61Sdh extern int fr_gethtablestat __P((iplookupop_t *, ipf_stack_t *));
81f4b3ec61Sdh extern int fr_htable_getnext __P((ipftoken_t *, ipflookupiter_t *, ipf_stack_t *));
82f4b3ec61Sdh extern void fr_htable_iterderef __P((u_int, int, void *, ipf_stack_t *));
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate #endif /* __IP_HTABLE_H__ */
85