TencentOS-kernel/kernel/bpf
Martin KaFai Lau 315866f0c3 bpf: INET_DIAG support in bpf_sk_storage
[upstream commit 1ed4d92458a969e71e7914550b6f0c730c14d84e]

This patch adds INET_DIAG support to bpf_sk_storage.

1. Although this series adds bpf_sk_storage diag capability to inet sk,
   bpf_sk_storage is in general applicable to all fullsock.  Hence, the
   bpf_sk_storage logic will operate on SK_DIAG_* nlattr.  The caller
   will pass in its specific nesting nlattr (e.g. INET_DIAG_*) as
   the argument.

2. The request will be like:
	INET_DIAG_REQ_SK_BPF_STORAGES (nla_nest) (defined in latter patch)
		SK_DIAG_BPF_STORAGE_REQ_MAP_FD (nla_put_u32)
		SK_DIAG_BPF_STORAGE_REQ_MAP_FD (nla_put_u32)
		......

   Considering there could have multiple bpf_sk_storages in a sk,
   instead of reusing INET_DIAG_INFO ("ss -i"),  the user can select
   some specific bpf_sk_storage to dump by specifying an array of
   SK_DIAG_BPF_STORAGE_REQ_MAP_FD.

   If no SK_DIAG_BPF_STORAGE_REQ_MAP_FD is specified (i.e. an empty
   INET_DIAG_REQ_SK_BPF_STORAGES), it will dump all bpf_sk_storages
   of a sk.

3. The reply will be like:
	INET_DIAG_BPF_SK_STORAGES (nla_nest) (defined in latter patch)
		SK_DIAG_BPF_STORAGE (nla_nest)
			SK_DIAG_BPF_STORAGE_MAP_ID (nla_put_u32)
			SK_DIAG_BPF_STORAGE_MAP_VALUE (nla_reserve_64bit)
		SK_DIAG_BPF_STORAGE (nla_nest)
			SK_DIAG_BPF_STORAGE_MAP_ID (nla_put_u32)
			SK_DIAG_BPF_STORAGE_MAP_VALUE (nla_reserve_64bit)
		......

4. Unlike other INET_DIAG info of a sk which is pretty static, the size
   required to dump the bpf_sk_storage(s) of a sk is dynamic as the
   system adding more bpf_sk_storage_map.  It is hard to set a static
   min_dump_alloc size.

   Hence, this series learns it at the runtime and adjust the
   cb->min_dump_alloc as it iterates all sk(s) of a system.  The
   "unsigned int *res_diag_size" in bpf_sk_storage_diag_put()
   is for this purpose.

   The next patch will update the cb->min_dump_alloc as it
   iterates the sk(s).

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20200225230421.1975729-1-kafai@fb.com
2022-08-30 11:33:28 +08:00
..
Makefile bpf: Add bpf_prog iterator 2022-08-30 11:33:28 +08:00
arraymap.c bpf: Implement bpf iterator for array maps 2022-08-30 11:33:28 +08:00
bpf_iter.c bpf: Change uapi for bpf iterator map elements 2022-08-30 11:33:28 +08:00
bpf_lru_list.c bpf_lru_list: Read double-checked variable once without lock 2021-04-12 12:52:15 +08:00
bpf_lru_list.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
bpf_lsm.c bpf: lsm: Implement attach, detach and execution 2022-08-30 11:33:21 +08:00
bpf_struct_ops.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00
bpf_struct_ops_types.h bpf: tcp: Support tcp_congestion_ops in bpf 2022-08-30 11:33:19 +08:00
btf.c bpf: Support readonly/readwrite buffers in verifier 2022-08-30 11:33:28 +08:00
cgroup.c bpf, cgroup: Return ENOLINK for auto-detached links on update 2022-08-30 11:33:23 +08:00
core.c bpf: Implement CAP_BPF 2022-08-30 11:33:26 +08:00
cpumap.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00
devmap.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00
disasm.c bpf: Introduce BPF nospec instruction for mitigating Spectre v4 2022-08-30 11:33:16 +08:00
disasm.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
dispatcher.c bpf: Introduce BPF dispatcher 2022-08-30 11:33:19 +08:00
hashtab.c bpf: Implement bpf iterator for hash maps 2022-08-30 11:33:28 +08:00
helpers.c bpf: Fix helper bpf_map_peek_elem_proto pointing to wrong callback 2021-03-16 16:44:00 +08:00
inode.c bpf: Create file bpf iterator 2022-08-30 11:33:25 +08:00
local_storage.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00
lpm_trie.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00
map_in_map.c bpf: Implement CAP_BPF 2022-08-30 11:33:26 +08:00
map_in_map.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
map_iter.c bpf: Change uapi for bpf iterator map elements 2022-08-30 11:33:28 +08:00
net_namespace.c inet: Run SK_LOOKUP BPF program on socket lookup 2022-08-30 11:33:24 +08:00
offload.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
percpu_freelist.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
percpu_freelist.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
prog_iter.c bpf: Refactor bpf_iter_reg to have separate seq_info member 2022-08-30 11:33:28 +08:00
queue_stack_maps.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00
reuseport_array.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00
stackmap.c bpf: Resolve BTF IDs in vmlinux image 2022-08-30 11:33:27 +08:00
syscall.c bpf: INET_DIAG support in bpf_sk_storage 2022-08-30 11:33:28 +08:00
sysfs_btf.c bpf: Fix sysfs export of empty BTF section 2021-03-16 16:37:55 +08:00
task_iter.c bpf: Refactor to provide aux info to bpf_iter_init_seq_priv_t 2022-08-30 11:33:28 +08:00
tnum.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
trampoline.c bpf: lsm: Implement attach, detach and execution 2022-08-30 11:33:21 +08:00
verifier.c bpf: Support readonly/readwrite buffers in verifier 2022-08-30 11:33:28 +08:00
xskmap.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00