3c6102125ff71d18e24881a45a81be751d32e327
[openafs.git] / src / vol / daemon_com.h
1 /*
2  * Copyright 2006-2007, Sine Nomine Associates and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 #ifndef _AFS_VOL_DAEMON_COM_H
11 #define _AFS_VOL_DAEMON_COM_H
12
13 /* 
14  * SYNC protocol constants
15  */
16
17 /* SYNC protocol command codes
18  *
19  * command codes 0-65535 are reserved for
20  * global SYNC package command codes
21  */
22 #define SYNC_COM_CODE_USER_BASE 65536
23 #define SYNC_COM_CODE_DECL(code) (SYNC_COM_CODE_USER_BASE+(code))
24
25 /* general command codes */
26 #define SYNC_COM_CHANNEL_CLOSE 0
27
28
29 /* SYNC protocol response codes
30  *
31  * response codes 0-65535 are reserved for 
32  * global SYNC package response codes
33  */
34 #define SYNC_RES_CODE_USER_BASE 65536
35 #define SYNC_RES_CODE_DECL(code) (SYNC_RES_CODE_USER_BASE+(code))
36
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 */
43
44
45 /* SYNC protocol reason codes
46  *
47  * reason codes 0-65535 are reserved for
48  * global SYNC package reason codes
49  */
50 #define SYNC_REASON_CODE_USER_BASE 65536
51 #define SYNC_REASON_CODE_DECL(code) (SYNC_REASON_CODE_USER_BASE+(code))
52
53 /* general reason codes */
54 #define SYNC_REASON_NONE                 0
55 #define SYNC_REASON_MALFORMED_PACKET     1
56 #define SYNC_REASON_NOMEM                2
57
58 /* SYNC protocol flags
59  *
60  * flag bits 0-7 are reserved for
61  * global SYNC package flags
62  */
63 #define SYNC_FLAG_CODE_USER_BASE 8
64 #define SYNC_FLAG_CODE_DECL(code) (1 << (SYNC_FLAG_CODE_USER_BASE+(code)))
65
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 */
70
71 /* SYNC protocol response buffers */
72 #define SYNC_PROTO_MAX_LEN     768  /* maximum size of sync protocol message */
73
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)
78
79
80 /* client-side state object */
81 typedef struct SYNC_client_state {
82     int fd;
83     afs_uint16 port;
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 */
89 } SYNC_client_state;
90
91 /* wire types */
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 */
98     afs_uint32 flags;
99 } SYNC_command_hdr;
100
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 */
106     afs_uint32 flags;
107 } SYNC_response_hdr;
108
109
110 /* user-visible types */
111 typedef struct SYNC_command {
112     SYNC_command_hdr hdr;
113     struct {
114         afs_uint32 len;
115         void * buf;
116     } payload;
117     afs_int32 recv_len;
118 } SYNC_command;
119
120 typedef struct SYNC_response {
121     SYNC_response_hdr hdr;
122     struct {
123         afs_uint32 len;
124         void * buf;
125     } payload;
126     afs_int32 recv_len;
127 } SYNC_response;
128
129
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 */
136
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);
141
142 #endif /* _AFS_VOL_DAEMON_COM_H */