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 /* 162 * Basic configuration management routines. 163 */ 164 extern zone_dochandle_t zonecfg_init_handle(void); 165 extern int zonecfg_get_handle(const char *, zone_dochandle_t); 166 extern int zonecfg_get_snapshot_handle(const char *, zone_dochandle_t); 167 extern int zonecfg_get_template_handle(const char *, const char *, 168 zone_dochandle_t); 169 extern int zonecfg_check_handle(zone_dochandle_t); 170 extern void zonecfg_fini_handle(zone_dochandle_t); 171 extern int zonecfg_destroy(const char *, boolean_t); 172 extern int zonecfg_destroy_snapshot(const char *); 173 extern int zonecfg_save(zone_dochandle_t); 174 extern int zonecfg_create_snapshot(const char *); 175 extern char *zonecfg_strerror(int); 176 extern int zonecfg_access(const char *, int); 177 extern void zonecfg_set_root(const char *); 178 extern const char *zonecfg_get_root(void); 179 extern boolean_t zonecfg_in_alt_root(void); 180 181 /* 182 * Zone name, path to zone directory, autoboot setting and pool. 183 */ 184 extern int zonecfg_validate_zonename(const char *); 185 extern int zonecfg_get_name(zone_dochandle_t, char *, size_t); 186 extern int zonecfg_set_name(zone_dochandle_t, char *); 187 extern int zonecfg_get_zonepath(zone_dochandle_t, char *, size_t); 188 extern int zonecfg_set_zonepath(zone_dochandle_t, char *); 189 extern int zonecfg_get_autoboot(zone_dochandle_t, boolean_t *); 190 extern int zonecfg_set_autoboot(zone_dochandle_t, boolean_t); 191 extern int zonecfg_get_pool(zone_dochandle_t, char *, size_t); 192 extern int zonecfg_set_pool(zone_dochandle_t, char *); 193 194 /* 195 * Filesystem configuration. 196 */ 197 extern int zonecfg_add_filesystem(zone_dochandle_t, struct zone_fstab *); 198 extern int zonecfg_delete_filesystem(zone_dochandle_t, 199 struct zone_fstab *); 200 extern int zonecfg_modify_filesystem(zone_dochandle_t, 201 struct zone_fstab *, struct zone_fstab *); 202 extern int zonecfg_lookup_filesystem(zone_dochandle_t, 203 struct zone_fstab *); 204 extern int zonecfg_add_ipd(zone_dochandle_t, struct zone_fstab *); 205 extern int zonecfg_delete_ipd(zone_dochandle_t, struct zone_fstab *); 206 extern int zonecfg_modify_ipd(zone_dochandle_t, 207 struct zone_fstab *, struct zone_fstab *); 208 extern int zonecfg_lookup_ipd(zone_dochandle_t, struct zone_fstab *); 209 extern int zonecfg_add_fs_option(struct zone_fstab *, char *); 210 extern int zonecfg_remove_fs_option(struct zone_fstab *, char *); 211 extern void zonecfg_free_fs_option_list(zone_fsopt_t *); 212 extern int zonecfg_find_mounts(char *, int(*)(const char *, void *), 213 void *); 214 215 /* 216 * Network interface configuration. 217 */ 218 extern int zonecfg_add_nwif(zone_dochandle_t, struct zone_nwiftab *); 219 extern int zonecfg_delete_nwif(zone_dochandle_t, struct zone_nwiftab *); 220 extern int zonecfg_modify_nwif(zone_dochandle_t, struct zone_nwiftab *, 221 struct zone_nwiftab *); 222 extern int zonecfg_lookup_nwif(zone_dochandle_t, struct zone_nwiftab *); 223 224 /* 225 * Device configuration and rule matching. 226 */ 227 extern int zonecfg_add_dev(zone_dochandle_t, struct zone_devtab *); 228 extern int zonecfg_delete_dev(zone_dochandle_t, struct zone_devtab *); 229 extern int zonecfg_modify_dev(zone_dochandle_t, struct zone_devtab *, 230 struct zone_devtab *); 231 extern int zonecfg_lookup_dev(zone_dochandle_t, struct zone_devtab *); 232 extern int zonecfg_match_dev(zone_dochandle_t, char *, 233 struct zone_devtab *); 234 235 /* 236 * Resource control configuration. 237 */ 238 extern int zonecfg_add_rctl(zone_dochandle_t, struct zone_rctltab *); 239 extern int zonecfg_delete_rctl(zone_dochandle_t, struct zone_rctltab *); 240 extern int zonecfg_modify_rctl(zone_dochandle_t, struct zone_rctltab *, 241 struct zone_rctltab *); 242 extern int zonecfg_lookup_rctl(zone_dochandle_t, struct zone_rctltab *); 243 extern int zonecfg_add_rctl_value(struct zone_rctltab *, 244 struct zone_rctlvaltab *); 245 extern int zonecfg_remove_rctl_value(struct zone_rctltab *, 246 struct zone_rctlvaltab *); 247 extern void zonecfg_free_rctl_value_list(struct zone_rctlvaltab *); 248 249 /* 250 * Generic attribute configuration and type/value extraction. 251 */ 252 extern int zonecfg_add_attr(zone_dochandle_t, struct zone_attrtab *); 253 extern int zonecfg_delete_attr(zone_dochandle_t, struct zone_attrtab *); 254 extern int zonecfg_modify_attr(zone_dochandle_t, struct zone_attrtab *, 255 struct zone_attrtab *); 256 extern int zonecfg_lookup_attr(zone_dochandle_t, struct zone_attrtab *); 257 extern int zonecfg_get_attr_boolean(const struct zone_attrtab *, 258 boolean_t *); 259 extern int zonecfg_get_attr_int(const struct zone_attrtab *, int64_t *); 260 extern int zonecfg_get_attr_string(const struct zone_attrtab *, char *, 261 size_t); 262 extern int zonecfg_get_attr_uint(const struct zone_attrtab *, uint64_t *); 263 264 /* 265 * '*ent' iterator routines. 266 */ 267 extern int zonecfg_setfsent(zone_dochandle_t); 268 extern int zonecfg_getfsent(zone_dochandle_t, struct zone_fstab *); 269 extern int zonecfg_endfsent(zone_dochandle_t); 270 extern int zonecfg_setipdent(zone_dochandle_t); 271 extern int zonecfg_getipdent(zone_dochandle_t, struct zone_fstab *); 272 extern int zonecfg_endipdent(zone_dochandle_t); 273 extern int zonecfg_setnwifent(zone_dochandle_t); 274 extern int zonecfg_getnwifent(zone_dochandle_t, struct zone_nwiftab *); 275 extern int zonecfg_endnwifent(zone_dochandle_t); 276 extern int zonecfg_setdevent(zone_dochandle_t); 277 extern int zonecfg_getdevent(zone_dochandle_t, struct zone_devtab *); 278 extern int zonecfg_enddevent(zone_dochandle_t); 279 extern int zonecfg_setattrent(zone_dochandle_t); 280 extern int zonecfg_getattrent(zone_dochandle_t, struct zone_attrtab *); 281 extern int zonecfg_endattrent(zone_dochandle_t); 282 extern int zonecfg_setrctlent(zone_dochandle_t); 283 extern int zonecfg_getrctlent(zone_dochandle_t, struct zone_rctltab *); 284 extern int zonecfg_endrctlent(zone_dochandle_t); 285 286 /* 287 * Privilege-related functions. 288 */ 289 extern int zonecfg_get_privset(priv_set_t *); 290 291 /* 292 * Higher-level routines. 293 */ 294 extern int zone_get_rootpath(char *, char *, size_t); 295 extern int zone_get_zonepath(char *, char *, size_t); 296 extern int zone_get_state(char *, zone_state_t *); 297 extern int zone_set_state(char *, zone_state_t); 298 extern char *zone_state_str(zone_state_t); 299 extern int zonecfg_get_name_by_uuid(const uuid_t, char *, size_t); 300 extern int zonecfg_get_uuid(const char *, uuid_t); 301 302 /* 303 * Iterator for configured zones. 304 */ 305 extern FILE *setzoneent(void); 306 extern char *getzoneent(FILE *); 307 extern struct zoneent *getzoneent_private(FILE *); 308 extern void endzoneent(FILE *); 309 310 /* 311 * File-system-related convenience functions. 312 */ 313 extern boolean_t zonecfg_valid_fs_type(const char *); 314 315 /* 316 * Network-related convenience functions. 317 */ 318 extern boolean_t zonecfg_same_net_address(char *, char *); 319 extern int zonecfg_valid_net_address(char *, struct lifreq *); 320 321 /* 322 * Rctl-related common functions. 323 */ 324 extern boolean_t zonecfg_is_rctl(const char *); 325 extern boolean_t zonecfg_valid_rctlname(const char *); 326 extern boolean_t zonecfg_valid_rctlblk(const rctlblk_t *); 327 extern boolean_t zonecfg_valid_rctl(const char *, const rctlblk_t *); 328 extern int zonecfg_construct_rctlblk(const struct zone_rctlvaltab *, 329 rctlblk_t *); 330 331 /* 332 * Live Upgrade support functions. Shared between ON and install gate. 333 */ 334 extern FILE *zonecfg_open_scratch(const char *, boolean_t); 335 extern int zonecfg_lock_scratch(FILE *); 336 extern void zonecfg_close_scratch(FILE *); 337 extern int zonecfg_get_scratch(FILE *, char *, size_t, char *, size_t, char *, 338 size_t); 339 extern int zonecfg_find_scratch(FILE *, const char *, const char *, char *, 340 size_t); 341 extern int zonecfg_reverse_scratch(FILE *, const char *, char *, size_t, 342 char *, size_t); 343 extern int zonecfg_add_scratch(FILE *, const char *, const char *, 344 const char *); 345 extern int zonecfg_delete_scratch(FILE *, const char *); 346 extern boolean_t zonecfg_is_scratch(const char *); 347 348 #ifdef __cplusplus 349 } 350 #endif 351 352 #endif /* _LIBZONECFG_H */ 353