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 |
| 26 | |
| 27 | /* |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 28 | * Specifies the lower bound on ACK numbers carried in the TCP header |
| 29 | */ |
| 30 | #define SFE_IPV4_TCP_MAX_ACK_WINDOW 65520 |
| 31 | |
| 32 | /* |
| 33 | * IPv4 TCP connection match additional data. |
| 34 | */ |
| 35 | struct sfe_ipv4_tcp_connection_match { |
| 36 | u8 win_scale; /* Window scale */ |
| 37 | u32 max_win; /* Maximum window size seen */ |
| 38 | u32 end; /* Sequence number of the next byte to send (seq + segment length) */ |
| 39 | u32 max_end; /* Sequence number of the last byte to ack */ |
| 40 | }; |
| 41 | |
| 42 | /* |
| 43 | * Bit flags for IPv4 connection matching entry. |
| 44 | */ |
| 45 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_SRC (1<<0) |
| 46 | /* Perform source translation */ |
| 47 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_DEST (1<<1) |
| 48 | /* Perform destination translation */ |
| 49 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_NO_SEQ_CHECK (1<<2) |
| 50 | /* Ignore TCP sequence numbers */ |
| 51 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_WRITE_FAST_ETH_HDR (1<<3) |
| 52 | /* Fast Ethernet header write */ |
| 53 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_WRITE_L2_HDR (1<<4) |
| 54 | /* Fast Ethernet header write */ |
| 55 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_PRIORITY_REMARK (1<<5) |
| 56 | /* remark priority of SKB */ |
| 57 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_DSCP_REMARK (1<<6) |
| 58 | /* remark DSCP of packet */ |
Ratheesh Kannoth | a3cf0e0 | 2021-12-09 09:44:10 +0530 | [diff] [blame] | 59 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_CSUM_OFFLOAD (1<<7) |
| 60 | /* checksum offload.*/ |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 61 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_PPPOE_DECAP (1<<8) |
| 62 | /* Indicates that PPPoE should be decapsulated */ |
| 63 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_PPPOE_ENCAP (1<<9) |
| 64 | /* Indicates that PPPoE should be encapsulated */ |
Ratheesh Kannoth | 71fc51e | 2022-01-05 10:02:47 +0530 | [diff] [blame] | 65 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_BRIDGE_FLOW (1<<10) |
| 66 | /* Bridge flow */ |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 67 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_MARK (1<<11) |
| 68 | /* skb mark of the packet */ |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 69 | #define SFE_IPV4_CONNECTION_MATCH_FLAG_INSERT_EGRESS_VLAN_TAG (1<<12) |
| 70 | /* Insert VLAN tag */ |
| 71 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 72 | /* |
| 73 | * IPv4 connection matching structure. |
| 74 | */ |
| 75 | struct sfe_ipv4_connection_match { |
| 76 | /* |
| 77 | * References to other objects. |
| 78 | */ |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 79 | struct hlist_node hnode; |
| 80 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 81 | struct sfe_ipv4_connection *connection; |
| 82 | struct sfe_ipv4_connection_match *counter_match; |
| 83 | /* Matches the flow in the opposite direction as the one in *connection */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 84 | /* |
| 85 | * Characteristics that identify flows that match this rule. |
| 86 | */ |
| 87 | struct net_device *match_dev; /* Network device */ |
| 88 | u8 match_protocol; /* Protocol */ |
| 89 | __be32 match_src_ip; /* Source IP address */ |
| 90 | __be32 match_dest_ip; /* Destination IP address */ |
| 91 | __be16 match_src_port; /* Source port/connection ident */ |
| 92 | __be16 match_dest_port; /* Destination port/connection ident */ |
| 93 | |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 94 | struct udp_sock *up; /* Stores UDP sock information; valid only in decap path */ |
| 95 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 96 | /* |
| 97 | * Control the operations of the match. |
| 98 | */ |
| 99 | u32 flags; /* Bit flags */ |
| 100 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 101 | u32 flow_cookie; /* used flow cookie, for debug */ |
| 102 | #endif |
| 103 | #ifdef CONFIG_XFRM |
| 104 | u32 flow_accel; /* The flow accelerated or not */ |
| 105 | #endif |
| 106 | |
| 107 | /* |
| 108 | * Connection state that we track once we match. |
| 109 | */ |
| 110 | union { /* Protocol-specific state */ |
| 111 | struct sfe_ipv4_tcp_connection_match tcp; |
| 112 | } protocol_state; |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 113 | |
| 114 | /* |
| 115 | * VLAN headers |
| 116 | */ |
| 117 | struct sfe_vlan_hdr ingress_vlan_hdr[SFE_MAX_VLAN_DEPTH]; |
| 118 | struct sfe_vlan_hdr egress_vlan_hdr[SFE_MAX_VLAN_DEPTH]; |
| 119 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 120 | /* |
| 121 | * Stats recorded in a sync period. These stats will be added to |
| 122 | * rx_packet_count64/rx_byte_count64 after a sync period. |
| 123 | */ |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 124 | atomic_t rx_packet_count; |
| 125 | atomic_t rx_byte_count; |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 126 | |
| 127 | /* |
| 128 | * Packet translation information. |
| 129 | */ |
| 130 | __be32 xlate_src_ip; /* Address after source translation */ |
| 131 | __be16 xlate_src_port; /* Port/connection ident after source translation */ |
| 132 | u16 xlate_src_csum_adjustment; |
| 133 | /* Transport layer checksum adjustment after source translation */ |
| 134 | u16 xlate_src_partial_csum_adjustment; |
| 135 | /* Transport layer pseudo header checksum adjustment after source translation */ |
| 136 | |
| 137 | __be32 xlate_dest_ip; /* Address after destination translation */ |
| 138 | __be16 xlate_dest_port; /* Port/connection ident after destination translation */ |
| 139 | u16 xlate_dest_csum_adjustment; |
| 140 | /* Transport layer checksum adjustment after destination translation */ |
| 141 | u16 xlate_dest_partial_csum_adjustment; |
| 142 | /* Transport layer pseudo header checksum adjustment after destination translation */ |
| 143 | |
| 144 | /* |
| 145 | * QoS information |
| 146 | */ |
| 147 | u32 priority; |
| 148 | u32 dscp; |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 149 | u32 mark; /* mark for outgoing packet */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 150 | |
| 151 | /* |
| 152 | * Packet transmit information. |
| 153 | */ |
| 154 | struct net_device *xmit_dev; /* Network device on which to transmit */ |
| 155 | unsigned short int xmit_dev_mtu; |
| 156 | /* Interface MTU */ |
| 157 | u16 xmit_dest_mac[ETH_ALEN / 2]; |
| 158 | /* Destination MAC address to use when forwarding */ |
| 159 | u16 xmit_src_mac[ETH_ALEN / 2]; |
| 160 | /* Source MAC address to use when forwarding */ |
| 161 | |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 162 | u8 ingress_vlan_hdr_cnt; /* Ingress active vlan headers count */ |
| 163 | u8 egress_vlan_hdr_cnt; /* Egress active vlan headers count */ |
| 164 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 165 | /* |
| 166 | * Summary stats. |
| 167 | */ |
| 168 | u64 rx_packet_count64; |
| 169 | u64 rx_byte_count64; |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 170 | |
| 171 | /* |
| 172 | * PPPoE information |
| 173 | */ |
| 174 | u16 pppoe_session_id; |
| 175 | u8 pppoe_remote_mac[ETH_ALEN]; |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | * Size of all needed L2 headers |
| 179 | */ |
| 180 | u16 l2_hdr_size; |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | /* |
| 184 | * Per-connection data structure. |
| 185 | */ |
| 186 | struct sfe_ipv4_connection { |
| 187 | struct sfe_ipv4_connection *next; |
| 188 | /* Pointer to the next entry in a hash chain */ |
| 189 | struct sfe_ipv4_connection *prev; |
| 190 | /* Pointer to the previous entry in a hash chain */ |
| 191 | int protocol; /* IP protocol number */ |
| 192 | __be32 src_ip; /* Src IP addr pre-translation */ |
| 193 | __be32 src_ip_xlate; /* Src IP addr post-translation */ |
| 194 | __be32 dest_ip; /* Dest IP addr pre-translation */ |
| 195 | __be32 dest_ip_xlate; /* Dest IP addr post-translation */ |
| 196 | __be16 src_port; /* Src port pre-translation */ |
| 197 | __be16 src_port_xlate; /* Src port post-translation */ |
| 198 | __be16 dest_port; /* Dest port pre-translation */ |
| 199 | __be16 dest_port_xlate; /* Dest port post-translation */ |
| 200 | struct sfe_ipv4_connection_match *original_match; |
| 201 | /* Original direction matching structure */ |
| 202 | struct net_device *original_dev; |
| 203 | /* Original direction source device */ |
| 204 | struct sfe_ipv4_connection_match *reply_match; |
| 205 | /* Reply direction matching structure */ |
| 206 | struct net_device *reply_dev; /* Reply direction source device */ |
| 207 | u64 last_sync_jiffies; /* Jiffies count for the last sync */ |
| 208 | struct sfe_ipv4_connection *all_connections_next; |
| 209 | /* Pointer to the next entry in the list of all connections */ |
| 210 | struct sfe_ipv4_connection *all_connections_prev; |
| 211 | /* Pointer to the previous entry in the list of all connections */ |
| 212 | u32 mark; /* mark for outgoing packet */ |
| 213 | u32 debug_read_seq; /* sequence number for debug dump */ |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 214 | bool removed; /* Indicates the connection is removed */ |
| 215 | struct rcu_head rcu; /* delay rcu free */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 216 | }; |
| 217 | |
| 218 | /* |
| 219 | * IPv4 connections and hash table size information. |
| 220 | */ |
| 221 | #define SFE_IPV4_CONNECTION_HASH_SHIFT 12 |
| 222 | #define SFE_IPV4_CONNECTION_HASH_SIZE (1 << SFE_IPV4_CONNECTION_HASH_SHIFT) |
| 223 | #define SFE_IPV4_CONNECTION_HASH_MASK (SFE_IPV4_CONNECTION_HASH_SIZE - 1) |
| 224 | |
| 225 | enum sfe_ipv4_exception_events { |
| 226 | SFE_IPV4_EXCEPTION_EVENT_UDP_HEADER_INCOMPLETE, |
| 227 | SFE_IPV4_EXCEPTION_EVENT_UDP_NO_CONNECTION, |
| 228 | SFE_IPV4_EXCEPTION_EVENT_UDP_IP_OPTIONS_OR_INITIAL_FRAGMENT, |
| 229 | SFE_IPV4_EXCEPTION_EVENT_UDP_SMALL_TTL, |
| 230 | SFE_IPV4_EXCEPTION_EVENT_UDP_NEEDS_FRAGMENTATION, |
| 231 | SFE_IPV4_EXCEPTION_EVENT_TCP_HEADER_INCOMPLETE, |
| 232 | SFE_IPV4_EXCEPTION_EVENT_TCP_NO_CONNECTION_SLOW_FLAGS, |
| 233 | SFE_IPV4_EXCEPTION_EVENT_TCP_NO_CONNECTION_FAST_FLAGS, |
| 234 | SFE_IPV4_EXCEPTION_EVENT_TCP_IP_OPTIONS_OR_INITIAL_FRAGMENT, |
| 235 | SFE_IPV4_EXCEPTION_EVENT_TCP_SMALL_TTL, |
| 236 | SFE_IPV4_EXCEPTION_EVENT_TCP_NEEDS_FRAGMENTATION, |
| 237 | SFE_IPV4_EXCEPTION_EVENT_TCP_FLAGS, |
| 238 | SFE_IPV4_EXCEPTION_EVENT_TCP_SEQ_EXCEEDS_RIGHT_EDGE, |
| 239 | SFE_IPV4_EXCEPTION_EVENT_TCP_SMALL_DATA_OFFS, |
| 240 | SFE_IPV4_EXCEPTION_EVENT_TCP_BAD_SACK, |
| 241 | SFE_IPV4_EXCEPTION_EVENT_TCP_BIG_DATA_OFFS, |
| 242 | SFE_IPV4_EXCEPTION_EVENT_TCP_SEQ_BEFORE_LEFT_EDGE, |
| 243 | SFE_IPV4_EXCEPTION_EVENT_TCP_ACK_EXCEEDS_RIGHT_EDGE, |
| 244 | SFE_IPV4_EXCEPTION_EVENT_TCP_ACK_BEFORE_LEFT_EDGE, |
| 245 | SFE_IPV4_EXCEPTION_EVENT_ICMP_HEADER_INCOMPLETE, |
| 246 | SFE_IPV4_EXCEPTION_EVENT_ICMP_UNHANDLED_TYPE, |
| 247 | SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_HEADER_INCOMPLETE, |
| 248 | SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_NON_V4, |
| 249 | SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_IP_OPTIONS_INCOMPLETE, |
| 250 | SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_UDP_HEADER_INCOMPLETE, |
| 251 | SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_TCP_HEADER_INCOMPLETE, |
| 252 | SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_UNHANDLED_PROTOCOL, |
| 253 | SFE_IPV4_EXCEPTION_EVENT_ICMP_NO_CONNECTION, |
| 254 | SFE_IPV4_EXCEPTION_EVENT_ICMP_FLUSHED_CONNECTION, |
| 255 | SFE_IPV4_EXCEPTION_EVENT_HEADER_INCOMPLETE, |
Ratheesh Kannoth | 43d64f8 | 2021-10-20 08:23:29 +0530 | [diff] [blame] | 256 | SFE_IPV4_EXCEPTION_EVENT_HEADER_CSUM_BAD, |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 257 | SFE_IPV4_EXCEPTION_EVENT_BAD_TOTAL_LENGTH, |
| 258 | SFE_IPV4_EXCEPTION_EVENT_NON_V4, |
| 259 | SFE_IPV4_EXCEPTION_EVENT_NON_INITIAL_FRAGMENT, |
| 260 | SFE_IPV4_EXCEPTION_EVENT_DATAGRAM_INCOMPLETE, |
| 261 | SFE_IPV4_EXCEPTION_EVENT_IP_OPTIONS_INCOMPLETE, |
| 262 | SFE_IPV4_EXCEPTION_EVENT_UNHANDLED_PROTOCOL, |
Guduri Prathyusha | 5f27e23 | 2022-01-06 14:39:04 +0530 | [diff] [blame] | 263 | SFE_IPV4_EXCEPTION_EVENT_NO_HEADROOM, |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 264 | SFE_IPV4_EXCEPTION_EVENT_INVALID_PPPOE_SESSION, |
| 265 | SFE_IPV4_EXCEPTION_EVENT_INCORRECT_PPPOE_PARSING, |
| 266 | SFE_IPV4_EXCEPTION_EVENT_PPPOE_NOT_SET_IN_CME, |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 267 | SFE_IPV4_EXCEPTION_EVENT_INGRESS_VLAN_TAG_MISMATCH, |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 268 | SFE_IPV4_EXCEPTION_EVENT_LAST |
| 269 | }; |
| 270 | |
| 271 | /* |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 272 | * per CPU stats |
| 273 | */ |
| 274 | struct sfe_ipv4_stats { |
| 275 | /* |
| 276 | * Stats recorded in a sync period. These stats will be added to |
| 277 | * connection_xxx64 after a sync period. |
| 278 | */ |
| 279 | u64 connection_create_requests64; |
| 280 | /* Number of IPv4 connection create requests */ |
| 281 | u64 connection_create_collisions64; |
| 282 | /* 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] | 283 | u64 connection_create_failures64; |
| 284 | /* Number of IPv4 connection create requests that failed */ |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 285 | u64 connection_destroy_requests64; |
| 286 | /* Number of IPv4 connection destroy requests */ |
| 287 | u64 connection_destroy_misses64; |
| 288 | /* Number of IPv4 connection destroy requests that missed our hash table */ |
| 289 | u64 connection_match_hash_hits64; |
| 290 | /* Number of IPv4 connection match hash hits */ |
| 291 | u64 connection_match_hash_reorders64; |
| 292 | /* Number of IPv4 connection match hash reorders */ |
| 293 | u64 connection_flushes64; /* Number of IPv4 connection flushes */ |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 294 | u64 packets_dropped64; /* Number of IPv4 packets dropped */ |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 295 | u64 packets_forwarded64; /* Number of IPv4 packets forwarded */ |
| 296 | u64 packets_not_forwarded64; /* Number of IPv4 packets not forwarded */ |
| 297 | u64 exception_events64[SFE_IPV4_EXCEPTION_EVENT_LAST]; |
Guduri Prathyusha | 034d635 | 2022-01-12 16:49:04 +0530 | [diff] [blame^] | 298 | u64 pppoe_encap_packets_forwarded64; /* Number of IPv4 PPPoE encap packets forwarded */ |
| 299 | u64 pppoe_decap_packets_forwarded64; /* Number of IPv4 PPPoE decap packets forwarded */ |
| 300 | u64 pppoe_bridge_packets_forwarded64; /* Number of IPv4 PPPoE bridge packets forwarded */ |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 301 | }; |
| 302 | |
| 303 | /* |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 304 | * Per-module structure. |
| 305 | */ |
| 306 | struct sfe_ipv4 { |
| 307 | spinlock_t lock; /* Lock for SMP correctness */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 308 | struct sfe_ipv4_connection *all_connections_head; |
| 309 | /* Head of the list of all connections */ |
| 310 | struct sfe_ipv4_connection *all_connections_tail; |
| 311 | /* Tail of the list of all connections */ |
| 312 | unsigned int num_connections; /* Number of connections */ |
Ken Zhu | 137722d | 2021-09-23 17:57:36 -0700 | [diff] [blame] | 313 | struct delayed_work sync_dwork; /* Work to sync the statistics */ |
| 314 | unsigned int work_cpu; /* The core to run stats sync on */ |
| 315 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 316 | sfe_sync_rule_callback_t __rcu sync_rule_callback; |
| 317 | /* Callback function registered by a connection manager for stats syncing */ |
| 318 | struct sfe_ipv4_connection *conn_hash[SFE_IPV4_CONNECTION_HASH_SIZE]; |
| 319 | /* Connection hash table */ |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 320 | |
| 321 | 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] | 322 | /* Connection match hash table */ |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 323 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 324 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 325 | struct sfe_flow_cookie_entry sfe_flow_cookie_table[SFE_FLOW_COOKIE_SIZE]; |
| 326 | /* flow cookie table*/ |
| 327 | flow_cookie_set_func_t flow_cookie_set_func; |
| 328 | /* function used to configure flow cookie in hardware*/ |
| 329 | int flow_cookie_enable; |
| 330 | /* Enable/disable flow cookie at runtime */ |
| 331 | #endif |
| 332 | |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 333 | struct sfe_ipv4_stats __percpu *stats_pcpu; |
| 334 | /* Per CPU statistics. */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 335 | |
Ken Zhu | dc42367 | 2021-09-02 18:27:01 -0700 | [diff] [blame] | 336 | struct sfe_ipv4_connection *wc_next; /* Connection list walk pointer for stats sync */ |
| 337 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 338 | /* |
| 339 | * Control state. |
| 340 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 341 | struct kobject *sys_ipv4; /* sysfs linkage */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 342 | int debug_dev; /* Major number of the debug char device */ |
| 343 | u32 debug_read_seq; /* sequence number for debug dump */ |
| 344 | }; |
| 345 | |
| 346 | /* |
| 347 | * Enumeration of the XML output. |
| 348 | */ |
| 349 | enum sfe_ipv4_debug_xml_states { |
| 350 | SFE_IPV4_DEBUG_XML_STATE_START, |
| 351 | SFE_IPV4_DEBUG_XML_STATE_CONNECTIONS_START, |
| 352 | SFE_IPV4_DEBUG_XML_STATE_CONNECTIONS_CONNECTION, |
| 353 | SFE_IPV4_DEBUG_XML_STATE_CONNECTIONS_END, |
| 354 | SFE_IPV4_DEBUG_XML_STATE_EXCEPTIONS_START, |
| 355 | SFE_IPV4_DEBUG_XML_STATE_EXCEPTIONS_EXCEPTION, |
| 356 | SFE_IPV4_DEBUG_XML_STATE_EXCEPTIONS_END, |
| 357 | SFE_IPV4_DEBUG_XML_STATE_STATS, |
| 358 | SFE_IPV4_DEBUG_XML_STATE_END, |
| 359 | SFE_IPV4_DEBUG_XML_STATE_DONE |
| 360 | }; |
| 361 | |
| 362 | /* |
| 363 | * XML write state. |
| 364 | */ |
| 365 | struct sfe_ipv4_debug_xml_write_state { |
| 366 | enum sfe_ipv4_debug_xml_states state; |
| 367 | /* XML output file state machine state */ |
| 368 | int iter_exception; /* Next exception iterator */ |
| 369 | }; |
| 370 | |
| 371 | typedef bool (*sfe_ipv4_debug_xml_write_method_t)(struct sfe_ipv4 *si, char *buffer, char *msg, size_t *length, |
| 372 | int *total_read, struct sfe_ipv4_debug_xml_write_state *ws); |
| 373 | |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 374 | u16 sfe_ipv4_gen_ip_csum(struct iphdr *iph); |
| 375 | void sfe_ipv4_exception_stats_inc(struct sfe_ipv4 *si, enum sfe_ipv4_exception_events reason); |
| 376 | bool sfe_ipv4_remove_connection(struct sfe_ipv4 *si, struct sfe_ipv4_connection *c); |
| 377 | 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] | 378 | void sfe_ipv4_sync_status(struct sfe_ipv4 *si, struct sfe_ipv4_connection *c, sfe_sync_reason_t reason); |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 379 | |
| 380 | struct sfe_ipv4_connection_match * |
| 381 | sfe_ipv4_find_connection_match_rcu(struct sfe_ipv4 *si, struct net_device *dev, u8 protocol, |
| 382 | __be32 src_ip, __be16 src_port, |
| 383 | __be32 dest_ip, __be16 dest_port); |
| 384 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 385 | void sfe_ipv4_exit(void); |
| 386 | int sfe_ipv4_init(void); |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 387 | |
| 388 | #endif /* __SFE_IPV4_H */ |