blob: f4b96b6e871379d2ab32f784a5a945aed1b278ea [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 Prathyusha5f27e232022-01-06 14:39:04 +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/*
Wayne Tanbb7f1782021-12-13 11:16:04 -080056 * VLAN header (aka VLAN tag)
57 */
58struct sfe_vlan_hdr {
59 u16 tpid; /* Tag Protocol Identifier */
60 u16 tci; /* Tag Control Information */
61};
62
63/*
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +053064 * Structure used to store L2 information
65 */
66struct sfe_l2_info {
67 u16 parse_flags; /* Flags indicating L2.5 headers presence */
68 u16 l2_hdr_offset; /* Offset of L2 header */
69 u16 l2_hdr_size; /* L2 header size */
70 u16 pppoe_hdr_offset; /* PPPOE header offset */
71 u16 protocol; /* L3 Protocol */
Wayne Tanbb7f1782021-12-13 11:16:04 -080072 struct sfe_vlan_hdr vlan_hdr[SFE_MAX_VLAN_DEPTH];
73 /* VLAN tag(s) of ingress packet */
74 u8 vlan_hdr_cnt; /* Number of VLAN tags in the ingress packet */
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +053075};
76
77/*
Xiaoping Fand44a5b42015-05-26 17:37:37 -070078 * Structure used to sync connection stats/state back within the system.
79 *
80 * NOTE: The addresses here are NON-NAT addresses, i.e. the true endpoint addressing.
81 * 'src' is the creator of the connection.
82 */
83struct sfe_connection_sync {
84 struct net_device *src_dev;
85 struct net_device *dest_dev;
86 int is_v6; /* Is it for ipv6? */
87 int protocol; /* IP protocol number (IPPROTO_...) */
88 sfe_ip_addr_t src_ip; /* Non-NAT source address, i.e. the creator of the connection */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -070089 sfe_ip_addr_t src_ip_xlate; /* NATed source address */
Xiaoping Fand44a5b42015-05-26 17:37:37 -070090 __be16 src_port; /* Non-NAT source port */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -070091 __be16 src_port_xlate; /* NATed source port */
92 sfe_ip_addr_t dest_ip; /* Non-NAT destination address, i.e. to whom the connection was created */
93 sfe_ip_addr_t dest_ip_xlate; /* NATed destination address */
Xiaoping Fand44a5b42015-05-26 17:37:37 -070094 __be16 dest_port; /* Non-NAT destination port */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -070095 __be16 dest_port_xlate; /* NATed destination port */
Xiaoping Fan6a1672f2016-08-17 19:58:12 -070096 u32 src_td_max_window;
97 u32 src_td_end;
98 u32 src_td_max_end;
99 u64 src_packet_count;
100 u64 src_byte_count;
101 u32 src_new_packet_count;
102 u32 src_new_byte_count;
103 u32 dest_td_max_window;
104 u32 dest_td_end;
105 u32 dest_td_max_end;
106 u64 dest_packet_count;
107 u64 dest_byte_count;
108 u32 dest_new_packet_count;
109 u32 dest_new_byte_count;
Wayne Tanbb7f1782021-12-13 11:16:04 -0800110 u32 reason; /* reason for stats sync message, i.e. destroy, flush, period sync */
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700111 u64 delta_jiffies; /* Time to be added to the current timeout to keep the connection alive */
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700112};
113
114/*
115 * connection mark structure
116 */
117struct sfe_connection_mark {
118 int protocol;
119 sfe_ip_addr_t src_ip;
120 sfe_ip_addr_t dest_ip;
121 __be16 src_port;
122 __be16 dest_port;
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700123 u32 mark;
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700124};
125
126/*
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700127 * Expose the hook for the receive processing.
128 */
129extern int (*athrs_fast_nat_recv)(struct sk_buff *skb);
130
131/*
132 * Expose what should be a static flag in the TCP connection tracker.
133 */
134extern int nf_ct_tcp_no_window_check;
135
136/*
137 * This callback will be called in a timer
138 * at 100 times per second to sync stats back to
139 * Linux connection track.
140 *
141 * A RCU lock is taken to prevent this callback
142 * from unregistering.
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700143 */
144typedef void (*sfe_sync_rule_callback_t)(struct sfe_connection_sync *);
145
146/*
147 * IPv4 APIs used by connection manager
148 */
Amitesh Anand63be37d2021-12-24 20:51:48 +0530149int 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 +0530150int sfe_ipv4_create_rule(struct sfe_ipv4_rule_create_msg *msg);
151void sfe_ipv4_destroy_rule(struct sfe_ipv4_rule_destroy_msg *msg);
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700152void sfe_ipv4_destroy_all_rules_for_dev(struct net_device *dev);
153void sfe_ipv4_register_sync_rule_callback(sfe_sync_rule_callback_t callback);
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530154void sfe_ipv4_update_rule(struct sfe_ipv4_rule_create_msg *msg);
Xiaoping Fan978b3772015-05-27 14:15:18 -0700155
156#ifdef SFE_SUPPORT_IPV6
157/*
158 * IPv6 APIs used by connection manager
159 */
Suruchi Suman23a279d2021-11-16 15:13:09 +0530160int sfe_ipv6_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 +0530161int sfe_ipv6_create_rule(struct sfe_ipv6_rule_create_msg *msg);
162void sfe_ipv6_destroy_rule(struct sfe_ipv6_rule_destroy_msg *msg);
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700163void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev);
164void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback);
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530165void sfe_ipv6_update_rule(struct sfe_ipv6_rule_create_msg *msg);
Xiaoping Fan978b3772015-05-27 14:15:18 -0700166#else
Suruchi Suman23a279d2021-11-16 15:13:09 +0530167static inline int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb, struct sfe_l2_info *l2_info, bool tun_outer)
Xiaoping Fan978b3772015-05-27 14:15:18 -0700168{
169 return 0;
170}
171
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530172static inline int sfe_ipv6_create_rule(struct sfe_ipv6_rule_create_msg *msg)
Xiaoping Fan978b3772015-05-27 14:15:18 -0700173{
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700174 return 0;
Xiaoping Fan978b3772015-05-27 14:15:18 -0700175}
176
Suruchi Suman23a279d2021-11-16 15:13:09 +0530177static inline void sfe_ipv6_destroy_rule(struct sfe_ipv6_rule_destroy_msg *msg)
Xiaoping Fan978b3772015-05-27 14:15:18 -0700178{
179 return;
180}
181
182static inline void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev)
183{
184 return;
185}
186
187static inline void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback)
188{
189 return;
190}
191
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530192static inline void sfe_ipv6_update_rule(struct sfe_ipv6_rule_create_msg *msg)
Xiaoping Fan978b3772015-05-27 14:15:18 -0700193{
194 return;
195}
196
Xiaoping Fan978b3772015-05-27 14:15:18 -0700197#endif
Xiaoping Fan9b6bb332016-04-05 19:21:26 -0700198
199/*
200 * sfe_ipv6_addr_equal()
201 * compare ipv6 address
202 *
203 * return: 1, equal; 0, no equal
204 */
205static inline int sfe_ipv6_addr_equal(struct sfe_ipv6_addr *a,
206 struct sfe_ipv6_addr *b)
207{
208 return a->addr[0] == b->addr[0] &&
209 a->addr[1] == b->addr[1] &&
210 a->addr[2] == b->addr[2] &&
211 a->addr[3] == b->addr[3];
212}
213
214/*
215 * sfe_ipv4_addr_equal()
216 * compare ipv4 address
217 *
218 * return: 1, equal; 0, no equal
219 */
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700220#define sfe_ipv4_addr_equal(a, b) ((u32)(a) == (u32)(b))
Xiaoping Fan9b6bb332016-04-05 19:21:26 -0700221
222/*
223 * sfe_addr_equal()
224 * compare ipv4 or ipv6 address
225 *
226 * return: 1, equal; 0, no equal
227 */
228static inline int sfe_addr_equal(sfe_ip_addr_t *a,
229 sfe_ip_addr_t *b, int is_v4)
230{
231 return is_v4 ? sfe_ipv4_addr_equal(a->ip, b->ip) : sfe_ipv6_addr_equal(a->ip6, b->ip6);
232}
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530233
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530234/*
235 * sfe_l2_parse_flag_set()
236 * Set L2 parse flag
237 */
Guduri Prathyusha5f27e232022-01-06 14:39:04 +0530238static inline void sfe_l2_parse_flag_set(struct sfe_l2_info *l2_info, u16 flag)
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530239{
240 l2_info->parse_flags |= flag;
241}
242
243/*
244 * sfe_l2_parse_flag_get()
245 * Get L2 parse flag
246 */
Guduri Prathyusha5f27e232022-01-06 14:39:04 +0530247static inline u16 sfe_l2_parse_flag_get(struct sfe_l2_info *l2_info)
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530248{
249 return l2_info->parse_flags;
250}
251
252/*
253 * sfe_l2_parse_flag_check()
254 * Check L2 parse flag
255 */
Guduri Prathyusha5f27e232022-01-06 14:39:04 +0530256static inline bool sfe_l2_parse_flag_check(struct sfe_l2_info *l2_info, u16 flag)
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530257{
Guduri Prathyusha5f27e232022-01-06 14:39:04 +0530258 return !!(l2_info->parse_flags & flag);
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530259}
260
261/*
262 * sfe_l2_hdr_offset_get()
263 * Get L2 header offset
264 */
265static inline u16 sfe_l2_hdr_offset_get(struct sfe_l2_info *l2_info)
266{
267 return l2_info->l2_hdr_offset;
268}
269
270/*
271 * sfe_l2_hdr_offset_set()
272 * Set L2 header offset
273 */
274static inline void sfe_l2_hdr_offset_set(struct sfe_l2_info *l2_info, u16 offset)
275{
276 l2_info->l2_hdr_offset = offset;
277}
278
279/*
280 * sfe_l2_pppoe_hdr_offset_get()
281 * Get L2 PPPoE header offset
282 */
283static inline u16 sfe_l2_pppoe_hdr_offset_get(struct sfe_l2_info *l2_info)
284{
285 return l2_info->pppoe_hdr_offset;
286}
287
288/*
289 * sfe_l2_pppoe_hdr_offset_set()
290 * Set L2 PPPoE header offset
291 */
292static inline void sfe_l2_pppoe_hdr_offset_set(struct sfe_l2_info *l2_info, u16 offset)
293{
294 l2_info->pppoe_hdr_offset = offset;
295}
296
297/*
298 * sfe_l2_hdr_size_get()
299 * Get L2 header size
300 */
301static inline u16 sfe_l2_hdr_size_get(struct sfe_l2_info *l2_info)
302{
303 return l2_info->l2_hdr_size;
304}
305
306/*
307 * sfe_l2_hdr_size_set()
308 * Set L2 header size
309 */
310static inline void sfe_l2_hdr_size_set(struct sfe_l2_info *l2_info, u16 size)
311{
312 l2_info->l2_hdr_size = size;
313}
314
315/*
316 * sfe_l2_protocol_get()
317 * Get L2 protocol
318 */
319static inline u16 sfe_l2_protocol_get(struct sfe_l2_info *l2_info)
320{
321 return l2_info->protocol;
322}
323
324/*
325 * sfe_l2_protocol_set()
326 * Set L2 protocol
327 */
328static inline void sfe_l2_protocol_set(struct sfe_l2_info *l2_info, u16 proto)
329{
330 l2_info->protocol = proto;
331}
332
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530333int sfe_init_if(void);
334void sfe_exit_if(void);
Ratheesh Kannoth7a6a4ae2021-10-20 08:24:05 +0530335
336#endif /* __SFE_H */