2019-06-04 11:11:33 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-01-23 13:07:09 +03:00
|
|
|
/*
|
|
|
|
* net/sched/act_sample.c - Packet sampling tc action
|
|
|
|
* Copyright (c) 2017 Yotam Gigi <yotamg@mellanox.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/rtnetlink.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/gfp.h>
|
|
|
|
#include <net/net_namespace.h>
|
|
|
|
#include <net/netlink.h>
|
|
|
|
#include <net/pkt_sched.h>
|
|
|
|
#include <linux/tc_act/tc_sample.h>
|
|
|
|
#include <net/tc_act/tc_sample.h>
|
|
|
|
#include <net/psample.h>
|
2019-03-20 17:00:09 +03:00
|
|
|
#include <net/pkt_cls.h>
|
2022-12-06 16:55:12 +03:00
|
|
|
#include <net/tc_wrapper.h>
|
2017-01-23 13:07:09 +03:00
|
|
|
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
|
|
|
|
static struct tc_action_ops act_sample_ops;
|
|
|
|
|
|
|
|
static const struct nla_policy sample_policy[TCA_SAMPLE_MAX + 1] = {
|
|
|
|
[TCA_SAMPLE_PARMS] = { .len = sizeof(struct tc_sample) },
|
|
|
|
[TCA_SAMPLE_RATE] = { .type = NLA_U32 },
|
|
|
|
[TCA_SAMPLE_TRUNC_SIZE] = { .type = NLA_U32 },
|
|
|
|
[TCA_SAMPLE_PSAMPLE_GROUP] = { .type = NLA_U32 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int tcf_sample_init(struct net *net, struct nlattr *nla,
|
2021-07-30 02:12:14 +03:00
|
|
|
struct nlattr *est, struct tc_action **a,
|
|
|
|
struct tcf_proto *tp,
|
2019-10-30 17:09:05 +03:00
|
|
|
u32 flags, struct netlink_ext_ack *extack)
|
2017-01-23 13:07:09 +03:00
|
|
|
{
|
2022-09-08 07:14:33 +03:00
|
|
|
struct tc_action_net *tn = net_generic(net, act_sample_ops.net_id);
|
2021-07-30 02:12:14 +03:00
|
|
|
bool bind = flags & TCA_ACT_FLAGS_BIND;
|
2017-01-23 13:07:09 +03:00
|
|
|
struct nlattr *tb[TCA_SAMPLE_MAX + 1];
|
|
|
|
struct psample_group *psample_group;
|
2019-08-01 16:02:51 +03:00
|
|
|
u32 psample_group_num, rate, index;
|
2019-03-20 17:00:09 +03:00
|
|
|
struct tcf_chain *goto_ch = NULL;
|
2017-01-23 13:07:09 +03:00
|
|
|
struct tc_sample *parm;
|
|
|
|
struct tcf_sample *s;
|
|
|
|
bool exists = false;
|
2018-07-05 17:24:32 +03:00
|
|
|
int ret, err;
|
2017-01-23 13:07:09 +03:00
|
|
|
|
|
|
|
if (!nla)
|
|
|
|
return -EINVAL;
|
netlink: make validation more configurable for future strictness
We currently have two levels of strict validation:
1) liberal (default)
- undefined (type >= max) & NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
- garbage at end of message accepted
2) strict (opt-in)
- NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
Split out parsing strictness into four different options:
* TRAILING - check that there's no trailing data after parsing
attributes (in message or nested)
* MAXTYPE - reject attrs > max known type
* UNSPEC - reject attributes with NLA_UNSPEC policy entries
* STRICT_ATTRS - strictly validate attribute size
The default for future things should be *everything*.
The current *_strict() is a combination of TRAILING and MAXTYPE,
and is renamed to _deprecated_strict().
The current regular parsing has none of this, and is renamed to
*_parse_deprecated().
Additionally it allows us to selectively set one of the new flags
even on old policies. Notably, the UNSPEC flag could be useful in
this case, since it can be arranged (by filling in the policy) to
not be an incompatible userspace ABI change, but would then going
forward prevent forgetting attribute entries. Similar can apply
to the POLICY flag.
We end up with the following renames:
* nla_parse -> nla_parse_deprecated
* nla_parse_strict -> nla_parse_deprecated_strict
* nlmsg_parse -> nlmsg_parse_deprecated
* nlmsg_parse_strict -> nlmsg_parse_deprecated_strict
* nla_parse_nested -> nla_parse_nested_deprecated
* nla_validate_nested -> nla_validate_nested_deprecated
Using spatch, of course:
@@
expression TB, MAX, HEAD, LEN, POL, EXT;
@@
-nla_parse(TB, MAX, HEAD, LEN, POL, EXT)
+nla_parse_deprecated(TB, MAX, HEAD, LEN, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression TB, MAX, NLA, POL, EXT;
@@
-nla_parse_nested(TB, MAX, NLA, POL, EXT)
+nla_parse_nested_deprecated(TB, MAX, NLA, POL, EXT)
@@
expression START, MAX, POL, EXT;
@@
-nla_validate_nested(START, MAX, POL, EXT)
+nla_validate_nested_deprecated(START, MAX, POL, EXT)
@@
expression NLH, HDRLEN, MAX, POL, EXT;
@@
-nlmsg_validate(NLH, HDRLEN, MAX, POL, EXT)
+nlmsg_validate_deprecated(NLH, HDRLEN, MAX, POL, EXT)
For this patch, don't actually add the strict, non-renamed versions
yet so that it breaks compile if I get it wrong.
Also, while at it, make nla_validate and nla_parse go down to a
common __nla_validate_parse() function to avoid code duplication.
Ultimately, this allows us to have very strict validation for every
new caller of nla_parse()/nlmsg_parse() etc as re-introduced in the
next patch, while existing things will continue to work as is.
In effect then, this adds fully strict validation for any new command.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-04-26 15:07:28 +03:00
|
|
|
ret = nla_parse_nested_deprecated(tb, TCA_SAMPLE_MAX, nla,
|
|
|
|
sample_policy, NULL);
|
2017-01-23 13:07:09 +03:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2023-02-24 18:00:58 +03:00
|
|
|
|
|
|
|
if (!tb[TCA_SAMPLE_PARMS])
|
2017-01-23 13:07:09 +03:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
parm = nla_data(tb[TCA_SAMPLE_PARMS]);
|
2019-08-01 16:02:51 +03:00
|
|
|
index = parm->index;
|
|
|
|
err = tcf_idr_check_alloc(tn, &index, a, bind);
|
2018-07-05 17:24:32 +03:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
exists = err;
|
2017-01-23 13:07:09 +03:00
|
|
|
if (exists && bind)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!exists) {
|
2019-08-01 16:02:51 +03:00
|
|
|
ret = tcf_idr_create(tn, index, est, a,
|
2021-12-17 21:16:17 +03:00
|
|
|
&act_sample_ops, bind, true, flags);
|
2018-07-05 17:24:32 +03:00
|
|
|
if (ret) {
|
2019-08-01 16:02:51 +03:00
|
|
|
tcf_idr_cleanup(tn, index);
|
2017-01-23 13:07:09 +03:00
|
|
|
return ret;
|
2018-07-05 17:24:32 +03:00
|
|
|
}
|
2017-01-23 13:07:09 +03:00
|
|
|
ret = ACT_P_CREATED;
|
2021-07-30 02:12:14 +03:00
|
|
|
} else if (!(flags & TCA_ACT_FLAGS_REPLACE)) {
|
2017-08-30 09:31:59 +03:00
|
|
|
tcf_idr_release(*a, bind);
|
2018-07-05 17:24:30 +03:00
|
|
|
return -EEXIST;
|
2017-01-23 13:07:09 +03:00
|
|
|
}
|
2023-02-24 18:00:58 +03:00
|
|
|
|
|
|
|
if (!tb[TCA_SAMPLE_RATE] || !tb[TCA_SAMPLE_PSAMPLE_GROUP]) {
|
|
|
|
NL_SET_ERR_MSG(extack, "sample rate and group are required");
|
|
|
|
err = -EINVAL;
|
|
|
|
goto release_idr;
|
|
|
|
}
|
|
|
|
|
2019-03-20 17:00:09 +03:00
|
|
|
err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
|
|
|
|
if (err < 0)
|
|
|
|
goto release_idr;
|
2017-01-23 13:07:09 +03:00
|
|
|
|
2019-04-04 13:31:35 +03:00
|
|
|
rate = nla_get_u32(tb[TCA_SAMPLE_RATE]);
|
|
|
|
if (!rate) {
|
|
|
|
NL_SET_ERR_MSG(extack, "invalid sample rate");
|
|
|
|
err = -EINVAL;
|
|
|
|
goto put_chain;
|
|
|
|
}
|
2018-08-14 21:46:16 +03:00
|
|
|
psample_group_num = nla_get_u32(tb[TCA_SAMPLE_PSAMPLE_GROUP]);
|
|
|
|
psample_group = psample_group_get(net, psample_group_num);
|
2017-01-31 12:33:53 +03:00
|
|
|
if (!psample_group) {
|
2019-03-20 17:00:09 +03:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto put_chain;
|
2017-01-31 12:33:53 +03:00
|
|
|
}
|
2018-08-14 21:46:16 +03:00
|
|
|
|
|
|
|
s = to_sample(*a);
|
|
|
|
|
|
|
|
spin_lock_bh(&s->tcf_lock);
|
2019-03-20 17:00:09 +03:00
|
|
|
goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
|
2019-04-04 13:31:35 +03:00
|
|
|
s->rate = rate;
|
2018-08-14 21:46:16 +03:00
|
|
|
s->psample_group_num = psample_group_num;
|
2019-09-24 02:09:18 +03:00
|
|
|
psample_group = rcu_replace_pointer(s->psample_group, psample_group,
|
|
|
|
lockdep_is_held(&s->tcf_lock));
|
2017-01-23 13:07:09 +03:00
|
|
|
|
|
|
|
if (tb[TCA_SAMPLE_TRUNC_SIZE]) {
|
|
|
|
s->truncate = true;
|
|
|
|
s->trunc_size = nla_get_u32(tb[TCA_SAMPLE_TRUNC_SIZE]);
|
|
|
|
}
|
2018-08-14 21:46:16 +03:00
|
|
|
spin_unlock_bh(&s->tcf_lock);
|
2019-08-27 21:49:38 +03:00
|
|
|
|
|
|
|
if (psample_group)
|
|
|
|
psample_group_put(psample_group);
|
2019-03-20 17:00:09 +03:00
|
|
|
if (goto_ch)
|
|
|
|
tcf_chain_put_by_act(goto_ch);
|
2017-01-23 13:07:09 +03:00
|
|
|
|
|
|
|
return ret;
|
2019-03-20 17:00:09 +03:00
|
|
|
put_chain:
|
|
|
|
if (goto_ch)
|
|
|
|
tcf_chain_put_by_act(goto_ch);
|
|
|
|
release_idr:
|
|
|
|
tcf_idr_release(*a, bind);
|
|
|
|
return err;
|
2017-01-23 13:07:09 +03:00
|
|
|
}
|
|
|
|
|
2017-12-05 23:53:07 +03:00
|
|
|
static void tcf_sample_cleanup(struct tc_action *a)
|
2017-01-23 13:07:09 +03:00
|
|
|
{
|
2017-11-30 03:07:51 +03:00
|
|
|
struct tcf_sample *s = to_sample(a);
|
2017-01-23 13:07:09 +03:00
|
|
|
struct psample_group *psample_group;
|
|
|
|
|
2018-08-10 20:51:47 +03:00
|
|
|
/* last reference to action, no need to lock */
|
|
|
|
psample_group = rcu_dereference_protected(s->psample_group, 1);
|
2017-01-23 13:07:09 +03:00
|
|
|
RCU_INIT_POINTER(s->psample_group, NULL);
|
2018-03-16 02:00:56 +03:00
|
|
|
if (psample_group)
|
|
|
|
psample_group_put(psample_group);
|
2017-01-23 13:07:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool tcf_sample_dev_ok_push(struct net_device *dev)
|
|
|
|
{
|
|
|
|
switch (dev->type) {
|
|
|
|
case ARPHRD_TUNNEL:
|
|
|
|
case ARPHRD_TUNNEL6:
|
|
|
|
case ARPHRD_SIT:
|
|
|
|
case ARPHRD_IPGRE:
|
2019-09-17 12:30:55 +03:00
|
|
|
case ARPHRD_IP6GRE:
|
2017-01-23 13:07:09 +03:00
|
|
|
case ARPHRD_VOID:
|
|
|
|
case ARPHRD_NONE:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-06 16:55:12 +03:00
|
|
|
TC_INDIRECT_SCOPE int tcf_sample_act(struct sk_buff *skb,
|
|
|
|
const struct tc_action *a,
|
|
|
|
struct tcf_result *res)
|
2017-01-23 13:07:09 +03:00
|
|
|
{
|
|
|
|
struct tcf_sample *s = to_sample(a);
|
|
|
|
struct psample_group *psample_group;
|
2021-03-14 15:19:30 +03:00
|
|
|
struct psample_metadata md = {};
|
2017-01-23 13:07:09 +03:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
tcf_lastuse_update(&s->tcf_tm);
|
2021-10-16 11:49:09 +03:00
|
|
|
bstats_update(this_cpu_ptr(s->common.cpu_bstats), skb);
|
2017-01-23 13:07:09 +03:00
|
|
|
retval = READ_ONCE(s->tcf_action);
|
|
|
|
|
2018-07-30 15:30:43 +03:00
|
|
|
psample_group = rcu_dereference_bh(s->psample_group);
|
2017-01-23 13:07:09 +03:00
|
|
|
|
|
|
|
/* randomly sample packets according to rate */
|
2022-10-10 05:44:02 +03:00
|
|
|
if (psample_group && (get_random_u32_below(s->rate) == 0)) {
|
2017-01-23 13:07:09 +03:00
|
|
|
if (!skb_at_tc_ingress(skb)) {
|
2021-03-14 15:19:30 +03:00
|
|
|
md.in_ifindex = skb->skb_iif;
|
|
|
|
md.out_ifindex = skb->dev->ifindex;
|
2017-01-23 13:07:09 +03:00
|
|
|
} else {
|
2021-03-14 15:19:30 +03:00
|
|
|
md.in_ifindex = skb->dev->ifindex;
|
2017-01-23 13:07:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* on ingress, the mac header gets popped, so push it back */
|
|
|
|
if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev))
|
|
|
|
skb_push(skb, skb->mac_len);
|
|
|
|
|
2021-03-14 15:19:30 +03:00
|
|
|
md.trunc_size = s->truncate ? s->trunc_size : skb->len;
|
|
|
|
psample_sample_packet(psample_group, skb, s->rate, &md);
|
2017-01-23 13:07:09 +03:00
|
|
|
|
|
|
|
if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev))
|
|
|
|
skb_pull(skb, skb->mac_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2021-03-10 13:33:20 +03:00
|
|
|
static void tcf_sample_stats_update(struct tc_action *a, u64 bytes, u64 packets,
|
|
|
|
u64 drops, u64 lastuse, bool hw)
|
|
|
|
{
|
|
|
|
struct tcf_sample *s = to_sample(a);
|
|
|
|
struct tcf_t *tm = &s->tcf_tm;
|
|
|
|
|
|
|
|
tcf_action_update_stats(a, bytes, packets, drops, hw);
|
|
|
|
tm->lastuse = max_t(u64, tm->lastuse, lastuse);
|
|
|
|
}
|
|
|
|
|
2017-01-23 13:07:09 +03:00
|
|
|
static int tcf_sample_dump(struct sk_buff *skb, struct tc_action *a,
|
|
|
|
int bind, int ref)
|
|
|
|
{
|
|
|
|
unsigned char *b = skb_tail_pointer(skb);
|
|
|
|
struct tcf_sample *s = to_sample(a);
|
|
|
|
struct tc_sample opt = {
|
|
|
|
.index = s->tcf_index,
|
2018-07-05 17:24:24 +03:00
|
|
|
.refcnt = refcount_read(&s->tcf_refcnt) - ref,
|
|
|
|
.bindcnt = atomic_read(&s->tcf_bindcnt) - bind,
|
2017-01-23 13:07:09 +03:00
|
|
|
};
|
|
|
|
struct tcf_t t;
|
|
|
|
|
2018-08-14 21:46:16 +03:00
|
|
|
spin_lock_bh(&s->tcf_lock);
|
2018-08-10 20:51:47 +03:00
|
|
|
opt.action = s->tcf_action;
|
2017-01-23 13:07:09 +03:00
|
|
|
if (nla_put(skb, TCA_SAMPLE_PARMS, sizeof(opt), &opt))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
tcf_tm_dump(&t, &s->tcf_tm);
|
|
|
|
if (nla_put_64bit(skb, TCA_SAMPLE_TM, sizeof(t), &t, TCA_SAMPLE_PAD))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
if (nla_put_u32(skb, TCA_SAMPLE_RATE, s->rate))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
if (s->truncate)
|
|
|
|
if (nla_put_u32(skb, TCA_SAMPLE_TRUNC_SIZE, s->trunc_size))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
if (nla_put_u32(skb, TCA_SAMPLE_PSAMPLE_GROUP, s->psample_group_num))
|
|
|
|
goto nla_put_failure;
|
2018-08-14 21:46:16 +03:00
|
|
|
spin_unlock_bh(&s->tcf_lock);
|
2018-08-10 20:51:47 +03:00
|
|
|
|
2017-01-23 13:07:09 +03:00
|
|
|
return skb->len;
|
|
|
|
|
|
|
|
nla_put_failure:
|
2018-08-14 21:46:16 +03:00
|
|
|
spin_unlock_bh(&s->tcf_lock);
|
2017-01-23 13:07:09 +03:00
|
|
|
nlmsg_trim(skb, b);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-09-13 18:28:40 +03:00
|
|
|
static void tcf_psample_group_put(void *priv)
|
|
|
|
{
|
|
|
|
struct psample_group *group = priv;
|
|
|
|
|
|
|
|
psample_group_put(group);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct psample_group *
|
|
|
|
tcf_sample_get_group(const struct tc_action *a,
|
|
|
|
tc_action_priv_destructor *destructor)
|
|
|
|
{
|
|
|
|
struct tcf_sample *s = to_sample(a);
|
|
|
|
struct psample_group *group;
|
|
|
|
|
|
|
|
group = rcu_dereference_protected(s->psample_group,
|
|
|
|
lockdep_is_held(&s->tcf_lock));
|
|
|
|
if (group) {
|
|
|
|
psample_group_take(group);
|
|
|
|
*destructor = tcf_psample_group_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
2021-12-17 21:16:21 +03:00
|
|
|
static void tcf_offload_sample_get_group(struct flow_action_entry *entry,
|
|
|
|
const struct tc_action *act)
|
|
|
|
{
|
|
|
|
entry->sample.psample_group =
|
|
|
|
act->ops->get_psample_group(act, &entry->destructor);
|
|
|
|
entry->destructor_priv = entry->sample.psample_group;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tcf_sample_offload_act_setup(struct tc_action *act, void *entry_data,
|
2022-04-07 10:35:22 +03:00
|
|
|
u32 *index_inc, bool bind,
|
|
|
|
struct netlink_ext_ack *extack)
|
2021-12-17 21:16:21 +03:00
|
|
|
{
|
|
|
|
if (bind) {
|
|
|
|
struct flow_action_entry *entry = entry_data;
|
|
|
|
|
|
|
|
entry->id = FLOW_ACTION_SAMPLE;
|
|
|
|
entry->sample.trunc_size = tcf_sample_trunc_size(act);
|
|
|
|
entry->sample.truncate = tcf_sample_truncate(act);
|
|
|
|
entry->sample.rate = tcf_sample_rate(act);
|
|
|
|
tcf_offload_sample_get_group(entry, act);
|
|
|
|
*index_inc = 1;
|
|
|
|
} else {
|
2021-12-17 21:16:22 +03:00
|
|
|
struct flow_offload_action *fl_action = entry_data;
|
|
|
|
|
|
|
|
fl_action->id = FLOW_ACTION_SAMPLE;
|
2021-12-17 21:16:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-23 13:07:09 +03:00
|
|
|
static struct tc_action_ops act_sample_ops = {
|
|
|
|
.kind = "sample",
|
2019-02-10 15:25:00 +03:00
|
|
|
.id = TCA_ID_SAMPLE,
|
2017-01-23 13:07:09 +03:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.act = tcf_sample_act,
|
2021-03-10 13:33:20 +03:00
|
|
|
.stats_update = tcf_sample_stats_update,
|
2017-01-23 13:07:09 +03:00
|
|
|
.dump = tcf_sample_dump,
|
|
|
|
.init = tcf_sample_init,
|
|
|
|
.cleanup = tcf_sample_cleanup,
|
2019-09-13 18:28:40 +03:00
|
|
|
.get_psample_group = tcf_sample_get_group,
|
2021-12-17 21:16:21 +03:00
|
|
|
.offload_act_setup = tcf_sample_offload_act_setup,
|
2017-01-23 13:07:09 +03:00
|
|
|
.size = sizeof(struct tcf_sample),
|
|
|
|
};
|
|
|
|
|
|
|
|
static __net_init int sample_init_net(struct net *net)
|
|
|
|
{
|
2022-09-08 07:14:33 +03:00
|
|
|
struct tc_action_net *tn = net_generic(net, act_sample_ops.net_id);
|
2017-01-23 13:07:09 +03:00
|
|
|
|
2019-08-25 20:01:32 +03:00
|
|
|
return tc_action_net_init(net, tn, &act_sample_ops);
|
2017-01-23 13:07:09 +03:00
|
|
|
}
|
|
|
|
|
2017-12-12 02:35:03 +03:00
|
|
|
static void __net_exit sample_exit_net(struct list_head *net_list)
|
2017-01-23 13:07:09 +03:00
|
|
|
{
|
2022-09-08 07:14:33 +03:00
|
|
|
tc_action_net_exit(net_list, act_sample_ops.net_id);
|
2017-01-23 13:07:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pernet_operations sample_net_ops = {
|
|
|
|
.init = sample_init_net,
|
2017-12-12 02:35:03 +03:00
|
|
|
.exit_batch = sample_exit_net,
|
2022-09-08 07:14:33 +03:00
|
|
|
.id = &act_sample_ops.net_id,
|
2017-01-23 13:07:09 +03:00
|
|
|
.size = sizeof(struct tc_action_net),
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init sample_init_module(void)
|
|
|
|
{
|
|
|
|
return tcf_register_action(&act_sample_ops, &sample_net_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit sample_cleanup_module(void)
|
|
|
|
{
|
|
|
|
tcf_unregister_action(&act_sample_ops, &sample_net_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(sample_init_module);
|
|
|
|
module_exit(sample_cleanup_module);
|
|
|
|
|
2017-10-30 12:41:36 +03:00
|
|
|
MODULE_AUTHOR("Yotam Gigi <yotam.gi@gmail.com>");
|
2017-01-23 13:07:09 +03:00
|
|
|
MODULE_DESCRIPTION("Packet sampling action");
|
|
|
|
MODULE_LICENSE("GPL v2");
|