Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Add a few tcp helper functions and macros to bpf_tracing_net.h

This patch adds a few tcp related helper functions to bpf_tracing_net.h.
They will be useful for both tcp-cc and network tracing related
bpf progs. They have already been in the bpf_tcp_helpers.h. This change
is needed to retire the bpf_tcp_helpers.h and consolidate all tests
to vmlinux.h (i.e. bpf_tracing_net.h).

Some of the helpers (tcp_sk and inet_csk) are also defined in
bpf_cc_cubic.c and they are removed. While at it, remove
the vmlinux.h from bpf_cc_cubic.c. bpf_tracing_net.h (which has
vmlinux.h after this patch) is enough and will be consistent
with the other tcp-cc tests in the later patches.

The other TCP_* macro additions will be needed for the bpf_dctcp
changes in the later patch.

Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20240509175026.3423614-3-martin.lau@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Martin KaFai Lau and committed by
Alexei Starovoitov
cbaec46d c0338e60

+42 -13
+1 -13
tools/testing/selftests/bpf/progs/bpf_cc_cubic.c
··· 13 13 * kernel functions. 14 14 */ 15 15 16 - #include "vmlinux.h" 17 - 16 + #include "bpf_tracing_net.h" 18 17 #include <bpf/bpf_helpers.h> 19 18 #include <bpf/bpf_tracing.h> 20 - #include "bpf_tracing_net.h" 21 19 22 20 #define BPF_STRUCT_OPS(name, args...) \ 23 21 SEC("struct_ops/"#name) \ ··· 37 39 extern __u32 tcp_reno_undo_cwnd(struct sock *sk) __ksym; 38 40 extern void cubictcp_acked(struct sock *sk, const struct ack_sample *sample) __ksym; 39 41 extern void cubictcp_cong_avoid(struct sock *sk, __u32 ack, __u32 acked) __ksym; 40 - 41 - static struct inet_connection_sock *inet_csk(const struct sock *sk) 42 - { 43 - return (struct inet_connection_sock *)sk; 44 - } 45 - 46 - static struct tcp_sock *tcp_sk(const struct sock *sk) 47 - { 48 - return (struct tcp_sock *)sk; 49 - } 50 42 51 43 static bool before(__u32 seq1, __u32 seq2) 52 44 {
+41
tools/testing/selftests/bpf/progs/bpf_tracing_net.h
··· 2 2 #ifndef __BPF_TRACING_NET_H__ 3 3 #define __BPF_TRACING_NET_H__ 4 4 5 + #include <vmlinux.h> 6 + #include <bpf/bpf_core_read.h> 7 + 5 8 #define AF_INET 2 6 9 #define AF_INET6 10 7 10 ··· 48 45 #define TCP_SAVED_SYN 28 49 46 #define TCP_CA_NAME_MAX 16 50 47 #define TCP_NAGLE_OFF 1 48 + 49 + #define TCP_ECN_OK 1 50 + #define TCP_ECN_QUEUE_CWR 2 51 + #define TCP_ECN_DEMAND_CWR 4 52 + #define TCP_ECN_SEEN 8 53 + 54 + #define TCP_CONG_NEEDS_ECN 0x2 51 55 52 56 #define ICSK_TIME_RETRANS 1 53 57 #define ICSK_TIME_PROBE0 3 ··· 138 128 #define tw_v6_rcv_saddr __tw_common.skc_v6_rcv_saddr 139 129 140 130 #define tcp_jiffies32 ((__u32)bpf_jiffies64()) 131 + 132 + static inline struct inet_connection_sock *inet_csk(const struct sock *sk) 133 + { 134 + return (struct inet_connection_sock *)sk; 135 + } 136 + 137 + static inline void *inet_csk_ca(const struct sock *sk) 138 + { 139 + return (void *)inet_csk(sk)->icsk_ca_priv; 140 + } 141 + 142 + static inline struct tcp_sock *tcp_sk(const struct sock *sk) 143 + { 144 + return (struct tcp_sock *)sk; 145 + } 146 + 147 + static inline bool tcp_in_slow_start(const struct tcp_sock *tp) 148 + { 149 + return tp->snd_cwnd < tp->snd_ssthresh; 150 + } 151 + 152 + static inline bool tcp_is_cwnd_limited(const struct sock *sk) 153 + { 154 + const struct tcp_sock *tp = tcp_sk(sk); 155 + 156 + /* If in slow start, ensure cwnd grows to twice what was ACKed. */ 157 + if (tcp_in_slow_start(tp)) 158 + return tp->snd_cwnd < 2 * tp->max_packets_out; 159 + 160 + return !!BPF_CORE_READ_BITFIELD(tp, is_cwnd_limited); 161 + } 141 162 142 163 #endif