140cb5e5dSvi /*
240cb5e5dSvi  * CDDL HEADER START
340cb5e5dSvi  *
440cb5e5dSvi  * The contents of this file are subject to the terms of the
540cb5e5dSvi  * Common Development and Distribution License (the "License").
640cb5e5dSvi  * You may not use this file except in compliance with the License.
740cb5e5dSvi  *
840cb5e5dSvi  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
940cb5e5dSvi  * or http://www.opensolaris.org/os/licensing.
1040cb5e5dSvi  * See the License for the specific language governing permissions
1140cb5e5dSvi  * and limitations under the License.
1240cb5e5dSvi  *
1340cb5e5dSvi  * When distributing Covered Code, include this CDDL HEADER in each
1440cb5e5dSvi  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1540cb5e5dSvi  * If applicable, add the following below this CDDL HEADER, with the
1640cb5e5dSvi  * fields enclosed by brackets "[]" replaced with your own identifying
1740cb5e5dSvi  * information: Portions Copyright [yyyy] [name of copyright owner]
1840cb5e5dSvi  *
1940cb5e5dSvi  * CDDL HEADER END
2040cb5e5dSvi  */
2140cb5e5dSvi 
2240cb5e5dSvi /*
23*2c2c4183Svi  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
2440cb5e5dSvi  * Use is subject to license terms.
2540cb5e5dSvi  */
2640cb5e5dSvi 
2740cb5e5dSvi #ifndef	_SIP_HASH_H
2840cb5e5dSvi #define	_SIP_HASH_H
2940cb5e5dSvi 
3040cb5e5dSvi #pragma ident	"%Z%%M%	%I%	%E% SMI"
3140cb5e5dSvi 
3240cb5e5dSvi #ifdef	__cplusplus
3340cb5e5dSvi extern "C" {
3440cb5e5dSvi #endif
3540cb5e5dSvi 
3640cb5e5dSvi #include <pthread.h>
3740cb5e5dSvi 
3840cb5e5dSvi /* A prime number */
3940cb5e5dSvi #define	SIP_HASH_SZ	6037
4040cb5e5dSvi 
4140cb5e5dSvi #define	SIP_DIGEST_TO_HASH(digest)					\
4240cb5e5dSvi 	((digest[0] + digest[1] + digest[2] + digest[3] + digest[4] +	\
4340cb5e5dSvi 	digest[5] + digest[6] + digest[7]) % SIP_HASH_SZ)
4440cb5e5dSvi 
4540cb5e5dSvi /* An entry in the hash table, sip_obj is opaque */
4640cb5e5dSvi typedef struct	sip_hash_obj_s {
4740cb5e5dSvi 	void			*sip_obj;
4840cb5e5dSvi 	struct sip_hash_obj_s	*next_obj;
4940cb5e5dSvi 	struct sip_hash_obj_s	*prev_obj;
5040cb5e5dSvi } sip_hash_obj_t;
5140cb5e5dSvi 
5240cb5e5dSvi 
5340cb5e5dSvi /* A hash list in the table */
5440cb5e5dSvi typedef struct sip_hash_s {
5540cb5e5dSvi 	sip_hash_obj_t	*hash_head;
5640cb5e5dSvi 	sip_hash_obj_t	*hash_tail;
5740cb5e5dSvi 	int		hash_count;
5840cb5e5dSvi 	pthread_mutex_t sip_hash_mutex;
5940cb5e5dSvi }sip_hash_t;
6040cb5e5dSvi 
6140cb5e5dSvi int	sip_hash_add(sip_hash_t	*, void *, int);
6240cb5e5dSvi void	*sip_hash_find(sip_hash_t *, void *, int,
6340cb5e5dSvi 	    boolean_t (*)(void *, void *));
6440cb5e5dSvi void	sip_walk_hash(sip_hash_t *, void (*)(void *, void *), void *);
6540cb5e5dSvi void	sip_hash_delete(sip_hash_t *, void *, int,
6640cb5e5dSvi 	    boolean_t (*)(void *, void *, int *));
6740cb5e5dSvi void	sip_hash_init();
6840cb5e5dSvi 
6940cb5e5dSvi #ifdef	__cplusplus
7040cb5e5dSvi }
7140cb5e5dSvi #endif
7240cb5e5dSvi 
7340cb5e5dSvi #endif	/* _SIP_HASH_H */
74