All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Stringer <joe@wand.net.nz>
To: Joe Stringer <joe@wand.net.nz>
Cc: daniel@iogearbox.net, netdev <netdev@vger.kernel.org>,
	ast@kernel.org, john fastabend <john.fastabend@gmail.com>,
	tgraf@suug.ch, Martin KaFai Lau <kafai@fb.com>
Subject: Re: [RFC bpf-next 00/11] Add socket lookup support
Date: Wed, 16 May 2018 12:05:06 -0700	[thread overview]
Message-ID: <CAOftzPhtPtZsqjT=Vrd-04qXdZKWJhPhuQ2maeJmK-os0nzdJw@mail.gmail.com> (raw)
In-Reply-To: <20180509210709.7201-1-joe@wand.net.nz>

On 9 May 2018 at 14:06, Joe Stringer <joe@wand.net.nz> wrote:
> This series proposes a new helper for the BPF API which allows BPF programs to
> perform lookups for sockets in a network namespace. This would allow programs
> to determine early on in processing whether the stack is expecting to receive
> the packet, and perform some action (eg drop, forward somewhere) based on this
> information.
>
> The series is structured roughly into:
> * Misc refactor
> * Add the socket pointer type
> * Add reference tracking to ensure that socket references are freed
> * Extend the BPF API to add sk_lookup() / sk_release() functions
> * Add tests/documentation
>
> The helper proposed in this series includes a parameter for a tuple which must
> be filled in by the caller to determine the socket to look up. The simplest
> case would be filling with the contents of the packet, ie mapping the packet's
> 5-tuple into the parameter. In common cases, it may alternatively be useful to
> reverse the direction of the tuple and perform a lookup, to find the socket
> that initiates this connection; and if the BPF program ever performs a form of
> IP address translation, it may further be useful to be able to look up
> arbitrary tuples that are not based upon the packet, but instead based on state
> held in BPF maps or hardcoded in the BPF program.
>
> Currently, access into the socket's fields are limited to those which are
> otherwise already accessible, and are restricted to read-only access.
>
> A few open points:
> * Currently, the lookup interface only returns either a valid socket or a NULL
>   pointer. This means that if there is any kind of issue with the tuple, such
>   as it provides an unsupported protocol number, or the socket can't be found,
>   then we are unable to differentiate these cases from one another. One natural
>   approach to improve this could be to return an ERR_PTR from the
>   bpf_sk_lookup() helper. This would be more complicated but maybe it's
>   worthwhile.

This suggestion would add a lot of complexity, and there's not many
legitimately different error cases. There's:
* Unsupported socket type
* Cannot find netns
* Tuple argument is the wrong size
* Can't find socket

If we split the helpers into protocol-specific types, the first one
would be addressed. The last one is addressed by returning NULL. It
seems like a reasonable compromise to me to return NULL also in the
middle two cases as well, and rely on the BPF writer to provide valid
arguments.

> * No ordering is defined between sockets. If the tuple could find multiple
>   sockets, then it will arbitrarily return one. It is up to the caller to
>   handle this. If we wish to handle this more reliably in future, we could
>   encode an ordering preference in the flags field.

Doesn't need to be addressed with this series, there is scope for
addressing these cases when the use case arises.

> * Currently this helper is only defined for TC hook point, but it should also
>   be valid at XDP and perhaps some other hooks.

Easy to add support for XDP on demand, initial implementation doesn't need it.

  parent reply	other threads:[~2018-05-16 19:05 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-09 21:06 [RFC bpf-next 00/11] Add socket lookup support Joe Stringer
2018-05-09 21:06 ` [RFC bpf-next 01/11] bpf: Add iterator for spilled registers Joe Stringer
2018-05-09 21:07 ` [RFC bpf-next 02/11] bpf: Simplify ptr_min_max_vals adjustment Joe Stringer
2018-05-09 21:07 ` [RFC bpf-next 03/11] bpf: Generalize ptr_or_null regs check Joe Stringer
2018-05-09 21:07 ` [RFC bpf-next 04/11] bpf: Add PTR_TO_SOCKET verifier type Joe Stringer
2018-05-15  2:37   ` Alexei Starovoitov
2018-05-16 23:56     ` Joe Stringer
2018-05-09 21:07 ` [RFC bpf-next 05/11] bpf: Macrofy stack state copy Joe Stringer
2018-05-09 21:07 ` [RFC bpf-next 06/11] bpf: Add reference tracking to verifier Joe Stringer
2018-05-15  3:04   ` Alexei Starovoitov
2018-05-17  1:05     ` Joe Stringer
2018-05-09 21:07 ` [RFC bpf-next 07/11] bpf: Add helper to retrieve socket in BPF Joe Stringer
2018-05-11  5:00   ` Martin KaFai Lau
2018-05-11 21:08     ` Joe Stringer
2018-05-11 21:41       ` Martin KaFai Lau
2018-05-12  0:54         ` Joe Stringer
2018-05-15  3:16           ` Alexei Starovoitov
2018-05-15 16:48             ` Martin KaFai Lau
2018-05-16 18:55               ` Joe Stringer
2018-05-09 21:07 ` [RFC bpf-next 08/11] selftests/bpf: Add tests for reference tracking Joe Stringer
2018-05-09 21:07 ` [RFC bpf-next 09/11] libbpf: Support loading individual progs Joe Stringer
2018-05-09 21:07 ` [RFC bpf-next 10/11] selftests/bpf: Add C tests for reference tracking Joe Stringer
2018-05-09 21:07 ` [RFC bpf-next 11/11] Documentation: Describe bpf " Joe Stringer
2018-05-15  3:19   ` Alexei Starovoitov
2018-05-16 19:05 ` Joe Stringer [this message]
2018-05-16 20:04   ` [RFC bpf-next 00/11] Add socket lookup support Alexei Starovoitov

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='CAOftzPhtPtZsqjT=Vrd-04qXdZKWJhPhuQ2maeJmK-os0nzdJw@mail.gmail.com' \
    --to=joe@wand.net.nz \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.