Skip to content

Commit caf9388

Browse files
committedApr 25, 2024
Merge branch 'tcp-trace-next'
Philo Lu says: ==================== tcp: update TCPCB_EVER_RETRANS after trace_tcp_retransmit_skb() Move TCPCB_EVER_RETRANS updating after the trace_tcp_retransmit_skb() in __tcp_retransmit_skb(), and then we are aware of whether the skb has ever been retransmitted in this tracepoint. This can be used, e.g., to get retransmission efficiency by counting skbs w/ and w/o TCPCB_EVER_RETRANS (through bpf tracing programs). For this purpose, TCPCB_EVER_RETRANS is also needed to be exposed to bpf. Previously, the flags are defined as macros in struct tcp_skb_cb. I moved them out into a new enum, and then they can be accessed with vmlinux.h. We have discussed to achieve this with BPF_SOCK_OPS in [0], and using tracepoint is thought to be a better solution. [0] https://lore.kernel.org/all/[email protected]/ ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents d806871 + 2bf90a5 commit caf9388

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed
 

‎include/net/tcp.h

+13-9
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,19 @@ static inline u32 tcp_rsk_tsval(const struct tcp_request_sock *treq)
928928

929929
#define TCPHDR_SYN_ECN (TCPHDR_SYN | TCPHDR_ECE | TCPHDR_CWR)
930930

931+
/* State flags for sacked in struct tcp_skb_cb */
932+
enum tcp_skb_cb_sacked_flags {
933+
TCPCB_SACKED_ACKED = (1 << 0), /* SKB ACK'd by a SACK block */
934+
TCPCB_SACKED_RETRANS = (1 << 1), /* SKB retransmitted */
935+
TCPCB_LOST = (1 << 2), /* SKB is lost */
936+
TCPCB_TAGBITS = (TCPCB_SACKED_ACKED | TCPCB_SACKED_RETRANS |
937+
TCPCB_LOST), /* All tag bits */
938+
TCPCB_REPAIRED = (1 << 4), /* SKB repaired (no skb_mstamp_ns) */
939+
TCPCB_EVER_RETRANS = (1 << 7), /* Ever retransmitted frame */
940+
TCPCB_RETRANS = (TCPCB_SACKED_RETRANS | TCPCB_EVER_RETRANS |
941+
TCPCB_REPAIRED),
942+
};
943+
931944
/* This is what the send packet queuing engine uses to pass
932945
* TCP per-packet control information to the transmission code.
933946
* We also store the host-order sequence numbers in here too.
@@ -950,15 +963,6 @@ struct tcp_skb_cb {
950963
__u8 tcp_flags; /* TCP header flags. (tcp[13]) */
951964

952965
__u8 sacked; /* State flags for SACK. */
953-
#define TCPCB_SACKED_ACKED 0x01 /* SKB ACK'd by a SACK block */
954-
#define TCPCB_SACKED_RETRANS 0x02 /* SKB retransmitted */
955-
#define TCPCB_LOST 0x04 /* SKB is lost */
956-
#define TCPCB_TAGBITS 0x07 /* All tag bits */
957-
#define TCPCB_REPAIRED 0x10 /* SKB repaired (no skb_mstamp_ns) */
958-
#define TCPCB_EVER_RETRANS 0x80 /* Ever retransmitted frame */
959-
#define TCPCB_RETRANS (TCPCB_SACKED_RETRANS|TCPCB_EVER_RETRANS| \
960-
TCPCB_REPAIRED)
961-
962966
__u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
963967
__u8 txstamp_ack:1, /* Record TX timestamp for ack? */
964968
eor:1, /* Is skb MSG_EOR marked? */

‎net/ipv4/tcp_output.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -3418,11 +3418,6 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
34183418
err = tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC);
34193419
}
34203420

3421-
/* To avoid taking spuriously low RTT samples based on a timestamp
3422-
* for a transmit that never happened, always mark EVER_RETRANS
3423-
*/
3424-
TCP_SKB_CB(skb)->sacked |= TCPCB_EVER_RETRANS;
3425-
34263421
if (BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_RETRANS_CB_FLAG))
34273422
tcp_call_bpf_3arg(sk, BPF_SOCK_OPS_RETRANS_CB,
34283423
TCP_SKB_CB(skb)->seq, segs, err);
@@ -3432,6 +3427,12 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
34323427
} else if (err != -EBUSY) {
34333428
NET_ADD_STATS(sock_net(sk), LINUX_MIB_TCPRETRANSFAIL, segs);
34343429
}
3430+
3431+
/* To avoid taking spuriously low RTT samples based on a timestamp
3432+
* for a transmit that never happened, always mark EVER_RETRANS
3433+
*/
3434+
TCP_SKB_CB(skb)->sacked |= TCPCB_EVER_RETRANS;
3435+
34353436
return err;
34363437
}
34373438

0 commit comments

Comments
 (0)
Please sign in to comment.