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>
44 #include <net/if.h>
45 #include <stdio.h>
46 #include <rctl.h>
47 #include <zone.h>
48 #include <libbrand.h>
49 #include <sys/uuid.h>
50 #include <libuutil.h>
51 #include <sys/mnttab.h>
52 #include <limits.h>
53 #include <utmpx.h>
54
55 #define ZONE_ID_UNDEFINED -1
56
57 #define Z_OK 0
58 #define Z_EMPTY_DOCUMENT 1 /* XML doc root element is null */
59 #define Z_WRONG_DOC_TYPE 2 /* top-level XML doc element != zone */
60 #define Z_BAD_PROPERTY 3 /* libxml-level property problem */
61 #define Z_TEMP_FILE 4 /* problem creating temporary file */
62 #define Z_SAVING_FILE 5 /* libxml error saving or validating */
63 #define Z_NO_ENTRY 6 /* no such entry */
64 #define Z_BOGUS_ZONE_NAME 7 /* illegal zone name */
110 #define ZONE_STATE_CONFIGURED 0
111 #define ZONE_STATE_INCOMPLETE 1
112 #define ZONE_STATE_INSTALLED 2
113 #define ZONE_STATE_READY 3
114 #define ZONE_STATE_RUNNING 4
115 #define ZONE_STATE_SHUTTING_DOWN 5
116 #define ZONE_STATE_DOWN 6
117 #define ZONE_STATE_MOUNTED 7
118
119 #define ZONE_STATE_MAXSTRLEN 14
120
121 #define LIBZONECFG_PATH "libzonecfg.so.1"
122
123 #define ZONE_CONFIG_ROOT "/etc/zones"
124 #define ZONE_INDEX_FILE ZONE_CONFIG_ROOT "/index"
125
126 #define MAXUSERNAME (sizeof (((struct utmpx *)0)->ut_name))
127 #define MAXAUTHS 4096
128 #define ZONE_MGMT_PROF "Zone Management"
129
130 /* Owner, group, and mode (defined by packaging) for the config directory */
131 #define ZONE_CONFIG_UID 0 /* root */
132 #define ZONE_CONFIG_GID 3 /* sys */
133 #define ZONE_CONFIG_MODE 0755
134
135 /* Owner, group, and mode (defined by packaging) for the index file */
136 #define ZONE_INDEX_UID 0 /* root */
137 #define ZONE_INDEX_GID 3 /* sys */
138 #define ZONE_INDEX_MODE 0644
139
140 /* The maximum length of the VERSION string in the pkginfo(4) file. */
141 #define ZONE_PKG_VERSMAX 256
142
143 /*
144 * Shortened alias names for the zones rctls.
145 */
146 #define ALIAS_MAXLWPS "max-lwps"
147 #define ALIAS_MAXSHMMEM "max-shm-memory"
148 #define ALIAS_MAXSHMIDS "max-shm-ids"
149 #define ALIAS_MAXMSGIDS "max-msg-ids"
150 #define ALIAS_MAXSEMIDS "max-sem-ids"
151 #define ALIAS_MAXLOCKEDMEM "locked"
152 #define ALIAS_MAXSWAP "swap"
153 #define ALIAS_MAXPHYSMEM "physical"
154 #define ALIAS_SHARES "cpu-shares"
155 #define ALIAS_CPUCAP "cpu-cap"
156 #define ALIAS_MAXPROCS "max-processes"
157
158 /* Default name for zone detached manifest */
159 #define ZONE_DETACHED "SUNWdetached.xml"
160
161 /*
162 * Bit flag definitions for passing into libzonecfg functions.
163 */
164 #define ZONE_DRY_RUN 0x01
165
166 /*
167 * The integer field expresses the current values on a get.
168 * On a put, it represents the new values if >= 0 or "don't change" if < 0.
169 */
170 struct zoneent {
171 char zone_name[ZONENAME_MAX]; /* name of the zone */
172 int zone_state; /* configured | incomplete | installed */
173 char zone_path[MAXPATHLEN]; /* path to zone storage */
174 uuid_t zone_uuid; /* unique ID for zone */
175 char zone_newname[ZONENAME_MAX]; /* for doing renames */
176 };
177
178 typedef struct zone_dochandle *zone_dochandle_t; /* opaque handle */
179
180 typedef uint_t zone_state_t;
181
182 typedef struct zone_fsopt {
183 struct zone_fsopt *zone_fsopt_next;
184 char zone_fsopt_opt[MAX_MNTOPT_STR];
185 } zone_fsopt_t;
186
187 struct zone_fstab {
188 char zone_fs_special[MAXPATHLEN]; /* special file */
189 char zone_fs_dir[MAXPATHLEN]; /* mount point */
190 char zone_fs_type[FSTYPSZ]; /* e.g. ufs */
191 zone_fsopt_t *zone_fs_options; /* mount options */
192 char zone_fs_raw[MAXPATHLEN]; /* device to fsck */
193 };
194
195 struct zone_nwiftab {
196 char zone_nwif_address[INET6_ADDRSTRLEN]; /* shared-ip only */
197 char zone_nwif_allowed_address[INET6_ADDRSTRLEN]; /* excl-ip only */
198 char zone_nwif_physical[LIFNAMSIZ];
199 char zone_nwif_defrouter[INET6_ADDRSTRLEN];
200 };
201
202 struct zone_devtab {
203 char zone_dev_match[MAXPATHLEN];
204 };
205
206 struct zone_rctlvaltab {
207 char zone_rctlval_priv[MAXNAMELEN];
208 char zone_rctlval_limit[MAXNAMELEN];
209 char zone_rctlval_action[MAXNAMELEN];
210 struct zone_rctlvaltab *zone_rctlval_next;
211 };
212
213 struct zone_rctltab {
214 char zone_rctl_name[MAXNAMELEN];
215 struct zone_rctlvaltab *zone_rctl_valptr;
216 };
217
218 struct zone_attrtab {
219 char zone_attr_name[MAXNAMELEN];
220 char zone_attr_type[MAXNAMELEN];
221 char zone_attr_value[2 * BUFSIZ];
222 };
223
297 /*
298 * Zone name, path to zone directory, autoboot setting, pool, boot
299 * arguments, and scheduling-class.
300 */
301 extern int zonecfg_validate_zonename(const char *);
302 extern int zonecfg_get_name(zone_dochandle_t, char *, size_t);
303 extern int zonecfg_set_name(zone_dochandle_t, char *);
304 extern int zonecfg_get_zonepath(zone_dochandle_t, char *, size_t);
305 extern int zonecfg_set_zonepath(zone_dochandle_t, char *);
306 extern int zonecfg_get_autoboot(zone_dochandle_t, boolean_t *);
307 extern int zonecfg_set_autoboot(zone_dochandle_t, boolean_t);
308 extern int zonecfg_get_iptype(zone_dochandle_t, zone_iptype_t *);
309 extern int zonecfg_set_iptype(zone_dochandle_t, zone_iptype_t);
310 extern int zonecfg_get_pool(zone_dochandle_t, char *, size_t);
311 extern int zonecfg_set_pool(zone_dochandle_t, char *);
312 extern int zonecfg_get_bootargs(zone_dochandle_t, char *, size_t);
313 extern int zonecfg_set_bootargs(zone_dochandle_t, char *);
314 extern int zonecfg_get_sched_class(zone_dochandle_t, char *, size_t);
315 extern int zonecfg_set_sched(zone_dochandle_t, char *);
316 extern int zonecfg_get_dflt_sched_class(zone_dochandle_t, char *, int);
317
318 /*
319 * Set/retrieve the brand for the zone
320 */
321 extern int zonecfg_get_brand(zone_dochandle_t, char *, size_t);
322 extern int zonecfg_set_brand(zone_dochandle_t, char *);
323
324 /*
325 * Filesystem configuration.
326 */
327 extern int zonecfg_add_filesystem(zone_dochandle_t, struct zone_fstab *);
328 extern int zonecfg_delete_filesystem(zone_dochandle_t,
329 struct zone_fstab *);
330 extern int zonecfg_modify_filesystem(zone_dochandle_t,
331 struct zone_fstab *, struct zone_fstab *);
332 extern int zonecfg_lookup_filesystem(zone_dochandle_t,
333 struct zone_fstab *);
334 extern int zonecfg_add_fs_option(struct zone_fstab *, char *);
335 extern int zonecfg_remove_fs_option(struct zone_fstab *, char *);
336 extern void zonecfg_free_fs_option_list(zone_fsopt_t *);
337 extern int zonecfg_find_mounts(char *, int(*)(const struct mnttab *,
338 void *), void *);
339
340 /*
341 * Network interface configuration.
342 */
343 extern int zonecfg_add_nwif(zone_dochandle_t, struct zone_nwiftab *);
344 extern int zonecfg_delete_nwif(zone_dochandle_t, struct zone_nwiftab *);
345 extern int zonecfg_modify_nwif(zone_dochandle_t, struct zone_nwiftab *,
346 struct zone_nwiftab *);
347 extern int zonecfg_lookup_nwif(zone_dochandle_t, struct zone_nwiftab *);
348
349 /*
350 * Hostid emulation configuration.
351 */
352 extern int zonecfg_get_hostid(zone_dochandle_t, char *, size_t);
353 extern int zonecfg_set_hostid(zone_dochandle_t, const char *);
354
355 /*
356 * Allowed FS mounts configuration.
357 */
358 extern int zonecfg_get_fs_allowed(zone_dochandle_t, char *, size_t);
359 extern int zonecfg_set_fs_allowed(zone_dochandle_t, const char *);
360
481 extern int zonecfg_getdevperment(zone_dochandle_t,
482 struct zone_devpermtab *);
483 extern int zonecfg_enddevperment(zone_dochandle_t);
484 extern int zonecfg_setadminent(zone_dochandle_t);
485 extern int zonecfg_getadminent(zone_dochandle_t, struct zone_admintab *);
486 extern int zonecfg_endadminent(zone_dochandle_t);
487
488 /*
489 * Privilege-related functions.
490 */
491 extern int zonecfg_default_privset(priv_set_t *, const char *);
492 extern int zonecfg_get_privset(zone_dochandle_t, priv_set_t *,
493 char **);
494 extern int zonecfg_get_limitpriv(zone_dochandle_t, char **);
495 extern int zonecfg_set_limitpriv(zone_dochandle_t, char *);
496
497 /*
498 * Higher-level routines.
499 */
500 extern int zone_get_brand(char *, char *, size_t);
501 extern int zone_get_rootpath(char *, char *, size_t);
502 extern int zone_get_devroot(char *, char *, size_t);
503 extern int zone_get_zonepath(char *, char *, size_t);
504 extern int zone_get_state(char *, zone_state_t *);
505 extern int zone_set_state(char *, zone_state_t);
506 extern char *zone_state_str(zone_state_t);
507 extern int zonecfg_get_name_by_uuid(const uuid_t, char *, size_t);
508 extern int zonecfg_get_uuid(const char *, uuid_t);
509 extern int zonecfg_default_brand(char *, size_t);
510 extern int zonecfg_fix_obsolete(zone_dochandle_t);
511
512 /*
513 * Iterator for configured zones.
514 */
515 extern FILE *setzoneent(void);
516 extern char *getzoneent(FILE *);
517 extern struct zoneent *getzoneent_private(FILE *);
518 extern void endzoneent(FILE *);
519
520 /*
|
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>
44 #include <net/if.h>
45 #include <sys/mac.h>
46 #include <stdio.h>
47 #include <rctl.h>
48 #include <zone.h>
49 #include <libbrand.h>
50 #include <sys/uuid.h>
51 #include <libuutil.h>
52 #include <sys/mnttab.h>
53 #include <limits.h>
54 #include <utmpx.h>
55
56 #define ZONE_ID_UNDEFINED -1
57
58 #define Z_OK 0
59 #define Z_EMPTY_DOCUMENT 1 /* XML doc root element is null */
60 #define Z_WRONG_DOC_TYPE 2 /* top-level XML doc element != zone */
61 #define Z_BAD_PROPERTY 3 /* libxml-level property problem */
62 #define Z_TEMP_FILE 4 /* problem creating temporary file */
63 #define Z_SAVING_FILE 5 /* libxml error saving or validating */
64 #define Z_NO_ENTRY 6 /* no such entry */
65 #define Z_BOGUS_ZONE_NAME 7 /* illegal zone name */
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
142
143 /* The maximum length of the VERSION string in the pkginfo(4) file. */
144 #define ZONE_PKG_VERSMAX 256
145
146 /*
147 * Shortened alias names for the zones rctls.
148 */
149 #define ALIAS_MAXLWPS "max-lwps"
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 {
226 char zone_rctlval_priv[MAXNAMELEN];
227 char zone_rctlval_limit[MAXNAMELEN];
228 char zone_rctlval_action[MAXNAMELEN];
229 struct zone_rctlvaltab *zone_rctlval_next;
230 };
231
232 struct zone_rctltab {
233 char zone_rctl_name[MAXNAMELEN];
234 struct zone_rctlvaltab *zone_rctl_valptr;
235 };
236
237 struct zone_attrtab {
238 char zone_attr_name[MAXNAMELEN];
239 char zone_attr_type[MAXNAMELEN];
240 char zone_attr_value[2 * BUFSIZ];
241 };
242
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 *);
335 extern int zonecfg_get_dflt_sched_class(zone_dochandle_t, char *, int);
336 extern zoneid_t zonecfg_get_did(zone_dochandle_t);
337 extern void zonecfg_set_did(zone_dochandle_t);
338
339 /*
340 * Set/retrieve the brand for the zone
341 */
342 extern int zonecfg_get_brand(zone_dochandle_t, char *, size_t);
343 extern int zonecfg_set_brand(zone_dochandle_t, char *);
344
345 /*
346 * Filesystem configuration.
347 */
348 extern int zonecfg_add_filesystem(zone_dochandle_t, struct zone_fstab *);
349 extern int zonecfg_delete_filesystem(zone_dochandle_t,
350 struct zone_fstab *);
351 extern int zonecfg_modify_filesystem(zone_dochandle_t,
352 struct zone_fstab *, struct zone_fstab *);
353 extern int zonecfg_lookup_filesystem(zone_dochandle_t,
354 struct zone_fstab *);
355 extern int zonecfg_add_fs_option(struct zone_fstab *, char *);
356 extern int zonecfg_remove_fs_option(struct zone_fstab *, char *);
357 extern void zonecfg_free_fs_option_list(zone_fsopt_t *);
358 extern int zonecfg_find_mounts(char *, int(*)(const struct mnttab *,
359 void *), void *);
360
361 /*
362 * Resource key/value attributes (properties).
363 */
364 extern int zonecfg_add_res_attr(struct zone_res_attrtab **,
365 struct zone_res_attrtab *);
366 extern void zonecfg_free_res_attr_list(struct zone_res_attrtab *);
367 extern int zonecfg_remove_res_attr(struct zone_res_attrtab **,
368 struct zone_res_attrtab *);
369
370 /*
371 * Network interface configuration.
372 */
373 extern int zonecfg_add_nwif(zone_dochandle_t, struct zone_nwiftab *);
374 extern int zonecfg_delete_nwif(zone_dochandle_t, struct zone_nwiftab *);
375 extern int zonecfg_modify_nwif(zone_dochandle_t, struct zone_nwiftab *,
376 struct zone_nwiftab *);
377 extern int zonecfg_lookup_nwif(zone_dochandle_t, struct zone_nwiftab *);
378
379 /*
380 * Hostid emulation configuration.
381 */
382 extern int zonecfg_get_hostid(zone_dochandle_t, char *, size_t);
383 extern int zonecfg_set_hostid(zone_dochandle_t, const char *);
384
385 /*
386 * Allowed FS mounts configuration.
387 */
388 extern int zonecfg_get_fs_allowed(zone_dochandle_t, char *, size_t);
389 extern int zonecfg_set_fs_allowed(zone_dochandle_t, const char *);
390
511 extern int zonecfg_getdevperment(zone_dochandle_t,
512 struct zone_devpermtab *);
513 extern int zonecfg_enddevperment(zone_dochandle_t);
514 extern int zonecfg_setadminent(zone_dochandle_t);
515 extern int zonecfg_getadminent(zone_dochandle_t, struct zone_admintab *);
516 extern int zonecfg_endadminent(zone_dochandle_t);
517
518 /*
519 * Privilege-related functions.
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 /*
|