On Tue, Mar 5, 2024 at 12:22 PM Yonghong Song <yonghong.song@xxxxxxxxx> wrote: > > Introduce a libbpf API bpf_program__attach_sk_msg() which allows > user to get a bpf_link. The API makes auto-deletion easier and > also allows user space application easier as link based APIs > are used for all programs. > > Signed-off-by: Yonghong Song <yonghong.song@xxxxxxxxx> > --- > tools/lib/bpf/libbpf.c | 8 ++++++++ > tools/lib/bpf/libbpf.h | 3 +++ > tools/lib/bpf/libbpf.map | 1 + > 3 files changed, 12 insertions(+) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 97b573516675..b3982bb3f979 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -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_SK_MSG] = "sk_msg", > }; > > static const char * const map_type_name[] = { > @@ -12280,6 +12281,13 @@ bpf_program__attach_netkit(const struct bpf_program *prog, int ifindex, > return bpf_program_attach_fd(prog, ifindex, "netkit", &link_create_opts); > } > > +struct bpf_link * > +bpf_program__attach_sk_msg(const struct bpf_program *prog, int map_fd, > + enum bpf_attach_type attach_type) Why do we need to allow users to override attach_type? Why can't it come from bpf_program's expected attach type? > +{ > + return __bpf_program_attach_fd(prog, map_fd, attach_type, "sk_msg", NULL); > +} > + > struct bpf_link *bpf_program__attach_freplace(const struct bpf_program *prog, > int target_fd, > const char *attach_func_name) > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h > index 5723cbbfcc41..c8448f05e8d6 100644 > --- a/tools/lib/bpf/libbpf.h > +++ b/tools/lib/bpf/libbpf.h > @@ -786,6 +786,9 @@ bpf_program__attach_netns(const struct bpf_program *prog, int netns_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_sk_msg(const struct bpf_program *prog, int map_fd, > + enum bpf_attach_type attach_type); > +LIBBPF_API struct bpf_link * > bpf_program__attach_freplace(const struct bpf_program *prog, > int target_fd, const char *attach_func_name); > > diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map > index 86804fd90dd1..c59986c6dbc5 100644 > --- a/tools/lib/bpf/libbpf.map > +++ b/tools/lib/bpf/libbpf.map > @@ -410,6 +410,7 @@ LIBBPF_1.3.0 { > > LIBBPF_1.4.0 { > global: > + bpf_program__attach_sk_msg; > bpf_token_create; > btf__new_split; > btf_ext__raw_data; > -- > 2.43.0 >