Skip to content

Commit c24b14c

Browse files
liu-song-6davem330
authored andcommitted
tcp: add tracepoint trace_tcp_send_reset
New tracepoint trace_tcp_send_reset is added and called from tcp_v4_send_reset(), tcp_v6_send_reset() and tcp_send_active_reset(). Signed-off-by: Song Liu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7344e29 commit c24b14c

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

include/trace/events/tcp.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb,
7777
TP_ARGS(sk, skb)
7878
);
7979

80+
/*
81+
* skb of trace_tcp_send_reset is the skb that caused RST. In case of
82+
* active reset, skb should be NULL
83+
*/
84+
DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset,
85+
86+
TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
87+
88+
TP_ARGS(sk, skb)
89+
);
90+
8091
#endif /* _TRACE_TCP_H */
8192

8293
/* This part must be outside protection */

net/core/net-traces.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(br_fdb_update);
4949
EXPORT_TRACEPOINT_SYMBOL_GPL(kfree_skb);
5050

5151
EXPORT_TRACEPOINT_SYMBOL_GPL(napi_poll);
52+
53+
EXPORT_TRACEPOINT_SYMBOL_GPL(tcp_send_reset);

net/ipv4/tcp_ipv4.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
#include <crypto/hash.h>
8686
#include <linux/scatterlist.h>
8787

88+
#include <trace/events/tcp.h>
89+
8890
#ifdef CONFIG_TCP_MD5SIG
8991
static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
9092
__be32 daddr, __be32 saddr, const struct tcphdr *th);
@@ -701,8 +703,10 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb)
701703
* routing might fail in this case. No choice here, if we choose to force
702704
* input interface, we will misroute in case of asymmetric route.
703705
*/
704-
if (sk)
706+
if (sk) {
705707
arg.bound_dev_if = sk->sk_bound_dev_if;
708+
trace_tcp_send_reset(sk, skb);
709+
}
706710

707711
BUILD_BUG_ON(offsetof(struct sock, sk_bound_dev_if) !=
708712
offsetof(struct inet_timewait_sock, tw_bound_dev_if));

net/ipv4/tcp_output.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,6 +3084,11 @@ void tcp_send_active_reset(struct sock *sk, gfp_t priority)
30843084
/* Send it off. */
30853085
if (tcp_transmit_skb(sk, skb, 0, priority))
30863086
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTFAILED);
3087+
3088+
/* skb of trace_tcp_send_reset() keeps the skb that caused RST,
3089+
* skb here is different to the troublesome skb, so use NULL
3090+
*/
3091+
trace_tcp_send_reset(sk, NULL);
30873092
}
30883093

30893094
/* Send a crossed SYN-ACK during socket establishment.

net/ipv6/tcp_ipv6.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
#include <crypto/hash.h>
7070
#include <linux/scatterlist.h>
7171

72+
#include <trace/events/tcp.h>
73+
7274
static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb);
7375
static void tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,
7476
struct request_sock *req);
@@ -890,7 +892,7 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb)
890892
int genhash;
891893
struct sock *sk1 = NULL;
892894
#endif
893-
int oif;
895+
int oif = 0;
894896

895897
if (th->rst)
896898
return;
@@ -939,7 +941,11 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb)
939941
ack_seq = ntohl(th->seq) + th->syn + th->fin + skb->len -
940942
(th->doff << 2);
941943

942-
oif = sk ? sk->sk_bound_dev_if : 0;
944+
if (sk) {
945+
oif = sk->sk_bound_dev_if;
946+
trace_tcp_send_reset(sk, skb);
947+
}
948+
943949
tcp_v6_send_response(sk, skb, seq, ack_seq, 0, 0, 0, oif, key, 1, 0, 0);
944950

945951
#ifdef CONFIG_TCP_MD5SIG

0 commit comments

Comments
 (0)