Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 1 | /* |
| 2 | * sfe_ipv4.h |
| 3 | * Shortcut forwarding engine header file for IPv4. |
| 4 | * |
| 5 | * Copyright (c) 2013-2016, 2019-2020, The Linux Foundation. All rights reserved. |
Guduri Prathyusha | 5f27e23 | 2022-01-06 14:39:04 +0530 | [diff] [blame] | 6 | * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 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 | * |
| 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 |
| 17 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 18 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 19 | */ |
| 20 | |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 21 | #ifndef __SFE_IPV4_H |
| 22 | #define __SFE_IPV4_H |
| 23 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 24 | #define SFE_IPV4_DSCP_MASK 0x3 |
| 25 | #define SFE_IPV4_DSCP_SHIFT 2 |
Tian Yang | d98d91b | 2022-03-09 14:50:12 -0800 | [diff] [blame] | 26 | #include <linux/version.h> |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 27 | |
| 28 | /* |
Ajay Abraham | e33abd5 | 2023-10-12 07:20:48 -0600 | [diff] [blame] | 29 | * By default Linux IP header and transport layer header structures are |
| 30 | * unpacked, assuming that such headers should be 32-bit aligned. |
| 31 | * Unfortunately some wireless adaptors can't cope with this requirement and |
| 32 | * some CPUs can't handle misaligned accesses. For those platforms we |
| 33 | * define SFE_IPV4_UNALIGNED_IP_HEADER and mark the structures as packed. |
| 34 | * When we do this the compiler will generate slightly worse code than for the |
| 35 | * aligned case (on most platforms) but will be much quicker than fixing |
| 36 | * things up in an unaligned trap handler. |
| 37 | */ |
| 38 | #define SFE_IPV4_UNALIGNED_IP_HEADER 1 |
| 39 | #if SFE_IPV4_UNALIGNED_IP_HEADER |
| 40 | #define SFE_IPV4_UNALIGNED_STRUCT __attribute__((packed)) |
| 41 | #else |
| 42 | #define SFE_IPV4_UNALIGNED_STRUCT |
| 43 | #endif |
| 44 | |
| 45 | /* |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 46 | * Specifies the lower bound on ACK numbers carried in the TCP header |
| 47 | */ |
| 48 | #define SFE_IPV4_TCP_MAX_ACK_WINDOW 65520 |
| 49 | |
| 50 | /* |
| 51 | * IPv4 TCP connection match additional data. |
| 52 | */ |
| 53 | struct sfe_ipv4_tcp_connection_match { |
| 54 | u8 win_scale; /* Window scale */ |
| 55 | u32 max_win; /* Maximum window size seen */ |
| 56 | u32 end; /* Sequence number of the next byte to send (seq + segment length) */ |
| 57 | u32 max_end; /* Sequence number of the last byte to ack */ |
| 58 | }; |
| 59 | |
Ajay Abraham | e33abd5 | 2023-10-12 07:20:48 -0600 | [diff] [blame] | 60 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 61 | /* |
| 62 | * Bit flags for IPv4 connection matching entry. |
| 63 | */ |
| 64 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_SRC (1<<0) |
| 65 | /* Perform source translation */ |
| 66 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_DEST (1<<1) |
| 67 | /* Perform destination translation */ |
| 68 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_NO_SEQ_CHECK (1<<2) |
| 69 | /* Ignore TCP sequence numbers */ |
| 70 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_WRITE_FAST_ETH_HDR (1<<3) |
| 71 | /* Fast Ethernet header write */ |
| 72 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_WRITE_L2_HDR (1<<4) |
| 73 | /* Fast Ethernet header write */ |
| 74 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_PRIORITY_REMARK (1<<5) |
| 75 | /* remark priority of SKB */ |
| 76 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_DSCP_REMARK (1<<6) |
| 77 | /* remark DSCP of packet */ |
Ratheesh Kannoth | a3cf0e0 | 2021-12-09 09:44:10 +0530 | [diff] [blame] | 78 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_CSUM_OFFLOAD (1<<7) |
| 79 | /* checksum offload.*/ |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 80 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_PPPOE_DECAP (1<<8) |
| 81 | /* Indicates that PPPoE should be decapsulated */ |
| 82 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_PPPOE_ENCAP (1<<9) |
| 83 | /* Indicates that PPPoE should be encapsulated */ |
Ratheesh Kannoth | 71fc51e | 2022-01-05 10:02:47 +0530 | [diff] [blame] | 84 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_BRIDGE_FLOW (1<<10) |
| 85 | /* Bridge flow */ |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 86 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_MARK (1<<11) |
| 87 | /* skb mark of the packet */ |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 88 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_INSERT_EGRESS_VLAN_TAG (1<<12) |
| 89 | /* Insert VLAN tag */ |
Ratheesh Kannoth | 5dee377 | 2022-01-18 11:27:14 +0530 | [diff] [blame] | 90 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_SRC_INTERFACE_CHECK (1<<13) |
Murat Sezgin | 9c53897 | 2022-05-17 13:33:17 -0700 | [diff] [blame] | 91 | /* Source interface check */ |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 92 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_PASSTHROUGH (1<<14) |
| 93 | /* passthrough flow: encap/decap to be skipped for this flow */ |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 94 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_FAST_XMIT (1<<15) |
| 95 | /* skb go fast xmit */ |
| 96 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_FAST_XMIT_FLOW_CHECKED (1<<16) |
| 97 | /* Fast xmit flow checked or not */ |
| 98 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_FAST_XMIT_DEV_ADMISSION (1<<17) |
| 99 | /* Fast xmit may be possible for this flow, if SFE check passes */ |
Murat Sezgin | 9c53897 | 2022-05-17 13:33:17 -0700 | [diff] [blame] | 100 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_SRC_INTERFACE_CHECK_NO_FLUSH (1<<18) |
| 101 | /* Source interface check but do not flush the connection */ |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 102 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 103 | /* |
| 104 | * IPv4 connection matching structure. |
| 105 | */ |
| 106 | struct sfe_ipv4_connection_match { |
| 107 | /* |
| 108 | * References to other objects. |
| 109 | */ |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 110 | struct hlist_node hnode; |
| 111 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 112 | /* |
| 113 | * Characteristics that identify flows that match this rule. |
| 114 | */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 115 | __be32 match_src_ip; /* Source IP address */ |
| 116 | __be32 match_dest_ip; /* Destination IP address */ |
| 117 | __be16 match_src_port; /* Source port/connection ident */ |
| 118 | __be16 match_dest_port; /* Destination port/connection ident */ |
Sourav Poddar | 345e26a | 2022-07-26 17:53:08 +0530 | [diff] [blame] | 119 | u8 match_protocol; /* Protocol */ |
| 120 | u32 flags; /* Bit flags */ |
| 121 | u16 xmit_dest_mac[ETH_ALEN / 2]; |
| 122 | /* Destination MAC address to use when forwarding */ |
| 123 | u16 xmit_src_mac[ETH_ALEN / 2]; |
| 124 | /* Source MAC address to use when forwarding */ |
| 125 | struct net_device *xmit_dev; /* Network device on which to transmit */ |
| 126 | /* |
| 127 | * xmit device's feature |
| 128 | */ |
| 129 | netdev_features_t features; |
| 130 | /* |
| 131 | * Packet transmit information. |
| 132 | */ |
| 133 | unsigned short int xmit_dev_mtu; |
| 134 | /* Interface MTU */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 135 | |
Sourav Poddar | 345e26a | 2022-07-26 17:53:08 +0530 | [diff] [blame] | 136 | /* |
| 137 | * Size of all needed L2 headers |
| 138 | */ |
| 139 | u16 l2_hdr_size; |
| 140 | |
| 141 | /* |
| 142 | * Stats recorded in a sync period. These stats will be added to |
| 143 | * rx_packet_count64/rx_byte_count64 after a sync period. |
| 144 | */ |
| 145 | atomic_t rx_packet_count; |
| 146 | atomic_t rx_byte_count; |
| 147 | |
| 148 | struct net_device *match_dev; /* Network device */ |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 149 | |
Ajay Abraham | e33abd5 | 2023-10-12 07:20:48 -0600 | [diff] [blame] | 150 | #ifdef CONFIG_NETFILTER_CP_FLOWSTATS |
| 151 | u32 cp_fs_original; /* Flag indicating if this is original */ |
| 152 | u32 last_seq_num; /* Sequence number saved*/ |
| 153 | u32 last_seq_time; |
| 154 | u32 tot_delta; /* added samples of latency |
| 155 | to compute average*/ |
| 156 | u32 tot_delta_square; /* sum of squares of delta; |
| 157 | to calculate std deviation.*/ |
| 158 | u32 num_samples; |
| 159 | /* |
| 160 | * Stats used for Latency flowstats. |
| 161 | */ |
Ajay Abraham | 488a3e6 | 2023-11-27 11:14:17 -0700 | [diff] [blame^] | 162 | atomic64_t fs_rx_packet_count; |
| 163 | atomic64_t fs_rx_byte_count; |
Ajay Abraham | e33abd5 | 2023-10-12 07:20:48 -0600 | [diff] [blame] | 164 | #endif //CONFIG_NETFILTER_CP_FLOWSTATS |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 165 | /* |
| 166 | * Control the operations of the match. |
| 167 | */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 168 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 169 | u32 flow_cookie; /* used flow cookie, for debug */ |
| 170 | #endif |
| 171 | #ifdef CONFIG_XFRM |
| 172 | u32 flow_accel; /* The flow accelerated or not */ |
| 173 | #endif |
| 174 | |
Sourav Poddar | 345e26a | 2022-07-26 17:53:08 +0530 | [diff] [blame] | 175 | struct sfe_ipv4_connection *connection; |
| 176 | struct sfe_ipv4_connection_match *counter_match; |
| 177 | /* Matches the flow in the opposite direction as the one in *connection */ |
| 178 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 179 | /* |
| 180 | * Connection state that we track once we match. |
| 181 | */ |
| 182 | union { /* Protocol-specific state */ |
| 183 | struct sfe_ipv4_tcp_connection_match tcp; |
| 184 | } protocol_state; |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 185 | |
Sourav Poddar | 345e26a | 2022-07-26 17:53:08 +0530 | [diff] [blame] | 186 | struct udp_sock *up; /* Stores UDP sock information; valid only in decap path */ |
| 187 | |
| 188 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0)) |
| 189 | const struct net_protocol *proto; /* stores protocol handler; valid only in decap path */ |
| 190 | #else |
| 191 | struct net_protocol *proto; /* stores protocol handler; valid only in decap path */ |
| 192 | #endif |
| 193 | |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 194 | /* |
| 195 | * VLAN headers |
| 196 | */ |
| 197 | struct sfe_vlan_hdr ingress_vlan_hdr[SFE_MAX_VLAN_DEPTH]; |
| 198 | struct sfe_vlan_hdr egress_vlan_hdr[SFE_MAX_VLAN_DEPTH]; |
| 199 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 200 | /* |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 201 | * Packet translation information. |
| 202 | */ |
| 203 | __be32 xlate_src_ip; /* Address after source translation */ |
| 204 | __be16 xlate_src_port; /* Port/connection ident after source translation */ |
| 205 | u16 xlate_src_csum_adjustment; |
| 206 | /* Transport layer checksum adjustment after source translation */ |
| 207 | u16 xlate_src_partial_csum_adjustment; |
| 208 | /* Transport layer pseudo header checksum adjustment after source translation */ |
| 209 | |
| 210 | __be32 xlate_dest_ip; /* Address after destination translation */ |
| 211 | __be16 xlate_dest_port; /* Port/connection ident after destination translation */ |
| 212 | u16 xlate_dest_csum_adjustment; |
| 213 | /* Transport layer checksum adjustment after destination translation */ |
| 214 | u16 xlate_dest_partial_csum_adjustment; |
| 215 | /* Transport layer pseudo header checksum adjustment after destination translation */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 216 | /* |
| 217 | * QoS information |
| 218 | */ |
| 219 | u32 priority; |
| 220 | u32 dscp; |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 221 | u32 mark; /* mark for outgoing packet */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 222 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 223 | |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 224 | u8 ingress_vlan_hdr_cnt; /* Ingress active vlan headers count */ |
| 225 | u8 egress_vlan_hdr_cnt; /* Egress active vlan headers count */ |
| 226 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 227 | /* |
| 228 | * Summary stats. |
| 229 | */ |
| 230 | u64 rx_packet_count64; |
| 231 | u64 rx_byte_count64; |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 232 | |
| 233 | /* |
| 234 | * PPPoE information |
| 235 | */ |
| 236 | u16 pppoe_session_id; |
| 237 | u8 pppoe_remote_mac[ETH_ALEN]; |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 238 | |
Tian Yang | 46d6eb0 | 2022-03-31 10:26:16 -0700 | [diff] [blame] | 239 | struct net_device *top_interface_dev; /* Used by tun6rd to store decap VLAN netdevice.*/ |
| 240 | |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 241 | bool sawf_valid; /* Indicates mark has valid SAWF information */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | /* |
| 245 | * Per-connection data structure. |
| 246 | */ |
| 247 | struct sfe_ipv4_connection { |
| 248 | struct sfe_ipv4_connection *next; |
| 249 | /* Pointer to the next entry in a hash chain */ |
| 250 | struct sfe_ipv4_connection *prev; |
| 251 | /* Pointer to the previous entry in a hash chain */ |
| 252 | int protocol; /* IP protocol number */ |
| 253 | __be32 src_ip; /* Src IP addr pre-translation */ |
| 254 | __be32 src_ip_xlate; /* Src IP addr post-translation */ |
| 255 | __be32 dest_ip; /* Dest IP addr pre-translation */ |
| 256 | __be32 dest_ip_xlate; /* Dest IP addr post-translation */ |
| 257 | __be16 src_port; /* Src port pre-translation */ |
| 258 | __be16 src_port_xlate; /* Src port post-translation */ |
| 259 | __be16 dest_port; /* Dest port pre-translation */ |
| 260 | __be16 dest_port_xlate; /* Dest port post-translation */ |
| 261 | struct sfe_ipv4_connection_match *original_match; |
| 262 | /* Original direction matching structure */ |
| 263 | struct net_device *original_dev; |
| 264 | /* Original direction source device */ |
| 265 | struct sfe_ipv4_connection_match *reply_match; |
| 266 | /* Reply direction matching structure */ |
| 267 | struct net_device *reply_dev; /* Reply direction source device */ |
| 268 | u64 last_sync_jiffies; /* Jiffies count for the last sync */ |
| 269 | struct sfe_ipv4_connection *all_connections_next; |
| 270 | /* Pointer to the next entry in the list of all connections */ |
| 271 | struct sfe_ipv4_connection *all_connections_prev; |
| 272 | /* Pointer to the previous entry in the list of all connections */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 273 | u32 debug_read_seq; /* sequence number for debug dump */ |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 274 | bool removed; /* Indicates the connection is removed */ |
| 275 | struct rcu_head rcu; /* delay rcu free */ |
Ajay Abraham | e33abd5 | 2023-10-12 07:20:48 -0600 | [diff] [blame] | 276 | #ifdef CONFIG_NETFILTER_CP_FLOWSTATS |
| 277 | int start_time; /* Jiffies to track when the flow started */ |
| 278 | #endif |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 279 | }; |
| 280 | |
Ajay Abraham | e33abd5 | 2023-10-12 07:20:48 -0600 | [diff] [blame] | 281 | #ifdef CONFIG_NETFILTER_CP_FLOWSTATS /* CP_LATENCY_IP*/ |
| 282 | #define MIN_IP_PKT_SIZE 84 |
| 283 | #define CP_IP_REC_TIMEOUT_SFE 15 /* In seconds: */ |
| 284 | #define MSEC_IN_SEC 1000 |
| 285 | #define MAX_RTT_THRESHOLD (700)*(HZ)/(MSEC_IN_SEC) |
| 286 | #endif |
| 287 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 288 | /* |
| 289 | * IPv4 connections and hash table size information. |
| 290 | */ |
| 291 | #define SFE_IPV4_CONNECTION_HASH_SHIFT 12 |
| 292 | #define SFE_IPV4_CONNECTION_HASH_SIZE (1 << SFE_IPV4_CONNECTION_HASH_SHIFT) |
| 293 | #define SFE_IPV4_CONNECTION_HASH_MASK (SFE_IPV4_CONNECTION_HASH_SIZE - 1) |
| 294 | |
| 295 | enum sfe_ipv4_exception_events { |
| 296 | SFE_IPV4_EXCEPTION_EVENT_UDP_HEADER_INCOMPLETE, |
| 297 | SFE_IPV4_EXCEPTION_EVENT_UDP_NO_CONNECTION, |
| 298 | SFE_IPV4_EXCEPTION_EVENT_UDP_IP_OPTIONS_OR_INITIAL_FRAGMENT, |
| 299 | SFE_IPV4_EXCEPTION_EVENT_UDP_SMALL_TTL, |
| 300 | SFE_IPV4_EXCEPTION_EVENT_UDP_NEEDS_FRAGMENTATION, |
| 301 | SFE_IPV4_EXCEPTION_EVENT_TCP_HEADER_INCOMPLETE, |
| 302 | SFE_IPV4_EXCEPTION_EVENT_TCP_NO_CONNECTION_SLOW_FLAGS, |
| 303 | SFE_IPV4_EXCEPTION_EVENT_TCP_NO_CONNECTION_FAST_FLAGS, |
| 304 | SFE_IPV4_EXCEPTION_EVENT_TCP_IP_OPTIONS_OR_INITIAL_FRAGMENT, |
| 305 | SFE_IPV4_EXCEPTION_EVENT_TCP_SMALL_TTL, |
| 306 | SFE_IPV4_EXCEPTION_EVENT_TCP_NEEDS_FRAGMENTATION, |
| 307 | SFE_IPV4_EXCEPTION_EVENT_TCP_FLAGS, |
| 308 | SFE_IPV4_EXCEPTION_EVENT_TCP_SEQ_EXCEEDS_RIGHT_EDGE, |
| 309 | SFE_IPV4_EXCEPTION_EVENT_TCP_SMALL_DATA_OFFS, |
| 310 | SFE_IPV4_EXCEPTION_EVENT_TCP_BAD_SACK, |
| 311 | SFE_IPV4_EXCEPTION_EVENT_TCP_BIG_DATA_OFFS, |
| 312 | SFE_IPV4_EXCEPTION_EVENT_TCP_SEQ_BEFORE_LEFT_EDGE, |
| 313 | SFE_IPV4_EXCEPTION_EVENT_TCP_ACK_EXCEEDS_RIGHT_EDGE, |
| 314 | SFE_IPV4_EXCEPTION_EVENT_TCP_ACK_BEFORE_LEFT_EDGE, |
| 315 | SFE_IPV4_EXCEPTION_EVENT_ICMP_HEADER_INCOMPLETE, |
| 316 | SFE_IPV4_EXCEPTION_EVENT_ICMP_UNHANDLED_TYPE, |
| 317 | SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_HEADER_INCOMPLETE, |
| 318 | SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_NON_V4, |
| 319 | SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_IP_OPTIONS_INCOMPLETE, |
| 320 | SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_UDP_HEADER_INCOMPLETE, |
| 321 | SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_TCP_HEADER_INCOMPLETE, |
| 322 | SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_UNHANDLED_PROTOCOL, |
| 323 | SFE_IPV4_EXCEPTION_EVENT_ICMP_NO_CONNECTION, |
| 324 | SFE_IPV4_EXCEPTION_EVENT_ICMP_FLUSHED_CONNECTION, |
| 325 | SFE_IPV4_EXCEPTION_EVENT_HEADER_INCOMPLETE, |
Ratheesh Kannoth | 43d64f8 | 2021-10-20 08:23:29 +0530 | [diff] [blame] | 326 | SFE_IPV4_EXCEPTION_EVENT_HEADER_CSUM_BAD, |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 327 | SFE_IPV4_EXCEPTION_EVENT_BAD_TOTAL_LENGTH, |
| 328 | SFE_IPV4_EXCEPTION_EVENT_NON_V4, |
| 329 | SFE_IPV4_EXCEPTION_EVENT_NON_INITIAL_FRAGMENT, |
| 330 | SFE_IPV4_EXCEPTION_EVENT_DATAGRAM_INCOMPLETE, |
| 331 | SFE_IPV4_EXCEPTION_EVENT_IP_OPTIONS_INCOMPLETE, |
| 332 | SFE_IPV4_EXCEPTION_EVENT_UNHANDLED_PROTOCOL, |
Guduri Prathyusha | 5f27e23 | 2022-01-06 14:39:04 +0530 | [diff] [blame] | 333 | SFE_IPV4_EXCEPTION_EVENT_NO_HEADROOM, |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 334 | SFE_IPV4_EXCEPTION_EVENT_INVALID_PPPOE_SESSION, |
| 335 | SFE_IPV4_EXCEPTION_EVENT_INCORRECT_PPPOE_PARSING, |
| 336 | SFE_IPV4_EXCEPTION_EVENT_PPPOE_NOT_SET_IN_CME, |
Wayne Tan | 1cabbf1 | 2022-05-01 13:01:45 -0700 | [diff] [blame] | 337 | SFE_IPV4_EXCEPTION_EVENT_PPPOE_BR_NOT_IN_CME, |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 338 | SFE_IPV4_EXCEPTION_EVENT_INGRESS_VLAN_TAG_MISMATCH, |
Ratheesh Kannoth | 5dee377 | 2022-01-18 11:27:14 +0530 | [diff] [blame] | 339 | SFE_IPV4_EXCEPTION_EVENT_INVALID_SRC_IFACE, |
Tian Yang | d98d91b | 2022-03-09 14:50:12 -0800 | [diff] [blame] | 340 | SFE_IPV4_EXCEPTION_EVENT_TUN6RD_NO_CONNECTION, |
| 341 | SFE_IPV4_EXCEPTION_EVENT_TUN6RD_NEEDS_FRAGMENTATION, |
| 342 | SFE_IPV4_EXCEPTION_EVENT_TUN6RD_SYNC_ON_FIND, |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 343 | SFE_IPV4_EXCEPTION_EVENT_GRE_HEADER_INCOMPLETE, |
| 344 | SFE_IPV4_EXCEPTION_EVENT_GRE_NO_CONNECTION, |
| 345 | SFE_IPV4_EXCEPTION_EVENT_GRE_IP_OPTIONS_OR_INITIAL_FRAGMENT, |
| 346 | SFE_IPV4_EXCEPTION_EVENT_GRE_SMALL_TTL, |
| 347 | SFE_IPV4_EXCEPTION_EVENT_GRE_NEEDS_FRAGMENTATION, |
Suhas N Bhargav | 592e64c | 2021-11-12 16:53:08 +0530 | [diff] [blame] | 348 | SFE_IPV4_EXCEPTION_EVENT_ESP_NO_CONNECTION, |
| 349 | SFE_IPV4_EXCEPTION_EVENT_ESP_IP_OPTIONS_OR_INITIAL_FRAGMENT, |
| 350 | SFE_IPV4_EXCEPTION_EVENT_ESP_NEEDS_FRAGMENTATION, |
| 351 | SFE_IPV4_EXCEPTION_EVENT_ESP_SMALL_TTL, |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 352 | SFE_IPV4_EXCEPTION_EVENT_LAST |
| 353 | }; |
| 354 | |
| 355 | /* |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 356 | * per CPU stats |
| 357 | */ |
| 358 | struct sfe_ipv4_stats { |
| 359 | /* |
| 360 | * Stats recorded in a sync period. These stats will be added to |
| 361 | * connection_xxx64 after a sync period. |
| 362 | */ |
| 363 | u64 connection_create_requests64; |
| 364 | /* Number of IPv4 connection create requests */ |
| 365 | u64 connection_create_collisions64; |
| 366 | /* Number of IPv4 connection create requests that collided with existing hash table entries */ |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 367 | u64 connection_create_failures64; |
| 368 | /* Number of IPv4 connection create requests that failed */ |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 369 | u64 connection_destroy_requests64; |
| 370 | /* Number of IPv4 connection destroy requests */ |
| 371 | u64 connection_destroy_misses64; |
| 372 | /* Number of IPv4 connection destroy requests that missed our hash table */ |
| 373 | u64 connection_match_hash_hits64; |
| 374 | /* Number of IPv4 connection match hash hits */ |
| 375 | u64 connection_match_hash_reorders64; |
| 376 | /* Number of IPv4 connection match hash reorders */ |
| 377 | u64 connection_flushes64; /* Number of IPv4 connection flushes */ |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 378 | u64 packets_dropped64; /* Number of IPv4 packets dropped */ |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 379 | u64 packets_forwarded64; /* Number of IPv4 packets forwarded */ |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 380 | u64 packets_fast_xmited64; /* Number of IPv4 packets fast transmited */ |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 381 | u64 packets_not_forwarded64; /* Number of IPv4 packets not forwarded */ |
| 382 | u64 exception_events64[SFE_IPV4_EXCEPTION_EVENT_LAST]; |
Guduri Prathyusha | 034d635 | 2022-01-12 16:49:04 +0530 | [diff] [blame] | 383 | u64 pppoe_encap_packets_forwarded64; /* Number of IPv4 PPPoE encap packets forwarded */ |
| 384 | u64 pppoe_decap_packets_forwarded64; /* Number of IPv4 PPPoE decap packets forwarded */ |
| 385 | u64 pppoe_bridge_packets_forwarded64; /* Number of IPv4 PPPoE bridge packets forwarded */ |
Wayne Tan | 1cabbf1 | 2022-05-01 13:01:45 -0700 | [diff] [blame] | 386 | u64 pppoe_bridge_packets_3tuple_forwarded64; /* Number of IPv4 PPPoE bridge packets forwarded based on 3-tuple info */ |
Vinod Kumar Reddy | 7fe5778 | 2022-08-26 14:43:49 +0530 | [diff] [blame] | 387 | u64 connection_create_requests_overflow64; /* Number of IPV4 connection create requests after reaching max limit */ |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 388 | }; |
| 389 | |
| 390 | /* |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 391 | * sfe_ipv4_per_service_class_stats |
| 392 | * Per service class stats |
| 393 | */ |
| 394 | struct sfe_ipv4_per_service_class_stats { |
| 395 | u64 tx_bytes; /* Byte count */ |
| 396 | u64 tx_packets; /* Packet count */ |
| 397 | seqcount_t seq; /* seq lock for read/write protection */ |
| 398 | /* |
| 399 | * TODO : add entries to be collected later. |
| 400 | */ |
| 401 | }; |
| 402 | |
| 403 | /* |
| 404 | * sfe_ipv4_service_class_stats_db |
| 405 | * stat entries for each service class. |
| 406 | */ |
| 407 | struct sfe_ipv4_service_class_stats_db { |
| 408 | struct sfe_ipv4_per_service_class_stats psc_stats[SFE_MAX_SERVICE_CLASS_ID]; |
| 409 | /* Per service class stats */ |
| 410 | }; |
| 411 | |
| 412 | /* |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 413 | * Per-module structure. |
| 414 | */ |
| 415 | struct sfe_ipv4 { |
| 416 | spinlock_t lock; /* Lock for SMP correctness */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 417 | struct sfe_ipv4_connection *all_connections_head; |
| 418 | /* Head of the list of all connections */ |
| 419 | struct sfe_ipv4_connection *all_connections_tail; |
| 420 | /* Tail of the list of all connections */ |
| 421 | unsigned int num_connections; /* Number of connections */ |
Ken Zhu | 137722d | 2021-09-23 17:57:36 -0700 | [diff] [blame] | 422 | struct delayed_work sync_dwork; /* Work to sync the statistics */ |
| 423 | unsigned int work_cpu; /* The core to run stats sync on */ |
| 424 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 425 | sfe_sync_rule_callback_t __rcu sync_rule_callback; |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 426 | sfe_ipv4_many_sync_callback_t __rcu many_sync_callback; |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 427 | /* Callback function registered by a connection manager for stats syncing */ |
| 428 | struct sfe_ipv4_connection *conn_hash[SFE_IPV4_CONNECTION_HASH_SIZE]; |
| 429 | /* Connection hash table */ |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 430 | |
| 431 | struct hlist_head hlist_conn_match_hash_head[SFE_IPV4_CONNECTION_HASH_SIZE]; |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 432 | /* Connection match hash table */ |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 433 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 434 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 435 | struct sfe_flow_cookie_entry sfe_flow_cookie_table[SFE_FLOW_COOKIE_SIZE]; |
| 436 | /* flow cookie table*/ |
| 437 | flow_cookie_set_func_t flow_cookie_set_func; |
| 438 | /* function used to configure flow cookie in hardware*/ |
| 439 | int flow_cookie_enable; |
| 440 | /* Enable/disable flow cookie at runtime */ |
| 441 | #endif |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 442 | struct sfe_ipv4_service_class_stats_db __percpu *stats_pcpu_psc; |
| 443 | /* Database to maintain per cpu per service class statistics */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 444 | |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 445 | struct sfe_ipv4_stats __percpu *stats_pcpu; |
| 446 | /* Per CPU statistics. */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 447 | |
Ken Zhu | dc42367 | 2021-09-02 18:27:01 -0700 | [diff] [blame] | 448 | struct sfe_ipv4_connection *wc_next; /* Connection list walk pointer for stats sync */ |
| 449 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 450 | /* |
| 451 | * Control state. |
| 452 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 453 | struct kobject *sys_ipv4; /* sysfs linkage */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 454 | int debug_dev; /* Major number of the debug char device */ |
| 455 | u32 debug_read_seq; /* sequence number for debug dump */ |
| 456 | }; |
| 457 | |
| 458 | /* |
| 459 | * Enumeration of the XML output. |
| 460 | */ |
| 461 | enum sfe_ipv4_debug_xml_states { |
| 462 | SFE_IPV4_DEBUG_XML_STATE_START, |
| 463 | SFE_IPV4_DEBUG_XML_STATE_CONNECTIONS_START, |
| 464 | SFE_IPV4_DEBUG_XML_STATE_CONNECTIONS_CONNECTION, |
| 465 | SFE_IPV4_DEBUG_XML_STATE_CONNECTIONS_END, |
| 466 | SFE_IPV4_DEBUG_XML_STATE_EXCEPTIONS_START, |
| 467 | SFE_IPV4_DEBUG_XML_STATE_EXCEPTIONS_EXCEPTION, |
| 468 | SFE_IPV4_DEBUG_XML_STATE_EXCEPTIONS_END, |
| 469 | SFE_IPV4_DEBUG_XML_STATE_STATS, |
| 470 | SFE_IPV4_DEBUG_XML_STATE_END, |
| 471 | SFE_IPV4_DEBUG_XML_STATE_DONE |
| 472 | }; |
| 473 | |
| 474 | /* |
| 475 | * XML write state. |
| 476 | */ |
| 477 | struct sfe_ipv4_debug_xml_write_state { |
| 478 | enum sfe_ipv4_debug_xml_states state; |
| 479 | /* XML output file state machine state */ |
| 480 | int iter_exception; /* Next exception iterator */ |
| 481 | }; |
| 482 | |
| 483 | typedef bool (*sfe_ipv4_debug_xml_write_method_t)(struct sfe_ipv4 *si, char *buffer, char *msg, size_t *length, |
| 484 | int *total_read, struct sfe_ipv4_debug_xml_write_state *ws); |
| 485 | |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 486 | u16 sfe_ipv4_gen_ip_csum(struct iphdr *iph); |
Jackson Bockus | 3fafbf3 | 2022-02-13 17:15:26 -0800 | [diff] [blame] | 487 | bool sfe_ipv4_service_class_stats_get(uint8_t sid, uint64_t *bytes, uint64_t *packets); |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 488 | void sfe_ipv4_service_class_stats_inc(struct sfe_ipv4 *si, uint8_t sid, uint64_t bytes); |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 489 | void sfe_ipv4_exception_stats_inc(struct sfe_ipv4 *si, enum sfe_ipv4_exception_events reason); |
| 490 | bool sfe_ipv4_remove_connection(struct sfe_ipv4 *si, struct sfe_ipv4_connection *c); |
| 491 | void sfe_ipv4_flush_connection(struct sfe_ipv4 *si, struct sfe_ipv4_connection *c, sfe_sync_reason_t reason); |
Ken Zhu | 88c5815 | 2021-12-09 15:12:06 -0800 | [diff] [blame] | 492 | void sfe_ipv4_sync_status(struct sfe_ipv4 *si, struct sfe_ipv4_connection *c, sfe_sync_reason_t reason); |
Sourav Poddar | 7297812 | 2022-08-09 12:44:50 +0530 | [diff] [blame] | 493 | #if defined(SFE_RFS_SUPPORTED) |
| 494 | void sfe_ipv4_fill_connection_dev(struct sfe_ipv4_rule_destroy_msg *msg, struct net_device **original_dev, struct net_device **reply_dev); |
| 495 | #endif |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 496 | struct sfe_ipv4_connection_match * |
| 497 | sfe_ipv4_find_connection_match_rcu(struct sfe_ipv4 *si, struct net_device *dev, u8 protocol, |
| 498 | __be32 src_ip, __be16 src_port, |
| 499 | __be32 dest_ip, __be16 dest_port); |
| 500 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 501 | void sfe_ipv4_exit(void); |
| 502 | int sfe_ipv4_init(void); |
Wayne Tan | a5817c0 | 2022-10-27 16:48:29 -0700 | [diff] [blame] | 503 | bool sfe_ipv4_cancel_delayed_work_sync(void); |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 504 | |
| 505 | #endif /* __SFE_IPV4_H */ |