From: Stanislav Fomichev <sdf@fomichev.me>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: Stanislav Fomichev <sdf@google.com>,
Network Development <netdev@vger.kernel.org>,
bpf@vger.kernel.org, David Miller <davem@davemloft.net>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
simon.horman@netronome.com, Willem de Bruijn <willemb@google.com>,
Petar Penkov <peterpenkov96@gmail.com>
Subject: Re: [RFC bpf-next v2 2/9] net: introduce skb_net helper
Date: Wed, 20 Mar 2019 09:49:11 -0700 [thread overview]
Message-ID: <20190320164911.GH7431@mini-arch.hsd1.ca.comcast.net> (raw)
In-Reply-To: <CAF=yD-JbxFKSVGuXz0-LbzAzSkMR-wZFEQe0e1mck2EY6vn3vg@mail.gmail.com>
On 03/19, Willem de Bruijn wrote:
> On Tue, Mar 19, 2019 at 6:20 PM Stanislav Fomichev <sdf@google.com> wrote:
> >
> > skb_net returns network namespace from the associated device or socket.
> >
> > This will be used in the next commit.
> >
> > I tried to inline it in skbuff.h, but I don't think it's feasible.
>
> If so, is this helper necessary?
>
> All existing cases that use it pass both skb_net(skb) and skb to the
> flow dissector, so can continue to call it locally if new argument net
> is NULL.
>
> The new users are in patch 9/9 in the device drivers, but those should
> pass the device pointer unconditionally.
Good point, I can try to drop it.
> > It depends on 'net/sock.h' for sock_net() and 'linux/netdevice.h' for
> > dev_net(), both of which we don't include from 'linux/skbuff.h' (but
> > both sock.h and netdevice.h include skbuff.h). I though about doing
> > it as a macro/putting it somewhere else, but we will have
> > skb_flow_dissect{_xyz} use it in the next commits.
> >
> > Signed-off-by: Stanislav Fomichev <sdf@google.com>
> > ---
> > include/linux/skbuff.h | 2 ++
> > net/core/skbuff.c | 16 ++++++++++++++++
> > 2 files changed, 18 insertions(+)
> >
> > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> > index e8c1d5b97f96..75e1d4d73cca 100644
> > --- a/include/linux/skbuff.h
> > +++ b/include/linux/skbuff.h
> > @@ -1275,6 +1275,8 @@ static inline int skb_flow_dissector_bpf_prog_detach(const union bpf_attr *attr)
> > }
> > #endif
> >
> > +struct net *skb_net(const struct sk_buff *skb);
> > +
> > struct bpf_flow_keys;
> > bool __skb_flow_bpf_dissect(struct bpf_prog *prog,
> > const struct sk_buff *skb,
> > diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> > index b413354ee709..d81f3a95fb4e 100644
> > --- a/net/core/skbuff.c
> > +++ b/net/core/skbuff.c
> > @@ -5725,3 +5725,19 @@ void __skb_ext_put(struct skb_ext *ext)
> > }
> > EXPORT_SYMBOL(__skb_ext_put);
> > #endif /* CONFIG_SKB_EXTENSIONS */
> > +
> > +/**
> > + * skb_net - Return network namespace associated with skb.
> > + * @skb: skb
> > + *
> > + * Returns pointer to struct net or NULL.
> > + */
> > +struct net *skb_net(const struct sk_buff *skb)
> > +{
> > + if (skb->dev)
> > + return dev_net(skb->dev);
> > + else if (skb->sk)
> > + return sock_net(skb->sk);
> > + return NULL;
> > +}
> > +EXPORT_SYMBOL(skb_net);
> > --
> > 2.21.0.225.g810b269d1ac-goog
> >
next prev parent reply other threads:[~2019-03-20 16:49 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-19 22:19 [RFC bpf-next v2 0/9] net: flow_dissector: trigger BPF hook when called from eth_get_headlen Stanislav Fomichev
2019-03-19 22:19 ` [RFC bpf-next v2 1/9] net: introduce __init_skb{,_data,_shinfo} helpers Stanislav Fomichev
2019-03-21 3:39 ` Alexei Starovoitov
2019-03-21 4:44 ` Eric Dumazet
2019-03-21 13:58 ` Willem de Bruijn
2019-03-21 15:44 ` Stanislav Fomichev
2019-03-21 16:00 ` Alexei Starovoitov
2019-03-21 16:13 ` Willem de Bruijn
2019-03-21 20:56 ` Alexei Starovoitov
2019-03-21 21:13 ` Stanislav Fomichev
2019-03-19 22:19 ` [RFC bpf-next v2 2/9] net: introduce skb_net helper Stanislav Fomichev
2019-03-20 2:14 ` Willem de Bruijn
2019-03-20 16:49 ` Stanislav Fomichev [this message]
2019-03-19 22:19 ` [RFC bpf-next v2 3/9] net: plumb network namespace into __skb_flow_dissect Stanislav Fomichev
2019-03-19 22:19 ` [RFC bpf-next v2 4/9] net: flow_dissector: prepare for no-skb use case Stanislav Fomichev
2019-03-19 22:19 ` [RFC bpf-next v2 5/9] flow_dissector: allow access only to a subset of __sk_buff fields Stanislav Fomichev
2019-03-19 22:19 ` [RFC bpf-next v2 6/9] net: flow_dissector: handle no-skb use case Stanislav Fomichev
2019-03-19 22:19 ` [RFC bpf-next v2 7/9] bpf: when doing BPF_PROG_TEST_RUN for flow dissector use no-skb mode Stanislav Fomichev
2019-03-20 2:14 ` Willem de Bruijn
2019-03-20 16:57 ` Stanislav Fomichev
2019-03-20 18:29 ` Willem de Bruijn
2019-03-20 19:02 ` Stanislav Fomichev
2019-03-20 19:08 ` Willem de Bruijn
2019-03-20 19:19 ` Stanislav Fomichev
2019-03-20 19:23 ` Willem de Bruijn
2019-03-20 19:48 ` Stanislav Fomichev
2019-03-20 20:03 ` Willem de Bruijn
2019-03-19 22:19 ` [RFC bpf-next v2 8/9] selftests/bpf: add flow dissector bpf_skb_load_bytes helper test Stanislav Fomichev
2019-03-19 22:19 ` [RFC bpf-next v2 9/9] net: flow_dissector: pass net argument to the eth_get_headlen Stanislav Fomichev
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=20190320164911.GH7431@mini-arch.hsd1.ca.comcast.net \
--to=sdf@fomichev.me \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=peterpenkov96@gmail.com \
--cc=sdf@google.com \
--cc=simon.horman@netronome.com \
--cc=willemb@google.com \
--cc=willemdebruijn.kernel@gmail.com \
/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).