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-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/errno.h>
30 #include <ipp/ipgpc/classifier.h>
32 /* Implementation file for behavior aggregate (BA) lookup table */
35 * ba_insert(bataid, filter_id, val, mask)
37 * inserts filter_id into element list of bataid->table->masked_values
38 * at position val& mask, mask is inserted into the mask list.
39 * filter_id shouldn't already exist in element list at
40 * bataid->table->masked_values[val], an error message is printed if this
42 * return DONTCARE_VALUE if mask == 0, NORMAL_VALUE otherwise
45 ba_insert(ba_table_id_t
*bataid
, int filter_id
, uint8_t val
, uint8_t mask
)
47 uint8_t mskd_val
= val
& mask
;
48 ba_table_t
*table
= &bataid
->table
;
50 /* dontcares are not inserted */
52 ++bataid
->stats
.num_dontcare
;
53 return (DONTCARE_VALUE
);
56 if (bataid
->info
.dontcareonly
== B_TRUE
) {
57 bataid
->info
.dontcareonly
= B_FALSE
;
60 if (ipgpc_list_insert(&table
->masked_values
[mskd_val
].filter_list
,
61 filter_id
) == EEXIST
) {
62 ipgpc0dbg(("ba_insert():filter_id %d EEXIST in ba_table",
66 (void) ipgpc_list_insert(&table
->masks
, mask
);
68 ++table
->masked_values
[mskd_val
].info
;
69 ++bataid
->stats
.num_inserted
;
71 return (NORMAL_VALUE
);
75 * ba_retrieve(bataid, value, fid_table)
77 * searches for all filters matching value in bataid->table
78 * search is performed by appling each mask in bataid->table->masks list
79 * to value and then looking value up in bataid->table->masked_values.
80 * Each filter id that is matched, is inserted into fid_table
81 * returns number of matched filters or (-1) if memory error
84 ba_retrieve(ba_table_id_t
*bataid
, uint8_t value
, ht_match_t
*fid_table
)
87 element_node_t
*filter_list
;
91 ba_table_t
*table
= &bataid
->table
;
93 /* special case, if value == 0, no need to apply masks */
95 /* masked value will always be 0 for this case */
97 table
->masked_values
[0].filter_list
;
98 if ((num_found
= ipgpc_mark_found(bataid
->info
.mask
,
99 filter_list
, fid_table
)) == -1) {
100 return (-1); /* signifies a memory error */
105 /* apply each mask to the value and do the look up in the ba table */
106 for (p
= table
->masks
; p
!= NULL
; p
= p
->next
) {
107 masked_value
= (uint8_t)(p
->id
) & value
;
108 if (bataid
->table
.masked_values
[masked_value
].info
== 0) {
109 /* masked_value has 0 filters associated with it */
113 table
->masked_values
[masked_value
].filter_list
;
114 if ((ret
= ipgpc_mark_found(bataid
->info
.mask
, filter_list
,
116 return (-1); /* signifies a memory error */
118 num_found
+= ret
; /* increment num_found */
125 * ba_remove(bataid, filter_id, value, mask)
127 * removes filter_id from bataid->table->masked_values[mask & value]
128 * mask is removed from bataid->table->masks if refcnt == 0 for that list
131 ba_remove(ba_table_id_t
*bataid
, int filter_id
, uint8_t value
, uint8_t mask
)
133 uint8_t masked_value
= value
& mask
;
134 ba_table_t
*table
= &bataid
->table
;
136 /* dontcares are not inserted */
138 --bataid
->stats
.num_dontcare
;
142 if (ipgpc_list_remove(&table
->masked_values
[masked_value
].filter_list
,
143 filter_id
) == B_TRUE
) {
145 --table
->masked_values
[masked_value
].info
;
146 --bataid
->stats
.num_inserted
;
148 * check to see if removing this entry will result in
149 * don't cares only inserted in the table
151 if (bataid
->stats
.num_inserted
<= 0) {
152 bataid
->info
.dontcareonly
= B_TRUE
;
154 /* remove mask if refcnt == 0 */
155 (void) ipgpc_list_remove(&table
->masks
, mask
);