Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 1 | /* |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 2 | * sfe.h |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 3 | * Shortcut forwarding engine. |
| 4 | * |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 5 | * 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 Fan | a42c68b | 2015-08-07 18:00:39 -0700 | [diff] [blame] | 12 | * 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 Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 17 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 18 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Ratheesh Kannoth | 7a6a4ae | 2021-10-20 08:24:05 +0530 | [diff] [blame^] | 21 | #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 Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 35 | /* |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 36 | * IPv6 address structure |
| 37 | */ |
| 38 | struct sfe_ipv6_addr { |
| 39 | __be32 addr[4]; |
| 40 | }; |
| 41 | |
| 42 | typedef union { |
| 43 | __be32 ip; |
| 44 | struct sfe_ipv6_addr ip6[1]; |
| 45 | } sfe_ip_addr_t; |
| 46 | |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame] | 47 | typedef 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 Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 53 | /* |
| 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 | */ |
| 59 | struct 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 Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame] | 65 | sfe_ip_addr_t src_ip_xlate; /* NATed source address */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 66 | __be16 src_port; /* Non-NAT source port */ |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame] | 67 | __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 Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 70 | __be16 dest_port; /* Non-NAT destination port */ |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame] | 71 | __be16 dest_port_xlate; /* NATed destination port */ |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 72 | 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 Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /* |
| 91 | * connection mark structure |
| 92 | */ |
| 93 | struct 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 Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 99 | u32 mark; |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | /* |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 103 | * Expose the hook for the receive processing. |
| 104 | */ |
| 105 | extern 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 | */ |
| 110 | extern 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 Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 119 | */ |
| 120 | typedef void (*sfe_sync_rule_callback_t)(struct sfe_connection_sync *); |
| 121 | |
| 122 | /* |
| 123 | * IPv4 APIs used by connection manager |
| 124 | */ |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 125 | int sfe_ipv4_recv(struct net_device *dev, struct sk_buff *skb); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 126 | int sfe_ipv4_create_rule(struct sfe_ipv4_rule_create_msg *msg); |
| 127 | void sfe_ipv4_destroy_rule(struct sfe_ipv4_rule_destroy_msg *msg); |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 128 | void sfe_ipv4_destroy_all_rules_for_dev(struct net_device *dev); |
| 129 | void sfe_ipv4_register_sync_rule_callback(sfe_sync_rule_callback_t callback); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 130 | void sfe_ipv4_update_rule(struct sfe_ipv4_rule_create_msg *msg); |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 131 | void sfe_ipv4_mark_rule(struct sfe_connection_mark *mark); |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 132 | |
| 133 | #ifdef SFE_SUPPORT_IPV6 |
| 134 | /* |
| 135 | * IPv6 APIs used by connection manager |
| 136 | */ |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 137 | int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 138 | int sfe_ipv6_create_rule(struct sfe_ipv6_rule_create_msg *msg); |
| 139 | void sfe_ipv6_destroy_rule(struct sfe_ipv6_rule_destroy_msg *msg); |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 140 | void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev); |
| 141 | void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 142 | void sfe_ipv6_update_rule(struct sfe_ipv6_rule_create_msg *msg); |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 143 | void sfe_ipv6_mark_rule(struct sfe_connection_mark *mark); |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 144 | #else |
| 145 | static inline int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb) |
| 146 | { |
| 147 | return 0; |
| 148 | } |
| 149 | |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 150 | static inline int sfe_ipv6_create_rule(struct sfe_ipv6_rule_create_msg *msg) |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 151 | { |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 152 | return 0; |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 155 | static inline void sfe_ipv6_destroy_rule(struct sfe_ipv6_rule_destroy_msg *msg); |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 156 | { |
| 157 | return; |
| 158 | } |
| 159 | |
| 160 | static inline void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev) |
| 161 | { |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | static inline void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback) |
| 166 | { |
| 167 | return; |
| 168 | } |
| 169 | |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 170 | static inline void sfe_ipv6_update_rule(struct sfe_ipv6_rule_create_msg *msg) |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 171 | { |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | static inline void sfe_ipv6_mark_rule(struct sfe_connection_mark *mark) |
| 176 | { |
| 177 | return; |
| 178 | } |
| 179 | #endif |
Xiaoping Fan | 9b6bb33 | 2016-04-05 19:21:26 -0700 | [diff] [blame] | 180 | |
| 181 | /* |
| 182 | * sfe_ipv6_addr_equal() |
| 183 | * compare ipv6 address |
| 184 | * |
| 185 | * return: 1, equal; 0, no equal |
| 186 | */ |
| 187 | static 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 Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 202 | #define sfe_ipv4_addr_equal(a, b) ((u32)(a) == (u32)(b)) |
Xiaoping Fan | 9b6bb33 | 2016-04-05 19:21:26 -0700 | [diff] [blame] | 203 | |
| 204 | /* |
| 205 | * sfe_addr_equal() |
| 206 | * compare ipv4 or ipv6 address |
| 207 | * |
| 208 | * return: 1, equal; 0, no equal |
| 209 | */ |
| 210 | static 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 Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 215 | |
| 216 | int sfe_init_if(void); |
| 217 | void sfe_exit_if(void); |
Ratheesh Kannoth | 7a6a4ae | 2021-10-20 08:24:05 +0530 | [diff] [blame^] | 218 | |
| 219 | #endif /* __SFE_H */ |