]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/msgr.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / include / msgr.h
1 #ifndef CEPH_MSGR_H
2 #define CEPH_MSGR_H
3
4 #ifndef __KERNEL__
5 #include <sys/socket.h> // for struct sockaddr_storage
6 #endif
7
8 #include "include/int_types.h"
9
10 /* See comment in ceph_fs.h. */
11 #ifndef __KERNEL__
12 #include "byteorder.h"
13 #define __le16 ceph_le16
14 #define __le32 ceph_le32
15 #define __le64 ceph_le64
16 #endif
17
18 /*
19 * Data types for message passing layer used by Ceph.
20 */
21
22 #define CEPH_MON_PORT_LEGACY 6789 /* legacy default monitor port */
23 #define CEPH_MON_PORT_IANA 3300 /* IANA monitor port */
24
25 /*
26 * tcp connection banner. include a protocol version. and adjust
27 * whenever the wire protocol changes. try to keep this string length
28 * constant.
29 */
30 #define CEPH_BANNER "ceph v027"
31
32
33 /*
34 * messenger V2 connection banner prefix.
35 * The full banner string should have the form: "ceph v2\n<le16>"
36 * the 2 bytes are the length of the remaining banner.
37 */
38 #define CEPH_BANNER_V2_PREFIX "ceph v2\n"
39
40 /*
41 * messenger V2 features
42 */
43 #define CEPH_MSGR2_INCARNATION_1 (0ull)
44
45 #define DEFINE_MSGR2_FEATURE(bit, incarnation, name) \
46 const static uint64_t CEPH_MSGR2_FEATURE_##name = (1ULL << bit); \
47 const static uint64_t CEPH_MSGR2_FEATUREMASK_##name = \
48 (1ULL << bit | CEPH_MSGR2_INCARNATION_##incarnation);
49
50 #define HAVE_MSGR2_FEATURE(x, name) \
51 (((x) & (CEPH_MSGR2_FEATUREMASK_##name)) == (CEPH_MSGR2_FEATUREMASK_##name))
52
53 DEFINE_MSGR2_FEATURE( 0, 1, REVISION_1) // msgr2.1
54
55 #define CEPH_MSGR2_SUPPORTED_FEATURES (CEPH_MSGR2_FEATURE_REVISION_1)
56
57 #define CEPH_MSGR2_REQUIRED_FEATURES (0ull)
58
59
60 /*
61 * Rollover-safe type and comparator for 32-bit sequence numbers.
62 * Comparator returns -1, 0, or 1.
63 */
64 typedef __u32 ceph_seq_t;
65
66 static inline __s32 ceph_seq_cmp(__u32 a, __u32 b)
67 {
68 return (__s32)a - (__s32)b;
69 }
70
71
72 /*
73 * entity_name -- logical name for a process participating in the
74 * network, e.g. 'mds0' or 'osd3'.
75 */
76 struct ceph_entity_name {
77 __u8 type; /* CEPH_ENTITY_TYPE_* */
78 __le64 num;
79 } __attribute__ ((packed));
80
81 #define CEPH_ENTITY_TYPE_MON 0x01
82 #define CEPH_ENTITY_TYPE_MDS 0x02
83 #define CEPH_ENTITY_TYPE_OSD 0x04
84 #define CEPH_ENTITY_TYPE_CLIENT 0x08
85 #define CEPH_ENTITY_TYPE_MGR 0x10
86 #define CEPH_ENTITY_TYPE_AUTH 0x20
87
88 #define CEPH_ENTITY_TYPE_ANY 0xFF
89
90 extern const char *ceph_entity_type_name(int type);
91
92 /*
93 * entity_addr -- network address
94 */
95 struct ceph_entity_addr {
96 __le32 type;
97 __le32 nonce; /* unique id for process (e.g. pid) */
98 struct sockaddr_storage in_addr;
99 } __attribute__ ((packed));
100
101 struct ceph_entity_inst {
102 struct ceph_entity_name name;
103 struct ceph_entity_addr addr;
104 } __attribute__ ((packed));
105
106
107 /* used by message exchange protocol */
108 #define CEPH_MSGR_TAG_READY 1 /* server->client: ready for messages */
109 #define CEPH_MSGR_TAG_RESETSESSION 2 /* server->client: reset, try again */
110 #define CEPH_MSGR_TAG_WAIT 3 /* server->client: wait for racing
111 incoming connection */
112 #define CEPH_MSGR_TAG_RETRY_SESSION 4 /* server->client + cseq: try again
113 with higher cseq */
114 #define CEPH_MSGR_TAG_RETRY_GLOBAL 5 /* server->client + gseq: try again
115 with higher gseq */
116 #define CEPH_MSGR_TAG_CLOSE 6 /* closing pipe */
117 #define CEPH_MSGR_TAG_MSG 7 /* message */
118 #define CEPH_MSGR_TAG_ACK 8 /* message ack */
119 #define CEPH_MSGR_TAG_KEEPALIVE 9 /* just a keepalive byte! */
120 #define CEPH_MSGR_TAG_BADPROTOVER 10 /* bad protocol version */
121 #define CEPH_MSGR_TAG_BADAUTHORIZER 11 /* bad authorizer */
122 #define CEPH_MSGR_TAG_FEATURES 12 /* insufficient features */
123 #define CEPH_MSGR_TAG_SEQ 13 /* 64-bit int follows with seen seq number */
124 #define CEPH_MSGR_TAG_KEEPALIVE2 14
125 #define CEPH_MSGR_TAG_KEEPALIVE2_ACK 15 /* keepalive reply */
126 #define CEPH_MSGR_TAG_CHALLENGE_AUTHORIZER 16 /* ceph v2 doing server challenge */
127
128 /*
129 * connection negotiation
130 */
131 struct ceph_msg_connect {
132 __le64 features; /* supported feature bits */
133 __le32 host_type; /* CEPH_ENTITY_TYPE_* */
134 __le32 global_seq; /* count connections initiated by this host */
135 __le32 connect_seq; /* count connections initiated in this session */
136 __le32 protocol_version;
137 __le32 authorizer_protocol;
138 __le32 authorizer_len;
139 __u8 flags; /* CEPH_MSG_CONNECT_* */
140 } __attribute__ ((packed));
141
142 struct ceph_msg_connect_reply {
143 __u8 tag;
144 __le64 features; /* feature bits for this session */
145 __le32 global_seq;
146 __le32 connect_seq;
147 __le32 protocol_version;
148 __le32 authorizer_len;
149 __u8 flags;
150 } __attribute__ ((packed));
151
152 #define CEPH_MSG_CONNECT_LOSSY 1 /* messages i send may be safely dropped */
153
154
155 /*
156 * message header
157 */
158 struct ceph_msg_header_old {
159 __le64 seq; /* message seq# for this session */
160 __le64 tid; /* transaction id */
161 __le16 type; /* message type */
162 __le16 priority; /* priority. higher value == higher priority */
163 __le16 version; /* version of message encoding */
164
165 __le32 front_len; /* bytes in main payload */
166 __le32 middle_len;/* bytes in middle payload */
167 __le32 data_len; /* bytes of data payload */
168 __le16 data_off; /* sender: include full offset;
169 receiver: mask against ~PAGE_MASK */
170
171 struct ceph_entity_inst src, orig_src;
172 __le32 reserved;
173 __le32 crc; /* header crc32c */
174 } __attribute__ ((packed));
175
176 struct ceph_msg_header {
177 __le64 seq; /* message seq# for this session */
178 __le64 tid; /* transaction id */
179 __le16 type; /* message type */
180 __le16 priority; /* priority. higher value == higher priority */
181 __le16 version; /* version of message encoding */
182
183 __le32 front_len; /* bytes in main payload */
184 __le32 middle_len;/* bytes in middle payload */
185 __le32 data_len; /* bytes of data payload */
186 __le16 data_off; /* sender: include full offset;
187 receiver: mask against ~PAGE_MASK */
188
189 struct ceph_entity_name src;
190
191 /* oldest code we think can decode this. unknown if zero. */
192 __le16 compat_version;
193 __le16 reserved;
194 __le32 crc; /* header crc32c */
195 } __attribute__ ((packed));
196
197 struct ceph_msg_header2 {
198 __le64 seq; /* message seq# for this session */
199 __le64 tid; /* transaction id */
200 __le16 type; /* message type */
201 __le16 priority; /* priority. higher value == higher priority */
202 __le16 version; /* version of message encoding */
203
204 __le32 data_pre_padding_len;
205 __le16 data_off; /* sender: include full offset;
206 receiver: mask against ~PAGE_MASK */
207
208 __le64 ack_seq;
209 __u8 flags;
210 /* oldest code we think can decode this. unknown if zero. */
211 __le16 compat_version;
212 __le16 reserved;
213 } __attribute__ ((packed));
214
215 #define CEPH_MSG_PRIO_LOW 64
216 #define CEPH_MSG_PRIO_DEFAULT 127
217 #define CEPH_MSG_PRIO_HIGH 196
218 #define CEPH_MSG_PRIO_HIGHEST 255
219
220 /*
221 * follows data payload
222 * ceph_msg_footer_old does not support digital signatures on messages PLR
223 */
224
225 struct ceph_msg_footer_old {
226 __le32 front_crc, middle_crc, data_crc;
227 __u8 flags;
228 } __attribute__ ((packed));
229
230 struct ceph_msg_footer {
231 __le32 front_crc, middle_crc, data_crc;
232 // sig holds the 64 bits of the digital signature for the message PLR
233 __le64 sig;
234 __u8 flags;
235 } __attribute__ ((packed));
236
237 #define CEPH_MSG_FOOTER_COMPLETE (1<<0) /* msg wasn't aborted */
238 #define CEPH_MSG_FOOTER_NOCRC (1<<1) /* no data crc */
239 #define CEPH_MSG_FOOTER_SIGNED (1<<2) /* msg was signed */
240
241 #ifndef __KERNEL__
242 #undef __le16
243 #undef __le32
244 #undef __le64
245 #endif
246
247 #endif