xref: /openbmc/linux/net/sched/act_vlan.c (revision 981471bd)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2c7e2b968SJiri Pirko /*
3c7e2b968SJiri Pirko  * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
4c7e2b968SJiri Pirko  */
5c7e2b968SJiri Pirko 
6c7e2b968SJiri Pirko #include <linux/module.h>
7c7e2b968SJiri Pirko #include <linux/init.h>
8c7e2b968SJiri Pirko #include <linux/kernel.h>
9c7e2b968SJiri Pirko #include <linux/skbuff.h>
10c7e2b968SJiri Pirko #include <linux/rtnetlink.h>
11c7e2b968SJiri Pirko #include <linux/if_vlan.h>
12c7e2b968SJiri Pirko #include <net/netlink.h>
13c7e2b968SJiri Pirko #include <net/pkt_sched.h>
147e0c8892SDavide Caratti #include <net/pkt_cls.h>
15c7e2b968SJiri Pirko 
16c7e2b968SJiri Pirko #include <linux/tc_act/tc_vlan.h>
17c7e2b968SJiri Pirko #include <net/tc_act/tc_vlan.h>
18c7e2b968SJiri Pirko 
19c7d03a00SAlexey Dobriyan static unsigned int vlan_net_id;
20a85a970aSWANG Cong static struct tc_action_ops act_vlan_ops;
21ddf97ccdSWANG Cong 
228aa7f22eSJamal Hadi Salim static int tcf_vlan_act(struct sk_buff *skb, const struct tc_action *a,
23c7e2b968SJiri Pirko 			struct tcf_result *res)
24c7e2b968SJiri Pirko {
25a85a970aSWANG Cong 	struct tcf_vlan *v = to_vlan(a);
264c5b9d96SManish Kurup 	struct tcf_vlan_params *p;
27c7e2b968SJiri Pirko 	int action;
28c7e2b968SJiri Pirko 	int err;
2945a497f2SShmulik Ladkani 	u16 tci;
30c7e2b968SJiri Pirko 
319c4a4e48SJamal Hadi Salim 	tcf_lastuse_update(&v->tcf_tm);
32e0496cbbSManish Kurup 	bstats_cpu_update(this_cpu_ptr(v->common.cpu_bstats), skb);
33e0496cbbSManish Kurup 
34f39acc84SShmulik Ladkani 	/* Ensure 'data' points at mac_header prior calling vlan manipulating
35f39acc84SShmulik Ladkani 	 * functions.
36f39acc84SShmulik Ladkani 	 */
37f39acc84SShmulik Ladkani 	if (skb_at_tc_ingress(skb))
38f39acc84SShmulik Ladkani 		skb_push_rcsum(skb, skb->mac_len);
39f39acc84SShmulik Ladkani 
404c5b9d96SManish Kurup 	action = READ_ONCE(v->tcf_action);
414c5b9d96SManish Kurup 
427fd4b288SPaolo Abeni 	p = rcu_dereference_bh(v->vlan_p);
434c5b9d96SManish Kurup 
444c5b9d96SManish Kurup 	switch (p->tcfv_action) {
45c7e2b968SJiri Pirko 	case TCA_VLAN_ACT_POP:
46c7e2b968SJiri Pirko 		err = skb_vlan_pop(skb);
47c7e2b968SJiri Pirko 		if (err)
48c7e2b968SJiri Pirko 			goto drop;
49c7e2b968SJiri Pirko 		break;
50c7e2b968SJiri Pirko 	case TCA_VLAN_ACT_PUSH:
514c5b9d96SManish Kurup 		err = skb_vlan_push(skb, p->tcfv_push_proto, p->tcfv_push_vid |
524c5b9d96SManish Kurup 				    (p->tcfv_push_prio << VLAN_PRIO_SHIFT));
53c7e2b968SJiri Pirko 		if (err)
54c7e2b968SJiri Pirko 			goto drop;
55c7e2b968SJiri Pirko 		break;
5645a497f2SShmulik Ladkani 	case TCA_VLAN_ACT_MODIFY:
5745a497f2SShmulik Ladkani 		/* No-op if no vlan tag (either hw-accel or in-payload) */
5845a497f2SShmulik Ladkani 		if (!skb_vlan_tagged(skb))
597fd4b288SPaolo Abeni 			goto out;
6045a497f2SShmulik Ladkani 		/* extract existing tag (and guarantee no hw-accel tag) */
6145a497f2SShmulik Ladkani 		if (skb_vlan_tag_present(skb)) {
6245a497f2SShmulik Ladkani 			tci = skb_vlan_tag_get(skb);
63b1817524SMichał Mirosław 			__vlan_hwaccel_clear_tag(skb);
6445a497f2SShmulik Ladkani 		} else {
6545a497f2SShmulik Ladkani 			/* in-payload vlan tag, pop it */
6645a497f2SShmulik Ladkani 			err = __skb_vlan_pop(skb, &tci);
6745a497f2SShmulik Ladkani 			if (err)
6845a497f2SShmulik Ladkani 				goto drop;
6945a497f2SShmulik Ladkani 		}
7045a497f2SShmulik Ladkani 		/* replace the vid */
714c5b9d96SManish Kurup 		tci = (tci & ~VLAN_VID_MASK) | p->tcfv_push_vid;
7245a497f2SShmulik Ladkani 		/* replace prio bits, if tcfv_push_prio specified */
734c5b9d96SManish Kurup 		if (p->tcfv_push_prio) {
7445a497f2SShmulik Ladkani 			tci &= ~VLAN_PRIO_MASK;
754c5b9d96SManish Kurup 			tci |= p->tcfv_push_prio << VLAN_PRIO_SHIFT;
7645a497f2SShmulik Ladkani 		}
7745a497f2SShmulik Ladkani 		/* put updated tci as hwaccel tag */
784c5b9d96SManish Kurup 		__vlan_hwaccel_put_tag(skb, p->tcfv_push_proto, tci);
7945a497f2SShmulik Ladkani 		break;
80c7e2b968SJiri Pirko 	default:
81c7e2b968SJiri Pirko 		BUG();
82c7e2b968SJiri Pirko 	}
83c7e2b968SJiri Pirko 
847fd4b288SPaolo Abeni out:
85f39acc84SShmulik Ladkani 	if (skb_at_tc_ingress(skb))
86f39acc84SShmulik Ladkani 		skb_pull_rcsum(skb, skb->mac_len);
87f39acc84SShmulik Ladkani 
88c7e2b968SJiri Pirko 	return action;
897fd4b288SPaolo Abeni 
907fd4b288SPaolo Abeni drop:
917fd4b288SPaolo Abeni 	qstats_drop_inc(this_cpu_ptr(v->common.cpu_qstats));
927fd4b288SPaolo Abeni 	return TC_ACT_SHOT;
93c7e2b968SJiri Pirko }
94c7e2b968SJiri Pirko 
95c7e2b968SJiri Pirko static const struct nla_policy vlan_policy[TCA_VLAN_MAX + 1] = {
96c7e2b968SJiri Pirko 	[TCA_VLAN_PARMS]		= { .len = sizeof(struct tc_vlan) },
97c7e2b968SJiri Pirko 	[TCA_VLAN_PUSH_VLAN_ID]		= { .type = NLA_U16 },
98c7e2b968SJiri Pirko 	[TCA_VLAN_PUSH_VLAN_PROTOCOL]	= { .type = NLA_U16 },
99956af371SHadar Hen Zion 	[TCA_VLAN_PUSH_VLAN_PRIORITY]	= { .type = NLA_U8 },
100c7e2b968SJiri Pirko };
101c7e2b968SJiri Pirko 
102c7e2b968SJiri Pirko static int tcf_vlan_init(struct net *net, struct nlattr *nla,
103a85a970aSWANG Cong 			 struct nlattr *est, struct tc_action **a,
104789871bbSVlad Buslov 			 int ovr, int bind, bool rtnl_held,
10585d0966fSDavide Caratti 			 struct tcf_proto *tp, struct netlink_ext_ack *extack)
106c7e2b968SJiri Pirko {
107ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, vlan_net_id);
108c7e2b968SJiri Pirko 	struct nlattr *tb[TCA_VLAN_MAX + 1];
1097e0c8892SDavide Caratti 	struct tcf_chain *goto_ch = NULL;
110764e9a24SVlad Buslov 	struct tcf_vlan_params *p;
111c7e2b968SJiri Pirko 	struct tc_vlan *parm;
112c7e2b968SJiri Pirko 	struct tcf_vlan *v;
113c7e2b968SJiri Pirko 	int action;
11494cb5492SDavide Caratti 	u16 push_vid = 0;
115c7e2b968SJiri Pirko 	__be16 push_proto = 0;
116956af371SHadar Hen Zion 	u8 push_prio = 0;
117b2313077SWANG Cong 	bool exists = false;
118b2313077SWANG Cong 	int ret = 0, err;
1197be8ef2cSDmytro Linkin 	u32 index;
120c7e2b968SJiri Pirko 
121c7e2b968SJiri Pirko 	if (!nla)
122c7e2b968SJiri Pirko 		return -EINVAL;
123c7e2b968SJiri Pirko 
1248cb08174SJohannes Berg 	err = nla_parse_nested_deprecated(tb, TCA_VLAN_MAX, nla, vlan_policy,
1258cb08174SJohannes Berg 					  NULL);
126c7e2b968SJiri Pirko 	if (err < 0)
127c7e2b968SJiri Pirko 		return err;
128c7e2b968SJiri Pirko 
129c7e2b968SJiri Pirko 	if (!tb[TCA_VLAN_PARMS])
130c7e2b968SJiri Pirko 		return -EINVAL;
131c7e2b968SJiri Pirko 	parm = nla_data(tb[TCA_VLAN_PARMS]);
1327be8ef2cSDmytro Linkin 	index = parm->index;
1337be8ef2cSDmytro Linkin 	err = tcf_idr_check_alloc(tn, &index, a, bind);
1340190c1d4SVlad Buslov 	if (err < 0)
1350190c1d4SVlad Buslov 		return err;
1360190c1d4SVlad Buslov 	exists = err;
1375026c9b1SJamal Hadi Salim 	if (exists && bind)
1385026c9b1SJamal Hadi Salim 		return 0;
1395026c9b1SJamal Hadi Salim 
140c7e2b968SJiri Pirko 	switch (parm->v_action) {
141c7e2b968SJiri Pirko 	case TCA_VLAN_ACT_POP:
142c7e2b968SJiri Pirko 		break;
143c7e2b968SJiri Pirko 	case TCA_VLAN_ACT_PUSH:
14445a497f2SShmulik Ladkani 	case TCA_VLAN_ACT_MODIFY:
1455026c9b1SJamal Hadi Salim 		if (!tb[TCA_VLAN_PUSH_VLAN_ID]) {
1465026c9b1SJamal Hadi Salim 			if (exists)
14765a206c0SChris Mi 				tcf_idr_release(*a, bind);
1480190c1d4SVlad Buslov 			else
1497be8ef2cSDmytro Linkin 				tcf_idr_cleanup(tn, index);
150c7e2b968SJiri Pirko 			return -EINVAL;
1515026c9b1SJamal Hadi Salim 		}
152c7e2b968SJiri Pirko 		push_vid = nla_get_u16(tb[TCA_VLAN_PUSH_VLAN_ID]);
1535026c9b1SJamal Hadi Salim 		if (push_vid >= VLAN_VID_MASK) {
1545026c9b1SJamal Hadi Salim 			if (exists)
15565a206c0SChris Mi 				tcf_idr_release(*a, bind);
1560190c1d4SVlad Buslov 			else
1577be8ef2cSDmytro Linkin 				tcf_idr_cleanup(tn, index);
158c7e2b968SJiri Pirko 			return -ERANGE;
1595026c9b1SJamal Hadi Salim 		}
160c7e2b968SJiri Pirko 
161c7e2b968SJiri Pirko 		if (tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]) {
162c7e2b968SJiri Pirko 			push_proto = nla_get_be16(tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]);
163c7e2b968SJiri Pirko 			switch (push_proto) {
164c7e2b968SJiri Pirko 			case htons(ETH_P_8021Q):
165c7e2b968SJiri Pirko 			case htons(ETH_P_8021AD):
166c7e2b968SJiri Pirko 				break;
167c7e2b968SJiri Pirko 			default:
1685a4931aeSDavide Caratti 				if (exists)
1695a4931aeSDavide Caratti 					tcf_idr_release(*a, bind);
1700190c1d4SVlad Buslov 				else
1717be8ef2cSDmytro Linkin 					tcf_idr_cleanup(tn, index);
172c7e2b968SJiri Pirko 				return -EPROTONOSUPPORT;
173c7e2b968SJiri Pirko 			}
174c7e2b968SJiri Pirko 		} else {
175c7e2b968SJiri Pirko 			push_proto = htons(ETH_P_8021Q);
176c7e2b968SJiri Pirko 		}
177956af371SHadar Hen Zion 
178956af371SHadar Hen Zion 		if (tb[TCA_VLAN_PUSH_VLAN_PRIORITY])
179956af371SHadar Hen Zion 			push_prio = nla_get_u8(tb[TCA_VLAN_PUSH_VLAN_PRIORITY]);
180c7e2b968SJiri Pirko 		break;
181c7e2b968SJiri Pirko 	default:
1825026c9b1SJamal Hadi Salim 		if (exists)
18365a206c0SChris Mi 			tcf_idr_release(*a, bind);
1840190c1d4SVlad Buslov 		else
1857be8ef2cSDmytro Linkin 			tcf_idr_cleanup(tn, index);
186c7e2b968SJiri Pirko 		return -EINVAL;
187c7e2b968SJiri Pirko 	}
188c7e2b968SJiri Pirko 	action = parm->v_action;
189c7e2b968SJiri Pirko 
1905026c9b1SJamal Hadi Salim 	if (!exists) {
1917be8ef2cSDmytro Linkin 		ret = tcf_idr_create(tn, index, est, a,
192e0496cbbSManish Kurup 				     &act_vlan_ops, bind, true);
1930190c1d4SVlad Buslov 		if (ret) {
1947be8ef2cSDmytro Linkin 			tcf_idr_cleanup(tn, index);
195c7e2b968SJiri Pirko 			return ret;
1960190c1d4SVlad Buslov 		}
197c7e2b968SJiri Pirko 
198c7e2b968SJiri Pirko 		ret = ACT_P_CREATED;
1994e8ddd7fSVlad Buslov 	} else if (!ovr) {
20065a206c0SChris Mi 		tcf_idr_release(*a, bind);
201c7e2b968SJiri Pirko 		return -EEXIST;
202c7e2b968SJiri Pirko 	}
203c7e2b968SJiri Pirko 
2047e0c8892SDavide Caratti 	err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
2057e0c8892SDavide Caratti 	if (err < 0)
2067e0c8892SDavide Caratti 		goto release_idr;
2077e0c8892SDavide Caratti 
208a85a970aSWANG Cong 	v = to_vlan(*a);
209c7e2b968SJiri Pirko 
2104c5b9d96SManish Kurup 	p = kzalloc(sizeof(*p), GFP_KERNEL);
2114c5b9d96SManish Kurup 	if (!p) {
2127e0c8892SDavide Caratti 		err = -ENOMEM;
2137e0c8892SDavide Caratti 		goto put_chain;
2144c5b9d96SManish Kurup 	}
215c7e2b968SJiri Pirko 
2164c5b9d96SManish Kurup 	p->tcfv_action = action;
2174c5b9d96SManish Kurup 	p->tcfv_push_vid = push_vid;
2184c5b9d96SManish Kurup 	p->tcfv_push_prio = push_prio;
2194c5b9d96SManish Kurup 	p->tcfv_push_proto = push_proto;
2204c5b9d96SManish Kurup 
221653cd284SVlad Buslov 	spin_lock_bh(&v->tcf_lock);
2227e0c8892SDavide Caratti 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
223764e9a24SVlad Buslov 	rcu_swap_protected(v->vlan_p, p, lockdep_is_held(&v->tcf_lock));
224653cd284SVlad Buslov 	spin_unlock_bh(&v->tcf_lock);
2254c5b9d96SManish Kurup 
2267e0c8892SDavide Caratti 	if (goto_ch)
2277e0c8892SDavide Caratti 		tcf_chain_put_by_act(goto_ch);
228764e9a24SVlad Buslov 	if (p)
229764e9a24SVlad Buslov 		kfree_rcu(p, rcu);
230c7e2b968SJiri Pirko 
231c7e2b968SJiri Pirko 	if (ret == ACT_P_CREATED)
23265a206c0SChris Mi 		tcf_idr_insert(tn, *a);
233c7e2b968SJiri Pirko 	return ret;
2347e0c8892SDavide Caratti put_chain:
2357e0c8892SDavide Caratti 	if (goto_ch)
2367e0c8892SDavide Caratti 		tcf_chain_put_by_act(goto_ch);
2377e0c8892SDavide Caratti release_idr:
2387e0c8892SDavide Caratti 	tcf_idr_release(*a, bind);
2397e0c8892SDavide Caratti 	return err;
240c7e2b968SJiri Pirko }
241c7e2b968SJiri Pirko 
2429a63b255SCong Wang static void tcf_vlan_cleanup(struct tc_action *a)
2434c5b9d96SManish Kurup {
2444c5b9d96SManish Kurup 	struct tcf_vlan *v = to_vlan(a);
2454c5b9d96SManish Kurup 	struct tcf_vlan_params *p;
2464c5b9d96SManish Kurup 
2474c5b9d96SManish Kurup 	p = rcu_dereference_protected(v->vlan_p, 1);
2481edf8abeSDavide Caratti 	if (p)
2494c5b9d96SManish Kurup 		kfree_rcu(p, rcu);
2504c5b9d96SManish Kurup }
2514c5b9d96SManish Kurup 
252c7e2b968SJiri Pirko static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a,
253c7e2b968SJiri Pirko 			 int bind, int ref)
254c7e2b968SJiri Pirko {
255c7e2b968SJiri Pirko 	unsigned char *b = skb_tail_pointer(skb);
256a85a970aSWANG Cong 	struct tcf_vlan *v = to_vlan(a);
257764e9a24SVlad Buslov 	struct tcf_vlan_params *p;
258c7e2b968SJiri Pirko 	struct tc_vlan opt = {
259c7e2b968SJiri Pirko 		.index    = v->tcf_index,
260036bb443SVlad Buslov 		.refcnt   = refcount_read(&v->tcf_refcnt) - ref,
261036bb443SVlad Buslov 		.bindcnt  = atomic_read(&v->tcf_bindcnt) - bind,
262c7e2b968SJiri Pirko 	};
263c7e2b968SJiri Pirko 	struct tcf_t t;
264c7e2b968SJiri Pirko 
265653cd284SVlad Buslov 	spin_lock_bh(&v->tcf_lock);
266764e9a24SVlad Buslov 	opt.action = v->tcf_action;
267764e9a24SVlad Buslov 	p = rcu_dereference_protected(v->vlan_p, lockdep_is_held(&v->tcf_lock));
268764e9a24SVlad Buslov 	opt.v_action = p->tcfv_action;
269c7e2b968SJiri Pirko 	if (nla_put(skb, TCA_VLAN_PARMS, sizeof(opt), &opt))
270c7e2b968SJiri Pirko 		goto nla_put_failure;
271c7e2b968SJiri Pirko 
2724c5b9d96SManish Kurup 	if ((p->tcfv_action == TCA_VLAN_ACT_PUSH ||
2734c5b9d96SManish Kurup 	     p->tcfv_action == TCA_VLAN_ACT_MODIFY) &&
2744c5b9d96SManish Kurup 	    (nla_put_u16(skb, TCA_VLAN_PUSH_VLAN_ID, p->tcfv_push_vid) ||
2750b0f43feSJamal Hadi Salim 	     nla_put_be16(skb, TCA_VLAN_PUSH_VLAN_PROTOCOL,
2764c5b9d96SManish Kurup 			  p->tcfv_push_proto) ||
277956af371SHadar Hen Zion 	     (nla_put_u8(skb, TCA_VLAN_PUSH_VLAN_PRIORITY,
2784c5b9d96SManish Kurup 					      p->tcfv_push_prio))))
279c7e2b968SJiri Pirko 		goto nla_put_failure;
280c7e2b968SJiri Pirko 
28148d8ee16SJamal Hadi Salim 	tcf_tm_dump(&t, &v->tcf_tm);
2829854518eSNicolas Dichtel 	if (nla_put_64bit(skb, TCA_VLAN_TM, sizeof(t), &t, TCA_VLAN_PAD))
283c7e2b968SJiri Pirko 		goto nla_put_failure;
284653cd284SVlad Buslov 	spin_unlock_bh(&v->tcf_lock);
285764e9a24SVlad Buslov 
286c7e2b968SJiri Pirko 	return skb->len;
287c7e2b968SJiri Pirko 
288c7e2b968SJiri Pirko nla_put_failure:
289653cd284SVlad Buslov 	spin_unlock_bh(&v->tcf_lock);
290c7e2b968SJiri Pirko 	nlmsg_trim(skb, b);
291c7e2b968SJiri Pirko 	return -1;
292c7e2b968SJiri Pirko }
293c7e2b968SJiri Pirko 
294ddf97ccdSWANG Cong static int tcf_vlan_walker(struct net *net, struct sk_buff *skb,
295ddf97ccdSWANG Cong 			   struct netlink_callback *cb, int type,
29641780105SAlexander Aring 			   const struct tc_action_ops *ops,
29741780105SAlexander Aring 			   struct netlink_ext_ack *extack)
298ddf97ccdSWANG Cong {
299ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, vlan_net_id);
300ddf97ccdSWANG Cong 
301b3620145SAlexander Aring 	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
302ddf97ccdSWANG Cong }
303ddf97ccdSWANG Cong 
304f061b48cSCong Wang static int tcf_vlan_search(struct net *net, struct tc_action **a, u32 index)
305ddf97ccdSWANG Cong {
306ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, vlan_net_id);
307ddf97ccdSWANG Cong 
30865a206c0SChris Mi 	return tcf_idr_search(tn, a, index);
309ddf97ccdSWANG Cong }
310ddf97ccdSWANG Cong 
311b35475c5SRoman Mashak static size_t tcf_vlan_get_fill_size(const struct tc_action *act)
312b35475c5SRoman Mashak {
313b35475c5SRoman Mashak 	return nla_total_size(sizeof(struct tc_vlan))
314b35475c5SRoman Mashak 		+ nla_total_size(sizeof(u16)) /* TCA_VLAN_PUSH_VLAN_ID */
315b35475c5SRoman Mashak 		+ nla_total_size(sizeof(u16)) /* TCA_VLAN_PUSH_VLAN_PROTOCOL */
316b35475c5SRoman Mashak 		+ nla_total_size(sizeof(u8)); /* TCA_VLAN_PUSH_VLAN_PRIORITY */
317b35475c5SRoman Mashak }
318b35475c5SRoman Mashak 
319c7e2b968SJiri Pirko static struct tc_action_ops act_vlan_ops = {
320c7e2b968SJiri Pirko 	.kind		=	"vlan",
321eddd2cf1SEli Cohen 	.id		=	TCA_ID_VLAN,
322c7e2b968SJiri Pirko 	.owner		=	THIS_MODULE,
3238aa7f22eSJamal Hadi Salim 	.act		=	tcf_vlan_act,
324c7e2b968SJiri Pirko 	.dump		=	tcf_vlan_dump,
325c7e2b968SJiri Pirko 	.init		=	tcf_vlan_init,
3264c5b9d96SManish Kurup 	.cleanup	=	tcf_vlan_cleanup,
327ddf97ccdSWANG Cong 	.walk		=	tcf_vlan_walker,
328b35475c5SRoman Mashak 	.get_fill_size	=	tcf_vlan_get_fill_size,
329ddf97ccdSWANG Cong 	.lookup		=	tcf_vlan_search,
330a85a970aSWANG Cong 	.size		=	sizeof(struct tcf_vlan),
331ddf97ccdSWANG Cong };
332ddf97ccdSWANG Cong 
333ddf97ccdSWANG Cong static __net_init int vlan_init_net(struct net *net)
334ddf97ccdSWANG Cong {
335ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, vlan_net_id);
336ddf97ccdSWANG Cong 
337981471bdSCong Wang 	return tc_action_net_init(net, tn, &act_vlan_ops);
338ddf97ccdSWANG Cong }
339ddf97ccdSWANG Cong 
340039af9c6SCong Wang static void __net_exit vlan_exit_net(struct list_head *net_list)
341ddf97ccdSWANG Cong {
342039af9c6SCong Wang 	tc_action_net_exit(net_list, vlan_net_id);
343ddf97ccdSWANG Cong }
344ddf97ccdSWANG Cong 
345ddf97ccdSWANG Cong static struct pernet_operations vlan_net_ops = {
346ddf97ccdSWANG Cong 	.init = vlan_init_net,
347039af9c6SCong Wang 	.exit_batch = vlan_exit_net,
348ddf97ccdSWANG Cong 	.id   = &vlan_net_id,
349ddf97ccdSWANG Cong 	.size = sizeof(struct tc_action_net),
350c7e2b968SJiri Pirko };
351c7e2b968SJiri Pirko 
352c7e2b968SJiri Pirko static int __init vlan_init_module(void)
353c7e2b968SJiri Pirko {
354ddf97ccdSWANG Cong 	return tcf_register_action(&act_vlan_ops, &vlan_net_ops);
355c7e2b968SJiri Pirko }
356c7e2b968SJiri Pirko 
357c7e2b968SJiri Pirko static void __exit vlan_cleanup_module(void)
358c7e2b968SJiri Pirko {
359ddf97ccdSWANG Cong 	tcf_unregister_action(&act_vlan_ops, &vlan_net_ops);
360c7e2b968SJiri Pirko }
361c7e2b968SJiri Pirko 
362c7e2b968SJiri Pirko module_init(vlan_init_module);
363c7e2b968SJiri Pirko module_exit(vlan_cleanup_module);
364c7e2b968SJiri Pirko 
365c7e2b968SJiri Pirko MODULE_AUTHOR("Jiri Pirko <jiri@resnulli.us>");
366c7e2b968SJiri Pirko MODULE_DESCRIPTION("vlan manipulation actions");
367c7e2b968SJiri Pirko MODULE_LICENSE("GPL v2");
368