Skip to content

Commit 23729ff

Browse files
fomichevborkmann
authored andcommitted
bpf: add BPF_CGROUP_SOCK_OPS callback that is executed on every RTT
Performance impact should be minimal because it's under a new BPF_SOCK_OPS_RTT_CB_FLAG flag that has to be explicitly enabled. Suggested-by: Eric Dumazet <edumazet@google.com> Cc: Eric Dumazet <edumazet@google.com> Cc: Priyaranjan Jha <priyarjha@google.com> Cc: Yuchung Cheng <ycheng@google.com> Cc: Soheil Hassas Yeganeh <soheil@google.com> Acked-by: Soheil Hassas Yeganeh <soheil@google.com> Acked-by: Yuchung Cheng <ycheng@google.com> Signed-off-by: Stanislav Fomichev <sdf@google.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent d2f5bbb commit 23729ff

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎include/net/tcp.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,6 +2221,14 @@ static inline bool tcp_bpf_ca_needs_ecn(struct sock *sk)
22212221
return (tcp_call_bpf(sk, BPF_SOCK_OPS_NEEDS_ECN, 0, NULL) == 1);
22222222
}
22232223

2224+
static inline void tcp_bpf_rtt(struct sock *sk)
2225+
{
2226+
struct tcp_sock *tp = tcp_sk(sk);
2227+
2228+
if (BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_RTT_CB_FLAG))
2229+
tcp_call_bpf(sk, BPF_SOCK_OPS_RTT_CB, 0, NULL);
2230+
}
2231+
22242232
#if IS_ENABLED(CONFIG_SMC)
22252233
extern struct static_key_false tcp_have_smc;
22262234
#endif

‎include/uapi/linux/bpf.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,7 @@ union bpf_attr {
17701770
* * **BPF_SOCK_OPS_RTO_CB_FLAG** (retransmission time out)
17711771
* * **BPF_SOCK_OPS_RETRANS_CB_FLAG** (retransmission)
17721772
* * **BPF_SOCK_OPS_STATE_CB_FLAG** (TCP state change)
1773+
* * **BPF_SOCK_OPS_RTT_CB_FLAG** (every RTT)
17731774
*
17741775
* Therefore, this function can be used to clear a callback flag by
17751776
* setting the appropriate bit to zero. e.g. to disable the RTO
@@ -3314,7 +3315,8 @@ struct bpf_sock_ops {
33143315
#define BPF_SOCK_OPS_RTO_CB_FLAG (1<<0)
33153316
#define BPF_SOCK_OPS_RETRANS_CB_FLAG (1<<1)
33163317
#define BPF_SOCK_OPS_STATE_CB_FLAG (1<<2)
3317-
#define BPF_SOCK_OPS_ALL_CB_FLAGS 0x7 /* Mask of all currently
3318+
#define BPF_SOCK_OPS_RTT_CB_FLAG (1<<3)
3319+
#define BPF_SOCK_OPS_ALL_CB_FLAGS 0xF /* Mask of all currently
33183320
* supported cb flags
33193321
*/
33203322

@@ -3369,6 +3371,8 @@ enum {
33693371
BPF_SOCK_OPS_TCP_LISTEN_CB, /* Called on listen(2), right after
33703372
* socket transition to LISTEN state.
33713373
*/
3374+
BPF_SOCK_OPS_RTT_CB, /* Called on every RTT.
3375+
*/
33723376
};
33733377

33743378
/* List of TCP states. There is a build check in net/ipv4/tcp.c to detect

‎net/ipv4/tcp_input.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ static void tcp_rtt_estimator(struct sock *sk, long mrtt_us)
778778
tp->rttvar_us -= (tp->rttvar_us - tp->mdev_max_us) >> 2;
779779
tp->rtt_seq = tp->snd_nxt;
780780
tp->mdev_max_us = tcp_rto_min_us(sk);
781+
782+
tcp_bpf_rtt(sk);
781783
}
782784
} else {
783785
/* no previous measure. */
@@ -786,6 +788,8 @@ static void tcp_rtt_estimator(struct sock *sk, long mrtt_us)
786788
tp->rttvar_us = max(tp->mdev_us, tcp_rto_min_us(sk));
787789
tp->mdev_max_us = tp->rttvar_us;
788790
tp->rtt_seq = tp->snd_nxt;
791+
792+
tcp_bpf_rtt(sk);
789793
}
790794
tp->srtt_us = max(1U, srtt);
791795
}

0 commit comments

Comments
 (0)