1676
|
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 (the "License").
|
|
6 |
* You may not use this file except in compliance with the License.
|
|
7 |
*
|
|
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.
|
|
12 |
*
|
|
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]
|
|
18 |
*
|
|
19 |
* CDDL HEADER END
|
|
20 |
*/
|
|
21 |
/*
|
|
22 |
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
|
|
23 |
* Use is subject to license terms.
|
|
24 |
*/
|
|
25 |
|
|
26 |
#ifndef _LABEL_MACRO_H
|
|
27 |
#define _LABEL_MACRO_H
|
|
28 |
|
|
29 |
#pragma ident "%Z%%M% %I% %E% SMI"
|
|
30 |
|
|
31 |
#include <sys/types.h>
|
|
32 |
|
|
33 |
#ifdef __cplusplus
|
|
34 |
extern "C" {
|
|
35 |
#endif
|
|
36 |
|
|
37 |
/* PRIVATE ONLY TO THE LABEL LIBRARY. DO NOT USE ELSEWHERE */
|
|
38 |
|
|
39 |
/* Actual Binary Label Structure Definitions */
|
|
40 |
|
|
41 |
typedef int16_t _Classification;
|
|
42 |
typedef struct {
|
|
43 |
union {
|
|
44 |
uint8_t class_ar[2];
|
|
45 |
_Classification class_chunk;
|
|
46 |
} class_u;
|
|
47 |
} Classification_t;
|
|
48 |
|
|
49 |
typedef struct {
|
|
50 |
uint32_t c1;
|
|
51 |
uint32_t c2;
|
|
52 |
uint32_t c3;
|
|
53 |
uint32_t c4;
|
|
54 |
uint32_t c5;
|
|
55 |
uint32_t c6;
|
|
56 |
uint32_t c7;
|
|
57 |
uint32_t c8;
|
|
58 |
} Compartments_t;
|
|
59 |
|
|
60 |
typedef struct {
|
|
61 |
uint32_t m1;
|
|
62 |
uint32_t m2;
|
|
63 |
uint32_t m3;
|
|
64 |
uint32_t m4;
|
|
65 |
uint32_t m5;
|
|
66 |
uint32_t m6;
|
|
67 |
uint32_t m7;
|
|
68 |
uint32_t m8;
|
|
69 |
} Markings_t;
|
|
70 |
|
|
71 |
typedef struct _mac_label_impl {
|
|
72 |
uint8_t id; /* Magic to say label type */
|
|
73 |
uint8_t _c_len; /* Number of Compartment words */
|
|
74 |
Classification_t classification;
|
|
75 |
Compartments_t compartments;
|
|
76 |
} _mac_label_impl_t;
|
|
77 |
|
|
78 |
typedef _mac_label_impl_t _blevel_impl_t, /* compatibility */
|
|
79 |
_bslabel_impl_t, /* Sensitivity Label */
|
|
80 |
_bclear_impl_t; /* Clearance */
|
|
81 |
|
|
82 |
typedef struct _binary_information_label_impl { /* Information Label */
|
|
83 |
_mac_label_impl_t binformation_level;
|
|
84 |
Markings_t markings;
|
|
85 |
} _bilabel_impl_t;
|
|
86 |
|
|
87 |
typedef struct _binary_cmw_label_impl { /* CMW Label */
|
|
88 |
_bslabel_impl_t bcl_sensitivity_label;
|
|
89 |
_bilabel_impl_t bcl_information_label;
|
|
90 |
} _bclabel_impl_t;
|
|
91 |
|
|
92 |
typedef struct _binary_level_range_impl { /* Level Range */
|
|
93 |
_mac_label_impl_t lower_bound;
|
|
94 |
_mac_label_impl_t upper_bound;
|
|
95 |
} _brange_impl_t, brange_t;
|
|
96 |
|
|
97 |
/* Label Identifier Types */
|
|
98 |
|
|
99 |
#define SUN_MAC_ID 0x41 /* MAC label, legacy SUN_SL_ID */
|
|
100 |
#define SUN_UCLR_ID 0x49 /* User Clearance, legacy SUN_CLR_ID */
|
|
101 |
|
|
102 |
#define _C_LEN 8 /* number of compartments words */
|
|
103 |
|
|
104 |
/* m_label_t macros */
|
|
105 |
#define _MTYPE(l, t) \
|
|
106 |
(((_mac_label_impl_t *)(l))->id == (t))
|
|
107 |
|
|
108 |
#define _MSETTYPE(l, t) \
|
|
109 |
(((_mac_label_impl_t *)(l))->id = (t))
|
|
110 |
|
|
111 |
#define _MGETTYPE(l) (((_mac_label_impl_t *)(l))->id)
|
|
112 |
|
|
113 |
#define _MEQUAL(l1, l2) \
|
|
114 |
(LCLASS(l1) == LCLASS(l2) && \
|
|
115 |
(l1)->_comps.c1 == (l2)->_comps.c1 && \
|
|
116 |
(l1)->_comps.c2 == (l2)->_comps.c2 && \
|
|
117 |
(l1)->_comps.c3 == (l2)->_comps.c3 && \
|
|
118 |
(l1)->_comps.c4 == (l2)->_comps.c4 && \
|
|
119 |
(l1)->_comps.c5 == (l2)->_comps.c5 && \
|
|
120 |
(l1)->_comps.c6 == (l2)->_comps.c6 && \
|
|
121 |
(l1)->_comps.c7 == (l2)->_comps.c7 && \
|
|
122 |
(l1)->_comps.c8 == (l2)->_comps.c8)
|
|
123 |
|
|
124 |
#define SUN_INVALID_ID 0 /* uninitialized label */
|
|
125 |
#define SUN_CMW_ID 0x83 /* 104 - total bytes in CMW Label */
|
|
126 |
#define SUN_SL_ID 0x41 /* 36 - total bytes in Sensitivity Label */
|
|
127 |
#define SUN_SL_UN 0xF1 /* undefined Sensitivity Label */
|
|
128 |
#define SUN_IL_ID 0x42 /* 68 - total bytes in Information Label */
|
|
129 |
#define SUN_IL_UN 0x73 /* undefined Information Label */
|
|
130 |
#define SUN_CLR_ID 0x49 /* 36 - total bytes in Clearance */
|
|
131 |
#define SUN_CLR_UN 0xF9 /* undefined Clearance */
|
|
132 |
|
|
133 |
#define _bcl_sl bcl_sensitivity_label
|
|
134 |
#define _bcl_il bcl_information_label
|
|
135 |
#define _bslev_il binformation_level
|
|
136 |
|
|
137 |
#define _lclass classification
|
|
138 |
#ifdef _BIG_ENDIAN
|
|
139 |
#define LCLASS(slp) ((slp)->_lclass.class_u.class_chunk)
|
|
140 |
#define LCLASS_SET(slp, l) ((slp)->_lclass.class_u.class_chunk = (l))
|
|
141 |
#else
|
|
142 |
#define LCLASS(slp) \
|
|
143 |
((_Classification)(((slp)->_lclass.class_u.class_ar[0] << 8) | \
|
|
144 |
(slp)->_lclass.class_u.class_ar[1]))
|
|
145 |
#define LCLASS_SET(slp, l) \
|
|
146 |
((slp)->_lclass.class_u.class_ar[0] = (uint8_t)((l)>> 8), \
|
|
147 |
(slp)->_lclass.class_u.class_ar[1] = (uint8_t)(l))
|
|
148 |
#endif /* _BIG_ENDIAN */
|
|
149 |
#define _comps compartments
|
|
150 |
|
|
151 |
#define _iid _bslev_il.id
|
|
152 |
#define _i_c_len _bslev_il._c_len
|
|
153 |
#define _iclass _bslev_il._lclass
|
|
154 |
#ifdef _BIG_ENDIAN
|
|
155 |
#define ICLASS(ilp) ((ilp)->_iclass.class_u.class_chunk)
|
|
156 |
#define ICLASS_SET(ilp, l) ((ilp)->_iclass.class_u.class_chunk = (l))
|
|
157 |
#else
|
|
158 |
#define ICLASS(ilp) \
|
|
159 |
((_Classification)(((ilp)->_iclass.class_u.class_ar[0] << 8) | \
|
|
160 |
(ilp)->_iclass.class_u.class_ar[1]))
|
|
161 |
#define ICLASS_SET(ilp, l) \
|
|
162 |
((ilp)->_iclass.class_u.class_ar[0] = (uint8_t)((l)>> 8), \
|
|
163 |
(ilp)->_iclass.class_u.class_ar[1] = (uint8_t)(l))
|
|
164 |
#endif /* _BIG_ENDIAN */
|
|
165 |
#define _icomps _bslev_il._comps
|
|
166 |
#define _imarks markings
|
|
167 |
|
|
168 |
/* Manifest Constant Values */
|
|
169 |
|
|
170 |
#define LOW_CLASS 0 /* Admin_Low classification value */
|
|
171 |
#define HIGH_CLASS 0x7FFF /* Admin_High classification value */
|
|
172 |
#define EMPTY_SET 0 /* Empty compartments and markings set */
|
|
173 |
#define UNIVERSAL_SET 0xFFFFFFFFU /* Universal compartments and */
|
|
174 |
/* markings set */
|
|
175 |
|
|
176 |
/* Construct initial labels */
|
|
177 |
|
|
178 |
#define _LOW_LABEL(l, t) \
|
|
179 |
((l)->id = t, (l)->_c_len = _C_LEN, LCLASS_SET(l, LOW_CLASS), \
|
|
180 |
(l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \
|
|
181 |
(l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \
|
|
182 |
EMPTY_SET)
|
|
183 |
|
|
184 |
#define _HIGH_LABEL(l, t) \
|
|
185 |
((l)->id = t, (l)->_c_len = _C_LEN, LCLASS_SET(l, HIGH_CLASS), \
|
|
186 |
(l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \
|
|
187 |
(l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \
|
|
188 |
UNIVERSAL_SET)
|
|
189 |
|
|
190 |
/* Macro equivalents */
|
|
191 |
|
|
192 |
/* Is this memory a properly formatted label of type t? */
|
|
193 |
#define BLTYPE(l, t) \
|
|
194 |
((t) == SUN_CMW_ID ? \
|
|
195 |
(((_bclabel_impl_t *)(l))->_bcl_sl.id == SUN_SL_ID || \
|
|
196 |
((_bclabel_impl_t *)(l))->_bcl_sl.id == SUN_SL_UN) && \
|
|
197 |
(((_bclabel_impl_t *)(l))->_bcl_il._iid == SUN_IL_ID || \
|
|
198 |
((_bclabel_impl_t *)(l))->_bcl_il._iid == SUN_IL_UN) : \
|
|
199 |
((_mac_label_impl_t *)(l))->id == (t))
|
|
200 |
|
|
201 |
/* Are the levels of these labels equal? */
|
|
202 |
#define BLEQUAL(l1, l2) \
|
|
203 |
_BLEQUAL((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2))
|
|
204 |
|
|
205 |
#define _BLEQUAL(l1, l2) \
|
|
206 |
(LCLASS(l1) == LCLASS(l2) && \
|
|
207 |
(l1)->_comps.c1 == (l2)->_comps.c1 && \
|
|
208 |
(l1)->_comps.c2 == (l2)->_comps.c2 && \
|
|
209 |
(l1)->_comps.c3 == (l2)->_comps.c3 && \
|
|
210 |
(l1)->_comps.c4 == (l2)->_comps.c4 && \
|
|
211 |
(l1)->_comps.c5 == (l2)->_comps.c5 && \
|
|
212 |
(l1)->_comps.c6 == (l2)->_comps.c6 && \
|
|
213 |
(l1)->_comps.c7 == (l2)->_comps.c7 && \
|
|
214 |
(l1)->_comps.c8 == (l2)->_comps.c8)
|
|
215 |
|
|
216 |
/* Does the level of l1 dominate that of l2? */
|
|
217 |
#define BLDOMINATES(l1, l2) \
|
|
218 |
_BLDOMINATES((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2))
|
|
219 |
|
|
220 |
#define _BLDOMINATES(l1, l2) (LCLASS(l1) >= LCLASS(l2) && \
|
|
221 |
(l2)->_comps.c1 == ((l1)->_comps.c1 & (l2)->_comps.c1) && \
|
|
222 |
(l2)->_comps.c2 == ((l1)->_comps.c2 & (l2)->_comps.c2) && \
|
|
223 |
(l2)->_comps.c3 == ((l1)->_comps.c3 & (l2)->_comps.c3) && \
|
|
224 |
(l2)->_comps.c4 == ((l1)->_comps.c4 & (l2)->_comps.c4) && \
|
|
225 |
(l2)->_comps.c5 == ((l1)->_comps.c5 & (l2)->_comps.c5) && \
|
|
226 |
(l2)->_comps.c6 == ((l1)->_comps.c6 & (l2)->_comps.c6) && \
|
|
227 |
(l2)->_comps.c7 == ((l1)->_comps.c7 & (l2)->_comps.c7) && \
|
|
228 |
(l2)->_comps.c8 == ((l1)->_comps.c8 & (l2)->_comps.c8))
|
|
229 |
|
|
230 |
/* Does the level of l1 strictly dominate that of l2? */
|
|
231 |
#define BLSTRICTDOM(l1, l2) (!BLEQUAL(l1, l2) && BLDOMINATES(l1, l2))
|
|
232 |
|
|
233 |
/* Is the level of l within the range r? */
|
|
234 |
#define BLINRANGE(l, r)\
|
|
235 |
(BLDOMINATES((l), &((r)->lower_bound)) && \
|
|
236 |
BLDOMINATES(&((r)->upper_bound), (l)))
|
|
237 |
|
|
238 |
/* Least Upper Bound level l1 and l2 replacing l1 with the result. */
|
|
239 |
#define BLMAXIMUM(l1, l2) \
|
|
240 |
_BLMAXIMUM((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2))
|
|
241 |
|
|
242 |
#define _BLMAXIMUM(l1, l2)\
|
|
243 |
(((l1)->_lclass = (LCLASS(l1) < LCLASS(l2)) ? \
|
|
244 |
(l2)->_lclass : (l1)->_lclass), \
|
|
245 |
(l1)->_comps.c1 |= (l2)->_comps.c1, \
|
|
246 |
(l1)->_comps.c2 |= (l2)->_comps.c2, \
|
|
247 |
(l1)->_comps.c3 |= (l2)->_comps.c3, \
|
|
248 |
(l1)->_comps.c4 |= (l2)->_comps.c4, \
|
|
249 |
(l1)->_comps.c5 |= (l2)->_comps.c5, \
|
|
250 |
(l1)->_comps.c6 |= (l2)->_comps.c6, \
|
|
251 |
(l1)->_comps.c7 |= (l2)->_comps.c7, \
|
|
252 |
(l1)->_comps.c8 |= (l2)->_comps.c8)
|
|
253 |
|
|
254 |
/* Greatest Lower Bound level l1 and l2 replacing l1 with the result. */
|
|
255 |
#define BLMINIMUM(l1, l2) \
|
|
256 |
_BLMINIMUM((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2))
|
|
257 |
|
|
258 |
#define _BLMINIMUM(l1, l2)\
|
|
259 |
(((l1)->_lclass = (LCLASS(l1) > LCLASS(l2)) ? \
|
|
260 |
(l2)->_lclass : (l1)->_lclass), \
|
|
261 |
(l1)->_comps.c1 &= (l2)->_comps.c1, \
|
|
262 |
(l1)->_comps.c2 &= (l2)->_comps.c2, \
|
|
263 |
(l1)->_comps.c3 &= (l2)->_comps.c3, \
|
|
264 |
(l1)->_comps.c4 &= (l2)->_comps.c4, \
|
|
265 |
(l1)->_comps.c5 &= (l2)->_comps.c5, \
|
|
266 |
(l1)->_comps.c6 &= (l2)->_comps.c6, \
|
|
267 |
(l1)->_comps.c7 &= (l2)->_comps.c7, \
|
|
268 |
(l1)->_comps.c8 &= (l2)->_comps.c8)
|
|
269 |
|
|
270 |
/* Create Manifest Labels */
|
|
271 |
|
|
272 |
/* Write a System_Low CMW Label into this memory. */
|
|
273 |
#define BCLLOW(l) (BSLLOW(BCLTOSL(l)), BILLOW(BCLTOIL(l)))
|
|
274 |
|
|
275 |
/* Write a System_Low Sensitivity Label into this memory. */
|
|
276 |
#define BSLLOW(l) _BSLLOW((_bslabel_impl_t *)(l))
|
|
277 |
|
|
278 |
#define _BSLLOW(l) \
|
|
279 |
((l)->id = SUN_SL_ID, (l)->_c_len = _C_LEN, LCLASS_SET(l, LOW_CLASS), \
|
|
280 |
(l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \
|
|
281 |
(l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \
|
|
282 |
EMPTY_SET)
|
|
283 |
|
|
284 |
/* Write a System_High Sensitivity Label into this memory. */
|
|
285 |
#define BSLHIGH(l) _BSLHIGH((_bslabel_impl_t *)(l))
|
|
286 |
|
|
287 |
#define _BSLHIGH(l) \
|
|
288 |
((l)->id = SUN_SL_ID, (l)->_c_len = _C_LEN, LCLASS_SET(l, HIGH_CLASS), \
|
|
289 |
(l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \
|
|
290 |
(l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \
|
|
291 |
UNIVERSAL_SET)
|
|
292 |
|
|
293 |
/* Write a System_Low Information Label into this memory. */
|
|
294 |
#define BILLOW(l) _BILLOW((_bilabel_impl_t *)(l))
|
|
295 |
|
|
296 |
#define _BILLOW(l) \
|
|
297 |
((l)->_iid = SUN_IL_ID, (l)->_i_c_len = _C_LEN, \
|
|
298 |
ICLASS_SET(l, LOW_CLASS), \
|
|
299 |
(l)->_icomps.c1 = (l)->_icomps.c2 = (l)->_icomps.c3 = \
|
|
300 |
(l)->_icomps.c4 = (l)->_icomps.c5 = (l)->_icomps.c6 = \
|
|
301 |
(l)->_icomps.c7 = (l)->_icomps.c8 = EMPTY_SET, \
|
|
302 |
(l)->_imarks.m1 = (l)->_imarks.m2 = (l)->_imarks.m3 = \
|
|
303 |
(l)->_imarks.m4 = (l)->_imarks.m5 = (l)->_imarks.m6 = \
|
|
304 |
(l)->_imarks.m7 = (l)->_imarks.m8 = EMPTY_SET)
|
|
305 |
|
|
306 |
|
|
307 |
/* Write a System_Low Sensitivity Label into this memory. */
|
|
308 |
#define BCLEARLOW(l) _BCLEARLOW((_bclear_impl_t *)(l))
|
|
309 |
|
|
310 |
#define _BCLEARLOW(c) \
|
|
311 |
((c)->id = SUN_CLR_ID, (c)->_c_len = _C_LEN, \
|
|
312 |
LCLASS_SET(c, LOW_CLASS), \
|
|
313 |
(c)->_comps.c1 = (c)->_comps.c2 = (c)->_comps.c3 = (c)->_comps.c4 = \
|
|
314 |
(c)->_comps.c5 = (c)->_comps.c6 = (c)->_comps.c7 = (c)->_comps.c8 = \
|
|
315 |
EMPTY_SET)
|
|
316 |
|
|
317 |
/* Write a System_High Sensitivity Label into this memory. */
|
|
318 |
#define BCLEARHIGH(l) _BCLEARHIGH((_bclear_impl_t *)(l))
|
|
319 |
|
|
320 |
#define _BCLEARHIGH(c) \
|
|
321 |
((c)->id = SUN_CLR_ID, (c)->_c_len = _C_LEN, \
|
|
322 |
LCLASS_SET(c, HIGH_CLASS), \
|
|
323 |
(c)->_comps.c1 = (c)->_comps.c2 = (c)->_comps.c3 = (c)->_comps.c4 = \
|
|
324 |
(c)->_comps.c5 = (c)->_comps.c6 = (c)->_comps.c7 = (c)->_comps.c8 = \
|
|
325 |
UNIVERSAL_SET)
|
|
326 |
|
|
327 |
/* Write an undefined Sensitivity Label into this memory. */
|
|
328 |
#define BSLUNDEF(l) (((_bslabel_impl_t *)(l))->id = SUN_SL_UN)
|
|
329 |
|
|
330 |
/* Write an undefined Clearance into this memory. */
|
|
331 |
#define BCLEARUNDEF(c) (((_bclear_impl_t *)(c))->id = SUN_CLR_UN)
|
|
332 |
|
|
333 |
/* Retrieve the Sensitivity Label portion of a CMW Label */
|
|
334 |
#define BCLTOSL(l) ((bslabel_t *)&((_bclabel_impl_t *)(l))->_bcl_sl)
|
|
335 |
|
|
336 |
/* Retrieve the Information Label portion of a CMW Label */
|
|
337 |
#define BCLTOIL(l) ((_bilabel_impl_t *)&((_bclabel_impl_t *)(l))->_bcl_il)
|
|
338 |
|
|
339 |
/* Copy the Sensitivity Label portion from a CMW Label */
|
|
340 |
#define GETCSL(l1, l2) \
|
|
341 |
(*((_bslabel_impl_t *)(l1)) = ((_bclabel_impl_t *)(l2))->_bcl_sl)
|
|
342 |
|
|
343 |
/* Replace the Sensitivity Label portion of a CMW Label */
|
|
344 |
#define SETCSL(l1, l2) \
|
|
345 |
(((_bclabel_impl_t *)(l1))->_bcl_sl = *((_bslabel_impl_t *)(l2)))
|
|
346 |
|
|
347 |
/* Set type of this memory to the label type 't' */
|
|
348 |
#define SETBLTYPE(l, t) (((_bclabel_impl_t *)(l))->_bcl_sl.id = (t))
|
|
349 |
|
|
350 |
#define GETBLTYPE(l) (((const _bclabel_impl_t *)(l))->_bcl_sl.id)
|
|
351 |
|
|
352 |
#ifdef __cplusplus
|
|
353 |
}
|
|
354 |
#endif
|
|
355 |
|
|
356 |
#endif /* !_LABEL_MACRO_H */
|