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
..
2024-07-31 15:16:00 +02:00
2022-08-25 11:11:19 +02:00
2018-08-13 00:42:51 -07:00
2019-09-19 09:08:00 +02:00
2024-05-13 18:30:34 +02:00
2025-09-29 21:58:19 +08:00
2018-11-14 04:46:23 -08:00
2018-06-27 11:32:06 +05:30
2020-06-25 15:42:02 +02:00
2025-09-17 17:26:40 +08:00
2024-05-13 18:30:34 +02:00
2025-10-02 22:14:14 +08:00
2024-10-11 16:00:11 +02:00
2023-08-11 11:33:38 +02:00
2022-12-08 11:16:29 +01:00
2020-09-15 02:54:09 -07:00
2023-08-11 11:33:51 +02:00
2025-10-02 22:12:46 +08:00
2025-10-02 22:14:34 +08:00
2025-10-02 22:13:20 +08:00
2025-10-02 22:14:29 +08:00
2018-12-05 19:41:11 +01:00
2024-03-08 08:21:29 +00:00
2022-11-25 17:36:45 +01:00
2019-12-31 12:36:59 +01:00
2025-02-07 11:46:05 +00:00
2019-08-06 19:05:24 +02:00
2024-05-13 18:30:34 +02:00
2023-05-17 11:11:43 +02:00
2020-04-13 10:34:26 +02:00
2025-09-29 21:59:33 +08:00
2019-06-06 13:01:03 -07:00
2021-01-09 13:37:37 +01:00
2024-05-13 18:30:34 +02:00
2025-10-02 22:13:09 +08:00
2024-07-31 15:15:59 +02:00
2020-08-17 00:53:38 -07:00
2019-09-24 08:39:30 -07:00
2024-07-31 15:15:59 +02:00
2023-11-08 11:21:06 +01:00
2018-11-19 11:16:57 +08:00
2020-05-06 16:00:34 +08:00
2020-02-22 22:09:34 -05:00
2020-12-29 13:46:50 +01:00
2019-02-20 10:20:55 +01:00
2019-04-03 06:59:52 -07:00
2020-03-04 16:09:34 -05:00
2024-05-13 18:30:34 +02:00
2025-10-02 22:13:20 +08:00
2021-06-30 08:48:51 -04:00
2021-01-27 08:19:03 -08:00
2019-02-27 10:08:07 +01:00
2024-10-11 16:00:11 +02:00
2024-07-31 15:16:01 +02:00
2020-03-23 21:20:56 -07:00
2025-10-02 22:13:10 +08:00
2019-02-05 17:36:19 -07:00
2024-05-13 18:30:34 +02:00
2020-01-13 19:40:37 +00:00
2021-01-09 13:37:37 +01:00
2020-05-02 17:24:11 +02:00
2020-09-23 10:46:34 +02:00
2019-02-20 10:20:55 +01:00
2021-01-09 13:37:37 +01:00
2025-10-02 22:13:41 +08:00
2024-05-13 18:30:34 +02:00
2024-05-13 18:30:34 +02:00
2024-08-08 15:52:17 +00:00
2020-01-09 13:19:41 -08:00
2025-09-29 21:58:19 +08:00
2021-01-09 13:37:37 +01:00
2020-09-09 19:03:12 +02:00
2020-08-17 20:03:43 -07:00
2020-08-20 01:16:21 -07:00
2020-02-02 20:08:23 -08:00
2020-04-06 11:25:59 +05:30
2020-03-25 12:43:10 +05:30
2020-07-14 15:33:12 -04:00
2020-04-15 11:54:10 +05:30
2018-08-24 13:09:03 +02:00
2021-04-16 11:57:51 +02:00
2020-01-29 18:00:16 +00:00
2024-10-11 16:00:11 +02:00
2022-01-05 12:33:48 +01:00
2020-11-05 11:07:02 +01:00
2019-07-21 09:04:16 +02:00
2025-01-18 15:31:34 +01:00
2018-11-19 18:19:47 -08:00
2018-12-18 11:29:52 -08:00
2025-10-02 22:13:56 +08:00
2021-12-08 08:46:51 +01:00
2025-10-02 22:13:22 +08:00
2019-10-07 14:56:02 -04:00
2021-06-29 13:56:26 +05:30
2021-06-29 13:56:26 +05:30
2019-07-29 21:05:09 +05:30
2018-05-15 15:15:59 -07:00
2019-08-14 09:28:38 +05:30
2018-07-23 20:26:32 -07:00
2019-01-03 10:22:07 +05:30
2018-10-30 11:01:12 -07:00
2022-06-25 11:46:27 +02:00
2019-05-20 16:47:13 -07:00
2019-08-12 13:29:46 -04:00
2018-11-23 08:19:26 +01:00
2018-05-22 18:54:04 +02:00
2018-05-18 10:28:24 +05:30
2018-05-18 10:28:24 +05:30
2025-10-02 22:13:21 +08:00
2018-04-12 09:39:59 -07:00
2021-09-22 11:45:29 +02:00
2020-04-02 16:34:29 +02:00
2024-08-08 15:52:17 +00:00
2021-09-07 23:21:26 -07:00
2018-07-02 15:18:13 -07:00
2019-06-17 19:52:44 +02:00
2018-05-14 00:06:00 -07:00
2020-01-09 14:58:35 -08:00
2023-01-18 09:26:26 +01:00
2023-09-23 10:46:58 +02:00
2024-10-11 16:00:11 +02:00
2019-03-25 12:40:15 +05:30
2020-06-17 12:53:11 +05:30
2019-06-09 09:18:11 +02:00
2021-05-22 10:57:29 +02:00
2018-11-16 14:44:23 -07:00
2025-09-27 22:38:53 +08:00
2024-05-13 18:30:34 +02:00
2024-10-11 16:00:11 +02:00
2020-01-12 09:42:26 +02:00
2020-09-28 17:55:43 -07:00
2024-10-11 16:00:11 +02:00
2020-01-24 18:05:38 -08:00
2020-12-02 08:34:39 +01:00
2024-05-13 18:30:34 +02:00
2022-03-11 10:06:50 +01:00
2024-10-10 10:27:23 +00:00