4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * bl.c - Binary label operations for kernel and user.
31 * These routines initialize, compare, set and extract portions
35 #include <sys/tsol/label.h>
36 #include <sys/tsol/label_macro.h>
40 * bltype - Check the type of a label structure.
42 * Entry label = Address of the label to check.
43 * type = Label type to check:
44 * SUN_SL_ID = Sensitivity Label,
45 * SUN_SL_UN = Undefined Sensitivity Label structure,
46 * SUN_IL_ID = Information Label,
47 * SUN_IL_UN = Undefined Information Label structure,
48 * SUN_CLR_ID = Clearance, or
49 * SUN_CLR_UN = Undefined Clearance structure.
53 * Returns True if the label is the type requested,
60 bltype(const void *label
, uint8_t type
)
63 return (BLTYPE(label
, type
));
68 * blequal - Compare two labels for Classification and Compartments set
71 * Entry label1, label2 = label levels to compare.
75 * Returns True if labels equal,
82 blequal(const m_label_t
*label1
, const m_label_t
*label2
)
85 return (BLEQUAL(label1
, label2
));
90 * bldominates - Compare two labels for Classification and Compartments
93 * Entry label1, label2 = labels levels to compare.
97 * Returns True if label1 dominates label2,
104 bldominates(const m_label_t
*label1
, const m_label_t
*label2
)
107 return (BLDOMINATES(label1
, label2
));
112 * blstrictdom - Compare two labels for Classification and Compartments
113 * sets strict dominance.
115 * Entry label1, label2 = labels levels to compare.
119 * Returns True if label1 dominates and is not equal to label2,
126 blstrictdom(const m_label_t
*label1
, const m_label_t
*label2
)
129 return (BLSTRICTDOM(label1
, label2
));
134 * blinrange - Compare a label's classification and compartments set to
135 * be within a lower and upper bound (range).
137 * Entry label = label level to compare.
138 * range = level range to compare against.
142 * Returns True if label is within the range,
149 blinrange(const m_label_t
*label
, const m_range_t
*range
)
151 return (BLDOMINATES((label
), ((range
)->lower_bound
)) &&
152 BLDOMINATES(((range
)->upper_bound
), (label
)));
156 * This is the TS8 version which is used in the kernel
160 _blinrange(const m_label_t
*label
, const brange_t
*range
)
162 return (BLINRANGE(label
, range
));
167 * blinlset - Check if the label belongs to the set
169 * Entry label = label level to compare.
170 * lset = label set to compare against.
174 * Returns True if label is an element of the set,
180 blinlset(const m_label_t
*label
, const blset_t lset
)
184 for (i
= 0; i
< NSLS_MAX
; i
++) {
185 if (!BLTYPE(&lset
[i
], SUN_SL_ID
))
187 if (BLEQUAL(label
, &lset
[i
]))
196 * blmaximum - Least Upper Bound of two levels.
198 * Entry label1, label2 = levels to bound.
200 * Exit label1 replaced by the LUB of label1 and label2.
208 blmaximum(m_label_t
*label1
, const m_label_t
*label2
)
211 BLMAXIMUM(label1
, label2
);
216 * blminimum - Greatest Lower Bound of two levels.
218 * Entry label1, label2 = levels to bound.
220 * Exit label1 replaced by the GLB of label1 and label2.
228 blminimum(m_label_t
*label1
, const m_label_t
*label2
)
231 BLMINIMUM(label1
, label2
);
236 * bsllow - Initialize an admin_low Sensitivity Label.
238 * Entry label = Sensitivity Label structure to be initialized.
240 * Exit label = Initialized to the admin_low Sensitivity Label.
248 bsllow(bslabel_t
*label
)
256 * bslhigh - Initialize an admin_high Sensitivity Label.
258 * Entry label = Sensitivity Label structure to be initialized.
260 * Exit label = Initialized to the admin_high Sensitivity Label.
268 bslhigh(bslabel_t
*label
)
275 * bclearlow - Initialize an admin_low Clearance.
277 * Entry clearance = Clearnace structure to be initialized.
279 * Exit clearance = Initialized to the admin_low Clearance.
287 bclearlow(bclear_t
*clearance
)
290 BCLEARLOW(clearance
);
295 * bclearhigh - Initialize an admin_high Clearance.
297 * Entry clearance = Clearance structure to be initialized.
299 * Exit clearance = Initialized to the admin_high Clearance.
307 bclearhigh(bclear_t
*clearance
)
310 BCLEARHIGH(clearance
);
314 * bslundef - Initialize an undefined Sensitivity Label.
316 * Entry label = Sensitivity Label structure to be initialized.
318 * Exit label = Initialized to undefined Sensitivity Label.
326 bslundef(bslabel_t
*label
)
334 * bclearundef - Initialize an undefined Clearance.
336 * Entry clearance = Clearance structure to be initialized.
338 * Exit clearance = Initialized to undefined Clearance.
346 bclearundef(bclear_t
*clearance
)
349 BCLEARUNDEF(clearance
);
354 * setbltype - Set the type of a label structure.
356 * Entry label = Address of the label to set.
357 * type = Label type to set:
358 * SUN_SL_ID = Sensitivity Label,
359 * SUN_SL_UN = Undefined Sensitivity Label structure,
360 * SUN_IL_ID = Information Label,
361 * SUN_IL_UN = Undefined Information Label structure,
362 * SUN_CLR_ID = Clearance, or
363 * SUN_CLR_UN = Undefined Clearance structure.
365 * Exit label = Type set to specified type.
373 setbltype(void *label
, uint8_t type
)
376 SETBLTYPE(label
, type
);
380 * Returns B_TRUE if the label is invalid (initialized to all zeros).
383 bisinvalid(const void *label
)
385 return (GETBLTYPE(label
) == SUN_INVALID_ID
);