blob: 664b1e36fc17356c7f422733f29e5133a0f89be1 [file] [log] [blame]
Xiaoping Fand44a5b42015-05-26 17:37:37 -07001/*
2 * sfe_cm.h
3 * Shortcut forwarding engine.
4 *
Xiaoping Fana42c68b2015-08-07 18:00:39 -07005 * Copyright (c) 2013-2015 The Linux Foundation. All rights reserved.
6 * Permission to use, copy, modify, and/or distribute this software for
7 * any purpose with or without fee is hereby granted, provided that the
8 * above copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Xiaoping Fand44a5b42015-05-26 17:37:37 -070016 */
17
18/*
19 * connection flags.
20 */
21#define SFE_CREATE_FLAG_NO_SEQ_CHECK 0x1
22 /* Indicates that we should not check sequence numbers */
23
24/*
25 * IPv6 address structure
26 */
27struct sfe_ipv6_addr {
28 __be32 addr[4];
29};
30
31typedef union {
32 __be32 ip;
33 struct sfe_ipv6_addr ip6[1];
34} sfe_ip_addr_t;
35
36/*
37 * connection creation structure.
38 */
39struct sfe_connection_create {
40 int protocol;
41 struct net_device *src_dev;
42 struct net_device *dest_dev;
43 uint32_t flags;
44 uint32_t src_mtu;
45 uint32_t dest_mtu;
46 sfe_ip_addr_t src_ip;
47 sfe_ip_addr_t src_ip_xlate;
48 sfe_ip_addr_t dest_ip;
49 sfe_ip_addr_t dest_ip_xlate;
50 __be16 src_port;
51 __be16 src_port_xlate;
52 __be16 dest_port;
53 __be16 dest_port_xlate;
54 uint8_t src_mac[ETH_ALEN];
55 uint8_t src_mac_xlate[ETH_ALEN];
56 uint8_t dest_mac[ETH_ALEN];
57 uint8_t dest_mac_xlate[ETH_ALEN];
58 uint8_t src_td_window_scale;
59 uint32_t src_td_max_window;
60 uint32_t src_td_end;
61 uint32_t src_td_max_end;
62 uint8_t dest_td_window_scale;
63 uint32_t dest_td_max_window;
64 uint32_t dest_td_end;
65 uint32_t dest_td_max_end;
66 uint32_t mark;
Zhi Chen8748eb32015-06-18 12:58:48 -070067#ifdef CONFIG_XFRM
68 uint32_t original_accel;
69 uint32_t reply_accel;
70#endif
Xiaoping Fan99cb4c12015-08-21 19:07:32 -070071 uint32_t src_priority;
72 uint32_t dest_priority;
73 uint32_t src_dscp;
74 uint32_t dest_dscp;
Xiaoping Fand44a5b42015-05-26 17:37:37 -070075};
76
77/*
78 * connection destruction structure.
79 */
80struct sfe_connection_destroy {
81 int protocol;
82 sfe_ip_addr_t src_ip;
83 sfe_ip_addr_t dest_ip;
84 __be16 src_port;
85 __be16 dest_port;
86};
87
Xiaoping Fan99cb4c12015-08-21 19:07:32 -070088typedef enum sfe_sync_reason {
89 SFE_SYNC_REASON_STATS, /* Sync is to synchronize stats */
90 SFE_SYNC_REASON_FLUSH, /* Sync is to flush a entry */
91 SFE_SYNC_REASON_DESTROY /* Sync is to destroy a entry(requested by connection manager) */
92} sfe_sync_reason_t;
93
Xiaoping Fand44a5b42015-05-26 17:37:37 -070094/*
95 * Structure used to sync connection stats/state back within the system.
96 *
97 * NOTE: The addresses here are NON-NAT addresses, i.e. the true endpoint addressing.
98 * 'src' is the creator of the connection.
99 */
100struct sfe_connection_sync {
101 struct net_device *src_dev;
102 struct net_device *dest_dev;
103 int is_v6; /* Is it for ipv6? */
104 int protocol; /* IP protocol number (IPPROTO_...) */
105 sfe_ip_addr_t src_ip; /* Non-NAT source address, i.e. the creator of the connection */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -0700106 sfe_ip_addr_t src_ip_xlate; /* NATed source address */
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700107 __be16 src_port; /* Non-NAT source port */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -0700108 __be16 src_port_xlate; /* NATed source port */
109 sfe_ip_addr_t dest_ip; /* Non-NAT destination address, i.e. to whom the connection was created */
110 sfe_ip_addr_t dest_ip_xlate; /* NATed destination address */
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700111 __be16 dest_port; /* Non-NAT destination port */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -0700112 __be16 dest_port_xlate; /* NATed destination port */
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700113 uint32_t src_td_max_window;
114 uint32_t src_td_end;
115 uint32_t src_td_max_end;
116 uint64_t src_packet_count;
117 uint64_t src_byte_count;
118 uint32_t src_new_packet_count;
119 uint32_t src_new_byte_count;
120 uint32_t dest_td_max_window;
121 uint32_t dest_td_end;
122 uint32_t dest_td_max_end;
123 uint64_t dest_packet_count;
124 uint64_t dest_byte_count;
125 uint32_t dest_new_packet_count;
126 uint32_t dest_new_byte_count;
Xiaoping Fan99cb4c12015-08-21 19:07:32 -0700127 uint32_t reason; /* reason for stats sync message, i.e. destroy, flush, period sync */
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700128 uint64_t delta_jiffies; /* Time to be added to the current timeout to keep the connection alive */
129};
130
131/*
132 * connection mark structure
133 */
134struct sfe_connection_mark {
135 int protocol;
136 sfe_ip_addr_t src_ip;
137 sfe_ip_addr_t dest_ip;
138 __be16 src_port;
139 __be16 dest_port;
140 uint32_t mark;
141};
142
143/*
144 * Type used for a sync rule callback.
145 */
146typedef void (*sfe_sync_rule_callback_t)(struct sfe_connection_sync *);
147
148/*
149 * IPv4 APIs used by connection manager
150 */
151extern int sfe_ipv4_recv(struct net_device *dev, struct sk_buff *skb);
152extern int sfe_ipv4_create_rule(struct sfe_connection_create *sic);
153extern void sfe_ipv4_destroy_rule(struct sfe_connection_destroy *sid);
154extern void sfe_ipv4_destroy_all_rules_for_dev(struct net_device *dev);
155extern void sfe_ipv4_register_sync_rule_callback(sfe_sync_rule_callback_t callback);
156extern void sfe_ipv4_update_rule(struct sfe_connection_create *sic);
157extern void sfe_ipv4_mark_rule(struct sfe_connection_mark *mark);
Xiaoping Fan978b3772015-05-27 14:15:18 -0700158
159#ifdef SFE_SUPPORT_IPV6
160/*
161 * IPv6 APIs used by connection manager
162 */
163extern int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb);
164extern int sfe_ipv6_create_rule(struct sfe_connection_create *sic);
165extern void sfe_ipv6_destroy_rule(struct sfe_connection_destroy *sid);
166extern void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev);
167extern void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback);
168extern void sfe_ipv6_update_rule(struct sfe_connection_create *sic);
169extern void sfe_ipv6_mark_rule(struct sfe_connection_mark *mark);
170#else
171static inline int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb)
172{
173 return 0;
174}
175
176static inline int sfe_ipv6_create_rule(struct sfe_connection_create *sic)
177{
178 return -1;
179}
180
181static inline void sfe_ipv6_destroy_rule(struct sfe_connection_destroy *sid)
182{
183 return;
184}
185
186static inline void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev)
187{
188 return;
189}
190
191static inline void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback)
192{
193 return;
194}
195
196static inline void sfe_ipv6_update_rule(struct sfe_connection_create *sic)
197{
198 return;
199}
200
201static inline void sfe_ipv6_mark_rule(struct sfe_connection_mark *mark)
202{
203 return;
204}
205#endif