Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef CEPH_MSGR_H
0003 #define CEPH_MSGR_H
0004 
0005 /*
0006  * Data types for message passing layer used by Ceph.
0007  */
0008 
0009 #define CEPH_MON_PORT    6789  /* default monitor port */
0010 
0011 /*
0012  * tcp connection banner.  include a protocol version. and adjust
0013  * whenever the wire protocol changes.  try to keep this string length
0014  * constant.
0015  */
0016 #define CEPH_BANNER "ceph v027"
0017 #define CEPH_BANNER_LEN 9
0018 #define CEPH_BANNER_MAX_LEN 30
0019 
0020 
0021 /*
0022  * messenger V2 connection banner prefix.
0023  * The full banner string should have the form: "ceph v2\n<le16>"
0024  * the 2 bytes are the length of the remaining banner.
0025  */
0026 #define CEPH_BANNER_V2 "ceph v2\n"
0027 #define CEPH_BANNER_V2_LEN 8
0028 #define CEPH_BANNER_V2_PREFIX_LEN (CEPH_BANNER_V2_LEN + sizeof(__le16))
0029 
0030 /*
0031  * messenger V2 features
0032  */
0033 #define CEPH_MSGR2_INCARNATION_1 (0ull)
0034 
0035 #define DEFINE_MSGR2_FEATURE(bit, incarnation, name)               \
0036     static const uint64_t __maybe_unused CEPH_MSGR2_FEATURE_##name = (1ULL << bit); \
0037     static const uint64_t __maybe_unused CEPH_MSGR2_FEATUREMASK_##name =            \
0038             (1ULL << bit | CEPH_MSGR2_INCARNATION_##incarnation);
0039 
0040 #define HAVE_MSGR2_FEATURE(x, name) \
0041     (((x) & (CEPH_MSGR2_FEATUREMASK_##name)) == (CEPH_MSGR2_FEATUREMASK_##name))
0042 
0043 DEFINE_MSGR2_FEATURE( 0, 1, REVISION_1)   // msgr2.1
0044 
0045 #define CEPH_MSGR2_SUPPORTED_FEATURES (CEPH_MSGR2_FEATURE_REVISION_1)
0046 
0047 #define CEPH_MSGR2_REQUIRED_FEATURES  (CEPH_MSGR2_FEATURE_REVISION_1)
0048 
0049 
0050 /*
0051  * Rollover-safe type and comparator for 32-bit sequence numbers.
0052  * Comparator returns -1, 0, or 1.
0053  */
0054 typedef __u32 ceph_seq_t;
0055 
0056 static inline __s32 ceph_seq_cmp(__u32 a, __u32 b)
0057 {
0058        return (__s32)a - (__s32)b;
0059 }
0060 
0061 
0062 /*
0063  * entity_name -- logical name for a process participating in the
0064  * network, e.g. 'mds0' or 'osd3'.
0065  */
0066 struct ceph_entity_name {
0067     __u8 type;      /* CEPH_ENTITY_TYPE_* */
0068     __le64 num;
0069 } __attribute__ ((packed));
0070 
0071 #define CEPH_ENTITY_TYPE_MON    0x01
0072 #define CEPH_ENTITY_TYPE_MDS    0x02
0073 #define CEPH_ENTITY_TYPE_OSD    0x04
0074 #define CEPH_ENTITY_TYPE_CLIENT 0x08
0075 #define CEPH_ENTITY_TYPE_AUTH   0x20
0076 
0077 #define CEPH_ENTITY_TYPE_ANY    0xFF
0078 
0079 extern const char *ceph_entity_type_name(int type);
0080 
0081 /*
0082  * entity_addr -- network address
0083  */
0084 struct ceph_entity_addr {
0085     __le32 type;  /* CEPH_ENTITY_ADDR_TYPE_* */
0086     __le32 nonce;  /* unique id for process (e.g. pid) */
0087     struct sockaddr_storage in_addr;
0088 } __attribute__ ((packed));
0089 
0090 static inline bool ceph_addr_equal_no_type(const struct ceph_entity_addr *lhs,
0091                        const struct ceph_entity_addr *rhs)
0092 {
0093     return !memcmp(&lhs->in_addr, &rhs->in_addr, sizeof(lhs->in_addr)) &&
0094            lhs->nonce == rhs->nonce;
0095 }
0096 
0097 struct ceph_entity_inst {
0098     struct ceph_entity_name name;
0099     struct ceph_entity_addr addr;
0100 } __attribute__ ((packed));
0101 
0102 
0103 /* used by message exchange protocol */
0104 #define CEPH_MSGR_TAG_READY         1  /* server->client: ready for messages */
0105 #define CEPH_MSGR_TAG_RESETSESSION  2  /* server->client: reset, try again */
0106 #define CEPH_MSGR_TAG_WAIT          3  /* server->client: wait for racing
0107                       incoming connection */
0108 #define CEPH_MSGR_TAG_RETRY_SESSION 4  /* server->client + cseq: try again
0109                       with higher cseq */
0110 #define CEPH_MSGR_TAG_RETRY_GLOBAL  5  /* server->client + gseq: try again
0111                       with higher gseq */
0112 #define CEPH_MSGR_TAG_CLOSE         6  /* closing pipe */
0113 #define CEPH_MSGR_TAG_MSG           7  /* message */
0114 #define CEPH_MSGR_TAG_ACK           8  /* message ack */
0115 #define CEPH_MSGR_TAG_KEEPALIVE     9  /* just a keepalive byte! */
0116 #define CEPH_MSGR_TAG_BADPROTOVER   10 /* bad protocol version */
0117 #define CEPH_MSGR_TAG_BADAUTHORIZER 11 /* bad authorizer */
0118 #define CEPH_MSGR_TAG_FEATURES      12 /* insufficient features */
0119 #define CEPH_MSGR_TAG_SEQ           13 /* 64-bit int follows with seen seq number */
0120 #define CEPH_MSGR_TAG_KEEPALIVE2    14 /* keepalive2 byte + ceph_timespec */
0121 #define CEPH_MSGR_TAG_KEEPALIVE2_ACK 15 /* keepalive2 reply */
0122 #define CEPH_MSGR_TAG_CHALLENGE_AUTHORIZER 16  /* cephx v2 doing server challenge */
0123 
0124 /*
0125  * connection negotiation
0126  */
0127 struct ceph_msg_connect {
0128     __le64 features;     /* supported feature bits */
0129     __le32 host_type;    /* CEPH_ENTITY_TYPE_* */
0130     __le32 global_seq;   /* count connections initiated by this host */
0131     __le32 connect_seq;  /* count connections initiated in this session */
0132     __le32 protocol_version;
0133     __le32 authorizer_protocol;
0134     __le32 authorizer_len;
0135     __u8  flags;         /* CEPH_MSG_CONNECT_* */
0136 } __attribute__ ((packed));
0137 
0138 struct ceph_msg_connect_reply {
0139     __u8 tag;
0140     __le64 features;     /* feature bits for this session */
0141     __le32 global_seq;
0142     __le32 connect_seq;
0143     __le32 protocol_version;
0144     __le32 authorizer_len;
0145     __u8 flags;
0146 } __attribute__ ((packed));
0147 
0148 #define CEPH_MSG_CONNECT_LOSSY  1  /* messages i send may be safely dropped */
0149 
0150 
0151 /*
0152  * message header
0153  */
0154 struct ceph_msg_header_old {
0155     __le64 seq;       /* message seq# for this session */
0156     __le64 tid;       /* transaction id */
0157     __le16 type;      /* message type */
0158     __le16 priority;  /* priority.  higher value == higher priority */
0159     __le16 version;   /* version of message encoding */
0160 
0161     __le32 front_len; /* bytes in main payload */
0162     __le32 middle_len;/* bytes in middle payload */
0163     __le32 data_len;  /* bytes of data payload */
0164     __le16 data_off;  /* sender: include full offset;
0165                  receiver: mask against ~PAGE_MASK */
0166 
0167     struct ceph_entity_inst src, orig_src;
0168     __le32 reserved;
0169     __le32 crc;       /* header crc32c */
0170 } __attribute__ ((packed));
0171 
0172 struct ceph_msg_header {
0173     __le64 seq;       /* message seq# for this session */
0174     __le64 tid;       /* transaction id */
0175     __le16 type;      /* message type */
0176     __le16 priority;  /* priority.  higher value == higher priority */
0177     __le16 version;   /* version of message encoding */
0178 
0179     __le32 front_len; /* bytes in main payload */
0180     __le32 middle_len;/* bytes in middle payload */
0181     __le32 data_len;  /* bytes of data payload */
0182     __le16 data_off;  /* sender: include full offset;
0183                  receiver: mask against ~PAGE_MASK */
0184 
0185     struct ceph_entity_name src;
0186     __le16 compat_version;
0187     __le16 reserved;
0188     __le32 crc;       /* header crc32c */
0189 } __attribute__ ((packed));
0190 
0191 struct ceph_msg_header2 {
0192     __le64 seq;       /* message seq# for this session */
0193     __le64 tid;       /* transaction id */
0194     __le16 type;      /* message type */
0195     __le16 priority;  /* priority.  higher value == higher priority */
0196     __le16 version;   /* version of message encoding */
0197 
0198     __le32 data_pre_padding_len;
0199     __le16 data_off;  /* sender: include full offset;
0200                  receiver: mask against ~PAGE_MASK */
0201 
0202     __le64 ack_seq;
0203     __u8 flags;
0204     /* oldest code we think can decode this.  unknown if zero. */
0205     __le16 compat_version;
0206     __le16 reserved;
0207 } __attribute__ ((packed));
0208 
0209 #define CEPH_MSG_PRIO_LOW     64
0210 #define CEPH_MSG_PRIO_DEFAULT 127
0211 #define CEPH_MSG_PRIO_HIGH    196
0212 #define CEPH_MSG_PRIO_HIGHEST 255
0213 
0214 /*
0215  * follows data payload
0216  */
0217 struct ceph_msg_footer_old {
0218     __le32 front_crc, middle_crc, data_crc;
0219     __u8 flags;
0220 } __attribute__ ((packed));
0221 
0222 struct ceph_msg_footer {
0223     __le32 front_crc, middle_crc, data_crc;
0224     // sig holds the 64 bits of the digital signature for the message PLR
0225     __le64  sig;
0226     __u8 flags;
0227 } __attribute__ ((packed));
0228 
0229 #define CEPH_MSG_FOOTER_COMPLETE  (1<<0)   /* msg wasn't aborted */
0230 #define CEPH_MSG_FOOTER_NOCRC     (1<<1)   /* no data crc */
0231 #define CEPH_MSG_FOOTER_SIGNED    (1<<2)   /* msg was signed */
0232 
0233 
0234 #endif