libzonecfg.h revision 1507:394fe4a8084d
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 2006 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#ifndef _LIBZONECFG_H
27#define	_LIBZONECFG_H
28
29#pragma ident	"%Z%%M%	%I%	%E% SMI"
30
31/*
32 * Zone configuration header file.
33 */
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/* sys/socket.h is required by net/if.h, which has a constant needed here */
40#include <sys/param.h>
41#include <sys/fstyp.h>
42#include <sys/mount.h>
43#include <priv.h>
44#include <netinet/in.h>
45#include <sys/socket.h>
46#include <net/if.h>
47#include <stdio.h>
48#include <rctl.h>
49#include <zone.h>
50#include <sys/uuid.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/*
89 * Warning: these are shared with the admin/install consolidation.
90 * Do not insert states between any of the currently defined states,
91 * and any new states must be evaluated for impact on range comparisons.
92 */
93#define	ZONE_STATE_CONFIGURED		0
94#define	ZONE_STATE_INCOMPLETE		1
95#define	ZONE_STATE_INSTALLED		2
96#define	ZONE_STATE_READY		3
97#define	ZONE_STATE_RUNNING		4
98#define	ZONE_STATE_SHUTTING_DOWN	5
99#define	ZONE_STATE_DOWN			6
100#define	ZONE_STATE_MOUNTED		7
101
102#define	ZONE_STATE_MAXSTRLEN	14
103
104#define	LIBZONECFG_PATH		"libzonecfg.so.1"
105
106#define	ZONE_CONFIG_ROOT	"/etc/zones"
107#define	ZONE_INDEX_FILE		ZONE_CONFIG_ROOT "/index"
108
109/* The maximum length of the VERSION string in the pkginfo(4) file. */
110#define	ZONE_PKG_VERSMAX	256
111
112/*
113 * The integer field expresses the current values on a get.
114 * On a put, it represents the new values if >= 0 or "don't change" if < 0.
115 */
116struct zoneent {
117	char	zone_name[ZONENAME_MAX];	/* name of the zone */
118	int	zone_state;	/* configured | incomplete | installed */
119	char	zone_path[MAXPATHLEN];		/* path to zone storage */
120	uuid_t	zone_uuid;			/* unique ID for zone */
121	char	zone_newname[ZONENAME_MAX];	/* for doing renames */
122};
123
124typedef struct zone_dochandle *zone_dochandle_t;	/* opaque handle */
125
126typedef uint_t zone_state_t;
127
128typedef struct zone_fsopt {
129	struct zone_fsopt *zone_fsopt_next;
130	char		   zone_fsopt_opt[MAX_MNTOPT_STR];
131} zone_fsopt_t;
132
133struct zone_fstab {
134	char		zone_fs_special[MAXPATHLEN]; 	/* special file */
135	char		zone_fs_dir[MAXPATHLEN];	/* mount point */
136	char		zone_fs_type[FSTYPSZ];		/* e.g. ufs */
137	zone_fsopt_t   *zone_fs_options;		/* mount options */
138	char		zone_fs_raw[MAXPATHLEN];	/* device to fsck */
139};
140
141struct zone_nwiftab {
142	char	zone_nwif_address[INET6_ADDRSTRLEN];
143	char	zone_nwif_physical[LIFNAMSIZ];
144};
145
146struct zone_devtab {
147	char	zone_dev_match[MAXPATHLEN];
148};
149
150struct zone_rctlvaltab {
151	char	zone_rctlval_priv[MAXNAMELEN];
152	char	zone_rctlval_limit[MAXNAMELEN];
153	char	zone_rctlval_action[MAXNAMELEN];
154	struct zone_rctlvaltab *zone_rctlval_next;
155};
156
157struct zone_rctltab {
158	char	zone_rctl_name[MAXNAMELEN];
159	struct zone_rctlvaltab *zone_rctl_valptr;
160};
161
162struct zone_attrtab {
163	char	zone_attr_name[MAXNAMELEN];
164	char	zone_attr_type[MAXNAMELEN];
165	char	zone_attr_value[2 * BUFSIZ];
166};
167
168struct zone_dstab {
169	char	zone_dataset_name[MAXNAMELEN];
170};
171
172struct zone_pkgtab {
173	char	zone_pkg_name[MAXNAMELEN];
174	char	zone_pkg_version[ZONE_PKG_VERSMAX];
175};
176
177struct zone_patchtab {
178	char	zone_patch_id[MAXNAMELEN];
179};
180
181struct zone_devpermtab {
182	char	zone_devperm_name[MAXPATHLEN];
183	uid_t	zone_devperm_uid;
184	gid_t	zone_devperm_gid;
185	mode_t	zone_devperm_mode;
186	char	*zone_devperm_acl;
187};
188
189/*
190 * Basic configuration management routines.
191 */
192extern	zone_dochandle_t	zonecfg_init_handle(void);
193extern	int	zonecfg_get_handle(const char *, zone_dochandle_t);
194extern	int	zonecfg_get_snapshot_handle(const char *, zone_dochandle_t);
195extern	int	zonecfg_get_template_handle(const char *, const char *,
196    zone_dochandle_t);
197extern	int	zonecfg_check_handle(zone_dochandle_t);
198extern	void	zonecfg_fini_handle(zone_dochandle_t);
199extern	int	zonecfg_destroy(const char *, boolean_t);
200extern	int	zonecfg_destroy_snapshot(const char *);
201extern	int	zonecfg_save(zone_dochandle_t);
202extern	int	zonecfg_create_snapshot(const char *);
203extern	char	*zonecfg_strerror(int);
204extern	int	zonecfg_access(const char *, int);
205extern	void	zonecfg_set_root(const char *);
206extern	const char *zonecfg_get_root(void);
207extern	boolean_t zonecfg_in_alt_root(void);
208
209/*
210 * Zone name, path to zone directory, autoboot setting and pool.
211 */
212extern	int	zonecfg_validate_zonename(const char *);
213extern	int	zonecfg_get_name(zone_dochandle_t, char *, size_t);
214extern	int	zonecfg_set_name(zone_dochandle_t, char *);
215extern	int	zonecfg_get_zonepath(zone_dochandle_t, char *, size_t);
216extern	int	zonecfg_set_zonepath(zone_dochandle_t, char *);
217extern	int	zonecfg_get_autoboot(zone_dochandle_t, boolean_t *);
218extern	int	zonecfg_set_autoboot(zone_dochandle_t, boolean_t);
219extern	int	zonecfg_get_pool(zone_dochandle_t, char *, size_t);
220extern	int	zonecfg_set_pool(zone_dochandle_t, char *);
221
222/*
223 * Filesystem configuration.
224 */
225extern	int	zonecfg_add_filesystem(zone_dochandle_t, struct zone_fstab *);
226extern	int	zonecfg_delete_filesystem(zone_dochandle_t,
227    struct zone_fstab *);
228extern	int	zonecfg_modify_filesystem(zone_dochandle_t,
229    struct zone_fstab *, struct zone_fstab *);
230extern	int	zonecfg_lookup_filesystem(zone_dochandle_t,
231    struct zone_fstab *);
232extern	int	zonecfg_add_ipd(zone_dochandle_t, struct zone_fstab *);
233extern	int	zonecfg_delete_ipd(zone_dochandle_t, struct zone_fstab *);
234extern	int	zonecfg_modify_ipd(zone_dochandle_t,
235    struct zone_fstab *, struct zone_fstab *);
236extern	int	zonecfg_lookup_ipd(zone_dochandle_t, struct zone_fstab *);
237extern	int	zonecfg_add_fs_option(struct zone_fstab *, char *);
238extern	int	zonecfg_remove_fs_option(struct zone_fstab *, char *);
239extern	void	zonecfg_free_fs_option_list(zone_fsopt_t *);
240extern	int 	zonecfg_find_mounts(char *, int(*)(const char *, void *),
241    void *);
242
243/*
244 * Network interface configuration.
245 */
246extern	int	zonecfg_add_nwif(zone_dochandle_t, struct zone_nwiftab *);
247extern	int	zonecfg_delete_nwif(zone_dochandle_t, struct zone_nwiftab *);
248extern	int	zonecfg_modify_nwif(zone_dochandle_t, struct zone_nwiftab *,
249    struct zone_nwiftab *);
250extern	int	zonecfg_lookup_nwif(zone_dochandle_t, struct zone_nwiftab *);
251
252/*
253 * Device configuration and rule matching.
254 */
255extern	int	zonecfg_add_dev(zone_dochandle_t, struct zone_devtab *);
256extern	int	zonecfg_delete_dev(zone_dochandle_t, struct zone_devtab *);
257extern	int	zonecfg_modify_dev(zone_dochandle_t, struct zone_devtab *,
258    struct zone_devtab *);
259extern	int	zonecfg_lookup_dev(zone_dochandle_t, struct zone_devtab *);
260extern	int	zonecfg_match_dev(zone_dochandle_t, char *,
261    struct zone_devtab *);
262
263/*
264 * Resource control configuration.
265 */
266extern	int	zonecfg_add_rctl(zone_dochandle_t, struct zone_rctltab *);
267extern	int	zonecfg_delete_rctl(zone_dochandle_t, struct zone_rctltab *);
268extern	int	zonecfg_modify_rctl(zone_dochandle_t, struct zone_rctltab *,
269    struct zone_rctltab *);
270extern	int	zonecfg_lookup_rctl(zone_dochandle_t, struct zone_rctltab *);
271extern	int	zonecfg_add_rctl_value(struct zone_rctltab *,
272    struct zone_rctlvaltab *);
273extern	int	zonecfg_remove_rctl_value(struct zone_rctltab *,
274    struct zone_rctlvaltab *);
275extern	void	zonecfg_free_rctl_value_list(struct zone_rctlvaltab *);
276
277/*
278 * Generic attribute configuration and type/value extraction.
279 */
280extern	int	zonecfg_add_attr(zone_dochandle_t, struct zone_attrtab *);
281extern	int	zonecfg_delete_attr(zone_dochandle_t, struct zone_attrtab *);
282extern	int	zonecfg_modify_attr(zone_dochandle_t, struct zone_attrtab *,
283    struct zone_attrtab *);
284extern	int	zonecfg_lookup_attr(zone_dochandle_t, struct zone_attrtab *);
285extern	int	zonecfg_get_attr_boolean(const struct zone_attrtab *,
286    boolean_t *);
287extern	int	zonecfg_get_attr_int(const struct zone_attrtab *, int64_t *);
288extern	int	zonecfg_get_attr_string(const struct zone_attrtab *, char *,
289    size_t);
290extern	int	zonecfg_get_attr_uint(const struct zone_attrtab *, uint64_t *);
291
292/*
293 * ZFS configuration.
294 */
295extern	int	zonecfg_add_ds(zone_dochandle_t, struct zone_dstab *);
296extern	int	zonecfg_delete_ds(zone_dochandle_t, struct zone_dstab *);
297extern	int	zonecfg_modify_ds(zone_dochandle_t, struct zone_dstab *,
298    struct zone_dstab *);
299extern	int	zonecfg_lookup_ds(zone_dochandle_t, struct zone_dstab *);
300
301/*
302 * attach/detach support.
303 */
304extern	int	zonecfg_get_attach_handle(const char *, const char *,
305    boolean_t, zone_dochandle_t);
306extern	int	zonecfg_detach_save(zone_dochandle_t);
307extern	int	zonecfg_get_detach_info(zone_dochandle_t, boolean_t);
308extern	boolean_t zonecfg_detached(const char *);
309extern	void	zonecfg_rm_detached(zone_dochandle_t, boolean_t forced);
310extern	int	zonecfg_devwalk(zone_dochandle_t handle,
311    int (*cb)(const char *, uid_t, gid_t, mode_t, const char *, void *),
312    void *data);
313extern	int	zonecfg_devperms_apply(zone_dochandle_t, const char *,
314    uid_t, gid_t, mode_t, const char *);
315
316
317/*
318 * '*ent' iterator routines.
319 */
320extern	int	zonecfg_setfsent(zone_dochandle_t);
321extern	int	zonecfg_getfsent(zone_dochandle_t, struct zone_fstab *);
322extern	int	zonecfg_endfsent(zone_dochandle_t);
323extern	int	zonecfg_setipdent(zone_dochandle_t);
324extern	int	zonecfg_getipdent(zone_dochandle_t, struct zone_fstab *);
325extern	int	zonecfg_endipdent(zone_dochandle_t);
326extern	int	zonecfg_setnwifent(zone_dochandle_t);
327extern	int	zonecfg_getnwifent(zone_dochandle_t, struct zone_nwiftab *);
328extern	int	zonecfg_endnwifent(zone_dochandle_t);
329extern	int	zonecfg_setdevent(zone_dochandle_t);
330extern	int	zonecfg_getdevent(zone_dochandle_t, struct zone_devtab *);
331extern	int	zonecfg_enddevent(zone_dochandle_t);
332extern	int	zonecfg_setattrent(zone_dochandle_t);
333extern	int	zonecfg_getattrent(zone_dochandle_t, struct zone_attrtab *);
334extern	int	zonecfg_endattrent(zone_dochandle_t);
335extern	int	zonecfg_setrctlent(zone_dochandle_t);
336extern	int	zonecfg_getrctlent(zone_dochandle_t, struct zone_rctltab *);
337extern	int	zonecfg_endrctlent(zone_dochandle_t);
338extern	int	zonecfg_setdsent(zone_dochandle_t);
339extern	int	zonecfg_getdsent(zone_dochandle_t, struct zone_dstab *);
340extern	int	zonecfg_enddsent(zone_dochandle_t);
341extern	int	zonecfg_setpkgent(zone_dochandle_t);
342extern	int	zonecfg_getpkgent(zone_dochandle_t, struct zone_pkgtab *);
343extern	int	zonecfg_endpkgent(zone_dochandle_t);
344extern	int	zonecfg_setpatchent(zone_dochandle_t);
345extern	int	zonecfg_getpatchent(zone_dochandle_t, struct zone_patchtab *);
346extern	int	zonecfg_endpatchent(zone_dochandle_t);
347extern	int	zonecfg_setdevperment(zone_dochandle_t);
348extern	int	zonecfg_getdevperment(zone_dochandle_t,
349    struct zone_devpermtab *);
350extern	int	zonecfg_enddevperment(zone_dochandle_t);
351
352/*
353 * Privilege-related functions.
354 */
355extern	int	zonecfg_get_privset(priv_set_t *);
356
357/*
358 * Higher-level routines.
359 */
360extern	int	zone_get_rootpath(char *, char *, size_t);
361extern	int	zone_get_zonepath(char *, char *, size_t);
362extern	int	zone_get_state(char *, zone_state_t *);
363extern	int	zone_set_state(char *, zone_state_t);
364extern	char	*zone_state_str(zone_state_t);
365extern	int	zonecfg_get_name_by_uuid(const uuid_t, char *, size_t);
366extern	int	zonecfg_get_uuid(const char *, uuid_t);
367
368/*
369 * Iterator for configured zones.
370 */
371extern FILE		*setzoneent(void);
372extern char		*getzoneent(FILE *);
373extern struct zoneent	*getzoneent_private(FILE *);
374extern void		endzoneent(FILE *);
375
376/*
377 * File-system-related convenience functions.
378 */
379extern boolean_t zonecfg_valid_fs_type(const char *);
380
381/*
382 * Network-related convenience functions.
383 */
384extern boolean_t zonecfg_same_net_address(char *, char *);
385extern int zonecfg_valid_net_address(char *, struct lifreq *);
386
387/*
388 * Rctl-related common functions.
389 */
390extern boolean_t zonecfg_is_rctl(const char *);
391extern boolean_t zonecfg_valid_rctlname(const char *);
392extern boolean_t zonecfg_valid_rctlblk(const rctlblk_t *);
393extern boolean_t zonecfg_valid_rctl(const char *, const rctlblk_t *);
394extern int zonecfg_construct_rctlblk(const struct zone_rctlvaltab *,
395    rctlblk_t *);
396
397/*
398 * Live Upgrade support functions.  Shared between ON and install gate.
399 */
400extern FILE *zonecfg_open_scratch(const char *, boolean_t);
401extern int zonecfg_lock_scratch(FILE *);
402extern void zonecfg_close_scratch(FILE *);
403extern int zonecfg_get_scratch(FILE *, char *, size_t, char *, size_t, char *,
404    size_t);
405extern int zonecfg_find_scratch(FILE *, const char *, const char *, char *,
406    size_t);
407extern int zonecfg_reverse_scratch(FILE *, const char *, char *, size_t,
408    char *, size_t);
409extern int zonecfg_add_scratch(FILE *, const char *, const char *,
410    const char *);
411extern int zonecfg_delete_scratch(FILE *, const char *);
412extern boolean_t zonecfg_is_scratch(const char *);
413
414#ifdef __cplusplus
415}
416#endif
417
418#endif	/* _LIBZONECFG_H */
419