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 #define NMLP_MAX 0x10 98 #define NSLS_MAX 0x4 99 100 typedef _mac_label_impl_t blset_t[NSLS_MAX]; 101 102 /* Label Identifier Types */ 103 104 #define SUN_MAC_ID 0x41 /* MAC label, legacy SUN_SL_ID */ 105 #define SUN_UCLR_ID 0x49 /* User Clearance, legacy SUN_CLR_ID */ 106 107 #define _C_LEN 8 /* number of compartments words */ 108 109 /* m_label_t macros */ 110 #define _MTYPE(l, t) \ 111 (((_mac_label_impl_t *)(l))->id == (t)) 112 113 #define _MSETTYPE(l, t) \ 114 (((_mac_label_impl_t *)(l))->id = (t)) 115 116 #define _MGETTYPE(l) (((_mac_label_impl_t *)(l))->id) 117 118 #define _MEQUAL(l1, l2) \ 119 (LCLASS(l1) == LCLASS(l2) && \ 120 (l1)->_comps.c1 == (l2)->_comps.c1 && \ 121 (l1)->_comps.c2 == (l2)->_comps.c2 && \ 122 (l1)->_comps.c3 == (l2)->_comps.c3 && \ 123 (l1)->_comps.c4 == (l2)->_comps.c4 && \ 124 (l1)->_comps.c5 == (l2)->_comps.c5 && \ 125 (l1)->_comps.c6 == (l2)->_comps.c6 && \ 126 (l1)->_comps.c7 == (l2)->_comps.c7 && \ 127 (l1)->_comps.c8 == (l2)->_comps.c8) 128 129 #define SUN_INVALID_ID 0 /* uninitialized label */ 130 #define SUN_CMW_ID 0x83 /* 104 - total bytes in CMW Label */ 131 #define SUN_SL_ID 0x41 /* 36 - total bytes in Sensitivity Label */ 132 #define SUN_SL_UN 0xF1 /* undefined Sensitivity Label */ 133 #define SUN_IL_ID 0x42 /* 68 - total bytes in Information Label */ 134 #define SUN_IL_UN 0x73 /* undefined Information Label */ 135 #define SUN_CLR_ID 0x49 /* 36 - total bytes in Clearance */ 136 #define SUN_CLR_UN 0xF9 /* undefined Clearance */ 137 138 #define _bcl_sl bcl_sensitivity_label 139 #define _bcl_il bcl_information_label 140 #define _bslev_il binformation_level 141 142 #define _lclass classification 143 #ifdef _BIG_ENDIAN 144 #define LCLASS(slp) ((slp)->_lclass.class_u.class_chunk) 145 #define LCLASS_SET(slp, l) ((slp)->_lclass.class_u.class_chunk = (l)) 146 #else 147 #define LCLASS(slp) \ 148 ((_Classification)(((slp)->_lclass.class_u.class_ar[0] << 8) | \ 149 (slp)->_lclass.class_u.class_ar[1])) 150 #define LCLASS_SET(slp, l) \ 151 ((slp)->_lclass.class_u.class_ar[0] = (uint8_t)((l)>> 8), \ 152 (slp)->_lclass.class_u.class_ar[1] = (uint8_t)(l)) 153 #endif /* _BIG_ENDIAN */ 154 #define _comps compartments 155 156 #define _iid _bslev_il.id 157 #define _i_c_len _bslev_il._c_len 158 #define _iclass _bslev_il._lclass 159 #ifdef _BIG_ENDIAN 160 #define ICLASS(ilp) ((ilp)->_iclass.class_u.class_chunk) 161 #define ICLASS_SET(ilp, l) ((ilp)->_iclass.class_u.class_chunk = (l)) 162 #else 163 #define ICLASS(ilp) \ 164 ((_Classification)(((ilp)->_iclass.class_u.class_ar[0] << 8) | \ 165 (ilp)->_iclass.class_u.class_ar[1])) 166 #define ICLASS_SET(ilp, l) \ 167 ((ilp)->_iclass.class_u.class_ar[0] = (uint8_t)((l)>> 8), \ 168 (ilp)->_iclass.class_u.class_ar[1] = (uint8_t)(l)) 169 #endif /* _BIG_ENDIAN */ 170 #define _icomps _bslev_il._comps 171 #define _imarks markings 172 173 /* Manifest Constant Values */ 174 175 #define LOW_CLASS 0 /* Admin_Low classification value */ 176 #define HIGH_CLASS 0x7FFF /* Admin_High classification value */ 177 #define EMPTY_SET 0 /* Empty compartments and markings set */ 178 #define UNIVERSAL_SET 0xFFFFFFFFU /* Universal compartments and */ 179 /* markings set */ 180 181 /* Construct initial labels */ 182 183 #define _LOW_LABEL(l, t) \ 184 ((l)->id = t, (l)->_c_len = _C_LEN, LCLASS_SET(l, LOW_CLASS), \ 185 (l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \ 186 (l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \ 187 EMPTY_SET) 188 189 #define _HIGH_LABEL(l, t) \ 190 ((l)->id = t, (l)->_c_len = _C_LEN, LCLASS_SET(l, HIGH_CLASS), \ 191 (l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \ 192 (l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \ 193 UNIVERSAL_SET) 194 195 /* Macro equivalents */ 196 197 /* Is this memory a properly formatted label of type t? */ 198 #define BLTYPE(l, t) \ 199 ((t) == SUN_CMW_ID ? \ 200 (((_bclabel_impl_t *)(l))->_bcl_sl.id == SUN_SL_ID || \ 201 ((_bclabel_impl_t *)(l))->_bcl_sl.id == SUN_SL_UN) && \ 202 (((_bclabel_impl_t *)(l))->_bcl_il._iid == SUN_IL_ID || \ 203 ((_bclabel_impl_t *)(l))->_bcl_il._iid == SUN_IL_UN) : \ 204 ((_mac_label_impl_t *)(l))->id == (t)) 205 206 /* Are the levels of these labels equal? */ 207 #define BLEQUAL(l1, l2) \ 208 _BLEQUAL((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2)) 209 210 #define _BLEQUAL(l1, l2) \ 211 (LCLASS(l1) == LCLASS(l2) && \ 212 (l1)->_comps.c1 == (l2)->_comps.c1 && \ 213 (l1)->_comps.c2 == (l2)->_comps.c2 && \ 214 (l1)->_comps.c3 == (l2)->_comps.c3 && \ 215 (l1)->_comps.c4 == (l2)->_comps.c4 && \ 216 (l1)->_comps.c5 == (l2)->_comps.c5 && \ 217 (l1)->_comps.c6 == (l2)->_comps.c6 && \ 218 (l1)->_comps.c7 == (l2)->_comps.c7 && \ 219 (l1)->_comps.c8 == (l2)->_comps.c8) 220 221 /* Does the level of l1 dominate that of l2? */ 222 #define BLDOMINATES(l1, l2) \ 223 _BLDOMINATES((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2)) 224 225 #define _BLDOMINATES(l1, l2) (LCLASS(l1) >= LCLASS(l2) && \ 226 (l2)->_comps.c1 == ((l1)->_comps.c1 & (l2)->_comps.c1) && \ 227 (l2)->_comps.c2 == ((l1)->_comps.c2 & (l2)->_comps.c2) && \ 228 (l2)->_comps.c3 == ((l1)->_comps.c3 & (l2)->_comps.c3) && \ 229 (l2)->_comps.c4 == ((l1)->_comps.c4 & (l2)->_comps.c4) && \ 230 (l2)->_comps.c5 == ((l1)->_comps.c5 & (l2)->_comps.c5) && \ 231 (l2)->_comps.c6 == ((l1)->_comps.c6 & (l2)->_comps.c6) && \ 232 (l2)->_comps.c7 == ((l1)->_comps.c7 & (l2)->_comps.c7) && \ 233 (l2)->_comps.c8 == ((l1)->_comps.c8 & (l2)->_comps.c8)) 234 235 /* Does the level of l1 strictly dominate that of l2? */ 236 #define BLSTRICTDOM(l1, l2) (!BLEQUAL(l1, l2) && BLDOMINATES(l1, l2)) 237 238 /* Is the level of l within the range r? */ 239 #define BLINRANGE(l, r)\ 240 (BLDOMINATES((l), &((r)->lower_bound)) && \ 241 BLDOMINATES(&((r)->upper_bound), (l))) 242 243 /* Least Upper Bound level l1 and l2 replacing l1 with the result. */ 244 #define BLMAXIMUM(l1, l2) \ 245 _BLMAXIMUM((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2)) 246 247 #define _BLMAXIMUM(l1, l2)\ 248 (((l1)->_lclass = (LCLASS(l1) < LCLASS(l2)) ? \ 249 (l2)->_lclass : (l1)->_lclass), \ 250 (l1)->_comps.c1 |= (l2)->_comps.c1, \ 251 (l1)->_comps.c2 |= (l2)->_comps.c2, \ 252 (l1)->_comps.c3 |= (l2)->_comps.c3, \ 253 (l1)->_comps.c4 |= (l2)->_comps.c4, \ 254 (l1)->_comps.c5 |= (l2)->_comps.c5, \ 255 (l1)->_comps.c6 |= (l2)->_comps.c6, \ 256 (l1)->_comps.c7 |= (l2)->_comps.c7, \ 257 (l1)->_comps.c8 |= (l2)->_comps.c8) 258 259 /* Greatest Lower Bound level l1 and l2 replacing l1 with the result. */ 260 #define BLMINIMUM(l1, l2) \ 261 _BLMINIMUM((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2)) 262 263 #define _BLMINIMUM(l1, l2)\ 264 (((l1)->_lclass = (LCLASS(l1) > LCLASS(l2)) ? \ 265 (l2)->_lclass : (l1)->_lclass), \ 266 (l1)->_comps.c1 &= (l2)->_comps.c1, \ 267 (l1)->_comps.c2 &= (l2)->_comps.c2, \ 268 (l1)->_comps.c3 &= (l2)->_comps.c3, \ 269 (l1)->_comps.c4 &= (l2)->_comps.c4, \ 270 (l1)->_comps.c5 &= (l2)->_comps.c5, \ 271 (l1)->_comps.c6 &= (l2)->_comps.c6, \ 272 (l1)->_comps.c7 &= (l2)->_comps.c7, \ 273 (l1)->_comps.c8 &= (l2)->_comps.c8) 274 275 /* Create Manifest Labels */ 276 277 /* Write a System_Low CMW Label into this memory. */ 278 #define BCLLOW(l) (BSLLOW(BCLTOSL(l)), BILLOW(BCLTOIL(l))) 279 280 /* Write a System_Low Sensitivity Label into this memory. */ 281 #define BSLLOW(l) _BSLLOW((_bslabel_impl_t *)(l)) 282 283 #define _BSLLOW(l) \ 284 ((l)->id = SUN_SL_ID, (l)->_c_len = _C_LEN, LCLASS_SET(l, LOW_CLASS), \ 285 (l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \ 286 (l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \ 287 EMPTY_SET) 288 289 /* Write a System_High Sensitivity Label into this memory. */ 290 #define BSLHIGH(l) _BSLHIGH((_bslabel_impl_t *)(l)) 291 292 #define _BSLHIGH(l) \ 293 ((l)->id = SUN_SL_ID, (l)->_c_len = _C_LEN, LCLASS_SET(l, HIGH_CLASS), \ 294 (l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \ 295 (l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \ 296 UNIVERSAL_SET) 297 298 /* Write a System_Low Information Label into this memory. */ 299 #define BILLOW(l) _BILLOW((_bilabel_impl_t *)(l)) 300 301 #define _BILLOW(l) \ 302 ((l)->_iid = SUN_IL_ID, (l)->_i_c_len = _C_LEN, \ 303 ICLASS_SET(l, LOW_CLASS), \ 304 (l)->_icomps.c1 = (l)->_icomps.c2 = (l)->_icomps.c3 = \ 305 (l)->_icomps.c4 = (l)->_icomps.c5 = (l)->_icomps.c6 = \ 306 (l)->_icomps.c7 = (l)->_icomps.c8 = EMPTY_SET, \ 307 (l)->_imarks.m1 = (l)->_imarks.m2 = (l)->_imarks.m3 = \ 308 (l)->_imarks.m4 = (l)->_imarks.m5 = (l)->_imarks.m6 = \ 309 (l)->_imarks.m7 = (l)->_imarks.m8 = EMPTY_SET) 310 311 312 /* Write a System_Low Sensitivity Label into this memory. */ 313 #define BCLEARLOW(l) _BCLEARLOW((_bclear_impl_t *)(l)) 314 315 #define _BCLEARLOW(c) \ 316 ((c)->id = SUN_CLR_ID, (c)->_c_len = _C_LEN, \ 317 LCLASS_SET(c, LOW_CLASS), \ 318 (c)->_comps.c1 = (c)->_comps.c2 = (c)->_comps.c3 = (c)->_comps.c4 = \ 319 (c)->_comps.c5 = (c)->_comps.c6 = (c)->_comps.c7 = (c)->_comps.c8 = \ 320 EMPTY_SET) 321 322 /* Write a System_High Sensitivity Label into this memory. */ 323 #define BCLEARHIGH(l) _BCLEARHIGH((_bclear_impl_t *)(l)) 324 325 #define _BCLEARHIGH(c) \ 326 ((c)->id = SUN_CLR_ID, (c)->_c_len = _C_LEN, \ 327 LCLASS_SET(c, HIGH_CLASS), \ 328 (c)->_comps.c1 = (c)->_comps.c2 = (c)->_comps.c3 = (c)->_comps.c4 = \ 329 (c)->_comps.c5 = (c)->_comps.c6 = (c)->_comps.c7 = (c)->_comps.c8 = \ 330 UNIVERSAL_SET) 331 332 /* Write an undefined Sensitivity Label into this memory. */ 333 #define BSLUNDEF(l) (((_bslabel_impl_t *)(l))->id = SUN_SL_UN) 334 335 /* Write an undefined Clearance into this memory. */ 336 #define BCLEARUNDEF(c) (((_bclear_impl_t *)(c))->id = SUN_CLR_UN) 337 338 /* Retrieve the Sensitivity Label portion of a CMW Label */ 339 #define BCLTOSL(l) ((bslabel_t *)&((_bclabel_impl_t *)(l))->_bcl_sl) 340 341 /* Retrieve the Information Label portion of a CMW Label */ 342 #define BCLTOIL(l) ((_bilabel_impl_t *)&((_bclabel_impl_t *)(l))->_bcl_il) 343 344 /* Copy the Sensitivity Label portion from a CMW Label */ 345 #define GETCSL(l1, l2) \ 346 (*((_bslabel_impl_t *)(l1)) = ((_bclabel_impl_t *)(l2))->_bcl_sl) 347 348 /* Replace the Sensitivity Label portion of a CMW Label */ 349 #define SETCSL(l1, l2) \ 350 (((_bclabel_impl_t *)(l1))->_bcl_sl = *((_bslabel_impl_t *)(l2))) 351 352 /* Set type of this memory to the label type 't' */ 353 #define SETBLTYPE(l, t) (((_bclabel_impl_t *)(l))->_bcl_sl.id = (t)) 354 355 #define GETBLTYPE(l) (((const _bclabel_impl_t *)(l))->_bcl_sl.id) 356 357 #ifdef __cplusplus 358 } 359 #endif 360 361 #endif /* !_LABEL_MACRO_H */ 362