1#ifndef _NET_NF_TABLES_H
2#define _NET_NF_TABLES_H
3
4#include <linux/module.h>
5#include <linux/list.h>
6#include <linux/netfilter.h>
7#include <linux/netfilter/nfnetlink.h>
8#include <linux/netfilter/x_tables.h>
9#include <linux/netfilter/nf_tables.h>
10#include <linux/u64_stats_sync.h>
11#include <net/netlink.h>
12
13#define NFT_JUMP_STACK_SIZE 16
14
15struct nft_pktinfo {
16 struct sk_buff *skb;
17 struct net *net;
18 const struct net_device *in;
19 const struct net_device *out;
20 u8 pf;
21 u8 hook;
22 u8 tprot;
23
24 struct xt_action_param xt;
25};
26
27static inline void nft_set_pktinfo(struct nft_pktinfo *pkt,
28 struct sk_buff *skb,
29 const struct nf_hook_state *state)
30{
31 pkt->skb = skb;
32 pkt->net = pkt->xt.net = state->net;
33 pkt->in = pkt->xt.in = state->in;
34 pkt->out = pkt->xt.out = state->out;
35 pkt->hook = pkt->xt.hooknum = state->hook;
36 pkt->pf = pkt->xt.family = state->pf;
37}
38
39
40
41
42
43
44
45struct nft_verdict {
46 u32 code;
47 struct nft_chain *chain;
48};
49
50struct nft_data {
51 union {
52 u32 data[4];
53 struct nft_verdict verdict;
54 };
55} __attribute__((aligned(__alignof__(u64))));
56
57
58
59
60
61
62
63
64
65struct nft_regs {
66 union {
67 u32 data[20];
68 struct nft_verdict verdict;
69 };
70};
71
72static inline void nft_data_copy(u32 *dst, const struct nft_data *src,
73 unsigned int len)
74{
75 memcpy(dst, src, len);
76}
77
78static inline void nft_data_debug(const struct nft_data *data)
79{
80 pr_debug("data[0]=%x data[1]=%x data[2]=%x data[3]=%x\n",
81 data->data[0], data->data[1],
82 data->data[2], data->data[3]);
83}
84
85
86
87
88
89
90
91
92
93
94
95
96
97struct nft_ctx {
98 struct net *net;
99 struct nft_af_info *afi;
100 struct nft_table *table;
101 struct nft_chain *chain;
102 const struct nlattr * const *nla;
103 u32 portid;
104 u32 seq;
105 bool report;
106};
107
108struct nft_data_desc {
109 enum nft_data_types type;
110 unsigned int len;
111};
112
113int nft_data_init(const struct nft_ctx *ctx,
114 struct nft_data *data, unsigned int size,
115 struct nft_data_desc *desc, const struct nlattr *nla);
116void nft_data_uninit(const struct nft_data *data, enum nft_data_types type);
117int nft_data_dump(struct sk_buff *skb, int attr, const struct nft_data *data,
118 enum nft_data_types type, unsigned int len);
119
120static inline enum nft_data_types nft_dreg_to_type(enum nft_registers reg)
121{
122 return reg == NFT_REG_VERDICT ? NFT_DATA_VERDICT : NFT_DATA_VALUE;
123}
124
125static inline enum nft_registers nft_type_to_reg(enum nft_data_types type)
126{
127 return type == NFT_DATA_VERDICT ? NFT_REG_VERDICT : NFT_REG_1 * NFT_REG_SIZE / NFT_REG32_SIZE;
128}
129
130unsigned int nft_parse_register(const struct nlattr *attr);
131int nft_dump_register(struct sk_buff *skb, unsigned int attr, unsigned int reg);
132
133int nft_validate_register_load(enum nft_registers reg, unsigned int len);
134int nft_validate_register_store(const struct nft_ctx *ctx,
135 enum nft_registers reg,
136 const struct nft_data *data,
137 enum nft_data_types type, unsigned int len);
138
139
140
141
142
143
144
145
146
147
148
149struct nft_userdata {
150 u8 len;
151 unsigned char data[0];
152};
153
154
155
156
157
158
159
160struct nft_set_elem {
161 union {
162 u32 buf[NFT_DATA_VALUE_MAXLEN / sizeof(u32)];
163 struct nft_data val;
164 } key;
165 void *priv;
166};
167
168struct nft_set;
169struct nft_set_iter {
170 u8 genmask;
171 unsigned int count;
172 unsigned int skip;
173 int err;
174 int (*fn)(const struct nft_ctx *ctx,
175 const struct nft_set *set,
176 const struct nft_set_iter *iter,
177 const struct nft_set_elem *elem);
178};
179
180
181
182
183
184
185
186
187struct nft_set_desc {
188 unsigned int klen;
189 unsigned int dlen;
190 unsigned int size;
191};
192
193
194
195
196
197
198
199
200enum nft_set_class {
201 NFT_SET_CLASS_O_1,
202 NFT_SET_CLASS_O_LOG_N,
203 NFT_SET_CLASS_O_N,
204};
205
206
207
208
209
210
211
212
213struct nft_set_estimate {
214 unsigned int size;
215 enum nft_set_class class;
216};
217
218struct nft_set_ext;
219struct nft_expr;
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238struct nft_set_ops {
239 bool (*lookup)(const struct net *net,
240 const struct nft_set *set,
241 const u32 *key,
242 const struct nft_set_ext **ext);
243 bool (*update)(struct nft_set *set,
244 const u32 *key,
245 void *(*new)(struct nft_set *,
246 const struct nft_expr *,
247 struct nft_regs *),
248 const struct nft_expr *expr,
249 struct nft_regs *regs,
250 const struct nft_set_ext **ext);
251
252 int (*insert)(const struct net *net,
253 const struct nft_set *set,
254 const struct nft_set_elem *elem);
255 void (*activate)(const struct net *net,
256 const struct nft_set *set,
257 const struct nft_set_elem *elem);
258 void * (*deactivate)(const struct net *net,
259 const struct nft_set *set,
260 const struct nft_set_elem *elem);
261 void (*remove)(const struct nft_set *set,
262 const struct nft_set_elem *elem);
263 void (*walk)(const struct nft_ctx *ctx,
264 const struct nft_set *set,
265 struct nft_set_iter *iter);
266
267 unsigned int (*privsize)(const struct nlattr * const nla[]);
268 bool (*estimate)(const struct nft_set_desc *desc,
269 u32 features,
270 struct nft_set_estimate *est);
271 int (*init)(const struct nft_set *set,
272 const struct nft_set_desc *desc,
273 const struct nlattr * const nla[]);
274 void (*destroy)(const struct nft_set *set);
275
276 struct list_head list;
277 struct module *owner;
278 unsigned int elemsize;
279 u32 features;
280};
281
282int nft_register_set(struct nft_set_ops *ops);
283void nft_unregister_set(struct nft_set_ops *ops);
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308struct nft_set {
309 struct list_head list;
310 struct list_head bindings;
311 char name[NFT_SET_MAXNAMELEN];
312 u32 ktype;
313 u32 dtype;
314 u32 size;
315 atomic_t nelems;
316 u32 ndeact;
317 u64 timeout;
318 u32 gc_int;
319 u16 policy;
320 u16 udlen;
321 unsigned char *udata;
322
323 const struct nft_set_ops *ops ____cacheline_aligned;
324 u16 flags:14,
325 genmask:2;
326 u8 klen;
327 u8 dlen;
328 unsigned char data[]
329 __attribute__((aligned(__alignof__(u64))));
330};
331
332static inline void *nft_set_priv(const struct nft_set *set)
333{
334 return (void *)set->data;
335}
336
337static inline struct nft_set *nft_set_container_of(const void *priv)
338{
339 return (void *)priv - offsetof(struct nft_set, data);
340}
341
342struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
343 const struct nlattr *nla, u8 genmask);
344struct nft_set *nf_tables_set_lookup_byid(const struct net *net,
345 const struct nlattr *nla, u8 genmask);
346
347static inline unsigned long nft_set_gc_interval(const struct nft_set *set)
348{
349 return set->gc_int ? msecs_to_jiffies(set->gc_int) : HZ;
350}
351
352
353
354
355
356
357
358
359
360
361
362struct nft_set_binding {
363 struct list_head list;
364 const struct nft_chain *chain;
365 u32 flags;
366};
367
368int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,
369 struct nft_set_binding *binding);
370void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set,
371 struct nft_set_binding *binding);
372
373
374
375
376
377
378
379
380
381
382
383
384
385enum nft_set_extensions {
386 NFT_SET_EXT_KEY,
387 NFT_SET_EXT_DATA,
388 NFT_SET_EXT_FLAGS,
389 NFT_SET_EXT_TIMEOUT,
390 NFT_SET_EXT_EXPIRATION,
391 NFT_SET_EXT_USERDATA,
392 NFT_SET_EXT_EXPR,
393 NFT_SET_EXT_NUM
394};
395
396
397
398
399
400
401
402struct nft_set_ext_type {
403 u8 len;
404 u8 align;
405};
406
407extern const struct nft_set_ext_type nft_set_ext_types[];
408
409
410
411
412
413
414
415struct nft_set_ext_tmpl {
416 u16 len;
417 u8 offset[NFT_SET_EXT_NUM];
418};
419
420
421
422
423
424
425
426
427struct nft_set_ext {
428 u8 genmask;
429 u8 offset[NFT_SET_EXT_NUM];
430 char data[0];
431};
432
433static inline void nft_set_ext_prepare(struct nft_set_ext_tmpl *tmpl)
434{
435 memset(tmpl, 0, sizeof(*tmpl));
436 tmpl->len = sizeof(struct nft_set_ext);
437}
438
439static inline void nft_set_ext_add_length(struct nft_set_ext_tmpl *tmpl, u8 id,
440 unsigned int len)
441{
442 tmpl->len = ALIGN(tmpl->len, nft_set_ext_types[id].align);
443 BUG_ON(tmpl->len > U8_MAX);
444 tmpl->offset[id] = tmpl->len;
445 tmpl->len += nft_set_ext_types[id].len + len;
446}
447
448static inline void nft_set_ext_add(struct nft_set_ext_tmpl *tmpl, u8 id)
449{
450 nft_set_ext_add_length(tmpl, id, 0);
451}
452
453static inline void nft_set_ext_init(struct nft_set_ext *ext,
454 const struct nft_set_ext_tmpl *tmpl)
455{
456 memcpy(ext->offset, tmpl->offset, sizeof(ext->offset));
457}
458
459static inline bool __nft_set_ext_exists(const struct nft_set_ext *ext, u8 id)
460{
461 return !!ext->offset[id];
462}
463
464static inline bool nft_set_ext_exists(const struct nft_set_ext *ext, u8 id)
465{
466 return ext && __nft_set_ext_exists(ext, id);
467}
468
469static inline void *nft_set_ext(const struct nft_set_ext *ext, u8 id)
470{
471 return (void *)ext + ext->offset[id];
472}
473
474static inline struct nft_data *nft_set_ext_key(const struct nft_set_ext *ext)
475{
476 return nft_set_ext(ext, NFT_SET_EXT_KEY);
477}
478
479static inline struct nft_data *nft_set_ext_data(const struct nft_set_ext *ext)
480{
481 return nft_set_ext(ext, NFT_SET_EXT_DATA);
482}
483
484static inline u8 *nft_set_ext_flags(const struct nft_set_ext *ext)
485{
486 return nft_set_ext(ext, NFT_SET_EXT_FLAGS);
487}
488
489static inline u64 *nft_set_ext_timeout(const struct nft_set_ext *ext)
490{
491 return nft_set_ext(ext, NFT_SET_EXT_TIMEOUT);
492}
493
494static inline unsigned long *nft_set_ext_expiration(const struct nft_set_ext *ext)
495{
496 return nft_set_ext(ext, NFT_SET_EXT_EXPIRATION);
497}
498
499static inline struct nft_userdata *nft_set_ext_userdata(const struct nft_set_ext *ext)
500{
501 return nft_set_ext(ext, NFT_SET_EXT_USERDATA);
502}
503
504static inline struct nft_expr *nft_set_ext_expr(const struct nft_set_ext *ext)
505{
506 return nft_set_ext(ext, NFT_SET_EXT_EXPR);
507}
508
509static inline bool nft_set_elem_expired(const struct nft_set_ext *ext)
510{
511 return nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION) &&
512 time_is_before_eq_jiffies(*nft_set_ext_expiration(ext));
513}
514
515static inline struct nft_set_ext *nft_set_elem_ext(const struct nft_set *set,
516 void *elem)
517{
518 return elem + set->ops->elemsize;
519}
520
521void *nft_set_elem_init(const struct nft_set *set,
522 const struct nft_set_ext_tmpl *tmpl,
523 const u32 *key, const u32 *data,
524 u64 timeout, gfp_t gfp);
525void nft_set_elem_destroy(const struct nft_set *set, void *elem);
526
527
528
529
530
531
532
533
534struct nft_set_gc_batch_head {
535 struct rcu_head rcu;
536 const struct nft_set *set;
537 unsigned int cnt;
538};
539
540#define NFT_SET_GC_BATCH_SIZE ((PAGE_SIZE - \
541 sizeof(struct nft_set_gc_batch_head)) / \
542 sizeof(void *))
543
544
545
546
547
548
549
550struct nft_set_gc_batch {
551 struct nft_set_gc_batch_head head;
552 void *elems[NFT_SET_GC_BATCH_SIZE];
553};
554
555struct nft_set_gc_batch *nft_set_gc_batch_alloc(const struct nft_set *set,
556 gfp_t gfp);
557void nft_set_gc_batch_release(struct rcu_head *rcu);
558
559static inline void nft_set_gc_batch_complete(struct nft_set_gc_batch *gcb)
560{
561 if (gcb != NULL)
562 call_rcu(&gcb->head.rcu, nft_set_gc_batch_release);
563}
564
565static inline struct nft_set_gc_batch *
566nft_set_gc_batch_check(const struct nft_set *set, struct nft_set_gc_batch *gcb,
567 gfp_t gfp)
568{
569 if (gcb != NULL) {
570 if (gcb->head.cnt + 1 < ARRAY_SIZE(gcb->elems))
571 return gcb;
572 nft_set_gc_batch_complete(gcb);
573 }
574 return nft_set_gc_batch_alloc(set, gfp);
575}
576
577static inline void nft_set_gc_batch_add(struct nft_set_gc_batch *gcb,
578 void *elem)
579{
580 gcb->elems[gcb->head.cnt++] = elem;
581}
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596struct nft_expr_type {
597 const struct nft_expr_ops *(*select_ops)(const struct nft_ctx *,
598 const struct nlattr * const tb[]);
599 const struct nft_expr_ops *ops;
600 struct list_head list;
601 const char *name;
602 struct module *owner;
603 const struct nla_policy *policy;
604 unsigned int maxattr;
605 u8 family;
606 u8 flags;
607};
608
609#define NFT_EXPR_STATEFUL 0x1
610
611
612
613
614
615
616
617
618
619
620
621
622
623struct nft_expr;
624struct nft_expr_ops {
625 void (*eval)(const struct nft_expr *expr,
626 struct nft_regs *regs,
627 const struct nft_pktinfo *pkt);
628 int (*clone)(struct nft_expr *dst,
629 const struct nft_expr *src);
630 unsigned int size;
631
632 int (*init)(const struct nft_ctx *ctx,
633 const struct nft_expr *expr,
634 const struct nlattr * const tb[]);
635 void (*destroy)(const struct nft_ctx *ctx,
636 const struct nft_expr *expr);
637 int (*dump)(struct sk_buff *skb,
638 const struct nft_expr *expr);
639 int (*validate)(const struct nft_ctx *ctx,
640 const struct nft_expr *expr,
641 const struct nft_data **data);
642 const struct nft_expr_type *type;
643 void *data;
644};
645
646#define NFT_EXPR_MAXATTR 16
647#define NFT_EXPR_SIZE(size) (sizeof(struct nft_expr) + \
648 ALIGN(size, __alignof__(struct nft_expr)))
649
650
651
652
653
654
655
656struct nft_expr {
657 const struct nft_expr_ops *ops;
658 unsigned char data[];
659};
660
661static inline void *nft_expr_priv(const struct nft_expr *expr)
662{
663 return (void *)expr->data;
664}
665
666struct nft_expr *nft_expr_init(const struct nft_ctx *ctx,
667 const struct nlattr *nla);
668void nft_expr_destroy(const struct nft_ctx *ctx, struct nft_expr *expr);
669int nft_expr_dump(struct sk_buff *skb, unsigned int attr,
670 const struct nft_expr *expr);
671
672static inline int nft_expr_clone(struct nft_expr *dst, struct nft_expr *src)
673{
674 int err;
675
676 __module_get(src->ops->type->owner);
677 if (src->ops->clone) {
678 dst->ops = src->ops;
679 err = src->ops->clone(dst, src);
680 if (err < 0)
681 return err;
682 } else {
683 memcpy(dst, src, src->ops->size);
684 }
685 return 0;
686}
687
688
689
690
691
692
693
694
695
696
697
698struct nft_rule {
699 struct list_head list;
700 u64 handle:42,
701 genmask:2,
702 dlen:12,
703 udata:1;
704 unsigned char data[]
705 __attribute__((aligned(__alignof__(struct nft_expr))));
706};
707
708static inline struct nft_expr *nft_expr_first(const struct nft_rule *rule)
709{
710 return (struct nft_expr *)&rule->data[0];
711}
712
713static inline struct nft_expr *nft_expr_next(const struct nft_expr *expr)
714{
715 return ((void *)expr) + expr->ops->size;
716}
717
718static inline struct nft_expr *nft_expr_last(const struct nft_rule *rule)
719{
720 return (struct nft_expr *)&rule->data[rule->dlen];
721}
722
723static inline struct nft_userdata *nft_userdata(const struct nft_rule *rule)
724{
725 return (void *)&rule->data[rule->dlen];
726}
727
728
729
730
731
732
733#define nft_rule_for_each_expr(expr, last, rule) \
734 for ((expr) = nft_expr_first(rule), (last) = nft_expr_last(rule); \
735 (expr) != (last); \
736 (expr) = nft_expr_next(expr))
737
738enum nft_chain_flags {
739 NFT_BASE_CHAIN = 0x1,
740};
741
742
743
744
745
746
747
748
749
750
751
752
753
754struct nft_chain {
755 struct list_head rules;
756 struct list_head list;
757 struct nft_table *table;
758 u64 handle;
759 u32 use;
760 u16 level;
761 u8 flags:6,
762 genmask:2;
763 char name[NFT_CHAIN_MAXNAMELEN];
764};
765
766enum nft_chain_type {
767 NFT_CHAIN_T_DEFAULT = 0,
768 NFT_CHAIN_T_ROUTE,
769 NFT_CHAIN_T_NAT,
770 NFT_CHAIN_T_MAX
771};
772
773
774
775
776
777
778
779
780
781
782
783struct nf_chain_type {
784 const char *name;
785 enum nft_chain_type type;
786 int family;
787 struct module *owner;
788 unsigned int hook_mask;
789 nf_hookfn *hooks[NF_MAX_HOOKS];
790};
791
792int nft_chain_validate_dependency(const struct nft_chain *chain,
793 enum nft_chain_type type);
794int nft_chain_validate_hooks(const struct nft_chain *chain,
795 unsigned int hook_flags);
796
797struct nft_stats {
798 u64 bytes;
799 u64 pkts;
800 struct u64_stats_sync syncp;
801};
802
803#define NFT_HOOK_OPS_MAX 2
804
805
806
807
808
809
810
811
812
813
814
815struct nft_base_chain {
816 struct nf_hook_ops ops[NFT_HOOK_OPS_MAX];
817 const struct nf_chain_type *type;
818 u8 policy;
819 u8 flags;
820 struct nft_stats __percpu *stats;
821 struct nft_chain chain;
822 char dev_name[IFNAMSIZ];
823};
824
825static inline struct nft_base_chain *nft_base_chain(const struct nft_chain *chain)
826{
827 return container_of(chain, struct nft_base_chain, chain);
828}
829
830int __nft_release_basechain(struct nft_ctx *ctx);
831
832unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);
833
834
835
836
837
838
839
840
841
842
843
844
845
846struct nft_table {
847 struct list_head list;
848 struct list_head chains;
849 struct list_head sets;
850 u64 hgenerator;
851 u32 use;
852 u16 flags:14,
853 genmask:2;
854 char name[NFT_TABLE_MAXNAMELEN];
855};
856
857enum nft_af_flags {
858 NFT_AF_NEEDS_DEV = (1 << 0),
859};
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874struct nft_af_info {
875 struct list_head list;
876 int family;
877 unsigned int nhooks;
878 struct module *owner;
879 struct list_head tables;
880 u32 flags;
881 unsigned int nops;
882 void (*hook_ops_init)(struct nf_hook_ops *,
883 unsigned int);
884 nf_hookfn *hooks[NF_MAX_HOOKS];
885};
886
887int nft_register_afinfo(struct net *, struct nft_af_info *);
888void nft_unregister_afinfo(struct net *, struct nft_af_info *);
889
890int nft_register_chain_type(const struct nf_chain_type *);
891void nft_unregister_chain_type(const struct nf_chain_type *);
892
893int nft_register_expr(struct nft_expr_type *);
894void nft_unregister_expr(struct nft_expr_type *);
895
896int nft_verdict_dump(struct sk_buff *skb, int type,
897 const struct nft_verdict *v);
898
899
900
901
902
903
904
905
906
907
908
909
910
911struct nft_traceinfo {
912 const struct nft_pktinfo *pkt;
913 const struct nft_base_chain *basechain;
914 const struct nft_chain *chain;
915 const struct nft_rule *rule;
916 const struct nft_verdict *verdict;
917 enum nft_trace_types type;
918 bool packet_dumped;
919 bool trace;
920};
921
922void nft_trace_init(struct nft_traceinfo *info, const struct nft_pktinfo *pkt,
923 const struct nft_verdict *verdict,
924 const struct nft_chain *basechain);
925
926void nft_trace_notify(struct nft_traceinfo *info);
927
928#define nft_dereference(p) \
929 nfnl_dereference(p, NFNL_SUBSYS_NFTABLES)
930
931#define MODULE_ALIAS_NFT_FAMILY(family) \
932 MODULE_ALIAS("nft-afinfo-" __stringify(family))
933
934#define MODULE_ALIAS_NFT_CHAIN(family, name) \
935 MODULE_ALIAS("nft-chain-" __stringify(family) "-" name)
936
937#define MODULE_ALIAS_NFT_AF_EXPR(family, name) \
938 MODULE_ALIAS("nft-expr-" __stringify(family) "-" name)
939
940#define MODULE_ALIAS_NFT_EXPR(name) \
941 MODULE_ALIAS("nft-expr-" name)
942
943#define MODULE_ALIAS_NFT_SET() \
944 MODULE_ALIAS("nft-set")
945
946
947
948
949
950
951
952
953
954
955
956
957
958static inline unsigned int nft_gencursor_next(const struct net *net)
959{
960 return net->nft.gencursor + 1 == 1 ? 1 : 0;
961}
962
963static inline u8 nft_genmask_next(const struct net *net)
964{
965 return 1 << nft_gencursor_next(net);
966}
967
968static inline u8 nft_genmask_cur(const struct net *net)
969{
970
971 return 1 << ACCESS_ONCE(net->nft.gencursor);
972}
973
974#define NFT_GENMASK_ANY ((1 << 0) | (1 << 1))
975
976
977
978
979
980
981#define nft_is_active(__net, __obj) \
982 (((__obj)->genmask & nft_genmask_cur(__net)) == 0)
983
984
985#define nft_is_active_next(__net, __obj) \
986 (((__obj)->genmask & nft_genmask_next(__net)) == 0)
987
988
989#define nft_activate_next(__net, __obj) \
990 (__obj)->genmask = nft_genmask_cur(__net)
991
992
993#define nft_deactivate_next(__net, __obj) \
994 (__obj)->genmask = nft_genmask_next(__net)
995
996
997#define nft_clear(__net, __obj) \
998 (__obj)->genmask &= ~nft_genmask_next(__net)
999#define nft_active_genmask(__obj, __genmask) \
1000 !((__obj)->genmask & __genmask)
1001
1002
1003
1004
1005
1006static inline bool nft_set_elem_active(const struct nft_set_ext *ext,
1007 u8 genmask)
1008{
1009 return !(ext->genmask & genmask);
1010}
1011
1012static inline void nft_set_elem_change_active(const struct net *net,
1013 const struct nft_set *set,
1014 struct nft_set_ext *ext)
1015{
1016 ext->genmask ^= nft_genmask_next(net);
1017}
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029#define NFT_SET_ELEM_BUSY_MASK (1 << 2)
1030
1031#if defined(__LITTLE_ENDIAN_BITFIELD)
1032#define NFT_SET_ELEM_BUSY_BIT 2
1033#elif defined(__BIG_ENDIAN_BITFIELD)
1034#define NFT_SET_ELEM_BUSY_BIT (BITS_PER_LONG - BITS_PER_BYTE + 2)
1035#else
1036#error
1037#endif
1038
1039static inline int nft_set_elem_mark_busy(struct nft_set_ext *ext)
1040{
1041 unsigned long *word = (unsigned long *)ext;
1042
1043 BUILD_BUG_ON(offsetof(struct nft_set_ext, genmask) != 0);
1044 return test_and_set_bit(NFT_SET_ELEM_BUSY_BIT, word);
1045}
1046
1047static inline void nft_set_elem_clear_busy(struct nft_set_ext *ext)
1048{
1049 unsigned long *word = (unsigned long *)ext;
1050
1051 clear_bit(NFT_SET_ELEM_BUSY_BIT, word);
1052}
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062struct nft_trans {
1063 struct list_head list;
1064 int msg_type;
1065 struct nft_ctx ctx;
1066 char data[0];
1067};
1068
1069struct nft_trans_rule {
1070 struct nft_rule *rule;
1071};
1072
1073#define nft_trans_rule(trans) \
1074 (((struct nft_trans_rule *)trans->data)->rule)
1075
1076struct nft_trans_set {
1077 struct nft_set *set;
1078 u32 set_id;
1079};
1080
1081#define nft_trans_set(trans) \
1082 (((struct nft_trans_set *)trans->data)->set)
1083#define nft_trans_set_id(trans) \
1084 (((struct nft_trans_set *)trans->data)->set_id)
1085
1086struct nft_trans_chain {
1087 bool update;
1088 char name[NFT_CHAIN_MAXNAMELEN];
1089 struct nft_stats __percpu *stats;
1090 u8 policy;
1091};
1092
1093#define nft_trans_chain_update(trans) \
1094 (((struct nft_trans_chain *)trans->data)->update)
1095#define nft_trans_chain_name(trans) \
1096 (((struct nft_trans_chain *)trans->data)->name)
1097#define nft_trans_chain_stats(trans) \
1098 (((struct nft_trans_chain *)trans->data)->stats)
1099#define nft_trans_chain_policy(trans) \
1100 (((struct nft_trans_chain *)trans->data)->policy)
1101
1102struct nft_trans_table {
1103 bool update;
1104 bool enable;
1105};
1106
1107#define nft_trans_table_update(trans) \
1108 (((struct nft_trans_table *)trans->data)->update)
1109#define nft_trans_table_enable(trans) \
1110 (((struct nft_trans_table *)trans->data)->enable)
1111
1112struct nft_trans_elem {
1113 struct nft_set *set;
1114 struct nft_set_elem elem;
1115};
1116
1117#define nft_trans_elem_set(trans) \
1118 (((struct nft_trans_elem *)trans->data)->set)
1119#define nft_trans_elem(trans) \
1120 (((struct nft_trans_elem *)trans->data)->elem)
1121
1122#endif
1123