@@ -4,6 +4,7 @@
#include <uapi/linux/psample.h>
#include <linux/list.h>
+#include <linux/skbuff.h>
struct psample_group {
struct list_head list;
@@ -14,6 +15,15 @@ struct psample_group {
struct rcu_head rcu;
};
+struct psample_ops {
+ void (*sample_packet)(struct psample_group *group, struct sk_buff *skb,
+ u32 trunc_size, int in_ifindex, int out_ifindex,
+ u32 sample_rate);
+
+};
+
+extern const struct psample_ops __rcu *psample_ops __read_mostly;
+
struct psample_group *psample_group_get(struct net *net, u32 group_num);
void psample_group_take(struct psample_group *group);
void psample_group_put(struct psample_group *group);
@@ -35,4 +45,21 @@ static inline void psample_sample_packet(struct psample_group *group,
#endif
+static void
+psample_nic_sample_packet(struct psample_group *group,
+ struct sk_buff *skb, u32 trunc_size,
+ int in_ifindex, int out_ifindex,
+ u32 sample_rate)
+{
+ const struct psample_ops *ops;
+
+ rcu_read_lock();
+ ops = rcu_dereference(psample_ops);
+ if (ops)
+ ops->sample_packet(group, skb, trunc_size,
+ in_ifindex, out_ifindex,
+ sample_rate);
+ rcu_read_unlock();
+}
+
#endif /* __NET_PSAMPLE_H */
@@ -8,6 +8,7 @@
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/module.h>
+#include <linux/rcupdate.h>
#include <net/net_namespace.h>
#include <net/sock.h>
#include <net/netlink.h>
@@ -35,6 +36,10 @@ static const struct genl_multicast_group psample_nl_mcgrps[] = {
static struct genl_family psample_nl_family __ro_after_init;
+static const struct psample_ops psample_sample_ops = {
+ .sample_packet = psample_sample_packet,
+};
+
static int psample_group_nl_fill(struct sk_buff *msg,
struct psample_group *group,
enum psample_command cmd, u32 portid, u32 seq,
@@ -456,11 +461,17 @@ EXPORT_SYMBOL_GPL(psample_sample_packet);
static int __init psample_module_init(void)
{
- return genl_register_family(&psample_nl_family);
+ int ret;
+
+ ret = genl_register_family(&psample_nl_family);
+ if (!ret)
+ RCU_INIT_POINTER(psample_ops, &psample_sample_ops);
+ return ret;
}
static void __exit psample_module_exit(void)
{
+ RCU_INIT_POINTER(psample_ops, NULL);
genl_unregister_family(&psample_nl_family);
}
@@ -3,7 +3,7 @@
# Makefile for the Linux Traffic Control Unit.
#
-obj-y := sch_generic.o sch_mq.o
+obj-y := sch_generic.o sch_mq.o psample_stub.o
obj-$(CONFIG_INET) += sch_frag.o
obj-$(CONFIG_NET_SCHED) += sch_api.o sch_blackhole.o
new file mode 100644
@@ -0,0 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+/* Copyright (c) 2021 Mellanox Technologies. */
+
+#include <net/psample.h>
+
+const struct psample_ops __rcu *psample_ops __read_mostly;
+EXPORT_SYMBOL_GPL(psample_ops);