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
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.
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]
23 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _IPP_IPGPC_TRIE_H
28 #define _IPP_IPGPC_TRIE_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <ipp/ipgpc/classifier-objects.h>
39 * Header file for trie data structure used to hold keys of non-exact match
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
48 #define COMPUTE_BIT_POS(len, pos) \
49 (((len - pos - 1) & 0xf8) | (pos & 0x7))
50 #endif /* _LITTLE_ENDIAN */
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
56 #define EXTRACTBIT_CMN(val, pos) ((val >> pos) & 1)
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 */
64 /* sets the bit at position pos of num to 1 if val == 1 */
65 #define SETBIT_CMN(num, pos, val) (num |= (val << pos))
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 */
73 /* sets the bit at position pos of num to 0 */
74 #define UNSETBIT_CMN(num, pos) (num &= (~(1 << pos)))
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 */
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
*);
94 #endif /* _IPP_IPGPC_TRIE_H */