1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NET_NF_TABLES_H
3 #define _NET_NF_TABLES_H
5 #include <asm/unaligned.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 #include <net/flow_offload.h>
16 #include <net/netns/generic.h>
18 #define NFT_MAX_HOOKS (NF_INET_INGRESS + 1)
22 #define NFT_JUMP_STACK_SIZE 16
25 NFT_PKTINFO_L4PROTO = (1 << 0),
26 NFT_PKTINFO_INNER = (1 << 1),
27 NFT_PKTINFO_INNER_FULL = (1 << 2),
32 const struct nf_hook_state *state;
40 static inline struct sock *nft_sk(const struct nft_pktinfo *pkt)
42 return pkt->state->sk;
45 static inline unsigned int nft_thoff(const struct nft_pktinfo *pkt)
50 static inline struct net *nft_net(const struct nft_pktinfo *pkt)
52 return pkt->state->net;
55 static inline unsigned int nft_hook(const struct nft_pktinfo *pkt)
57 return pkt->state->hook;
60 static inline u8 nft_pf(const struct nft_pktinfo *pkt)
62 return pkt->state->pf;
65 static inline const struct net_device *nft_in(const struct nft_pktinfo *pkt)
67 return pkt->state->in;
70 static inline const struct net_device *nft_out(const struct nft_pktinfo *pkt)
72 return pkt->state->out;
75 static inline void nft_set_pktinfo(struct nft_pktinfo *pkt,
77 const struct nf_hook_state *state)
83 static inline void nft_set_pktinfo_unspec(struct nft_pktinfo *pkt)
92 * struct nft_verdict - nf_tables verdict
94 * @code: nf_tables/netfilter verdict code
95 * @chain: destination chain for NFT_JUMP/NFT_GOTO
99 struct nft_chain *chain;
105 struct nft_verdict verdict;
107 } __attribute__((aligned(__alignof__(u64))));
109 #define NFT_REG32_NUM 20
112 * struct nft_regs - nf_tables register set
114 * @data: data registers
115 * @verdict: verdict register
117 * The first four data registers alias to the verdict register.
121 u32 data[NFT_REG32_NUM];
122 struct nft_verdict verdict;
126 struct nft_regs_track {
128 const struct nft_expr *selector;
129 const struct nft_expr *bitwise;
131 } regs[NFT_REG32_NUM];
133 const struct nft_expr *cur;
134 const struct nft_expr *last;
137 /* Store/load an u8, u16 or u64 integer to/from the u32 data register.
139 * Note, when using concatenations, register allocation happens at 32-bit
140 * level. So for store instruction, pad the rest part with zero to avoid
144 static inline void nft_reg_store8(u32 *dreg, u8 val)
150 static inline u8 nft_reg_load8(const u32 *sreg)
155 static inline void nft_reg_store16(u32 *dreg, u16 val)
161 static inline void nft_reg_store_be16(u32 *dreg, __be16 val)
163 nft_reg_store16(dreg, (__force __u16)val);
166 static inline u16 nft_reg_load16(const u32 *sreg)
171 static inline __be16 nft_reg_load_be16(const u32 *sreg)
173 return (__force __be16)nft_reg_load16(sreg);
176 static inline __be32 nft_reg_load_be32(const u32 *sreg)
178 return *(__force __be32 *)sreg;
181 static inline void nft_reg_store64(u64 *dreg, u64 val)
183 put_unaligned(val, dreg);
186 static inline u64 nft_reg_load64(const u32 *sreg)
188 return get_unaligned((u64 *)sreg);
191 static inline void nft_data_copy(u32 *dst, const struct nft_data *src,
194 if (len % NFT_REG32_SIZE)
195 dst[len / NFT_REG32_SIZE] = 0;
196 memcpy(dst, src, len);
200 * struct nft_ctx - nf_tables rule/set context
202 * @net: net namespace
203 * @table: the table the chain is contained in
204 * @chain: the chain the rule is contained in
205 * @nla: netlink attributes
206 * @portid: netlink portID of the original message
207 * @seq: netlink sequence number
208 * @family: protocol family
209 * @level: depth of the chains
210 * @report: notify via unicast netlink message
214 struct nft_table *table;
215 struct nft_chain *chain;
216 const struct nlattr * const *nla;
225 enum nft_data_desc_flags {
226 NFT_DATA_DESC_SETELEM = (1 << 0),
229 struct nft_data_desc {
230 enum nft_data_types type;
236 int nft_data_init(const struct nft_ctx *ctx, struct nft_data *data,
237 struct nft_data_desc *desc, const struct nlattr *nla);
238 void nft_data_hold(const struct nft_data *data, enum nft_data_types type);
239 void nft_data_release(const struct nft_data *data, enum nft_data_types type);
240 int nft_data_dump(struct sk_buff *skb, int attr, const struct nft_data *data,
241 enum nft_data_types type, unsigned int len);
243 static inline enum nft_data_types nft_dreg_to_type(enum nft_registers reg)
245 return reg == NFT_REG_VERDICT ? NFT_DATA_VERDICT : NFT_DATA_VALUE;
248 static inline enum nft_registers nft_type_to_reg(enum nft_data_types type)
250 return type == NFT_DATA_VERDICT ? NFT_REG_VERDICT : NFT_REG_1 * NFT_REG_SIZE / NFT_REG32_SIZE;
253 int nft_parse_u32_check(const struct nlattr *attr, int max, u32 *dest);
254 int nft_dump_register(struct sk_buff *skb, unsigned int attr, unsigned int reg);
256 int nft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len);
257 int nft_parse_register_store(const struct nft_ctx *ctx,
258 const struct nlattr *attr, u8 *dreg,
259 const struct nft_data *data,
260 enum nft_data_types type, unsigned int len);
263 * struct nft_userdata - user defined data associated with an object
265 * @len: length of the data
268 * The presence of user data is indicated in an object specific fashion,
269 * so a length of zero can't occur and the value "len" indicates data
272 struct nft_userdata {
274 unsigned char data[];
277 /* placeholder structure for opaque set element backend representation. */
278 struct nft_elem_priv { };
281 * struct nft_set_elem - generic representation of set elements
284 * @key_end: closing element key
285 * @priv: element private data and extensions
287 struct nft_set_elem {
289 u32 buf[NFT_DATA_VALUE_MAXLEN / sizeof(u32)];
293 u32 buf[NFT_DATA_VALUE_MAXLEN / sizeof(u32)];
297 u32 buf[NFT_DATA_VALUE_MAXLEN / sizeof(u32)];
300 struct nft_elem_priv *priv;
303 static inline void *nft_elem_priv_cast(const struct nft_elem_priv *priv)
309 struct nft_set_iter {
314 int (*fn)(const struct nft_ctx *ctx,
316 const struct nft_set_iter *iter,
317 struct nft_elem_priv *elem_priv);
321 * struct nft_set_desc - description of set elements
327 * @objtype: object type
329 * @size: number of set elements
330 * @policy: set policy
331 * @gc_int: garbage collector interval
332 * @field_len: length of each field in concatenation, bytes
333 * @field_count: number of concatenated fields in element
334 * @expr: set must support for expressions
336 struct nft_set_desc {
346 u8 field_len[NFT_REG32_COUNT];
352 * enum nft_set_class - performance class
354 * @NFT_LOOKUP_O_1: constant, O(1)
355 * @NFT_LOOKUP_O_LOG_N: logarithmic, O(log N)
356 * @NFT_LOOKUP_O_N: linear, O(N)
360 NFT_SET_CLASS_O_LOG_N,
365 * struct nft_set_estimate - estimation of memory and performance
368 * @size: required memory
369 * @lookup: lookup performance class
370 * @space: memory class
372 struct nft_set_estimate {
374 enum nft_set_class lookup;
375 enum nft_set_class space;
378 #define NFT_EXPR_MAXATTR 16
379 #define NFT_EXPR_SIZE(size) (sizeof(struct nft_expr) + \
380 ALIGN(size, __alignof__(struct nft_expr)))
383 * struct nft_expr - nf_tables expression
385 * @ops: expression ops
386 * @data: expression private data
389 const struct nft_expr_ops *ops;
391 __attribute__((aligned(__alignof__(u64))));
394 static inline void *nft_expr_priv(const struct nft_expr *expr)
396 return (void *)expr->data;
399 struct nft_expr_info;
401 int nft_expr_inner_parse(const struct nft_ctx *ctx, const struct nlattr *nla,
402 struct nft_expr_info *info);
403 int nft_expr_clone(struct nft_expr *dst, struct nft_expr *src);
404 void nft_expr_destroy(const struct nft_ctx *ctx, struct nft_expr *expr);
405 int nft_expr_dump(struct sk_buff *skb, unsigned int attr,
406 const struct nft_expr *expr, bool reset);
407 bool nft_expr_reduce_bitwise(struct nft_regs_track *track,
408 const struct nft_expr *expr);
413 * struct nft_set_ops - nf_tables set operations
415 * @lookup: look up an element within the set
416 * @update: update an element if exists, add it if doesn't exist
417 * @delete: delete an element
418 * @insert: insert new element into set
419 * @activate: activate new element in the next generation
420 * @deactivate: lookup for element and deactivate it in the next generation
421 * @flush: deactivate element in the next generation
422 * @remove: remove element from set
423 * @walk: iterate over all set elements
424 * @get: get set elements
425 * @privsize: function to return size of set private data
426 * @init: initialize private data of new set instance
427 * @destroy: destroy private data of set instance
428 * @elemsize: element private size
430 * Operations lookup, update and delete have simpler interfaces, are faster
431 * and currently only used in the packet path. All the rest are slower,
432 * control plane functions.
435 bool (*lookup)(const struct net *net,
436 const struct nft_set *set,
438 const struct nft_set_ext **ext);
439 bool (*update)(struct nft_set *set,
441 struct nft_elem_priv *
442 (*new)(struct nft_set *,
443 const struct nft_expr *,
445 const struct nft_expr *expr,
446 struct nft_regs *regs,
447 const struct nft_set_ext **ext);
448 bool (*delete)(const struct nft_set *set,
451 int (*insert)(const struct net *net,
452 const struct nft_set *set,
453 const struct nft_set_elem *elem,
454 struct nft_elem_priv **priv);
455 void (*activate)(const struct net *net,
456 const struct nft_set *set,
457 struct nft_elem_priv *elem_priv);
458 struct nft_elem_priv * (*deactivate)(const struct net *net,
459 const struct nft_set *set,
460 const struct nft_set_elem *elem);
461 void (*flush)(const struct net *net,
462 const struct nft_set *set,
463 struct nft_elem_priv *priv);
464 void (*remove)(const struct net *net,
465 const struct nft_set *set,
466 struct nft_elem_priv *elem_priv);
467 void (*walk)(const struct nft_ctx *ctx,
469 struct nft_set_iter *iter);
470 struct nft_elem_priv * (*get)(const struct net *net,
471 const struct nft_set *set,
472 const struct nft_set_elem *elem,
474 void (*commit)(struct nft_set *set);
475 void (*abort)(const struct nft_set *set);
476 u64 (*privsize)(const struct nlattr * const nla[],
477 const struct nft_set_desc *desc);
478 bool (*estimate)(const struct nft_set_desc *desc,
480 struct nft_set_estimate *est);
481 int (*init)(const struct nft_set *set,
482 const struct nft_set_desc *desc,
483 const struct nlattr * const nla[]);
484 void (*destroy)(const struct nft_ctx *ctx,
485 const struct nft_set *set);
486 void (*gc_init)(const struct nft_set *set);
488 unsigned int elemsize;
492 * struct nft_set_type - nf_tables set type
494 * @ops: set ops for this type
495 * @features: features supported by the implementation
497 struct nft_set_type {
498 const struct nft_set_ops ops;
501 #define to_set_type(o) container_of(o, struct nft_set_type, ops)
503 struct nft_set_elem_expr {
506 __attribute__((aligned(__alignof__(struct nft_expr))));
509 #define nft_setelem_expr_at(__elem_expr, __offset) \
510 ((struct nft_expr *)&__elem_expr->data[__offset])
512 #define nft_setelem_expr_foreach(__expr, __elem_expr, __size) \
513 for (__expr = nft_setelem_expr_at(__elem_expr, 0), __size = 0; \
514 __size < (__elem_expr)->size; \
515 __size += (__expr)->ops->size, __expr = ((void *)(__expr)) + (__expr)->ops->size)
517 #define NFT_SET_EXPR_MAX 2
520 * struct nft_set - nf_tables set instance
522 * @list: table set list node
523 * @bindings: list of set bindings
524 * @refs: internal refcounting for async set destruction
525 * @table: table this set belongs to
526 * @net: netnamespace this set belongs to
527 * @name: name of the set
528 * @handle: unique handle of the set
529 * @ktype: key type (numeric type defined by userspace, not used in the kernel)
530 * @dtype: data type (verdict or numeric type defined by userspace)
531 * @objtype: object type (see NFT_OBJECT_* definitions)
532 * @size: maximum set size
533 * @field_len: length of each field in concatenation, bytes
534 * @field_count: number of concatenated fields in element
535 * @use: number of rules references to this set
536 * @nelems: number of elements
537 * @ndeact: number of deactivated elements queued for removal
538 * @timeout: default timeout value in jiffies
539 * @gc_int: garbage collection interval in msecs
540 * @policy: set parameterization (see enum nft_set_policies)
541 * @udlen: user data length
543 * @expr: stateful expression
546 * @dead: set will be freed, never cleared
547 * @genmask: generation mask
550 * @data: private set data
553 struct list_head list;
554 struct list_head bindings;
556 struct nft_table *table;
564 u8 field_len[NFT_REG32_COUNT];
573 unsigned char *udata;
574 struct list_head pending_update;
575 /* runtime data below here */
576 const struct nft_set_ops *ops ____cacheline_aligned;
583 struct nft_expr *exprs[NFT_SET_EXPR_MAX];
584 struct list_head catchall_list;
586 __attribute__((aligned(__alignof__(u64))));
589 static inline bool nft_set_is_anonymous(const struct nft_set *set)
591 return set->flags & NFT_SET_ANONYMOUS;
594 static inline void *nft_set_priv(const struct nft_set *set)
596 return (void *)set->data;
599 static inline bool nft_set_gc_is_pending(const struct nft_set *s)
601 return refcount_read(&s->refs) != 1;
604 static inline struct nft_set *nft_set_container_of(const void *priv)
606 return (void *)priv - offsetof(struct nft_set, data);
609 struct nft_set *nft_set_lookup_global(const struct net *net,
610 const struct nft_table *table,
611 const struct nlattr *nla_set_name,
612 const struct nlattr *nla_set_id,
615 struct nft_set_ext *nft_set_catchall_lookup(const struct net *net,
616 const struct nft_set *set);
618 static inline unsigned long nft_set_gc_interval(const struct nft_set *set)
620 u32 gc_int = READ_ONCE(set->gc_int);
622 return gc_int ? msecs_to_jiffies(gc_int) : HZ;
626 * struct nft_set_binding - nf_tables set binding
628 * @list: set bindings list node
629 * @chain: chain containing the rule bound to the set
630 * @flags: set action flags
632 * A set binding contains all information necessary for validation
633 * of new elements added to a bound set.
635 struct nft_set_binding {
636 struct list_head list;
637 const struct nft_chain *chain;
641 enum nft_trans_phase;
642 void nf_tables_activate_set(const struct nft_ctx *ctx, struct nft_set *set);
643 void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set,
644 struct nft_set_binding *binding,
645 enum nft_trans_phase phase);
646 int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,
647 struct nft_set_binding *binding);
648 void nf_tables_destroy_set(const struct nft_ctx *ctx, struct nft_set *set);
651 * enum nft_set_extensions - set extension type IDs
653 * @NFT_SET_EXT_KEY: element key
654 * @NFT_SET_EXT_KEY_END: upper bound element key, for ranges
655 * @NFT_SET_EXT_DATA: mapping data
656 * @NFT_SET_EXT_FLAGS: element flags
657 * @NFT_SET_EXT_TIMEOUT: element timeout
658 * @NFT_SET_EXT_EXPIRATION: element expiration time
659 * @NFT_SET_EXT_USERDATA: user data associated with the element
660 * @NFT_SET_EXT_EXPRESSIONS: expressions assiciated with the element
661 * @NFT_SET_EXT_OBJREF: stateful object reference associated with element
662 * @NFT_SET_EXT_NUM: number of extension types
664 enum nft_set_extensions {
670 NFT_SET_EXT_EXPIRATION,
671 NFT_SET_EXT_USERDATA,
672 NFT_SET_EXT_EXPRESSIONS,
678 * struct nft_set_ext_type - set extension type
680 * @len: fixed part length of the extension
681 * @align: alignment requirements of the extension
683 struct nft_set_ext_type {
688 extern const struct nft_set_ext_type nft_set_ext_types[];
691 * struct nft_set_ext_tmpl - set extension template
693 * @len: length of extension area
694 * @offset: offsets of individual extension types
696 struct nft_set_ext_tmpl {
698 u8 offset[NFT_SET_EXT_NUM];
699 u8 ext_len[NFT_SET_EXT_NUM];
703 * struct nft_set_ext - set extensions
705 * @genmask: generation mask
706 * @offset: offsets of individual extension types
707 * @data: beginning of extension data
711 u8 offset[NFT_SET_EXT_NUM];
715 static inline void nft_set_ext_prepare(struct nft_set_ext_tmpl *tmpl)
717 memset(tmpl, 0, sizeof(*tmpl));
718 tmpl->len = sizeof(struct nft_set_ext);
721 static inline int nft_set_ext_add_length(struct nft_set_ext_tmpl *tmpl, u8 id,
724 tmpl->len = ALIGN(tmpl->len, nft_set_ext_types[id].align);
725 if (tmpl->len > U8_MAX)
728 tmpl->offset[id] = tmpl->len;
729 tmpl->ext_len[id] = nft_set_ext_types[id].len + len;
730 tmpl->len += tmpl->ext_len[id];
735 static inline int nft_set_ext_add(struct nft_set_ext_tmpl *tmpl, u8 id)
737 return nft_set_ext_add_length(tmpl, id, 0);
740 static inline void nft_set_ext_init(struct nft_set_ext *ext,
741 const struct nft_set_ext_tmpl *tmpl)
743 memcpy(ext->offset, tmpl->offset, sizeof(ext->offset));
746 static inline bool __nft_set_ext_exists(const struct nft_set_ext *ext, u8 id)
748 return !!ext->offset[id];
751 static inline bool nft_set_ext_exists(const struct nft_set_ext *ext, u8 id)
753 return ext && __nft_set_ext_exists(ext, id);
756 static inline void *nft_set_ext(const struct nft_set_ext *ext, u8 id)
758 return (void *)ext + ext->offset[id];
761 static inline struct nft_data *nft_set_ext_key(const struct nft_set_ext *ext)
763 return nft_set_ext(ext, NFT_SET_EXT_KEY);
766 static inline struct nft_data *nft_set_ext_key_end(const struct nft_set_ext *ext)
768 return nft_set_ext(ext, NFT_SET_EXT_KEY_END);
771 static inline struct nft_data *nft_set_ext_data(const struct nft_set_ext *ext)
773 return nft_set_ext(ext, NFT_SET_EXT_DATA);
776 static inline u8 *nft_set_ext_flags(const struct nft_set_ext *ext)
778 return nft_set_ext(ext, NFT_SET_EXT_FLAGS);
781 static inline u64 *nft_set_ext_timeout(const struct nft_set_ext *ext)
783 return nft_set_ext(ext, NFT_SET_EXT_TIMEOUT);
786 static inline u64 *nft_set_ext_expiration(const struct nft_set_ext *ext)
788 return nft_set_ext(ext, NFT_SET_EXT_EXPIRATION);
791 static inline struct nft_userdata *nft_set_ext_userdata(const struct nft_set_ext *ext)
793 return nft_set_ext(ext, NFT_SET_EXT_USERDATA);
796 static inline struct nft_set_elem_expr *nft_set_ext_expr(const struct nft_set_ext *ext)
798 return nft_set_ext(ext, NFT_SET_EXT_EXPRESSIONS);
801 static inline bool nft_set_elem_expired(const struct nft_set_ext *ext)
803 return nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION) &&
804 time_is_before_eq_jiffies64(*nft_set_ext_expiration(ext));
807 static inline struct nft_set_ext *nft_set_elem_ext(const struct nft_set *set,
808 const struct nft_elem_priv *elem_priv)
810 return (void *)elem_priv + set->ops->elemsize;
813 static inline struct nft_object **nft_set_ext_obj(const struct nft_set_ext *ext)
815 return nft_set_ext(ext, NFT_SET_EXT_OBJREF);
818 struct nft_expr *nft_set_elem_expr_alloc(const struct nft_ctx *ctx,
819 const struct nft_set *set,
820 const struct nlattr *attr);
822 struct nft_elem_priv *nft_set_elem_init(const struct nft_set *set,
823 const struct nft_set_ext_tmpl *tmpl,
824 const u32 *key, const u32 *key_end,
826 u64 timeout, u64 expiration, gfp_t gfp);
827 int nft_set_elem_expr_clone(const struct nft_ctx *ctx, struct nft_set *set,
828 struct nft_expr *expr_array[]);
829 void nft_set_elem_destroy(const struct nft_set *set,
830 const struct nft_elem_priv *elem_priv,
832 void nf_tables_set_elem_destroy(const struct nft_ctx *ctx,
833 const struct nft_set *set,
834 const struct nft_elem_priv *elem_priv);
838 * struct nft_expr_type - nf_tables expression type
840 * @select_ops: function to select nft_expr_ops
841 * @release_ops: release nft_expr_ops
842 * @ops: default ops, used when no select_ops functions is present
843 * @list: used internally
845 * @owner: module reference
846 * @policy: netlink attribute policy
847 * @maxattr: highest netlink attribute number
848 * @family: address family for AF-specific types
849 * @flags: expression type flags
851 struct nft_expr_type {
852 const struct nft_expr_ops *(*select_ops)(const struct nft_ctx *,
853 const struct nlattr * const tb[]);
854 void (*release_ops)(const struct nft_expr_ops *ops);
855 const struct nft_expr_ops *ops;
856 const struct nft_expr_ops *inner_ops;
857 struct list_head list;
859 struct module *owner;
860 const struct nla_policy *policy;
861 unsigned int maxattr;
866 #define NFT_EXPR_STATEFUL 0x1
867 #define NFT_EXPR_GC 0x2
869 enum nft_trans_phase {
871 NFT_TRANS_PREPARE_ERROR,
877 struct nft_flow_rule;
878 struct nft_offload_ctx;
881 * struct nft_expr_ops - nf_tables expression operations
883 * @eval: Expression evaluation function
884 * @size: full expression size, including private data size
885 * @init: initialization function
886 * @activate: activate expression in the next generation
887 * @deactivate: deactivate expression in next generation
888 * @destroy: destruction function, called after synchronize_rcu
889 * @dump: function to dump parameters
890 * @type: expression type
891 * @validate: validate expression, called during loop detection
892 * @data: extra data to attach to this expression operation
894 struct nft_expr_ops {
895 void (*eval)(const struct nft_expr *expr,
896 struct nft_regs *regs,
897 const struct nft_pktinfo *pkt);
898 int (*clone)(struct nft_expr *dst,
899 const struct nft_expr *src);
902 int (*init)(const struct nft_ctx *ctx,
903 const struct nft_expr *expr,
904 const struct nlattr * const tb[]);
905 void (*activate)(const struct nft_ctx *ctx,
906 const struct nft_expr *expr);
907 void (*deactivate)(const struct nft_ctx *ctx,
908 const struct nft_expr *expr,
909 enum nft_trans_phase phase);
910 void (*destroy)(const struct nft_ctx *ctx,
911 const struct nft_expr *expr);
912 void (*destroy_clone)(const struct nft_ctx *ctx,
913 const struct nft_expr *expr);
914 int (*dump)(struct sk_buff *skb,
915 const struct nft_expr *expr,
917 int (*validate)(const struct nft_ctx *ctx,
918 const struct nft_expr *expr,
919 const struct nft_data **data);
920 bool (*reduce)(struct nft_regs_track *track,
921 const struct nft_expr *expr);
922 bool (*gc)(struct net *net,
923 const struct nft_expr *expr);
924 int (*offload)(struct nft_offload_ctx *ctx,
925 struct nft_flow_rule *flow,
926 const struct nft_expr *expr);
927 bool (*offload_action)(const struct nft_expr *expr);
928 void (*offload_stats)(struct nft_expr *expr,
929 const struct flow_stats *stats);
930 const struct nft_expr_type *type;
935 * struct nft_rule - nf_tables rule
937 * @list: used internally
938 * @handle: rule handle
939 * @genmask: generation mask
940 * @dlen: length of expression data
941 * @udata: user data is appended to the rule
942 * @data: expression data
945 struct list_head list;
951 __attribute__((aligned(__alignof__(struct nft_expr))));
954 static inline struct nft_expr *nft_expr_first(const struct nft_rule *rule)
956 return (struct nft_expr *)&rule->data[0];
959 static inline struct nft_expr *nft_expr_next(const struct nft_expr *expr)
961 return ((void *)expr) + expr->ops->size;
964 static inline struct nft_expr *nft_expr_last(const struct nft_rule *rule)
966 return (struct nft_expr *)&rule->data[rule->dlen];
969 static inline bool nft_expr_more(const struct nft_rule *rule,
970 const struct nft_expr *expr)
972 return expr != nft_expr_last(rule) && expr->ops;
975 static inline struct nft_userdata *nft_userdata(const struct nft_rule *rule)
977 return (void *)&rule->data[rule->dlen];
980 void nft_rule_expr_activate(const struct nft_ctx *ctx, struct nft_rule *rule);
981 void nft_rule_expr_deactivate(const struct nft_ctx *ctx, struct nft_rule *rule,
982 enum nft_trans_phase phase);
983 void nf_tables_rule_destroy(const struct nft_ctx *ctx, struct nft_rule *rule);
985 static inline void nft_set_elem_update_expr(const struct nft_set_ext *ext,
986 struct nft_regs *regs,
987 const struct nft_pktinfo *pkt)
989 struct nft_set_elem_expr *elem_expr;
990 struct nft_expr *expr;
993 if (__nft_set_ext_exists(ext, NFT_SET_EXT_EXPRESSIONS)) {
994 elem_expr = nft_set_ext_expr(ext);
995 nft_setelem_expr_foreach(expr, elem_expr, size) {
996 expr->ops->eval(expr, regs, pkt);
997 if (regs->verdict.code == NFT_BREAK)
1004 * The last pointer isn't really necessary, but the compiler isn't able to
1005 * determine that the result of nft_expr_last() is always the same since it
1006 * can't assume that the dlen value wasn't changed within calls in the loop.
1008 #define nft_rule_for_each_expr(expr, last, rule) \
1009 for ((expr) = nft_expr_first(rule), (last) = nft_expr_last(rule); \
1011 (expr) = nft_expr_next(expr))
1013 #define NFT_CHAIN_POLICY_UNSET U8_MAX
1015 struct nft_rule_dp {
1018 handle:42; /* for tracing */
1019 unsigned char data[]
1020 __attribute__((aligned(__alignof__(struct nft_expr))));
1023 struct nft_rule_dp_last {
1024 struct nft_rule_dp end; /* end of nft_rule_blob marker */
1025 struct rcu_head h; /* call_rcu head */
1026 struct nft_rule_blob *blob; /* ptr to free via call_rcu */
1027 const struct nft_chain *chain; /* for nftables tracing */
1030 static inline const struct nft_rule_dp *nft_rule_next(const struct nft_rule_dp *rule)
1032 return (void *)rule + sizeof(*rule) + rule->dlen;
1035 struct nft_rule_blob {
1037 unsigned char data[]
1038 __attribute__((aligned(__alignof__(struct nft_rule_dp))));
1042 * struct nft_chain - nf_tables chain
1044 * @rules: list of rules in the chain
1045 * @list: used internally
1046 * @rhlhead: used internally
1047 * @table: table that this chain belongs to
1048 * @handle: chain handle
1049 * @use: number of jump references to this chain
1050 * @flags: bitmask of enum nft_chain_flags
1051 * @name: name of the chain
1054 struct nft_rule_blob __rcu *blob_gen_0;
1055 struct nft_rule_blob __rcu *blob_gen_1;
1056 struct list_head rules;
1057 struct list_head list;
1058 struct rhlist_head rhlhead;
1059 struct nft_table *table;
1069 /* Only used during control plane commit phase: */
1070 struct nft_rule_blob *blob_next;
1073 int nft_chain_validate(const struct nft_ctx *ctx, const struct nft_chain *chain);
1074 int nft_setelem_validate(const struct nft_ctx *ctx, struct nft_set *set,
1075 const struct nft_set_iter *iter,
1076 struct nft_elem_priv *elem_priv);
1077 int nft_set_catchall_validate(const struct nft_ctx *ctx, struct nft_set *set);
1078 int nf_tables_bind_chain(const struct nft_ctx *ctx, struct nft_chain *chain);
1079 void nf_tables_unbind_chain(const struct nft_ctx *ctx, struct nft_chain *chain);
1081 enum nft_chain_types {
1082 NFT_CHAIN_T_DEFAULT = 0,
1089 * struct nft_chain_type - nf_tables chain type info
1091 * @name: name of the type
1092 * @type: numeric identifier
1093 * @family: address family
1094 * @owner: module owner
1095 * @hook_mask: mask of valid hooks
1096 * @hooks: array of hook functions
1097 * @ops_register: base chain register function
1098 * @ops_unregister: base chain unregister function
1100 struct nft_chain_type {
1102 enum nft_chain_types type;
1104 struct module *owner;
1105 unsigned int hook_mask;
1106 nf_hookfn *hooks[NFT_MAX_HOOKS];
1107 int (*ops_register)(struct net *net, const struct nf_hook_ops *ops);
1108 void (*ops_unregister)(struct net *net, const struct nf_hook_ops *ops);
1111 int nft_chain_validate_dependency(const struct nft_chain *chain,
1112 enum nft_chain_types type);
1113 int nft_chain_validate_hooks(const struct nft_chain *chain,
1114 unsigned int hook_flags);
1116 static inline bool nft_chain_binding(const struct nft_chain *chain)
1118 return chain->flags & NFT_CHAIN_BINDING;
1121 static inline bool nft_chain_is_bound(struct nft_chain *chain)
1123 return (chain->flags & NFT_CHAIN_BINDING) && chain->bound;
1126 int nft_chain_add(struct nft_table *table, struct nft_chain *chain);
1127 void nft_chain_del(struct nft_chain *chain);
1128 void nf_tables_chain_destroy(struct nft_ctx *ctx);
1133 struct u64_stats_sync syncp;
1137 struct list_head list;
1138 struct nf_hook_ops ops;
1139 struct rcu_head rcu;
1143 * struct nft_base_chain - nf_tables base chain
1145 * @ops: netfilter hook ops
1146 * @hook_list: list of netfilter hooks (for NFPROTO_NETDEV family)
1148 * @policy: default policy
1149 * @stats: per-cpu chain stats
1151 * @flow_block: flow block (for hardware offload)
1153 struct nft_base_chain {
1154 struct nf_hook_ops ops;
1155 struct list_head hook_list;
1156 const struct nft_chain_type *type;
1159 struct nft_stats __percpu *stats;
1160 struct nft_chain chain;
1161 struct flow_block flow_block;
1164 static inline struct nft_base_chain *nft_base_chain(const struct nft_chain *chain)
1166 return container_of(chain, struct nft_base_chain, chain);
1169 static inline bool nft_is_base_chain(const struct nft_chain *chain)
1171 return chain->flags & NFT_CHAIN_BASE;
1174 int __nft_release_basechain(struct nft_ctx *ctx);
1176 unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);
1178 static inline bool nft_use_inc(u32 *use)
1180 if (*use == UINT_MAX)
1188 static inline void nft_use_dec(u32 *use)
1190 WARN_ON_ONCE((*use)-- == 0);
1193 /* For error and abort path: restore use counter to previous state. */
1194 static inline void nft_use_inc_restore(u32 *use)
1196 WARN_ON_ONCE(!nft_use_inc(use));
1199 #define nft_use_dec_restore nft_use_dec
1202 * struct nft_table - nf_tables table
1204 * @list: used internally
1205 * @chains_ht: chains in the table
1206 * @chains: same, for stable walks
1207 * @sets: sets in the table
1208 * @objects: stateful objects in the table
1209 * @flowtables: flow tables in the table
1210 * @hgenerator: handle generator state
1211 * @handle: table handle
1212 * @use: number of chain references to this table
1213 * @family:address family
1214 * @flags: table flag (see enum nft_table_flags)
1215 * @genmask: generation mask
1216 * @nlpid: netlink port ID
1217 * @name: name of the table
1218 * @udlen: length of the user data
1220 * @validate_state: internal, set when transaction adds jumps
1223 struct list_head list;
1224 struct rhltable chains_ht;
1225 struct list_head chains;
1226 struct list_head sets;
1227 struct list_head objects;
1228 struct list_head flowtables;
1242 static inline bool nft_table_has_owner(const struct nft_table *table)
1244 return table->flags & NFT_TABLE_F_OWNER;
1247 static inline bool nft_base_chain_netdev(int family, u32 hooknum)
1249 return family == NFPROTO_NETDEV ||
1250 (family == NFPROTO_INET && hooknum == NF_INET_INGRESS);
1253 void nft_register_chain_type(const struct nft_chain_type *);
1254 void nft_unregister_chain_type(const struct nft_chain_type *);
1256 int nft_register_expr(struct nft_expr_type *);
1257 void nft_unregister_expr(struct nft_expr_type *);
1259 int nft_verdict_dump(struct sk_buff *skb, int type,
1260 const struct nft_verdict *v);
1263 * struct nft_object_hash_key - key to lookup nft_object
1265 * @name: name of the stateful object to look up
1266 * @table: table the object belongs to
1268 struct nft_object_hash_key {
1270 const struct nft_table *table;
1274 * struct nft_object - nf_tables stateful object
1276 * @list: table stateful object list node
1277 * @key: keys that identify this object
1278 * @rhlhead: nft_objname_ht node
1279 * @genmask: generation mask
1280 * @use: number of references to this stateful object
1281 * @handle: unique object handle
1282 * @ops: object operations
1283 * @data: object data, layout depends on type
1286 struct list_head list;
1287 struct rhlist_head rhlhead;
1288 struct nft_object_hash_key key;
1294 /* runtime data below here */
1295 const struct nft_object_ops *ops ____cacheline_aligned;
1296 unsigned char data[]
1297 __attribute__((aligned(__alignof__(u64))));
1300 static inline void *nft_obj_data(const struct nft_object *obj)
1302 return (void *)obj->data;
1305 #define nft_expr_obj(expr) *((struct nft_object **)nft_expr_priv(expr))
1307 struct nft_object *nft_obj_lookup(const struct net *net,
1308 const struct nft_table *table,
1309 const struct nlattr *nla, u32 objtype,
1312 void nft_obj_notify(struct net *net, const struct nft_table *table,
1313 struct nft_object *obj, u32 portid, u32 seq,
1314 int event, u16 flags, int family, int report, gfp_t gfp);
1317 * struct nft_object_type - stateful object type
1319 * @select_ops: function to select nft_object_ops
1320 * @ops: default ops, used when no select_ops functions is present
1321 * @list: list node in list of object types
1322 * @type: stateful object numeric type
1323 * @owner: module owner
1324 * @maxattr: maximum netlink attribute
1325 * @policy: netlink attribute policy
1327 struct nft_object_type {
1328 const struct nft_object_ops *(*select_ops)(const struct nft_ctx *,
1329 const struct nlattr * const tb[]);
1330 const struct nft_object_ops *ops;
1331 struct list_head list;
1333 unsigned int maxattr;
1334 struct module *owner;
1335 const struct nla_policy *policy;
1339 * struct nft_object_ops - stateful object operations
1341 * @eval: stateful object evaluation function
1342 * @size: stateful object size
1343 * @init: initialize object from netlink attributes
1344 * @destroy: release existing stateful object
1345 * @dump: netlink dump stateful object
1346 * @update: update stateful object
1348 struct nft_object_ops {
1349 void (*eval)(struct nft_object *obj,
1350 struct nft_regs *regs,
1351 const struct nft_pktinfo *pkt);
1353 int (*init)(const struct nft_ctx *ctx,
1354 const struct nlattr *const tb[],
1355 struct nft_object *obj);
1356 void (*destroy)(const struct nft_ctx *ctx,
1357 struct nft_object *obj);
1358 int (*dump)(struct sk_buff *skb,
1359 struct nft_object *obj,
1361 void (*update)(struct nft_object *obj,
1362 struct nft_object *newobj);
1363 const struct nft_object_type *type;
1366 int nft_register_obj(struct nft_object_type *obj_type);
1367 void nft_unregister_obj(struct nft_object_type *obj_type);
1369 #define NFT_NETDEVICE_MAX 256
1372 * struct nft_flowtable - nf_tables flow table
1374 * @list: flow table list node in table list
1375 * @table: the table the flow table is contained in
1376 * @name: name of this flow table
1377 * @hooknum: hook number
1378 * @ops_len: number of hooks in array
1379 * @genmask: generation mask
1380 * @use: number of references to this flow table
1381 * @handle: unique object handle
1382 * @dev_name: array of device names
1383 * @data: rhashtable and garbage collector
1384 * @ops: array of hooks
1386 struct nft_flowtable {
1387 struct list_head list;
1388 struct nft_table *table;
1395 /* runtime data below here */
1396 struct list_head hook_list ____cacheline_aligned;
1397 struct nf_flowtable data;
1400 struct nft_flowtable *nft_flowtable_lookup(const struct nft_table *table,
1401 const struct nlattr *nla,
1404 void nf_tables_deactivate_flowtable(const struct nft_ctx *ctx,
1405 struct nft_flowtable *flowtable,
1406 enum nft_trans_phase phase);
1408 void nft_register_flowtable_type(struct nf_flowtable_type *type);
1409 void nft_unregister_flowtable_type(struct nf_flowtable_type *type);
1412 * struct nft_traceinfo - nft tracing information and state
1414 * @trace: other struct members are initialised
1415 * @nf_trace: copy of skb->nf_trace before rule evaluation
1416 * @type: event type (enum nft_trace_types)
1417 * @skbid: hash of skb to be used as trace id
1418 * @packet_dumped: packet headers sent in a previous traceinfo message
1419 * @basechain: base chain currently processed
1421 struct nft_traceinfo {
1425 enum nft_trace_types type:8;
1427 const struct nft_base_chain *basechain;
1430 void nft_trace_init(struct nft_traceinfo *info, const struct nft_pktinfo *pkt,
1431 const struct nft_chain *basechain);
1433 void nft_trace_notify(const struct nft_pktinfo *pkt,
1434 const struct nft_verdict *verdict,
1435 const struct nft_rule_dp *rule,
1436 struct nft_traceinfo *info);
1438 #define MODULE_ALIAS_NFT_CHAIN(family, name) \
1439 MODULE_ALIAS("nft-chain-" __stringify(family) "-" name)
1441 #define MODULE_ALIAS_NFT_AF_EXPR(family, name) \
1442 MODULE_ALIAS("nft-expr-" __stringify(family) "-" name)
1444 #define MODULE_ALIAS_NFT_EXPR(name) \
1445 MODULE_ALIAS("nft-expr-" name)
1447 #define MODULE_ALIAS_NFT_OBJ(type) \
1448 MODULE_ALIAS("nft-obj-" __stringify(type))
1450 #if IS_ENABLED(CONFIG_NF_TABLES)
1453 * The gencursor defines two generations, the currently active and the
1454 * next one. Objects contain a bitmask of 2 bits specifying the generations
1455 * they're active in. A set bit means they're inactive in the generation
1456 * represented by that bit.
1458 * New objects start out as inactive in the current and active in the
1459 * next generation. When committing the ruleset the bitmask is cleared,
1460 * meaning they're active in all generations. When removing an object,
1461 * it is set inactive in the next generation. After committing the ruleset,
1462 * the objects are removed.
1464 static inline unsigned int nft_gencursor_next(const struct net *net)
1466 return net->nft.gencursor + 1 == 1 ? 1 : 0;
1469 static inline u8 nft_genmask_next(const struct net *net)
1471 return 1 << nft_gencursor_next(net);
1474 static inline u8 nft_genmask_cur(const struct net *net)
1476 /* Use READ_ONCE() to prevent refetching the value for atomicity */
1477 return 1 << READ_ONCE(net->nft.gencursor);
1480 #define NFT_GENMASK_ANY ((1 << 0) | (1 << 1))
1483 * Generic transaction helpers
1486 /* Check if this object is currently active. */
1487 #define nft_is_active(__net, __obj) \
1488 (((__obj)->genmask & nft_genmask_cur(__net)) == 0)
1490 /* Check if this object is active in the next generation. */
1491 #define nft_is_active_next(__net, __obj) \
1492 (((__obj)->genmask & nft_genmask_next(__net)) == 0)
1494 /* This object becomes active in the next generation. */
1495 #define nft_activate_next(__net, __obj) \
1496 (__obj)->genmask = nft_genmask_cur(__net)
1498 /* This object becomes inactive in the next generation. */
1499 #define nft_deactivate_next(__net, __obj) \
1500 (__obj)->genmask = nft_genmask_next(__net)
1502 /* After committing the ruleset, clear the stale generation bit. */
1503 #define nft_clear(__net, __obj) \
1504 (__obj)->genmask &= ~nft_genmask_next(__net)
1505 #define nft_active_genmask(__obj, __genmask) \
1506 !((__obj)->genmask & __genmask)
1509 * Set element transaction helpers
1512 static inline bool nft_set_elem_active(const struct nft_set_ext *ext,
1515 return !(ext->genmask & genmask);
1518 static inline void nft_set_elem_change_active(const struct net *net,
1519 const struct nft_set *set,
1520 struct nft_set_ext *ext)
1522 ext->genmask ^= nft_genmask_next(net);
1525 #endif /* IS_ENABLED(CONFIG_NF_TABLES) */
1527 #define NFT_SET_ELEM_DEAD_MASK (1 << 2)
1529 #if defined(__LITTLE_ENDIAN_BITFIELD)
1530 #define NFT_SET_ELEM_DEAD_BIT 2
1531 #elif defined(__BIG_ENDIAN_BITFIELD)
1532 #define NFT_SET_ELEM_DEAD_BIT (BITS_PER_LONG - BITS_PER_BYTE + 2)
1537 static inline void nft_set_elem_dead(struct nft_set_ext *ext)
1539 unsigned long *word = (unsigned long *)ext;
1541 BUILD_BUG_ON(offsetof(struct nft_set_ext, genmask) != 0);
1542 set_bit(NFT_SET_ELEM_DEAD_BIT, word);
1545 static inline int nft_set_elem_is_dead(const struct nft_set_ext *ext)
1547 unsigned long *word = (unsigned long *)ext;
1549 BUILD_BUG_ON(offsetof(struct nft_set_ext, genmask) != 0);
1550 return test_bit(NFT_SET_ELEM_DEAD_BIT, word);
1554 * struct nft_trans - nf_tables object update in transaction
1556 * @list: used internally
1557 * @binding_list: list of objects with possible bindings
1558 * @msg_type: message type
1559 * @put_net: ctx->net needs to be put
1560 * @ctx: transaction context
1561 * @data: internal information related to the transaction
1564 struct list_head list;
1565 struct list_head binding_list;
1572 struct nft_trans_rule {
1573 struct nft_rule *rule;
1574 struct nft_flow_rule *flow;
1579 #define nft_trans_rule(trans) \
1580 (((struct nft_trans_rule *)trans->data)->rule)
1581 #define nft_trans_flow_rule(trans) \
1582 (((struct nft_trans_rule *)trans->data)->flow)
1583 #define nft_trans_rule_id(trans) \
1584 (((struct nft_trans_rule *)trans->data)->rule_id)
1585 #define nft_trans_rule_bound(trans) \
1586 (((struct nft_trans_rule *)trans->data)->bound)
1588 struct nft_trans_set {
1589 struct nft_set *set;
1598 #define nft_trans_set(trans) \
1599 (((struct nft_trans_set *)trans->data)->set)
1600 #define nft_trans_set_id(trans) \
1601 (((struct nft_trans_set *)trans->data)->set_id)
1602 #define nft_trans_set_bound(trans) \
1603 (((struct nft_trans_set *)trans->data)->bound)
1604 #define nft_trans_set_update(trans) \
1605 (((struct nft_trans_set *)trans->data)->update)
1606 #define nft_trans_set_timeout(trans) \
1607 (((struct nft_trans_set *)trans->data)->timeout)
1608 #define nft_trans_set_gc_int(trans) \
1609 (((struct nft_trans_set *)trans->data)->gc_int)
1610 #define nft_trans_set_size(trans) \
1611 (((struct nft_trans_set *)trans->data)->size)
1613 struct nft_trans_chain {
1614 struct nft_chain *chain;
1617 struct nft_stats __percpu *stats;
1621 struct nft_base_chain *basechain;
1622 struct list_head hook_list;
1625 #define nft_trans_chain(trans) \
1626 (((struct nft_trans_chain *)trans->data)->chain)
1627 #define nft_trans_chain_update(trans) \
1628 (((struct nft_trans_chain *)trans->data)->update)
1629 #define nft_trans_chain_name(trans) \
1630 (((struct nft_trans_chain *)trans->data)->name)
1631 #define nft_trans_chain_stats(trans) \
1632 (((struct nft_trans_chain *)trans->data)->stats)
1633 #define nft_trans_chain_policy(trans) \
1634 (((struct nft_trans_chain *)trans->data)->policy)
1635 #define nft_trans_chain_bound(trans) \
1636 (((struct nft_trans_chain *)trans->data)->bound)
1637 #define nft_trans_chain_id(trans) \
1638 (((struct nft_trans_chain *)trans->data)->chain_id)
1639 #define nft_trans_basechain(trans) \
1640 (((struct nft_trans_chain *)trans->data)->basechain)
1641 #define nft_trans_chain_hooks(trans) \
1642 (((struct nft_trans_chain *)trans->data)->hook_list)
1644 struct nft_trans_table {
1648 #define nft_trans_table_update(trans) \
1649 (((struct nft_trans_table *)trans->data)->update)
1651 struct nft_trans_elem {
1652 struct nft_set *set;
1653 struct nft_elem_priv *elem_priv;
1657 #define nft_trans_elem_set(trans) \
1658 (((struct nft_trans_elem *)trans->data)->set)
1659 #define nft_trans_elem_priv(trans) \
1660 (((struct nft_trans_elem *)trans->data)->elem_priv)
1661 #define nft_trans_elem_set_bound(trans) \
1662 (((struct nft_trans_elem *)trans->data)->bound)
1664 struct nft_trans_obj {
1665 struct nft_object *obj;
1666 struct nft_object *newobj;
1670 #define nft_trans_obj(trans) \
1671 (((struct nft_trans_obj *)trans->data)->obj)
1672 #define nft_trans_obj_newobj(trans) \
1673 (((struct nft_trans_obj *)trans->data)->newobj)
1674 #define nft_trans_obj_update(trans) \
1675 (((struct nft_trans_obj *)trans->data)->update)
1677 struct nft_trans_flowtable {
1678 struct nft_flowtable *flowtable;
1680 struct list_head hook_list;
1684 #define nft_trans_flowtable(trans) \
1685 (((struct nft_trans_flowtable *)trans->data)->flowtable)
1686 #define nft_trans_flowtable_update(trans) \
1687 (((struct nft_trans_flowtable *)trans->data)->update)
1688 #define nft_trans_flowtable_hooks(trans) \
1689 (((struct nft_trans_flowtable *)trans->data)->hook_list)
1690 #define nft_trans_flowtable_flags(trans) \
1691 (((struct nft_trans_flowtable *)trans->data)->flags)
1693 #define NFT_TRANS_GC_BATCHCOUNT 256
1695 struct nft_trans_gc {
1696 struct list_head list;
1698 struct nft_set *set;
1701 struct nft_elem_priv *priv[NFT_TRANS_GC_BATCHCOUNT];
1702 struct rcu_head rcu;
1705 struct nft_trans_gc *nft_trans_gc_alloc(struct nft_set *set,
1706 unsigned int gc_seq, gfp_t gfp);
1707 void nft_trans_gc_destroy(struct nft_trans_gc *trans);
1709 struct nft_trans_gc *nft_trans_gc_queue_async(struct nft_trans_gc *gc,
1710 unsigned int gc_seq, gfp_t gfp);
1711 void nft_trans_gc_queue_async_done(struct nft_trans_gc *gc);
1713 struct nft_trans_gc *nft_trans_gc_queue_sync(struct nft_trans_gc *gc, gfp_t gfp);
1714 void nft_trans_gc_queue_sync_done(struct nft_trans_gc *trans);
1716 void nft_trans_gc_elem_add(struct nft_trans_gc *gc, void *priv);
1718 struct nft_trans_gc *nft_trans_gc_catchall_async(struct nft_trans_gc *gc,
1719 unsigned int gc_seq);
1720 struct nft_trans_gc *nft_trans_gc_catchall_sync(struct nft_trans_gc *gc);
1722 void nft_setelem_data_deactivate(const struct net *net,
1723 const struct nft_set *set,
1724 struct nft_elem_priv *elem_priv);
1726 int __init nft_chain_filter_init(void);
1727 void nft_chain_filter_fini(void);
1729 void __init nft_chain_route_init(void);
1730 void nft_chain_route_fini(void);
1732 void nf_tables_trans_destroy_flush_work(void);
1734 int nf_msecs_to_jiffies64(const struct nlattr *nla, u64 *result);
1735 __be64 nf_jiffies64_to_msecs(u64 input);
1737 #ifdef CONFIG_MODULES
1738 __printf(2, 3) int nft_request_module(struct net *net, const char *fmt, ...);
1740 static inline int nft_request_module(struct net *net, const char *fmt, ...) { return -ENOENT; }
1743 struct nftables_pernet {
1744 struct list_head tables;
1745 struct list_head commit_list;
1746 struct list_head binding_list;
1747 struct list_head module_list;
1748 struct list_head notify_list;
1749 struct mutex commit_mutex;
1751 unsigned int base_seq;
1752 unsigned int gc_seq;
1756 extern unsigned int nf_tables_net_id;
1758 static inline struct nftables_pernet *nft_pernet(const struct net *net)
1760 return net_generic(net, nf_tables_net_id);
1763 #define __NFT_REDUCE_READONLY 1UL
1764 #define NFT_REDUCE_READONLY (void *)__NFT_REDUCE_READONLY
1766 static inline bool nft_reduce_is_readonly(const struct nft_expr *expr)
1768 return expr->ops->reduce == NFT_REDUCE_READONLY;
1771 void nft_reg_track_update(struct nft_regs_track *track,
1772 const struct nft_expr *expr, u8 dreg, u8 len);
1773 void nft_reg_track_cancel(struct nft_regs_track *track, u8 dreg, u8 len);
1774 void __nft_reg_track_cancel(struct nft_regs_track *track, u8 dreg);
1776 static inline bool nft_reg_track_cmp(struct nft_regs_track *track,
1777 const struct nft_expr *expr, u8 dreg)
1779 return track->regs[dreg].selector &&
1780 track->regs[dreg].selector->ops == expr->ops &&
1781 track->regs[dreg].num_reg == 0;
1784 #endif /* _NET_NF_TABLES_H */