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.
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.
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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 * from "tndb.h 7.34 01/08/31 SMI; TSOL 2.x"
28 #ifndef _SYS_TSOL_TNDB_H
29 #define _SYS_TSOL_TNDB_H
31 #include <sys/types.h>
33 #include <sys/tsol/label.h>
34 #include <sys/tsol/label_macro.h>
38 #include <net/route.h>
45 /* same on ILP32 and LP64 */
46 typedef union tnaddr
{
47 struct sockaddr_in ip_addr_v4
;
48 struct sockaddr_in6 ip_addr_v6
;
51 #define ta_family ip_addr_v4.sin_family
52 #define ta_addr_v4 ip_addr_v4.sin_addr
53 #define ta_addr_v6 ip_addr_v6.sin6_addr
54 #define ta_port_v4 ip_addr_v4.sin_port
55 #define ta_port_v6 ip_addr_v6.sin6_port
57 #define TNADDR_EQ(addr1, addr2) \
58 (((addr1)->ta_family == AF_INET && (addr2)->ta_family == AF_INET && \
59 (addr1)->ta_addr_v4.s_addr == (addr2)->ta_addr_v4.s_addr) || \
60 ((addr1)->ta_family == AF_INET6 && (addr2)->ta_family == AF_INET6 && \
61 IN6_ARE_ADDR_EQUAL(&(addr1)->ta_addr_v6, &(addr2)->ta_addr_v6)))
64 * structure for TN database access routines and TN system calls
67 typedef enum tsol_dbops
{
75 #define TNTNAMSIZ ZONENAME_MAX /* template name size */
76 #define IP_STR_SIZE 200 /* string ip address size */
78 #define TNRHDB_NCOL 2 /* # of columns in tnrhdb */
81 * For tnrhdb access library routines and tnrh(2TSOL)
82 * same for both ILP32 and LP64.
84 typedef struct tsol_rhent
{
85 short rh_prefix
; /* length of subnet mask */
86 short rh_unused
; /* padding */
87 tnaddr_t rh_address
; /* IP address */
88 char rh_template
[TNTNAMSIZ
]; /* template name */
91 typedef struct tsol_rhstr_s
{
98 * host types recognized by tsol hosts
110 typedef struct cipso_tag_type_1
{
111 uchar_t tag_type
; /* Tag Type (1) */
112 uchar_t tag_length
; /* Length of Tag */
113 uchar_t tag_align
; /* Alignment Octet */
114 uchar_t tag_sl
; /* Sensitivity Level */
115 uchar_t tag_cat
[1]; /* Categories */
116 } cipso_tag_type_1_t
;
118 #define TSOL_CIPSO_MIN_LENGTH 6
119 #define TSOL_CIPSO_MAX_LENGTH IP_MAX_OPT_LENGTH
120 #define TSOL_TT1_MIN_LENGTH 4
121 #define TSOL_TT1_MAX_LENGTH 34
123 #define TSOL_CIPSO_DOI_OFFSET 2
124 #define TSOL_CIPSO_TAG_OFFSET 6
126 typedef struct cipso_option
{
127 uchar_t cipso_type
; /* Type of option (134) */
128 uchar_t cipso_length
; /* Length of option */
129 uchar_t cipso_doi
[4]; /* Domain of Interpretation */
130 uchar_t cipso_tag_type
[1]; /* variable length */
134 * RIPSO classifications
136 #define TSOL_CL_TOP_SECRET 0x3d
137 #define TSOL_CL_SECRET 0x5a
138 #define TSOL_CL_CONFIDENTIAL 0x96
139 #define TSOL_CL_UNCLASSIFIED 0xab
142 * RIPSO protection authorities
144 #define TSOL_PA_GENSER 0x80
145 #define TSOL_PA_SIOP_ESI 0x40
146 #define TSOL_PA_SCI 0x20
147 #define TSOL_PA_NSA 0x10
148 #define TSOL_PA_DOE 0x08
151 * this mask is only used for tndb structures, and is different
152 * from t6mask_t bits definitions
155 typedef unsigned int tnmask_t
;
158 * unlabeled host structure for the tnrhtp template.
159 * same for both ILP32 and LP64.
162 tnmask_t mask
; /* tells which attributes are returned by the library */
163 bslabel_t def_label
; /* default label */
164 brange_t gw_sl_range
; /* for routing only */
165 blset_t sl_set
; /* label set */
169 * CIPSO host structure for the tnrhtp template
170 * same for both ILP32 and LP64.
173 tnmask_t mask
; /* tells which attributes are returned by the library */
174 bclear_t def_cl
; /* default clearance */
175 brange_t sl_range
; /* min/max SL range */
176 blset_t sl_set
; /* label set */
180 * Valid keys and values of the key=value pairs for tnrhtp
182 #define TP_UNLABELED "unlabeled"
183 #define TP_CIPSO "cipso"
184 #define TP_ZONE "zone"
185 #define TP_HOSTTYPE "host_type"
187 #define TP_DEFLABEL "def_label"
188 #define TP_MINLABEL "min_sl"
189 #define TP_MAXLABEL "max_sl"
190 #define TP_SET "sl_set"
194 #define TNRHTP_NCOL 2 /* # of columns in tnrhtp */
197 * For tnrhtp access library routines and tnrhtp(2TSOL)
198 * same for both ILP32 and LP64.
200 typedef struct tsol_tpent
{
201 char name
[TNTNAMSIZ
]; /* template name */
202 tsol_host_type_t host_type
; /* specifies host type */
203 int tp_doi
; /* Domain of Interpretation */
204 #define tp_cipso_doi_unl tp_doi
205 #define tp_cipso_doi_cipso tp_doi
207 struct tsol_unl unl
; /* template for unlabeled */
208 #define tp_mask_unl un.unl.mask
209 #define tp_def_label un.unl.def_label
210 #define tp_gw_sl_range un.unl.gw_sl_range
211 #define tp_gw_sl_set un.unl.sl_set
213 struct tsol_cipso cipso
; /* template for CIPSO */
214 #define tp_mask_cipso un.cipso.mask
215 #define tp_def_cl_cipso un.cipso.def_cl
216 #define tp_sl_range_cipso un.cipso.sl_range
217 #define tp_sl_set_cipso un.cipso.sl_set
221 typedef struct tsol_tpstr_s
{
227 * For tnmlp(2TSOL); same for both ILP32 and LP64.
229 typedef struct tsol_mlpent
{
230 zoneid_t tsme_zoneid
;
231 uint_t tsme_flags
; /* TSOL_MEF_* */
235 #define TSOL_MEF_SHARED 0x00000001 /* MLP defined on shared addresses */
238 * For tnzonecfg access library routines.
239 * List of MLPs ends with null entry, where protocol and port are both zero.
241 typedef struct tsol_zcent
{
242 char zc_name
[ZONENAME_MAX
];
246 tsol_mlp_t
*zc_private_mlp
;
247 tsol_mlp_t
*zc_shared_mlp
;
249 #define TSOL_MLP_END(mlp) ((mlp)->mlp_ipp == 0 && (mlp)->mlp_port == 0)
251 typedef struct tsol_tpc
{
252 kmutex_t tpc_lock
; /* lock for structure */
253 uint_t tpc_refcnt
; /* reference count */
254 boolean_t tpc_invalid
; /* entry has been deleted */
255 struct tsol_tpent tpc_tp
; /* template */
258 typedef struct tsol_tnrhc
{
259 struct tsol_tnrhc
*rhc_next
; /* link to next entry */
260 kmutex_t rhc_lock
; /* lock for structure */
261 tnaddr_t rhc_host
; /* IPv4/IPv6 host address */
262 tsol_tpc_t
*rhc_tpc
; /* pointer to template */
263 uint_t rhc_refcnt
; /* Number of references */
264 char rhc_invalid
; /* out-of-date rhc */
265 char rhc_isbcast
; /* broadcast address */
266 char rhc_local
; /* loopback or local interace */
269 /* Size of remote host hash tables in kernel */
270 #define TNRHC_SIZE 256
271 #define TSOL_MASK_TABLE_SIZE 33
272 #define TSOL_MASK_TABLE_SIZE_V6 129
275 #define TNRHC_HOLD(a) { \
276 mutex_enter(&(a)->rhc_lock); \
278 ASSERT((a)->rhc_refcnt > 0); \
279 mutex_exit(&(a)->rhc_lock); \
281 #define TNRHC_RELE(a) { \
282 mutex_enter(&(a)->rhc_lock); \
283 ASSERT((a)->rhc_refcnt > 0); \
284 if (--(a)->rhc_refcnt <= 0) \
287 mutex_exit(&(a)->rhc_lock); \
289 extern void tnrhc_free(tsol_tnrhc_t
*);
290 #define TPC_HOLD(a) { \
291 mutex_enter(&(a)->tpc_lock); \
293 ASSERT((a)->tpc_refcnt > 0); \
294 mutex_exit(&(a)->tpc_lock); \
296 #define TPC_RELE(a) { \
297 mutex_enter(&(a)->tpc_lock); \
298 ASSERT((a)->tpc_refcnt > 0); \
299 if (--(a)->tpc_refcnt <= 0) \
302 mutex_exit(&(a)->tpc_lock); \
304 extern void tpc_free(tsol_tpc_t
*);
308 * The next three hashing macros are copied from macros in ip_ire.h.
310 #define TSOL_ADDR_HASH(addr, table_size) \
311 (((((addr) >> 16) ^ (addr)) ^ ((((addr) >> 16) ^ (addr))>> 8)) \
314 #define TSOL_ADDR_HASH_V6(addr, table_size) \
315 (((addr).s6_addr8[8] ^ (addr).s6_addr8[9] ^ \
316 (addr).s6_addr8[10] ^ (addr).s6_addr8[13] ^ \
317 (addr).s6_addr8[14] ^ (addr).s6_addr8[15]) % (table_size))
319 /* This assumes that table_size is a power of 2. */
320 #define TSOL_ADDR_MASK_HASH_V6(addr, mask, table_size) \
321 ((((addr).s6_addr8[8] & (mask).s6_addr8[8]) ^ \
322 ((addr).s6_addr8[9] & (mask).s6_addr8[9]) ^ \
323 ((addr).s6_addr8[10] & (mask).s6_addr8[10]) ^ \
324 ((addr).s6_addr8[13] & (mask).s6_addr8[13]) ^ \
325 ((addr).s6_addr8[14] & (mask).s6_addr8[14]) ^ \
326 ((addr).s6_addr8[15] & (mask).s6_addr8[15])) & ((table_size) - 1))
330 * Constants used for getting the mask value in struct tsol_tpent
335 TNT_SL_RANGE_TSOL
, /* use this for both unl and zone */
342 #define tsol_tntmask(value) ((unsigned int)(1<<(value)))
344 #define TSOL_MSK_DEF_LABEL tsol_tntmask(TNT_DEF_LABEL)
345 #define TSOL_MSK_DEF_CL tsol_tntmask(TNT_DEF_CL)
346 #define TSOL_MSK_SL_RANGE_TSOL tsol_tntmask(TNT_SL_RANGE_TSOL)
347 #define TSOL_MSK_CIPSO_DOI tsol_tntmask(TNT_CIPSO_DOI)
352 #define TSOL_PARSE_ERANGE 1 /* result buffer not allocated */
353 #define TSOL_NOT_SUPPORTED 2 /* address family not supported */
354 #define TSOL_NOT_FOUND 3 /* search by * routines target not found */
357 * Structure used to hold a list of IP addresses.
359 typedef struct tsol_address
{
360 struct tsol_address
*next
;
361 in_addr_t ip_address
;
364 /* This is shared between tcache and mdb */
365 typedef struct tnrhc_hash_s
{
366 tsol_tnrhc_t
*tnrh_list
;
378 extern tsol_tpc_t
*find_tpc(const void *, uchar_t
, boolean_t
);
379 extern void tcache_init(void);
380 extern in_port_t
tsol_next_port(zone_t
*, in_port_t
, int, boolean_t
);
381 extern mlp_type_t
tsol_mlp_port_type(zone_t
*, uchar_t
, uint16_t, mlp_type_t
);
382 extern zoneid_t
tsol_mlp_findzone(uchar_t
, uint16_t);
383 extern int tsol_mlp_anon(zone_t
*, mlp_type_t
, uchar_t
, uint16_t, boolean_t
);
384 extern void tsol_print_label(const blevel_t
*, const char *);
388 struct tsol_gcgrp_addr_s
;
390 extern struct tsol_gc_s
*gc_create(struct rtsa_s
*, struct tsol_gcgrp_s
*,
392 extern void gc_inactive(struct tsol_gc_s
*);
393 extern int rtsa_validate(const struct rtsa_s
*);
394 extern struct tsol_gcgrp_s
*gcgrp_lookup(struct tsol_gcgrp_addr_s
*, boolean_t
);
395 extern void gcgrp_inactive(struct tsol_gcgrp_s
*);
396 extern int tnrh_load(const tsol_rhent_t
*);
403 #endif /* _SYS_TSOL_TNDB_H */