xref: /titanic_50/usr/src/common/svc/repcache_protocol.h (revision 5b7f77ad52bf657ba49d64d16f527e958d0fb820)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53eae19d9Swesolows  * Common Development and Distribution License (the "License").
63eae19d9Swesolows  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
213eae19d9Swesolows 
227c478bd9Sstevel@tonic-gate /*
23*5b7f77adStw21770  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_REPCACHE_PROTOCOL_H
287c478bd9Sstevel@tonic-gate #define	_REPCACHE_PROTOCOL_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * The Repository Cache Protocol
347c478bd9Sstevel@tonic-gate  * -----------------------------
357c478bd9Sstevel@tonic-gate  *
367c478bd9Sstevel@tonic-gate  * 1. Introduction
377c478bd9Sstevel@tonic-gate  * ---------------
387c478bd9Sstevel@tonic-gate  * This header file defines the private protocols between libscf(3lib) and
397c478bd9Sstevel@tonic-gate  * svc.configd(1m).  There are two separate protocols:
407c478bd9Sstevel@tonic-gate  *
417c478bd9Sstevel@tonic-gate  * 1.	The 'global' protocol, accessible via an fattach(3C)ed door located
427c478bd9Sstevel@tonic-gate  *	at REPOSITORY_DOOR_NAME.
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  * 2.	The 'client' protocol, accessible through a door created using the
457c478bd9Sstevel@tonic-gate  *	global protocol, which allows access to the repository.
467c478bd9Sstevel@tonic-gate  *
477c478bd9Sstevel@tonic-gate  * 1.1 Design restrictions
487c478bd9Sstevel@tonic-gate  * -----------------------
497c478bd9Sstevel@tonic-gate  * A basic constraint of the door IPC mechanism is that there is no reliable
507c478bd9Sstevel@tonic-gate  * delivery.  In particular:
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * 1.	If libscf(3lib) recieves an EINTR from door_call(), it doesn't know
537c478bd9Sstevel@tonic-gate  *      whether or not the server recieved (and is processing) its request.
547c478bd9Sstevel@tonic-gate  *
557c478bd9Sstevel@tonic-gate  * 2.	When svc.configd(1M) calls door_return(), the client may have already
567c478bd9Sstevel@tonic-gate  *	received an EINTR, aborting its door_call().  In this case, the
577c478bd9Sstevel@tonic-gate  *	returned values are dropped on the floor.
587c478bd9Sstevel@tonic-gate  *
597c478bd9Sstevel@tonic-gate  * The practical upshot of all of this is simple:
607c478bd9Sstevel@tonic-gate  *
617c478bd9Sstevel@tonic-gate  *	Every individual protocol action must be idempotent.
627c478bd9Sstevel@tonic-gate  *
637c478bd9Sstevel@tonic-gate  * That is, a client must be able to retry any single request multiple times,
647c478bd9Sstevel@tonic-gate  * and get the correct results.
657c478bd9Sstevel@tonic-gate  *
667c478bd9Sstevel@tonic-gate  * 1.2. Protocol shorthand
677c478bd9Sstevel@tonic-gate  * -----------------------
687c478bd9Sstevel@tonic-gate  * We represent by "REQUEST(arg1, arg2) -> result, res1, [desc]" a request code
697c478bd9Sstevel@tonic-gate  * of REP_PROTOCOL_REQUEST (or REPOSITORY_DOOR_REQUEST), which takes two
707c478bd9Sstevel@tonic-gate  * additional arguments, arg1 and arg2, and returns a result code, res1, and
717c478bd9Sstevel@tonic-gate  * a file descriptor desc.
727c478bd9Sstevel@tonic-gate  *
737c478bd9Sstevel@tonic-gate  * If an error occurs, the server will usually only send the result code. (a
747c478bd9Sstevel@tonic-gate  * short return)
757c478bd9Sstevel@tonic-gate  *
767c478bd9Sstevel@tonic-gate  * Inside the protocol destription, <foo> indicates the type foo indicates.
777c478bd9Sstevel@tonic-gate  *
787c478bd9Sstevel@tonic-gate  * 2. The Global protocol
797c478bd9Sstevel@tonic-gate  * ----------------------
807c478bd9Sstevel@tonic-gate  * Everything starting with "REPOSITORY_DOOR" or "repository_door" belongs
817c478bd9Sstevel@tonic-gate  * to the global protocol.
827c478bd9Sstevel@tonic-gate  *
837c478bd9Sstevel@tonic-gate  * 2.1. Global requests
847c478bd9Sstevel@tonic-gate  * --------------------
857c478bd9Sstevel@tonic-gate  *
867c478bd9Sstevel@tonic-gate  * REQUEST_CONNECT(rdr_flags, ...) -> result, [new_door]
877c478bd9Sstevel@tonic-gate  *	Request a new Client door.  rdr_flags determines attributes of the
887c478bd9Sstevel@tonic-gate  *	connection:
897c478bd9Sstevel@tonic-gate  *
907c478bd9Sstevel@tonic-gate  *	    FLAG_DEBUG
917c478bd9Sstevel@tonic-gate  *		Sets connection debugging flags to those in rdr_debug.
927c478bd9Sstevel@tonic-gate  *
937c478bd9Sstevel@tonic-gate  *	The new door is returned with DOOR_RELEASE set, so if the client does
947c478bd9Sstevel@tonic-gate  *	not recieve the response, the new door will recieve an unref
957c478bd9Sstevel@tonic-gate  *	notification.  This makes this request idempotent.
967c478bd9Sstevel@tonic-gate  *
977c478bd9Sstevel@tonic-gate  * 2.2. Global reponse codes
987c478bd9Sstevel@tonic-gate  * -------------------------
997c478bd9Sstevel@tonic-gate  * GLXXX: This needs to be thought through.
1007c478bd9Sstevel@tonic-gate  *
1017c478bd9Sstevel@tonic-gate  * SUCCESS
1027c478bd9Sstevel@tonic-gate  * FAIL_BAD_REQUEST
1037c478bd9Sstevel@tonic-gate  * FAIL_VERSION_MISMATCH
1047c478bd9Sstevel@tonic-gate  * FAIL_BAD_FLAG
1057c478bd9Sstevel@tonic-gate  * FAIL_BAD_USER
1067c478bd9Sstevel@tonic-gate  * FAIL_NO_RESOURCES
1077c478bd9Sstevel@tonic-gate  *
1087c478bd9Sstevel@tonic-gate  * 3. The Client protocol
1097c478bd9Sstevel@tonic-gate  * ----------------------
1107c478bd9Sstevel@tonic-gate  * Everything starting with "REP_PROTOCOL" or "rep_protocol" belongs to the
1117c478bd9Sstevel@tonic-gate  * client protocol.
1127c478bd9Sstevel@tonic-gate  *
1137c478bd9Sstevel@tonic-gate  * 3.1. Techniques used
1147c478bd9Sstevel@tonic-gate  * --------------------
1157c478bd9Sstevel@tonic-gate  * 3.1.1. Client-controlled identifiers
1167c478bd9Sstevel@tonic-gate  *
1177c478bd9Sstevel@tonic-gate  * An idiom the protocol uses to lower the number of round trips is
1187c478bd9Sstevel@tonic-gate  * client-controlled identifiers.  The basic idea is this:  whenever a
1197c478bd9Sstevel@tonic-gate  * client wants to set up and use a piece of server state, he picks an
1207c478bd9Sstevel@tonic-gate  * integer *which he knows is not in use* to identify it.  The server then
1217c478bd9Sstevel@tonic-gate  * maintains per-client, per-resource id->resource maps.  This has a number
1227c478bd9Sstevel@tonic-gate  * of advantages:
1237c478bd9Sstevel@tonic-gate  *
1247c478bd9Sstevel@tonic-gate  * 1.	Since the client allocates the identifiers, we don't need to do
1257c478bd9Sstevel@tonic-gate  *	a round-trip just to allocate a number.
1267c478bd9Sstevel@tonic-gate  *
1277c478bd9Sstevel@tonic-gate  * 2.	Since it is the client's job to make sure identifiers don't collide,
1287c478bd9Sstevel@tonic-gate  *	idempotency for setup (destroy) are simple:  If the identifier
1297c478bd9Sstevel@tonic-gate  *	already exists (does not exist), we just return success.
1307c478bd9Sstevel@tonic-gate  *
1317c478bd9Sstevel@tonic-gate  * 3.	Since the identifiers are per-client, the design automatically
1327c478bd9Sstevel@tonic-gate  *	precludes clients being able to manipulate other client's state.
1337c478bd9Sstevel@tonic-gate  *
1347c478bd9Sstevel@tonic-gate  * 3.1.2 Sequence numbers
1357c478bd9Sstevel@tonic-gate  *
1367c478bd9Sstevel@tonic-gate  * A standard way of gaining idempotency is introducing sequence numbers.
1377c478bd9Sstevel@tonic-gate  * These are simply integers which get incremented at points in the protocol,
1387c478bd9Sstevel@tonic-gate  * and make sure the client and server are in sync.
1397c478bd9Sstevel@tonic-gate  *
1407c478bd9Sstevel@tonic-gate  * In this protocol, we use sequence numbers for requests (like ITER_READ)
1417c478bd9Sstevel@tonic-gate  * which are repeated, returning different data each time.  Since requests
1427c478bd9Sstevel@tonic-gate  * can also be repeated due to unreliable dispatch, the client increments
1437c478bd9Sstevel@tonic-gate  * the sequence number after every successful request.  This allows the server
1447c478bd9Sstevel@tonic-gate  * to differentiate the two cases. (note that this means that failing
1457c478bd9Sstevel@tonic-gate  * requests have no side effects and are repeatable)
1467c478bd9Sstevel@tonic-gate  *
1477c478bd9Sstevel@tonic-gate  * 3.2. Client abstractions
1487c478bd9Sstevel@tonic-gate  * ------------------------
1497c478bd9Sstevel@tonic-gate  * 3.2.1 Entities
1507c478bd9Sstevel@tonic-gate  *
1517c478bd9Sstevel@tonic-gate  * An "entity" is a typed register which the client can manipulate.
1527c478bd9Sstevel@tonic-gate  * Entities are named in the protocol by client-controlled identifiers.
1537c478bd9Sstevel@tonic-gate  * They have a fixed type for their entire lifetime, and may be in one
1547c478bd9Sstevel@tonic-gate  * of two states:
1557c478bd9Sstevel@tonic-gate  *
1567c478bd9Sstevel@tonic-gate  * valid
1577c478bd9Sstevel@tonic-gate  *	The entity has a valid value, and may be read from.  This state
1587c478bd9Sstevel@tonic-gate  *	is reached by a successful write to the entity by some protocol
1597c478bd9Sstevel@tonic-gate  *	step.
1607c478bd9Sstevel@tonic-gate  *
1617c478bd9Sstevel@tonic-gate  * invalid
1627c478bd9Sstevel@tonic-gate  *	The entity does not contain a valid value.  There are a number
1637c478bd9Sstevel@tonic-gate  *	of ways to reach this state:
1647c478bd9Sstevel@tonic-gate  *
1657c478bd9Sstevel@tonic-gate  *	1.  The entity was just created.
1667c478bd9Sstevel@tonic-gate  *	2.  The underlying object that this entity refers to was destroyed.
1677c478bd9Sstevel@tonic-gate  *	3.  A protocol request which would have modified this entity
1687c478bd9Sstevel@tonic-gate  *	    failed.
1697c478bd9Sstevel@tonic-gate  *
1707c478bd9Sstevel@tonic-gate  * An entity is an element in the tree of repository data.  Every entity
1717c478bd9Sstevel@tonic-gate  * (except for the most distant SCOPE) has exactly one parent.  Entities
1727c478bd9Sstevel@tonic-gate  * can have multiple children of different types, restricted by its base
1737c478bd9Sstevel@tonic-gate  * type.
1747c478bd9Sstevel@tonic-gate  *
1757c478bd9Sstevel@tonic-gate  * The ENTITY_GET call is used to get the root of the tree (the most local
1767c478bd9Sstevel@tonic-gate  * scope)
1777c478bd9Sstevel@tonic-gate  *
1787c478bd9Sstevel@tonic-gate  * 3.2.2. The entity tree
1797c478bd9Sstevel@tonic-gate  * ----------------------
1807c478bd9Sstevel@tonic-gate  * The structure of a scope is as follows:
1817c478bd9Sstevel@tonic-gate  *
1827c478bd9Sstevel@tonic-gate  *	 _______
1837c478bd9Sstevel@tonic-gate  *	| SCOPE |
1847c478bd9Sstevel@tonic-gate  *	|_______|
1857c478bd9Sstevel@tonic-gate  *	    \ .
1867c478bd9Sstevel@tonic-gate  *	     \ .
1877c478bd9Sstevel@tonic-gate  *	      \_________
1887c478bd9Sstevel@tonic-gate  *	      | SERVICE |
1897c478bd9Sstevel@tonic-gate  *	      |_________|
1907c478bd9Sstevel@tonic-gate  *		/.    \ .
1917c478bd9Sstevel@tonic-gate  *	       /.      \ .
1927c478bd9Sstevel@tonic-gate  *	  ____/		\__________
1937c478bd9Sstevel@tonic-gate  *	 | PG |		| INSTANCE |
1947c478bd9Sstevel@tonic-gate  *	 |____|		|__________|
1957c478bd9Sstevel@tonic-gate  *			  /.	 \ .
1967c478bd9Sstevel@tonic-gate  *			 /.	  \ .
1977c478bd9Sstevel@tonic-gate  *		    ____/	   \__________
1987c478bd9Sstevel@tonic-gate  *		   | PG |	   | SNAPSHOT |
1997c478bd9Sstevel@tonic-gate  *		   |____|	   |__________|
2007c478bd9Sstevel@tonic-gate  *					\ .
2017c478bd9Sstevel@tonic-gate  *					 \ .
2027c478bd9Sstevel@tonic-gate  *					  \___________
2037c478bd9Sstevel@tonic-gate  *					  | SNAPLEVEL |
2047c478bd9Sstevel@tonic-gate  *					  |___________|
2057c478bd9Sstevel@tonic-gate  *					     /.
2067c478bd9Sstevel@tonic-gate  *					    /.
2077c478bd9Sstevel@tonic-gate  *				       ____/
2087c478bd9Sstevel@tonic-gate  *				      | PG |
2097c478bd9Sstevel@tonic-gate  *				      |____|
2107c478bd9Sstevel@tonic-gate  *
2117c478bd9Sstevel@tonic-gate  * Where the dots indicate an arbitrary number (including 0) of children.
2127c478bd9Sstevel@tonic-gate  *
2137c478bd9Sstevel@tonic-gate  * For a given scope, the next scope (in the sense of distance) is its
2147c478bd9Sstevel@tonic-gate  * TYPE_SCOPE parent.  The furthest out scope has no parent.
2157c478bd9Sstevel@tonic-gate  *
2167c478bd9Sstevel@tonic-gate  * 3.2.2 Iterators
2177c478bd9Sstevel@tonic-gate  *
2187c478bd9Sstevel@tonic-gate  * GLXXX
2197c478bd9Sstevel@tonic-gate  *
2207c478bd9Sstevel@tonic-gate  * 3.3. Client requests
2217c478bd9Sstevel@tonic-gate  * --------------------
2227c478bd9Sstevel@tonic-gate  *
2237c478bd9Sstevel@tonic-gate  * CLOSE() -> result
2247c478bd9Sstevel@tonic-gate  *	Closes the connection, revoking the door.  After this call completes,
2257c478bd9Sstevel@tonic-gate  *	no further calls will succeed.
2267c478bd9Sstevel@tonic-gate  *
2277c478bd9Sstevel@tonic-gate  * ENTITY_SETUP(entity_id, type) -> result
2287c478bd9Sstevel@tonic-gate  *	Sets up an entity, identified by entity_id, to identify a single
2297c478bd9Sstevel@tonic-gate  *	<type>.  <type> may not be TYPE_NONE.
2307c478bd9Sstevel@tonic-gate  *
2317c478bd9Sstevel@tonic-gate  * ENTITY_NAME(entity_id, name_type) -> result, name
2327c478bd9Sstevel@tonic-gate  *	Returns the name of entity_id.  name_type determines which type of
2337c478bd9Sstevel@tonic-gate  *	name to get.
2347c478bd9Sstevel@tonic-gate  *
2357c478bd9Sstevel@tonic-gate  * ENTITY_PARENT_TYPE(entity_id) -> result, parent_type
2367c478bd9Sstevel@tonic-gate  *	Retrieves the type of entity_id's parent
2377c478bd9Sstevel@tonic-gate  *
2387c478bd9Sstevel@tonic-gate  * ENTITY_GET_CHILD(entity_id, child_id, name) -> result
2397c478bd9Sstevel@tonic-gate  *	Puts entity_id's child (of child_id's type) named 'name' into child_id.
2407c478bd9Sstevel@tonic-gate  *
2417c478bd9Sstevel@tonic-gate  * ENTITY_GET_PARENT(entity_id, out_id) -> result
2427c478bd9Sstevel@tonic-gate  *	Puts entity_id's parent into out_id.
2437c478bd9Sstevel@tonic-gate  *
2447c478bd9Sstevel@tonic-gate  * ENTITY_GET(entity_id, number) -> result
2457c478bd9Sstevel@tonic-gate  *	Makes entity_id point to a particular object.  If any error
2467c478bd9Sstevel@tonic-gate  *	occurs, dest_id will be invalid.
2477c478bd9Sstevel@tonic-gate  *
2487c478bd9Sstevel@tonic-gate  * ENTITY_UPDATE(entity_id, changeid) -> result
2497c478bd9Sstevel@tonic-gate  *	Updates the entity to pick up any new changes.
2507c478bd9Sstevel@tonic-gate  *
2517c478bd9Sstevel@tonic-gate  * ENTITY_CREATE_CHILD(entity_id, type, name, child_id, changeid) -> result
2527c478bd9Sstevel@tonic-gate  *	Attaches the object of type /type/ in child_id as the child of
2537c478bd9Sstevel@tonic-gate  *	entity_id named 'name'.
2547c478bd9Sstevel@tonic-gate  *
2557c478bd9Sstevel@tonic-gate  * ENTITY_CREATE_PG(entity_id, name, type, flags, child_id, changeid) -> result
2567c478bd9Sstevel@tonic-gate  *	Creates a property group child of entity_id named 'name', type 'type'
2577c478bd9Sstevel@tonic-gate  *	and flags 'flags', and puts the resulting object in child_id.
2587c478bd9Sstevel@tonic-gate  *
2597c478bd9Sstevel@tonic-gate  * ENTITY_DELETE(entity_id, changeid) -> result
2607c478bd9Sstevel@tonic-gate  *	Deletes the entity represented by entity_id.
2617c478bd9Sstevel@tonic-gate  *
2627c478bd9Sstevel@tonic-gate  * ENTITY_RESET(entity_id) -> result
2637c478bd9Sstevel@tonic-gate  *	Resets the entity.
2647c478bd9Sstevel@tonic-gate  *
2657c478bd9Sstevel@tonic-gate  * ENTITY_TEARDOWN(entity_id) -> result
2667c478bd9Sstevel@tonic-gate  *	Destroys the entity entity_id.
2677c478bd9Sstevel@tonic-gate  *
2687c478bd9Sstevel@tonic-gate  * ITER_SETUP(iter_id) -> result
2697c478bd9Sstevel@tonic-gate  *	Sets up an iterator id.
2707c478bd9Sstevel@tonic-gate  *
2717c478bd9Sstevel@tonic-gate  * ITER_START(iter_id, entity_id, itertype, flags, pattern) -> result
2727c478bd9Sstevel@tonic-gate  *	Sets up an iterator, identified by iter_id, which will iterate the
2737c478bd9Sstevel@tonic-gate  *	<itertype> children of entity_id whose names match 'pattern',
2747c478bd9Sstevel@tonic-gate  *	with the matching controlled by flags.  Initializing an iterator
2757c478bd9Sstevel@tonic-gate  *	counts as the first sequence number (1).
2767c478bd9Sstevel@tonic-gate  *
2777c478bd9Sstevel@tonic-gate  * ITER_READ(iter_id, sequence, entity_id) -> result
2787c478bd9Sstevel@tonic-gate  *	Retrieves the next element of iterator iter_id.  Sequence starts at 2,
2797c478bd9Sstevel@tonic-gate  *	and is incremented by the client after each successful iteration.
2807c478bd9Sstevel@tonic-gate  *	The result is written to entity_id, which must be of the same type
2817c478bd9Sstevel@tonic-gate  *	as the iterator result.  The iterator must not be iterating values.
2827c478bd9Sstevel@tonic-gate  *
2837c478bd9Sstevel@tonic-gate  * ITER_READ_VALUE(iter_id, sequence) -> result, type, value
2847c478bd9Sstevel@tonic-gate  *	Retrieves the next value for iterator iter_id.  Sequence starts at 2,
2857c478bd9Sstevel@tonic-gate  *	and is incremented by the client after each successful iteration.
2867c478bd9Sstevel@tonic-gate  *	The iterator must be iterating a property's values.
2877c478bd9Sstevel@tonic-gate  *
2887c478bd9Sstevel@tonic-gate  * ITER_RESET(iter_id) -> result
2897c478bd9Sstevel@tonic-gate  *	Throws away any accumulated state.
2907c478bd9Sstevel@tonic-gate  *
2917c478bd9Sstevel@tonic-gate  * ITER_TEARDOWN(iter_id) -> result
2927c478bd9Sstevel@tonic-gate  *	Destroys the iterator iter_id.
2937c478bd9Sstevel@tonic-gate  *
2947c478bd9Sstevel@tonic-gate  * NEXT_SNAPLEVEL(entity_src, entity_dst) -> result
2957c478bd9Sstevel@tonic-gate  *	If entity_src is a snapshot, set entity_dst to the first snaplevel
2967c478bd9Sstevel@tonic-gate  *	in it.  If entity_src is a snaplevel, set entity_dst to the next
2977c478bd9Sstevel@tonic-gate  *	snaplevel, or fail if there isn't one.
2987c478bd9Sstevel@tonic-gate  *
2997c478bd9Sstevel@tonic-gate  * SNAPSHOT_TAKE(entity_id, name, dest_id, flags) -> result
3007c478bd9Sstevel@tonic-gate  *	Takes a snapshot of entity_id, creating snaplevels for the instance and
3017c478bd9Sstevel@tonic-gate  *	its parent service.  If flags is REP_SNAPSHOT_NEW, a new snapshot named
3027c478bd9Sstevel@tonic-gate  *	'name' is created as a child of entity_id, dest_id is pointed to it,
3037c478bd9Sstevel@tonic-gate  *	and the new snaplevels are attached to it.  If flags is
3047c478bd9Sstevel@tonic-gate  *	REP_SNAPSHOT_ATTACH, name must be empty, and the new snaplevels are
3057c478bd9Sstevel@tonic-gate  *	attached to the snapshot dest_id points to.
3067c478bd9Sstevel@tonic-gate  *
3077c478bd9Sstevel@tonic-gate  * SNAPSHOT_TAKE_NAMED(entity_id, instname, svcname, name, dest_id) -> result
3087c478bd9Sstevel@tonic-gate  *	Like SNAPSHOT_TAKE, but always acts as if REP_SNAPSHOT_NEW is
3097c478bd9Sstevel@tonic-gate  *	specified, and instname and svcname override the actual service and
3107c478bd9Sstevel@tonic-gate  *	instance names, respectively, written into the snaplevels.
3117c478bd9Sstevel@tonic-gate  *
3127c478bd9Sstevel@tonic-gate  *	Note that this is only useful for writing snapshots which will later
3137c478bd9Sstevel@tonic-gate  *	be transferred to another instance (svc:/svcname:instname/)
3147c478bd9Sstevel@tonic-gate  *
3157c478bd9Sstevel@tonic-gate  * SNAPSHOT_ATTACH(source_id, dest_id) -> result
3167c478bd9Sstevel@tonic-gate  *	The snaplevels attached to the snapshot referenced by source_id are
3177c478bd9Sstevel@tonic-gate  *	attached to the snapshot dest_id is pointed at.
3187c478bd9Sstevel@tonic-gate  *
3197c478bd9Sstevel@tonic-gate  * PROPERTY_GET_TYPE(entity_id) -> result, value type
3207c478bd9Sstevel@tonic-gate  *	Finds the value type of entity_id, which must be a property.
3217c478bd9Sstevel@tonic-gate  *
3227c478bd9Sstevel@tonic-gate  * PROPERTY_GET_VALUE(entity_id) -> result, type, value
3237c478bd9Sstevel@tonic-gate  *	If the property contains a single value, returns it and its type.
3247c478bd9Sstevel@tonic-gate  *
3257c478bd9Sstevel@tonic-gate  * PROPERTYGRP_SETUP_WAIT(entity_id) -> result, [pipe fd]
3267c478bd9Sstevel@tonic-gate  *	Sets up a notification for changes to the object entity_id currently
3277c478bd9Sstevel@tonic-gate  *	references.  On success, returns one side of a pipe -- when there
3287c478bd9Sstevel@tonic-gate  *	has been a change (or the daemon dies), the other end of the pipe will
3297c478bd9Sstevel@tonic-gate  *	be closed.
3307c478bd9Sstevel@tonic-gate  *
3317c478bd9Sstevel@tonic-gate  *	Only one of these can be set up per client -- attempts to set up more
3327c478bd9Sstevel@tonic-gate  *	than one will cause the previous one to get closed.
3337c478bd9Sstevel@tonic-gate  *
3347c478bd9Sstevel@tonic-gate  * PROPERTYGRP_TX_START(entity_id_tx, entity_id) -> result
3357c478bd9Sstevel@tonic-gate  *	Makes entity_id_tx point to the same property group as entity_id,
3367c478bd9Sstevel@tonic-gate  *	then attempts to set up entity_id_tx as a transaction on that group.
3377c478bd9Sstevel@tonic-gate  *	entity_id and entity_id_tx must be distinct.  On failure, entity_id_tx
3387c478bd9Sstevel@tonic-gate  *	is reset.
3397c478bd9Sstevel@tonic-gate  *
3407c478bd9Sstevel@tonic-gate  * PROPERTYGRP_TX_COMMIT(entity_id, data) -> result
3417c478bd9Sstevel@tonic-gate  *	Gives the actual steps to follow, and attempts to commit them.
3427c478bd9Sstevel@tonic-gate  *
3437c478bd9Sstevel@tonic-gate  * CLIENT_ADD_NOTIFY(type, pattern) -> result
3447c478bd9Sstevel@tonic-gate  *	Adds a new property group name or type pattern to the notify list
3457c478bd9Sstevel@tonic-gate  *	(see CLIENT_WAIT).  If successful, takes effect immediately.
3467c478bd9Sstevel@tonic-gate  *
3477c478bd9Sstevel@tonic-gate  * CLIENT_WAIT(entity_id) -> result, fmri
3487c478bd9Sstevel@tonic-gate  *	Waits for a change to a propertygroup that matches the patterns
3497c478bd9Sstevel@tonic-gate  *	set up using CLIENT_ADD_NOTIFY, and puts the resultant propertygroup
3507c478bd9Sstevel@tonic-gate  *	in entity_id.  Note that if an error occurs, you can loose
3517c478bd9Sstevel@tonic-gate  *	notifications.  Either entity_id is set to a changed propertygroup,
3527c478bd9Sstevel@tonic-gate  *	or fmri is a non-zero-length string identifying a deleted thing.
3537c478bd9Sstevel@tonic-gate  *
3547c478bd9Sstevel@tonic-gate  * BACKUP(name) -> result
3557c478bd9Sstevel@tonic-gate  *	Backs up the persistant repository with a particular name.
356*5b7f77adStw21770  *
357*5b7f77adStw21770  * SET_ANNOTATION(operation, file)
358*5b7f77adStw21770  *	Set up a security audit annotation event.  operation is the name of
359*5b7f77adStw21770  *	the operation that is being annotated, and file is the file being
360*5b7f77adStw21770  *	processed.  This will be used to mark operations which comprise
361*5b7f77adStw21770  *	multiple primitive operations such as svccfg import.
3627c478bd9Sstevel@tonic-gate  */
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate #include <door.h>
3657c478bd9Sstevel@tonic-gate #include <stddef.h>
3667c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
3697c478bd9Sstevel@tonic-gate extern "C" {
3707c478bd9Sstevel@tonic-gate #endif
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate /*
3737c478bd9Sstevel@tonic-gate  * svc.configd initial protocol details
3747c478bd9Sstevel@tonic-gate  */
3757c478bd9Sstevel@tonic-gate #define	REPOSITORY_DOOR_BASEVER	(('R' << 24) | ('e' << 16) | ('p' << 8))
3767c478bd9Sstevel@tonic-gate #define	REPOSITORY_DOOR_NAME	"/etc/svc/volatile/repository_door"
3777c478bd9Sstevel@tonic-gate #define	REPOSITORY_DOOR_COOKIE	((void *)REPOSITORY_DOOR_BASEVER)
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate #define	REPOSITORY_BOOT_BACKUP	((const char *)"boot")
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate /*
3827c478bd9Sstevel@tonic-gate  * This value should be incremented any time the protocol changes.  When in
3837c478bd9Sstevel@tonic-gate  * doubt, bump it.
3847c478bd9Sstevel@tonic-gate  */
385*5b7f77adStw21770 #define	REPOSITORY_DOOR_VERSION			(20 + REPOSITORY_DOOR_BASEVER)
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate /*
3887c478bd9Sstevel@tonic-gate  * flags for rdr_flags
3897c478bd9Sstevel@tonic-gate  */
3907c478bd9Sstevel@tonic-gate #define	REPOSITORY_DOOR_FLAG_DEBUG		0x00000001	/* rdr_debug */
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate #define	REPOSITORY_DOOR_FLAG_ALL		0x00000001	/* all flags */
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate /*
3957c478bd9Sstevel@tonic-gate  * Request IDs
3967c478bd9Sstevel@tonic-gate  */
3977c478bd9Sstevel@tonic-gate enum repository_door_requestid {
3987c478bd9Sstevel@tonic-gate 	REPOSITORY_DOOR_REQUEST_CONNECT = (('M' << 8) | 1)
3997c478bd9Sstevel@tonic-gate };
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate enum repository_door_statusid {
4027c478bd9Sstevel@tonic-gate 	REPOSITORY_DOOR_SUCCESS			= 0,
4037c478bd9Sstevel@tonic-gate 	REPOSITORY_DOOR_FAIL_BAD_REQUEST	= 1,
4047c478bd9Sstevel@tonic-gate 	REPOSITORY_DOOR_FAIL_VERSION_MISMATCH	= 2,
4057c478bd9Sstevel@tonic-gate 	REPOSITORY_DOOR_FAIL_BAD_FLAG		= 3,
4067c478bd9Sstevel@tonic-gate 	REPOSITORY_DOOR_FAIL_NO_RESOURCES	= 4,
4077c478bd9Sstevel@tonic-gate 	REPOSITORY_DOOR_FAIL_PERMISSION_DENIED	= 5
4087c478bd9Sstevel@tonic-gate };
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate /*
4117c478bd9Sstevel@tonic-gate  * You may only add elements to the end of this structure.
4127c478bd9Sstevel@tonic-gate  */
4137c478bd9Sstevel@tonic-gate typedef struct repository_door_request {
4147c478bd9Sstevel@tonic-gate 	uint32_t rdr_version;			/* must be first element */
4157c478bd9Sstevel@tonic-gate 	enum repository_door_requestid rdr_request;
4167c478bd9Sstevel@tonic-gate 	uint32_t rdr_flags;
4177c478bd9Sstevel@tonic-gate 	uint32_t rdr_debug;
4187c478bd9Sstevel@tonic-gate } repository_door_request_t;
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate typedef struct repository_door_response {
4217c478bd9Sstevel@tonic-gate 	enum repository_door_statusid rdr_status;
4227c478bd9Sstevel@tonic-gate } repository_door_response_t;
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate /*
4257c478bd9Sstevel@tonic-gate  * Client interface.  Used on doors returned by REQUEST_CONNECT
4267c478bd9Sstevel@tonic-gate  */
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate #define	REP_PROTOCOL_NAME_LEN		120	/* maximum name length */
4297c478bd9Sstevel@tonic-gate #define	REP_PROTOCOL_VALUE_LEN		4096	/* maximum value length */
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate #define	REP_PROTOCOL_FMRI_LEN		(6 * REP_PROTOCOL_NAME_LEN)
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate #define	REP_PROTOCOL_BASE		('C' << 8)
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate /*
4367c478bd9Sstevel@tonic-gate  * Request codes
4377c478bd9Sstevel@tonic-gate  */
4387c478bd9Sstevel@tonic-gate enum rep_protocol_requestid {
4397c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_CLOSE		= REP_PROTOCOL_BASE,
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_SETUP,
4427c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_NAME,
4437c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_PARENT_TYPE,
4447c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_GET_CHILD,
4457c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_GET_PARENT,
4467c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_GET,
4477c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_UPDATE,
4487c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_CREATE_CHILD,
4497c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_CREATE_PG,
4507c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_DELETE,
4517c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_RESET,
4527c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_TEARDOWN,
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ITER_SETUP,
4557c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ITER_START,
4567c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ITER_READ,
4577c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ITER_READ_VALUE,
4587c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ITER_RESET,
4597c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ITER_TEARDOWN,
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_NEXT_SNAPLEVEL,
4627c478bd9Sstevel@tonic-gate 
4637c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_SNAPSHOT_TAKE,
4647c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_SNAPSHOT_TAKE_NAMED,
4657c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_SNAPSHOT_ATTACH,
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_PROPERTY_GET_TYPE,
4687c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_PROPERTY_GET_VALUE,
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_PROPERTYGRP_SETUP_WAIT,
4717c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_PROPERTYGRP_TX_START,
4727c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_PROPERTYGRP_TX_COMMIT,
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_CLIENT_ADD_NOTIFY,
4757c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_CLIENT_WAIT,
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_BACKUP,
4787c478bd9Sstevel@tonic-gate 
479*5b7f77adStw21770 	REP_PROTOCOL_SET_AUDIT_ANNOTATION,
480*5b7f77adStw21770 
4817c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_MAX_REQUEST
4827c478bd9Sstevel@tonic-gate };
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate /*
4857c478bd9Sstevel@tonic-gate  * Response codes.  These are returned to the client, and the errors are
4867c478bd9Sstevel@tonic-gate  * translated into scf_error_t's by libscf (see proto_error()).
4877c478bd9Sstevel@tonic-gate  */
4887c478bd9Sstevel@tonic-gate typedef int32_t rep_protocol_responseid_t;
4897c478bd9Sstevel@tonic-gate enum rep_protocol_responseid {
4907c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_SUCCESS =			0,
4917c478bd9Sstevel@tonic-gate 	/* iterators: No more values. */
4927c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_DONE =			1,
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate 	/* Request from client was malformed. */
4957c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_BAD_REQUEST =		-1,
4967c478bd9Sstevel@tonic-gate 	/* Prerequisite call has not been made. */
4977c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_MISORDERED =		-2,
4987c478bd9Sstevel@tonic-gate 	/* Register for ID has not been created. */
4997c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_UNKNOWN_ID =		-3,
5007c478bd9Sstevel@tonic-gate 	/* Out of memory or other resource. */
5017c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_NO_RESOURCES =	-4,
5027c478bd9Sstevel@tonic-gate 	/* Type argument is invalid. */
5037c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_INVALID_TYPE =	-5,
5047c478bd9Sstevel@tonic-gate 	/* Requested object does not exist. */
5057c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_NOT_FOUND =		-6,
5067c478bd9Sstevel@tonic-gate 	/* Register for given ID does not point to an object. */
5077c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_NOT_SET =		-7,
5087c478bd9Sstevel@tonic-gate 
5097c478bd9Sstevel@tonic-gate 	/* Requested name is longer than supplied buffer. */
5107c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_TRUNCATED =		-8,
5117c478bd9Sstevel@tonic-gate 	/* Operation requires different type. */
5127c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_TYPE_MISMATCH =	-9,
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate 	/* Changeable object has been changed since last update. */
5157c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_NOT_LATEST =		-10,
5167c478bd9Sstevel@tonic-gate 	/* Creation failed because object with given name exists. */
5177c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_EXISTS =		-11,
5187c478bd9Sstevel@tonic-gate 	/* Transaction is invalid. */
5197c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_BAD_TX =		-12,
5207c478bd9Sstevel@tonic-gate 	/* Operation is not applicable to indicated object. */
5217c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_NOT_APPLICABLE =	-13,
5227c478bd9Sstevel@tonic-gate 	/* Two IDs for operation were unexpectedly equal. */
5237c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_DUPLICATE_ID =	-14,
5247c478bd9Sstevel@tonic-gate 
5257c478bd9Sstevel@tonic-gate 	/* Permission denied. */
5267c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_PERMISSION_DENIED =	-15,
5277c478bd9Sstevel@tonic-gate 	/* Backend does not exist or otherwise refused access. */
5287c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_BACKEND_ACCESS =	-16,
5297c478bd9Sstevel@tonic-gate 	/* Backend is read-only. */
5307c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_BACKEND_READONLY =	-17,
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate 	/* Object has been deleted. */
5337c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_DELETED =		-18,
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_FAIL_UNKNOWN =		-0xfd
5367c478bd9Sstevel@tonic-gate };
5377c478bd9Sstevel@tonic-gate 
5387c478bd9Sstevel@tonic-gate /*
5397c478bd9Sstevel@tonic-gate  * Types
5407c478bd9Sstevel@tonic-gate  */
5417c478bd9Sstevel@tonic-gate typedef enum rep_protocol_entity {
5427c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_NONE,
5437c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_SCOPE,
5447c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_SERVICE,
5457c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_INSTANCE,
5467c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_SNAPSHOT,
5477c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_SNAPLEVEL,
5487c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_PROPERTYGRP,
5497c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_CPROPERTYGRP,	/* "composed" property group */
5507c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_PROPERTY,
5517c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_VALUE,
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_ENTITY_MAX
5547c478bd9Sstevel@tonic-gate } rep_protocol_entity_t;
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate typedef enum rep_protocol_value_type {
5577c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_TYPE_INVALID	= '\0',
5587c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_TYPE_BOOLEAN	= 'b',
5597c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_TYPE_COUNT		= 'c',
5607c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_TYPE_INTEGER	= 'i',
5617c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_TYPE_TIME		= 't',
5627c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_TYPE_STRING	= 's',
5637c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_TYPE_OPAQUE	= 'o',
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_SUBTYPE_USTRING	= REP_PROTOCOL_TYPE_STRING|('u' << 8),
5667c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_SUBTYPE_URI	= REP_PROTOCOL_TYPE_STRING|('U' << 8),
5677c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_SUBTYPE_FMRI	= REP_PROTOCOL_TYPE_STRING|('f' << 8),
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_SUBTYPE_HOST	= REP_PROTOCOL_TYPE_STRING|('h' << 8),
5707c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_SUBTYPE_HOSTNAME	= REP_PROTOCOL_TYPE_STRING|('N' << 8),
5717c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_SUBTYPE_NETADDR_V4	= REP_PROTOCOL_TYPE_STRING|('4' << 8),
5727c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_SUBTYPE_NETADDR_V6	= REP_PROTOCOL_TYPE_STRING|('6' << 8)
5737c478bd9Sstevel@tonic-gate } rep_protocol_value_type_t;
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate #define	REP_PROTOCOL_BASE_TYPE(t)	((t) & 0x00ff)
5777c478bd9Sstevel@tonic-gate #define	REP_PROTOCOL_SUBTYPE(t)		(((t) & 0xff00) >> 8)
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate /*
5807c478bd9Sstevel@tonic-gate  * Request structures
5817c478bd9Sstevel@tonic-gate  */
5827c478bd9Sstevel@tonic-gate typedef struct rep_protocol_request {
5837c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;
5847c478bd9Sstevel@tonic-gate } rep_protocol_request_t;
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate struct rep_protocol_iter_request {
5877c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;
5887c478bd9Sstevel@tonic-gate 	uint32_t rpr_iterid;
5897c478bd9Sstevel@tonic-gate };
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate struct rep_protocol_iter_start {
5927c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ITER_START */
5937c478bd9Sstevel@tonic-gate 	uint32_t rpr_iterid;
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate 	uint32_t rpr_entity;
5967c478bd9Sstevel@tonic-gate 	uint32_t rpr_itertype;
5977c478bd9Sstevel@tonic-gate 	uint32_t rpr_flags;
5987c478bd9Sstevel@tonic-gate 	char	rpr_pattern[REP_PROTOCOL_NAME_LEN];
5997c478bd9Sstevel@tonic-gate };
6007c478bd9Sstevel@tonic-gate #define	RP_ITER_START_ALL	0x00000001	/* ignore pattern, match all */
6017c478bd9Sstevel@tonic-gate #define	RP_ITER_START_EXACT	0x00000002	/* exact match with pattern */
6027c478bd9Sstevel@tonic-gate #define	RP_ITER_START_PGTYPE	0x00000003	/* exact match pg type */
6037c478bd9Sstevel@tonic-gate #define	RP_ITER_START_FILT_MASK	0x00000003
6047c478bd9Sstevel@tonic-gate #define	RP_ITER_START_COMPOSED	0x00000004	/* composed */
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate struct rep_protocol_iter_read {
6077c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ITER_READ */
6087c478bd9Sstevel@tonic-gate 	uint32_t rpr_iterid;
6097c478bd9Sstevel@tonic-gate 	uint32_t rpr_sequence;		/* client increments upon success */
6107c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;		/* entity to write result to */
6117c478bd9Sstevel@tonic-gate };
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate struct rep_protocol_iter_read_value {
6147c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ITER_READ_VALUE */
6157c478bd9Sstevel@tonic-gate 	uint32_t rpr_iterid;
6167c478bd9Sstevel@tonic-gate 	uint32_t rpr_sequence;		/* client increments upon success */
6177c478bd9Sstevel@tonic-gate };
6187c478bd9Sstevel@tonic-gate 
6197c478bd9Sstevel@tonic-gate struct rep_protocol_entity_setup {
6207c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_SETUP */
6217c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
6227c478bd9Sstevel@tonic-gate 	uint32_t rpr_entitytype;
6237c478bd9Sstevel@tonic-gate };
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate struct rep_protocol_entity_name {
6267c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_NAME */
6277c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
6287c478bd9Sstevel@tonic-gate 	uint32_t rpr_answertype;
6297c478bd9Sstevel@tonic-gate };
6307c478bd9Sstevel@tonic-gate #define	RP_ENTITY_NAME_NAME			0
6317c478bd9Sstevel@tonic-gate #define	RP_ENTITY_NAME_PGTYPE			1
6327c478bd9Sstevel@tonic-gate #define	RP_ENTITY_NAME_PGFLAGS			2
6337c478bd9Sstevel@tonic-gate #define	RP_ENTITY_NAME_SNAPLEVEL_SCOPE		3
6347c478bd9Sstevel@tonic-gate #define	RP_ENTITY_NAME_SNAPLEVEL_SERVICE	4
6357c478bd9Sstevel@tonic-gate #define	RP_ENTITY_NAME_SNAPLEVEL_INSTANCE	5
6363eae19d9Swesolows #define	RP_ENTITY_NAME_PGREADPROT		6
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate struct rep_protocol_entity_update {
6397c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_UPDATE */
6407c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
6417c478bd9Sstevel@tonic-gate 	uint32_t rpr_changeid;
6427c478bd9Sstevel@tonic-gate };
6437c478bd9Sstevel@tonic-gate 
6447c478bd9Sstevel@tonic-gate struct rep_protocol_entity_parent_type {
6457c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_PARENT_TYPE */
6467c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
6477c478bd9Sstevel@tonic-gate };
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate struct rep_protocol_entity_parent {
6507c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_GET_PARENT */
6517c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
6527c478bd9Sstevel@tonic-gate 	uint32_t rpr_outid;
6537c478bd9Sstevel@tonic-gate };
6547c478bd9Sstevel@tonic-gate 
6557c478bd9Sstevel@tonic-gate struct rep_protocol_entity_get {
6567c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_SET */
6577c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
6587c478bd9Sstevel@tonic-gate 	uint32_t rpr_object;
6597c478bd9Sstevel@tonic-gate };
6607c478bd9Sstevel@tonic-gate #define	RP_ENTITY_GET_INVALIDATE	1
6617c478bd9Sstevel@tonic-gate #define	RP_ENTITY_GET_MOST_LOCAL_SCOPE	2
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate struct rep_protocol_entity_create_child {
6647c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request; /* ENTITY_CREATE_CHILD */
6657c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
6667c478bd9Sstevel@tonic-gate 	uint32_t rpr_childtype;
6677c478bd9Sstevel@tonic-gate 	uint32_t rpr_childid;
6687c478bd9Sstevel@tonic-gate 	uint32_t rpr_changeid;
6697c478bd9Sstevel@tonic-gate 	char	rpr_name[REP_PROTOCOL_NAME_LEN];
6707c478bd9Sstevel@tonic-gate };
6717c478bd9Sstevel@tonic-gate 
6727c478bd9Sstevel@tonic-gate struct rep_protocol_entity_create_pg {
6737c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request; /* ENTITY_CREATE_PG */
6747c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
6757c478bd9Sstevel@tonic-gate 	uint32_t rpr_childtype;
6767c478bd9Sstevel@tonic-gate 	uint32_t rpr_childid;
6777c478bd9Sstevel@tonic-gate 	uint32_t rpr_changeid;
6787c478bd9Sstevel@tonic-gate 	char	rpr_name[REP_PROTOCOL_NAME_LEN];
6797c478bd9Sstevel@tonic-gate 	char	rpr_type[REP_PROTOCOL_NAME_LEN];
6807c478bd9Sstevel@tonic-gate 	uint32_t rpr_flags;
6817c478bd9Sstevel@tonic-gate };
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate struct rep_protocol_entity_get_child {
6847c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_GET_CHILD */
6857c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
6867c478bd9Sstevel@tonic-gate 	uint32_t rpr_childid;
6877c478bd9Sstevel@tonic-gate 	char	rpr_name[REP_PROTOCOL_NAME_LEN];
6887c478bd9Sstevel@tonic-gate };
6897c478bd9Sstevel@tonic-gate 
6907c478bd9Sstevel@tonic-gate struct rep_protocol_entity_delete {
6917c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request; /* ENTITY_DELETE_CHILD */
6927c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
6937c478bd9Sstevel@tonic-gate 	uint32_t rpr_changeid;
6947c478bd9Sstevel@tonic-gate };
6957c478bd9Sstevel@tonic-gate 
6967c478bd9Sstevel@tonic-gate struct rep_protocol_entity_reset {
6977c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_NAME */
6987c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
6997c478bd9Sstevel@tonic-gate };
7007c478bd9Sstevel@tonic-gate 
7017c478bd9Sstevel@tonic-gate struct rep_protocol_entity_request {
7027c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_NAME */
7037c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
7047c478bd9Sstevel@tonic-gate };
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate struct rep_protocol_entity_teardown {
7077c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* ENTITY_TEARDOWN */
7087c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
7097c478bd9Sstevel@tonic-gate };
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate struct rep_protocol_entity_pair {
7127c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* NEXT_SNAPLEVEL */
7137c478bd9Sstevel@tonic-gate 	uint32_t rpr_entity_src;
7147c478bd9Sstevel@tonic-gate 	uint32_t rpr_entity_dst;
7157c478bd9Sstevel@tonic-gate };
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate struct rep_protocol_transaction_start {
7187c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* TX_SETUP */
7197c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid_tx;		/* property group tx entity */
7207c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;			/* property group entity */
7217c478bd9Sstevel@tonic-gate };
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate struct rep_protocol_transaction_commit {
7247c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request; /* TX_COMMIT */
7257c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
7267c478bd9Sstevel@tonic-gate 	uint32_t rpr_size;			/* size of entire structure */
7277c478bd9Sstevel@tonic-gate 	uint8_t rpr_cmd[1];
7287c478bd9Sstevel@tonic-gate };
7297c478bd9Sstevel@tonic-gate 
7307c478bd9Sstevel@tonic-gate #define	REP_PROTOCOL_TRANSACTION_COMMIT_SIZE(sz) \
7317c478bd9Sstevel@tonic-gate 	    (offsetof(struct rep_protocol_transaction_commit, rpr_cmd[sz]))
7327c478bd9Sstevel@tonic-gate 
7337c478bd9Sstevel@tonic-gate #define	REP_PROTOCOL_TRANSACTION_COMMIT_MIN_SIZE \
7347c478bd9Sstevel@tonic-gate 	    REP_PROTOCOL_TRANSACTION_COMMIT_SIZE(0)
7357c478bd9Sstevel@tonic-gate 
7367c478bd9Sstevel@tonic-gate enum rep_protocol_transaction_action {
7377c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_TX_ENTRY_INVALID,	/* N/A */
7387c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_TX_ENTRY_NEW,	/* new property */
7397c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_TX_ENTRY_CLEAR,	/* clear old property */
7407c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_TX_ENTRY_REPLACE,	/* change type of old property */
7417c478bd9Sstevel@tonic-gate 	REP_PROTOCOL_TX_ENTRY_DELETE	/* delete property (no values) */
7427c478bd9Sstevel@tonic-gate };
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate struct rep_protocol_transaction_cmd {
7457c478bd9Sstevel@tonic-gate 	enum	rep_protocol_transaction_action rptc_action;
7467c478bd9Sstevel@tonic-gate 	uint32_t rptc_type;
7477c478bd9Sstevel@tonic-gate 	uint32_t rptc_size;		/* size of entire structure */
7487c478bd9Sstevel@tonic-gate 	uint32_t rptc_name_len;
7497c478bd9Sstevel@tonic-gate 	uint8_t	rptc_data[1];
7507c478bd9Sstevel@tonic-gate };
7517c478bd9Sstevel@tonic-gate 
7527c478bd9Sstevel@tonic-gate #define	REP_PROTOCOL_TRANSACTION_CMD_SIZE(sz) \
7537c478bd9Sstevel@tonic-gate 	    (offsetof(struct rep_protocol_transaction_cmd, rptc_data[sz]))
7547c478bd9Sstevel@tonic-gate 
7557c478bd9Sstevel@tonic-gate #define	REP_PROTOCOL_TRANSACTION_CMD_MIN_SIZE \
7567c478bd9Sstevel@tonic-gate 	    REP_PROTOCOL_TRANSACTION_CMD_SIZE(0)
7577c478bd9Sstevel@tonic-gate 
7587c478bd9Sstevel@tonic-gate #define	TX_SIZE(x)	P2ROUNDUP((x), sizeof (uint32_t))
7597c478bd9Sstevel@tonic-gate 
7607c478bd9Sstevel@tonic-gate struct rep_protocol_transaction_request {
7617c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request; /* SETUP, ABORT or TEARDOWN */
7627c478bd9Sstevel@tonic-gate 	uint32_t rpr_txid;
7637c478bd9Sstevel@tonic-gate };
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate struct rep_protocol_property_request {
7667c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;
7677c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
7687c478bd9Sstevel@tonic-gate };
7697c478bd9Sstevel@tonic-gate 
7707c478bd9Sstevel@tonic-gate struct rep_protocol_propertygrp_request {
7717c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;
7727c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
7737c478bd9Sstevel@tonic-gate };
7747c478bd9Sstevel@tonic-gate 
7757c478bd9Sstevel@tonic-gate struct rep_protocol_notify_request {
7767c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;
7777c478bd9Sstevel@tonic-gate 	uint32_t rpr_type;
7787c478bd9Sstevel@tonic-gate 	char	rpr_pattern[REP_PROTOCOL_NAME_LEN];
7797c478bd9Sstevel@tonic-gate };
7807c478bd9Sstevel@tonic-gate #define	REP_PROTOCOL_NOTIFY_PGNAME 1
7817c478bd9Sstevel@tonic-gate #define	REP_PROTOCOL_NOTIFY_PGTYPE 2
7827c478bd9Sstevel@tonic-gate 
7837c478bd9Sstevel@tonic-gate struct rep_protocol_wait_request {
7847c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;
7857c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid;
7867c478bd9Sstevel@tonic-gate };
7877c478bd9Sstevel@tonic-gate 
7887c478bd9Sstevel@tonic-gate struct rep_protocol_snapshot_take {
7897c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* SNAPSHOT_TAKE */
7907c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid_src;
7917c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid_dest;
7927c478bd9Sstevel@tonic-gate 	int	rpr_flags;
7937c478bd9Sstevel@tonic-gate 	char	rpr_name[REP_PROTOCOL_NAME_LEN];
7947c478bd9Sstevel@tonic-gate };
7957c478bd9Sstevel@tonic-gate #define	REP_SNAPSHOT_NEW	0x00000001
7967c478bd9Sstevel@tonic-gate #define	REP_SNAPSHOT_ATTACH	0x00000002
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate struct rep_protocol_snapshot_take_named {
7997c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request; /* SNAPSHOT_TAKE_NAMED */
8007c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid_src;
8017c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid_dest;
8027c478bd9Sstevel@tonic-gate 	char	rpr_svcname[REP_PROTOCOL_NAME_LEN];
8037c478bd9Sstevel@tonic-gate 	char	rpr_instname[REP_PROTOCOL_NAME_LEN];
8047c478bd9Sstevel@tonic-gate 	char	rpr_name[REP_PROTOCOL_NAME_LEN];
8057c478bd9Sstevel@tonic-gate };
8067c478bd9Sstevel@tonic-gate 
8077c478bd9Sstevel@tonic-gate struct rep_protocol_snapshot_attach {
8087c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* SNAPSHOT_ATTACH */
8097c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid_src;
8107c478bd9Sstevel@tonic-gate 	uint32_t rpr_entityid_dest;
8117c478bd9Sstevel@tonic-gate };
8127c478bd9Sstevel@tonic-gate 
8137c478bd9Sstevel@tonic-gate struct rep_protocol_backup_request {
8147c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rpr_request;	/* BACKUP */
8157c478bd9Sstevel@tonic-gate 	uint32_t rpr_changeid;
8167c478bd9Sstevel@tonic-gate 	char rpr_name[REP_PROTOCOL_NAME_LEN];
8177c478bd9Sstevel@tonic-gate };
8187c478bd9Sstevel@tonic-gate 
819*5b7f77adStw21770 struct rep_protocol_annotation {
820*5b7f77adStw21770 	enum rep_protocol_requestid rpr_request;	/* SET_ANNOTATION */
821*5b7f77adStw21770 	char rpr_operation[REP_PROTOCOL_NAME_LEN];
822*5b7f77adStw21770 	char rpr_file[MAXPATHLEN];
823*5b7f77adStw21770 };
824*5b7f77adStw21770 
8257c478bd9Sstevel@tonic-gate /*
8267c478bd9Sstevel@tonic-gate  * Response structures
8277c478bd9Sstevel@tonic-gate  */
8287c478bd9Sstevel@tonic-gate typedef struct rep_protocol_response {
8297c478bd9Sstevel@tonic-gate 	rep_protocol_responseid_t rpr_response;
8307c478bd9Sstevel@tonic-gate } rep_protocol_response_t;
8317c478bd9Sstevel@tonic-gate 
8327c478bd9Sstevel@tonic-gate struct rep_protocol_integer_response {
8337c478bd9Sstevel@tonic-gate 	rep_protocol_responseid_t rpr_response;
8347c478bd9Sstevel@tonic-gate 	uint32_t rpr_value;
8357c478bd9Sstevel@tonic-gate };
8367c478bd9Sstevel@tonic-gate 
8377c478bd9Sstevel@tonic-gate struct rep_protocol_name_response {	/* response to ENTITY_NAME */
8387c478bd9Sstevel@tonic-gate 	rep_protocol_responseid_t rpr_response;
8397c478bd9Sstevel@tonic-gate 	char rpr_name[REP_PROTOCOL_NAME_LEN];
8407c478bd9Sstevel@tonic-gate };
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate struct rep_protocol_fmri_response {
8437c478bd9Sstevel@tonic-gate 	rep_protocol_responseid_t rpr_response;
8447c478bd9Sstevel@tonic-gate 	char rpr_fmri[REP_PROTOCOL_FMRI_LEN];
8457c478bd9Sstevel@tonic-gate };
8467c478bd9Sstevel@tonic-gate 
8477c478bd9Sstevel@tonic-gate struct rep_protocol_value_response {
8487c478bd9Sstevel@tonic-gate 	rep_protocol_responseid_t rpr_response;
8497c478bd9Sstevel@tonic-gate 	rep_protocol_value_type_t rpr_type;
8507c478bd9Sstevel@tonic-gate 	char			rpr_value[2 * REP_PROTOCOL_VALUE_LEN + 1];
8517c478bd9Sstevel@tonic-gate };
8527c478bd9Sstevel@tonic-gate 
8537c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
8547c478bd9Sstevel@tonic-gate }
8557c478bd9Sstevel@tonic-gate #endif
8567c478bd9Sstevel@tonic-gate 
8577c478bd9Sstevel@tonic-gate #endif	/* _REPCACHE_PROTOCOL_H */
858