xref: /openbmc/linux/net/sched/act_police.c (revision 789871bb2a0381425b106d2a995bde1460d35a34)
14bba3925SPatrick McHardy /*
20c6965ddSJiri Pirko  * net/sched/act_police.c	Input police filter
34bba3925SPatrick McHardy  *
44bba3925SPatrick McHardy  *		This program is free software; you can redistribute it and/or
54bba3925SPatrick McHardy  *		modify it under the terms of the GNU General Public License
64bba3925SPatrick McHardy  *		as published by the Free Software Foundation; either version
74bba3925SPatrick McHardy  *		2 of the License, or (at your option) any later version.
84bba3925SPatrick McHardy  *
94bba3925SPatrick McHardy  * Authors:	Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
104bba3925SPatrick McHardy  * 		J Hadi Salim (action changes)
114bba3925SPatrick McHardy  */
124bba3925SPatrick McHardy 
134bba3925SPatrick McHardy #include <linux/module.h>
144bba3925SPatrick McHardy #include <linux/types.h>
154bba3925SPatrick McHardy #include <linux/kernel.h>
164bba3925SPatrick McHardy #include <linux/string.h>
174bba3925SPatrick McHardy #include <linux/errno.h>
184bba3925SPatrick McHardy #include <linux/skbuff.h>
194bba3925SPatrick McHardy #include <linux/rtnetlink.h>
204bba3925SPatrick McHardy #include <linux/init.h>
215a0e3ad6STejun Heo #include <linux/slab.h>
224bba3925SPatrick McHardy #include <net/act_api.h>
23dc5fc579SArnaldo Carvalho de Melo #include <net/netlink.h>
244bba3925SPatrick McHardy 
250e243218SJiri Pirko struct tcf_police {
26ec0595ccSWANG Cong 	struct tc_action	common;
270e243218SJiri Pirko 	int			tcfp_result;
280e243218SJiri Pirko 	u32			tcfp_ewma_rate;
29c6d14ff1SJiri Pirko 	s64			tcfp_burst;
300e243218SJiri Pirko 	u32			tcfp_mtu;
31c6d14ff1SJiri Pirko 	s64			tcfp_toks;
32c6d14ff1SJiri Pirko 	s64			tcfp_ptoks;
33c6d14ff1SJiri Pirko 	s64			tcfp_mtu_ptoks;
34c6d14ff1SJiri Pirko 	s64			tcfp_t_c;
35c6d14ff1SJiri Pirko 	struct psched_ratecfg	rate;
36c6d14ff1SJiri Pirko 	bool			rate_present;
37c6d14ff1SJiri Pirko 	struct psched_ratecfg	peak;
38c6d14ff1SJiri Pirko 	bool			peak_present;
390e243218SJiri Pirko };
40a85a970aSWANG Cong 
41a85a970aSWANG Cong #define to_police(pc) ((struct tcf_police *)pc)
420e243218SJiri Pirko 
431e9b3d53SPatrick McHardy /* old policer structure from before tc actions */
44cc7ec456SEric Dumazet struct tc_police_compat {
451e9b3d53SPatrick McHardy 	u32			index;
461e9b3d53SPatrick McHardy 	int			action;
471e9b3d53SPatrick McHardy 	u32			limit;
481e9b3d53SPatrick McHardy 	u32			burst;
491e9b3d53SPatrick McHardy 	u32			mtu;
501e9b3d53SPatrick McHardy 	struct tc_ratespec	rate;
511e9b3d53SPatrick McHardy 	struct tc_ratespec	peakrate;
521e9b3d53SPatrick McHardy };
531e9b3d53SPatrick McHardy 
544bba3925SPatrick McHardy /* Each policer is serialized by its individual spinlock */
554bba3925SPatrick McHardy 
56c7d03a00SAlexey Dobriyan static unsigned int police_net_id;
57a85a970aSWANG Cong static struct tc_action_ops act_police_ops;
58ddf97ccdSWANG Cong 
59ddf97ccdSWANG Cong static int tcf_act_police_walker(struct net *net, struct sk_buff *skb,
60ddf97ccdSWANG Cong 				 struct netlink_callback *cb, int type,
6141780105SAlexander Aring 				 const struct tc_action_ops *ops,
6241780105SAlexander Aring 				 struct netlink_ext_ack *extack)
634bba3925SPatrick McHardy {
64ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, police_net_id);
654bba3925SPatrick McHardy 
66b3620145SAlexander Aring 	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
674bba3925SPatrick McHardy }
684bba3925SPatrick McHardy 
6953b2bf3fSPatrick McHardy static const struct nla_policy police_policy[TCA_POLICE_MAX + 1] = {
7053b2bf3fSPatrick McHardy 	[TCA_POLICE_RATE]	= { .len = TC_RTAB_SIZE },
7153b2bf3fSPatrick McHardy 	[TCA_POLICE_PEAKRATE]	= { .len = TC_RTAB_SIZE },
7253b2bf3fSPatrick McHardy 	[TCA_POLICE_AVRATE]	= { .type = NLA_U32 },
7353b2bf3fSPatrick McHardy 	[TCA_POLICE_RESULT]	= { .type = NLA_U32 },
7453b2bf3fSPatrick McHardy };
7553b2bf3fSPatrick McHardy 
76d9fa17efSWANG Cong static int tcf_act_police_init(struct net *net, struct nlattr *nla,
77a85a970aSWANG Cong 			       struct nlattr *est, struct tc_action **a,
78*789871bbSVlad Buslov 			       int ovr, int bind, bool rtnl_held,
79589dad6dSAlexander Aring 			       struct netlink_ext_ack *extack)
804bba3925SPatrick McHardy {
814bba3925SPatrick McHardy 	int ret = 0, err;
827ba699c6SPatrick McHardy 	struct nlattr *tb[TCA_POLICE_MAX + 1];
834bba3925SPatrick McHardy 	struct tc_police *parm;
84e9ce1cd3SDavid S. Miller 	struct tcf_police *police;
854bba3925SPatrick McHardy 	struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL;
86ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, police_net_id);
870852e455SWANG Cong 	bool exists = false;
881e9b3d53SPatrick McHardy 	int size;
894bba3925SPatrick McHardy 
90cee63723SPatrick McHardy 	if (nla == NULL)
914bba3925SPatrick McHardy 		return -EINVAL;
924bba3925SPatrick McHardy 
93fceb6435SJohannes Berg 	err = nla_parse_nested(tb, TCA_POLICE_MAX, nla, police_policy, NULL);
94cee63723SPatrick McHardy 	if (err < 0)
95cee63723SPatrick McHardy 		return err;
96cee63723SPatrick McHardy 
977ba699c6SPatrick McHardy 	if (tb[TCA_POLICE_TBF] == NULL)
981e9b3d53SPatrick McHardy 		return -EINVAL;
997ba699c6SPatrick McHardy 	size = nla_len(tb[TCA_POLICE_TBF]);
1001e9b3d53SPatrick McHardy 	if (size != sizeof(*parm) && size != sizeof(struct tc_police_compat))
1014bba3925SPatrick McHardy 		return -EINVAL;
1024bba3925SPatrick McHardy 
1030852e455SWANG Cong 	parm = nla_data(tb[TCA_POLICE_TBF]);
10465a206c0SChris Mi 	exists = tcf_idr_check(tn, parm->index, a, bind);
1050852e455SWANG Cong 	if (exists && bind)
1060852e455SWANG Cong 		return 0;
1070852e455SWANG Cong 
1080852e455SWANG Cong 	if (!exists) {
10965a206c0SChris Mi 		ret = tcf_idr_create(tn, parm->index, NULL, a,
110a85a970aSWANG Cong 				     &act_police_ops, bind, false);
111a03e6fe5SWANG Cong 		if (ret)
112a03e6fe5SWANG Cong 			return ret;
113a03e6fe5SWANG Cong 		ret = ACT_P_CREATED;
1140852e455SWANG Cong 	} else {
11565a206c0SChris Mi 		tcf_idr_release(*a, bind);
1160852e455SWANG Cong 		if (!ovr)
1170852e455SWANG Cong 			return -EEXIST;
118e9ce1cd3SDavid S. Miller 	}
1194bba3925SPatrick McHardy 
120a85a970aSWANG Cong 	police = to_police(*a);
1214bba3925SPatrick McHardy 	if (parm->rate.rate) {
1224bba3925SPatrick McHardy 		err = -ENOMEM;
123e9bc3fa2SAlexander Aring 		R_tab = qdisc_get_rtab(&parm->rate, tb[TCA_POLICE_RATE], NULL);
1244bba3925SPatrick McHardy 		if (R_tab == NULL)
1254bba3925SPatrick McHardy 			goto failure;
126c1b56878SStephen Hemminger 
1274bba3925SPatrick McHardy 		if (parm->peakrate.rate) {
1284bba3925SPatrick McHardy 			P_tab = qdisc_get_rtab(&parm->peakrate,
129e9bc3fa2SAlexander Aring 					       tb[TCA_POLICE_PEAKRATE], NULL);
13071bcb09aSStephen Hemminger 			if (P_tab == NULL)
1314bba3925SPatrick McHardy 				goto failure;
1324bba3925SPatrick McHardy 		}
1334bba3925SPatrick McHardy 	}
13471bcb09aSStephen Hemminger 
13571bcb09aSStephen Hemminger 	if (est) {
13622e0f8b9SJohn Fastabend 		err = gen_replace_estimator(&police->tcf_bstats, NULL,
13771bcb09aSStephen Hemminger 					    &police->tcf_rate_est,
138edb09eb1SEric Dumazet 					    &police->tcf_lock,
139edb09eb1SEric Dumazet 					    NULL, est);
14071bcb09aSStephen Hemminger 		if (err)
14174030603SWANG Cong 			goto failure;
142a883bf56SJarek Poplawski 	} else if (tb[TCA_POLICE_AVRATE] &&
143a883bf56SJarek Poplawski 		   (ret == ACT_P_CREATED ||
1441c0d32fdSEric Dumazet 		    !gen_estimator_active(&police->tcf_rate_est))) {
145a883bf56SJarek Poplawski 		err = -EINVAL;
14674030603SWANG Cong 		goto failure;
14771bcb09aSStephen Hemminger 	}
14871bcb09aSStephen Hemminger 
14974030603SWANG Cong 	spin_lock_bh(&police->tcf_lock);
15071bcb09aSStephen Hemminger 	/* No failure allowed after this point */
151c6d14ff1SJiri Pirko 	police->tcfp_mtu = parm->mtu;
152c6d14ff1SJiri Pirko 	if (police->tcfp_mtu == 0) {
153c6d14ff1SJiri Pirko 		police->tcfp_mtu = ~0;
154c6d14ff1SJiri Pirko 		if (R_tab)
155c6d14ff1SJiri Pirko 			police->tcfp_mtu = 255 << R_tab->rate.cell_log;
1564bba3925SPatrick McHardy 	}
157c6d14ff1SJiri Pirko 	if (R_tab) {
158c6d14ff1SJiri Pirko 		police->rate_present = true;
1593e1e3aaeSEric Dumazet 		psched_ratecfg_precompute(&police->rate, &R_tab->rate, 0);
160c6d14ff1SJiri Pirko 		qdisc_put_rtab(R_tab);
161c6d14ff1SJiri Pirko 	} else {
162c6d14ff1SJiri Pirko 		police->rate_present = false;
163c6d14ff1SJiri Pirko 	}
164c6d14ff1SJiri Pirko 	if (P_tab) {
165c6d14ff1SJiri Pirko 		police->peak_present = true;
1663e1e3aaeSEric Dumazet 		psched_ratecfg_precompute(&police->peak, &P_tab->rate, 0);
167c6d14ff1SJiri Pirko 		qdisc_put_rtab(P_tab);
168c6d14ff1SJiri Pirko 	} else {
169c6d14ff1SJiri Pirko 		police->peak_present = false;
1704bba3925SPatrick McHardy 	}
1714bba3925SPatrick McHardy 
1727ba699c6SPatrick McHardy 	if (tb[TCA_POLICE_RESULT])
1731587bac4SPatrick McHardy 		police->tcfp_result = nla_get_u32(tb[TCA_POLICE_RESULT]);
174c6d14ff1SJiri Pirko 	police->tcfp_burst = PSCHED_TICKS2NS(parm->burst);
175c6d14ff1SJiri Pirko 	police->tcfp_toks = police->tcfp_burst;
176c6d14ff1SJiri Pirko 	if (police->peak_present) {
177c6d14ff1SJiri Pirko 		police->tcfp_mtu_ptoks = (s64) psched_l2t_ns(&police->peak,
178c6d14ff1SJiri Pirko 							     police->tcfp_mtu);
179c6d14ff1SJiri Pirko 		police->tcfp_ptoks = police->tcfp_mtu_ptoks;
1804bba3925SPatrick McHardy 	}
181e9ce1cd3SDavid S. Miller 	police->tcf_action = parm->action;
1824bba3925SPatrick McHardy 
1837ba699c6SPatrick McHardy 	if (tb[TCA_POLICE_AVRATE])
1841587bac4SPatrick McHardy 		police->tcfp_ewma_rate = nla_get_u32(tb[TCA_POLICE_AVRATE]);
1854bba3925SPatrick McHardy 
186e9ce1cd3SDavid S. Miller 	spin_unlock_bh(&police->tcf_lock);
1874bba3925SPatrick McHardy 	if (ret != ACT_P_CREATED)
1884bba3925SPatrick McHardy 		return ret;
1894bba3925SPatrick McHardy 
190d2de875cSEric Dumazet 	police->tcfp_t_c = ktime_get_ns();
19165a206c0SChris Mi 	tcf_idr_insert(tn, *a);
1924bba3925SPatrick McHardy 
1934bba3925SPatrick McHardy 	return ret;
1944bba3925SPatrick McHardy 
1954bba3925SPatrick McHardy failure:
19671bcb09aSStephen Hemminger 	qdisc_put_rtab(P_tab);
19771bcb09aSStephen Hemminger 	qdisc_put_rtab(R_tab);
1984bba3925SPatrick McHardy 	if (ret == ACT_P_CREATED)
1995bf7f818SDavide Caratti 		tcf_idr_release(*a, bind);
2004bba3925SPatrick McHardy 	return err;
2014bba3925SPatrick McHardy }
2024bba3925SPatrick McHardy 
203dc7f9f6eSEric Dumazet static int tcf_act_police(struct sk_buff *skb, const struct tc_action *a,
2044bba3925SPatrick McHardy 			  struct tcf_result *res)
2054bba3925SPatrick McHardy {
206a85a970aSWANG Cong 	struct tcf_police *police = to_police(a);
207c6d14ff1SJiri Pirko 	s64 now;
208c6d14ff1SJiri Pirko 	s64 toks;
209c6d14ff1SJiri Pirko 	s64 ptoks = 0;
2104bba3925SPatrick McHardy 
211e9ce1cd3SDavid S. Miller 	spin_lock(&police->tcf_lock);
2124bba3925SPatrick McHardy 
213bfe0d029SEric Dumazet 	bstats_update(&police->tcf_bstats, skb);
2143d3ed181SJamal Hadi Salim 	tcf_lastuse_update(&police->tcf_tm);
2154bba3925SPatrick McHardy 
2161c0d32fdSEric Dumazet 	if (police->tcfp_ewma_rate) {
2171c0d32fdSEric Dumazet 		struct gnet_stats_rate_est64 sample;
2181c0d32fdSEric Dumazet 
2191c0d32fdSEric Dumazet 		if (!gen_estimator_read(&police->tcf_rate_est, &sample) ||
2201c0d32fdSEric Dumazet 		    sample.bps >= police->tcfp_ewma_rate) {
221e9ce1cd3SDavid S. Miller 			police->tcf_qstats.overlimits++;
222b9647580SJarek Poplawski 			if (police->tcf_action == TC_ACT_SHOT)
223b9647580SJarek Poplawski 				police->tcf_qstats.drops++;
224e9ce1cd3SDavid S. Miller 			spin_unlock(&police->tcf_lock);
225e9ce1cd3SDavid S. Miller 			return police->tcf_action;
2264bba3925SPatrick McHardy 		}
2271c0d32fdSEric Dumazet 	}
2284bba3925SPatrick McHardy 
2290abf77e5SJussi Kivilinna 	if (qdisc_pkt_len(skb) <= police->tcfp_mtu) {
230c6d14ff1SJiri Pirko 		if (!police->rate_present) {
231e9ce1cd3SDavid S. Miller 			spin_unlock(&police->tcf_lock);
232e9ce1cd3SDavid S. Miller 			return police->tcfp_result;
2334bba3925SPatrick McHardy 		}
2344bba3925SPatrick McHardy 
235d2de875cSEric Dumazet 		now = ktime_get_ns();
236c6d14ff1SJiri Pirko 		toks = min_t(s64, now - police->tcfp_t_c,
237e9ce1cd3SDavid S. Miller 			     police->tcfp_burst);
238c6d14ff1SJiri Pirko 		if (police->peak_present) {
239e9ce1cd3SDavid S. Miller 			ptoks = toks + police->tcfp_ptoks;
240c6d14ff1SJiri Pirko 			if (ptoks > police->tcfp_mtu_ptoks)
241c6d14ff1SJiri Pirko 				ptoks = police->tcfp_mtu_ptoks;
242c6d14ff1SJiri Pirko 			ptoks -= (s64) psched_l2t_ns(&police->peak,
243c6d14ff1SJiri Pirko 						     qdisc_pkt_len(skb));
2444bba3925SPatrick McHardy 		}
245e9ce1cd3SDavid S. Miller 		toks += police->tcfp_toks;
246c6d14ff1SJiri Pirko 		if (toks > police->tcfp_burst)
247e9ce1cd3SDavid S. Miller 			toks = police->tcfp_burst;
248c6d14ff1SJiri Pirko 		toks -= (s64) psched_l2t_ns(&police->rate, qdisc_pkt_len(skb));
2494bba3925SPatrick McHardy 		if ((toks|ptoks) >= 0) {
250e9ce1cd3SDavid S. Miller 			police->tcfp_t_c = now;
251e9ce1cd3SDavid S. Miller 			police->tcfp_toks = toks;
252e9ce1cd3SDavid S. Miller 			police->tcfp_ptoks = ptoks;
253f71b109fSRoman Mashak 			if (police->tcfp_result == TC_ACT_SHOT)
254f71b109fSRoman Mashak 				police->tcf_qstats.drops++;
255e9ce1cd3SDavid S. Miller 			spin_unlock(&police->tcf_lock);
256e9ce1cd3SDavid S. Miller 			return police->tcfp_result;
2574bba3925SPatrick McHardy 		}
2584bba3925SPatrick McHardy 	}
2594bba3925SPatrick McHardy 
260e9ce1cd3SDavid S. Miller 	police->tcf_qstats.overlimits++;
261b9647580SJarek Poplawski 	if (police->tcf_action == TC_ACT_SHOT)
262b9647580SJarek Poplawski 		police->tcf_qstats.drops++;
263e9ce1cd3SDavid S. Miller 	spin_unlock(&police->tcf_lock);
264e9ce1cd3SDavid S. Miller 	return police->tcf_action;
2654bba3925SPatrick McHardy }
2664bba3925SPatrick McHardy 
2675a7a5555SJamal Hadi Salim static int tcf_act_police_dump(struct sk_buff *skb, struct tc_action *a,
2685a7a5555SJamal Hadi Salim 			       int bind, int ref)
2694bba3925SPatrick McHardy {
27027a884dcSArnaldo Carvalho de Melo 	unsigned char *b = skb_tail_pointer(skb);
271a85a970aSWANG Cong 	struct tcf_police *police = to_police(a);
2720f04cfd0SJeff Mahoney 	struct tc_police opt = {
2730f04cfd0SJeff Mahoney 		.index = police->tcf_index,
2740f04cfd0SJeff Mahoney 		.action = police->tcf_action,
2750f04cfd0SJeff Mahoney 		.mtu = police->tcfp_mtu,
276c6d14ff1SJiri Pirko 		.burst = PSCHED_NS2TICKS(police->tcfp_burst),
277036bb443SVlad Buslov 		.refcnt = refcount_read(&police->tcf_refcnt) - ref,
278036bb443SVlad Buslov 		.bindcnt = atomic_read(&police->tcf_bindcnt) - bind,
2790f04cfd0SJeff Mahoney 	};
2803d3ed181SJamal Hadi Salim 	struct tcf_t t;
2814bba3925SPatrick McHardy 
282c6d14ff1SJiri Pirko 	if (police->rate_present)
28301cb71d2SEric Dumazet 		psched_ratecfg_getrate(&opt.rate, &police->rate);
284c6d14ff1SJiri Pirko 	if (police->peak_present)
28501cb71d2SEric Dumazet 		psched_ratecfg_getrate(&opt.peakrate, &police->peak);
2861b34ec43SDavid S. Miller 	if (nla_put(skb, TCA_POLICE_TBF, sizeof(opt), &opt))
2871b34ec43SDavid S. Miller 		goto nla_put_failure;
2881b34ec43SDavid S. Miller 	if (police->tcfp_result &&
2891b34ec43SDavid S. Miller 	    nla_put_u32(skb, TCA_POLICE_RESULT, police->tcfp_result))
2901b34ec43SDavid S. Miller 		goto nla_put_failure;
2911b34ec43SDavid S. Miller 	if (police->tcfp_ewma_rate &&
2921b34ec43SDavid S. Miller 	    nla_put_u32(skb, TCA_POLICE_AVRATE, police->tcfp_ewma_rate))
2931b34ec43SDavid S. Miller 		goto nla_put_failure;
2943d3ed181SJamal Hadi Salim 
2953d3ed181SJamal Hadi Salim 	t.install = jiffies_to_clock_t(jiffies - police->tcf_tm.install);
2963d3ed181SJamal Hadi Salim 	t.lastuse = jiffies_to_clock_t(jiffies - police->tcf_tm.lastuse);
29753eb440fSJamal Hadi Salim 	t.firstuse = jiffies_to_clock_t(jiffies - police->tcf_tm.firstuse);
2983d3ed181SJamal Hadi Salim 	t.expires = jiffies_to_clock_t(police->tcf_tm.expires);
2993d3ed181SJamal Hadi Salim 	if (nla_put_64bit(skb, TCA_POLICE_TM, sizeof(t), &t, TCA_POLICE_PAD))
3003d3ed181SJamal Hadi Salim 		goto nla_put_failure;
3013d3ed181SJamal Hadi Salim 
3024bba3925SPatrick McHardy 	return skb->len;
3034bba3925SPatrick McHardy 
3047ba699c6SPatrick McHardy nla_put_failure:
305dc5fc579SArnaldo Carvalho de Melo 	nlmsg_trim(skb, b);
3064bba3925SPatrick McHardy 	return -1;
3074bba3925SPatrick McHardy }
3084bba3925SPatrick McHardy 
309331a9295SAlexander Aring static int tcf_police_search(struct net *net, struct tc_action **a, u32 index,
310331a9295SAlexander Aring 			     struct netlink_ext_ack *extack)
311ddf97ccdSWANG Cong {
312ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, police_net_id);
313ddf97ccdSWANG Cong 
31465a206c0SChris Mi 	return tcf_idr_search(tn, a, index);
315ddf97ccdSWANG Cong }
316ddf97ccdSWANG Cong 
3174bba3925SPatrick McHardy MODULE_AUTHOR("Alexey Kuznetsov");
3184bba3925SPatrick McHardy MODULE_DESCRIPTION("Policing actions");
3194bba3925SPatrick McHardy MODULE_LICENSE("GPL");
3204bba3925SPatrick McHardy 
3214bba3925SPatrick McHardy static struct tc_action_ops act_police_ops = {
3224bba3925SPatrick McHardy 	.kind		=	"police",
3234bba3925SPatrick McHardy 	.type		=	TCA_ID_POLICE,
3244bba3925SPatrick McHardy 	.owner		=	THIS_MODULE,
3254bba3925SPatrick McHardy 	.act		=	tcf_act_police,
3264bba3925SPatrick McHardy 	.dump		=	tcf_act_police_dump,
327d9fa17efSWANG Cong 	.init		=	tcf_act_police_init,
328ddf97ccdSWANG Cong 	.walk		=	tcf_act_police_walker,
329ddf97ccdSWANG Cong 	.lookup		=	tcf_police_search,
330a85a970aSWANG Cong 	.size		=	sizeof(struct tcf_police),
331ddf97ccdSWANG Cong };
332ddf97ccdSWANG Cong 
333ddf97ccdSWANG Cong static __net_init int police_init_net(struct net *net)
334ddf97ccdSWANG Cong {
335ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, police_net_id);
336ddf97ccdSWANG Cong 
337c7e460ceSCong Wang 	return tc_action_net_init(tn, &act_police_ops);
338ddf97ccdSWANG Cong }
339ddf97ccdSWANG Cong 
340039af9c6SCong Wang static void __net_exit police_exit_net(struct list_head *net_list)
341ddf97ccdSWANG Cong {
342039af9c6SCong Wang 	tc_action_net_exit(net_list, police_net_id);
343ddf97ccdSWANG Cong }
344ddf97ccdSWANG Cong 
345ddf97ccdSWANG Cong static struct pernet_operations police_net_ops = {
346ddf97ccdSWANG Cong 	.init = police_init_net,
347039af9c6SCong Wang 	.exit_batch = police_exit_net,
348ddf97ccdSWANG Cong 	.id   = &police_net_id,
349ddf97ccdSWANG Cong 	.size = sizeof(struct tc_action_net),
3504bba3925SPatrick McHardy };
3514bba3925SPatrick McHardy 
3525a7a5555SJamal Hadi Salim static int __init police_init_module(void)
3534bba3925SPatrick McHardy {
354ddf97ccdSWANG Cong 	return tcf_register_action(&act_police_ops, &police_net_ops);
3554bba3925SPatrick McHardy }
3564bba3925SPatrick McHardy 
3575a7a5555SJamal Hadi Salim static void __exit police_cleanup_module(void)
3584bba3925SPatrick McHardy {
359ddf97ccdSWANG Cong 	tcf_unregister_action(&act_police_ops, &police_net_ops);
3604bba3925SPatrick McHardy }
3614bba3925SPatrick McHardy 
3624bba3925SPatrick McHardy module_init(police_init_module);
3634bba3925SPatrick McHardy module_exit(police_cleanup_module);
364