libzonecfg.h revision 2303:327ca1e2fdf0
190792Sgshapiro/* 2261363Sgshapiro * CDDL HEADER START 390792Sgshapiro * 490792Sgshapiro * The contents of this file are subject to the terms of the 590792Sgshapiro * Common Development and Distribution License (the "License"). 690792Sgshapiro * You may not use this file except in compliance with the License. 790792Sgshapiro * 890792Sgshapiro * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 990792Sgshapiro * or http://www.opensolaris.org/os/licensing. 1090792Sgshapiro * See the License for the specific language governing permissions 1190792Sgshapiro * and limitations under the License. 1290792Sgshapiro * 1390792Sgshapiro * When distributing Covered Code, include this CDDL HEADER in each 1490792Sgshapiro * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1590792Sgshapiro * If applicable, add the following below this CDDL HEADER, with the 16266692Sgshapiro * fields enclosed by brackets "[]" replaced with your own identifying 1790792Sgshapiro * information: Portions Copyright [yyyy] [name of copyright owner] 1890792Sgshapiro * 1990792Sgshapiro * CDDL HEADER END 2090792Sgshapiro */ 21168515Sgshapiro 2290792Sgshapiro/* 2390792Sgshapiro * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 2490792Sgshapiro * Use is subject to license terms. 2590792Sgshapiro */ 2690792Sgshapiro 2790792Sgshapiro#ifndef _LIBZONECFG_H 2890792Sgshapiro#define _LIBZONECFG_H 2990792Sgshapiro 3090792Sgshapiro#pragma ident "%Z%%M% %I% %E% SMI" 3190792Sgshapiro 3290792Sgshapiro/* 3390792Sgshapiro * Zone configuration header file. 3490792Sgshapiro */ 35168515Sgshapiro 3690792Sgshapiro#ifdef __cplusplus 37168515Sgshapiroextern "C" { 3890792Sgshapiro#endif 39120256Sgshapiro 4090792Sgshapiro/* sys/socket.h is required by net/if.h, which has a constant needed here */ 4190792Sgshapiro#include <sys/param.h> 4290792Sgshapiro#include <sys/fstyp.h> 4390792Sgshapiro#include <sys/mount.h> 4490792Sgshapiro#include <priv.h> 4590792Sgshapiro#include <netinet/in.h> 4690792Sgshapiro#include <sys/socket.h> 4790792Sgshapiro#include <net/if.h> 4890792Sgshapiro#include <stdio.h> 4990792Sgshapiro#include <rctl.h> 5090792Sgshapiro#include <zone.h> 5190792Sgshapiro#include <sys/uuid.h> 5290792Sgshapiro 5390792Sgshapiro#define ZONE_ID_UNDEFINED -1 5490792Sgshapiro 5590792Sgshapiro#define Z_OK 0 5690792Sgshapiro#define Z_EMPTY_DOCUMENT 1 /* XML doc root element is null */ 5790792Sgshapiro#define Z_WRONG_DOC_TYPE 2 /* top-level XML doc element != zone */ 5890792Sgshapiro#define Z_BAD_PROPERTY 3 /* libxml-level property problem */ 5990792Sgshapiro#define Z_TEMP_FILE 4 /* problem creating temporary file */ 6090792Sgshapiro#define Z_SAVING_FILE 5 /* libxml error saving or validating */ 61120256Sgshapiro#define Z_NO_ENTRY 6 /* no such entry */ 62120256Sgshapiro#define Z_BOGUS_ZONE_NAME 7 /* illegal zone name */ 6390792Sgshapiro#define Z_REQD_RESOURCE_MISSING 8 /* required resource missing */ 6490792Sgshapiro#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#define Z_PRIV_PROHIBITED 37 /* specified privilege is prohibited */ 89#define Z_PRIV_REQUIRED 38 /* required privilege is missing */ 90#define Z_PRIV_UNKNOWN 39 /* specified privilege is unknown */ 91 92/* 93 * Warning: these are shared with the admin/install consolidation. 94 * Do not insert states between any of the currently defined states, 95 * and any new states must be evaluated for impact on range comparisons. 96 */ 97#define ZONE_STATE_CONFIGURED 0 98#define ZONE_STATE_INCOMPLETE 1 99#define ZONE_STATE_INSTALLED 2 100#define ZONE_STATE_READY 3 101#define ZONE_STATE_RUNNING 4 102#define ZONE_STATE_SHUTTING_DOWN 5 103#define ZONE_STATE_DOWN 6 104#define ZONE_STATE_MOUNTED 7 105 106#define ZONE_STATE_MAXSTRLEN 14 107 108#define LIBZONECFG_PATH "libzonecfg.so.1" 109 110#define ZONE_CONFIG_ROOT "/etc/zones" 111#define ZONE_INDEX_FILE ZONE_CONFIG_ROOT "/index" 112 113/* Owner, group, and mode (defined by packaging) for the config directory */ 114#define ZONE_CONFIG_UID 0 /* root */ 115#define ZONE_CONFIG_GID 3 /* sys */ 116#define ZONE_CONFIG_MODE 0755 117 118/* Owner, group, and mode (defined by packaging) for the index file */ 119#define ZONE_INDEX_UID 0 /* root */ 120#define ZONE_INDEX_GID 3 /* sys */ 121#define ZONE_INDEX_MODE 0644 122 123/* The maximum length of the VERSION string in the pkginfo(4) file. */ 124#define ZONE_PKG_VERSMAX 256 125 126/* 127 * Bit flag definitions for passing into libzonecfg functions. 128 */ 129#define ZONE_DRY_RUN 0x01 130 131/* 132 * The integer field expresses the current values on a get. 133 * On a put, it represents the new values if >= 0 or "don't change" if < 0. 134 */ 135struct zoneent { 136 char zone_name[ZONENAME_MAX]; /* name of the zone */ 137 int zone_state; /* configured | incomplete | installed */ 138 char zone_path[MAXPATHLEN]; /* path to zone storage */ 139 uuid_t zone_uuid; /* unique ID for zone */ 140 char zone_newname[ZONENAME_MAX]; /* for doing renames */ 141}; 142 143typedef struct zone_dochandle *zone_dochandle_t; /* opaque handle */ 144 145typedef uint_t zone_state_t; 146 147typedef struct zone_fsopt { 148 struct zone_fsopt *zone_fsopt_next; 149 char zone_fsopt_opt[MAX_MNTOPT_STR]; 150} zone_fsopt_t; 151 152struct zone_fstab { 153 char zone_fs_special[MAXPATHLEN]; /* special file */ 154 char zone_fs_dir[MAXPATHLEN]; /* mount point */ 155 char zone_fs_type[FSTYPSZ]; /* e.g. ufs */ 156 zone_fsopt_t *zone_fs_options; /* mount options */ 157 char zone_fs_raw[MAXPATHLEN]; /* device to fsck */ 158}; 159 160struct zone_nwiftab { 161 char zone_nwif_address[INET6_ADDRSTRLEN]; 162 char zone_nwif_physical[LIFNAMSIZ]; 163}; 164 165struct zone_devtab { 166 char zone_dev_match[MAXPATHLEN]; 167}; 168 169struct zone_rctlvaltab { 170 char zone_rctlval_priv[MAXNAMELEN]; 171 char zone_rctlval_limit[MAXNAMELEN]; 172 char zone_rctlval_action[MAXNAMELEN]; 173 struct zone_rctlvaltab *zone_rctlval_next; 174}; 175 176struct zone_rctltab { 177 char zone_rctl_name[MAXNAMELEN]; 178 struct zone_rctlvaltab *zone_rctl_valptr; 179}; 180 181struct zone_attrtab { 182 char zone_attr_name[MAXNAMELEN]; 183 char zone_attr_type[MAXNAMELEN]; 184 char zone_attr_value[2 * BUFSIZ]; 185}; 186 187struct zone_dstab { 188 char zone_dataset_name[MAXNAMELEN]; 189}; 190 191struct zone_pkgtab { 192 char zone_pkg_name[MAXNAMELEN]; 193 char zone_pkg_version[ZONE_PKG_VERSMAX]; 194}; 195 196struct zone_patchtab { 197 char zone_patch_id[MAXNAMELEN]; 198}; 199 200struct zone_devpermtab { 201 char zone_devperm_name[MAXPATHLEN]; 202 uid_t zone_devperm_uid; 203 gid_t zone_devperm_gid; 204 mode_t zone_devperm_mode; 205 char *zone_devperm_acl; 206}; 207 208/* 209 * Basic configuration management routines. 210 */ 211extern zone_dochandle_t zonecfg_init_handle(void); 212extern int zonecfg_get_handle(const char *, zone_dochandle_t); 213extern int zonecfg_get_snapshot_handle(const char *, zone_dochandle_t); 214extern int zonecfg_get_template_handle(const char *, const char *, 215 zone_dochandle_t); 216extern int zonecfg_check_handle(zone_dochandle_t); 217extern void zonecfg_fini_handle(zone_dochandle_t); 218extern int zonecfg_destroy(const char *, boolean_t); 219extern int zonecfg_destroy_snapshot(const char *); 220extern int zonecfg_save(zone_dochandle_t); 221extern int zonecfg_create_snapshot(const char *); 222extern char *zonecfg_strerror(int); 223extern int zonecfg_access(const char *, int); 224extern void zonecfg_set_root(const char *); 225extern const char *zonecfg_get_root(void); 226extern boolean_t zonecfg_in_alt_root(void); 227 228/* 229 * Zone name, path to zone directory, autoboot setting, pool and boot 230 * arguments. 231 */ 232extern int zonecfg_validate_zonename(const char *); 233extern int zonecfg_get_name(zone_dochandle_t, char *, size_t); 234extern int zonecfg_set_name(zone_dochandle_t, char *); 235extern int zonecfg_get_zonepath(zone_dochandle_t, char *, size_t); 236extern int zonecfg_set_zonepath(zone_dochandle_t, char *); 237extern int zonecfg_get_autoboot(zone_dochandle_t, boolean_t *); 238extern int zonecfg_set_autoboot(zone_dochandle_t, boolean_t); 239extern int zonecfg_get_pool(zone_dochandle_t, char *, size_t); 240extern int zonecfg_set_pool(zone_dochandle_t, char *); 241extern int zonecfg_get_bootargs(zone_dochandle_t, char *, size_t); 242extern int zonecfg_set_bootargs(zone_dochandle_t, char *); 243 244/* 245 * Filesystem configuration. 246 */ 247extern int zonecfg_add_filesystem(zone_dochandle_t, struct zone_fstab *); 248extern int zonecfg_delete_filesystem(zone_dochandle_t, 249 struct zone_fstab *); 250extern int zonecfg_modify_filesystem(zone_dochandle_t, 251 struct zone_fstab *, struct zone_fstab *); 252extern int zonecfg_lookup_filesystem(zone_dochandle_t, 253 struct zone_fstab *); 254extern int zonecfg_add_ipd(zone_dochandle_t, struct zone_fstab *); 255extern int zonecfg_delete_ipd(zone_dochandle_t, struct zone_fstab *); 256extern int zonecfg_modify_ipd(zone_dochandle_t, 257 struct zone_fstab *, struct zone_fstab *); 258extern int zonecfg_lookup_ipd(zone_dochandle_t, struct zone_fstab *); 259extern int zonecfg_add_fs_option(struct zone_fstab *, char *); 260extern int zonecfg_remove_fs_option(struct zone_fstab *, char *); 261extern void zonecfg_free_fs_option_list(zone_fsopt_t *); 262extern int zonecfg_find_mounts(char *, int(*)(const char *, void *), 263 void *); 264 265/* 266 * Network interface configuration. 267 */ 268extern int zonecfg_add_nwif(zone_dochandle_t, struct zone_nwiftab *); 269extern int zonecfg_delete_nwif(zone_dochandle_t, struct zone_nwiftab *); 270extern int zonecfg_modify_nwif(zone_dochandle_t, struct zone_nwiftab *, 271 struct zone_nwiftab *); 272extern int zonecfg_lookup_nwif(zone_dochandle_t, struct zone_nwiftab *); 273 274/* 275 * Device configuration and rule matching. 276 */ 277extern int zonecfg_add_dev(zone_dochandle_t, struct zone_devtab *); 278extern int zonecfg_delete_dev(zone_dochandle_t, struct zone_devtab *); 279extern int zonecfg_modify_dev(zone_dochandle_t, struct zone_devtab *, 280 struct zone_devtab *); 281extern int zonecfg_lookup_dev(zone_dochandle_t, struct zone_devtab *); 282extern int zonecfg_match_dev(zone_dochandle_t, char *, 283 struct zone_devtab *); 284 285/* 286 * Resource control configuration. 287 */ 288extern int zonecfg_add_rctl(zone_dochandle_t, struct zone_rctltab *); 289extern int zonecfg_delete_rctl(zone_dochandle_t, struct zone_rctltab *); 290extern int zonecfg_modify_rctl(zone_dochandle_t, struct zone_rctltab *, 291 struct zone_rctltab *); 292extern int zonecfg_lookup_rctl(zone_dochandle_t, struct zone_rctltab *); 293extern int zonecfg_add_rctl_value(struct zone_rctltab *, 294 struct zone_rctlvaltab *); 295extern int zonecfg_remove_rctl_value(struct zone_rctltab *, 296 struct zone_rctlvaltab *); 297extern void zonecfg_free_rctl_value_list(struct zone_rctlvaltab *); 298 299/* 300 * Generic attribute configuration and type/value extraction. 301 */ 302extern int zonecfg_add_attr(zone_dochandle_t, struct zone_attrtab *); 303extern int zonecfg_delete_attr(zone_dochandle_t, struct zone_attrtab *); 304extern int zonecfg_modify_attr(zone_dochandle_t, struct zone_attrtab *, 305 struct zone_attrtab *); 306extern int zonecfg_lookup_attr(zone_dochandle_t, struct zone_attrtab *); 307extern int zonecfg_get_attr_boolean(const struct zone_attrtab *, 308 boolean_t *); 309extern int zonecfg_get_attr_int(const struct zone_attrtab *, int64_t *); 310extern int zonecfg_get_attr_string(const struct zone_attrtab *, char *, 311 size_t); 312extern int zonecfg_get_attr_uint(const struct zone_attrtab *, uint64_t *); 313 314/* 315 * ZFS configuration. 316 */ 317extern int zonecfg_add_ds(zone_dochandle_t, struct zone_dstab *); 318extern int zonecfg_delete_ds(zone_dochandle_t, struct zone_dstab *); 319extern int zonecfg_modify_ds(zone_dochandle_t, struct zone_dstab *, 320 struct zone_dstab *); 321extern int zonecfg_lookup_ds(zone_dochandle_t, struct zone_dstab *); 322 323/* 324 * attach/detach support. 325 */ 326extern int zonecfg_get_attach_handle(const char *, const char *, 327 boolean_t, zone_dochandle_t); 328extern int zonecfg_attach_manifest(int, zone_dochandle_t, 329 zone_dochandle_t); 330extern int zonecfg_detach_save(zone_dochandle_t, uint_t); 331extern int zonecfg_get_detach_info(zone_dochandle_t, boolean_t); 332extern boolean_t zonecfg_detached(const char *); 333extern void zonecfg_rm_detached(zone_dochandle_t, boolean_t forced); 334extern int zonecfg_devwalk(zone_dochandle_t handle, 335 int (*cb)(const char *, uid_t, gid_t, mode_t, const char *, void *), 336 void *data); 337extern int zonecfg_devperms_apply(zone_dochandle_t, const char *, 338 uid_t, gid_t, mode_t, const char *); 339 340 341/* 342 * '*ent' iterator routines. 343 */ 344extern int zonecfg_setfsent(zone_dochandle_t); 345extern int zonecfg_getfsent(zone_dochandle_t, struct zone_fstab *); 346extern int zonecfg_endfsent(zone_dochandle_t); 347extern int zonecfg_setipdent(zone_dochandle_t); 348extern int zonecfg_getipdent(zone_dochandle_t, struct zone_fstab *); 349extern int zonecfg_endipdent(zone_dochandle_t); 350extern int zonecfg_setnwifent(zone_dochandle_t); 351extern int zonecfg_getnwifent(zone_dochandle_t, struct zone_nwiftab *); 352extern int zonecfg_endnwifent(zone_dochandle_t); 353extern int zonecfg_setdevent(zone_dochandle_t); 354extern int zonecfg_getdevent(zone_dochandle_t, struct zone_devtab *); 355extern int zonecfg_enddevent(zone_dochandle_t); 356extern int zonecfg_setattrent(zone_dochandle_t); 357extern int zonecfg_getattrent(zone_dochandle_t, struct zone_attrtab *); 358extern int zonecfg_endattrent(zone_dochandle_t); 359extern int zonecfg_setrctlent(zone_dochandle_t); 360extern int zonecfg_getrctlent(zone_dochandle_t, struct zone_rctltab *); 361extern int zonecfg_endrctlent(zone_dochandle_t); 362extern int zonecfg_setdsent(zone_dochandle_t); 363extern int zonecfg_getdsent(zone_dochandle_t, struct zone_dstab *); 364extern int zonecfg_enddsent(zone_dochandle_t); 365extern int zonecfg_setpkgent(zone_dochandle_t); 366extern int zonecfg_getpkgent(zone_dochandle_t, struct zone_pkgtab *); 367extern int zonecfg_endpkgent(zone_dochandle_t); 368extern int zonecfg_setpatchent(zone_dochandle_t); 369extern int zonecfg_getpatchent(zone_dochandle_t, struct zone_patchtab *); 370extern int zonecfg_endpatchent(zone_dochandle_t); 371extern int zonecfg_setdevperment(zone_dochandle_t); 372extern int zonecfg_getdevperment(zone_dochandle_t, 373 struct zone_devpermtab *); 374extern int zonecfg_enddevperment(zone_dochandle_t); 375 376/* 377 * Privilege-related functions. 378 */ 379extern int zonecfg_default_privset(priv_set_t *); 380extern int zonecfg_get_privset(zone_dochandle_t, priv_set_t *, 381 char **); 382extern int zonecfg_get_limitpriv(zone_dochandle_t, char **); 383extern int zonecfg_set_limitpriv(zone_dochandle_t, char *); 384 385/* 386 * Higher-level routines. 387 */ 388extern int zone_get_rootpath(char *, char *, size_t); 389extern int zone_get_zonepath(char *, char *, size_t); 390extern int zone_get_state(char *, zone_state_t *); 391extern int zone_set_state(char *, zone_state_t); 392extern char *zone_state_str(zone_state_t); 393extern int zonecfg_get_name_by_uuid(const uuid_t, char *, size_t); 394extern int zonecfg_get_uuid(const char *, uuid_t); 395 396/* 397 * Iterator for configured zones. 398 */ 399extern FILE *setzoneent(void); 400extern char *getzoneent(FILE *); 401extern struct zoneent *getzoneent_private(FILE *); 402extern void endzoneent(FILE *); 403 404/* 405 * File-system-related convenience functions. 406 */ 407extern boolean_t zonecfg_valid_fs_type(const char *); 408 409/* 410 * Network-related convenience functions. 411 */ 412extern boolean_t zonecfg_same_net_address(char *, char *); 413extern int zonecfg_valid_net_address(char *, struct lifreq *); 414 415/* 416 * Rctl-related common functions. 417 */ 418extern boolean_t zonecfg_is_rctl(const char *); 419extern boolean_t zonecfg_valid_rctlname(const char *); 420extern boolean_t zonecfg_valid_rctlblk(const rctlblk_t *); 421extern boolean_t zonecfg_valid_rctl(const char *, const rctlblk_t *); 422extern int zonecfg_construct_rctlblk(const struct zone_rctlvaltab *, 423 rctlblk_t *); 424 425/* 426 * Live Upgrade support functions. Shared between ON and install gate. 427 */ 428extern FILE *zonecfg_open_scratch(const char *, boolean_t); 429extern int zonecfg_lock_scratch(FILE *); 430extern void zonecfg_close_scratch(FILE *); 431extern int zonecfg_get_scratch(FILE *, char *, size_t, char *, size_t, char *, 432 size_t); 433extern int zonecfg_find_scratch(FILE *, const char *, const char *, char *, 434 size_t); 435extern int zonecfg_reverse_scratch(FILE *, const char *, char *, size_t, 436 char *, size_t); 437extern int zonecfg_add_scratch(FILE *, const char *, const char *, 438 const char *); 439extern int zonecfg_delete_scratch(FILE *, const char *); 440extern boolean_t zonecfg_is_scratch(const char *); 441 442#ifdef __cplusplus 443} 444#endif 445 446#endif /* _LIBZONECFG_H */ 447