diff mbox series

[bpf-next,v5,1/5] bpf, sk_msg: add some generic helpers that may be useful from sk_msg

Message ID 159033903373.12355.15489763099696629346.stgit@john-Precision-5820-Tower
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series bpf: Add sk_msg and networking helpers | expand

Commit Message

John Fastabend May 24, 2020, 4:50 p.m. UTC
Add these generic helpers that may be useful to use from sk_msg programs.
The helpers do not depend on ctx so we can simply add them here,

 BPF_FUNC_perf_event_output
 BPF_FUNC_get_current_uid_gid
 BPF_FUNC_get_current_pid_tgid
 BPF_FUNC_get_current_comm
 BPF_FUNC_get_current_cgroup_id
 BPF_FUNC_get_current_ancestor_cgroup_id
 BPF_FUNC_get_cgroup_classid

Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 net/core/filter.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Daniel Borkmann May 25, 2020, 9:51 p.m. UTC | #1
On 5/24/20 6:50 PM, John Fastabend wrote:
> Add these generic helpers that may be useful to use from sk_msg programs.
> The helpers do not depend on ctx so we can simply add them here,
> 
>   BPF_FUNC_perf_event_output
>   BPF_FUNC_get_current_uid_gid
>   BPF_FUNC_get_current_pid_tgid
>   BPF_FUNC_get_current_comm

Hmm, added helpers below are what you list here except get_current_comm.
Was this forgotten to be added here?

>   BPF_FUNC_get_current_cgroup_id
>   BPF_FUNC_get_current_ancestor_cgroup_id
>   BPF_FUNC_get_cgroup_classid
> 
> Acked-by: Yonghong Song <yhs@fb.com>
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>
> ---
>   net/core/filter.c |   16 ++++++++++++++++
>   1 file changed, 16 insertions(+)
> 
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 822d662..a56046a 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -6443,6 +6443,22 @@ sk_msg_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
>   		return &bpf_msg_push_data_proto;
>   	case BPF_FUNC_msg_pop_data:
>   		return &bpf_msg_pop_data_proto;
> +	case BPF_FUNC_perf_event_output:
> +		return &bpf_event_output_data_proto;
> +	case BPF_FUNC_get_current_uid_gid:
> +		return &bpf_get_current_uid_gid_proto;
> +	case BPF_FUNC_get_current_pid_tgid:
> +		return &bpf_get_current_pid_tgid_proto;
> +#ifdef CONFIG_CGROUPS
> +	case BPF_FUNC_get_current_cgroup_id:
> +		return &bpf_get_current_cgroup_id_proto;
> +	case BPF_FUNC_get_current_ancestor_cgroup_id:
> +		return &bpf_get_current_ancestor_cgroup_id_proto;
> +#endif
> +#ifdef CONFIG_CGROUP_NET_CLASSID
> +	case BPF_FUNC_get_cgroup_classid:
> +		return &bpf_get_cgroup_classid_curr_proto;
> +#endif
>   	default:
>   		return bpf_base_func_proto(func_id);
>   	}
>
John Fastabend May 25, 2020, 10:57 p.m. UTC | #2
Daniel Borkmann wrote:
> On 5/24/20 6:50 PM, John Fastabend wrote:
> > Add these generic helpers that may be useful to use from sk_msg programs.
> > The helpers do not depend on ctx so we can simply add them here,
> > 
> >   BPF_FUNC_perf_event_output
> >   BPF_FUNC_get_current_uid_gid
> >   BPF_FUNC_get_current_pid_tgid
> >   BPF_FUNC_get_current_comm
> 
> Hmm, added helpers below are what you list here except get_current_comm.
> Was this forgotten to be added here?

Forgot to update commit messages. I dropped it because it wasn't clear to
me it was very useful or how I would use it from this context. I figure we
can add it later if its needed.

