sock.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #undef TRACE_SYSTEM
  3. #define TRACE_SYSTEM sock
  4. #if !defined(_TRACE_SOCK_H) || defined(TRACE_HEADER_MULTI_READ)
  5. #define _TRACE_SOCK_H
  6. #include <net/sock.h>
  7. #include <net/ipv6.h>
  8. #include <linux/tracepoint.h>
  9. #include <linux/ipv6.h>
  10. #include <linux/tcp.h>
  11. #define family_names \
  12. EM(AF_INET) \
  13. EMe(AF_INET6)
  14. /* The protocol traced by inet_sock_set_state */
  15. #define inet_protocol_names \
  16. EM(IPPROTO_TCP) \
  17. EM(IPPROTO_DCCP) \
  18. EMe(IPPROTO_SCTP)
  19. #define tcp_state_names \
  20. EM(TCP_ESTABLISHED) \
  21. EM(TCP_SYN_SENT) \
  22. EM(TCP_SYN_RECV) \
  23. EM(TCP_FIN_WAIT1) \
  24. EM(TCP_FIN_WAIT2) \
  25. EM(TCP_TIME_WAIT) \
  26. EM(TCP_CLOSE) \
  27. EM(TCP_CLOSE_WAIT) \
  28. EM(TCP_LAST_ACK) \
  29. EM(TCP_LISTEN) \
  30. EM(TCP_CLOSING) \
  31. EMe(TCP_NEW_SYN_RECV)
  32. #define skmem_kind_names \
  33. EM(SK_MEM_SEND) \
  34. EMe(SK_MEM_RECV)
  35. /* enums need to be exported to user space */
  36. #undef EM
  37. #undef EMe
  38. #define EM(a) TRACE_DEFINE_ENUM(a);
  39. #define EMe(a) TRACE_DEFINE_ENUM(a);
  40. family_names
  41. inet_protocol_names
  42. tcp_state_names
  43. skmem_kind_names
  44. #undef EM
  45. #undef EMe
  46. #define EM(a) { a, #a },
  47. #define EMe(a) { a, #a }
  48. #define show_family_name(val) \
  49. __print_symbolic(val, family_names)
  50. #define show_inet_protocol_name(val) \
  51. __print_symbolic(val, inet_protocol_names)
  52. #define show_tcp_state_name(val) \
  53. __print_symbolic(val, tcp_state_names)
  54. #define show_skmem_kind_names(val) \
  55. __print_symbolic(val, skmem_kind_names)
  56. TRACE_EVENT(sock_rcvqueue_full,
  57. TP_PROTO(struct sock *sk, struct sk_buff *skb),
  58. TP_ARGS(sk, skb),
  59. TP_STRUCT__entry(
  60. __field(int, rmem_alloc)
  61. __field(unsigned int, truesize)
  62. __field(int, sk_rcvbuf)
  63. ),
  64. TP_fast_assign(
  65. __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
  66. __entry->truesize = skb->truesize;
  67. __entry->sk_rcvbuf = sk->sk_rcvbuf;
  68. ),
  69. TP_printk("rmem_alloc=%d truesize=%u sk_rcvbuf=%d",
  70. __entry->rmem_alloc, __entry->truesize, __entry->sk_rcvbuf)
  71. );
  72. TRACE_EVENT(sock_exceed_buf_limit,
  73. TP_PROTO(struct sock *sk, struct proto *prot, long allocated, int kind),
  74. TP_ARGS(sk, prot, allocated, kind),
  75. TP_STRUCT__entry(
  76. __array(char, name, 32)
  77. __field(long *, sysctl_mem)
  78. __field(long, allocated)
  79. __field(int, sysctl_rmem)
  80. __field(int, rmem_alloc)
  81. __field(int, sysctl_wmem)
  82. __field(int, wmem_alloc)
  83. __field(int, wmem_queued)
  84. __field(int, kind)
  85. ),
  86. TP_fast_assign(
  87. strncpy(__entry->name, prot->name, 32);
  88. __entry->sysctl_mem = prot->sysctl_mem;
  89. __entry->allocated = allocated;
  90. __entry->sysctl_rmem = sk_get_rmem0(sk, prot);
  91. __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
  92. __entry->sysctl_wmem = sk_get_wmem0(sk, prot);
  93. __entry->wmem_alloc = refcount_read(&sk->sk_wmem_alloc);
  94. __entry->wmem_queued = sk->sk_wmem_queued;
  95. __entry->kind = kind;
  96. ),
  97. TP_printk("proto:%s sysctl_mem=%ld,%ld,%ld allocated=%ld sysctl_rmem=%d rmem_alloc=%d sysctl_wmem=%d wmem_alloc=%d wmem_queued=%d kind=%s",
  98. __entry->name,
  99. __entry->sysctl_mem[0],
  100. __entry->sysctl_mem[1],
  101. __entry->sysctl_mem[2],
  102. __entry->allocated,
  103. __entry->sysctl_rmem,
  104. __entry->rmem_alloc,
  105. __entry->sysctl_wmem,
  106. __entry->wmem_alloc,
  107. __entry->wmem_queued,
  108. show_skmem_kind_names(__entry->kind)
  109. )
  110. );
  111. TRACE_EVENT(inet_sock_set_state,
  112. TP_PROTO(const struct sock *sk, const int oldstate, const int newstate),
  113. TP_ARGS(sk, oldstate, newstate),
  114. TP_STRUCT__entry(
  115. __field(const void *, skaddr)
  116. __field(int, oldstate)
  117. __field(int, newstate)
  118. __field(__u16, sport)
  119. __field(__u16, dport)
  120. __field(__u16, family)
  121. __field(__u8, protocol)
  122. __array(__u8, saddr, 4)
  123. __array(__u8, daddr, 4)
  124. __array(__u8, saddr_v6, 16)
  125. __array(__u8, daddr_v6, 16)
  126. ),
  127. TP_fast_assign(
  128. struct inet_sock *inet = inet_sk(sk);
  129. struct in6_addr *pin6;
  130. __be32 *p32;
  131. __entry->skaddr = sk;
  132. __entry->oldstate = oldstate;
  133. __entry->newstate = newstate;
  134. __entry->family = sk->sk_family;
  135. __entry->protocol = sk->sk_protocol;
  136. __entry->sport = ntohs(inet->inet_sport);
  137. __entry->dport = ntohs(inet->inet_dport);
  138. p32 = (__be32 *) __entry->saddr;
  139. *p32 = inet->inet_saddr;
  140. p32 = (__be32 *) __entry->daddr;
  141. *p32 = inet->inet_daddr;
  142. #if IS_ENABLED(CONFIG_IPV6)
  143. if (sk->sk_family == AF_INET6) {
  144. pin6 = (struct in6_addr *)__entry->saddr_v6;
  145. *pin6 = sk->sk_v6_rcv_saddr;
  146. pin6 = (struct in6_addr *)__entry->daddr_v6;
  147. *pin6 = sk->sk_v6_daddr;
  148. } else
  149. #endif
  150. {
  151. pin6 = (struct in6_addr *)__entry->saddr_v6;
  152. ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
  153. pin6 = (struct in6_addr *)__entry->daddr_v6;
  154. ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
  155. }
  156. ),
  157. TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
  158. show_family_name(__entry->family),
  159. show_inet_protocol_name(__entry->protocol),
  160. __entry->sport, __entry->dport,
  161. __entry->saddr, __entry->daddr,
  162. __entry->saddr_v6, __entry->daddr_v6,
  163. show_tcp_state_name(__entry->oldstate),
  164. show_tcp_state_name(__entry->newstate))
  165. );
  166. #endif /* _TRACE_SOCK_H */
  167. /* This part must be outside protection */
  168. #include <trace/define_trace.h>