1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
23d14c5d2SYehuda Sadeh #ifndef CEPH_MSGR_H
33d14c5d2SYehuda Sadeh #define CEPH_MSGR_H
43d14c5d2SYehuda Sadeh
53d14c5d2SYehuda Sadeh /*
63d14c5d2SYehuda Sadeh * Data types for message passing layer used by Ceph.
73d14c5d2SYehuda Sadeh */
83d14c5d2SYehuda Sadeh
93d14c5d2SYehuda Sadeh #define CEPH_MON_PORT 6789 /* default monitor port */
103d14c5d2SYehuda Sadeh
113d14c5d2SYehuda Sadeh /*
123d14c5d2SYehuda Sadeh * tcp connection banner. include a protocol version. and adjust
133d14c5d2SYehuda Sadeh * whenever the wire protocol changes. try to keep this string length
143d14c5d2SYehuda Sadeh * constant.
153d14c5d2SYehuda Sadeh */
163d14c5d2SYehuda Sadeh #define CEPH_BANNER "ceph v027"
17cd1a677cSIlya Dryomov #define CEPH_BANNER_LEN 9
183d14c5d2SYehuda Sadeh #define CEPH_BANNER_MAX_LEN 30
193d14c5d2SYehuda Sadeh
203d14c5d2SYehuda Sadeh
213d14c5d2SYehuda Sadeh /*
22cd1a677cSIlya Dryomov * messenger V2 connection banner prefix.
23cd1a677cSIlya Dryomov * The full banner string should have the form: "ceph v2\n<le16>"
24cd1a677cSIlya Dryomov * the 2 bytes are the length of the remaining banner.
25cd1a677cSIlya Dryomov */
26cd1a677cSIlya Dryomov #define CEPH_BANNER_V2 "ceph v2\n"
27cd1a677cSIlya Dryomov #define CEPH_BANNER_V2_LEN 8
28cd1a677cSIlya Dryomov #define CEPH_BANNER_V2_PREFIX_LEN (CEPH_BANNER_V2_LEN + sizeof(__le16))
29cd1a677cSIlya Dryomov
30cd1a677cSIlya Dryomov /*
31cd1a677cSIlya Dryomov * messenger V2 features
32cd1a677cSIlya Dryomov */
33cd1a677cSIlya Dryomov #define CEPH_MSGR2_INCARNATION_1 (0ull)
34cd1a677cSIlya Dryomov
35cd1a677cSIlya Dryomov #define DEFINE_MSGR2_FEATURE(bit, incarnation, name) \
36*664f1e25SIlya Dryomov static const uint64_t __maybe_unused CEPH_MSGR2_FEATURE_##name = (1ULL << bit); \
37*664f1e25SIlya Dryomov static const uint64_t __maybe_unused CEPH_MSGR2_FEATUREMASK_##name = \
38cd1a677cSIlya Dryomov (1ULL << bit | CEPH_MSGR2_INCARNATION_##incarnation);
39cd1a677cSIlya Dryomov
40cd1a677cSIlya Dryomov #define HAVE_MSGR2_FEATURE(x, name) \
41cd1a677cSIlya Dryomov (((x) & (CEPH_MSGR2_FEATUREMASK_##name)) == (CEPH_MSGR2_FEATUREMASK_##name))
42cd1a677cSIlya Dryomov
43cd1a677cSIlya Dryomov DEFINE_MSGR2_FEATURE( 0, 1, REVISION_1) // msgr2.1
44cd1a677cSIlya Dryomov
45cd1a677cSIlya Dryomov #define CEPH_MSGR2_SUPPORTED_FEATURES (CEPH_MSGR2_FEATURE_REVISION_1)
46cd1a677cSIlya Dryomov
47cd1a677cSIlya Dryomov #define CEPH_MSGR2_REQUIRED_FEATURES (CEPH_MSGR2_FEATURE_REVISION_1)
48cd1a677cSIlya Dryomov
49cd1a677cSIlya Dryomov
50cd1a677cSIlya Dryomov /*
513d14c5d2SYehuda Sadeh * Rollover-safe type and comparator for 32-bit sequence numbers.
523d14c5d2SYehuda Sadeh * Comparator returns -1, 0, or 1.
533d14c5d2SYehuda Sadeh */
543d14c5d2SYehuda Sadeh typedef __u32 ceph_seq_t;
553d14c5d2SYehuda Sadeh
ceph_seq_cmp(__u32 a,__u32 b)563d14c5d2SYehuda Sadeh static inline __s32 ceph_seq_cmp(__u32 a, __u32 b)
573d14c5d2SYehuda Sadeh {
583d14c5d2SYehuda Sadeh return (__s32)a - (__s32)b;
593d14c5d2SYehuda Sadeh }
603d14c5d2SYehuda Sadeh
613d14c5d2SYehuda Sadeh
623d14c5d2SYehuda Sadeh /*
633d14c5d2SYehuda Sadeh * entity_name -- logical name for a process participating in the
643d14c5d2SYehuda Sadeh * network, e.g. 'mds0' or 'osd3'.
653d14c5d2SYehuda Sadeh */
663d14c5d2SYehuda Sadeh struct ceph_entity_name {
673d14c5d2SYehuda Sadeh __u8 type; /* CEPH_ENTITY_TYPE_* */
683d14c5d2SYehuda Sadeh __le64 num;
693d14c5d2SYehuda Sadeh } __attribute__ ((packed));
703d14c5d2SYehuda Sadeh
713d14c5d2SYehuda Sadeh #define CEPH_ENTITY_TYPE_MON 0x01
723d14c5d2SYehuda Sadeh #define CEPH_ENTITY_TYPE_MDS 0x02
733d14c5d2SYehuda Sadeh #define CEPH_ENTITY_TYPE_OSD 0x04
743d14c5d2SYehuda Sadeh #define CEPH_ENTITY_TYPE_CLIENT 0x08
753d14c5d2SYehuda Sadeh #define CEPH_ENTITY_TYPE_AUTH 0x20
763d14c5d2SYehuda Sadeh
773d14c5d2SYehuda Sadeh #define CEPH_ENTITY_TYPE_ANY 0xFF
783d14c5d2SYehuda Sadeh
793d14c5d2SYehuda Sadeh extern const char *ceph_entity_type_name(int type);
803d14c5d2SYehuda Sadeh
813d14c5d2SYehuda Sadeh /*
823d14c5d2SYehuda Sadeh * entity_addr -- network address
833d14c5d2SYehuda Sadeh */
843d14c5d2SYehuda Sadeh struct ceph_entity_addr {
85313771e8SIlya Dryomov __le32 type; /* CEPH_ENTITY_ADDR_TYPE_* */
863d14c5d2SYehuda Sadeh __le32 nonce; /* unique id for process (e.g. pid) */
873d14c5d2SYehuda Sadeh struct sockaddr_storage in_addr;
883d14c5d2SYehuda Sadeh } __attribute__ ((packed));
893d14c5d2SYehuda Sadeh
ceph_addr_equal_no_type(const struct ceph_entity_addr * lhs,const struct ceph_entity_addr * rhs)90313771e8SIlya Dryomov static inline bool ceph_addr_equal_no_type(const struct ceph_entity_addr *lhs,
91313771e8SIlya Dryomov const struct ceph_entity_addr *rhs)
92313771e8SIlya Dryomov {
93313771e8SIlya Dryomov return !memcmp(&lhs->in_addr, &rhs->in_addr, sizeof(lhs->in_addr)) &&
94313771e8SIlya Dryomov lhs->nonce == rhs->nonce;
95313771e8SIlya Dryomov }
96313771e8SIlya Dryomov
973d14c5d2SYehuda Sadeh struct ceph_entity_inst {
983d14c5d2SYehuda Sadeh struct ceph_entity_name name;
993d14c5d2SYehuda Sadeh struct ceph_entity_addr addr;
1003d14c5d2SYehuda Sadeh } __attribute__ ((packed));
1013d14c5d2SYehuda Sadeh
1023d14c5d2SYehuda Sadeh
1033d14c5d2SYehuda Sadeh /* used by message exchange protocol */
1043d14c5d2SYehuda Sadeh #define CEPH_MSGR_TAG_READY 1 /* server->client: ready for messages */
1053d14c5d2SYehuda Sadeh #define CEPH_MSGR_TAG_RESETSESSION 2 /* server->client: reset, try again */
1063d14c5d2SYehuda Sadeh #define CEPH_MSGR_TAG_WAIT 3 /* server->client: wait for racing
1073d14c5d2SYehuda Sadeh incoming connection */
1083d14c5d2SYehuda Sadeh #define CEPH_MSGR_TAG_RETRY_SESSION 4 /* server->client + cseq: try again
1093d14c5d2SYehuda Sadeh with higher cseq */
1103d14c5d2SYehuda Sadeh #define CEPH_MSGR_TAG_RETRY_GLOBAL 5 /* server->client + gseq: try again
1113d14c5d2SYehuda Sadeh with higher gseq */
1123d14c5d2SYehuda Sadeh #define CEPH_MSGR_TAG_CLOSE 6 /* closing pipe */
1133d14c5d2SYehuda Sadeh #define CEPH_MSGR_TAG_MSG 7 /* message */
1143d14c5d2SYehuda Sadeh #define CEPH_MSGR_TAG_ACK 8 /* message ack */
1153d14c5d2SYehuda Sadeh #define CEPH_MSGR_TAG_KEEPALIVE 9 /* just a keepalive byte! */
1163d14c5d2SYehuda Sadeh #define CEPH_MSGR_TAG_BADPROTOVER 10 /* bad protocol version */
1173d14c5d2SYehuda Sadeh #define CEPH_MSGR_TAG_BADAUTHORIZER 11 /* bad authorizer */
1183d14c5d2SYehuda Sadeh #define CEPH_MSGR_TAG_FEATURES 12 /* insufficient features */
1193a23083bSSage Weil #define CEPH_MSGR_TAG_SEQ 13 /* 64-bit int follows with seen seq number */
1208b9558aaSYan, Zheng #define CEPH_MSGR_TAG_KEEPALIVE2 14 /* keepalive2 byte + ceph_timespec */
1218b9558aaSYan, Zheng #define CEPH_MSGR_TAG_KEEPALIVE2_ACK 15 /* keepalive2 reply */
1226daca13dSIlya Dryomov #define CEPH_MSGR_TAG_CHALLENGE_AUTHORIZER 16 /* cephx v2 doing server challenge */
1233d14c5d2SYehuda Sadeh
1243d14c5d2SYehuda Sadeh /*
1253d14c5d2SYehuda Sadeh * connection negotiation
1263d14c5d2SYehuda Sadeh */
1273d14c5d2SYehuda Sadeh struct ceph_msg_connect {
1283d14c5d2SYehuda Sadeh __le64 features; /* supported feature bits */
1293d14c5d2SYehuda Sadeh __le32 host_type; /* CEPH_ENTITY_TYPE_* */
1303d14c5d2SYehuda Sadeh __le32 global_seq; /* count connections initiated by this host */
1313d14c5d2SYehuda Sadeh __le32 connect_seq; /* count connections initiated in this session */
1323d14c5d2SYehuda Sadeh __le32 protocol_version;
1333d14c5d2SYehuda Sadeh __le32 authorizer_protocol;
1343d14c5d2SYehuda Sadeh __le32 authorizer_len;
1353d14c5d2SYehuda Sadeh __u8 flags; /* CEPH_MSG_CONNECT_* */
1363d14c5d2SYehuda Sadeh } __attribute__ ((packed));
1373d14c5d2SYehuda Sadeh
1383d14c5d2SYehuda Sadeh struct ceph_msg_connect_reply {
1393d14c5d2SYehuda Sadeh __u8 tag;
1403d14c5d2SYehuda Sadeh __le64 features; /* feature bits for this session */
1413d14c5d2SYehuda Sadeh __le32 global_seq;
1423d14c5d2SYehuda Sadeh __le32 connect_seq;
1433d14c5d2SYehuda Sadeh __le32 protocol_version;
1443d14c5d2SYehuda Sadeh __le32 authorizer_len;
1453d14c5d2SYehuda Sadeh __u8 flags;
1463d14c5d2SYehuda Sadeh } __attribute__ ((packed));
1473d14c5d2SYehuda Sadeh
1483d14c5d2SYehuda Sadeh #define CEPH_MSG_CONNECT_LOSSY 1 /* messages i send may be safely dropped */
1493d14c5d2SYehuda Sadeh
1503d14c5d2SYehuda Sadeh
1513d14c5d2SYehuda Sadeh /*
1523d14c5d2SYehuda Sadeh * message header
1533d14c5d2SYehuda Sadeh */
1543d14c5d2SYehuda Sadeh struct ceph_msg_header_old {
1553d14c5d2SYehuda Sadeh __le64 seq; /* message seq# for this session */
1563d14c5d2SYehuda Sadeh __le64 tid; /* transaction id */
1573d14c5d2SYehuda Sadeh __le16 type; /* message type */
1583d14c5d2SYehuda Sadeh __le16 priority; /* priority. higher value == higher priority */
1593d14c5d2SYehuda Sadeh __le16 version; /* version of message encoding */
1603d14c5d2SYehuda Sadeh
1613d14c5d2SYehuda Sadeh __le32 front_len; /* bytes in main payload */
1623d14c5d2SYehuda Sadeh __le32 middle_len;/* bytes in middle payload */
1633d14c5d2SYehuda Sadeh __le32 data_len; /* bytes of data payload */
1643d14c5d2SYehuda Sadeh __le16 data_off; /* sender: include full offset;
1653d14c5d2SYehuda Sadeh receiver: mask against ~PAGE_MASK */
1663d14c5d2SYehuda Sadeh
1673d14c5d2SYehuda Sadeh struct ceph_entity_inst src, orig_src;
1683d14c5d2SYehuda Sadeh __le32 reserved;
1693d14c5d2SYehuda Sadeh __le32 crc; /* header crc32c */
1703d14c5d2SYehuda Sadeh } __attribute__ ((packed));
1713d14c5d2SYehuda Sadeh
1723d14c5d2SYehuda Sadeh struct ceph_msg_header {
1733d14c5d2SYehuda Sadeh __le64 seq; /* message seq# for this session */
1743d14c5d2SYehuda Sadeh __le64 tid; /* transaction id */
1753d14c5d2SYehuda Sadeh __le16 type; /* message type */
1763d14c5d2SYehuda Sadeh __le16 priority; /* priority. higher value == higher priority */
1773d14c5d2SYehuda Sadeh __le16 version; /* version of message encoding */
1783d14c5d2SYehuda Sadeh
1793d14c5d2SYehuda Sadeh __le32 front_len; /* bytes in main payload */
1803d14c5d2SYehuda Sadeh __le32 middle_len;/* bytes in middle payload */
1813d14c5d2SYehuda Sadeh __le32 data_len; /* bytes of data payload */
1823d14c5d2SYehuda Sadeh __le16 data_off; /* sender: include full offset;
1833d14c5d2SYehuda Sadeh receiver: mask against ~PAGE_MASK */
1843d14c5d2SYehuda Sadeh
1853d14c5d2SYehuda Sadeh struct ceph_entity_name src;
186d4e1a4e0SJohn Spray __le16 compat_version;
187d4e1a4e0SJohn Spray __le16 reserved;
1883d14c5d2SYehuda Sadeh __le32 crc; /* header crc32c */
1893d14c5d2SYehuda Sadeh } __attribute__ ((packed));
1903d14c5d2SYehuda Sadeh
191cd1a677cSIlya Dryomov struct ceph_msg_header2 {
192cd1a677cSIlya Dryomov __le64 seq; /* message seq# for this session */
193cd1a677cSIlya Dryomov __le64 tid; /* transaction id */
194cd1a677cSIlya Dryomov __le16 type; /* message type */
195cd1a677cSIlya Dryomov __le16 priority; /* priority. higher value == higher priority */
196cd1a677cSIlya Dryomov __le16 version; /* version of message encoding */
197cd1a677cSIlya Dryomov
198cd1a677cSIlya Dryomov __le32 data_pre_padding_len;
199cd1a677cSIlya Dryomov __le16 data_off; /* sender: include full offset;
200cd1a677cSIlya Dryomov receiver: mask against ~PAGE_MASK */
201cd1a677cSIlya Dryomov
202cd1a677cSIlya Dryomov __le64 ack_seq;
203cd1a677cSIlya Dryomov __u8 flags;
204cd1a677cSIlya Dryomov /* oldest code we think can decode this. unknown if zero. */
205cd1a677cSIlya Dryomov __le16 compat_version;
206cd1a677cSIlya Dryomov __le16 reserved;
207cd1a677cSIlya Dryomov } __attribute__ ((packed));
208cd1a677cSIlya Dryomov
2093d14c5d2SYehuda Sadeh #define CEPH_MSG_PRIO_LOW 64
2103d14c5d2SYehuda Sadeh #define CEPH_MSG_PRIO_DEFAULT 127
2113d14c5d2SYehuda Sadeh #define CEPH_MSG_PRIO_HIGH 196
2123d14c5d2SYehuda Sadeh #define CEPH_MSG_PRIO_HIGHEST 255
2133d14c5d2SYehuda Sadeh
2143d14c5d2SYehuda Sadeh /*
2153d14c5d2SYehuda Sadeh * follows data payload
2163d14c5d2SYehuda Sadeh */
21733d07337SYan, Zheng struct ceph_msg_footer_old {
21833d07337SYan, Zheng __le32 front_crc, middle_crc, data_crc;
21933d07337SYan, Zheng __u8 flags;
22033d07337SYan, Zheng } __attribute__ ((packed));
22133d07337SYan, Zheng
2223d14c5d2SYehuda Sadeh struct ceph_msg_footer {
2233d14c5d2SYehuda Sadeh __le32 front_crc, middle_crc, data_crc;
22433d07337SYan, Zheng // sig holds the 64 bits of the digital signature for the message PLR
22533d07337SYan, Zheng __le64 sig;
2263d14c5d2SYehuda Sadeh __u8 flags;
2273d14c5d2SYehuda Sadeh } __attribute__ ((packed));
2283d14c5d2SYehuda Sadeh
2293d14c5d2SYehuda Sadeh #define CEPH_MSG_FOOTER_COMPLETE (1<<0) /* msg wasn't aborted */
2303d14c5d2SYehuda Sadeh #define CEPH_MSG_FOOTER_NOCRC (1<<1) /* no data crc */
23133d07337SYan, Zheng #define CEPH_MSG_FOOTER_SIGNED (1<<2) /* msg was signed */
2323d14c5d2SYehuda Sadeh
2333d14c5d2SYehuda Sadeh
2343d14c5d2SYehuda Sadeh #endif
235