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 /*
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2015, Joyent, Inc.
25 */
26
27 #ifndef _LIBZONECFG_H
28 #define _LIBZONECFG_H
29
30 /*
31 * Zone configuration header file.
32 */
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 /* sys/socket.h is required by net/if.h, which has a constant needed here */
39 #include <sys/param.h>
40 #include <sys/fstyp.h>
41 #include <sys/mount.h>
42 #include <priv.h>
43 #include <netinet/in.h>
44 #include <sys/socket.h>
103 #define Z_POOL_CREATE 48 /* pool create failed */
104 #define Z_POOL_BIND 49 /* pool bind failed */
105 #define Z_INVALID_PROPERTY 50 /* invalid property value */
106
107 /*
108 * Warning: these are shared with the admin/install consolidation.
109 * Do not insert states between any of the currently defined states,
110 * and any new states must be evaluated for impact on range comparisons.
111 */
112 #define ZONE_STATE_CONFIGURED 0
113 #define ZONE_STATE_INCOMPLETE 1
114 #define ZONE_STATE_INSTALLED 2
115 #define ZONE_STATE_READY 3
116 #define ZONE_STATE_RUNNING 4
117 #define ZONE_STATE_SHUTTING_DOWN 5
118 #define ZONE_STATE_DOWN 6
119 #define ZONE_STATE_MOUNTED 7
120
121 #define ZONE_STATE_MAXSTRLEN 14
122
123 #define ZONE_PROP_MAXSTRLEN 1024
124
125 #define LIBZONECFG_PATH "libzonecfg.so.1"
126
127 #define ZONE_CONFIG_ROOT "/etc/zones"
128 #define ZONE_INDEX_FILE ZONE_CONFIG_ROOT "/index"
129
130 #define MAXUSERNAME (sizeof (((struct utmpx *)0)->ut_name))
131 #define MAXAUTHS 4096
132 #define ZONE_MGMT_PROF "Zone Management"
133
134 #define ZONE_INT32SZ 11 /* string to hold 32bit int. */
135
136 /* Owner, group, and mode (defined by packaging) for the config directory */
137 #define ZONE_CONFIG_UID 0 /* root */
138 #define ZONE_CONFIG_GID 3 /* sys */
139 #define ZONE_CONFIG_MODE 0755
140
141 /* Owner, group, and mode (defined by packaging) for the index file */
142 #define ZONE_INDEX_UID 0 /* root */
143 #define ZONE_INDEX_GID 3 /* sys */
144 #define ZONE_INDEX_MODE 0644
153 #define ALIAS_MAXSHMMEM "max-shm-memory"
154 #define ALIAS_MAXSHMIDS "max-shm-ids"
155 #define ALIAS_MAXMSGIDS "max-msg-ids"
156 #define ALIAS_MAXSEMIDS "max-sem-ids"
157 #define ALIAS_MAXLOCKEDMEM "locked"
158 #define ALIAS_MAXSWAP "swap"
159 #define ALIAS_MAXPHYSMEM "physical"
160 #define ALIAS_SHARES "cpu-shares"
161 #define ALIAS_CPUCAP "cpu-cap"
162 #define ALIAS_MAXPROCS "max-processes"
163 #define ALIAS_ZFSPRI "zfs-io-priority"
164
165 /* Default name for zone detached manifest */
166 #define ZONE_DETACHED "SUNWdetached.xml"
167
168 /*
169 * Bit flag definitions for passing into libzonecfg functions.
170 */
171 #define ZONE_DRY_RUN 0x01
172
173 typedef enum zone_iptype {
174 ZS_SHARED,
175 ZS_EXCLUSIVE
176 } zone_iptype_t;
177
178 /*
179 * The integer field expresses the current values on a get.
180 * On a put, it represents the new values if >= 0 or "don't change" if < 0.
181 */
182 struct zoneent {
183 char zone_name[ZONENAME_MAX]; /* name of the zone */
184 int zone_state; /* configured | incomplete | installed */
185 char zone_path[MAXPATHLEN]; /* path to zone storage */
186 uuid_t zone_uuid; /* unique ID for zone */
187 char zone_newname[ZONENAME_MAX]; /* for doing renames */
188 char zone_brand[MAXNAMELEN]; /* zone's brand */
189 zone_iptype_t zone_iptype; /* zone's IP type */
190 zoneid_t zone_did; /* persistent debug ID */
191 };
192
193 typedef struct zone_dochandle *zone_dochandle_t; /* opaque handle */
194
195 typedef uint_t zone_state_t;
196
197 typedef struct zone_fsopt {
198 struct zone_fsopt *zone_fsopt_next;
199 char zone_fsopt_opt[MAX_MNTOPT_STR];
200 } zone_fsopt_t;
201
202 struct zone_fstab {
203 char zone_fs_special[MAXPATHLEN]; /* special file */
204 char zone_fs_dir[MAXPATHLEN]; /* mount point */
205 char zone_fs_type[FSTYPSZ]; /* e.g. ufs */
206 zone_fsopt_t *zone_fs_options; /* mount options */
207 char zone_fs_raw[MAXPATHLEN]; /* device to fsck */
208 };
209
210 /*
211 * Generic resource attribute list.
212 * Key/value resource that can be attached to net or device.
213 */
214 struct zone_res_attrtab {
215 char zone_res_attr_name[MAXNAMELEN];
216 char zone_res_attr_value[ZONE_PROP_MAXSTRLEN];
217 struct zone_res_attrtab *zone_res_attr_next;
218 };
219
220 struct zone_nwiftab {
221 char zone_nwif_address[INET6_ADDRSTRLEN]; /* shared-ip only */
222 char zone_nwif_allowed_address[INET6_ADDRSTRLEN]; /* excl-ip only */
223 char zone_nwif_physical[LIFNAMSIZ];
224 char zone_nwif_mac[MAXMACADDRLEN]; /* excl-ip only */
225 char zone_nwif_vlan_id[ZONE_INT32SZ]; /* excl-ip only */
226 char zone_nwif_gnic[LIFNAMSIZ]; /* excl-ip only */
227 char zone_nwif_defrouter[INET6_ADDRSTRLEN];
228 struct zone_res_attrtab *zone_nwif_attrp;
229 };
230
231 struct zone_devtab {
232 char zone_dev_match[MAXPATHLEN];
233 struct zone_res_attrtab *zone_dev_attrp;
234 };
235
236 struct zone_rctlvaltab {
274 char *zone_devperm_acl;
275 };
276
277 struct zone_admintab {
278 char zone_admin_user[MAXUSERNAME];
279 char zone_admin_auths[MAXAUTHS];
280 };
281
282 typedef struct zone_userauths {
283 char user[MAXUSERNAME];
284 char zonename[ZONENAME_MAX];
285 struct zone_userauths *next;
286 } zone_userauths_t;
287
288 typedef struct {
289 uu_avl_node_t zpe_entry;
290 char *zpe_name;
291 char *zpe_vers;
292 } zone_pkg_entry_t;
293
294 /*
295 * Basic configuration management routines.
296 */
297 extern zone_dochandle_t zonecfg_init_handle(void);
298 extern int zonecfg_get_handle(const char *, zone_dochandle_t);
299 extern int zonecfg_get_snapshot_handle(const char *, zone_dochandle_t);
300 extern int zonecfg_get_template_handle(const char *, const char *,
301 zone_dochandle_t);
302 extern int zonecfg_get_xml_handle(const char *, zone_dochandle_t);
303 extern int zonecfg_check_handle(zone_dochandle_t);
304 extern void zonecfg_fini_handle(zone_dochandle_t);
305 extern int zonecfg_destroy(const char *, boolean_t);
306 extern int zonecfg_destroy_snapshot(const char *);
307 extern int zonecfg_save(zone_dochandle_t);
308 extern int zonecfg_create_snapshot(const char *);
309 extern char *zonecfg_strerror(int);
310 extern int zonecfg_access(const char *, int);
311 extern void zonecfg_set_root(const char *);
312 extern const char *zonecfg_get_root(void);
313 extern boolean_t zonecfg_in_alt_root(void);
314 extern int zonecfg_num_resources(zone_dochandle_t, char *);
315 extern int zonecfg_del_all_resources(zone_dochandle_t, char *);
316 extern boolean_t zonecfg_valid_ncpus(char *, char *);
317 extern boolean_t zonecfg_valid_importance(char *);
318 extern int zonecfg_str_to_bytes(char *, uint64_t *);
319 extern boolean_t zonecfg_valid_memlimit(char *, uint64_t *);
320 extern boolean_t zonecfg_valid_alias_limit(char *, char *, uint64_t *);
321 extern void zonecfg_notify_create(zone_dochandle_t);
322
323 /*
324 * Zone name, path to zone directory, autoboot setting, pool, boot
325 * arguments, and scheduling-class.
326 */
327 extern int zonecfg_validate_zonename(const char *);
328 extern int zonecfg_get_name(zone_dochandle_t, char *, size_t);
329 extern int zonecfg_set_name(zone_dochandle_t, char *);
330 extern int zonecfg_get_zonepath(zone_dochandle_t, char *, size_t);
331 extern int zonecfg_set_zonepath(zone_dochandle_t, char *);
332 extern int zonecfg_get_autoboot(zone_dochandle_t, boolean_t *);
333 extern int zonecfg_set_autoboot(zone_dochandle_t, boolean_t);
334 extern int zonecfg_get_iptype(zone_dochandle_t, zone_iptype_t *);
335 extern int zonecfg_set_iptype(zone_dochandle_t, zone_iptype_t);
336 extern int zonecfg_get_pool(zone_dochandle_t, char *, size_t);
337 extern int zonecfg_set_pool(zone_dochandle_t, char *);
338 extern int zonecfg_get_bootargs(zone_dochandle_t, char *, size_t);
339 extern int zonecfg_set_bootargs(zone_dochandle_t, char *);
340 extern int zonecfg_get_sched_class(zone_dochandle_t, char *, size_t);
341 extern int zonecfg_set_sched(zone_dochandle_t, char *);
527 */
528 extern int zonecfg_default_privset(priv_set_t *, const char *);
529 extern int zonecfg_get_privset(zone_dochandle_t, priv_set_t *,
530 char **);
531 extern int zonecfg_get_limitpriv(zone_dochandle_t, char **);
532 extern int zonecfg_set_limitpriv(zone_dochandle_t, char *);
533
534 /*
535 * Higher-level routines.
536 */
537 extern int zone_get_brand(char *, char *, size_t);
538 extern zoneid_t zone_get_did(char *);
539 extern int zone_get_rootpath(char *, char *, size_t);
540 extern int zone_get_devroot(char *, char *, size_t);
541 extern int zone_get_zonepath(char *, char *, size_t);
542 extern int zone_get_state(char *, zone_state_t *);
543 extern int zone_set_state(char *, zone_state_t);
544 extern char *zone_state_str(zone_state_t);
545 extern int zonecfg_get_name_by_uuid(const uuid_t, char *, size_t);
546 extern int zonecfg_get_uuid(const char *, uuid_t);
547 extern int zonecfg_set_uuid(const char *, const char *, const char *);
548 extern int zonecfg_default_brand(char *, size_t);
549 extern int zonecfg_fix_obsolete(zone_dochandle_t);
550
551 /*
552 * Iterator for configured zones.
553 */
554 extern FILE *setzoneent(void);
555 extern char *getzoneent(FILE *);
556 extern struct zoneent *getzoneent_private(FILE *);
557 extern void endzoneent(FILE *);
558
559 /*
560 * File-system-related convenience functions.
561 */
562 extern boolean_t zonecfg_valid_fs_type(const char *);
563
564 /*
565 * Network-related convenience functions.
566 */
567 extern boolean_t zonecfg_same_net_address(char *, char *);
|
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 /*
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #ifndef _LIBZONECFG_H
27 #define _LIBZONECFG_H
28
29 /*
30 * Zone configuration header file.
31 */
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /* sys/socket.h is required by net/if.h, which has a constant needed here */
38 #include <sys/param.h>
39 #include <sys/fstyp.h>
40 #include <sys/mount.h>
41 #include <priv.h>
42 #include <netinet/in.h>
43 #include <sys/socket.h>
102 #define Z_POOL_CREATE 48 /* pool create failed */
103 #define Z_POOL_BIND 49 /* pool bind failed */
104 #define Z_INVALID_PROPERTY 50 /* invalid property value */
105
106 /*
107 * Warning: these are shared with the admin/install consolidation.
108 * Do not insert states between any of the currently defined states,
109 * and any new states must be evaluated for impact on range comparisons.
110 */
111 #define ZONE_STATE_CONFIGURED 0
112 #define ZONE_STATE_INCOMPLETE 1
113 #define ZONE_STATE_INSTALLED 2
114 #define ZONE_STATE_READY 3
115 #define ZONE_STATE_RUNNING 4
116 #define ZONE_STATE_SHUTTING_DOWN 5
117 #define ZONE_STATE_DOWN 6
118 #define ZONE_STATE_MOUNTED 7
119
120 #define ZONE_STATE_MAXSTRLEN 14
121
122 #define LIBZONECFG_PATH "libzonecfg.so.1"
123
124 #define ZONE_CONFIG_ROOT "/etc/zones"
125 #define ZONE_INDEX_FILE ZONE_CONFIG_ROOT "/index"
126
127 #define MAXUSERNAME (sizeof (((struct utmpx *)0)->ut_name))
128 #define MAXAUTHS 4096
129 #define ZONE_MGMT_PROF "Zone Management"
130
131 #define ZONE_INT32SZ 11 /* string to hold 32bit int. */
132
133 /* Owner, group, and mode (defined by packaging) for the config directory */
134 #define ZONE_CONFIG_UID 0 /* root */
135 #define ZONE_CONFIG_GID 3 /* sys */
136 #define ZONE_CONFIG_MODE 0755
137
138 /* Owner, group, and mode (defined by packaging) for the index file */
139 #define ZONE_INDEX_UID 0 /* root */
140 #define ZONE_INDEX_GID 3 /* sys */
141 #define ZONE_INDEX_MODE 0644
150 #define ALIAS_MAXSHMMEM "max-shm-memory"
151 #define ALIAS_MAXSHMIDS "max-shm-ids"
152 #define ALIAS_MAXMSGIDS "max-msg-ids"
153 #define ALIAS_MAXSEMIDS "max-sem-ids"
154 #define ALIAS_MAXLOCKEDMEM "locked"
155 #define ALIAS_MAXSWAP "swap"
156 #define ALIAS_MAXPHYSMEM "physical"
157 #define ALIAS_SHARES "cpu-shares"
158 #define ALIAS_CPUCAP "cpu-cap"
159 #define ALIAS_MAXPROCS "max-processes"
160 #define ALIAS_ZFSPRI "zfs-io-priority"
161
162 /* Default name for zone detached manifest */
163 #define ZONE_DETACHED "SUNWdetached.xml"
164
165 /*
166 * Bit flag definitions for passing into libzonecfg functions.
167 */
168 #define ZONE_DRY_RUN 0x01
169
170 /*
171 * The integer field expresses the current values on a get.
172 * On a put, it represents the new values if >= 0 or "don't change" if < 0.
173 */
174 struct zoneent {
175 char zone_name[ZONENAME_MAX]; /* name of the zone */
176 int zone_state; /* configured | incomplete | installed */
177 char zone_path[MAXPATHLEN]; /* path to zone storage */
178 uuid_t zone_uuid; /* unique ID for zone */
179 char zone_newname[ZONENAME_MAX]; /* for doing renames */
180 };
181
182 typedef struct zone_dochandle *zone_dochandle_t; /* opaque handle */
183
184 typedef uint_t zone_state_t;
185
186 typedef struct zone_fsopt {
187 struct zone_fsopt *zone_fsopt_next;
188 char zone_fsopt_opt[MAX_MNTOPT_STR];
189 } zone_fsopt_t;
190
191 struct zone_fstab {
192 char zone_fs_special[MAXPATHLEN]; /* special file */
193 char zone_fs_dir[MAXPATHLEN]; /* mount point */
194 char zone_fs_type[FSTYPSZ]; /* e.g. ufs */
195 zone_fsopt_t *zone_fs_options; /* mount options */
196 char zone_fs_raw[MAXPATHLEN]; /* device to fsck */
197 };
198
199 /*
200 * Generic resource attribute list.
201 * Key/value resource that can be attached to net or device.
202 */
203 struct zone_res_attrtab {
204 char zone_res_attr_name[MAXNAMELEN];
205 char zone_res_attr_value[MAXNAMELEN];
206 struct zone_res_attrtab *zone_res_attr_next;
207 };
208
209 struct zone_nwiftab {
210 char zone_nwif_address[INET6_ADDRSTRLEN]; /* shared-ip only */
211 char zone_nwif_allowed_address[INET6_ADDRSTRLEN]; /* excl-ip only */
212 char zone_nwif_physical[LIFNAMSIZ];
213 char zone_nwif_mac[MAXMACADDRLEN]; /* excl-ip only */
214 char zone_nwif_vlan_id[ZONE_INT32SZ]; /* excl-ip only */
215 char zone_nwif_gnic[LIFNAMSIZ]; /* excl-ip only */
216 char zone_nwif_defrouter[INET6_ADDRSTRLEN];
217 struct zone_res_attrtab *zone_nwif_attrp;
218 };
219
220 struct zone_devtab {
221 char zone_dev_match[MAXPATHLEN];
222 struct zone_res_attrtab *zone_dev_attrp;
223 };
224
225 struct zone_rctlvaltab {
263 char *zone_devperm_acl;
264 };
265
266 struct zone_admintab {
267 char zone_admin_user[MAXUSERNAME];
268 char zone_admin_auths[MAXAUTHS];
269 };
270
271 typedef struct zone_userauths {
272 char user[MAXUSERNAME];
273 char zonename[ZONENAME_MAX];
274 struct zone_userauths *next;
275 } zone_userauths_t;
276
277 typedef struct {
278 uu_avl_node_t zpe_entry;
279 char *zpe_name;
280 char *zpe_vers;
281 } zone_pkg_entry_t;
282
283 typedef enum zone_iptype {
284 ZS_SHARED,
285 ZS_EXCLUSIVE
286 } zone_iptype_t;
287
288 /*
289 * Basic configuration management routines.
290 */
291 extern zone_dochandle_t zonecfg_init_handle(void);
292 extern int zonecfg_get_handle(const char *, zone_dochandle_t);
293 extern int zonecfg_get_snapshot_handle(const char *, zone_dochandle_t);
294 extern int zonecfg_get_template_handle(const char *, const char *,
295 zone_dochandle_t);
296 extern int zonecfg_get_xml_handle(const char *, zone_dochandle_t);
297 extern int zonecfg_check_handle(zone_dochandle_t);
298 extern void zonecfg_fini_handle(zone_dochandle_t);
299 extern int zonecfg_destroy(const char *, boolean_t);
300 extern int zonecfg_destroy_snapshot(const char *);
301 extern int zonecfg_save(zone_dochandle_t);
302 extern int zonecfg_create_snapshot(const char *);
303 extern char *zonecfg_strerror(int);
304 extern int zonecfg_access(const char *, int);
305 extern void zonecfg_set_root(const char *);
306 extern const char *zonecfg_get_root(void);
307 extern boolean_t zonecfg_in_alt_root(void);
308 extern int zonecfg_num_resources(zone_dochandle_t, char *);
309 extern int zonecfg_del_all_resources(zone_dochandle_t, char *);
310 extern boolean_t zonecfg_valid_ncpus(char *, char *);
311 extern boolean_t zonecfg_valid_importance(char *);
312 extern int zonecfg_str_to_bytes(char *, uint64_t *);
313 extern boolean_t zonecfg_valid_memlimit(char *, uint64_t *);
314 extern boolean_t zonecfg_valid_alias_limit(char *, char *, uint64_t *);
315
316 /*
317 * Zone name, path to zone directory, autoboot setting, pool, boot
318 * arguments, and scheduling-class.
319 */
320 extern int zonecfg_validate_zonename(const char *);
321 extern int zonecfg_get_name(zone_dochandle_t, char *, size_t);
322 extern int zonecfg_set_name(zone_dochandle_t, char *);
323 extern int zonecfg_get_zonepath(zone_dochandle_t, char *, size_t);
324 extern int zonecfg_set_zonepath(zone_dochandle_t, char *);
325 extern int zonecfg_get_autoboot(zone_dochandle_t, boolean_t *);
326 extern int zonecfg_set_autoboot(zone_dochandle_t, boolean_t);
327 extern int zonecfg_get_iptype(zone_dochandle_t, zone_iptype_t *);
328 extern int zonecfg_set_iptype(zone_dochandle_t, zone_iptype_t);
329 extern int zonecfg_get_pool(zone_dochandle_t, char *, size_t);
330 extern int zonecfg_set_pool(zone_dochandle_t, char *);
331 extern int zonecfg_get_bootargs(zone_dochandle_t, char *, size_t);
332 extern int zonecfg_set_bootargs(zone_dochandle_t, char *);
333 extern int zonecfg_get_sched_class(zone_dochandle_t, char *, size_t);
334 extern int zonecfg_set_sched(zone_dochandle_t, char *);
520 */
521 extern int zonecfg_default_privset(priv_set_t *, const char *);
522 extern int zonecfg_get_privset(zone_dochandle_t, priv_set_t *,
523 char **);
524 extern int zonecfg_get_limitpriv(zone_dochandle_t, char **);
525 extern int zonecfg_set_limitpriv(zone_dochandle_t, char *);
526
527 /*
528 * Higher-level routines.
529 */
530 extern int zone_get_brand(char *, char *, size_t);
531 extern zoneid_t zone_get_did(char *);
532 extern int zone_get_rootpath(char *, char *, size_t);
533 extern int zone_get_devroot(char *, char *, size_t);
534 extern int zone_get_zonepath(char *, char *, size_t);
535 extern int zone_get_state(char *, zone_state_t *);
536 extern int zone_set_state(char *, zone_state_t);
537 extern char *zone_state_str(zone_state_t);
538 extern int zonecfg_get_name_by_uuid(const uuid_t, char *, size_t);
539 extern int zonecfg_get_uuid(const char *, uuid_t);
540 extern int zonecfg_default_brand(char *, size_t);
541 extern int zonecfg_fix_obsolete(zone_dochandle_t);
542
543 /*
544 * Iterator for configured zones.
545 */
546 extern FILE *setzoneent(void);
547 extern char *getzoneent(FILE *);
548 extern struct zoneent *getzoneent_private(FILE *);
549 extern void endzoneent(FILE *);
550
551 /*
552 * File-system-related convenience functions.
553 */
554 extern boolean_t zonecfg_valid_fs_type(const char *);
555
556 /*
557 * Network-related convenience functions.
558 */
559 extern boolean_t zonecfg_same_net_address(char *, char *);
|