xref: /titanic_41/usr/src/uts/common/ipp/ipgpc/trie.h (revision 8d483882aa3390058094b043f3d62187b5d1de03)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _IPP_IPGPC_TRIE_H
28 #define	_IPP_IPGPC_TRIE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <ipp/ipgpc/classifier-objects.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * Header file for trie data structure used to hold keys of non-exact match
40  * selectors
41  */
42 
43 #ifdef	_LITTLE_ENDIAN
44 /*
45  * given the length of a key, and the desired bit position, compute the
46  * correct bit position assuming and NBO key on a _LITTLE_ENDIAN machine
47  */
48 #define	COMPUTE_BIT_POS(len, pos) \
49 	(((len - pos - 1) & 0xf8) | (pos & 0x7))
50 #endif /* _LITTLE_ENDIAN */
51 
52 /*
53  * extracts a single bit at position pos from a given value, val, for an
54  * unsigned integer of length len.  len will be equal to either 16 or 32
55  */
56 #define	EXTRACTBIT_CMN(val, pos)	((val >> pos) & 1)
57 #ifdef	_BIG_ENDIAN
58 #define	EXTRACTBIT(val, pos, len)	(EXTRACTBIT_CMN(val, pos))
59 #else  /* _LITTLE_ENDIAN */
60 #define	EXTRACTBIT(val, pos, len) \
61 	(EXTRACTBIT_CMN(val, (COMPUTE_BIT_POS(len, pos))))
62 #endif /* _BIG_ENDIAN */
63 
64 /* sets the bit at position pos of num to 1 if val == 1 */
65 #define	SETBIT_CMN(num, pos, val)	(num |= (val << pos))
66 #ifdef	_BIG_ENDIAN
67 #define	SETBIT(num, pos, val, len)	(SETBIT_CMN(num, pos, val))
68 #else  /* _LITTLE_ENDIAN */
69 #define	SETBIT(num, pos, val, len) \
70 	(SETBIT_CMN(num, (COMPUTE_BIT_POS(len, pos)), val))
71 #endif /* _BIG_ENDIAN */
72 
73 /* sets the bit at position pos of num to 0 */
74 #define	UNSETBIT_CMN(num, pos)	(num &= (~(1 << pos)))
75 #ifdef	_BIG_ENDIAN
76 #define	UNSETBIT(num, pos, len)	(UNSETBIT_CMN(num, pos))
77 #else  /* _LITTLE_ENDIAN */
78 #define	UNSETBIT(num, pos, len) \
79 	(UNSETBIT_CMN(num, (COMPUTE_BIT_POS(len, pos))))
80 #endif /* _BIG_ENDIAN */
81 
82 extern node_t *create_node(int);
83 extern int t_insert(trie_id_t *, key_t, uint32_t, uint32_t);
84 extern int t_insert6(trie_id_t *, key_t, in6_addr_t, in6_addr_t);
85 extern void t_remove(trie_id_t *, key_t, uint32_t, uint32_t);
86 extern void t_remove6(trie_id_t *, key_t, in6_addr_t, in6_addr_t);
87 extern int t_retrieve(trie_id_t *, uint32_t, ht_match_t *);
88 extern int t_retrieve6(trie_id_t *, in6_addr_t, ht_match_t *);
89 
90 #ifdef	__cplusplus
91 }
92 #endif
93 
94 #endif	/* _IPP_IPGPC_TRIE_H */
95