Skip to content

Commit 55f9677

Browse files
committed
Merge: net: backport visibility improvements
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4765 JIRA: https://issues.redhat.com/browse/RHEL-48648 Various visibility improvements; mainly around drop reasons, reset reason and improved tracepoints this time. Signed-off-by: Antoine Tenart <atenart@redhat.com> Approved-by: Chris von Recklinghausen <crecklin@redhat.com> Approved-by: Marcelo Ricardo Leitner <mleitner@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Lucas Zampieri <lzampier@redhat.com>
2 parents 15f74fa + ebf4f1c commit 55f9677

39 files changed

+647
-266
lines changed

include/linux/skbuff.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,14 @@ static inline bool skb_unref(struct sk_buff *skb)
11591159
return true;
11601160
}
11611161

1162-
void __fix_address
1163-
kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason);
1162+
void __fix_address sk_skb_reason_drop(struct sock *sk, struct sk_buff *skb,
1163+
enum skb_drop_reason reason);
1164+
1165+
static inline void
1166+
kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)
1167+
{
1168+
sk_skb_reason_drop(NULL, skb, reason);
1169+
}
11641170

11651171
/**
11661172
* kfree_skb - free an sk_buff with 'NOT_SPECIFIED' reason

include/net/dropreason-core.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
FN(TCP_MD5FAILURE) \
2626
FN(SOCKET_BACKLOG) \
2727
FN(TCP_FLAGS) \
28+
FN(TCP_ABORT_ON_DATA) \
2829
FN(TCP_ZEROWINDOW) \
2930
FN(TCP_OLD_DATA) \
3031
FN(TCP_OVERWINDOW) \
3132
FN(TCP_OFOMERGE) \
3233
FN(TCP_RFC7323_PAWS) \
3334
FN(TCP_OLD_SEQUENCE) \
3435
FN(TCP_INVALID_SEQUENCE) \
36+
FN(TCP_INVALID_ACK_SEQUENCE) \
3537
FN(TCP_RESET) \
3638
FN(TCP_INVALID_SYN) \
3739
FN(TCP_CLOSE) \
@@ -49,6 +51,7 @@
4951
FN(NEIGH_QUEUEFULL) \
5052
FN(NEIGH_DEAD) \
5153
FN(TC_EGRESS) \
54+
FN(SECURITY_HOOK) \
5255
FN(QDISC_DROP) \
5356
FN(CPU_BACKLOG) \
5457
FN(XDP) \
@@ -100,7 +103,13 @@ enum skb_drop_reason {
100103
SKB_CONSUMED,
101104
/** @SKB_DROP_REASON_NOT_SPECIFIED: drop reason is not specified */
102105
SKB_DROP_REASON_NOT_SPECIFIED,
103-
/** @SKB_DROP_REASON_NO_SOCKET: socket not found */
106+
/**
107+
* @SKB_DROP_REASON_NO_SOCKET: no valid socket that can be used.
108+
* Reason could be one of three cases:
109+
* 1) no established/listening socket found during lookup process
110+
* 2) no valid request socket during 3WHS process
111+
* 3) no valid child socket during 3WHS process
112+
*/
104113
SKB_DROP_REASON_NO_SOCKET,
105114
/** @SKB_DROP_REASON_PKT_TOO_SMALL: packet size is too small */
106115
SKB_DROP_REASON_PKT_TOO_SMALL,
@@ -167,6 +176,11 @@ enum skb_drop_reason {
167176
SKB_DROP_REASON_SOCKET_BACKLOG,
168177
/** @SKB_DROP_REASON_TCP_FLAGS: TCP flags invalid */
169178
SKB_DROP_REASON_TCP_FLAGS,
179+
/**
180+
* @SKB_DROP_REASON_TCP_ABORT_ON_DATA: abort on data, corresponding to
181+
* LINUX_MIB_TCPABORTONDATA
182+
*/
183+
SKB_DROP_REASON_TCP_ABORT_ON_DATA,
170184
/**
171185
* @SKB_DROP_REASON_TCP_ZEROWINDOW: TCP receive window size is zero,
172186
* see LINUX_MIB_TCPZEROWINDOWDROP
@@ -191,13 +205,19 @@ enum skb_drop_reason {
191205
SKB_DROP_REASON_TCP_OFOMERGE,
192206
/**
193207
* @SKB_DROP_REASON_TCP_RFC7323_PAWS: PAWS check, corresponding to
194-
* LINUX_MIB_PAWSESTABREJECTED
208+
* LINUX_MIB_PAWSESTABREJECTED, LINUX_MIB_PAWSACTIVEREJECTED
195209
*/
196210
SKB_DROP_REASON_TCP_RFC7323_PAWS,
197211
/** @SKB_DROP_REASON_TCP_OLD_SEQUENCE: Old SEQ field (duplicate packet) */
198212
SKB_DROP_REASON_TCP_OLD_SEQUENCE,
199213
/** @SKB_DROP_REASON_TCP_INVALID_SEQUENCE: Not acceptable SEQ field */
200214
SKB_DROP_REASON_TCP_INVALID_SEQUENCE,
215+
/**
216+
* @SKB_DROP_REASON_TCP_INVALID_ACK_SEQUENCE: Not acceptable ACK SEQ
217+
* field because ack sequence is not in the window between snd_una
218+
* and snd_nxt
219+
*/
220+
SKB_DROP_REASON_TCP_INVALID_ACK_SEQUENCE,
201221
/** @SKB_DROP_REASON_TCP_RESET: Invalid RST packet */
202222
SKB_DROP_REASON_TCP_RESET,
203223
/**
@@ -241,6 +261,8 @@ enum skb_drop_reason {
241261
SKB_DROP_REASON_NEIGH_DEAD,
242262
/** @SKB_DROP_REASON_TC_EGRESS: dropped in TC egress HOOK */
243263
SKB_DROP_REASON_TC_EGRESS,
264+
/** @SKB_DROP_REASON_SECURITY_HOOK: dropped due to security HOOK */
265+
SKB_DROP_REASON_SECURITY_HOOK,
244266
/**
245267
* @SKB_DROP_REASON_QDISC_DROP: dropped by qdisc when packet outputting (
246268
* failed to enqueue to current qdisc)

include/net/inet_sock.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ static inline struct sock *skb_to_full_sk(const struct sk_buff *skb)
285285
return sk_to_full_sk(skb->sk);
286286
}
287287

288-
static inline struct inet_sock *inet_sk(const struct sock *sk)
289-
{
290-
return (struct inet_sock *)sk;
291-
}
288+
#define inet_sk(ptr) container_of_const(ptr, struct inet_sock, sk)
292289

293290
static inline void __inet_sk_copy_descendant(struct sock *sk_to,
294291
const struct sock *sk_from,

include/net/request_sock.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/refcount.h>
1919

2020
#include <net/sock.h>
21+
#include <net/rstreason.h>
2122

2223
struct request_sock;
2324
struct sk_buff;
@@ -34,7 +35,8 @@ struct request_sock_ops {
3435
void (*send_ack)(const struct sock *sk, struct sk_buff *skb,
3536
struct request_sock *req);
3637
void (*send_reset)(const struct sock *sk,
37-
struct sk_buff *skb);
38+
struct sk_buff *skb,
39+
enum sk_rst_reason reason);
3840
void (*destructor)(struct request_sock *req);
3941
void (*syn_ack_timeout)(const struct request_sock *req);
4042
};

include/net/rstreason.h

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
3+
#ifndef _LINUX_RSTREASON_H
4+
#define _LINUX_RSTREASON_H
5+
#include <net/dropreason-core.h>
6+
#include <uapi/linux/mptcp.h>
7+
8+
#define DEFINE_RST_REASON(FN, FNe) \
9+
FN(NOT_SPECIFIED) \
10+
FN(NO_SOCKET) \
11+
FN(TCP_INVALID_ACK_SEQUENCE) \
12+
FN(TCP_RFC7323_PAWS) \
13+
FN(TCP_TOO_OLD_ACK) \
14+
FN(TCP_ACK_UNSENT_DATA) \
15+
FN(TCP_FLAGS) \
16+
FN(TCP_OLD_ACK) \
17+
FN(TCP_ABORT_ON_DATA) \
18+
FN(TCP_TIMEWAIT_SOCKET) \
19+
FN(INVALID_SYN) \
20+
FN(MPTCP_RST_EUNSPEC) \
21+
FN(MPTCP_RST_EMPTCP) \
22+
FN(MPTCP_RST_ERESOURCE) \
23+
FN(MPTCP_RST_EPROHIBIT) \
24+
FN(MPTCP_RST_EWQ2BIG) \
25+
FN(MPTCP_RST_EBADPERF) \
26+
FN(MPTCP_RST_EMIDDLEBOX) \
27+
FN(ERROR) \
28+
FNe(MAX)
29+
30+
/**
31+
* enum sk_rst_reason - the reasons of socket reset
32+
*
33+
* The reasons of sk reset, which are used in DCCP/TCP/MPTCP protocols.
34+
*
35+
* There are three parts in order:
36+
* 1) skb drop reasons: relying on drop reasons for such as passive reset
37+
* 2) independent reset reasons: such as active reset reasons
38+
* 3) reset reasons in MPTCP: only for MPTCP use
39+
*/
40+
enum sk_rst_reason {
41+
/* Refer to include/net/dropreason-core.h
42+
* Rely on skb drop reasons because it indicates exactly why RST
43+
* could happen.
44+
*/
45+
/** @SK_RST_REASON_NOT_SPECIFIED: reset reason is not specified */
46+
SK_RST_REASON_NOT_SPECIFIED,
47+
/** @SK_RST_REASON_NO_SOCKET: no valid socket that can be used */
48+
SK_RST_REASON_NO_SOCKET,
49+
/**
50+
* @SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE: Not acceptable ACK SEQ
51+
* field because ack sequence is not in the window between snd_una
52+
* and snd_nxt
53+
*/
54+
SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE,
55+
/**
56+
* @SK_RST_REASON_TCP_RFC7323_PAWS: PAWS check, corresponding to
57+
* LINUX_MIB_PAWSESTABREJECTED, LINUX_MIB_PAWSACTIVEREJECTED
58+
*/
59+
SK_RST_REASON_TCP_RFC7323_PAWS,
60+
/** @SK_RST_REASON_TCP_TOO_OLD_ACK: TCP ACK is too old */
61+
SK_RST_REASON_TCP_TOO_OLD_ACK,
62+
/**
63+
* @SK_RST_REASON_TCP_ACK_UNSENT_DATA: TCP ACK for data we haven't
64+
* sent yet
65+
*/
66+
SK_RST_REASON_TCP_ACK_UNSENT_DATA,
67+
/** @SK_RST_REASON_TCP_FLAGS: TCP flags invalid */
68+
SK_RST_REASON_TCP_FLAGS,
69+
/** @SK_RST_REASON_TCP_OLD_ACK: TCP ACK is old, but in window */
70+
SK_RST_REASON_TCP_OLD_ACK,
71+
/**
72+
* @SK_RST_REASON_TCP_ABORT_ON_DATA: abort on data
73+
* corresponding to LINUX_MIB_TCPABORTONDATA
74+
*/
75+
SK_RST_REASON_TCP_ABORT_ON_DATA,
76+
77+
/* Here start with the independent reasons */
78+
/** @SK_RST_REASON_TCP_TIMEWAIT_SOCKET: happen on the timewait socket */
79+
SK_RST_REASON_TCP_TIMEWAIT_SOCKET,
80+
/**
81+
* @SK_RST_REASON_INVALID_SYN: receive bad syn packet
82+
* RFC 793 says if the state is not CLOSED/LISTEN/SYN-SENT then
83+
* "fourth, check the SYN bit,...If the SYN is in the window it is
84+
* an error, send a reset"
85+
*/
86+
SK_RST_REASON_INVALID_SYN,
87+
88+
/* Copy from include/uapi/linux/mptcp.h.
89+
* These reset fields will not be changed since they adhere to
90+
* RFC 8684. So do not touch them. I'm going to list each definition
91+
* of them respectively.
92+
*/
93+
/**
94+
* @SK_RST_REASON_MPTCP_RST_EUNSPEC: Unspecified error.
95+
* This is the default error; it implies that the subflow is no
96+
* longer available. The presence of this option shows that the
97+
* RST was generated by an MPTCP-aware device.
98+
*/
99+
SK_RST_REASON_MPTCP_RST_EUNSPEC,
100+
/**
101+
* @SK_RST_REASON_MPTCP_RST_EMPTCP: MPTCP-specific error.
102+
* An error has been detected in the processing of MPTCP options.
103+
* This is the usual reason code to return in the cases where a RST
104+
* is being sent to close a subflow because of an invalid response.
105+
*/
106+
SK_RST_REASON_MPTCP_RST_EMPTCP,
107+
/**
108+
* @SK_RST_REASON_MPTCP_RST_ERESOURCE: Lack of resources.
109+
* This code indicates that the sending host does not have enough
110+
* resources to support the terminated subflow.
111+
*/
112+
SK_RST_REASON_MPTCP_RST_ERESOURCE,
113+
/**
114+
* @SK_RST_REASON_MPTCP_RST_EPROHIBIT: Administratively prohibited.
115+
* This code indicates that the requested subflow is prohibited by
116+
* the policies of the sending host.
117+
*/
118+
SK_RST_REASON_MPTCP_RST_EPROHIBIT,
119+
/**
120+
* @SK_RST_REASON_MPTCP_RST_EWQ2BIG: Too much outstanding data.
121+
* This code indicates that there is an excessive amount of data
122+
* that needs to be transmitted over the terminated subflow while
123+
* having already been acknowledged over one or more other subflows.
124+
* This may occur if a path has been unavailable for a short period
125+
* and it is more efficient to reset and start again than it is to
126+
* retransmit the queued data.
127+
*/
128+
SK_RST_REASON_MPTCP_RST_EWQ2BIG,
129+
/**
130+
* @SK_RST_REASON_MPTCP_RST_EBADPERF: Unacceptable performance.
131+
* This code indicates that the performance of this subflow was
132+
* too low compared to the other subflows of this Multipath TCP
133+
* connection.
134+
*/
135+
SK_RST_REASON_MPTCP_RST_EBADPERF,
136+
/**
137+
* @SK_RST_REASON_MPTCP_RST_EMIDDLEBOX: Middlebox interference.
138+
* Middlebox interference has been detected over this subflow,
139+
* making MPTCP signaling invalid. For example, this may be sent
140+
* if the checksum does not validate.
141+
*/
142+
SK_RST_REASON_MPTCP_RST_EMIDDLEBOX,
143+
144+
/** @SK_RST_REASON_ERROR: unexpected error happens */
145+
SK_RST_REASON_ERROR,
146+
147+
/**
148+
* @SK_RST_REASON_MAX: Maximum of socket reset reasons.
149+
* It shouldn't be used as a real 'reason'.
150+
*/
151+
SK_RST_REASON_MAX,
152+
};
153+
154+
/* Convert skb drop reasons to enum sk_rst_reason type */
155+
static inline enum sk_rst_reason
156+
sk_rst_convert_drop_reason(enum skb_drop_reason reason)
157+
{
158+
switch (reason) {
159+
case SKB_DROP_REASON_NOT_SPECIFIED:
160+
return SK_RST_REASON_NOT_SPECIFIED;
161+
case SKB_DROP_REASON_NO_SOCKET:
162+
return SK_RST_REASON_NO_SOCKET;
163+
case SKB_DROP_REASON_TCP_INVALID_ACK_SEQUENCE:
164+
return SK_RST_REASON_TCP_INVALID_ACK_SEQUENCE;
165+
case SKB_DROP_REASON_TCP_RFC7323_PAWS:
166+
return SK_RST_REASON_TCP_RFC7323_PAWS;
167+
case SKB_DROP_REASON_TCP_TOO_OLD_ACK:
168+
return SK_RST_REASON_TCP_TOO_OLD_ACK;
169+
case SKB_DROP_REASON_TCP_ACK_UNSENT_DATA:
170+
return SK_RST_REASON_TCP_ACK_UNSENT_DATA;
171+
case SKB_DROP_REASON_TCP_FLAGS:
172+
return SK_RST_REASON_TCP_FLAGS;
173+
case SKB_DROP_REASON_TCP_OLD_ACK:
174+
return SK_RST_REASON_TCP_OLD_ACK;
175+
case SKB_DROP_REASON_TCP_ABORT_ON_DATA:
176+
return SK_RST_REASON_TCP_ABORT_ON_DATA;
177+
default:
178+
/* If we don't have our own corresponding reason */
179+
return SK_RST_REASON_NOT_SPECIFIED;
180+
}
181+
}
182+
#endif

include/net/tcp.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ void tcp_wfree(struct sk_buff *skb);
344344
void tcp_write_timer_handler(struct sock *sk);
345345
void tcp_delack_timer_handler(struct sock *sk);
346346
int tcp_ioctl(struct sock *sk, int cmd, int *karg);
347-
int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb);
347+
enum skb_drop_reason tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb);
348348
void tcp_rcv_established(struct sock *sk, struct sk_buff *skb);
349349
void tcp_rcv_space_adjust(struct sock *sk);
350350
int tcp_twsk_unique(struct sock *sk, struct sock *sktw, void *twp);
@@ -390,8 +390,8 @@ enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw,
390390
struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
391391
struct request_sock *req, bool fastopen,
392392
bool *lost_race);
393-
int tcp_child_process(struct sock *parent, struct sock *child,
394-
struct sk_buff *skb);
393+
enum skb_drop_reason tcp_child_process(struct sock *parent, struct sock *child,
394+
struct sk_buff *skb);
395395
void tcp_enter_loss(struct sock *sk);
396396
void tcp_cwnd_reduction(struct sock *sk, int newly_acked_sacked, int newly_lost, int flag);
397397
void tcp_clear_retrans(struct tcp_sock *tp);
@@ -614,7 +614,8 @@ void tcp_send_probe0(struct sock *);
614614
void tcp_send_partial(struct sock *);
615615
int tcp_write_wakeup(struct sock *, int mib);
616616
void tcp_send_fin(struct sock *sk);
617-
void tcp_send_active_reset(struct sock *sk, gfp_t priority);
617+
void tcp_send_active_reset(struct sock *sk, gfp_t priority,
618+
enum sk_rst_reason reason);
618619
int tcp_send_synack(struct sock *);
619620
void tcp_push_one(struct sock *, unsigned int mss_now);
620621
void __tcp_send_ack(struct sock *sk, u32 rcv_nxt);

0 commit comments

Comments
 (0)