msgr.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. * client-side processes will try to bind to ports in this
  10. * range, simply for the benefit of tools like nmap or wireshark
  11. * that would like to identify the protocol.
  12. */
  13. #define CEPH_PORT_FIRST 6789
  14. #define CEPH_PORT_START 6800 /* non-monitors start here */
  15. #define CEPH_PORT_LAST 6900
  16. /*
  17. * tcp connection banner. include a protocol version. and adjust
  18. * whenever the wire protocol changes. try to keep this string length
  19. * constant.
  20. */
  21. #define CEPH_BANNER "ceph v027"
  22. #define CEPH_BANNER_MAX_LEN 30
  23. /*
  24. * Rollover-safe type and comparator for 32-bit sequence numbers.
  25. * Comparator returns -1, 0, or 1.
  26. */
  27. typedef __u32 ceph_seq_t;
  28. static inline __s32 ceph_seq_cmp(__u32 a, __u32 b)
  29. {
  30. return (__s32)a - (__s32)b;
  31. }
  32. /*
  33. * entity_name -- logical name for a process participating in the
  34. * network, e.g. 'mds0' or 'osd3'.
  35. */
  36. struct ceph_entity_name {
  37. __u8 type; /* CEPH_ENTITY_TYPE_* */
  38. __le64 num;
  39. } __attribute__ ((packed));
  40. #define CEPH_ENTITY_TYPE_MON 0x01
  41. #define CEPH_ENTITY_TYPE_MDS 0x02
  42. #define CEPH_ENTITY_TYPE_OSD 0x04
  43. #define CEPH_ENTITY_TYPE_CLIENT 0x08
  44. #define CEPH_ENTITY_TYPE_AUTH 0x20
  45. #define CEPH_ENTITY_TYPE_ANY 0xFF
  46. extern const char *ceph_entity_type_name(int type);
  47. /*
  48. * entity_addr -- network address
  49. */
  50. struct ceph_entity_addr {
  51. __le32 type;
  52. __le32 nonce; /* unique id for process (e.g. pid) */
  53. struct sockaddr_storage in_addr;
  54. } __attribute__ ((packed));
  55. struct ceph_entity_inst {
  56. struct ceph_entity_name name;
  57. struct ceph_entity_addr addr;
  58. } __attribute__ ((packed));
  59. /* used by message exchange protocol */
  60. #define CEPH_MSGR_TAG_READY 1 /* server->client: ready for messages */
  61. #define CEPH_MSGR_TAG_RESETSESSION 2 /* server->client: reset, try again */
  62. #define CEPH_MSGR_TAG_WAIT 3 /* server->client: wait for racing
  63. incoming connection */
  64. #define CEPH_MSGR_TAG_RETRY_SESSION 4 /* server->client + cseq: try again
  65. with higher cseq */
  66. #define CEPH_MSGR_TAG_RETRY_GLOBAL 5 /* server->client + gseq: try again
  67. with higher gseq */
  68. #define CEPH_MSGR_TAG_CLOSE 6 /* closing pipe */
  69. #define CEPH_MSGR_TAG_MSG 7 /* message */
  70. #define CEPH_MSGR_TAG_ACK 8 /* message ack */
  71. #define CEPH_MSGR_TAG_KEEPALIVE 9 /* just a keepalive byte! */
  72. #define CEPH_MSGR_TAG_BADPROTOVER 10 /* bad protocol version */
  73. #define CEPH_MSGR_TAG_BADAUTHORIZER 11 /* bad authorizer */
  74. #define CEPH_MSGR_TAG_FEATURES 12 /* insufficient features */
  75. #define CEPH_MSGR_TAG_SEQ 13 /* 64-bit int follows with seen seq number */
  76. #define CEPH_MSGR_TAG_KEEPALIVE2 14 /* keepalive2 byte + ceph_timespec */
  77. #define CEPH_MSGR_TAG_KEEPALIVE2_ACK 15 /* keepalive2 reply */
  78. #define CEPH_MSGR_TAG_CHALLENGE_AUTHORIZER 16 /* cephx v2 doing server challenge */
  79. /*
  80. * connection negotiation
  81. */
  82. struct ceph_msg_connect {
  83. __le64 features; /* supported feature bits */
  84. __le32 host_type; /* CEPH_ENTITY_TYPE_* */
  85. __le32 global_seq; /* count connections initiated by this host */
  86. __le32 connect_seq; /* count connections initiated in this session */
  87. __le32 protocol_version;
  88. __le32 authorizer_protocol;
  89. __le32 authorizer_len;
  90. __u8 flags; /* CEPH_MSG_CONNECT_* */
  91. } __attribute__ ((packed));
  92. struct ceph_msg_connect_reply {
  93. __u8 tag;
  94. __le64 features; /* feature bits for this session */
  95. __le32 global_seq;
  96. __le32 connect_seq;
  97. __le32 protocol_version;
  98. __le32 authorizer_len;
  99. __u8 flags;
  100. } __attribute__ ((packed));
  101. #define CEPH_MSG_CONNECT_LOSSY 1 /* messages i send may be safely dropped */
  102. /*
  103. * message header
  104. */
  105. struct ceph_msg_header_old {
  106. __le64 seq; /* message seq# for this session */
  107. __le64 tid; /* transaction id */
  108. __le16 type; /* message type */
  109. __le16 priority; /* priority. higher value == higher priority */
  110. __le16 version; /* version of message encoding */
  111. __le32 front_len; /* bytes in main payload */
  112. __le32 middle_len;/* bytes in middle payload */
  113. __le32 data_len; /* bytes of data payload */
  114. __le16 data_off; /* sender: include full offset;
  115. receiver: mask against ~PAGE_MASK */
  116. struct ceph_entity_inst src, orig_src;
  117. __le32 reserved;
  118. __le32 crc; /* header crc32c */
  119. } __attribute__ ((packed));
  120. struct ceph_msg_header {
  121. __le64 seq; /* message seq# for this session */
  122. __le64 tid; /* transaction id */
  123. __le16 type; /* message type */
  124. __le16 priority; /* priority. higher value == higher priority */
  125. __le16 version; /* version of message encoding */
  126. __le32 front_len; /* bytes in main payload */
  127. __le32 middle_len;/* bytes in middle payload */
  128. __le32 data_len; /* bytes of data payload */
  129. __le16 data_off; /* sender: include full offset;
  130. receiver: mask against ~PAGE_MASK */
  131. struct ceph_entity_name src;
  132. __le16 compat_version;
  133. __le16 reserved;
  134. __le32 crc; /* header crc32c */
  135. } __attribute__ ((packed));
  136. #define CEPH_MSG_PRIO_LOW 64
  137. #define CEPH_MSG_PRIO_DEFAULT 127
  138. #define CEPH_MSG_PRIO_HIGH 196
  139. #define CEPH_MSG_PRIO_HIGHEST 255
  140. /*
  141. * follows data payload
  142. */
  143. struct ceph_msg_footer_old {
  144. __le32 front_crc, middle_crc, data_crc;
  145. __u8 flags;
  146. } __attribute__ ((packed));
  147. struct ceph_msg_footer {
  148. __le32 front_crc, middle_crc, data_crc;
  149. // sig holds the 64 bits of the digital signature for the message PLR
  150. __le64 sig;
  151. __u8 flags;
  152. } __attribute__ ((packed));
  153. #define CEPH_MSG_FOOTER_COMPLETE (1<<0) /* msg wasn't aborted */
  154. #define CEPH_MSG_FOOTER_NOCRC (1<<1) /* no data crc */
  155. #define CEPH_MSG_FOOTER_SIGNED (1<<2) /* msg was signed */
  156. #endif