netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Y Song <ys114321@gmail.com>
To: Alban Crequy <alban@kinvolk.io>
Cc: "Alban Crequy" <alban.crequy@gmail.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	bpf <bpf@vger.kernel.org>, netdev <netdev@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	"Iago López Galeiras" <iago@kinvolk.io>
Subject: Re: [PATCH bpf-next v2 1/3] bpf: sock ops: add netns ino and dev in bpf context
Date: Fri, 19 Apr 2019 15:59:04 -0700	[thread overview]
Message-ID: <CAH3MdRUiXrVwHKHb-XuQffrDAEZHovjxCvRtQ69J-=_L=FX2Ng@mail.gmail.com> (raw)
In-Reply-To: <CADZs7q6XahoWDKWu90xEais_kJ1rKekcXWd2Lh+WyvKiJCtG1w@mail.gmail.com>

On Fri, Apr 19, 2019 at 4:51 AM Alban Crequy <alban@kinvolk.io> wrote:
>
> On Thu, Apr 18, 2019 at 11:31 PM Y Song <ys114321@gmail.com> wrote:
> >
> > On Thu, Apr 18, 2019 at 8:58 AM Alban Crequy <alban.crequy@gmail.com> wrote:
> > >
> > > From: Alban Crequy <alban@kinvolk.io>
> > >
> > > sockops programs can now access the network namespace inode and device
> > > via (struct bpf_sock_ops)->netns_ino and ->netns_dev. This can be useful
> > > to apply different policies on different network namespaces.
> > >
> > > In the unlikely case where network namespaces are not compiled in
> > > (CONFIG_NET_NS=n), the verifier will not allow access to ->netns_*.
> > >
> > > The generated BPF bytecode for netns_ino is loading the correct inode
> > > number at the time of execution.
> > >
> > > However, the generated BPF bytecode for netns_dev is loading an
> > > immediate value determined at BPF-load-time by looking at the initial
> > > network namespace. In practice, this works because all netns currently
> > > use the same virtual device. If this was to change, this code would need
> > > to be updated too.
> > >
> > > Signed-off-by: Alban Crequy <alban@kinvolk.io>
> > >
> > > ---
> > >
> > > Changes since v1:
> > > - add netns_dev (review from Alexei)
> > > ---
> > >  include/uapi/linux/bpf.h |  2 ++
> > >  net/core/filter.c        | 70 ++++++++++++++++++++++++++++++++++++++++
> > >  2 files changed, 72 insertions(+)
> > >
> > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> > > index eaf2d3284248..f4f841dde42c 100644
> > > --- a/include/uapi/linux/bpf.h
> > > +++ b/include/uapi/linux/bpf.h
> > > @@ -3213,6 +3213,8 @@ struct bpf_sock_ops {
> > >         __u32 sk_txhash;
> > >         __u64 bytes_received;
> > >         __u64 bytes_acked;
> > > +       __u64 netns_dev;
> > > +       __u64 netns_ino;
> >
> > Maybe we can define netns_dev as __u32?
> >    __u64 netns_ino;
> >    __u32 netns_dev;
> >
> > There is a hole at the end which can be used if the next
> > field to be added in the future is a __u32.
> >
> > From
> > static inline u32 new_encode_dev(dev_t dev)
> > {
> >         unsigned major = MAJOR(dev);
> >         unsigned minor = MINOR(dev);
> >         return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
> > }
> >
> > device num is encoded in a u32.
>
> I could do that but there are already two occurrences of "__u64
> netns_dev" in bpf.h:
> - struct bpf_prog_info
> - struct bpf_map_info
>
> Should I keep it a u64 for consistency with the rest of bpf.h, or
> change it to u32?

Agreed. We probably should keep it to be __u64 to be consistent with others.

  reply	other threads:[~2019-04-19 22:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-18 15:56 [PATCH bpf-next v2 1/3] bpf: sock ops: add netns ino and dev in bpf context Alban Crequy
2019-04-18 15:56 ` [PATCH bpf-next v2 2/3] selftests: bpf: read netns from struct bpf_sock_ops Alban Crequy
2019-04-18 21:35   ` Y Song
2019-04-18 15:56 ` [PATCH bpf-next v2 3/3] selftests: bpf: verifier: read netns_dev and netns_ino " Alban Crequy
2019-04-18 21:31 ` [PATCH bpf-next v2 1/3] bpf: sock ops: add netns ino and dev in bpf context Y Song
2019-04-19 11:51   ` Alban Crequy
2019-04-19 22:59     ` Y Song [this message]
2019-04-18 21:41 ` Song Liu
2019-04-18 21:51   ` Song Liu

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='CAH3MdRUiXrVwHKHb-XuQffrDAEZHovjxCvRtQ69J-=_L=FX2Ng@mail.gmail.com' \
    --to=ys114321@gmail.com \
    --cc=alban.crequy@gmail.com \
    --cc=alban@kinvolk.io \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=iago@kinvolk.io \
    --cc=john.fastabend@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --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).