> 
> >   BPF_FUNC_get_current_cgroup_id
> >   BPF_FUNC_get_current_ancestor_cgroup_id
> >   BPF_FUNC_get_cgroup_classid
> > 
> > Acked-by: Yonghong Song <yhs@fb.com>
> > Signed-off-by: John Fastabend <john.fastabend@gmail.com>
> > ---
> >   net/core/filter.c |   16 ++++++++++++++++
> >   1 file changed, 16 insertions(+)
> > 
> > diff --git a/net/core/filter.c b/net/core/filter.c
> > index 822d662..a56046a 100644
> > --- a/net/core/filter.c
> > +++ b/net/core/filter.c
> > @@ -6443,6 +6443,22 @@ sk_msg_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
> >   		return &bpf_msg_push_data_proto;
> >   	case BPF_FUNC_msg_pop_data:
> >   		return &bpf_msg_pop_data_proto;
> > +	case BPF_FUNC_perf_event_output:
> > +		return &bpf_event_output_data_proto;
> > +	case BPF_FUNC_get_current_uid_gid:
> > +		return &bpf_get_current_uid_gid_proto;
> > +	case BPF_FUNC_get_current_pid_tgid:
> > +		return &bpf_get_current_pid_tgid_proto;
> > +#ifdef CONFIG_CGROUPS
> > +	case BPF_FUNC_get_current_cgroup_id:
> > +		return &bpf_get_current_cgroup_id_proto;
> > +	case BPF_FUNC_get_current_ancestor_cgroup_id:
> > +		return &bpf_get_current_ancestor_cgroup_id_proto;
> > +#endif
> > +#ifdef CONFIG_CGROUP_NET_CLASSID
> > +	case BPF_FUNC_get_cgroup_classid:
> > +		return &bpf_get_cgroup_classid_curr_proto;
> > +#endif
> >   	default:
> >   		return bpf_base_func_proto(func_id);
> >   	}
> > 
>
Andrii Nakryiko May 26, 2020, 6:33 p.m. UTC | #3
On Mon, May 25, 2020 at 3:57 PM John Fastabend <john.fastabend@gmail.com> wrote:
>
> Daniel Borkmann wrote:
> > On 5/24/20 6:50 PM, John Fastabend wrote:
> > > Add these generic helpers that may be useful to use from sk_msg programs.
> > > The helpers do not depend on ctx so we can simply add them here,
> > >
> > >   BPF_FUNC_perf_event_output
> > >   BPF_FUNC_get_current_uid_gid
> > >   BPF_FUNC_get_current_pid_tgid
> > >   BPF_FUNC_get_current_comm
> >
> > Hmm, added helpers below are what you list here except get_current_comm.
> > Was this forgotten to be added here?
>
> Forgot to update commit messages. I dropped it because it wasn't clear to
> me it was very useful or how I would use it from this context. I figure we
> can add it later if its needed.

But it's also not harmful in any way and is in a similar group as
get_current_pid_tgid. So let's add it sooner rather than later. There
is no cost in allowing this, right?

>
> >
> > >   BPF_FUNC_get_current_cgroup_id
> > >   BPF_FUNC_get_current_ancestor_cgroup_id
> > >   BPF_FUNC_get_cgroup_classid
> > >
> > > Acked-by: Yonghong Song <yhs@fb.com>
> > > Signed-off-by: John Fastabend <john.fastabend@gmail.com>
> > > ---
> > >   net/core/filter.c |   16 ++++++++++++++++
> > >   1 file changed, 16 insertions(+)
> > >
> > > diff --git a/net/core/filter.c b/net/core/filter.c
> > > index 822d662..a56046a 100644
> > > --- a/net/core/filter.c
> > > +++ b/net/core/filter.c
> > > @@ -6443,6 +6443,22 @@ sk_msg_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
> > >             return &bpf_msg_push_data_proto;
> > >     case BPF_FUNC_msg_pop_data:
> > >             return &bpf_msg_pop_data_proto;
> > > +   case BPF_FUNC_perf_event_output:
> > > +           return &bpf_event_output_data_proto;
> > > +   case BPF_FUNC_get_current_uid_gid:
> > > +           return &bpf_get_current_uid_gid_proto;
> > > +   case BPF_FUNC_get_current_pid_tgid:
> > > +           return &bpf_get_current_pid_tgid_proto;
> > > +#ifdef CONFIG_CGROUPS
> > > +   case BPF_FUNC_get_current_cgroup_id:
> > > +           return &bpf_get_current_cgroup_id_proto;
> > > +   case BPF_FUNC_get_current_ancestor_cgroup_id:
> > > +           return &bpf_get_current_ancestor_cgroup_id_proto;
> > > +#endif
> > > +#ifdef CONFIG_CGROUP_NET_CLASSID
> > > +   case BPF_FUNC_get_cgroup_classid:
> > > +           return &bpf_get_cgroup_classid_curr_proto;
> > > +#endif
> > >     default:
> > >             return bpf_base_func_proto(func_id);
> > >     }
> > >
> >
>
>
John Fastabend May 26, 2020, 8:51 p.m. UTC | #4
Andrii Nakryiko wrote:
> On Mon, May 25, 2020 at 3:57 PM John Fastabend <john.fastabend@gmail.com> wrote:
> >
> > Daniel Borkmann wrote:
> > > On 5/24/20 6:50 PM, John Fastabend wrote:
> > > > Add these generic helpers that may be useful to use from sk_msg programs.
> > > > The helpers do not depend on ctx so we can simply add them here,
> > > >
> > > >   BPF_FUNC_perf_event_output
> > > >   BPF_FUNC_get_current_uid_gid
> > > >   BPF_FUNC_get_current_pid_tgid
> > > >   BPF_FUNC_get_current_comm
> > >
> > > Hmm, added helpers below are what you list here except get_current_comm.
> > > Was this forgotten to be added here?
> >
> > Forgot to update commit messages. I dropped it because it wasn't clear to
> > me it was very useful or how I would use it from this context. I figure we
> > can add it later if its needed.
> 
> But it's also not harmful in any way and is in a similar group as
> get_current_pid_tgid. So let's add it sooner rather than later. There
> is no cost in allowing this, right?
> 

