GNU Linux-libre 4.19.263-gnu1
[releases.git] / include / net / netfilter / nf_tables.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NET_NF_TABLES_H
3 #define _NET_NF_TABLES_H
4
5 #include <linux/module.h>
6 #include <linux/list.h>
7 #include <linux/netfilter.h>
8 #include <linux/netfilter/nfnetlink.h>
9 #include <linux/netfilter/x_tables.h>
10 #include <linux/netfilter/nf_tables.h>
11 #include <linux/u64_stats_sync.h>
12 #include <linux/rhashtable.h>
13 #include <net/netfilter/nf_flow_table.h>
14 #include <net/netlink.h>
15
16 #define NFT_JUMP_STACK_SIZE     16
17
18 struct nft_pktinfo {
19         struct sk_buff                  *skb;
20         bool                            tprot_set;
21         u8                              tprot;
22         /* for x_tables compatibility */
23         struct xt_action_param          xt;
24 };
25
26 static inline struct net *nft_net(const struct nft_pktinfo *pkt)
27 {
28         return pkt->xt.state->net;
29 }
30
31 static inline unsigned int nft_hook(const struct nft_pktinfo *pkt)
32 {
33         return pkt->xt.state->hook;
34 }
35
36 static inline u8 nft_pf(const struct nft_pktinfo *pkt)
37 {
38         return pkt->xt.state->pf;
39 }
40
41 static inline const struct net_device *nft_in(const struct nft_pktinfo *pkt)
42 {
43         return pkt->xt.state->in;
44 }
45
46 static inline const struct net_device *nft_out(const struct nft_pktinfo *pkt)
47 {
48         return pkt->xt.state->out;
49 }
50
51 static inline void nft_set_pktinfo(struct nft_pktinfo *pkt,
52                                    struct sk_buff *skb,
53                                    const struct nf_hook_state *state)
54 {
55         pkt->skb = skb;
56         pkt->xt.state = state;
57 }
58
59 static inline void nft_set_pktinfo_unspec(struct nft_pktinfo *pkt,
60                                           struct sk_buff *skb)
61 {
62         pkt->tprot_set = false;
63         pkt->tprot = 0;
64         pkt->xt.thoff = 0;
65         pkt->xt.fragoff = 0;
66 }
67
68 /**
69  *      struct nft_verdict - nf_tables verdict
70  *
71  *      @code: nf_tables/netfilter verdict code
72  *      @chain: destination chain for NFT_JUMP/NFT_GOTO
73  */
74 struct nft_verdict {
75         u32                             code;
76         struct nft_chain                *chain;
77 };
78
79 struct nft_data {
80         union {
81                 u32                     data[4];
82                 struct nft_verdict      verdict;
83         };
84 } __attribute__((aligned(__alignof__(u64))));
85
86 /**
87  *      struct nft_regs - nf_tables register set
88  *
89  *      @data: data registers
90  *      @verdict: verdict register
91  *
92  *      The first four data registers alias to the verdict register.
93  */
94 struct nft_regs {
95         union {
96                 u32                     data[20];
97                 struct nft_verdict      verdict;
98         };
99 };
100
101 /* Store/load an u16 or u8 integer to/from the u32 data register.
102  *
103  * Note, when using concatenations, register allocation happens at 32-bit
104  * level. So for store instruction, pad the rest part with zero to avoid
105  * garbage values.
106  */
107
108 static inline void nft_reg_store16(u32 *dreg, u16 val)
109 {
110         *dreg = 0;
111         *(u16 *)dreg = val;
112 }
113
114 static inline void nft_reg_store8(u32 *dreg, u8 val)
115 {
116         *dreg = 0;
117         *(u8 *)dreg = val;
118 }
119
120 static inline u16 nft_reg_load16(u32 *sreg)
121 {
122         return *(u16 *)sreg;
123 }
124
125 static inline u8 nft_reg_load8(u32 *sreg)
126 {
127         return *(u8 *)sreg;
128 }
129
130 static inline void nft_data_copy(u32 *dst, const struct nft_data *src,
131                                  unsigned int len)
132 {
133         if (len % NFT_REG32_SIZE)
134                 dst[len / NFT_REG32_SIZE] = 0;
135         memcpy(dst, src, len);
136 }
137
138 static inline void nft_data_debug(const struct nft_data *data)
139 {
140         pr_debug("data[0]=%x data[1]=%x data[2]=%x data[3]=%x\n",
141                  data->data[0], data->data[1],
142                  data->data[2], data->data[3]);
143 }
144
145 /**
146  *      struct nft_ctx - nf_tables rule/set context
147  *
148  *      @net: net namespace
149  *      @table: the table the chain is contained in
150  *      @chain: the chain the rule is contained in
151  *      @nla: netlink attributes
152  *      @portid: netlink portID of the original message
153  *      @seq: netlink sequence number
154  *      @family: protocol family
155  *      @level: depth of the chains
156  *      @report: notify via unicast netlink message
157  */
158 struct nft_ctx {
159         struct net                      *net;
160         struct nft_table                *table;
161         struct nft_chain                *chain;
162         const struct nlattr * const     *nla;
163         u32                             portid;
164         u32                             seq;
165         u8                              family;
166         u8                              level;
167         bool                            report;
168 };
169
170 struct nft_data_desc {
171         enum nft_data_types             type;
172         unsigned int                    len;
173 };
174
175 int nft_data_init(const struct nft_ctx *ctx,
176                   struct nft_data *data, unsigned int size,
177                   struct nft_data_desc *desc, const struct nlattr *nla);
178 void nft_data_hold(const struct nft_data *data, enum nft_data_types type);
179 void nft_data_release(const struct nft_data *data, enum nft_data_types type);
180 int nft_data_dump(struct sk_buff *skb, int attr, const struct nft_data *data,
181                   enum nft_data_types type, unsigned int len);
182
183 static inline enum nft_data_types nft_dreg_to_type(enum nft_registers reg)
184 {
185         return reg == NFT_REG_VERDICT ? NFT_DATA_VERDICT : NFT_DATA_VALUE;
186 }
187
188 static inline enum nft_registers nft_type_to_reg(enum nft_data_types type)
189 {
190         return type == NFT_DATA_VERDICT ? NFT_REG_VERDICT : NFT_REG_1 * NFT_REG_SIZE / NFT_REG32_SIZE;
191 }
192
193 int nft_parse_u32_check(const struct nlattr *attr, int max, u32 *dest);
194 unsigned int nft_parse_register(const struct nlattr *attr);
195 int nft_dump_register(struct sk_buff *skb, unsigned int attr, unsigned int reg);
196
197 int nft_validate_register_load(enum nft_registers reg, unsigned int len);
198 int nft_validate_register_store(const struct nft_ctx *ctx,
199                                 enum nft_registers reg,
200                                 const struct nft_data *data,
201                                 enum nft_data_types type, unsigned int len);
202
203 /**
204  *      struct nft_userdata - user defined data associated with an object
205  *
206  *      @len: length of the data
207  *      @data: content
208  *
209  *      The presence of user data is indicated in an object specific fashion,
210  *      so a length of zero can't occur and the value "len" indicates data
211  *      of length len + 1.
212  */
213 struct nft_userdata {
214         u8                      len;
215         unsigned char           data[0];
216 };
217
218 /**
219  *      struct nft_set_elem - generic representation of set elements
220  *
221  *      @key: element key
222  *      @priv: element private data and extensions
223  */
224 struct nft_set_elem {
225         union {
226                 u32             buf[NFT_DATA_VALUE_MAXLEN / sizeof(u32)];
227                 struct nft_data val;
228         } key;
229         void                    *priv;
230 };
231
232 struct nft_set;
233 struct nft_set_iter {
234         u8              genmask;
235         unsigned int    count;
236         unsigned int    skip;
237         int             err;
238         int             (*fn)(const struct nft_ctx *ctx,
239                               struct nft_set *set,
240                               const struct nft_set_iter *iter,
241                               struct nft_set_elem *elem);
242 };
243
244 /**
245  *      struct nft_set_desc - description of set elements
246  *
247  *      @klen: key length
248  *      @dlen: data length
249  *      @size: number of set elements
250  */
251 struct nft_set_desc {
252         unsigned int            klen;
253         unsigned int            dlen;
254         unsigned int            size;
255 };
256
257 /**
258  *      enum nft_set_class - performance class
259  *
260  *      @NFT_LOOKUP_O_1: constant, O(1)
261  *      @NFT_LOOKUP_O_LOG_N: logarithmic, O(log N)
262  *      @NFT_LOOKUP_O_N: linear, O(N)
263  */
264 enum nft_set_class {
265         NFT_SET_CLASS_O_1,
266         NFT_SET_CLASS_O_LOG_N,
267         NFT_SET_CLASS_O_N,
268 };
269
270 /**
271  *      struct nft_set_estimate - estimation of memory and performance
272  *                                characteristics
273  *
274  *      @size: required memory
275  *      @lookup: lookup performance class
276  *      @space: memory class
277  */
278 struct nft_set_estimate {
279         u64                     size;
280         enum nft_set_class      lookup;
281         enum nft_set_class      space;
282 };
283
284 struct nft_set_ext;
285 struct nft_expr;
286
287 /**
288  *      struct nft_set_ops - nf_tables set operations
289  *
290  *      @lookup: look up an element within the set
291  *      @insert: insert new element into set
292  *      @activate: activate new element in the next generation
293  *      @deactivate: lookup for element and deactivate it in the next generation
294  *      @flush: deactivate element in the next generation
295  *      @remove: remove element from set
296  *      @walk: iterate over all set elemeennts
297  *      @get: get set elements
298  *      @privsize: function to return size of set private data
299  *      @init: initialize private data of new set instance
300  *      @destroy: destroy private data of set instance
301  *      @elemsize: element private size
302  */
303 struct nft_set_ops {
304         bool                            (*lookup)(const struct net *net,
305                                                   const struct nft_set *set,
306                                                   const u32 *key,
307                                                   const struct nft_set_ext **ext);
308         bool                            (*update)(struct nft_set *set,
309                                                   const u32 *key,
310                                                   void *(*new)(struct nft_set *,
311                                                                const struct nft_expr *,
312                                                                struct nft_regs *),
313                                                   const struct nft_expr *expr,
314                                                   struct nft_regs *regs,
315                                                   const struct nft_set_ext **ext);
316
317         int                             (*insert)(const struct net *net,
318                                                   const struct nft_set *set,
319                                                   const struct nft_set_elem *elem,
320                                                   struct nft_set_ext **ext);
321         void                            (*activate)(const struct net *net,
322                                                     const struct nft_set *set,
323                                                     const struct nft_set_elem *elem);
324         void *                          (*deactivate)(const struct net *net,
325                                                       const struct nft_set *set,
326                                                       const struct nft_set_elem *elem);
327         bool                            (*flush)(const struct net *net,
328                                                  const struct nft_set *set,
329                                                  void *priv);
330         void                            (*remove)(const struct net *net,
331                                                   const struct nft_set *set,
332                                                   const struct nft_set_elem *elem);
333         void                            (*walk)(const struct nft_ctx *ctx,
334                                                 struct nft_set *set,
335                                                 struct nft_set_iter *iter);
336         void *                          (*get)(const struct net *net,
337                                                const struct nft_set *set,
338                                                const struct nft_set_elem *elem,
339                                                unsigned int flags);
340
341         u64                             (*privsize)(const struct nlattr * const nla[],
342                                                     const struct nft_set_desc *desc);
343         bool                            (*estimate)(const struct nft_set_desc *desc,
344                                                     u32 features,
345                                                     struct nft_set_estimate *est);
346         int                             (*init)(const struct nft_set *set,
347                                                 const struct nft_set_desc *desc,
348                                                 const struct nlattr * const nla[]);
349         void                            (*destroy)(const struct nft_set *set);
350         void                            (*gc_init)(const struct nft_set *set);
351
352         unsigned int                    elemsize;
353 };
354
355 /**
356  *      struct nft_set_type - nf_tables set type
357  *
358  *      @ops: set ops for this type
359  *      @list: used internally
360  *      @owner: module reference
361  *      @features: features supported by the implementation
362  */
363 struct nft_set_type {
364         const struct nft_set_ops        ops;
365         struct list_head                list;
366         struct module                   *owner;
367         u32                             features;
368 };
369 #define to_set_type(o) container_of(o, struct nft_set_type, ops)
370
371 int nft_register_set(struct nft_set_type *type);
372 void nft_unregister_set(struct nft_set_type *type);
373
374 /**
375  *      struct nft_set - nf_tables set instance
376  *
377  *      @list: table set list node
378  *      @bindings: list of set bindings
379  *      @table: table this set belongs to
380  *      @net: netnamespace this set belongs to
381  *      @name: name of the set
382  *      @handle: unique handle of the set
383  *      @ktype: key type (numeric type defined by userspace, not used in the kernel)
384  *      @dtype: data type (verdict or numeric type defined by userspace)
385  *      @objtype: object type (see NFT_OBJECT_* definitions)
386  *      @size: maximum set size
387  *      @use: number of rules references to this set
388  *      @nelems: number of elements
389  *      @ndeact: number of deactivated elements queued for removal
390  *      @timeout: default timeout value in jiffies
391  *      @gc_int: garbage collection interval in msecs
392  *      @policy: set parameterization (see enum nft_set_policies)
393  *      @udlen: user data length
394  *      @udata: user data
395  *      @ops: set ops
396  *      @flags: set flags
397  *      @genmask: generation mask
398  *      @klen: key length
399  *      @dlen: data length
400  *      @data: private set data
401  */
402 struct nft_set {
403         struct list_head                list;
404         struct list_head                bindings;
405         struct nft_table                *table;
406         possible_net_t                  net;
407         char                            *name;
408         u64                             handle;
409         u32                             ktype;
410         u32                             dtype;
411         u32                             objtype;
412         u32                             size;
413         u32                             use;
414         atomic_t                        nelems;
415         u32                             ndeact;
416         u64                             timeout;
417         u32                             gc_int;
418         u16                             policy;
419         u16                             udlen;
420         unsigned char                   *udata;
421         /* runtime data below here */
422         const struct nft_set_ops        *ops ____cacheline_aligned;
423         u16                             flags:14,
424                                         genmask:2;
425         u8                              klen;
426         u8                              dlen;
427         unsigned char                   data[]
428                 __attribute__((aligned(__alignof__(u64))));
429 };
430
431 static inline bool nft_set_is_anonymous(const struct nft_set *set)
432 {
433         return set->flags & NFT_SET_ANONYMOUS;
434 }
435
436 static inline void *nft_set_priv(const struct nft_set *set)
437 {
438         return (void *)set->data;
439 }
440
441 static inline struct nft_set *nft_set_container_of(const void *priv)
442 {
443         return (void *)priv - offsetof(struct nft_set, data);
444 }
445
446 struct nft_set *nft_set_lookup_global(const struct net *net,
447                                       const struct nft_table *table,
448                                       const struct nlattr *nla_set_name,
449                                       const struct nlattr *nla_set_id,
450                                       u8 genmask);
451
452 static inline unsigned long nft_set_gc_interval(const struct nft_set *set)
453 {
454         return set->gc_int ? msecs_to_jiffies(set->gc_int) : HZ;
455 }
456
457 /**
458  *      struct nft_set_binding - nf_tables set binding
459  *
460  *      @list: set bindings list node
461  *      @chain: chain containing the rule bound to the set
462  *      @flags: set action flags
463  *
464  *      A set binding contains all information necessary for validation
465  *      of new elements added to a bound set.
466  */
467 struct nft_set_binding {
468         struct list_head                list;
469         const struct nft_chain          *chain;
470         u32                             flags;
471 };
472
473 enum nft_trans_phase;
474 void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set,
475                               struct nft_set_binding *binding,
476                               enum nft_trans_phase phase);
477 int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,
478                        struct nft_set_binding *binding);
479 void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set,
480                           struct nft_set_binding *binding, bool commit);
481 void nf_tables_destroy_set(const struct nft_ctx *ctx, struct nft_set *set);
482
483 /**
484  *      enum nft_set_extensions - set extension type IDs
485  *
486  *      @NFT_SET_EXT_KEY: element key
487  *      @NFT_SET_EXT_DATA: mapping data
488  *      @NFT_SET_EXT_FLAGS: element flags
489  *      @NFT_SET_EXT_TIMEOUT: element timeout
490  *      @NFT_SET_EXT_EXPIRATION: element expiration time
491  *      @NFT_SET_EXT_USERDATA: user data associated with the element
492  *      @NFT_SET_EXT_EXPR: expression assiociated with the element
493  *      @NFT_SET_EXT_OBJREF: stateful object reference associated with element
494  *      @NFT_SET_EXT_NUM: number of extension types
495  */
496 enum nft_set_extensions {
497         NFT_SET_EXT_KEY,
498         NFT_SET_EXT_DATA,
499         NFT_SET_EXT_FLAGS,
500         NFT_SET_EXT_TIMEOUT,
501         NFT_SET_EXT_EXPIRATION,
502         NFT_SET_EXT_USERDATA,
503         NFT_SET_EXT_EXPR,
504         NFT_SET_EXT_OBJREF,
505         NFT_SET_EXT_NUM
506 };
507
508 /**
509  *      struct nft_set_ext_type - set extension type
510  *
511  *      @len: fixed part length of the extension
512  *      @align: alignment requirements of the extension
513  */
514 struct nft_set_ext_type {
515         u8      len;
516         u8      align;
517 };
518
519 extern const struct nft_set_ext_type nft_set_ext_types[];
520
521 /**
522  *      struct nft_set_ext_tmpl - set extension template
523  *
524  *      @len: length of extension area
525  *      @offset: offsets of individual extension types
526  */
527 struct nft_set_ext_tmpl {
528         u16     len;
529         u8      offset[NFT_SET_EXT_NUM];
530 };
531
532 /**
533  *      struct nft_set_ext - set extensions
534  *
535  *      @genmask: generation mask
536  *      @offset: offsets of individual extension types
537  *      @data: beginning of extension data
538  */
539 struct nft_set_ext {
540         u8      genmask;
541         u8      offset[NFT_SET_EXT_NUM];
542         char    data[0];
543 };
544
545 static inline void nft_set_ext_prepare(struct nft_set_ext_tmpl *tmpl)
546 {
547         memset(tmpl, 0, sizeof(*tmpl));
548         tmpl->len = sizeof(struct nft_set_ext);
549 }
550
551 static inline void nft_set_ext_add_length(struct nft_set_ext_tmpl *tmpl, u8 id,
552                                           unsigned int len)
553 {
554         tmpl->len        = ALIGN(tmpl->len, nft_set_ext_types[id].align);
555         BUG_ON(tmpl->len > U8_MAX);
556         tmpl->offset[id] = tmpl->len;
557         tmpl->len       += nft_set_ext_types[id].len + len;
558 }
559
560 static inline void nft_set_ext_add(struct nft_set_ext_tmpl *tmpl, u8 id)
561 {
562         nft_set_ext_add_length(tmpl, id, 0);
563 }
564
565 static inline void nft_set_ext_init(struct nft_set_ext *ext,
566                                     const struct nft_set_ext_tmpl *tmpl)
567 {
568         memcpy(ext->offset, tmpl->offset, sizeof(ext->offset));
569 }
570
571 static inline bool __nft_set_ext_exists(const struct nft_set_ext *ext, u8 id)
572 {
573         return !!ext->offset[id];
574 }
575
576 static inline bool nft_set_ext_exists(const struct nft_set_ext *ext, u8 id)
577 {
578         return ext && __nft_set_ext_exists(ext, id);
579 }
580
581 static inline void *nft_set_ext(const struct nft_set_ext *ext, u8 id)
582 {
583         return (void *)ext + ext->offset[id];
584 }
585
586 static inline struct nft_data *nft_set_ext_key(const struct nft_set_ext *ext)
587 {
588         return nft_set_ext(ext, NFT_SET_EXT_KEY);
589 }
590
591 static inline struct nft_data *nft_set_ext_data(const struct nft_set_ext *ext)
592 {
593         return nft_set_ext(ext, NFT_SET_EXT_DATA);
594 }
595
596 static inline u8 *nft_set_ext_flags(const struct nft_set_ext *ext)
597 {
598         return nft_set_ext(ext, NFT_SET_EXT_FLAGS);
599 }
600
601 static inline u64 *nft_set_ext_timeout(const struct nft_set_ext *ext)
602 {
603         return nft_set_ext(ext, NFT_SET_EXT_TIMEOUT);
604 }
605
606 static inline u64 *nft_set_ext_expiration(const struct nft_set_ext *ext)
607 {
608         return nft_set_ext(ext, NFT_SET_EXT_EXPIRATION);
609 }
610
611 static inline struct nft_userdata *nft_set_ext_userdata(const struct nft_set_ext *ext)
612 {
613         return nft_set_ext(ext, NFT_SET_EXT_USERDATA);
614 }
615
616 static inline struct nft_expr *nft_set_ext_expr(const struct nft_set_ext *ext)
617 {
618         return nft_set_ext(ext, NFT_SET_EXT_EXPR);
619 }
620
621 static inline bool nft_set_elem_expired(const struct nft_set_ext *ext)
622 {
623         return nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION) &&
624                time_is_before_eq_jiffies64(*nft_set_ext_expiration(ext));
625 }
626
627 static inline struct nft_set_ext *nft_set_elem_ext(const struct nft_set *set,
628                                                    void *elem)
629 {
630         return elem + set->ops->elemsize;
631 }
632
633 static inline struct nft_object **nft_set_ext_obj(const struct nft_set_ext *ext)
634 {
635         return nft_set_ext(ext, NFT_SET_EXT_OBJREF);
636 }
637
638 void *nft_set_elem_init(const struct nft_set *set,
639                         const struct nft_set_ext_tmpl *tmpl,
640                         const u32 *key, const u32 *data,
641                         u64 timeout, gfp_t gfp);
642 void nft_set_elem_destroy(const struct nft_set *set, void *elem,
643                           bool destroy_expr);
644
645 /**
646  *      struct nft_set_gc_batch_head - nf_tables set garbage collection batch
647  *
648  *      @rcu: rcu head
649  *      @set: set the elements belong to
650  *      @cnt: count of elements
651  */
652 struct nft_set_gc_batch_head {
653         struct rcu_head                 rcu;
654         const struct nft_set            *set;
655         unsigned int                    cnt;
656 };
657
658 #define NFT_SET_GC_BATCH_SIZE   ((PAGE_SIZE -                             \
659                                   sizeof(struct nft_set_gc_batch_head)) / \
660                                  sizeof(void *))
661
662 /**
663  *      struct nft_set_gc_batch - nf_tables set garbage collection batch
664  *
665  *      @head: GC batch head
666  *      @elems: garbage collection elements
667  */
668 struct nft_set_gc_batch {
669         struct nft_set_gc_batch_head    head;
670         void                            *elems[NFT_SET_GC_BATCH_SIZE];
671 };
672
673 struct nft_set_gc_batch *nft_set_gc_batch_alloc(const struct nft_set *set,
674                                                 gfp_t gfp);
675 void nft_set_gc_batch_release(struct rcu_head *rcu);
676
677 static inline void nft_set_gc_batch_complete(struct nft_set_gc_batch *gcb)
678 {
679         if (gcb != NULL)
680                 call_rcu(&gcb->head.rcu, nft_set_gc_batch_release);
681 }
682
683 static inline struct nft_set_gc_batch *
684 nft_set_gc_batch_check(const struct nft_set *set, struct nft_set_gc_batch *gcb,
685                        gfp_t gfp)
686 {
687         if (gcb != NULL) {
688                 if (gcb->head.cnt + 1 < ARRAY_SIZE(gcb->elems))
689                         return gcb;
690                 nft_set_gc_batch_complete(gcb);
691         }
692         return nft_set_gc_batch_alloc(set, gfp);
693 }
694
695 static inline void nft_set_gc_batch_add(struct nft_set_gc_batch *gcb,
696                                         void *elem)
697 {
698         gcb->elems[gcb->head.cnt++] = elem;
699 }
700
701 struct nft_expr_ops;
702 /**
703  *      struct nft_expr_type - nf_tables expression type
704  *
705  *      @select_ops: function to select nft_expr_ops
706  *      @release_ops: release nft_expr_ops
707  *      @ops: default ops, used when no select_ops functions is present
708  *      @list: used internally
709  *      @name: Identifier
710  *      @owner: module reference
711  *      @policy: netlink attribute policy
712  *      @maxattr: highest netlink attribute number
713  *      @family: address family for AF-specific types
714  *      @flags: expression type flags
715  */
716 struct nft_expr_type {
717         const struct nft_expr_ops       *(*select_ops)(const struct nft_ctx *,
718                                                        const struct nlattr * const tb[]);
719         void                            (*release_ops)(const struct nft_expr_ops *ops);
720         const struct nft_expr_ops       *ops;
721         struct list_head                list;
722         const char                      *name;
723         struct module                   *owner;
724         const struct nla_policy         *policy;
725         unsigned int                    maxattr;
726         u8                              family;
727         u8                              flags;
728 };
729
730 #define NFT_EXPR_STATEFUL               0x1
731 #define NFT_EXPR_GC                     0x2
732
733 enum nft_trans_phase {
734         NFT_TRANS_PREPARE,
735         NFT_TRANS_ABORT,
736         NFT_TRANS_COMMIT,
737         NFT_TRANS_RELEASE
738 };
739
740 /**
741  *      struct nft_expr_ops - nf_tables expression operations
742  *
743  *      @eval: Expression evaluation function
744  *      @size: full expression size, including private data size
745  *      @init: initialization function
746  *      @activate: activate expression in the next generation
747  *      @deactivate: deactivate expression in next generation
748  *      @destroy: destruction function, called after synchronize_rcu
749  *      @dump: function to dump parameters
750  *      @type: expression type
751  *      @validate: validate expression, called during loop detection
752  *      @data: extra data to attach to this expression operation
753  */
754 struct nft_expr;
755 struct nft_expr_ops {
756         void                            (*eval)(const struct nft_expr *expr,
757                                                 struct nft_regs *regs,
758                                                 const struct nft_pktinfo *pkt);
759         int                             (*clone)(struct nft_expr *dst,
760                                                  const struct nft_expr *src);
761         unsigned int                    size;
762
763         int                             (*init)(const struct nft_ctx *ctx,
764                                                 const struct nft_expr *expr,
765                                                 const struct nlattr * const tb[]);
766         void                            (*activate)(const struct nft_ctx *ctx,
767                                                     const struct nft_expr *expr);
768         void                            (*deactivate)(const struct nft_ctx *ctx,
769                                                       const struct nft_expr *expr,
770                                                       enum nft_trans_phase phase);
771         void                            (*destroy)(const struct nft_ctx *ctx,
772                                                    const struct nft_expr *expr);
773         void                            (*destroy_clone)(const struct nft_ctx *ctx,
774                                                          const struct nft_expr *expr);
775         int                             (*dump)(struct sk_buff *skb,
776                                                 const struct nft_expr *expr);
777         int                             (*validate)(const struct nft_ctx *ctx,
778                                                     const struct nft_expr *expr,
779                                                     const struct nft_data **data);
780         bool                            (*gc)(struct net *net,
781                                               const struct nft_expr *expr);
782         const struct nft_expr_type      *type;
783         void                            *data;
784 };
785
786 #define NFT_EXPR_MAXATTR                16
787 #define NFT_EXPR_SIZE(size)             (sizeof(struct nft_expr) + \
788                                          ALIGN(size, __alignof__(struct nft_expr)))
789
790 /**
791  *      struct nft_expr - nf_tables expression
792  *
793  *      @ops: expression ops
794  *      @data: expression private data
795  */
796 struct nft_expr {
797         const struct nft_expr_ops       *ops;
798         unsigned char                   data[]
799                 __attribute__((aligned(__alignof__(u64))));
800 };
801
802 static inline void *nft_expr_priv(const struct nft_expr *expr)
803 {
804         return (void *)expr->data;
805 }
806
807 struct nft_expr *nft_expr_init(const struct nft_ctx *ctx,
808                                const struct nlattr *nla);
809 void nft_expr_destroy(const struct nft_ctx *ctx, struct nft_expr *expr);
810 int nft_expr_dump(struct sk_buff *skb, unsigned int attr,
811                   const struct nft_expr *expr);
812
813 static inline int nft_expr_clone(struct nft_expr *dst, struct nft_expr *src)
814 {
815         int err;
816
817         if (src->ops->clone) {
818                 dst->ops = src->ops;
819                 err = src->ops->clone(dst, src);
820                 if (err < 0)
821                         return err;
822         } else {
823                 memcpy(dst, src, src->ops->size);
824         }
825
826         __module_get(src->ops->type->owner);
827         return 0;
828 }
829
830 /**
831  *      struct nft_rule - nf_tables rule
832  *
833  *      @list: used internally
834  *      @handle: rule handle
835  *      @genmask: generation mask
836  *      @dlen: length of expression data
837  *      @udata: user data is appended to the rule
838  *      @data: expression data
839  */
840 struct nft_rule {
841         struct list_head                list;
842         u64                             handle:42,
843                                         genmask:2,
844                                         dlen:12,
845                                         udata:1;
846         unsigned char                   data[]
847                 __attribute__((aligned(__alignof__(struct nft_expr))));
848 };
849
850 static inline struct nft_expr *nft_expr_first(const struct nft_rule *rule)
851 {
852         return (struct nft_expr *)&rule->data[0];
853 }
854
855 static inline struct nft_expr *nft_expr_next(const struct nft_expr *expr)
856 {
857         return ((void *)expr) + expr->ops->size;
858 }
859
860 static inline struct nft_expr *nft_expr_last(const struct nft_rule *rule)
861 {
862         return (struct nft_expr *)&rule->data[rule->dlen];
863 }
864
865 static inline struct nft_userdata *nft_userdata(const struct nft_rule *rule)
866 {
867         return (void *)&rule->data[rule->dlen];
868 }
869
870 /*
871  * The last pointer isn't really necessary, but the compiler isn't able to
872  * determine that the result of nft_expr_last() is always the same since it
873  * can't assume that the dlen value wasn't changed within calls in the loop.
874  */
875 #define nft_rule_for_each_expr(expr, last, rule) \
876         for ((expr) = nft_expr_first(rule), (last) = nft_expr_last(rule); \
877              (expr) != (last); \
878              (expr) = nft_expr_next(expr))
879
880 enum nft_chain_flags {
881         NFT_BASE_CHAIN                  = 0x1,
882 };
883
884 /**
885  *      struct nft_chain - nf_tables chain
886  *
887  *      @rules: list of rules in the chain
888  *      @list: used internally
889  *      @rhlhead: used internally
890  *      @table: table that this chain belongs to
891  *      @handle: chain handle
892  *      @use: number of jump references to this chain
893  *      @flags: bitmask of enum nft_chain_flags
894  *      @name: name of the chain
895  */
896 struct nft_chain {
897         struct nft_rule                 *__rcu *rules_gen_0;
898         struct nft_rule                 *__rcu *rules_gen_1;
899         struct list_head                rules;
900         struct list_head                list;
901         struct rhlist_head              rhlhead;
902         struct nft_table                *table;
903         u64                             handle;
904         u32                             use;
905         u8                              flags:6,
906                                         genmask:2;
907         char                            *name;
908
909         /* Only used during control plane commit phase: */
910         struct nft_rule                 **rules_next;
911 };
912
913 int nft_chain_validate(const struct nft_ctx *ctx, const struct nft_chain *chain);
914
915 enum nft_chain_types {
916         NFT_CHAIN_T_DEFAULT = 0,
917         NFT_CHAIN_T_ROUTE,
918         NFT_CHAIN_T_NAT,
919         NFT_CHAIN_T_MAX
920 };
921
922 /**
923  *      struct nft_chain_type - nf_tables chain type info
924  *
925  *      @name: name of the type
926  *      @type: numeric identifier
927  *      @family: address family
928  *      @owner: module owner
929  *      @hook_mask: mask of valid hooks
930  *      @hooks: array of hook functions
931  *      @ops_register: base chain register function
932  *      @ops_unregister: base chain unregister function
933  */
934 struct nft_chain_type {
935         const char                      *name;
936         enum nft_chain_types            type;
937         int                             family;
938         struct module                   *owner;
939         unsigned int                    hook_mask;
940         nf_hookfn                       *hooks[NF_MAX_HOOKS];
941         int                             (*ops_register)(struct net *net, const struct nf_hook_ops *ops);
942         void                            (*ops_unregister)(struct net *net, const struct nf_hook_ops *ops);
943 };
944
945 int nft_chain_validate_dependency(const struct nft_chain *chain,
946                                   enum nft_chain_types type);
947 int nft_chain_validate_hooks(const struct nft_chain *chain,
948                              unsigned int hook_flags);
949
950 struct nft_stats {
951         u64                     bytes;
952         u64                     pkts;
953         struct u64_stats_sync   syncp;
954 };
955
956 /**
957  *      struct nft_base_chain - nf_tables base chain
958  *
959  *      @ops: netfilter hook ops
960  *      @type: chain type
961  *      @policy: default policy
962  *      @stats: per-cpu chain stats
963  *      @chain: the chain
964  *      @dev_name: device name that this base chain is attached to (if any)
965  */
966 struct nft_base_chain {
967         struct nf_hook_ops              ops;
968         const struct nft_chain_type     *type;
969         u8                              policy;
970         u8                              flags;
971         struct nft_stats __percpu       *stats;
972         struct nft_chain                chain;
973         char                            dev_name[IFNAMSIZ];
974 };
975
976 static inline struct nft_base_chain *nft_base_chain(const struct nft_chain *chain)
977 {
978         return container_of(chain, struct nft_base_chain, chain);
979 }
980
981 static inline bool nft_is_base_chain(const struct nft_chain *chain)
982 {
983         return chain->flags & NFT_BASE_CHAIN;
984 }
985
986 int __nft_release_basechain(struct nft_ctx *ctx);
987
988 unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);
989
990 /**
991  *      struct nft_table - nf_tables table
992  *
993  *      @list: used internally
994  *      @chains_ht: chains in the table
995  *      @chains: same, for stable walks
996  *      @sets: sets in the table
997  *      @objects: stateful objects in the table
998  *      @flowtables: flow tables in the table
999  *      @hgenerator: handle generator state
1000  *      @handle: table handle
1001  *      @use: number of chain references to this table
1002  *      @flags: table flag (see enum nft_table_flags)
1003  *      @genmask: generation mask
1004  *      @afinfo: address family info
1005  *      @name: name of the table
1006  */
1007 struct nft_table {
1008         struct list_head                list;
1009         struct rhltable                 chains_ht;
1010         struct list_head                chains;
1011         struct list_head                sets;
1012         struct list_head                objects;
1013         struct list_head                flowtables;
1014         u64                             hgenerator;
1015         u64                             handle;
1016         u32                             use;
1017         u16                             family:6,
1018                                         flags:8,
1019                                         genmask:2;
1020         char                            *name;
1021 };
1022
1023 void nft_register_chain_type(const struct nft_chain_type *);
1024 void nft_unregister_chain_type(const struct nft_chain_type *);
1025
1026 int nft_register_expr(struct nft_expr_type *);
1027 void nft_unregister_expr(struct nft_expr_type *);
1028
1029 int nft_verdict_dump(struct sk_buff *skb, int type,
1030                      const struct nft_verdict *v);
1031
1032 /**
1033  *      struct nft_object - nf_tables stateful object
1034  *
1035  *      @list: table stateful object list node
1036  *      @table: table this object belongs to
1037  *      @name: name of this stateful object
1038  *      @genmask: generation mask
1039  *      @use: number of references to this stateful object
1040  *      @handle: unique object handle
1041  *      @ops: object operations
1042  *      @data: object data, layout depends on type
1043  */
1044 struct nft_object {
1045         struct list_head                list;
1046         char                            *name;
1047         struct nft_table                *table;
1048         u32                             genmask:2,
1049                                         use:30;
1050         u64                             handle;
1051         /* runtime data below here */
1052         const struct nft_object_ops     *ops ____cacheline_aligned;
1053         unsigned char                   data[]
1054                 __attribute__((aligned(__alignof__(u64))));
1055 };
1056
1057 static inline void *nft_obj_data(const struct nft_object *obj)
1058 {
1059         return (void *)obj->data;
1060 }
1061
1062 #define nft_expr_obj(expr)      *((struct nft_object **)nft_expr_priv(expr))
1063
1064 struct nft_object *nft_obj_lookup(const struct nft_table *table,
1065                                   const struct nlattr *nla, u32 objtype,
1066                                   u8 genmask);
1067
1068 void nft_obj_notify(struct net *net, struct nft_table *table,
1069                     struct nft_object *obj, u32 portid, u32 seq,
1070                     int event, int family, int report, gfp_t gfp);
1071
1072 /**
1073  *      struct nft_object_type - stateful object type
1074  *
1075  *      @select_ops: function to select nft_object_ops
1076  *      @ops: default ops, used when no select_ops functions is present
1077  *      @list: list node in list of object types
1078  *      @type: stateful object numeric type
1079  *      @owner: module owner
1080  *      @maxattr: maximum netlink attribute
1081  *      @policy: netlink attribute policy
1082  */
1083 struct nft_object_type {
1084         const struct nft_object_ops     *(*select_ops)(const struct nft_ctx *,
1085                                                        const struct nlattr * const tb[]);
1086         const struct nft_object_ops     *ops;
1087         struct list_head                list;
1088         u32                             type;
1089         unsigned int                    maxattr;
1090         struct module                   *owner;
1091         const struct nla_policy         *policy;
1092 };
1093
1094 /**
1095  *      struct nft_object_ops - stateful object operations
1096  *
1097  *      @eval: stateful object evaluation function
1098  *      @size: stateful object size
1099  *      @init: initialize object from netlink attributes
1100  *      @destroy: release existing stateful object
1101  *      @dump: netlink dump stateful object
1102  */
1103 struct nft_object_ops {
1104         void                            (*eval)(struct nft_object *obj,
1105                                                 struct nft_regs *regs,
1106                                                 const struct nft_pktinfo *pkt);
1107         unsigned int                    size;
1108         int                             (*init)(const struct nft_ctx *ctx,
1109                                                 const struct nlattr *const tb[],
1110                                                 struct nft_object *obj);
1111         void                            (*destroy)(const struct nft_ctx *ctx,
1112                                                    struct nft_object *obj);
1113         int                             (*dump)(struct sk_buff *skb,
1114                                                 struct nft_object *obj,
1115                                                 bool reset);
1116         const struct nft_object_type    *type;
1117 };
1118
1119 int nft_register_obj(struct nft_object_type *obj_type);
1120 void nft_unregister_obj(struct nft_object_type *obj_type);
1121
1122 #define NFT_FLOWTABLE_DEVICE_MAX        8
1123
1124 /**
1125  *      struct nft_flowtable - nf_tables flow table
1126  *
1127  *      @list: flow table list node in table list
1128  *      @table: the table the flow table is contained in
1129  *      @name: name of this flow table
1130  *      @hooknum: hook number
1131  *      @priority: hook priority
1132  *      @ops_len: number of hooks in array
1133  *      @genmask: generation mask
1134  *      @use: number of references to this flow table
1135  *      @handle: unique object handle
1136  *      @dev_name: array of device names
1137  *      @data: rhashtable and garbage collector
1138  *      @ops: array of hooks
1139  */
1140 struct nft_flowtable {
1141         struct list_head                list;
1142         struct nft_table                *table;
1143         char                            *name;
1144         int                             hooknum;
1145         int                             priority;
1146         int                             ops_len;
1147         u32                             genmask:2,
1148                                         use:30;
1149         u64                             handle;
1150         /* runtime data below here */
1151         struct nf_hook_ops              *ops ____cacheline_aligned;
1152         struct nf_flowtable             data;
1153 };
1154
1155 struct nft_flowtable *nft_flowtable_lookup(const struct nft_table *table,
1156                                            const struct nlattr *nla,
1157                                            u8 genmask);
1158
1159 void nft_register_flowtable_type(struct nf_flowtable_type *type);
1160 void nft_unregister_flowtable_type(struct nf_flowtable_type *type);
1161
1162 /**
1163  *      struct nft_traceinfo - nft tracing information and state
1164  *
1165  *      @pkt: pktinfo currently processed
1166  *      @basechain: base chain currently processed
1167  *      @chain: chain currently processed
1168  *      @rule:  rule that was evaluated
1169  *      @verdict: verdict given by rule
1170  *      @type: event type (enum nft_trace_types)
1171  *      @packet_dumped: packet headers sent in a previous traceinfo message
1172  *      @trace: other struct members are initialised
1173  */
1174 struct nft_traceinfo {
1175         const struct nft_pktinfo        *pkt;
1176         const struct nft_base_chain     *basechain;
1177         const struct nft_chain          *chain;
1178         const struct nft_rule           *rule;
1179         const struct nft_verdict        *verdict;
1180         enum nft_trace_types            type;
1181         bool                            packet_dumped;
1182         bool                            trace;
1183 };
1184
1185 void nft_trace_init(struct nft_traceinfo *info, const struct nft_pktinfo *pkt,
1186                     const struct nft_verdict *verdict,
1187                     const struct nft_chain *basechain);
1188
1189 void nft_trace_notify(struct nft_traceinfo *info);
1190
1191 #define MODULE_ALIAS_NFT_CHAIN(family, name) \
1192         MODULE_ALIAS("nft-chain-" __stringify(family) "-" name)
1193
1194 #define MODULE_ALIAS_NFT_AF_EXPR(family, name) \
1195         MODULE_ALIAS("nft-expr-" __stringify(family) "-" name)
1196
1197 #define MODULE_ALIAS_NFT_EXPR(name) \
1198         MODULE_ALIAS("nft-expr-" name)
1199
1200 #define MODULE_ALIAS_NFT_SET() \
1201         MODULE_ALIAS("nft-set")
1202
1203 #define MODULE_ALIAS_NFT_OBJ(type) \
1204         MODULE_ALIAS("nft-obj-" __stringify(type))
1205
1206 /*
1207  * The gencursor defines two generations, the currently active and the
1208  * next one. Objects contain a bitmask of 2 bits specifying the generations
1209  * they're active in. A set bit means they're inactive in the generation
1210  * represented by that bit.
1211  *
1212  * New objects start out as inactive in the current and active in the
1213  * next generation. When committing the ruleset the bitmask is cleared,
1214  * meaning they're active in all generations. When removing an object,
1215  * it is set inactive in the next generation. After committing the ruleset,
1216  * the objects are removed.
1217  */
1218 static inline unsigned int nft_gencursor_next(const struct net *net)
1219 {
1220         return net->nft.gencursor + 1 == 1 ? 1 : 0;
1221 }
1222
1223 static inline u8 nft_genmask_next(const struct net *net)
1224 {
1225         return 1 << nft_gencursor_next(net);
1226 }
1227
1228 static inline u8 nft_genmask_cur(const struct net *net)
1229 {
1230         /* Use READ_ONCE() to prevent refetching the value for atomicity */
1231         return 1 << READ_ONCE(net->nft.gencursor);
1232 }
1233
1234 #define NFT_GENMASK_ANY         ((1 << 0) | (1 << 1))
1235
1236 /*
1237  * Generic transaction helpers
1238  */
1239
1240 /* Check if this object is currently active. */
1241 #define nft_is_active(__net, __obj)                             \
1242         (((__obj)->genmask & nft_genmask_cur(__net)) == 0)
1243
1244 /* Check if this object is active in the next generation. */
1245 #define nft_is_active_next(__net, __obj)                        \
1246         (((__obj)->genmask & nft_genmask_next(__net)) == 0)
1247
1248 /* This object becomes active in the next generation. */
1249 #define nft_activate_next(__net, __obj)                         \
1250         (__obj)->genmask = nft_genmask_cur(__net)
1251
1252 /* This object becomes inactive in the next generation. */
1253 #define nft_deactivate_next(__net, __obj)                       \
1254         (__obj)->genmask = nft_genmask_next(__net)
1255
1256 /* After committing the ruleset, clear the stale generation bit. */
1257 #define nft_clear(__net, __obj)                                 \
1258         (__obj)->genmask &= ~nft_genmask_next(__net)
1259 #define nft_active_genmask(__obj, __genmask)                    \
1260         !((__obj)->genmask & __genmask)
1261
1262 /*
1263  * Set element transaction helpers
1264  */
1265
1266 static inline bool nft_set_elem_active(const struct nft_set_ext *ext,
1267                                        u8 genmask)
1268 {
1269         return !(ext->genmask & genmask);
1270 }
1271
1272 static inline void nft_set_elem_change_active(const struct net *net,
1273                                               const struct nft_set *set,
1274                                               struct nft_set_ext *ext)
1275 {
1276         ext->genmask ^= nft_genmask_next(net);
1277 }
1278
1279 /*
1280  * We use a free bit in the genmask field to indicate the element
1281  * is busy, meaning it is currently being processed either by
1282  * the netlink API or GC.
1283  *
1284  * Even though the genmask is only a single byte wide, this works
1285  * because the extension structure if fully constant once initialized,
1286  * so there are no non-atomic write accesses unless it is already
1287  * marked busy.
1288  */
1289 #define NFT_SET_ELEM_BUSY_MASK  (1 << 2)
1290
1291 #if defined(__LITTLE_ENDIAN_BITFIELD)
1292 #define NFT_SET_ELEM_BUSY_BIT   2
1293 #elif defined(__BIG_ENDIAN_BITFIELD)
1294 #define NFT_SET_ELEM_BUSY_BIT   (BITS_PER_LONG - BITS_PER_BYTE + 2)
1295 #else
1296 #error
1297 #endif
1298
1299 static inline int nft_set_elem_mark_busy(struct nft_set_ext *ext)
1300 {
1301         unsigned long *word = (unsigned long *)ext;
1302
1303         BUILD_BUG_ON(offsetof(struct nft_set_ext, genmask) != 0);
1304         return test_and_set_bit(NFT_SET_ELEM_BUSY_BIT, word);
1305 }
1306
1307 static inline void nft_set_elem_clear_busy(struct nft_set_ext *ext)
1308 {
1309         unsigned long *word = (unsigned long *)ext;
1310
1311         clear_bit(NFT_SET_ELEM_BUSY_BIT, word);
1312 }
1313
1314 /**
1315  *      struct nft_trans - nf_tables object update in transaction
1316  *
1317  *      @list: used internally
1318  *      @msg_type: message type
1319  *      @ctx: transaction context
1320  *      @data: internal information related to the transaction
1321  */
1322 struct nft_trans {
1323         struct list_head                list;
1324         int                             msg_type;
1325         struct nft_ctx                  ctx;
1326         char                            data[0];
1327 };
1328
1329 struct nft_trans_rule {
1330         struct nft_rule                 *rule;
1331         u32                             rule_id;
1332 };
1333
1334 #define nft_trans_rule(trans)   \
1335         (((struct nft_trans_rule *)trans->data)->rule)
1336 #define nft_trans_rule_id(trans)        \
1337         (((struct nft_trans_rule *)trans->data)->rule_id)
1338
1339 struct nft_trans_set {
1340         struct nft_set                  *set;
1341         u32                             set_id;
1342         bool                            bound;
1343 };
1344
1345 #define nft_trans_set(trans)    \
1346         (((struct nft_trans_set *)trans->data)->set)
1347 #define nft_trans_set_id(trans) \
1348         (((struct nft_trans_set *)trans->data)->set_id)
1349 #define nft_trans_set_bound(trans)      \
1350         (((struct nft_trans_set *)trans->data)->bound)
1351
1352 struct nft_trans_chain {
1353         bool                            update;
1354         char                            *name;
1355         struct nft_stats __percpu       *stats;
1356         u8                              policy;
1357 };
1358
1359 #define nft_trans_chain_update(trans)   \
1360         (((struct nft_trans_chain *)trans->data)->update)
1361 #define nft_trans_chain_name(trans)     \
1362         (((struct nft_trans_chain *)trans->data)->name)
1363 #define nft_trans_chain_stats(trans)    \
1364         (((struct nft_trans_chain *)trans->data)->stats)
1365 #define nft_trans_chain_policy(trans)   \
1366         (((struct nft_trans_chain *)trans->data)->policy)
1367
1368 struct nft_trans_table {
1369         bool                            update;
1370         bool                            enable;
1371 };
1372
1373 #define nft_trans_table_update(trans)   \
1374         (((struct nft_trans_table *)trans->data)->update)
1375 #define nft_trans_table_enable(trans)   \
1376         (((struct nft_trans_table *)trans->data)->enable)
1377
1378 struct nft_trans_elem {
1379         struct nft_set                  *set;
1380         struct nft_set_elem             elem;
1381         bool                            bound;
1382 };
1383
1384 #define nft_trans_elem_set(trans)       \
1385         (((struct nft_trans_elem *)trans->data)->set)
1386 #define nft_trans_elem(trans)   \
1387         (((struct nft_trans_elem *)trans->data)->elem)
1388 #define nft_trans_elem_set_bound(trans) \
1389         (((struct nft_trans_elem *)trans->data)->bound)
1390
1391 struct nft_trans_obj {
1392         struct nft_object               *obj;
1393 };
1394
1395 #define nft_trans_obj(trans)    \
1396         (((struct nft_trans_obj *)trans->data)->obj)
1397
1398 struct nft_trans_flowtable {
1399         struct nft_flowtable            *flowtable;
1400 };
1401
1402 #define nft_trans_flowtable(trans)      \
1403         (((struct nft_trans_flowtable *)trans->data)->flowtable)
1404
1405 int __init nft_chain_filter_init(void);
1406 void nft_chain_filter_fini(void);
1407
1408 #endif /* _NET_NF_TABLES_H */