8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / common / tsol / blabel.c
blob114ef6afa803279fbe7ac40f4b8ed4329f4db4d3
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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
32 * of binary labels.
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.
51 * Exit None.
53 * Returns True if the label is the type requested,
54 * otherwise false.
56 * Calls BLTYPE.
59 int
60 bltype(const void *label, uint8_t type)
63 return (BLTYPE(label, type));
68 * blequal - Compare two labels for Classification and Compartments set
69 * equality.
71 * Entry label1, label2 = label levels to compare.
73 * Exit None.
75 * Returns True if labels equal,
76 * otherwise false.
78 * Calls BLEQUAL.
81 int
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
91 * sets dominance.
93 * Entry label1, label2 = labels levels to compare.
95 * Exit None.
97 * Returns True if label1 dominates label2,
98 * otherwise false.
100 * Calls BLDOMINATES.
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.
117 * Exit None.
119 * Returns True if label1 dominates and is not equal to label2,
120 * otherwise false.
122 * Calls BLSTRICTDOM.
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.
140 * Exit None.
142 * Returns True if label is within the range,
143 * otherwise false.
145 * Calls BLINRANGE.
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));
165 #ifdef _KERNEL
167 * blinlset - Check if the label belongs to the set
169 * Entry label = label level to compare.
170 * lset = label set to compare against.
172 * Exit None.
174 * Returns True if label is an element of the set,
175 * otherwise false.
180 blinlset(const m_label_t *label, const blset_t lset)
182 int i;
184 for (i = 0; i < NSLS_MAX; i++) {
185 if (!BLTYPE(&lset[i], SUN_SL_ID))
186 return (B_FALSE);
187 if (BLEQUAL(label, &lset[i]))
188 return (B_TRUE);
190 return (B_FALSE);
192 #endif /* _KERNEL */
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.
202 * Returns None.
204 * Calls BLMAXIMUM.
207 void
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.
222 * Returns None.
224 * Calls BLMINIMUM.
227 void
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.
242 * Returns None.
244 * Calls BSLLOW.
247 void
248 bsllow(bslabel_t *label)
251 BSLLOW(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.
262 * Returns None.
264 * Calls BSLHIGH.
267 void
268 bslhigh(bslabel_t *label)
271 BSLHIGH(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.
281 * Returns None.
283 * Calls BCLEARLOW.
286 void
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.
301 * Returns None.
303 * Calls BCLEARHIGH.
306 void
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.
320 * Returns None.
322 * Calls BSLUNDEF.
325 void
326 bslundef(bslabel_t *label)
329 BSLUNDEF(label);
334 * bclearundef - Initialize an undefined Clearance.
336 * Entry clearance = Clearance structure to be initialized.
338 * Exit clearance = Initialized to undefined Clearance.
340 * Returns None.
342 * Calls BCLEARUNDEF.
345 void
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.
367 * Returns None.
369 * Calls SETBLTYPE.
372 void
373 setbltype(void *label, uint8_t type)
376 SETBLTYPE(label, type);
380 * Returns B_TRUE if the label is invalid (initialized to all zeros).
382 boolean_t
383 bisinvalid(const void *label)
385 return (GETBLTYPE(label) == SUN_INVALID_ID);