11676Sjpk /* 21676Sjpk * CDDL HEADER START 31676Sjpk * 41676Sjpk * The contents of this file are subject to the terms of the 51676Sjpk * Common Development and Distribution License (the "License"). 61676Sjpk * You may not use this file except in compliance with the License. 71676Sjpk * 81676Sjpk * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91676Sjpk * or http://www.opensolaris.org/os/licensing. 101676Sjpk * See the License for the specific language governing permissions 111676Sjpk * and limitations under the License. 121676Sjpk * 131676Sjpk * When distributing Covered Code, include this CDDL HEADER in each 141676Sjpk * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151676Sjpk * If applicable, add the following below this CDDL HEADER, with the 161676Sjpk * fields enclosed by brackets "[]" replaced with your own identifying 171676Sjpk * information: Portions Copyright [yyyy] [name of copyright owner] 181676Sjpk * 191676Sjpk * CDDL HEADER END 201676Sjpk */ 211676Sjpk /* 221676Sjpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 231676Sjpk * Use is subject to license terms. 241676Sjpk */ 251676Sjpk 261676Sjpk #ifndef _LABEL_MACRO_H 271676Sjpk #define _LABEL_MACRO_H 281676Sjpk 291676Sjpk #pragma ident "%Z%%M% %I% %E% SMI" 301676Sjpk 311676Sjpk #include <sys/types.h> 321676Sjpk 331676Sjpk #ifdef __cplusplus 341676Sjpk extern "C" { 351676Sjpk #endif 361676Sjpk 371676Sjpk /* PRIVATE ONLY TO THE LABEL LIBRARY. DO NOT USE ELSEWHERE */ 381676Sjpk 391676Sjpk /* Actual Binary Label Structure Definitions */ 401676Sjpk 411676Sjpk typedef int16_t _Classification; 421676Sjpk typedef struct { 431676Sjpk union { 441676Sjpk uint8_t class_ar[2]; 451676Sjpk _Classification class_chunk; 461676Sjpk } class_u; 471676Sjpk } Classification_t; 481676Sjpk 491676Sjpk typedef struct { 501676Sjpk uint32_t c1; 511676Sjpk uint32_t c2; 521676Sjpk uint32_t c3; 531676Sjpk uint32_t c4; 541676Sjpk uint32_t c5; 551676Sjpk uint32_t c6; 561676Sjpk uint32_t c7; 571676Sjpk uint32_t c8; 581676Sjpk } Compartments_t; 591676Sjpk 601676Sjpk typedef struct { 611676Sjpk uint32_t m1; 621676Sjpk uint32_t m2; 631676Sjpk uint32_t m3; 641676Sjpk uint32_t m4; 651676Sjpk uint32_t m5; 661676Sjpk uint32_t m6; 671676Sjpk uint32_t m7; 681676Sjpk uint32_t m8; 691676Sjpk } Markings_t; 701676Sjpk 711676Sjpk typedef struct _mac_label_impl { 721676Sjpk uint8_t id; /* Magic to say label type */ 731676Sjpk uint8_t _c_len; /* Number of Compartment words */ 741676Sjpk Classification_t classification; 751676Sjpk Compartments_t compartments; 761676Sjpk } _mac_label_impl_t; 771676Sjpk 781676Sjpk typedef _mac_label_impl_t _blevel_impl_t, /* compatibility */ 791676Sjpk _bslabel_impl_t, /* Sensitivity Label */ 801676Sjpk _bclear_impl_t; /* Clearance */ 811676Sjpk 821676Sjpk typedef struct _binary_information_label_impl { /* Information Label */ 831676Sjpk _mac_label_impl_t binformation_level; 841676Sjpk Markings_t markings; 851676Sjpk } _bilabel_impl_t; 861676Sjpk 871676Sjpk typedef struct _binary_cmw_label_impl { /* CMW Label */ 881676Sjpk _bslabel_impl_t bcl_sensitivity_label; 891676Sjpk _bilabel_impl_t bcl_information_label; 901676Sjpk } _bclabel_impl_t; 911676Sjpk 921676Sjpk typedef struct _binary_level_range_impl { /* Level Range */ 931676Sjpk _mac_label_impl_t lower_bound; 941676Sjpk _mac_label_impl_t upper_bound; 951676Sjpk } _brange_impl_t, brange_t; 961676Sjpk 97*1688Srica #define NMLP_MAX 0x10 98*1688Srica #define NSLS_MAX 0x4 99*1688Srica 100*1688Srica typedef _mac_label_impl_t blset_t[NSLS_MAX]; 101*1688Srica 1021676Sjpk /* Label Identifier Types */ 1031676Sjpk 1041676Sjpk #define SUN_MAC_ID 0x41 /* MAC label, legacy SUN_SL_ID */ 1051676Sjpk #define SUN_UCLR_ID 0x49 /* User Clearance, legacy SUN_CLR_ID */ 1061676Sjpk 1071676Sjpk #define _C_LEN 8 /* number of compartments words */ 1081676Sjpk 1091676Sjpk /* m_label_t macros */ 1101676Sjpk #define _MTYPE(l, t) \ 1111676Sjpk (((_mac_label_impl_t *)(l))->id == (t)) 1121676Sjpk 1131676Sjpk #define _MSETTYPE(l, t) \ 1141676Sjpk (((_mac_label_impl_t *)(l))->id = (t)) 1151676Sjpk 1161676Sjpk #define _MGETTYPE(l) (((_mac_label_impl_t *)(l))->id) 1171676Sjpk 1181676Sjpk #define _MEQUAL(l1, l2) \ 1191676Sjpk (LCLASS(l1) == LCLASS(l2) && \ 1201676Sjpk (l1)->_comps.c1 == (l2)->_comps.c1 && \ 1211676Sjpk (l1)->_comps.c2 == (l2)->_comps.c2 && \ 1221676Sjpk (l1)->_comps.c3 == (l2)->_comps.c3 && \ 1231676Sjpk (l1)->_comps.c4 == (l2)->_comps.c4 && \ 1241676Sjpk (l1)->_comps.c5 == (l2)->_comps.c5 && \ 1251676Sjpk (l1)->_comps.c6 == (l2)->_comps.c6 && \ 1261676Sjpk (l1)->_comps.c7 == (l2)->_comps.c7 && \ 1271676Sjpk (l1)->_comps.c8 == (l2)->_comps.c8) 1281676Sjpk 1291676Sjpk #define SUN_INVALID_ID 0 /* uninitialized label */ 1301676Sjpk #define SUN_CMW_ID 0x83 /* 104 - total bytes in CMW Label */ 1311676Sjpk #define SUN_SL_ID 0x41 /* 36 - total bytes in Sensitivity Label */ 1321676Sjpk #define SUN_SL_UN 0xF1 /* undefined Sensitivity Label */ 1331676Sjpk #define SUN_IL_ID 0x42 /* 68 - total bytes in Information Label */ 1341676Sjpk #define SUN_IL_UN 0x73 /* undefined Information Label */ 1351676Sjpk #define SUN_CLR_ID 0x49 /* 36 - total bytes in Clearance */ 1361676Sjpk #define SUN_CLR_UN 0xF9 /* undefined Clearance */ 1371676Sjpk 1381676Sjpk #define _bcl_sl bcl_sensitivity_label 1391676Sjpk #define _bcl_il bcl_information_label 1401676Sjpk #define _bslev_il binformation_level 1411676Sjpk 1421676Sjpk #define _lclass classification 1431676Sjpk #ifdef _BIG_ENDIAN 1441676Sjpk #define LCLASS(slp) ((slp)->_lclass.class_u.class_chunk) 1451676Sjpk #define LCLASS_SET(slp, l) ((slp)->_lclass.class_u.class_chunk = (l)) 1461676Sjpk #else 1471676Sjpk #define LCLASS(slp) \ 1481676Sjpk ((_Classification)(((slp)->_lclass.class_u.class_ar[0] << 8) | \ 1491676Sjpk (slp)->_lclass.class_u.class_ar[1])) 1501676Sjpk #define LCLASS_SET(slp, l) \ 1511676Sjpk ((slp)->_lclass.class_u.class_ar[0] = (uint8_t)((l)>> 8), \ 1521676Sjpk (slp)->_lclass.class_u.class_ar[1] = (uint8_t)(l)) 1531676Sjpk #endif /* _BIG_ENDIAN */ 1541676Sjpk #define _comps compartments 1551676Sjpk 1561676Sjpk #define _iid _bslev_il.id 1571676Sjpk #define _i_c_len _bslev_il._c_len 1581676Sjpk #define _iclass _bslev_il._lclass 1591676Sjpk #ifdef _BIG_ENDIAN 1601676Sjpk #define ICLASS(ilp) ((ilp)->_iclass.class_u.class_chunk) 1611676Sjpk #define ICLASS_SET(ilp, l) ((ilp)->_iclass.class_u.class_chunk = (l)) 1621676Sjpk #else 1631676Sjpk #define ICLASS(ilp) \ 1641676Sjpk ((_Classification)(((ilp)->_iclass.class_u.class_ar[0] << 8) | \ 1651676Sjpk (ilp)->_iclass.class_u.class_ar[1])) 1661676Sjpk #define ICLASS_SET(ilp, l) \ 1671676Sjpk ((ilp)->_iclass.class_u.class_ar[0] = (uint8_t)((l)>> 8), \ 1681676Sjpk (ilp)->_iclass.class_u.class_ar[1] = (uint8_t)(l)) 1691676Sjpk #endif /* _BIG_ENDIAN */ 1701676Sjpk #define _icomps _bslev_il._comps 1711676Sjpk #define _imarks markings 1721676Sjpk 1731676Sjpk /* Manifest Constant Values */ 1741676Sjpk 1751676Sjpk #define LOW_CLASS 0 /* Admin_Low classification value */ 1761676Sjpk #define HIGH_CLASS 0x7FFF /* Admin_High classification value */ 1771676Sjpk #define EMPTY_SET 0 /* Empty compartments and markings set */ 1781676Sjpk #define UNIVERSAL_SET 0xFFFFFFFFU /* Universal compartments and */ 1791676Sjpk /* markings set */ 1801676Sjpk 1811676Sjpk /* Construct initial labels */ 1821676Sjpk 1831676Sjpk #define _LOW_LABEL(l, t) \ 1841676Sjpk ((l)->id = t, (l)->_c_len = _C_LEN, LCLASS_SET(l, LOW_CLASS), \ 1851676Sjpk (l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \ 1861676Sjpk (l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \ 1871676Sjpk EMPTY_SET) 1881676Sjpk 1891676Sjpk #define _HIGH_LABEL(l, t) \ 1901676Sjpk ((l)->id = t, (l)->_c_len = _C_LEN, LCLASS_SET(l, HIGH_CLASS), \ 1911676Sjpk (l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \ 1921676Sjpk (l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \ 1931676Sjpk UNIVERSAL_SET) 1941676Sjpk 1951676Sjpk /* Macro equivalents */ 1961676Sjpk 1971676Sjpk /* Is this memory a properly formatted label of type t? */ 1981676Sjpk #define BLTYPE(l, t) \ 1991676Sjpk ((t) == SUN_CMW_ID ? \ 2001676Sjpk (((_bclabel_impl_t *)(l))->_bcl_sl.id == SUN_SL_ID || \ 2011676Sjpk ((_bclabel_impl_t *)(l))->_bcl_sl.id == SUN_SL_UN) && \ 2021676Sjpk (((_bclabel_impl_t *)(l))->_bcl_il._iid == SUN_IL_ID || \ 2031676Sjpk ((_bclabel_impl_t *)(l))->_bcl_il._iid == SUN_IL_UN) : \ 2041676Sjpk ((_mac_label_impl_t *)(l))->id == (t)) 2051676Sjpk 2061676Sjpk /* Are the levels of these labels equal? */ 2071676Sjpk #define BLEQUAL(l1, l2) \ 2081676Sjpk _BLEQUAL((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2)) 2091676Sjpk 2101676Sjpk #define _BLEQUAL(l1, l2) \ 2111676Sjpk (LCLASS(l1) == LCLASS(l2) && \ 2121676Sjpk (l1)->_comps.c1 == (l2)->_comps.c1 && \ 2131676Sjpk (l1)->_comps.c2 == (l2)->_comps.c2 && \ 2141676Sjpk (l1)->_comps.c3 == (l2)->_comps.c3 && \ 2151676Sjpk (l1)->_comps.c4 == (l2)->_comps.c4 && \ 2161676Sjpk (l1)->_comps.c5 == (l2)->_comps.c5 && \ 2171676Sjpk (l1)->_comps.c6 == (l2)->_comps.c6 && \ 2181676Sjpk (l1)->_comps.c7 == (l2)->_comps.c7 && \ 2191676Sjpk (l1)->_comps.c8 == (l2)->_comps.c8) 2201676Sjpk 2211676Sjpk /* Does the level of l1 dominate that of l2? */ 2221676Sjpk #define BLDOMINATES(l1, l2) \ 2231676Sjpk _BLDOMINATES((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2)) 2241676Sjpk 2251676Sjpk #define _BLDOMINATES(l1, l2) (LCLASS(l1) >= LCLASS(l2) && \ 2261676Sjpk (l2)->_comps.c1 == ((l1)->_comps.c1 & (l2)->_comps.c1) && \ 2271676Sjpk (l2)->_comps.c2 == ((l1)->_comps.c2 & (l2)->_comps.c2) && \ 2281676Sjpk (l2)->_comps.c3 == ((l1)->_comps.c3 & (l2)->_comps.c3) && \ 2291676Sjpk (l2)->_comps.c4 == ((l1)->_comps.c4 & (l2)->_comps.c4) && \ 2301676Sjpk (l2)->_comps.c5 == ((l1)->_comps.c5 & (l2)->_comps.c5) && \ 2311676Sjpk (l2)->_comps.c6 == ((l1)->_comps.c6 & (l2)->_comps.c6) && \ 2321676Sjpk (l2)->_comps.c7 == ((l1)->_comps.c7 & (l2)->_comps.c7) && \ 2331676Sjpk (l2)->_comps.c8 == ((l1)->_comps.c8 & (l2)->_comps.c8)) 2341676Sjpk 2351676Sjpk /* Does the level of l1 strictly dominate that of l2? */ 2361676Sjpk #define BLSTRICTDOM(l1, l2) (!BLEQUAL(l1, l2) && BLDOMINATES(l1, l2)) 2371676Sjpk 2381676Sjpk /* Is the level of l within the range r? */ 2391676Sjpk #define BLINRANGE(l, r)\ 2401676Sjpk (BLDOMINATES((l), &((r)->lower_bound)) && \ 2411676Sjpk BLDOMINATES(&((r)->upper_bound), (l))) 2421676Sjpk 2431676Sjpk /* Least Upper Bound level l1 and l2 replacing l1 with the result. */ 2441676Sjpk #define BLMAXIMUM(l1, l2) \ 2451676Sjpk _BLMAXIMUM((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2)) 2461676Sjpk 2471676Sjpk #define _BLMAXIMUM(l1, l2)\ 2481676Sjpk (((l1)->_lclass = (LCLASS(l1) < LCLASS(l2)) ? \ 2491676Sjpk (l2)->_lclass : (l1)->_lclass), \ 2501676Sjpk (l1)->_comps.c1 |= (l2)->_comps.c1, \ 2511676Sjpk (l1)->_comps.c2 |= (l2)->_comps.c2, \ 2521676Sjpk (l1)->_comps.c3 |= (l2)->_comps.c3, \ 2531676Sjpk (l1)->_comps.c4 |= (l2)->_comps.c4, \ 2541676Sjpk (l1)->_comps.c5 |= (l2)->_comps.c5, \ 2551676Sjpk (l1)->_comps.c6 |= (l2)->_comps.c6, \ 2561676Sjpk (l1)->_comps.c7 |= (l2)->_comps.c7, \ 2571676Sjpk (l1)->_comps.c8 |= (l2)->_comps.c8) 2581676Sjpk 2591676Sjpk /* Greatest Lower Bound level l1 and l2 replacing l1 with the result. */ 2601676Sjpk #define BLMINIMUM(l1, l2) \ 2611676Sjpk _BLMINIMUM((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2)) 2621676Sjpk 2631676Sjpk #define _BLMINIMUM(l1, l2)\ 2641676Sjpk (((l1)->_lclass = (LCLASS(l1) > LCLASS(l2)) ? \ 2651676Sjpk (l2)->_lclass : (l1)->_lclass), \ 2661676Sjpk (l1)->_comps.c1 &= (l2)->_comps.c1, \ 2671676Sjpk (l1)->_comps.c2 &= (l2)->_comps.c2, \ 2681676Sjpk (l1)->_comps.c3 &= (l2)->_comps.c3, \ 2691676Sjpk (l1)->_comps.c4 &= (l2)->_comps.c4, \ 2701676Sjpk (l1)->_comps.c5 &= (l2)->_comps.c5, \ 2711676Sjpk (l1)->_comps.c6 &= (l2)->_comps.c6, \ 2721676Sjpk (l1)->_comps.c7 &= (l2)->_comps.c7, \ 2731676Sjpk (l1)->_comps.c8 &= (l2)->_comps.c8) 2741676Sjpk 2751676Sjpk /* Create Manifest Labels */ 2761676Sjpk 2771676Sjpk /* Write a System_Low CMW Label into this memory. */ 2781676Sjpk #define BCLLOW(l) (BSLLOW(BCLTOSL(l)), BILLOW(BCLTOIL(l))) 2791676Sjpk 2801676Sjpk /* Write a System_Low Sensitivity Label into this memory. */ 2811676Sjpk #define BSLLOW(l) _BSLLOW((_bslabel_impl_t *)(l)) 2821676Sjpk 2831676Sjpk #define _BSLLOW(l) \ 2841676Sjpk ((l)->id = SUN_SL_ID, (l)->_c_len = _C_LEN, LCLASS_SET(l, LOW_CLASS), \ 2851676Sjpk (l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \ 2861676Sjpk (l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \ 2871676Sjpk EMPTY_SET) 2881676Sjpk 2891676Sjpk /* Write a System_High Sensitivity Label into this memory. */ 2901676Sjpk #define BSLHIGH(l) _BSLHIGH((_bslabel_impl_t *)(l)) 2911676Sjpk 2921676Sjpk #define _BSLHIGH(l) \ 2931676Sjpk ((l)->id = SUN_SL_ID, (l)->_c_len = _C_LEN, LCLASS_SET(l, HIGH_CLASS), \ 2941676Sjpk (l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \ 2951676Sjpk (l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \ 2961676Sjpk UNIVERSAL_SET) 2971676Sjpk 2981676Sjpk /* Write a System_Low Information Label into this memory. */ 2991676Sjpk #define BILLOW(l) _BILLOW((_bilabel_impl_t *)(l)) 3001676Sjpk 3011676Sjpk #define _BILLOW(l) \ 3021676Sjpk ((l)->_iid = SUN_IL_ID, (l)->_i_c_len = _C_LEN, \ 3031676Sjpk ICLASS_SET(l, LOW_CLASS), \ 3041676Sjpk (l)->_icomps.c1 = (l)->_icomps.c2 = (l)->_icomps.c3 = \ 3051676Sjpk (l)->_icomps.c4 = (l)->_icomps.c5 = (l)->_icomps.c6 = \ 3061676Sjpk (l)->_icomps.c7 = (l)->_icomps.c8 = EMPTY_SET, \ 3071676Sjpk (l)->_imarks.m1 = (l)->_imarks.m2 = (l)->_imarks.m3 = \ 3081676Sjpk (l)->_imarks.m4 = (l)->_imarks.m5 = (l)->_imarks.m6 = \ 3091676Sjpk (l)->_imarks.m7 = (l)->_imarks.m8 = EMPTY_SET) 3101676Sjpk 3111676Sjpk 3121676Sjpk /* Write a System_Low Sensitivity Label into this memory. */ 3131676Sjpk #define BCLEARLOW(l) _BCLEARLOW((_bclear_impl_t *)(l)) 3141676Sjpk 3151676Sjpk #define _BCLEARLOW(c) \ 3161676Sjpk ((c)->id = SUN_CLR_ID, (c)->_c_len = _C_LEN, \ 3171676Sjpk LCLASS_SET(c, LOW_CLASS), \ 3181676Sjpk (c)->_comps.c1 = (c)->_comps.c2 = (c)->_comps.c3 = (c)->_comps.c4 = \ 3191676Sjpk (c)->_comps.c5 = (c)->_comps.c6 = (c)->_comps.c7 = (c)->_comps.c8 = \ 3201676Sjpk EMPTY_SET) 3211676Sjpk 3221676Sjpk /* Write a System_High Sensitivity Label into this memory. */ 3231676Sjpk #define BCLEARHIGH(l) _BCLEARHIGH((_bclear_impl_t *)(l)) 3241676Sjpk 3251676Sjpk #define _BCLEARHIGH(c) \ 3261676Sjpk ((c)->id = SUN_CLR_ID, (c)->_c_len = _C_LEN, \ 3271676Sjpk LCLASS_SET(c, HIGH_CLASS), \ 3281676Sjpk (c)->_comps.c1 = (c)->_comps.c2 = (c)->_comps.c3 = (c)->_comps.c4 = \ 3291676Sjpk (c)->_comps.c5 = (c)->_comps.c6 = (c)->_comps.c7 = (c)->_comps.c8 = \ 3301676Sjpk UNIVERSAL_SET) 3311676Sjpk 3321676Sjpk /* Write an undefined Sensitivity Label into this memory. */ 3331676Sjpk #define BSLUNDEF(l) (((_bslabel_impl_t *)(l))->id = SUN_SL_UN) 3341676Sjpk 3351676Sjpk /* Write an undefined Clearance into this memory. */ 3361676Sjpk #define BCLEARUNDEF(c) (((_bclear_impl_t *)(c))->id = SUN_CLR_UN) 3371676Sjpk 3381676Sjpk /* Retrieve the Sensitivity Label portion of a CMW Label */ 3391676Sjpk #define BCLTOSL(l) ((bslabel_t *)&((_bclabel_impl_t *)(l))->_bcl_sl) 3401676Sjpk 3411676Sjpk /* Retrieve the Information Label portion of a CMW Label */ 3421676Sjpk #define BCLTOIL(l) ((_bilabel_impl_t *)&((_bclabel_impl_t *)(l))->_bcl_il) 3431676Sjpk 3441676Sjpk /* Copy the Sensitivity Label portion from a CMW Label */ 3451676Sjpk #define GETCSL(l1, l2) \ 3461676Sjpk (*((_bslabel_impl_t *)(l1)) = ((_bclabel_impl_t *)(l2))->_bcl_sl) 3471676Sjpk 3481676Sjpk /* Replace the Sensitivity Label portion of a CMW Label */ 3491676Sjpk #define SETCSL(l1, l2) \ 3501676Sjpk (((_bclabel_impl_t *)(l1))->_bcl_sl = *((_bslabel_impl_t *)(l2))) 3511676Sjpk 3521676Sjpk /* Set type of this memory to the label type 't' */ 3531676Sjpk #define SETBLTYPE(l, t) (((_bclabel_impl_t *)(l))->_bcl_sl.id = (t)) 3541676Sjpk 3551676Sjpk #define GETBLTYPE(l) (((const _bclabel_impl_t *)(l))->_bcl_sl.id) 3561676Sjpk 3571676Sjpk #ifdef __cplusplus 3581676Sjpk } 3591676Sjpk #endif 3601676Sjpk 3611676Sjpk #endif /* !_LABEL_MACRO_H */ 362