xref: /onnv-gate/usr/src/common/svc/repcache_protocol.h (revision 12483:368e589460be)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55040Swesolows  * Common Development and Distribution License (the "License").
65040Swesolows  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
215040Swesolows 
220Sstevel@tonic-gate /*
23*12483SAntonello.Cruz@Sun.COM  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_REPCACHE_PROTOCOL_H
270Sstevel@tonic-gate #define	_REPCACHE_PROTOCOL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * The Repository Cache Protocol
310Sstevel@tonic-gate  * -----------------------------
320Sstevel@tonic-gate  *
330Sstevel@tonic-gate  * 1. Introduction
340Sstevel@tonic-gate  * ---------------
350Sstevel@tonic-gate  * This header file defines the private protocols between libscf(3lib) and
360Sstevel@tonic-gate  * svc.configd(1m).  There are two separate protocols:
370Sstevel@tonic-gate  *
380Sstevel@tonic-gate  * 1.	The 'global' protocol, accessible via an fattach(3C)ed door located
390Sstevel@tonic-gate  *	at REPOSITORY_DOOR_NAME.
400Sstevel@tonic-gate  *
410Sstevel@tonic-gate  * 2.	The 'client' protocol, accessible through a door created using the
420Sstevel@tonic-gate  *	global protocol, which allows access to the repository.
430Sstevel@tonic-gate  *
440Sstevel@tonic-gate  * 1.1 Design restrictions
450Sstevel@tonic-gate  * -----------------------
460Sstevel@tonic-gate  * A basic constraint of the door IPC mechanism is that there is no reliable
470Sstevel@tonic-gate  * delivery.  In particular:
480Sstevel@tonic-gate  *
490Sstevel@tonic-gate  * 1.	If libscf(3lib) recieves an EINTR from door_call(), it doesn't know
500Sstevel@tonic-gate  *      whether or not the server recieved (and is processing) its request.
510Sstevel@tonic-gate  *
520Sstevel@tonic-gate  * 2.	When svc.configd(1M) calls door_return(), the client may have already
530Sstevel@tonic-gate  *	received an EINTR, aborting its door_call().  In this case, the
540Sstevel@tonic-gate  *	returned values are dropped on the floor.
550Sstevel@tonic-gate  *
560Sstevel@tonic-gate  * The practical upshot of all of this is simple:
570Sstevel@tonic-gate  *
580Sstevel@tonic-gate  *	Every individual protocol action must be idempotent.
590Sstevel@tonic-gate  *
600Sstevel@tonic-gate  * That is, a client must be able to retry any single request multiple times,
610Sstevel@tonic-gate  * and get the correct results.
620Sstevel@tonic-gate  *
630Sstevel@tonic-gate  * 1.2. Protocol shorthand
640Sstevel@tonic-gate  * -----------------------
650Sstevel@tonic-gate  * We represent by "REQUEST(arg1, arg2) -> result, res1, [desc]" a request code
660Sstevel@tonic-gate  * of REP_PROTOCOL_REQUEST (or REPOSITORY_DOOR_REQUEST), which takes two
670Sstevel@tonic-gate  * additional arguments, arg1 and arg2, and returns a result code, res1, and
680Sstevel@tonic-gate  * a file descriptor desc.
690Sstevel@tonic-gate  *
700Sstevel@tonic-gate  * If an error occurs, the server will usually only send the result code. (a
710Sstevel@tonic-gate  * short return)
720Sstevel@tonic-gate  *
730Sstevel@tonic-gate  * Inside the protocol destription, <foo> indicates the type foo indicates.
740Sstevel@tonic-gate  *
750Sstevel@tonic-gate  * 2. The Global protocol
760Sstevel@tonic-gate  * ----------------------
770Sstevel@tonic-gate  * Everything starting with "REPOSITORY_DOOR" or "repository_door" belongs
780Sstevel@tonic-gate  * to the global protocol.
790Sstevel@tonic-gate  *
800Sstevel@tonic-gate  * 2.1. Global requests
810Sstevel@tonic-gate  * --------------------
820Sstevel@tonic-gate  *
830Sstevel@tonic-gate  * REQUEST_CONNECT(rdr_flags, ...) -> result, [new_door]
840Sstevel@tonic-gate  *	Request a new Client door.  rdr_flags determines attributes of the
850Sstevel@tonic-gate  *	connection:
860Sstevel@tonic-gate  *
870Sstevel@tonic-gate  *	    FLAG_DEBUG
880Sstevel@tonic-gate  *		Sets connection debugging flags to those in rdr_debug.
890Sstevel@tonic-gate  *
900Sstevel@tonic-gate  *	The new door is returned with DOOR_RELEASE set, so if the client does
910Sstevel@tonic-gate  *	not recieve the response, the new door will recieve an unref
920Sstevel@tonic-gate  *	notification.  This makes this request idempotent.
930Sstevel@tonic-gate  *
940Sstevel@tonic-gate  * 2.2. Global reponse codes
950Sstevel@tonic-gate  * -------------------------
960Sstevel@tonic-gate  * GLXXX: This needs to be thought through.
970Sstevel@tonic-gate  *
980Sstevel@tonic-gate  * SUCCESS
990Sstevel@tonic-gate  * FAIL_BAD_REQUEST
1000Sstevel@tonic-gate  * FAIL_VERSION_MISMATCH
1010Sstevel@tonic-gate  * FAIL_BAD_FLAG
1020Sstevel@tonic-gate  * FAIL_BAD_USER
1030Sstevel@tonic-gate  * FAIL_NO_RESOURCES
1040Sstevel@tonic-gate  *
1050Sstevel@tonic-gate  * 3. The Client protocol
1060Sstevel@tonic-gate  * ----------------------
1070Sstevel@tonic-gate  * Everything starting with "REP_PROTOCOL" or "rep_protocol" belongs to the
1080Sstevel@tonic-gate  * client protocol.
1090Sstevel@tonic-gate  *
1100Sstevel@tonic-gate  * 3.1. Techniques used
1110Sstevel@tonic-gate  * --------------------
1120Sstevel@tonic-gate  * 3.1.1. Client-controlled identifiers
1130Sstevel@tonic-gate  *
1140Sstevel@tonic-gate  * An idiom the protocol uses to lower the number of round trips is
1150Sstevel@tonic-gate  * client-controlled identifiers.  The basic idea is this:  whenever a
1160Sstevel@tonic-gate  * client wants to set up and use a piece of server state, he picks an
1170Sstevel@tonic-gate  * integer *which he knows is not in use* to identify it.  The server then
1180Sstevel@tonic-gate  * maintains per-client, per-resource id->resource maps.  This has a number
1190Sstevel@tonic-gate  * of advantages:
1200Sstevel@tonic-gate  *
1210Sstevel@tonic-gate  * 1.	Since the client allocates the identifiers, we don't need to do
1220Sstevel@tonic-gate  *	a round-trip just to allocate a number.
1230Sstevel@tonic-gate  *
1240Sstevel@tonic-gate  * 2.	Since it is the client's job to make sure identifiers don't collide,
1250Sstevel@tonic-gate  *	idempotency for setup (destroy) are simple:  If the identifier
1260Sstevel@tonic-gate  *	already exists (does not exist), we just return success.
1270Sstevel@tonic-gate  *
1280Sstevel@tonic-gate  * 3.	Since the identifiers are per-client, the design automatically
1290Sstevel@tonic-gate  *	precludes clients being able to manipulate other client's state.
1300Sstevel@tonic-gate  *
1310Sstevel@tonic-gate  * 3.1.2 Sequence numbers
1320Sstevel@tonic-gate  *
1330Sstevel@tonic-gate  * A standard way of gaining idempotency is introducing sequence numbers.
1340Sstevel@tonic-gate  * These are simply integers which get incremented at points in the protocol,
1350Sstevel@tonic-gate  * and make sure the client and server are in sync.
1360Sstevel@tonic-gate  *
1370Sstevel@tonic-gate  * In this protocol, we use sequence numbers for requests (like ITER_READ)
1380Sstevel@tonic-gate  * which are repeated, returning different data each time.  Since requests
1390Sstevel@tonic-gate  * can also be repeated due to unreliable dispatch, the client increments
1400Sstevel@tonic-gate  * the sequence number after every successful request.  This allows the server
1410Sstevel@tonic-gate  * to differentiate the two cases. (note that this means that failing
1420Sstevel@tonic-gate  * requests have no side effects and are repeatable)
1430Sstevel@tonic-gate  *
1440Sstevel@tonic-gate  * 3.2. Client abstractions
1450Sstevel@tonic-gate  * ------------------------
1460Sstevel@tonic-gate  * 3.2.1 Entities
1470Sstevel@tonic-gate  *
1480Sstevel@tonic-gate  * An "entity" is a typed register which the client can manipulate.
1490Sstevel@tonic-gate  * Entities are named in the protocol by client-controlled identifiers.
1500Sstevel@tonic-gate  * They have a fixed type for their entire lifetime, and may be in one
1510Sstevel@tonic-gate  * of two states:
1520Sstevel@tonic-gate  *
1530Sstevel@tonic-gate  * valid
1540Sstevel@tonic-gate  *	The entity has a valid value, and may be read from.  This state
1550Sstevel@tonic-gate  *	is reached by a successful write to the entity by some protocol
1560Sstevel@tonic-gate  *	step.
1570Sstevel@tonic-gate  *
1580Sstevel@tonic-gate  * invalid
1590Sstevel@tonic-gate  *	The entity does not contain a valid value.  There are a number
1600Sstevel@tonic-gate  *	of ways to reach this state:
1610Sstevel@tonic-gate  *
1620Sstevel@tonic-gate  *	1.  The entity was just created.
1630Sstevel@tonic-gate  *	2.  The underlying object that this entity refers to was destroyed.
1640Sstevel@tonic-gate  *	3.  A protocol request which would have modified this entity
1650Sstevel@tonic-gate  *	    failed.
1660Sstevel@tonic-gate  *
1670Sstevel@tonic-gate  * An entity is an element in the tree of repository data.  Every entity
1680Sstevel@tonic-gate  * (except for the most distant SCOPE) has exactly one parent.  Entities
1690Sstevel@tonic-gate  * can have multiple children of different types, restricted by its base
1700Sstevel@tonic-gate  * type.
1710Sstevel@tonic-gate  *
1720Sstevel@tonic-gate  * The ENTITY_GET call is used to get the root of the tree (the most local
1730Sstevel@tonic-gate  * scope)
1740Sstevel@tonic-gate  *
1750Sstevel@tonic-gate  * 3.2.2. The entity tree
1760Sstevel@tonic-gate  * ----------------------
1770Sstevel@tonic-gate  * The structure of a scope is as follows:
1780Sstevel@tonic-gate  *
1790Sstevel@tonic-gate  *	 _______
1800Sstevel@tonic-gate  *	| SCOPE |
1810Sstevel@tonic-gate  *	|_______|
1820Sstevel@tonic-gate  *	    \ .
1830Sstevel@tonic-gate  *	     \ .
1840Sstevel@tonic-gate  *	      \_________
1850Sstevel@tonic-gate  *	      | SERVICE |
1860Sstevel@tonic-gate  *	      |_________|
1870Sstevel@tonic-gate  *		/.    \ .
1880Sstevel@tonic-gate  *	       /.      \ .
1890Sstevel@tonic-gate  *	  ____/		\__________
1900Sstevel@tonic-gate  *	 | PG |		| INSTANCE |
1910Sstevel@tonic-gate  *	 |____|		|__________|
1920Sstevel@tonic-gate  *			  /.	 \ .
1930Sstevel@tonic-gate  *			 /.	  \ .
1940Sstevel@tonic-gate  *		    ____/	   \__________
1950Sstevel@tonic-gate  *		   | PG |	   | SNAPSHOT |
1960Sstevel@tonic-gate  *		   |____|	   |__________|
1970Sstevel@tonic-gate  *					\ .
1980Sstevel@tonic-gate  *					 \ .
1990Sstevel@tonic-gate  *					  \___________
2000Sstevel@tonic-gate  *					  | SNAPLEVEL |
2010Sstevel@tonic-gate  *					  |___________|
2020Sstevel@tonic-gate  *					     /.
2030Sstevel@tonic-gate  *					    /.
2040Sstevel@tonic-gate  *				       ____/
2050Sstevel@tonic-gate  *				      | PG |
2060Sstevel@tonic-gate  *				      |____|
2070Sstevel@tonic-gate  *
2080Sstevel@tonic-gate  * Where the dots indicate an arbitrary number (including 0) of children.
2090Sstevel@tonic-gate  *
2100Sstevel@tonic-gate  * For a given scope, the next scope (in the sense of distance) is its
2110Sstevel@tonic-gate  * TYPE_SCOPE parent.  The furthest out scope has no parent.
2120Sstevel@tonic-gate  *
2130Sstevel@tonic-gate  * 3.2.2 Iterators
2140Sstevel@tonic-gate  *
2150Sstevel@tonic-gate  * GLXXX
2160Sstevel@tonic-gate  *
2170Sstevel@tonic-gate  * 3.3. Client requests
2180Sstevel@tonic-gate  * --------------------
2190Sstevel@tonic-gate  *
2200Sstevel@tonic-gate  * CLOSE() -> result
2210Sstevel@tonic-gate  *	Closes the connection, revoking the door.  After this call completes,
2220Sstevel@tonic-gate  *	no further calls will succeed.
2230Sstevel@tonic-gate  *
2240Sstevel@tonic-gate  * ENTITY_SETUP(entity_id, type) -> result
2250Sstevel@tonic-gate  *	Sets up an entity, identified by entity_id, to identify a single
2260Sstevel@tonic-gate  *	<type>.  <type> may not be TYPE_NONE.
2270Sstevel@tonic-gate  *
2280Sstevel@tonic-gate  * ENTITY_NAME(entity_id, name_type) -> result, name
2290Sstevel@tonic-gate  *	Returns the name of entity_id.  name_type determines which type of
2300Sstevel@tonic-gate  *	name to get.
2310Sstevel@tonic-gate  *
2320Sstevel@tonic-gate  * ENTITY_PARENT_TYPE(entity_id) -> result, parent_type
2330Sstevel@tonic-gate  *	Retrieves the type of entity_id's parent
2340Sstevel@tonic-gate  *
2350Sstevel@tonic-gate  * ENTITY_GET_CHILD(entity_id, child_id, name) -> result
2360Sstevel@tonic-gate  *	Puts entity_id's child (of child_id's type) named 'name' into child_id.
2370Sstevel@tonic-gate  *
2380Sstevel@tonic-gate  * ENTITY_GET_PARENT(entity_id, out_id) -> result
2390Sstevel@tonic-gate  *	Puts entity_id's parent into out_id.
2400Sstevel@tonic-gate  *
2410Sstevel@tonic-gate  * ENTITY_GET(entity_id, number) -> result
2420Sstevel@tonic-gate  *	Makes entity_id point to a particular object.  If any error
2430Sstevel@tonic-gate  *	occurs, dest_id will be invalid.
2440Sstevel@tonic-gate  *
2450Sstevel@tonic-gate  * ENTITY_UPDATE(entity_id, changeid) -> result
2460Sstevel@tonic-gate  *	Updates the entity to pick up any new changes.
2470Sstevel@tonic-gate  *
2480Sstevel@tonic-gate  * ENTITY_CREATE_CHILD(entity_id, type, name, child_id, changeid) -> result
2490Sstevel@tonic-gate  *	Attaches the object of type /type/ in child_id as the child of
2500Sstevel@tonic-gate  *	entity_id named 'name'.
2510Sstevel@tonic-gate  *
2520Sstevel@tonic-gate  * ENTITY_CREATE_PG(entity_id, name, type, flags, child_id, changeid) -> result
2530Sstevel@tonic-gate  *	Creates a property group child of entity_id named 'name', type 'type'
2540Sstevel@tonic-gate  *	and flags 'flags', and puts the resulting object in child_id.
2550Sstevel@tonic-gate  *
2560Sstevel@tonic-gate  * ENTITY_DELETE(entity_id, changeid) -> result
2570Sstevel@tonic-gate  *	Deletes the entity represented by entity_id.
2580Sstevel@tonic-gate  *
2590Sstevel@tonic-gate  * ENTITY_RESET(entity_id) -> result
2600Sstevel@tonic-gate  *	Resets the entity.
2610Sstevel@tonic-gate  *
2620Sstevel@tonic-gate  * ENTITY_TEARDOWN(entity_id) -> result
2630Sstevel@tonic-gate  *	Destroys the entity entity_id.
2640Sstevel@tonic-gate  *
2650Sstevel@tonic-gate  * ITER_SETUP(iter_id) -> result
2660Sstevel@tonic-gate  *	Sets up an iterator id.
2670Sstevel@tonic-gate  *
2680Sstevel@tonic-gate  * ITER_START(iter_id, entity_id, itertype, flags, pattern) -> result
2690Sstevel@tonic-gate  *	Sets up an iterator, identified by iter_id, which will iterate the
2700Sstevel@tonic-gate  *	<itertype> children of entity_id whose names match 'pattern',
2710Sstevel@tonic-gate  *	with the matching controlled by flags.  Initializing an iterator
2720Sstevel@tonic-gate  *	counts as the first sequence number (1).
2730Sstevel@tonic-gate  *
2740Sstevel@tonic-gate  * ITER_READ(iter_id, sequence, entity_id) -> result
2750Sstevel@tonic-gate  *	Retrieves the next element of iterator iter_id.  Sequence starts at 2,
2760Sstevel@tonic-gate  *	and is incremented by the client after each successful iteration.
2770Sstevel@tonic-gate  *	The result is written to entity_id, which must be of the same type
2780Sstevel@tonic-gate  *	as the iterator result.  The iterator must not be iterating values.
2790Sstevel@tonic-gate  *
2800Sstevel@tonic-gate  * ITER_READ_VALUE(iter_id, sequence) -> result, type, value
2810Sstevel@tonic-gate  *	Retrieves the next value for iterator iter_id.  Sequence starts at 2,
2820Sstevel@tonic-gate  *	and is incremented by the client after each successful iteration.
2830Sstevel@tonic-gate  *	The iterator must be iterating a property's values.
2840Sstevel@tonic-gate  *
2850Sstevel@tonic-gate  * ITER_RESET(iter_id) -> result
2860Sstevel@tonic-gate  *	Throws away any accumulated state.
2870Sstevel@tonic-gate  *
2880Sstevel@tonic-gate  * ITER_TEARDOWN(iter_id) -> result
2890Sstevel@tonic-gate  *	Destroys the iterator iter_id.
2900Sstevel@tonic-gate  *
2910Sstevel@tonic-gate  * NEXT_SNAPLEVEL(entity_src, entity_dst) -> result
2920Sstevel@tonic-gate  *	If entity_src is a snapshot, set entity_dst to the first snaplevel
2930Sstevel@tonic-gate  *	in it.  If entity_src is a snaplevel, set entity_dst to the next
2940Sstevel@tonic-gate  *	snaplevel, or fail if there isn't one.
2950Sstevel@tonic-gate  *
2960Sstevel@tonic-gate  * SNAPSHOT_TAKE(entity_id, name, dest_id, flags) -> result
2970Sstevel@tonic-gate  *	Takes a snapshot of entity_id, creating snaplevels for the instance and
2980Sstevel@tonic-gate  *	its parent service.  If flags is REP_SNAPSHOT_NEW, a new snapshot named
2990Sstevel@tonic-gate  *	'name' is created as a child of entity_id, dest_id is pointed to it,
3000Sstevel@tonic-gate  *	and the new snaplevels are attached to it.  If flags is
3010Sstevel@tonic-gate  *	REP_SNAPSHOT_ATTACH, name must be empty, and the new snaplevels are
3020Sstevel@tonic-gate  *	attached to the snapshot dest_id points to.
3030Sstevel@tonic-gate  *
3040Sstevel@tonic-gate  * SNAPSHOT_TAKE_NAMED(entity_id, instname, svcname, name, dest_id) -> result
3050Sstevel@tonic-gate  *	Like SNAPSHOT_TAKE, but always acts as if REP_SNAPSHOT_NEW is
3060Sstevel@tonic-gate  *	specified, and instname and svcname override the actual service and
3070Sstevel@tonic-gate  *	instance names, respectively, written into the snaplevels.
3080Sstevel@tonic-gate  *
3090Sstevel@tonic-gate  *	Note that this is only useful for writing snapshots which will later
3100Sstevel@tonic-gate  *	be transferred to another instance (svc:/svcname:instname/)
3110Sstevel@tonic-gate  *
3120Sstevel@tonic-gate  * SNAPSHOT_ATTACH(source_id, dest_id) -> result
3130Sstevel@tonic-gate  *	The snaplevels attached to the snapshot referenced by source_id are
3140Sstevel@tonic-gate  *	attached to the snapshot dest_id is pointed at.
3150Sstevel@tonic-gate  *
3160Sstevel@tonic-gate  * PROPERTY_GET_TYPE(entity_id) -> result, value type
3170Sstevel@tonic-gate  *	Finds the value type of entity_id, which must be a property.
3180Sstevel@tonic-gate  *
3190Sstevel@tonic-gate  * PROPERTY_GET_VALUE(entity_id) -> result, type, value
3200Sstevel@tonic-gate  *	If the property contains a single value, returns it and its type.
3210Sstevel@tonic-gate  *
3220Sstevel@tonic-gate  * PROPERTYGRP_SETUP_WAIT(entity_id) -> result, [pipe fd]
3230Sstevel@tonic-gate  *	Sets up a notification for changes to the object entity_id currently
3240Sstevel@tonic-gate  *	references.  On success, returns one side of a pipe -- when there
3250Sstevel@tonic-gate  *	has been a change (or the daemon dies), the other end of the pipe will
3260Sstevel@tonic-gate  *	be closed.
3270Sstevel@tonic-gate  *
3280Sstevel@tonic-gate  *	Only one of these can be set up per client -- attempts to set up more
3290Sstevel@tonic-gate  *	than one will cause the previous one to get closed.
3300Sstevel@tonic-gate  *
3310Sstevel@tonic-gate  * PROPERTYGRP_TX_START(entity_id_tx, entity_id) -> result
3320Sstevel@tonic-gate  *	Makes entity_id_tx point to the same property group as entity_id,
3330Sstevel@tonic-gate  *	then attempts to set up entity_id_tx as a transaction on that group.
3340Sstevel@tonic-gate  *	entity_id and entity_id_tx must be distinct.  On failure, entity_id_tx
3350Sstevel@tonic-gate  *	is reset.
3360Sstevel@tonic-gate  *
3370Sstevel@tonic-gate  * PROPERTYGRP_TX_COMMIT(entity_id, data) -> result
3380Sstevel@tonic-gate  *	Gives the actual steps to follow, and attempts to commit them.
3390Sstevel@tonic-gate  *
3400Sstevel@tonic-gate  * CLIENT_ADD_NOTIFY(type, pattern) -> result
3410Sstevel@tonic-gate  *	Adds a new property group name or type pattern to the notify list
3420Sstevel@tonic-gate  *	(see CLIENT_WAIT).  If successful, takes effect immediately.
3430Sstevel@tonic-gate  *
3440Sstevel@tonic-gate  * CLIENT_WAIT(entity_id) -> result, fmri
3450Sstevel@tonic-gate  *	Waits for a change to a propertygroup that matches the patterns
3460Sstevel@tonic-gate  *	set up using CLIENT_ADD_NOTIFY, and puts the resultant propertygroup
3470Sstevel@tonic-gate  *	in entity_id.  Note that if an error occurs, you can loose
3480Sstevel@tonic-gate  *	notifications.  Either entity_id is set to a changed propertygroup,
3490Sstevel@tonic-gate  *	or fmri is a non-zero-length string identifying a deleted thing.
3500Sstevel@tonic-gate  *
3510Sstevel@tonic-gate  * BACKUP(name) -> result
3520Sstevel@tonic-gate  *	Backs up the persistant repository with a particular name.
3535777Stw21770  *
3545777Stw21770  * SET_ANNOTATION(operation, file)
3555777Stw21770  *	Set up a security audit annotation event.  operation is the name of
3565777Stw21770  *	the operation that is being annotated, and file is the file being
3575777Stw21770  *	processed.  This will be used to mark operations which comprise
3585777Stw21770  *	multiple primitive operations such as svccfg import.
3596035Sstevep  *
3606035Sstevep  * SWITCH(flag) -> result
3616035Sstevep  *	The flag is used to indicate the direction of the switch operation.
3626035Sstevep  *	When the flag is set to 'fast', move the main repository from the
3636035Sstevep  *	default location (/etc/svc) to the tmpfs locationa (/etc/svc/volatile).
3646035Sstevep  *	When it is set to 'perm', the switch is reversed.
3650Sstevel@tonic-gate  */
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate #include <door.h>
3680Sstevel@tonic-gate #include <stddef.h>
3690Sstevel@tonic-gate #include <sys/sysmacros.h>
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate #ifdef	__cplusplus
3720Sstevel@tonic-gate extern "C" {
3730Sstevel@tonic-gate #endif
3740Sstevel@tonic-gate 
3750Sstevel@tonic-gate /*
3760Sstevel@tonic-gate  * svc.configd initial protocol details
3770Sstevel@tonic-gate  */
3780Sstevel@tonic-gate #define	REPOSITORY_DOOR_BASEVER	(('R' << 24) | ('e' << 16) | ('p' << 8))
3790Sstevel@tonic-gate #define	REPOSITORY_DOOR_NAME	"/etc/svc/volatile/repository_door"
3800Sstevel@tonic-gate #define	REPOSITORY_DOOR_COOKIE	((void *)REPOSITORY_DOOR_BASEVER)
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate #define	REPOSITORY_BOOT_BACKUP	((const char *)"boot")
3830Sstevel@tonic-gate 
3840Sstevel@tonic-gate /*
3850Sstevel@tonic-gate  * This value should be incremented any time the protocol changes.  When in
3860Sstevel@tonic-gate  * doubt, bump it.
3870Sstevel@tonic-gate  */
3886035Sstevep #define	REPOSITORY_DOOR_VERSION			(21 + REPOSITORY_DOOR_BASEVER)
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate /*
3910Sstevel@tonic-gate  * flags for rdr_flags
3920Sstevel@tonic-gate  */
3930Sstevel@tonic-gate #define	REPOSITORY_DOOR_FLAG_DEBUG		0x00000001	/* rdr_debug */
3940Sstevel@tonic-gate 
3950Sstevel@tonic-gate #define	REPOSITORY_DOOR_FLAG_ALL		0x00000001	/* all flags */
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate /*
3980Sstevel@tonic-gate  * Request IDs
3990Sstevel@tonic-gate  */
4000Sstevel@tonic-gate enum repository_door_requestid {
4010Sstevel@tonic-gate 	REPOSITORY_DOOR_REQUEST_CONNECT = (('M' << 8) | 1)
4020Sstevel@tonic-gate };
4030Sstevel@tonic-gate 
4040Sstevel@tonic-gate enum repository_door_statusid {
4050Sstevel@tonic-gate 	REPOSITORY_DOOR_SUCCESS			= 0,
4060Sstevel@tonic-gate 	REPOSITORY_DOOR_FAIL_BAD_REQUEST	= 1,
4070Sstevel@tonic-gate 	REPOSITORY_DOOR_FAIL_VERSION_MISMATCH	= 2,
4080Sstevel@tonic-gate 	REPOSITORY_DOOR_FAIL_BAD_FLAG		= 3,
4090Sstevel@tonic-gate 	REPOSITORY_DOOR_FAIL_NO_RESOURCES	= 4,
4100Sstevel@tonic-gate 	REPOSITORY_DOOR_FAIL_PERMISSION_DENIED	= 5
4110Sstevel@tonic-gate };
4120Sstevel@tonic-gate 
4130Sstevel@tonic-gate /*
4140Sstevel@tonic-gate  * You may only add elements to the end of this structure.
4150Sstevel@tonic-gate  */
4160Sstevel@tonic-gate typedef struct repository_door_request {
4170Sstevel@tonic-gate 	uint32_t rdr_version;			/* must be first element */
4180Sstevel@tonic-gate 	enum repository_door_requestid rdr_request;
4190Sstevel@tonic-gate 	uint32_t rdr_flags;
4200Sstevel@tonic-gate 	uint32_t rdr_debug;
4210Sstevel@tonic-gate } repository_door_request_t;
4220Sstevel@tonic-gate 
4230Sstevel@tonic-gate typedef struct repository_door_response {
4240Sstevel@tonic-gate 	enum repository_door_statusid rdr_status;
4250Sstevel@tonic-gate } repository_door_response_t;
4260Sstevel@tonic-gate 
4270Sstevel@tonic-gate /*
4280Sstevel@tonic-gate  * Client interface.  Used on doors returned by REQUEST_CONNECT
4290Sstevel@tonic-gate  */
4300Sstevel@tonic-gate 
4310Sstevel@tonic-gate #define	REP_PROTOCOL_NAME_LEN		120	/* maximum name length */
4320Sstevel@tonic-gate #define	REP_PROTOCOL_VALUE_LEN		4096	/* maximum value length */
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate #define	REP_PROTOCOL_FMRI_LEN		(6 * REP_PROTOCOL_NAME_LEN)
4350Sstevel@tonic-gate 
4360Sstevel@tonic-gate #define	REP_PROTOCOL_BASE		('C' << 8)
4370Sstevel@tonic-gate 
4380Sstevel@tonic-gate /*
4390Sstevel@tonic-gate  * Request codes
4400Sstevel@tonic-gate  */
4410Sstevel@tonic-gate enum rep_protocol_requestid {
4420Sstevel@tonic-gate 	REP_PROTOCOL_CLOSE		= REP_PROTOCOL_BASE,
4430Sstevel@tonic-gate 
4440Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_SETUP,
4450Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_NAME,
4460Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_PARENT_TYPE,
4470Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_GET_CHILD,
4480Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_GET_PARENT,
4490Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_GET,
4500Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_UPDATE,
4510Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_CREATE_CHILD,
4520Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_CREATE_PG,
4530Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_DELETE,
4540Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_RESET,
4550Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_TEARDOWN,
4560Sstevel@tonic-gate 
4570Sstevel@tonic-gate 	REP_PROTOCOL_ITER_SETUP,
4580Sstevel@tonic-gate 	REP_PROTOCOL_ITER_START,
4590Sstevel@tonic-gate 	REP_PROTOCOL_ITER_READ,
4600Sstevel@tonic-gate 	REP_PROTOCOL_ITER_READ_VALUE,
4610Sstevel@tonic-gate 	REP_PROTOCOL_ITER_RESET,
4620Sstevel@tonic-gate 	REP_PROTOCOL_ITER_TEARDOWN,
4630Sstevel@tonic-gate 
4640Sstevel@tonic-gate 	REP_PROTOCOL_NEXT_SNAPLEVEL,
4650Sstevel@tonic-gate 
4660Sstevel@tonic-gate 	REP_PROTOCOL_SNAPSHOT_TAKE,
4670Sstevel@tonic-gate 	REP_PROTOCOL_SNAPSHOT_TAKE_NAMED,
4680Sstevel@tonic-gate 	REP_PROTOCOL_SNAPSHOT_ATTACH,
4690Sstevel@tonic-gate 
4700Sstevel@tonic-gate 	REP_PROTOCOL_PROPERTY_GET_TYPE,
4710Sstevel@tonic-gate 	REP_PROTOCOL_PROPERTY_GET_VALUE,
4720Sstevel@tonic-gate 
4730Sstevel@tonic-gate 	REP_PROTOCOL_PROPERTYGRP_SETUP_WAIT,
4740Sstevel@tonic-gate 	REP_PROTOCOL_PROPERTYGRP_TX_START,
4750Sstevel@tonic-gate 	REP_PROTOCOL_PROPERTYGRP_TX_COMMIT,
4760Sstevel@tonic-gate 
4770Sstevel@tonic-gate 	REP_PROTOCOL_CLIENT_ADD_NOTIFY,
4780Sstevel@tonic-gate 	REP_PROTOCOL_CLIENT_WAIT,
4790Sstevel@tonic-gate 
4800Sstevel@tonic-gate 	REP_PROTOCOL_BACKUP,
4810Sstevel@tonic-gate 
4825777Stw21770 	REP_PROTOCOL_SET_AUDIT_ANNOTATION,
4835777Stw21770 
4846035Sstevep 	REP_PROTOCOL_SWITCH,
4856035Sstevep 
4860Sstevel@tonic-gate 	REP_PROTOCOL_MAX_REQUEST
4870Sstevel@tonic-gate };
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate /*
4900Sstevel@tonic-gate  * Response codes.  These are returned to the client, and the errors are
4910Sstevel@tonic-gate  * translated into scf_error_t's by libscf (see proto_error()).
4920Sstevel@tonic-gate  */
4930Sstevel@tonic-gate typedef int32_t rep_protocol_responseid_t;
4940Sstevel@tonic-gate enum rep_protocol_responseid {
4950Sstevel@tonic-gate 	REP_PROTOCOL_SUCCESS =			0,
4960Sstevel@tonic-gate 	/* iterators: No more values. */
4970Sstevel@tonic-gate 	REP_PROTOCOL_DONE =			1,
4980Sstevel@tonic-gate 
4990Sstevel@tonic-gate 	/* Request from client was malformed. */
5000Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_BAD_REQUEST =		-1,
5010Sstevel@tonic-gate 	/* Prerequisite call has not been made. */
5020Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_MISORDERED =		-2,
5030Sstevel@tonic-gate 	/* Register for ID has not been created. */
5040Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_UNKNOWN_ID =		-3,
5050Sstevel@tonic-gate 	/* Out of memory or other resource. */
5060Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_NO_RESOURCES =	-4,
5070Sstevel@tonic-gate 	/* Type argument is invalid. */
5080Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_INVALID_TYPE =	-5,
5090Sstevel@tonic-gate 	/* Requested object does not exist. */
5100Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_NOT_FOUND =		-6,
5110Sstevel@tonic-gate 	/* Register for given ID does not point to an object. */
5120Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_NOT_SET =		-7,
5130Sstevel@tonic-gate 
5140Sstevel@tonic-gate 	/* Requested name is longer than supplied buffer. */
5150Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_TRUNCATED =		-8,
5160Sstevel@tonic-gate 	/* Operation requires different type. */
5170Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_TYPE_MISMATCH =	-9,
5180Sstevel@tonic-gate 
5190Sstevel@tonic-gate 	/* Changeable object has been changed since last update. */
5200Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_NOT_LATEST =		-10,
5210Sstevel@tonic-gate 	/* Creation failed because object with given name exists. */
5220Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_EXISTS =		-11,
5230Sstevel@tonic-gate 	/* Transaction is invalid. */
5240Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_BAD_TX =		-12,
5250Sstevel@tonic-gate 	/* Operation is not applicable to indicated object. */
5260Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_NOT_APPLICABLE =	-13,
5270Sstevel@tonic-gate 	/* Two IDs for operation were unexpectedly equal. */
5280Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_DUPLICATE_ID =	-14,
5290Sstevel@tonic-gate 
5300Sstevel@tonic-gate 	/* Permission denied. */
5310Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_PERMISSION_DENIED =	-15,
5320Sstevel@tonic-gate 	/* Backend does not exist or otherwise refused access. */
5330Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_BACKEND_ACCESS =	-16,
5340Sstevel@tonic-gate 	/* Backend is read-only. */
5350Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_BACKEND_READONLY =	-17,
5360Sstevel@tonic-gate 
5370Sstevel@tonic-gate 	/* Object has been deleted. */
5380Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_DELETED =		-18,
5390Sstevel@tonic-gate 
5400Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_UNKNOWN =		-0xfd
5410Sstevel@tonic-gate };
5420Sstevel@tonic-gate 
5430Sstevel@tonic-gate /*
5440Sstevel@tonic-gate  * Types
5450Sstevel@tonic-gate  */
5460Sstevel@tonic-gate typedef enum rep_protocol_entity {
5470Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_NONE,
5480Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_SCOPE,
5490Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_SERVICE,
5500Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_INSTANCE,
5510Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_SNAPSHOT,
5520Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_SNAPLEVEL,
5530Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_PROPERTYGRP,
5540Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_CPROPERTYGRP,	/* "composed" property group */
5550Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_PROPERTY,
5560Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_VALUE,
5570Sstevel@tonic-gate 
5580Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_MAX
5590Sstevel@tonic-gate } rep_protocol_entity_t;
5600Sstevel@tonic-gate 
5610Sstevel@tonic-gate typedef enum rep_protocol_value_type {
5620Sstevel@tonic-gate 	REP_PROTOCOL_TYPE_INVALID	= '\0',
5630Sstevel@tonic-gate 	REP_PROTOCOL_TYPE_BOOLEAN	= 'b',
5640Sstevel@tonic-gate 	REP_PROTOCOL_TYPE_COUNT		= 'c',
5650Sstevel@tonic-gate 	REP_PROTOCOL_TYPE_INTEGER	= 'i',
5660Sstevel@tonic-gate 	REP_PROTOCOL_TYPE_TIME		= 't',
5670Sstevel@tonic-gate 	REP_PROTOCOL_TYPE_STRING	= 's',
5680Sstevel@tonic-gate 	REP_PROTOCOL_TYPE_OPAQUE	= 'o',
5690Sstevel@tonic-gate 
5700Sstevel@tonic-gate 	REP_PROTOCOL_SUBTYPE_USTRING	= REP_PROTOCOL_TYPE_STRING|('u' << 8),
5710Sstevel@tonic-gate 	REP_PROTOCOL_SUBTYPE_URI	= REP_PROTOCOL_TYPE_STRING|('U' << 8),
5720Sstevel@tonic-gate 	REP_PROTOCOL_SUBTYPE_FMRI	= REP_PROTOCOL_TYPE_STRING|('f' << 8),
5730Sstevel@tonic-gate 
5740Sstevel@tonic-gate 	REP_PROTOCOL_SUBTYPE_HOST	= REP_PROTOCOL_TYPE_STRING|('h' << 8),
5750Sstevel@tonic-gate 	REP_PROTOCOL_SUBTYPE_HOSTNAME	= REP_PROTOCOL_TYPE_STRING|('N' << 8),
576*12483SAntonello.Cruz@Sun.COM 	REP_PROTOCOL_SUBTYPE_NETADDR	= REP_PROTOCOL_TYPE_STRING|('n' << 8),
5770Sstevel@tonic-gate 	REP_PROTOCOL_SUBTYPE_NETADDR_V4	= REP_PROTOCOL_TYPE_STRING|('4' << 8),
5780Sstevel@tonic-gate 	REP_PROTOCOL_SUBTYPE_NETADDR_V6	= REP_PROTOCOL_TYPE_STRING|('6' << 8)
5790Sstevel@tonic-gate } rep_protocol_value_type_t;
5800Sstevel@tonic-gate 
5810Sstevel@tonic-gate 
5820Sstevel@tonic-gate #define	REP_PROTOCOL_BASE_TYPE(t)	((t) & 0x00ff)
5830Sstevel@tonic-gate #define	REP_PROTOCOL_SUBTYPE(t)		(((t) & 0xff00) >> 8)
5840Sstevel@tonic-gate 
5850Sstevel@tonic-gate /*
5860Sstevel@tonic-gate  * Request structures
5870Sstevel@tonic-gate  */
5880Sstevel@tonic-gate typedef struct rep_protocol_request {
5890Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;
5900Sstevel@tonic-gate } rep_protocol_request_t;
5910Sstevel@tonic-gate 
5920Sstevel@tonic-gate struct rep_protocol_iter_request {
5930Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;
5940Sstevel@tonic-gate 	uint32_t rpr_iterid;
5950Sstevel@tonic-gate };
5960Sstevel@tonic-gate 
5970Sstevel@tonic-gate struct rep_protocol_iter_start {
5980Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ITER_START */
5990Sstevel@tonic-gate 	uint32_t rpr_iterid;
6000Sstevel@tonic-gate 
6010Sstevel@tonic-gate 	uint32_t rpr_entity;
6020Sstevel@tonic-gate 	uint32_t rpr_itertype;
6030Sstevel@tonic-gate 	uint32_t rpr_flags;
6040Sstevel@tonic-gate 	char	rpr_pattern[REP_PROTOCOL_NAME_LEN];
6050Sstevel@tonic-gate };
6060Sstevel@tonic-gate #define	RP_ITER_START_ALL	0x00000001	/* ignore pattern, match all */
6070Sstevel@tonic-gate #define	RP_ITER_START_EXACT	0x00000002	/* exact match with pattern */
6080Sstevel@tonic-gate #define	RP_ITER_START_PGTYPE	0x00000003	/* exact match pg type */
6090Sstevel@tonic-gate #define	RP_ITER_START_FILT_MASK	0x00000003
6100Sstevel@tonic-gate #define	RP_ITER_START_COMPOSED	0x00000004	/* composed */
6110Sstevel@tonic-gate 
6120Sstevel@tonic-gate struct rep_protocol_iter_read {
6130Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ITER_READ */
6140Sstevel@tonic-gate 	uint32_t rpr_iterid;
6150Sstevel@tonic-gate 	uint32_t rpr_sequence;		/* client increments upon success */
6160Sstevel@tonic-gate 	uint32_t rpr_entityid;		/* entity to write result to */
6170Sstevel@tonic-gate };
6180Sstevel@tonic-gate 
6190Sstevel@tonic-gate struct rep_protocol_iter_read_value {
6200Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ITER_READ_VALUE */
6210Sstevel@tonic-gate 	uint32_t rpr_iterid;
6220Sstevel@tonic-gate 	uint32_t rpr_sequence;		/* client increments upon success */
6230Sstevel@tonic-gate };
6240Sstevel@tonic-gate 
6250Sstevel@tonic-gate struct rep_protocol_entity_setup {
6260Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_SETUP */
6270Sstevel@tonic-gate 	uint32_t rpr_entityid;
6280Sstevel@tonic-gate 	uint32_t rpr_entitytype;
6290Sstevel@tonic-gate };
6300Sstevel@tonic-gate 
6310Sstevel@tonic-gate struct rep_protocol_entity_name {
6320Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_NAME */
6330Sstevel@tonic-gate 	uint32_t rpr_entityid;
6340Sstevel@tonic-gate 	uint32_t rpr_answertype;
6350Sstevel@tonic-gate };
6360Sstevel@tonic-gate #define	RP_ENTITY_NAME_NAME			0
6370Sstevel@tonic-gate #define	RP_ENTITY_NAME_PGTYPE			1
6380Sstevel@tonic-gate #define	RP_ENTITY_NAME_PGFLAGS			2
6390Sstevel@tonic-gate #define	RP_ENTITY_NAME_SNAPLEVEL_SCOPE		3
6400Sstevel@tonic-gate #define	RP_ENTITY_NAME_SNAPLEVEL_SERVICE	4
6410Sstevel@tonic-gate #define	RP_ENTITY_NAME_SNAPLEVEL_INSTANCE	5
6425040Swesolows #define	RP_ENTITY_NAME_PGREADPROT		6
6430Sstevel@tonic-gate 
6440Sstevel@tonic-gate struct rep_protocol_entity_update {
6450Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_UPDATE */
6460Sstevel@tonic-gate 	uint32_t rpr_entityid;
6470Sstevel@tonic-gate 	uint32_t rpr_changeid;
6480Sstevel@tonic-gate };
6490Sstevel@tonic-gate 
6500Sstevel@tonic-gate struct rep_protocol_entity_parent_type {
6510Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_PARENT_TYPE */
6520Sstevel@tonic-gate 	uint32_t rpr_entityid;
6530Sstevel@tonic-gate };
6540Sstevel@tonic-gate 
6550Sstevel@tonic-gate struct rep_protocol_entity_parent {
6560Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_GET_PARENT */
6570Sstevel@tonic-gate 	uint32_t rpr_entityid;
6580Sstevel@tonic-gate 	uint32_t rpr_outid;
6590Sstevel@tonic-gate };
6600Sstevel@tonic-gate 
6610Sstevel@tonic-gate struct rep_protocol_entity_get {
6620Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_SET */
6630Sstevel@tonic-gate 	uint32_t rpr_entityid;
6640Sstevel@tonic-gate 	uint32_t rpr_object;
6650Sstevel@tonic-gate };
6660Sstevel@tonic-gate #define	RP_ENTITY_GET_INVALIDATE	1
6670Sstevel@tonic-gate #define	RP_ENTITY_GET_MOST_LOCAL_SCOPE	2
6680Sstevel@tonic-gate 
6690Sstevel@tonic-gate struct rep_protocol_entity_create_child {
6700Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request; /* ENTITY_CREATE_CHILD */
6710Sstevel@tonic-gate 	uint32_t rpr_entityid;
6720Sstevel@tonic-gate 	uint32_t rpr_childtype;
6730Sstevel@tonic-gate 	uint32_t rpr_childid;
6740Sstevel@tonic-gate 	uint32_t rpr_changeid;
6750Sstevel@tonic-gate 	char	rpr_name[REP_PROTOCOL_NAME_LEN];
6760Sstevel@tonic-gate };
6770Sstevel@tonic-gate 
6780Sstevel@tonic-gate struct rep_protocol_entity_create_pg {
6790Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request; /* ENTITY_CREATE_PG */
6800Sstevel@tonic-gate 	uint32_t rpr_entityid;
6810Sstevel@tonic-gate 	uint32_t rpr_childtype;
6820Sstevel@tonic-gate 	uint32_t rpr_childid;
6830Sstevel@tonic-gate 	uint32_t rpr_changeid;
6840Sstevel@tonic-gate 	char	rpr_name[REP_PROTOCOL_NAME_LEN];
6850Sstevel@tonic-gate 	char	rpr_type[REP_PROTOCOL_NAME_LEN];
6860Sstevel@tonic-gate 	uint32_t rpr_flags;
6870Sstevel@tonic-gate };
6880Sstevel@tonic-gate 
6890Sstevel@tonic-gate struct rep_protocol_entity_get_child {
6900Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_GET_CHILD */
6910Sstevel@tonic-gate 	uint32_t rpr_entityid;
6920Sstevel@tonic-gate 	uint32_t rpr_childid;
6930Sstevel@tonic-gate 	char	rpr_name[REP_PROTOCOL_NAME_LEN];
6940Sstevel@tonic-gate };
6950Sstevel@tonic-gate 
6960Sstevel@tonic-gate struct rep_protocol_entity_delete {
6970Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request; /* ENTITY_DELETE_CHILD */
6980Sstevel@tonic-gate 	uint32_t rpr_entityid;
6990Sstevel@tonic-gate 	uint32_t rpr_changeid;
7000Sstevel@tonic-gate };
7010Sstevel@tonic-gate 
7020Sstevel@tonic-gate struct rep_protocol_entity_reset {
7030Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_NAME */
7040Sstevel@tonic-gate 	uint32_t rpr_entityid;
7050Sstevel@tonic-gate };
7060Sstevel@tonic-gate 
7070Sstevel@tonic-gate struct rep_protocol_entity_request {
7080Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_NAME */
7090Sstevel@tonic-gate 	uint32_t rpr_entityid;
7100Sstevel@tonic-gate };
7110Sstevel@tonic-gate 
7120Sstevel@tonic-gate struct rep_protocol_entity_teardown {
7130Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_TEARDOWN */
7140Sstevel@tonic-gate 	uint32_t rpr_entityid;
7150Sstevel@tonic-gate };
7160Sstevel@tonic-gate 
7170Sstevel@tonic-gate struct rep_protocol_entity_pair {
7180Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* NEXT_SNAPLEVEL */
7190Sstevel@tonic-gate 	uint32_t rpr_entity_src;
7200Sstevel@tonic-gate 	uint32_t rpr_entity_dst;
7210Sstevel@tonic-gate };
7220Sstevel@tonic-gate 
7230Sstevel@tonic-gate struct rep_protocol_transaction_start {
7240Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* TX_SETUP */
7250Sstevel@tonic-gate 	uint32_t rpr_entityid_tx;		/* property group tx entity */
7260Sstevel@tonic-gate 	uint32_t rpr_entityid;			/* property group entity */
7270Sstevel@tonic-gate };
7280Sstevel@tonic-gate 
7290Sstevel@tonic-gate struct rep_protocol_transaction_commit {
7300Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request; /* TX_COMMIT */
7310Sstevel@tonic-gate 	uint32_t rpr_entityid;
7320Sstevel@tonic-gate 	uint32_t rpr_size;			/* size of entire structure */
7330Sstevel@tonic-gate 	uint8_t rpr_cmd[1];
7340Sstevel@tonic-gate };
7350Sstevel@tonic-gate 
7360Sstevel@tonic-gate #define	REP_PROTOCOL_TRANSACTION_COMMIT_SIZE(sz) \
7370Sstevel@tonic-gate 	    (offsetof(struct rep_protocol_transaction_commit, rpr_cmd[sz]))
7380Sstevel@tonic-gate 
7390Sstevel@tonic-gate #define	REP_PROTOCOL_TRANSACTION_COMMIT_MIN_SIZE \
7400Sstevel@tonic-gate 	    REP_PROTOCOL_TRANSACTION_COMMIT_SIZE(0)
7410Sstevel@tonic-gate 
7420Sstevel@tonic-gate enum rep_protocol_transaction_action {
7430Sstevel@tonic-gate 	REP_PROTOCOL_TX_ENTRY_INVALID,	/* N/A */
7440Sstevel@tonic-gate 	REP_PROTOCOL_TX_ENTRY_NEW,	/* new property */
7450Sstevel@tonic-gate 	REP_PROTOCOL_TX_ENTRY_CLEAR,	/* clear old property */
7460Sstevel@tonic-gate 	REP_PROTOCOL_TX_ENTRY_REPLACE,	/* change type of old property */
7470Sstevel@tonic-gate 	REP_PROTOCOL_TX_ENTRY_DELETE	/* delete property (no values) */
7480Sstevel@tonic-gate };
7490Sstevel@tonic-gate 
7500Sstevel@tonic-gate struct rep_protocol_transaction_cmd {
7510Sstevel@tonic-gate 	enum	rep_protocol_transaction_action rptc_action;
7520Sstevel@tonic-gate 	uint32_t rptc_type;
7530Sstevel@tonic-gate 	uint32_t rptc_size;		/* size of entire structure */
7540Sstevel@tonic-gate 	uint32_t rptc_name_len;
7550Sstevel@tonic-gate 	uint8_t	rptc_data[1];
7560Sstevel@tonic-gate };
7570Sstevel@tonic-gate 
7580Sstevel@tonic-gate #define	REP_PROTOCOL_TRANSACTION_CMD_SIZE(sz) \
7590Sstevel@tonic-gate 	    (offsetof(struct rep_protocol_transaction_cmd, rptc_data[sz]))
7600Sstevel@tonic-gate 
7610Sstevel@tonic-gate #define	REP_PROTOCOL_TRANSACTION_CMD_MIN_SIZE \
7620Sstevel@tonic-gate 	    REP_PROTOCOL_TRANSACTION_CMD_SIZE(0)
7630Sstevel@tonic-gate 
7640Sstevel@tonic-gate #define	TX_SIZE(x)	P2ROUNDUP((x), sizeof (uint32_t))
7650Sstevel@tonic-gate 
7660Sstevel@tonic-gate struct rep_protocol_transaction_request {
7670Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request; /* SETUP, ABORT or TEARDOWN */
7680Sstevel@tonic-gate 	uint32_t rpr_txid;
7690Sstevel@tonic-gate };
7700Sstevel@tonic-gate 
7710Sstevel@tonic-gate struct rep_protocol_property_request {
7720Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;
7730Sstevel@tonic-gate 	uint32_t rpr_entityid;
7740Sstevel@tonic-gate };
7750Sstevel@tonic-gate 
7760Sstevel@tonic-gate struct rep_protocol_propertygrp_request {
7770Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;
7780Sstevel@tonic-gate 	uint32_t rpr_entityid;
7790Sstevel@tonic-gate };
7800Sstevel@tonic-gate 
7810Sstevel@tonic-gate struct rep_protocol_notify_request {
7820Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;
7830Sstevel@tonic-gate 	uint32_t rpr_type;
7840Sstevel@tonic-gate 	char	rpr_pattern[REP_PROTOCOL_NAME_LEN];
7850Sstevel@tonic-gate };
7860Sstevel@tonic-gate #define	REP_PROTOCOL_NOTIFY_PGNAME 1
7870Sstevel@tonic-gate #define	REP_PROTOCOL_NOTIFY_PGTYPE 2
7880Sstevel@tonic-gate 
7890Sstevel@tonic-gate struct rep_protocol_wait_request {
7900Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;
7910Sstevel@tonic-gate 	uint32_t rpr_entityid;
7920Sstevel@tonic-gate };
7930Sstevel@tonic-gate 
7940Sstevel@tonic-gate struct rep_protocol_snapshot_take {
7950Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* SNAPSHOT_TAKE */
7960Sstevel@tonic-gate 	uint32_t rpr_entityid_src;
7970Sstevel@tonic-gate 	uint32_t rpr_entityid_dest;
7980Sstevel@tonic-gate 	int	rpr_flags;
7990Sstevel@tonic-gate 	char	rpr_name[REP_PROTOCOL_NAME_LEN];
8000Sstevel@tonic-gate };
8010Sstevel@tonic-gate #define	REP_SNAPSHOT_NEW	0x00000001
8020Sstevel@tonic-gate #define	REP_SNAPSHOT_ATTACH	0x00000002
8030Sstevel@tonic-gate 
8040Sstevel@tonic-gate struct rep_protocol_snapshot_take_named {
8050Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request; /* SNAPSHOT_TAKE_NAMED */
8060Sstevel@tonic-gate 	uint32_t rpr_entityid_src;
8070Sstevel@tonic-gate 	uint32_t rpr_entityid_dest;
8080Sstevel@tonic-gate 	char	rpr_svcname[REP_PROTOCOL_NAME_LEN];
8090Sstevel@tonic-gate 	char	rpr_instname[REP_PROTOCOL_NAME_LEN];
8100Sstevel@tonic-gate 	char	rpr_name[REP_PROTOCOL_NAME_LEN];
8110Sstevel@tonic-gate };
8120Sstevel@tonic-gate 
8130Sstevel@tonic-gate struct rep_protocol_snapshot_attach {
8140Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* SNAPSHOT_ATTACH */
8150Sstevel@tonic-gate 	uint32_t rpr_entityid_src;
8160Sstevel@tonic-gate 	uint32_t rpr_entityid_dest;
8170Sstevel@tonic-gate };
8180Sstevel@tonic-gate 
8190Sstevel@tonic-gate struct rep_protocol_backup_request {
8200Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* BACKUP */
8210Sstevel@tonic-gate 	uint32_t rpr_changeid;
8220Sstevel@tonic-gate 	char rpr_name[REP_PROTOCOL_NAME_LEN];
8230Sstevel@tonic-gate };
8240Sstevel@tonic-gate 
8255777Stw21770 struct rep_protocol_annotation {
8265777Stw21770 	enum rep_protocol_requestid rpr_request;	/* SET_ANNOTATION */
8275777Stw21770 	char rpr_operation[REP_PROTOCOL_NAME_LEN];
8285777Stw21770 	char rpr_file[MAXPATHLEN];
8295777Stw21770 };
8305777Stw21770 
8316035Sstevep struct rep_protocol_switch_request {
8326035Sstevep 	enum rep_protocol_requestid rpr_request;	/* SWITCH */
8336035Sstevep 	uint32_t rpr_changeid;
8346035Sstevep 	int rpr_flag;
8356035Sstevep };
8366035Sstevep 
8370Sstevel@tonic-gate /*
8380Sstevel@tonic-gate  * Response structures
8390Sstevel@tonic-gate  */
8400Sstevel@tonic-gate typedef struct rep_protocol_response {
8410Sstevel@tonic-gate 	rep_protocol_responseid_t rpr_response;
8420Sstevel@tonic-gate } rep_protocol_response_t;
8430Sstevel@tonic-gate 
8440Sstevel@tonic-gate struct rep_protocol_integer_response {
8450Sstevel@tonic-gate 	rep_protocol_responseid_t rpr_response;
8460Sstevel@tonic-gate 	uint32_t rpr_value;
8470Sstevel@tonic-gate };
8480Sstevel@tonic-gate 
8490Sstevel@tonic-gate struct rep_protocol_name_response {	/* response to ENTITY_NAME */
8500Sstevel@tonic-gate 	rep_protocol_responseid_t rpr_response;
8510Sstevel@tonic-gate 	char rpr_name[REP_PROTOCOL_NAME_LEN];
8520Sstevel@tonic-gate };
8530Sstevel@tonic-gate 
8540Sstevel@tonic-gate struct rep_protocol_fmri_response {
8550Sstevel@tonic-gate 	rep_protocol_responseid_t rpr_response;
8560Sstevel@tonic-gate 	char rpr_fmri[REP_PROTOCOL_FMRI_LEN];
8570Sstevel@tonic-gate };
8580Sstevel@tonic-gate 
8590Sstevel@tonic-gate struct rep_protocol_value_response {
8600Sstevel@tonic-gate 	rep_protocol_responseid_t rpr_response;
8610Sstevel@tonic-gate 	rep_protocol_value_type_t rpr_type;
8620Sstevel@tonic-gate 	char			rpr_value[2 * REP_PROTOCOL_VALUE_LEN + 1];
8630Sstevel@tonic-gate };
8640Sstevel@tonic-gate 
8650Sstevel@tonic-gate #ifdef	__cplusplus
8660Sstevel@tonic-gate }
8670Sstevel@tonic-gate #endif
8680Sstevel@tonic-gate 
8690Sstevel@tonic-gate #endif	/* _REPCACHE_PROTOCOL_H */
870