Sage Weil | 0dee3c2 | 2009-10-06 11:31:06 -0700 | [diff] [blame] | 1 | #ifndef __MSGR_H |
| 2 | #define __MSGR_H |
| 3 | |
| 4 | /* |
| 5 | * Data types for message passing layer used by Ceph. |
| 6 | */ |
| 7 | |
| 8 | #define CEPH_MON_PORT 6789 /* default monitor port */ |
| 9 | |
| 10 | /* |
| 11 | * client-side processes will try to bind to ports in this |
| 12 | * range, simply for the benefit of tools like nmap or wireshark |
| 13 | * that would like to identify the protocol. |
| 14 | */ |
| 15 | #define CEPH_PORT_FIRST 6789 |
| 16 | #define CEPH_PORT_START 6800 /* non-monitors start here */ |
| 17 | #define CEPH_PORT_LAST 6900 |
| 18 | |
| 19 | /* |
| 20 | * tcp connection banner. include a protocol version. and adjust |
| 21 | * whenever the wire protocol changes. try to keep this string length |
| 22 | * constant. |
| 23 | */ |
Sage Weil | 6df058c | 2009-12-22 11:24:33 -0800 | [diff] [blame^] | 24 | #define CEPH_BANNER "ceph v025" |
Sage Weil | 0dee3c2 | 2009-10-06 11:31:06 -0700 | [diff] [blame] | 25 | #define CEPH_BANNER_MAX_LEN 30 |
| 26 | |
| 27 | |
| 28 | /* |
| 29 | * Rollover-safe type and comparator for 32-bit sequence numbers. |
| 30 | * Comparator returns -1, 0, or 1. |
| 31 | */ |
| 32 | typedef __u32 ceph_seq_t; |
| 33 | |
| 34 | static inline __s32 ceph_seq_cmp(__u32 a, __u32 b) |
| 35 | { |
| 36 | return (__s32)a - (__s32)b; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | /* |
| 41 | * entity_name -- logical name for a process participating in the |
| 42 | * network, e.g. 'mds0' or 'osd3'. |
| 43 | */ |
| 44 | struct ceph_entity_name { |
| 45 | __u8 type; /* CEPH_ENTITY_TYPE_* */ |
| 46 | __le64 num; |
| 47 | } __attribute__ ((packed)); |
| 48 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 49 | #define CEPH_ENTITY_TYPE_MON 0x01 |
| 50 | #define CEPH_ENTITY_TYPE_MDS 0x02 |
| 51 | #define CEPH_ENTITY_TYPE_OSD 0x04 |
| 52 | #define CEPH_ENTITY_TYPE_CLIENT 0x08 |
| 53 | #define CEPH_ENTITY_TYPE_ADMIN 0x10 |
| 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); |
Sage Weil | 0dee3c2 | 2009-10-06 11:31:06 -0700 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * entity_addr -- network address |
| 62 | */ |
| 63 | struct ceph_entity_addr { |
| 64 | __le32 erank; /* entity's rank in process */ |
| 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_entity_addr_is_local(const struct ceph_entity_addr *a, |
| 70 | const struct ceph_entity_addr *b) |
| 71 | { |
| 72 | return a->nonce == b->nonce && |
| 73 | memcmp(&a->in_addr, &b->in_addr, sizeof(a->in_addr)) == 0; |
| 74 | } |
| 75 | |
| 76 | static inline bool ceph_entity_addr_equal(const struct ceph_entity_addr *a, |
| 77 | const struct ceph_entity_addr *b) |
| 78 | { |
| 79 | return memcmp(a, b, sizeof(*a)) == 0; |
| 80 | } |
| 81 | |
| 82 | struct ceph_entity_inst { |
| 83 | struct ceph_entity_name name; |
| 84 | struct ceph_entity_addr addr; |
| 85 | } __attribute__ ((packed)); |
| 86 | |
| 87 | |
| 88 | /* used by message exchange protocol */ |
| 89 | #define CEPH_MSGR_TAG_READY 1 /* server->client: ready for messages */ |
| 90 | #define CEPH_MSGR_TAG_RESETSESSION 2 /* server->client: reset, try again */ |
| 91 | #define CEPH_MSGR_TAG_WAIT 3 /* server->client: wait for racing |
| 92 | incoming connection */ |
| 93 | #define CEPH_MSGR_TAG_RETRY_SESSION 4 /* server->client + cseq: try again |
| 94 | with higher cseq */ |
| 95 | #define CEPH_MSGR_TAG_RETRY_GLOBAL 5 /* server->client + gseq: try again |
| 96 | with higher gseq */ |
| 97 | #define CEPH_MSGR_TAG_CLOSE 6 /* closing pipe */ |
| 98 | #define CEPH_MSGR_TAG_MSG 7 /* message */ |
| 99 | #define CEPH_MSGR_TAG_ACK 8 /* message ack */ |
| 100 | #define CEPH_MSGR_TAG_KEEPALIVE 9 /* just a keepalive byte! */ |
| 101 | #define CEPH_MSGR_TAG_BADPROTOVER 10 /* bad protocol version */ |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 102 | #define CEPH_MSGR_TAG_BADAUTHORIZER 11 /* bad authorizer */ |
Sage Weil | 0dee3c2 | 2009-10-06 11:31:06 -0700 | [diff] [blame] | 103 | |
| 104 | |
| 105 | /* |
| 106 | * connection negotiation |
| 107 | */ |
| 108 | struct ceph_msg_connect { |
| 109 | __le32 host_type; /* CEPH_ENTITY_TYPE_* */ |
| 110 | __le32 global_seq; /* count connections initiated by this host */ |
| 111 | __le32 connect_seq; /* count connections initiated in this session */ |
| 112 | __le32 protocol_version; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 113 | __le32 authorizer_protocol; |
| 114 | __le32 authorizer_len; |
Sage Weil | 0dee3c2 | 2009-10-06 11:31:06 -0700 | [diff] [blame] | 115 | __u8 flags; /* CEPH_MSG_CONNECT_* */ |
| 116 | } __attribute__ ((packed)); |
| 117 | |
| 118 | struct ceph_msg_connect_reply { |
| 119 | __u8 tag; |
| 120 | __le32 global_seq; |
| 121 | __le32 connect_seq; |
| 122 | __le32 protocol_version; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 123 | __le32 authorizer_len; |
Sage Weil | 0dee3c2 | 2009-10-06 11:31:06 -0700 | [diff] [blame] | 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 { |
| 134 | __le64 seq; /* message seq# for this session */ |
Sage Weil | 6df058c | 2009-12-22 11:24:33 -0800 | [diff] [blame^] | 135 | __le64 tid; /* transaction id */ |
Sage Weil | 0dee3c2 | 2009-10-06 11:31:06 -0700 | [diff] [blame] | 136 | __le16 type; /* message type */ |
| 137 | __le16 priority; /* priority. higher value == higher priority */ |
Sage Weil | 535bbb5 | 2009-10-13 12:55:26 -0700 | [diff] [blame] | 138 | __le16 version; /* version of message encoding */ |
Sage Weil | 0dee3c2 | 2009-10-06 11:31:06 -0700 | [diff] [blame] | 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 dst_erank; |
| 148 | __le32 crc; /* header crc32c */ |
| 149 | } __attribute__ ((packed)); |
| 150 | |
| 151 | #define CEPH_MSG_PRIO_LOW 64 |
| 152 | #define CEPH_MSG_PRIO_DEFAULT 127 |
| 153 | #define CEPH_MSG_PRIO_HIGH 196 |
| 154 | #define CEPH_MSG_PRIO_HIGHEST 255 |
| 155 | |
| 156 | /* |
| 157 | * follows data payload |
| 158 | */ |
| 159 | struct ceph_msg_footer { |
| 160 | __le32 front_crc, middle_crc, data_crc; |
| 161 | __u8 flags; |
| 162 | } __attribute__ ((packed)); |
| 163 | |
| 164 | #define CEPH_MSG_FOOTER_COMPLETE (1<<0) /* msg wasn't aborted */ |
| 165 | #define CEPH_MSG_FOOTER_NOCRC (1<<1) /* no data crc */ |
| 166 | |
| 167 | |
| 168 | #endif |