xref: /titanic_50/usr/src/lib/libtsnet/common/libtsnet.h (revision ff3124eff995e6cd8ebd8c6543648e0670920034)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  * All symbols and functions in this header file and library are private to Sun
26  * Microsystems.  The only guarantee that is made is that if your application
27  * uses them, it will break on upgrade.
28  */
29 
30 #ifndef	_LIBTSNET_H
31 #define	_LIBTSNET_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #include <stdio.h>
36 #include <sys/tsol/tndb.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #define	TNRHTP_PATH	"/etc/security/tsol/tnrhtp"
43 #define	TNRHDB_PATH	"/etc/security/tsol/tnrhdb"
44 #define	TNZONECFG_PATH	"/etc/security/tsol/tnzonecfg"
45 
46 #define	TNDB_COMMA	", \t"
47 #define	TN_RESERVED	",#;"
48 
49 /*
50  * String parsing routines
51  *
52  * These functions are in four logical groups: one for template (tnrhtp)
53  * entries, one for remote host (tnrhdb) entries, one for zone configuration
54  * (tnzonecfg) entries, and a fourth for routing attributes.
55  *
56  * In each group, there are functions that parse from a string or database, and
57  * a function to free returned entries.  The parsing functions all take a
58  * pointer to an integer and a pointer to a character pointer for returning
59  * errors.  On error, the returned entry pointer is NULL, the integer is set to
60  * one of the LTSNET_* errors below, and the character pointer points to the
61  * location of the error.  (For the functions that iterate on a database, this
62  * points into static storage in the library.  This storage is associated with
63  * the iterator.)
64  *
65  * The functions that do look-ups based on a value (name or address) do not
66  * return errors other than "not found," which is signaled by a return value of
67  * NULL.
68  */
69 
70 /* Template entry parsing */
71 extern tsol_tpent_t *tsol_gettpbyname(const char *);
72 extern tsol_tpent_t *tsol_gettpent(void);
73 extern tsol_tpent_t *tsol_fgettpent(FILE *, boolean_t *);
74 extern void tsol_freetpent(tsol_tpent_t *);
75 extern void tsol_settpent(int);
76 extern void tsol_endtpent(void);
77 extern int str_to_tpstr(const char *, int, void *, char *, int);
78 extern tsol_tpent_t *tpstr_to_ent(tsol_tpstr_t *, int *, char **);
79 
80 /* Remote host entry parsing */
81 extern tsol_rhent_t *tsol_getrhbyaddr(const void *, size_t, int);
82 extern tsol_rhent_t *tsol_getrhent(void);
83 extern tsol_rhent_t *tsol_fgetrhent(FILE *, boolean_t *);
84 extern void tsol_freerhent(tsol_rhent_t *);
85 extern void tsol_setrhent(int);
86 extern void tsol_endrhent(void);
87 extern int str_to_rhstr(const char *, int, void *, char *, int);
88 extern tsol_rhent_t *rhstr_to_ent(tsol_rhstr_t *, int *, char **);
89 extern tsol_host_type_t tsol_getrhtype(char *);
90 
91 
92 /* Zone configuration parsing */
93 extern tsol_zcent_t *tsol_sgetzcent(const char *, int *, char **);
94 extern void tsol_freezcent(tsol_zcent_t *);
95 
96 /* Routing attribute parsing */
97 extern const char *sl_to_str(const bslabel_t *);
98 struct rtsa_s;
99 extern const char *rtsa_to_str(const struct rtsa_s *, char *, size_t);
100 extern boolean_t rtsa_keyword(const char *, struct rtsa_s *, int *, char **);
101 extern const char *parse_entry(char *, size_t, const char *, const char *);
102 
103 /* Convert LTSNET_* to a printable string */
104 extern const char *tsol_strerror(int, int);
105 
106 /* System calls; these return -1 on error and set errno */
107 extern int tnrhtp(int, tsol_tpent_t *);
108 extern int tnrh(int, tsol_rhent_t *);
109 extern int tnmlp(int, tsol_mlpent_t *);
110 
111 /*
112  * Errors that can occur in the parsing routines.  Note that not all errors are
113  * possible with every routine.  Must be kept in sync with list in misc.c.
114  */
115 #define	LTSNET_NONE		0	/* No error */
116 #define	LTSNET_SYSERR		1	/* System error; see errno */
117 #define	LTSNET_EMPTY		2	/* Empty string or end of list */
118 #define	LTSNET_ILL_ENTRY	3	/* Entry is malformed */
119 #define	LTSNET_NO_NAME		4	/* Missing name */
120 #define	LTSNET_NO_ATTRS		5	/* Missing template attributes */
121 #define	LTSNET_ILL_NAME		6	/* Illegal name */
122 #define	LTSNET_ILL_KEYDELIM	7	/* Illegal keyword delimiter */
123 #define	LTSNET_ILL_KEY		8	/* Unknown keyword */
124 #define	LTSNET_DUP_KEY		9	/* Duplicate keyword */
125 #define	LTSNET_ILL_VALDELIM	10	/* Illegal value delimiter */
126 #define	LTSNET_NO_HOSTTYPE	11	/* Missing host type */
127 #define	LTSNET_ILL_HOSTTYPE	12	/* Illegal host type */
128 #define	LTSNET_NO_LABEL		13	/* Missing label */
129 #define	LTSNET_ILL_LABEL	14	/* Illegal label */
130 #define	LTSNET_NO_RANGE		15	/* Missing label range */
131 #define	LTSNET_ILL_RANGE	16	/* Illegal label range */
132 #define	LTSNET_NO_LOWERBOUND	17	/* No lower bound in range */
133 #define	LTSNET_ILL_LOWERBOUND	18	/* Illegal lower bound in range */
134 #define	LTSNET_NO_UPPERBOUND	19	/* No upper bound in range */
135 #define	LTSNET_ILL_UPPERBOUND	20	/* Illegal upper bound in range */
136 #define	LTSNET_NO_DOI		21	/* Missing DOI */
137 #define	LTSNET_ILL_DOI		22	/* Illegal DOI */
138 #define	LTSNET_SET_TOO_BIG	23	/* Too many entries in set */
139 #define	LTSNET_NO_ADDR		24	/* Missing address/network */
140 #define	LTSNET_ILL_ADDR		25	/* Illegal address/network */
141 #define	LTSNET_ILL_FLAG		26	/* Illegal flag */
142 #define	LTSNET_ILL_MLP		27	/* Illegal MLP specification */
143 #define	LTSNET_BAD_TYPE		28	/* Unacceptable keyword for type */
144 
145 #ifdef	__cplusplus
146 }
147 #endif
148 
149 #endif	/* _LIBTSNET_H */
150