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