1*1676Sjpk /* 2*1676Sjpk * CDDL HEADER START 3*1676Sjpk * 4*1676Sjpk * The contents of this file are subject to the terms of the 5*1676Sjpk * Common Development and Distribution License (the "License"). 6*1676Sjpk * You may not use this file except in compliance with the License. 7*1676Sjpk * 8*1676Sjpk * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*1676Sjpk * or http://www.opensolaris.org/os/licensing. 10*1676Sjpk * See the License for the specific language governing permissions 11*1676Sjpk * and limitations under the License. 12*1676Sjpk * 13*1676Sjpk * When distributing Covered Code, include this CDDL HEADER in each 14*1676Sjpk * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*1676Sjpk * If applicable, add the following below this CDDL HEADER, with the 16*1676Sjpk * fields enclosed by brackets "[]" replaced with your own identifying 17*1676Sjpk * information: Portions Copyright [yyyy] [name of copyright owner] 18*1676Sjpk * 19*1676Sjpk * CDDL HEADER END 20*1676Sjpk */ 21*1676Sjpk /* 22*1676Sjpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23*1676Sjpk * Use is subject to license terms. 24*1676Sjpk * 25*1676Sjpk * from "tndb.h 7.34 01/08/31 SMI; TSOL 2.x" 26*1676Sjpk */ 27*1676Sjpk 28*1676Sjpk #ifndef _SYS_TSOL_TNDB_H 29*1676Sjpk #define _SYS_TSOL_TNDB_H 30*1676Sjpk 31*1676Sjpk #pragma ident "%Z%%M% %I% %E% SMI" 32*1676Sjpk 33*1676Sjpk #include <sys/types.h> 34*1676Sjpk #include <sys/tsol/label.h> 35*1676Sjpk #include <sys/tsol/label_macro.h> 36*1676Sjpk #include <net/if.h> 37*1676Sjpk 38*1676Sjpk #ifdef _KERNEL 39*1676Sjpk #include <net/route.h> 40*1676Sjpk #include <sys/zone.h> 41*1676Sjpk #endif 42*1676Sjpk 43*1676Sjpk #ifdef __cplusplus 44*1676Sjpk extern "C" { 45*1676Sjpk #endif 46*1676Sjpk 47*1676Sjpk /* same on ILP32 and LP64 */ 48*1676Sjpk typedef union tnaddr { 49*1676Sjpk struct sockaddr_in ip_addr_v4; 50*1676Sjpk struct sockaddr_in6 ip_addr_v6; 51*1676Sjpk } tnaddr_t; 52*1676Sjpk 53*1676Sjpk #define ta_family ip_addr_v4.sin_family 54*1676Sjpk #define ta_addr_v4 ip_addr_v4.sin_addr 55*1676Sjpk #define ta_addr_v6 ip_addr_v6.sin6_addr 56*1676Sjpk #define ta_port_v4 ip_addr_v4.sin_port 57*1676Sjpk #define ta_port_v6 ip_addr_v6.sin6_port 58*1676Sjpk 59*1676Sjpk #define TNADDR_EQ(addr1, addr2) \ 60*1676Sjpk (((addr1)->ta_family == AF_INET && (addr2)->ta_family == AF_INET && \ 61*1676Sjpk (addr1)->ta_addr_v4.s_addr == (addr2)->ta_addr_v4.s_addr) || \ 62*1676Sjpk ((addr1)->ta_family == AF_INET6 && (addr2)->ta_family == AF_INET6 && \ 63*1676Sjpk IN6_ARE_ADDR_EQUAL(&(addr1)->ta_addr_v6, &(addr2)->ta_addr_v6))) 64*1676Sjpk 65*1676Sjpk /* 66*1676Sjpk * structure for TN database access routines and TN system calls 67*1676Sjpk */ 68*1676Sjpk 69*1676Sjpk typedef enum tsol_dbops { 70*1676Sjpk TNDB_NOOP = 0, 71*1676Sjpk TNDB_LOAD = 1, 72*1676Sjpk TNDB_DELETE = 2, 73*1676Sjpk TNDB_FLUSH = 3, 74*1676Sjpk TNDB_GET = 5 75*1676Sjpk } tsol_dbops_t; 76*1676Sjpk 77*1676Sjpk #define TNTNAMSIZ 32 /* template name size */ 78*1676Sjpk #define IP_STR_SIZE 200 /* string ip address size */ 79*1676Sjpk 80*1676Sjpk #define TNRHDB_NCOL 2 /* # of columns in tnrhdb */ 81*1676Sjpk 82*1676Sjpk /* 83*1676Sjpk * For tnrhdb access library routines and tnrh(2TSOL) 84*1676Sjpk * same for both ILP32 and LP64. 85*1676Sjpk */ 86*1676Sjpk typedef struct tsol_rhent { 87*1676Sjpk short rh_prefix; /* length of subnet mask */ 88*1676Sjpk short rh_unused; /* padding */ 89*1676Sjpk tnaddr_t rh_address; /* IP address */ 90*1676Sjpk char rh_template[TNTNAMSIZ]; /* template name */ 91*1676Sjpk } tsol_rhent_t; 92*1676Sjpk 93*1676Sjpk typedef struct tsol_rhstr_s { 94*1676Sjpk int family; 95*1676Sjpk char *address; 96*1676Sjpk char *template; 97*1676Sjpk } tsol_rhstr_t; 98*1676Sjpk 99*1676Sjpk /* 100*1676Sjpk * host types recognized by tsol hosts 101*1676Sjpk */ 102*1676Sjpk typedef enum { 103*1676Sjpk UNLABELED = 1, 104*1676Sjpk SUN_CIPSO = 3 105*1676Sjpk } tsol_host_type_t; 106*1676Sjpk 107*1676Sjpk typedef enum { 108*1676Sjpk OPT_NONE = 0, 109*1676Sjpk OPT_CIPSO = 1 110*1676Sjpk } tsol_ip_label_t; 111*1676Sjpk 112*1676Sjpk typedef struct cipso_tag_type_1 { 113*1676Sjpk uchar_t tag_type; /* Tag Type (1) */ 114*1676Sjpk uchar_t tag_length; /* Length of Tag */ 115*1676Sjpk uchar_t tag_align; /* Alignment Octet */ 116*1676Sjpk uchar_t tag_sl; /* Sensitivity Level */ 117*1676Sjpk uchar_t tag_cat[1]; /* Categories */ 118*1676Sjpk } cipso_tag_type_1_t; 119*1676Sjpk 120*1676Sjpk #define TSOL_CIPSO_MIN_LENGTH 6 121*1676Sjpk #define TSOL_CIPSO_MAX_LENGTH IP_MAX_OPT_LENGTH 122*1676Sjpk #define TSOL_TT1_MIN_LENGTH 4 123*1676Sjpk #define TSOL_TT1_MAX_LENGTH 34 124*1676Sjpk 125*1676Sjpk #define TSOL_CIPSO_DOI_OFFSET 2 126*1676Sjpk #define TSOL_CIPSO_TAG_OFFSET 6 127*1676Sjpk 128*1676Sjpk typedef struct cipso_option { 129*1676Sjpk uchar_t cipso_type; /* Type of option (134) */ 130*1676Sjpk uchar_t cipso_length; /* Length of option */ 131*1676Sjpk uchar_t cipso_doi[4]; /* Domain of Interpretation */ 132*1676Sjpk uchar_t cipso_tag_type[1]; /* variable length */ 133*1676Sjpk } cipso_option_t; 134*1676Sjpk 135*1676Sjpk /* 136*1676Sjpk * RIPSO classifications 137*1676Sjpk */ 138*1676Sjpk #define TSOL_CL_TOP_SECRET 0x3d 139*1676Sjpk #define TSOL_CL_SECRET 0x5a 140*1676Sjpk #define TSOL_CL_CONFIDENTIAL 0x96 141*1676Sjpk #define TSOL_CL_UNCLASSIFIED 0xab 142*1676Sjpk 143*1676Sjpk /* 144*1676Sjpk * RIPSO protection authorities 145*1676Sjpk */ 146*1676Sjpk #define TSOL_PA_GENSER 0x80 147*1676Sjpk #define TSOL_PA_SIOP_ESI 0x40 148*1676Sjpk #define TSOL_PA_SCI 0x20 149*1676Sjpk #define TSOL_PA_NSA 0x10 150*1676Sjpk #define TSOL_PA_DOE 0x08 151*1676Sjpk 152*1676Sjpk /* 153*1676Sjpk * this mask is only used for tndb structures, and is different 154*1676Sjpk * from t6mask_t bits definitions 155*1676Sjpk */ 156*1676Sjpk 157*1676Sjpk typedef unsigned int tnmask_t; 158*1676Sjpk 159*1676Sjpk /* 160*1676Sjpk * unlabeled host structure for the tnrhtp template. 161*1676Sjpk * same for both ILP32 and LP64. 162*1676Sjpk */ 163*1676Sjpk struct tsol_unl { 164*1676Sjpk tnmask_t mask; /* tells which attributes are returned by the library */ 165*1676Sjpk bslabel_t def_label; /* default label */ 166*1676Sjpk brange_t gw_sl_range; /* for routing only */ 167*1676Sjpk blset_t sl_set; /* label set */ 168*1676Sjpk }; 169*1676Sjpk 170*1676Sjpk /* 171*1676Sjpk * CIPSO host structure for the tnrhtp template 172*1676Sjpk * same for both ILP32 and LP64. 173*1676Sjpk */ 174*1676Sjpk struct tsol_cipso { 175*1676Sjpk tnmask_t mask; /* tells which attributes are returned by the library */ 176*1676Sjpk bclear_t def_cl; /* default clearance */ 177*1676Sjpk brange_t sl_range; /* min/max SL range */ 178*1676Sjpk blset_t sl_set; /* label set */ 179*1676Sjpk }; 180*1676Sjpk 181*1676Sjpk /* 182*1676Sjpk * Valid keys and values of the key=value pairs for tnrhtp 183*1676Sjpk */ 184*1676Sjpk #define TP_UNLABELED "unlabeled" 185*1676Sjpk #define TP_CIPSO "cipso" 186*1676Sjpk #define TP_ZONE "zone" 187*1676Sjpk #define TP_HOSTTYPE "host_type" 188*1676Sjpk #define TP_DOI "doi" 189*1676Sjpk #define TP_DEFLABEL "def_label" 190*1676Sjpk #define TP_MINLABEL "min_sl" 191*1676Sjpk #define TP_MAXLABEL "max_sl" 192*1676Sjpk #define TP_SET "sl_set" 193*1676Sjpk 194*1676Sjpk #define TP_COMMA "," 195*1676Sjpk 196*1676Sjpk #define TNRHTP_NCOL 2 /* # of columns in tnrhtp */ 197*1676Sjpk 198*1676Sjpk /* 199*1676Sjpk * For tnrhtp access library routines and tnrhtp(2TSOL) 200*1676Sjpk * same for both ILP32 and LP64. 201*1676Sjpk */ 202*1676Sjpk typedef struct tsol_tpent { 203*1676Sjpk char name[TNTNAMSIZ]; /* template name */ 204*1676Sjpk tsol_host_type_t host_type; /* specifies host type */ 205*1676Sjpk int tp_doi; /* Domain of Interpretation */ 206*1676Sjpk #define tp_cipso_doi_unl tp_doi 207*1676Sjpk #define tp_cipso_doi_cipso tp_doi 208*1676Sjpk union { 209*1676Sjpk struct tsol_unl unl; /* template for unlabeled */ 210*1676Sjpk #define tp_mask_unl un.unl.mask 211*1676Sjpk #define tp_def_label un.unl.def_label 212*1676Sjpk #define tp_gw_sl_range un.unl.gw_sl_range 213*1676Sjpk #define tp_gw_sl_set un.unl.sl_set 214*1676Sjpk 215*1676Sjpk struct tsol_cipso cipso; /* template for CIPSO */ 216*1676Sjpk #define tp_mask_cipso un.cipso.mask 217*1676Sjpk #define tp_def_cl_cipso un.cipso.def_cl 218*1676Sjpk #define tp_sl_range_cipso un.cipso.sl_range 219*1676Sjpk #define tp_sl_set_cipso un.cipso.sl_set 220*1676Sjpk } un; 221*1676Sjpk } tsol_tpent_t; 222*1676Sjpk 223*1676Sjpk typedef struct tsol_tpstr_s { 224*1676Sjpk char *template; 225*1676Sjpk char *attrs; 226*1676Sjpk } tsol_tpstr_t; 227*1676Sjpk 228*1676Sjpk /* 229*1676Sjpk * For tnmlp(2TSOL); same for both ILP32 and LP64. 230*1676Sjpk */ 231*1676Sjpk typedef struct tsol_mlpent { 232*1676Sjpk zoneid_t tsme_zoneid; 233*1676Sjpk uint_t tsme_flags; /* TSOL_MEF_* */ 234*1676Sjpk tsol_mlp_t tsme_mlp; 235*1676Sjpk } tsol_mlpent_t; 236*1676Sjpk 237*1676Sjpk #define TSOL_MEF_SHARED 0x00000001 /* MLP defined on shared addresses */ 238*1676Sjpk 239*1676Sjpk /* 240*1676Sjpk * For tnzonecfg access library routines. 241*1676Sjpk * List of MLPs ends with null entry, where protocol and port are both zero. 242*1676Sjpk */ 243*1676Sjpk typedef struct tsol_zcent { 244*1676Sjpk char zc_name[TNTNAMSIZ]; 245*1676Sjpk int zc_doi; 246*1676Sjpk bslabel_t zc_label; 247*1676Sjpk int zc_match; 248*1676Sjpk tsol_mlp_t *zc_private_mlp; 249*1676Sjpk tsol_mlp_t *zc_shared_mlp; 250*1676Sjpk } tsol_zcent_t; 251*1676Sjpk #define TSOL_MLP_END(mlp) ((mlp)->mlp_ipp == 0 && (mlp)->mlp_port == 0) 252*1676Sjpk 253*1676Sjpk typedef struct tsol_tpc { 254*1676Sjpk kmutex_t tpc_lock; /* lock for structure */ 255*1676Sjpk uint_t tpc_refcnt; /* reference count */ 256*1676Sjpk boolean_t tpc_invalid; /* entry has been deleted */ 257*1676Sjpk struct tsol_tpent tpc_tp; /* template */ 258*1676Sjpk } tsol_tpc_t; 259*1676Sjpk 260*1676Sjpk typedef struct tsol_tnrhc { 261*1676Sjpk struct tsol_tnrhc *rhc_next; /* link to next entry */ 262*1676Sjpk kmutex_t rhc_lock; /* lock for structure */ 263*1676Sjpk tnaddr_t rhc_host; /* IPv4/IPv6 host address */ 264*1676Sjpk tsol_tpc_t *rhc_tpc; /* pointer to template */ 265*1676Sjpk uint_t rhc_refcnt; /* Number of references */ 266*1676Sjpk char rhc_invalid; /* out-of-date rhc */ 267*1676Sjpk char rhc_isbcast; /* broadcast address */ 268*1676Sjpk char rhc_local; /* loopback or local interace */ 269*1676Sjpk } tsol_tnrhc_t; 270*1676Sjpk 271*1676Sjpk /* Size of remote host hash tables in kernel */ 272*1676Sjpk #define TNRHC_SIZE 256 273*1676Sjpk #define TSOL_MASK_TABLE_SIZE 33 274*1676Sjpk #define TSOL_MASK_TABLE_SIZE_V6 129 275*1676Sjpk 276*1676Sjpk #ifdef _KERNEL 277*1676Sjpk #define TNRHC_HOLD(a) { \ 278*1676Sjpk mutex_enter(&(a)->rhc_lock); \ 279*1676Sjpk (a)->rhc_refcnt++; \ 280*1676Sjpk ASSERT((a)->rhc_refcnt > 0); \ 281*1676Sjpk mutex_exit(&(a)->rhc_lock); \ 282*1676Sjpk } 283*1676Sjpk #define TNRHC_RELE(a) { \ 284*1676Sjpk mutex_enter(&(a)->rhc_lock); \ 285*1676Sjpk ASSERT((a)->rhc_refcnt > 0); \ 286*1676Sjpk if (--(a)->rhc_refcnt <= 0) \ 287*1676Sjpk tnrhc_free(a); \ 288*1676Sjpk else \ 289*1676Sjpk mutex_exit(&(a)->rhc_lock); \ 290*1676Sjpk } 291*1676Sjpk extern void tnrhc_free(tsol_tnrhc_t *); 292*1676Sjpk #define TPC_HOLD(a) { \ 293*1676Sjpk mutex_enter(&(a)->tpc_lock); \ 294*1676Sjpk (a)->tpc_refcnt++; \ 295*1676Sjpk ASSERT((a)->tpc_refcnt > 0); \ 296*1676Sjpk mutex_exit(&(a)->tpc_lock); \ 297*1676Sjpk } 298*1676Sjpk #define TPC_RELE(a) { \ 299*1676Sjpk mutex_enter(&(a)->tpc_lock); \ 300*1676Sjpk ASSERT((a)->tpc_refcnt > 0); \ 301*1676Sjpk if (--(a)->tpc_refcnt <= 0) \ 302*1676Sjpk tpc_free(a); \ 303*1676Sjpk else \ 304*1676Sjpk mutex_exit(&(a)->tpc_lock); \ 305*1676Sjpk } 306*1676Sjpk extern void tpc_free(tsol_tpc_t *); 307*1676Sjpk #endif /* _KERNEL */ 308*1676Sjpk 309*1676Sjpk /* 310*1676Sjpk * The next three hashing macros are copied from macros in ip_ire.h. 311*1676Sjpk */ 312*1676Sjpk #define TSOL_ADDR_HASH(addr, table_size) \ 313*1676Sjpk (((((addr) >> 16) ^ (addr)) ^ ((((addr) >> 16) ^ (addr))>> 8)) \ 314*1676Sjpk % (table_size)) 315*1676Sjpk 316*1676Sjpk #define TSOL_ADDR_HASH_V6(addr, table_size) \ 317*1676Sjpk (((addr).s6_addr8[8] ^ (addr).s6_addr8[9] ^ \ 318*1676Sjpk (addr).s6_addr8[10] ^ (addr).s6_addr8[13] ^ \ 319*1676Sjpk (addr).s6_addr8[14] ^ (addr).s6_addr8[15]) % (table_size)) 320*1676Sjpk 321*1676Sjpk /* This assumes that table_size is a power of 2. */ 322*1676Sjpk #define TSOL_ADDR_MASK_HASH_V6(addr, mask, table_size) \ 323*1676Sjpk ((((addr).s6_addr8[8] & (mask).s6_addr8[8]) ^ \ 324*1676Sjpk ((addr).s6_addr8[9] & (mask).s6_addr8[9]) ^ \ 325*1676Sjpk ((addr).s6_addr8[10] & (mask).s6_addr8[10]) ^ \ 326*1676Sjpk ((addr).s6_addr8[13] & (mask).s6_addr8[13]) ^ \ 327*1676Sjpk ((addr).s6_addr8[14] & (mask).s6_addr8[14]) ^ \ 328*1676Sjpk ((addr).s6_addr8[15] & (mask).s6_addr8[15])) & ((table_size) - 1)) 329*1676Sjpk 330*1676Sjpk 331*1676Sjpk /* 332*1676Sjpk * Constants used for getting the mask value in struct tsol_tpent 333*1676Sjpk */ 334*1676Sjpk enum { 335*1676Sjpk TNT_DEF_LABEL, 336*1676Sjpk TNT_DEF_CL, 337*1676Sjpk TNT_SL_RANGE_TSOL, /* use this for both unl and zone */ 338*1676Sjpk TNT_CIPSO_DOI 339*1676Sjpk }; 340*1676Sjpk 341*1676Sjpk /* 342*1676Sjpk * mask definitions 343*1676Sjpk */ 344*1676Sjpk #define tsol_tntmask(value) ((unsigned int)(1<<(value))) 345*1676Sjpk 346*1676Sjpk #define TSOL_MSK_DEF_LABEL tsol_tntmask(TNT_DEF_LABEL) 347*1676Sjpk #define TSOL_MSK_DEF_CL tsol_tntmask(TNT_DEF_CL) 348*1676Sjpk #define TSOL_MSK_SL_RANGE_TSOL tsol_tntmask(TNT_SL_RANGE_TSOL) 349*1676Sjpk #define TSOL_MSK_CIPSO_DOI tsol_tntmask(TNT_CIPSO_DOI) 350*1676Sjpk 351*1676Sjpk /* 352*1676Sjpk * TN errors 353*1676Sjpk */ 354*1676Sjpk #define TSOL_PARSE_ERANGE 1 /* result buffer not allocated */ 355*1676Sjpk #define TSOL_NOT_SUPPORTED 2 /* address family not supported */ 356*1676Sjpk #define TSOL_NOT_FOUND 3 /* search by * routines target not found */ 357*1676Sjpk 358*1676Sjpk /* 359*1676Sjpk * Structure used to hold a list of IP addresses. 360*1676Sjpk */ 361*1676Sjpk typedef struct tsol_address { 362*1676Sjpk struct tsol_address *next; 363*1676Sjpk in_addr_t ip_address; 364*1676Sjpk } tsol_address_t; 365*1676Sjpk 366*1676Sjpk /* This is shared between tcache and mdb */ 367*1676Sjpk typedef struct tnrhc_hash_s { 368*1676Sjpk tsol_tnrhc_t *tnrh_list; 369*1676Sjpk kmutex_t tnrh_lock; 370*1676Sjpk } tnrhc_hash_t; 371*1676Sjpk 372*1676Sjpk #ifdef _KERNEL 373*1676Sjpk typedef enum { 374*1676Sjpk mlptSingle, 375*1676Sjpk mlptPrivate, 376*1676Sjpk mlptShared, 377*1676Sjpk mlptBoth 378*1676Sjpk } mlp_type_t; 379*1676Sjpk 380*1676Sjpk extern tsol_tpc_t *find_tpc(const void *, uchar_t, boolean_t); 381*1676Sjpk extern void tcache_init(void); 382*1676Sjpk extern in_port_t tsol_next_port(zone_t *, in_port_t, int, boolean_t); 383*1676Sjpk extern mlp_type_t tsol_mlp_port_type(zone_t *, uchar_t, uint16_t, mlp_type_t); 384*1676Sjpk extern zoneid_t tsol_mlp_findzone(uchar_t, uint16_t); 385*1676Sjpk extern int tsol_mlp_anon(zone_t *, mlp_type_t, uchar_t, uint16_t, boolean_t); 386*1676Sjpk extern void tsol_print_label(const blevel_t *, const char *); 387*1676Sjpk 388*1676Sjpk struct tsol_gc_s; 389*1676Sjpk struct tsol_gcgrp_s; 390*1676Sjpk struct tsol_gcgrp_addr_s; 391*1676Sjpk 392*1676Sjpk extern struct tsol_gc_s *gc_create(struct rtsa_s *, struct tsol_gcgrp_s *, 393*1676Sjpk boolean_t *); 394*1676Sjpk extern void gc_inactive(struct tsol_gc_s *); 395*1676Sjpk extern int rtsa_validate(const struct rtsa_s *); 396*1676Sjpk extern struct tsol_gcgrp_s *gcgrp_lookup(struct tsol_gcgrp_addr_s *, boolean_t); 397*1676Sjpk extern void gcgrp_inactive(struct tsol_gcgrp_s *); 398*1676Sjpk extern int tnrh_load(const tsol_rhent_t *); 399*1676Sjpk #endif /* _KERNEL */ 400*1676Sjpk 401*1676Sjpk #ifdef __cplusplus 402*1676Sjpk } 403*1676Sjpk #endif 404*1676Sjpk 405*1676Sjpk #endif /* _SYS_TSOL_TNDB_H */ 406