It shouldn't cost anything only thing is I have code that runs the other
three that has been deployed, at least into a dev environment, so I know
its useful and works.

How about we push it as a follow up? I can add it and do some cleanups
on the CHECK_FAILs tonight.

Thanks,
John
Andrii Nakryiko May 26, 2020, 9:29 p.m. UTC | #5
On Tue, May 26, 2020 at 1:51 PM John Fastabend <john.fastabend@gmail.com> wrote:
>
> Andrii Nakryiko wrote:
> > On Mon, May 25, 2020 at 3:57 PM John Fastabend <john.fastabend@gmail.com> wrote:
> > >
> > > Daniel Borkmann wrote:
> > > > On 5/24/20 6:50 PM, John Fastabend wrote:
> > > > > Add these generic helpers that may be useful to use from sk_msg programs.
> > > > > The helpers do not depend on ctx so we can simply add them here,
> > > > >
> > > > >   BPF_FUNC_perf_event_output
> > > > >   BPF_FUNC_get_current_uid_gid
> > > > >   BPF_FUNC_get_current_pid_tgid
> > > > >   BPF_FUNC_get_current_comm
> > > >
> > > > Hmm, added helpers below are what you list here except get_current_comm.
> > > > Was this forgotten to be added here?
> > >
> > > Forgot to update commit messages. I dropped it because it wasn't clear to
> > > me it was very useful or how I would use it from this context. I figure we
> > > can add it later if its needed.
> >
> > But it's also not harmful in any way and is in a similar group as
> > get_current_pid_tgid. So let's add it sooner rather than later. There
> > is no cost in allowing this, right?
> >
>
> It shouldn't cost anything only thing is I have code that runs the other
> three that has been deployed, at least into a dev environment, so I know
> its useful and works.
>
> How about we push it as a follow up? I can add it and do some cleanups
> on the CHECK_FAILs tonight.

Sure, no worries, works for me.

>
> Thanks,
> John
Daniel Borkmann May 26, 2020, 11:12 p.m. UTC | #6
On 5/26/20 11:29 PM, Andrii Nakryiko wrote:
> On Tue, May 26, 2020 at 1:51 PM John Fastabend <john.fastabend@gmail.com> wrote:
>>
>> Andrii Nakryiko wrote:
>>> On Mon, May 25, 2020 at 3:57 PM John Fastabend <john.fastabend@gmail.com> wrote:
>>>>
>>>> Daniel Borkmann wrote:
>>>>> On 5/24/20 6:50 PM, John Fastabend wrote:
>>>>>> Add these generic helpers that may be useful to use from sk_msg programs.
>>>>>> The helpers do not depend on ctx so we can simply add them here,
>>>>>>
>>>>>>    BPF_FUNC_perf_event_output
>>>>>>    BPF_FUNC_get_current_uid_gid
>>>>>>    BPF_FUNC_get_current_pid_tgid
>>>>>>    BPF_FUNC_get_current_comm
>>>>>
>>>>> Hmm, added helpers below are what you list here except get_current_comm.
>>>>> Was this forgotten to be added here?
>>>>
>>>> Forgot to update commit messages. I dropped it because it wasn't clear to
>>>> me it was very useful or how I would use it from this context. I figure we
>>>> can add it later if its needed.
>>>
>>> But it's also not harmful in any way and is in a similar group as
>>> get_current_pid_tgid. So let's add it sooner rather than later. There
>>> is no cost in allowing this, right?
>>>
>>
>> It shouldn't cost anything only thing is I have code that runs the other
>> three that has been deployed, at least into a dev environment, so I know
>> its useful and works.
>>
>> How about we push it as a follow up? I can add it and do some cleanups
>> on the CHECK_FAILs tonight.
> 
> Sure, no worries, works for me.

Ok, applied then, thanks!
diff mbox series

Patch

diff --git a/net/core/filter.c b/net/core/filter.c
index 822d662..a56046a 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -6443,6 +6443,22 @@  sk_msg_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 		return &bpf_msg_push_data_proto;
 	case BPF_FUNC_msg_pop_data:
 		return &bpf_msg_pop_data_proto;
+	case BPF_FUNC_perf_event_output:
+		return &bpf_event_output_data_proto;
+	case BPF_FUNC_get_current_uid_gid:
+		return &bpf_get_current_uid_gid_proto;
+	case BPF_FUNC_get_current_pid_tgid:
+		return &bpf_get_current_pid_tgid_proto;
+#ifdef CONFIG_CGROUPS
+	case BPF_FUNC_get_current_cgroup_id:
+		return &bpf_get_current_cgroup_id_proto;
+	case BPF_FUNC_get_current_ancestor_cgroup_id:
+		return &bpf_get_current_ancestor_cgroup_id_proto;
+#endif
+#ifdef CONFIG_CGROUP_NET_CLASSID
+	case BPF_FUNC_get_cgroup_classid:
+		return &bpf_get_cgroup_classid_curr_proto;
+#endif
 	default:
 		return bpf_base_func_proto(func_id);
 	}