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 /* 22*9901STon.Nguyen@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 231676Sjpk * Use is subject to license terms. 241676Sjpk * 251676Sjpk * from "tndb.h 7.34 01/08/31 SMI; TSOL 2.x" 261676Sjpk */ 271676Sjpk 281676Sjpk #ifndef _SYS_TSOL_TNDB_H 291676Sjpk #define _SYS_TSOL_TNDB_H 301676Sjpk 311676Sjpk #include <sys/types.h> 32*9901STon.Nguyen@Sun.COM #include <sys/zone.h> 331676Sjpk #include <sys/tsol/label.h> 341676Sjpk #include <sys/tsol/label_macro.h> 351676Sjpk #include <net/if.h> 361676Sjpk 371676Sjpk #ifdef _KERNEL 381676Sjpk #include <net/route.h> 391676Sjpk #endif 401676Sjpk 411676Sjpk #ifdef __cplusplus 421676Sjpk extern "C" { 431676Sjpk #endif 441676Sjpk 451676Sjpk /* same on ILP32 and LP64 */ 461676Sjpk typedef union tnaddr { 471676Sjpk struct sockaddr_in ip_addr_v4; 481676Sjpk struct sockaddr_in6 ip_addr_v6; 491676Sjpk } tnaddr_t; 501676Sjpk 511676Sjpk #define ta_family ip_addr_v4.sin_family 521676Sjpk #define ta_addr_v4 ip_addr_v4.sin_addr 531676Sjpk #define ta_addr_v6 ip_addr_v6.sin6_addr 541676Sjpk #define ta_port_v4 ip_addr_v4.sin_port 551676Sjpk #define ta_port_v6 ip_addr_v6.sin6_port 561676Sjpk 571676Sjpk #define TNADDR_EQ(addr1, addr2) \ 581676Sjpk (((addr1)->ta_family == AF_INET && (addr2)->ta_family == AF_INET && \ 591676Sjpk (addr1)->ta_addr_v4.s_addr == (addr2)->ta_addr_v4.s_addr) || \ 601676Sjpk ((addr1)->ta_family == AF_INET6 && (addr2)->ta_family == AF_INET6 && \ 611676Sjpk IN6_ARE_ADDR_EQUAL(&(addr1)->ta_addr_v6, &(addr2)->ta_addr_v6))) 621676Sjpk 631676Sjpk /* 641676Sjpk * structure for TN database access routines and TN system calls 651676Sjpk */ 661676Sjpk 671676Sjpk typedef enum tsol_dbops { 681676Sjpk TNDB_NOOP = 0, 691676Sjpk TNDB_LOAD = 1, 701676Sjpk TNDB_DELETE = 2, 711676Sjpk TNDB_FLUSH = 3, 721676Sjpk TNDB_GET = 5 731676Sjpk } tsol_dbops_t; 741676Sjpk 75*9901STon.Nguyen@Sun.COM #define TNTNAMSIZ ZONENAME_MAX /* template name size */ 76*9901STon.Nguyen@Sun.COM #define IP_STR_SIZE 200 /* string ip address size */ 771676Sjpk 78*9901STon.Nguyen@Sun.COM #define TNRHDB_NCOL 2 /* # of columns in tnrhdb */ 791676Sjpk 801676Sjpk /* 811676Sjpk * For tnrhdb access library routines and tnrh(2TSOL) 821676Sjpk * same for both ILP32 and LP64. 831676Sjpk */ 841676Sjpk typedef struct tsol_rhent { 851676Sjpk short rh_prefix; /* length of subnet mask */ 861676Sjpk short rh_unused; /* padding */ 871676Sjpk tnaddr_t rh_address; /* IP address */ 881676Sjpk char rh_template[TNTNAMSIZ]; /* template name */ 891676Sjpk } tsol_rhent_t; 901676Sjpk 911676Sjpk typedef struct tsol_rhstr_s { 921676Sjpk int family; 931676Sjpk char *address; 941676Sjpk char *template; 951676Sjpk } tsol_rhstr_t; 961676Sjpk 971676Sjpk /* 981676Sjpk * host types recognized by tsol hosts 991676Sjpk */ 1001676Sjpk typedef enum { 1011676Sjpk UNLABELED = 1, 1021676Sjpk SUN_CIPSO = 3 1031676Sjpk } tsol_host_type_t; 1041676Sjpk 1051676Sjpk typedef enum { 1061676Sjpk OPT_NONE = 0, 1071676Sjpk OPT_CIPSO = 1 1081676Sjpk } tsol_ip_label_t; 1091676Sjpk 1101676Sjpk typedef struct cipso_tag_type_1 { 1111676Sjpk uchar_t tag_type; /* Tag Type (1) */ 1121676Sjpk uchar_t tag_length; /* Length of Tag */ 1131676Sjpk uchar_t tag_align; /* Alignment Octet */ 1141676Sjpk uchar_t tag_sl; /* Sensitivity Level */ 1151676Sjpk uchar_t tag_cat[1]; /* Categories */ 1161676Sjpk } cipso_tag_type_1_t; 1171676Sjpk 1181676Sjpk #define TSOL_CIPSO_MIN_LENGTH 6 1191676Sjpk #define TSOL_CIPSO_MAX_LENGTH IP_MAX_OPT_LENGTH 1201676Sjpk #define TSOL_TT1_MIN_LENGTH 4 1211676Sjpk #define TSOL_TT1_MAX_LENGTH 34 1221676Sjpk 1231676Sjpk #define TSOL_CIPSO_DOI_OFFSET 2 1241676Sjpk #define TSOL_CIPSO_TAG_OFFSET 6 1251676Sjpk 1261676Sjpk typedef struct cipso_option { 1271676Sjpk uchar_t cipso_type; /* Type of option (134) */ 1281676Sjpk uchar_t cipso_length; /* Length of option */ 1291676Sjpk uchar_t cipso_doi[4]; /* Domain of Interpretation */ 1301676Sjpk uchar_t cipso_tag_type[1]; /* variable length */ 1311676Sjpk } cipso_option_t; 1321676Sjpk 1331676Sjpk /* 1341676Sjpk * RIPSO classifications 1351676Sjpk */ 1361676Sjpk #define TSOL_CL_TOP_SECRET 0x3d 1371676Sjpk #define TSOL_CL_SECRET 0x5a 1381676Sjpk #define TSOL_CL_CONFIDENTIAL 0x96 1391676Sjpk #define TSOL_CL_UNCLASSIFIED 0xab 1401676Sjpk 1411676Sjpk /* 1421676Sjpk * RIPSO protection authorities 1431676Sjpk */ 1441676Sjpk #define TSOL_PA_GENSER 0x80 1451676Sjpk #define TSOL_PA_SIOP_ESI 0x40 1461676Sjpk #define TSOL_PA_SCI 0x20 1471676Sjpk #define TSOL_PA_NSA 0x10 1481676Sjpk #define TSOL_PA_DOE 0x08 1491676Sjpk 1501676Sjpk /* 1511676Sjpk * this mask is only used for tndb structures, and is different 1521676Sjpk * from t6mask_t bits definitions 1531676Sjpk */ 1541676Sjpk 1551676Sjpk typedef unsigned int tnmask_t; 1561676Sjpk 1571676Sjpk /* 1581676Sjpk * unlabeled host structure for the tnrhtp template. 1591676Sjpk * same for both ILP32 and LP64. 1601676Sjpk */ 1611676Sjpk struct tsol_unl { 1621676Sjpk tnmask_t mask; /* tells which attributes are returned by the library */ 1631676Sjpk bslabel_t def_label; /* default label */ 1641676Sjpk brange_t gw_sl_range; /* for routing only */ 1651676Sjpk blset_t sl_set; /* label set */ 1661676Sjpk }; 1671676Sjpk 1681676Sjpk /* 1691676Sjpk * CIPSO host structure for the tnrhtp template 1701676Sjpk * same for both ILP32 and LP64. 1711676Sjpk */ 1721676Sjpk struct tsol_cipso { 1731676Sjpk tnmask_t mask; /* tells which attributes are returned by the library */ 1741676Sjpk bclear_t def_cl; /* default clearance */ 1751676Sjpk brange_t sl_range; /* min/max SL range */ 1761676Sjpk blset_t sl_set; /* label set */ 1771676Sjpk }; 1781676Sjpk 1791676Sjpk /* 1801676Sjpk * Valid keys and values of the key=value pairs for tnrhtp 1811676Sjpk */ 1821676Sjpk #define TP_UNLABELED "unlabeled" 1831676Sjpk #define TP_CIPSO "cipso" 1841676Sjpk #define TP_ZONE "zone" 1851676Sjpk #define TP_HOSTTYPE "host_type" 1861676Sjpk #define TP_DOI "doi" 1871676Sjpk #define TP_DEFLABEL "def_label" 1881676Sjpk #define TP_MINLABEL "min_sl" 1891676Sjpk #define TP_MAXLABEL "max_sl" 1901676Sjpk #define TP_SET "sl_set" 1911676Sjpk 1921676Sjpk #define TP_COMMA "," 1931676Sjpk 1941676Sjpk #define TNRHTP_NCOL 2 /* # of columns in tnrhtp */ 1951676Sjpk 1961676Sjpk /* 1971676Sjpk * For tnrhtp access library routines and tnrhtp(2TSOL) 1981676Sjpk * same for both ILP32 and LP64. 1991676Sjpk */ 2001676Sjpk typedef struct tsol_tpent { 2011676Sjpk char name[TNTNAMSIZ]; /* template name */ 2021676Sjpk tsol_host_type_t host_type; /* specifies host type */ 2031676Sjpk int tp_doi; /* Domain of Interpretation */ 2041676Sjpk #define tp_cipso_doi_unl tp_doi 2051676Sjpk #define tp_cipso_doi_cipso tp_doi 2061676Sjpk union { 2071676Sjpk struct tsol_unl unl; /* template for unlabeled */ 2081676Sjpk #define tp_mask_unl un.unl.mask 2091676Sjpk #define tp_def_label un.unl.def_label 2101676Sjpk #define tp_gw_sl_range un.unl.gw_sl_range 2111676Sjpk #define tp_gw_sl_set un.unl.sl_set 2121676Sjpk 2131676Sjpk struct tsol_cipso cipso; /* template for CIPSO */ 2141676Sjpk #define tp_mask_cipso un.cipso.mask 2151676Sjpk #define tp_def_cl_cipso un.cipso.def_cl 2161676Sjpk #define tp_sl_range_cipso un.cipso.sl_range 2171676Sjpk #define tp_sl_set_cipso un.cipso.sl_set 2181676Sjpk } un; 2191676Sjpk } tsol_tpent_t; 2201676Sjpk 2211676Sjpk typedef struct tsol_tpstr_s { 2221676Sjpk char *template; 2231676Sjpk char *attrs; 2241676Sjpk } tsol_tpstr_t; 2251676Sjpk 2261676Sjpk /* 2271676Sjpk * For tnmlp(2TSOL); same for both ILP32 and LP64. 2281676Sjpk */ 2291676Sjpk typedef struct tsol_mlpent { 2301676Sjpk zoneid_t tsme_zoneid; 2311676Sjpk uint_t tsme_flags; /* TSOL_MEF_* */ 2321676Sjpk tsol_mlp_t tsme_mlp; 2331676Sjpk } tsol_mlpent_t; 2341676Sjpk 2351676Sjpk #define TSOL_MEF_SHARED 0x00000001 /* MLP defined on shared addresses */ 2361676Sjpk 2371676Sjpk /* 2381676Sjpk * For tnzonecfg access library routines. 2391676Sjpk * List of MLPs ends with null entry, where protocol and port are both zero. 2401676Sjpk */ 2411676Sjpk typedef struct tsol_zcent { 242*9901STon.Nguyen@Sun.COM char zc_name[ZONENAME_MAX]; 2431676Sjpk int zc_doi; 2441676Sjpk bslabel_t zc_label; 2451676Sjpk int zc_match; 2461676Sjpk tsol_mlp_t *zc_private_mlp; 2471676Sjpk tsol_mlp_t *zc_shared_mlp; 2481676Sjpk } tsol_zcent_t; 2491676Sjpk #define TSOL_MLP_END(mlp) ((mlp)->mlp_ipp == 0 && (mlp)->mlp_port == 0) 2501676Sjpk 2511676Sjpk typedef struct tsol_tpc { 2521676Sjpk kmutex_t tpc_lock; /* lock for structure */ 2531676Sjpk uint_t tpc_refcnt; /* reference count */ 2541676Sjpk boolean_t tpc_invalid; /* entry has been deleted */ 2551676Sjpk struct tsol_tpent tpc_tp; /* template */ 2561676Sjpk } tsol_tpc_t; 2571676Sjpk 2581676Sjpk typedef struct tsol_tnrhc { 2591676Sjpk struct tsol_tnrhc *rhc_next; /* link to next entry */ 2601676Sjpk kmutex_t rhc_lock; /* lock for structure */ 2611676Sjpk tnaddr_t rhc_host; /* IPv4/IPv6 host address */ 2621676Sjpk tsol_tpc_t *rhc_tpc; /* pointer to template */ 2631676Sjpk uint_t rhc_refcnt; /* Number of references */ 2641676Sjpk char rhc_invalid; /* out-of-date rhc */ 2651676Sjpk char rhc_isbcast; /* broadcast address */ 2661676Sjpk char rhc_local; /* loopback or local interace */ 2671676Sjpk } tsol_tnrhc_t; 2681676Sjpk 2691676Sjpk /* Size of remote host hash tables in kernel */ 2701676Sjpk #define TNRHC_SIZE 256 2711676Sjpk #define TSOL_MASK_TABLE_SIZE 33 2721676Sjpk #define TSOL_MASK_TABLE_SIZE_V6 129 2731676Sjpk 2741676Sjpk #ifdef _KERNEL 2751676Sjpk #define TNRHC_HOLD(a) { \ 2761676Sjpk mutex_enter(&(a)->rhc_lock); \ 2771676Sjpk (a)->rhc_refcnt++; \ 2781676Sjpk ASSERT((a)->rhc_refcnt > 0); \ 2791676Sjpk mutex_exit(&(a)->rhc_lock); \ 2801676Sjpk } 2811676Sjpk #define TNRHC_RELE(a) { \ 2821676Sjpk mutex_enter(&(a)->rhc_lock); \ 2831676Sjpk ASSERT((a)->rhc_refcnt > 0); \ 2841676Sjpk if (--(a)->rhc_refcnt <= 0) \ 2851676Sjpk tnrhc_free(a); \ 2861676Sjpk else \ 2871676Sjpk mutex_exit(&(a)->rhc_lock); \ 2881676Sjpk } 2891676Sjpk extern void tnrhc_free(tsol_tnrhc_t *); 2901676Sjpk #define TPC_HOLD(a) { \ 2911676Sjpk mutex_enter(&(a)->tpc_lock); \ 2921676Sjpk (a)->tpc_refcnt++; \ 2931676Sjpk ASSERT((a)->tpc_refcnt > 0); \ 2941676Sjpk mutex_exit(&(a)->tpc_lock); \ 2951676Sjpk } 2961676Sjpk #define TPC_RELE(a) { \ 2971676Sjpk mutex_enter(&(a)->tpc_lock); \ 2981676Sjpk ASSERT((a)->tpc_refcnt > 0); \ 2991676Sjpk if (--(a)->tpc_refcnt <= 0) \ 3001676Sjpk tpc_free(a); \ 3011676Sjpk else \ 3021676Sjpk mutex_exit(&(a)->tpc_lock); \ 3031676Sjpk } 3041676Sjpk extern void tpc_free(tsol_tpc_t *); 3051676Sjpk #endif /* _KERNEL */ 3061676Sjpk 3071676Sjpk /* 3081676Sjpk * The next three hashing macros are copied from macros in ip_ire.h. 3091676Sjpk */ 3101676Sjpk #define TSOL_ADDR_HASH(addr, table_size) \ 3111676Sjpk (((((addr) >> 16) ^ (addr)) ^ ((((addr) >> 16) ^ (addr))>> 8)) \ 3121676Sjpk % (table_size)) 3131676Sjpk 3141676Sjpk #define TSOL_ADDR_HASH_V6(addr, table_size) \ 3151676Sjpk (((addr).s6_addr8[8] ^ (addr).s6_addr8[9] ^ \ 3161676Sjpk (addr).s6_addr8[10] ^ (addr).s6_addr8[13] ^ \ 3171676Sjpk (addr).s6_addr8[14] ^ (addr).s6_addr8[15]) % (table_size)) 3181676Sjpk 3191676Sjpk /* This assumes that table_size is a power of 2. */ 3201676Sjpk #define TSOL_ADDR_MASK_HASH_V6(addr, mask, table_size) \ 3211676Sjpk ((((addr).s6_addr8[8] & (mask).s6_addr8[8]) ^ \ 3221676Sjpk ((addr).s6_addr8[9] & (mask).s6_addr8[9]) ^ \ 3231676Sjpk ((addr).s6_addr8[10] & (mask).s6_addr8[10]) ^ \ 3241676Sjpk ((addr).s6_addr8[13] & (mask).s6_addr8[13]) ^ \ 3251676Sjpk ((addr).s6_addr8[14] & (mask).s6_addr8[14]) ^ \ 3261676Sjpk ((addr).s6_addr8[15] & (mask).s6_addr8[15])) & ((table_size) - 1)) 3271676Sjpk 3281676Sjpk 3291676Sjpk /* 3301676Sjpk * Constants used for getting the mask value in struct tsol_tpent 3311676Sjpk */ 3321676Sjpk enum { 3331676Sjpk TNT_DEF_LABEL, 3341676Sjpk TNT_DEF_CL, 3351676Sjpk TNT_SL_RANGE_TSOL, /* use this for both unl and zone */ 3361676Sjpk TNT_CIPSO_DOI 3371676Sjpk }; 3381676Sjpk 3391676Sjpk /* 3401676Sjpk * mask definitions 3411676Sjpk */ 3421676Sjpk #define tsol_tntmask(value) ((unsigned int)(1<<(value))) 3431676Sjpk 3441676Sjpk #define TSOL_MSK_DEF_LABEL tsol_tntmask(TNT_DEF_LABEL) 3451676Sjpk #define TSOL_MSK_DEF_CL tsol_tntmask(TNT_DEF_CL) 3461676Sjpk #define TSOL_MSK_SL_RANGE_TSOL tsol_tntmask(TNT_SL_RANGE_TSOL) 3471676Sjpk #define TSOL_MSK_CIPSO_DOI tsol_tntmask(TNT_CIPSO_DOI) 3481676Sjpk 3491676Sjpk /* 3501676Sjpk * TN errors 3511676Sjpk */ 3521676Sjpk #define TSOL_PARSE_ERANGE 1 /* result buffer not allocated */ 3531676Sjpk #define TSOL_NOT_SUPPORTED 2 /* address family not supported */ 3541676Sjpk #define TSOL_NOT_FOUND 3 /* search by * routines target not found */ 3551676Sjpk 3561676Sjpk /* 3571676Sjpk * Structure used to hold a list of IP addresses. 3581676Sjpk */ 3591676Sjpk typedef struct tsol_address { 3601676Sjpk struct tsol_address *next; 3611676Sjpk in_addr_t ip_address; 3621676Sjpk } tsol_address_t; 3631676Sjpk 3641676Sjpk /* This is shared between tcache and mdb */ 3651676Sjpk typedef struct tnrhc_hash_s { 3661676Sjpk tsol_tnrhc_t *tnrh_list; 3671676Sjpk kmutex_t tnrh_lock; 3681676Sjpk } tnrhc_hash_t; 3691676Sjpk 3701676Sjpk #ifdef _KERNEL 3711676Sjpk typedef enum { 3721676Sjpk mlptSingle, 3731676Sjpk mlptPrivate, 3741676Sjpk mlptShared, 3751676Sjpk mlptBoth 3761676Sjpk } mlp_type_t; 3771676Sjpk 3781676Sjpk extern tsol_tpc_t *find_tpc(const void *, uchar_t, boolean_t); 3791676Sjpk extern void tcache_init(void); 3801676Sjpk extern in_port_t tsol_next_port(zone_t *, in_port_t, int, boolean_t); 3811676Sjpk extern mlp_type_t tsol_mlp_port_type(zone_t *, uchar_t, uint16_t, mlp_type_t); 3821676Sjpk extern zoneid_t tsol_mlp_findzone(uchar_t, uint16_t); 3831676Sjpk extern int tsol_mlp_anon(zone_t *, mlp_type_t, uchar_t, uint16_t, boolean_t); 3841676Sjpk extern void tsol_print_label(const blevel_t *, const char *); 3851676Sjpk 3861676Sjpk struct tsol_gc_s; 3871676Sjpk struct tsol_gcgrp_s; 3881676Sjpk struct tsol_gcgrp_addr_s; 3891676Sjpk 3901676Sjpk extern struct tsol_gc_s *gc_create(struct rtsa_s *, struct tsol_gcgrp_s *, 3911676Sjpk boolean_t *); 3921676Sjpk extern void gc_inactive(struct tsol_gc_s *); 3931676Sjpk extern int rtsa_validate(const struct rtsa_s *); 3941676Sjpk extern struct tsol_gcgrp_s *gcgrp_lookup(struct tsol_gcgrp_addr_s *, boolean_t); 3951676Sjpk extern void gcgrp_inactive(struct tsol_gcgrp_s *); 3961676Sjpk extern int tnrh_load(const tsol_rhent_t *); 3971676Sjpk #endif /* _KERNEL */ 3981676Sjpk 3991676Sjpk #ifdef __cplusplus 4001676Sjpk } 4011676Sjpk #endif 4021676Sjpk 4031676Sjpk #endif /* _SYS_TSOL_TNDB_H */ 404