1 #ifndef _NET_NF_TABLES_H
2 #define _NET_NF_TABLES_H
4 #include <linux/list.h>
5 #include <linux/netfilter.h>
6 #include <linux/netfilter/nfnetlink.h>
7 #include <linux/netfilter/x_tables.h>
8 #include <linux/netfilter/nf_tables.h>
9 #include <linux/u64_stats_sync.h>
10 #include <net/netlink.h>
12 #define NFT_JUMP_STACK_SIZE 16
16 const struct net_device
*in
;
17 const struct net_device
*out
;
18 const struct nf_hook_ops
*ops
;
22 /* for x_tables compatibility */
23 struct xt_action_param xt
;
26 static inline void nft_set_pktinfo(struct nft_pktinfo
*pkt
,
27 const struct nf_hook_ops
*ops
,
29 const struct nf_hook_state
*state
)
32 pkt
->in
= pkt
->xt
.in
= state
->in
;
33 pkt
->out
= pkt
->xt
.out
= state
->out
;
35 pkt
->xt
.hooknum
= ops
->hooknum
;
36 pkt
->xt
.family
= ops
->pf
;
44 struct nft_chain
*chain
;
47 } __attribute__((aligned(__alignof__(u64
))));
49 static inline int nft_data_cmp(const struct nft_data
*d1
,
50 const struct nft_data
*d2
,
53 return memcmp(d1
->data
, d2
->data
, len
);
56 static inline void nft_data_copy(struct nft_data
*dst
,
57 const struct nft_data
*src
)
59 BUILD_BUG_ON(__alignof__(*dst
) != __alignof__(u64
));
60 *(u64
*)&dst
->data
[0] = *(u64
*)&src
->data
[0];
61 *(u64
*)&dst
->data
[2] = *(u64
*)&src
->data
[2];
64 static inline void nft_data_debug(const struct nft_data
*data
)
66 pr_debug("data[0]=%x data[1]=%x data[2]=%x data[3]=%x\n",
67 data
->data
[0], data
->data
[1],
68 data
->data
[2], data
->data
[3]);
72 * struct nft_ctx - nf_tables rule/set context
75 * @afi: address family info
76 * @table: the table the chain is contained in
77 * @chain: the chain the rule is contained in
78 * @nla: netlink attributes
79 * @portid: netlink portID of the original message
80 * @seq: netlink sequence number
81 * @report: notify via unicast netlink message
85 struct nft_af_info
*afi
;
86 struct nft_table
*table
;
87 struct nft_chain
*chain
;
88 const struct nlattr
* const *nla
;
94 struct nft_data_desc
{
95 enum nft_data_types type
;
99 int nft_data_init(const struct nft_ctx
*ctx
, struct nft_data
*data
,
100 struct nft_data_desc
*desc
, const struct nlattr
*nla
);
101 void nft_data_uninit(const struct nft_data
*data
, enum nft_data_types type
);
102 int nft_data_dump(struct sk_buff
*skb
, int attr
, const struct nft_data
*data
,
103 enum nft_data_types type
, unsigned int len
);
105 static inline enum nft_data_types
nft_dreg_to_type(enum nft_registers reg
)
107 return reg
== NFT_REG_VERDICT
? NFT_DATA_VERDICT
: NFT_DATA_VALUE
;
110 static inline enum nft_registers
nft_type_to_reg(enum nft_data_types type
)
112 return type
== NFT_DATA_VERDICT
? NFT_REG_VERDICT
: NFT_REG_1
;
115 int nft_validate_input_register(enum nft_registers reg
);
116 int nft_validate_output_register(enum nft_registers reg
);
117 int nft_validate_data_load(const struct nft_ctx
*ctx
, enum nft_registers reg
,
118 const struct nft_data
*data
,
119 enum nft_data_types type
, unsigned int len
);
123 * struct nft_userdata - user defined data associated with an object
125 * @len: length of the data
128 * The presence of user data is indicated in an object specific fashion,
129 * so a length of zero can't occur and the value "len" indicates data
132 struct nft_userdata
{
134 unsigned char data
[0];
138 * struct nft_set_elem - generic representation of set elements
141 * @priv: element private data and extensions
143 struct nft_set_elem
{
149 struct nft_set_iter
{
153 int (*fn
)(const struct nft_ctx
*ctx
,
154 const struct nft_set
*set
,
155 const struct nft_set_iter
*iter
,
156 const struct nft_set_elem
*elem
);
160 * struct nft_set_desc - description of set elements
164 * @size: number of set elements
166 struct nft_set_desc
{
173 * enum nft_set_class - performance class
175 * @NFT_LOOKUP_O_1: constant, O(1)
176 * @NFT_LOOKUP_O_LOG_N: logarithmic, O(log N)
177 * @NFT_LOOKUP_O_N: linear, O(N)
181 NFT_SET_CLASS_O_LOG_N
,
186 * struct nft_set_estimate - estimation of memory and performance
189 * @size: required memory
190 * @class: lookup performance class
192 struct nft_set_estimate
{
194 enum nft_set_class
class;
201 * struct nft_set_ops - nf_tables set operations
203 * @lookup: look up an element within the set
204 * @insert: insert new element into set
205 * @activate: activate new element in the next generation
206 * @deactivate: deactivate element in the next generation
207 * @remove: remove element from set
208 * @walk: iterate over all set elemeennts
209 * @privsize: function to return size of set private data
210 * @init: initialize private data of new set instance
211 * @destroy: destroy private data of set instance
212 * @list: nf_tables_set_ops list node
213 * @owner: module reference
214 * @elemsize: element private size
215 * @features: features supported by the implementation
218 bool (*lookup
)(const struct nft_set
*set
,
219 const struct nft_data
*key
,
220 const struct nft_set_ext
**ext
);
221 bool (*update
)(struct nft_set
*set
,
222 const struct nft_data
*key
,
223 void *(*new)(struct nft_set
*,
224 const struct nft_expr
*,
226 const struct nft_expr
*expr
,
227 struct nft_data data
[],
228 const struct nft_set_ext
**ext
);
230 int (*insert
)(const struct nft_set
*set
,
231 const struct nft_set_elem
*elem
);
232 void (*activate
)(const struct nft_set
*set
,
233 const struct nft_set_elem
*elem
);
234 void * (*deactivate
)(const struct nft_set
*set
,
235 const struct nft_set_elem
*elem
);
236 void (*remove
)(const struct nft_set
*set
,
237 const struct nft_set_elem
*elem
);
238 void (*walk
)(const struct nft_ctx
*ctx
,
239 const struct nft_set
*set
,
240 struct nft_set_iter
*iter
);
242 unsigned int (*privsize
)(const struct nlattr
* const nla
[]);
243 bool (*estimate
)(const struct nft_set_desc
*desc
,
245 struct nft_set_estimate
*est
);
246 int (*init
)(const struct nft_set
*set
,
247 const struct nft_set_desc
*desc
,
248 const struct nlattr
* const nla
[]);
249 void (*destroy
)(const struct nft_set
*set
);
251 struct list_head list
;
252 struct module
*owner
;
253 unsigned int elemsize
;
257 int nft_register_set(struct nft_set_ops
*ops
);
258 void nft_unregister_set(struct nft_set_ops
*ops
);
261 * struct nft_set - nf_tables set instance
263 * @list: table set list node
264 * @bindings: list of set bindings
265 * @name: name of the set
266 * @ktype: key type (numeric type defined by userspace, not used in the kernel)
267 * @dtype: data type (verdict or numeric type defined by userspace)
268 * @size: maximum set size
269 * @nelems: number of elements
270 * @ndeact: number of deactivated elements queued for removal
271 * @timeout: default timeout value in msecs
272 * @gc_int: garbage collection interval in msecs
273 * @policy: set parameterization (see enum nft_set_policies)
275 * @pnet: network namespace
279 * @data: private set data
282 struct list_head list
;
283 struct list_head bindings
;
293 /* runtime data below here */
294 const struct nft_set_ops
*ops ____cacheline_aligned
;
300 __attribute__((aligned(__alignof__(u64
))));
303 static inline void *nft_set_priv(const struct nft_set
*set
)
305 return (void *)set
->data
;
308 static inline struct nft_set
*nft_set_container_of(const void *priv
)
310 return (void *)priv
- offsetof(struct nft_set
, data
);
313 struct nft_set
*nf_tables_set_lookup(const struct nft_table
*table
,
314 const struct nlattr
*nla
);
315 struct nft_set
*nf_tables_set_lookup_byid(const struct net
*net
,
316 const struct nlattr
*nla
);
318 static inline unsigned long nft_set_gc_interval(const struct nft_set
*set
)
320 return set
->gc_int
? msecs_to_jiffies(set
->gc_int
) : HZ
;
324 * struct nft_set_binding - nf_tables set binding
326 * @list: set bindings list node
327 * @chain: chain containing the rule bound to the set
328 * @flags: set action flags
330 * A set binding contains all information necessary for validation
331 * of new elements added to a bound set.
333 struct nft_set_binding
{
334 struct list_head list
;
335 const struct nft_chain
*chain
;
339 int nf_tables_bind_set(const struct nft_ctx
*ctx
, struct nft_set
*set
,
340 struct nft_set_binding
*binding
);
341 void nf_tables_unbind_set(const struct nft_ctx
*ctx
, struct nft_set
*set
,
342 struct nft_set_binding
*binding
);
345 * enum nft_set_extensions - set extension type IDs
347 * @NFT_SET_EXT_KEY: element key
348 * @NFT_SET_EXT_DATA: mapping data
349 * @NFT_SET_EXT_FLAGS: element flags
350 * @NFT_SET_EXT_TIMEOUT: element timeout
351 * @NFT_SET_EXT_EXPIRATION: element expiration time
352 * @NFT_SET_EXT_USERDATA: user data associated with the element
353 * @NFT_SET_EXT_NUM: number of extension types
355 enum nft_set_extensions
{
360 NFT_SET_EXT_EXPIRATION
,
361 NFT_SET_EXT_USERDATA
,
366 * struct nft_set_ext_type - set extension type
368 * @len: fixed part length of the extension
369 * @align: alignment requirements of the extension
371 struct nft_set_ext_type
{
376 extern const struct nft_set_ext_type nft_set_ext_types
[];
379 * struct nft_set_ext_tmpl - set extension template
381 * @len: length of extension area
382 * @offset: offsets of individual extension types
384 struct nft_set_ext_tmpl
{
386 u8 offset
[NFT_SET_EXT_NUM
];
390 * struct nft_set_ext - set extensions
392 * @genmask: generation mask
393 * @offset: offsets of individual extension types
394 * @data: beginning of extension data
398 u8 offset
[NFT_SET_EXT_NUM
];
402 static inline void nft_set_ext_prepare(struct nft_set_ext_tmpl
*tmpl
)
404 memset(tmpl
, 0, sizeof(*tmpl
));
405 tmpl
->len
= sizeof(struct nft_set_ext
);
408 static inline void nft_set_ext_add_length(struct nft_set_ext_tmpl
*tmpl
, u8 id
,
411 tmpl
->len
= ALIGN(tmpl
->len
, nft_set_ext_types
[id
].align
);
412 BUG_ON(tmpl
->len
> U8_MAX
);
413 tmpl
->offset
[id
] = tmpl
->len
;
414 tmpl
->len
+= nft_set_ext_types
[id
].len
+ len
;
417 static inline void nft_set_ext_add(struct nft_set_ext_tmpl
*tmpl
, u8 id
)
419 nft_set_ext_add_length(tmpl
, id
, 0);
422 static inline void nft_set_ext_init(struct nft_set_ext
*ext
,
423 const struct nft_set_ext_tmpl
*tmpl
)
425 memcpy(ext
->offset
, tmpl
->offset
, sizeof(ext
->offset
));
428 static inline bool __nft_set_ext_exists(const struct nft_set_ext
*ext
, u8 id
)
430 return !!ext
->offset
[id
];
433 static inline bool nft_set_ext_exists(const struct nft_set_ext
*ext
, u8 id
)
435 return ext
&& __nft_set_ext_exists(ext
, id
);
438 static inline void *nft_set_ext(const struct nft_set_ext
*ext
, u8 id
)
440 return (void *)ext
+ ext
->offset
[id
];
443 static inline struct nft_data
*nft_set_ext_key(const struct nft_set_ext
*ext
)
445 return nft_set_ext(ext
, NFT_SET_EXT_KEY
);
448 static inline struct nft_data
*nft_set_ext_data(const struct nft_set_ext
*ext
)
450 return nft_set_ext(ext
, NFT_SET_EXT_DATA
);
453 static inline u8
*nft_set_ext_flags(const struct nft_set_ext
*ext
)
455 return nft_set_ext(ext
, NFT_SET_EXT_FLAGS
);
458 static inline u64
*nft_set_ext_timeout(const struct nft_set_ext
*ext
)
460 return nft_set_ext(ext
, NFT_SET_EXT_TIMEOUT
);
463 static inline unsigned long *nft_set_ext_expiration(const struct nft_set_ext
*ext
)
465 return nft_set_ext(ext
, NFT_SET_EXT_EXPIRATION
);
468 static inline struct nft_userdata
*nft_set_ext_userdata(const struct nft_set_ext
*ext
)
470 return nft_set_ext(ext
, NFT_SET_EXT_USERDATA
);
473 static inline bool nft_set_elem_expired(const struct nft_set_ext
*ext
)
475 return nft_set_ext_exists(ext
, NFT_SET_EXT_EXPIRATION
) &&
476 time_is_before_eq_jiffies(*nft_set_ext_expiration(ext
));
479 static inline struct nft_set_ext
*nft_set_elem_ext(const struct nft_set
*set
,
482 return elem
+ set
->ops
->elemsize
;
485 void *nft_set_elem_init(const struct nft_set
*set
,
486 const struct nft_set_ext_tmpl
*tmpl
,
487 const struct nft_data
*key
,
488 const struct nft_data
*data
,
489 u64 timeout
, gfp_t gfp
);
490 void nft_set_elem_destroy(const struct nft_set
*set
, void *elem
);
493 * struct nft_set_gc_batch_head - nf_tables set garbage collection batch
496 * @set: set the elements belong to
497 * @cnt: count of elements
499 struct nft_set_gc_batch_head
{
501 const struct nft_set
*set
;
505 #define NFT_SET_GC_BATCH_SIZE ((PAGE_SIZE - \
506 sizeof(struct nft_set_gc_batch_head)) / \
510 * struct nft_set_gc_batch - nf_tables set garbage collection batch
512 * @head: GC batch head
513 * @elems: garbage collection elements
515 struct nft_set_gc_batch
{
516 struct nft_set_gc_batch_head head
;
517 void *elems
[NFT_SET_GC_BATCH_SIZE
];
520 struct nft_set_gc_batch
*nft_set_gc_batch_alloc(const struct nft_set
*set
,
522 void nft_set_gc_batch_release(struct rcu_head
*rcu
);
524 static inline void nft_set_gc_batch_complete(struct nft_set_gc_batch
*gcb
)
527 call_rcu(&gcb
->head
.rcu
, nft_set_gc_batch_release
);
530 static inline struct nft_set_gc_batch
*
531 nft_set_gc_batch_check(const struct nft_set
*set
, struct nft_set_gc_batch
*gcb
,
535 if (gcb
->head
.cnt
+ 1 < ARRAY_SIZE(gcb
->elems
))
537 nft_set_gc_batch_complete(gcb
);
539 return nft_set_gc_batch_alloc(set
, gfp
);
542 static inline void nft_set_gc_batch_add(struct nft_set_gc_batch
*gcb
,
545 gcb
->elems
[gcb
->head
.cnt
++] = elem
;
549 * struct nft_expr_type - nf_tables expression type
551 * @select_ops: function to select nft_expr_ops
552 * @ops: default ops, used when no select_ops functions is present
553 * @list: used internally
555 * @owner: module reference
556 * @policy: netlink attribute policy
557 * @maxattr: highest netlink attribute number
558 * @family: address family for AF-specific types
560 struct nft_expr_type
{
561 const struct nft_expr_ops
*(*select_ops
)(const struct nft_ctx
*,
562 const struct nlattr
* const tb
[]);
563 const struct nft_expr_ops
*ops
;
564 struct list_head list
;
566 struct module
*owner
;
567 const struct nla_policy
*policy
;
568 unsigned int maxattr
;
573 * struct nft_expr_ops - nf_tables expression operations
575 * @eval: Expression evaluation function
576 * @size: full expression size, including private data size
577 * @init: initialization function
578 * @destroy: destruction function
579 * @dump: function to dump parameters
580 * @type: expression type
581 * @validate: validate expression, called during loop detection
582 * @data: extra data to attach to this expression operation
585 struct nft_expr_ops
{
586 void (*eval
)(const struct nft_expr
*expr
,
587 struct nft_data data
[NFT_REG_MAX
+ 1],
588 const struct nft_pktinfo
*pkt
);
591 int (*init
)(const struct nft_ctx
*ctx
,
592 const struct nft_expr
*expr
,
593 const struct nlattr
* const tb
[]);
594 void (*destroy
)(const struct nft_ctx
*ctx
,
595 const struct nft_expr
*expr
);
596 int (*dump
)(struct sk_buff
*skb
,
597 const struct nft_expr
*expr
);
598 int (*validate
)(const struct nft_ctx
*ctx
,
599 const struct nft_expr
*expr
,
600 const struct nft_data
**data
);
601 const struct nft_expr_type
*type
;
605 #define NFT_EXPR_MAXATTR 16
606 #define NFT_EXPR_SIZE(size) (sizeof(struct nft_expr) + \
607 ALIGN(size, __alignof__(struct nft_expr)))
610 * struct nft_expr - nf_tables expression
612 * @ops: expression ops
613 * @data: expression private data
616 const struct nft_expr_ops
*ops
;
617 unsigned char data
[];
620 static inline void *nft_expr_priv(const struct nft_expr
*expr
)
622 return (void *)expr
->data
;
626 * struct nft_rule - nf_tables rule
628 * @list: used internally
629 * @handle: rule handle
630 * @genmask: generation mask
631 * @dlen: length of expression data
632 * @udata: user data is appended to the rule
633 * @data: expression data
636 struct list_head list
;
642 __attribute__((aligned(__alignof__(struct nft_expr
))));
645 static inline struct nft_expr
*nft_expr_first(const struct nft_rule
*rule
)
647 return (struct nft_expr
*)&rule
->data
[0];
650 static inline struct nft_expr
*nft_expr_next(const struct nft_expr
*expr
)
652 return ((void *)expr
) + expr
->ops
->size
;
655 static inline struct nft_expr
*nft_expr_last(const struct nft_rule
*rule
)
657 return (struct nft_expr
*)&rule
->data
[rule
->dlen
];
660 static inline struct nft_userdata
*nft_userdata(const struct nft_rule
*rule
)
662 return (void *)&rule
->data
[rule
->dlen
];
666 * The last pointer isn't really necessary, but the compiler isn't able to
667 * determine that the result of nft_expr_last() is always the same since it
668 * can't assume that the dlen value wasn't changed within calls in the loop.
670 #define nft_rule_for_each_expr(expr, last, rule) \
671 for ((expr) = nft_expr_first(rule), (last) = nft_expr_last(rule); \
673 (expr) = nft_expr_next(expr))
675 enum nft_chain_flags
{
676 NFT_BASE_CHAIN
= 0x1,
677 NFT_CHAIN_INACTIVE
= 0x2,
681 * struct nft_chain - nf_tables chain
683 * @rules: list of rules in the chain
684 * @list: used internally
685 * @table: table that this chain belongs to
686 * @handle: chain handle
687 * @use: number of jump references to this chain
688 * @level: length of longest path to this chain
689 * @flags: bitmask of enum nft_chain_flags
690 * @name: name of the chain
693 struct list_head rules
;
694 struct list_head list
;
695 struct nft_table
*table
;
700 char name
[NFT_CHAIN_MAXNAMELEN
];
703 enum nft_chain_type
{
704 NFT_CHAIN_T_DEFAULT
= 0,
711 * struct nf_chain_type - nf_tables chain type info
713 * @name: name of the type
714 * @type: numeric identifier
715 * @family: address family
716 * @owner: module owner
717 * @hook_mask: mask of valid hooks
718 * @hooks: hookfn overrides
720 struct nf_chain_type
{
722 enum nft_chain_type type
;
724 struct module
*owner
;
725 unsigned int hook_mask
;
726 nf_hookfn
*hooks
[NF_MAX_HOOKS
];
729 int nft_chain_validate_dependency(const struct nft_chain
*chain
,
730 enum nft_chain_type type
);
731 int nft_chain_validate_hooks(const struct nft_chain
*chain
,
732 unsigned int hook_flags
);
737 struct u64_stats_sync syncp
;
740 #define NFT_HOOK_OPS_MAX 2
743 * struct nft_base_chain - nf_tables base chain
745 * @ops: netfilter hook ops
746 * @pnet: net namespace that this chain belongs to
748 * @policy: default policy
749 * @stats: per-cpu chain stats
752 struct nft_base_chain
{
753 struct nf_hook_ops ops
[NFT_HOOK_OPS_MAX
];
755 const struct nf_chain_type
*type
;
757 struct nft_stats __percpu
*stats
;
758 struct nft_chain chain
;
761 static inline struct nft_base_chain
*nft_base_chain(const struct nft_chain
*chain
)
763 return container_of(chain
, struct nft_base_chain
, chain
);
766 unsigned int nft_do_chain(struct nft_pktinfo
*pkt
,
767 const struct nf_hook_ops
*ops
);
770 * struct nft_table - nf_tables table
772 * @list: used internally
773 * @chains: chains in the table
774 * @sets: sets in the table
775 * @hgenerator: handle generator state
776 * @use: number of chain references to this table
777 * @flags: table flag (see enum nft_table_flags)
778 * @name: name of the table
781 struct list_head list
;
782 struct list_head chains
;
783 struct list_head sets
;
787 char name
[NFT_TABLE_MAXNAMELEN
];
791 * struct nft_af_info - nf_tables address family info
793 * @list: used internally
794 * @family: address family
795 * @nhooks: number of hooks in this family
796 * @owner: module owner
797 * @tables: used internally
798 * @nops: number of hook ops in this family
799 * @hook_ops_init: initialization function for chain hook ops
800 * @hooks: hookfn overrides for packet validation
803 struct list_head list
;
806 struct module
*owner
;
807 struct list_head tables
;
809 void (*hook_ops_init
)(struct nf_hook_ops
*,
811 nf_hookfn
*hooks
[NF_MAX_HOOKS
];
814 int nft_register_afinfo(struct net
*, struct nft_af_info
*);
815 void nft_unregister_afinfo(struct nft_af_info
*);
817 int nft_register_chain_type(const struct nf_chain_type
*);
818 void nft_unregister_chain_type(const struct nf_chain_type
*);
820 int nft_register_expr(struct nft_expr_type
*);
821 void nft_unregister_expr(struct nft_expr_type
*);
823 #define nft_dereference(p) \
824 nfnl_dereference(p, NFNL_SUBSYS_NFTABLES)
826 #define MODULE_ALIAS_NFT_FAMILY(family) \
827 MODULE_ALIAS("nft-afinfo-" __stringify(family))
829 #define MODULE_ALIAS_NFT_CHAIN(family, name) \
830 MODULE_ALIAS("nft-chain-" __stringify(family) "-" name)
832 #define MODULE_ALIAS_NFT_AF_EXPR(family, name) \
833 MODULE_ALIAS("nft-expr-" __stringify(family) "-" name)
835 #define MODULE_ALIAS_NFT_EXPR(name) \
836 MODULE_ALIAS("nft-expr-" name)
838 #define MODULE_ALIAS_NFT_SET() \
839 MODULE_ALIAS("nft-set")
842 * The gencursor defines two generations, the currently active and the
843 * next one. Objects contain a bitmask of 2 bits specifying the generations
844 * they're active in. A set bit means they're inactive in the generation
845 * represented by that bit.
847 * New objects start out as inactive in the current and active in the
848 * next generation. When committing the ruleset the bitmask is cleared,
849 * meaning they're active in all generations. When removing an object,
850 * it is set inactive in the next generation. After committing the ruleset,
851 * the objects are removed.
853 static inline unsigned int nft_gencursor_next(const struct net
*net
)
855 return net
->nft
.gencursor
+ 1 == 1 ? 1 : 0;
858 static inline u8
nft_genmask_next(const struct net
*net
)
860 return 1 << nft_gencursor_next(net
);
863 static inline u8
nft_genmask_cur(const struct net
*net
)
865 /* Use ACCESS_ONCE() to prevent refetching the value for atomicity */
866 return 1 << ACCESS_ONCE(net
->nft
.gencursor
);
869 #define NFT_GENMASK_ANY ((1 << 0) | (1 << 1))
872 * Set element transaction helpers
875 static inline bool nft_set_elem_active(const struct nft_set_ext
*ext
,
878 return !(ext
->genmask
& genmask
);
881 static inline void nft_set_elem_change_active(const struct nft_set
*set
,
882 struct nft_set_ext
*ext
)
884 ext
->genmask
^= nft_genmask_next(read_pnet(&set
->pnet
));
888 * We use a free bit in the genmask field to indicate the element
889 * is busy, meaning it is currently being processed either by
890 * the netlink API or GC.
892 * Even though the genmask is only a single byte wide, this works
893 * because the extension structure if fully constant once initialized,
894 * so there are no non-atomic write accesses unless it is already
897 #define NFT_SET_ELEM_BUSY_MASK (1 << 2)
899 #if defined(__LITTLE_ENDIAN_BITFIELD)
900 #define NFT_SET_ELEM_BUSY_BIT 2
901 #elif defined(__BIG_ENDIAN_BITFIELD)
902 #define NFT_SET_ELEM_BUSY_BIT (BITS_PER_LONG - BITS_PER_BYTE + 2)
907 static inline int nft_set_elem_mark_busy(struct nft_set_ext
*ext
)
909 unsigned long *word
= (unsigned long *)ext
;
911 BUILD_BUG_ON(offsetof(struct nft_set_ext
, genmask
) != 0);
912 return test_and_set_bit(NFT_SET_ELEM_BUSY_BIT
, word
);
915 static inline void nft_set_elem_clear_busy(struct nft_set_ext
*ext
)
917 unsigned long *word
= (unsigned long *)ext
;
919 clear_bit(NFT_SET_ELEM_BUSY_BIT
, word
);
923 * struct nft_trans - nf_tables object update in transaction
925 * @list: used internally
926 * @msg_type: message type
927 * @ctx: transaction context
928 * @data: internal information related to the transaction
931 struct list_head list
;
937 struct nft_trans_rule
{
938 struct nft_rule
*rule
;
941 #define nft_trans_rule(trans) \
942 (((struct nft_trans_rule *)trans->data)->rule)
944 struct nft_trans_set
{
949 #define nft_trans_set(trans) \
950 (((struct nft_trans_set *)trans->data)->set)
951 #define nft_trans_set_id(trans) \
952 (((struct nft_trans_set *)trans->data)->set_id)
954 struct nft_trans_chain
{
956 char name
[NFT_CHAIN_MAXNAMELEN
];
957 struct nft_stats __percpu
*stats
;
961 #define nft_trans_chain_update(trans) \
962 (((struct nft_trans_chain *)trans->data)->update)
963 #define nft_trans_chain_name(trans) \
964 (((struct nft_trans_chain *)trans->data)->name)
965 #define nft_trans_chain_stats(trans) \
966 (((struct nft_trans_chain *)trans->data)->stats)
967 #define nft_trans_chain_policy(trans) \
968 (((struct nft_trans_chain *)trans->data)->policy)
970 struct nft_trans_table
{
975 #define nft_trans_table_update(trans) \
976 (((struct nft_trans_table *)trans->data)->update)
977 #define nft_trans_table_enable(trans) \
978 (((struct nft_trans_table *)trans->data)->enable)
980 struct nft_trans_elem
{
982 struct nft_set_elem elem
;
985 #define nft_trans_elem_set(trans) \
986 (((struct nft_trans_elem *)trans->data)->set)
987 #define nft_trans_elem(trans) \
988 (((struct nft_trans_elem *)trans->data)->elem)
990 #endif /* _NET_NF_TABLES_H */