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 #include <ipp/ipgpc/classifier-objects.h> 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 /* 37 * Header file for trie data structure used to hold keys of non-exact match 38 * selectors 39 */ 40 41 #ifdef _LITTLE_ENDIAN 42 /* 43 * given the length of a key, and the desired bit position, compute the 44 * correct bit position assuming and NBO key on a _LITTLE_ENDIAN machine 45 */ 46 #define COMPUTE_BIT_POS(len, pos) \ 47 (((len - pos - 1) & 0xf8) | (pos & 0x7)) 48 #endif /* _LITTLE_ENDIAN */ 49 50 /* 51 * extracts a single bit at position pos from a given value, val, for an 52 * unsigned integer of length len. len will be equal to either 16 or 32 53 */ 54 #define EXTRACTBIT_CMN(val, pos) ((val >> pos) & 1) 55 #ifdef _BIG_ENDIAN 56 #define EXTRACTBIT(val, pos, len) (EXTRACTBIT_CMN(val, pos)) 57 #else /* _LITTLE_ENDIAN */ 58 #define EXTRACTBIT(val, pos, len) \ 59 (EXTRACTBIT_CMN(val, (COMPUTE_BIT_POS(len, pos)))) 60 #endif /* _BIG_ENDIAN */ 61 62 /* sets the bit at position pos of num to 1 if val == 1 */ 63 #define SETBIT_CMN(num, pos, val) (num |= (val << pos)) 64 #ifdef _BIG_ENDIAN 65 #define SETBIT(num, pos, val, len) (SETBIT_CMN(num, pos, val)) 66 #else /* _LITTLE_ENDIAN */ 67 #define SETBIT(num, pos, val, len) \ 68 (SETBIT_CMN(num, (COMPUTE_BIT_POS(len, pos)), val)) 69 #endif /* _BIG_ENDIAN */ 70 71 /* sets the bit at position pos of num to 0 */ 72 #define UNSETBIT_CMN(num, pos) (num &= (~(1 << pos))) 73 #ifdef _BIG_ENDIAN 74 #define UNSETBIT(num, pos, len) (UNSETBIT_CMN(num, pos)) 75 #else /* _LITTLE_ENDIAN */ 76 #define UNSETBIT(num, pos, len) \ 77 (UNSETBIT_CMN(num, (COMPUTE_BIT_POS(len, pos)))) 78 #endif /* _BIG_ENDIAN */ 79 80 extern node_t *create_node(int); 81 extern int t_insert(trie_id_t *, key_t, uint32_t, uint32_t); 82 extern int t_insert6(trie_id_t *, key_t, in6_addr_t, in6_addr_t); 83 extern void t_remove(trie_id_t *, key_t, uint32_t, uint32_t); 84 extern void t_remove6(trie_id_t *, key_t, in6_addr_t, in6_addr_t); 85 extern int t_retrieve(trie_id_t *, uint32_t, ht_match_t *); 86 extern int t_retrieve6(trie_id_t *, in6_addr_t, ht_match_t *); 87 88 #ifdef __cplusplus 89 } 90 #endif 91 92 #endif /* _IPP_IPGPC_TRIE_H */ 93