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