xref: /titanic_52/usr/src/head/libzonecfg.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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_RESOURCE_EXISTS	21	/* resource already exists */
76 #define	Z_INVALID_DOCUMENT	22	/* libxml can't validate against DTD */
77 #define	Z_ID_IN_USE		23	/* add_index conflict */
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 };
112 
113 typedef struct zone_dochandle *zone_dochandle_t;	/* opaque handle */
114 
115 typedef uint_t zone_state_t;
116 
117 typedef struct zone_fsopt {
118 	struct zone_fsopt *zone_fsopt_next;
119 	char		   zone_fsopt_opt[MAX_MNTOPT_STR];
120 } zone_fsopt_t;
121 
122 struct zone_fstab {
123 	char		zone_fs_special[MAXPATHLEN]; 	/* special file */
124 	char		zone_fs_dir[MAXPATHLEN];	/* mount point */
125 	char		zone_fs_type[FSTYPSZ];		/* e.g. ufs */
126 	zone_fsopt_t   *zone_fs_options;		/* mount options */
127 	char		zone_fs_raw[MAXPATHLEN];	/* device to fsck */
128 };
129 
130 struct zone_nwiftab {
131 	char	zone_nwif_address[INET6_ADDRSTRLEN];
132 	char	zone_nwif_physical[LIFNAMSIZ];
133 };
134 
135 struct zone_devtab {
136 	char	zone_dev_match[MAXPATHLEN];
137 };
138 
139 struct zone_rctlvaltab {
140 	char	zone_rctlval_priv[MAXNAMELEN];
141 	char	zone_rctlval_limit[MAXNAMELEN];
142 	char	zone_rctlval_action[MAXNAMELEN];
143 	struct zone_rctlvaltab *zone_rctlval_next;
144 };
145 
146 struct zone_rctltab {
147 	char	zone_rctl_name[MAXNAMELEN];
148 	struct zone_rctlvaltab *zone_rctl_valptr;
149 };
150 
151 struct zone_attrtab {
152 	char	zone_attr_name[MAXNAMELEN];
153 	char	zone_attr_type[MAXNAMELEN];
154 	char	zone_attr_value[2 * BUFSIZ];
155 };
156 
157 /*
158  * Basic configuration management routines.
159  */
160 extern	zone_dochandle_t	zonecfg_init_handle(void);
161 extern	int	zonecfg_get_handle(char *, zone_dochandle_t);
162 extern	int	zonecfg_get_snapshot_handle(char *, zone_dochandle_t);
163 extern	int	zonecfg_check_handle(zone_dochandle_t);
164 extern	void	zonecfg_fini_handle(zone_dochandle_t);
165 extern	int	zonecfg_destroy(const char *);
166 extern	int	zonecfg_destroy_snapshot(char *);
167 extern	int	zonecfg_save(zone_dochandle_t);
168 extern	int	zonecfg_create_snapshot(char *);
169 extern	char	*zonecfg_strerror(int);
170 extern	int	zonecfg_access(const char *, int);
171 
172 /*
173  * Zone name, path to zone directory, autoboot setting and pool.
174  */
175 extern	int	zonecfg_get_name(zone_dochandle_t, char *, size_t);
176 extern	int	zonecfg_set_name(zone_dochandle_t, char *);
177 extern	int	zonecfg_get_zonepath(zone_dochandle_t, char *, size_t);
178 extern	int	zonecfg_set_zonepath(zone_dochandle_t, char *);
179 extern	int	zonecfg_get_autoboot(zone_dochandle_t, boolean_t *);
180 extern	int	zonecfg_set_autoboot(zone_dochandle_t, boolean_t);
181 extern	int	zonecfg_get_pool(zone_dochandle_t, char *, size_t);
182 extern	int	zonecfg_set_pool(zone_dochandle_t, char *);
183 
184 /*
185  * Filesystem configuration.
186  */
187 extern	int	zonecfg_add_filesystem(zone_dochandle_t, struct zone_fstab *);
188 extern	int	zonecfg_delete_filesystem(zone_dochandle_t,
189     struct zone_fstab *);
190 extern	int	zonecfg_modify_filesystem(zone_dochandle_t,
191     struct zone_fstab *, struct zone_fstab *);
192 extern	int	zonecfg_lookup_filesystem(zone_dochandle_t,
193     struct zone_fstab *);
194 extern	int	zonecfg_add_ipd(zone_dochandle_t, struct zone_fstab *);
195 extern	int	zonecfg_delete_ipd(zone_dochandle_t, struct zone_fstab *);
196 extern	int	zonecfg_modify_ipd(zone_dochandle_t,
197     struct zone_fstab *, struct zone_fstab *);
198 extern	int	zonecfg_lookup_ipd(zone_dochandle_t, struct zone_fstab *);
199 extern	int	zonecfg_add_fs_option(struct zone_fstab *, char *);
200 extern	int	zonecfg_remove_fs_option(struct zone_fstab *, char *);
201 extern	void	zonecfg_free_fs_option_list(zone_fsopt_t *);
202 extern	int 	zonecfg_find_mounts(char *, int(*)(const char *, void *),
203     void *);
204 
205 /*
206  * Network interface configuration.
207  */
208 extern	int	zonecfg_add_nwif(zone_dochandle_t, struct zone_nwiftab *);
209 extern	int	zonecfg_delete_nwif(zone_dochandle_t, struct zone_nwiftab *);
210 extern	int	zonecfg_modify_nwif(zone_dochandle_t, struct zone_nwiftab *,
211     struct zone_nwiftab *);
212 extern	int	zonecfg_lookup_nwif(zone_dochandle_t, struct zone_nwiftab *);
213 
214 /*
215  * Device configuration and rule matching.
216  */
217 extern	int	zonecfg_add_dev(zone_dochandle_t, struct zone_devtab *);
218 extern	int	zonecfg_delete_dev(zone_dochandle_t, struct zone_devtab *);
219 extern	int	zonecfg_modify_dev(zone_dochandle_t, struct zone_devtab *,
220     struct zone_devtab *);
221 extern	int	zonecfg_lookup_dev(zone_dochandle_t, struct zone_devtab *);
222 extern	int	zonecfg_match_dev(zone_dochandle_t, char *,
223     struct zone_devtab *);
224 
225 /*
226  * Resource control configuration.
227  */
228 extern	int	zonecfg_add_rctl(zone_dochandle_t, struct zone_rctltab *);
229 extern	int	zonecfg_delete_rctl(zone_dochandle_t, struct zone_rctltab *);
230 extern	int	zonecfg_modify_rctl(zone_dochandle_t, struct zone_rctltab *,
231     struct zone_rctltab *);
232 extern	int	zonecfg_lookup_rctl(zone_dochandle_t, struct zone_rctltab *);
233 extern	int	zonecfg_add_rctl_value(struct zone_rctltab *,
234     struct zone_rctlvaltab *);
235 extern	int	zonecfg_remove_rctl_value(struct zone_rctltab *,
236     struct zone_rctlvaltab *);
237 extern	void	zonecfg_free_rctl_value_list(struct zone_rctlvaltab *);
238 
239 /*
240  * Generic attribute configuration and type/value extraction.
241  */
242 extern	int	zonecfg_add_attr(zone_dochandle_t, struct zone_attrtab *);
243 extern	int	zonecfg_delete_attr(zone_dochandle_t, struct zone_attrtab *);
244 extern	int	zonecfg_modify_attr(zone_dochandle_t, struct zone_attrtab *,
245     struct zone_attrtab *);
246 extern	int	zonecfg_lookup_attr(zone_dochandle_t, struct zone_attrtab *);
247 extern	int	zonecfg_get_attr_boolean(const struct zone_attrtab *,
248     boolean_t *);
249 extern	int	zonecfg_get_attr_int(const struct zone_attrtab *, int64_t *);
250 extern	int	zonecfg_get_attr_string(const struct zone_attrtab *, char *,
251     size_t);
252 extern	int	zonecfg_get_attr_uint(const struct zone_attrtab *, uint64_t *);
253 
254 /*
255  * '*ent' iterator routines.
256  */
257 extern	int	zonecfg_setfsent(zone_dochandle_t);
258 extern	int	zonecfg_getfsent(zone_dochandle_t, struct zone_fstab *);
259 extern	int	zonecfg_endfsent(zone_dochandle_t);
260 extern	int	zonecfg_setipdent(zone_dochandle_t);
261 extern	int	zonecfg_getipdent(zone_dochandle_t, struct zone_fstab *);
262 extern	int	zonecfg_endipdent(zone_dochandle_t);
263 extern	int	zonecfg_setnwifent(zone_dochandle_t);
264 extern	int	zonecfg_getnwifent(zone_dochandle_t, struct zone_nwiftab *);
265 extern	int	zonecfg_endnwifent(zone_dochandle_t);
266 extern	int	zonecfg_setdevent(zone_dochandle_t);
267 extern	int	zonecfg_getdevent(zone_dochandle_t, struct zone_devtab *);
268 extern	int	zonecfg_enddevent(zone_dochandle_t);
269 extern	int	zonecfg_setattrent(zone_dochandle_t);
270 extern	int	zonecfg_getattrent(zone_dochandle_t, struct zone_attrtab *);
271 extern	int	zonecfg_endattrent(zone_dochandle_t);
272 extern	int	zonecfg_setrctlent(zone_dochandle_t);
273 extern	int	zonecfg_getrctlent(zone_dochandle_t, struct zone_rctltab *);
274 extern	int	zonecfg_endrctlent(zone_dochandle_t);
275 
276 /*
277  * Privilege-related functions.
278  */
279 extern	int	zonecfg_get_privset(priv_set_t *);
280 
281 /*
282  * Index update routines.
283  */
284 extern	int	zonecfg_add_index(char *, char *);
285 extern	int	zonecfg_delete_index(char *);
286 
287 /*
288  * Higher-level routines.
289  */
290 extern	int	zone_get_rootpath(char *, char *, size_t);
291 extern	int	zone_get_zonepath(char *, char *, size_t);
292 extern	int	zone_get_state(char *, zone_state_t *);
293 extern	int	zone_set_state(char *, zone_state_t);
294 extern	char	*zone_state_str(zone_state_t);
295 
296 /*
297  * Iterator for configured zones.
298  */
299 extern FILE		*setzoneent(void);
300 extern char		*getzoneent(FILE *);
301 extern struct zoneent	*getzoneent_private(FILE *);
302 extern void		endzoneent(FILE *);
303 
304 /*
305  * File-system-related convenience functions.
306  */
307 extern boolean_t zonecfg_valid_fs_type(const char *);
308 
309 /*
310  * Network-related convenience functions.
311  */
312 extern boolean_t zonecfg_same_net_address(char *, char *);
313 extern int zonecfg_valid_net_address(char *, struct lifreq *);
314 
315 /*
316  * Rctl-related common functions.
317  */
318 extern boolean_t zonecfg_is_rctl(const char *);
319 extern boolean_t zonecfg_valid_rctlname(const char *);
320 extern boolean_t zonecfg_valid_rctlblk(const rctlblk_t *);
321 extern boolean_t zonecfg_valid_rctl(const char *, const rctlblk_t *);
322 extern int zonecfg_construct_rctlblk(const struct zone_rctlvaltab *,
323     rctlblk_t *);
324 
325 #ifdef __cplusplus
326 }
327 #endif
328 
329 #endif	/* _LIBZONECFG_H */
330