msgr.h 7.2 KB

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