Skip to content

Commit b446934

Browse files
edumazetPaolo Abeni
authored andcommitted
tcp: add TCP_OLD_SEQUENCE drop reason
tcp_sequence() uses two conditions to decide to drop a packet, and we currently report generic TCP_INVALID_SEQUENCE drop reason. Duplicates are common, we need to distinguish them from the other case. I chose to not reuse TCP_OLD_DATA, and instead added TCP_OLD_SEQUENCE drop reason. Signed-off-by: Eric Dumazet <edumazet@google.com> Link: https://lore.kernel.org/r/20230719064754.2794106-1-edumazet@google.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent af1e2cf commit b446934

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

include/net/dropreason-core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
FN(TCP_OVERWINDOW) \
3131
FN(TCP_OFOMERGE) \
3232
FN(TCP_RFC7323_PAWS) \
33+
FN(TCP_OLD_SEQUENCE) \
3334
FN(TCP_INVALID_SEQUENCE) \
3435
FN(TCP_RESET) \
3536
FN(TCP_INVALID_SYN) \
@@ -188,6 +189,8 @@ enum skb_drop_reason {
188189
* LINUX_MIB_PAWSESTABREJECTED
189190
*/
190191
SKB_DROP_REASON_TCP_RFC7323_PAWS,
192+
/** @SKB_DROP_REASON_TCP_OLD_SEQUENCE: Old SEQ field (duplicate packet) */
193+
SKB_DROP_REASON_TCP_OLD_SEQUENCE,
191194
/** @SKB_DROP_REASON_TCP_INVALID_SEQUENCE: Not acceptable SEQ field */
192195
SKB_DROP_REASON_TCP_INVALID_SEQUENCE,
193196
/** @SKB_DROP_REASON_TCP_RESET: Invalid RST packet */

net/ipv4/tcp_input.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4312,10 +4312,16 @@ static inline bool tcp_paws_discard(const struct sock *sk,
43124312
* (borrowed from freebsd)
43134313
*/
43144314

4315-
static inline bool tcp_sequence(const struct tcp_sock *tp, u32 seq, u32 end_seq)
4315+
static enum skb_drop_reason tcp_sequence(const struct tcp_sock *tp,
4316+
u32 seq, u32 end_seq)
43164317
{
4317-
return !before(end_seq, tp->rcv_wup) &&
4318-
!after(seq, tp->rcv_nxt + tcp_receive_window(tp));
4318+
if (before(end_seq, tp->rcv_wup))
4319+
return SKB_DROP_REASON_TCP_OLD_SEQUENCE;
4320+
4321+
if (after(seq, tp->rcv_nxt + tcp_receive_window(tp)))
4322+
return SKB_DROP_REASON_TCP_INVALID_SEQUENCE;
4323+
4324+
return SKB_NOT_DROPPED_YET;
43194325
}
43204326

43214327
/* When we get a reset we do this. */
@@ -5738,7 +5744,8 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
57385744
}
57395745

57405746
/* Step 1: check sequence number */
5741-
if (!tcp_sequence(tp, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq)) {
5747+
reason = tcp_sequence(tp, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq);
5748+
if (reason) {
57425749
/* RFC793, page 37: "In all states except SYN-SENT, all reset
57435750
* (RST) segments are validated by checking their SEQ-fields."
57445751
* And page 69: "If an incoming segment is not acceptable,
@@ -5755,7 +5762,6 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
57555762
} else if (tcp_reset_check(sk, skb)) {
57565763
goto reset;
57575764
}
5758-
SKB_DR_SET(reason, TCP_INVALID_SEQUENCE);
57595765
goto discard;
57605766
}
57615767

0 commit comments

Comments
 (0)