tcp.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #undef TRACE_SYSTEM
  3. #define TRACE_SYSTEM tcp
  4. #if !defined(_TRACE_TCP_H) || defined(TRACE_HEADER_MULTI_READ)
  5. #define _TRACE_TCP_H
  6. #include <linux/ipv6.h>
  7. #include <linux/tcp.h>
  8. #include <linux/tracepoint.h>
  9. #include <net/ipv6.h>
  10. #include <net/tcp.h>
  11. #include <linux/sock_diag.h>
  12. #define TP_STORE_V4MAPPED(__entry, saddr, daddr) \
  13. do { \
  14. struct in6_addr *pin6; \
  15. \
  16. pin6 = (struct in6_addr *)__entry->saddr_v6; \
  17. ipv6_addr_set_v4mapped(saddr, pin6); \
  18. pin6 = (struct in6_addr *)__entry->daddr_v6; \
  19. ipv6_addr_set_v4mapped(daddr, pin6); \
  20. } while (0)
  21. #if IS_ENABLED(CONFIG_IPV6)
  22. #define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6) \
  23. do { \
  24. if (sk->sk_family == AF_INET6) { \
  25. struct in6_addr *pin6; \
  26. \
  27. pin6 = (struct in6_addr *)__entry->saddr_v6; \
  28. *pin6 = saddr6; \
  29. pin6 = (struct in6_addr *)__entry->daddr_v6; \
  30. *pin6 = daddr6; \
  31. } else { \
  32. TP_STORE_V4MAPPED(__entry, saddr, daddr); \
  33. } \
  34. } while (0)
  35. #else
  36. #define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6) \
  37. TP_STORE_V4MAPPED(__entry, saddr, daddr)
  38. #endif
  39. /*
  40. * tcp event with arguments sk and skb
  41. *
  42. * Note: this class requires a valid sk pointer; while skb pointer could
  43. * be NULL.
  44. */
  45. DECLARE_EVENT_CLASS(tcp_event_sk_skb,
  46. TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
  47. TP_ARGS(sk, skb),
  48. TP_STRUCT__entry(
  49. __field(const void *, skbaddr)
  50. __field(const void *, skaddr)
  51. __field(__u16, sport)
  52. __field(__u16, dport)
  53. __array(__u8, saddr, 4)
  54. __array(__u8, daddr, 4)
  55. __array(__u8, saddr_v6, 16)
  56. __array(__u8, daddr_v6, 16)
  57. ),
  58. TP_fast_assign(
  59. struct inet_sock *inet = inet_sk(sk);
  60. __be32 *p32;
  61. __entry->skbaddr = skb;
  62. __entry->skaddr = sk;
  63. __entry->sport = ntohs(inet->inet_sport);
  64. __entry->dport = ntohs(inet->inet_dport);
  65. p32 = (__be32 *) __entry->saddr;
  66. *p32 = inet->inet_saddr;
  67. p32 = (__be32 *) __entry->daddr;
  68. *p32 = inet->inet_daddr;
  69. TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr,
  70. sk->sk_v6_rcv_saddr, sk->sk_v6_daddr);
  71. ),
  72. TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
  73. __entry->sport, __entry->dport, __entry->saddr, __entry->daddr,
  74. __entry->saddr_v6, __entry->daddr_v6)
  75. );
  76. DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb,
  77. TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
  78. TP_ARGS(sk, skb)
  79. );
  80. /*
  81. * skb of trace_tcp_send_reset is the skb that caused RST. In case of
  82. * active reset, skb should be NULL
  83. */
  84. DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset,
  85. TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
  86. TP_ARGS(sk, skb)
  87. );
  88. /*
  89. * tcp event with arguments sk
  90. *
  91. * Note: this class requires a valid sk pointer.
  92. */
  93. DECLARE_EVENT_CLASS(tcp_event_sk,
  94. TP_PROTO(struct sock *sk),
  95. TP_ARGS(sk),
  96. TP_STRUCT__entry(
  97. __field(const void *, skaddr)
  98. __field(__u16, sport)
  99. __field(__u16, dport)
  100. __array(__u8, saddr, 4)
  101. __array(__u8, daddr, 4)
  102. __array(__u8, saddr_v6, 16)
  103. __array(__u8, daddr_v6, 16)
  104. __field(__u64, sock_cookie)
  105. ),
  106. TP_fast_assign(
  107. struct inet_sock *inet = inet_sk(sk);
  108. __be32 *p32;
  109. __entry->skaddr = sk;
  110. __entry->sport = ntohs(inet->inet_sport);
  111. __entry->dport = ntohs(inet->inet_dport);
  112. p32 = (__be32 *) __entry->saddr;
  113. *p32 = inet->inet_saddr;
  114. p32 = (__be32 *) __entry->daddr;
  115. *p32 = inet->inet_daddr;
  116. TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr,
  117. sk->sk_v6_rcv_saddr, sk->sk_v6_daddr);
  118. __entry->sock_cookie = sock_gen_cookie(sk);
  119. ),
  120. TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c sock_cookie=%llx",
  121. __entry->sport, __entry->dport,
  122. __entry->saddr, __entry->daddr,
  123. __entry->saddr_v6, __entry->daddr_v6,
  124. __entry->sock_cookie)
  125. );
  126. DEFINE_EVENT(tcp_event_sk, tcp_receive_reset,
  127. TP_PROTO(struct sock *sk),
  128. TP_ARGS(sk)
  129. );
  130. DEFINE_EVENT(tcp_event_sk, tcp_destroy_sock,
  131. TP_PROTO(struct sock *sk),
  132. TP_ARGS(sk)
  133. );
  134. DEFINE_EVENT(tcp_event_sk, tcp_rcv_space_adjust,
  135. TP_PROTO(struct sock *sk),
  136. TP_ARGS(sk)
  137. );
  138. TRACE_EVENT(tcp_retransmit_synack,
  139. TP_PROTO(const struct sock *sk, const struct request_sock *req),
  140. TP_ARGS(sk, req),
  141. TP_STRUCT__entry(
  142. __field(const void *, skaddr)
  143. __field(const void *, req)
  144. __field(__u16, sport)
  145. __field(__u16, dport)
  146. __array(__u8, saddr, 4)
  147. __array(__u8, daddr, 4)
  148. __array(__u8, saddr_v6, 16)
  149. __array(__u8, daddr_v6, 16)
  150. ),
  151. TP_fast_assign(
  152. struct inet_request_sock *ireq = inet_rsk(req);
  153. __be32 *p32;
  154. __entry->skaddr = sk;
  155. __entry->req = req;
  156. __entry->sport = ireq->ir_num;
  157. __entry->dport = ntohs(ireq->ir_rmt_port);
  158. p32 = (__be32 *) __entry->saddr;
  159. *p32 = ireq->ir_loc_addr;
  160. p32 = (__be32 *) __entry->daddr;
  161. *p32 = ireq->ir_rmt_addr;
  162. TP_STORE_ADDRS(__entry, ireq->ir_loc_addr, ireq->ir_rmt_addr,
  163. ireq->ir_v6_loc_addr, ireq->ir_v6_rmt_addr);
  164. ),
  165. TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
  166. __entry->sport, __entry->dport,
  167. __entry->saddr, __entry->daddr,
  168. __entry->saddr_v6, __entry->daddr_v6)
  169. );
  170. #include <trace/events/net_probe_common.h>
  171. TRACE_EVENT(tcp_probe,
  172. TP_PROTO(struct sock *sk, struct sk_buff *skb),
  173. TP_ARGS(sk, skb),
  174. TP_STRUCT__entry(
  175. /* sockaddr_in6 is always bigger than sockaddr_in */
  176. __array(__u8, saddr, sizeof(struct sockaddr_in6))
  177. __array(__u8, daddr, sizeof(struct sockaddr_in6))
  178. __field(__u16, sport)
  179. __field(__u16, dport)
  180. __field(__u32, mark)
  181. __field(__u16, data_len)
  182. __field(__u32, snd_nxt)
  183. __field(__u32, snd_una)
  184. __field(__u32, snd_cwnd)
  185. __field(__u32, ssthresh)
  186. __field(__u32, snd_wnd)
  187. __field(__u32, srtt)
  188. __field(__u32, rcv_wnd)
  189. __field(__u64, sock_cookie)
  190. ),
  191. TP_fast_assign(
  192. const struct tcphdr *th = (const struct tcphdr *)skb->data;
  193. const struct inet_sock *inet = inet_sk(sk);
  194. const struct tcp_sock *tp = tcp_sk(sk);
  195. memset(__entry->saddr, 0, sizeof(struct sockaddr_in6));
  196. memset(__entry->daddr, 0, sizeof(struct sockaddr_in6));
  197. TP_STORE_ADDR_PORTS(__entry, inet, sk);
  198. /* For filtering use */
  199. __entry->sport = ntohs(inet->inet_sport);
  200. __entry->dport = ntohs(inet->inet_dport);
  201. __entry->mark = skb->mark;
  202. __entry->data_len = skb->len - __tcp_hdrlen(th);
  203. __entry->snd_nxt = tp->snd_nxt;
  204. __entry->snd_una = tp->snd_una;
  205. __entry->snd_cwnd = tp->snd_cwnd;
  206. __entry->snd_wnd = tp->snd_wnd;
  207. __entry->rcv_wnd = tp->rcv_wnd;
  208. __entry->ssthresh = tcp_current_ssthresh(sk);
  209. __entry->srtt = tp->srtt_us >> 3;
  210. __entry->sock_cookie = sock_gen_cookie(sk);
  211. ),
  212. TP_printk("src=%pISpc dest=%pISpc mark=%#x data_len=%d snd_nxt=%#x snd_una=%#x snd_cwnd=%u ssthresh=%u snd_wnd=%u srtt=%u rcv_wnd=%u sock_cookie=%llx",
  213. __entry->saddr, __entry->daddr, __entry->mark,
  214. __entry->data_len, __entry->snd_nxt, __entry->snd_una,
  215. __entry->snd_cwnd, __entry->ssthresh, __entry->snd_wnd,
  216. __entry->srtt, __entry->rcv_wnd, __entry->sock_cookie)
  217. );
  218. #endif /* _TRACE_TCP_H */
  219. /* This part must be outside protection */
  220. #include <trace/define_trace.h>