From: Stanislav Fomichev <sdf@google.com>
To: netdev@vger.kernel.org, bpf@vger.kernel.org
Cc: davem@davemloft.net, ast@kernel.org, daniel@iogearbox.net,
simon.horman@netronome.com, willemb@google.com,
peterpenkov96@gmail.com, Stanislav Fomichev <sdf@google.com>
Subject: [RFC bpf-next v2 2/9] net: introduce skb_net helper
Date: Tue, 19 Mar 2019 15:19:41 -0700 [thread overview]
Message-ID: <20190319221948.170441-3-sdf@google.com> (raw)
In-Reply-To: <20190319221948.170441-1-sdf@google.com>
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.
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-19 22:20 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 ` Stanislav Fomichev [this message]
2019-03-20 2:14 ` [RFC bpf-next v2 2/9] net: introduce skb_net helper Willem de Bruijn
2019-03-20 16:49 ` Stanislav Fomichev
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=20190319221948.170441-3-sdf@google.com \
--to=sdf@google.com \
--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=simon.horman@netronome.com \
--cc=willemb@google.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 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.