xref: /titanic_44/usr/src/head/libzonecfg.h (revision 28167c24ba5be8b7c1d05e02d053f4a55cd21cc9)
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 #include <sys/uuid.h>
52 
53 #define	ZONE_ID_UNDEFINED	-1
54 
55 #define	Z_OK			0
56 #define	Z_EMPTY_DOCUMENT	1	/* XML doc root element is null */
57 #define	Z_WRONG_DOC_TYPE	2	/* top-level XML doc element != zone */
58 #define	Z_BAD_PROPERTY		3	/* libxml-level property problem */
59 #define	Z_TEMP_FILE		4	/* problem creating temporary file */
60 #define	Z_SAVING_FILE		5	/* libxml error saving or validating */
61 #define	Z_NO_ENTRY		6	/* no such entry */
62 #define	Z_BOGUS_ZONE_NAME	7	/* illegal zone name */
63 #define	Z_REQD_RESOURCE_MISSING	8	/* required resource missing */
64 #define	Z_REQD_PROPERTY_MISSING	9	/* required property missing */
65 #define	Z_BAD_HANDLE		10	/* bad document handle */
66 #define	Z_NOMEM			11	/* out of memory (like ENOMEM) */
67 #define	Z_INVAL			12	/* invalid argument (like EINVAL) */
68 #define	Z_ACCES			13	/* permission denied (like EACCES) */
69 #define	Z_TOO_BIG		14	/* string won't fit in char array */
70 #define	Z_MISC_FS		15	/* miscellaneous file-system error */
71 #define	Z_NO_ZONE		16	/* no such zone */
72 #define	Z_NO_RESOURCE_TYPE	17	/* no/wrong resource type */
73 #define	Z_NO_RESOURCE_ID	18	/* no/wrong resource id */
74 #define	Z_NO_PROPERTY_TYPE	19	/* no/wrong property type */
75 #define	Z_NO_PROPERTY_ID	20	/* no/wrong property id */
76 #define	Z_BAD_ZONE_STATE	21	/* zone state invalid for given task */
77 #define	Z_INVALID_DOCUMENT	22	/* libxml can't validate against DTD */
78 #define	Z_NAME_IN_USE		23	/* zone name already in use (rename) */
79 #define	Z_NO_SUCH_ID		24	/* delete_index: no old ID */
80 #define	Z_UPDATING_INDEX	25	/* add/modify/delete_index problem */
81 #define	Z_LOCKING_FILE		26	/* problem locking index file */
82 #define	Z_UNLOCKING_FILE	27	/* problem unlocking index file */
83 #define	Z_SYSTEM		28	/* consult errno instead */
84 #define	Z_INSUFFICIENT_SPEC	29	/* resource insufficiently specified */
85 #define	Z_RESOLVED_PATH		34	/* resolved path mismatch */
86 #define	Z_IPV6_ADDR_PREFIX_LEN	35	/* IPv6 address prefix length needed */
87 #define	Z_BOGUS_ADDRESS		36	/* not IPv[4|6] address or host name */
88 
89 /*
90  * Warning: these are shared with the admin/install consolidation.
91  * Do not insert states between any of the currently defined states,
92  * and any new states must be evaluated for impact on range comparisons.
93  */
94 #define	ZONE_STATE_CONFIGURED		0
95 #define	ZONE_STATE_INCOMPLETE		1
96 #define	ZONE_STATE_INSTALLED		2
97 #define	ZONE_STATE_READY		3
98 #define	ZONE_STATE_RUNNING		4
99 #define	ZONE_STATE_SHUTTING_DOWN	5
100 #define	ZONE_STATE_DOWN			6
101 #define	ZONE_STATE_MOUNTED		7
102 
103 #define	ZONE_STATE_MAXSTRLEN	14
104 
105 #define	LIBZONECFG_PATH		"libzonecfg.so.1"
106 
107 #define	ZONE_CONFIG_ROOT	"/etc/zones"
108 #define	ZONE_INDEX_FILE		ZONE_CONFIG_ROOT "/index"
109 
110 /*
111  * The integer field expresses the current values on a get.
112  * On a put, it represents the new values if >= 0 or "don't change" if < 0.
113  */
114 struct zoneent {
115 	char	zone_name[ZONENAME_MAX];	/* name of the zone */
116 	int	zone_state;	/* configured | incomplete | installed */
117 	char	zone_path[MAXPATHLEN];		/* path to zone storage */
118 	uuid_t	zone_uuid;			/* unique ID for zone */
119 	char	zone_newname[ZONENAME_MAX];	/* for doing renames */
120 };
121 
122 typedef struct zone_dochandle *zone_dochandle_t;	/* opaque handle */
123 
124 typedef uint_t zone_state_t;
125 
126 typedef struct zone_fsopt {
127 	struct zone_fsopt *zone_fsopt_next;
128 	char		   zone_fsopt_opt[MAX_MNTOPT_STR];
129 } zone_fsopt_t;
130 
131 struct zone_fstab {
132 	char		zone_fs_special[MAXPATHLEN]; 	/* special file */
133 	char		zone_fs_dir[MAXPATHLEN];	/* mount point */
134 	char		zone_fs_type[FSTYPSZ];		/* e.g. ufs */
135 	zone_fsopt_t   *zone_fs_options;		/* mount options */
136 	char		zone_fs_raw[MAXPATHLEN];	/* device to fsck */
137 };
138 
139 struct zone_nwiftab {
140 	char	zone_nwif_address[INET6_ADDRSTRLEN];
141 	char	zone_nwif_physical[LIFNAMSIZ];
142 };
143 
144 struct zone_devtab {
145 	char	zone_dev_match[MAXPATHLEN];
146 };
147 
148 struct zone_rctlvaltab {
149 	char	zone_rctlval_priv[MAXNAMELEN];
150 	char	zone_rctlval_limit[MAXNAMELEN];
151 	char	zone_rctlval_action[MAXNAMELEN];
152 	struct zone_rctlvaltab *zone_rctlval_next;
153 };
154 
155 struct zone_rctltab {
156 	char	zone_rctl_name[MAXNAMELEN];
157 	struct zone_rctlvaltab *zone_rctl_valptr;
158 };
159 
160 struct zone_attrtab {
161 	char	zone_attr_name[MAXNAMELEN];
162 	char	zone_attr_type[MAXNAMELEN];
163 	char	zone_attr_value[2 * BUFSIZ];
164 };
165 
166 struct zone_dstab {
167 	char	zone_dataset_name[MAXNAMELEN];
168 };
169 
170 /*
171  * Basic configuration management routines.
172  */
173 extern	zone_dochandle_t	zonecfg_init_handle(void);
174 extern	int	zonecfg_get_handle(const char *, zone_dochandle_t);
175 extern	int	zonecfg_get_snapshot_handle(const char *, zone_dochandle_t);
176 extern	int	zonecfg_get_template_handle(const char *, const char *,
177     zone_dochandle_t);
178 extern	int	zonecfg_check_handle(zone_dochandle_t);
179 extern	void	zonecfg_fini_handle(zone_dochandle_t);
180 extern	int	zonecfg_destroy(const char *, boolean_t);
181 extern	int	zonecfg_destroy_snapshot(const char *);
182 extern	int	zonecfg_save(zone_dochandle_t);
183 extern	int	zonecfg_create_snapshot(const char *);
184 extern	char	*zonecfg_strerror(int);
185 extern	int	zonecfg_access(const char *, int);
186 extern	void	zonecfg_set_root(const char *);
187 extern	const char *zonecfg_get_root(void);
188 extern	boolean_t zonecfg_in_alt_root(void);
189 
190 /*
191  * Zone name, path to zone directory, autoboot setting and pool.
192  */
193 extern	int	zonecfg_validate_zonename(const char *);
194 extern	int	zonecfg_get_name(zone_dochandle_t, char *, size_t);
195 extern	int	zonecfg_set_name(zone_dochandle_t, char *);
196 extern	int	zonecfg_get_zonepath(zone_dochandle_t, char *, size_t);
197 extern	int	zonecfg_set_zonepath(zone_dochandle_t, char *);
198 extern	int	zonecfg_get_autoboot(zone_dochandle_t, boolean_t *);
199 extern	int	zonecfg_set_autoboot(zone_dochandle_t, boolean_t);
200 extern	int	zonecfg_get_pool(zone_dochandle_t, char *, size_t);
201 extern	int	zonecfg_set_pool(zone_dochandle_t, char *);
202 
203 /*
204  * Filesystem configuration.
205  */
206 extern	int	zonecfg_add_filesystem(zone_dochandle_t, struct zone_fstab *);
207 extern	int	zonecfg_delete_filesystem(zone_dochandle_t,
208     struct zone_fstab *);
209 extern	int	zonecfg_modify_filesystem(zone_dochandle_t,
210     struct zone_fstab *, struct zone_fstab *);
211 extern	int	zonecfg_lookup_filesystem(zone_dochandle_t,
212     struct zone_fstab *);
213 extern	int	zonecfg_add_ipd(zone_dochandle_t, struct zone_fstab *);
214 extern	int	zonecfg_delete_ipd(zone_dochandle_t, struct zone_fstab *);
215 extern	int	zonecfg_modify_ipd(zone_dochandle_t,
216     struct zone_fstab *, struct zone_fstab *);
217 extern	int	zonecfg_lookup_ipd(zone_dochandle_t, struct zone_fstab *);
218 extern	int	zonecfg_add_fs_option(struct zone_fstab *, char *);
219 extern	int	zonecfg_remove_fs_option(struct zone_fstab *, char *);
220 extern	void	zonecfg_free_fs_option_list(zone_fsopt_t *);
221 extern	int 	zonecfg_find_mounts(char *, int(*)(const char *, void *),
222     void *);
223 
224 /*
225  * Network interface configuration.
226  */
227 extern	int	zonecfg_add_nwif(zone_dochandle_t, struct zone_nwiftab *);
228 extern	int	zonecfg_delete_nwif(zone_dochandle_t, struct zone_nwiftab *);
229 extern	int	zonecfg_modify_nwif(zone_dochandle_t, struct zone_nwiftab *,
230     struct zone_nwiftab *);
231 extern	int	zonecfg_lookup_nwif(zone_dochandle_t, struct zone_nwiftab *);
232 
233 /*
234  * Device configuration and rule matching.
235  */
236 extern	int	zonecfg_add_dev(zone_dochandle_t, struct zone_devtab *);
237 extern	int	zonecfg_delete_dev(zone_dochandle_t, struct zone_devtab *);
238 extern	int	zonecfg_modify_dev(zone_dochandle_t, struct zone_devtab *,
239     struct zone_devtab *);
240 extern	int	zonecfg_lookup_dev(zone_dochandle_t, struct zone_devtab *);
241 extern	int	zonecfg_match_dev(zone_dochandle_t, char *,
242     struct zone_devtab *);
243 
244 /*
245  * Resource control configuration.
246  */
247 extern	int	zonecfg_add_rctl(zone_dochandle_t, struct zone_rctltab *);
248 extern	int	zonecfg_delete_rctl(zone_dochandle_t, struct zone_rctltab *);
249 extern	int	zonecfg_modify_rctl(zone_dochandle_t, struct zone_rctltab *,
250     struct zone_rctltab *);
251 extern	int	zonecfg_lookup_rctl(zone_dochandle_t, struct zone_rctltab *);
252 extern	int	zonecfg_add_rctl_value(struct zone_rctltab *,
253     struct zone_rctlvaltab *);
254 extern	int	zonecfg_remove_rctl_value(struct zone_rctltab *,
255     struct zone_rctlvaltab *);
256 extern	void	zonecfg_free_rctl_value_list(struct zone_rctlvaltab *);
257 
258 /*
259  * Generic attribute configuration and type/value extraction.
260  */
261 extern	int	zonecfg_add_attr(zone_dochandle_t, struct zone_attrtab *);
262 extern	int	zonecfg_delete_attr(zone_dochandle_t, struct zone_attrtab *);
263 extern	int	zonecfg_modify_attr(zone_dochandle_t, struct zone_attrtab *,
264     struct zone_attrtab *);
265 extern	int	zonecfg_lookup_attr(zone_dochandle_t, struct zone_attrtab *);
266 extern	int	zonecfg_get_attr_boolean(const struct zone_attrtab *,
267     boolean_t *);
268 extern	int	zonecfg_get_attr_int(const struct zone_attrtab *, int64_t *);
269 extern	int	zonecfg_get_attr_string(const struct zone_attrtab *, char *,
270     size_t);
271 extern	int	zonecfg_get_attr_uint(const struct zone_attrtab *, uint64_t *);
272 
273 /*
274  * ZFS configuration.
275  */
276 extern	int	zonecfg_add_ds(zone_dochandle_t, struct zone_dstab *);
277 extern	int	zonecfg_delete_ds(zone_dochandle_t, struct zone_dstab *);
278 extern	int	zonecfg_modify_ds(zone_dochandle_t, struct zone_dstab *,
279     struct zone_dstab *);
280 extern	int	zonecfg_lookup_ds(zone_dochandle_t, struct zone_dstab *);
281 
282 /*
283  * '*ent' iterator routines.
284  */
285 extern	int	zonecfg_setfsent(zone_dochandle_t);
286 extern	int	zonecfg_getfsent(zone_dochandle_t, struct zone_fstab *);
287 extern	int	zonecfg_endfsent(zone_dochandle_t);
288 extern	int	zonecfg_setipdent(zone_dochandle_t);
289 extern	int	zonecfg_getipdent(zone_dochandle_t, struct zone_fstab *);
290 extern	int	zonecfg_endipdent(zone_dochandle_t);
291 extern	int	zonecfg_setnwifent(zone_dochandle_t);
292 extern	int	zonecfg_getnwifent(zone_dochandle_t, struct zone_nwiftab *);
293 extern	int	zonecfg_endnwifent(zone_dochandle_t);
294 extern	int	zonecfg_setdevent(zone_dochandle_t);
295 extern	int	zonecfg_getdevent(zone_dochandle_t, struct zone_devtab *);
296 extern	int	zonecfg_enddevent(zone_dochandle_t);
297 extern	int	zonecfg_setattrent(zone_dochandle_t);
298 extern	int	zonecfg_getattrent(zone_dochandle_t, struct zone_attrtab *);
299 extern	int	zonecfg_endattrent(zone_dochandle_t);
300 extern	int	zonecfg_setrctlent(zone_dochandle_t);
301 extern	int	zonecfg_getrctlent(zone_dochandle_t, struct zone_rctltab *);
302 extern	int	zonecfg_endrctlent(zone_dochandle_t);
303 extern	int	zonecfg_setdsent(zone_dochandle_t);
304 extern	int	zonecfg_getdsent(zone_dochandle_t, struct zone_dstab *);
305 extern	int	zonecfg_enddsent(zone_dochandle_t);
306 
307 /*
308  * Privilege-related functions.
309  */
310 extern	int	zonecfg_get_privset(priv_set_t *);
311 
312 /*
313  * Higher-level routines.
314  */
315 extern	int	zone_get_rootpath(char *, char *, size_t);
316 extern	int	zone_get_zonepath(char *, char *, size_t);
317 extern	int	zone_get_state(char *, zone_state_t *);
318 extern	int	zone_set_state(char *, zone_state_t);
319 extern	char	*zone_state_str(zone_state_t);
320 extern	int	zonecfg_get_name_by_uuid(const uuid_t, char *, size_t);
321 extern	int	zonecfg_get_uuid(const char *, uuid_t);
322 
323 /*
324  * Iterator for configured zones.
325  */
326 extern FILE		*setzoneent(void);
327 extern char		*getzoneent(FILE *);
328 extern struct zoneent	*getzoneent_private(FILE *);
329 extern void		endzoneent(FILE *);
330 
331 /*
332  * File-system-related convenience functions.
333  */
334 extern boolean_t zonecfg_valid_fs_type(const char *);
335 
336 /*
337  * Network-related convenience functions.
338  */
339 extern boolean_t zonecfg_same_net_address(char *, char *);
340 extern int zonecfg_valid_net_address(char *, struct lifreq *);
341 
342 /*
343  * Rctl-related common functions.
344  */
345 extern boolean_t zonecfg_is_rctl(const char *);
346 extern boolean_t zonecfg_valid_rctlname(const char *);
347 extern boolean_t zonecfg_valid_rctlblk(const rctlblk_t *);
348 extern boolean_t zonecfg_valid_rctl(const char *, const rctlblk_t *);
349 extern int zonecfg_construct_rctlblk(const struct zone_rctlvaltab *,
350     rctlblk_t *);
351 
352 /*
353  * Live Upgrade support functions.  Shared between ON and install gate.
354  */
355 extern FILE *zonecfg_open_scratch(const char *, boolean_t);
356 extern int zonecfg_lock_scratch(FILE *);
357 extern void zonecfg_close_scratch(FILE *);
358 extern int zonecfg_get_scratch(FILE *, char *, size_t, char *, size_t, char *,
359     size_t);
360 extern int zonecfg_find_scratch(FILE *, const char *, const char *, char *,
361     size_t);
362 extern int zonecfg_reverse_scratch(FILE *, const char *, char *, size_t,
363     char *, size_t);
364 extern int zonecfg_add_scratch(FILE *, const char *, const char *,
365     const char *);
366 extern int zonecfg_delete_scratch(FILE *, const char *);
367 extern boolean_t zonecfg_is_scratch(const char *);
368 
369 #ifdef __cplusplus
370 }
371 #endif
372 
373 #endif	/* _LIBZONECFG_H */
374