xref: /openbmc/linux/net/sched/act_vlan.c (revision 4b61d3e8)
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);
325e1ad95bSVlad Buslov 	tcf_action_update_bstats(&v->common, 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:
9126b537a8SVlad Buslov 	tcf_action_inc_drop_qstats(&v->common);
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,
105abbb0d33SVlad Buslov 			 struct tcf_proto *tp, u32 flags,
106abbb0d33SVlad Buslov 			 struct netlink_ext_ack *extack)
107c7e2b968SJiri Pirko {
108ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, vlan_net_id);
109c7e2b968SJiri Pirko 	struct nlattr *tb[TCA_VLAN_MAX + 1];
1107e0c8892SDavide Caratti 	struct tcf_chain *goto_ch = NULL;
111764e9a24SVlad Buslov 	struct tcf_vlan_params *p;
112c7e2b968SJiri Pirko 	struct tc_vlan *parm;
113c7e2b968SJiri Pirko 	struct tcf_vlan *v;
114c7e2b968SJiri Pirko 	int action;
11594cb5492SDavide Caratti 	u16 push_vid = 0;
116c7e2b968SJiri Pirko 	__be16 push_proto = 0;
117956af371SHadar Hen Zion 	u8 push_prio = 0;
118b2313077SWANG Cong 	bool exists = false;
119b2313077SWANG Cong 	int ret = 0, err;
1207be8ef2cSDmytro Linkin 	u32 index;
121c7e2b968SJiri Pirko 
122c7e2b968SJiri Pirko 	if (!nla)
123c7e2b968SJiri Pirko 		return -EINVAL;
124c7e2b968SJiri Pirko 
1258cb08174SJohannes Berg 	err = nla_parse_nested_deprecated(tb, TCA_VLAN_MAX, nla, vlan_policy,
1268cb08174SJohannes Berg 					  NULL);
127c7e2b968SJiri Pirko 	if (err < 0)
128c7e2b968SJiri Pirko 		return err;
129c7e2b968SJiri Pirko 
130c7e2b968SJiri Pirko 	if (!tb[TCA_VLAN_PARMS])
131c7e2b968SJiri Pirko 		return -EINVAL;
132c7e2b968SJiri Pirko 	parm = nla_data(tb[TCA_VLAN_PARMS]);
1337be8ef2cSDmytro Linkin 	index = parm->index;
1347be8ef2cSDmytro Linkin 	err = tcf_idr_check_alloc(tn, &index, a, bind);
1350190c1d4SVlad Buslov 	if (err < 0)
1360190c1d4SVlad Buslov 		return err;
1370190c1d4SVlad Buslov 	exists = err;
1385026c9b1SJamal Hadi Salim 	if (exists && bind)
1395026c9b1SJamal Hadi Salim 		return 0;
1405026c9b1SJamal Hadi Salim 
141c7e2b968SJiri Pirko 	switch (parm->v_action) {
142c7e2b968SJiri Pirko 	case TCA_VLAN_ACT_POP:
143c7e2b968SJiri Pirko 		break;
144c7e2b968SJiri Pirko 	case TCA_VLAN_ACT_PUSH:
14545a497f2SShmulik Ladkani 	case TCA_VLAN_ACT_MODIFY:
1465026c9b1SJamal Hadi Salim 		if (!tb[TCA_VLAN_PUSH_VLAN_ID]) {
1475026c9b1SJamal Hadi Salim 			if (exists)
14865a206c0SChris Mi 				tcf_idr_release(*a, bind);
1490190c1d4SVlad Buslov 			else
1507be8ef2cSDmytro Linkin 				tcf_idr_cleanup(tn, index);
151c7e2b968SJiri Pirko 			return -EINVAL;
1525026c9b1SJamal Hadi Salim 		}
153c7e2b968SJiri Pirko 		push_vid = nla_get_u16(tb[TCA_VLAN_PUSH_VLAN_ID]);
1545026c9b1SJamal Hadi Salim 		if (push_vid >= VLAN_VID_MASK) {
1555026c9b1SJamal Hadi Salim 			if (exists)
15665a206c0SChris Mi 				tcf_idr_release(*a, bind);
1570190c1d4SVlad Buslov 			else
1587be8ef2cSDmytro Linkin 				tcf_idr_cleanup(tn, index);
159c7e2b968SJiri Pirko 			return -ERANGE;
1605026c9b1SJamal Hadi Salim 		}
161c7e2b968SJiri Pirko 
162c7e2b968SJiri Pirko 		if (tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]) {
163c7e2b968SJiri Pirko 			push_proto = nla_get_be16(tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]);
164c7e2b968SJiri Pirko 			switch (push_proto) {
165c7e2b968SJiri Pirko 			case htons(ETH_P_8021Q):
166c7e2b968SJiri Pirko 			case htons(ETH_P_8021AD):
167c7e2b968SJiri Pirko 				break;
168c7e2b968SJiri Pirko 			default:
1695a4931aeSDavide Caratti 				if (exists)
1705a4931aeSDavide Caratti 					tcf_idr_release(*a, bind);
1710190c1d4SVlad Buslov 				else
1727be8ef2cSDmytro Linkin 					tcf_idr_cleanup(tn, index);
173c7e2b968SJiri Pirko 				return -EPROTONOSUPPORT;
174c7e2b968SJiri Pirko 			}
175c7e2b968SJiri Pirko 		} else {
176c7e2b968SJiri Pirko 			push_proto = htons(ETH_P_8021Q);
177c7e2b968SJiri Pirko 		}
178956af371SHadar Hen Zion 
179956af371SHadar Hen Zion 		if (tb[TCA_VLAN_PUSH_VLAN_PRIORITY])
180956af371SHadar Hen Zion 			push_prio = nla_get_u8(tb[TCA_VLAN_PUSH_VLAN_PRIORITY]);
181c7e2b968SJiri Pirko 		break;
182c7e2b968SJiri Pirko 	default:
1835026c9b1SJamal Hadi Salim 		if (exists)
18465a206c0SChris Mi 			tcf_idr_release(*a, bind);
1850190c1d4SVlad Buslov 		else
1867be8ef2cSDmytro Linkin 			tcf_idr_cleanup(tn, index);
187c7e2b968SJiri Pirko 		return -EINVAL;
188c7e2b968SJiri Pirko 	}
189c7e2b968SJiri Pirko 	action = parm->v_action;
190c7e2b968SJiri Pirko 
1915026c9b1SJamal Hadi Salim 	if (!exists) {
192e3822678SVlad Buslov 		ret = tcf_idr_create_from_flags(tn, index, est, a,
193e3822678SVlad Buslov 						&act_vlan_ops, bind, flags);
1940190c1d4SVlad Buslov 		if (ret) {
1957be8ef2cSDmytro Linkin 			tcf_idr_cleanup(tn, index);
196c7e2b968SJiri Pirko 			return ret;
1970190c1d4SVlad Buslov 		}
198c7e2b968SJiri Pirko 
199c7e2b968SJiri Pirko 		ret = ACT_P_CREATED;
2004e8ddd7fSVlad Buslov 	} else if (!ovr) {
20165a206c0SChris Mi 		tcf_idr_release(*a, bind);
202c7e2b968SJiri Pirko 		return -EEXIST;
203c7e2b968SJiri Pirko 	}
204c7e2b968SJiri Pirko 
2057e0c8892SDavide Caratti 	err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
2067e0c8892SDavide Caratti 	if (err < 0)
2077e0c8892SDavide Caratti 		goto release_idr;
2087e0c8892SDavide Caratti 
209a85a970aSWANG Cong 	v = to_vlan(*a);
210c7e2b968SJiri Pirko 
2114c5b9d96SManish Kurup 	p = kzalloc(sizeof(*p), GFP_KERNEL);
2124c5b9d96SManish Kurup 	if (!p) {
2137e0c8892SDavide Caratti 		err = -ENOMEM;
2147e0c8892SDavide Caratti 		goto put_chain;
2154c5b9d96SManish Kurup 	}
216c7e2b968SJiri Pirko 
2174c5b9d96SManish Kurup 	p->tcfv_action = action;
2184c5b9d96SManish Kurup 	p->tcfv_push_vid = push_vid;
2194c5b9d96SManish Kurup 	p->tcfv_push_prio = push_prio;
2204c5b9d96SManish Kurup 	p->tcfv_push_proto = push_proto;
2214c5b9d96SManish Kurup 
222653cd284SVlad Buslov 	spin_lock_bh(&v->tcf_lock);
2237e0c8892SDavide Caratti 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
224445d3749SPaul E. McKenney 	p = rcu_replace_pointer(v->vlan_p, p, lockdep_is_held(&v->tcf_lock));
225653cd284SVlad Buslov 	spin_unlock_bh(&v->tcf_lock);
2264c5b9d96SManish Kurup 
2277e0c8892SDavide Caratti 	if (goto_ch)
2287e0c8892SDavide Caratti 		tcf_chain_put_by_act(goto_ch);
229764e9a24SVlad Buslov 	if (p)
230764e9a24SVlad Buslov 		kfree_rcu(p, rcu);
231c7e2b968SJiri Pirko 
232c7e2b968SJiri Pirko 	if (ret == ACT_P_CREATED)
23365a206c0SChris Mi 		tcf_idr_insert(tn, *a);
234c7e2b968SJiri Pirko 	return ret;
2357e0c8892SDavide Caratti put_chain:
2367e0c8892SDavide Caratti 	if (goto_ch)
2377e0c8892SDavide Caratti 		tcf_chain_put_by_act(goto_ch);
2387e0c8892SDavide Caratti release_idr:
2397e0c8892SDavide Caratti 	tcf_idr_release(*a, bind);
2407e0c8892SDavide Caratti 	return err;
241c7e2b968SJiri Pirko }
242c7e2b968SJiri Pirko 
2439a63b255SCong Wang static void tcf_vlan_cleanup(struct tc_action *a)
2444c5b9d96SManish Kurup {
2454c5b9d96SManish Kurup 	struct tcf_vlan *v = to_vlan(a);
2464c5b9d96SManish Kurup 	struct tcf_vlan_params *p;
2474c5b9d96SManish Kurup 
2484c5b9d96SManish Kurup 	p = rcu_dereference_protected(v->vlan_p, 1);
2491edf8abeSDavide Caratti 	if (p)
2504c5b9d96SManish Kurup 		kfree_rcu(p, rcu);
2514c5b9d96SManish Kurup }
2524c5b9d96SManish Kurup 
253c7e2b968SJiri Pirko static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a,
254c7e2b968SJiri Pirko 			 int bind, int ref)
255c7e2b968SJiri Pirko {
256c7e2b968SJiri Pirko 	unsigned char *b = skb_tail_pointer(skb);
257a85a970aSWANG Cong 	struct tcf_vlan *v = to_vlan(a);
258764e9a24SVlad Buslov 	struct tcf_vlan_params *p;
259c7e2b968SJiri Pirko 	struct tc_vlan opt = {
260c7e2b968SJiri Pirko 		.index    = v->tcf_index,
261036bb443SVlad Buslov 		.refcnt   = refcount_read(&v->tcf_refcnt) - ref,
262036bb443SVlad Buslov 		.bindcnt  = atomic_read(&v->tcf_bindcnt) - bind,
263c7e2b968SJiri Pirko 	};
264c7e2b968SJiri Pirko 	struct tcf_t t;
265c7e2b968SJiri Pirko 
266653cd284SVlad Buslov 	spin_lock_bh(&v->tcf_lock);
267764e9a24SVlad Buslov 	opt.action = v->tcf_action;
268764e9a24SVlad Buslov 	p = rcu_dereference_protected(v->vlan_p, lockdep_is_held(&v->tcf_lock));
269764e9a24SVlad Buslov 	opt.v_action = p->tcfv_action;
270c7e2b968SJiri Pirko 	if (nla_put(skb, TCA_VLAN_PARMS, sizeof(opt), &opt))
271c7e2b968SJiri Pirko 		goto nla_put_failure;
272c7e2b968SJiri Pirko 
2734c5b9d96SManish Kurup 	if ((p->tcfv_action == TCA_VLAN_ACT_PUSH ||
2744c5b9d96SManish Kurup 	     p->tcfv_action == TCA_VLAN_ACT_MODIFY) &&
2754c5b9d96SManish Kurup 	    (nla_put_u16(skb, TCA_VLAN_PUSH_VLAN_ID, p->tcfv_push_vid) ||
2760b0f43feSJamal Hadi Salim 	     nla_put_be16(skb, TCA_VLAN_PUSH_VLAN_PROTOCOL,
2774c5b9d96SManish Kurup 			  p->tcfv_push_proto) ||
278956af371SHadar Hen Zion 	     (nla_put_u8(skb, TCA_VLAN_PUSH_VLAN_PRIORITY,
2794c5b9d96SManish Kurup 					      p->tcfv_push_prio))))
280c7e2b968SJiri Pirko 		goto nla_put_failure;
281c7e2b968SJiri Pirko 
28248d8ee16SJamal Hadi Salim 	tcf_tm_dump(&t, &v->tcf_tm);
2839854518eSNicolas Dichtel 	if (nla_put_64bit(skb, TCA_VLAN_TM, sizeof(t), &t, TCA_VLAN_PAD))
284c7e2b968SJiri Pirko 		goto nla_put_failure;
285653cd284SVlad Buslov 	spin_unlock_bh(&v->tcf_lock);
286764e9a24SVlad Buslov 
287c7e2b968SJiri Pirko 	return skb->len;
288c7e2b968SJiri Pirko 
289c7e2b968SJiri Pirko nla_put_failure:
290653cd284SVlad Buslov 	spin_unlock_bh(&v->tcf_lock);
291c7e2b968SJiri Pirko 	nlmsg_trim(skb, b);
292c7e2b968SJiri Pirko 	return -1;
293c7e2b968SJiri Pirko }
294c7e2b968SJiri Pirko 
295ddf97ccdSWANG Cong static int tcf_vlan_walker(struct net *net, struct sk_buff *skb,
296ddf97ccdSWANG Cong 			   struct netlink_callback *cb, int type,
29741780105SAlexander Aring 			   const struct tc_action_ops *ops,
29841780105SAlexander Aring 			   struct netlink_ext_ack *extack)
299ddf97ccdSWANG Cong {
300ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, vlan_net_id);
301ddf97ccdSWANG Cong 
302b3620145SAlexander Aring 	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
303ddf97ccdSWANG Cong }
304ddf97ccdSWANG Cong 
3054b61d3e8SPo Liu static void tcf_vlan_stats_update(struct tc_action *a, u64 bytes, u64 packets,
3064b61d3e8SPo Liu 				  u64 drops, u64 lastuse, bool hw)
307fa730a3bSJiri Pirko {
308fa730a3bSJiri Pirko 	struct tcf_vlan *v = to_vlan(a);
309fa730a3bSJiri Pirko 	struct tcf_t *tm = &v->tcf_tm;
310fa730a3bSJiri Pirko 
3114b61d3e8SPo Liu 	tcf_action_update_stats(a, bytes, packets, drops, hw);
312fa730a3bSJiri Pirko 	tm->lastuse = max_t(u64, tm->lastuse, lastuse);
313fa730a3bSJiri Pirko }
314fa730a3bSJiri Pirko 
315f061b48cSCong Wang static int tcf_vlan_search(struct net *net, struct tc_action **a, u32 index)
316ddf97ccdSWANG Cong {
317ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, vlan_net_id);
318ddf97ccdSWANG Cong 
31965a206c0SChris Mi 	return tcf_idr_search(tn, a, index);
320ddf97ccdSWANG Cong }
321ddf97ccdSWANG Cong 
322b35475c5SRoman Mashak static size_t tcf_vlan_get_fill_size(const struct tc_action *act)
323b35475c5SRoman Mashak {
324b35475c5SRoman Mashak 	return nla_total_size(sizeof(struct tc_vlan))
325b35475c5SRoman Mashak 		+ nla_total_size(sizeof(u16)) /* TCA_VLAN_PUSH_VLAN_ID */
326b35475c5SRoman Mashak 		+ nla_total_size(sizeof(u16)) /* TCA_VLAN_PUSH_VLAN_PROTOCOL */
327b35475c5SRoman Mashak 		+ nla_total_size(sizeof(u8)); /* TCA_VLAN_PUSH_VLAN_PRIORITY */
328b35475c5SRoman Mashak }
329b35475c5SRoman Mashak 
330c7e2b968SJiri Pirko static struct tc_action_ops act_vlan_ops = {
331c7e2b968SJiri Pirko 	.kind		=	"vlan",
332eddd2cf1SEli Cohen 	.id		=	TCA_ID_VLAN,
333c7e2b968SJiri Pirko 	.owner		=	THIS_MODULE,
3348aa7f22eSJamal Hadi Salim 	.act		=	tcf_vlan_act,
335c7e2b968SJiri Pirko 	.dump		=	tcf_vlan_dump,
336c7e2b968SJiri Pirko 	.init		=	tcf_vlan_init,
3374c5b9d96SManish Kurup 	.cleanup	=	tcf_vlan_cleanup,
338ddf97ccdSWANG Cong 	.walk		=	tcf_vlan_walker,
339fa730a3bSJiri Pirko 	.stats_update	=	tcf_vlan_stats_update,
340b35475c5SRoman Mashak 	.get_fill_size	=	tcf_vlan_get_fill_size,
341ddf97ccdSWANG Cong 	.lookup		=	tcf_vlan_search,
342a85a970aSWANG Cong 	.size		=	sizeof(struct tcf_vlan),
343ddf97ccdSWANG Cong };
344ddf97ccdSWANG Cong 
345ddf97ccdSWANG Cong static __net_init int vlan_init_net(struct net *net)
346ddf97ccdSWANG Cong {
347ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, vlan_net_id);
348ddf97ccdSWANG Cong 
349981471bdSCong Wang 	return tc_action_net_init(net, tn, &act_vlan_ops);
350ddf97ccdSWANG Cong }
351ddf97ccdSWANG Cong 
352039af9c6SCong Wang static void __net_exit vlan_exit_net(struct list_head *net_list)
353ddf97ccdSWANG Cong {
354039af9c6SCong Wang 	tc_action_net_exit(net_list, vlan_net_id);
355ddf97ccdSWANG Cong }
356ddf97ccdSWANG Cong 
357ddf97ccdSWANG Cong static struct pernet_operations vlan_net_ops = {
358ddf97ccdSWANG Cong 	.init = vlan_init_net,
359039af9c6SCong Wang 	.exit_batch = vlan_exit_net,
360ddf97ccdSWANG Cong 	.id   = &vlan_net_id,
361ddf97ccdSWANG Cong 	.size = sizeof(struct tc_action_net),
362c7e2b968SJiri Pirko };
363c7e2b968SJiri Pirko 
364c7e2b968SJiri Pirko static int __init vlan_init_module(void)
365c7e2b968SJiri Pirko {
366ddf97ccdSWANG Cong 	return tcf_register_action(&act_vlan_ops, &vlan_net_ops);
367c7e2b968SJiri Pirko }
368c7e2b968SJiri Pirko 
369c7e2b968SJiri Pirko static void __exit vlan_cleanup_module(void)
370c7e2b968SJiri Pirko {
371ddf97ccdSWANG Cong 	tcf_unregister_action(&act_vlan_ops, &vlan_net_ops);
372c7e2b968SJiri Pirko }
373c7e2b968SJiri Pirko 
374c7e2b968SJiri Pirko module_init(vlan_init_module);
375c7e2b968SJiri Pirko module_exit(vlan_cleanup_module);
376c7e2b968SJiri Pirko 
377c7e2b968SJiri Pirko MODULE_AUTHOR("Jiri Pirko <jiri@resnulli.us>");
378c7e2b968SJiri Pirko MODULE_DESCRIPTION("vlan manipulation actions");
379c7e2b968SJiri Pirko MODULE_LICENSE("GPL v2");
380