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