PERFORCE change 124740 for review

Fredrik Lindberg fli at FreeBSD.org
Sun Aug 5 11:21:33 PDT 2007


http://perforce.freebsd.org/chv.cgi?CH=124740

Change 124740 by fli at fli_nexus on 2007/08/05 18:20:44

	- Add definitions needed to support record database operations,
	  add/remove/list.
		- Add definitions needed to support cache operations, list/flush.
	- Add definitions needed to support interface operations, list.
	- Give structures and defintions a better prefix than "client packet",
	  they are now called mipc.
	- Clean up comments and style.
	- Add several new error codes. 

Affected files ...

.. //depot/projects/soc2007/fli-mdns_sd/shared/mdnsd_clipkg.h#3 edit

Differences ...

==== //depot/projects/soc2007/fli-mdns_sd/shared/mdnsd_clipkg.h#3 (text+ko) ====

@@ -24,8 +24,8 @@
  *
  */
 
-#ifndef _MDNSD_CLIPKG_H_
-#define _MDNSD_CLIPKG_H_
+#ifndef _MDNSD_IPC_H_
+#define _MDNSD_IPC_H_
 
 /*
  * This contains definitions of the protocol used between mdnsd and
@@ -39,7 +39,7 @@
  * Protocol version, this is embedded in the first octet of the
  * initial header.
  */
-#define CP_VERSION 1
+#define MIPC_VERSION 1
 
 /*
  * Maximum message length
@@ -48,61 +48,97 @@
  * limits the maximum resource length to 8978 bytes and thus should
  * 16384 bytes be well enough for any resources + message headers.
  */
-#define CP_MAXPLEN 16384
+#define MIPC_MAXPLEN 16384
 
 /*
- * Initial header
+ * Initial header - All message are prepended with this header
  *
  * 0    8            31      47       63
  * +----+------------+--------+--------+
  * |ver | message id | mtype  | msglen |
  * +----+------------+--------+--------+
  *
- * `ver'    - Set to CP_VERSION
+ * `ver'    - Set to MIPC_VERSION
  * `message id' - Arbitrary integer specified by the client, it should
  *                uniquely identify the message. A response from the server
  *                will contain the same message id.
  * `mtype'  - Defines the message type.
  * `msglen' - Hold the total message length, including initial header.
  */
