1*40cb5e5dSvi /*
2*40cb5e5dSvi  * CDDL HEADER START
3*40cb5e5dSvi  *
4*40cb5e5dSvi  * The contents of this file are subject to the terms of the
5*40cb5e5dSvi  * Common Development and Distribution License (the "License").
6*40cb5e5dSvi  * You may not use this file except in compliance with the License.
7*40cb5e5dSvi  *
8*40cb5e5dSvi  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*40cb5e5dSvi  * or http://www.opensolaris.org/os/licensing.
10*40cb5e5dSvi  * See the License for the specific language governing permissions
11*40cb5e5dSvi  * and limitations under the License.
12*40cb5e5dSvi  *
13*40cb5e5dSvi  * When distributing Covered Code, include this CDDL HEADER in each
14*40cb5e5dSvi  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*40cb5e5dSvi  * If applicable, add the following below this CDDL HEADER, with the
16*40cb5e5dSvi  * fields enclosed by brackets "[]" replaced with your own identifying
17*40cb5e5dSvi  * information: Portions Copyright [yyyy] [name of copyright owner]
18*40cb5e5dSvi  *
19*40cb5e5dSvi  * CDDL HEADER END
20*40cb5e5dSvi  */
21*40cb5e5dSvi 
22*40cb5e5dSvi /*
23*40cb5e5dSvi  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*40cb5e5dSvi  * Use is subject to license terms.
25*40cb5e5dSvi  */
26*40cb5e5dSvi 
27*40cb5e5dSvi #ifndef	_SIP_HASH_H
28*40cb5e5dSvi #define	_SIP_HASH_H
29*40cb5e5dSvi 
30*40cb5e5dSvi #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*40cb5e5dSvi 
32*40cb5e5dSvi #ifdef	__cplusplus
33*40cb5e5dSvi extern "C" {
34*40cb5e5dSvi #endif
35*40cb5e5dSvi 
36*40cb5e5dSvi #include <stdlib.h>
37*40cb5e5dSvi #include <pthread.h>
38*40cb5e5dSvi #include <sip.h>
39*40cb5e5dSvi 
40*40cb5e5dSvi /* A prime number */
41*40cb5e5dSvi #define	SIP_HASH_SZ	6037
42*40cb5e5dSvi 
43*40cb5e5dSvi #define	SIP_DIGEST_TO_HASH(digest)					\
44*40cb5e5dSvi 	((digest[0] + digest[1] + digest[2] + digest[3] + digest[4] +	\
45*40cb5e5dSvi 	digest[5] + digest[6] + digest[7]) % SIP_HASH_SZ)
46*40cb5e5dSvi 
47*40cb5e5dSvi /* An entry in the hash table, sip_obj is opaque */
48*40cb5e5dSvi typedef struct	sip_hash_obj_s {
49*40cb5e5dSvi 	void			*sip_obj;
50*40cb5e5dSvi 	struct sip_hash_obj_s	*next_obj;
51*40cb5e5dSvi 	struct sip_hash_obj_s	*prev_obj;
52*40cb5e5dSvi } sip_hash_obj_t;
53*40cb5e5dSvi 
54*40cb5e5dSvi 
55*40cb5e5dSvi /* A hash list in the table */
56*40cb5e5dSvi typedef struct sip_hash_s {
57*40cb5e5dSvi 	sip_hash_obj_t	*hash_head;
58*40cb5e5dSvi 	sip_hash_obj_t	*hash_tail;
59*40cb5e5dSvi 	int		hash_count;
60*40cb5e5dSvi 	pthread_mutex_t sip_hash_mutex;
61*40cb5e5dSvi }sip_hash_t;
62*40cb5e5dSvi 
63*40cb5e5dSvi int	sip_hash_add(sip_hash_t	*, void *, int);
64*40cb5e5dSvi void	*sip_hash_find(sip_hash_t *, void *, int,
65*40cb5e5dSvi 	    boolean_t (*)(void *, void *));
66*40cb5e5dSvi void	sip_walk_hash(sip_hash_t *, void (*)(void *, void *), void *);
67*40cb5e5dSvi void	sip_hash_delete(sip_hash_t *, void *, int,
68*40cb5e5dSvi 	    boolean_t (*)(void *, void *, int *));
69*40cb5e5dSvi void	sip_hash_init();
70*40cb5e5dSvi 
71*40cb5e5dSvi #ifdef	__cplusplus
72*40cb5e5dSvi }
73*40cb5e5dSvi #endif
74*40cb5e5dSvi 
75*40cb5e5dSvi #endif	/* _SIP_HASH_H */
76