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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 net/core/sock_map.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

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;
-- 
2.17.1




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux