Files
kernel_samsung_a71/include/uapi/linux
Martin KaFai Lau 9ebb87cc5b BACKPORT: bpf: Add struct bpf_tcp_sock and BPF_FUNC_tcp_sock
This patch adds a helper function BPF_FUNC_tcp_sock and it
is currently available for cg_skb and sched_(cls|act):

struct bpf_tcp_sock *bpf_tcp_sock(struct bpf_sock *sk);

int cg_skb_foo(struct __sk_buff *skb) {
	struct bpf_tcp_sock *tp;
	struct bpf_sock *sk;
	__u32 snd_cwnd;

	sk = skb->sk;
	if (!sk)
		return 1;

	tp = bpf_tcp_sock(sk);
	if (!tp)
		return 1;

	snd_cwnd = tp->snd_cwnd;
	/* ... */

	return 1;
}

A 'struct bpf_tcp_sock' is also added to the uapi bpf.h to provide
read-only access.  bpf_tcp_sock has all the existing tcp_sock's fields
that has already been exposed by the bpf_sock_ops.
i.e. no new tcp_sock's fields are exposed in bpf.h.

This helper returns a pointer to the tcp_sock.  If it is not a tcp_sock
or it cannot be traced back to a tcp_sock by sk_to_full_sk(), it
returns NULL.  Hence, the caller needs to check for NULL before
accessing it.

The current use case is to expose members from tcp_sock
to allow a cg_skb_bpf_prog to provide per cgroup traffic
policing/shaping.

Acked-by: Alexei Starovoitov <ast@kernel.org>
Change-Id: I6efe1fd67f02a3a1c489ed5b7f4e86990b9d225a
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2025-10-02 22:14:34 +08:00
..
2018-06-27 11:32:06 +05:30
2024-05-13 18:30:34 +02:00
2024-07-31 15:15:59 +02:00
2019-09-24 08:39:30 -07:00
2023-11-08 11:21:06 +01:00
2018-11-19 11:16:57 +08:00
2025-10-02 22:13:20 +08:00
2024-05-13 18:30:34 +02:00
2024-05-13 18:30:34 +02:00
2024-05-13 18:30:34 +02:00
2021-04-16 11:57:51 +02:00
2021-06-29 13:56:26 +05:30
2018-07-23 20:26:32 -07:00
2019-08-12 13:29:46 -04:00
2020-01-09 14:58:35 -08:00
2023-09-23 10:46:58 +02:00
2024-05-13 18:30:34 +02:00
2022-03-11 10:06:50 +01:00