1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NET_NF_TABLES_CORE_H
3 #define _NET_NF_TABLES_CORE_H
4
5 #include <net/netfilter/nf_tables.h>
6
7 extern struct nft_expr_type nft_imm_type;
8 extern struct nft_expr_type nft_cmp_type;
9 extern struct nft_expr_type nft_lookup_type;
10 extern struct nft_expr_type nft_bitwise_type;
11 extern struct nft_expr_type nft_byteorder_type;
12 extern struct nft_expr_type nft_payload_type;
13 extern struct nft_expr_type nft_dynset_type;
14 extern struct nft_expr_type nft_range_type;
15 extern struct nft_expr_type nft_meta_type;
16 extern struct nft_expr_type nft_rt_type;
17 extern struct nft_expr_type nft_exthdr_type;
18
19 #ifdef CONFIG_NETWORK_SECMARK
20 extern struct nft_object_type nft_secmark_obj_type;
21 #endif
22
23 int nf_tables_core_module_init(void);
24 void nf_tables_core_module_exit(void);
25
26 struct nft_bitwise_fast_expr {
27 u32 mask;
28 u32 xor;
29 enum nft_registers sreg:8;
30 enum nft_registers dreg:8;
31 };
32
33 struct nft_cmp_fast_expr {
34 u32 data;
35 u32 mask;
36 enum nft_registers sreg:8;
37 u8 len;
38 bool inv;
39 };
40
41 struct nft_immediate_expr {
42 struct nft_data data;
43 enum nft_registers dreg:8;
44 u8 dlen;
45 };
46
47 /* Calculate the mask for the nft_cmp_fast expression. On big endian the
48 * mask needs to include the *upper* bytes when interpreting that data as
49 * something smaller than the full u32, therefore a cpu_to_le32 is done.
50 */
nft_cmp_fast_mask(unsigned int len)51 static inline u32 nft_cmp_fast_mask(unsigned int len)
52 {
53 return cpu_to_le32(~0U >> (sizeof_field(struct nft_cmp_fast_expr,
54 data) * BITS_PER_BYTE - len));
55 }
56
57 extern const struct nft_expr_ops nft_cmp_fast_ops;
58
59 struct nft_payload {
60 enum nft_payload_bases base:8;
61 u8 offset;
62 u8 len;
63 enum nft_registers dreg:8;
64 };
65
66 struct nft_payload_set {
67 enum nft_payload_bases base:8;
68 u8 offset;
69 u8 len;
70 enum nft_registers sreg:8;
71 u8 csum_type;
72 u8 csum_offset;
73 u8 csum_flags;
74 };
75
76 extern const struct nft_expr_ops nft_payload_fast_ops;
77
78 extern const struct nft_expr_ops nft_bitwise_fast_ops;
79
80 extern struct static_key_false nft_counters_enabled;
81 extern struct static_key_false nft_trace_enabled;
82
83 extern const struct nft_set_type nft_set_rhash_type;
84 extern const struct nft_set_type nft_set_hash_type;
85 extern const struct nft_set_type nft_set_hash_fast_type;
86 extern const struct nft_set_type nft_set_rbtree_type;
87 extern const struct nft_set_type nft_set_bitmap_type;
88 extern const struct nft_set_type nft_set_pipapo_type;
89 extern const struct nft_set_type nft_set_pipapo_avx2_type;
90
91 struct nft_expr;
92 struct nft_regs;
93 struct nft_pktinfo;
94 void nft_meta_get_eval(const struct nft_expr *expr,
95 struct nft_regs *regs, const struct nft_pktinfo *pkt);
96 void nft_cmp_eval(const struct nft_expr *expr,
97 struct nft_regs *regs, const struct nft_pktinfo *pkt);
98 void nft_lookup_eval(const struct nft_expr *expr,
99 struct nft_regs *regs, const struct nft_pktinfo *pkt);
100 void nft_payload_eval(const struct nft_expr *expr,
101 struct nft_regs *regs, const struct nft_pktinfo *pkt);
102 void nft_immediate_eval(const struct nft_expr *expr,
103 struct nft_regs *regs, const struct nft_pktinfo *pkt);
104 void nft_bitwise_eval(const struct nft_expr *expr,
105 struct nft_regs *regs, const struct nft_pktinfo *pkt);
106 void nft_range_eval(const struct nft_expr *expr,
107 struct nft_regs *regs, const struct nft_pktinfo *pkt);
108 void nft_byteorder_eval(const struct nft_expr *expr,
109 struct nft_regs *regs, const struct nft_pktinfo *pkt);
110 void nft_dynset_eval(const struct nft_expr *expr,
111 struct nft_regs *regs, const struct nft_pktinfo *pkt);
112 void nft_rt_get_eval(const struct nft_expr *expr,
113 struct nft_regs *regs, const struct nft_pktinfo *pkt);
114 #endif /* _NET_NF_TABLES_CORE_H */
115