Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 1 | /* |
| 2 | * sfe_ipv6.h |
| 3 | * Shortcut forwarding engine header file for IPv6. |
| 4 | * |
| 5 | * Copyright (c) 2015-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_IPV6_H |
| 22 | #define __SFE_IPV6_H |
| 23 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 24 | #define CHAR_DEV_MSG_SIZE 768 |
| 25 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 26 | #define SFE_IPV6_DSCP_MASK 0xf03f |
| 27 | #define SFE_IPV6_DSCP_SHIFT 2 |
| 28 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 29 | #define SFE_IPV6_FRAG_OFFSET 0xfff8 |
| 30 | |
| 31 | /* |
| 32 | * generic IPv6 extension header |
| 33 | */ |
| 34 | struct sfe_ipv6_ext_hdr { |
| 35 | __u8 next_hdr; |
| 36 | __u8 hdr_len; |
| 37 | __u8 padding[6]; |
Ratheesh Kannoth | 741f799 | 2021-10-20 07:39:52 +0530 | [diff] [blame] | 38 | }; |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 39 | |
| 40 | /* |
| 41 | * Specifies the lower bound on ACK numbers carried in the TCP header |
| 42 | */ |
| 43 | #define SFE_IPV6_TCP_MAX_ACK_WINDOW 65520 |
| 44 | |
| 45 | /* |
| 46 | * IPv6 TCP connection match additional data. |
| 47 | */ |
| 48 | struct sfe_ipv6_tcp_connection_match { |
| 49 | u8 win_scale; /* Window scale */ |
| 50 | u32 max_win; /* Maximum window size seen */ |
| 51 | u32 end; /* Sequence number of the next byte to send (seq + segment length) */ |
| 52 | u32 max_end; /* Sequence number of the last byte to ack */ |
| 53 | }; |
| 54 | |
| 55 | /* |
| 56 | * Bit flags for IPv6 connection matching entry. |
| 57 | */ |
| 58 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_XLATE_SRC (1<<0) |
| 59 | /* Perform source translation */ |
| 60 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_XLATE_DEST (1<<1) |
| 61 | /* Perform destination translation */ |
| 62 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_NO_SEQ_CHECK (1<<2) |
| 63 | /* Ignore TCP sequence numbers */ |
| 64 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_WRITE_FAST_ETH_HDR (1<<3) |
| 65 | /* Fast Ethernet header write */ |
| 66 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_WRITE_L2_HDR (1<<4) |
| 67 | /* Fast Ethernet header write */ |
| 68 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_PRIORITY_REMARK (1<<5) |
| 69 | /* remark priority of SKB */ |
| 70 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_DSCP_REMARK (1<<6) |
| 71 | /* remark DSCP of packet */ |
Ratheesh Kannoth | a3cf0e0 | 2021-12-09 09:44:10 +0530 | [diff] [blame] | 72 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_CSUM_OFFLOAD (1<<7) |
| 73 | /* checksum offload.*/ |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 74 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_PPPOE_DECAP (1<<8) |
| 75 | /* Indicates that PPPoE should be decapsulated */ |
| 76 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_PPPOE_ENCAP (1<<9) |
| 77 | /* Indicates that PPPoE should be encapsulated */ |
Ratheesh Kannoth | 71fc51e | 2022-01-05 10:02:47 +0530 | [diff] [blame] | 78 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_BRIDGE_FLOW (1<<10) |
| 79 | /* Bridge flow */ |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 80 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_MARK (1<<11) |
| 81 | /* set skb mark*/ |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 82 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_INSERT_EGRESS_VLAN_TAG (1<<12) |
| 83 | /* Insert VLAN tag */ |
Ratheesh Kannoth | 5dee377 | 2022-01-18 11:27:14 +0530 | [diff] [blame] | 84 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_SRC_INTERFACE_CHECK (1<<13) |
| 85 | /* Source interface check.*/ |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 86 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_PASSTHROUGH (1<<14) |
| 87 | /* passthrough flow: encap/decap to be skipped for this flow */ |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame^] | 88 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_FAST_XMIT (1<<15) |
| 89 | /* go fast xmit*/ |
| 90 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_FAST_XMIT_FLOW_CHECKED (1<<16) |
| 91 | /* fast xmit checked or not*/ |
| 92 | #define SFE_IPV6_CONNECTION_MATCH_FLAG_FAST_XMIT_DEV_ADMISSION (1<<17) |
| 93 | /* Fast xmit may be possible for this flow, if SFE check passes */ |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 94 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 95 | /* |
| 96 | * IPv6 connection matching structure. |
| 97 | */ |
| 98 | struct sfe_ipv6_connection_match { |
| 99 | /* |
| 100 | * References to other objects. |
| 101 | */ |
Ratheesh Kannoth | a212fc5 | 2021-10-20 07:50:32 +0530 | [diff] [blame] | 102 | struct hlist_node hnode; |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 103 | struct sfe_ipv6_connection *connection; |
| 104 | struct sfe_ipv6_connection_match *counter_match; |
| 105 | /* Matches the flow in the opposite direction as the one in connection */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 106 | /* |
| 107 | * Characteristics that identify flows that match this rule. |
| 108 | */ |
| 109 | struct net_device *match_dev; /* Network device */ |
| 110 | u8 match_protocol; /* Protocol */ |
| 111 | struct sfe_ipv6_addr match_src_ip[1]; /* Source IP address */ |
| 112 | struct sfe_ipv6_addr match_dest_ip[1]; /* Destination IP address */ |
| 113 | __be16 match_src_port; /* Source port/connection ident */ |
| 114 | __be16 match_dest_port; /* Destination port/connection ident */ |
| 115 | |
Suruchi Suman | 23a279d | 2021-11-16 15:13:09 +0530 | [diff] [blame] | 116 | struct udp_sock *up; /* Stores UDP sock information; valid only in decap path */ |
Tian Yang | afb0345 | 2022-01-13 18:53:13 -0800 | [diff] [blame] | 117 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0)) |
| 118 | const struct inet6_protocol *proto; /* stores protocol handler; valid only in decap path */ |
| 119 | #else |
| 120 | struct inet6_protocol *proto; /* stores protocol handler; valid only in decap path */ |
| 121 | #endif |
| 122 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 123 | /* |
| 124 | * Control the operations of the match. |
| 125 | */ |
| 126 | u32 flags; /* Bit flags */ |
| 127 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 128 | u32 flow_cookie; /* used flow cookie, for debug */ |
| 129 | #endif |
| 130 | #ifdef CONFIG_XFRM |
| 131 | u32 flow_accel; /* The flow accelerated or not */ |
| 132 | #endif |
| 133 | |
| 134 | /* |
| 135 | * Connection state that we track once we match. |
| 136 | */ |
| 137 | union { /* Protocol-specific state */ |
| 138 | struct sfe_ipv6_tcp_connection_match tcp; |
| 139 | } protocol_state; |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 140 | |
| 141 | /* |
| 142 | * VLAN headers |
| 143 | */ |
| 144 | struct sfe_vlan_hdr ingress_vlan_hdr[SFE_MAX_VLAN_DEPTH]; |
| 145 | struct sfe_vlan_hdr egress_vlan_hdr[SFE_MAX_VLAN_DEPTH]; |
| 146 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 147 | /* |
| 148 | * Stats recorded in a sync period. These stats will be added to |
| 149 | * rx_packet_count64/rx_byte_count64 after a sync period. |
| 150 | */ |
Ratheesh Kannoth | a212fc5 | 2021-10-20 07:50:32 +0530 | [diff] [blame] | 151 | atomic_t rx_packet_count; |
| 152 | atomic_t rx_byte_count; |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 153 | |
| 154 | /* |
| 155 | * Packet translation information. |
| 156 | */ |
| 157 | struct sfe_ipv6_addr xlate_src_ip[1]; /* Address after source translation */ |
| 158 | __be16 xlate_src_port; /* Port/connection ident after source translation */ |
| 159 | u16 xlate_src_csum_adjustment; |
| 160 | /* Transport layer checksum adjustment after source translation */ |
| 161 | struct sfe_ipv6_addr xlate_dest_ip[1]; /* Address after destination translation */ |
| 162 | __be16 xlate_dest_port; /* Port/connection ident after destination translation */ |
| 163 | u16 xlate_dest_csum_adjustment; |
| 164 | /* Transport layer checksum adjustment after destination translation */ |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 165 | u32 mark; /* mark for outgoing packet */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 166 | |
| 167 | /* |
| 168 | * QoS information |
| 169 | */ |
| 170 | u32 priority; |
| 171 | u32 dscp; |
| 172 | |
| 173 | /* |
| 174 | * Packet transmit information. |
| 175 | */ |
| 176 | struct net_device *xmit_dev; /* Network device on which to transmit */ |
| 177 | unsigned short int xmit_dev_mtu; |
| 178 | /* Interface MTU */ |
| 179 | u16 xmit_dest_mac[ETH_ALEN / 2]; |
| 180 | /* Destination MAC address to use when forwarding */ |
| 181 | u16 xmit_src_mac[ETH_ALEN / 2]; |
| 182 | /* Source MAC address to use when forwarding */ |
| 183 | |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 184 | u8 ingress_vlan_hdr_cnt; /* Ingress active vlan headers count */ |
| 185 | u8 egress_vlan_hdr_cnt; /* Egress active vlan headers count */ |
| 186 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 187 | /* |
| 188 | * Summary stats. |
| 189 | */ |
| 190 | u64 rx_packet_count64; |
| 191 | u64 rx_byte_count64; |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 192 | |
| 193 | /* |
| 194 | * PPPoE information. |
| 195 | */ |
| 196 | u16 pppoe_session_id; |
| 197 | u8 pppoe_remote_mac[ETH_ALEN]; |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 198 | |
| 199 | /* |
| 200 | * Size of all needed L2 headers |
| 201 | */ |
| 202 | u16 l2_hdr_size; |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame^] | 203 | |
| 204 | /* |
| 205 | * xmit device's feature |
| 206 | */ |
| 207 | netdev_features_t features; |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 208 | }; |
| 209 | |
| 210 | /* |
| 211 | * Per-connection data structure. |
| 212 | */ |
| 213 | struct sfe_ipv6_connection { |
| 214 | struct sfe_ipv6_connection *next; |
| 215 | /* Pointer to the next entry in a hash chain */ |
| 216 | struct sfe_ipv6_connection *prev; |
| 217 | /* Pointer to the previous entry in a hash chain */ |
| 218 | int protocol; /* IP protocol number */ |
| 219 | struct sfe_ipv6_addr src_ip[1]; /* Src IP addr pre-translation */ |
| 220 | struct sfe_ipv6_addr src_ip_xlate[1]; /* Src IP addr post-translation */ |
| 221 | struct sfe_ipv6_addr dest_ip[1]; /* Dest IP addr pre-translation */ |
| 222 | struct sfe_ipv6_addr dest_ip_xlate[1]; /* Dest IP addr post-translation */ |
| 223 | __be16 src_port; /* Src port pre-translation */ |
| 224 | __be16 src_port_xlate; /* Src port post-translation */ |
| 225 | __be16 dest_port; /* Dest port pre-translation */ |
| 226 | __be16 dest_port_xlate; /* Dest port post-translation */ |
| 227 | struct sfe_ipv6_connection_match *original_match; |
| 228 | /* Original direction matching structure */ |
| 229 | struct net_device *original_dev; |
| 230 | /* Original direction source device */ |
| 231 | struct sfe_ipv6_connection_match *reply_match; |
| 232 | /* Reply direction matching structure */ |
| 233 | struct net_device *reply_dev; /* Reply direction source device */ |
| 234 | u64 last_sync_jiffies; /* Jiffies count for the last sync */ |
| 235 | struct sfe_ipv6_connection *all_connections_next; |
| 236 | /* Pointer to the next entry in the list of all connections */ |
| 237 | struct sfe_ipv6_connection *all_connections_prev; |
| 238 | /* Pointer to the previous entry in the list of all connections */ |
Ratheesh Kannoth | a212fc5 | 2021-10-20 07:50:32 +0530 | [diff] [blame] | 239 | bool removed; /* Indicates the connection is removed */ |
| 240 | struct rcu_head rcu; /* delay rcu free */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 241 | u32 debug_read_seq; /* sequence number for debug dump */ |
| 242 | }; |
| 243 | |
| 244 | /* |
| 245 | * IPv6 connections and hash table size information. |
| 246 | */ |
| 247 | #define SFE_IPV6_CONNECTION_HASH_SHIFT 12 |
| 248 | #define SFE_IPV6_CONNECTION_HASH_SIZE (1 << SFE_IPV6_CONNECTION_HASH_SHIFT) |
| 249 | #define SFE_IPV6_CONNECTION_HASH_MASK (SFE_IPV6_CONNECTION_HASH_SIZE - 1) |
| 250 | |
| 251 | enum sfe_ipv6_exception_events { |
| 252 | SFE_IPV6_EXCEPTION_EVENT_UDP_HEADER_INCOMPLETE, |
| 253 | SFE_IPV6_EXCEPTION_EVENT_UDP_NO_CONNECTION, |
| 254 | SFE_IPV6_EXCEPTION_EVENT_UDP_IP_OPTIONS_OR_INITIAL_FRAGMENT, |
| 255 | SFE_IPV6_EXCEPTION_EVENT_UDP_SMALL_TTL, |
| 256 | SFE_IPV6_EXCEPTION_EVENT_UDP_NEEDS_FRAGMENTATION, |
| 257 | SFE_IPV6_EXCEPTION_EVENT_TCP_HEADER_INCOMPLETE, |
| 258 | SFE_IPV6_EXCEPTION_EVENT_TCP_NO_CONNECTION_SLOW_FLAGS, |
| 259 | SFE_IPV6_EXCEPTION_EVENT_TCP_NO_CONNECTION_FAST_FLAGS, |
| 260 | SFE_IPV6_EXCEPTION_EVENT_TCP_IP_OPTIONS_OR_INITIAL_FRAGMENT, |
| 261 | SFE_IPV6_EXCEPTION_EVENT_TCP_SMALL_TTL, |
| 262 | SFE_IPV6_EXCEPTION_EVENT_TCP_NEEDS_FRAGMENTATION, |
| 263 | SFE_IPV6_EXCEPTION_EVENT_TCP_FLAGS, |
| 264 | SFE_IPV6_EXCEPTION_EVENT_TCP_SEQ_EXCEEDS_RIGHT_EDGE, |
| 265 | SFE_IPV6_EXCEPTION_EVENT_TCP_SMALL_DATA_OFFS, |
| 266 | SFE_IPV6_EXCEPTION_EVENT_TCP_BAD_SACK, |
| 267 | SFE_IPV6_EXCEPTION_EVENT_TCP_BIG_DATA_OFFS, |
| 268 | SFE_IPV6_EXCEPTION_EVENT_TCP_SEQ_BEFORE_LEFT_EDGE, |
| 269 | SFE_IPV6_EXCEPTION_EVENT_TCP_ACK_EXCEEDS_RIGHT_EDGE, |
| 270 | SFE_IPV6_EXCEPTION_EVENT_TCP_ACK_BEFORE_LEFT_EDGE, |
| 271 | SFE_IPV6_EXCEPTION_EVENT_ICMP_HEADER_INCOMPLETE, |
| 272 | SFE_IPV6_EXCEPTION_EVENT_ICMP_UNHANDLED_TYPE, |
| 273 | SFE_IPV6_EXCEPTION_EVENT_ICMP_IPV6_HEADER_INCOMPLETE, |
| 274 | SFE_IPV6_EXCEPTION_EVENT_ICMP_IPV6_NON_V6, |
| 275 | SFE_IPV6_EXCEPTION_EVENT_ICMP_IPV6_IP_OPTIONS_INCOMPLETE, |
| 276 | SFE_IPV6_EXCEPTION_EVENT_ICMP_IPV6_UDP_HEADER_INCOMPLETE, |
| 277 | SFE_IPV6_EXCEPTION_EVENT_ICMP_IPV6_TCP_HEADER_INCOMPLETE, |
| 278 | SFE_IPV6_EXCEPTION_EVENT_ICMP_IPV6_UNHANDLED_PROTOCOL, |
| 279 | SFE_IPV6_EXCEPTION_EVENT_ICMP_NO_CONNECTION, |
| 280 | SFE_IPV6_EXCEPTION_EVENT_ICMP_FLUSHED_CONNECTION, |
| 281 | SFE_IPV6_EXCEPTION_EVENT_HEADER_INCOMPLETE, |
| 282 | SFE_IPV6_EXCEPTION_EVENT_BAD_TOTAL_LENGTH, |
| 283 | SFE_IPV6_EXCEPTION_EVENT_NON_V6, |
| 284 | SFE_IPV6_EXCEPTION_EVENT_NON_INITIAL_FRAGMENT, |
| 285 | SFE_IPV6_EXCEPTION_EVENT_DATAGRAM_INCOMPLETE, |
| 286 | SFE_IPV6_EXCEPTION_EVENT_IP_OPTIONS_INCOMPLETE, |
| 287 | SFE_IPV6_EXCEPTION_EVENT_UNHANDLED_PROTOCOL, |
| 288 | SFE_IPV6_EXCEPTION_EVENT_FLOW_COOKIE_ADD_FAIL, |
Guduri Prathyusha | 5f27e23 | 2022-01-06 14:39:04 +0530 | [diff] [blame] | 289 | SFE_IPV6_EXCEPTION_EVENT_NO_HEADROOM, |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 290 | SFE_IPV6_EXCEPTION_EVENT_INVALID_PPPOE_SESSION, |
| 291 | SFE_IPV6_EXCEPTION_EVENT_INCORRECT_PPPOE_PARSING, |
| 292 | SFE_IPV6_EXCEPTION_EVENT_PPPOE_NOT_SET_IN_CME, |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 293 | SFE_IPV6_EXCEPTION_EVENT_NOT_ENOUGH_HEADROOM, |
| 294 | SFE_IPV6_EXCEPTION_EVENT_INGRESS_VLAN_TAG_MISMATCH, |
Ratheesh Kannoth | 5dee377 | 2022-01-18 11:27:14 +0530 | [diff] [blame] | 295 | SFE_IPV6_EXCEPTION_EVENT_INVALID_SRC_IFACE, |
Tian Yang | afb0345 | 2022-01-13 18:53:13 -0800 | [diff] [blame] | 296 | SFE_IPV6_EXCEPTION_EVENT_TUNIPIP6_HEADER_INCOMPLETE, |
| 297 | SFE_IPV6_EXCEPTION_EVENT_TUNIPIP6_NO_CONNECTION, |
| 298 | SFE_IPV6_EXCEPTION_EVENT_TUNIPIP6_IP_OPTIONS_OR_INITIAL_FRAGMENT, |
| 299 | SFE_IPV6_EXCEPTION_EVENT_TUNIPIP6_SMALL_TTL, |
| 300 | SFE_IPV6_EXCEPTION_EVENT_TUNIPIP6_NEEDS_FRAGMENTATION, |
| 301 | SFE_IPV6_EXCEPTION_EVENT_TUNIPIP6_SYNC_ON_FIND, |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 302 | SFE_IPV6_EXCEPTION_EVENT_GRE_HEADER_INCOMPLETE, |
| 303 | SFE_IPV6_EXCEPTION_EVENT_GRE_NO_CONNECTION, |
| 304 | SFE_IPV6_EXCEPTION_EVENT_GRE_IP_OPTIONS_OR_INITIAL_FRAGMENT, |
| 305 | SFE_IPV6_EXCEPTION_EVENT_GRE_SMALL_TTL, |
| 306 | SFE_IPV6_EXCEPTION_EVENT_GRE_NEEDS_FRAGMENTATION, |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 307 | SFE_IPV6_EXCEPTION_EVENT_LAST |
| 308 | }; |
| 309 | |
| 310 | /* |
Ratheesh Kannoth | 1ed9546 | 2021-10-20 07:57:45 +0530 | [diff] [blame] | 311 | * Per CPU stats |
| 312 | */ |
| 313 | struct sfe_ipv6_stats { |
| 314 | /* |
| 315 | * Stats recorded in a sync period. These stats will be added to |
| 316 | * connection_xxx64 after a sync period. |
| 317 | */ |
| 318 | u64 connection_create_requests64; |
| 319 | /* Number of IPv6 connection create requests */ |
| 320 | u64 connection_create_collisions64; |
| 321 | /* Number of IPv6 connection create requests that collided with existing hash table entries */ |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 322 | u64 connection_create_failures64; |
| 323 | /* Number of IPv6 connection create requests failures. */ |
| 324 | |
Ratheesh Kannoth | 1ed9546 | 2021-10-20 07:57:45 +0530 | [diff] [blame] | 325 | u64 connection_destroy_requests64; |
| 326 | /* Number of IPv6 connection destroy requests */ |
| 327 | u64 connection_destroy_misses64; |
| 328 | /* Number of IPv6 connection destroy requests that missed our hash table */ |
| 329 | u64 connection_match_hash_hits64; |
| 330 | /* Number of IPv6 connection match hash hits */ |
| 331 | u64 connection_match_hash_reorders64; |
| 332 | /* Number of IPv6 connection match hash reorders */ |
| 333 | u64 connection_flushes64; /* Number of IPv6 connection flushes */ |
Suruchi Suman | 23a279d | 2021-11-16 15:13:09 +0530 | [diff] [blame] | 334 | u64 packets_dropped64; /* Number of IPv4 packets dropped */ |
Ratheesh Kannoth | 1ed9546 | 2021-10-20 07:57:45 +0530 | [diff] [blame] | 335 | u64 packets_forwarded64; /* Number of IPv6 packets forwarded */ |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame^] | 336 | u64 packets_fast_xmited64; /* Number of IPv6 packets fast transmited */ |
Ratheesh Kannoth | 1ed9546 | 2021-10-20 07:57:45 +0530 | [diff] [blame] | 337 | u64 packets_not_forwarded64; /* Number of IPv6 packets not forwarded */ |
| 338 | u64 exception_events64[SFE_IPV6_EXCEPTION_EVENT_LAST]; |
Guduri Prathyusha | 034d635 | 2022-01-12 16:49:04 +0530 | [diff] [blame] | 339 | u64 pppoe_encap_packets_forwarded64; /* Number of IPv6 PPPoE encap packets forwarded */ |
| 340 | u64 pppoe_decap_packets_forwarded64; /* Number of IPv6 PPPoE decap packets forwarded */ |
| 341 | u64 pppoe_bridge_packets_forwarded64; /* Number of IPv6 PPPoE decap packets forwarded */ |
Ratheesh Kannoth | 1ed9546 | 2021-10-20 07:57:45 +0530 | [diff] [blame] | 342 | }; |
| 343 | |
| 344 | /* |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 345 | * Per-module structure. |
| 346 | */ |
| 347 | struct sfe_ipv6 { |
| 348 | spinlock_t lock; /* Lock for SMP correctness */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 349 | struct sfe_ipv6_connection *all_connections_head; |
| 350 | /* Head of the list of all connections */ |
| 351 | struct sfe_ipv6_connection *all_connections_tail; |
| 352 | /* Tail of the list of all connections */ |
| 353 | unsigned int num_connections; /* Number of connections */ |
Ken Zhu | 137722d | 2021-09-23 17:57:36 -0700 | [diff] [blame] | 354 | struct delayed_work sync_dwork; /* Work to sync the statistics */ |
| 355 | unsigned int work_cpu; /* The core to run stats sync on */ |
| 356 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 357 | sfe_sync_rule_callback_t __rcu sync_rule_callback; |
| 358 | /* Callback function registered by a connection manager for stats syncing */ |
| 359 | struct sfe_ipv6_connection *conn_hash[SFE_IPV6_CONNECTION_HASH_SIZE]; |
| 360 | /* Connection hash table */ |
Ratheesh Kannoth | a212fc5 | 2021-10-20 07:50:32 +0530 | [diff] [blame] | 361 | struct hlist_head hlist_conn_match_hash_head[SFE_IPV6_CONNECTION_HASH_SIZE]; |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 362 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 363 | struct sfe_ipv6_flow_cookie_entry sfe_flow_cookie_table[SFE_FLOW_COOKIE_SIZE]; |
| 364 | /* flow cookie table*/ |
| 365 | sfe_ipv6_flow_cookie_set_func_t flow_cookie_set_func; |
| 366 | /* function used to configure flow cookie in hardware*/ |
| 367 | int flow_cookie_enable; |
| 368 | /* Enable/disable flow cookie at runtime */ |
| 369 | #endif |
| 370 | |
Ratheesh Kannoth | 1ed9546 | 2021-10-20 07:57:45 +0530 | [diff] [blame] | 371 | struct sfe_ipv6_stats __percpu *stats_pcpu; |
| 372 | /* Common SFE counters. */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 373 | |
Ken Zhu | 32b9539 | 2021-09-03 13:52:04 -0700 | [diff] [blame] | 374 | struct sfe_ipv6_connection *wc_next; |
| 375 | /* The next walk point in the all connection list*/ |
| 376 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 377 | /* |
| 378 | * Control state. |
| 379 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 380 | struct kobject *sys_ipv6; /* sysfs linkage */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 381 | int debug_dev; /* Major number of the debug char device */ |
| 382 | u32 debug_read_seq; /* sequence number for debug dump */ |
| 383 | }; |
| 384 | |
| 385 | /* |
| 386 | * Enumeration of the XML output. |
| 387 | */ |
| 388 | enum sfe_ipv6_debug_xml_states { |
| 389 | SFE_IPV6_DEBUG_XML_STATE_START, |
| 390 | SFE_IPV6_DEBUG_XML_STATE_CONNECTIONS_START, |
| 391 | SFE_IPV6_DEBUG_XML_STATE_CONNECTIONS_CONNECTION, |
| 392 | SFE_IPV6_DEBUG_XML_STATE_CONNECTIONS_END, |
| 393 | SFE_IPV6_DEBUG_XML_STATE_EXCEPTIONS_START, |
| 394 | SFE_IPV6_DEBUG_XML_STATE_EXCEPTIONS_EXCEPTION, |
| 395 | SFE_IPV6_DEBUG_XML_STATE_EXCEPTIONS_END, |
| 396 | SFE_IPV6_DEBUG_XML_STATE_STATS, |
| 397 | SFE_IPV6_DEBUG_XML_STATE_END, |
| 398 | SFE_IPV6_DEBUG_XML_STATE_DONE |
| 399 | }; |
| 400 | |
| 401 | /* |
| 402 | * XML write state. |
| 403 | */ |
| 404 | struct sfe_ipv6_debug_xml_write_state { |
| 405 | enum sfe_ipv6_debug_xml_states state; |
| 406 | /* XML output file state machine state */ |
| 407 | int iter_exception; /* Next exception iterator */ |
| 408 | }; |
| 409 | |
| 410 | typedef bool (*sfe_ipv6_debug_xml_write_method_t)(struct sfe_ipv6 *si, char *buffer, char *msg, size_t *length, |
| 411 | int *total_read, struct sfe_ipv6_debug_xml_write_state *ws); |
| 412 | |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 413 | /* |
| 414 | * sfe_ipv6_is_ext_hdr() |
| 415 | * check if we recognize ipv6 extension header |
| 416 | */ |
| 417 | static inline bool sfe_ipv6_is_ext_hdr(u8 hdr) |
| 418 | { |
| 419 | return (hdr == NEXTHDR_HOP) || |
| 420 | (hdr == NEXTHDR_ROUTING) || |
| 421 | (hdr == NEXTHDR_FRAGMENT) || |
| 422 | (hdr == NEXTHDR_AUTH) || |
| 423 | (hdr == NEXTHDR_DEST) || |
| 424 | (hdr == NEXTHDR_MOBILITY); |
| 425 | } |
| 426 | |
| 427 | /* |
| 428 | * sfe_ipv6_change_dsfield() |
| 429 | * change dscp field in IPv6 packet |
| 430 | */ |
| 431 | static inline void sfe_ipv6_change_dsfield(struct ipv6hdr *iph, u8 dscp) |
| 432 | { |
| 433 | __be16 *p = (__be16 *)iph; |
| 434 | |
| 435 | *p = ((*p & htons(SFE_IPV6_DSCP_MASK)) | htons((u16)dscp << 4)); |
| 436 | } |
| 437 | |
| 438 | void sfe_ipv6_exception_stats_inc(struct sfe_ipv6 *si, enum sfe_ipv6_exception_events reason); |
| 439 | |
| 440 | struct sfe_ipv6_connection_match * |
| 441 | sfe_ipv6_find_connection_match_rcu(struct sfe_ipv6 *si, struct net_device *dev, u8 protocol, |
| 442 | struct sfe_ipv6_addr *src_ip, __be16 src_port, |
| 443 | struct sfe_ipv6_addr *dest_ip, __be16 dest_port); |
| 444 | |
| 445 | bool sfe_ipv6_remove_connection(struct sfe_ipv6 *si, struct sfe_ipv6_connection *c); |
| 446 | |
| 447 | void sfe_ipv6_flush_connection(struct sfe_ipv6 *si, |
| 448 | struct sfe_ipv6_connection *c, |
| 449 | sfe_sync_reason_t reason); |
| 450 | |
Ken Zhu | 88c5815 | 2021-12-09 15:12:06 -0800 | [diff] [blame] | 451 | void sfe_ipv6_sync_status(struct sfe_ipv6 *si, |
| 452 | struct sfe_ipv6_connection *c, |
| 453 | sfe_sync_reason_t reason); |
| 454 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 455 | void sfe_ipv6_exit(void); |
| 456 | int sfe_ipv6_init(void); |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 457 | |
| 458 | #endif /* __SFE_IPV6_H */ |