blob: b125b2be4467a46c57208c21385a41bf722f6fc4 [file] [log] [blame]
Thomas Gleixner9952f692019-05-28 10:10:04 -07001// SPDX-License-Identifier: GPL-2.0-only
Alexander Duyckca9b0e22008-09-12 16:30:20 -07002/*
3 * Copyright (c) 2008, Intel Corporation.
4 *
Alexander Duyckca9b0e22008-09-12 16:30:20 -07005 * Author: Alexander Duyck <alexander.h.duyck@intel.com>
6 */
7
8#include <linux/module.h>
9#include <linux/init.h>
10#include <linux/kernel.h>
11#include <linux/skbuff.h>
12#include <linux/rtnetlink.h>
13#include <net/netlink.h>
14#include <net/pkt_sched.h>
Qiaobin Fue7e37282018-07-01 15:16:27 -040015#include <net/ip.h>
16#include <net/ipv6.h>
17#include <net/dsfield.h>
Davide Carattiec7727b2019-03-20 15:00:11 +010018#include <net/pkt_cls.h>
Alexander Duyckca9b0e22008-09-12 16:30:20 -070019
20#include <linux/tc_act/tc_skbedit.h>
21#include <net/tc_act/tc_skbedit.h>
22
Alexey Dobriyanc7d03a02016-11-17 04:58:21 +030023static unsigned int skbedit_net_id;
WANG Conga85a9702016-07-25 16:09:41 -070024static struct tc_action_ops act_skbedit_ops;
WANG Congddf97cc2016-02-22 15:57:53 -080025
Jamal Hadi Salim45da1da2018-08-12 09:34:58 -040026static int tcf_skbedit_act(struct sk_buff *skb, const struct tc_action *a,
27 struct tcf_result *res)
Alexander Duyckca9b0e22008-09-12 16:30:20 -070028{
WANG Conga85a9702016-07-25 16:09:41 -070029 struct tcf_skbedit *d = to_skbedit(a);
Davide Carattic749cdd2018-07-11 16:04:50 +020030 struct tcf_skbedit_params *params;
31 int action;
Alexander Duyckca9b0e22008-09-12 16:30:20 -070032
Jamal Hadi Salim9c4a4e42016-06-06 06:32:53 -040033 tcf_lastuse_update(&d->tcf_tm);
Davide Caratti6f3dfb02018-07-11 16:04:49 +020034 bstats_cpu_update(this_cpu_ptr(d->common.cpu_bstats), skb);
Alexander Duyckca9b0e22008-09-12 16:30:20 -070035
Paolo Abeni7fd4b282018-07-30 14:30:43 +020036 params = rcu_dereference_bh(d->params);
Davide Carattic749cdd2018-07-11 16:04:50 +020037 action = READ_ONCE(d->tcf_action);
38
39 if (params->flags & SKBEDIT_F_PRIORITY)
40 skb->priority = params->priority;
41 if (params->flags & SKBEDIT_F_INHERITDSFIELD) {
Qiaobin Fue7e37282018-07-01 15:16:27 -040042 int wlen = skb_network_offset(skb);
43
44 switch (tc_skb_protocol(skb)) {
45 case htons(ETH_P_IP):
46 wlen += sizeof(struct iphdr);
47 if (!pskb_may_pull(skb, wlen))
48 goto err;
49 skb->priority = ipv4_get_dsfield(ip_hdr(skb)) >> 2;
50 break;
51
52 case htons(ETH_P_IPV6):
53 wlen += sizeof(struct ipv6hdr);
54 if (!pskb_may_pull(skb, wlen))
55 goto err;
56 skb->priority = ipv6_get_dsfield(ipv6_hdr(skb)) >> 2;
57 break;
58 }
59 }
Davide Carattic749cdd2018-07-11 16:04:50 +020060 if (params->flags & SKBEDIT_F_QUEUE_MAPPING &&
61 skb->dev->real_num_tx_queues > params->queue_mapping)
62 skb_set_queue_mapping(skb, params->queue_mapping);
63 if (params->flags & SKBEDIT_F_MARK) {
64 skb->mark &= ~params->mask;
65 skb->mark |= params->mark & params->mask;
Antonio Quartulli4fe77d82016-10-24 20:32:57 +080066 }
Davide Carattic749cdd2018-07-11 16:04:50 +020067 if (params->flags & SKBEDIT_F_PTYPE)
68 skb->pkt_type = params->ptype;
Davide Carattic749cdd2018-07-11 16:04:50 +020069 return action;
Paolo Abeni7fd4b282018-07-30 14:30:43 +020070
Qiaobin Fue7e37282018-07-01 15:16:27 -040071err:
Davide Caratti6f3dfb02018-07-11 16:04:49 +020072 qstats_drop_inc(this_cpu_ptr(d->common.cpu_qstats));
Paolo Abeni7fd4b282018-07-30 14:30:43 +020073 return TC_ACT_SHOT;
Alexander Duyckca9b0e22008-09-12 16:30:20 -070074}
75
Petr Machata837cb172020-03-26 22:45:55 +020076static void tcf_skbedit_stats_update(struct tc_action *a, u64 bytes,
77 u32 packets, u64 lastuse, bool hw)
78{
79 struct tcf_skbedit *d = to_skbedit(a);
80 struct tcf_t *tm = &d->tcf_tm;
81
82 tcf_action_update_stats(a, bytes, packets, false, hw);
83 tm->lastuse = max_t(u64, tm->lastuse, lastuse);
84}
85
Alexander Duyckca9b0e22008-09-12 16:30:20 -070086static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = {
87 [TCA_SKBEDIT_PARMS] = { .len = sizeof(struct tc_skbedit) },
88 [TCA_SKBEDIT_PRIORITY] = { .len = sizeof(u32) },
89 [TCA_SKBEDIT_QUEUE_MAPPING] = { .len = sizeof(u16) },
jamal1c55d622009-10-15 03:09:18 +000090 [TCA_SKBEDIT_MARK] = { .len = sizeof(u32) },
Jamal Hadi Salimff202ee2016-07-02 06:43:15 -040091 [TCA_SKBEDIT_PTYPE] = { .len = sizeof(u16) },
Antonio Quartulli4fe77d82016-10-24 20:32:57 +080092 [TCA_SKBEDIT_MASK] = { .len = sizeof(u32) },
Qiaobin Fue7e37282018-07-01 15:16:27 -040093 [TCA_SKBEDIT_FLAGS] = { .len = sizeof(u64) },
Alexander Duyckca9b0e22008-09-12 16:30:20 -070094};
95
Benjamin LaHaisec1b52732013-01-14 05:15:39 +000096static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
WANG Conga85a9702016-07-25 16:09:41 -070097 struct nlattr *est, struct tc_action **a,
Vlad Buslov789871b2018-07-05 17:24:25 +030098 int ovr, int bind, bool rtnl_held,
Vlad Buslovabbb0d32019-10-30 16:09:05 +020099 struct tcf_proto *tp, u32 act_flags,
Vlad Buslov789871b2018-07-05 17:24:25 +0300100 struct netlink_ext_ack *extack)
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700101{
WANG Congddf97cc2016-02-22 15:57:53 -0800102 struct tc_action_net *tn = net_generic(net, skbedit_net_id);
Vlad Buslov6d7a8df2018-09-03 10:07:15 +0300103 struct tcf_skbedit_params *params_new;
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700104 struct nlattr *tb[TCA_SKBEDIT_MAX + 1];
Davide Carattiec7727b2019-03-20 15:00:11 +0100105 struct tcf_chain *goto_ch = NULL;
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700106 struct tc_skbedit *parm;
107 struct tcf_skbedit *d;
Antonio Quartulli4fe77d82016-10-24 20:32:57 +0800108 u32 flags = 0, *priority = NULL, *mark = NULL, *mask = NULL;
Jamal Hadi Salimff202ee2016-07-02 06:43:15 -0400109 u16 *queue_mapping = NULL, *ptype = NULL;
WANG Congb2313072016-06-13 13:46:28 -0700110 bool exists = false;
111 int ret = 0, err;
Dmytro Linkin7be8ef22019-08-01 13:02:51 +0000112 u32 index;
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700113
114 if (nla == NULL)
115 return -EINVAL;
116
Johannes Berg8cb08172019-04-26 14:07:28 +0200117 err = nla_parse_nested_deprecated(tb, TCA_SKBEDIT_MAX, nla,
118 skbedit_policy, NULL);
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700119 if (err < 0)
120 return err;
121
122 if (tb[TCA_SKBEDIT_PARMS] == NULL)
123 return -EINVAL;
124
125 if (tb[TCA_SKBEDIT_PRIORITY] != NULL) {
126 flags |= SKBEDIT_F_PRIORITY;
127 priority = nla_data(tb[TCA_SKBEDIT_PRIORITY]);
128 }
129
130 if (tb[TCA_SKBEDIT_QUEUE_MAPPING] != NULL) {
131 flags |= SKBEDIT_F_QUEUE_MAPPING;
132 queue_mapping = nla_data(tb[TCA_SKBEDIT_QUEUE_MAPPING]);
133 }
jamal1c55d622009-10-15 03:09:18 +0000134
Jamal Hadi Salimff202ee2016-07-02 06:43:15 -0400135 if (tb[TCA_SKBEDIT_PTYPE] != NULL) {
136 ptype = nla_data(tb[TCA_SKBEDIT_PTYPE]);
137 if (!skb_pkt_type_ok(*ptype))
138 return -EINVAL;
139 flags |= SKBEDIT_F_PTYPE;
140 }
141
jamal1c55d622009-10-15 03:09:18 +0000142 if (tb[TCA_SKBEDIT_MARK] != NULL) {
143 flags |= SKBEDIT_F_MARK;
144 mark = nla_data(tb[TCA_SKBEDIT_MARK]);
145 }
146
Antonio Quartulli4fe77d82016-10-24 20:32:57 +0800147 if (tb[TCA_SKBEDIT_MASK] != NULL) {
148 flags |= SKBEDIT_F_MASK;
149 mask = nla_data(tb[TCA_SKBEDIT_MASK]);
150 }
151
Qiaobin Fue7e37282018-07-01 15:16:27 -0400152 if (tb[TCA_SKBEDIT_FLAGS] != NULL) {
153 u64 *pure_flags = nla_data(tb[TCA_SKBEDIT_FLAGS]);
154
155 if (*pure_flags & SKBEDIT_F_INHERITDSFIELD)
156 flags |= SKBEDIT_F_INHERITDSFIELD;
157 }
158
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700159 parm = nla_data(tb[TCA_SKBEDIT_PARMS]);
Dmytro Linkin7be8ef22019-08-01 13:02:51 +0000160 index = parm->index;
161 err = tcf_idr_check_alloc(tn, &index, a, bind);
Vlad Buslov0190c1d2018-07-05 17:24:32 +0300162 if (err < 0)
163 return err;
164 exists = err;
Jamal Hadi Salim5e1567a2016-05-10 16:49:30 -0400165 if (exists && bind)
166 return 0;
167
168 if (!flags) {
Roman Mashakaf5d0182018-05-11 10:55:09 -0400169 if (exists)
170 tcf_idr_release(*a, bind);
Vlad Buslov0190c1d2018-07-05 17:24:32 +0300171 else
Dmytro Linkin7be8ef22019-08-01 13:02:51 +0000172 tcf_idr_cleanup(tn, index);
Jamal Hadi Salim5e1567a2016-05-10 16:49:30 -0400173 return -EINVAL;
174 }
175
176 if (!exists) {
Dmytro Linkin7be8ef22019-08-01 13:02:51 +0000177 ret = tcf_idr_create(tn, index, est, a,
Vlad Buslove3822672019-10-30 16:09:06 +0200178 &act_skbedit_ops, bind, true, 0);
Vlad Buslov0190c1d2018-07-05 17:24:32 +0300179 if (ret) {
Dmytro Linkin7be8ef22019-08-01 13:02:51 +0000180 tcf_idr_cleanup(tn, index);
WANG Cong86062032014-02-11 17:07:31 -0800181 return ret;
Vlad Buslov0190c1d2018-07-05 17:24:32 +0300182 }
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700183
WANG Conga85a9702016-07-25 16:09:41 -0700184 d = to_skbedit(*a);
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700185 ret = ACT_P_CREATED;
186 } else {
WANG Conga85a9702016-07-25 16:09:41 -0700187 d = to_skbedit(*a);
Vlad Buslov4e8ddd72018-07-05 17:24:30 +0300188 if (!ovr) {
189 tcf_idr_release(*a, bind);
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700190 return -EEXIST;
Vlad Buslov4e8ddd72018-07-05 17:24:30 +0300191 }
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700192 }
Davide Carattiec7727b2019-03-20 15:00:11 +0100193 err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
194 if (err < 0)
195 goto release_idr;
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700196
Davide Carattic749cdd2018-07-11 16:04:50 +0200197 params_new = kzalloc(sizeof(*params_new), GFP_KERNEL);
198 if (unlikely(!params_new)) {
Davide Carattiec7727b2019-03-20 15:00:11 +0100199 err = -ENOMEM;
200 goto put_chain;
Davide Carattic749cdd2018-07-11 16:04:50 +0200201 }
202
203 params_new->flags = flags;
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700204 if (flags & SKBEDIT_F_PRIORITY)
Davide Carattic749cdd2018-07-11 16:04:50 +0200205 params_new->priority = *priority;
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700206 if (flags & SKBEDIT_F_QUEUE_MAPPING)
Davide Carattic749cdd2018-07-11 16:04:50 +0200207 params_new->queue_mapping = *queue_mapping;
jamal1c55d622009-10-15 03:09:18 +0000208 if (flags & SKBEDIT_F_MARK)
Davide Carattic749cdd2018-07-11 16:04:50 +0200209 params_new->mark = *mark;
Jamal Hadi Salimff202ee2016-07-02 06:43:15 -0400210 if (flags & SKBEDIT_F_PTYPE)
Davide Carattic749cdd2018-07-11 16:04:50 +0200211 params_new->ptype = *ptype;
Antonio Quartulli4fe77d82016-10-24 20:32:57 +0800212 /* default behaviour is to use all the bits */
Davide Carattic749cdd2018-07-11 16:04:50 +0200213 params_new->mask = 0xffffffff;
Antonio Quartulli4fe77d82016-10-24 20:32:57 +0800214 if (flags & SKBEDIT_F_MASK)
Davide Carattic749cdd2018-07-11 16:04:50 +0200215 params_new->mask = *mask;
jamal1c55d622009-10-15 03:09:18 +0000216
Vlad Buslov6d7a8df2018-09-03 10:07:15 +0300217 spin_lock_bh(&d->tcf_lock);
Davide Carattiec7727b2019-03-20 15:00:11 +0100218 goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
Paul E. McKenney445d3742019-09-23 16:09:18 -0700219 params_new = rcu_replace_pointer(d->params, params_new,
220 lockdep_is_held(&d->tcf_lock));
Vlad Buslov6d7a8df2018-09-03 10:07:15 +0300221 spin_unlock_bh(&d->tcf_lock);
222 if (params_new)
223 kfree_rcu(params_new, rcu);
Davide Carattiec7727b2019-03-20 15:00:11 +0100224 if (goto_ch)
225 tcf_chain_put_by_act(goto_ch);
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700226
227 if (ret == ACT_P_CREATED)
Chris Mi65a206c2017-08-30 02:31:59 -0400228 tcf_idr_insert(tn, *a);
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700229 return ret;
Davide Carattiec7727b2019-03-20 15:00:11 +0100230put_chain:
231 if (goto_ch)
232 tcf_chain_put_by_act(goto_ch);
233release_idr:
234 tcf_idr_release(*a, bind);
235 return err;
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700236}
237
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000238static int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a,
239 int bind, int ref)
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700240{
241 unsigned char *b = skb_tail_pointer(skb);
WANG Conga85a9702016-07-25 16:09:41 -0700242 struct tcf_skbedit *d = to_skbedit(a);
Davide Carattic749cdd2018-07-11 16:04:50 +0200243 struct tcf_skbedit_params *params;
Eric Dumazet1c40be12010-08-16 20:04:22 +0000244 struct tc_skbedit opt = {
245 .index = d->tcf_index,
Vlad Buslov036bb442018-07-05 17:24:24 +0300246 .refcnt = refcount_read(&d->tcf_refcnt) - ref,
247 .bindcnt = atomic_read(&d->tcf_bindcnt) - bind,
Eric Dumazet1c40be12010-08-16 20:04:22 +0000248 };
Qiaobin Fue7e37282018-07-01 15:16:27 -0400249 u64 pure_flags = 0;
Davide Carattic749cdd2018-07-11 16:04:50 +0200250 struct tcf_t t;
251
Vlad Buslov6d7a8df2018-09-03 10:07:15 +0300252 spin_lock_bh(&d->tcf_lock);
253 params = rcu_dereference_protected(d->params,
254 lockdep_is_held(&d->tcf_lock));
255 opt.action = d->tcf_action;
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700256
David S. Miller1b34ec42012-03-29 05:11:39 -0400257 if (nla_put(skb, TCA_SKBEDIT_PARMS, sizeof(opt), &opt))
258 goto nla_put_failure;
Davide Carattic749cdd2018-07-11 16:04:50 +0200259 if ((params->flags & SKBEDIT_F_PRIORITY) &&
260 nla_put_u32(skb, TCA_SKBEDIT_PRIORITY, params->priority))
David S. Miller1b34ec42012-03-29 05:11:39 -0400261 goto nla_put_failure;
Davide Carattic749cdd2018-07-11 16:04:50 +0200262 if ((params->flags & SKBEDIT_F_QUEUE_MAPPING) &&
263 nla_put_u16(skb, TCA_SKBEDIT_QUEUE_MAPPING, params->queue_mapping))
David S. Miller1b34ec42012-03-29 05:11:39 -0400264 goto nla_put_failure;
Davide Carattic749cdd2018-07-11 16:04:50 +0200265 if ((params->flags & SKBEDIT_F_MARK) &&
266 nla_put_u32(skb, TCA_SKBEDIT_MARK, params->mark))
David S. Miller1b34ec42012-03-29 05:11:39 -0400267 goto nla_put_failure;
Davide Carattic749cdd2018-07-11 16:04:50 +0200268 if ((params->flags & SKBEDIT_F_PTYPE) &&
269 nla_put_u16(skb, TCA_SKBEDIT_PTYPE, params->ptype))
Jamal Hadi Salimff202ee2016-07-02 06:43:15 -0400270 goto nla_put_failure;
Davide Carattic749cdd2018-07-11 16:04:50 +0200271 if ((params->flags & SKBEDIT_F_MASK) &&
272 nla_put_u32(skb, TCA_SKBEDIT_MASK, params->mask))
Antonio Quartulli4fe77d82016-10-24 20:32:57 +0800273 goto nla_put_failure;
Davide Carattic749cdd2018-07-11 16:04:50 +0200274 if (params->flags & SKBEDIT_F_INHERITDSFIELD)
Qiaobin Fue7e37282018-07-01 15:16:27 -0400275 pure_flags |= SKBEDIT_F_INHERITDSFIELD;
276 if (pure_flags != 0 &&
277 nla_put(skb, TCA_SKBEDIT_FLAGS, sizeof(pure_flags), &pure_flags))
278 goto nla_put_failure;
Jamal Hadi Salim48d8ee12016-06-06 06:32:55 -0400279
280 tcf_tm_dump(&t, &d->tcf_tm);
Nicolas Dichtel98545182016-04-26 10:06:18 +0200281 if (nla_put_64bit(skb, TCA_SKBEDIT_TM, sizeof(t), &t, TCA_SKBEDIT_PAD))
David S. Miller1b34ec42012-03-29 05:11:39 -0400282 goto nla_put_failure;
Vlad Buslov6d7a8df2018-09-03 10:07:15 +0300283 spin_unlock_bh(&d->tcf_lock);
284
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700285 return skb->len;
286
287nla_put_failure:
Vlad Buslov6d7a8df2018-09-03 10:07:15 +0300288 spin_unlock_bh(&d->tcf_lock);
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700289 nlmsg_trim(skb, b);
290 return -1;
291}
292
Davide Carattic749cdd2018-07-11 16:04:50 +0200293static void tcf_skbedit_cleanup(struct tc_action *a)
294{
295 struct tcf_skbedit *d = to_skbedit(a);
296 struct tcf_skbedit_params *params;
297
298 params = rcu_dereference_protected(d->params, 1);
299 if (params)
300 kfree_rcu(params, rcu);
301}
302
WANG Congddf97cc2016-02-22 15:57:53 -0800303static int tcf_skbedit_walker(struct net *net, struct sk_buff *skb,
304 struct netlink_callback *cb, int type,
Alexander Aring41780102018-02-15 10:54:58 -0500305 const struct tc_action_ops *ops,
306 struct netlink_ext_ack *extack)
WANG Congddf97cc2016-02-22 15:57:53 -0800307{
308 struct tc_action_net *tn = net_generic(net, skbedit_net_id);
309
Alexander Aringb3620142018-02-15 10:54:59 -0500310 return tcf_generic_walker(tn, skb, cb, type, ops, extack);
WANG Congddf97cc2016-02-22 15:57:53 -0800311}
312
Cong Wangf061b482018-08-29 10:15:35 -0700313static int tcf_skbedit_search(struct net *net, struct tc_action **a, u32 index)
WANG Congddf97cc2016-02-22 15:57:53 -0800314{
315 struct tc_action_net *tn = net_generic(net, skbedit_net_id);
316
Chris Mi65a206c2017-08-30 02:31:59 -0400317 return tcf_idr_search(tn, a, index);
WANG Congddf97cc2016-02-22 15:57:53 -0800318}
319
Roman Mashake1fea322019-08-07 15:57:28 -0400320static size_t tcf_skbedit_get_fill_size(const struct tc_action *act)
321{
322 return nla_total_size(sizeof(struct tc_skbedit))
323 + nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_PRIORITY */
324 + nla_total_size(sizeof(u16)) /* TCA_SKBEDIT_QUEUE_MAPPING */
325 + nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_MARK */
326 + nla_total_size(sizeof(u16)) /* TCA_SKBEDIT_PTYPE */
327 + nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_MASK */
328 + nla_total_size_64bit(sizeof(u64)); /* TCA_SKBEDIT_FLAGS */
329}
330
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700331static struct tc_action_ops act_skbedit_ops = {
332 .kind = "skbedit",
Eli Coheneddd2cf2019-02-10 14:25:00 +0200333 .id = TCA_ID_SKBEDIT,
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700334 .owner = THIS_MODULE,
Jamal Hadi Salim45da1da2018-08-12 09:34:58 -0400335 .act = tcf_skbedit_act,
Petr Machata837cb172020-03-26 22:45:55 +0200336 .stats_update = tcf_skbedit_stats_update,
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700337 .dump = tcf_skbedit_dump,
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700338 .init = tcf_skbedit_init,
Davide Carattic749cdd2018-07-11 16:04:50 +0200339 .cleanup = tcf_skbedit_cleanup,
WANG Congddf97cc2016-02-22 15:57:53 -0800340 .walk = tcf_skbedit_walker,
Roman Mashake1fea322019-08-07 15:57:28 -0400341 .get_fill_size = tcf_skbedit_get_fill_size,
WANG Congddf97cc2016-02-22 15:57:53 -0800342 .lookup = tcf_skbedit_search,
WANG Conga85a9702016-07-25 16:09:41 -0700343 .size = sizeof(struct tcf_skbedit),
WANG Congddf97cc2016-02-22 15:57:53 -0800344};
345
346static __net_init int skbedit_init_net(struct net *net)
347{
348 struct tc_action_net *tn = net_generic(net, skbedit_net_id);
349
Cong Wang981471b2019-08-25 10:01:32 -0700350 return tc_action_net_init(net, tn, &act_skbedit_ops);
WANG Congddf97cc2016-02-22 15:57:53 -0800351}
352
Cong Wang039af9c2017-12-11 15:35:03 -0800353static void __net_exit skbedit_exit_net(struct list_head *net_list)
WANG Congddf97cc2016-02-22 15:57:53 -0800354{
Cong Wang039af9c2017-12-11 15:35:03 -0800355 tc_action_net_exit(net_list, skbedit_net_id);
WANG Congddf97cc2016-02-22 15:57:53 -0800356}
357
358static struct pernet_operations skbedit_net_ops = {
359 .init = skbedit_init_net,
Cong Wang039af9c2017-12-11 15:35:03 -0800360 .exit_batch = skbedit_exit_net,
WANG Congddf97cc2016-02-22 15:57:53 -0800361 .id = &skbedit_net_id,
362 .size = sizeof(struct tc_action_net),
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700363};
364
365MODULE_AUTHOR("Alexander Duyck, <alexander.h.duyck@intel.com>");
366MODULE_DESCRIPTION("SKB Editing");
367MODULE_LICENSE("GPL");
368
369static int __init skbedit_init_module(void)
370{
WANG Congddf97cc2016-02-22 15:57:53 -0800371 return tcf_register_action(&act_skbedit_ops, &skbedit_net_ops);
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700372}
373
374static void __exit skbedit_cleanup_module(void)
375{
WANG Congddf97cc2016-02-22 15:57:53 -0800376 tcf_unregister_action(&act_skbedit_ops, &skbedit_net_ops);
Alexander Duyckca9b0e22008-09-12 16:30:20 -0700377}
378
379module_init(skbedit_init_module);
380module_exit(skbedit_cleanup_module);