xref: /titanic_51/usr/src/head/libzonecfg.h (revision 113f42324b1acf3e5144da27ddbda36e338fbd07)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _LIBZONECFG_H
28 #define	_LIBZONECFG_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Zone configuration header file.
34  */
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /* sys/socket.h is required by net/if.h, which has a constant needed here */
41 #include <sys/param.h>
42 #include <sys/fstyp.h>
43 #include <sys/mount.h>
44 #include <priv.h>
45 #include <netinet/in.h>
46 #include <sys/socket.h>
47 #include <net/if.h>
48 #include <stdio.h>
49 #include <rctl.h>
50 #include <zone.h>
51 
52 #define	ZONE_ID_UNDEFINED	-1
53 
54 #define	Z_OK			0
55 #define	Z_EMPTY_DOCUMENT	1	/* XML doc root element is null */
56 #define	Z_WRONG_DOC_TYPE	2	/* top-level XML doc element != zone */
57 #define	Z_BAD_PROPERTY		3	/* libxml-level property problem */
58 #define	Z_TEMP_FILE		4	/* problem creating temporary file */
59 #define	Z_SAVING_FILE		5	/* libxml error saving or validating */
60 #define	Z_NO_ENTRY		6	/* no such entry */
61 #define	Z_BOGUS_ZONE_NAME	7	/* illegal zone name */
62 #define	Z_REQD_RESOURCE_MISSING	8	/* required resource missing */
63 #define	Z_REQD_PROPERTY_MISSING	9	/* required property missing */
64 #define	Z_BAD_HANDLE		10	/* bad document handle */
65 #define	Z_NOMEM			11	/* out of memory (like ENOMEM) */
66 #define	Z_INVAL			12	/* invalid argument (like EINVAL) */
67 #define	Z_ACCES			13	/* permission denied (like EACCES) */
68 #define	Z_TOO_BIG		14	/* string won't fit in char array */
69 #define	Z_MISC_FS		15	/* miscellaneous file-system error */
70 #define	Z_NO_ZONE		16	/* no such zone */
71 #define	Z_NO_RESOURCE_TYPE	17	/* no/wrong resource type */
72 #define	Z_NO_RESOURCE_ID	18	/* no/wrong resource id */
73 #define	Z_NO_PROPERTY_TYPE	19	/* no/wrong property type */
74 #define	Z_NO_PROPERTY_ID	20	/* no/wrong property id */
75 #define	Z_BAD_ZONE_STATE	21	/* zone state invalid for given task */
76 #define	Z_INVALID_DOCUMENT	22	/* libxml can't validate against DTD */
77 #define	Z_NAME_IN_USE		23	/* zone name already in use (rename) */
78 #define	Z_NO_SUCH_ID		24	/* delete_index: no old ID */
79 #define	Z_UPDATING_INDEX	25	/* add/modify/delete_index problem */
80 #define	Z_LOCKING_FILE		26	/* problem locking index file */
81 #define	Z_UNLOCKING_FILE	27	/* problem unlocking index file */
82 #define	Z_SYSTEM		28	/* consult errno instead */
83 #define	Z_INSUFFICIENT_SPEC	29	/* resource insufficiently specified */
84 #define	Z_RESOLVED_PATH		34	/* resolved path mismatch */
85 #define	Z_IPV6_ADDR_PREFIX_LEN	35	/* IPv6 address prefix length needed */
86 #define	Z_BOGUS_ADDRESS		36	/* not IPv[4|6] address or host name */
87 
88 #define	ZONE_STATE_CONFIGURED		0
89 #define	ZONE_STATE_INCOMPLETE		1
90 #define	ZONE_STATE_INSTALLED		2
91 #define	ZONE_STATE_READY		3
92 #define	ZONE_STATE_RUNNING		4
93 #define	ZONE_STATE_SHUTTING_DOWN	5
94 #define	ZONE_STATE_DOWN			6
95 
96 #define	ZONE_STATE_MAXSTRLEN	14
97 
98 #define	LIBZONECFG_PATH		"libzonecfg.so.1"
99 
100 #define	ZONE_CONFIG_ROOT	"/etc/zones"
101 #define	ZONE_INDEX_FILE		ZONE_CONFIG_ROOT "/index"
102 
103 /*
104  * The integer field expresses the current values on a get.
105  * On a put, it represents the new values if >= 0 or "don't change" if < 0.
106  */
107 struct zoneent {
108 	char	zone_name[ZONENAME_MAX];	/* name of the zone */
109 	int	zone_state;	/* configured | incomplete | installed */
110 	char	zone_path[MAXPATHLEN];
111 	char	zone_newname[ZONENAME_MAX];	/* for doing renames */
112 };
113 
114 typedef struct zone_dochandle *zone_dochandle_t;	/* opaque handle */
115 
116 typedef uint_t zone_state_t;
117 
118 typedef struct zone_fsopt {
119 	struct zone_fsopt *zone_fsopt_next;
120 	char		   zone_fsopt_opt[MAX_MNTOPT_STR];
121 } zone_fsopt_t;
122 
123 struct zone_fstab {
124 	char		zone_fs_special[MAXPATHLEN]; 	/* special file */
125 	char		zone_fs_dir[MAXPATHLEN];	/* mount point */
126 	char		zone_fs_type[FSTYPSZ];		/* e.g. ufs */
127 	zone_fsopt_t   *zone_fs_options;		/* mount options */
128 	char		zone_fs_raw[MAXPATHLEN];	/* device to fsck */
129 };
130 
131 struct zone_nwiftab {
132 	char	zone_nwif_address[INET6_ADDRSTRLEN];
133 	char	zone_nwif_physical[LIFNAMSIZ];
134 };
135 
136 struct zone_devtab {
137 	char	zone_dev_match[MAXPATHLEN];
138 };
139 
140 struct zone_rctlvaltab {
141 	char	zone_rctlval_priv[MAXNAMELEN];
142 	char	zone_rctlval_limit[MAXNAMELEN];
143 	char	zone_rctlval_action[MAXNAMELEN];
144 	struct zone_rctlvaltab *zone_rctlval_next;
145 };
146 
147 struct zone_rctltab {
148 	char	zone_rctl_name[MAXNAMELEN];
149 	struct zone_rctlvaltab *zone_rctl_valptr;
150 };
151 
152 struct zone_attrtab {
153 	char	zone_attr_name[MAXNAMELEN];
154 	char	zone_attr_type[MAXNAMELEN];
155 	char	zone_attr_value[2 * BUFSIZ];
156 };
157 
158 /*
159  * Basic configuration management routines.
160  */
161 extern	zone_dochandle_t	zonecfg_init_handle(void);
162 extern	int	zonecfg_get_handle(char *, zone_dochandle_t);
163 extern	int	zonecfg_get_snapshot_handle(char *, zone_dochandle_t);
164 extern	int	zonecfg_get_template_handle(char *, char *, zone_dochandle_t);
165 extern	int	zonecfg_check_handle(zone_dochandle_t);
166 extern	void	zonecfg_fini_handle(zone_dochandle_t);
167 extern	int	zonecfg_destroy(const char *, boolean_t);
168 extern	int	zonecfg_destroy_snapshot(char *);
169 extern	int	zonecfg_save(zone_dochandle_t);
170 extern	int	zonecfg_create_snapshot(char *);
171 extern	char	*zonecfg_strerror(int);
172 extern	int	zonecfg_access(const char *, int);
173 
174 /*
175  * Zone name, path to zone directory, autoboot setting and pool.
176  */
177 extern	int	zonecfg_validate_zonename(char *);
178 extern	int	zonecfg_get_name(zone_dochandle_t, char *, size_t);
179 extern	int	zonecfg_set_name(zone_dochandle_t, char *);
180 extern	int	zonecfg_get_zonepath(zone_dochandle_t, char *, size_t);
181 extern	int	zonecfg_set_zonepath(zone_dochandle_t, char *);
182 extern	int	zonecfg_get_autoboot(zone_dochandle_t, boolean_t *);
183 extern	int	zonecfg_set_autoboot(zone_dochandle_t, boolean_t);
184 extern	int	zonecfg_get_pool(zone_dochandle_t, char *, size_t);
185 extern	int	zonecfg_set_pool(zone_dochandle_t, char *);
186 
187 /*
188  * Filesystem configuration.
189  */
190 extern	int	zonecfg_add_filesystem(zone_dochandle_t, struct zone_fstab *);
191 extern	int	zonecfg_delete_filesystem(zone_dochandle_t,
192     struct zone_fstab *);
193 extern	int	zonecfg_modify_filesystem(zone_dochandle_t,
194     struct zone_fstab *, struct zone_fstab *);
195 extern	int	zonecfg_lookup_filesystem(zone_dochandle_t,
196     struct zone_fstab *);
197 extern	int	zonecfg_add_ipd(zone_dochandle_t, struct zone_fstab *);
198 extern	int	zonecfg_delete_ipd(zone_dochandle_t, struct zone_fstab *);
199 extern	int	zonecfg_modify_ipd(zone_dochandle_t,
200     struct zone_fstab *, struct zone_fstab *);
201 extern	int	zonecfg_lookup_ipd(zone_dochandle_t, struct zone_fstab *);
202 extern	int	zonecfg_add_fs_option(struct zone_fstab *, char *);
203 extern	int	zonecfg_remove_fs_option(struct zone_fstab *, char *);
204 extern	void	zonecfg_free_fs_option_list(zone_fsopt_t *);
205 extern	int 	zonecfg_find_mounts(char *, int(*)(const char *, void *),
206     void *);
207 
208 /*
209  * Network interface configuration.
210  */
211 extern	int	zonecfg_add_nwif(zone_dochandle_t, struct zone_nwiftab *);
212 extern	int	zonecfg_delete_nwif(zone_dochandle_t, struct zone_nwiftab *);
213 extern	int	zonecfg_modify_nwif(zone_dochandle_t, struct zone_nwiftab *,
214     struct zone_nwiftab *);
215 extern	int	zonecfg_lookup_nwif(zone_dochandle_t, struct zone_nwiftab *);
216 
217 /*
218  * Device configuration and rule matching.
219  */
220 extern	int	zonecfg_add_dev(zone_dochandle_t, struct zone_devtab *);
221 extern	int	zonecfg_delete_dev(zone_dochandle_t, struct zone_devtab *);
222 extern	int	zonecfg_modify_dev(zone_dochandle_t, struct zone_devtab *,
223     struct zone_devtab *);
224 extern	int	zonecfg_lookup_dev(zone_dochandle_t, struct zone_devtab *);
225 extern	int	zonecfg_match_dev(zone_dochandle_t, char *,
226     struct zone_devtab *);
227 
228 /*
229  * Resource control configuration.
230  */
231 extern	int	zonecfg_add_rctl(zone_dochandle_t, struct zone_rctltab *);
232 extern	int	zonecfg_delete_rctl(zone_dochandle_t, struct zone_rctltab *);
233 extern	int	zonecfg_modify_rctl(zone_dochandle_t, struct zone_rctltab *,
234     struct zone_rctltab *);
235 extern	int	zonecfg_lookup_rctl(zone_dochandle_t, struct zone_rctltab *);
236 extern	int	zonecfg_add_rctl_value(struct zone_rctltab *,
237     struct zone_rctlvaltab *);
238 extern	int	zonecfg_remove_rctl_value(struct zone_rctltab *,
239     struct zone_rctlvaltab *);
240 extern	void	zonecfg_free_rctl_value_list(struct zone_rctlvaltab *);
241 
242 /*
243  * Generic attribute configuration and type/value extraction.
244  */
245 extern	int	zonecfg_add_attr(zone_dochandle_t, struct zone_attrtab *);
246 extern	int	zonecfg_delete_attr(zone_dochandle_t, struct zone_attrtab *);
247 extern	int	zonecfg_modify_attr(zone_dochandle_t, struct zone_attrtab *,
248     struct zone_attrtab *);
249 extern	int	zonecfg_lookup_attr(zone_dochandle_t, struct zone_attrtab *);
250 extern	int	zonecfg_get_attr_boolean(const struct zone_attrtab *,
251     boolean_t *);
252 extern	int	zonecfg_get_attr_int(const struct zone_attrtab *, int64_t *);
253 extern	int	zonecfg_get_attr_string(const struct zone_attrtab *, char *,
254     size_t);
255 extern	int	zonecfg_get_attr_uint(const struct zone_attrtab *, uint64_t *);
256 
257 /*
258  * '*ent' iterator routines.
259  */
260 extern	int	zonecfg_setfsent(zone_dochandle_t);
261 extern	int	zonecfg_getfsent(zone_dochandle_t, struct zone_fstab *);
262 extern	int	zonecfg_endfsent(zone_dochandle_t);
263 extern	int	zonecfg_setipdent(zone_dochandle_t);
264 extern	int	zonecfg_getipdent(zone_dochandle_t, struct zone_fstab *);
265 extern	int	zonecfg_endipdent(zone_dochandle_t);
266 extern	int	zonecfg_setnwifent(zone_dochandle_t);
267 extern	int	zonecfg_getnwifent(zone_dochandle_t, struct zone_nwiftab *);
268 extern	int	zonecfg_endnwifent(zone_dochandle_t);
269 extern	int	zonecfg_setdevent(zone_dochandle_t);
270 extern	int	zonecfg_getdevent(zone_dochandle_t, struct zone_devtab *);
271 extern	int	zonecfg_enddevent(zone_dochandle_t);
272 extern	int	zonecfg_setattrent(zone_dochandle_t);
273 extern	int	zonecfg_getattrent(zone_dochandle_t, struct zone_attrtab *);
274 extern	int	zonecfg_endattrent(zone_dochandle_t);
275 extern	int	zonecfg_setrctlent(zone_dochandle_t);
276 extern	int	zonecfg_getrctlent(zone_dochandle_t, struct zone_rctltab *);
277 extern	int	zonecfg_endrctlent(zone_dochandle_t);
278 
279 /*
280  * Privilege-related functions.
281  */
282 extern	int	zonecfg_get_privset(priv_set_t *);
283 
284 /*
285  * Higher-level routines.
286  */
287 extern	int	zone_get_rootpath(char *, char *, size_t);
288 extern	int	zone_get_zonepath(char *, char *, size_t);
289 extern	int	zone_get_state(char *, zone_state_t *);
290 extern	int	zone_set_state(char *, zone_state_t);
291 extern	char	*zone_state_str(zone_state_t);
292 
293 /*
294  * Iterator for configured zones.
295  */
296 extern FILE		*setzoneent(void);
297 extern char		*getzoneent(FILE *);
298 extern struct zoneent	*getzoneent_private(FILE *);
299 extern void		endzoneent(FILE *);
300 
301 /*
302  * File-system-related convenience functions.
303  */
304 extern boolean_t zonecfg_valid_fs_type(const char *);
305 
306 /*
307  * Network-related convenience functions.
308  */
309 extern boolean_t zonecfg_same_net_address(char *, char *);
310 extern int zonecfg_valid_net_address(char *, struct lifreq *);
311 
312 /*
313  * Rctl-related common functions.
314  */
315 extern boolean_t zonecfg_is_rctl(const char *);
316 extern boolean_t zonecfg_valid_rctlname(const char *);
317 extern boolean_t zonecfg_valid_rctlblk(const rctlblk_t *);
318 extern boolean_t zonecfg_valid_rctl(const char *, const rctlblk_t *);
319 extern int zonecfg_construct_rctlblk(const struct zone_rctlvaltab *,
320     rctlblk_t *);
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 
326 #endif	/* _LIBZONECFG_H */
327