act_ctinfo.c (002c6ca75289a4ac4f6738213dd2d258704886e4) act_ctinfo.c (52d1aa8b8249ff477aaa38b6f74a8ced780d079c)
1// SPDX-License-Identifier: GPL-2.0+
2/* net/sched/act_ctinfo.c netfilter ctinfo connmark actions
3 *
4 * Copyright (c) 2019 Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
5 */
6
7#include <linux/module.h>
8#include <linux/init.h>

--- 18 unchanged lines hidden (view full) ---

27static struct tc_action_ops act_ctinfo_ops;
28
29static void tcf_ctinfo_dscp_set(struct nf_conn *ct, struct tcf_ctinfo *ca,
30 struct tcf_ctinfo_params *cp,
31 struct sk_buff *skb, int wlen, int proto)
32{
33 u8 dscp, newdscp;
34
1// SPDX-License-Identifier: GPL-2.0+
2/* net/sched/act_ctinfo.c netfilter ctinfo connmark actions
3 *
4 * Copyright (c) 2019 Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
5 */
6
7#include <linux/module.h>
8#include <linux/init.h>

--- 18 unchanged lines hidden (view full) ---

27static struct tc_action_ops act_ctinfo_ops;
28
29static void tcf_ctinfo_dscp_set(struct nf_conn *ct, struct tcf_ctinfo *ca,
30 struct tcf_ctinfo_params *cp,
31 struct sk_buff *skb, int wlen, int proto)
32{
33 u8 dscp, newdscp;
34
35 newdscp = (((ct->mark & cp->dscpmask) >> cp->dscpmaskshift) << 2) &
35 newdscp = (((READ_ONCE(ct->mark) & cp->dscpmask) >> cp->dscpmaskshift) << 2) &
36 ~INET_ECN_MASK;
37
38 switch (proto) {
39 case NFPROTO_IPV4:
40 dscp = ipv4_get_dsfield(ip_hdr(skb)) & ~INET_ECN_MASK;
41 if (dscp != newdscp) {
42 if (likely(!skb_try_make_writable(skb, wlen))) {
43 ipv4_change_dsfield(ip_hdr(skb),

--- 23 unchanged lines hidden (view full) ---

67 }
68}
69
70static void tcf_ctinfo_cpmark_set(struct nf_conn *ct, struct tcf_ctinfo *ca,
71 struct tcf_ctinfo_params *cp,
72 struct sk_buff *skb)
73{
74 ca->stats_cpmark_set++;
36 ~INET_ECN_MASK;
37
38 switch (proto) {
39 case NFPROTO_IPV4:
40 dscp = ipv4_get_dsfield(ip_hdr(skb)) & ~INET_ECN_MASK;
41 if (dscp != newdscp) {
42 if (likely(!skb_try_make_writable(skb, wlen))) {
43 ipv4_change_dsfield(ip_hdr(skb),

--- 23 unchanged lines hidden (view full) ---

67 }
68}
69
70static void tcf_ctinfo_cpmark_set(struct nf_conn *ct, struct tcf_ctinfo *ca,
71 struct tcf_ctinfo_params *cp,
72 struct sk_buff *skb)
73{
74 ca->stats_cpmark_set++;
75 skb->mark = ct->mark & cp->cpmarkmask;
75 skb->mark = READ_ONCE(ct->mark) & cp->cpmarkmask;
76}
77
78static int tcf_ctinfo_act(struct sk_buff *skb, const struct tc_action *a,
79 struct tcf_result *res)
80{
81 const struct nf_conntrack_tuple_hash *thash = NULL;
82 struct tcf_ctinfo *ca = to_ctinfo(a);
83 struct nf_conntrack_tuple tuple;

--- 41 unchanged lines hidden (view full) ---

125 thash = nf_conntrack_find_get(cp->net, &zone, &tuple);
126 if (!thash)
127 goto out;
128
129 ct = nf_ct_tuplehash_to_ctrack(thash);
130 }
131
132 if (cp->mode & CTINFO_MODE_DSCP)
76}
77
78static int tcf_ctinfo_act(struct sk_buff *skb, const struct tc_action *a,
79 struct tcf_result *res)
80{
81 const struct nf_conntrack_tuple_hash *thash = NULL;
82 struct tcf_ctinfo *ca = to_ctinfo(a);
83 struct nf_conntrack_tuple tuple;

--- 41 unchanged lines hidden (view full) ---

125 thash = nf_conntrack_find_get(cp->net, &zone, &tuple);
126 if (!thash)
127 goto out;
128
129 ct = nf_ct_tuplehash_to_ctrack(thash);
130 }
131
132 if (cp->mode & CTINFO_MODE_DSCP)
133 if (!cp->dscpstatemask || (ct->mark & cp->dscpstatemask))
133 if (!cp->dscpstatemask || (READ_ONCE(ct->mark) & cp->dscpstatemask))
134 tcf_ctinfo_dscp_set(ct, ca, cp, skb, wlen, proto);
135
136 if (cp->mode & CTINFO_MODE_CPMARK)
137 tcf_ctinfo_cpmark_set(ct, ca, cp, skb);
138
139 if (thash)
140 nf_ct_put(ct);
141out:

--- 257 unchanged lines hidden ---
134 tcf_ctinfo_dscp_set(ct, ca, cp, skb, wlen, proto);
135
136 if (cp->mode & CTINFO_MODE_CPMARK)
137 tcf_ctinfo_cpmark_set(ct, ca, cp, skb);
138
139 if (thash)
140 nf_ct_put(ct);
141out:

--- 257 unchanged lines hidden ---