1313#include <linux/netfilter.h>
1414#include <linux/netfilter/nf_tables.h>
1515#include <net/netfilter/nf_tables.h>
16+ #include <net/netfilter/nf_tables_core.h>
1617#include <net/netfilter/nf_tables_offload.h>
1718
1819struct nft_counter {
@@ -174,7 +175,7 @@ static const struct nla_policy nft_counter_policy[NFTA_COUNTER_MAX + 1] = {
174175 [NFTA_COUNTER_BYTES ] = { .type = NLA_U64 },
175176};
176177
177- static struct nft_object_type nft_counter_obj_type ;
178+ struct nft_object_type nft_counter_obj_type ;
178179static const struct nft_object_ops nft_counter_obj_ops = {
179180 .type = & nft_counter_obj_type ,
180181 .size = sizeof (struct nft_counter_percpu_priv ),
@@ -184,17 +185,16 @@ static const struct nft_object_ops nft_counter_obj_ops = {
184185 .dump = nft_counter_obj_dump ,
185186};
186187
187- static struct nft_object_type nft_counter_obj_type __read_mostly = {
188+ struct nft_object_type nft_counter_obj_type __read_mostly = {
188189 .type = NFT_OBJECT_COUNTER ,
189190 .ops = & nft_counter_obj_ops ,
190191 .maxattr = NFTA_COUNTER_MAX ,
191192 .policy = nft_counter_policy ,
192193 .owner = THIS_MODULE ,
193194};
194195
195- static void nft_counter_eval (const struct nft_expr * expr ,
196- struct nft_regs * regs ,
197- const struct nft_pktinfo * pkt )
196+ void nft_counter_eval (const struct nft_expr * expr , struct nft_regs * regs ,
197+ const struct nft_pktinfo * pkt )
198198{
199199 struct nft_counter_percpu_priv * priv = nft_expr_priv (expr );
200200
@@ -275,7 +275,15 @@ static void nft_counter_offload_stats(struct nft_expr *expr,
275275 preempt_enable ();
276276}
277277
278- static struct nft_expr_type nft_counter_type ;
278+ void nft_counter_init_seqcount (void )
279+ {
280+ int cpu ;
281+
282+ for_each_possible_cpu (cpu )
283+ seqcount_init (per_cpu_ptr (& nft_counter_seq , cpu ));
284+ }
285+
286+ struct nft_expr_type nft_counter_type ;
279287static const struct nft_expr_ops nft_counter_ops = {
280288 .type = & nft_counter_type ,
281289 .size = NFT_EXPR_SIZE (sizeof (struct nft_counter_percpu_priv )),
@@ -289,47 +297,11 @@ static const struct nft_expr_ops nft_counter_ops = {
289297 .offload_stats = nft_counter_offload_stats ,
290298};
291299
292- static struct nft_expr_type nft_counter_type __read_mostly = {
300+ struct nft_expr_type nft_counter_type __read_mostly = {
293301 .name = "counter" ,
294302 .ops = & nft_counter_ops ,
295303 .policy = nft_counter_policy ,
296304 .maxattr = NFTA_COUNTER_MAX ,
297305 .flags = NFT_EXPR_STATEFUL ,
298306 .owner = THIS_MODULE ,
299307};
300-
301- static int __init nft_counter_module_init (void )
302- {
303- int cpu , err ;
304-
305- for_each_possible_cpu (cpu )
306- seqcount_init (per_cpu_ptr (& nft_counter_seq , cpu ));
307-
308- err = nft_register_obj (& nft_counter_obj_type );
309- if (err < 0 )
310- return err ;
311-
312- err = nft_register_expr (& nft_counter_type );
313- if (err < 0 )
314- goto err1 ;
315-
316- return 0 ;
317- err1 :
318- nft_unregister_obj (& nft_counter_obj_type );
319- return err ;
320- }
321-
322- static void __exit nft_counter_module_exit (void )
323- {
324- nft_unregister_expr (& nft_counter_type );
325- nft_unregister_obj (& nft_counter_obj_type );
326- }
327-
328- module_init (nft_counter_module_init );
329- module_exit (nft_counter_module_exit );
330-
331- MODULE_LICENSE ("GPL" );
332- MODULE_AUTHOR ("Patrick McHardy <kaber@trash.net>" );
333- MODULE_ALIAS_NFT_EXPR ("counter" );
334- MODULE_ALIAS_NFT_OBJ (NFT_OBJECT_COUNTER );
335- MODULE_DESCRIPTION ("nftables counter rule support" );
0 commit comments