1 #ifndef _NF_FLOW_TABLE_H
2 #define _NF_FLOW_TABLE_H
6 #include <linux/netdevice.h>
7 #include <linux/rhashtable-types.h>
8 #include <linux/rcupdate.h>
9 #include <linux/netfilter.h>
10 #include <linux/netfilter/nf_conntrack_tuple_common.h>
11 #include <net/flow_offload.h>
17 enum flow_offload_tuple_dir;
19 struct nf_flowtable_type {
20 struct list_head list;
22 int (*init)(struct nf_flowtable *ft);
23 int (*setup)(struct nf_flowtable *ft,
24 struct net_device *dev,
25 enum flow_block_command cmd);
26 int (*action)(struct net *net,
27 const struct flow_offload *flow,
28 enum flow_offload_tuple_dir dir,
29 struct nf_flow_rule *flow_rule);
30 void (*free)(struct nf_flowtable *ft);
35 enum nf_flowtable_flags {
36 NF_FLOWTABLE_HW_OFFLOAD = 0x1,
40 struct list_head list;
41 struct rhashtable rhashtable;
43 const struct nf_flowtable_type *type;
44 struct delayed_work gc_work;
46 struct flow_block flow_block;
50 enum flow_offload_tuple_dir {
51 FLOW_OFFLOAD_DIR_ORIGINAL = IP_CT_DIR_ORIGINAL,
52 FLOW_OFFLOAD_DIR_REPLY = IP_CT_DIR_REPLY,
53 FLOW_OFFLOAD_DIR_MAX = IP_CT_DIR_MAX
56 struct flow_offload_tuple {
58 struct in_addr src_v4;
59 struct in6_addr src_v6;
62 struct in_addr dst_v4;
63 struct in6_addr dst_v6;
78 struct dst_entry *dst_cache;
81 struct flow_offload_tuple_rhash {
82 struct rhash_head node;
83 struct flow_offload_tuple tuple;
86 #define FLOW_OFFLOAD_SNAT 0x1
87 #define FLOW_OFFLOAD_DNAT 0x2
88 #define FLOW_OFFLOAD_DYING 0x4
89 #define FLOW_OFFLOAD_TEARDOWN 0x8
90 #define FLOW_OFFLOAD_HW 0x10
91 #define FLOW_OFFLOAD_HW_DYING 0x20
92 #define FLOW_OFFLOAD_HW_DEAD 0x40
94 enum flow_offload_type {
95 NF_FLOW_OFFLOAD_UNSPEC = 0,
96 NF_FLOW_OFFLOAD_ROUTE,
100 struct flow_offload_tuple_rhash tuplehash[FLOW_OFFLOAD_DIR_MAX];
105 struct rcu_head rcu_head;
108 #define NF_FLOW_TIMEOUT (30 * HZ)
110 struct nf_flow_route {
112 struct dst_entry *dst;
113 } tuple[FLOW_OFFLOAD_DIR_MAX];
116 struct flow_offload *flow_offload_alloc(struct nf_conn *ct);
117 void flow_offload_free(struct flow_offload *flow);
119 int flow_offload_route_init(struct flow_offload *flow,
120 const struct nf_flow_route *route);
122 int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow);
123 struct flow_offload_tuple_rhash *flow_offload_lookup(struct nf_flowtable *flow_table,
124 struct flow_offload_tuple *tuple);
125 void nf_flow_table_cleanup(struct net_device *dev);
127 int nf_flow_table_init(struct nf_flowtable *flow_table);
128 void nf_flow_table_free(struct nf_flowtable *flow_table);
130 void flow_offload_teardown(struct flow_offload *flow);
131 static inline void flow_offload_dead(struct flow_offload *flow)
133 flow->flags |= FLOW_OFFLOAD_DYING;
136 int nf_flow_snat_port(const struct flow_offload *flow,
137 struct sk_buff *skb, unsigned int thoff,
138 u8 protocol, enum flow_offload_tuple_dir dir);
139 int nf_flow_dnat_port(const struct flow_offload *flow,
140 struct sk_buff *skb, unsigned int thoff,
141 u8 protocol, enum flow_offload_tuple_dir dir);
147 unsigned int nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
148 const struct nf_hook_state *state);
149 unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
150 const struct nf_hook_state *state);
152 #define MODULE_ALIAS_NF_FLOWTABLE(family) \
153 MODULE_ALIAS("nf-flowtable-" __stringify(family))
155 void nf_flow_offload_add(struct nf_flowtable *flowtable,
156 struct flow_offload *flow);
157 void nf_flow_offload_del(struct nf_flowtable *flowtable,
158 struct flow_offload *flow);
159 void nf_flow_offload_stats(struct nf_flowtable *flowtable,
160 struct flow_offload *flow);
162 void nf_flow_table_offload_flush(struct nf_flowtable *flowtable);
163 int nf_flow_table_offload_setup(struct nf_flowtable *flowtable,
164 struct net_device *dev,
165 enum flow_block_command cmd);
166 int nf_flow_rule_route_ipv4(struct net *net, const struct flow_offload *flow,
167 enum flow_offload_tuple_dir dir,
168 struct nf_flow_rule *flow_rule);
169 int nf_flow_rule_route_ipv6(struct net *net, const struct flow_offload *flow,
170 enum flow_offload_tuple_dir dir,
171 struct nf_flow_rule *flow_rule);
173 int nf_flow_table_offload_init(void);
174 void nf_flow_table_offload_exit(void);
176 #endif /* _NF_FLOW_TABLE_H */