blob: d0e0a6d80c57aa07f45e26fd8227cc68c2fab792 [file] [log] [blame]
Xiaoping Fand44a5b42015-05-26 17:37:37 -07001/*
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +05302 * sfe.h
Xiaoping Fand44a5b42015-05-26 17:37:37 -07003 * Shortcut forwarding engine.
4 *
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +05305 * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +05306 * Copyright (c) 2021,2022 Qualcomm Innovation Center, Inc. All rights reserved.
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +05307 *
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
Xiaoping Fana42c68b2015-08-07 18:00:39 -070012 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +053017 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Xiaoping Fand44a5b42015-05-26 17:37:37 -070019 */
20
Ratheesh Kannoth7a6a4ae2021-10-20 08:24:05 +053021#ifndef __SFE_H
22#define __SFE_H
23
24/*
25 * Maximum number of accelerated IPv4 or IPv6 connections
26 */
27#if defined(SFE_MEM_PROFILE_LOW)
28#define SFE_MAX_CONNECTION_NUM 512
29#elif defined(SFE_MEM_PROFILE_MEDIUM)
30#define SFE_MAX_CONNECTION_NUM 2048
31#else
32#define SFE_MAX_CONNECTION_NUM 4096
33#endif
34
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +053035#define SFE_L2_PARSE_FLAGS_PPPOE_INGRESS 0x01 /* Indicates presence of a valid PPPoE header */
36
Xiaoping Fand44a5b42015-05-26 17:37:37 -070037/*
Xiaoping Fand44a5b42015-05-26 17:37:37 -070038 * IPv6 address structure
39 */
40struct sfe_ipv6_addr {
41 __be32 addr[4];
42};
43
44typedef union {
45 __be32 ip;
46 struct sfe_ipv6_addr ip6[1];
47} sfe_ip_addr_t;
48
Xiaoping Fan99cb4c12015-08-21 19:07:32 -070049typedef enum sfe_sync_reason {
50 SFE_SYNC_REASON_STATS, /* Sync is to synchronize stats */
51 SFE_SYNC_REASON_FLUSH, /* Sync is to flush a entry */
52 SFE_SYNC_REASON_DESTROY /* Sync is to destroy a entry(requested by connection manager) */
53} sfe_sync_reason_t;
54
Xiaoping Fand44a5b42015-05-26 17:37:37 -070055/*
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +053056 * Structure used to store L2 information
57 */
58struct sfe_l2_info {
59 u16 parse_flags; /* Flags indicating L2.5 headers presence */
60 u16 l2_hdr_offset; /* Offset of L2 header */
61 u16 l2_hdr_size; /* L2 header size */
62 u16 pppoe_hdr_offset; /* PPPOE header offset */
63 u16 protocol; /* L3 Protocol */
64};
65
66/*
Xiaoping Fand44a5b42015-05-26 17:37:37 -070067 * Structure used to sync connection stats/state back within the system.
68 *
69 * NOTE: The addresses here are NON-NAT addresses, i.e. the true endpoint addressing.
70 * 'src' is the creator of the connection.
71 */
72struct sfe_connection_sync {
73 struct net_device *src_dev;
74 struct net_device *dest_dev;
75 int is_v6; /* Is it for ipv6? */
76 int protocol; /* IP protocol number (IPPROTO_...) */
77 sfe_ip_addr_t src_ip; /* Non-NAT source address, i.e. the creator of the connection */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -070078 sfe_ip_addr_t src_ip_xlate; /* NATed source address */
Xiaoping Fand44a5b42015-05-26 17:37:37 -070079 __be16 src_port; /* Non-NAT source port */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -070080 __be16 src_port_xlate; /* NATed source port */
81 sfe_ip_addr_t dest_ip; /* Non-NAT destination address, i.e. to whom the connection was created */
82 sfe_ip_addr_t dest_ip_xlate; /* NATed destination address */
Xiaoping Fand44a5b42015-05-26 17:37:37 -070083 __be16 dest_port; /* Non-NAT destination port */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -070084 __be16 dest_port_xlate; /* NATed destination port */
Xiaoping Fan6a1672f2016-08-17 19:58:12 -070085 u32 src_td_max_window;
86 u32 src_td_end;
87 u32 src_td_max_end;
88 u64 src_packet_count;
89 u64 src_byte_count;
90 u32 src_new_packet_count;
91 u32 src_new_byte_count;
92 u32 dest_td_max_window;
93 u32 dest_td_end;
94 u32 dest_td_max_end;
95 u64 dest_packet_count;
96 u64 dest_byte_count;
97 u32 dest_new_packet_count;
98 u32 dest_new_byte_count;
99 u32 reason; /* reason for stats sync message, i.e. destroy, flush, period sync */
100 u64 delta_jiffies; /* Time to be added to the current timeout to keep the connection alive */
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700101};
102
103/*
104 * connection mark structure
105 */
106struct sfe_connection_mark {
107 int protocol;
108 sfe_ip_addr_t src_ip;
109 sfe_ip_addr_t dest_ip;
110 __be16 src_port;
111 __be16 dest_port;
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700112 u32 mark;
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700113};
114
115/*
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700116 * Expose the hook for the receive processing.
117 */
118extern int (*athrs_fast_nat_recv)(struct sk_buff *skb);
119
120/*
121 * Expose what should be a static flag in the TCP connection tracker.
122 */
123extern int nf_ct_tcp_no_window_check;
124
125/*
126 * This callback will be called in a timer
127 * at 100 times per second to sync stats back to
128 * Linux connection track.
129 *
130 * A RCU lock is taken to prevent this callback
131 * from unregistering.
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700132 */
133typedef void (*sfe_sync_rule_callback_t)(struct sfe_connection_sync *);
134
135/*
136 * IPv4 APIs used by connection manager
137 */
Amitesh Anand63be37d2021-12-24 20:51:48 +0530138int sfe_ipv4_recv(struct net_device *dev, struct sk_buff *skb, struct sfe_l2_info *l2_info, bool tun_outer);
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530139int sfe_ipv4_create_rule(struct sfe_ipv4_rule_create_msg *msg);
140void sfe_ipv4_destroy_rule(struct sfe_ipv4_rule_destroy_msg *msg);
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700141void sfe_ipv4_destroy_all_rules_for_dev(struct net_device *dev);
142void sfe_ipv4_register_sync_rule_callback(sfe_sync_rule_callback_t callback);
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530143void sfe_ipv4_update_rule(struct sfe_ipv4_rule_create_msg *msg);
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700144void sfe_ipv4_mark_rule(struct sfe_connection_mark *mark);
Xiaoping Fan978b3772015-05-27 14:15:18 -0700145
146#ifdef SFE_SUPPORT_IPV6
147/*
148 * IPv6 APIs used by connection manager
149 */
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530150int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb, struct sfe_l2_info *l2_info);
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530151int sfe_ipv6_create_rule(struct sfe_ipv6_rule_create_msg *msg);
152void sfe_ipv6_destroy_rule(struct sfe_ipv6_rule_destroy_msg *msg);
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700153void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev);
154void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback);
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530155void sfe_ipv6_update_rule(struct sfe_ipv6_rule_create_msg *msg);
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700156void sfe_ipv6_mark_rule(struct sfe_connection_mark *mark);
Xiaoping Fan978b3772015-05-27 14:15:18 -0700157#else
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530158static inline int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb, struct sfe_l2_info *l2_info)
Xiaoping Fan978b3772015-05-27 14:15:18 -0700159{
160 return 0;
161}
162
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530163static inline int sfe_ipv6_create_rule(struct sfe_ipv6_rule_create_msg *msg)
Xiaoping Fan978b3772015-05-27 14:15:18 -0700164{
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700165 return 0;
Xiaoping Fan978b3772015-05-27 14:15:18 -0700166}
167
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530168static inline void sfe_ipv6_destroy_rule(struct sfe_ipv6_rule_destroy_msg *msg);
Xiaoping Fan978b3772015-05-27 14:15:18 -0700169{
170 return;
171}
172
173static inline void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev)
174{
175 return;
176}
177
178static inline void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback)
179{
180 return;
181}
182
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530183static inline void sfe_ipv6_update_rule(struct sfe_ipv6_rule_create_msg *msg)
Xiaoping Fan978b3772015-05-27 14:15:18 -0700184{
185 return;
186}
187
188static inline void sfe_ipv6_mark_rule(struct sfe_connection_mark *mark)
189{
190 return;
191}
192#endif
Xiaoping Fan9b6bb332016-04-05 19:21:26 -0700193
194/*
195 * sfe_ipv6_addr_equal()
196 * compare ipv6 address
197 *
198 * return: 1, equal; 0, no equal
199 */
200static inline int sfe_ipv6_addr_equal(struct sfe_ipv6_addr *a,
201 struct sfe_ipv6_addr *b)
202{
203 return a->addr[0] == b->addr[0] &&
204 a->addr[1] == b->addr[1] &&
205 a->addr[2] == b->addr[2] &&
206 a->addr[3] == b->addr[3];
207}
208
209/*
210 * sfe_ipv4_addr_equal()
211 * compare ipv4 address
212 *
213 * return: 1, equal; 0, no equal
214 */
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700215#define sfe_ipv4_addr_equal(a, b) ((u32)(a) == (u32)(b))
Xiaoping Fan9b6bb332016-04-05 19:21:26 -0700216
217/*
218 * sfe_addr_equal()
219 * compare ipv4 or ipv6 address
220 *
221 * return: 1, equal; 0, no equal
222 */
223static inline int sfe_addr_equal(sfe_ip_addr_t *a,
224 sfe_ip_addr_t *b, int is_v4)
225{
226 return is_v4 ? sfe_ipv4_addr_equal(a->ip, b->ip) : sfe_ipv6_addr_equal(a->ip6, b->ip6);
227}
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530228
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530229/*
230 * sfe_l2_parse_flag_set()
231 * Set L2 parse flag
232 */
233static inline void sfe_l2_parse_flag_set(struct sfe_l2_info *l2_info, u32 flag)
234{
235 l2_info->parse_flags |= flag;
236}
237
238/*
239 * sfe_l2_parse_flag_get()
240 * Get L2 parse flag
241 */
242static inline u32 sfe_l2_parse_flag_get(struct sfe_l2_info *l2_info)
243{
244 return l2_info->parse_flags;
245}
246
247/*
248 * sfe_l2_parse_flag_check()
249 * Check L2 parse flag
250 */
251static inline bool sfe_l2_parse_flag_check(struct sfe_l2_info *l2_info, u32 flag)
252{
253 return l2_info->parse_flags & flag;
254}
255
256/*
257 * sfe_l2_hdr_offset_get()
258 * Get L2 header offset
259 */
260static inline u16 sfe_l2_hdr_offset_get(struct sfe_l2_info *l2_info)
261{
262 return l2_info->l2_hdr_offset;
263}
264
265/*
266 * sfe_l2_hdr_offset_set()
267 * Set L2 header offset
268 */
269static inline void sfe_l2_hdr_offset_set(struct sfe_l2_info *l2_info, u16 offset)
270{
271 l2_info->l2_hdr_offset = offset;
272}
273
274/*
275 * sfe_l2_pppoe_hdr_offset_get()
276 * Get L2 PPPoE header offset
277 */
278static inline u16 sfe_l2_pppoe_hdr_offset_get(struct sfe_l2_info *l2_info)
279{
280 return l2_info->pppoe_hdr_offset;
281}
282
283/*
284 * sfe_l2_pppoe_hdr_offset_set()
285 * Set L2 PPPoE header offset
286 */
287static inline void sfe_l2_pppoe_hdr_offset_set(struct sfe_l2_info *l2_info, u16 offset)
288{
289 l2_info->pppoe_hdr_offset = offset;
290}
291
292/*
293 * sfe_l2_hdr_size_get()
294 * Get L2 header size
295 */
296static inline u16 sfe_l2_hdr_size_get(struct sfe_l2_info *l2_info)
297{
298 return l2_info->l2_hdr_size;
299}
300
301/*
302 * sfe_l2_hdr_size_set()
303 * Set L2 header size
304 */
305static inline void sfe_l2_hdr_size_set(struct sfe_l2_info *l2_info, u16 size)
306{
307 l2_info->l2_hdr_size = size;
308}
309
310/*
311 * sfe_l2_protocol_get()
312 * Get L2 protocol
313 */
314static inline u16 sfe_l2_protocol_get(struct sfe_l2_info *l2_info)
315{
316 return l2_info->protocol;
317}
318
319/*
320 * sfe_l2_protocol_set()
321 * Set L2 protocol
322 */
323static inline void sfe_l2_protocol_set(struct sfe_l2_info *l2_info, u16 proto)
324{
325 l2_info->protocol = proto;
326}
327
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530328int sfe_init_if(void);
329void sfe_exit_if(void);
Ratheesh Kannoth7a6a4ae2021-10-20 08:24:05 +0530330
331#endif /* __SFE_H */