blob: 4aaacdfad62bd1ea5f646f9f1dcce16018c3dee9 [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.
6 * Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved.
7 *
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
Xiaoping Fand44a5b42015-05-26 17:37:37 -070035/*
Xiaoping Fand44a5b42015-05-26 17:37:37 -070036 * IPv6 address structure
37 */
38struct sfe_ipv6_addr {
39 __be32 addr[4];
40};
41
42typedef union {
43 __be32 ip;
44 struct sfe_ipv6_addr ip6[1];
45} sfe_ip_addr_t;
46
Xiaoping Fan99cb4c12015-08-21 19:07:32 -070047typedef enum sfe_sync_reason {
48 SFE_SYNC_REASON_STATS, /* Sync is to synchronize stats */
49 SFE_SYNC_REASON_FLUSH, /* Sync is to flush a entry */
50 SFE_SYNC_REASON_DESTROY /* Sync is to destroy a entry(requested by connection manager) */
51} sfe_sync_reason_t;
52
Xiaoping Fand44a5b42015-05-26 17:37:37 -070053/*
54 * Structure used to sync connection stats/state back within the system.
55 *
56 * NOTE: The addresses here are NON-NAT addresses, i.e. the true endpoint addressing.
57 * 'src' is the creator of the connection.
58 */
59struct sfe_connection_sync {
60 struct net_device *src_dev;
61 struct net_device *dest_dev;
62 int is_v6; /* Is it for ipv6? */
63 int protocol; /* IP protocol number (IPPROTO_...) */
64 sfe_ip_addr_t src_ip; /* Non-NAT source address, i.e. the creator of the connection */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -070065 sfe_ip_addr_t src_ip_xlate; /* NATed source address */
Xiaoping Fand44a5b42015-05-26 17:37:37 -070066 __be16 src_port; /* Non-NAT source port */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -070067 __be16 src_port_xlate; /* NATed source port */
68 sfe_ip_addr_t dest_ip; /* Non-NAT destination address, i.e. to whom the connection was created */
69 sfe_ip_addr_t dest_ip_xlate; /* NATed destination address */
Xiaoping Fand44a5b42015-05-26 17:37:37 -070070 __be16 dest_port; /* Non-NAT destination port */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -070071 __be16 dest_port_xlate; /* NATed destination port */
Xiaoping Fan6a1672f2016-08-17 19:58:12 -070072 u32 src_td_max_window;
73 u32 src_td_end;
74 u32 src_td_max_end;
75 u64 src_packet_count;
76 u64 src_byte_count;
77 u32 src_new_packet_count;
78 u32 src_new_byte_count;
79 u32 dest_td_max_window;
80 u32 dest_td_end;
81 u32 dest_td_max_end;
82 u64 dest_packet_count;
83 u64 dest_byte_count;
84 u32 dest_new_packet_count;
85 u32 dest_new_byte_count;
86 u32 reason; /* reason for stats sync message, i.e. destroy, flush, period sync */
87 u64 delta_jiffies; /* Time to be added to the current timeout to keep the connection alive */
Xiaoping Fand44a5b42015-05-26 17:37:37 -070088};
89
90/*
91 * connection mark structure
92 */
93struct sfe_connection_mark {
94 int protocol;
95 sfe_ip_addr_t src_ip;
96 sfe_ip_addr_t dest_ip;
97 __be16 src_port;
98 __be16 dest_port;
Xiaoping Fan6a1672f2016-08-17 19:58:12 -070099 u32 mark;
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700100};
101
102/*
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700103 * Expose the hook for the receive processing.
104 */
105extern int (*athrs_fast_nat_recv)(struct sk_buff *skb);
106
107/*
108 * Expose what should be a static flag in the TCP connection tracker.
109 */
110extern int nf_ct_tcp_no_window_check;
111
112/*
113 * This callback will be called in a timer
114 * at 100 times per second to sync stats back to
115 * Linux connection track.
116 *
117 * A RCU lock is taken to prevent this callback
118 * from unregistering.
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700119 */
120typedef void (*sfe_sync_rule_callback_t)(struct sfe_connection_sync *);
121
122/*
123 * IPv4 APIs used by connection manager
124 */
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700125int sfe_ipv4_recv(struct net_device *dev, struct sk_buff *skb);
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530126int sfe_ipv4_create_rule(struct sfe_ipv4_rule_create_msg *msg);
127void sfe_ipv4_destroy_rule(struct sfe_ipv4_rule_destroy_msg *msg);
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700128void sfe_ipv4_destroy_all_rules_for_dev(struct net_device *dev);
129void sfe_ipv4_register_sync_rule_callback(sfe_sync_rule_callback_t callback);
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530130void sfe_ipv4_update_rule(struct sfe_ipv4_rule_create_msg *msg);
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700131void sfe_ipv4_mark_rule(struct sfe_connection_mark *mark);
Xiaoping Fan978b3772015-05-27 14:15:18 -0700132
133#ifdef SFE_SUPPORT_IPV6
134/*
135 * IPv6 APIs used by connection manager
136 */
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700137int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb);
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530138int sfe_ipv6_create_rule(struct sfe_ipv6_rule_create_msg *msg);
139void sfe_ipv6_destroy_rule(struct sfe_ipv6_rule_destroy_msg *msg);
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700140void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev);
141void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback);
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530142void sfe_ipv6_update_rule(struct sfe_ipv6_rule_create_msg *msg);
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700143void sfe_ipv6_mark_rule(struct sfe_connection_mark *mark);
Xiaoping Fan978b3772015-05-27 14:15:18 -0700144#else
145static inline int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb)
146{
147 return 0;
148}
149
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530150static inline int sfe_ipv6_create_rule(struct sfe_ipv6_rule_create_msg *msg)
Xiaoping Fan978b3772015-05-27 14:15:18 -0700151{
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700152 return 0;
Xiaoping Fan978b3772015-05-27 14:15:18 -0700153}
154
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530155static inline void sfe_ipv6_destroy_rule(struct sfe_ipv6_rule_destroy_msg *msg);
Xiaoping Fan978b3772015-05-27 14:15:18 -0700156{
157 return;
158}
159
160static inline void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev)
161{
162 return;
163}
164
165static inline void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback)
166{
167 return;
168}
169
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530170static inline void sfe_ipv6_update_rule(struct sfe_ipv6_rule_create_msg *msg)
Xiaoping Fan978b3772015-05-27 14:15:18 -0700171{
172 return;
173}
174
175static inline void sfe_ipv6_mark_rule(struct sfe_connection_mark *mark)
176{
177 return;
178}
179#endif
Xiaoping Fan9b6bb332016-04-05 19:21:26 -0700180
181/*
182 * sfe_ipv6_addr_equal()
183 * compare ipv6 address
184 *
185 * return: 1, equal; 0, no equal
186 */
187static inline int sfe_ipv6_addr_equal(struct sfe_ipv6_addr *a,
188 struct sfe_ipv6_addr *b)
189{
190 return a->addr[0] == b->addr[0] &&
191 a->addr[1] == b->addr[1] &&
192 a->addr[2] == b->addr[2] &&
193 a->addr[3] == b->addr[3];
194}
195
196/*
197 * sfe_ipv4_addr_equal()
198 * compare ipv4 address
199 *
200 * return: 1, equal; 0, no equal
201 */
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700202#define sfe_ipv4_addr_equal(a, b) ((u32)(a) == (u32)(b))
Xiaoping Fan9b6bb332016-04-05 19:21:26 -0700203
204/*
205 * sfe_addr_equal()
206 * compare ipv4 or ipv6 address
207 *
208 * return: 1, equal; 0, no equal
209 */
210static inline int sfe_addr_equal(sfe_ip_addr_t *a,
211 sfe_ip_addr_t *b, int is_v4)
212{
213 return is_v4 ? sfe_ipv4_addr_equal(a->ip, b->ip) : sfe_ipv6_addr_equal(a->ip6, b->ip6);
214}
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530215
216int sfe_init_if(void);
217void sfe_exit_if(void);
Ratheesh Kannoth7a6a4ae2021-10-20 08:24:05 +0530218
219#endif /* __SFE_H */