2 * Copyright 2006-2008, 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))
26 * general command codes.
29 SYNC_COM_CHANNEL_CLOSE = 0, /**< request sync channel shutdown */
34 /* SYNC protocol response codes
36 * response codes 0-65535 are reserved for
37 * global SYNC package response codes
39 #define SYNC_RES_CODE_USER_BASE 65536
40 #define SYNC_RES_CODE_DECL(code) (SYNC_RES_CODE_USER_BASE+(code))
43 * general response codes.
46 SYNC_OK = 0, /**< sync call returned ok */
47 SYNC_DENIED = 1, /**< sync request denied by server */
48 SYNC_COM_ERROR = 2, /**< sync protocol communicaions error */
49 SYNC_BAD_COMMAND = 3, /**< sync command code not implemented by server */
50 SYNC_FAILED = 4, /**< sync server-side procedure failed */
54 /* SYNC protocol reason codes
56 * reason codes 0-65535 are reserved for
57 * global SYNC package reason codes
59 #define SYNC_REASON_CODE_USER_BASE 65536
60 #define SYNC_REASON_CODE_DECL(code) (SYNC_REASON_CODE_USER_BASE+(code))
62 /* general reason codes */
63 #define SYNC_REASON_NONE 0
64 #define SYNC_REASON_MALFORMED_PACKET 1
65 #define SYNC_REASON_NOMEM 2
66 #define SYNC_REASON_ENCODING_ERROR 3
68 /* SYNC protocol flags
70 * flag bits 0-7 are reserved for
71 * global SYNC package flags
73 #define SYNC_FLAG_CODE_USER_BASE 8
74 #define SYNC_FLAG_CODE_DECL(code) (1 << (SYNC_FLAG_CODE_USER_BASE+(code)))
76 /* general flag codes */
77 #define SYNC_FLAG_CHANNEL_SHUTDOWN 0x1
78 #define SYNC_FLAG_DAFS_EXTENSIONS 0x2 /* signal that other end of socket is compiled
79 * with demand attach extensions */
81 /* SYNC protocol response buffers */
82 #define SYNC_PROTO_MAX_LEN 768 /* maximum size of sync protocol message */
84 /* use a large type to get proper buffer alignment so we can safely cast the pointer */
85 #define SYNC_PROTO_BUF_DECL(buf) \
86 afs_int64 _##buf##_l[SYNC_PROTO_MAX_LEN/sizeof(afs_int64)]; \
87 char * buf = (char *)(_##buf##_l)
89 #ifdef USE_UNIX_SOCKETS
90 #include <afs/afsutil.h>
92 #define SYNC_SOCK_DOMAIN AF_UNIX
93 typedef struct sockaddr_un SYNC_sockaddr_t;
94 #else /* USE_UNIX_SOCKETS */
95 #define SYNC_SOCK_DOMAIN AF_INET
96 typedef struct sockaddr_in SYNC_sockaddr_t;
97 #endif /* USE_UNIX_SOCKETS */
100 * sync server endpoint address.
102 typedef struct SYNC_endpoint {
103 int domain; /**< socket domain */
104 afs_uint16 in; /**< localhost ipv4 tcp port number */
105 char * un; /**< unix domain socket filename (not a full path) */
108 #define SYNC_ENDPOINT_DECL(in_port, un_path) \
109 { SYNC_SOCK_DOMAIN, in_port, un_path }
113 * SYNC server state structure.
115 typedef struct SYNC_server_state {
116 int fd; /**< listening socket descriptor */
117 SYNC_endpoint_t endpoint; /**< server endpoint address */
118 afs_uint32 proto_version; /**< our protocol version */
119 int bind_retry_limit; /**< upper limit on times to retry socket bind() */
120 int listen_depth; /**< socket listen queue depth */
121 char * proto_name; /**< sync protocol associated with this conn */
122 SYNC_sockaddr_t addr; /**< server listen socket sockaddr */
123 } SYNC_server_state_t;
126 * SYNC client state structure.
128 typedef struct SYNC_client_state {
129 int fd; /**< client socket descriptor */
130 SYNC_endpoint_t endpoint; /**< address of sync server */
131 afs_uint32 proto_version; /**< our protocol version */
132 int retry_limit; /**< max number of times for SYNC_ask to retry */
133 afs_int32 hard_timeout; /**< upper limit on time to keep trying */
134 char * proto_name; /**< sync protocol associated with this conn */
135 byte fatal_error; /**< nonzer if fatal error on this client conn */
139 typedef struct SYNC_command_hdr {
140 afs_uint32 proto_version; /* sync protocol version */
141 afs_int32 programType; /* type of program issuing the request */
142 afs_int32 command; /* request type */
143 afs_int32 reason; /* reason for request */
144 afs_uint32 command_len; /* entire length of command */
148 typedef struct SYNC_response_hdr {
149 afs_uint32 proto_version; /* sync protocol version */
150 afs_uint32 response_len; /* entire length of response */
151 afs_int32 response; /* response code */
152 afs_int32 reason; /* reason for response */
157 /* user-visible types */
158 typedef struct SYNC_command {
159 SYNC_command_hdr hdr;
167 typedef struct SYNC_response {
168 SYNC_response_hdr hdr;
176 /* general prototypes */
177 extern int SYNC_getSock(SYNC_endpoint_t * endpoint);
178 extern void SYNC_getAddr(SYNC_endpoint_t * endpoint, SYNC_sockaddr_t * addr);
180 /* client-side prototypes */
181 extern afs_int32 SYNC_ask(SYNC_client_state *, SYNC_command * com, SYNC_response * res);
182 extern int SYNC_connect(SYNC_client_state *); /* setup the channel */
183 extern int SYNC_disconnect(SYNC_client_state *); /* just close the socket */
184 extern afs_int32 SYNC_closeChannel(SYNC_client_state *); /* do a graceful channel close */
185 extern int SYNC_reconnect(SYNC_client_state *); /* do a reconnect after a protocol error, or from a forked child */
187 /* server-side prototypes */
188 extern int SYNC_getCom(int fd, SYNC_command * com);
189 extern int SYNC_putRes(int fd, SYNC_response * res);
190 extern int SYNC_verifyProtocolString(char * buf, size_t len);
191 extern void SYNC_cleanupSock(SYNC_server_state_t * state);
192 extern int SYNC_bindSock(SYNC_server_state_t * state);
194 #endif /* _AFS_VOL_DAEMON_COM_H */