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