GNU Linux-libre 6.0.15-gnu
[releases.git] / include / net / netfilter / nf_tables_core.h
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 #include <linux/indirect_call_wrapper.h>
7
8 extern struct nft_expr_type nft_imm_type;
9 extern struct nft_expr_type nft_cmp_type;
10 extern struct nft_expr_type nft_counter_type;
11 extern struct nft_expr_type nft_lookup_type;
12 extern struct nft_expr_type nft_bitwise_type;
13 extern struct nft_expr_type nft_byteorder_type;
14 extern struct nft_expr_type nft_payload_type;
15 extern struct nft_expr_type nft_dynset_type;
16 extern struct nft_expr_type nft_range_type;
17 extern struct nft_expr_type nft_meta_type;
18 extern struct nft_expr_type nft_rt_type;
19 extern struct nft_expr_type nft_exthdr_type;
20 extern struct nft_expr_type nft_last_type;
21
22 #ifdef CONFIG_NETWORK_SECMARK
23 extern struct nft_object_type nft_secmark_obj_type;
24 #endif
25 extern struct nft_object_type nft_counter_obj_type;
26
27 int nf_tables_core_module_init(void);
28 void nf_tables_core_module_exit(void);
29
30 struct nft_bitwise_fast_expr {
31         u32                     mask;
32         u32                     xor;
33         u8                      sreg;
34         u8                      dreg;
35 };
36
37 struct nft_cmp_fast_expr {
38         u32                     data;
39         u32                     mask;
40         u8                      sreg;
41         u8                      len;
42         bool                    inv;
43 };
44
45 struct nft_cmp16_fast_expr {
46         struct nft_data         data;
47         struct nft_data         mask;
48         u8                      sreg;
49         u8                      len;
50         bool                    inv;
51 };
52
53 struct nft_immediate_expr {
54         struct nft_data         data;
55         u8                      dreg;
56         u8                      dlen;
57 };
58
59 extern const struct nft_expr_ops nft_cmp_fast_ops;
60 extern const struct nft_expr_ops nft_cmp16_fast_ops;
61
62 struct nft_payload {
63         enum nft_payload_bases  base:8;
64         u8                      offset;
65         u8                      len;
66         u8                      dreg;
67 };
68
69 struct nft_payload_set {
70         enum nft_payload_bases  base:8;
71         u8                      offset;
72         u8                      len;
73         u8                      sreg;
74         u8                      csum_type;
75         u8                      csum_offset;
76         u8                      csum_flags;
77 };
78
79 extern const struct nft_expr_ops nft_payload_fast_ops;
80
81 extern const struct nft_expr_ops nft_bitwise_fast_ops;
82
83 extern struct static_key_false nft_counters_enabled;
84 extern struct static_key_false nft_trace_enabled;
85
86 extern const struct nft_set_type nft_set_rhash_type;
87 extern const struct nft_set_type nft_set_hash_type;
88 extern const struct nft_set_type nft_set_hash_fast_type;
89 extern const struct nft_set_type nft_set_rbtree_type;
90 extern const struct nft_set_type nft_set_bitmap_type;
91 extern const struct nft_set_type nft_set_pipapo_type;
92 extern const struct nft_set_type nft_set_pipapo_avx2_type;
93
94 #ifdef CONFIG_RETPOLINE
95 bool nft_rhash_lookup(const struct net *net, const struct nft_set *set,
96                       const u32 *key, const struct nft_set_ext **ext);
97 bool nft_rbtree_lookup(const struct net *net, const struct nft_set *set,
98                        const u32 *key, const struct nft_set_ext **ext);
99 bool nft_bitmap_lookup(const struct net *net, const struct nft_set *set,
100                        const u32 *key, const struct nft_set_ext **ext);
101 bool nft_hash_lookup_fast(const struct net *net,
102                           const struct nft_set *set,
103                           const u32 *key, const struct nft_set_ext **ext);
104 bool nft_hash_lookup(const struct net *net, const struct nft_set *set,
105                      const u32 *key, const struct nft_set_ext **ext);
106 bool nft_set_do_lookup(const struct net *net, const struct nft_set *set,
107                        const u32 *key, const struct nft_set_ext **ext);
108 #else
109 static inline bool
110 nft_set_do_lookup(const struct net *net, const struct nft_set *set,
111                   const u32 *key, const struct nft_set_ext **ext)
112 {
113         return set->ops->lookup(net, set, key, ext);
114 }
115 #endif
116
117 /* called from nft_pipapo_avx2.c */
118 bool nft_pipapo_lookup(const struct net *net, const struct nft_set *set,
119                        const u32 *key, const struct nft_set_ext **ext);
120 /* called from nft_set_pipapo.c */
121 bool nft_pipapo_avx2_lookup(const struct net *net, const struct nft_set *set,
122                             const u32 *key, const struct nft_set_ext **ext);
123
124 void nft_counter_init_seqcount(void);
125
126 struct nft_expr;
127 struct nft_regs;
128 struct nft_pktinfo;
129 void nft_meta_get_eval(const struct nft_expr *expr,
130                        struct nft_regs *regs, const struct nft_pktinfo *pkt);
131 void nft_cmp_eval(const struct nft_expr *expr,
132                   struct nft_regs *regs, const struct nft_pktinfo *pkt);
133 void nft_lookup_eval(const struct nft_expr *expr,
134                      struct nft_regs *regs, const struct nft_pktinfo *pkt);
135 void nft_payload_eval(const struct nft_expr *expr,
136                       struct nft_regs *regs, const struct nft_pktinfo *pkt);
137 void nft_immediate_eval(const struct nft_expr *expr,
138                         struct nft_regs *regs, const struct nft_pktinfo *pkt);
139 void nft_bitwise_eval(const struct nft_expr *expr,
140                       struct nft_regs *regs, const struct nft_pktinfo *pkt);
141 void nft_range_eval(const struct nft_expr *expr,
142                     struct nft_regs *regs, const struct nft_pktinfo *pkt);
143 void nft_byteorder_eval(const struct nft_expr *expr,
144                         struct nft_regs *regs, const struct nft_pktinfo *pkt);
145 void nft_dynset_eval(const struct nft_expr *expr,
146                      struct nft_regs *regs, const struct nft_pktinfo *pkt);
147 void nft_rt_get_eval(const struct nft_expr *expr,
148                      struct nft_regs *regs, const struct nft_pktinfo *pkt);
149 void nft_counter_eval(const struct nft_expr *expr, struct nft_regs *regs,
150                       const struct nft_pktinfo *pkt);
151 #endif /* _NET_NF_TABLES_CORE_H */