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