]>
Commit | Line | Data |
---|---|---|
3b49e2e9 PNA |
1 | #ifndef _NF_FLOW_TABLE_H |
2 | #define _NF_FLOW_TABLE_H | |
3 | ||
ac2a6666 PNA |
4 | #include <linux/in.h> |
5 | #include <linux/in6.h> | |
6 | #include <linux/netdevice.h> | |
0eb71a9d | 7 | #include <linux/rhashtable-types.h> |
ac2a6666 | 8 | #include <linux/rcupdate.h> |
a1b2f04e | 9 | #include <linux/netfilter.h> |
af81f9e7 | 10 | #include <linux/netfilter/nf_conntrack_tuple_common.h> |
8bb69f3b | 11 | #include <net/flow_offload.h> |
ac2a6666 | 12 | #include <net/dst.h> |
3b49e2e9 PNA |
13 | |
14 | struct nf_flowtable; | |
c29f74e0 PNA |
15 | struct nf_flow_rule; |
16 | struct flow_offload; | |
17 | enum flow_offload_tuple_dir; | |
3b49e2e9 | 18 | |
9c26ba9b PB |
19 | struct nf_flow_key { |
20 | struct flow_dissector_key_meta meta; | |
21 | struct flow_dissector_key_control control; | |
cfab6dbd | 22 | struct flow_dissector_key_control enc_control; |
9c26ba9b PB |
23 | struct flow_dissector_key_basic basic; |
24 | union { | |
25 | struct flow_dissector_key_ipv4_addrs ipv4; | |
26 | struct flow_dissector_key_ipv6_addrs ipv6; | |
27 | }; | |
cfab6dbd | 28 | struct flow_dissector_key_keyid enc_key_id; |
29 | union { | |
30 | struct flow_dissector_key_ipv4_addrs enc_ipv4; | |
31 | struct flow_dissector_key_ipv6_addrs enc_ipv6; | |
32 | }; | |
9c26ba9b PB |
33 | struct flow_dissector_key_tcp tcp; |
34 | struct flow_dissector_key_ports tp; | |
35 | } __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */ | |
36 | ||
37 | struct nf_flow_match { | |
38 | struct flow_dissector dissector; | |
39 | struct nf_flow_key key; | |
40 | struct nf_flow_key mask; | |
41 | }; | |
42 | ||
43 | struct nf_flow_rule { | |
44 | struct nf_flow_match match; | |
45 | struct flow_rule *rule; | |
46 | }; | |
47 | ||
3b49e2e9 PNA |
48 | struct nf_flowtable_type { |
49 | struct list_head list; | |
50 | int family; | |
a268de77 | 51 | int (*init)(struct nf_flowtable *ft); |
8bb69f3b PNA |
52 | int (*setup)(struct nf_flowtable *ft, |
53 | struct net_device *dev, | |
54 | enum flow_block_command cmd); | |
c29f74e0 PNA |
55 | int (*action)(struct net *net, |
56 | const struct flow_offload *flow, | |
57 | enum flow_offload_tuple_dir dir, | |
58 | struct nf_flow_rule *flow_rule); | |
b408c5b0 | 59 | void (*free)(struct nf_flowtable *ft); |
3b49e2e9 PNA |
60 | nf_hookfn *hook; |
61 | struct module *owner; | |
62 | }; | |
63 | ||
8bb69f3b | 64 | enum nf_flowtable_flags { |
cfbd1125 | 65 | NF_FLOWTABLE_HW_OFFLOAD = 0x1, /* NFT_FLOWTABLE_HW_OFFLOAD */ |
8bb69f3b PNA |
66 | }; |
67 | ||
3b49e2e9 | 68 | struct nf_flowtable { |
84453a90 | 69 | struct list_head list; |
3b49e2e9 | 70 | struct rhashtable rhashtable; |
71a8a63b | 71 | int priority; |
3b49e2e9 PNA |
72 | const struct nf_flowtable_type *type; |
73 | struct delayed_work gc_work; | |
8bb69f3b PNA |
74 | unsigned int flags; |
75 | struct flow_block flow_block; | |
978703f4 | 76 | struct mutex flow_block_lock; /* Guards flow_block */ |
8bb69f3b | 77 | possible_net_t net; |
3b49e2e9 PNA |
78 | }; |
79 | ||
a5449cdc PNA |
80 | static inline bool nf_flowtable_hw_offload(struct nf_flowtable *flowtable) |
81 | { | |
82 | return flowtable->flags & NF_FLOWTABLE_HW_OFFLOAD; | |
83 | } | |
84 | ||
ac2a6666 | 85 | enum flow_offload_tuple_dir { |
af81f9e7 FF |
86 | FLOW_OFFLOAD_DIR_ORIGINAL = IP_CT_DIR_ORIGINAL, |
87 | FLOW_OFFLOAD_DIR_REPLY = IP_CT_DIR_REPLY, | |
88 | FLOW_OFFLOAD_DIR_MAX = IP_CT_DIR_MAX | |
ac2a6666 | 89 | }; |
ac2a6666 PNA |
90 | |
91 | struct flow_offload_tuple { | |
92 | union { | |
93 | struct in_addr src_v4; | |
94 | struct in6_addr src_v6; | |
95 | }; | |
96 | union { | |
97 | struct in_addr dst_v4; | |
98 | struct in6_addr dst_v6; | |
99 | }; | |
100 | struct { | |
101 | __be16 src_port; | |
102 | __be16 dst_port; | |
103 | }; | |
104 | ||
105 | int iifidx; | |
106 | ||
107 | u8 l3proto; | |
108 | u8 l4proto; | |
109 | u8 dir; | |
110 | ||
4f3780c0 FF |
111 | u16 mtu; |
112 | ||
ac2a6666 PNA |
113 | struct dst_entry *dst_cache; |
114 | }; | |
115 | ||
116 | struct flow_offload_tuple_rhash { | |
117 | struct rhash_head node; | |
118 | struct flow_offload_tuple tuple; | |
119 | }; | |
120 | ||
355a8b13 PNA |
121 | enum nf_flow_flags { |
122 | NF_FLOW_SNAT, | |
123 | NF_FLOW_DNAT, | |
124 | NF_FLOW_TEARDOWN, | |
125 | NF_FLOW_HW, | |
126 | NF_FLOW_HW_DYING, | |
127 | NF_FLOW_HW_DEAD, | |
f698fe40 | 128 | NF_FLOW_HW_REFRESH, |
355a8b13 | 129 | }; |
ac2a6666 | 130 | |
f1363e05 PNA |
131 | enum flow_offload_type { |
132 | NF_FLOW_OFFLOAD_UNSPEC = 0, | |
133 | NF_FLOW_OFFLOAD_ROUTE, | |
134 | }; | |
135 | ||
ac2a6666 PNA |
136 | struct flow_offload { |
137 | struct flow_offload_tuple_rhash tuplehash[FLOW_OFFLOAD_DIR_MAX]; | |
b32d2f34 | 138 | struct nf_conn *ct; |
355a8b13 | 139 | unsigned long flags; |
f1363e05 | 140 | u16 type; |
9f48e9bf | 141 | u32 timeout; |
62248df8 | 142 | struct rcu_head rcu_head; |
ac2a6666 PNA |
143 | }; |
144 | ||
145 | #define NF_FLOW_TIMEOUT (30 * HZ) | |
fb46f1b7 PNA |
146 | #define nf_flowtable_time_stamp (u32)jiffies |
147 | ||
148 | static inline __s32 nf_flow_timeout_delta(unsigned int timeout) | |
149 | { | |
150 | return (__s32)(timeout - nf_flowtable_time_stamp); | |
151 | } | |
ac2a6666 PNA |
152 | |
153 | struct nf_flow_route { | |
154 | struct { | |
155 | struct dst_entry *dst; | |
ac2a6666 PNA |
156 | } tuple[FLOW_OFFLOAD_DIR_MAX]; |
157 | }; | |
158 | ||
f1363e05 | 159 | struct flow_offload *flow_offload_alloc(struct nf_conn *ct); |
ac2a6666 PNA |
160 | void flow_offload_free(struct flow_offload *flow); |
161 | ||
978703f4 PB |
162 | int nf_flow_table_offload_add_cb(struct nf_flowtable *flow_table, |
163 | flow_setup_cb_t *cb, void *cb_priv); | |
164 | void nf_flow_table_offload_del_cb(struct nf_flowtable *flow_table, | |
165 | flow_setup_cb_t *cb, void *cb_priv); | |
166 | ||
f1363e05 PNA |
167 | int flow_offload_route_init(struct flow_offload *flow, |
168 | const struct nf_flow_route *route); | |
169 | ||
ac2a6666 | 170 | int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow); |
8b3646d6 PB |
171 | void flow_offload_refresh(struct nf_flowtable *flow_table, |
172 | struct flow_offload *flow); | |
173 | ||
ac2a6666 PNA |
174 | struct flow_offload_tuple_rhash *flow_offload_lookup(struct nf_flowtable *flow_table, |
175 | struct flow_offload_tuple *tuple); | |
5f1be84a | 176 | void nf_flow_table_cleanup(struct net_device *dev); |
c0ea1bcb | 177 | |
a268de77 | 178 | int nf_flow_table_init(struct nf_flowtable *flow_table); |
b408c5b0 | 179 | void nf_flow_table_free(struct nf_flowtable *flow_table); |
ac2a6666 | 180 | |
59c466dd | 181 | void flow_offload_teardown(struct flow_offload *flow); |
ac2a6666 PNA |
182 | |
183 | int nf_flow_snat_port(const struct flow_offload *flow, | |
184 | struct sk_buff *skb, unsigned int thoff, | |
185 | u8 protocol, enum flow_offload_tuple_dir dir); | |
186 | int nf_flow_dnat_port(const struct flow_offload *flow, | |
187 | struct sk_buff *skb, unsigned int thoff, | |
188 | u8 protocol, enum flow_offload_tuple_dir dir); | |
189 | ||
190 | struct flow_ports { | |
191 | __be16 source, dest; | |
192 | }; | |
193 | ||
7c23b629 PNA |
194 | unsigned int nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, |
195 | const struct nf_hook_state *state); | |
196 | unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb, | |
197 | const struct nf_hook_state *state); | |
198 | ||
ac2a6666 PNA |
199 | #define MODULE_ALIAS_NF_FLOWTABLE(family) \ |
200 | MODULE_ALIAS("nf-flowtable-" __stringify(family)) | |
201 | ||
c29f74e0 PNA |
202 | void nf_flow_offload_add(struct nf_flowtable *flowtable, |
203 | struct flow_offload *flow); | |
204 | void nf_flow_offload_del(struct nf_flowtable *flowtable, | |
205 | struct flow_offload *flow); | |
206 | void nf_flow_offload_stats(struct nf_flowtable *flowtable, | |
207 | struct flow_offload *flow); | |
208 | ||
209 | void nf_flow_table_offload_flush(struct nf_flowtable *flowtable); | |
210 | int nf_flow_table_offload_setup(struct nf_flowtable *flowtable, | |
211 | struct net_device *dev, | |
212 | enum flow_block_command cmd); | |
5c27d8d7 PNA |
213 | int nf_flow_rule_route_ipv4(struct net *net, const struct flow_offload *flow, |
214 | enum flow_offload_tuple_dir dir, | |
215 | struct nf_flow_rule *flow_rule); | |
216 | int nf_flow_rule_route_ipv6(struct net *net, const struct flow_offload *flow, | |
217 | enum flow_offload_tuple_dir dir, | |
218 | struct nf_flow_rule *flow_rule); | |
c29f74e0 PNA |
219 | |
220 | int nf_flow_table_offload_init(void); | |
221 | void nf_flow_table_offload_exit(void); | |
8bb69f3b | 222 | |
0286fbc6 | 223 | #endif /* _NF_FLOW_TABLE_H */ |