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> |
ac2a6666 | 11 | #include <net/dst.h> |
3b49e2e9 PNA |
12 | |
13 | struct nf_flowtable; | |
14 | ||
15 | struct nf_flowtable_type { | |
16 | struct list_head list; | |
17 | int family; | |
a268de77 | 18 | int (*init)(struct nf_flowtable *ft); |
b408c5b0 | 19 | void (*free)(struct nf_flowtable *ft); |
78458e3e | 20 | #if IS_ENABLED(CONFIG_NETFILTER) |
3b49e2e9 | 21 | nf_hookfn *hook; |
78458e3e | 22 | #endif |
3b49e2e9 PNA |
23 | struct module *owner; |
24 | }; | |
25 | ||
26 | struct nf_flowtable { | |
84453a90 | 27 | struct list_head list; |
3b49e2e9 PNA |
28 | struct rhashtable rhashtable; |
29 | const struct nf_flowtable_type *type; | |
30 | struct delayed_work gc_work; | |
31 | }; | |
32 | ||
ac2a6666 | 33 | enum flow_offload_tuple_dir { |
af81f9e7 FF |
34 | FLOW_OFFLOAD_DIR_ORIGINAL = IP_CT_DIR_ORIGINAL, |
35 | FLOW_OFFLOAD_DIR_REPLY = IP_CT_DIR_REPLY, | |
36 | FLOW_OFFLOAD_DIR_MAX = IP_CT_DIR_MAX | |
ac2a6666 | 37 | }; |
ac2a6666 PNA |
38 | |
39 | struct flow_offload_tuple { | |
40 | union { | |
41 | struct in_addr src_v4; | |
42 | struct in6_addr src_v6; | |
43 | }; | |
44 | union { | |
45 | struct in_addr dst_v4; | |
46 | struct in6_addr dst_v6; | |
47 | }; | |
48 | struct { | |
49 | __be16 src_port; | |
50 | __be16 dst_port; | |
51 | }; | |
52 | ||
53 | int iifidx; | |
54 | ||
55 | u8 l3proto; | |
56 | u8 l4proto; | |
57 | u8 dir; | |
58 | ||
4f3780c0 FF |
59 | u16 mtu; |
60 | ||
ac2a6666 PNA |
61 | struct dst_entry *dst_cache; |
62 | }; | |
63 | ||
64 | struct flow_offload_tuple_rhash { | |
65 | struct rhash_head node; | |
66 | struct flow_offload_tuple tuple; | |
67 | }; | |
68 | ||
69 | #define FLOW_OFFLOAD_SNAT 0x1 | |
70 | #define FLOW_OFFLOAD_DNAT 0x2 | |
71 | #define FLOW_OFFLOAD_DYING 0x4 | |
59c466dd | 72 | #define FLOW_OFFLOAD_TEARDOWN 0x8 |
ac2a6666 PNA |
73 | |
74 | struct flow_offload { | |
75 | struct flow_offload_tuple_rhash tuplehash[FLOW_OFFLOAD_DIR_MAX]; | |
76 | u32 flags; | |
77 | union { | |
78 | /* Your private driver data here. */ | |
79 | u32 timeout; | |
80 | }; | |
81 | }; | |
82 | ||
83 | #define NF_FLOW_TIMEOUT (30 * HZ) | |
84 | ||
85 | struct nf_flow_route { | |
86 | struct { | |
87 | struct dst_entry *dst; | |
ac2a6666 PNA |
88 | } tuple[FLOW_OFFLOAD_DIR_MAX]; |
89 | }; | |
90 | ||
91 | struct flow_offload *flow_offload_alloc(struct nf_conn *ct, | |
92 | struct nf_flow_route *route); | |
93 | void flow_offload_free(struct flow_offload *flow); | |
94 | ||
95 | int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow); | |
ac2a6666 PNA |
96 | struct flow_offload_tuple_rhash *flow_offload_lookup(struct nf_flowtable *flow_table, |
97 | struct flow_offload_tuple *tuple); | |
5f1be84a | 98 | void nf_flow_table_cleanup(struct net_device *dev); |
c0ea1bcb | 99 | |
a268de77 | 100 | int nf_flow_table_init(struct nf_flowtable *flow_table); |
b408c5b0 | 101 | void nf_flow_table_free(struct nf_flowtable *flow_table); |
ac2a6666 | 102 | |
59c466dd | 103 | void flow_offload_teardown(struct flow_offload *flow); |
6bdc3c68 FF |
104 | static inline void flow_offload_dead(struct flow_offload *flow) |
105 | { | |
106 | flow->flags |= FLOW_OFFLOAD_DYING; | |
107 | } | |
ac2a6666 PNA |
108 | |
109 | int nf_flow_snat_port(const struct flow_offload *flow, | |
110 | struct sk_buff *skb, unsigned int thoff, | |
111 | u8 protocol, enum flow_offload_tuple_dir dir); | |
112 | int nf_flow_dnat_port(const struct flow_offload *flow, | |
113 | struct sk_buff *skb, unsigned int thoff, | |
114 | u8 protocol, enum flow_offload_tuple_dir dir); | |
115 | ||
116 | struct flow_ports { | |
117 | __be16 source, dest; | |
118 | }; | |
119 | ||
78458e3e | 120 | #if IS_ENABLED(CONFIG_NETFILTER) |
7c23b629 PNA |
121 | unsigned int nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, |
122 | const struct nf_hook_state *state); | |
123 | unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb, | |
124 | const struct nf_hook_state *state); | |
78458e3e | 125 | #endif |
7c23b629 | 126 | |
ac2a6666 PNA |
127 | #define MODULE_ALIAS_NF_FLOWTABLE(family) \ |
128 | MODULE_ALIAS("nf-flowtable-" __stringify(family)) | |
129 | ||
3b49e2e9 | 130 | #endif /* _FLOW_OFFLOAD_H */ |