2 * Copyright 2006-2007, Sine Nomine Associates and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #ifndef _AFS_VOL_DAEMON_COM_H
11 #define _AFS_VOL_DAEMON_COM_H
14 * SYNC protocol constants
17 /* SYNC protocol command codes
19 * command codes 0-65535 are reserved for
20 * global SYNC package command codes
22 #define SYNC_COM_CODE_USER_BASE 65536
23 #define SYNC_COM_CODE_DECL(code) (SYNC_COM_CODE_USER_BASE+(code))
25 /* general command codes */
26 #define SYNC_COM_CHANNEL_CLOSE 0
29 /* SYNC protocol response codes
31 * response codes 0-65535 are reserved for
32 * global SYNC package response codes
34 #define SYNC_RES_CODE_USER_BASE 65536
35 #define SYNC_RES_CODE_DECL(code) (SYNC_RES_CODE_USER_BASE+(code))
37 /* general response codes */
38 #define SYNC_OK 0 /* sync call returned ok */
39 #define SYNC_DENIED 1 /* sync request denied by server */
40 #define SYNC_COM_ERROR 2 /* sync protocol communicaions error */
41 #define SYNC_BAD_COMMAND 3 /* sync command code not implemented by server */
42 #define SYNC_FAILED 4 /* sync server-side procedure failed */
45 /* SYNC protocol reason codes
47 * reason codes 0-65535 are reserved for
48 * global SYNC package reason codes
50 #define SYNC_REASON_CODE_USER_BASE 65536
51 #define SYNC_REASON_CODE_DECL(code) (SYNC_REASON_CODE_USER_BASE+(code))
53 /* general reason codes */
54 #define SYNC_REASON_NONE 0
55 #define SYNC_REASON_MALFORMED_PACKET 1
56 #define SYNC_REASON_NOMEM 2
58 /* SYNC protocol flags
60 * flag bits 0-7 are reserved for
61 * global SYNC package flags
63 #define SYNC_FLAG_CODE_USER_BASE 8
64 #define SYNC_FLAG_CODE_DECL(code) (1 << (SYNC_FLAG_CODE_USER_BASE+(code)))
66 /* general flag codes */
67 #define SYNC_FLAG_CHANNEL_SHUTDOWN 0x1
68 #define SYNC_FLAG_DAFS_EXTENSIONS 0x2 /* signal that other end of socket is compiled
69 * with demand attach extensions */
71 /* SYNC protocol response buffers */
72 #define SYNC_PROTO_MAX_LEN 768 /* maximum size of sync protocol message */
74 /* use a large type to get proper buffer alignment so we can safely cast the pointer */
75 #define SYNC_PROTO_BUF_DECL(buf) \
76 afs_int64 _##buf##_l[SYNC_PROTO_MAX_LEN/sizeof(afs_int64)]; \
77 char * buf = (char *)(_##buf##_l)
80 /* client-side state object */
81 typedef struct SYNC_client_state {
84 afs_uint32 proto_version;
85 int retry_limit; /* max number of times for SYNC_ask to retry */
86 afs_int32 hard_timeout; /* upper limit on time to keep trying */
87 char * proto_name; /**< sync protocol associated with this conn */
88 byte fatal_error; /* fatal error on this client conn */
92 typedef struct SYNC_command_hdr {
93 afs_uint32 proto_version; /* sync protocol version */
94 afs_int32 programType; /* type of program issuing the request */
95 afs_int32 command; /* request type */
96 afs_int32 reason; /* reason for request */
97 afs_uint32 command_len; /* entire length of command */
101 typedef struct SYNC_response_hdr {
102 afs_uint32 proto_version; /* sync protocol version */
103 afs_uint32 response_len; /* entire length of response */
104 afs_int32 response; /* response code */
105 afs_int32 reason; /* reason for response */
110 /* user-visible types */
111 typedef struct SYNC_command {
112 SYNC_command_hdr hdr;
120 typedef struct SYNC_response {
121 SYNC_response_hdr hdr;
130 /* client-side prototypes */
131 extern afs_int32 SYNC_ask(SYNC_client_state *, SYNC_command * com, SYNC_response * res);
132 extern int SYNC_connect(SYNC_client_state *); /* setup the channel */
133 extern int SYNC_disconnect(SYNC_client_state *); /* just close the socket */
134 extern afs_int32 SYNC_closeChannel(SYNC_client_state *); /* do a graceful channel close */
135 extern int SYNC_reconnect(SYNC_client_state *); /* do a reconnect after a protocol error, or from a forked child */
137 /* server-side prototypes */
138 extern int SYNC_getCom(int fd, SYNC_command * com);
139 extern int SYNC_putRes(int fd, SYNC_response * res);
140 extern int SYNC_verifyProtocolString(char * buf, size_t len);
142 #endif /* _AFS_VOL_DAEMON_COM_H */