rstreason.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef _LINUX_RSTREASON_H
  3. #define _LINUX_RSTREASON_H
  4. #include <net/dropreason-core.h>
  5. #include <uapi/linux/mptcp.h>
  6. #define DEFINE_RST_REASON(FN, FNe) \
  7. FN(NOT_SPECIFIED) \
  8. FN(NO_SOCKET) \
  9. FN(TCP_INVALID_ACK_SEQUENCE) \
  10. FN(TCP_RFC7323_PAWS) \
  11. FN(TCP_TOO_OLD_ACK) \
  12. FN(TCP_ACK_UNSENT_DATA) \
  13. FN(TCP_FLAGS) \
  14. FN(TCP_OLD_ACK) \
  15. FN(TCP_ABORT_ON_DATA) \
  16. FN(TCP_TIMEWAIT_SOCKET) \
  17. FN(INVALID_SYN) \
  18. FN(TCP_ABORT_ON_CLOSE) \
  19. FN(TCP_ABORT_ON_LINGER) \
  20. FN(TCP_ABORT_ON_MEMORY) \
  21. FN(TCP_STATE) \
  22. FN(TCP_KEEPALIVE_TIMEOUT) \
  23. FN(TCP_DISCONNECT_WITH_DATA) \
  24. FN(MPTCP_RST_EUNSPEC) \
  25. FN(MPTCP_RST_EMPTCP) \
  26. FN(MPTCP_RST_ERESOURCE) \
  27. FN(MPTCP_RST_EPROHIBIT) \
  28. FN(MPTCP_RST_EWQ2BIG) \
  29. FN(MPTCP_RST_EBADPERF) \
  30. FN(MPTCP_RST_EMIDDLEBOX) \
  31. FN(ERROR) \
  32. FNe(MAX)
  33. /**
  34. * enum sk_rst_reason - the reasons of socket reset
  35. *
  36. * The reasons of sk reset, which are used in TCP/MPTCP protocols.
  37. *
  38. * There are three parts in order:
  39. * 1) skb drop reasons: relying on drop reasons for such as passive reset
  40. * 2) independent reset reasons: such as active reset reasons
  41. * 3) reset reasons in MPTCP: only for MPTCP use
  42. */
  43. enum sk_rst_reason {
  44. /* Refer to include/net/dropreason-core.h
  45. * Rely on skb drop reasons because it indicates exactly why RST
  46. * could happen.
  47. */
  48. /** @SK_RST_REASON_NOT_SPECIFIED: reset reason is not specified */
  49. SK_RST_REASON_NOT_SPECIFIED,
  50. /** @SK_RST_REASON_NO_SOCKET: no valid socket that can be used */
  51. SK_RST_REASON_NO_SOCKET,
  52. /**
  53. * @SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE: Not acceptable ACK SEQ
  54. * field because ack sequence is not in the window between snd_una
  55. * and snd_nxt
  56. */
  57. SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE,
  58. /**
  59. * @SK_RST_REASON_TCP_RFC7323_PAWS: PAWS check, corresponding to
  60. * LINUX_MIB_PAWSESTABREJECTED, LINUX_MIB_PAWSACTIVEREJECTED
  61. */
  62. SK_RST_REASON_TCP_RFC7323_PAWS,
  63. /** @SK_RST_REASON_TCP_TOO_OLD_ACK: TCP ACK is too old */
  64. SK_RST_REASON_TCP_TOO_OLD_ACK,
  65. /**
  66. * @SK_RST_REASON_TCP_ACK_UNSENT_DATA: TCP ACK for data we haven't
  67. * sent yet
  68. */
  69. SK_RST_REASON_TCP_ACK_UNSENT_DATA,
  70. /** @SK_RST_REASON_TCP_FLAGS: TCP flags invalid */
  71. SK_RST_REASON_TCP_FLAGS,
  72. /** @SK_RST_REASON_TCP_OLD_ACK: TCP ACK is old, but in window */
  73. SK_RST_REASON_TCP_OLD_ACK,
  74. /**
  75. * @SK_RST_REASON_TCP_ABORT_ON_DATA: abort on data
  76. * corresponding to LINUX_MIB_TCPABORTONDATA
  77. */
  78. SK_RST_REASON_TCP_ABORT_ON_DATA,
  79. /* Here start with the independent reasons */
  80. /** @SK_RST_REASON_TCP_TIMEWAIT_SOCKET: happen on the timewait socket */
  81. SK_RST_REASON_TCP_TIMEWAIT_SOCKET,
  82. /**
  83. * @SK_RST_REASON_INVALID_SYN: receive bad syn packet
  84. * RFC 793 says if the state is not CLOSED/LISTEN/SYN-SENT then
  85. * "fourth, check the SYN bit,...If the SYN is in the window it is
  86. * an error, send a reset"
  87. */
  88. SK_RST_REASON_INVALID_SYN,
  89. /**
  90. * @SK_RST_REASON_TCP_ABORT_ON_CLOSE: abort on close
  91. * corresponding to LINUX_MIB_TCPABORTONCLOSE
  92. */
  93. SK_RST_REASON_TCP_ABORT_ON_CLOSE,
  94. /**
  95. * @SK_RST_REASON_TCP_ABORT_ON_LINGER: abort on linger
  96. * corresponding to LINUX_MIB_TCPABORTONLINGER
  97. */
  98. SK_RST_REASON_TCP_ABORT_ON_LINGER,
  99. /**
  100. * @SK_RST_REASON_TCP_ABORT_ON_MEMORY: abort on memory
  101. * corresponding to LINUX_MIB_TCPABORTONMEMORY
  102. */
  103. SK_RST_REASON_TCP_ABORT_ON_MEMORY,
  104. /**
  105. * @SK_RST_REASON_TCP_STATE: abort on tcp state
  106. * Please see RFC 9293 for all possible reset conditions
  107. */
  108. SK_RST_REASON_TCP_STATE,
  109. /**
  110. * @SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT: time to timeout
  111. * When we have already run out of all the chances, which means
  112. * keepalive timeout, we have to reset the connection
  113. */
  114. SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT,
  115. /**
  116. * @SK_RST_REASON_TCP_DISCONNECT_WITH_DATA: disconnect when write
  117. * queue is not empty
  118. * It means user has written data into the write queue when doing
  119. * disconnecting, so we have to send an RST.
  120. */
  121. SK_RST_REASON_TCP_DISCONNECT_WITH_DATA,
  122. /* Copy from include/uapi/linux/mptcp.h.
  123. * These reset fields will not be changed since they adhere to
  124. * RFC 8684. So do not touch them. I'm going to list each definition
  125. * of them respectively.
  126. */
  127. /**
  128. * @SK_RST_REASON_MPTCP_RST_EUNSPEC: Unspecified error.
  129. * This is the default error; it implies that the subflow is no
  130. * longer available. The presence of this option shows that the
  131. * RST was generated by an MPTCP-aware device.
  132. */
  133. SK_RST_REASON_MPTCP_RST_EUNSPEC,
  134. /**
  135. * @SK_RST_REASON_MPTCP_RST_EMPTCP: MPTCP-specific error.
  136. * An error has been detected in the processing of MPTCP options.
  137. * This is the usual reason code to return in the cases where a RST
  138. * is being sent to close a subflow because of an invalid response.
  139. */
  140. SK_RST_REASON_MPTCP_RST_EMPTCP,
  141. /**
  142. * @SK_RST_REASON_MPTCP_RST_ERESOURCE: Lack of resources.
  143. * This code indicates that the sending host does not have enough
  144. * resources to support the terminated subflow.
  145. */
  146. SK_RST_REASON_MPTCP_RST_ERESOURCE,
  147. /**
  148. * @SK_RST_REASON_MPTCP_RST_EPROHIBIT: Administratively prohibited.
  149. * This code indicates that the requested subflow is prohibited by
  150. * the policies of the sending host.
  151. */
  152. SK_RST_REASON_MPTCP_RST_EPROHIBIT,
  153. /**
  154. * @SK_RST_REASON_MPTCP_RST_EWQ2BIG: Too much outstanding data.
  155. * This code indicates that there is an excessive amount of data
  156. * that needs to be transmitted over the terminated subflow while
  157. * having already been acknowledged over one or more other subflows.
  158. * This may occur if a path has been unavailable for a short period
  159. * and it is more efficient to reset and start again than it is to
  160. * retransmit the queued data.
  161. */
  162. SK_RST_REASON_MPTCP_RST_EWQ2BIG,
  163. /**
  164. * @SK_RST_REASON_MPTCP_RST_EBADPERF: Unacceptable performance.
  165. * This code indicates that the performance of this subflow was
  166. * too low compared to the other subflows of this Multipath TCP
  167. * connection.
  168. */
  169. SK_RST_REASON_MPTCP_RST_EBADPERF,
  170. /**
  171. * @SK_RST_REASON_MPTCP_RST_EMIDDLEBOX: Middlebox interference.
  172. * Middlebox interference has been detected over this subflow,
  173. * making MPTCP signaling invalid. For example, this may be sent
  174. * if the checksum does not validate.
  175. */
  176. SK_RST_REASON_MPTCP_RST_EMIDDLEBOX,
  177. /** @SK_RST_REASON_ERROR: unexpected error happens */
  178. SK_RST_REASON_ERROR,
  179. /**
  180. * @SK_RST_REASON_MAX: Maximum of socket reset reasons.
  181. * It shouldn't be used as a real 'reason'.
  182. */
  183. SK_RST_REASON_MAX,
  184. };
  185. /* Convert skb drop reasons to enum sk_rst_reason type */
  186. static inline enum sk_rst_reason
  187. sk_rst_convert_drop_reason(enum skb_drop_reason reason)
  188. {
  189. switch (reason) {
  190. case SKB_DROP_REASON_NOT_SPECIFIED:
  191. return SK_RST_REASON_NOT_SPECIFIED;
  192. case SKB_DROP_REASON_NO_SOCKET:
  193. return SK_RST_REASON_NO_SOCKET;
  194. case SKB_DROP_REASON_TCP_INVALID_ACK_SEQUENCE:
  195. return SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE;
  196. case SKB_DROP_REASON_TCP_RFC7323_PAWS:
  197. return SK_RST_REASON_TCP_RFC7323_PAWS;
  198. case SKB_DROP_REASON_TCP_TOO_OLD_ACK:
  199. return SK_RST_REASON_TCP_TOO_OLD_ACK;
  200. case SKB_DROP_REASON_TCP_ACK_UNSENT_DATA:
  201. return SK_RST_REASON_TCP_ACK_UNSENT_DATA;
  202. case SKB_DROP_REASON_TCP_FLAGS:
  203. return SK_RST_REASON_TCP_FLAGS;
  204. case SKB_DROP_REASON_TCP_OLD_ACK:
  205. return SK_RST_REASON_TCP_OLD_ACK;
  206. case SKB_DROP_REASON_TCP_ABORT_ON_DATA:
  207. return SK_RST_REASON_TCP_ABORT_ON_DATA;
  208. default:
  209. /* If we don't have our own corresponding reason */
  210. return SK_RST_REASON_NOT_SPECIFIED;
  211. }
  212. }
  213. #endif