xref: /openbmc/linux/net/sched/act_skbedit.c (revision e1fea322fc6d4075254ca9c5f2afdace0281da2a)
19952f691SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2ca9b0e27SAlexander Duyck /*
3ca9b0e27SAlexander Duyck  * Copyright (c) 2008, Intel Corporation.
4ca9b0e27SAlexander Duyck  *
5ca9b0e27SAlexander Duyck  * Author: Alexander Duyck <alexander.h.duyck@intel.com>
6ca9b0e27SAlexander Duyck  */
7ca9b0e27SAlexander Duyck 
8ca9b0e27SAlexander Duyck #include <linux/module.h>
9ca9b0e27SAlexander Duyck #include <linux/init.h>
10ca9b0e27SAlexander Duyck #include <linux/kernel.h>
11ca9b0e27SAlexander Duyck #include <linux/skbuff.h>
12ca9b0e27SAlexander Duyck #include <linux/rtnetlink.h>
13ca9b0e27SAlexander Duyck #include <net/netlink.h>
14ca9b0e27SAlexander Duyck #include <net/pkt_sched.h>
15e7e3728bSQiaobin Fu #include <net/ip.h>
16e7e3728bSQiaobin Fu #include <net/ipv6.h>
17e7e3728bSQiaobin Fu #include <net/dsfield.h>
18ec7727bbSDavide Caratti #include <net/pkt_cls.h>
19ca9b0e27SAlexander Duyck 
20ca9b0e27SAlexander Duyck #include <linux/tc_act/tc_skbedit.h>
21ca9b0e27SAlexander Duyck #include <net/tc_act/tc_skbedit.h>
22ca9b0e27SAlexander Duyck 
23c7d03a00SAlexey Dobriyan static unsigned int skbedit_net_id;
24a85a970aSWANG Cong static struct tc_action_ops act_skbedit_ops;
25ddf97ccdSWANG Cong 
2645da1dacSJamal Hadi Salim static int tcf_skbedit_act(struct sk_buff *skb, const struct tc_action *a,
27ca9b0e27SAlexander Duyck 			   struct tcf_result *res)
28ca9b0e27SAlexander Duyck {
29a85a970aSWANG Cong 	struct tcf_skbedit *d = to_skbedit(a);
30c749cddaSDavide Caratti 	struct tcf_skbedit_params *params;
31c749cddaSDavide Caratti 	int action;
32ca9b0e27SAlexander Duyck 
339c4a4e48SJamal Hadi Salim 	tcf_lastuse_update(&d->tcf_tm);
346f3dfb0dSDavide Caratti 	bstats_cpu_update(this_cpu_ptr(d->common.cpu_bstats), skb);
35ca9b0e27SAlexander Duyck 
367fd4b288SPaolo Abeni 	params = rcu_dereference_bh(d->params);
37c749cddaSDavide Caratti 	action = READ_ONCE(d->tcf_action);
38c749cddaSDavide Caratti 
39c749cddaSDavide Caratti 	if (params->flags & SKBEDIT_F_PRIORITY)
40c749cddaSDavide Caratti 		skb->priority = params->priority;
41c749cddaSDavide Caratti 	if (params->flags & SKBEDIT_F_INHERITDSFIELD) {
42e7e3728bSQiaobin Fu 		int wlen = skb_network_offset(skb);
43e7e3728bSQiaobin Fu 
44e7e3728bSQiaobin Fu 		switch (tc_skb_protocol(skb)) {
45e7e3728bSQiaobin Fu 		case htons(ETH_P_IP):
46e7e3728bSQiaobin Fu 			wlen += sizeof(struct iphdr);
47e7e3728bSQiaobin Fu 			if (!pskb_may_pull(skb, wlen))
48e7e3728bSQiaobin Fu 				goto err;
49e7e3728bSQiaobin Fu 			skb->priority = ipv4_get_dsfield(ip_hdr(skb)) >> 2;
50e7e3728bSQiaobin Fu 			break;
51e7e3728bSQiaobin Fu 
52e7e3728bSQiaobin Fu 		case htons(ETH_P_IPV6):
53e7e3728bSQiaobin Fu 			wlen += sizeof(struct ipv6hdr);
54e7e3728bSQiaobin Fu 			if (!pskb_may_pull(skb, wlen))
55e7e3728bSQiaobin Fu 				goto err;
56e7e3728bSQiaobin Fu 			skb->priority = ipv6_get_dsfield(ipv6_hdr(skb)) >> 2;
57e7e3728bSQiaobin Fu 			break;
58e7e3728bSQiaobin Fu 		}
59e7e3728bSQiaobin Fu 	}
60c749cddaSDavide Caratti 	if (params->flags & SKBEDIT_F_QUEUE_MAPPING &&
61c749cddaSDavide Caratti 	    skb->dev->real_num_tx_queues > params->queue_mapping)
62c749cddaSDavide Caratti 		skb_set_queue_mapping(skb, params->queue_mapping);
63c749cddaSDavide Caratti 	if (params->flags & SKBEDIT_F_MARK) {
64c749cddaSDavide Caratti 		skb->mark &= ~params->mask;
65c749cddaSDavide Caratti 		skb->mark |= params->mark & params->mask;
664fe77d82SAntonio Quartulli 	}
67c749cddaSDavide Caratti 	if (params->flags & SKBEDIT_F_PTYPE)
68c749cddaSDavide Caratti 		skb->pkt_type = params->ptype;
69c749cddaSDavide Caratti 	return action;
707fd4b288SPaolo Abeni 
71e7e3728bSQiaobin Fu err:
726f3dfb0dSDavide Caratti 	qstats_drop_inc(this_cpu_ptr(d->common.cpu_qstats));
737fd4b288SPaolo Abeni 	return TC_ACT_SHOT;
74ca9b0e27SAlexander Duyck }
75ca9b0e27SAlexander Duyck 
76ca9b0e27SAlexander Duyck static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = {
77ca9b0e27SAlexander Duyck 	[TCA_SKBEDIT_PARMS]		= { .len = sizeof(struct tc_skbedit) },
78ca9b0e27SAlexander Duyck 	[TCA_SKBEDIT_PRIORITY]		= { .len = sizeof(u32) },
79ca9b0e27SAlexander Duyck 	[TCA_SKBEDIT_QUEUE_MAPPING]	= { .len = sizeof(u16) },
801c55d62eSjamal 	[TCA_SKBEDIT_MARK]		= { .len = sizeof(u32) },
81ff202ee1SJamal Hadi Salim 	[TCA_SKBEDIT_PTYPE]		= { .len = sizeof(u16) },
824fe77d82SAntonio Quartulli 	[TCA_SKBEDIT_MASK]		= { .len = sizeof(u32) },
83e7e3728bSQiaobin Fu 	[TCA_SKBEDIT_FLAGS]		= { .len = sizeof(u64) },
84ca9b0e27SAlexander Duyck };
85ca9b0e27SAlexander Duyck 
86c1b52739SBenjamin LaHaise static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
87a85a970aSWANG Cong 			    struct nlattr *est, struct tc_action **a,
88789871bbSVlad Buslov 			    int ovr, int bind, bool rtnl_held,
8985d0966fSDavide Caratti 			    struct tcf_proto *tp,
90789871bbSVlad Buslov 			    struct netlink_ext_ack *extack)
91ca9b0e27SAlexander Duyck {
92ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, skbedit_net_id);
936d7a8df6SVlad Buslov 	struct tcf_skbedit_params *params_new;
94ca9b0e27SAlexander Duyck 	struct nlattr *tb[TCA_SKBEDIT_MAX + 1];
95ec7727bbSDavide Caratti 	struct tcf_chain *goto_ch = NULL;
96ca9b0e27SAlexander Duyck 	struct tc_skbedit *parm;
97ca9b0e27SAlexander Duyck 	struct tcf_skbedit *d;
984fe77d82SAntonio Quartulli 	u32 flags = 0, *priority = NULL, *mark = NULL, *mask = NULL;
99ff202ee1SJamal Hadi Salim 	u16 *queue_mapping = NULL, *ptype = NULL;
100b2313077SWANG Cong 	bool exists = false;
101b2313077SWANG Cong 	int ret = 0, err;
1027be8ef2cSDmytro Linkin 	u32 index;
103ca9b0e27SAlexander Duyck 
104ca9b0e27SAlexander Duyck 	if (nla == NULL)
105ca9b0e27SAlexander Duyck 		return -EINVAL;
106ca9b0e27SAlexander Duyck 
1078cb08174SJohannes Berg 	err = nla_parse_nested_deprecated(tb, TCA_SKBEDIT_MAX, nla,
1088cb08174SJohannes Berg 					  skbedit_policy, NULL);
109ca9b0e27SAlexander Duyck 	if (err < 0)
110ca9b0e27SAlexander Duyck 		return err;
111ca9b0e27SAlexander Duyck 
112ca9b0e27SAlexander Duyck 	if (tb[TCA_SKBEDIT_PARMS] == NULL)
113ca9b0e27SAlexander Duyck 		return -EINVAL;
114ca9b0e27SAlexander Duyck 
115ca9b0e27SAlexander Duyck 	if (tb[TCA_SKBEDIT_PRIORITY] != NULL) {
116ca9b0e27SAlexander Duyck 		flags |= SKBEDIT_F_PRIORITY;
117ca9b0e27SAlexander Duyck 		priority = nla_data(tb[TCA_SKBEDIT_PRIORITY]);
118ca9b0e27SAlexander Duyck 	}
119ca9b0e27SAlexander Duyck 
120ca9b0e27SAlexander Duyck 	if (tb[TCA_SKBEDIT_QUEUE_MAPPING] != NULL) {
121ca9b0e27SAlexander Duyck 		flags |= SKBEDIT_F_QUEUE_MAPPING;
122ca9b0e27SAlexander Duyck 		queue_mapping = nla_data(tb[TCA_SKBEDIT_QUEUE_MAPPING]);
123ca9b0e27SAlexander Duyck 	}
1241c55d62eSjamal 
125ff202ee1SJamal Hadi Salim 	if (tb[TCA_SKBEDIT_PTYPE] != NULL) {
126ff202ee1SJamal Hadi Salim 		ptype = nla_data(tb[TCA_SKBEDIT_PTYPE]);
127ff202ee1SJamal Hadi Salim 		if (!skb_pkt_type_ok(*ptype))
128ff202ee1SJamal Hadi Salim 			return -EINVAL;
129ff202ee1SJamal Hadi Salim 		flags |= SKBEDIT_F_PTYPE;
130ff202ee1SJamal Hadi Salim 	}
131ff202ee1SJamal Hadi Salim 
1321c55d62eSjamal 	if (tb[TCA_SKBEDIT_MARK] != NULL) {
1331c55d62eSjamal 		flags |= SKBEDIT_F_MARK;
1341c55d62eSjamal 		mark = nla_data(tb[TCA_SKBEDIT_MARK]);
1351c55d62eSjamal 	}
1361c55d62eSjamal 
1374fe77d82SAntonio Quartulli 	if (tb[TCA_SKBEDIT_MASK] != NULL) {
1384fe77d82SAntonio Quartulli 		flags |= SKBEDIT_F_MASK;
1394fe77d82SAntonio Quartulli 		mask = nla_data(tb[TCA_SKBEDIT_MASK]);
1404fe77d82SAntonio Quartulli 	}
1414fe77d82SAntonio Quartulli 
142e7e3728bSQiaobin Fu 	if (tb[TCA_SKBEDIT_FLAGS] != NULL) {
143e7e3728bSQiaobin Fu 		u64 *pure_flags = nla_data(tb[TCA_SKBEDIT_FLAGS]);
144e7e3728bSQiaobin Fu 
145e7e3728bSQiaobin Fu 		if (*pure_flags & SKBEDIT_F_INHERITDSFIELD)
146e7e3728bSQiaobin Fu 			flags |= SKBEDIT_F_INHERITDSFIELD;
147e7e3728bSQiaobin Fu 	}
148e7e3728bSQiaobin Fu 
149ca9b0e27SAlexander Duyck 	parm = nla_data(tb[TCA_SKBEDIT_PARMS]);
1507be8ef2cSDmytro Linkin 	index = parm->index;
1517be8ef2cSDmytro Linkin 	err = tcf_idr_check_alloc(tn, &index, a, bind);
1520190c1d4SVlad Buslov 	if (err < 0)
1530190c1d4SVlad Buslov 		return err;
1540190c1d4SVlad Buslov 	exists = err;
1555e1567aeSJamal Hadi Salim 	if (exists && bind)
1565e1567aeSJamal Hadi Salim 		return 0;
1575e1567aeSJamal Hadi Salim 
1585e1567aeSJamal Hadi Salim 	if (!flags) {
159af5d0184SRoman Mashak 		if (exists)
16065a206c0SChris Mi 			tcf_idr_release(*a, bind);
1610190c1d4SVlad Buslov 		else
1627be8ef2cSDmytro Linkin 			tcf_idr_cleanup(tn, index);
1635e1567aeSJamal Hadi Salim 		return -EINVAL;
1645e1567aeSJamal Hadi Salim 	}
1655e1567aeSJamal Hadi Salim 
1665e1567aeSJamal Hadi Salim 	if (!exists) {
1677be8ef2cSDmytro Linkin 		ret = tcf_idr_create(tn, index, est, a,
1686f3dfb0dSDavide Caratti 				     &act_skbedit_ops, bind, true);
1690190c1d4SVlad Buslov 		if (ret) {
1707be8ef2cSDmytro Linkin 			tcf_idr_cleanup(tn, index);
17186062033SWANG Cong 			return ret;
1720190c1d4SVlad Buslov 		}
173ca9b0e27SAlexander Duyck 
174a85a970aSWANG Cong 		d = to_skbedit(*a);
175ca9b0e27SAlexander Duyck 		ret = ACT_P_CREATED;
176ca9b0e27SAlexander Duyck 	} else {
177a85a970aSWANG Cong 		d = to_skbedit(*a);
1784e8ddd7fSVlad Buslov 		if (!ovr) {
17965a206c0SChris Mi 			tcf_idr_release(*a, bind);
180ca9b0e27SAlexander Duyck 			return -EEXIST;
181ca9b0e27SAlexander Duyck 		}
1824e8ddd7fSVlad Buslov 	}
183ec7727bbSDavide Caratti 	err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
184ec7727bbSDavide Caratti 	if (err < 0)
185ec7727bbSDavide Caratti 		goto release_idr;
186ca9b0e27SAlexander Duyck 
187c749cddaSDavide Caratti 	params_new = kzalloc(sizeof(*params_new), GFP_KERNEL);
188c749cddaSDavide Caratti 	if (unlikely(!params_new)) {
189ec7727bbSDavide Caratti 		err = -ENOMEM;
190ec7727bbSDavide Caratti 		goto put_chain;
191c749cddaSDavide Caratti 	}
192c749cddaSDavide Caratti 
193c749cddaSDavide Caratti 	params_new->flags = flags;
194ca9b0e27SAlexander Duyck 	if (flags & SKBEDIT_F_PRIORITY)
195c749cddaSDavide Caratti 		params_new->priority = *priority;
196ca9b0e27SAlexander Duyck 	if (flags & SKBEDIT_F_QUEUE_MAPPING)
197c749cddaSDavide Caratti 		params_new->queue_mapping = *queue_mapping;
1981c55d62eSjamal 	if (flags & SKBEDIT_F_MARK)
199c749cddaSDavide Caratti 		params_new->mark = *mark;
200ff202ee1SJamal Hadi Salim 	if (flags & SKBEDIT_F_PTYPE)
201c749cddaSDavide Caratti 		params_new->ptype = *ptype;
2024fe77d82SAntonio Quartulli 	/* default behaviour is to use all the bits */
203c749cddaSDavide Caratti 	params_new->mask = 0xffffffff;
2044fe77d82SAntonio Quartulli 	if (flags & SKBEDIT_F_MASK)
205c749cddaSDavide Caratti 		params_new->mask = *mask;
2061c55d62eSjamal 
2076d7a8df6SVlad Buslov 	spin_lock_bh(&d->tcf_lock);
208ec7727bbSDavide Caratti 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
2096d7a8df6SVlad Buslov 	rcu_swap_protected(d->params, params_new,
2106d7a8df6SVlad Buslov 			   lockdep_is_held(&d->tcf_lock));
2116d7a8df6SVlad Buslov 	spin_unlock_bh(&d->tcf_lock);
2126d7a8df6SVlad Buslov 	if (params_new)
2136d7a8df6SVlad Buslov 		kfree_rcu(params_new, rcu);
214ec7727bbSDavide Caratti 	if (goto_ch)
215ec7727bbSDavide Caratti 		tcf_chain_put_by_act(goto_ch);
216ca9b0e27SAlexander Duyck 
217ca9b0e27SAlexander Duyck 	if (ret == ACT_P_CREATED)
21865a206c0SChris Mi 		tcf_idr_insert(tn, *a);
219ca9b0e27SAlexander Duyck 	return ret;
220ec7727bbSDavide Caratti put_chain:
221ec7727bbSDavide Caratti 	if (goto_ch)
222ec7727bbSDavide Caratti 		tcf_chain_put_by_act(goto_ch);
223ec7727bbSDavide Caratti release_idr:
224ec7727bbSDavide Caratti 	tcf_idr_release(*a, bind);
225ec7727bbSDavide Caratti 	return err;
226ca9b0e27SAlexander Duyck }
227ca9b0e27SAlexander Duyck 
228cc7ec456SEric Dumazet static int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a,
229ca9b0e27SAlexander Duyck 			    int bind, int ref)
230ca9b0e27SAlexander Duyck {
231ca9b0e27SAlexander Duyck 	unsigned char *b = skb_tail_pointer(skb);
232a85a970aSWANG Cong 	struct tcf_skbedit *d = to_skbedit(a);
233c749cddaSDavide Caratti 	struct tcf_skbedit_params *params;
2341c40be12SEric Dumazet 	struct tc_skbedit opt = {
2351c40be12SEric Dumazet 		.index   = d->tcf_index,
236036bb443SVlad Buslov 		.refcnt  = refcount_read(&d->tcf_refcnt) - ref,
237036bb443SVlad Buslov 		.bindcnt = atomic_read(&d->tcf_bindcnt) - bind,
2381c40be12SEric Dumazet 	};
239e7e3728bSQiaobin Fu 	u64 pure_flags = 0;
240c749cddaSDavide Caratti 	struct tcf_t t;
241c749cddaSDavide Caratti 
2426d7a8df6SVlad Buslov 	spin_lock_bh(&d->tcf_lock);
2436d7a8df6SVlad Buslov 	params = rcu_dereference_protected(d->params,
2446d7a8df6SVlad Buslov 					   lockdep_is_held(&d->tcf_lock));
2456d7a8df6SVlad Buslov 	opt.action = d->tcf_action;
246ca9b0e27SAlexander Duyck 
2471b34ec43SDavid S. Miller 	if (nla_put(skb, TCA_SKBEDIT_PARMS, sizeof(opt), &opt))
2481b34ec43SDavid S. Miller 		goto nla_put_failure;
249c749cddaSDavide Caratti 	if ((params->flags & SKBEDIT_F_PRIORITY) &&
250c749cddaSDavide Caratti 	    nla_put_u32(skb, TCA_SKBEDIT_PRIORITY, params->priority))
2511b34ec43SDavid S. Miller 		goto nla_put_failure;
252c749cddaSDavide Caratti 	if ((params->flags & SKBEDIT_F_QUEUE_MAPPING) &&
253c749cddaSDavide Caratti 	    nla_put_u16(skb, TCA_SKBEDIT_QUEUE_MAPPING, params->queue_mapping))
2541b34ec43SDavid S. Miller 		goto nla_put_failure;
255c749cddaSDavide Caratti 	if ((params->flags & SKBEDIT_F_MARK) &&
256c749cddaSDavide Caratti 	    nla_put_u32(skb, TCA_SKBEDIT_MARK, params->mark))
2571b34ec43SDavid S. Miller 		goto nla_put_failure;
258c749cddaSDavide Caratti 	if ((params->flags & SKBEDIT_F_PTYPE) &&
259c749cddaSDavide Caratti 	    nla_put_u16(skb, TCA_SKBEDIT_PTYPE, params->ptype))
260ff202ee1SJamal Hadi Salim 		goto nla_put_failure;
261c749cddaSDavide Caratti 	if ((params->flags & SKBEDIT_F_MASK) &&
262c749cddaSDavide Caratti 	    nla_put_u32(skb, TCA_SKBEDIT_MASK, params->mask))
2634fe77d82SAntonio Quartulli 		goto nla_put_failure;
264c749cddaSDavide Caratti 	if (params->flags & SKBEDIT_F_INHERITDSFIELD)
265e7e3728bSQiaobin Fu 		pure_flags |= SKBEDIT_F_INHERITDSFIELD;
266e7e3728bSQiaobin Fu 	if (pure_flags != 0 &&
267e7e3728bSQiaobin Fu 	    nla_put(skb, TCA_SKBEDIT_FLAGS, sizeof(pure_flags), &pure_flags))
268e7e3728bSQiaobin Fu 		goto nla_put_failure;
26948d8ee16SJamal Hadi Salim 
27048d8ee16SJamal Hadi Salim 	tcf_tm_dump(&t, &d->tcf_tm);
2719854518eSNicolas Dichtel 	if (nla_put_64bit(skb, TCA_SKBEDIT_TM, sizeof(t), &t, TCA_SKBEDIT_PAD))
2721b34ec43SDavid S. Miller 		goto nla_put_failure;
2736d7a8df6SVlad Buslov 	spin_unlock_bh(&d->tcf_lock);
2746d7a8df6SVlad Buslov 
275ca9b0e27SAlexander Duyck 	return skb->len;
276ca9b0e27SAlexander Duyck 
277ca9b0e27SAlexander Duyck nla_put_failure:
2786d7a8df6SVlad Buslov 	spin_unlock_bh(&d->tcf_lock);
279ca9b0e27SAlexander Duyck 	nlmsg_trim(skb, b);
280ca9b0e27SAlexander Duyck 	return -1;
281ca9b0e27SAlexander Duyck }
282ca9b0e27SAlexander Duyck 
283c749cddaSDavide Caratti static void tcf_skbedit_cleanup(struct tc_action *a)
284c749cddaSDavide Caratti {
285c749cddaSDavide Caratti 	struct tcf_skbedit *d = to_skbedit(a);
286c749cddaSDavide Caratti 	struct tcf_skbedit_params *params;
287c749cddaSDavide Caratti 
288c749cddaSDavide Caratti 	params = rcu_dereference_protected(d->params, 1);
289c749cddaSDavide Caratti 	if (params)
290c749cddaSDavide Caratti 		kfree_rcu(params, rcu);
291c749cddaSDavide Caratti }
292c749cddaSDavide Caratti 
293ddf97ccdSWANG Cong static int tcf_skbedit_walker(struct net *net, struct sk_buff *skb,
294ddf97ccdSWANG Cong 			      struct netlink_callback *cb, int type,
29541780105SAlexander Aring 			      const struct tc_action_ops *ops,
29641780105SAlexander Aring 			      struct netlink_ext_ack *extack)
297ddf97ccdSWANG Cong {
298ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, skbedit_net_id);
299ddf97ccdSWANG Cong 
300b3620145SAlexander Aring 	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
301ddf97ccdSWANG Cong }
302ddf97ccdSWANG Cong 
303f061b48cSCong Wang static int tcf_skbedit_search(struct net *net, struct tc_action **a, u32 index)
304ddf97ccdSWANG Cong {
305ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, skbedit_net_id);
306ddf97ccdSWANG Cong 
30765a206c0SChris Mi 	return tcf_idr_search(tn, a, index);
308ddf97ccdSWANG Cong }
309ddf97ccdSWANG Cong 
310*e1fea322SRoman Mashak static size_t tcf_skbedit_get_fill_size(const struct tc_action *act)
311*e1fea322SRoman Mashak {
312*e1fea322SRoman Mashak 	return nla_total_size(sizeof(struct tc_skbedit))
313*e1fea322SRoman Mashak 		+ nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_PRIORITY */
314*e1fea322SRoman Mashak 		+ nla_total_size(sizeof(u16)) /* TCA_SKBEDIT_QUEUE_MAPPING */
315*e1fea322SRoman Mashak 		+ nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_MARK */
316*e1fea322SRoman Mashak 		+ nla_total_size(sizeof(u16)) /* TCA_SKBEDIT_PTYPE */
317*e1fea322SRoman Mashak 		+ nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_MASK */
318*e1fea322SRoman Mashak 		+ nla_total_size_64bit(sizeof(u64)); /* TCA_SKBEDIT_FLAGS */
319*e1fea322SRoman Mashak }
320*e1fea322SRoman Mashak 
321ca9b0e27SAlexander Duyck static struct tc_action_ops act_skbedit_ops = {
322ca9b0e27SAlexander Duyck 	.kind		=	"skbedit",
323eddd2cf1SEli Cohen 	.id		=	TCA_ID_SKBEDIT,
324ca9b0e27SAlexander Duyck 	.owner		=	THIS_MODULE,
32545da1dacSJamal Hadi Salim 	.act		=	tcf_skbedit_act,
326ca9b0e27SAlexander Duyck 	.dump		=	tcf_skbedit_dump,
327ca9b0e27SAlexander Duyck 	.init		=	tcf_skbedit_init,
328c749cddaSDavide Caratti 	.cleanup	=	tcf_skbedit_cleanup,
329ddf97ccdSWANG Cong 	.walk		=	tcf_skbedit_walker,
330*e1fea322SRoman Mashak 	.get_fill_size	=	tcf_skbedit_get_fill_size,
331ddf97ccdSWANG Cong 	.lookup		=	tcf_skbedit_search,
332a85a970aSWANG Cong 	.size		=	sizeof(struct tcf_skbedit),
333ddf97ccdSWANG Cong };
334ddf97ccdSWANG Cong 
335ddf97ccdSWANG Cong static __net_init int skbedit_init_net(struct net *net)
336ddf97ccdSWANG Cong {
337ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, skbedit_net_id);
338ddf97ccdSWANG Cong 
339c7e460ceSCong Wang 	return tc_action_net_init(tn, &act_skbedit_ops);
340ddf97ccdSWANG Cong }
341ddf97ccdSWANG Cong 
342039af9c6SCong Wang static void __net_exit skbedit_exit_net(struct list_head *net_list)
343ddf97ccdSWANG Cong {
344039af9c6SCong Wang 	tc_action_net_exit(net_list, skbedit_net_id);
345ddf97ccdSWANG Cong }
346ddf97ccdSWANG Cong 
347ddf97ccdSWANG Cong static struct pernet_operations skbedit_net_ops = {
348ddf97ccdSWANG Cong 	.init = skbedit_init_net,
349039af9c6SCong Wang 	.exit_batch = skbedit_exit_net,
350ddf97ccdSWANG Cong 	.id   = &skbedit_net_id,
351ddf97ccdSWANG Cong 	.size = sizeof(struct tc_action_net),
352ca9b0e27SAlexander Duyck };
353ca9b0e27SAlexander Duyck 
354ca9b0e27SAlexander Duyck MODULE_AUTHOR("Alexander Duyck, <alexander.h.duyck@intel.com>");
355ca9b0e27SAlexander Duyck MODULE_DESCRIPTION("SKB Editing");
356ca9b0e27SAlexander Duyck MODULE_LICENSE("GPL");
357ca9b0e27SAlexander Duyck 
358ca9b0e27SAlexander Duyck static int __init skbedit_init_module(void)
359ca9b0e27SAlexander Duyck {
360ddf97ccdSWANG Cong 	return tcf_register_action(&act_skbedit_ops, &skbedit_net_ops);
361ca9b0e27SAlexander Duyck }
362ca9b0e27SAlexander Duyck 
363ca9b0e27SAlexander Duyck static void __exit skbedit_cleanup_module(void)
364ca9b0e27SAlexander Duyck {
365ddf97ccdSWANG Cong 	tcf_unregister_action(&act_skbedit_ops, &skbedit_net_ops);
366ca9b0e27SAlexander Duyck }
367ca9b0e27SAlexander Duyck 
368ca9b0e27SAlexander Duyck module_init(skbedit_init_module);
369ca9b0e27SAlexander Duyck module_exit(skbedit_cleanup_module);
370