diff mbox series

[RFC,3/3] bpf: set attached sockmap id in attach_name

Message ID 20220218095612.52082-4-laoar.shao@gmail.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series bpf: show attached name for progs without btf name | expand

Checks

Context Check Description
bpf/vmtest-bpf-PR fail PR summary
bpf/vmtest-bpf fail VM_Test
netdev/tree_selection success Guessing tree name failed - patch did not apply, async

Commit Message

Yafang Shao Feb. 18, 2022, 9:56 a.m. UTC
Set the attached name when a bpf prog is attached to a sockmap, and
unset it when the bpf prog is detached.

Below is the result after this change,
$ cat progs.debug
  id name             attached
   5 dump_bpf_map     bpf_iter_bpf_map
   7 dump_bpf_prog    bpf_iter_bpf_prog
  17 bpf_sockmap      cgroup:/
  19 bpf_redir_proxy  sockmap:9

$ cat maps.debug
  id name             max_entries
   3 iterator.rodata      1
   9 ltcp_map         65535

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 net/core/sock_map.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/net/core/sock_map.c b/net/core/sock_map.c
index f39ef79ced67..ce8d0bbba6cc 100644
--- a/net/core/sock_map.c
+++ b/net/core/sock_map.c
@@ -1411,6 +1411,7 @@  static int sock_map_prog_update(struct bpf_map *map, struct bpf_prog *prog,
 {
 	struct sk_psock_progs *progs = sock_map_progs(map);
 	struct bpf_prog **pprog;
+	char sockmap_info[16];
 
 	if (!progs)
 		return -EOPNOTSUPP;
@@ -1438,8 +1439,13 @@  static int sock_map_prog_update(struct bpf_map *map, struct bpf_prog *prog,
 		return -EOPNOTSUPP;
 	}
 
-	if (old)
+	if (old) {
+		kfree(prog->aux->attach_name);
 		return psock_replace_prog(pprog, prog, old);
+	}
+
+	snprintf(sockmap_info, 16, "sockmap:%d", map->id);
+	prog->aux->attach_name = kstrdup(sockmap_info, GFP_KERNEL);
 
 	psock_set_prog(pprog, prog);
 	return 0;