Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #undef TRACE_SYSTEM
0003 #define TRACE_SYSTEM sock
0004 
0005 #if !defined(_TRACE_SOCK_H) || defined(TRACE_HEADER_MULTI_READ)
0006 #define _TRACE_SOCK_H
0007 
0008 #include <net/sock.h>
0009 #include <net/ipv6.h>
0010 #include <linux/tracepoint.h>
0011 #include <linux/ipv6.h>
0012 #include <linux/tcp.h>
0013 
0014 #define family_names            \
0015         EM(AF_INET)             \
0016         EMe(AF_INET6)
0017 
0018 /* The protocol traced by inet_sock_set_state */
0019 #define inet_protocol_names     \
0020         EM(IPPROTO_TCP)         \
0021         EM(IPPROTO_DCCP)        \
0022         EM(IPPROTO_SCTP)        \
0023         EMe(IPPROTO_MPTCP)
0024 
0025 #define tcp_state_names         \
0026         EM(TCP_ESTABLISHED)     \
0027         EM(TCP_SYN_SENT)        \
0028         EM(TCP_SYN_RECV)        \
0029         EM(TCP_FIN_WAIT1)       \
0030         EM(TCP_FIN_WAIT2)       \
0031         EM(TCP_TIME_WAIT)       \
0032         EM(TCP_CLOSE)           \
0033         EM(TCP_CLOSE_WAIT)      \
0034         EM(TCP_LAST_ACK)        \
0035         EM(TCP_LISTEN)          \
0036         EM(TCP_CLOSING)         \
0037         EMe(TCP_NEW_SYN_RECV)
0038 
0039 #define skmem_kind_names            \
0040         EM(SK_MEM_SEND)         \
0041         EMe(SK_MEM_RECV)
0042 
0043 /* enums need to be exported to user space */
0044 #undef EM
0045 #undef EMe
0046 #define EM(a)       TRACE_DEFINE_ENUM(a);
0047 #define EMe(a)      TRACE_DEFINE_ENUM(a);
0048 
0049 family_names
0050 inet_protocol_names
0051 tcp_state_names
0052 skmem_kind_names
0053 
0054 #undef EM
0055 #undef EMe
0056 #define EM(a)       { a, #a },
0057 #define EMe(a)      { a, #a }
0058 
0059 #define show_family_name(val)           \
0060     __print_symbolic(val, family_names)
0061 
0062 #define show_inet_protocol_name(val)    \
0063     __print_symbolic(val, inet_protocol_names)
0064 
0065 #define show_tcp_state_name(val)        \
0066     __print_symbolic(val, tcp_state_names)
0067 
0068 #define show_skmem_kind_names(val)  \
0069     __print_symbolic(val, skmem_kind_names)
0070 
0071 TRACE_EVENT(sock_rcvqueue_full,
0072 
0073     TP_PROTO(struct sock *sk, struct sk_buff *skb),
0074 
0075     TP_ARGS(sk, skb),
0076 
0077     TP_STRUCT__entry(
0078         __field(int, rmem_alloc)
0079         __field(unsigned int, truesize)
0080         __field(int, sk_rcvbuf)
0081     ),
0082 
0083     TP_fast_assign(
0084         __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
0085         __entry->truesize   = skb->truesize;
0086         __entry->sk_rcvbuf  = READ_ONCE(sk->sk_rcvbuf);
0087     ),
0088 
0089     TP_printk("rmem_alloc=%d truesize=%u sk_rcvbuf=%d",
0090         __entry->rmem_alloc, __entry->truesize, __entry->sk_rcvbuf)
0091 );
0092 
0093 TRACE_EVENT(sock_exceed_buf_limit,
0094 
0095     TP_PROTO(struct sock *sk, struct proto *prot, long allocated, int kind),
0096 
0097     TP_ARGS(sk, prot, allocated, kind),
0098 
0099     TP_STRUCT__entry(
0100         __array(char, name, 32)
0101         __array(long, sysctl_mem, 3)
0102         __field(long, allocated)
0103         __field(int, sysctl_rmem)
0104         __field(int, rmem_alloc)
0105         __field(int, sysctl_wmem)
0106         __field(int, wmem_alloc)
0107         __field(int, wmem_queued)
0108         __field(int, kind)
0109     ),
0110 
0111     TP_fast_assign(
0112         strncpy(__entry->name, prot->name, 32);
0113         __entry->sysctl_mem[0] = READ_ONCE(prot->sysctl_mem[0]);
0114         __entry->sysctl_mem[1] = READ_ONCE(prot->sysctl_mem[1]);
0115         __entry->sysctl_mem[2] = READ_ONCE(prot->sysctl_mem[2]);
0116         __entry->allocated = allocated;
0117         __entry->sysctl_rmem = sk_get_rmem0(sk, prot);
0118         __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
0119         __entry->sysctl_wmem = sk_get_wmem0(sk, prot);
0120         __entry->wmem_alloc = refcount_read(&sk->sk_wmem_alloc);
0121         __entry->wmem_queued = READ_ONCE(sk->sk_wmem_queued);
0122         __entry->kind = kind;
0123     ),
0124 
0125     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",
0126         __entry->name,
0127         __entry->sysctl_mem[0],
0128         __entry->sysctl_mem[1],
0129         __entry->sysctl_mem[2],
0130         __entry->allocated,
0131         __entry->sysctl_rmem,
0132         __entry->rmem_alloc,
0133         __entry->sysctl_wmem,
0134         __entry->wmem_alloc,
0135         __entry->wmem_queued,
0136         show_skmem_kind_names(__entry->kind)
0137     )
0138 );
0139 
0140 TRACE_EVENT(inet_sock_set_state,
0141 
0142     TP_PROTO(const struct sock *sk, const int oldstate, const int newstate),
0143 
0144     TP_ARGS(sk, oldstate, newstate),
0145 
0146     TP_STRUCT__entry(
0147         __field(const void *, skaddr)
0148         __field(int, oldstate)
0149         __field(int, newstate)
0150         __field(__u16, sport)
0151         __field(__u16, dport)
0152         __field(__u16, family)
0153         __field(__u16, protocol)
0154         __array(__u8, saddr, 4)
0155         __array(__u8, daddr, 4)
0156         __array(__u8, saddr_v6, 16)
0157         __array(__u8, daddr_v6, 16)
0158     ),
0159 
0160     TP_fast_assign(
0161         struct inet_sock *inet = inet_sk(sk);
0162         struct in6_addr *pin6;
0163         __be32 *p32;
0164 
0165         __entry->skaddr = sk;
0166         __entry->oldstate = oldstate;
0167         __entry->newstate = newstate;
0168 
0169         __entry->family = sk->sk_family;
0170         __entry->protocol = sk->sk_protocol;
0171         __entry->sport = ntohs(inet->inet_sport);
0172         __entry->dport = ntohs(inet->inet_dport);
0173 
0174         p32 = (__be32 *) __entry->saddr;
0175         *p32 = inet->inet_saddr;
0176 
0177         p32 = (__be32 *) __entry->daddr;
0178         *p32 =  inet->inet_daddr;
0179 
0180 #if IS_ENABLED(CONFIG_IPV6)
0181         if (sk->sk_family == AF_INET6) {
0182             pin6 = (struct in6_addr *)__entry->saddr_v6;
0183             *pin6 = sk->sk_v6_rcv_saddr;
0184             pin6 = (struct in6_addr *)__entry->daddr_v6;
0185             *pin6 = sk->sk_v6_daddr;
0186         } else
0187 #endif
0188         {
0189             pin6 = (struct in6_addr *)__entry->saddr_v6;
0190             ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
0191             pin6 = (struct in6_addr *)__entry->daddr_v6;
0192             ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
0193         }
0194     ),
0195 
0196     TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
0197             show_family_name(__entry->family),
0198             show_inet_protocol_name(__entry->protocol),
0199             __entry->sport, __entry->dport,
0200             __entry->saddr, __entry->daddr,
0201             __entry->saddr_v6, __entry->daddr_v6,
0202             show_tcp_state_name(__entry->oldstate),
0203             show_tcp_state_name(__entry->newstate))
0204 );
0205 
0206 TRACE_EVENT(inet_sk_error_report,
0207 
0208     TP_PROTO(const struct sock *sk),
0209 
0210     TP_ARGS(sk),
0211 
0212     TP_STRUCT__entry(
0213         __field(int, error)
0214         __field(__u16, sport)
0215         __field(__u16, dport)
0216         __field(__u16, family)
0217         __field(__u16, protocol)
0218         __array(__u8, saddr, 4)
0219         __array(__u8, daddr, 4)
0220         __array(__u8, saddr_v6, 16)
0221         __array(__u8, daddr_v6, 16)
0222     ),
0223 
0224     TP_fast_assign(
0225         struct inet_sock *inet = inet_sk(sk);
0226         struct in6_addr *pin6;
0227         __be32 *p32;
0228 
0229         __entry->error = sk->sk_err;
0230         __entry->family = sk->sk_family;
0231         __entry->protocol = sk->sk_protocol;
0232         __entry->sport = ntohs(inet->inet_sport);
0233         __entry->dport = ntohs(inet->inet_dport);
0234 
0235         p32 = (__be32 *) __entry->saddr;
0236         *p32 = inet->inet_saddr;
0237 
0238         p32 = (__be32 *) __entry->daddr;
0239         *p32 =  inet->inet_daddr;
0240 
0241 #if IS_ENABLED(CONFIG_IPV6)
0242         if (sk->sk_family == AF_INET6) {
0243             pin6 = (struct in6_addr *)__entry->saddr_v6;
0244             *pin6 = sk->sk_v6_rcv_saddr;
0245             pin6 = (struct in6_addr *)__entry->daddr_v6;
0246             *pin6 = sk->sk_v6_daddr;
0247         } else
0248 #endif
0249         {
0250             pin6 = (struct in6_addr *)__entry->saddr_v6;
0251             ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
0252             pin6 = (struct in6_addr *)__entry->daddr_v6;
0253             ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
0254         }
0255     ),
0256 
0257     TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c error=%d",
0258           show_family_name(__entry->family),
0259           show_inet_protocol_name(__entry->protocol),
0260           __entry->sport, __entry->dport,
0261           __entry->saddr, __entry->daddr,
0262           __entry->saddr_v6, __entry->daddr_v6,
0263           __entry->error)
0264 );
0265 
0266 #endif /* _TRACE_SOCK_H */
0267 
0268 /* This part must be outside protection */
0269 #include <trace/define_trace.h>