-struct cp_head {
-	unsigned int	cph_ver:8;	/* protocol version */
-	unsigned int	cph_id:24;	/* arbitrary message id */
-	uint16_t	cph_msgtype;	/* message type */
-	uint16_t	cph_msglen;	/* total message length */
+struct mipc_head {
+	unsigned int	mih_ver:8;	/* protocol version */
+	unsigned int	mih_id:24;	/* arbitrary message id */
+	uint16_t	mih_msgtype;	/* message type */
+	uint16_t	mih_msglen;	/* total message length */
 } __packed;
 
 /*
  * List of recognized message types
  */
-#define CPM_ACK		0	/* command successful, no payload */
-#define CPM_ERROR	1	/* struct cp_error {} */
-#define CPM_QUERY	2	/* struct cp_query {} */
-#define CPM_QRESP	3	/* struct cp_qresp {} */
+#define MIM_ACK			0	/* Command successful, no payload */
+#define MIM_ERROR		1	/* Error message, mipc_error {} */
+#define MIM_QUERY		2	/* Register a query, mipc_query {} */
+#define MIM_QRESP		3	/* Query response, mipc_qresp {} */
+#define MIM_IF_LIST		4	/* Req. Active interfaces, no payload */
+#define MIM_IF			5	/* Interface information, mipc_if {} */
+#define MIM_IDENT_ADD		6	/* Add identifier, mipc_dbident {} */
+#define MIM_IDENT_DEL		7	/* Rem. identifier, mipc_dbident {} */
+#define MIM_IDENT_LIST		8	/* List identifers, mipc_dbi_list {} */
+#define MIM_IDENT		10	/* Identifer info, mipc_dbident {} */
+#define MIM_IDENT_NAME_ADD	11	/* Add name to ident mipc_dbi_name {} */
+#define MIM_IDENT_NAME_DEL	12	/* Rem. name  mipc_dbi_name {} */
+#define MIM_IDENT_NAME_LIST	13	/* List ident. mipc_dbi_name_list {} */
+#define MIM_IDENT_NAME		14	/* Name information, mipc_dbi_name {} */
+#define MIM_IDENT_RES_ADD	15	/* Add res., mipc_dbi_res_set {} */
+#define MIM_IDENT_RES_DEL	16	/* Rem. res., mipc_dbi_res_set {} */
+#define MIM_IDENT_RES_LIST	17	/* List res, mipc_dbi_res_list {} */
+#define MIM_IDENT_RES		18	/* Res. info., mipc_dbi_res_get {} */
+#define MIM_CACHE_LIST		19	/* Cache list, mipc_dbi_cache_list {} */
+#define MIM_CACHE		20	/* Cache record, mipc_cache {} */
+#define MIM_CACHE_FLUSH		21	/* Cache flush, mipc_cache_flush {} */
 
 /*
  * Error message, in case an error occurs an error code
  * is returned that identifies the type of error.
+ *
+ * Usage context
+ *   Might be return as a response to any message if an error was found
+ *   during message processing.
+ *
+ * Message structure
+ * +----------------+
+ * |   error code   |
+ * +----------------+
+ *
  */
-struct cp_error {
-	uint32_t cpe_code;
+struct mipc_error {
+	uint32_t	mie_code;
 } __packed;
 
 /*
  * List of recognized error codes
  */
-#define CPE_PERM	1	/* Permission denied */
-#define CPE_IVAL	2	/* Invalid message */
-#define CPE_UMSG	3	/* Unknown message type */
-#define CPE_TOUT	4	/* Query timeout */
-#define CPE_REGQ	5	/* Failed to register query */
-#define CPE_DEREGQ	6	/* Failed to register query */
+#define MIE_PERM	1	/* Permission denied */
+#define MIE_IVAL	2	/* Invalid message */
+#define MIE_UMSG	3	/* Unknown message type */
+#define MIE_TOUT	4	/* Query timeout */
+#define MIE_REGQ	5	/* Failed to register query */
+#define MIE_DEREGQ	6	/* Failed to register query */
+#define MIE_EXISTS	7	/* Entry does already exists */
+#define MIE_NOENT	8	/* Entry does not exists */
+#define MIE_INTE	9	/* Internal software error */
+#define MIE_NOIF	10	/* No such interface */
 
 /*
- * Query message, has a 12 byte header followed by a
- * wide character encoded domain name.
+ * Query message, has a 12 byte header followed by a wide character
+ * encoded domain name.
  * Direction: Client -> Server
  *
+ * Usage context
+ *   MIM_QUERY - Register a query, client must be prepared to receive
+ *               zero or many MIM_QRESP messages.
+ *
+ * Message structure
  * 0    7   15       31   39           63       79       95
  * +----+----+--------+----+------------+--------+--------+---//---+
  * |cmd |len |timeout |fam |   ifidx    | class  |  type  |  name  |
@@ -120,39 +156,39 @@
  *  `type'  - Should contain the desired type or mdns_t_any
  *  `name'  - Wide character encoded (wchar_t) domain name
  *
- * Responses to CPQ_CMD_ONESHOT
+ * Responses to MIQ_CMD_ONESHOT
  *  - One or more struct cp_qresp {}, the more bit might be set to indicate
  *    that more responses are to follow, this is only a hint. A client
  *    must be able to accept responses for as long as the timeout value
  *    specicied in the query message.
  *  - If the timeout value expires without ANY responses an error
- *    message with the code CPE_TOUT is returned.
+ *    message with the code MIE_TOUT is returned.
  *
- * Responses to CPQ_CMD_CREG
- *  - If the query was successful registed a CPM_ACK message is returned,
- *    responses might come in at any point after this until a CPQ_CMD_CDEREG
+ * Responses to MIQ_CMD_CREG
+ *  - If the query was successful registed a MIM_ACK message is returned,
+ *    responses might come in at any point after this until a MIQ_CMD_CDEREG
  *    command is issued.
  *  - If the registration failed for some reason, an error message with
- *    the code CPE_REGQ is returned.
+ *    the code MIE_REGQ is returned.
  *
- * Responses to CPQ_CMD_CDEREG
- *  - If the de-registration was successful a CPM_ACK message is returned,
- *    otherwise an error message with the code CPE_DEREGQ is returned.
+ * Responses to MIQ_CMD_CDEREG
+ *  - If the de-registration was successful a MIM_ACK message is returned,
+ *    otherwise an error message with the code MIE_DEREGQ is returned.
  */
-struct cp_query {
-	uint8_t	cpq_cmd;	/* query command */
-	uint8_t	cpq_len;	/* query name length in characters */
-	uint16_t cpq_timeout;	/* timeout in seconds (oneshot only) */
-	unsigned int cpq_fam:8; /* address family to query */
-	unsigned int cpq_ifidx:24; /* interface index, 0 = all ifs */
-	uint16_t cpq_class;	/* query class */
-	uint16_t cpq_type;	/* query type */
+struct mipc_query {
+	uint8_t		miq_cmd;	/* query command */
+	uint8_t		miq_len;	/* query name length in characters */
+	uint16_t	miq_timeout;	/* timeout in seconds (oneshot only) */
+	unsigned int	miq_fam:8;	/* address family to query */
+	unsigned int	miq_ifidx:24;	/* interface index, 0 = all ifs */
+	uint16_t	miq_class;	/* query class */
+	uint16_t	miq_type;	/* query type */
 	/* Query name follows */
 } __packed;
 
-#define CPQ_CMD_ONESHOT 0	
-#define CPQ_CMD_CREG	1	
-#define CPQ_CMD_CDEREG	2
+#define MIQ_CMD_ONESHOT 0	
+#define MIQ_CMD_CREG	1	
+#define MIQ_CMD_CDEREG	2
 
 /*
  * Query response message, 16 byte header followed by a variable length
@@ -160,6 +196,11 @@
  * resource data field.
  * Direction: Server -> Client
  *
+ * Usage context
+ *   MIM_QRESP - Response to a previous MIM_QUERY
+ *
+ * Message structure
+ *
  * 0    7   15       31   39           63               95       111
  * +----+----+--------+----+------------+----------------+--------+--------+
  * |m/z |nlen| reslen |fam |   ifidx    |      ttl       |  class |  type  |
@@ -180,22 +221,289 @@
  * `type'     - Resource type.
  * `resource' - Resource data is not decoded in any way (except for name
  *              decompression) and contains the raw data from mDNS packets.
- *
- * The header message if will always be set to the id the original
- * query message had.
  */
-struct cp_qresp {
-	unsigned int	cpr_more:1; /* more resources are coming */
-	unsigned int	cpr_zero:7; /* reserved/zero */
-	uint8_t		cpr_namlen; /* resource name length in characters */
-	uint16_t	cpr_reslen; /* resource data length (bytes) */
-	unsigned int cpr_fam:8; /* address family */
-	unsigned int cpr_ifidx:24;  /* interface index */
-	uint32_t	cpr_ttl;    /* ttl (in seconds) */
-	uint16_t	cpr_class;  /* resource class */
-	uint16_t	cpr_type;   /* resource type */
+struct mipc_qresp {
+	unsigned int	mir_more:1; /* more resources are coming */
+	unsigned int	mir_zero:7; /* reserved/zero */
+	uint8_t		mir_namlen; /* resource name length in characters */
+	uint16_t	mir_reslen; /* resource data length (bytes) */
+	unsigned int	mir_fam:8; /* address family */
+	unsigned int	mir_ifidx:24;  /* interface index */
+	uint32_t	mir_ttl;    /* ttl (in seconds) */
+	uint16_t	mir_class;  /* resource class */
+	uint16_t	mir_type;   /* resource type */
 	/* Wide character encoded name */
 	/* Resource data follows */
-};
+} __packed;
+
+
+/*
+ * Interface information
+ *
+ * Usage context
+ *   MIM_IF - Response to MIM_IF_LIST
+ *
+ * Message structure
+ * 0               31   39           63
+ * +----------------+----+------------+
+ * | interface idx  |len |   flags    |
+ * +----------------+----+------------+
+ */
+struct mipc_if {
+	uint32_t	miif_ifidx;	/* Interface index */
+	unsigned int	miif_len:8;	/* Interface name length */
+	unsigned int	miif_flags:24;	/* Flags */
+	/* Interface name (ascii) */
+} __packed;
+
+/*
+ * List indentifiers from the record database
+ * Direction: Client -> Server
+ *
+ * Usage context
+ *   MIM_IDENT_LIST - Request a list of identifiers on a specific interface.
+ *                    Response is zero or many MIM_IDENT followed by one MIM_OK
+ *
+ * Message structure
+ * +----------------+
+ * |  ident length  |
+ * +----------------+
+ *
+ */
+struct mipc_dbi_list {
+	uint32_t	miil_ifidx; /* Interface index */
+} __packed;
+
+/*
+ * Database record ident message.
+ * A database record is uniquely identified by an identifier, which
+ * is a normal ascii string.
+ * Direction: Client <-> Server
+ *
+ * Usage context
+ *  MIM_IDENT_ADD - cp_dbident {} as payload, will add the identifier
+ *                  specified in the message. MIM_ACK on success, MIM_ERROR
+ *                  on failure.
+ *  MIM_IDENT_DEL - cp_dbident {} as payload, will remove the specified
+ *                  identifier (and all names + resources) from the
+ *                  record database. MIM_ACK on success, MIM_ERROR on failure.
+ *  MIM_IDENT_LIST - No payload. Returns one MIM_IDENT message with
+ *                   cp_dbident {} as payload for each existing record. When
+ *                   no more records exists an CMP_ACK is returned.
+ *
+ * Message structure
+ * +----------------+-------//-------+
+ * |  ident length  |  ident string  |
+ * +----------------+-------//-------+
+ *
+ */
+
+struct mipc_dbident {
+	uint32_t	mii_ifidx; /* Interface index */
+	uint32_t	mii_len; /* ident length */
+	/* Ident follows (ascii) */
+} __packed;
+
+/*
+ * Add/remove a name from an identifier in the record database
+ * Direction: Client <-> Server
+ *
+ * Usage context
+ *  MIM_IDENT_NAME_ADD - Add a name to an identifier
+ *  MIM_IDENT_NAME_DEL - Remove a name from an identifier
+ *  MIM_IDENT_NAME     - Details on a specific name
+ *
+ * Message structure
+ * 0               31               63       79   87    95
+ * +----------------+----------------+--------+----+-+---+
+ * | interface idx  |  ident length  |  len   |elen|a|zer|
+ * +----------------+----------------+--------+----+-+---+
+ * +---//---+-----//-----+-----//-----+
+ * | ident  | unexp name |  exp name  |
+ * +---//---+-----//-----+-----//-----+
+ *
+ * The fields `miin_elen' and the flags miin_{active} are only used
+ * when retriving data from the server. These fields should be zeroed when
+ * this structure are used in the context client -> server.
+ */
+struct mipc_dbi_name {
+	uint32_t	miin_ifidx;	/* Interface index, 0 = all ifs */
+	uint32_t	miin_ilen;	/* Identifier length */
+	uint16_t	miin_len;	/* Name length (in characters) */
+	uint8_t		miin_elen; 	/* Expanded name length (characters) */
+	unsigned int	miin_active:1;	/* Currently selected name */
+	unsigned int	miin_zero:7;
+	/* Identifier (ascii) */
+	/* Unexpanded name, wide character encoded */
+	/* Expanded name, wide character encoded */
+} __packed;
+
+/*
+ * List names assigned to an identifier
+ * Direction: Client -> Server
+ *
+ * Usage context
+ *   MIM_IDENT_NAME_LIST - List names assigned to an identifier, the response
+ *   is zero or many MIM_IDENT_NAME (mipc_dbi_name {}) followed by an MIM_ACK
+ *
+ * Message structure
+ * 0               31               63
+ * +----------------+----------------+---//---+
+ * | interface idx  |  ident length  |  ident |
+ * +----------------+----------------+---//---+
+ */
+struct mipc_dbi_name_list {
+	uint32_t	miinl_ifidx; /* Interface index */
+	uint32_t	miinl_ilen; /* Identifer length */
+	/* Identifier (ascii) */
+} __packed;
+
+/*
+ * Resource set assigned to an identifier
+ * Direction: Client -> Server
+ *
+ * Usage context
+ *  MIM_IDENT_RES_ADD - Add resource to an identifier
+ *  MIM_IDENT_RES_DEL - Remove an resource to an identifier
+ *
+ * Message structure
+ * 0               31       47       63               95               127
+ * +----------------+--------+--------+----------------+----------------+
+ * | interface idx  |  class |  type  |      ttl       |  ident length  |
+ * +----------------+--------+--------+----------------+----------------+
+ *
+ * 127     143       151
+ * +--------+-+-------+----//----+-------------//-------------+
+ * | reslen |p| zero  |   ident  | wide name OR pointer ident |
+ * +--------+-+-------+----//----+------------//--------------+
+ */
+struct mipc_dbi_res_set {
+	uint32_t	mirs_ifidx;	/* Interface index */
+	uint16_t	mirs_class;
+	uint16_t	mirs_type;
+	uint32_t	mirs_ttl;
+	uint32_t	mirs_ilen;	/* ident length */
+	uint16_t	mirs_rlen;	/* Resource length (in characters) */
+	unsigned int	mirs_pointer:1;	/* Resource data is a pointer */
+	unsigned int	mirs_zero:15;
+	/* Record identifier (ascii) */
+	/* Wide character encoded name OR ascii encoded pointer name */
+} __packed;
+
+/*
+ * Retrive information on a resource assigned to an identifier
+ * Direction: Server -> Client
+ *
+ * Usage context
+ *   MIM_IDENT_RES - Information on a resource, response to MIM_IDENT_RES_LIST
+ *
+ * Message structure
+ * 0           23   31       47       63       79       95               127
+ * +------------+----+--------+--------+--------+--------+----------------+
+ * |   zero     |rlen|   len  |  elen  |  class |  type  |      ttl       |
+ * +------------+----+--------+--------+--------+--------+----------------+
+ * 127            159
+ * +----------------+----//----+----//----+----//----+----//----+
+ * |   ident length | rec name | unexp res| exp res  |ident ptr |
+ * +----------------+----//----+----//----+----//----+----//----+
+ */
+struct mipc_dbi_res_get {
+	unsigned int	mirg_zero:24;
+	unsigned int	mirg_rlen:8;	/* Name length (in characters) */
+	uint16_t	mirg_len;	/* Unencoded resource (in characters) */
+	uint16_t	mirg_elen;	/* Encoded resource length */
+	uint16_t	mirg_class; /* Resource class */
+	uint16_t	mirg_type;  /* Resource type */
+	uint32_t	mirg_ttl;   /* TTL (in seconds)) */
+	uint32_t	mirg_ilen;  /* Pointer identifer length */
+	/* Record name, wide character encoded */
+	/* Unencoded (unexpanded) resource data */
+	/* Expanded, encoded resource data (binary) */
+	/* Pointer identifier (if applicable) */
+} __packed;
+
+/*
+ * List resources assigned to an identifier
+ * Direction: Client -> Server
+ *
+ * Usage context
+ *   MIM_IDENT_RES_LIST - Request a list of resources assigned to an identifier
+ *
+ * Message structure
+ * 0               31               63
+ * +----------------+----------------+----//----+
+ * | identifer len  |  interface idx |   ident  |
+ * +----------------+----------------+----//----+
+ */
+struct mipc_dbi_res_list {
+	uint32_t	mirl_ilen;	/* Identifer length */
+	uint32_t	mirl_ifidx;	/* Interface index */
+	/* Record identifier (ascii) */
+} __packed;
+
+
+/*
+ * Request to flush cache on given interface index, an index of 0 is equal
+ * to all active interfaces.
+ * Direction: Client -> Server
+ *
+ * Usage context
+ *   MIM_CACHE_FLUSH - Request cache flush
+ *
+ * Message structure
+ * 0               31
+ * +----------------+
+ * | interface idx  |
+ * +----------------+
+ */
+struct mipc_cache_flush {
+	uint32_t	mcf_ifidx;	/* Interface index */
+} __packed;
+
+/*
+ * Request to view cache contents
+ * Direction: Client -> Server
+ *
+ * Usage context
+ *   MIM_CACHE_LIST - Rquest to list cache contents
+ *
+ * Message structure
+ * 0               31
+ * +----------------+
+ * | interface idx  |
+ * +----------------+
+ */
+struct mipc_cache_list {
+	uint32_t	mcl_ifidx;	/* Interface index */
+} __packed;
+
+/*
+ * Information on a cache entry
+ * Direction: Server -> Client
+ *
+ * Usage context
+ *   MIM_CACHE - Response to MIM_CACHE_LIST
+ *
+ * Message structure
+ * 0       15       31                63              95   103  111     127
+ * +--------+--------+----------------+----------------+----+----+--------+
+ * | class  |  type  |      ttl       |     ttl left   |zero|rlen| reslen |
+ * +--------+--------+----------------+----------------+----+----+--------+
+ * 127
+ * +---------//---------+---------//---------+
+ * |     record name    | resource (binary)  |
+ * +---------//---------+---------//---------+
+ */
+struct mipc_cache {
+	uint16_t	mc_class;	/* Resource class */
+	uint16_t	mc_type;	/* Resource type */
+	uint32_t	mc_ttl;		/* Resource TTL */
+	uint32_t	mc_ttl_left;	/* Time left of TTL */
+	uint8_t		mc_zero;
+	uint8_t		mc_reclen;	/* Record length (in characters) */
+	uint16_t	mc_reslen;	/* Resouce length */
+	/* Wide character encoded record name */
+	/* Binary resource */
+} __packed;
 
-#endif /* _MDNSD_CLIPKG_H_ */
+#endif /* _MDNSD_IPC_H_ */


More information about the p4-projects mailing list