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