Skip to content

Commit 808c1b6

Browse files
borkmanndavem330
authored andcommitted
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>
1 parent 09c37a2 commit 808c1b6

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

include/net/dst.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,18 @@ static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev,
398398
__skb_tunnel_rx(skb, dev, net);
399399
}
400400

401+
static inline u32 dst_tclassid(const struct sk_buff *skb)
402+
{
403+
#ifdef CONFIG_IP_ROUTE_CLASSID
404+
const struct dst_entry *dst;
405+
406+
dst = skb_dst(skb);
407+
if (dst)
408+
return dst->tclassid;
409+
#endif
410+
return 0;
411+
}
412+
401413
int dst_discard_out(struct net *net, struct sock *sk, struct sk_buff *skb);
402414
static inline int dst_discard(struct sk_buff *skb)
403415
{

net/core/filter.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,14 +1682,7 @@ static const struct bpf_func_proto bpf_get_cgroup_classid_proto = {
16821682

16831683
static u64 bpf_get_route_realm(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
16841684
{
1685-
#ifdef CONFIG_IP_ROUTE_CLASSID
1686-
const struct dst_entry *dst;
1687-
1688-
dst = skb_dst((struct sk_buff *) (unsigned long) r1);
1689-
if (dst)
1690-
return dst->tclassid;
1691-
#endif
1692-
return 0;
1685+
return dst_tclassid((struct sk_buff *) (unsigned long) r1);
16931686
}
16941687

16951688
static const struct bpf_func_proto bpf_get_route_realm_proto = {

0 commit comments

Comments
 (0)