GNU Linux-libre 4.19.286-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 int nft_dump_register(struct sk_buff *skb, unsigned int attr, unsigned int reg);
195
196 int nft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len);
197 int nft_parse_register_store(const struct nft_ctx *ctx,
198                              const struct nlattr *attr, u8 *dreg,
199                              const struct nft_data *data,
200                              enum nft_data_types type, unsigned int len);
201
202 /**
203  *      struct nft_userdata - user defined data associated with an object
204  *
205  *      @len: length of the data
206  *      @data: content
207  *
208  *      The presence of user data is indicated in an object specific fashion,
209  *      so a length of zero can't occur and the value "len" indicates data
210  *      of length len + 1.
211  */
212 struct nft_userdata {
213         u8                      len;
214         unsigned char           data[0];
215 };
216
217 /**
218  *      struct nft_set_elem - generic representation of set elements
219  *
220  *      @key: element key
221  *      @priv: element private data and extensions
222  */
223 struct nft_set_elem {
224         union {
225                 u32             buf[NFT_DATA_VALUE_MAXLEN / sizeof(u32)];
226                 struct nft_data val;
227         } key;
228         union {
229                 u32             buf[NFT_DATA_VALUE_MAXLEN / sizeof(u32)];
230                 struct nft_data val;
231         } data;
232         void                    *priv;
233 };
234
235 struct nft_set;
236 struct nft_set_iter {
237         u8              genmask;
238         unsigned int    count;
239         unsigned int    skip;
240         int             err;
241         int             (*fn)(const struct nft_ctx *ctx,
242                               struct nft_set *set,
243                               const struct nft_set_iter *iter,
244                               struct nft_set_elem *elem);
245 };
246
247 /**
248  *      struct nft_set_desc - description of set elements
249  *
250  *      @klen: key length
251  *      @dlen: data length
252  *      @size: number of set elements
253  */
254 struct nft_set_desc {
255         unsigned int            klen;
256         unsigned int            dlen;
257         unsigned int            size;
258 };
259
260 /**
261  *      enum nft_set_class - performance class
262  *
263  *      @NFT_LOOKUP_O_1: constant, O(1)
264  *      @NFT_LOOKUP_O_LOG_N: logarithmic, O(log N)
265  *      @NFT_LOOKUP_O_N: linear, O(N)
266  */
267 enum nft_set_class {
268         NFT_SET_CLASS_O_1,
269         NFT_SET_CLASS_O_LOG_N,
270         NFT_SET_CLASS_O_N,
271 };
272
273 /**
274  *      struct nft_set_estimate - estimation of memory and performance
275  *                                characteristics
276  *
277  *      @size: required memory
278  *      @lookup: lookup performance class
279  *      @space: memory class
280  */
281 struct nft_set_estimate {
282         u64                     size;
283         enum nft_set_class      lookup;
284         enum nft_set_class      space;
285 };
286
287 struct nft_set_ext;
288 struct nft_expr;
289
290 /**
291  *      struct nft_set_ops - nf_tables set operations
292  *
293  *      @lookup: look up an element within the set
294  *      @insert: insert new element into set
295  *      @activate: activate new element in the next generation
296  *      @deactivate: lookup for element and deactivate it in the next generation
297  *      @flush: deactivate element in the next generation
298  *      @remove: remove element from set
299  *      @walk: iterate over all set elemeennts
300  *      @get: get set elements
301  *      @privsize: function to return size of set private data
302  *      @init: initialize private data of new set instance
303  *      @destroy: destroy private data of set instance
304  *      @elemsize: element private size
305  */
306 struct nft_set_ops {
307         bool                            (*lookup)(const struct net *net,
308                                                   const struct nft_set *set,
309                                                   const u32 *key,
310                                                   const struct nft_set_ext **ext);
311         bool                            (*update)(struct nft_set *set,
312                                                   const u32 *key,
313                                                   void *(*new)(struct nft_set *,
314                                                                const struct nft_expr *,
315                                                                struct nft_regs *),
316                                                   const struct nft_expr *expr,
317                                                   struct nft_regs *regs,
318                                                   const struct nft_set_ext **ext);
319
320         int                             (*insert)(const struct net *net,
321                                                   const struct nft_set *set,
322                                                   const struct nft_set_elem *elem,
323                                                   struct nft_set_ext **ext);
324         void                            (*activate)(const struct net *net,
325                                                     const struct nft_set *set,
326                                                     const struct nft_set_elem *elem);
327         void *                          (*deactivate)(const struct net *net,
328                                                       const struct nft_set *set,
329                                                       const struct nft_set_elem *elem);
330         bool                            (*flush)(const struct net *net,
331                                                  const struct nft_set *set,
332                                                  void *priv);
333         void                            (*remove)(const struct net *net,
334                                                   const struct nft_set *set,
335                                                   const struct nft_set_elem *elem);
336         void                            (*walk)(const struct nft_ctx *ctx,
337                                                 struct nft_set *set,
338                                                 struct nft_set_iter *iter);
339         void *                          (*get)(const struct net *net,
340                                                const struct nft_set *set,
341                                                const struct nft_set_elem *elem,
342                                                unsigned int flags);
343
344         u64                             (*privsize)(const struct nlattr * const nla[],
345                                                     const struct nft_set_desc *desc);
346         bool                            (*estimate)(const struct nft_set_desc *desc,
347                                                     u32 features,
348                                                     struct nft_set_estimate *est);
349         int                             (*init)(const struct nft_set *set,
350                                                 const struct nft_set_desc *desc,
351                                                 const struct nlattr * const nla[]);
352         void                            (*destroy)(const struct nft_set *set);
353         void                            (*gc_init)(const struct nft_set *set);
354
355         unsigned int                    elemsize;
356 };
357
358 /**
359  *      struct nft_set_type - nf_tables set type
360  *
361  *      @ops: set ops for this type
362  *      @list: used internally
363  *      @owner: module reference
364  *      @features: features supported by the implementation
365  */
366 struct nft_set_type {
367         const struct nft_set_ops        ops;
368         struct list_head                list;
369         struct module                   *owner;
370         u32                             features;
371 };
372 #define to_set_type(o) container_of(o, struct nft_set_type, ops)
373
374 int nft_register_set(struct nft_set_type *type);
375 void nft_unregister_set(struct nft_set_type *type);
376
377 /**
378  *      struct nft_set - nf_tables set instance
379  *
380  *      @list: table set list node
381  *      @bindings: list of set bindings
382  *      @table: table this set belongs to
383  *      @net: netnamespace this set belongs to
384  *      @name: name of the set
385  *      @handle: unique handle of the set
386  *      @ktype: key type (numeric type defined by userspace, not used in the kernel)
387  *      @dtype: data type (verdict or numeric type defined by userspace)
388  *      @objtype: object type (see NFT_OBJECT_* definitions)
389  *      @size: maximum set size
390  *      @use: number of rules references to this set
391  *      @nelems: number of elements
392  *      @ndeact: number of deactivated elements queued for removal
393  *      @timeout: default timeout value in jiffies
394  *      @gc_int: garbage collection interval in msecs
395  *      @policy: set parameterization (see enum nft_set_policies)
396  *      @udlen: user data length
397  *      @udata: user data
398  *      @ops: set ops
399  *      @flags: set flags
400  *      @genmask: generation mask
401  *      @klen: key length
402  *      @dlen: data length
403  *      @data: private set data
404  */
405 struct nft_set {
406         struct list_head                list;
407         struct list_head                bindings;
408         struct nft_table                *table;
409         possible_net_t                  net;
410         char                            *name;
411         u64                             handle;
412         u32                             ktype;
413         u32                             dtype;
414         u32                             objtype;
415         u32                             size;
416         u32                             use;
417         atomic_t                        nelems;
418         u32                             ndeact;
419         u64                             timeout;
420         u32                             gc_int;
421         u16                             policy;
422         u16                             udlen;
423         unsigned char                   *udata;
424         /* runtime data below here */
425         const struct nft_set_ops        *ops ____cacheline_aligned;
426         u16                             flags:14,
427                                         genmask:2;
428         u8                              klen;
429         u8                              dlen;
430         unsigned char                   data[]
431                 __attribute__((aligned(__alignof__(u64))));
432 };
433
434 static inline bool nft_set_is_anonymous(const struct nft_set *set)
435 {
436         return set->flags & NFT_SET_ANONYMOUS;
437 }
438
439 static inline void *nft_set_priv(const struct nft_set *set)
440 {
441         return (void *)set->data;
442 }
443
444 static inline struct nft_set *nft_set_container_of(const void *priv)
445 {
446         return (void *)priv - offsetof(struct nft_set, data);
447 }
448
449 struct nft_set *nft_set_lookup_global(const struct net *net,
450                                       const struct nft_table *table,
451                                       const struct nlattr *nla_set_name,
452                                       const struct nlattr *nla_set_id,
453                                       u8 genmask);
454
455 static inline unsigned long nft_set_gc_interval(const struct nft_set *set)
456 {
457         return set->gc_int ? msecs_to_jiffies(set->gc_int) : HZ;
458 }
459
460 /**
461  *      struct nft_set_binding - nf_tables set binding
462  *
463  *      @list: set bindings list node
464  *      @chain: chain containing the rule bound to the set
465  *      @flags: set action flags
466  *
467  *      A set binding contains all information necessary for validation
468  *      of new elements added to a bound set.
469  */
470 struct nft_set_binding {
471         struct list_head                list;
472         const struct nft_chain          *chain;
473         u32                             flags;
474 };
475
476 enum nft_trans_phase;
477 void nf_tables_activate_set(const struct nft_ctx *ctx, struct nft_set *set);
478 void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set,
479                               struct nft_set_binding *binding,
480                               enum nft_trans_phase phase);
481 int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,
482                        struct nft_set_binding *binding);
483 void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set,
484                           struct nft_set_binding *binding, bool commit);
485 void nf_tables_destroy_set(const struct nft_ctx *ctx, struct nft_set *set);
486
487 /**
488  *      enum nft_set_extensions - set extension type IDs
489  *
490  *      @NFT_SET_EXT_KEY: element key
491  *      @NFT_SET_EXT_DATA: mapping data
492  *      @NFT_SET_EXT_FLAGS: element flags
493  *      @NFT_SET_EXT_TIMEOUT: element timeout
494  *      @NFT_SET_EXT_EXPIRATION: element expiration time
495  *      @NFT_SET_EXT_USERDATA: user data associated with the element
496  *      @NFT_SET_EXT_EXPR: expression assiociated with the element
497  *      @NFT_SET_EXT_OBJREF: stateful object reference associated with element
498  *      @NFT_SET_EXT_NUM: number of extension types
499  */
500 enum nft_set_extensions {
501         NFT_SET_EXT_KEY,
502         NFT_SET_EXT_DATA,
503         NFT_SET_EXT_FLAGS,
504         NFT_SET_EXT_TIMEOUT,
505         NFT_SET_EXT_EXPIRATION,
506         NFT_SET_EXT_USERDATA,
507         NFT_SET_EXT_EXPR,
508         NFT_SET_EXT_OBJREF,
509         NFT_SET_EXT_NUM
510 };
511
512 /**
513  *      struct nft_set_ext_type - set extension type
514  *
515  *      @len: fixed part length of the extension
516  *      @align: alignment requirements of the extension
517  */
518 struct nft_set_ext_type {
519         u8      len;
520         u8      align;
521 };
522
523 extern const struct nft_set_ext_type nft_set_ext_types[];
524
525 /**
526  *      struct nft_set_ext_tmpl - set extension template
527  *
528  *      @len: length of extension area
529  *      @offset: offsets of individual extension types
530  */
531 struct nft_set_ext_tmpl {
532         u16     len;
533         u8      offset[NFT_SET_EXT_NUM];
534 };
535
536 /**
537  *      struct nft_set_ext - set extensions
538  *
539  *      @genmask: generation mask
540  *      @offset: offsets of individual extension types
541  *      @data: beginning of extension data
542  */
543 struct nft_set_ext {
544         u8      genmask;
545         u8      offset[NFT_SET_EXT_NUM];
546         char    data[0];
547 };
548
549 static inline void nft_set_ext_prepare(struct nft_set_ext_tmpl *tmpl)
550 {
551         memset(tmpl, 0, sizeof(*tmpl));
552         tmpl->len = sizeof(struct nft_set_ext);
553 }
554
555 static inline void nft_set_ext_add_length(struct nft_set_ext_tmpl *tmpl, u8 id,
556                                           unsigned int len)
557 {
558         tmpl->len        = ALIGN(tmpl->len, nft_set_ext_types[id].align);
559         BUG_ON(tmpl->len > U8_MAX);
560         tmpl->offset[id] = tmpl->len;
561         tmpl->len       += nft_set_ext_types[id].len + len;
562 }
563
564 static inline void nft_set_ext_add(struct nft_set_ext_tmpl *tmpl, u8 id)
565 {
566         nft_set_ext_add_length(tmpl, id, 0);
567 }
568
569 static inline void nft_set_ext_init(struct nft_set_ext *ext,
570                                     const struct nft_set_ext_tmpl *tmpl)
571 {
572         memcpy(ext->offset, tmpl->offset, sizeof(ext->offset));
573 }
574
575 static inline bool __nft_set_ext_exists(const struct nft_set_ext *ext, u8 id)
576 {
577         return !!ext->offset[id];
578 }
579
580 static inline bool nft_set_ext_exists(const struct nft_set_ext *ext, u8 id)
581 {
582         return ext && __nft_set_ext_exists(ext, id);
583 }
584
585 static inline void *nft_set_ext(const struct nft_set_ext *ext, u8 id)
586 {
587         return (void *)ext + ext->offset[id];
588 }
589
590 static inline struct nft_data *nft_set_ext_key(const struct nft_set_ext *ext)
591 {
592         return nft_set_ext(ext, NFT_SET_EXT_KEY);
593 }
594
595 static inline struct nft_data *nft_set_ext_data(const struct nft_set_ext *ext)
596 {
597         return nft_set_ext(ext, NFT_SET_EXT_DATA);
598 }
599
600 static inline u8 *nft_set_ext_flags(const struct nft_set_ext *ext)
601 {
602         return nft_set_ext(ext, NFT_SET_EXT_FLAGS);
603 }
604
605 static inline u64 *nft_set_ext_timeout(const struct nft_set_ext *ext)
606 {
607         return nft_set_ext(ext, NFT_SET_EXT_TIMEOUT);
608 }
609
610 static inline u64 *nft_set_ext_expiration(const struct nft_set_ext *ext)
611 {
612         return nft_set_ext(ext, NFT_SET_EXT_EXPIRATION);
613 }
614
615 static inline struct nft_userdata *nft_set_ext_userdata(const struct nft_set_ext *ext)
616 {
617         return nft_set_ext(ext, NFT_SET_EXT_USERDATA);
618 }
619
620 static inline struct nft_expr *nft_set_ext_expr(const struct nft_set_ext *ext)
621 {
622         return nft_set_ext(ext, NFT_SET_EXT_EXPR);
623 }
624
625 static inline bool nft_set_elem_expired(const struct nft_set_ext *ext)
626 {
627         return nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION) &&
628                time_is_before_eq_jiffies64(*nft_set_ext_expiration(ext));
629 }
630
631 static inline struct nft_set_ext *nft_set_elem_ext(const struct nft_set *set,
632                                                    void *elem)
633 {
634         return elem + set->ops->elemsize;
635 }
636
637 static inline struct nft_object **nft_set_ext_obj(const struct nft_set_ext *ext)
638 {
639         return nft_set_ext(ext, NFT_SET_EXT_OBJREF);
640 }
641
642 void *nft_set_elem_init(const struct nft_set *set,
643                         const struct nft_set_ext_tmpl *tmpl,
644                         const u32 *key, const u32 *data,
645                         u64 timeout, gfp_t gfp);
646 void nft_set_elem_destroy(const struct nft_set *set, void *elem,
647                           bool destroy_expr);
648
649 /**
650  *      struct nft_set_gc_batch_head - nf_tables set garbage collection batch
651  *
652  *      @rcu: rcu head
653  *      @set: set the elements belong to
654  *      @cnt: count of elements
655  */
656 struct nft_set_gc_batch_head {
657         struct rcu_head                 rcu;
658         const struct nft_set            *set;
659         unsigned int                    cnt;
660 };
661
662 #define NFT_SET_GC_BATCH_SIZE   ((PAGE_SIZE -                             \
663                                   sizeof(struct nft_set_gc_batch_head)) / \
664                                  sizeof(void *))
665
666 /**
667  *      struct nft_set_gc_batch - nf_tables set garbage collection batch
668  *
669  *      @head: GC batch head
670  *      @elems: garbage collection elements
671  */
672 struct nft_set_gc_batch {
673         struct nft_set_gc_batch_head    head;
674         void                            *elems[NFT_SET_GC_BATCH_SIZE];
675 };
676
677 struct nft_set_gc_batch *nft_set_gc_batch_alloc(const struct nft_set *set,
678                                                 gfp_t gfp);
679 void nft_set_gc_batch_release(struct rcu_head *rcu);
680
681 static inline void nft_set_gc_batch_complete(struct nft_set_gc_batch *gcb)
682 {
683         if (gcb != NULL)
684                 call_rcu(&gcb->head.rcu, nft_set_gc_batch_release);
685 }
686
687 static inline struct nft_set_gc_batch *
688 nft_set_gc_batch_check(const struct nft_set *set, struct nft_set_gc_batch *gcb,
689                        gfp_t gfp)
690 {
691         if (gcb != NULL) {
692                 if (gcb->head.cnt + 1 < ARRAY_SIZE(gcb->elems))
693                         return gcb;
694                 nft_set_gc_batch_complete(gcb);
695         }
696         return nft_set_gc_batch_alloc(set, gfp);
697 }
698
699 static inline void nft_set_gc_batch_add(struct nft_set_gc_batch *gcb,
700                                         void *elem)
701 {
702         gcb->elems[gcb->head.cnt++] = elem;
703 }
704
705 struct nft_expr_ops;
706 /**
707  *      struct nft_expr_type - nf_tables expression type
708  *
709  *      @select_ops: function to select nft_expr_ops
710  *      @release_ops: release nft_expr_ops
711  *      @ops: default ops, used when no select_ops functions is present
712  *      @list: used internally
713  *      @name: Identifier
714  *      @owner: module reference
715  *      @policy: netlink attribute policy
716  *      @maxattr: highest netlink attribute number
717  *      @family: address family for AF-specific types
718  *      @flags: expression type flags
719  */
720 struct nft_expr_type {
721         const struct nft_expr_ops       *(*select_ops)(const struct nft_ctx *,
722                                                        const struct nlattr * const tb[]);
723         void                            (*release_ops)(const struct nft_expr_ops *ops);
724         const struct nft_expr_ops       *ops;
725         struct list_head                list;
726         const char                      *name;
727         struct module                   *owner;
728         const struct nla_policy         *policy;
729         unsigned int                    maxattr;
730         u8                              family;
731         u8                              flags;
732 };
733
734 #define NFT_EXPR_STATEFUL               0x1
735 #define NFT_EXPR_GC                     0x2
736
737 enum nft_trans_phase {
738         NFT_TRANS_PREPARE,
739         NFT_TRANS_ABORT,
740         NFT_TRANS_COMMIT,
741         NFT_TRANS_RELEASE
742 };
743
744 /**
745  *      struct nft_expr_ops - nf_tables expression operations
746  *
747  *      @eval: Expression evaluation function
748  *      @size: full expression size, including private data size
749  *      @init: initialization function
750  *      @activate: activate expression in the next generation
751  *      @deactivate: deactivate expression in next generation
752  *      @destroy: destruction function, called after synchronize_rcu
753  *      @dump: function to dump parameters
754  *      @type: expression type
755  *      @validate: validate expression, called during loop detection
756  *      @data: extra data to attach to this expression operation
757  */
758 struct nft_expr;
759 struct nft_expr_ops {
760         void                            (*eval)(const struct nft_expr *expr,
761                                                 struct nft_regs *regs,
762                                                 const struct nft_pktinfo *pkt);
763         int                             (*clone)(struct nft_expr *dst,
764                                                  const struct nft_expr *src);
765         unsigned int                    size;
766
767         int                             (*init)(const struct nft_ctx *ctx,
768                                                 const struct nft_expr *expr,
769                                                 const struct nlattr * const tb[]);
770         void                            (*activate)(const struct nft_ctx *ctx,
771                                                     const struct nft_expr *expr);
772         void                            (*deactivate)(const struct nft_ctx *ctx,
773                                                       const struct nft_expr *expr,
774                                                       enum nft_trans_phase phase);
775         void                            (*destroy)(const struct nft_ctx *ctx,
776                                                    const struct nft_expr *expr);
777         void                            (*destroy_clone)(const struct nft_ctx *ctx,
778                                                          const struct nft_expr *expr);
779         int                             (*dump)(struct sk_buff *skb,
780                                                 const struct nft_expr *expr);
781         int                             (*validate)(const struct nft_ctx *ctx,
782                                                     const struct nft_expr *expr,
783                                                     const struct nft_data **data);
784         bool                            (*gc)(struct net *net,
785                                               const struct nft_expr *expr);
786         const struct nft_expr_type      *type;
787         void                            *data;
788 };
789
790 #define NFT_EXPR_MAXATTR                16
791 #define NFT_EXPR_SIZE(size)             (sizeof(struct nft_expr) + \
792                                          ALIGN(size, __alignof__(struct nft_expr)))
793
794 /**
795  *      struct nft_expr - nf_tables expression
796  *
797  *      @ops: expression ops
798  *      @data: expression private data
799  */
800 struct nft_expr {
801         const struct nft_expr_ops       *ops;
802         unsigned char                   data[]
803                 __attribute__((aligned(__alignof__(u64))));
804 };
805
806 static inline void *nft_expr_priv(const struct nft_expr *expr)
807 {
808         return (void *)expr->data;
809 }
810
811 struct nft_expr *nft_expr_init(const struct nft_ctx *ctx,
812                                const struct nlattr *nla);
813 void nft_expr_destroy(const struct nft_ctx *ctx, struct nft_expr *expr);
814 int nft_expr_dump(struct sk_buff *skb, unsigned int attr,
815                   const struct nft_expr *expr);
816
817 static inline int nft_expr_clone(struct nft_expr *dst, struct nft_expr *src)
818 {
819         int err;
820
821         if (src->ops->clone) {
822                 dst->ops = src->ops;
823                 err = src->ops->clone(dst, src);
824                 if (err < 0)
825                         return err;
826         } else {
827                 memcpy(dst, src, src->ops->size);
828         }
829
830         __module_get(src->ops->type->owner);
831         return 0;
832 }
833
834 /**
835  *      struct nft_rule - nf_tables rule
836  *
837  *      @list: used internally
838  *      @handle: rule handle
839  *      @genmask: generation mask
840  *      @dlen: length of expression data
841  *      @udata: user data is appended to the rule
842  *      @data: expression data
843  */
844 struct nft_rule {
845         struct list_head                list;
846         u64                             handle:42,
847                                         genmask:2,
848                                         dlen:12,
849                                         udata:1;
850         unsigned char                   data[]
851                 __attribute__((aligned(__alignof__(struct nft_expr))));
852 };
853
854 static inline struct nft_expr *nft_expr_first(const struct nft_rule *rule)
855 {
856         return (struct nft_expr *)&rule->data[0];
857 }
858
859 static inline struct nft_expr *nft_expr_next(const struct nft_expr *expr)
860 {
861         return ((void *)expr) + expr->ops->size;
862 }
863
864 static inline struct nft_expr *nft_expr_last(const struct nft_rule *rule)
865 {
866         return (struct nft_expr *)&rule->data[rule->dlen];
867 }
868
869 static inline struct nft_userdata *nft_userdata(const struct nft_rule *rule)
870 {
871         return (void *)&rule->data[rule->dlen];
872 }
873
874 /*
875  * The last pointer isn't really necessary, but the compiler isn't able to
876  * determine that the result of nft_expr_last() is always the same since it
877  * can't assume that the dlen value wasn't changed within calls in the loop.
878  */
879 #define nft_rule_for_each_expr(expr, last, rule) \
880         for ((expr) = nft_expr_first(rule), (last) = nft_expr_last(rule); \
881              (expr) != (last); \
882              (expr) = nft_expr_next(expr))
883
884 enum nft_chain_flags {
885         NFT_BASE_CHAIN                  = 0x1,
886 };
887
888 /**
889  *      struct nft_chain - nf_tables chain
890  *
891  *      @rules: list of rules in the chain
892  *      @list: used internally
893  *      @rhlhead: used internally
894  *      @table: table that this chain belongs to
895  *      @handle: chain handle
896  *      @use: number of jump references to this chain
897  *      @flags: bitmask of enum nft_chain_flags
898  *      @name: name of the chain
899  */
900 struct nft_chain {
901         struct nft_rule                 *__rcu *rules_gen_0;
902         struct nft_rule                 *__rcu *rules_gen_1;
903         struct list_head                rules;
904         struct list_head                list;
905         struct rhlist_head              rhlhead;
906         struct nft_table                *table;
907         u64                             handle;
908         u32                             use;
909         u8                              flags:6,
910                                         genmask:2;
911         char                            *name;
912
913         /* Only used during control plane commit phase: */
914         struct nft_rule                 **rules_next;
915 };
916
917 int nft_chain_validate(const struct nft_ctx *ctx, const struct nft_chain *chain);
918
919 enum nft_chain_types {
920         NFT_CHAIN_T_DEFAULT = 0,
921         NFT_CHAIN_T_ROUTE,
922         NFT_CHAIN_T_NAT,
923         NFT_CHAIN_T_MAX
924 };
925
926 /**
927  *      struct nft_chain_type - nf_tables chain type info
928  *
929  *      @name: name of the type
930  *      @type: numeric identifier
931  *      @family: address family
932  *      @owner: module owner
933  *      @hook_mask: mask of valid hooks
934  *      @hooks: array of hook functions
935  *      @ops_register: base chain register function
936  *      @ops_unregister: base chain unregister function
937  */
938 struct nft_chain_type {
939         const char                      *name;
940         enum nft_chain_types            type;
941         int                             family;
942         struct module                   *owner;
943         unsigned int                    hook_mask;
944         nf_hookfn                       *hooks[NF_MAX_HOOKS];
945         int                             (*ops_register)(struct net *net, const struct nf_hook_ops *ops);
946         void                            (*ops_unregister)(struct net *net, const struct nf_hook_ops *ops);
947 };
948
949 int nft_chain_validate_dependency(const struct nft_chain *chain,
950                                   enum nft_chain_types type);
951 int nft_chain_validate_hooks(const struct nft_chain *chain,
952                              unsigned int hook_flags);
953
954 struct nft_stats {
955         u64                     bytes;
956         u64                     pkts;
957         struct u64_stats_sync   syncp;
958 };
959
960 /**
961  *      struct nft_base_chain - nf_tables base chain
962  *
963  *      @ops: netfilter hook ops
964  *      @type: chain type
965  *      @policy: default policy
966  *      @stats: per-cpu chain stats
967  *      @chain: the chain
968  *      @dev_name: device name that this base chain is attached to (if any)
969  */
970 struct nft_base_chain {
971         struct nf_hook_ops              ops;
972         const struct nft_chain_type     *type;
973         u8                              policy;
974         u8                              flags;
975         struct nft_stats __percpu       *stats;
976         struct nft_chain                chain;
977         char                            dev_name[IFNAMSIZ];
978 };
979
980 static inline struct nft_base_chain *nft_base_chain(const struct nft_chain *chain)
981 {
982         return container_of(chain, struct nft_base_chain, chain);
983 }
984
985 static inline bool nft_is_base_chain(const struct nft_chain *chain)
986 {
987         return chain->flags & NFT_BASE_CHAIN;
988 }
989
990 int __nft_release_basechain(struct nft_ctx *ctx);
991
992 unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);
993
994 /**
995  *      struct nft_table - nf_tables table
996  *
997  *      @list: used internally
998  *      @chains_ht: chains in the table
999  *      @chains: same, for stable walks
1000  *      @sets: sets in the table
1001  *      @objects: stateful objects in the table
1002  *      @flowtables: flow tables in the table
1003  *      @hgenerator: handle generator state
1004  *      @handle: table handle
1005  *      @use: number of chain references to this table
1006  *      @flags: table flag (see enum nft_table_flags)
1007  *      @genmask: generation mask
1008  *      @afinfo: address family info
1009  *      @name: name of the table
1010  */
1011 struct nft_table {
1012         struct list_head                list;
1013         struct rhltable                 chains_ht;
1014         struct list_head                chains;
1015         struct list_head                sets;
1016         struct list_head                objects;
1017         struct list_head                flowtables;
1018         u64                             hgenerator;
1019         u64                             handle;
1020         u32                             use;
1021         u16                             family:6,
1022                                         flags:8,
1023                                         genmask:2;
1024         char                            *name;
1025 };
1026
1027 void nft_register_chain_type(const struct nft_chain_type *);
1028 void nft_unregister_chain_type(const struct nft_chain_type *);
1029
1030 int nft_register_expr(struct nft_expr_type *);
1031 void nft_unregister_expr(struct nft_expr_type *);
1032
1033 int nft_verdict_dump(struct sk_buff *skb, int type,
1034                      const struct nft_verdict *v);
1035
1036 /**
1037  *      struct nft_object - nf_tables stateful object
1038  *
1039  *      @list: table stateful object list node
1040  *      @table: table this object belongs to
1041  *      @name: name of this stateful object
1042  *      @genmask: generation mask
1043  *      @use: number of references to this stateful object
1044  *      @handle: unique object handle
1045  *      @ops: object operations
1046  *      @data: object data, layout depends on type
1047  */
1048 struct nft_object {
1049         struct list_head                list;
1050         char                            *name;
1051         struct nft_table                *table;
1052         u32                             genmask:2,
1053                                         use:30;
1054         u64                             handle;
1055         /* runtime data below here */
1056         const struct nft_object_ops     *ops ____cacheline_aligned;
1057         unsigned char                   data[]
1058                 __attribute__((aligned(__alignof__(u64))));
1059 };
1060
1061 static inline void *nft_obj_data(const struct nft_object *obj)
1062 {
1063         return (void *)obj->data;
1064 }
1065
1066 #define nft_expr_obj(expr)      *((struct nft_object **)nft_expr_priv(expr))
1067
1068 struct nft_object *nft_obj_lookup(const struct nft_table *table,
1069                                   const struct nlattr *nla, u32 objtype,
1070                                   u8 genmask);
1071
1072 void nft_obj_notify(struct net *net, 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  *      @ctx: transaction context
1324  *      @data: internal information related to the transaction
1325  */
1326 struct nft_trans {
1327         struct list_head                list;
1328         int                             msg_type;
1329         struct nft_ctx                  ctx;
1330         char                            data[0];
1331 };
1332
1333 struct nft_trans_rule {
1334         struct nft_rule                 *rule;
1335         u32                             rule_id;
1336 };
1337
1338 #define nft_trans_rule(trans)   \
1339         (((struct nft_trans_rule *)trans->data)->rule)
1340 #define nft_trans_rule_id(trans)        \
1341         (((struct nft_trans_rule *)trans->data)->rule_id)
1342
1343 struct nft_trans_set {
1344         struct nft_set                  *set;
1345         u32                             set_id;
1346         bool                            bound;
1347 };
1348
1349 #define nft_trans_set(trans)    \
1350         (((struct nft_trans_set *)trans->data)->set)
1351 #define nft_trans_set_id(trans) \
1352         (((struct nft_trans_set *)trans->data)->set_id)
1353 #define nft_trans_set_bound(trans)      \
1354         (((struct nft_trans_set *)trans->data)->bound)
1355
1356 struct nft_trans_chain {
1357         bool                            update;
1358         char                            *name;
1359         struct nft_stats __percpu       *stats;
1360         u8                              policy;
1361 };
1362
1363 #define nft_trans_chain_update(trans)   \
1364         (((struct nft_trans_chain *)trans->data)->update)
1365 #define nft_trans_chain_name(trans)     \
1366         (((struct nft_trans_chain *)trans->data)->name)
1367 #define nft_trans_chain_stats(trans)    \
1368         (((struct nft_trans_chain *)trans->data)->stats)
1369 #define nft_trans_chain_policy(trans)   \
1370         (((struct nft_trans_chain *)trans->data)->policy)
1371
1372 struct nft_trans_table {
1373         bool                            update;
1374         bool                            enable;
1375 };
1376
1377 #define nft_trans_table_update(trans)   \
1378         (((struct nft_trans_table *)trans->data)->update)
1379 #define nft_trans_table_enable(trans)   \
1380         (((struct nft_trans_table *)trans->data)->enable)
1381
1382 struct nft_trans_elem {
1383         struct nft_set                  *set;
1384         struct nft_set_elem             elem;
1385         bool                            bound;
1386 };
1387
1388 #define nft_trans_elem_set(trans)       \
1389         (((struct nft_trans_elem *)trans->data)->set)
1390 #define nft_trans_elem(trans)   \
1391         (((struct nft_trans_elem *)trans->data)->elem)
1392 #define nft_trans_elem_set_bound(trans) \
1393         (((struct nft_trans_elem *)trans->data)->bound)
1394
1395 struct nft_trans_obj {
1396         struct nft_object               *obj;
1397 };
1398
1399 #define nft_trans_obj(trans)    \
1400         (((struct nft_trans_obj *)trans->data)->obj)
1401
1402 struct nft_trans_flowtable {
1403         struct nft_flowtable            *flowtable;
1404 };
1405
1406 #define nft_trans_flowtable(trans)      \
1407         (((struct nft_trans_flowtable *)trans->data)->flowtable)
1408
1409 int __init nft_chain_filter_init(void);
1410 void nft_chain_filter_fini(void);
1411
1412 #endif /* _NET_NF_TABLES_H */