linux/include/trace/events/sock.h
<<
>>
Prefs
   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/* enums need to be exported to user space */
  39#undef EM
  40#undef EMe
  41#define EM(a)       TRACE_DEFINE_ENUM(a);
  42#define EMe(a)      TRACE_DEFINE_ENUM(a);
  43
  44family_names
  45inet_protocol_names
  46tcp_state_names
  47
  48#undef EM
  49#undef EMe
  50#define EM(a)       { a, #a },
  51#define EMe(a)      { a, #a }
  52
  53#define show_family_name(val)                   \
  54        __print_symbolic(val, family_names)
  55
  56#define show_inet_protocol_name(val)    \
  57        __print_symbolic(val, inet_protocol_names)
  58
  59#define show_tcp_state_name(val)        \
  60        __print_symbolic(val, tcp_state_names)
  61
  62TRACE_EVENT(sock_rcvqueue_full,
  63
  64        TP_PROTO(struct sock *sk, struct sk_buff *skb),
  65
  66        TP_ARGS(sk, skb),
  67
  68        TP_STRUCT__entry(
  69                __field(int, rmem_alloc)
  70                __field(unsigned int, truesize)
  71                __field(int, sk_rcvbuf)
  72        ),
  73
  74        TP_fast_assign(
  75                __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
  76                __entry->truesize   = skb->truesize;
  77                __entry->sk_rcvbuf  = sk->sk_rcvbuf;
  78        ),
  79
  80        TP_printk("rmem_alloc=%d truesize=%u sk_rcvbuf=%d",
  81                __entry->rmem_alloc, __entry->truesize, __entry->sk_rcvbuf)
  82);
  83
  84TRACE_EVENT(sock_exceed_buf_limit,
  85
  86        TP_PROTO(struct sock *sk, struct proto *prot, long allocated),
  87
  88        TP_ARGS(sk, prot, allocated),
  89
  90        TP_STRUCT__entry(
  91                __array(char, name, 32)
  92                __field(long *, sysctl_mem)
  93                __field(long, allocated)
  94                __field(int, sysctl_rmem)
  95                __field(int, rmem_alloc)
  96        ),
  97
  98        TP_fast_assign(
  99                strncpy(__entry->name, prot->name, 32);
 100                __entry->sysctl_mem = prot->sysctl_mem;
 101                __entry->allocated = allocated;
 102                __entry->sysctl_rmem = sk_get_rmem0(sk, prot);
 103                __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
 104        ),
 105
 106        TP_printk("proto:%s sysctl_mem=%ld,%ld,%ld allocated=%ld "
 107                "sysctl_rmem=%d rmem_alloc=%d",
 108                __entry->name,
 109                __entry->sysctl_mem[0],
 110                __entry->sysctl_mem[1],
 111                __entry->sysctl_mem[2],
 112                __entry->allocated,
 113                __entry->sysctl_rmem,
 114                __entry->rmem_alloc)
 115);
 116
 117TRACE_EVENT(inet_sock_set_state,
 118
 119        TP_PROTO(const struct sock *sk, const int oldstate, const int newstate),
 120
 121        TP_ARGS(sk, oldstate, newstate),
 122
 123        TP_STRUCT__entry(
 124                __field(const void *, skaddr)
 125                __field(int, oldstate)
 126                __field(int, newstate)
 127                __field(__u16, sport)
 128                __field(__u16, dport)
 129                __field(__u16, family)
 130                __field(__u8, protocol)
 131                __array(__u8, saddr, 4)
 132                __array(__u8, daddr, 4)
 133                __array(__u8, saddr_v6, 16)
 134                __array(__u8, daddr_v6, 16)
 135        ),
 136
 137        TP_fast_assign(
 138                struct inet_sock *inet = inet_sk(sk);
 139                struct in6_addr *pin6;
 140                __be32 *p32;
 141
 142                __entry->skaddr = sk;
 143                __entry->oldstate = oldstate;
 144                __entry->newstate = newstate;
 145
 146                __entry->family = sk->sk_family;
 147                __entry->protocol = sk->sk_protocol;
 148                __entry->sport = ntohs(inet->inet_sport);
 149                __entry->dport = ntohs(inet->inet_dport);
 150
 151                p32 = (__be32 *) __entry->saddr;
 152                *p32 = inet->inet_saddr;
 153
 154                p32 = (__be32 *) __entry->daddr;
 155                *p32 =  inet->inet_daddr;
 156
 157#if IS_ENABLED(CONFIG_IPV6)
 158                if (sk->sk_family == AF_INET6) {
 159                        pin6 = (struct in6_addr *)__entry->saddr_v6;
 160                        *pin6 = sk->sk_v6_rcv_saddr;
 161                        pin6 = (struct in6_addr *)__entry->daddr_v6;
 162                        *pin6 = sk->sk_v6_daddr;
 163                } else
 164#endif
 165                {
 166                        pin6 = (struct in6_addr *)__entry->saddr_v6;
 167                        ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
 168                        pin6 = (struct in6_addr *)__entry->daddr_v6;
 169                        ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
 170                }
 171        ),
 172
 173        TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
 174                        show_family_name(__entry->family),
 175                        show_inet_protocol_name(__entry->protocol),
 176                        __entry->sport, __entry->dport,
 177                        __entry->saddr, __entry->daddr,
 178                        __entry->saddr_v6, __entry->daddr_v6,
 179                        show_tcp_state_name(__entry->oldstate),
 180                        show_tcp_state_name(__entry->newstate))
 181);
 182
 183#endif /* _TRACE_SOCK_H */
 184
 185/* This part must be outside protection */
 186#include <trace/define_trace.h>
 187