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(u32 *dreg, u64 val)
183 put_unaligned(val, (u64 *)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[];
278 * struct nft_set_elem - generic representation of set elements
281 * @key_end: closing element key
282 * @priv: element private data and extensions
284 struct nft_set_elem {
286 u32 buf[NFT_DATA_VALUE_MAXLEN / sizeof(u32)];
290 u32 buf[NFT_DATA_VALUE_MAXLEN / sizeof(u32)];
294 u32 buf[NFT_DATA_VALUE_MAXLEN / sizeof(u32)];
301 struct nft_set_iter {
306 int (*fn)(const struct nft_ctx *ctx,
308 const struct nft_set_iter *iter,
309 struct nft_set_elem *elem);
313 * struct nft_set_desc - description of set elements
319 * @objtype: object type
321 * @size: number of set elements
322 * @policy: set policy
323 * @gc_int: garbage collector interval
324 * @field_len: length of each field in concatenation, bytes
325 * @field_count: number of concatenated fields in element
326 * @expr: set must support for expressions
328 struct nft_set_desc {
338 u8 field_len[NFT_REG32_COUNT];
344 * enum nft_set_class - performance class
346 * @NFT_LOOKUP_O_1: constant, O(1)
347 * @NFT_LOOKUP_O_LOG_N: logarithmic, O(log N)
348 * @NFT_LOOKUP_O_N: linear, O(N)
352 NFT_SET_CLASS_O_LOG_N,
357 * struct nft_set_estimate - estimation of memory and performance
360 * @size: required memory
361 * @lookup: lookup performance class
362 * @space: memory class
364 struct nft_set_estimate {
366 enum nft_set_class lookup;
367 enum nft_set_class space;
370 #define NFT_EXPR_MAXATTR 16
371 #define NFT_EXPR_SIZE(size) (sizeof(struct nft_expr) + \
372 ALIGN(size, __alignof__(struct nft_expr)))
375 * struct nft_expr - nf_tables expression
377 * @ops: expression ops
378 * @data: expression private data
381 const struct nft_expr_ops *ops;
383 __attribute__((aligned(__alignof__(u64))));
386 static inline void *nft_expr_priv(const struct nft_expr *expr)
388 return (void *)expr->data;
391 struct nft_expr_info;
393 int nft_expr_inner_parse(const struct nft_ctx *ctx, const struct nlattr *nla,
394 struct nft_expr_info *info);
395 int nft_expr_clone(struct nft_expr *dst, struct nft_expr *src);
396 void nft_expr_destroy(const struct nft_ctx *ctx, struct nft_expr *expr);
397 int nft_expr_dump(struct sk_buff *skb, unsigned int attr,
398 const struct nft_expr *expr, bool reset);
399 bool nft_expr_reduce_bitwise(struct nft_regs_track *track,
400 const struct nft_expr *expr);
405 * struct nft_set_ops - nf_tables set operations
407 * @lookup: look up an element within the set
408 * @update: update an element if exists, add it if doesn't exist
409 * @delete: delete an element
410 * @insert: insert new element into set
411 * @activate: activate new element in the next generation
412 * @deactivate: lookup for element and deactivate it in the next generation
413 * @flush: deactivate element in the next generation
414 * @remove: remove element from set
415 * @walk: iterate over all set elements
416 * @get: get set elements
417 * @privsize: function to return size of set private data
418 * @init: initialize private data of new set instance
419 * @destroy: destroy private data of set instance
420 * @elemsize: element private size
422 * Operations lookup, update and delete have simpler interfaces, are faster
423 * and currently only used in the packet path. All the rest are slower,
424 * control plane functions.
427 bool (*lookup)(const struct net *net,
428 const struct nft_set *set,
430 const struct nft_set_ext **ext);
431 bool (*update)(struct nft_set *set,
433 void *(*new)(struct nft_set *,
434 const struct nft_expr *,
436 const struct nft_expr *expr,
437 struct nft_regs *regs,
438 const struct nft_set_ext **ext);
439 bool (*delete)(const struct nft_set *set,
442 int (*insert)(const struct net *net,
443 const struct nft_set *set,
444 const struct nft_set_elem *elem,
445 struct nft_set_ext **ext);
446 void (*activate)(const struct net *net,
447 const struct nft_set *set,
448 const struct nft_set_elem *elem);
449 void * (*deactivate)(const struct net *net,
450 const struct nft_set *set,
451 const struct nft_set_elem *elem);
452 bool (*flush)(const struct net *net,
453 const struct nft_set *set,
455 void (*remove)(const struct net *net,
456 const struct nft_set *set,
457 const struct nft_set_elem *elem);
458 void (*walk)(const struct nft_ctx *ctx,
460 struct nft_set_iter *iter);
461 void * (*get)(const struct net *net,
462 const struct nft_set *set,
463 const struct nft_set_elem *elem,
465 void (*commit)(const struct nft_set *set);
466 void (*abort)(const struct nft_set *set);
467 u64 (*privsize)(const struct nlattr * const nla[],
468 const struct nft_set_desc *desc);
469 bool (*estimate)(const struct nft_set_desc *desc,
471 struct nft_set_estimate *est);
472 int (*init)(const struct nft_set *set,
473 const struct nft_set_desc *desc,
474 const struct nlattr * const nla[]);
475 void (*destroy)(const struct nft_ctx *ctx,
476 const struct nft_set *set);
477 void (*gc_init)(const struct nft_set *set);
479 unsigned int elemsize;
483 * struct nft_set_type - nf_tables set type
485 * @ops: set ops for this type
486 * @features: features supported by the implementation
488 struct nft_set_type {
489 const struct nft_set_ops ops;
492 #define to_set_type(o) container_of(o, struct nft_set_type, ops)
494 struct nft_set_elem_expr {
497 __attribute__((aligned(__alignof__(struct nft_expr))));
500 #define nft_setelem_expr_at(__elem_expr, __offset) \
501 ((struct nft_expr *)&__elem_expr->data[__offset])
503 #define nft_setelem_expr_foreach(__expr, __elem_expr, __size) \
504 for (__expr = nft_setelem_expr_at(__elem_expr, 0), __size = 0; \
505 __size < (__elem_expr)->size; \
506 __size += (__expr)->ops->size, __expr = ((void *)(__expr)) + (__expr)->ops->size)
508 #define NFT_SET_EXPR_MAX 2
511 * struct nft_set - nf_tables set instance
513 * @list: table set list node
514 * @bindings: list of set bindings
515 * @refs: internal refcounting for async set destruction
516 * @table: table this set belongs to
517 * @net: netnamespace this set belongs to
518 * @name: name of the set
519 * @handle: unique handle of the set
520 * @ktype: key type (numeric type defined by userspace, not used in the kernel)
521 * @dtype: data type (verdict or numeric type defined by userspace)
522 * @objtype: object type (see NFT_OBJECT_* definitions)
523 * @size: maximum set size
524 * @field_len: length of each field in concatenation, bytes
525 * @field_count: number of concatenated fields in element
526 * @use: number of rules references to this set
527 * @nelems: number of elements
528 * @ndeact: number of deactivated elements queued for removal
529 * @timeout: default timeout value in jiffies
530 * @gc_int: garbage collection interval in msecs
531 * @policy: set parameterization (see enum nft_set_policies)
532 * @udlen: user data length
534 * @expr: stateful expression
537 * @dead: set will be freed, never cleared
538 * @genmask: generation mask
541 * @data: private set data
544 struct list_head list;
545 struct list_head bindings;
547 struct nft_table *table;
555 u8 field_len[NFT_REG32_COUNT];
564 unsigned char *udata;
565 struct list_head pending_update;
566 /* runtime data below here */
567 const struct nft_set_ops *ops ____cacheline_aligned;
574 struct nft_expr *exprs[NFT_SET_EXPR_MAX];
575 struct list_head catchall_list;
577 __attribute__((aligned(__alignof__(u64))));
580 static inline bool nft_set_is_anonymous(const struct nft_set *set)
582 return set->flags & NFT_SET_ANONYMOUS;
585 static inline void *nft_set_priv(const struct nft_set *set)
587 return (void *)set->data;
590 static inline bool nft_set_gc_is_pending(const struct nft_set *s)
592 return refcount_read(&s->refs) != 1;
595 static inline struct nft_set *nft_set_container_of(const void *priv)
597 return (void *)priv - offsetof(struct nft_set, data);
600 struct nft_set *nft_set_lookup_global(const struct net *net,
601 const struct nft_table *table,
602 const struct nlattr *nla_set_name,
603 const struct nlattr *nla_set_id,
606 struct nft_set_ext *nft_set_catchall_lookup(const struct net *net,
607 const struct nft_set *set);
609 static inline unsigned long nft_set_gc_interval(const struct nft_set *set)
611 u32 gc_int = READ_ONCE(set->gc_int);
613 return gc_int ? msecs_to_jiffies(gc_int) : HZ;
617 * struct nft_set_binding - nf_tables set binding
619 * @list: set bindings list node
620 * @chain: chain containing the rule bound to the set
621 * @flags: set action flags
623 * A set binding contains all information necessary for validation
624 * of new elements added to a bound set.
626 struct nft_set_binding {
627 struct list_head list;
628 const struct nft_chain *chain;
632 enum nft_trans_phase;
633 void nf_tables_activate_set(const struct nft_ctx *ctx, struct nft_set *set);
634 void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set,
635 struct nft_set_binding *binding,
636 enum nft_trans_phase phase);
637 int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,
638 struct nft_set_binding *binding);
639 void nf_tables_destroy_set(const struct nft_ctx *ctx, struct nft_set *set);
642 * enum nft_set_extensions - set extension type IDs
644 * @NFT_SET_EXT_KEY: element key
645 * @NFT_SET_EXT_KEY_END: upper bound element key, for ranges
646 * @NFT_SET_EXT_DATA: mapping data
647 * @NFT_SET_EXT_FLAGS: element flags
648 * @NFT_SET_EXT_TIMEOUT: element timeout
649 * @NFT_SET_EXT_EXPIRATION: element expiration time
650 * @NFT_SET_EXT_USERDATA: user data associated with the element
651 * @NFT_SET_EXT_EXPRESSIONS: expressions assiciated with the element
652 * @NFT_SET_EXT_OBJREF: stateful object reference associated with element
653 * @NFT_SET_EXT_NUM: number of extension types
655 enum nft_set_extensions {
661 NFT_SET_EXT_EXPIRATION,
662 NFT_SET_EXT_USERDATA,
663 NFT_SET_EXT_EXPRESSIONS,
669 * struct nft_set_ext_type - set extension type
671 * @len: fixed part length of the extension
672 * @align: alignment requirements of the extension
674 struct nft_set_ext_type {
679 extern const struct nft_set_ext_type nft_set_ext_types[];
682 * struct nft_set_ext_tmpl - set extension template
684 * @len: length of extension area
685 * @offset: offsets of individual extension types
687 struct nft_set_ext_tmpl {
689 u8 offset[NFT_SET_EXT_NUM];
690 u8 ext_len[NFT_SET_EXT_NUM];
694 * struct nft_set_ext - set extensions
696 * @genmask: generation mask
697 * @offset: offsets of individual extension types
698 * @data: beginning of extension data
702 u8 offset[NFT_SET_EXT_NUM];
706 static inline void nft_set_ext_prepare(struct nft_set_ext_tmpl *tmpl)
708 memset(tmpl, 0, sizeof(*tmpl));
709 tmpl->len = sizeof(struct nft_set_ext);
712 static inline int nft_set_ext_add_length(struct nft_set_ext_tmpl *tmpl, u8 id,
715 tmpl->len = ALIGN(tmpl->len, nft_set_ext_types[id].align);
716 if (tmpl->len > U8_MAX)
719 tmpl->offset[id] = tmpl->len;
720 tmpl->ext_len[id] = nft_set_ext_types[id].len + len;
721 tmpl->len += tmpl->ext_len[id];
726 static inline int nft_set_ext_add(struct nft_set_ext_tmpl *tmpl, u8 id)
728 return nft_set_ext_add_length(tmpl, id, 0);
731 static inline void nft_set_ext_init(struct nft_set_ext *ext,
732 const struct nft_set_ext_tmpl *tmpl)
734 memcpy(ext->offset, tmpl->offset, sizeof(ext->offset));
737 static inline bool __nft_set_ext_exists(const struct nft_set_ext *ext, u8 id)
739 return !!ext->offset[id];
742 static inline bool nft_set_ext_exists(const struct nft_set_ext *ext, u8 id)
744 return ext && __nft_set_ext_exists(ext, id);
747 static inline void *nft_set_ext(const struct nft_set_ext *ext, u8 id)
749 return (void *)ext + ext->offset[id];
752 static inline struct nft_data *nft_set_ext_key(const struct nft_set_ext *ext)
754 return nft_set_ext(ext, NFT_SET_EXT_KEY);
757 static inline struct nft_data *nft_set_ext_key_end(const struct nft_set_ext *ext)
759 return nft_set_ext(ext, NFT_SET_EXT_KEY_END);
762 static inline struct nft_data *nft_set_ext_data(const struct nft_set_ext *ext)
764 return nft_set_ext(ext, NFT_SET_EXT_DATA);
767 static inline u8 *nft_set_ext_flags(const struct nft_set_ext *ext)
769 return nft_set_ext(ext, NFT_SET_EXT_FLAGS);
772 static inline u64 *nft_set_ext_timeout(const struct nft_set_ext *ext)
774 return nft_set_ext(ext, NFT_SET_EXT_TIMEOUT);
777 static inline u64 *nft_set_ext_expiration(const struct nft_set_ext *ext)
779 return nft_set_ext(ext, NFT_SET_EXT_EXPIRATION);
782 static inline struct nft_userdata *nft_set_ext_userdata(const struct nft_set_ext *ext)
784 return nft_set_ext(ext, NFT_SET_EXT_USERDATA);
787 static inline struct nft_set_elem_expr *nft_set_ext_expr(const struct nft_set_ext *ext)
789 return nft_set_ext(ext, NFT_SET_EXT_EXPRESSIONS);
792 static inline bool nft_set_elem_expired(const struct nft_set_ext *ext)
794 return nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION) &&
795 time_is_before_eq_jiffies64(*nft_set_ext_expiration(ext));
798 static inline struct nft_set_ext *nft_set_elem_ext(const struct nft_set *set,
801 return elem + set->ops->elemsize;
804 static inline struct nft_object **nft_set_ext_obj(const struct nft_set_ext *ext)
806 return nft_set_ext(ext, NFT_SET_EXT_OBJREF);
809 struct nft_expr *nft_set_elem_expr_alloc(const struct nft_ctx *ctx,
810 const struct nft_set *set,
811 const struct nlattr *attr);
813 void *nft_set_elem_init(const struct nft_set *set,
814 const struct nft_set_ext_tmpl *tmpl,
815 const u32 *key, const u32 *key_end, const u32 *data,
816 u64 timeout, u64 expiration, gfp_t gfp);
817 int nft_set_elem_expr_clone(const struct nft_ctx *ctx, struct nft_set *set,
818 struct nft_expr *expr_array[]);
819 void nft_set_elem_destroy(const struct nft_set *set, void *elem,
821 void nf_tables_set_elem_destroy(const struct nft_ctx *ctx,
822 const struct nft_set *set, void *elem);
826 * struct nft_expr_type - nf_tables expression type
828 * @select_ops: function to select nft_expr_ops
829 * @release_ops: release nft_expr_ops
830 * @ops: default ops, used when no select_ops functions is present
831 * @list: used internally
833 * @owner: module reference
834 * @policy: netlink attribute policy
835 * @maxattr: highest netlink attribute number
836 * @family: address family for AF-specific types
837 * @flags: expression type flags
839 struct nft_expr_type {
840 const struct nft_expr_ops *(*select_ops)(const struct nft_ctx *,
841 const struct nlattr * const tb[]);
842 void (*release_ops)(const struct nft_expr_ops *ops);
843 const struct nft_expr_ops *ops;
844 const struct nft_expr_ops *inner_ops;
845 struct list_head list;
847 struct module *owner;
848 const struct nla_policy *policy;
849 unsigned int maxattr;
854 #define NFT_EXPR_STATEFUL 0x1
855 #define NFT_EXPR_GC 0x2
857 enum nft_trans_phase {
859 NFT_TRANS_PREPARE_ERROR,
865 struct nft_flow_rule;
866 struct nft_offload_ctx;
869 * struct nft_expr_ops - nf_tables expression operations
871 * @eval: Expression evaluation function
872 * @size: full expression size, including private data size
873 * @init: initialization function
874 * @activate: activate expression in the next generation
875 * @deactivate: deactivate expression in next generation
876 * @destroy: destruction function, called after synchronize_rcu
877 * @dump: function to dump parameters
878 * @type: expression type
879 * @validate: validate expression, called during loop detection
880 * @data: extra data to attach to this expression operation
882 struct nft_expr_ops {
883 void (*eval)(const struct nft_expr *expr,
884 struct nft_regs *regs,
885 const struct nft_pktinfo *pkt);
886 int (*clone)(struct nft_expr *dst,
887 const struct nft_expr *src);
890 int (*init)(const struct nft_ctx *ctx,
891 const struct nft_expr *expr,
892 const struct nlattr * const tb[]);
893 void (*activate)(const struct nft_ctx *ctx,
894 const struct nft_expr *expr);
895 void (*deactivate)(const struct nft_ctx *ctx,
896 const struct nft_expr *expr,
897 enum nft_trans_phase phase);
898 void (*destroy)(const struct nft_ctx *ctx,
899 const struct nft_expr *expr);
900 void (*destroy_clone)(const struct nft_ctx *ctx,
901 const struct nft_expr *expr);
902 int (*dump)(struct sk_buff *skb,
903 const struct nft_expr *expr,
905 int (*validate)(const struct nft_ctx *ctx,
906 const struct nft_expr *expr,
907 const struct nft_data **data);
908 bool (*reduce)(struct nft_regs_track *track,
909 const struct nft_expr *expr);
910 bool (*gc)(struct net *net,
911 const struct nft_expr *expr);
912 int (*offload)(struct nft_offload_ctx *ctx,
913 struct nft_flow_rule *flow,
914 const struct nft_expr *expr);
915 bool (*offload_action)(const struct nft_expr *expr);
916 void (*offload_stats)(struct nft_expr *expr,
917 const struct flow_stats *stats);
918 const struct nft_expr_type *type;
923 * struct nft_rule - nf_tables rule
925 * @list: used internally
926 * @handle: rule handle
927 * @genmask: generation mask
928 * @dlen: length of expression data
929 * @udata: user data is appended to the rule
930 * @data: expression data
933 struct list_head list;
939 __attribute__((aligned(__alignof__(struct nft_expr))));
942 static inline struct nft_expr *nft_expr_first(const struct nft_rule *rule)
944 return (struct nft_expr *)&rule->data[0];
947 static inline struct nft_expr *nft_expr_next(const struct nft_expr *expr)
949 return ((void *)expr) + expr->ops->size;
952 static inline struct nft_expr *nft_expr_last(const struct nft_rule *rule)
954 return (struct nft_expr *)&rule->data[rule->dlen];
957 static inline bool nft_expr_more(const struct nft_rule *rule,
958 const struct nft_expr *expr)
960 return expr != nft_expr_last(rule) && expr->ops;
963 static inline struct nft_userdata *nft_userdata(const struct nft_rule *rule)
965 return (void *)&rule->data[rule->dlen];
968 void nft_rule_expr_activate(const struct nft_ctx *ctx, struct nft_rule *rule);
969 void nft_rule_expr_deactivate(const struct nft_ctx *ctx, struct nft_rule *rule,
970 enum nft_trans_phase phase);
971 void nf_tables_rule_destroy(const struct nft_ctx *ctx, struct nft_rule *rule);
973 static inline void nft_set_elem_update_expr(const struct nft_set_ext *ext,
974 struct nft_regs *regs,
975 const struct nft_pktinfo *pkt)
977 struct nft_set_elem_expr *elem_expr;
978 struct nft_expr *expr;
981 if (__nft_set_ext_exists(ext, NFT_SET_EXT_EXPRESSIONS)) {
982 elem_expr = nft_set_ext_expr(ext);
983 nft_setelem_expr_foreach(expr, elem_expr, size) {
984 expr->ops->eval(expr, regs, pkt);
985 if (regs->verdict.code == NFT_BREAK)
992 * The last pointer isn't really necessary, but the compiler isn't able to
993 * determine that the result of nft_expr_last() is always the same since it
994 * can't assume that the dlen value wasn't changed within calls in the loop.
996 #define nft_rule_for_each_expr(expr, last, rule) \
997 for ((expr) = nft_expr_first(rule), (last) = nft_expr_last(rule); \
999 (expr) = nft_expr_next(expr))
1001 #define NFT_CHAIN_POLICY_UNSET U8_MAX
1003 struct nft_rule_dp {
1006 handle:42; /* for tracing */
1007 unsigned char data[]
1008 __attribute__((aligned(__alignof__(struct nft_expr))));
1011 struct nft_rule_dp_last {
1012 struct nft_rule_dp end; /* end of nft_rule_blob marker */
1013 struct rcu_head h; /* call_rcu head */
1014 struct nft_rule_blob *blob; /* ptr to free via call_rcu */
1015 const struct nft_chain *chain; /* for nftables tracing */
1018 static inline const struct nft_rule_dp *nft_rule_next(const struct nft_rule_dp *rule)
1020 return (void *)rule + sizeof(*rule) + rule->dlen;
1023 struct nft_rule_blob {
1025 unsigned char data[]
1026 __attribute__((aligned(__alignof__(struct nft_rule_dp))));
1030 * struct nft_chain - nf_tables chain
1032 * @rules: list of rules in the chain
1033 * @list: used internally
1034 * @rhlhead: used internally
1035 * @table: table that this chain belongs to
1036 * @handle: chain handle
1037 * @use: number of jump references to this chain
1038 * @flags: bitmask of enum nft_chain_flags
1039 * @name: name of the chain
1042 struct nft_rule_blob __rcu *blob_gen_0;
1043 struct nft_rule_blob __rcu *blob_gen_1;
1044 struct list_head rules;
1045 struct list_head list;
1046 struct rhlist_head rhlhead;
1047 struct nft_table *table;
1057 /* Only used during control plane commit phase: */
1058 struct nft_rule_blob *blob_next;
1061 int nft_chain_validate(const struct nft_ctx *ctx, const struct nft_chain *chain);
1062 int nft_setelem_validate(const struct nft_ctx *ctx, struct nft_set *set,
1063 const struct nft_set_iter *iter,
1064 struct nft_set_elem *elem);
1065 int nft_set_catchall_validate(const struct nft_ctx *ctx, struct nft_set *set);
1066 int nf_tables_bind_chain(const struct nft_ctx *ctx, struct nft_chain *chain);
1067 void nf_tables_unbind_chain(const struct nft_ctx *ctx, struct nft_chain *chain);
1069 enum nft_chain_types {
1070 NFT_CHAIN_T_DEFAULT = 0,
1077 * struct nft_chain_type - nf_tables chain type info
1079 * @name: name of the type
1080 * @type: numeric identifier
1081 * @family: address family
1082 * @owner: module owner
1083 * @hook_mask: mask of valid hooks
1084 * @hooks: array of hook functions
1085 * @ops_register: base chain register function
1086 * @ops_unregister: base chain unregister function
1088 struct nft_chain_type {
1090 enum nft_chain_types type;
1092 struct module *owner;
1093 unsigned int hook_mask;
1094 nf_hookfn *hooks[NFT_MAX_HOOKS];
1095 int (*ops_register)(struct net *net, const struct nf_hook_ops *ops);
1096 void (*ops_unregister)(struct net *net, const struct nf_hook_ops *ops);
1099 int nft_chain_validate_dependency(const struct nft_chain *chain,
1100 enum nft_chain_types type);
1101 int nft_chain_validate_hooks(const struct nft_chain *chain,
1102 unsigned int hook_flags);
1104 static inline bool nft_chain_binding(const struct nft_chain *chain)
1106 return chain->flags & NFT_CHAIN_BINDING;
1109 static inline bool nft_chain_is_bound(struct nft_chain *chain)
1111 return (chain->flags & NFT_CHAIN_BINDING) && chain->bound;
1114 int nft_chain_add(struct nft_table *table, struct nft_chain *chain);
1115 void nft_chain_del(struct nft_chain *chain);
1116 void nf_tables_chain_destroy(struct nft_ctx *ctx);
1121 struct u64_stats_sync syncp;
1125 struct list_head list;
1126 struct nf_hook_ops ops;
1127 struct rcu_head rcu;
1131 * struct nft_base_chain - nf_tables base chain
1133 * @ops: netfilter hook ops
1134 * @hook_list: list of netfilter hooks (for NFPROTO_NETDEV family)
1136 * @policy: default policy
1137 * @stats: per-cpu chain stats
1139 * @flow_block: flow block (for hardware offload)
1141 struct nft_base_chain {
1142 struct nf_hook_ops ops;
1143 struct list_head hook_list;
1144 const struct nft_chain_type *type;
1147 struct nft_stats __percpu *stats;
1148 struct nft_chain chain;
1149 struct flow_block flow_block;
1152 static inline struct nft_base_chain *nft_base_chain(const struct nft_chain *chain)
1154 return container_of(chain, struct nft_base_chain, chain);
1157 static inline bool nft_is_base_chain(const struct nft_chain *chain)
1159 return chain->flags & NFT_CHAIN_BASE;
1162 int __nft_release_basechain(struct nft_ctx *ctx);
1164 unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);
1166 static inline bool nft_use_inc(u32 *use)
1168 if (*use == UINT_MAX)
1176 static inline void nft_use_dec(u32 *use)
1178 WARN_ON_ONCE((*use)-- == 0);
1181 /* For error and abort path: restore use counter to previous state. */
1182 static inline void nft_use_inc_restore(u32 *use)
1184 WARN_ON_ONCE(!nft_use_inc(use));
1187 #define nft_use_dec_restore nft_use_dec
1190 * struct nft_table - nf_tables table
1192 * @list: used internally
1193 * @chains_ht: chains in the table
1194 * @chains: same, for stable walks
1195 * @sets: sets in the table
1196 * @objects: stateful objects in the table
1197 * @flowtables: flow tables in the table
1198 * @hgenerator: handle generator state
1199 * @handle: table handle
1200 * @use: number of chain references to this table
1201 * @flags: table flag (see enum nft_table_flags)
1202 * @genmask: generation mask
1203 * @afinfo: address family info
1204 * @name: name of the table
1205 * @validate_state: internal, set when transaction adds jumps
1208 struct list_head list;
1209 struct rhltable chains_ht;
1210 struct list_head chains;
1211 struct list_head sets;
1212 struct list_head objects;
1213 struct list_head flowtables;
1227 static inline bool nft_table_has_owner(const struct nft_table *table)
1229 return table->flags & NFT_TABLE_F_OWNER;
1232 static inline bool nft_base_chain_netdev(int family, u32 hooknum)
1234 return family == NFPROTO_NETDEV ||
1235 (family == NFPROTO_INET && hooknum == NF_INET_INGRESS);
1238 void nft_register_chain_type(const struct nft_chain_type *);
1239 void nft_unregister_chain_type(const struct nft_chain_type *);
1241 int nft_register_expr(struct nft_expr_type *);
1242 void nft_unregister_expr(struct nft_expr_type *);
1244 int nft_verdict_dump(struct sk_buff *skb, int type,
1245 const struct nft_verdict *v);
1248 * struct nft_object_hash_key - key to lookup nft_object
1250 * @name: name of the stateful object to look up
1251 * @table: table the object belongs to
1253 struct nft_object_hash_key {
1255 const struct nft_table *table;
1259 * struct nft_object - nf_tables stateful object
1261 * @list: table stateful object list node
1262 * @key: keys that identify this object
1263 * @rhlhead: nft_objname_ht node
1264 * @genmask: generation mask
1265 * @use: number of references to this stateful object
1266 * @handle: unique object handle
1267 * @ops: object operations
1268 * @data: object data, layout depends on type
1271 struct list_head list;
1272 struct rhlist_head rhlhead;
1273 struct nft_object_hash_key key;
1279 /* runtime data below here */
1280 const struct nft_object_ops *ops ____cacheline_aligned;
1281 unsigned char data[]
1282 __attribute__((aligned(__alignof__(u64))));
1285 static inline void *nft_obj_data(const struct nft_object *obj)
1287 return (void *)obj->data;
1290 #define nft_expr_obj(expr) *((struct nft_object **)nft_expr_priv(expr))
1292 struct nft_object *nft_obj_lookup(const struct net *net,
1293 const struct nft_table *table,
1294 const struct nlattr *nla, u32 objtype,
1297 void nft_obj_notify(struct net *net, const struct nft_table *table,
1298 struct nft_object *obj, u32 portid, u32 seq,
1299 int event, u16 flags, int family, int report, gfp_t gfp);
1302 * struct nft_object_type - stateful object type
1304 * @select_ops: function to select nft_object_ops
1305 * @ops: default ops, used when no select_ops functions is present
1306 * @list: list node in list of object types
1307 * @type: stateful object numeric type
1308 * @owner: module owner
1309 * @maxattr: maximum netlink attribute
1310 * @policy: netlink attribute policy
1312 struct nft_object_type {
1313 const struct nft_object_ops *(*select_ops)(const struct nft_ctx *,
1314 const struct nlattr * const tb[]);
1315 const struct nft_object_ops *ops;
1316 struct list_head list;
1318 unsigned int maxattr;
1319 struct module *owner;
1320 const struct nla_policy *policy;
1324 * struct nft_object_ops - stateful object operations
1326 * @eval: stateful object evaluation function
1327 * @size: stateful object size
1328 * @init: initialize object from netlink attributes
1329 * @destroy: release existing stateful object
1330 * @dump: netlink dump stateful object
1331 * @update: update stateful object
1333 struct nft_object_ops {
1334 void (*eval)(struct nft_object *obj,
1335 struct nft_regs *regs,
1336 const struct nft_pktinfo *pkt);
1338 int (*init)(const struct nft_ctx *ctx,
1339 const struct nlattr *const tb[],
1340 struct nft_object *obj);
1341 void (*destroy)(const struct nft_ctx *ctx,
1342 struct nft_object *obj);
1343 int (*dump)(struct sk_buff *skb,
1344 struct nft_object *obj,
1346 void (*update)(struct nft_object *obj,
1347 struct nft_object *newobj);
1348 const struct nft_object_type *type;
1351 int nft_register_obj(struct nft_object_type *obj_type);
1352 void nft_unregister_obj(struct nft_object_type *obj_type);
1354 #define NFT_NETDEVICE_MAX 256
1357 * struct nft_flowtable - nf_tables flow table
1359 * @list: flow table list node in table list
1360 * @table: the table the flow table is contained in
1361 * @name: name of this flow table
1362 * @hooknum: hook number
1363 * @ops_len: number of hooks in array
1364 * @genmask: generation mask
1365 * @use: number of references to this flow table
1366 * @handle: unique object handle
1367 * @dev_name: array of device names
1368 * @data: rhashtable and garbage collector
1369 * @ops: array of hooks
1371 struct nft_flowtable {
1372 struct list_head list;
1373 struct nft_table *table;
1380 /* runtime data below here */
1381 struct list_head hook_list ____cacheline_aligned;
1382 struct nf_flowtable data;
1385 struct nft_flowtable *nft_flowtable_lookup(const struct nft_table *table,
1386 const struct nlattr *nla,
1389 void nf_tables_deactivate_flowtable(const struct nft_ctx *ctx,
1390 struct nft_flowtable *flowtable,
1391 enum nft_trans_phase phase);
1393 void nft_register_flowtable_type(struct nf_flowtable_type *type);
1394 void nft_unregister_flowtable_type(struct nf_flowtable_type *type);
1397 * struct nft_traceinfo - nft tracing information and state
1399 * @trace: other struct members are initialised
1400 * @nf_trace: copy of skb->nf_trace before rule evaluation
1401 * @type: event type (enum nft_trace_types)
1402 * @skbid: hash of skb to be used as trace id
1403 * @packet_dumped: packet headers sent in a previous traceinfo message
1404 * @basechain: base chain currently processed
1406 struct nft_traceinfo {
1410 enum nft_trace_types type:8;
1412 const struct nft_base_chain *basechain;
1415 void nft_trace_init(struct nft_traceinfo *info, const struct nft_pktinfo *pkt,
1416 const struct nft_chain *basechain);
1418 void nft_trace_notify(const struct nft_pktinfo *pkt,
1419 const struct nft_verdict *verdict,
1420 const struct nft_rule_dp *rule,
1421 struct nft_traceinfo *info);
1423 #define MODULE_ALIAS_NFT_CHAIN(family, name) \
1424 MODULE_ALIAS("nft-chain-" __stringify(family) "-" name)
1426 #define MODULE_ALIAS_NFT_AF_EXPR(family, name) \
1427 MODULE_ALIAS("nft-expr-" __stringify(family) "-" name)
1429 #define MODULE_ALIAS_NFT_EXPR(name) \
1430 MODULE_ALIAS("nft-expr-" name)
1432 #define MODULE_ALIAS_NFT_OBJ(type) \
1433 MODULE_ALIAS("nft-obj-" __stringify(type))
1435 #if IS_ENABLED(CONFIG_NF_TABLES)
1438 * The gencursor defines two generations, the currently active and the
1439 * next one. Objects contain a bitmask of 2 bits specifying the generations
1440 * they're active in. A set bit means they're inactive in the generation
1441 * represented by that bit.
1443 * New objects start out as inactive in the current and active in the
1444 * next generation. When committing the ruleset the bitmask is cleared,
1445 * meaning they're active in all generations. When removing an object,
1446 * it is set inactive in the next generation. After committing the ruleset,
1447 * the objects are removed.
1449 static inline unsigned int nft_gencursor_next(const struct net *net)
1451 return net->nft.gencursor + 1 == 1 ? 1 : 0;
1454 static inline u8 nft_genmask_next(const struct net *net)
1456 return 1 << nft_gencursor_next(net);
1459 static inline u8 nft_genmask_cur(const struct net *net)
1461 /* Use READ_ONCE() to prevent refetching the value for atomicity */
1462 return 1 << READ_ONCE(net->nft.gencursor);
1465 #define NFT_GENMASK_ANY ((1 << 0) | (1 << 1))
1468 * Generic transaction helpers
1471 /* Check if this object is currently active. */
1472 #define nft_is_active(__net, __obj) \
1473 (((__obj)->genmask & nft_genmask_cur(__net)) == 0)
1475 /* Check if this object is active in the next generation. */
1476 #define nft_is_active_next(__net, __obj) \
1477 (((__obj)->genmask & nft_genmask_next(__net)) == 0)
1479 /* This object becomes active in the next generation. */
1480 #define nft_activate_next(__net, __obj) \
1481 (__obj)->genmask = nft_genmask_cur(__net)
1483 /* This object becomes inactive in the next generation. */
1484 #define nft_deactivate_next(__net, __obj) \
1485 (__obj)->genmask = nft_genmask_next(__net)
1487 /* After committing the ruleset, clear the stale generation bit. */
1488 #define nft_clear(__net, __obj) \
1489 (__obj)->genmask &= ~nft_genmask_next(__net)
1490 #define nft_active_genmask(__obj, __genmask) \
1491 !((__obj)->genmask & __genmask)
1494 * Set element transaction helpers
1497 static inline bool nft_set_elem_active(const struct nft_set_ext *ext,
1500 return !(ext->genmask & genmask);
1503 static inline void nft_set_elem_change_active(const struct net *net,
1504 const struct nft_set *set,
1505 struct nft_set_ext *ext)
1507 ext->genmask ^= nft_genmask_next(net);
1510 #endif /* IS_ENABLED(CONFIG_NF_TABLES) */
1512 #define NFT_SET_ELEM_DEAD_MASK (1 << 2)
1514 #if defined(__LITTLE_ENDIAN_BITFIELD)
1515 #define NFT_SET_ELEM_DEAD_BIT 2
1516 #elif defined(__BIG_ENDIAN_BITFIELD)
1517 #define NFT_SET_ELEM_DEAD_BIT (BITS_PER_LONG - BITS_PER_BYTE + 2)
1522 static inline void nft_set_elem_dead(struct nft_set_ext *ext)
1524 unsigned long *word = (unsigned long *)ext;
1526 BUILD_BUG_ON(offsetof(struct nft_set_ext, genmask) != 0);
1527 set_bit(NFT_SET_ELEM_DEAD_BIT, word);
1530 static inline int nft_set_elem_is_dead(const struct nft_set_ext *ext)
1532 unsigned long *word = (unsigned long *)ext;
1534 BUILD_BUG_ON(offsetof(struct nft_set_ext, genmask) != 0);
1535 return test_bit(NFT_SET_ELEM_DEAD_BIT, word);
1539 * struct nft_trans - nf_tables object update in transaction
1541 * @list: used internally
1542 * @binding_list: list of objects with possible bindings
1543 * @msg_type: message type
1544 * @put_net: ctx->net needs to be put
1545 * @ctx: transaction context
1546 * @data: internal information related to the transaction
1549 struct list_head list;
1550 struct list_head binding_list;
1557 struct nft_trans_rule {
1558 struct nft_rule *rule;
1559 struct nft_flow_rule *flow;
1564 #define nft_trans_rule(trans) \
1565 (((struct nft_trans_rule *)trans->data)->rule)
1566 #define nft_trans_flow_rule(trans) \
1567 (((struct nft_trans_rule *)trans->data)->flow)
1568 #define nft_trans_rule_id(trans) \
1569 (((struct nft_trans_rule *)trans->data)->rule_id)
1570 #define nft_trans_rule_bound(trans) \
1571 (((struct nft_trans_rule *)trans->data)->bound)
1573 struct nft_trans_set {
1574 struct nft_set *set;
1583 #define nft_trans_set(trans) \
1584 (((struct nft_trans_set *)trans->data)->set)
1585 #define nft_trans_set_id(trans) \
1586 (((struct nft_trans_set *)trans->data)->set_id)
1587 #define nft_trans_set_bound(trans) \
1588 (((struct nft_trans_set *)trans->data)->bound)
1589 #define nft_trans_set_update(trans) \
1590 (((struct nft_trans_set *)trans->data)->update)
1591 #define nft_trans_set_timeout(trans) \
1592 (((struct nft_trans_set *)trans->data)->timeout)
1593 #define nft_trans_set_gc_int(trans) \
1594 (((struct nft_trans_set *)trans->data)->gc_int)
1595 #define nft_trans_set_size(trans) \
1596 (((struct nft_trans_set *)trans->data)->size)
1598 struct nft_trans_chain {
1599 struct nft_chain *chain;
1602 struct nft_stats __percpu *stats;
1606 struct nft_base_chain *basechain;
1607 struct list_head hook_list;
1610 #define nft_trans_chain(trans) \
1611 (((struct nft_trans_chain *)trans->data)->chain)
1612 #define nft_trans_chain_update(trans) \
1613 (((struct nft_trans_chain *)trans->data)->update)
1614 #define nft_trans_chain_name(trans) \
1615 (((struct nft_trans_chain *)trans->data)->name)
1616 #define nft_trans_chain_stats(trans) \
1617 (((struct nft_trans_chain *)trans->data)->stats)
1618 #define nft_trans_chain_policy(trans) \
1619 (((struct nft_trans_chain *)trans->data)->policy)
1620 #define nft_trans_chain_bound(trans) \
1621 (((struct nft_trans_chain *)trans->data)->bound)
1622 #define nft_trans_chain_id(trans) \
1623 (((struct nft_trans_chain *)trans->data)->chain_id)
1624 #define nft_trans_basechain(trans) \
1625 (((struct nft_trans_chain *)trans->data)->basechain)
1626 #define nft_trans_chain_hooks(trans) \
1627 (((struct nft_trans_chain *)trans->data)->hook_list)
1629 struct nft_trans_table {
1633 #define nft_trans_table_update(trans) \
1634 (((struct nft_trans_table *)trans->data)->update)
1636 struct nft_trans_elem {
1637 struct nft_set *set;
1638 struct nft_set_elem elem;
1642 #define nft_trans_elem_set(trans) \
1643 (((struct nft_trans_elem *)trans->data)->set)
1644 #define nft_trans_elem(trans) \
1645 (((struct nft_trans_elem *)trans->data)->elem)
1646 #define nft_trans_elem_set_bound(trans) \
1647 (((struct nft_trans_elem *)trans->data)->bound)
1649 struct nft_trans_obj {
1650 struct nft_object *obj;
1651 struct nft_object *newobj;
1655 #define nft_trans_obj(trans) \
1656 (((struct nft_trans_obj *)trans->data)->obj)
1657 #define nft_trans_obj_newobj(trans) \
1658 (((struct nft_trans_obj *)trans->data)->newobj)
1659 #define nft_trans_obj_update(trans) \
1660 (((struct nft_trans_obj *)trans->data)->update)
1662 struct nft_trans_flowtable {
1663 struct nft_flowtable *flowtable;
1665 struct list_head hook_list;
1669 #define nft_trans_flowtable(trans) \
1670 (((struct nft_trans_flowtable *)trans->data)->flowtable)
1671 #define nft_trans_flowtable_update(trans) \
1672 (((struct nft_trans_flowtable *)trans->data)->update)
1673 #define nft_trans_flowtable_hooks(trans) \
1674 (((struct nft_trans_flowtable *)trans->data)->hook_list)
1675 #define nft_trans_flowtable_flags(trans) \
1676 (((struct nft_trans_flowtable *)trans->data)->flags)
1678 #define NFT_TRANS_GC_BATCHCOUNT 256
1680 struct nft_trans_gc {
1681 struct list_head list;
1683 struct nft_set *set;
1686 void *priv[NFT_TRANS_GC_BATCHCOUNT];
1687 struct rcu_head rcu;
1690 struct nft_trans_gc *nft_trans_gc_alloc(struct nft_set *set,
1691 unsigned int gc_seq, gfp_t gfp);
1692 void nft_trans_gc_destroy(struct nft_trans_gc *trans);
1694 struct nft_trans_gc *nft_trans_gc_queue_async(struct nft_trans_gc *gc,
1695 unsigned int gc_seq, gfp_t gfp);
1696 void nft_trans_gc_queue_async_done(struct nft_trans_gc *gc);
1698 struct nft_trans_gc *nft_trans_gc_queue_sync(struct nft_trans_gc *gc, gfp_t gfp);
1699 void nft_trans_gc_queue_sync_done(struct nft_trans_gc *trans);
1701 void nft_trans_gc_elem_add(struct nft_trans_gc *gc, void *priv);
1703 struct nft_trans_gc *nft_trans_gc_catchall(struct nft_trans_gc *gc,
1704 unsigned int gc_seq);
1706 void nft_setelem_data_deactivate(const struct net *net,
1707 const struct nft_set *set,
1708 struct nft_set_elem *elem);
1710 int __init nft_chain_filter_init(void);
1711 void nft_chain_filter_fini(void);
1713 void __init nft_chain_route_init(void);
1714 void nft_chain_route_fini(void);
1716 void nf_tables_trans_destroy_flush_work(void);
1718 int nf_msecs_to_jiffies64(const struct nlattr *nla, u64 *result);
1719 __be64 nf_jiffies64_to_msecs(u64 input);
1721 #ifdef CONFIG_MODULES
1722 __printf(2, 3) int nft_request_module(struct net *net, const char *fmt, ...);
1724 static inline int nft_request_module(struct net *net, const char *fmt, ...) { return -ENOENT; }
1727 struct nftables_pernet {
1728 struct list_head tables;
1729 struct list_head commit_list;
1730 struct list_head binding_list;
1731 struct list_head module_list;
1732 struct list_head notify_list;
1733 struct mutex commit_mutex;
1735 unsigned int base_seq;
1736 unsigned int gc_seq;
1740 extern unsigned int nf_tables_net_id;
1742 static inline struct nftables_pernet *nft_pernet(const struct net *net)
1744 return net_generic(net, nf_tables_net_id);
1747 #define __NFT_REDUCE_READONLY 1UL
1748 #define NFT_REDUCE_READONLY (void *)__NFT_REDUCE_READONLY
1750 static inline bool nft_reduce_is_readonly(const struct nft_expr *expr)
1752 return expr->ops->reduce == NFT_REDUCE_READONLY;
1755 void nft_reg_track_update(struct nft_regs_track *track,
1756 const struct nft_expr *expr, u8 dreg, u8 len);
1757 void nft_reg_track_cancel(struct nft_regs_track *track, u8 dreg, u8 len);
1758 void __nft_reg_track_cancel(struct nft_regs_track *track, u8 dreg);
1760 static inline bool nft_reg_track_cmp(struct nft_regs_track *track,
1761 const struct nft_expr *expr, u8 dreg)
1763 return track->regs[dreg].selector &&
1764 track->regs[dreg].selector->ops == expr->ops &&
1765 track->regs[dreg].num_reg == 0;
1768 #endif /* _NET_NF_TABLES_H */