msgr.h 5.5 KB

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