2019-05-28 10:03:50 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/* net/sched/act_ctinfo.c netfilter ctinfo connmark actions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019 Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/rtnetlink.h>
|
|
|
|
#include <linux/pkt_cls.h>
|
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <linux/ipv6.h>
|
|
|
|
#include <net/netlink.h>
|
|
|
|
#include <net/pkt_sched.h>
|
|
|
|
#include <net/act_api.h>
|
|
|
|
#include <net/pkt_cls.h>
|
|
|
|
#include <uapi/linux/tc_act/tc_ctinfo.h>
|
|
|
|
#include <net/tc_act/tc_ctinfo.h>
|
2022-12-06 06:55:12 -07:00
|
|
|
#include <net/tc_wrapper.h>
|
2019-05-28 10:03:50 -07:00
|
|
|
|
|
|
|
#include <net/netfilter/nf_conntrack.h>
|
|
|
|
#include <net/netfilter/nf_conntrack_core.h>
|
|
|
|
#include <net/netfilter/nf_conntrack_ecache.h>
|
|
|
|
#include <net/netfilter/nf_conntrack_zones.h>
|
|
|
|
|
|
|
|
static struct tc_action_ops act_ctinfo_ops;
|
|
|
|
|
|
|
|
static void tcf_ctinfo_dscp_set(struct nf_conn *ct, struct tcf_ctinfo *ca,
|
|
|
|
struct tcf_ctinfo_params *cp,
|
|
|
|
struct sk_buff *skb, int wlen, int proto)
|
|
|
|
{
|
|
|
|
u8 dscp, newdscp;
|
|
|
|
|
2022-11-09 12:39:07 -07:00
|
|
|
newdscp = (((READ_ONCE(ct->mark) & cp->dscpmask) >> cp->dscpmaskshift) << 2) &
|
2019-05-28 10:03:50 -07:00
|
|
|
~INET_ECN_MASK;
|
|
|
|
|
|
|
|
switch (proto) {
|
|
|
|
case NFPROTO_IPV4:
|
|
|
|
dscp = ipv4_get_dsfield(ip_hdr(skb)) & ~INET_ECN_MASK;
|
|
|
|
if (dscp != newdscp) {
|
|
|
|
if (likely(!skb_try_make_writable(skb, wlen))) {
|
|
|
|
ipv4_change_dsfield(ip_hdr(skb),
|
|
|
|
INET_ECN_MASK,
|
|
|
|
newdscp);
|
|
|
|
ca->stats_dscp_set++;
|
|
|
|
} else {
|
|
|
|
ca->stats_dscp_error++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NFPROTO_IPV6:
|
|
|
|
dscp = ipv6_get_dsfield(ipv6_hdr(skb)) & ~INET_ECN_MASK;
|
|
|
|
if (dscp != newdscp) {
|
|
|
|
if (likely(!skb_try_make_writable(skb, wlen))) {
|
|
|
|
ipv6_change_dsfield(ipv6_hdr(skb),
|
|
|
|
INET_ECN_MASK,
|
|
|
|
newdscp);
|
|
|
|
ca->stats_dscp_set++;
|
|
|
|
} else {
|
|
|
|
ca->stats_dscp_error++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tcf_ctinfo_cpmark_set(struct nf_conn *ct, struct tcf_ctinfo *ca,
|
|
|
|
struct tcf_ctinfo_params *cp,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
ca->stats_cpmark_set++;
|
2022-11-09 12:39:07 -07:00
|
|
|
skb->mark = READ_ONCE(ct->mark) & cp->cpmarkmask;
|
2019-05-28 10:03:50 -07:00
|
|
|
}
|
|
|
|
|
2022-12-06 06:55:12 -07:00
|
|
|
TC_INDIRECT_SCOPE int tcf_ctinfo_act(struct sk_buff *skb,
|
|
|
|
const struct tc_action *a,
|
|
|
|
struct tcf_result *res)
|
2019-05-28 10:03:50 -07:00
|
|
|
{
|
|
|
|
const struct nf_conntrack_tuple_hash *thash = NULL;
|
|
|
|
struct tcf_ctinfo *ca = to_ctinfo(a);
|
|
|
|
struct nf_conntrack_tuple tuple;
|
|
|
|
struct nf_conntrack_zone zone;
|
|
|
|
enum ip_conntrack_info ctinfo;
|
|
|
|
struct tcf_ctinfo_params *cp;
|
|
|
|
struct nf_conn *ct;
|
|
|
|
int proto, wlen;
|
|
|
|
int action;
|
|
|
|
|
|
|
|
cp = rcu_dereference_bh(ca->params);
|
|
|
|
|
|
|
|
tcf_lastuse_update(&ca->tcf_tm);
|
2023-02-10 13:08:25 -07:00
|
|
|
tcf_action_update_bstats(&ca->common, skb);
|
2019-05-28 10:03:50 -07:00
|
|
|
action = READ_ONCE(ca->tcf_action);
|
|
|
|
|
|
|
|
wlen = skb_network_offset(skb);
|
sched: consistently handle layer3 header accesses in the presence of VLANs
There are a couple of places in net/sched/ that check skb->protocol and act
on the value there. However, in the presence of VLAN tags, the value stored
in skb->protocol can be inconsistent based on whether VLAN acceleration is
enabled. The commit quoted in the Fixes tag below fixed the users of
skb->protocol to use a helper that will always see the VLAN ethertype.
However, most of the callers don't actually handle the VLAN ethertype, but
expect to find the IP header type in the protocol field. This means that
things like changing the ECN field, or parsing diffserv values, stops
working if there's a VLAN tag, or if there are multiple nested VLAN
tags (QinQ).
To fix this, change the helper to take an argument that indicates whether
the caller wants to skip the VLAN tags or not. When skipping VLAN tags, we
make sure to skip all of them, so behaviour is consistent even in QinQ
mode.
To make the helper usable from the ECN code, move it to if_vlan.h instead
of pkt_sched.h.
v3:
- Remove empty lines
- Move vlan variable definitions inside loop in skb_protocol()
- Also use skb_protocol() helper in IP{,6}_ECN_decapsulate() and
bpf_skb_ecn_set_ce()
v2:
- Use eth_type_vlan() helper in skb_protocol()
- Also fix code that reads skb->protocol directly
- Change a couple of 'if/else if' statements to switch constructs to avoid
calling the helper twice
Reported-by: Ilya Ponetayev <i.ponetaev@ndmsystems.com>
Fixes: d8b9605d2697 ("net: sched: fix skb->protocol use in case of accelerated vlan path")
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-07-03 13:26:43 -07:00
|
|
|
switch (skb_protocol(skb, true)) {
|
|
|
|
case htons(ETH_P_IP):
|
2019-05-28 10:03:50 -07:00
|
|
|
wlen += sizeof(struct iphdr);
|
|
|
|
if (!pskb_may_pull(skb, wlen))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
proto = NFPROTO_IPV4;
|
sched: consistently handle layer3 header accesses in the presence of VLANs
There are a couple of places in net/sched/ that check skb->protocol and act
on the value there. However, in the presence of VLAN tags, the value stored
in skb->protocol can be inconsistent based on whether VLAN acceleration is
enabled. The commit quoted in the Fixes tag below fixed the users of
skb->protocol to use a helper that will always see the VLAN ethertype.
However, most of the callers don't actually handle the VLAN ethertype, but
expect to find the IP header type in the protocol field. This means that
things like changing the ECN field, or parsing diffserv values, stops
working if there's a VLAN tag, or if there are multiple nested VLAN
tags (QinQ).
To fix this, change the helper to take an argument that indicates whether
the caller wants to skip the VLAN tags or not. When skipping VLAN tags, we
make sure to skip all of them, so behaviour is consistent even in QinQ
mode.
To make the helper usable from the ECN code, move it to if_vlan.h instead
of pkt_sched.h.
v3:
- Remove empty lines
- Move vlan variable definitions inside loop in skb_protocol()
- Also use skb_protocol() helper in IP{,6}_ECN_decapsulate() and
bpf_skb_ecn_set_ce()
v2:
- Use eth_type_vlan() helper in skb_protocol()
- Also fix code that reads skb->protocol directly
- Change a couple of 'if/else if' statements to switch constructs to avoid
calling the helper twice
Reported-by: Ilya Ponetayev <i.ponetaev@ndmsystems.com>
Fixes: d8b9605d2697 ("net: sched: fix skb->protocol use in case of accelerated vlan path")
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-07-03 13:26:43 -07:00
|
|
|
break;
|
|
|
|
case htons(ETH_P_IPV6):
|
2019-05-28 10:03:50 -07:00
|
|
|
wlen += sizeof(struct ipv6hdr);
|
|
|
|
if (!pskb_may_pull(skb, wlen))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
proto = NFPROTO_IPV6;
|
sched: consistently handle layer3 header accesses in the presence of VLANs
There are a couple of places in net/sched/ that check skb->protocol and act
on the value there. However, in the presence of VLAN tags, the value stored
in skb->protocol can be inconsistent based on whether VLAN acceleration is
enabled. The commit quoted in the Fixes tag below fixed the users of
skb->protocol to use a helper that will always see the VLAN ethertype.
However, most of the callers don't actually handle the VLAN ethertype, but
expect to find the IP header type in the protocol field. This means that
things like changing the ECN field, or parsing diffserv values, stops
working if there's a VLAN tag, or if there are multiple nested VLAN
tags (QinQ).
To fix this, change the helper to take an argument that indicates whether
the caller wants to skip the VLAN tags or not. When skipping VLAN tags, we
make sure to skip all of them, so behaviour is consistent even in QinQ
mode.
To make the helper usable from the ECN code, move it to if_vlan.h instead
of pkt_sched.h.
v3:
- Remove empty lines
- Move vlan variable definitions inside loop in skb_protocol()
- Also use skb_protocol() helper in IP{,6}_ECN_decapsulate() and
bpf_skb_ecn_set_ce()
v2:
- Use eth_type_vlan() helper in skb_protocol()
- Also fix code that reads skb->protocol directly
- Change a couple of 'if/else if' statements to switch constructs to avoid
calling the helper twice
Reported-by: Ilya Ponetayev <i.ponetaev@ndmsystems.com>
Fixes: d8b9605d2697 ("net: sched: fix skb->protocol use in case of accelerated vlan path")
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-07-03 13:26:43 -07:00
|
|
|
break;
|
|
|
|
default:
|
2019-05-28 10:03:50 -07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ct = nf_ct_get(skb, &ctinfo);
|
|
|
|
if (!ct) { /* look harder, usually ingress */
|
|
|
|
if (!nf_ct_get_tuplepr(skb, skb_network_offset(skb),
|
|
|
|
proto, cp->net, &tuple))
|
|
|
|
goto out;
|
|
|
|
zone.id = cp->zone;
|
|
|
|
zone.dir = NF_CT_DEFAULT_ZONE_DIR;
|
|
|
|
|
|
|
|
thash = nf_conntrack_find_get(cp->net, &zone, &tuple);
|
|
|
|
if (!thash)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ct = nf_ct_tuplehash_to_ctrack(thash);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cp->mode & CTINFO_MODE_DSCP)
|
2022-11-09 12:39:07 -07:00
|
|
|
if (!cp->dscpstatemask || (READ_ONCE(ct->mark) & cp->dscpstatemask))
|
2019-05-28 10:03:50 -07:00
|
|
|
tcf_ctinfo_dscp_set(ct, ca, cp, skb, wlen, proto);
|
|
|
|
|
|
|
|
if (cp->mode & CTINFO_MODE_CPMARK)
|
|
|
|
tcf_ctinfo_cpmark_set(ct, ca, cp, skb);
|
|
|
|
|
|
|
|
if (thash)
|
|
|
|
nf_ct_put(ct);
|
|
|
|
out:
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct nla_policy ctinfo_policy[TCA_CTINFO_MAX + 1] = {
|
2020-08-18 01:17:31 -07:00
|
|
|
[TCA_CTINFO_ACT] =
|
|
|
|
NLA_POLICY_EXACT_LEN(sizeof(struct tc_ctinfo)),
|
2019-05-28 10:03:50 -07:00
|
|
|
[TCA_CTINFO_ZONE] = { .type = NLA_U16 },
|
|
|
|
[TCA_CTINFO_PARMS_DSCP_MASK] = { .type = NLA_U32 },
|
|
|
|
[TCA_CTINFO_PARMS_DSCP_STATEMASK] = { .type = NLA_U32 },
|
|
|
|
[TCA_CTINFO_PARMS_CPMARK_MASK] = { .type = NLA_U32 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int tcf_ctinfo_init(struct net *net, struct nlattr *nla,
|
|
|
|
struct nlattr *est, struct tc_action **a,
|
2019-10-30 07:09:05 -07:00
|
|
|
struct tcf_proto *tp, u32 flags,
|
2019-05-28 10:03:50 -07:00
|
|
|
struct netlink_ext_ack *extack)
|
|
|
|
{
|
2022-09-07 21:14:33 -07:00
|
|
|
struct tc_action_net *tn = net_generic(net, act_ctinfo_ops.net_id);
|
2021-07-29 16:12:14 -07:00
|
|
|
bool bind = flags & TCA_ACT_FLAGS_BIND;
|
2019-08-01 06:02:51 -07:00
|
|
|
u32 dscpmask = 0, dscpstatemask, index;
|
2019-05-28 10:03:50 -07:00
|
|
|
struct nlattr *tb[TCA_CTINFO_MAX + 1];
|
|
|
|
struct tcf_ctinfo_params *cp_new;
|
|
|
|
struct tcf_chain *goto_ch = NULL;
|
|
|
|
struct tc_ctinfo *actparm;
|
|
|
|
struct tcf_ctinfo *ci;
|
|
|
|
u8 dscpmaskshift;
|
|
|
|
int ret = 0, err;
|
|
|
|
|
2019-06-14 02:09:44 -07:00
|
|
|
if (!nla) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "ctinfo requires attributes to be passed");
|
2019-05-28 10:03:50 -07:00
|
|
|
return -EINVAL;
|
2019-06-14 02:09:44 -07:00
|
|
|
}
|
2019-05-28 10:03:50 -07:00
|
|
|
|
2019-06-14 02:09:44 -07:00
|
|
|
err = nla_parse_nested(tb, TCA_CTINFO_MAX, nla, ctinfo_policy, extack);
|
2019-05-28 10:03:50 -07:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2019-06-14 02:09:44 -07:00
|
|
|
if (!tb[TCA_CTINFO_ACT]) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack,
|
|
|
|
"Missing required TCA_CTINFO_ACT attribute");
|
2019-05-28 10:03:50 -07:00
|
|
|
return -EINVAL;
|
2019-06-14 02:09:44 -07:00
|
|
|
}
|
2019-05-28 10:03:50 -07:00
|
|
|
actparm = nla_data(tb[TCA_CTINFO_ACT]);
|
|
|
|
|
|
|
|
/* do some basic validation here before dynamically allocating things */
|
|
|
|
/* that we would otherwise have to clean up. */
|
|
|
|
if (tb[TCA_CTINFO_PARMS_DSCP_MASK]) {
|
|
|
|
dscpmask = nla_get_u32(tb[TCA_CTINFO_PARMS_DSCP_MASK]);
|
|
|
|
/* need contiguous 6 bit mask */
|
|
|
|
dscpmaskshift = dscpmask ? __ffs(dscpmask) : 0;
|
2019-06-14 02:09:44 -07:00
|
|
|
if ((~0 & (dscpmask >> dscpmaskshift)) != 0x3f) {
|
|
|
|
NL_SET_ERR_MSG_ATTR(extack,
|
|
|
|
tb[TCA_CTINFO_PARMS_DSCP_MASK],
|
|
|
|
"dscp mask must be 6 contiguous bits");
|
2019-05-28 10:03:50 -07:00
|
|
|
return -EINVAL;
|
2019-06-14 02:09:44 -07:00
|
|
|
}
|
2019-05-28 10:03:50 -07:00
|
|
|
dscpstatemask = tb[TCA_CTINFO_PARMS_DSCP_STATEMASK] ?
|
|
|
|
nla_get_u32(tb[TCA_CTINFO_PARMS_DSCP_STATEMASK]) : 0;
|
|
|
|
/* mask & statemask must not overlap */
|
2019-06-14 02:09:44 -07:00
|
|
|
if (dscpmask & dscpstatemask) {
|
|
|
|
NL_SET_ERR_MSG_ATTR(extack,
|
|
|
|
tb[TCA_CTINFO_PARMS_DSCP_STATEMASK],
|
|
|
|
"dscp statemask must not overlap dscp mask");
|
2019-05-28 10:03:50 -07:00
|
|
|
return -EINVAL;
|
2019-06-14 02:09:44 -07:00
|
|
|
}
|
2019-05-28 10:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* done the validation:now to the actual action allocation */
|
2019-08-01 06:02:51 -07:00
|
|
|
index = actparm->index;
|
|
|
|
err = tcf_idr_check_alloc(tn, &index, a, bind);
|
2019-05-28 10:03:50 -07:00
|
|
|
if (!err) {
|
2023-02-10 13:08:25 -07:00
|
|
|
ret = tcf_idr_create_from_flags(tn, index, est, a,
|
|
|
|
&act_ctinfo_ops, bind, flags);
|
2019-05-28 10:03:50 -07:00
|
|
|
if (ret) {
|
2019-08-01 06:02:51 -07:00
|
|
|
tcf_idr_cleanup(tn, index);
|
2019-05-28 10:03:50 -07:00
|
|
|
return ret;
|
|
|
|
}
|
2019-06-17 03:03:26 -07:00
|
|
|
ret = ACT_P_CREATED;
|
2019-05-28 10:03:50 -07:00
|
|
|
} else if (err > 0) {
|
|
|
|
if (bind) /* don't override defaults */
|
2023-12-29 06:26:41 -07:00
|
|
|
return ACT_P_BOUND;
|
2021-07-29 16:12:14 -07:00
|
|
|
if (!(flags & TCA_ACT_FLAGS_REPLACE)) {
|
2019-05-28 10:03:50 -07:00
|
|
|
tcf_idr_release(*a, bind);
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = tcf_action_check_ctrlact(actparm->action, tp, &goto_ch, extack);
|
|
|
|
if (err < 0)
|
|
|
|
goto release_idr;
|
|
|
|
|
|
|
|
ci = to_ctinfo(*a);
|
|
|
|
|
|
|
|
cp_new = kzalloc(sizeof(*cp_new), GFP_KERNEL);
|
|
|
|
if (unlikely(!cp_new)) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto put_chain;
|
|
|
|
}
|
|
|
|
|
|
|
|
cp_new->net = net;
|
|
|
|
cp_new->zone = tb[TCA_CTINFO_ZONE] ?
|
|
|
|
nla_get_u16(tb[TCA_CTINFO_ZONE]) : 0;
|
|
|
|
if (dscpmask) {
|
|
|
|
cp_new->dscpmask = dscpmask;
|
|
|
|
cp_new->dscpmaskshift = dscpmaskshift;
|
|
|
|
cp_new->dscpstatemask = dscpstatemask;
|
|
|
|
cp_new->mode |= CTINFO_MODE_DSCP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tb[TCA_CTINFO_PARMS_CPMARK_MASK]) {
|
|
|
|
cp_new->cpmarkmask =
|
|
|
|
nla_get_u32(tb[TCA_CTINFO_PARMS_CPMARK_MASK]);
|
|
|
|
cp_new->mode |= CTINFO_MODE_CPMARK;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_bh(&ci->tcf_lock);
|
|
|
|
goto_ch = tcf_action_set_ctrlact(*a, actparm->action, goto_ch);
|
2019-09-23 16:09:18 -07:00
|
|
|
cp_new = rcu_replace_pointer(ci->params, cp_new,
|
|
|
|
lockdep_is_held(&ci->tcf_lock));
|
2019-05-28 10:03:50 -07:00
|
|
|
spin_unlock_bh(&ci->tcf_lock);
|
|
|
|
|
|
|
|
if (goto_ch)
|
|
|
|
tcf_chain_put_by_act(goto_ch);
|
|
|
|
if (cp_new)
|
|
|
|
kfree_rcu(cp_new, rcu);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
put_chain:
|
|
|
|
if (goto_ch)
|
|
|
|
tcf_chain_put_by_act(goto_ch);
|
|
|
|
release_idr:
|
|
|
|
tcf_idr_release(*a, bind);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tcf_ctinfo_dump(struct sk_buff *skb, struct tc_action *a,
|
|
|
|
int bind, int ref)
|
|
|
|
{
|
|
|
|
struct tcf_ctinfo *ci = to_ctinfo(a);
|
|
|
|
struct tc_ctinfo opt = {
|
|
|
|
.index = ci->tcf_index,
|
|
|
|
.refcnt = refcount_read(&ci->tcf_refcnt) - ref,
|
|
|
|
.bindcnt = atomic_read(&ci->tcf_bindcnt) - bind,
|
|
|
|
};
|
|
|
|
unsigned char *b = skb_tail_pointer(skb);
|
|
|
|
struct tcf_ctinfo_params *cp;
|
|
|
|
struct tcf_t t;
|
|
|
|
|
|
|
|
spin_lock_bh(&ci->tcf_lock);
|
|
|
|
cp = rcu_dereference_protected(ci->params,
|
|
|
|
lockdep_is_held(&ci->tcf_lock));
|
|
|
|
|
|
|
|
tcf_tm_dump(&t, &ci->tcf_tm);
|
|
|
|
if (nla_put_64bit(skb, TCA_CTINFO_TM, sizeof(t), &t, TCA_CTINFO_PAD))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
opt.action = ci->tcf_action;
|
|
|
|
if (nla_put(skb, TCA_CTINFO_ACT, sizeof(opt), &opt))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
if (nla_put_u16(skb, TCA_CTINFO_ZONE, cp->zone))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
if (cp->mode & CTINFO_MODE_DSCP) {
|
|
|
|
if (nla_put_u32(skb, TCA_CTINFO_PARMS_DSCP_MASK,
|
|
|
|
cp->dscpmask))
|
|
|
|
goto nla_put_failure;
|
|
|
|
if (nla_put_u32(skb, TCA_CTINFO_PARMS_DSCP_STATEMASK,
|
|
|
|
cp->dscpstatemask))
|
|
|
|
goto nla_put_failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cp->mode & CTINFO_MODE_CPMARK) {
|
|
|
|
if (nla_put_u32(skb, TCA_CTINFO_PARMS_CPMARK_MASK,
|
|
|
|
cp->cpmarkmask))
|
|
|
|
goto nla_put_failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nla_put_u64_64bit(skb, TCA_CTINFO_STATS_DSCP_SET,
|
|
|
|
ci->stats_dscp_set, TCA_CTINFO_PAD))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
if (nla_put_u64_64bit(skb, TCA_CTINFO_STATS_DSCP_ERROR,
|
|
|
|
ci->stats_dscp_error, TCA_CTINFO_PAD))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
if (nla_put_u64_64bit(skb, TCA_CTINFO_STATS_CPMARK_SET,
|
|
|
|
ci->stats_cpmark_set, TCA_CTINFO_PAD))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
spin_unlock_bh(&ci->tcf_lock);
|
|
|
|
return skb->len;
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
spin_unlock_bh(&ci->tcf_lock);
|
|
|
|
nlmsg_trim(skb, b);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-01-18 21:45:06 -07:00
|
|
|
static void tcf_ctinfo_cleanup(struct tc_action *a)
|
|
|
|
{
|
|
|
|
struct tcf_ctinfo *ci = to_ctinfo(a);
|
|
|
|
struct tcf_ctinfo_params *cp;
|
|
|
|
|
|
|
|
cp = rcu_dereference_protected(ci->params, 1);
|
|
|
|
if (cp)
|
|
|
|
kfree_rcu(cp, rcu);
|
|
|
|
}
|
|
|
|
|
2019-05-28 10:03:50 -07:00
|
|
|
static struct tc_action_ops act_ctinfo_ops = {
|
|
|
|
.kind = "ctinfo",
|
|
|
|
.id = TCA_ID_CTINFO,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.act = tcf_ctinfo_act,
|
|
|
|
.dump = tcf_ctinfo_dump,
|
|
|
|
.init = tcf_ctinfo_init,
|
2020-01-18 21:45:06 -07:00
|
|
|
.cleanup= tcf_ctinfo_cleanup,
|
2019-05-28 10:03:50 -07:00
|
|
|
.size = sizeof(struct tcf_ctinfo),
|
|
|
|
};
|
2024-02-01 06:09:41 -07:00
|
|
|
MODULE_ALIAS_NET_ACT("ctinfo");
|
2019-05-28 10:03:50 -07:00
|
|
|
|
|
|
|
static __net_init int ctinfo_init_net(struct net *net)
|
|
|
|
{
|
2022-09-07 21:14:33 -07:00
|
|
|
struct tc_action_net *tn = net_generic(net, act_ctinfo_ops.net_id);
|
2019-05-28 10:03:50 -07:00
|
|
|
|
2019-08-25 10:01:32 -07:00
|
|
|
return tc_action_net_init(net, tn, &act_ctinfo_ops);
|
2019-05-28 10:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __net_exit ctinfo_exit_net(struct list_head *net_list)
|
|
|
|
{
|
2022-09-07 21:14:33 -07:00
|
|
|
tc_action_net_exit(net_list, act_ctinfo_ops.net_id);
|
2019-05-28 10:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pernet_operations ctinfo_net_ops = {
|
|
|
|
.init = ctinfo_init_net,
|
|
|
|
.exit_batch = ctinfo_exit_net,
|
2022-09-07 21:14:33 -07:00
|
|
|
.id = &act_ctinfo_ops.net_id,
|
2019-05-28 10:03:50 -07:00
|
|
|
.size = sizeof(struct tc_action_net),
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init ctinfo_init_module(void)
|
|
|
|
{
|
|
|
|
return tcf_register_action(&act_ctinfo_ops, &ctinfo_net_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit ctinfo_cleanup_module(void)
|
|
|
|
{
|
|
|
|
tcf_unregister_action(&act_ctinfo_ops, &ctinfo_net_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(ctinfo_init_module);
|
|
|
|
module_exit(ctinfo_cleanup_module);
|
|
|
|
MODULE_AUTHOR("Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>");
|
|
|
|
MODULE_DESCRIPTION("Connection tracking mark actions");
|
|
|
|
MODULE_LICENSE("GPL");
|