packet.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* packet.h: Rx packet layout and definitions
  2. *
  3. * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #ifndef _LINUX_RXRPC_PACKET_H
  12. #define _LINUX_RXRPC_PACKET_H
  13. typedef u32 rxrpc_seq_t; /* Rx message sequence number */
  14. typedef u32 rxrpc_serial_t; /* Rx message serial number */
  15. typedef __be32 rxrpc_seq_net_t; /* on-the-wire Rx message sequence number */
  16. typedef __be32 rxrpc_serial_net_t; /* on-the-wire Rx message serial number */
  17. /*****************************************************************************/
  18. /*
  19. * on-the-wire Rx packet header
  20. * - all multibyte fields should be in network byte order
  21. */
  22. struct rxrpc_header {
  23. __be32 epoch; /* client boot timestamp */
  24. __be32 cid; /* connection and channel ID */
  25. #define RXRPC_MAXCALLS 4 /* max active calls per conn */
  26. #define RXRPC_CHANNELMASK (RXRPC_MAXCALLS-1) /* mask for channel ID */
  27. #define RXRPC_CIDMASK (~RXRPC_CHANNELMASK) /* mask for connection ID */
  28. #define RXRPC_CIDSHIFT ilog2(RXRPC_MAXCALLS) /* shift for connection ID */
  29. #define RXRPC_CID_INC (1 << RXRPC_CIDSHIFT) /* connection ID increment */
  30. __be32 callNumber; /* call ID (0 for connection-level packets) */
  31. #define RXRPC_PROCESS_MAXCALLS (1<<2) /* maximum number of active calls per conn (power of 2) */
  32. __be32 seq; /* sequence number of pkt in call stream */
  33. __be32 serial; /* serial number of pkt sent to network */
  34. uint8_t type; /* packet type */
  35. #define RXRPC_PACKET_TYPE_DATA 1 /* data */
  36. #define RXRPC_PACKET_TYPE_ACK 2 /* ACK */
  37. #define RXRPC_PACKET_TYPE_BUSY 3 /* call reject */
  38. #define RXRPC_PACKET_TYPE_ABORT 4 /* call/connection abort */
  39. #define RXRPC_PACKET_TYPE_ACKALL 5 /* ACK all outstanding packets on call */
  40. #define RXRPC_PACKET_TYPE_CHALLENGE 6 /* connection security challenge (SRVR->CLNT) */
  41. #define RXRPC_PACKET_TYPE_RESPONSE 7 /* connection secutity response (CLNT->SRVR) */
  42. #define RXRPC_PACKET_TYPE_DEBUG 8 /* debug info request */
  43. #define RXRPC_N_PACKET_TYPES 9 /* number of packet types (incl type 0) */
  44. uint8_t flags; /* packet flags */
  45. #define RXRPC_CLIENT_INITIATED 0x01 /* signifies a packet generated by a client */
  46. #define RXRPC_REQUEST_ACK 0x02 /* request an unconditional ACK of this packet */
  47. #define RXRPC_LAST_PACKET 0x04 /* the last packet from this side for this call */
  48. #define RXRPC_MORE_PACKETS 0x08 /* more packets to come */
  49. #define RXRPC_JUMBO_PACKET 0x20 /* [DATA] this is a jumbo packet */
  50. #define RXRPC_SLOW_START_OK 0x20 /* [ACK] slow start supported */
  51. uint8_t userStatus; /* app-layer defined status */
  52. uint8_t securityIndex; /* security protocol ID */
  53. union {
  54. __be16 _rsvd; /* reserved */
  55. __be16 cksum; /* kerberos security checksum */
  56. };
  57. __be16 serviceId; /* service ID */
  58. } __packed;
  59. #define __rxrpc_header_off(X) offsetof(struct rxrpc_header,X)
  60. extern const char *rxrpc_pkts[];
  61. /*****************************************************************************/
  62. /*
  63. * jumbo packet secondary header
  64. * - can be mapped to read header by:
  65. * - new_serial = serial + 1
  66. * - new_seq = seq + 1
  67. * - new_flags = j_flags
  68. * - new__rsvd = j__rsvd
  69. * - duplicating all other fields
  70. */
  71. struct rxrpc_jumbo_header {
  72. uint8_t flags; /* packet flags (as per rxrpc_header) */
  73. uint8_t pad;
  74. __be16 _rsvd; /* reserved (used by kerberos security as cksum) */
  75. };
  76. #define RXRPC_JUMBO_DATALEN 1412 /* non-terminal jumbo packet data length */
  77. /*****************************************************************************/
  78. /*
  79. * on-the-wire Rx ACK packet data payload
  80. * - all multibyte fields should be in network byte order
  81. */
  82. struct rxrpc_ackpacket {
  83. __be16 bufferSpace; /* number of packet buffers available */
  84. __be16 maxSkew; /* diff between serno being ACK'd and highest serial no
  85. * received */
  86. __be32 firstPacket; /* sequence no of first ACK'd packet in attached list */
  87. __be32 previousPacket; /* sequence no of previous packet received */
  88. __be32 serial; /* serial no of packet that prompted this ACK */
  89. uint8_t reason; /* reason for ACK */
  90. #define RXRPC_ACK_REQUESTED 1 /* ACK was requested on packet */
  91. #define RXRPC_ACK_DUPLICATE 2 /* duplicate packet received */
  92. #define RXRPC_ACK_OUT_OF_SEQUENCE 3 /* out of sequence packet received */
  93. #define RXRPC_ACK_EXCEEDS_WINDOW 4 /* packet received beyond end of ACK window */
  94. #define RXRPC_ACK_NOSPACE 5 /* packet discarded due to lack of buffer space */
  95. #define RXRPC_ACK_PING 6 /* keep alive ACK */
  96. #define RXRPC_ACK_PING_RESPONSE 7 /* response to RXRPC_ACK_PING */
  97. #define RXRPC_ACK_DELAY 8 /* nothing happened since received packet */
  98. #define RXRPC_ACK_IDLE 9 /* ACK due to fully received ACK window */
  99. uint8_t nAcks; /* number of ACKs */
  100. #define RXRPC_MAXACKS 255
  101. uint8_t acks[0]; /* list of ACK/NAKs */
  102. #define RXRPC_ACK_TYPE_NACK 0
  103. #define RXRPC_ACK_TYPE_ACK 1
  104. } __packed;
  105. /*
  106. * ACK packets can have a further piece of information tagged on the end
  107. */
  108. struct rxrpc_ackinfo {
  109. __be32 rxMTU; /* maximum Rx MTU size (bytes) [AFS 3.3] */
  110. __be32 maxMTU; /* maximum interface MTU size (bytes) [AFS 3.3] */
  111. __be32 rwind; /* Rx window size (packets) [AFS 3.4] */
  112. __be32 jumbo_max; /* max packets to stick into a jumbo packet [AFS 3.5] */
  113. };
  114. /*****************************************************************************/
  115. /*
  116. * Kerberos security type-2 challenge packet
  117. */
  118. struct rxkad_challenge {
  119. __be32 version; /* version of this challenge type */
  120. __be32 nonce; /* encrypted random number */
  121. __be32 min_level; /* minimum security level */
  122. __be32 __padding; /* padding to 8-byte boundary */
  123. } __packed;
  124. /*****************************************************************************/
  125. /*
  126. * Kerberos security type-2 response packet
  127. */
  128. struct rxkad_response {
  129. __be32 version; /* version of this response type */
  130. __be32 __pad;
  131. /* encrypted bit of the response */
  132. struct {
  133. __be32 epoch; /* current epoch */
  134. __be32 cid; /* parent connection ID */
  135. __be32 checksum; /* checksum */
  136. __be32 securityIndex; /* security type */
  137. __be32 call_id[4]; /* encrypted call IDs */
  138. __be32 inc_nonce; /* challenge nonce + 1 */
  139. __be32 level; /* desired level */
  140. } encrypted;
  141. __be32 kvno; /* Kerberos key version number */
  142. __be32 ticket_len; /* Kerberos ticket length */
  143. } __packed;
  144. /*****************************************************************************/
  145. /*
  146. * RxRPC-level abort codes
  147. */
  148. #define RX_CALL_DEAD -1 /* call/conn has been inactive and is shut down */
  149. #define RX_INVALID_OPERATION -2 /* invalid operation requested / attempted */
  150. #define RX_CALL_TIMEOUT -3 /* call timeout exceeded */
  151. #define RX_EOF -4 /* unexpected end of data on read op */
  152. #define RX_PROTOCOL_ERROR -5 /* low-level protocol error */
  153. #define RX_USER_ABORT -6 /* generic user abort */
  154. #define RX_ADDRINUSE -7 /* UDP port in use */
  155. #define RX_DEBUGI_BADTYPE -8 /* bad debugging packet type */
  156. /*
  157. * (un)marshalling abort codes (rxgen)
  158. */
  159. #define RXGEN_CC_MARSHAL -450
  160. #define RXGEN_CC_UNMARSHAL -451
  161. #define RXGEN_SS_MARSHAL -452
  162. #define RXGEN_SS_UNMARSHAL -453
  163. #define RXGEN_DECODE -454
  164. #define RXGEN_OPCODE -455
  165. #define RXGEN_SS_XDRFREE -456
  166. #define RXGEN_CC_XDRFREE -457
  167. /*
  168. * Rx kerberos security abort codes
  169. * - unfortunately we have no generalised security abort codes to say things
  170. * like "unsupported security", so we have to use these instead and hope the
  171. * other side understands
  172. */
  173. #define RXKADINCONSISTENCY 19270400 /* security module structure inconsistent */
  174. #define RXKADPACKETSHORT 19270401 /* packet too short for security challenge */
  175. #define RXKADLEVELFAIL 19270402 /* security level negotiation failed */
  176. #define RXKADTICKETLEN 19270403 /* ticket length too short or too long */
  177. #define RXKADOUTOFSEQUENCE 19270404 /* packet had bad sequence number */
  178. #define RXKADNOAUTH 19270405 /* caller not authorised */
  179. #define RXKADBADKEY 19270406 /* illegal key: bad parity or weak */
  180. #define RXKADBADTICKET 19270407 /* security object was passed a bad ticket */
  181. #define RXKADUNKNOWNKEY 19270408 /* ticket contained unknown key version number */
  182. #define RXKADEXPIRED 19270409 /* authentication expired */
  183. #define RXKADSEALEDINCON 19270410 /* sealed data inconsistent */
  184. #define RXKADDATALEN 19270411 /* user data too long */
  185. #define RXKADILLEGALLEVEL 19270412 /* caller not authorised to use encrypted conns */
  186. #endif /* _LINUX_RXRPC_PACKET_H */