ramips: drop support for kernel 4.14
[openwrt/openwrt.git] / target / linux / generic / backport-4.14 / 380-v5.3-net-sched-Introduce-act_ctinfo-action.patch
1 From 85fc2a6db8279c5e43c38ef7e715d14e57287997 Mon Sep 17 00:00:00 2001
2 From: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
3 Date: Wed, 13 Mar 2019 20:54:49 +0000
4 Subject: [PATCH] net: sched: Backport Introduce act_ctinfo action
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 ctinfo is a new tc filter action module. It is designed to restore
10 information contained in firewall conntrack marks to other packet fields
11 and is typically used on packet ingress paths. At present it has two
12 independent sub-functions or operating modes, DSCP restoration mode &
13 skb mark restoration mode.
14
15 The DSCP restore mode:
16
17 This mode copies DSCP values that have been placed in the firewall
18 conntrack mark back into the IPv4/v6 diffserv fields of relevant
19 packets.
20
21 The DSCP restoration is intended for use and has been found useful for
22 restoring ingress classifications based on egress classifications across
23 links that bleach or otherwise change DSCP, typically home ISP Internet
24 links. Restoring DSCP on ingress on the WAN link allows qdiscs such as
25 but by no means limited to CAKE to shape inbound packets according to
26 policies that are easier to set & mark on egress.
27
28 Ingress classification is traditionally a challenging task since
29 iptables rules haven't yet run and tc filter/eBPF programs are pre-NAT
30 lookups, hence are unable to see internal IPv4 addresses as used on the
31 typical home masquerading gateway. Thus marking the connection in some
32 manner on egress for later restoration of classification on ingress is
33 easier to implement.
34
35 Parameters related to DSCP restore mode:
36
37 dscpmask - a 32 bit mask of 6 contiguous bits and indicate bits of the
38 conntrack mark field contain the DSCP value to be restored.
39
40 statemask - a 32 bit mask of (usually) 1 bit length, outside the area
41 specified by dscpmask. This represents a conditional operation flag
42 whereby the DSCP is only restored if the flag is set. This is useful to
43 implement a 'one shot' iptables based classification where the
44 'complicated' iptables rules are only run once to classify the
45 connection on initial (egress) packet and subsequent packets are all
46 marked/restored with the same DSCP. A mask of zero disables the
47 conditional behaviour ie. the conntrack mark DSCP bits are always
48 restored to the ip diffserv field (assuming the conntrack entry is found
49 & the skb is an ipv4/ipv6 type)
50
51 e.g. dscpmask 0xfc000000 statemask 0x01000000
52
53 |----0xFC----conntrack mark----000000---|
54 | Bits 31-26 | bit 25 | bit24 |~~~ Bit 0|
55 | DSCP | unused | flag |unused |
56 |-----------------------0x01---000000---|
57 | |
58 | |
59 ---| Conditional flag
60 v only restore if set
61 |-ip diffserv-|
62 | 6 bits |
63 |-------------|
64
65 The skb mark restore mode (cpmark):
66
67 This mode copies the firewall conntrack mark to the skb's mark field.
68 It is completely the functional equivalent of the existing act_connmark
69 action with the additional feature of being able to apply a mask to the
70 restored value.
71
72 Parameters related to skb mark restore mode:
73
74 mask - a 32 bit mask applied to the firewall conntrack mark to mask out
75 bits unwanted for restoration. This can be useful where the conntrack
76 mark is being used for different purposes by different applications. If
77 not specified and by default the whole mark field is copied (i.e.
78 default mask of 0xffffffff)
79
80 e.g. mask 0x00ffffff to mask out the top 8 bits being used by the
81 aforementioned DSCP restore mode.
82
83 |----0x00----conntrack mark----ffffff---|
84 | Bits 31-24 | |
85 | DSCP & flag| some value here |
86 |---------------------------------------|
87 |
88 |
89 v
90 |------------skb mark-------------------|
91 | | |
92 | zeroed | |
93 |---------------------------------------|
94
95 Overall parameters:
96
97 zone - conntrack zone
98
99 control - action related control (reclassify | pipe | drop | continue |
100 ok | goto chain <CHAIN_INDEX>)
101
102 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
103 Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
104 Acked-by: Cong Wang <xiyou.wangcong@gmail.com>
105 Signed-off-by: David S. Miller <davem@davemloft.net>
106
107 Backport
108 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
109 ---
110 include/net/tc_act/tc_ctinfo.h | 33 +++
111 include/uapi/linux/pkt_cls.h | 3 +-
112 include/uapi/linux/tc_act/tc_ctinfo.h | 29 ++
113 net/sched/Kconfig | 13 +
114 net/sched/Makefile | 1 +
115 net/sched/act_ctinfo.c | 405 ++++++++++++++++++++++++++
116 6 files changed, 482 insertions(+), 1 deletion(-)
117 create mode 100644 include/net/tc_act/tc_ctinfo.h
118 create mode 100644 include/uapi/linux/tc_act/tc_ctinfo.h
119 create mode 100644 net/sched/act_ctinfo.c
120
121 --- /dev/null
122 +++ b/include/net/tc_act/tc_ctinfo.h
123 @@ -0,0 +1,33 @@
124 +/* SPDX-License-Identifier: GPL-2.0 */
125 +#ifndef __NET_TC_CTINFO_H
126 +#define __NET_TC_CTINFO_H
127 +
128 +#include <net/act_api.h>
129 +
130 +struct tcf_ctinfo_params {
131 + struct rcu_head rcu;
132 + struct net *net;
133 + u32 dscpmask;
134 + u32 dscpstatemask;
135 + u32 cpmarkmask;
136 + u16 zone;
137 + u8 mode;
138 + u8 dscpmaskshift;
139 +};
140 +
141 +struct tcf_ctinfo {
142 + struct tc_action common;
143 + struct tcf_ctinfo_params __rcu *params;
144 + u64 stats_dscp_set;
145 + u64 stats_dscp_error;
146 + u64 stats_cpmark_set;
147 +};
148 +
149 +enum {
150 + CTINFO_MODE_DSCP = BIT(0),
151 + CTINFO_MODE_CPMARK = BIT(1)
152 +};
153 +
154 +#define to_ctinfo(a) ((struct tcf_ctinfo *)a)
155 +
156 +#endif /* __NET_TC_CTINFO_H */
157 --- a/include/uapi/linux/pkt_cls.h
158 +++ b/include/uapi/linux/pkt_cls.h
159 @@ -66,7 +66,8 @@ enum {
160 TCA_ID_UNSPEC=0,
161 TCA_ID_POLICE=1,
162 /* other actions go here */
163 - __TCA_ID_MAX=255
164 + TCA_ID_CTINFO=27,
165 + __TCA_ID_MAX = 255
166 };
167
168 #define TCA_ID_MAX __TCA_ID_MAX
169 --- /dev/null
170 +++ b/include/uapi/linux/tc_act/tc_ctinfo.h
171 @@ -0,0 +1,29 @@
172 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
173 +#ifndef __UAPI_TC_CTINFO_H
174 +#define __UAPI_TC_CTINFO_H
175 +
176 +#include <linux/types.h>
177 +#include <linux/pkt_cls.h>
178 +
179 +struct tc_ctinfo {
180 + tc_gen;
181 +};
182 +
183 +enum {
184 + TCA_CTINFO_UNSPEC,
185 + TCA_CTINFO_PAD,
186 + TCA_CTINFO_TM,
187 + TCA_CTINFO_ACT,
188 + TCA_CTINFO_ZONE,
189 + TCA_CTINFO_PARMS_DSCP_MASK,
190 + TCA_CTINFO_PARMS_DSCP_STATEMASK,
191 + TCA_CTINFO_PARMS_CPMARK_MASK,
192 + TCA_CTINFO_STATS_DSCP_SET,
193 + TCA_CTINFO_STATS_DSCP_ERROR,
194 + TCA_CTINFO_STATS_CPMARK_SET,
195 + __TCA_CTINFO_MAX
196 +};
197 +
198 +#define TCA_CTINFO_MAX (__TCA_CTINFO_MAX - 1)
199 +
200 +#endif
201 --- a/net/sched/Kconfig
202 +++ b/net/sched/Kconfig
203 @@ -808,6 +808,19 @@ config NET_ACT_CONNMARK
204 To compile this code as a module, choose M here: the
205 module will be called act_connmark.
206
207 +config NET_ACT_CTINFO
208 + tristate "Netfilter Connmark to DSCP Retriever"
209 + depends on NET_CLS_ACT && NETFILTER && IP_NF_IPTABLES
210 + depends on NF_CONNTRACK && NF_CONNTRACK_MARK
211 + help
212 + Say Y here to allow transfer of a connmark stored DSCP into
213 + ipv4/v6 diffserv
214 +
215 + If unsure, say N.
216 +
217 + To compile this code as a module, choose M here: the
218 + module will be called act_ctinfo.
219 +
220 config NET_ACT_SKBMOD
221 tristate "skb data modification action"
222 depends on NET_CLS_ACT
223 --- a/net/sched/Makefile
224 +++ b/net/sched/Makefile
225 @@ -21,6 +21,7 @@ obj-$(CONFIG_NET_ACT_CSUM) += act_csum.o
226 obj-$(CONFIG_NET_ACT_VLAN) += act_vlan.o
227 obj-$(CONFIG_NET_ACT_BPF) += act_bpf.o
228 obj-$(CONFIG_NET_ACT_CONNMARK) += act_connmark.o
229 +obj-$(CONFIG_NET_ACT_CTINFO) += act_ctinfo.o
230 obj-$(CONFIG_NET_ACT_SKBMOD) += act_skbmod.o
231 obj-$(CONFIG_NET_ACT_IFE) += act_ife.o
232 obj-$(CONFIG_NET_IFE_SKBMARK) += act_meta_mark.o
233 --- /dev/null
234 +++ b/net/sched/act_ctinfo.c
235 @@ -0,0 +1,405 @@
236 +// SPDX-License-Identifier: GPL-2.0+
237 +/* net/sched/act_ctinfo.c netfilter ctinfo connmark actions
238 + *
239 + * Copyright (c) 2019 Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
240 + */
241 +
242 +#include <linux/module.h>
243 +#include <linux/init.h>
244 +#include <linux/kernel.h>
245 +#include <linux/skbuff.h>
246 +#include <linux/rtnetlink.h>
247 +#include <linux/pkt_cls.h>
248 +#include <linux/ip.h>
249 +#include <linux/ipv6.h>
250 +#include <net/netlink.h>
251 +#include <net/pkt_sched.h>
252 +#include <net/act_api.h>
253 +#include <net/pkt_cls.h>
254 +#include <uapi/linux/tc_act/tc_ctinfo.h>
255 +#include <net/tc_act/tc_ctinfo.h>
256 +
257 +#include <net/netfilter/nf_conntrack.h>
258 +#include <net/netfilter/nf_conntrack_core.h>
259 +#include <net/netfilter/nf_conntrack_ecache.h>
260 +#include <net/netfilter/nf_conntrack_zones.h>
261 +
262 +static struct tc_action_ops act_ctinfo_ops;
263 +static unsigned int ctinfo_net_id;
264 +
265 +static void tcf_ctinfo_dscp_set(struct nf_conn *ct, struct tcf_ctinfo *ca,
266 + struct tcf_ctinfo_params *cp,
267 + struct sk_buff *skb, int wlen, int proto)
268 +{
269 + u8 dscp,newdscp;
270 +
271 + newdscp = (((ct->mark & cp->dscpmask) >> cp->dscpmaskshift) << 2) &
272 + ~INET_ECN_MASK;
273 +
274 + /* mark contains DSCP so restore DSCP bits from ct->mark into diffserv */
275 + /* using overlimits stats to count how many DSCP updates */
276 + switch (proto) {
277 + case NFPROTO_IPV4:
278 + dscp = ipv4_get_dsfield(ip_hdr(skb)) & ~INET_ECN_MASK;
279 + if (dscp != newdscp) {
280 + if (likely(!skb_try_make_writable(skb, wlen))) {
281 + ipv4_change_dsfield(ip_hdr(skb),
282 + INET_ECN_MASK,
283 + newdscp);
284 + ca->stats_dscp_set++;
285 + } else {
286 + ca->stats_dscp_error++;
287 + }
288 + }
289 + break;
290 + case NFPROTO_IPV6:
291 + dscp = ipv6_get_dsfield(ipv6_hdr(skb)) & ~INET_ECN_MASK;
292 + if (dscp != newdscp) {
293 + if (likely(!skb_try_make_writable(skb, wlen))) {
294 + ipv6_change_dsfield(ipv6_hdr(skb),
295 + INET_ECN_MASK,
296 + newdscp);
297 + ca->stats_dscp_set++;
298 + } else {
299 + ca->stats_dscp_error++;
300 + }
301 + }
302 + break;
303 + default:
304 + break;
305 + }
306 +}
307 +
308 +static void tcf_ctinfo_cpmark_set(struct nf_conn *ct, struct tcf_ctinfo *ca,
309 + struct tcf_ctinfo_params *cp,
310 + struct sk_buff *skb)
311 +{
312 + ca->stats_cpmark_set++;
313 + skb->mark = ct->mark & cp->cpmarkmask;
314 +}
315 +
316 +static int tcf_ctinfo_act(struct sk_buff *skb, const struct tc_action *a,
317 + struct tcf_result *res)
318 +{
319 + const struct nf_conntrack_tuple_hash *thash = NULL;
320 + struct tcf_ctinfo *ca = to_ctinfo(a);
321 + struct nf_conntrack_tuple tuple;
322 + struct nf_conntrack_zone zone;
323 + enum ip_conntrack_info ctinfo;
324 + struct tcf_ctinfo_params *cp;
325 + struct nf_conn *ct;
326 + int proto, wlen;
327 + int action;
328 +
329 + cp = rcu_dereference_bh(ca->params);
330 +
331 + tcf_lastuse_update(&ca->tcf_tm);
332 + bstats_update(&ca->tcf_bstats, skb);
333 + action = READ_ONCE(ca->tcf_action);
334 +
335 + wlen = skb_network_offset(skb);
336 + if (tc_skb_protocol(skb) == htons(ETH_P_IP)) {
337 + wlen += sizeof(struct iphdr);
338 + if (!pskb_may_pull(skb, wlen))
339 + goto out;
340 +
341 + proto = NFPROTO_IPV4;
342 + } else if (tc_skb_protocol(skb) == htons(ETH_P_IPV6)) {
343 + wlen += sizeof(struct ipv6hdr);
344 + if (!pskb_may_pull(skb, wlen))
345 + goto out;
346 +
347 + proto = NFPROTO_IPV6;
348 + } else {
349 + goto out;
350 + }
351 +
352 + ct = nf_ct_get(skb, &ctinfo);
353 + if (!ct) { /* look harder, usually ingress */
354 + if (!nf_ct_get_tuplepr(skb, skb_network_offset(skb),
355 + proto, cp->net, &tuple))
356 + goto out;
357 + zone.id = cp->zone;
358 + zone.dir = NF_CT_DEFAULT_ZONE_DIR;
359 +
360 + thash = nf_conntrack_find_get(cp->net, &zone, &tuple);
361 + if (!thash)
362 + goto out;
363 +
364 + ct = nf_ct_tuplehash_to_ctrack(thash);
365 + }
366 +
367 + if (cp->mode & CTINFO_MODE_DSCP)
368 + if (!cp->dscpstatemask || (ct->mark & cp->dscpstatemask))
369 + tcf_ctinfo_dscp_set(ct, ca, cp, skb, wlen, proto);
370 +
371 + if (cp->mode & CTINFO_MODE_CPMARK)
372 + tcf_ctinfo_cpmark_set(ct, ca, cp, skb);
373 +
374 + if (thash)
375 + nf_ct_put(ct);
376 +out:
377 + return action;
378 +}
379 +
380 +static const struct nla_policy ctinfo_policy[TCA_CTINFO_MAX + 1] = {
381 + [TCA_CTINFO_ACT] = { .len = sizeof(struct
382 + tc_ctinfo) },
383 + [TCA_CTINFO_ZONE] = { .type = NLA_U16 },
384 + [TCA_CTINFO_PARMS_DSCP_MASK] = { .type = NLA_U32 },
385 + [TCA_CTINFO_PARMS_DSCP_STATEMASK] = { .type = NLA_U32 },
386 + [TCA_CTINFO_PARMS_CPMARK_MASK] = { .type = NLA_U32 },
387 +};
388 +
389 +static int tcf_ctinfo_init(struct net *net, struct nlattr *nla,
390 + struct nlattr *est, struct tc_action **a,
391 + int ovr, int bind)
392 +{
393 + struct tc_action_net *tn = net_generic(net, ctinfo_net_id);
394 + struct nlattr *tb[TCA_CTINFO_MAX + 1];
395 + struct tcf_ctinfo_params *cp_new;
396 +/* struct tcf_chain *goto_ch = NULL; */
397 + u32 dscpmask = 0, dscpstatemask;
398 + struct tc_ctinfo *actparm;
399 + struct tcf_ctinfo *ci;
400 + u8 dscpmaskshift;
401 + int ret = 0, err;
402 +
403 + if (!nla)
404 + return -EINVAL;
405 +
406 + err = nla_parse_nested(tb, TCA_CTINFO_MAX, nla, ctinfo_policy, NULL);
407 + if (err < 0)
408 + return err;
409 +
410 + if (!tb[TCA_CTINFO_ACT])
411 + return -EINVAL;
412 + actparm = nla_data(tb[TCA_CTINFO_ACT]);
413 +
414 + /* do some basic validation here before dynamically allocating things */
415 + /* that we would otherwise have to clean up. */
416 + if (tb[TCA_CTINFO_PARMS_DSCP_MASK]) {
417 + dscpmask = nla_get_u32(tb[TCA_CTINFO_PARMS_DSCP_MASK]);
418 + /* need contiguous 6 bit mask */
419 + dscpmaskshift = dscpmask ? __ffs(dscpmask) : 0;
420 + if ((~0 & (dscpmask >> dscpmaskshift)) != 0x3f)
421 + return -EINVAL;
422 + dscpstatemask = tb[TCA_CTINFO_PARMS_DSCP_STATEMASK] ?
423 + nla_get_u32(tb[TCA_CTINFO_PARMS_DSCP_STATEMASK]) : 0;
424 + /* mask & statemask must not overlap */
425 + if (dscpmask & dscpstatemask)
426 + return -EINVAL;
427 + }
428 + /* done the validation:now to the actual action allocation */
429 + err = tcf_idr_check(tn, actparm->index, a, bind);
430 + if (!err) {
431 + ret = tcf_idr_create(tn, actparm->index, est, a,
432 + &act_ctinfo_ops, bind, false);
433 + if (ret) {
434 + /* tcf_idr_cleanup(tn, actparm->index); */
435 + return ret;
436 + }
437 + ret = ACT_P_CREATED;
438 + } else if (err > 0) {
439 + if (bind) /* don't override defaults */
440 + return 0;
441 + if (!ovr) {
442 + tcf_idr_release(*a, bind);
443 + return -EEXIST;
444 + }
445 + } else {
446 + return err;
447 + }
448 +
449 +/* err = tcf_action_check_ctrlact(actparm->action, tp, &goto_ch, extack);
450 + if (err < 0)
451 + goto release_idr;
452 + */
453 +
454 + ci = to_ctinfo(*a);
455 +
456 + cp_new = kzalloc(sizeof(*cp_new), GFP_KERNEL);
457 + if (unlikely(!cp_new)) {
458 + err = -ENOMEM;
459 + goto put_chain;
460 + }
461 +
462 + cp_new->net = net;
463 + cp_new->zone = tb[TCA_CTINFO_ZONE] ?
464 + nla_get_u16(tb[TCA_CTINFO_ZONE]) : 0;
465 + if (dscpmask) {
466 + cp_new->dscpmask = dscpmask;
467 + cp_new->dscpmaskshift = dscpmaskshift;
468 + cp_new->dscpstatemask = dscpstatemask;
469 + cp_new->mode |= CTINFO_MODE_DSCP;
470 + }
471 +
472 + if (tb[TCA_CTINFO_PARMS_CPMARK_MASK]) {
473 + cp_new->cpmarkmask = nla_get_u32(tb[TCA_CTINFO_PARMS_CPMARK_MASK]);
474 + cp_new->mode |= CTINFO_MODE_CPMARK;
475 + }
476 +
477 + spin_lock_bh(&ci->tcf_lock);
478 +/* goto_ch = tcf_action_set_ctrlact(*a, actparm->action, goto_ch); */
479 + ci->tcf_action = actparm->action;
480 + rcu_swap_protected(ci->params, cp_new,
481 + lockdep_is_held(&ci->tcf_lock));
482 + spin_unlock_bh(&ci->tcf_lock);
483 +
484 +/* if (goto_ch)
485 + tcf_chain_put_by_act(goto_ch); */
486 + if (cp_new)
487 + kfree_rcu(cp_new, rcu);
488 +
489 + if (ret == ACT_P_CREATED)
490 + tcf_idr_insert(tn, *a);
491 +
492 + return ret;
493 +
494 +put_chain:
495 +/* if (goto_ch)
496 + tcf_chain_put_by_act(goto_ch); */
497 +/*release_idr:*/
498 + tcf_idr_release(*a, bind);
499 + return err;
500 +}
501 +
502 +static int tcf_ctinfo_dump(struct sk_buff *skb, struct tc_action *a,
503 + int bind, int ref)
504 +{
505 + struct tcf_ctinfo *ci = to_ctinfo(a);
506 + struct tc_ctinfo opt = {
507 + .index = ci->tcf_index,
508 + .refcnt = ci->tcf_refcnt - ref,
509 + .bindcnt = ci->tcf_bindcnt - bind,
510 + };
511 + unsigned char *b = skb_tail_pointer(skb);
512 + struct tcf_ctinfo_params *cp;
513 + struct tcf_t t;
514 +
515 + spin_lock_bh(&ci->tcf_lock);
516 + cp = rcu_dereference_protected(ci->params,
517 + lockdep_is_held(&ci->tcf_lock));
518 +
519 + tcf_tm_dump(&t, &ci->tcf_tm);
520 + if (nla_put_64bit(skb, TCA_CTINFO_TM, sizeof(t), &t, TCA_CTINFO_PAD))
521 + goto nla_put_failure;
522 +
523 + opt.action = ci->tcf_action;
524 + if (nla_put(skb, TCA_CTINFO_ACT, sizeof(opt), &opt))
525 + goto nla_put_failure;
526 +
527 + if (nla_put_u16(skb, TCA_CTINFO_ZONE, cp->zone))
528 + goto nla_put_failure;
529 +
530 + if (cp->mode & CTINFO_MODE_DSCP) {
531 + if (nla_put_u32(skb, TCA_CTINFO_PARMS_DSCP_MASK,
532 + cp->dscpmask))
533 + goto nla_put_failure;
534 + if (nla_put_u32(skb, TCA_CTINFO_PARMS_DSCP_STATEMASK,
535 + cp->dscpstatemask))
536 + goto nla_put_failure;
537 + }
538 +
539 + if (cp->mode & CTINFO_MODE_CPMARK) {
540 + if (nla_put_u32(skb, TCA_CTINFO_PARMS_CPMARK_MASK,
541 + cp->cpmarkmask))
542 + goto nla_put_failure;
543 + }
544 +
545 + if (nla_put_u64_64bit(skb, TCA_CTINFO_STATS_DSCP_SET,
546 + ci->stats_dscp_set, TCA_CTINFO_PAD))
547 + goto nla_put_failure;
548 +
549 + if (nla_put_u64_64bit(skb, TCA_CTINFO_STATS_DSCP_ERROR,
550 + ci->stats_dscp_error, TCA_CTINFO_PAD))
551 + goto nla_put_failure;
552 +
553 + if (nla_put_u64_64bit(skb, TCA_CTINFO_STATS_CPMARK_SET,
554 + ci->stats_cpmark_set, TCA_CTINFO_PAD))
555 + goto nla_put_failure;
556 +
557 + spin_unlock_bh(&ci->tcf_lock);
558 + return skb->len;
559 +
560 +nla_put_failure:
561 + spin_unlock_bh(&ci->tcf_lock);
562 + nlmsg_trim(skb, b);
563 + return -1;
564 +}
565 +
566 +static int tcf_ctinfo_walker(struct net *net, struct sk_buff *skb,
567 + struct netlink_callback *cb, int type,
568 + const struct tc_action_ops *ops)
569 +{
570 + struct tc_action_net *tn = net_generic(net, ctinfo_net_id);
571 +
572 + return tcf_generic_walker(tn, skb, cb, type, ops);
573 +}
574 +
575 +static int tcf_ctinfo_search(struct net *net, struct tc_action **a, u32 index)
576 +{
577 + struct tc_action_net *tn = net_generic(net, ctinfo_net_id);
578 +
579 + return tcf_idr_search(tn, a, index);
580 +}
581 +
582 +static void tcf_ctinfo_cleanup(struct tc_action *a, int bind)
583 +{
584 + struct tcf_ctinfo *ci = to_ctinfo(a);
585 + struct tcf_ctinfo_params *cp;
586 +
587 + cp = rcu_dereference_protected(ci->params, 1);
588 + if (cp)
589 + kfree_rcu(cp, rcu);
590 +}
591 +
592 +static struct tc_action_ops act_ctinfo_ops = {
593 + .kind = "ctinfo",
594 + .type = TCA_ID_CTINFO,
595 + .owner = THIS_MODULE,
596 + .act = tcf_ctinfo_act,
597 + .dump = tcf_ctinfo_dump,
598 + .init = tcf_ctinfo_init,
599 + .cleanup= tcf_ctinfo_cleanup,
600 + .walk = tcf_ctinfo_walker,
601 + .lookup = tcf_ctinfo_search,
602 + .size = sizeof(struct tcf_ctinfo),
603 +};
604 +
605 +static __net_init int ctinfo_init_net(struct net *net)
606 +{
607 + struct tc_action_net *tn = net_generic(net, ctinfo_net_id);
608 +
609 + return tc_action_net_init(net, tn, &act_ctinfo_ops);
610 +}
611 +
612 +static void __net_exit ctinfo_exit_net(struct net *net)
613 +{
614 + struct tc_action_net *tn = net_generic(net, ctinfo_net_id);
615 +
616 + tc_action_net_exit(tn);
617 +}
618 +
619 +static struct pernet_operations ctinfo_net_ops = {
620 + .init = ctinfo_init_net,
621 + .exit = ctinfo_exit_net,
622 + .id = &ctinfo_net_id,
623 + .size = sizeof(struct tc_action_net),
624 +};
625 +
626 +static int __init ctinfo_init_module(void)
627 +{
628 + return tcf_register_action(&act_ctinfo_ops, &ctinfo_net_ops);
629 +}
630 +
631 +static void __exit ctinfo_cleanup_module(void)
632 +{
633 + tcf_unregister_action(&act_ctinfo_ops, &ctinfo_net_ops);
634 +}
635 +
636 +module_init(ctinfo_init_module);
637 +module_exit(ctinfo_cleanup_module);
638 +MODULE_AUTHOR("Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>");
639 +MODULE_DESCRIPTION("Conntrack mark to DSCP restoring");
640 +MODULE_LICENSE("GPL");