bpf: fix accessing bpf_sysctl.file_pos on s390
[linux-2.6-microblaze.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: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_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set,
478                               struct nft_set_binding *binding,
479                               enum nft_trans_phase phase);
480 int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,
481                        struct nft_set_binding *binding);
482 void nf_tables_destroy_set(const struct nft_ctx *ctx, struct nft_set *set);
483
484 /**
485  *      enum nft_set_extensions - set extension type IDs
486  *
487  *      @NFT_SET_EXT_KEY: element key
488  *      @NFT_SET_EXT_DATA: mapping data
489  *      @NFT_SET_EXT_FLAGS: element flags
490  *      @NFT_SET_EXT_TIMEOUT: element timeout
491  *      @NFT_SET_EXT_EXPIRATION: element expiration time
492  *      @NFT_SET_EXT_USERDATA: user data associated with the element
493  *      @NFT_SET_EXT_EXPR: expression assiociated with the element
494  *      @NFT_SET_EXT_OBJREF: stateful object reference associated with element
495  *      @NFT_SET_EXT_NUM: number of extension types
496  */
497 enum nft_set_extensions {
498         NFT_SET_EXT_KEY,
499         NFT_SET_EXT_DATA,
500         NFT_SET_EXT_FLAGS,
501         NFT_SET_EXT_TIMEOUT,
502         NFT_SET_EXT_EXPIRATION,
503         NFT_SET_EXT_USERDATA,
504         NFT_SET_EXT_EXPR,
505         NFT_SET_EXT_OBJREF,
506         NFT_SET_EXT_NUM
507 };
508
509 /**
510  *      struct nft_set_ext_type - set extension type
511  *
512  *      @len: fixed part length of the extension
513  *      @align: alignment requirements of the extension
514  */
515 struct nft_set_ext_type {
516         u8      len;
517         u8      align;
518 };
519
520 extern const struct nft_set_ext_type nft_set_ext_types[];
521
522 /**
523  *      struct nft_set_ext_tmpl - set extension template
524  *
525  *      @len: length of extension area
526  *      @offset: offsets of individual extension types
527  */
528 struct nft_set_ext_tmpl {
529         u16     len;
530         u8      offset[NFT_SET_EXT_NUM];
531 };
532
533 /**
534  *      struct nft_set_ext - set extensions
535  *
536  *      @genmask: generation mask
537  *      @offset: offsets of individual extension types
538  *      @data: beginning of extension data
539  */
540 struct nft_set_ext {
541         u8      genmask;
542         u8      offset[NFT_SET_EXT_NUM];
543         char    data[0];
544 };
545
546 static inline void nft_set_ext_prepare(struct nft_set_ext_tmpl *tmpl)
547 {
548         memset(tmpl, 0, sizeof(*tmpl));
549         tmpl->len = sizeof(struct nft_set_ext);
550 }
551
552 static inline void nft_set_ext_add_length(struct nft_set_ext_tmpl *tmpl, u8 id,
553                                           unsigned int len)
554 {
555         tmpl->len        = ALIGN(tmpl->len, nft_set_ext_types[id].align);
556         BUG_ON(tmpl->len > U8_MAX);
557         tmpl->offset[id] = tmpl->len;
558         tmpl->len       += nft_set_ext_types[id].len + len;
559 }
560
561 static inline void nft_set_ext_add(struct nft_set_ext_tmpl *tmpl, u8 id)
562 {
563         nft_set_ext_add_length(tmpl, id, 0);
564 }
565
566 static inline void nft_set_ext_init(struct nft_set_ext *ext,
567                                     const struct nft_set_ext_tmpl *tmpl)
568 {
569         memcpy(ext->offset, tmpl->offset, sizeof(ext->offset));
570 }
571
572 static inline bool __nft_set_ext_exists(const struct nft_set_ext *ext, u8 id)
573 {
574         return !!ext->offset[id];
575 }
576
577 static inline bool nft_set_ext_exists(const struct nft_set_ext *ext, u8 id)
578 {
579         return ext && __nft_set_ext_exists(ext, id);
580 }
581
582 static inline void *nft_set_ext(const struct nft_set_ext *ext, u8 id)
583 {
584         return (void *)ext + ext->offset[id];
585 }
586
587 static inline struct nft_data *nft_set_ext_key(const struct nft_set_ext *ext)
588 {
589         return nft_set_ext(ext, NFT_SET_EXT_KEY);
590 }
591
592 static inline struct nft_data *nft_set_ext_data(const struct nft_set_ext *ext)
593 {
594         return nft_set_ext(ext, NFT_SET_EXT_DATA);
595 }
596
597 static inline u8 *nft_set_ext_flags(const struct nft_set_ext *ext)
598 {
599         return nft_set_ext(ext, NFT_SET_EXT_FLAGS);
600 }
601
602 static inline u64 *nft_set_ext_timeout(const struct nft_set_ext *ext)
603 {
604         return nft_set_ext(ext, NFT_SET_EXT_TIMEOUT);
605 }
606
607 static inline u64 *nft_set_ext_expiration(const struct nft_set_ext *ext)
608 {
609         return nft_set_ext(ext, NFT_SET_EXT_EXPIRATION);
610 }
611
612 static inline struct nft_userdata *nft_set_ext_userdata(const struct nft_set_ext *ext)
613 {
614         return nft_set_ext(ext, NFT_SET_EXT_USERDATA);
615 }
616
617 static inline struct nft_expr *nft_set_ext_expr(const struct nft_set_ext *ext)
618 {
619         return nft_set_ext(ext, NFT_SET_EXT_EXPR);
620 }
621
622 static inline bool nft_set_elem_expired(const struct nft_set_ext *ext)
623 {
624         return nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION) &&
625                time_is_before_eq_jiffies64(*nft_set_ext_expiration(ext));
626 }
627
628 static inline struct nft_set_ext *nft_set_elem_ext(const struct nft_set *set,
629                                                    void *elem)
630 {
631         return elem + set->ops->elemsize;
632 }
633
634 static inline struct nft_object **nft_set_ext_obj(const struct nft_set_ext *ext)
635 {
636         return nft_set_ext(ext, NFT_SET_EXT_OBJREF);
637 }
638
639 void *nft_set_elem_init(const struct nft_set *set,
640                         const struct nft_set_ext_tmpl *tmpl,
641                         const u32 *key, const u32 *data,
642                         u64 timeout, u64 expiration, gfp_t gfp);
643 void nft_set_elem_destroy(const struct nft_set *set, void *elem,
644                           bool destroy_expr);
645
646 /**
647  *      struct nft_set_gc_batch_head - nf_tables set garbage collection batch
648  *
649  *      @rcu: rcu head
650  *      @set: set the elements belong to
651  *      @cnt: count of elements
652  */
653 struct nft_set_gc_batch_head {
654         struct rcu_head                 rcu;
655         const struct nft_set            *set;
656         unsigned int                    cnt;
657 };
658
659 #define NFT_SET_GC_BATCH_SIZE   ((PAGE_SIZE -                             \
660                                   sizeof(struct nft_set_gc_batch_head)) / \
661                                  sizeof(void *))
662
663 /**
664  *      struct nft_set_gc_batch - nf_tables set garbage collection batch
665  *
666  *      @head: GC batch head
667  *      @elems: garbage collection elements
668  */
669 struct nft_set_gc_batch {
670         struct nft_set_gc_batch_head    head;
671         void                            *elems[NFT_SET_GC_BATCH_SIZE];
672 };
673
674 struct nft_set_gc_batch *nft_set_gc_batch_alloc(const struct nft_set *set,
675                                                 gfp_t gfp);
676 void nft_set_gc_batch_release(struct rcu_head *rcu);
677
678 static inline void nft_set_gc_batch_complete(struct nft_set_gc_batch *gcb)
679 {
680         if (gcb != NULL)
681                 call_rcu(&gcb->head.rcu, nft_set_gc_batch_release);
682 }
683
684 static inline struct nft_set_gc_batch *
685 nft_set_gc_batch_check(const struct nft_set *set, struct nft_set_gc_batch *gcb,
686                        gfp_t gfp)
687 {
688         if (gcb != NULL) {
689                 if (gcb->head.cnt + 1 < ARRAY_SIZE(gcb->elems))
690                         return gcb;
691                 nft_set_gc_batch_complete(gcb);
692         }
693         return nft_set_gc_batch_alloc(set, gfp);
694 }
695
696 static inline void nft_set_gc_batch_add(struct nft_set_gc_batch *gcb,
697                                         void *elem)
698 {
699         gcb->elems[gcb->head.cnt++] = elem;
700 }
701
702 struct nft_expr_ops;
703 /**
704  *      struct nft_expr_type - nf_tables expression type
705  *
706  *      @select_ops: function to select nft_expr_ops
707  *      @release_ops: release nft_expr_ops
708  *      @ops: default ops, used when no select_ops functions is present
709  *      @list: used internally
710  *      @name: Identifier
711  *      @owner: module reference
712  *      @policy: netlink attribute policy
713  *      @maxattr: highest netlink attribute number
714  *      @family: address family for AF-specific types
715  *      @flags: expression type flags
716  */
717 struct nft_expr_type {
718         const struct nft_expr_ops       *(*select_ops)(const struct nft_ctx *,
719                                                        const struct nlattr * const tb[]);
720         void                            (*release_ops)(const struct nft_expr_ops *ops);
721         const struct nft_expr_ops       *ops;
722         struct list_head                list;
723         const char                      *name;
724         struct module                   *owner;
725         const struct nla_policy         *policy;
726         unsigned int                    maxattr;
727         u8                              family;
728         u8                              flags;
729 };
730
731 #define NFT_EXPR_STATEFUL               0x1
732 #define NFT_EXPR_GC                     0x2
733
734 enum nft_trans_phase {
735         NFT_TRANS_PREPARE,
736         NFT_TRANS_ABORT,
737         NFT_TRANS_COMMIT,
738         NFT_TRANS_RELEASE
739 };
740
741 struct nft_flow_rule;
742 struct nft_offload_ctx;
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         int                             (*offload)(struct nft_offload_ctx *ctx,
787                                                    struct nft_flow_rule *flow,
788                                                    const struct nft_expr *expr);
789         u32                             offload_flags;
790         const struct nft_expr_type      *type;
791         void                            *data;
792 };
793
794 #define NFT_EXPR_MAXATTR                16
795 #define NFT_EXPR_SIZE(size)             (sizeof(struct nft_expr) + \
796                                          ALIGN(size, __alignof__(struct nft_expr)))
797
798 /**
799  *      struct nft_expr - nf_tables expression
800  *
801  *      @ops: expression ops
802  *      @data: expression private data
803  */
804 struct nft_expr {
805         const struct nft_expr_ops       *ops;
806         unsigned char                   data[];
807 };
808
809 static inline void *nft_expr_priv(const struct nft_expr *expr)
810 {
811         return (void *)expr->data;
812 }
813
814 struct nft_expr *nft_expr_init(const struct nft_ctx *ctx,
815                                const struct nlattr *nla);
816 void nft_expr_destroy(const struct nft_ctx *ctx, struct nft_expr *expr);
817 int nft_expr_dump(struct sk_buff *skb, unsigned int attr,
818                   const struct nft_expr *expr);
819
820 /**
821  *      struct nft_rule - nf_tables rule
822  *
823  *      @list: used internally
824  *      @handle: rule handle
825  *      @genmask: generation mask
826  *      @dlen: length of expression data
827  *      @udata: user data is appended to the rule
828  *      @data: expression data
829  */
830 struct nft_rule {
831         struct list_head                list;
832         u64                             handle:42,
833                                         genmask:2,
834                                         dlen:12,
835                                         udata:1;
836         unsigned char                   data[]
837                 __attribute__((aligned(__alignof__(struct nft_expr))));
838 };
839
840 static inline struct nft_expr *nft_expr_first(const struct nft_rule *rule)
841 {
842         return (struct nft_expr *)&rule->data[0];
843 }
844
845 static inline struct nft_expr *nft_expr_next(const struct nft_expr *expr)
846 {
847         return ((void *)expr) + expr->ops->size;
848 }
849
850 static inline struct nft_expr *nft_expr_last(const struct nft_rule *rule)
851 {
852         return (struct nft_expr *)&rule->data[rule->dlen];
853 }
854
855 static inline struct nft_userdata *nft_userdata(const struct nft_rule *rule)
856 {
857         return (void *)&rule->data[rule->dlen];
858 }
859
860 /*
861  * The last pointer isn't really necessary, but the compiler isn't able to
862  * determine that the result of nft_expr_last() is always the same since it
863  * can't assume that the dlen value wasn't changed within calls in the loop.
864  */
865 #define nft_rule_for_each_expr(expr, last, rule) \
866         for ((expr) = nft_expr_first(rule), (last) = nft_expr_last(rule); \
867              (expr) != (last); \
868              (expr) = nft_expr_next(expr))
869
870 enum nft_chain_flags {
871         NFT_BASE_CHAIN                  = 0x1,
872         NFT_CHAIN_HW_OFFLOAD            = 0x2,
873 };
874
875 /**
876  *      struct nft_chain - nf_tables chain
877  *
878  *      @rules: list of rules in the chain
879  *      @list: used internally
880  *      @rhlhead: used internally
881  *      @table: table that this chain belongs to
882  *      @handle: chain handle
883  *      @use: number of jump references to this chain
884  *      @flags: bitmask of enum nft_chain_flags
885  *      @name: name of the chain
886  */
887 struct nft_chain {
888         struct nft_rule                 *__rcu *rules_gen_0;
889         struct nft_rule                 *__rcu *rules_gen_1;
890         struct list_head                rules;
891         struct list_head                list;
892         struct rhlist_head              rhlhead;
893         struct nft_table                *table;
894         u64                             handle;
895         u32                             use;
896         u8                              flags:6,
897                                         genmask:2;
898         char                            *name;
899
900         /* Only used during control plane commit phase: */
901         struct nft_rule                 **rules_next;
902 };
903
904 int nft_chain_validate(const struct nft_ctx *ctx, const struct nft_chain *chain);
905
906 enum nft_chain_types {
907         NFT_CHAIN_T_DEFAULT = 0,
908         NFT_CHAIN_T_ROUTE,
909         NFT_CHAIN_T_NAT,
910         NFT_CHAIN_T_MAX
911 };
912
913 /**
914  *      struct nft_chain_type - nf_tables chain type info
915  *
916  *      @name: name of the type
917  *      @type: numeric identifier
918  *      @family: address family
919  *      @owner: module owner
920  *      @hook_mask: mask of valid hooks
921  *      @hooks: array of hook functions
922  *      @ops_register: base chain register function
923  *      @ops_unregister: base chain unregister function
924  */
925 struct nft_chain_type {
926         const char                      *name;
927         enum nft_chain_types            type;
928         int                             family;
929         struct module                   *owner;
930         unsigned int                    hook_mask;
931 #if IS_ENABLED(CONFIG_NETFILTER)
932         nf_hookfn                       *hooks[NF_MAX_HOOKS];
933         int                             (*ops_register)(struct net *net, const struct nf_hook_ops *ops);
934         void                            (*ops_unregister)(struct net *net, const struct nf_hook_ops *ops);
935 #endif
936 };
937
938 int nft_chain_validate_dependency(const struct nft_chain *chain,
939                                   enum nft_chain_types type);
940 int nft_chain_validate_hooks(const struct nft_chain *chain,
941                              unsigned int hook_flags);
942
943 struct nft_stats {
944         u64                     bytes;
945         u64                     pkts;
946         struct u64_stats_sync   syncp;
947 };
948
949 /**
950  *      struct nft_base_chain - nf_tables base chain
951  *
952  *      @ops: netfilter hook ops
953  *      @type: chain type
954  *      @policy: default policy
955  *      @stats: per-cpu chain stats
956  *      @chain: the chain
957  *      @dev_name: device name that this base chain is attached to (if any)
958  *      @flow_block: flow block (for hardware offload)
959  */
960 struct nft_base_chain {
961 #if IS_ENABLED(CONFIG_NETFILTER)
962         struct nf_hook_ops              ops;
963 #endif
964         const struct nft_chain_type     *type;
965         u8                              policy;
966         u8                              flags;
967         struct nft_stats __percpu       *stats;
968         struct nft_chain                chain;
969         char                            dev_name[IFNAMSIZ];
970         struct flow_block               flow_block;
971 };
972
973 static inline struct nft_base_chain *nft_base_chain(const struct nft_chain *chain)
974 {
975         return container_of(chain, struct nft_base_chain, chain);
976 }
977
978 static inline bool nft_is_base_chain(const struct nft_chain *chain)
979 {
980         return chain->flags & NFT_BASE_CHAIN;
981 }
982
983 int __nft_release_basechain(struct nft_ctx *ctx);
984
985 unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);
986
987 /**
988  *      struct nft_table - nf_tables table
989  *
990  *      @list: used internally
991  *      @chains_ht: chains in the table
992  *      @chains: same, for stable walks
993  *      @sets: sets in the table
994  *      @objects: stateful objects in the table
995  *      @flowtables: flow tables in the table
996  *      @hgenerator: handle generator state
997  *      @handle: table handle
998  *      @use: number of chain references to this table
999  *      @flags: table flag (see enum nft_table_flags)
1000  *      @genmask: generation mask
1001  *      @afinfo: address family info
1002  *      @name: name of the table
1003  */
1004 struct nft_table {
1005         struct list_head                list;
1006         struct rhltable                 chains_ht;
1007         struct list_head                chains;
1008         struct list_head                sets;
1009         struct list_head                objects;
1010         struct list_head                flowtables;
1011         u64                             hgenerator;
1012         u64                             handle;
1013         u32                             use;
1014         u16                             family:6,
1015                                         flags:8,
1016                                         genmask:2;
1017         char                            *name;
1018 };
1019
1020 void nft_register_chain_type(const struct nft_chain_type *);
1021 void nft_unregister_chain_type(const struct nft_chain_type *);
1022
1023 int nft_register_expr(struct nft_expr_type *);
1024 void nft_unregister_expr(struct nft_expr_type *);
1025
1026 int nft_verdict_dump(struct sk_buff *skb, int type,
1027                      const struct nft_verdict *v);
1028
1029 /**
1030  *      struct nft_object_hash_key - key to lookup nft_object
1031  *
1032  *      @name: name of the stateful object to look up
1033  *      @table: table the object belongs to
1034  */
1035 struct nft_object_hash_key {
1036         const char                      *name;
1037         const struct nft_table          *table;
1038 };
1039
1040 /**
1041  *      struct nft_object - nf_tables stateful object
1042  *
1043  *      @list: table stateful object list node
1044  *      @key:  keys that identify this object
1045  *      @rhlhead: nft_objname_ht node
1046  *      @genmask: generation mask
1047  *      @use: number of references to this stateful object
1048  *      @handle: unique object handle
1049  *      @ops: object operations
1050  *      @data: object data, layout depends on type
1051  */
1052 struct nft_object {
1053         struct list_head                list;
1054         struct rhlist_head              rhlhead;
1055         struct nft_object_hash_key      key;
1056         u32                             genmask:2,
1057                                         use:30;
1058         u64                             handle;
1059         /* runtime data below here */
1060         const struct nft_object_ops     *ops ____cacheline_aligned;
1061         unsigned char                   data[]
1062                 __attribute__((aligned(__alignof__(u64))));
1063 };
1064
1065 static inline void *nft_obj_data(const struct nft_object *obj)
1066 {
1067         return (void *)obj->data;
1068 }
1069
1070 #define nft_expr_obj(expr)      *((struct nft_object **)nft_expr_priv(expr))
1071
1072 struct nft_object *nft_obj_lookup(const struct net *net,
1073                                   const struct nft_table *table,
1074                                   const struct nlattr *nla, u32 objtype,
1075                                   u8 genmask);
1076
1077 void nft_obj_notify(struct net *net, const struct nft_table *table,
1078                     struct nft_object *obj, u32 portid, u32 seq,
1079                     int event, int family, int report, gfp_t gfp);
1080
1081 /**
1082  *      struct nft_object_type - stateful object type
1083  *
1084  *      @select_ops: function to select nft_object_ops
1085  *      @ops: default ops, used when no select_ops functions is present
1086  *      @list: list node in list of object types
1087  *      @type: stateful object numeric type
1088  *      @owner: module owner
1089  *      @maxattr: maximum netlink attribute
1090  *      @policy: netlink attribute policy
1091  */
1092 struct nft_object_type {
1093         const struct nft_object_ops     *(*select_ops)(const struct nft_ctx *,
1094                                                        const struct nlattr * const tb[]);
1095         const struct nft_object_ops     *ops;
1096         struct list_head                list;
1097         u32                             type;
1098         unsigned int                    maxattr;
1099         struct module                   *owner;
1100         const struct nla_policy         *policy;
1101 };
1102
1103 /**
1104  *      struct nft_object_ops - stateful object operations
1105  *
1106  *      @eval: stateful object evaluation function
1107  *      @size: stateful object size
1108  *      @init: initialize object from netlink attributes
1109  *      @destroy: release existing stateful object
1110  *      @dump: netlink dump stateful object
1111  */
1112 struct nft_object_ops {
1113         void                            (*eval)(struct nft_object *obj,
1114                                                 struct nft_regs *regs,
1115                                                 const struct nft_pktinfo *pkt);
1116         unsigned int                    size;
1117         int                             (*init)(const struct nft_ctx *ctx,
1118                                                 const struct nlattr *const tb[],
1119                                                 struct nft_object *obj);
1120         void                            (*destroy)(const struct nft_ctx *ctx,
1121                                                    struct nft_object *obj);
1122         int                             (*dump)(struct sk_buff *skb,
1123                                                 struct nft_object *obj,
1124                                                 bool reset);
1125         const struct nft_object_type    *type;
1126 };
1127
1128 int nft_register_obj(struct nft_object_type *obj_type);
1129 void nft_unregister_obj(struct nft_object_type *obj_type);
1130
1131 #define NFT_FLOWTABLE_DEVICE_MAX        8
1132
1133 /**
1134  *      struct nft_flowtable - nf_tables flow table
1135  *
1136  *      @list: flow table list node in table list
1137  *      @table: the table the flow table is contained in
1138  *      @name: name of this flow table
1139  *      @hooknum: hook number
1140  *      @priority: hook priority
1141  *      @ops_len: number of hooks in array
1142  *      @genmask: generation mask
1143  *      @use: number of references to this flow table
1144  *      @handle: unique object handle
1145  *      @dev_name: array of device names
1146  *      @data: rhashtable and garbage collector
1147  *      @ops: array of hooks
1148  */
1149 struct nft_flowtable {
1150         struct list_head                list;
1151         struct nft_table                *table;
1152         char                            *name;
1153         int                             hooknum;
1154         int                             priority;
1155         int                             ops_len;
1156         u32                             genmask:2,
1157                                         use:30;
1158         u64                             handle;
1159         /* runtime data below here */
1160 #if IS_ENABLED(CONFIG_NETFILTER)
1161         struct nf_hook_ops              *ops ____cacheline_aligned;
1162 #endif
1163         struct nf_flowtable             data;
1164 };
1165
1166 struct nft_flowtable *nft_flowtable_lookup(const struct nft_table *table,
1167                                            const struct nlattr *nla,
1168                                            u8 genmask);
1169
1170 void nft_register_flowtable_type(struct nf_flowtable_type *type);
1171 void nft_unregister_flowtable_type(struct nf_flowtable_type *type);
1172
1173 /**
1174  *      struct nft_traceinfo - nft tracing information and state
1175  *
1176  *      @pkt: pktinfo currently processed
1177  *      @basechain: base chain currently processed
1178  *      @chain: chain currently processed
1179  *      @rule:  rule that was evaluated
1180  *      @verdict: verdict given by rule
1181  *      @type: event type (enum nft_trace_types)
1182  *      @packet_dumped: packet headers sent in a previous traceinfo message
1183  *      @trace: other struct members are initialised
1184  */
1185 struct nft_traceinfo {
1186         const struct nft_pktinfo        *pkt;
1187         const struct nft_base_chain     *basechain;
1188         const struct nft_chain          *chain;
1189         const struct nft_rule           *rule;
1190         const struct nft_verdict        *verdict;
1191         enum nft_trace_types            type;
1192         bool                            packet_dumped;
1193         bool                            trace;
1194 };
1195
1196 void nft_trace_init(struct nft_traceinfo *info, const struct nft_pktinfo *pkt,
1197                     const struct nft_verdict *verdict,
1198                     const struct nft_chain *basechain);
1199
1200 void nft_trace_notify(struct nft_traceinfo *info);
1201
1202 #define MODULE_ALIAS_NFT_CHAIN(family, name) \
1203         MODULE_ALIAS("nft-chain-" __stringify(family) "-" name)
1204
1205 #define MODULE_ALIAS_NFT_AF_EXPR(family, name) \
1206         MODULE_ALIAS("nft-expr-" __stringify(family) "-" name)
1207
1208 #define MODULE_ALIAS_NFT_EXPR(name) \
1209         MODULE_ALIAS("nft-expr-" name)
1210
1211 #define MODULE_ALIAS_NFT_SET() \
1212         MODULE_ALIAS("nft-set")
1213
1214 #define MODULE_ALIAS_NFT_OBJ(type) \
1215         MODULE_ALIAS("nft-obj-" __stringify(type))
1216
1217 #if IS_ENABLED(CONFIG_NF_TABLES)
1218
1219 /*
1220  * The gencursor defines two generations, the currently active and the
1221  * next one. Objects contain a bitmask of 2 bits specifying the generations
1222  * they're active in. A set bit means they're inactive in the generation
1223  * represented by that bit.
1224  *
1225  * New objects start out as inactive in the current and active in the
1226  * next generation. When committing the ruleset the bitmask is cleared,
1227  * meaning they're active in all generations. When removing an object,
1228  * it is set inactive in the next generation. After committing the ruleset,
1229  * the objects are removed.
1230  */
1231 static inline unsigned int nft_gencursor_next(const struct net *net)
1232 {
1233         return net->nft.gencursor + 1 == 1 ? 1 : 0;
1234 }
1235
1236 static inline u8 nft_genmask_next(const struct net *net)
1237 {
1238         return 1 << nft_gencursor_next(net);
1239 }
1240
1241 static inline u8 nft_genmask_cur(const struct net *net)
1242 {
1243         /* Use READ_ONCE() to prevent refetching the value for atomicity */
1244         return 1 << READ_ONCE(net->nft.gencursor);
1245 }
1246
1247 #define NFT_GENMASK_ANY         ((1 << 0) | (1 << 1))
1248
1249 /*
1250  * Generic transaction helpers
1251  */
1252
1253 /* Check if this object is currently active. */
1254 #define nft_is_active(__net, __obj)                             \
1255         (((__obj)->genmask & nft_genmask_cur(__net)) == 0)
1256
1257 /* Check if this object is active in the next generation. */
1258 #define nft_is_active_next(__net, __obj)                        \
1259         (((__obj)->genmask & nft_genmask_next(__net)) == 0)
1260
1261 /* This object becomes active in the next generation. */
1262 #define nft_activate_next(__net, __obj)                         \
1263         (__obj)->genmask = nft_genmask_cur(__net)
1264
1265 /* This object becomes inactive in the next generation. */
1266 #define nft_deactivate_next(__net, __obj)                       \
1267         (__obj)->genmask = nft_genmask_next(__net)
1268
1269 /* After committing the ruleset, clear the stale generation bit. */
1270 #define nft_clear(__net, __obj)                                 \
1271         (__obj)->genmask &= ~nft_genmask_next(__net)
1272 #define nft_active_genmask(__obj, __genmask)                    \
1273         !((__obj)->genmask & __genmask)
1274
1275 /*
1276  * Set element transaction helpers
1277  */
1278
1279 static inline bool nft_set_elem_active(const struct nft_set_ext *ext,
1280                                        u8 genmask)
1281 {
1282         return !(ext->genmask & genmask);
1283 }
1284
1285 static inline void nft_set_elem_change_active(const struct net *net,
1286                                               const struct nft_set *set,
1287                                               struct nft_set_ext *ext)
1288 {
1289         ext->genmask ^= nft_genmask_next(net);
1290 }
1291
1292 #endif /* IS_ENABLED(CONFIG_NF_TABLES) */
1293
1294 /*
1295  * We use a free bit in the genmask field to indicate the element
1296  * is busy, meaning it is currently being processed either by
1297  * the netlink API or GC.
1298  *
1299  * Even though the genmask is only a single byte wide, this works
1300  * because the extension structure if fully constant once initialized,
1301  * so there are no non-atomic write accesses unless it is already
1302  * marked busy.
1303  */
1304 #define NFT_SET_ELEM_BUSY_MASK  (1 << 2)
1305
1306 #if defined(__LITTLE_ENDIAN_BITFIELD)
1307 #define NFT_SET_ELEM_BUSY_BIT   2
1308 #elif defined(__BIG_ENDIAN_BITFIELD)
1309 #define NFT_SET_ELEM_BUSY_BIT   (BITS_PER_LONG - BITS_PER_BYTE + 2)
1310 #else
1311 #error
1312 #endif
1313
1314 static inline int nft_set_elem_mark_busy(struct nft_set_ext *ext)
1315 {
1316         unsigned long *word = (unsigned long *)ext;
1317
1318         BUILD_BUG_ON(offsetof(struct nft_set_ext, genmask) != 0);
1319         return test_and_set_bit(NFT_SET_ELEM_BUSY_BIT, word);
1320 }
1321
1322 static inline void nft_set_elem_clear_busy(struct nft_set_ext *ext)
1323 {
1324         unsigned long *word = (unsigned long *)ext;
1325
1326         clear_bit(NFT_SET_ELEM_BUSY_BIT, word);
1327 }
1328
1329 /**
1330  *      struct nft_trans - nf_tables object update in transaction
1331  *
1332  *      @list: used internally
1333  *      @msg_type: message type
1334  *      @put_net: ctx->net needs to be put
1335  *      @ctx: transaction context
1336  *      @data: internal information related to the transaction
1337  */
1338 struct nft_trans {
1339         struct list_head                list;
1340         int                             msg_type;
1341         bool                            put_net;
1342         struct nft_ctx                  ctx;
1343         char                            data[0];
1344 };
1345
1346 struct nft_trans_rule {
1347         struct nft_rule                 *rule;
1348         struct nft_flow_rule            *flow;
1349         u32                             rule_id;
1350 };
1351
1352 #define nft_trans_rule(trans)   \
1353         (((struct nft_trans_rule *)trans->data)->rule)
1354 #define nft_trans_flow_rule(trans)      \
1355         (((struct nft_trans_rule *)trans->data)->flow)
1356 #define nft_trans_rule_id(trans)        \
1357         (((struct nft_trans_rule *)trans->data)->rule_id)
1358
1359 struct nft_trans_set {
1360         struct nft_set                  *set;
1361         u32                             set_id;
1362         bool                            bound;
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 #define nft_trans_set_bound(trans)      \
1370         (((struct nft_trans_set *)trans->data)->bound)
1371
1372 struct nft_trans_chain {
1373         bool                            update;
1374         char                            *name;
1375         struct nft_stats __percpu       *stats;
1376         u8                              policy;
1377 };
1378
1379 #define nft_trans_chain_update(trans)   \
1380         (((struct nft_trans_chain *)trans->data)->update)
1381 #define nft_trans_chain_name(trans)     \
1382         (((struct nft_trans_chain *)trans->data)->name)
1383 #define nft_trans_chain_stats(trans)    \
1384         (((struct nft_trans_chain *)trans->data)->stats)
1385 #define nft_trans_chain_policy(trans)   \
1386         (((struct nft_trans_chain *)trans->data)->policy)
1387
1388 struct nft_trans_table {
1389         bool                            update;
1390         bool                            enable;
1391 };
1392
1393 #define nft_trans_table_update(trans)   \
1394         (((struct nft_trans_table *)trans->data)->update)
1395 #define nft_trans_table_enable(trans)   \
1396         (((struct nft_trans_table *)trans->data)->enable)
1397
1398 struct nft_trans_elem {
1399         struct nft_set                  *set;
1400         struct nft_set_elem             elem;
1401         bool                            bound;
1402 };
1403
1404 #define nft_trans_elem_set(trans)       \
1405         (((struct nft_trans_elem *)trans->data)->set)
1406 #define nft_trans_elem(trans)   \
1407         (((struct nft_trans_elem *)trans->data)->elem)
1408 #define nft_trans_elem_set_bound(trans) \
1409         (((struct nft_trans_elem *)trans->data)->bound)
1410
1411 struct nft_trans_obj {
1412         struct nft_object               *obj;
1413 };
1414
1415 #define nft_trans_obj(trans)    \
1416         (((struct nft_trans_obj *)trans->data)->obj)
1417
1418 struct nft_trans_flowtable {
1419         struct nft_flowtable            *flowtable;
1420 };
1421
1422 #define nft_trans_flowtable(trans)      \
1423         (((struct nft_trans_flowtable *)trans->data)->flowtable)
1424
1425 int __init nft_chain_filter_init(void);
1426 void nft_chain_filter_fini(void);
1427
1428 void __init nft_chain_route_init(void);
1429 void nft_chain_route_fini(void);
1430 #endif /* _NET_NF_TABLES_H */