From: John Fastabend <john.fastabend@gmail.com>
To: Martin KaFai Lau <kafai@fb.com>
Cc: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org
Subject: Re: [bpf-next PATCH 1/2] bpf: allow sk_msg programs to read sock fields
Date: Thu, 17 May 2018 13:16:39 -0700 [thread overview]
Message-ID: <525de7ce-dce2-5e13-4a3b-34367d656b6c@gmail.com> (raw)
In-Reply-To: <20180517181736.e6l5lw4ek6w44ede@kafai-mbp.dhcp.thefacebook.com>
On 05/17/2018 11:17 AM, Martin KaFai Lau wrote:
> On Thu, May 17, 2018 at 08:54:04AM -0700, John Fastabend wrote:
>> Currently sk_msg programs only have access to the raw data. However,
>> it is often useful when building policies to have the policies specific
>> to the socket endpoint. This allows using the socket tuple as input
>> into filters, etc.
>>
>> This patch adds ctx access to the sock fields.
>>
>> Signed-off-by: John Fastabend <john.fastabend@gmail.com>
>> ---
>> include/linux/filter.h | 1
>> include/uapi/linux/bpf.h | 8 +++
>> kernel/bpf/sockmap.c | 1
>> net/core/filter.c | 114 +++++++++++++++++++++++++++++++++++++++++++++-
> It is indeed a lot of dup lines with sock_ops_convert_ctx_access()
> as you mentioned in the cover.
>
> Other than that, LGTM.
>
> Acked-by: Martin KaFai Lau <kafafi@fb.com>
>
>> 4 files changed, 121 insertions(+), 3 deletions(-)
>>
>> diff --git a/include/linux/filter.h b/include/linux/filter.h
>> index 9dbcb9d..d358d18 100644
>> --- a/include/linux/filter.h
>> +++ b/include/linux/filter.h
>> @@ -517,6 +517,7 @@ struct sk_msg_buff {
>> bool sg_copy[MAX_SKB_FRAGS];
>> __u32 flags;
>> struct sock *sk_redir;
>> + struct sock *sk;
>> struct sk_buff *skb;
>> struct list_head list;
>> };
>> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
>> index d94d333..97446bb 100644
>> --- a/include/uapi/linux/bpf.h
>> +++ b/include/uapi/linux/bpf.h
>> @@ -2176,6 +2176,14 @@ enum sk_action {
>> struct sk_msg_md {
>> void *data;
>> void *data_end;
>> +
>> + __u32 family;
>> + __u32 remote_ip4; /* Stored in network byte order */
>> + __u32 local_ip4; /* Stored in network byte order */
>> + __u32 remote_ip6[4]; /* Stored in network byte order */
>> + __u32 local_ip6[4]; /* Stored in network byte order */
>> + __u32 remote_port; /* Stored in network byte order */
>> + __u32 local_port; /* stored in host byte order */
> This ordering inconsistency could be a trap to write bpf_prog
> but I guess it is too late to change now considering
> bpf_sock_ops is also using this convention.
>
Yep, when writing both bpf_sock_ops programs and sk_msg based
programs its nice to have them both use the same semantics. The
two programs, at least in my experience, are used together
typically sharing maps and heavily dependent on one another.
> Just curious, we cannot always assume inet_sk and then uses
> its inet_sport?
>
For now we only support SOCK_STREAM so I guess we could also
use inet_sport but then it wouldn't align with bpf_sock_ops.
If we want to add it later we can put another field in there
to use it "__u32 source_port". For now though I prefer to keep
the bpf_sock_ops and sk_msg_md sock field access aligned.
.John
next prev parent reply other threads:[~2018-05-17 20:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-17 15:53 [bpf-next PATCH 0/2] SK_MSG programs: read sock fields John Fastabend
2018-05-17 15:54 ` [bpf-next PATCH 1/2] bpf: allow sk_msg programs to " John Fastabend
2018-05-17 18:17 ` Martin KaFai Lau
2018-05-17 20:16 ` John Fastabend [this message]
2018-05-17 15:54 ` [bpf-next PATCH 2/2] bpf: add sk_msg prog sk access tests to test_verifier John Fastabend
2018-05-17 18:57 ` Martin KaFai Lau
2018-05-17 20:12 ` John Fastabend
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=525de7ce-dce2-5e13-4a3b-34367d656b6c@gmail.com \
--to=john.fastabend@gmail.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=kafai@fb.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).