xref: /openbmc/linux/net/sched/act_police.c (revision 4e8ddd7f1758ca4ddd0c1f7cf3e66fce736241d2)
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,
78789871bbSVlad 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;
114*4e8ddd7fSVlad Buslov 	} else if (!ovr) {
11565a206c0SChris Mi 		tcf_idr_release(*a, bind);
1160852e455SWANG Cong 		return -EEXIST;
117e9ce1cd3SDavid S. Miller 	}
1184bba3925SPatrick McHardy 
119a85a970aSWANG Cong 	police = to_police(*a);
1204bba3925SPatrick McHardy 	if (parm->rate.rate) {
1214bba3925SPatrick McHardy 		err = -ENOMEM;
122e9bc3fa2SAlexander Aring 		R_tab = qdisc_get_rtab(&parm->rate, tb[TCA_POLICE_RATE], NULL);
1234bba3925SPatrick McHardy 		if (R_tab == NULL)
1244bba3925SPatrick McHardy 			goto failure;
125c1b56878SStephen Hemminger 
1264bba3925SPatrick McHardy 		if (parm->peakrate.rate) {
1274bba3925SPatrick McHardy 			P_tab = qdisc_get_rtab(&parm->peakrate,
128e9bc3fa2SAlexander Aring 					       tb[TCA_POLICE_PEAKRATE], NULL);
12971bcb09aSStephen Hemminger 			if (P_tab == NULL)
1304bba3925SPatrick McHardy 				goto failure;
1314bba3925SPatrick McHardy 		}
1324bba3925SPatrick McHardy 	}
13371bcb09aSStephen Hemminger 
13471bcb09aSStephen Hemminger 	if (est) {
13522e0f8b9SJohn Fastabend 		err = gen_replace_estimator(&police->tcf_bstats, NULL,
13671bcb09aSStephen Hemminger 					    &police->tcf_rate_est,
137edb09eb1SEric Dumazet 					    &police->tcf_lock,
138edb09eb1SEric Dumazet 					    NULL, est);
13971bcb09aSStephen Hemminger 		if (err)
14074030603SWANG Cong 			goto failure;
141a883bf56SJarek Poplawski 	} else if (tb[TCA_POLICE_AVRATE] &&
142a883bf56SJarek Poplawski 		   (ret == ACT_P_CREATED ||
1431c0d32fdSEric Dumazet 		    !gen_estimator_active(&police->tcf_rate_est))) {
144a883bf56SJarek Poplawski 		err = -EINVAL;
14574030603SWANG Cong 		goto failure;
14671bcb09aSStephen Hemminger 	}
14771bcb09aSStephen Hemminger 
14874030603SWANG Cong 	spin_lock_bh(&police->tcf_lock);
14971bcb09aSStephen Hemminger 	/* No failure allowed after this point */
150c6d14ff1SJiri Pirko 	police->tcfp_mtu = parm->mtu;
151c6d14ff1SJiri Pirko 	if (police->tcfp_mtu == 0) {
152c6d14ff1SJiri Pirko 		police->tcfp_mtu = ~0;
153c6d14ff1SJiri Pirko 		if (R_tab)
154c6d14ff1SJiri Pirko 			police->tcfp_mtu = 255 << R_tab->rate.cell_log;
1554bba3925SPatrick McHardy 	}
156c6d14ff1SJiri Pirko 	if (R_tab) {
157c6d14ff1SJiri Pirko 		police->rate_present = true;
1583e1e3aaeSEric Dumazet 		psched_ratecfg_precompute(&police->rate, &R_tab->rate, 0);
159c6d14ff1SJiri Pirko 		qdisc_put_rtab(R_tab);
160c6d14ff1SJiri Pirko 	} else {
161c6d14ff1SJiri Pirko 		police->rate_present = false;
162c6d14ff1SJiri Pirko 	}
163c6d14ff1SJiri Pirko 	if (P_tab) {
164c6d14ff1SJiri Pirko 		police->peak_present = true;
1653e1e3aaeSEric Dumazet 		psched_ratecfg_precompute(&police->peak, &P_tab->rate, 0);
166c6d14ff1SJiri Pirko 		qdisc_put_rtab(P_tab);
167c6d14ff1SJiri Pirko 	} else {
168c6d14ff1SJiri Pirko 		police->peak_present = false;
1694bba3925SPatrick McHardy 	}
1704bba3925SPatrick McHardy 
1717ba699c6SPatrick McHardy 	if (tb[TCA_POLICE_RESULT])
1721587bac4SPatrick McHardy 		police->tcfp_result = nla_get_u32(tb[TCA_POLICE_RESULT]);
173c6d14ff1SJiri Pirko 	police->tcfp_burst = PSCHED_TICKS2NS(parm->burst);
174c6d14ff1SJiri Pirko 	police->tcfp_toks = police->tcfp_burst;
175c6d14ff1SJiri Pirko 	if (police->peak_present) {
176c6d14ff1SJiri Pirko 		police->tcfp_mtu_ptoks = (s64) psched_l2t_ns(&police->peak,
177c6d14ff1SJiri Pirko 							     police->tcfp_mtu);
178c6d14ff1SJiri Pirko 		police->tcfp_ptoks = police->tcfp_mtu_ptoks;
1794bba3925SPatrick McHardy 	}
180e9ce1cd3SDavid S. Miller 	police->tcf_action = parm->action;
1814bba3925SPatrick McHardy 
1827ba699c6SPatrick McHardy 	if (tb[TCA_POLICE_AVRATE])
1831587bac4SPatrick McHardy 		police->tcfp_ewma_rate = nla_get_u32(tb[TCA_POLICE_AVRATE]);
1844bba3925SPatrick McHardy 
185e9ce1cd3SDavid S. Miller 	spin_unlock_bh(&police->tcf_lock);
1864bba3925SPatrick McHardy 	if (ret != ACT_P_CREATED)
1874bba3925SPatrick McHardy 		return ret;
1884bba3925SPatrick McHardy 
189d2de875cSEric Dumazet 	police->tcfp_t_c = ktime_get_ns();
19065a206c0SChris Mi 	tcf_idr_insert(tn, *a);
1914bba3925SPatrick McHardy 
1924bba3925SPatrick McHardy 	return ret;
1934bba3925SPatrick McHardy 
1944bba3925SPatrick McHardy failure:
19571bcb09aSStephen Hemminger 	qdisc_put_rtab(P_tab);
19671bcb09aSStephen Hemminger 	qdisc_put_rtab(R_tab);
1975bf7f818SDavide Caratti 	tcf_idr_release(*a, bind);
1984bba3925SPatrick McHardy 	return err;
1994bba3925SPatrick McHardy }
2004bba3925SPatrick McHardy 
201dc7f9f6eSEric Dumazet static int tcf_act_police(struct sk_buff *skb, const struct tc_action *a,
2024bba3925SPatrick McHardy 			  struct tcf_result *res)
2034bba3925SPatrick McHardy {
204a85a970aSWANG Cong 	struct tcf_police *police = to_police(a);
205c6d14ff1SJiri Pirko 	s64 now;
206c6d14ff1SJiri Pirko 	s64 toks;
207c6d14ff1SJiri Pirko 	s64 ptoks = 0;
2084bba3925SPatrick McHardy 
209e9ce1cd3SDavid S. Miller 	spin_lock(&police->tcf_lock);
2104bba3925SPatrick McHardy 
211bfe0d029SEric Dumazet 	bstats_update(&police->tcf_bstats, skb);
2123d3ed181SJamal Hadi Salim 	tcf_lastuse_update(&police->tcf_tm);
2134bba3925SPatrick McHardy 
2141c0d32fdSEric Dumazet 	if (police->tcfp_ewma_rate) {
2151c0d32fdSEric Dumazet 		struct gnet_stats_rate_est64 sample;
2161c0d32fdSEric Dumazet 
2171c0d32fdSEric Dumazet 		if (!gen_estimator_read(&police->tcf_rate_est, &sample) ||
2181c0d32fdSEric Dumazet 		    sample.bps >= police->tcfp_ewma_rate) {
219e9ce1cd3SDavid S. Miller 			police->tcf_qstats.overlimits++;
220b9647580SJarek Poplawski 			if (police->tcf_action == TC_ACT_SHOT)
221b9647580SJarek Poplawski 				police->tcf_qstats.drops++;
222e9ce1cd3SDavid S. Miller 			spin_unlock(&police->tcf_lock);
223e9ce1cd3SDavid S. Miller 			return police->tcf_action;
2244bba3925SPatrick McHardy 		}
2251c0d32fdSEric Dumazet 	}
2264bba3925SPatrick McHardy 
2270abf77e5SJussi Kivilinna 	if (qdisc_pkt_len(skb) <= police->tcfp_mtu) {
228c6d14ff1SJiri Pirko 		if (!police->rate_present) {
229e9ce1cd3SDavid S. Miller 			spin_unlock(&police->tcf_lock);
230e9ce1cd3SDavid S. Miller 			return police->tcfp_result;
2314bba3925SPatrick McHardy 		}
2324bba3925SPatrick McHardy 
233d2de875cSEric Dumazet 		now = ktime_get_ns();
234c6d14ff1SJiri Pirko 		toks = min_t(s64, now - police->tcfp_t_c,
235e9ce1cd3SDavid S. Miller 			     police->tcfp_burst);
236c6d14ff1SJiri Pirko 		if (police->peak_present) {
237e9ce1cd3SDavid S. Miller 			ptoks = toks + police->tcfp_ptoks;
238c6d14ff1SJiri Pirko 			if (ptoks > police->tcfp_mtu_ptoks)
239c6d14ff1SJiri Pirko 				ptoks = police->tcfp_mtu_ptoks;
240c6d14ff1SJiri Pirko 			ptoks -= (s64) psched_l2t_ns(&police->peak,
241c6d14ff1SJiri Pirko 						     qdisc_pkt_len(skb));
2424bba3925SPatrick McHardy 		}
243e9ce1cd3SDavid S. Miller 		toks += police->tcfp_toks;
244c6d14ff1SJiri Pirko 		if (toks > police->tcfp_burst)
245e9ce1cd3SDavid S. Miller 			toks = police->tcfp_burst;
246c6d14ff1SJiri Pirko 		toks -= (s64) psched_l2t_ns(&police->rate, qdisc_pkt_len(skb));
2474bba3925SPatrick McHardy 		if ((toks|ptoks) >= 0) {
248e9ce1cd3SDavid S. Miller 			police->tcfp_t_c = now;
249e9ce1cd3SDavid S. Miller 			police->tcfp_toks = toks;
250e9ce1cd3SDavid S. Miller 			police->tcfp_ptoks = ptoks;
251f71b109fSRoman Mashak 			if (police->tcfp_result == TC_ACT_SHOT)
252f71b109fSRoman Mashak 				police->tcf_qstats.drops++;
253e9ce1cd3SDavid S. Miller 			spin_unlock(&police->tcf_lock);
254e9ce1cd3SDavid S. Miller 			return police->tcfp_result;
2554bba3925SPatrick McHardy 		}
2564bba3925SPatrick McHardy 	}
2574bba3925SPatrick McHardy 
258e9ce1cd3SDavid S. Miller 	police->tcf_qstats.overlimits++;
259b9647580SJarek Poplawski 	if (police->tcf_action == TC_ACT_SHOT)
260b9647580SJarek Poplawski 		police->tcf_qstats.drops++;
261e9ce1cd3SDavid S. Miller 	spin_unlock(&police->tcf_lock);
262e9ce1cd3SDavid S. Miller 	return police->tcf_action;
2634bba3925SPatrick McHardy }
2644bba3925SPatrick McHardy 
2655a7a5555SJamal Hadi Salim static int tcf_act_police_dump(struct sk_buff *skb, struct tc_action *a,
2665a7a5555SJamal Hadi Salim 			       int bind, int ref)
2674bba3925SPatrick McHardy {
26827a884dcSArnaldo Carvalho de Melo 	unsigned char *b = skb_tail_pointer(skb);
269a85a970aSWANG Cong 	struct tcf_police *police = to_police(a);
2700f04cfd0SJeff Mahoney 	struct tc_police opt = {
2710f04cfd0SJeff Mahoney 		.index = police->tcf_index,
2720f04cfd0SJeff Mahoney 		.action = police->tcf_action,
2730f04cfd0SJeff Mahoney 		.mtu = police->tcfp_mtu,
274c6d14ff1SJiri Pirko 		.burst = PSCHED_NS2TICKS(police->tcfp_burst),
275036bb443SVlad Buslov 		.refcnt = refcount_read(&police->tcf_refcnt) - ref,
276036bb443SVlad Buslov 		.bindcnt = atomic_read(&police->tcf_bindcnt) - bind,
2770f04cfd0SJeff Mahoney 	};
2783d3ed181SJamal Hadi Salim 	struct tcf_t t;
2794bba3925SPatrick McHardy 
280c6d14ff1SJiri Pirko 	if (police->rate_present)
28101cb71d2SEric Dumazet 		psched_ratecfg_getrate(&opt.rate, &police->rate);
282c6d14ff1SJiri Pirko 	if (police->peak_present)
28301cb71d2SEric Dumazet 		psched_ratecfg_getrate(&opt.peakrate, &police->peak);
2841b34ec43SDavid S. Miller 	if (nla_put(skb, TCA_POLICE_TBF, sizeof(opt), &opt))
2851b34ec43SDavid S. Miller 		goto nla_put_failure;
2861b34ec43SDavid S. Miller 	if (police->tcfp_result &&
2871b34ec43SDavid S. Miller 	    nla_put_u32(skb, TCA_POLICE_RESULT, police->tcfp_result))
2881b34ec43SDavid S. Miller 		goto nla_put_failure;
2891b34ec43SDavid S. Miller 	if (police->tcfp_ewma_rate &&
2901b34ec43SDavid S. Miller 	    nla_put_u32(skb, TCA_POLICE_AVRATE, police->tcfp_ewma_rate))
2911b34ec43SDavid S. Miller 		goto nla_put_failure;
2923d3ed181SJamal Hadi Salim 
2933d3ed181SJamal Hadi Salim 	t.install = jiffies_to_clock_t(jiffies - police->tcf_tm.install);
2943d3ed181SJamal Hadi Salim 	t.lastuse = jiffies_to_clock_t(jiffies - police->tcf_tm.lastuse);
29553eb440fSJamal Hadi Salim 	t.firstuse = jiffies_to_clock_t(jiffies - police->tcf_tm.firstuse);
2963d3ed181SJamal Hadi Salim 	t.expires = jiffies_to_clock_t(police->tcf_tm.expires);
2973d3ed181SJamal Hadi Salim 	if (nla_put_64bit(skb, TCA_POLICE_TM, sizeof(t), &t, TCA_POLICE_PAD))
2983d3ed181SJamal Hadi Salim 		goto nla_put_failure;
2993d3ed181SJamal Hadi Salim 
3004bba3925SPatrick McHardy 	return skb->len;
3014bba3925SPatrick McHardy 
3027ba699c6SPatrick McHardy nla_put_failure:
303dc5fc579SArnaldo Carvalho de Melo 	nlmsg_trim(skb, b);
3044bba3925SPatrick McHardy 	return -1;
3054bba3925SPatrick McHardy }
3064bba3925SPatrick McHardy 
307331a9295SAlexander Aring static int tcf_police_search(struct net *net, struct tc_action **a, u32 index,
308331a9295SAlexander Aring 			     struct netlink_ext_ack *extack)
309ddf97ccdSWANG Cong {
310ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, police_net_id);
311ddf97ccdSWANG Cong 
31265a206c0SChris Mi 	return tcf_idr_search(tn, a, index);
313ddf97ccdSWANG Cong }
314ddf97ccdSWANG Cong 
315b409074eSVlad Buslov static int tcf_police_delete(struct net *net, u32 index)
316b409074eSVlad Buslov {
317b409074eSVlad Buslov 	struct tc_action_net *tn = net_generic(net, police_net_id);
318b409074eSVlad Buslov 
319b409074eSVlad Buslov 	return tcf_idr_delete_index(tn, index);
320b409074eSVlad Buslov }
321b409074eSVlad Buslov 
3224bba3925SPatrick McHardy MODULE_AUTHOR("Alexey Kuznetsov");
3234bba3925SPatrick McHardy MODULE_DESCRIPTION("Policing actions");
3244bba3925SPatrick McHardy MODULE_LICENSE("GPL");
3254bba3925SPatrick McHardy 
3264bba3925SPatrick McHardy static struct tc_action_ops act_police_ops = {
3274bba3925SPatrick McHardy 	.kind		=	"police",
3284bba3925SPatrick McHardy 	.type		=	TCA_ID_POLICE,
3294bba3925SPatrick McHardy 	.owner		=	THIS_MODULE,
3304bba3925SPatrick McHardy 	.act		=	tcf_act_police,
3314bba3925SPatrick McHardy 	.dump		=	tcf_act_police_dump,
332d9fa17efSWANG Cong 	.init		=	tcf_act_police_init,
333ddf97ccdSWANG Cong 	.walk		=	tcf_act_police_walker,
334ddf97ccdSWANG Cong 	.lookup		=	tcf_police_search,
335b409074eSVlad Buslov 	.delete		=	tcf_police_delete,
336a85a970aSWANG Cong 	.size		=	sizeof(struct tcf_police),
337ddf97ccdSWANG Cong };
338ddf97ccdSWANG Cong 
339ddf97ccdSWANG Cong static __net_init int police_init_net(struct net *net)
340ddf97ccdSWANG Cong {
341ddf97ccdSWANG Cong 	struct tc_action_net *tn = net_generic(net, police_net_id);
342ddf97ccdSWANG Cong 
343c7e460ceSCong Wang 	return tc_action_net_init(tn, &act_police_ops);
344ddf97ccdSWANG Cong }
345ddf97ccdSWANG Cong 
346039af9c6SCong Wang static void __net_exit police_exit_net(struct list_head *net_list)
347ddf97ccdSWANG Cong {
348039af9c6SCong Wang 	tc_action_net_exit(net_list, police_net_id);
349ddf97ccdSWANG Cong }
350ddf97ccdSWANG Cong 
351ddf97ccdSWANG Cong static struct pernet_operations police_net_ops = {
352ddf97ccdSWANG Cong 	.init = police_init_net,
353039af9c6SCong Wang 	.exit_batch = police_exit_net,
354ddf97ccdSWANG Cong 	.id   = &police_net_id,
355ddf97ccdSWANG Cong 	.size = sizeof(struct tc_action_net),
3564bba3925SPatrick McHardy };
3574bba3925SPatrick McHardy 
3585a7a5555SJamal Hadi Salim static int __init police_init_module(void)
3594bba3925SPatrick McHardy {
360ddf97ccdSWANG Cong 	return tcf_register_action(&act_police_ops, &police_net_ops);
3614bba3925SPatrick McHardy }
3624bba3925SPatrick McHardy 
3635a7a5555SJamal Hadi Salim static void __exit police_cleanup_module(void)
3644bba3925SPatrick McHardy {
365ddf97ccdSWANG Cong 	tcf_unregister_action(&act_police_ops, &police_net_ops);
3664bba3925SPatrick McHardy }
3674bba3925SPatrick McHardy 
3684bba3925SPatrick McHardy module_init(police_init_module);
3694bba3925SPatrick McHardy module_exit(police_cleanup_module);
370