5 #include <sys/socket.h> // for struct sockaddr_storage
8 #include "include/int_types.h"
10 /* See comment in ceph_fs.h. */
12 #include "byteorder.h"
13 #define __le16 ceph_le16
14 #define __le32 ceph_le32
15 #define __le64 ceph_le64
19 * Data types for message passing layer used by Ceph.
22 #define CEPH_MON_PORT_LEGACY 6789 /* legacy default monitor port */
23 #define CEPH_MON_PORT_IANA 3300 /* IANA monitor port */
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.
30 #define CEPH_PORT_FIRST 6789
33 * tcp connection banner. include a protocol version. and adjust
34 * whenever the wire protocol changes. try to keep this string length
37 #define CEPH_BANNER "ceph v027"
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.
45 #define CEPH_BANNER_V2_PREFIX "ceph v2\n"
48 * messenger V2 features
50 #define CEPH_MSGR2_INCARNATION_1 (0ull)
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);
57 #define HAVE_MSGR2_FEATURE(x, name) \
58 (((x) & (CEPH_MSGR2_FEATUREMASK_##name)) == (CEPH_MSGR2_FEATUREMASK_##name))
60 DEFINE_MSGR2_FEATURE( 0, 1, REVISION_1
) // msgr2.1
62 #define CEPH_MSGR2_SUPPORTED_FEATURES (CEPH_MSGR2_FEATURE_REVISION_1)
64 #define CEPH_MSGR2_REQUIRED_FEATURES (0ull)
68 * Rollover-safe type and comparator for 32-bit sequence numbers.
69 * Comparator returns -1, 0, or 1.
71 typedef __u32 ceph_seq_t
;
73 static inline __s32
ceph_seq_cmp(__u32 a
, __u32 b
)
75 return (__s32
)a
- (__s32
)b
;
80 * entity_name -- logical name for a process participating in the
81 * network, e.g. 'mds0' or 'osd3'.
83 struct ceph_entity_name
{
84 __u8 type
; /* CEPH_ENTITY_TYPE_* */
86 } __attribute__ ((packed
));
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
95 #define CEPH_ENTITY_TYPE_ANY 0xFF
97 extern const char *ceph_entity_type_name(int type
);
100 * entity_addr -- network address
102 struct ceph_entity_addr
{
104 __le32 nonce
; /* unique id for process (e.g. pid) */
105 struct sockaddr_storage in_addr
;
106 } __attribute__ ((packed
));
108 struct ceph_entity_inst
{
109 struct ceph_entity_name name
;
110 struct ceph_entity_addr addr
;
111 } __attribute__ ((packed
));
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
121 #define CEPH_MSGR_TAG_RETRY_GLOBAL 5 /* server->client + gseq: try again
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 */
136 * connection negotiation
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
));
149 struct ceph_msg_connect_reply
{
151 __le64 features
; /* feature bits for this session */
154 __le32 protocol_version
;
155 __le32 authorizer_len
;
157 } __attribute__ ((packed
));
159 #define CEPH_MSG_CONNECT_LOSSY 1 /* messages i send may be safely dropped */
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 */
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 */
178 struct ceph_entity_inst src
, orig_src
;
180 __le32 crc
; /* header crc32c */
181 } __attribute__ ((packed
));
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 */
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 */
196 struct ceph_entity_name src
;
198 /* oldest code we think can decode this. unknown if zero. */
199 __le16 compat_version
;
201 __le32 crc
; /* header crc32c */
202 } __attribute__ ((packed
));
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 */
211 __le32 data_pre_padding_len
;
212 __le16 data_off
; /* sender: include full offset;
213 receiver: mask against ~PAGE_MASK */
217 /* oldest code we think can decode this. unknown if zero. */
218 __le16 compat_version
;
220 } __attribute__ ((packed
));
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
228 * follows data payload
229 * ceph_msg_footer_old does not support digital signatures on messages PLR
232 struct ceph_msg_footer_old
{
233 __le32 front_crc
, middle_crc
, data_crc
;
235 } __attribute__ ((packed
));
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
242 } __attribute__ ((packed
));
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 */