xref: /titanic_41/usr/src/head/libzonecfg.h (revision fd9cb95cbb2f626355a60efb9d02c5f0a33c10e6)
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 #define	ZONE_STATE_CONFIGURED		0
90 #define	ZONE_STATE_INCOMPLETE		1
91 #define	ZONE_STATE_INSTALLED		2
92 #define	ZONE_STATE_READY		3
93 #define	ZONE_STATE_MOUNTED		4
94 #define	ZONE_STATE_RUNNING		5
95 #define	ZONE_STATE_SHUTTING_DOWN	6
96 #define	ZONE_STATE_DOWN			7
97 
98 #define	ZONE_STATE_MAXSTRLEN	14
99 
100 #define	LIBZONECFG_PATH		"libzonecfg.so.1"
101 
102 #define	ZONE_CONFIG_ROOT	"/etc/zones"
103 #define	ZONE_INDEX_FILE		ZONE_CONFIG_ROOT "/index"
104 
105 /*
106  * The integer field expresses the current values on a get.
107  * On a put, it represents the new values if >= 0 or "don't change" if < 0.
108  */
109 struct zoneent {
110 	char	zone_name[ZONENAME_MAX];	/* name of the zone */
111 	int	zone_state;	/* configured | incomplete | installed */
112 	char	zone_path[MAXPATHLEN];		/* path to zone storage */
113 	uuid_t	zone_uuid;			/* unique ID for zone */
114 	char	zone_newname[ZONENAME_MAX];	/* for doing renames */
115 };
116 
117 typedef struct zone_dochandle *zone_dochandle_t;	/* opaque handle */
118 
119 typedef uint_t zone_state_t;
120 
121 typedef struct zone_fsopt {
122 	struct zone_fsopt *zone_fsopt_next;
123 	char		   zone_fsopt_opt[MAX_MNTOPT_STR];
124 } zone_fsopt_t;
125 
126 struct zone_fstab {
127 	char		zone_fs_special[MAXPATHLEN]; 	/* special file */
128 	char		zone_fs_dir[MAXPATHLEN];	/* mount point */
129 	char		zone_fs_type[FSTYPSZ];		/* e.g. ufs */
130 	zone_fsopt_t   *zone_fs_options;		/* mount options */
131 	char		zone_fs_raw[MAXPATHLEN];	/* device to fsck */
132 };
133 
134 struct zone_nwiftab {
135 	char	zone_nwif_address[INET6_ADDRSTRLEN];
136 	char	zone_nwif_physical[LIFNAMSIZ];
137 };
138 
139 struct zone_devtab {
140 	char	zone_dev_match[MAXPATHLEN];
141 };
142 
143 struct zone_rctlvaltab {
144 	char	zone_rctlval_priv[MAXNAMELEN];
145 	char	zone_rctlval_limit[MAXNAMELEN];
146 	char	zone_rctlval_action[MAXNAMELEN];
147 	struct zone_rctlvaltab *zone_rctlval_next;
148 };
149 
150 struct zone_rctltab {
151 	char	zone_rctl_name[MAXNAMELEN];
152 	struct zone_rctlvaltab *zone_rctl_valptr;
153 };
154 
155 struct zone_attrtab {
156 	char	zone_attr_name[MAXNAMELEN];
157 	char	zone_attr_type[MAXNAMELEN];
158 	char	zone_attr_value[2 * BUFSIZ];
159 };
160 
161 struct zone_dstab {
162 	char	zone_dataset_name[MAXNAMELEN];
163 };
164 
165 /*
166  * Basic configuration management routines.
167  */
168 extern	zone_dochandle_t	zonecfg_init_handle(void);
169 extern	int	zonecfg_get_handle(const char *, zone_dochandle_t);
170 extern	int	zonecfg_get_snapshot_handle(const char *, zone_dochandle_t);
171 extern	int	zonecfg_get_template_handle(const char *, const char *,
172     zone_dochandle_t);
173 extern	int	zonecfg_check_handle(zone_dochandle_t);
174 extern	void	zonecfg_fini_handle(zone_dochandle_t);
175 extern	int	zonecfg_destroy(const char *, boolean_t);
176 extern	int	zonecfg_destroy_snapshot(const char *);
177 extern	int	zonecfg_save(zone_dochandle_t);
178 extern	int	zonecfg_create_snapshot(const char *);
179 extern	char	*zonecfg_strerror(int);
180 extern	int	zonecfg_access(const char *, int);
181 extern	void	zonecfg_set_root(const char *);
182 extern	const char *zonecfg_get_root(void);
183 extern	boolean_t zonecfg_in_alt_root(void);
184 
185 /*
186  * Zone name, path to zone directory, autoboot setting and pool.
187  */
188 extern	int	zonecfg_validate_zonename(const char *);
189 extern	int	zonecfg_get_name(zone_dochandle_t, char *, size_t);
190 extern	int	zonecfg_set_name(zone_dochandle_t, char *);
191 extern	int	zonecfg_get_zonepath(zone_dochandle_t, char *, size_t);
192 extern	int	zonecfg_set_zonepath(zone_dochandle_t, char *);
193 extern	int	zonecfg_get_autoboot(zone_dochandle_t, boolean_t *);
194 extern	int	zonecfg_set_autoboot(zone_dochandle_t, boolean_t);
195 extern	int	zonecfg_get_pool(zone_dochandle_t, char *, size_t);
196 extern	int	zonecfg_set_pool(zone_dochandle_t, char *);
197 
198 /*
199  * Filesystem configuration.
200  */
201 extern	int	zonecfg_add_filesystem(zone_dochandle_t, struct zone_fstab *);
202 extern	int	zonecfg_delete_filesystem(zone_dochandle_t,
203     struct zone_fstab *);
204 extern	int	zonecfg_modify_filesystem(zone_dochandle_t,
205     struct zone_fstab *, struct zone_fstab *);
206 extern	int	zonecfg_lookup_filesystem(zone_dochandle_t,
207     struct zone_fstab *);
208 extern	int	zonecfg_add_ipd(zone_dochandle_t, struct zone_fstab *);
209 extern	int	zonecfg_delete_ipd(zone_dochandle_t, struct zone_fstab *);
210 extern	int	zonecfg_modify_ipd(zone_dochandle_t,
211     struct zone_fstab *, struct zone_fstab *);
212 extern	int	zonecfg_lookup_ipd(zone_dochandle_t, struct zone_fstab *);
213 extern	int	zonecfg_add_fs_option(struct zone_fstab *, char *);
214 extern	int	zonecfg_remove_fs_option(struct zone_fstab *, char *);
215 extern	void	zonecfg_free_fs_option_list(zone_fsopt_t *);
216 extern	int 	zonecfg_find_mounts(char *, int(*)(const char *, void *),
217     void *);
218 
219 /*
220  * Network interface configuration.
221  */
222 extern	int	zonecfg_add_nwif(zone_dochandle_t, struct zone_nwiftab *);
223 extern	int	zonecfg_delete_nwif(zone_dochandle_t, struct zone_nwiftab *);
224 extern	int	zonecfg_modify_nwif(zone_dochandle_t, struct zone_nwiftab *,
225     struct zone_nwiftab *);
226 extern	int	zonecfg_lookup_nwif(zone_dochandle_t, struct zone_nwiftab *);
227 
228 /*
229  * Device configuration and rule matching.
230  */
231 extern	int	zonecfg_add_dev(zone_dochandle_t, struct zone_devtab *);
232 extern	int	zonecfg_delete_dev(zone_dochandle_t, struct zone_devtab *);
233 extern	int	zonecfg_modify_dev(zone_dochandle_t, struct zone_devtab *,
234     struct zone_devtab *);
235 extern	int	zonecfg_lookup_dev(zone_dochandle_t, struct zone_devtab *);
236 extern	int	zonecfg_match_dev(zone_dochandle_t, char *,
237     struct zone_devtab *);
238 
239 /*
240  * Resource control configuration.
241  */
242 extern	int	zonecfg_add_rctl(zone_dochandle_t, struct zone_rctltab *);
243 extern	int	zonecfg_delete_rctl(zone_dochandle_t, struct zone_rctltab *);
244 extern	int	zonecfg_modify_rctl(zone_dochandle_t, struct zone_rctltab *,
245     struct zone_rctltab *);
246 extern	int	zonecfg_lookup_rctl(zone_dochandle_t, struct zone_rctltab *);
247 extern	int	zonecfg_add_rctl_value(struct zone_rctltab *,
248     struct zone_rctlvaltab *);
249 extern	int	zonecfg_remove_rctl_value(struct zone_rctltab *,
250     struct zone_rctlvaltab *);
251 extern	void	zonecfg_free_rctl_value_list(struct zone_rctlvaltab *);
252 
253 /*
254  * Generic attribute configuration and type/value extraction.
255  */
256 extern	int	zonecfg_add_attr(zone_dochandle_t, struct zone_attrtab *);
257 extern	int	zonecfg_delete_attr(zone_dochandle_t, struct zone_attrtab *);
258 extern	int	zonecfg_modify_attr(zone_dochandle_t, struct zone_attrtab *,
259     struct zone_attrtab *);
260 extern	int	zonecfg_lookup_attr(zone_dochandle_t, struct zone_attrtab *);
261 extern	int	zonecfg_get_attr_boolean(const struct zone_attrtab *,
262     boolean_t *);
263 extern	int	zonecfg_get_attr_int(const struct zone_attrtab *, int64_t *);
264 extern	int	zonecfg_get_attr_string(const struct zone_attrtab *, char *,
265     size_t);
266 extern	int	zonecfg_get_attr_uint(const struct zone_attrtab *, uint64_t *);
267 
268 /*
269  * ZFS configuration.
270  */
271 extern	int	zonecfg_add_ds(zone_dochandle_t, struct zone_dstab *);
272 extern	int	zonecfg_delete_ds(zone_dochandle_t, struct zone_dstab *);
273 extern	int	zonecfg_modify_ds(zone_dochandle_t, struct zone_dstab *,
274     struct zone_dstab *);
275 extern	int	zonecfg_lookup_ds(zone_dochandle_t, struct zone_dstab *);
276 
277 /*
278  * '*ent' iterator routines.
279  */
280 extern	int	zonecfg_setfsent(zone_dochandle_t);
281 extern	int	zonecfg_getfsent(zone_dochandle_t, struct zone_fstab *);
282 extern	int	zonecfg_endfsent(zone_dochandle_t);
283 extern	int	zonecfg_setipdent(zone_dochandle_t);
284 extern	int	zonecfg_getipdent(zone_dochandle_t, struct zone_fstab *);
285 extern	int	zonecfg_endipdent(zone_dochandle_t);
286 extern	int	zonecfg_setnwifent(zone_dochandle_t);
287 extern	int	zonecfg_getnwifent(zone_dochandle_t, struct zone_nwiftab *);
288 extern	int	zonecfg_endnwifent(zone_dochandle_t);
289 extern	int	zonecfg_setdevent(zone_dochandle_t);
290 extern	int	zonecfg_getdevent(zone_dochandle_t, struct zone_devtab *);
291 extern	int	zonecfg_enddevent(zone_dochandle_t);
292 extern	int	zonecfg_setattrent(zone_dochandle_t);
293 extern	int	zonecfg_getattrent(zone_dochandle_t, struct zone_attrtab *);
294 extern	int	zonecfg_endattrent(zone_dochandle_t);
295 extern	int	zonecfg_setrctlent(zone_dochandle_t);
296 extern	int	zonecfg_getrctlent(zone_dochandle_t, struct zone_rctltab *);
297 extern	int	zonecfg_endrctlent(zone_dochandle_t);
298 extern	int	zonecfg_setdsent(zone_dochandle_t);
299 extern	int	zonecfg_getdsent(zone_dochandle_t, struct zone_dstab *);
300 extern	int	zonecfg_enddsent(zone_dochandle_t);
301 
302 /*
303  * Privilege-related functions.
304  */
305 extern	int	zonecfg_get_privset(priv_set_t *);
306 
307 /*
308  * Higher-level routines.
309  */
310 extern	int	zone_get_rootpath(char *, char *, size_t);
311 extern	int	zone_get_zonepath(char *, char *, size_t);
312 extern	int	zone_get_state(char *, zone_state_t *);
313 extern	int	zone_set_state(char *, zone_state_t);
314 extern	char	*zone_state_str(zone_state_t);
315 extern	int	zonecfg_get_name_by_uuid(const uuid_t, char *, size_t);
316 extern	int	zonecfg_get_uuid(const char *, uuid_t);
317 
318 /*
319  * Iterator for configured zones.
320  */
321 extern FILE		*setzoneent(void);
322 extern char		*getzoneent(FILE *);
323 extern struct zoneent	*getzoneent_private(FILE *);
324 extern void		endzoneent(FILE *);
325 
326 /*
327  * File-system-related convenience functions.
328  */
329 extern boolean_t zonecfg_valid_fs_type(const char *);
330 
331 /*
332  * Network-related convenience functions.
333  */
334 extern boolean_t zonecfg_same_net_address(char *, char *);
335 extern int zonecfg_valid_net_address(char *, struct lifreq *);
336 
337 /*
338  * Rctl-related common functions.
339  */
340 extern boolean_t zonecfg_is_rctl(const char *);
341 extern boolean_t zonecfg_valid_rctlname(const char *);
342 extern boolean_t zonecfg_valid_rctlblk(const rctlblk_t *);
343 extern boolean_t zonecfg_valid_rctl(const char *, const rctlblk_t *);
344 extern int zonecfg_construct_rctlblk(const struct zone_rctlvaltab *,
345     rctlblk_t *);
346 
347 /*
348  * Live Upgrade support functions.  Shared between ON and install gate.
349  */
350 extern FILE *zonecfg_open_scratch(const char *, boolean_t);
351 extern int zonecfg_lock_scratch(FILE *);
352 extern void zonecfg_close_scratch(FILE *);
353 extern int zonecfg_get_scratch(FILE *, char *, size_t, char *, size_t, char *,
354     size_t);
355 extern int zonecfg_find_scratch(FILE *, const char *, const char *, char *,
356     size_t);
357 extern int zonecfg_reverse_scratch(FILE *, const char *, char *, size_t,
358     char *, size_t);
359 extern int zonecfg_add_scratch(FILE *, const char *, const char *,
360     const char *);
361 extern int zonecfg_delete_scratch(FILE *, const char *);
362 extern boolean_t zonecfg_is_scratch(const char *);
363 
364 #ifdef __cplusplus
365 }
366 #endif
367 
368 #endif	/* _LIBZONECFG_H */
369