lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 19 Mar 2019 15:19:41 -0700
From:   Stanislav Fomichev <sdf@...gle.com>
To:     netdev@...r.kernel.org, bpf@...r.kernel.org
Cc:     davem@...emloft.net, ast@...nel.org, daniel@...earbox.net,
        simon.horman@...ronome.com, willemb@...gle.com,
        peterpenkov96@...il.com, Stanislav Fomichev <sdf@...gle.com>
Subject: [RFC bpf-next v2 2/9] net: introduce skb_net helper

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@...gle.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