]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
net: sock: add trace for socket errors
authorAlexander Aring <aahringo@redhat.com>
Sun, 27 Jun 2021 22:48:22 +0000 (18:48 -0400)
committerDavid S. Miller <davem@davemloft.net>
Tue, 29 Jun 2021 18:28:21 +0000 (11:28 -0700)
This patch will add tracers to trace inet socket errors only. A user
space monitor application can track connection errors indepedent from
socket lifetime and do additional handling. For example a cluster
manager can fence a node if errors occurs in a specific heuristic.

Signed-off-by: Alexander Aring <aahringo@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/trace/events/sock.h
net/core/sock.c

index a966d4b5ab3778faedcc9301bee44ca3e3a0c008..12c315782766a6f9ad227dd59a3c4e968e023819 100644 (file)
@@ -201,6 +201,66 @@ TRACE_EVENT(inet_sock_set_state,
                        show_tcp_state_name(__entry->newstate))
 );
 
+TRACE_EVENT(inet_sk_error_report,
+
+       TP_PROTO(const struct sock *sk),
+
+       TP_ARGS(sk),
+
+       TP_STRUCT__entry(
+               __field(int, error)
+               __field(__u16, sport)
+               __field(__u16, dport)
+               __field(__u16, family)
+               __field(__u16, protocol)
+               __array(__u8, saddr, 4)
+               __array(__u8, daddr, 4)
+               __array(__u8, saddr_v6, 16)
+               __array(__u8, daddr_v6, 16)
+       ),
+
+       TP_fast_assign(
+               struct inet_sock *inet = inet_sk(sk);
+               struct in6_addr *pin6;
+               __be32 *p32;
+
+               __entry->error = sk->sk_err;
+               __entry->family = sk->sk_family;
+               __entry->protocol = sk->sk_protocol;
+               __entry->sport = ntohs(inet->inet_sport);
+               __entry->dport = ntohs(inet->inet_dport);
+
+               p32 = (__be32 *) __entry->saddr;
+               *p32 = inet->inet_saddr;
+
+               p32 = (__be32 *) __entry->daddr;
+               *p32 =  inet->inet_daddr;
+
+#if IS_ENABLED(CONFIG_IPV6)
+               if (sk->sk_family == AF_INET6) {
+                       pin6 = (struct in6_addr *)__entry->saddr_v6;
+                       *pin6 = sk->sk_v6_rcv_saddr;
+                       pin6 = (struct in6_addr *)__entry->daddr_v6;
+                       *pin6 = sk->sk_v6_daddr;
+               } else
+#endif
+               {
+                       pin6 = (struct in6_addr *)__entry->saddr_v6;
+                       ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
+                       pin6 = (struct in6_addr *)__entry->daddr_v6;
+                       ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
+               }
+       ),
+
+       TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c error=%d",
+                 show_family_name(__entry->family),
+                 show_inet_protocol_name(__entry->protocol),
+                 __entry->sport, __entry->dport,
+                 __entry->saddr, __entry->daddr,
+                 __entry->saddr_v6, __entry->daddr_v6,
+                 __entry->error)
+);
+
 #endif /* _TRACE_SOCK_H */
 
 /* This part must be outside protection */
index c30f8f4cbb229227034e936450a9b62707104884..ba1c0f75cd45b4c944dfb326f1fd2f5866200fcf 100644 (file)
@@ -334,6 +334,16 @@ EXPORT_SYMBOL(__sk_backlog_rcv);
 void sk_error_report(struct sock *sk)
 {
        sk->sk_error_report(sk);
+
+       switch (sk->sk_family) {
+       case AF_INET:
+               fallthrough;
+       case AF_INET6:
+               trace_inet_sk_error_report(sk);
+               break;
+       default:
+               break;
+       }
 }
 EXPORT_SYMBOL(sk_error_report);