]>
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 PNA |
18 | |
19 | struct nf_flowtable_type { | |
20 | struct list_head list; | |
21 | int family; | |
a268de77 | 22 | int (*init)(struct nf_flowtable *ft); |
8bb69f3b PNA |
23 | int (*setup)(struct nf_flowtable *ft, |
24 | struct net_device *dev, | |
25 | enum flow_block_command cmd); | |
c29f74e0 PNA |
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); | |
b408c5b0 | 30 | void (*free)(struct nf_flowtable *ft); |
3b49e2e9 PNA |
31 | nf_hookfn *hook; |
32 | struct module *owner; | |
33 | }; | |
34 | ||
8bb69f3b PNA |
35 | enum nf_flowtable_flags { |
36 | NF_FLOWTABLE_HW_OFFLOAD = 0x1, | |
37 | }; | |
38 | ||
3b49e2e9 | 39 | struct nf_flowtable { |
84453a90 | 40 | struct list_head list; |
3b49e2e9 | 41 | struct rhashtable rhashtable; |
71a8a63b | 42 | int priority; |
3b49e2e9 PNA |
43 | const struct nf_flowtable_type *type; |
44 | struct delayed_work gc_work; | |
8bb69f3b PNA |
45 | unsigned int flags; |
46 | struct flow_block flow_block; | |
47 | possible_net_t net; | |
3b49e2e9 PNA |
48 | }; |
49 | ||
ac2a6666 | 50 | enum flow_offload_tuple_dir { |
af81f9e7 FF |
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 | |
ac2a6666 | 54 | }; |
ac2a6666 PNA |
55 | |
56 | struct flow_offload_tuple { | |
57 | union { | |
58 | struct in_addr src_v4; | |
59 | struct in6_addr src_v6; | |
60 | }; | |
61 | union { | |
62 | struct in_addr dst_v4; | |
63 | struct in6_addr dst_v6; | |
64 | }; | |
65 | struct { | |
66 | __be16 src_port; | |
67 | __be16 dst_port; | |
68 | }; | |
69 | ||
70 | int iifidx; | |
71 | ||
72 | u8 l3proto; | |
73 | u8 l4proto; | |
74 | u8 dir; | |
75 | ||
4f3780c0 FF |
76 | u16 mtu; |
77 | ||
ac2a6666 PNA |
78 | struct dst_entry *dst_cache; |
79 | }; | |
80 | ||
81 | struct flow_offload_tuple_rhash { | |
82 | struct rhash_head node; | |
83 | struct flow_offload_tuple tuple; | |
84 | }; | |
85 | ||
86 | #define FLOW_OFFLOAD_SNAT 0x1 | |
87 | #define FLOW_OFFLOAD_DNAT 0x2 | |
59c466dd | 88 | #define FLOW_OFFLOAD_TEARDOWN 0x8 |
c29f74e0 PNA |
89 | #define FLOW_OFFLOAD_HW 0x10 |
90 | #define FLOW_OFFLOAD_HW_DYING 0x20 | |
91 | #define FLOW_OFFLOAD_HW_DEAD 0x40 | |
ac2a6666 | 92 | |
f1363e05 PNA |
93 | enum flow_offload_type { |
94 | NF_FLOW_OFFLOAD_UNSPEC = 0, | |
95 | NF_FLOW_OFFLOAD_ROUTE, | |
96 | }; | |
97 | ||
ac2a6666 PNA |
98 | struct flow_offload { |
99 | struct flow_offload_tuple_rhash tuplehash[FLOW_OFFLOAD_DIR_MAX]; | |
b32d2f34 | 100 | struct nf_conn *ct; |
f1363e05 PNA |
101 | u16 flags; |
102 | u16 type; | |
9f48e9bf | 103 | u32 timeout; |
62248df8 | 104 | struct rcu_head rcu_head; |
ac2a6666 PNA |
105 | }; |
106 | ||
107 | #define NF_FLOW_TIMEOUT (30 * HZ) | |
fb46f1b7 PNA |
108 | #define nf_flowtable_time_stamp (u32)jiffies |
109 | ||
110 | static inline __s32 nf_flow_timeout_delta(unsigned int timeout) | |
111 | { | |
112 | return (__s32)(timeout - nf_flowtable_time_stamp); | |
113 | } | |
ac2a6666 PNA |
114 | |
115 | struct nf_flow_route { | |
116 | struct { | |
117 | struct dst_entry *dst; | |
ac2a6666 PNA |
118 | } tuple[FLOW_OFFLOAD_DIR_MAX]; |
119 | }; | |
120 | ||
f1363e05 | 121 | struct flow_offload *flow_offload_alloc(struct nf_conn *ct); |
ac2a6666 PNA |
122 | void flow_offload_free(struct flow_offload *flow); |
123 | ||
f1363e05 PNA |
124 | int flow_offload_route_init(struct flow_offload *flow, |
125 | const struct nf_flow_route *route); | |
126 | ||
ac2a6666 | 127 | int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow); |
ac2a6666 PNA |
128 | struct flow_offload_tuple_rhash *flow_offload_lookup(struct nf_flowtable *flow_table, |
129 | struct flow_offload_tuple *tuple); | |
5f1be84a | 130 | void nf_flow_table_cleanup(struct net_device *dev); |
c0ea1bcb | 131 | |
a268de77 | 132 | int nf_flow_table_init(struct nf_flowtable *flow_table); |
b408c5b0 | 133 | void nf_flow_table_free(struct nf_flowtable *flow_table); |
ac2a6666 | 134 | |
59c466dd | 135 | void flow_offload_teardown(struct flow_offload *flow); |
ac2a6666 PNA |
136 | |
137 | int nf_flow_snat_port(const struct flow_offload *flow, | |
138 | struct sk_buff *skb, unsigned int thoff, | |
139 | u8 protocol, enum flow_offload_tuple_dir dir); | |
140 | int nf_flow_dnat_port(const struct flow_offload *flow, | |
141 | struct sk_buff *skb, unsigned int thoff, | |
142 | u8 protocol, enum flow_offload_tuple_dir dir); | |
143 | ||
144 | struct flow_ports { | |
145 | __be16 source, dest; | |
146 | }; | |
147 | ||
7c23b629 PNA |
148 | unsigned int nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, |
149 | const struct nf_hook_state *state); | |
150 | unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb, | |
151 | const struct nf_hook_state *state); | |
152 | ||
ac2a6666 PNA |
153 | #define MODULE_ALIAS_NF_FLOWTABLE(family) \ |
154 | MODULE_ALIAS("nf-flowtable-" __stringify(family)) | |
155 | ||
c29f74e0 PNA |
156 | void nf_flow_offload_add(struct nf_flowtable *flowtable, |
157 | struct flow_offload *flow); | |
158 | void nf_flow_offload_del(struct nf_flowtable *flowtable, | |
159 | struct flow_offload *flow); | |
160 | void nf_flow_offload_stats(struct nf_flowtable *flowtable, | |
161 | struct flow_offload *flow); | |
162 | ||
163 | void nf_flow_table_offload_flush(struct nf_flowtable *flowtable); | |
164 | int nf_flow_table_offload_setup(struct nf_flowtable *flowtable, | |
165 | struct net_device *dev, | |
166 | enum flow_block_command cmd); | |
5c27d8d7 PNA |
167 | int nf_flow_rule_route_ipv4(struct net *net, const struct flow_offload *flow, |
168 | enum flow_offload_tuple_dir dir, | |
169 | struct nf_flow_rule *flow_rule); | |
170 | int nf_flow_rule_route_ipv6(struct net *net, const struct flow_offload *flow, | |
171 | enum flow_offload_tuple_dir dir, | |
172 | struct nf_flow_rule *flow_rule); | |
c29f74e0 PNA |
173 | |
174 | int nf_flow_table_offload_init(void); | |
175 | void nf_flow_table_offload_exit(void); | |
8bb69f3b | 176 | |
0286fbc6 | 177 | #endif /* _NF_FLOW_TABLE_H */ |