ACPI: thermal: Install Notify() handler directly
[linux-block.git] / net / netfilter / nft_set_hash.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2008-2014 Patrick McHardy <kaber@trash.net>
4  *
5  * Development of this code funded by Astaro AG (http://www.astaro.com/)
6  */
7
8 #include <linux/kernel.h>
9 #include <linux/init.h>
10 #include <linux/module.h>
11 #include <linux/list.h>
12 #include <linux/log2.h>
13 #include <linux/jhash.h>
14 #include <linux/netlink.h>
15 #include <linux/workqueue.h>
16 #include <linux/rhashtable.h>
17 #include <linux/netfilter.h>
18 #include <linux/netfilter/nf_tables.h>
19 #include <net/netfilter/nf_tables_core.h>
20
21 /* We target a hash table size of 4, element hint is 75% of final size */
22 #define NFT_RHASH_ELEMENT_HINT 3
23
24 struct nft_rhash {
25         struct rhashtable               ht;
26         struct delayed_work             gc_work;
27 };
28
29 struct nft_rhash_elem {
30         struct rhash_head               node;
31         struct nft_set_ext              ext;
32 };
33
34 struct nft_rhash_cmp_arg {
35         const struct nft_set            *set;
36         const u32                       *key;
37         u8                              genmask;
38 };
39
40 static inline u32 nft_rhash_key(const void *data, u32 len, u32 seed)
41 {
42         const struct nft_rhash_cmp_arg *arg = data;
43
44         return jhash(arg->key, len, seed);
45 }
46
47 static inline u32 nft_rhash_obj(const void *data, u32 len, u32 seed)
48 {
49         const struct nft_rhash_elem *he = data;
50
51         return jhash(nft_set_ext_key(&he->ext), len, seed);
52 }
53
54 static inline int nft_rhash_cmp(struct rhashtable_compare_arg *arg,
55                                 const void *ptr)
56 {
57         const struct nft_rhash_cmp_arg *x = arg->key;
58         const struct nft_rhash_elem *he = ptr;
59
60         if (memcmp(nft_set_ext_key(&he->ext), x->key, x->set->klen))
61                 return 1;
62         if (nft_set_elem_expired(&he->ext))
63                 return 1;
64         if (!nft_set_elem_active(&he->ext, x->genmask))
65                 return 1;
66         return 0;
67 }
68
69 static const struct rhashtable_params nft_rhash_params = {
70         .head_offset            = offsetof(struct nft_rhash_elem, node),
71         .hashfn                 = nft_rhash_key,
72         .obj_hashfn             = nft_rhash_obj,
73         .obj_cmpfn              = nft_rhash_cmp,
74         .automatic_shrinking    = true,
75 };
76
77 INDIRECT_CALLABLE_SCOPE
78 bool nft_rhash_lookup(const struct net *net, const struct nft_set *set,
79                       const u32 *key, const struct nft_set_ext **ext)
80 {
81         struct nft_rhash *priv = nft_set_priv(set);
82         const struct nft_rhash_elem *he;
83         struct nft_rhash_cmp_arg arg = {
84                 .genmask = nft_genmask_cur(net),
85                 .set     = set,
86                 .key     = key,
87         };
88
89         he = rhashtable_lookup(&priv->ht, &arg, nft_rhash_params);
90         if (he != NULL)
91                 *ext = &he->ext;
92
93         return !!he;
94 }
95
96 static void *nft_rhash_get(const struct net *net, const struct nft_set *set,
97                            const struct nft_set_elem *elem, unsigned int flags)
98 {
99         struct nft_rhash *priv = nft_set_priv(set);
100         struct nft_rhash_elem *he;
101         struct nft_rhash_cmp_arg arg = {
102                 .genmask = nft_genmask_cur(net),
103                 .set     = set,
104                 .key     = elem->key.val.data,
105         };
106
107         he = rhashtable_lookup(&priv->ht, &arg, nft_rhash_params);
108         if (he != NULL)
109                 return he;
110
111         return ERR_PTR(-ENOENT);
112 }
113
114 static bool nft_rhash_update(struct nft_set *set, const u32 *key,
115                              void *(*new)(struct nft_set *,
116                                           const struct nft_expr *,
117                                           struct nft_regs *regs),
118                              const struct nft_expr *expr,
119                              struct nft_regs *regs,
120                              const struct nft_set_ext **ext)
121 {
122         struct nft_rhash *priv = nft_set_priv(set);
123         struct nft_rhash_elem *he, *prev;
124         struct nft_rhash_cmp_arg arg = {
125                 .genmask = NFT_GENMASK_ANY,
126                 .set     = set,
127                 .key     = key,
128         };
129
130         he = rhashtable_lookup(&priv->ht, &arg, nft_rhash_params);
131         if (he != NULL)
132                 goto out;
133
134         he = new(set, expr, regs);
135         if (he == NULL)
136                 goto err1;
137
138         prev = rhashtable_lookup_get_insert_key(&priv->ht, &arg, &he->node,
139                                                 nft_rhash_params);
140         if (IS_ERR(prev))
141                 goto err2;
142
143         /* Another cpu may race to insert the element with the same key */
144         if (prev) {
145                 nft_set_elem_destroy(set, he, true);
146                 atomic_dec(&set->nelems);
147                 he = prev;
148         }
149
150 out:
151         *ext = &he->ext;
152         return true;
153
154 err2:
155         nft_set_elem_destroy(set, he, true);
156         atomic_dec(&set->nelems);
157 err1:
158         return false;
159 }
160
161 static int nft_rhash_insert(const struct net *net, const struct nft_set *set,
162                             const struct nft_set_elem *elem,
163                             struct nft_set_ext **ext)
164 {
165         struct nft_rhash *priv = nft_set_priv(set);
166         struct nft_rhash_elem *he = elem->priv;
167         struct nft_rhash_cmp_arg arg = {
168                 .genmask = nft_genmask_next(net),
169                 .set     = set,
170                 .key     = elem->key.val.data,
171         };
172         struct nft_rhash_elem *prev;
173
174         prev = rhashtable_lookup_get_insert_key(&priv->ht, &arg, &he->node,
175                                                 nft_rhash_params);
176         if (IS_ERR(prev))
177                 return PTR_ERR(prev);
178         if (prev) {
179                 *ext = &prev->ext;
180                 return -EEXIST;
181         }
182         return 0;
183 }
184
185 static void nft_rhash_activate(const struct net *net, const struct nft_set *set,
186                                const struct nft_set_elem *elem)
187 {
188         struct nft_rhash_elem *he = elem->priv;
189
190         nft_set_elem_change_active(net, set, &he->ext);
191         nft_set_elem_clear_busy(&he->ext);
192 }
193
194 static bool nft_rhash_flush(const struct net *net,
195                             const struct nft_set *set, void *priv)
196 {
197         struct nft_rhash_elem *he = priv;
198
199         if (!nft_set_elem_mark_busy(&he->ext) ||
200             !nft_is_active(net, &he->ext)) {
201                 nft_set_elem_change_active(net, set, &he->ext);
202                 return true;
203         }
204         return false;
205 }
206
207 static void *nft_rhash_deactivate(const struct net *net,
208                                   const struct nft_set *set,
209                                   const struct nft_set_elem *elem)
210 {
211         struct nft_rhash *priv = nft_set_priv(set);
212         struct nft_rhash_elem *he;
213         struct nft_rhash_cmp_arg arg = {
214                 .genmask = nft_genmask_next(net),
215                 .set     = set,
216                 .key     = elem->key.val.data,
217         };
218
219         rcu_read_lock();
220         he = rhashtable_lookup(&priv->ht, &arg, nft_rhash_params);
221         if (he != NULL &&
222             !nft_rhash_flush(net, set, he))
223                 he = NULL;
224
225         rcu_read_unlock();
226
227         return he;
228 }
229
230 static void nft_rhash_remove(const struct net *net,
231                              const struct nft_set *set,
232                              const struct nft_set_elem *elem)
233 {
234         struct nft_rhash *priv = nft_set_priv(set);
235         struct nft_rhash_elem *he = elem->priv;
236
237         rhashtable_remove_fast(&priv->ht, &he->node, nft_rhash_params);
238 }
239
240 static bool nft_rhash_delete(const struct nft_set *set,
241                              const u32 *key)
242 {
243         struct nft_rhash *priv = nft_set_priv(set);
244         struct nft_rhash_cmp_arg arg = {
245                 .genmask = NFT_GENMASK_ANY,
246                 .set = set,
247                 .key = key,
248         };
249         struct nft_rhash_elem *he;
250
251         he = rhashtable_lookup(&priv->ht, &arg, nft_rhash_params);
252         if (he == NULL)
253                 return false;
254
255         return rhashtable_remove_fast(&priv->ht, &he->node, nft_rhash_params) == 0;
256 }
257
258 static void nft_rhash_walk(const struct nft_ctx *ctx, struct nft_set *set,
259                            struct nft_set_iter *iter)
260 {
261         struct nft_rhash *priv = nft_set_priv(set);
262         struct nft_rhash_elem *he;
263         struct rhashtable_iter hti;
264         struct nft_set_elem elem;
265
266         rhashtable_walk_enter(&priv->ht, &hti);
267         rhashtable_walk_start(&hti);
268
269         while ((he = rhashtable_walk_next(&hti))) {
270                 if (IS_ERR(he)) {
271                         if (PTR_ERR(he) != -EAGAIN) {
272                                 iter->err = PTR_ERR(he);
273                                 break;
274                         }
275
276                         continue;
277                 }
278
279                 if (iter->count < iter->skip)
280                         goto cont;
281                 if (nft_set_elem_expired(&he->ext))
282                         goto cont;
283                 if (!nft_set_elem_active(&he->ext, iter->genmask))
284                         goto cont;
285
286                 elem.priv = he;
287
288                 iter->err = iter->fn(ctx, set, iter, &elem);
289                 if (iter->err < 0)
290                         break;
291
292 cont:
293                 iter->count++;
294         }
295         rhashtable_walk_stop(&hti);
296         rhashtable_walk_exit(&hti);
297 }
298
299 static bool nft_rhash_expr_needs_gc_run(const struct nft_set *set,
300                                         struct nft_set_ext *ext)
301 {
302         struct nft_set_elem_expr *elem_expr = nft_set_ext_expr(ext);
303         struct nft_expr *expr;
304         u32 size;
305
306         nft_setelem_expr_foreach(expr, elem_expr, size) {
307                 if (expr->ops->gc &&
308                     expr->ops->gc(read_pnet(&set->net), expr))
309                         return true;
310         }
311
312         return false;
313 }
314
315 static void nft_rhash_gc(struct work_struct *work)
316 {
317         struct nft_set *set;
318         struct nft_rhash_elem *he;
319         struct nft_rhash *priv;
320         struct nft_set_gc_batch *gcb = NULL;
321         struct rhashtable_iter hti;
322
323         priv = container_of(work, struct nft_rhash, gc_work.work);
324         set  = nft_set_container_of(priv);
325
326         rhashtable_walk_enter(&priv->ht, &hti);
327         rhashtable_walk_start(&hti);
328
329         while ((he = rhashtable_walk_next(&hti))) {
330                 if (IS_ERR(he)) {
331                         if (PTR_ERR(he) != -EAGAIN)
332                                 break;
333                         continue;
334                 }
335
336                 if (nft_set_ext_exists(&he->ext, NFT_SET_EXT_EXPRESSIONS) &&
337                     nft_rhash_expr_needs_gc_run(set, &he->ext))
338                         goto needs_gc_run;
339
340                 if (!nft_set_elem_expired(&he->ext))
341                         continue;
342 needs_gc_run:
343                 if (nft_set_elem_mark_busy(&he->ext))
344                         continue;
345
346                 gcb = nft_set_gc_batch_check(set, gcb, GFP_ATOMIC);
347                 if (gcb == NULL)
348                         break;
349                 rhashtable_remove_fast(&priv->ht, &he->node, nft_rhash_params);
350                 atomic_dec(&set->nelems);
351                 nft_set_gc_batch_add(gcb, he);
352         }
353         rhashtable_walk_stop(&hti);
354         rhashtable_walk_exit(&hti);
355
356         he = nft_set_catchall_gc(set);
357         if (he) {
358                 gcb = nft_set_gc_batch_check(set, gcb, GFP_ATOMIC);
359                 if (gcb)
360                         nft_set_gc_batch_add(gcb, he);
361         }
362         nft_set_gc_batch_complete(gcb);
363         queue_delayed_work(system_power_efficient_wq, &priv->gc_work,
364                            nft_set_gc_interval(set));
365 }
366
367 static u64 nft_rhash_privsize(const struct nlattr * const nla[],
368                               const struct nft_set_desc *desc)
369 {
370         return sizeof(struct nft_rhash);
371 }
372
373 static void nft_rhash_gc_init(const struct nft_set *set)
374 {
375         struct nft_rhash *priv = nft_set_priv(set);
376
377         queue_delayed_work(system_power_efficient_wq, &priv->gc_work,
378                            nft_set_gc_interval(set));
379 }
380
381 static int nft_rhash_init(const struct nft_set *set,
382                           const struct nft_set_desc *desc,
383                           const struct nlattr * const tb[])
384 {
385         struct nft_rhash *priv = nft_set_priv(set);
386         struct rhashtable_params params = nft_rhash_params;
387         int err;
388
389         params.nelem_hint = desc->size ?: NFT_RHASH_ELEMENT_HINT;
390         params.key_len    = set->klen;
391
392         err = rhashtable_init(&priv->ht, &params);
393         if (err < 0)
394                 return err;
395
396         INIT_DEFERRABLE_WORK(&priv->gc_work, nft_rhash_gc);
397         if (set->flags & NFT_SET_TIMEOUT)
398                 nft_rhash_gc_init(set);
399
400         return 0;
401 }
402
403 struct nft_rhash_ctx {
404         const struct nft_ctx    ctx;
405         const struct nft_set    *set;
406 };
407
408 static void nft_rhash_elem_destroy(void *ptr, void *arg)
409 {
410         struct nft_rhash_ctx *rhash_ctx = arg;
411
412         nf_tables_set_elem_destroy(&rhash_ctx->ctx, rhash_ctx->set, ptr);
413 }
414
415 static void nft_rhash_destroy(const struct nft_ctx *ctx,
416                               const struct nft_set *set)
417 {
418         struct nft_rhash *priv = nft_set_priv(set);
419         struct nft_rhash_ctx rhash_ctx = {
420                 .ctx    = *ctx,
421                 .set    = set,
422         };
423
424         cancel_delayed_work_sync(&priv->gc_work);
425         rcu_barrier();
426         rhashtable_free_and_destroy(&priv->ht, nft_rhash_elem_destroy,
427                                     (void *)&rhash_ctx);
428 }
429
430 /* Number of buckets is stored in u32, so cap our result to 1U<<31 */
431 #define NFT_MAX_BUCKETS (1U << 31)
432
433 static u32 nft_hash_buckets(u32 size)
434 {
435         u64 val = div_u64((u64)size * 4, 3);
436
437         if (val >= NFT_MAX_BUCKETS)
438                 return NFT_MAX_BUCKETS;
439
440         return roundup_pow_of_two(val);
441 }
442
443 static bool nft_rhash_estimate(const struct nft_set_desc *desc, u32 features,
444                                struct nft_set_estimate *est)
445 {
446         est->size   = ~0;
447         est->lookup = NFT_SET_CLASS_O_1;
448         est->space  = NFT_SET_CLASS_O_N;
449
450         return true;
451 }
452
453 struct nft_hash {
454         u32                             seed;
455         u32                             buckets;
456         struct hlist_head               table[];
457 };
458
459 struct nft_hash_elem {
460         struct hlist_node               node;
461         struct nft_set_ext              ext;
462 };
463
464 INDIRECT_CALLABLE_SCOPE
465 bool nft_hash_lookup(const struct net *net, const struct nft_set *set,
466                      const u32 *key, const struct nft_set_ext **ext)
467 {
468         struct nft_hash *priv = nft_set_priv(set);
469         u8 genmask = nft_genmask_cur(net);
470         const struct nft_hash_elem *he;
471         u32 hash;
472
473         hash = jhash(key, set->klen, priv->seed);
474         hash = reciprocal_scale(hash, priv->buckets);
475         hlist_for_each_entry_rcu(he, &priv->table[hash], node) {
476                 if (!memcmp(nft_set_ext_key(&he->ext), key, set->klen) &&
477                     nft_set_elem_active(&he->ext, genmask)) {
478                         *ext = &he->ext;
479                         return true;
480                 }
481         }
482         return false;
483 }
484
485 static void *nft_hash_get(const struct net *net, const struct nft_set *set,
486                           const struct nft_set_elem *elem, unsigned int flags)
487 {
488         struct nft_hash *priv = nft_set_priv(set);
489         u8 genmask = nft_genmask_cur(net);
490         struct nft_hash_elem *he;
491         u32 hash;
492
493         hash = jhash(elem->key.val.data, set->klen, priv->seed);
494         hash = reciprocal_scale(hash, priv->buckets);
495         hlist_for_each_entry_rcu(he, &priv->table[hash], node) {
496                 if (!memcmp(nft_set_ext_key(&he->ext), elem->key.val.data, set->klen) &&
497                     nft_set_elem_active(&he->ext, genmask))
498                         return he;
499         }
500         return ERR_PTR(-ENOENT);
501 }
502
503 INDIRECT_CALLABLE_SCOPE
504 bool nft_hash_lookup_fast(const struct net *net,
505                           const struct nft_set *set,
506                           const u32 *key, const struct nft_set_ext **ext)
507 {
508         struct nft_hash *priv = nft_set_priv(set);
509         u8 genmask = nft_genmask_cur(net);
510         const struct nft_hash_elem *he;
511         u32 hash, k1, k2;
512
513         k1 = *key;
514         hash = jhash_1word(k1, priv->seed);
515         hash = reciprocal_scale(hash, priv->buckets);
516         hlist_for_each_entry_rcu(he, &priv->table[hash], node) {
517                 k2 = *(u32 *)nft_set_ext_key(&he->ext)->data;
518                 if (k1 == k2 &&
519                     nft_set_elem_active(&he->ext, genmask)) {
520                         *ext = &he->ext;
521                         return true;
522                 }
523         }
524         return false;
525 }
526
527 static u32 nft_jhash(const struct nft_set *set, const struct nft_hash *priv,
528                      const struct nft_set_ext *ext)
529 {
530         const struct nft_data *key = nft_set_ext_key(ext);
531         u32 hash, k1;
532
533         if (set->klen == 4) {
534                 k1 = *(u32 *)key;
535                 hash = jhash_1word(k1, priv->seed);
536         } else {
537                 hash = jhash(key, set->klen, priv->seed);
538         }
539         hash = reciprocal_scale(hash, priv->buckets);
540
541         return hash;
542 }
543
544 static int nft_hash_insert(const struct net *net, const struct nft_set *set,
545                            const struct nft_set_elem *elem,
546                            struct nft_set_ext **ext)
547 {
548         struct nft_hash_elem *this = elem->priv, *he;
549         struct nft_hash *priv = nft_set_priv(set);
550         u8 genmask = nft_genmask_next(net);
551         u32 hash;
552
553         hash = nft_jhash(set, priv, &this->ext);
554         hlist_for_each_entry(he, &priv->table[hash], node) {
555                 if (!memcmp(nft_set_ext_key(&this->ext),
556                             nft_set_ext_key(&he->ext), set->klen) &&
557                     nft_set_elem_active(&he->ext, genmask)) {
558                         *ext = &he->ext;
559                         return -EEXIST;
560                 }
561         }
562         hlist_add_head_rcu(&this->node, &priv->table[hash]);
563         return 0;
564 }
565
566 static void nft_hash_activate(const struct net *net, const struct nft_set *set,
567                               const struct nft_set_elem *elem)
568 {
569         struct nft_hash_elem *he = elem->priv;
570
571         nft_set_elem_change_active(net, set, &he->ext);
572 }
573
574 static bool nft_hash_flush(const struct net *net,
575                            const struct nft_set *set, void *priv)
576 {
577         struct nft_hash_elem *he = priv;
578
579         nft_set_elem_change_active(net, set, &he->ext);
580         return true;
581 }
582
583 static void *nft_hash_deactivate(const struct net *net,
584                                  const struct nft_set *set,
585                                  const struct nft_set_elem *elem)
586 {
587         struct nft_hash *priv = nft_set_priv(set);
588         struct nft_hash_elem *this = elem->priv, *he;
589         u8 genmask = nft_genmask_next(net);
590         u32 hash;
591
592         hash = nft_jhash(set, priv, &this->ext);
593         hlist_for_each_entry(he, &priv->table[hash], node) {
594                 if (!memcmp(nft_set_ext_key(&he->ext), &elem->key.val,
595                             set->klen) &&
596                     nft_set_elem_active(&he->ext, genmask)) {
597                         nft_set_elem_change_active(net, set, &he->ext);
598                         return he;
599                 }
600         }
601         return NULL;
602 }
603
604 static void nft_hash_remove(const struct net *net,
605                             const struct nft_set *set,
606                             const struct nft_set_elem *elem)
607 {
608         struct nft_hash_elem *he = elem->priv;
609
610         hlist_del_rcu(&he->node);
611 }
612
613 static void nft_hash_walk(const struct nft_ctx *ctx, struct nft_set *set,
614                           struct nft_set_iter *iter)
615 {
616         struct nft_hash *priv = nft_set_priv(set);
617         struct nft_hash_elem *he;
618         struct nft_set_elem elem;
619         int i;
620
621         for (i = 0; i < priv->buckets; i++) {
622                 hlist_for_each_entry_rcu(he, &priv->table[i], node) {
623                         if (iter->count < iter->skip)
624                                 goto cont;
625                         if (!nft_set_elem_active(&he->ext, iter->genmask))
626                                 goto cont;
627
628                         elem.priv = he;
629
630                         iter->err = iter->fn(ctx, set, iter, &elem);
631                         if (iter->err < 0)
632                                 return;
633 cont:
634                         iter->count++;
635                 }
636         }
637 }
638
639 static u64 nft_hash_privsize(const struct nlattr * const nla[],
640                              const struct nft_set_desc *desc)
641 {
642         return sizeof(struct nft_hash) +
643                (u64)nft_hash_buckets(desc->size) * sizeof(struct hlist_head);
644 }
645
646 static int nft_hash_init(const struct nft_set *set,
647                          const struct nft_set_desc *desc,
648                          const struct nlattr * const tb[])
649 {
650         struct nft_hash *priv = nft_set_priv(set);
651
652         priv->buckets = nft_hash_buckets(desc->size);
653         get_random_bytes(&priv->seed, sizeof(priv->seed));
654
655         return 0;
656 }
657
658 static void nft_hash_destroy(const struct nft_ctx *ctx,
659                              const struct nft_set *set)
660 {
661         struct nft_hash *priv = nft_set_priv(set);
662         struct nft_hash_elem *he;
663         struct hlist_node *next;
664         int i;
665
666         for (i = 0; i < priv->buckets; i++) {
667                 hlist_for_each_entry_safe(he, next, &priv->table[i], node) {
668                         hlist_del_rcu(&he->node);
669                         nf_tables_set_elem_destroy(ctx, set, he);
670                 }
671         }
672 }
673
674 static bool nft_hash_estimate(const struct nft_set_desc *desc, u32 features,
675                               struct nft_set_estimate *est)
676 {
677         if (!desc->size)
678                 return false;
679
680         if (desc->klen == 4)
681                 return false;
682
683         est->size   = sizeof(struct nft_hash) +
684                       (u64)nft_hash_buckets(desc->size) * sizeof(struct hlist_head) +
685                       (u64)desc->size * sizeof(struct nft_hash_elem);
686         est->lookup = NFT_SET_CLASS_O_1;
687         est->space  = NFT_SET_CLASS_O_N;
688
689         return true;
690 }
691
692 static bool nft_hash_fast_estimate(const struct nft_set_desc *desc, u32 features,
693                                    struct nft_set_estimate *est)
694 {
695         if (!desc->size)
696                 return false;
697
698         if (desc->klen != 4)
699                 return false;
700
701         est->size   = sizeof(struct nft_hash) +
702                       (u64)nft_hash_buckets(desc->size) * sizeof(struct hlist_head) +
703                       (u64)desc->size * sizeof(struct nft_hash_elem);
704         est->lookup = NFT_SET_CLASS_O_1;
705         est->space  = NFT_SET_CLASS_O_N;
706
707         return true;
708 }
709
710 const struct nft_set_type nft_set_rhash_type = {
711         .features       = NFT_SET_MAP | NFT_SET_OBJECT |
712                           NFT_SET_TIMEOUT | NFT_SET_EVAL,
713         .ops            = {
714                 .privsize       = nft_rhash_privsize,
715                 .elemsize       = offsetof(struct nft_rhash_elem, ext),
716                 .estimate       = nft_rhash_estimate,
717                 .init           = nft_rhash_init,
718                 .gc_init        = nft_rhash_gc_init,
719                 .destroy        = nft_rhash_destroy,
720                 .insert         = nft_rhash_insert,
721                 .activate       = nft_rhash_activate,
722                 .deactivate     = nft_rhash_deactivate,
723                 .flush          = nft_rhash_flush,
724                 .remove         = nft_rhash_remove,
725                 .lookup         = nft_rhash_lookup,
726                 .update         = nft_rhash_update,
727                 .delete         = nft_rhash_delete,
728                 .walk           = nft_rhash_walk,
729                 .get            = nft_rhash_get,
730         },
731 };
732
733 const struct nft_set_type nft_set_hash_type = {
734         .features       = NFT_SET_MAP | NFT_SET_OBJECT,
735         .ops            = {
736                 .privsize       = nft_hash_privsize,
737                 .elemsize       = offsetof(struct nft_hash_elem, ext),
738                 .estimate       = nft_hash_estimate,
739                 .init           = nft_hash_init,
740                 .destroy        = nft_hash_destroy,
741                 .insert         = nft_hash_insert,
742                 .activate       = nft_hash_activate,
743                 .deactivate     = nft_hash_deactivate,
744                 .flush          = nft_hash_flush,
745                 .remove         = nft_hash_remove,
746                 .lookup         = nft_hash_lookup,
747                 .walk           = nft_hash_walk,
748                 .get            = nft_hash_get,
749         },
750 };
751
752 const struct nft_set_type nft_set_hash_fast_type = {
753         .features       = NFT_SET_MAP | NFT_SET_OBJECT,
754         .ops            = {
755                 .privsize       = nft_hash_privsize,
756                 .elemsize       = offsetof(struct nft_hash_elem, ext),
757                 .estimate       = nft_hash_fast_estimate,
758                 .init           = nft_hash_init,
759                 .destroy        = nft_hash_destroy,
760                 .insert         = nft_hash_insert,
761                 .activate       = nft_hash_activate,
762                 .deactivate     = nft_hash_deactivate,
763                 .flush          = nft_hash_flush,
764                 .remove         = nft_hash_remove,
765                 .lookup         = nft_hash_lookup_fast,
766                 .walk           = nft_hash_walk,
767                 .get            = nft_hash_get,
768         },
769 };