~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/net/netfilter/nf_tables.h

Version: ~ [ linux-5.16 ] ~ [ linux-5.15.13 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.90 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.170 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.224 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.261 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.296 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.298 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp