Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c5670fa authored by Yotam Gigi's avatar Yotam Gigi Committed by David S. Miller
Browse files

net/sched: Introduce sample tc action



This action allows the user to sample traffic matched by tc classifier.
The sampling consists of choosing packets randomly and sampling them using
the psample module. The user can configure the psample group number, the
sampling rate and the packet's truncation (to save kernel-user traffic).

Example:
To sample ingress traffic from interface eth1, one may use the commands:

tc qdisc add dev eth1 handle ffff: ingress

tc filter add dev eth1 parent ffff: \
	   matchall action sample rate 12 group 4

Where the first command adds an ingress qdisc and the second starts
sampling randomly with an average of one sampled packet per 12 packets on
dev eth1 to psample group 4.

Signed-off-by: default avatarYotam Gigi <yotamg@mellanox.com>
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Acked-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
Reviewed-by: default avatarSimon Horman <simon.horman@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6ae0a628
Loading
Loading
Loading
Loading
+50 −0
Original line number Original line Diff line number Diff line
#ifndef __NET_TC_SAMPLE_H
#define __NET_TC_SAMPLE_H

#include <net/act_api.h>
#include <linux/tc_act/tc_sample.h>
#include <net/psample.h>

struct tcf_sample {
	struct tc_action common;
	u32 rate;
	bool truncate;
	u32 trunc_size;
	struct psample_group __rcu *psample_group;
	u32 psample_group_num;
	struct list_head tcfm_list;
	struct rcu_head rcu;
};
#define to_sample(a) ((struct tcf_sample *)a)

static inline bool is_tcf_sample(const struct tc_action *a)
{
#ifdef CONFIG_NET_CLS_ACT
	return a->ops && a->ops->type == TCA_ACT_SAMPLE;
#else
	return false;
#endif
}

static inline __u32 tcf_sample_rate(const struct tc_action *a)
{
	return to_sample(a)->rate;
}

static inline bool tcf_sample_truncate(const struct tc_action *a)
{
	return to_sample(a)->truncate;
}

static inline int tcf_sample_trunc_size(const struct tc_action *a)
{
	return to_sample(a)->trunc_size;
}

static inline struct psample_group *
tcf_sample_psample_group(const struct tc_action *a)
{
	return rcu_dereference(to_sample(a)->psample_group);
}

#endif /* __NET_TC_SAMPLE_H */
+1 −0
Original line number Original line Diff line number Diff line
@@ -4,6 +4,7 @@ header-y += tc_defact.h
header-y += tc_gact.h
header-y += tc_gact.h
header-y += tc_ipt.h
header-y += tc_ipt.h
header-y += tc_mirred.h
header-y += tc_mirred.h
header-y += tc_sample.h
header-y += tc_nat.h
header-y += tc_nat.h
header-y += tc_pedit.h
header-y += tc_pedit.h
header-y += tc_skbedit.h
header-y += tc_skbedit.h
+26 −0
Original line number Original line Diff line number Diff line
#ifndef __LINUX_TC_SAMPLE_H
#define __LINUX_TC_SAMPLE_H

#include <linux/types.h>
#include <linux/pkt_cls.h>
#include <linux/if_ether.h>

#define TCA_ACT_SAMPLE 26

struct tc_sample {
	tc_gen;
};

enum {
	TCA_SAMPLE_UNSPEC,
	TCA_SAMPLE_TM,
	TCA_SAMPLE_PARMS,
	TCA_SAMPLE_RATE,
	TCA_SAMPLE_TRUNC_SIZE,
	TCA_SAMPLE_PSAMPLE_GROUP,
	TCA_SAMPLE_PAD,
	__TCA_SAMPLE_MAX
};
#define TCA_SAMPLE_MAX (__TCA_SAMPLE_MAX - 1)

#endif
+12 −0
Original line number Original line Diff line number Diff line
@@ -650,6 +650,18 @@ config NET_ACT_MIRRED
	  To compile this code as a module, choose M here: the
	  To compile this code as a module, choose M here: the
	  module will be called act_mirred.
	  module will be called act_mirred.


config NET_ACT_SAMPLE
        tristate "Traffic Sampling"
        depends on NET_CLS_ACT
        select PSAMPLE
        ---help---
	  Say Y here to allow packet sampling tc action. The packet sample
	  action consists of statistically choosing packets and sampling
	  them using the psample module.

	  To compile this code as a module, choose M here: the
	  module will be called act_sample.

config NET_ACT_IPT
config NET_ACT_IPT
        tristate "IPtables targets"
        tristate "IPtables targets"
        depends on NET_CLS_ACT && NETFILTER && IP_NF_IPTABLES
        depends on NET_CLS_ACT && NETFILTER && IP_NF_IPTABLES
+1 −0
Original line number Original line Diff line number Diff line
@@ -10,6 +10,7 @@ obj-$(CONFIG_NET_CLS_ACT) += act_api.o
obj-$(CONFIG_NET_ACT_POLICE)	+= act_police.o
obj-$(CONFIG_NET_ACT_POLICE)	+= act_police.o
obj-$(CONFIG_NET_ACT_GACT)	+= act_gact.o
obj-$(CONFIG_NET_ACT_GACT)	+= act_gact.o
obj-$(CONFIG_NET_ACT_MIRRED)	+= act_mirred.o
obj-$(CONFIG_NET_ACT_MIRRED)	+= act_mirred.o
obj-$(CONFIG_NET_ACT_SAMPLE)	+= act_sample.o
obj-$(CONFIG_NET_ACT_IPT)	+= act_ipt.o
obj-$(CONFIG_NET_ACT_IPT)	+= act_ipt.o
obj-$(CONFIG_NET_ACT_NAT)	+= act_nat.o
obj-$(CONFIG_NET_ACT_NAT)	+= act_nat.o
obj-$(CONFIG_NET_ACT_PEDIT)	+= act_pedit.o
obj-$(CONFIG_NET_ACT_PEDIT)	+= act_pedit.o
Loading