1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
26ae0a628SYotam Gigi #ifndef __NET_PSAMPLE_H
36ae0a628SYotam Gigi #define __NET_PSAMPLE_H
46ae0a628SYotam Gigi
56ae0a628SYotam Gigi #include <uapi/linux/psample.h>
66ae0a628SYotam Gigi #include <linux/list.h>
76ae0a628SYotam Gigi
86ae0a628SYotam Gigi struct psample_group {
96ae0a628SYotam Gigi struct list_head list;
106ae0a628SYotam Gigi struct net *net;
116ae0a628SYotam Gigi u32 group_num;
126ae0a628SYotam Gigi u32 refcount;
136ae0a628SYotam Gigi u32 seq;
14dbf47a2aSVlad Buslov struct rcu_head rcu;
156ae0a628SYotam Gigi };
166ae0a628SYotam Gigi
17a03e99d3SIdo Schimmel struct psample_metadata {
18a03e99d3SIdo Schimmel u32 trunc_size;
19a03e99d3SIdo Schimmel int in_ifindex;
20a03e99d3SIdo Schimmel int out_ifindex;
2107e1a580SIdo Schimmel u16 out_tc;
2207e1a580SIdo Schimmel u64 out_tc_occ; /* bytes */
2307e1a580SIdo Schimmel u64 latency; /* nanoseconds */
2407e1a580SIdo Schimmel u8 out_tc_valid:1,
2507e1a580SIdo Schimmel out_tc_occ_valid:1,
2607e1a580SIdo Schimmel latency_valid:1,
277b1b2b60SAdrian Moreno rate_as_probability:1,
287b1b2b60SAdrian Moreno unused:4;
29093b0f36SAdrian Moreno const u8 *user_cookie;
30093b0f36SAdrian Moreno u32 user_cookie_len;
31a03e99d3SIdo Schimmel };
32a03e99d3SIdo Schimmel
336ae0a628SYotam Gigi struct psample_group *psample_group_get(struct net *net, u32 group_num);
344a5da47dSVlad Buslov void psample_group_take(struct psample_group *group);
356ae0a628SYotam Gigi void psample_group_put(struct psample_group *group);
366ae0a628SYotam Gigi
37beb7f2deSRoi Dayan struct sk_buff;
38beb7f2deSRoi Dayan
396ae0a628SYotam Gigi #if IS_ENABLED(CONFIG_PSAMPLE)
406ae0a628SYotam Gigi
41*8341eee8SAdrian Moreno void psample_sample_packet(struct psample_group *group,
42*8341eee8SAdrian Moreno const struct sk_buff *skb, u32 sample_rate,
43*8341eee8SAdrian Moreno const struct psample_metadata *md);
446ae0a628SYotam Gigi
456ae0a628SYotam Gigi #else
466ae0a628SYotam Gigi
psample_sample_packet(struct psample_group * group,const struct sk_buff * skb,u32 sample_rate,const struct psample_metadata * md)476ae0a628SYotam Gigi static inline void psample_sample_packet(struct psample_group *group,
48*8341eee8SAdrian Moreno const struct sk_buff *skb,
49*8341eee8SAdrian Moreno u32 sample_rate,
50a03e99d3SIdo Schimmel const struct psample_metadata *md)
516ae0a628SYotam Gigi {
526ae0a628SYotam Gigi }
536ae0a628SYotam Gigi
546ae0a628SYotam Gigi #endif
556ae0a628SYotam Gigi
566ae0a628SYotam Gigi #endif /* __NET_PSAMPLE_H */
57