libbpf: Add bpf_link support for BPF_PROG_TYPE_SOCKMAP
authorYonghong Song <yonghong.song@linux.dev>
Wed, 10 Apr 2024 04:35:32 +0000 (21:35 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 11 Apr 2024 02:52:25 +0000 (19:52 -0700)
Introduce a libbpf API function bpf_program__attach_sockmap()
which allow user to get a bpf_link for their corresponding programs.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Reviewed-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20240410043532.3737722-1-yonghong.song@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf.h
tools/lib/bpf/libbpf.map

index b091154bc5b58462fbb80065df64444d935f4340..97eb6e5dd7c8bdabd0c63cd815a49935642c2f1d 100644 (file)
@@ -149,6 +149,7 @@ static const char * const link_type_name[] = {
        [BPF_LINK_TYPE_TCX]                     = "tcx",
        [BPF_LINK_TYPE_UPROBE_MULTI]            = "uprobe_multi",
        [BPF_LINK_TYPE_NETKIT]                  = "netkit",
+       [BPF_LINK_TYPE_SOCKMAP]                 = "sockmap",
 };
 
 static const char * const map_type_name[] = {
@@ -12533,6 +12534,12 @@ bpf_program__attach_netns(const struct bpf_program *prog, int netns_fd)
        return bpf_program_attach_fd(prog, netns_fd, "netns", NULL);
 }
 
+struct bpf_link *
+bpf_program__attach_sockmap(const struct bpf_program *prog, int map_fd)
+{
+       return bpf_program_attach_fd(prog, map_fd, "sockmap", NULL);
+}
+
 struct bpf_link *bpf_program__attach_xdp(const struct bpf_program *prog, int ifindex)
 {
        /* target_fd/target_ifindex use the same field in LINK_CREATE */
index 4f775a6dcaa0076010a0493027a1a3ddfccb363b..1333ae20ebe68b10bc466b03d6b7873db2b741a4 100644 (file)
@@ -795,6 +795,8 @@ bpf_program__attach_cgroup(const struct bpf_program *prog, int cgroup_fd);
 LIBBPF_API struct bpf_link *
 bpf_program__attach_netns(const struct bpf_program *prog, int netns_fd);
 LIBBPF_API struct bpf_link *
+bpf_program__attach_sockmap(const struct bpf_program *prog, int map_fd);
+LIBBPF_API struct bpf_link *
 bpf_program__attach_xdp(const struct bpf_program *prog, int ifindex);
 LIBBPF_API struct bpf_link *
 bpf_program__attach_freplace(const struct bpf_program *prog,
index 23d82bba021a396e87fbc6053a12b7925762d207..c1ce8aa3520bf4a833fad43de1db5b1caef62c07 100644 (file)
@@ -419,6 +419,7 @@ LIBBPF_1.4.0 {
 
 LIBBPF_1.5.0 {
        global:
+               bpf_program__attach_sockmap;
                ring__consume_n;
                ring_buffer__consume_n;
 } LIBBPF_1.4.0;