summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2016-03-16 01:42:50 +0100
committerMichael Bestas <mkbestas@lineageos.org>2022-04-19 00:50:10 +0300
commit49d7a6877aebde96cdc7f369facb260b4ebc6ce5 (patch)
tree16f5ff0f109c0e5ab78fe1dbc2cbde375b1029ea
parent1c4f960f2e7c97d21861c0132159f190adb2149e (diff)
bpf, dst: add and use dst_tclassid helper
We can just add a small helper dst_tclassid() for retrieving the dst->tclassid value. It makes the code a bit better in that we can get rid of the ifdef from filter.c by moving this into the header. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
-rw-r--r--include/net/dst.h12
-rw-r--r--net/core/filter.c9
2 files changed, 13 insertions, 8 deletions
diff --git a/include/net/dst.h b/include/net/dst.h
index dc1f26da3c61..1daa9e2a1b46 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -404,6 +404,18 @@ static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev,
__skb_tunnel_rx(skb, dev, net);
}
+static inline u32 dst_tclassid(const struct sk_buff *skb)
+{
+#ifdef CONFIG_IP_ROUTE_CLASSID
+ const struct dst_entry *dst;
+
+ dst = skb_dst(skb);
+ if (dst)
+ return dst->tclassid;
+#endif
+ return 0;
+}
+
int dst_discard_out(struct net *net, struct sock *sk, struct sk_buff *skb);
static inline int dst_discard(struct sk_buff *skb)
{
diff --git a/net/core/filter.c b/net/core/filter.c
index cf0bad6aca3a..22a008313b73 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -1692,14 +1692,7 @@ static const struct bpf_func_proto bpf_get_cgroup_classid_proto = {
static u64 bpf_get_route_realm(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
{
-#ifdef CONFIG_IP_ROUTE_CLASSID
- const struct dst_entry *dst;
-
- dst = skb_dst((struct sk_buff *) (unsigned long) r1);
- if (dst)
- return dst->tclassid;
-#endif
- return 0;
+ return dst_tclassid((struct sk_buff *) (unsigned long) r1);
}
static const struct bpf_func_proto bpf_get_route_realm_proto = {