Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1 | /* |
| 2 | * sfe_ipv4.c |
| 3 | * Shortcut forwarding engine - IPv4 edition. |
| 4 | * |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 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 | * |
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. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 19 | */ |
Matthew McClintock | a322194 | 2014-01-16 11:44:26 -0600 | [diff] [blame] | 20 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 21 | #include <linux/module.h> |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 22 | #include <linux/sysfs.h> |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 23 | #include <linux/skbuff.h> |
| 24 | #include <linux/icmp.h> |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 25 | #include <net/tcp.h> |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 26 | #include <net/udp.h> |
| 27 | #include <net/vxlan.h> |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 28 | #include <linux/etherdevice.h> |
Tian Yang | 45f39c8 | 2020-10-06 14:07:47 -0700 | [diff] [blame] | 29 | #include <linux/version.h> |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 30 | #include <linux/lockdep.h> |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 31 | #include <linux/refcount.h> |
| 32 | #include <linux/netfilter.h> |
| 33 | #include <linux/inetdevice.h> |
| 34 | #include <linux/netfilter_ipv4.h> |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 35 | #include <linux/seqlock.h> |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 36 | #include <net/protocol.h> |
| 37 | #include <net/gre.h> |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 38 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 39 | #include "sfe_debug.h" |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 40 | #include "sfe_api.h" |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 41 | #include "sfe.h" |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 42 | #include "sfe_flow_cookie.h" |
| 43 | #include "sfe_ipv4.h" |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 44 | #include "sfe_ipv4_udp.h" |
| 45 | #include "sfe_ipv4_tcp.h" |
| 46 | #include "sfe_ipv4_icmp.h" |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 47 | #include "sfe_pppoe.h" |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 48 | #include "sfe_ipv4_gre.h" |
Tian Yang | d98d91b | 2022-03-09 14:50:12 -0800 | [diff] [blame^] | 49 | #include "sfe_ipv4_tun6rd.h" |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 50 | |
| 51 | static char *sfe_ipv4_exception_events_string[SFE_IPV4_EXCEPTION_EVENT_LAST] = { |
| 52 | "UDP_HEADER_INCOMPLETE", |
| 53 | "UDP_NO_CONNECTION", |
| 54 | "UDP_IP_OPTIONS_OR_INITIAL_FRAGMENT", |
| 55 | "UDP_SMALL_TTL", |
| 56 | "UDP_NEEDS_FRAGMENTATION", |
| 57 | "TCP_HEADER_INCOMPLETE", |
| 58 | "TCP_NO_CONNECTION_SLOW_FLAGS", |
| 59 | "TCP_NO_CONNECTION_FAST_FLAGS", |
| 60 | "TCP_IP_OPTIONS_OR_INITIAL_FRAGMENT", |
| 61 | "TCP_SMALL_TTL", |
| 62 | "TCP_NEEDS_FRAGMENTATION", |
| 63 | "TCP_FLAGS", |
| 64 | "TCP_SEQ_EXCEEDS_RIGHT_EDGE", |
| 65 | "TCP_SMALL_DATA_OFFS", |
| 66 | "TCP_BAD_SACK", |
| 67 | "TCP_BIG_DATA_OFFS", |
| 68 | "TCP_SEQ_BEFORE_LEFT_EDGE", |
| 69 | "TCP_ACK_EXCEEDS_RIGHT_EDGE", |
| 70 | "TCP_ACK_BEFORE_LEFT_EDGE", |
| 71 | "ICMP_HEADER_INCOMPLETE", |
| 72 | "ICMP_UNHANDLED_TYPE", |
| 73 | "ICMP_IPV4_HEADER_INCOMPLETE", |
| 74 | "ICMP_IPV4_NON_V4", |
| 75 | "ICMP_IPV4_IP_OPTIONS_INCOMPLETE", |
| 76 | "ICMP_IPV4_UDP_HEADER_INCOMPLETE", |
| 77 | "ICMP_IPV4_TCP_HEADER_INCOMPLETE", |
| 78 | "ICMP_IPV4_UNHANDLED_PROTOCOL", |
| 79 | "ICMP_NO_CONNECTION", |
| 80 | "ICMP_FLUSHED_CONNECTION", |
| 81 | "HEADER_INCOMPLETE", |
Ratheesh Kannoth | 43d64f8 | 2021-10-20 08:23:29 +0530 | [diff] [blame] | 82 | "HEADER_CSUM_BAD", |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 83 | "BAD_TOTAL_LENGTH", |
| 84 | "NON_V4", |
| 85 | "NON_INITIAL_FRAGMENT", |
| 86 | "DATAGRAM_INCOMPLETE", |
| 87 | "IP_OPTIONS_INCOMPLETE", |
Ratheesh Kannoth | 5dee377 | 2022-01-18 11:27:14 +0530 | [diff] [blame] | 88 | "UNHANDLED_PROTOCOL", |
Nitin Shetty | 16ab38d | 2022-02-09 01:26:19 +0530 | [diff] [blame] | 89 | "NO_HEADROOM", |
| 90 | "INVALID_PPPOE_SESSION", |
| 91 | "INCORRECT_PPPOE_PARSING", |
| 92 | "PPPOE_NOT_SET_IN_CME", |
| 93 | "INGRESS_VLAN_TAG_MISMATCH", |
Ratheesh Kannoth | 5dee377 | 2022-01-18 11:27:14 +0530 | [diff] [blame] | 94 | "INVALID_SOURCE_INTERFACE", |
Tian Yang | d98d91b | 2022-03-09 14:50:12 -0800 | [diff] [blame^] | 95 | "TUN6RD_NO_CONNECTION", |
| 96 | "TUN6RD_NEEDS_FRAGMENTATION", |
| 97 | "TUN6RD_SYNC_ON_FIND", |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 98 | "GRE_HEADER_INCOMPLETE", |
| 99 | "GRE_NO_CONNECTION", |
| 100 | "GRE_IP_OPTIONS_OR_INITIAL_FRAGMENT", |
| 101 | "GRE_SMALL_TTL", |
| 102 | "GRE_NEEDS_FRAGMENTATION" |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 103 | }; |
| 104 | |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 105 | static struct sfe_ipv4 __si; |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 106 | struct sfe_ipv4_msg *sfe_ipv4_sync_many_msg; |
| 107 | uint32_t sfe_ipv4_sync_max_number; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 108 | |
| 109 | /* |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 110 | * sfe_ipv4_gen_ip_csum() |
| 111 | * Generate the IP checksum for an IPv4 header. |
| 112 | * |
| 113 | * Note that this function assumes that we have only 20 bytes of IP header. |
| 114 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 115 | u16 sfe_ipv4_gen_ip_csum(struct iphdr *iph) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 116 | { |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 117 | u32 sum; |
| 118 | u16 *i = (u16 *)iph; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 119 | |
| 120 | iph->check = 0; |
| 121 | |
| 122 | /* |
| 123 | * Generate the sum. |
| 124 | */ |
| 125 | sum = i[0] + i[1] + i[2] + i[3] + i[4] + i[5] + i[6] + i[7] + i[8] + i[9]; |
| 126 | |
| 127 | /* |
| 128 | * Fold it to ones-complement form. |
| 129 | */ |
| 130 | sum = (sum & 0xffff) + (sum >> 16); |
| 131 | sum = (sum & 0xffff) + (sum >> 16); |
| 132 | |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 133 | return (u16)sum ^ 0xffff; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /* |
| 137 | * sfe_ipv4_get_connection_match_hash() |
| 138 | * Generate the hash used in connection match lookups. |
| 139 | */ |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 140 | static inline unsigned int sfe_ipv4_get_connection_match_hash(struct net_device *dev, u8 protocol, |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 141 | __be32 src_ip, __be16 src_port, |
| 142 | __be32 dest_ip, __be16 dest_port) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 143 | { |
Ratheesh Kannoth | 5dee377 | 2022-01-18 11:27:14 +0530 | [diff] [blame] | 144 | u32 hash = ntohl(src_ip ^ dest_ip) ^ protocol ^ ntohs(src_port ^ dest_port); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 145 | return ((hash >> SFE_IPV4_CONNECTION_HASH_SHIFT) ^ hash) & SFE_IPV4_CONNECTION_HASH_MASK; |
| 146 | } |
| 147 | |
| 148 | /* |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 149 | * sfe_ipv4_find_connection_match_rcu() |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 150 | * Get the IPv4 flow match info that corresponds to a particular 5-tuple. |
| 151 | * |
| 152 | * On entry we must be holding the lock that protects the hash table. |
| 153 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 154 | struct sfe_ipv4_connection_match * |
| 155 | sfe_ipv4_find_connection_match_rcu(struct sfe_ipv4 *si, struct net_device *dev, u8 protocol, |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 156 | __be32 src_ip, __be16 src_port, |
| 157 | __be32 dest_ip, __be16 dest_port) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 158 | { |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 159 | struct sfe_ipv4_connection_match *cm = NULL; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 160 | unsigned int conn_match_idx; |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 161 | struct hlist_head *lhead; |
| 162 | |
| 163 | WARN_ON_ONCE(!rcu_read_lock_held()); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 164 | |
| 165 | conn_match_idx = sfe_ipv4_get_connection_match_hash(dev, protocol, src_ip, src_port, dest_ip, dest_port); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 166 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 167 | lhead = &si->hlist_conn_match_hash_head[conn_match_idx]; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 168 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 169 | hlist_for_each_entry_rcu(cm, lhead, hnode) { |
| 170 | if (cm->match_src_port != src_port |
| 171 | || cm->match_dest_port != dest_port |
| 172 | || cm->match_src_ip != src_ip |
| 173 | || cm->match_dest_ip != dest_ip |
Ratheesh Kannoth | 5dee377 | 2022-01-18 11:27:14 +0530 | [diff] [blame] | 174 | || cm->match_protocol != protocol) { |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 175 | continue; |
| 176 | } |
| 177 | |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 178 | this_cpu_inc(si->stats_pcpu->connection_match_hash_hits64); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 179 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 180 | break; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 181 | } |
| 182 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 183 | return cm; |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * sfe_ipv4_connection_match_update_summary_stats() |
| 188 | * Update the summary stats for a connection match entry. |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 189 | * |
| 190 | * Stats are incremented atomically. So use atomic substraction to update summary |
| 191 | * stats. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 192 | */ |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 193 | static inline void sfe_ipv4_connection_match_update_summary_stats(struct sfe_ipv4_connection_match *cm, |
| 194 | u32 *packets, u32 *bytes) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 195 | { |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 196 | u32 packet_count, byte_count; |
| 197 | |
| 198 | packet_count = atomic_read(&cm->rx_packet_count); |
| 199 | cm->rx_packet_count64 += packet_count; |
| 200 | atomic_sub(packet_count, &cm->rx_packet_count); |
| 201 | |
| 202 | byte_count = atomic_read(&cm->rx_byte_count); |
| 203 | cm->rx_byte_count64 += byte_count; |
| 204 | atomic_sub(byte_count, &cm->rx_byte_count); |
| 205 | |
| 206 | *packets = packet_count; |
| 207 | *bytes = byte_count; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /* |
| 211 | * sfe_ipv4_connection_match_compute_translations() |
| 212 | * Compute port and address translations for a connection match entry. |
| 213 | */ |
| 214 | static void sfe_ipv4_connection_match_compute_translations(struct sfe_ipv4_connection_match *cm) |
| 215 | { |
| 216 | /* |
| 217 | * Before we insert the entry look to see if this is tagged as doing address |
| 218 | * translations. If it is then work out the adjustment that we need to apply |
| 219 | * to the transport checksum. |
| 220 | */ |
| 221 | if (cm->flags & SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_SRC) { |
| 222 | /* |
| 223 | * Precompute an incremental checksum adjustment so we can |
| 224 | * edit packets in this stream very quickly. The algorithm is from RFC1624. |
| 225 | */ |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 226 | u16 src_ip_hi = cm->match_src_ip >> 16; |
| 227 | u16 src_ip_lo = cm->match_src_ip & 0xffff; |
| 228 | u32 xlate_src_ip = ~cm->xlate_src_ip; |
| 229 | u16 xlate_src_ip_hi = xlate_src_ip >> 16; |
| 230 | u16 xlate_src_ip_lo = xlate_src_ip & 0xffff; |
| 231 | u16 xlate_src_port = ~cm->xlate_src_port; |
| 232 | u32 adj; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 233 | |
| 234 | /* |
| 235 | * When we compute this fold it down to a 16-bit offset |
| 236 | * as that way we can avoid having to do a double |
| 237 | * folding of the twos-complement result because the |
| 238 | * addition of 2 16-bit values cannot cause a double |
| 239 | * wrap-around! |
| 240 | */ |
| 241 | adj = src_ip_hi + src_ip_lo + cm->match_src_port |
| 242 | + xlate_src_ip_hi + xlate_src_ip_lo + xlate_src_port; |
| 243 | adj = (adj & 0xffff) + (adj >> 16); |
| 244 | adj = (adj & 0xffff) + (adj >> 16); |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 245 | cm->xlate_src_csum_adjustment = (u16)adj; |
Nicolas Costa | ac2979c | 2014-01-14 10:35:24 -0600 | [diff] [blame] | 246 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | if (cm->flags & SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_DEST) { |
| 250 | /* |
| 251 | * Precompute an incremental checksum adjustment so we can |
| 252 | * edit packets in this stream very quickly. The algorithm is from RFC1624. |
| 253 | */ |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 254 | u16 dest_ip_hi = cm->match_dest_ip >> 16; |
| 255 | u16 dest_ip_lo = cm->match_dest_ip & 0xffff; |
| 256 | u32 xlate_dest_ip = ~cm->xlate_dest_ip; |
| 257 | u16 xlate_dest_ip_hi = xlate_dest_ip >> 16; |
| 258 | u16 xlate_dest_ip_lo = xlate_dest_ip & 0xffff; |
| 259 | u16 xlate_dest_port = ~cm->xlate_dest_port; |
| 260 | u32 adj; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 261 | |
| 262 | /* |
| 263 | * When we compute this fold it down to a 16-bit offset |
| 264 | * as that way we can avoid having to do a double |
| 265 | * folding of the twos-complement result because the |
| 266 | * addition of 2 16-bit values cannot cause a double |
| 267 | * wrap-around! |
| 268 | */ |
| 269 | adj = dest_ip_hi + dest_ip_lo + cm->match_dest_port |
| 270 | + xlate_dest_ip_hi + xlate_dest_ip_lo + xlate_dest_port; |
| 271 | adj = (adj & 0xffff) + (adj >> 16); |
| 272 | adj = (adj & 0xffff) + (adj >> 16); |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 273 | cm->xlate_dest_csum_adjustment = (u16)adj; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 274 | } |
Xiaoping Fan | ad755af | 2015-04-01 16:58:46 -0700 | [diff] [blame] | 275 | |
| 276 | if (cm->flags & SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_SRC) { |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 277 | u32 adj = ~cm->match_src_ip + cm->xlate_src_ip; |
Xiaoping Fan | ad755af | 2015-04-01 16:58:46 -0700 | [diff] [blame] | 278 | if (adj < cm->xlate_src_ip) { |
| 279 | adj++; |
| 280 | } |
| 281 | |
| 282 | adj = (adj & 0xffff) + (adj >> 16); |
| 283 | adj = (adj & 0xffff) + (adj >> 16); |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 284 | cm->xlate_src_partial_csum_adjustment = (u16)adj; |
Xiaoping Fan | ad755af | 2015-04-01 16:58:46 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | if (cm->flags & SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_DEST) { |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 288 | u32 adj = ~cm->match_dest_ip + cm->xlate_dest_ip; |
Xiaoping Fan | ad755af | 2015-04-01 16:58:46 -0700 | [diff] [blame] | 289 | if (adj < cm->xlate_dest_ip) { |
| 290 | adj++; |
| 291 | } |
| 292 | |
| 293 | adj = (adj & 0xffff) + (adj >> 16); |
| 294 | adj = (adj & 0xffff) + (adj >> 16); |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 295 | cm->xlate_dest_partial_csum_adjustment = (u16)adj; |
Xiaoping Fan | ad755af | 2015-04-01 16:58:46 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /* |
| 301 | * sfe_ipv4_update_summary_stats() |
| 302 | * Update the summary stats. |
| 303 | */ |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 304 | static void sfe_ipv4_update_summary_stats(struct sfe_ipv4 *si, struct sfe_ipv4_stats *stats) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 305 | { |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 306 | int i = 0; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 307 | |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 308 | memset(stats, 0, sizeof(*stats)); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 309 | |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 310 | for_each_possible_cpu(i) { |
| 311 | const struct sfe_ipv4_stats *s = per_cpu_ptr(si->stats_pcpu, i); |
| 312 | |
| 313 | stats->connection_create_requests64 += s->connection_create_requests64; |
| 314 | stats->connection_create_collisions64 += s->connection_create_collisions64; |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 315 | stats->connection_create_failures64 += s->connection_create_failures64; |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 316 | stats->connection_destroy_requests64 += s->connection_destroy_requests64; |
| 317 | stats->connection_destroy_misses64 += s->connection_destroy_misses64; |
| 318 | stats->connection_match_hash_hits64 += s->connection_match_hash_hits64; |
| 319 | stats->connection_match_hash_reorders64 += s->connection_match_hash_reorders64; |
| 320 | stats->connection_flushes64 += s->connection_flushes64; |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 321 | stats->packets_dropped64 += s->packets_dropped64; |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 322 | stats->packets_forwarded64 += s->packets_forwarded64; |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 323 | stats->packets_fast_xmited64 += s->packets_fast_xmited64; |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 324 | stats->packets_not_forwarded64 += s->packets_not_forwarded64; |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 325 | stats->pppoe_encap_packets_forwarded64 += s->pppoe_encap_packets_forwarded64; |
| 326 | stats->pppoe_decap_packets_forwarded64 += s->pppoe_decap_packets_forwarded64; |
Guduri Prathyusha | 034d635 | 2022-01-12 16:49:04 +0530 | [diff] [blame] | 327 | stats->pppoe_bridge_packets_forwarded64 += s->pppoe_bridge_packets_forwarded64; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 328 | } |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 329 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /* |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 333 | * sfe_ipv4_insert_connection_match() |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 334 | * Insert a connection match into the hash. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 335 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 336 | static inline void sfe_ipv4_insert_connection_match(struct sfe_ipv4 *si, |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 337 | struct sfe_ipv4_connection_match *cm) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 338 | { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 339 | unsigned int conn_match_idx |
| 340 | = sfe_ipv4_get_connection_match_hash(cm->match_dev, cm->match_protocol, |
| 341 | cm->match_src_ip, cm->match_src_port, |
| 342 | cm->match_dest_ip, cm->match_dest_port); |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 343 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 344 | lockdep_assert_held(&si->lock); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 345 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 346 | hlist_add_head_rcu(&cm->hnode, &si->hlist_conn_match_hash_head[conn_match_idx]); |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 347 | #ifdef CONFIG_NF_FLOW_COOKIE |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 348 | if (!si->flow_cookie_enable) |
| 349 | return; |
| 350 | |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 351 | /* |
| 352 | * Configure hardware to put a flow cookie in packet of this flow, |
| 353 | * then we can accelerate the lookup process when we received this packet. |
| 354 | */ |
| 355 | for (conn_match_idx = 1; conn_match_idx < SFE_FLOW_COOKIE_SIZE; conn_match_idx++) { |
| 356 | struct sfe_flow_cookie_entry *entry = &si->sfe_flow_cookie_table[conn_match_idx]; |
| 357 | |
| 358 | if ((NULL == entry->match) && time_is_before_jiffies(entry->last_clean_time + HZ)) { |
| 359 | flow_cookie_set_func_t func; |
| 360 | |
| 361 | rcu_read_lock(); |
| 362 | func = rcu_dereference(si->flow_cookie_set_func); |
| 363 | if (func) { |
Xiaoping Fan | 5917642 | 2015-05-22 15:58:10 -0700 | [diff] [blame] | 364 | if (!func(cm->match_protocol, cm->match_src_ip, cm->match_src_port, |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 365 | cm->match_dest_ip, cm->match_dest_port, conn_match_idx)) { |
| 366 | entry->match = cm; |
| 367 | cm->flow_cookie = conn_match_idx; |
| 368 | } |
| 369 | } |
| 370 | rcu_read_unlock(); |
| 371 | |
| 372 | break; |
| 373 | } |
| 374 | } |
| 375 | #endif |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /* |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 379 | * sfe_ipv4_remove_connection_match() |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 380 | * Remove a connection match object from the hash. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 381 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 382 | static inline void sfe_ipv4_remove_connection_match(struct sfe_ipv4 *si, struct sfe_ipv4_connection_match *cm) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 383 | { |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 384 | |
| 385 | lockdep_assert_held(&si->lock); |
| 386 | |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 387 | #ifdef CONFIG_NF_FLOW_COOKIE |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 388 | if (si->flow_cookie_enable) { |
| 389 | /* |
| 390 | * Tell hardware that we no longer need a flow cookie in packet of this flow |
| 391 | */ |
| 392 | unsigned int conn_match_idx; |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 393 | |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 394 | for (conn_match_idx = 1; conn_match_idx < SFE_FLOW_COOKIE_SIZE; conn_match_idx++) { |
| 395 | struct sfe_flow_cookie_entry *entry = &si->sfe_flow_cookie_table[conn_match_idx]; |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 396 | |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 397 | if (cm == entry->match) { |
| 398 | flow_cookie_set_func_t func; |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 399 | |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 400 | rcu_read_lock(); |
| 401 | func = rcu_dereference(si->flow_cookie_set_func); |
| 402 | if (func) { |
| 403 | func(cm->match_protocol, cm->match_src_ip, cm->match_src_port, |
| 404 | cm->match_dest_ip, cm->match_dest_port, 0); |
| 405 | } |
| 406 | rcu_read_unlock(); |
| 407 | |
| 408 | cm->flow_cookie = 0; |
| 409 | entry->match = NULL; |
| 410 | entry->last_clean_time = jiffies; |
| 411 | break; |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 412 | } |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | #endif |
| 416 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 417 | hlist_del_init_rcu(&cm->hnode); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 418 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | /* |
| 422 | * sfe_ipv4_get_connection_hash() |
| 423 | * Generate the hash used in connection lookups. |
| 424 | */ |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 425 | static inline unsigned int sfe_ipv4_get_connection_hash(u8 protocol, __be32 src_ip, __be16 src_port, |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 426 | __be32 dest_ip, __be16 dest_port) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 427 | { |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 428 | u32 hash = ntohl(src_ip ^ dest_ip) ^ protocol ^ ntohs(src_port ^ dest_port); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 429 | return ((hash >> SFE_IPV4_CONNECTION_HASH_SHIFT) ^ hash) & SFE_IPV4_CONNECTION_HASH_MASK; |
| 430 | } |
| 431 | |
| 432 | /* |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 433 | * sfe_ipv4_find_connection() |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 434 | * Get the IPv4 connection info that corresponds to a particular 5-tuple. |
| 435 | * |
| 436 | * On entry we must be holding the lock that protects the hash table. |
| 437 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 438 | static inline struct sfe_ipv4_connection *sfe_ipv4_find_connection(struct sfe_ipv4 *si, u32 protocol, |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 439 | __be32 src_ip, __be16 src_port, |
| 440 | __be32 dest_ip, __be16 dest_port) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 441 | { |
| 442 | struct sfe_ipv4_connection *c; |
| 443 | unsigned int conn_idx = sfe_ipv4_get_connection_hash(protocol, src_ip, src_port, dest_ip, dest_port); |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 444 | |
| 445 | lockdep_assert_held(&si->lock); |
| 446 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 447 | c = si->conn_hash[conn_idx]; |
| 448 | |
| 449 | /* |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 450 | * Will need connection entry for next create/destroy metadata, |
| 451 | * So no need to re-order entry for these requests |
| 452 | */ |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 453 | while (c) { |
| 454 | if ((c->src_port == src_port) |
| 455 | && (c->dest_port == dest_port) |
| 456 | && (c->src_ip == src_ip) |
| 457 | && (c->dest_ip == dest_ip) |
| 458 | && (c->protocol == protocol)) { |
| 459 | return c; |
| 460 | } |
| 461 | |
| 462 | c = c->next; |
| 463 | } |
| 464 | |
| 465 | return NULL; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /* |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 469 | * sfe_ipv4_insert_connection() |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 470 | * Insert a connection into the hash. |
| 471 | * |
| 472 | * On entry we must be holding the lock that protects the hash table. |
| 473 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 474 | static void sfe_ipv4_insert_connection(struct sfe_ipv4 *si, struct sfe_ipv4_connection *c) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 475 | { |
| 476 | struct sfe_ipv4_connection **hash_head; |
| 477 | struct sfe_ipv4_connection *prev_head; |
| 478 | unsigned int conn_idx; |
| 479 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 480 | lockdep_assert_held(&si->lock); |
| 481 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 482 | /* |
| 483 | * Insert entry into the connection hash. |
| 484 | */ |
| 485 | conn_idx = sfe_ipv4_get_connection_hash(c->protocol, c->src_ip, c->src_port, |
| 486 | c->dest_ip, c->dest_port); |
| 487 | hash_head = &si->conn_hash[conn_idx]; |
| 488 | prev_head = *hash_head; |
| 489 | c->prev = NULL; |
| 490 | if (prev_head) { |
| 491 | prev_head->prev = c; |
| 492 | } |
| 493 | |
| 494 | c->next = prev_head; |
| 495 | *hash_head = c; |
| 496 | |
| 497 | /* |
| 498 | * Insert entry into the "all connections" list. |
| 499 | */ |
| 500 | if (si->all_connections_tail) { |
| 501 | c->all_connections_prev = si->all_connections_tail; |
| 502 | si->all_connections_tail->all_connections_next = c; |
| 503 | } else { |
| 504 | c->all_connections_prev = NULL; |
| 505 | si->all_connections_head = c; |
| 506 | } |
| 507 | |
| 508 | si->all_connections_tail = c; |
| 509 | c->all_connections_next = NULL; |
| 510 | si->num_connections++; |
| 511 | |
| 512 | /* |
| 513 | * Insert the connection match objects too. |
| 514 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 515 | sfe_ipv4_insert_connection_match(si, c->original_match); |
| 516 | sfe_ipv4_insert_connection_match(si, c->reply_match); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | /* |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 520 | * sfe_ipv4_remove_connection() |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 521 | * Remove a sfe_ipv4_connection object from the hash. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 522 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 523 | bool sfe_ipv4_remove_connection(struct sfe_ipv4 *si, struct sfe_ipv4_connection *c) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 524 | { |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 525 | lockdep_assert_held(&si->lock); |
| 526 | |
| 527 | if (c->removed) { |
| 528 | DEBUG_ERROR("%px: Connection has been removed already\n", c); |
| 529 | return false; |
| 530 | } |
| 531 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 532 | /* |
| 533 | * Remove the connection match objects. |
| 534 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 535 | sfe_ipv4_remove_connection_match(si, c->reply_match); |
| 536 | sfe_ipv4_remove_connection_match(si, c->original_match); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 537 | |
| 538 | /* |
| 539 | * Unlink the connection. |
| 540 | */ |
| 541 | if (c->prev) { |
| 542 | c->prev->next = c->next; |
| 543 | } else { |
| 544 | unsigned int conn_idx = sfe_ipv4_get_connection_hash(c->protocol, c->src_ip, c->src_port, |
| 545 | c->dest_ip, c->dest_port); |
| 546 | si->conn_hash[conn_idx] = c->next; |
| 547 | } |
| 548 | |
| 549 | if (c->next) { |
| 550 | c->next->prev = c->prev; |
| 551 | } |
Xiaoping Fan | 3458647 | 2015-07-03 02:20:35 -0700 | [diff] [blame] | 552 | |
| 553 | /* |
| 554 | * Unlink connection from all_connections list |
| 555 | */ |
| 556 | if (c->all_connections_prev) { |
| 557 | c->all_connections_prev->all_connections_next = c->all_connections_next; |
| 558 | } else { |
| 559 | si->all_connections_head = c->all_connections_next; |
| 560 | } |
| 561 | |
| 562 | if (c->all_connections_next) { |
| 563 | c->all_connections_next->all_connections_prev = c->all_connections_prev; |
| 564 | } else { |
| 565 | si->all_connections_tail = c->all_connections_prev; |
| 566 | } |
| 567 | |
Ken Zhu | dc42367 | 2021-09-02 18:27:01 -0700 | [diff] [blame] | 568 | /* |
| 569 | * If I am the next sync connection, move the sync to my next or head. |
| 570 | */ |
| 571 | if (unlikely(si->wc_next == c)) { |
| 572 | si->wc_next = c->all_connections_next; |
| 573 | } |
| 574 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 575 | c->removed = true; |
Xiaoping Fan | 3458647 | 2015-07-03 02:20:35 -0700 | [diff] [blame] | 576 | si->num_connections--; |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 577 | return true; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | /* |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 581 | * sfe_ipv4_gen_sync_connection() |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 582 | * Sync a connection. |
| 583 | * |
| 584 | * On entry to this function we expect that the lock for the connection is either |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 585 | * already held (while called from sfe_ipv4_periodic_sync() or isn't required |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 586 | * (while called from sfe_ipv4_flush_connection()) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 587 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 588 | static void sfe_ipv4_gen_sync_connection(struct sfe_ipv4 *si, struct sfe_ipv4_connection *c, |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame] | 589 | struct sfe_connection_sync *sis, sfe_sync_reason_t reason, |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 590 | u64 now_jiffies) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 591 | { |
| 592 | struct sfe_ipv4_connection_match *original_cm; |
| 593 | struct sfe_ipv4_connection_match *reply_cm; |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 594 | u32 packet_count, byte_count; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 595 | |
| 596 | /* |
| 597 | * Fill in the update message. |
| 598 | */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 599 | sis->is_v6 = 0; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 600 | sis->protocol = c->protocol; |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 601 | sis->src_ip.ip = c->src_ip; |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame] | 602 | sis->src_ip_xlate.ip = c->src_ip_xlate; |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 603 | sis->dest_ip.ip = c->dest_ip; |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame] | 604 | sis->dest_ip_xlate.ip = c->dest_ip_xlate; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 605 | sis->src_port = c->src_port; |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame] | 606 | sis->src_port_xlate = c->src_port_xlate; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 607 | sis->dest_port = c->dest_port; |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame] | 608 | sis->dest_port_xlate = c->dest_port_xlate; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 609 | |
| 610 | original_cm = c->original_match; |
| 611 | reply_cm = c->reply_match; |
| 612 | sis->src_td_max_window = original_cm->protocol_state.tcp.max_win; |
| 613 | sis->src_td_end = original_cm->protocol_state.tcp.end; |
| 614 | sis->src_td_max_end = original_cm->protocol_state.tcp.max_end; |
| 615 | sis->dest_td_max_window = reply_cm->protocol_state.tcp.max_win; |
| 616 | sis->dest_td_end = reply_cm->protocol_state.tcp.end; |
| 617 | sis->dest_td_max_end = reply_cm->protocol_state.tcp.max_end; |
| 618 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 619 | sfe_ipv4_connection_match_update_summary_stats(original_cm, &packet_count, &byte_count); |
| 620 | sis->src_new_packet_count = packet_count; |
| 621 | sis->src_new_byte_count = byte_count; |
Matthew McClintock | d0cdb80 | 2014-02-24 16:30:35 -0600 | [diff] [blame] | 622 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 623 | sfe_ipv4_connection_match_update_summary_stats(reply_cm, &packet_count, &byte_count); |
| 624 | sis->dest_new_packet_count = packet_count; |
| 625 | sis->dest_new_byte_count = byte_count; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 626 | |
Matthew McClintock | d0cdb80 | 2014-02-24 16:30:35 -0600 | [diff] [blame] | 627 | sis->src_dev = original_cm->match_dev; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 628 | sis->src_packet_count = original_cm->rx_packet_count64; |
| 629 | sis->src_byte_count = original_cm->rx_byte_count64; |
Matthew McClintock | d0cdb80 | 2014-02-24 16:30:35 -0600 | [diff] [blame] | 630 | |
| 631 | sis->dest_dev = reply_cm->match_dev; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 632 | sis->dest_packet_count = reply_cm->rx_packet_count64; |
| 633 | sis->dest_byte_count = reply_cm->rx_byte_count64; |
| 634 | |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame] | 635 | sis->reason = reason; |
| 636 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 637 | /* |
| 638 | * Get the time increment since our last sync. |
| 639 | */ |
| 640 | sis->delta_jiffies = now_jiffies - c->last_sync_jiffies; |
| 641 | c->last_sync_jiffies = now_jiffies; |
| 642 | } |
| 643 | |
| 644 | /* |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 645 | * sfe_ipv4_free_connection_rcu() |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 646 | * Called at RCU qs state to free the connection object. |
| 647 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 648 | static void sfe_ipv4_free_connection_rcu(struct rcu_head *head) |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 649 | { |
| 650 | struct sfe_ipv4_connection *c; |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 651 | struct udp_sock *up; |
| 652 | struct sock *sk; |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 653 | |
| 654 | /* |
| 655 | * We dont need spin lock as the connection is already removed from link list |
| 656 | */ |
| 657 | c = container_of(head, struct sfe_ipv4_connection, rcu); |
| 658 | |
| 659 | BUG_ON(!c->removed); |
| 660 | |
| 661 | DEBUG_TRACE("%px: connecton has been deleted\n", c); |
| 662 | |
| 663 | /* |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 664 | * Decrease the refcount taken in function sfe_ipv4_create_rule(), |
| 665 | * during call of __udp4_lib_lookup() |
| 666 | */ |
| 667 | up = c->reply_match->up; |
| 668 | if (up) { |
| 669 | sk = (struct sock *)up; |
| 670 | sock_put(sk); |
| 671 | } |
| 672 | |
| 673 | /* |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 674 | * Release our hold of the source and dest devices and free the memory |
| 675 | * for our connection objects. |
| 676 | */ |
| 677 | dev_put(c->original_dev); |
| 678 | dev_put(c->reply_dev); |
| 679 | kfree(c->original_match); |
| 680 | kfree(c->reply_match); |
| 681 | kfree(c); |
| 682 | } |
| 683 | |
| 684 | /* |
Ken Zhu | 88c5815 | 2021-12-09 15:12:06 -0800 | [diff] [blame] | 685 | * sfe_ipv4_sync_status() |
| 686 | * update a connection status to its connection manager. |
| 687 | * |
| 688 | * si: the ipv4 context |
| 689 | * c: which connection to be notified |
| 690 | * reason: what kind of notification: flush, stats or destroy |
| 691 | */ |
| 692 | void sfe_ipv4_sync_status(struct sfe_ipv4 *si, |
| 693 | struct sfe_ipv4_connection *c, |
| 694 | sfe_sync_reason_t reason) |
| 695 | { |
| 696 | struct sfe_connection_sync sis; |
| 697 | u64 now_jiffies; |
| 698 | sfe_sync_rule_callback_t sync_rule_callback; |
| 699 | |
| 700 | rcu_read_lock(); |
| 701 | sync_rule_callback = rcu_dereference(si->sync_rule_callback); |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 702 | rcu_read_unlock(); |
Ken Zhu | 88c5815 | 2021-12-09 15:12:06 -0800 | [diff] [blame] | 703 | if (!sync_rule_callback) { |
Ken Zhu | 88c5815 | 2021-12-09 15:12:06 -0800 | [diff] [blame] | 704 | return; |
| 705 | } |
| 706 | |
| 707 | /* |
| 708 | * Generate a sync message and then sync. |
| 709 | */ |
| 710 | now_jiffies = get_jiffies_64(); |
| 711 | sfe_ipv4_gen_sync_connection(si, c, &sis, reason, now_jiffies); |
| 712 | sync_rule_callback(&sis); |
Ken Zhu | 88c5815 | 2021-12-09 15:12:06 -0800 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | /* |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 716 | * sfe_ipv4_flush_connection() |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 717 | * Flush a connection and free all associated resources. |
| 718 | * |
| 719 | * We need to be called with bottom halves disabled locally as we need to acquire |
| 720 | * the connection hash lock and release it again. In general we're actually called |
| 721 | * from within a BH and so we're fine, but we're also called when connections are |
| 722 | * torn down. |
| 723 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 724 | void sfe_ipv4_flush_connection(struct sfe_ipv4 *si, |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 725 | struct sfe_ipv4_connection *c, |
| 726 | sfe_sync_reason_t reason) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 727 | { |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 728 | BUG_ON(!c->removed); |
| 729 | |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 730 | this_cpu_inc(si->stats_pcpu->connection_flushes64); |
Ken Zhu | 88c5815 | 2021-12-09 15:12:06 -0800 | [diff] [blame] | 731 | sfe_ipv4_sync_status(si, c, reason); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 732 | |
| 733 | /* |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 734 | * Release our hold of the source and dest devices and free the memory |
| 735 | * for our connection objects. |
| 736 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 737 | call_rcu(&c->rcu, sfe_ipv4_free_connection_rcu); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | /* |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 741 | * sfe_ipv4_service_class_stats_inc() |
| 742 | * Increment per cpu per service class stats. |
| 743 | */ |
| 744 | void sfe_ipv4_service_class_stats_inc(struct sfe_ipv4 *si, uint8_t sid, uint64_t bytes) |
| 745 | { |
| 746 | struct sfe_ipv4_service_class_stats_db *sc_stats_db = this_cpu_ptr(si->stats_pcpu_psc); |
| 747 | struct sfe_ipv4_per_service_class_stats *sc_stats = &sc_stats_db->psc_stats[sid]; |
| 748 | |
| 749 | write_seqcount_begin(&sc_stats->seq); |
| 750 | sc_stats->tx_bytes += bytes; |
| 751 | sc_stats->tx_packets++; |
| 752 | write_seqcount_end(&sc_stats->seq); |
| 753 | } |
| 754 | |
| 755 | /* |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 756 | * sfe_ipv4_exception_stats_inc() |
| 757 | * Increment exception stats. |
| 758 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 759 | void sfe_ipv4_exception_stats_inc(struct sfe_ipv4 *si, enum sfe_ipv4_exception_events reason) |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 760 | { |
| 761 | struct sfe_ipv4_stats *stats = this_cpu_ptr(si->stats_pcpu); |
| 762 | stats->exception_events64[reason]++; |
| 763 | stats->packets_not_forwarded64++; |
| 764 | } |
| 765 | |
| 766 | /* |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 767 | * sfe_ipv4_is_loal_ip() |
| 768 | * Returns true if IP is local; returns false otherwise. |
| 769 | */ |
| 770 | static bool sfe_ipv4_is_local_ip(struct sfe_ipv4 *si, __be32 ip_addr) |
| 771 | { |
| 772 | struct net_device *dev; |
| 773 | |
| 774 | dev = ip_dev_find(&init_net, ip_addr); |
| 775 | if (dev) { |
| 776 | dev_put(dev); |
| 777 | return true; |
| 778 | } |
| 779 | |
| 780 | return false; |
| 781 | } |
| 782 | |
| 783 | /* |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 784 | * sfe_ipv4_recv() |
Matthew McClintock | a8ad796 | 2014-01-16 16:49:30 -0600 | [diff] [blame] | 785 | * Handle packet receives and forwaring. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 786 | * |
| 787 | * Returns 1 if the packet is forwarded or 0 if it isn't. |
| 788 | */ |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 789 | int sfe_ipv4_recv(struct net_device *dev, struct sk_buff *skb, struct sfe_l2_info *l2_info, bool tun_outer) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 790 | { |
| 791 | struct sfe_ipv4 *si = &__si; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 792 | unsigned int len; |
| 793 | unsigned int tot_len; |
| 794 | unsigned int frag_off; |
| 795 | unsigned int ihl; |
Ken Zhu | 88c5815 | 2021-12-09 15:12:06 -0800 | [diff] [blame] | 796 | bool sync_on_find; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 797 | bool ip_options; |
Ratheesh Kannoth | 741f799 | 2021-10-20 07:39:52 +0530 | [diff] [blame] | 798 | struct iphdr *iph; |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 799 | u32 protocol; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 800 | |
| 801 | /* |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 802 | * Check that we have space for an IP header here. |
| 803 | */ |
| 804 | len = skb->len; |
Ratheesh Kannoth | 741f799 | 2021-10-20 07:39:52 +0530 | [diff] [blame] | 805 | if (unlikely(!pskb_may_pull(skb, sizeof(struct iphdr)))) { |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 806 | sfe_ipv4_exception_stats_inc(si, SFE_IPV4_EXCEPTION_EVENT_HEADER_INCOMPLETE); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 807 | DEBUG_TRACE("len: %u is too short\n", len); |
| 808 | return 0; |
| 809 | } |
| 810 | |
| 811 | /* |
Ratheesh Kannoth | a3cf0e0 | 2021-12-09 09:44:10 +0530 | [diff] [blame] | 812 | * Validate ip csum if necessary. If ip_summed is set to CHECKSUM_UNNECESSARY, it is assumed |
| 813 | * that the L3 checksum is validated by the Rx interface or the tunnel interface that has |
| 814 | * generated the packet. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 815 | */ |
Ratheesh Kannoth | 741f799 | 2021-10-20 07:39:52 +0530 | [diff] [blame] | 816 | iph = (struct iphdr *)skb->data; |
Ratheesh Kannoth | 43d64f8 | 2021-10-20 08:23:29 +0530 | [diff] [blame] | 817 | if (unlikely(skb->ip_summed != CHECKSUM_UNNECESSARY) && (ip_fast_csum((u8 *)iph, iph->ihl))) { |
| 818 | sfe_ipv4_exception_stats_inc(si, SFE_IPV4_EXCEPTION_EVENT_HEADER_CSUM_BAD); |
| 819 | |
| 820 | DEBUG_TRACE("Bad IPv4 header csum: 0x%x\n", iph->check); |
| 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | /* |
| 825 | * Check that our "total length" is large enough for an IP header. |
| 826 | */ |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 827 | tot_len = ntohs(iph->tot_len); |
Ratheesh Kannoth | 741f799 | 2021-10-20 07:39:52 +0530 | [diff] [blame] | 828 | if (unlikely(tot_len < sizeof(struct iphdr))) { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 829 | |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 830 | sfe_ipv4_exception_stats_inc(si, SFE_IPV4_EXCEPTION_EVENT_BAD_TOTAL_LENGTH); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 831 | DEBUG_TRACE("tot_len: %u is too short\n", tot_len); |
| 832 | return 0; |
| 833 | } |
| 834 | |
| 835 | /* |
| 836 | * Is our IP version wrong? |
| 837 | */ |
| 838 | if (unlikely(iph->version != 4)) { |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 839 | sfe_ipv4_exception_stats_inc(si, SFE_IPV4_EXCEPTION_EVENT_NON_V4); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 840 | DEBUG_TRACE("IP version: %u\n", iph->version); |
| 841 | return 0; |
| 842 | } |
| 843 | |
| 844 | /* |
| 845 | * Does our datagram fit inside the skb? |
| 846 | */ |
| 847 | if (unlikely(tot_len > len)) { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 848 | DEBUG_TRACE("tot_len: %u, exceeds len: %u\n", tot_len, len); |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 849 | sfe_ipv4_exception_stats_inc(si, SFE_IPV4_EXCEPTION_EVENT_DATAGRAM_INCOMPLETE); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | /* |
| 854 | * Do we have a non-initial fragment? |
Nicolas Costa | ac2979c | 2014-01-14 10:35:24 -0600 | [diff] [blame] | 855 | */ |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 856 | frag_off = ntohs(iph->frag_off); |
| 857 | if (unlikely(frag_off & IP_OFFSET)) { |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 858 | sfe_ipv4_exception_stats_inc(si, SFE_IPV4_EXCEPTION_EVENT_NON_INITIAL_FRAGMENT); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 859 | DEBUG_TRACE("non-initial fragment\n"); |
| 860 | return 0; |
| 861 | } |
| 862 | |
| 863 | /* |
| 864 | * If we have a (first) fragment then mark it to cause any connection to flush. |
| 865 | */ |
Ken Zhu | 88c5815 | 2021-12-09 15:12:06 -0800 | [diff] [blame] | 866 | sync_on_find = unlikely(frag_off & IP_MF) ? true : false; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 867 | |
| 868 | /* |
| 869 | * Do we have any IP options? That's definite a slow path! If we do have IP |
| 870 | * options we need to recheck our header size. |
| 871 | */ |
| 872 | ihl = iph->ihl << 2; |
Ratheesh Kannoth | 741f799 | 2021-10-20 07:39:52 +0530 | [diff] [blame] | 873 | ip_options = unlikely(ihl != sizeof(struct iphdr)) ? true : false; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 874 | if (unlikely(ip_options)) { |
| 875 | if (unlikely(len < ihl)) { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 876 | |
| 877 | DEBUG_TRACE("len: %u is too short for header of size: %u\n", len, ihl); |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 878 | sfe_ipv4_exception_stats_inc(si, SFE_IPV4_EXCEPTION_EVENT_IP_OPTIONS_INCOMPLETE); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 879 | return 0; |
| 880 | } |
| 881 | |
Ken Zhu | 88c5815 | 2021-12-09 15:12:06 -0800 | [diff] [blame] | 882 | sync_on_find = true; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | protocol = iph->protocol; |
| 886 | if (IPPROTO_UDP == protocol) { |
Ken Zhu | 88c5815 | 2021-12-09 15:12:06 -0800 | [diff] [blame] | 887 | return sfe_ipv4_recv_udp(si, skb, dev, len, iph, ihl, sync_on_find, l2_info, tun_outer); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | if (IPPROTO_TCP == protocol) { |
Ken Zhu | 88c5815 | 2021-12-09 15:12:06 -0800 | [diff] [blame] | 891 | return sfe_ipv4_recv_tcp(si, skb, dev, len, iph, ihl, sync_on_find, l2_info); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | if (IPPROTO_ICMP == protocol) { |
| 895 | return sfe_ipv4_recv_icmp(si, skb, dev, len, iph, ihl); |
| 896 | } |
| 897 | |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 898 | #ifdef SFE_GRE_TUN_ENABLE |
| 899 | if (IPPROTO_GRE == protocol) { |
Nitin Shetty | 2114a89 | 2022-01-28 20:03:56 +0530 | [diff] [blame] | 900 | return sfe_ipv4_recv_gre(si, skb, dev, len, iph, ihl, sync_on_find, l2_info, tun_outer); |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 901 | } |
| 902 | #endif |
Tian Yang | d98d91b | 2022-03-09 14:50:12 -0800 | [diff] [blame^] | 903 | if (IPPROTO_IPV6 == protocol) { |
| 904 | return sfe_ipv4_recv_tun6rd(si, skb, dev, len, iph, ihl, sync_on_find, l2_info, true); |
| 905 | } |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 906 | |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 907 | sfe_ipv4_exception_stats_inc(si, SFE_IPV4_EXCEPTION_EVENT_UNHANDLED_PROTOCOL); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 908 | |
| 909 | DEBUG_TRACE("not UDP, TCP or ICMP: %u\n", protocol); |
| 910 | return 0; |
| 911 | } |
| 912 | |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 913 | static void |
| 914 | sfe_ipv4_update_tcp_state(struct sfe_ipv4_connection *c, |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 915 | struct sfe_ipv4_rule_create_msg *msg) |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 916 | { |
| 917 | struct sfe_ipv4_connection_match *orig_cm; |
| 918 | struct sfe_ipv4_connection_match *repl_cm; |
| 919 | struct sfe_ipv4_tcp_connection_match *orig_tcp; |
| 920 | struct sfe_ipv4_tcp_connection_match *repl_tcp; |
| 921 | |
| 922 | orig_cm = c->original_match; |
| 923 | repl_cm = c->reply_match; |
| 924 | orig_tcp = &orig_cm->protocol_state.tcp; |
| 925 | repl_tcp = &repl_cm->protocol_state.tcp; |
| 926 | |
| 927 | /* update orig */ |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 928 | if (orig_tcp->max_win < msg->tcp_rule.flow_max_window) { |
| 929 | orig_tcp->max_win = msg->tcp_rule.flow_max_window; |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 930 | } |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 931 | if ((s32)(orig_tcp->end - msg->tcp_rule.flow_end) < 0) { |
| 932 | orig_tcp->end = msg->tcp_rule.flow_end; |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 933 | } |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 934 | if ((s32)(orig_tcp->max_end - msg->tcp_rule.flow_max_end) < 0) { |
| 935 | orig_tcp->max_end = msg->tcp_rule.flow_max_end; |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | /* update reply */ |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 939 | if (repl_tcp->max_win < msg->tcp_rule.return_max_window) { |
| 940 | repl_tcp->max_win = msg->tcp_rule.return_max_window; |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 941 | } |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 942 | if ((s32)(repl_tcp->end - msg->tcp_rule.return_end) < 0) { |
| 943 | repl_tcp->end = msg->tcp_rule.return_end; |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 944 | } |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 945 | if ((s32)(repl_tcp->max_end - msg->tcp_rule.return_max_end) < 0) { |
| 946 | repl_tcp->max_end = msg->tcp_rule.return_max_end; |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | /* update match flags */ |
| 950 | orig_cm->flags &= ~SFE_IPV4_CONNECTION_MATCH_FLAG_NO_SEQ_CHECK; |
| 951 | repl_cm->flags &= ~SFE_IPV4_CONNECTION_MATCH_FLAG_NO_SEQ_CHECK; |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 952 | if (msg->rule_flags & SFE_RULE_CREATE_FLAG_NO_SEQ_CHECK) { |
| 953 | |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 954 | orig_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_NO_SEQ_CHECK; |
| 955 | repl_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_NO_SEQ_CHECK; |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | static void |
| 960 | sfe_ipv4_update_protocol_state(struct sfe_ipv4_connection *c, |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 961 | struct sfe_ipv4_rule_create_msg *msg) |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 962 | { |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 963 | switch (msg->tuple.protocol) { |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 964 | case IPPROTO_TCP: |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 965 | sfe_ipv4_update_tcp_state(c, msg); |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 966 | break; |
| 967 | } |
| 968 | } |
| 969 | |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 970 | /* |
| 971 | * sfe_ipv4_match_entry_set_vlan() |
| 972 | */ |
| 973 | static void sfe_ipv4_match_entry_set_vlan( |
| 974 | struct sfe_ipv4_connection_match *cm, |
| 975 | u32 primary_ingress_vlan_tag, |
| 976 | u32 primary_egress_vlan_tag, |
| 977 | u32 secondary_ingress_vlan_tag, |
| 978 | u32 secondary_egress_vlan_tag) |
| 979 | { |
| 980 | u16 tpid; |
| 981 | /* |
| 982 | * Prevent stacking header counts when updating. |
| 983 | */ |
| 984 | cm->ingress_vlan_hdr_cnt = 0; |
| 985 | cm->egress_vlan_hdr_cnt = 0; |
| 986 | memset(cm->ingress_vlan_hdr, 0, sizeof(cm->ingress_vlan_hdr)); |
| 987 | memset(cm->egress_vlan_hdr, 0, sizeof(cm->egress_vlan_hdr)); |
| 988 | |
| 989 | /* |
| 990 | * vlan_hdr[0] corresponds to outer tag |
| 991 | * vlan_hdr[1] corresponds to inner tag |
| 992 | * Extract the vlan information (tpid and tci) from rule message |
| 993 | */ |
| 994 | if ((primary_ingress_vlan_tag & VLAN_VID_MASK) != SFE_VLAN_ID_NOT_CONFIGURED) { |
| 995 | tpid = (u16)(primary_ingress_vlan_tag >> 16); |
| 996 | cm->ingress_vlan_hdr[0].tpid = ntohs(tpid); |
| 997 | cm->ingress_vlan_hdr[0].tci = (u16)primary_ingress_vlan_tag; |
| 998 | cm->ingress_vlan_hdr_cnt++; |
| 999 | } |
| 1000 | |
| 1001 | if ((secondary_ingress_vlan_tag & VLAN_VID_MASK) != SFE_VLAN_ID_NOT_CONFIGURED) { |
| 1002 | tpid = (u16)(secondary_ingress_vlan_tag >> 16); |
| 1003 | cm->ingress_vlan_hdr[1].tpid = ntohs(tpid); |
| 1004 | cm->ingress_vlan_hdr[1].tci = (u16)secondary_ingress_vlan_tag; |
| 1005 | cm->ingress_vlan_hdr_cnt++; |
| 1006 | } |
| 1007 | |
| 1008 | if ((primary_egress_vlan_tag & VLAN_VID_MASK) != SFE_VLAN_ID_NOT_CONFIGURED) { |
| 1009 | tpid = (u16)(primary_egress_vlan_tag >> 16); |
| 1010 | cm->egress_vlan_hdr[0].tpid = ntohs(tpid); |
| 1011 | cm->egress_vlan_hdr[0].tci = (u16)primary_egress_vlan_tag; |
| 1012 | cm->egress_vlan_hdr_cnt++; |
| 1013 | } |
| 1014 | |
| 1015 | if ((secondary_egress_vlan_tag & VLAN_VID_MASK) != SFE_VLAN_ID_NOT_CONFIGURED) { |
| 1016 | tpid = (u16)(secondary_egress_vlan_tag >> 16); |
| 1017 | cm->egress_vlan_hdr[1].tpid = ntohs(tpid); |
| 1018 | cm->egress_vlan_hdr[1].tci = (u16)secondary_egress_vlan_tag; |
| 1019 | cm->egress_vlan_hdr_cnt++; |
| 1020 | } |
| 1021 | } |
| 1022 | |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1023 | void sfe_ipv4_update_rule(struct sfe_ipv4_rule_create_msg *msg) |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 1024 | { |
| 1025 | struct sfe_ipv4_connection *c; |
| 1026 | struct sfe_ipv4 *si = &__si; |
| 1027 | |
| 1028 | spin_lock_bh(&si->lock); |
| 1029 | |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 1030 | c = sfe_ipv4_find_connection(si, |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1031 | msg->tuple.protocol, |
| 1032 | msg->tuple.flow_ip, |
| 1033 | msg->tuple.flow_ident, |
| 1034 | msg->tuple.return_ip, |
| 1035 | msg->tuple.return_ident); |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 1036 | if (c != NULL) { |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1037 | sfe_ipv4_update_protocol_state(c, msg); |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | spin_unlock_bh(&si->lock); |
| 1041 | } |
| 1042 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1043 | /* |
Guduri Prathyusha | 79a5fee | 2021-11-11 17:59:10 +0530 | [diff] [blame] | 1044 | * sfe_ipv4_xmit_eth_type_check() |
| 1045 | * Checking if MAC header has to be written. |
| 1046 | */ |
| 1047 | static inline bool sfe_ipv4_xmit_eth_type_check(struct net_device *dev, u32 cm_flags) |
| 1048 | { |
| 1049 | if (!(dev->flags & IFF_NOARP)) { |
| 1050 | return true; |
| 1051 | } |
| 1052 | |
| 1053 | /* |
| 1054 | * For PPPoE, since we are now supporting PPPoE encapsulation, we are writing L2 header. |
| 1055 | */ |
| 1056 | if (unlikely(cm_flags & SFE_IPV4_CONNECTION_MATCH_FLAG_PPPOE_ENCAP)) { |
| 1057 | return true; |
| 1058 | } |
| 1059 | |
| 1060 | return false; |
| 1061 | } |
| 1062 | |
| 1063 | /* |
Jackson Bockus | 3fafbf3 | 2022-02-13 17:15:26 -0800 | [diff] [blame] | 1064 | * sfe_ipv4_service_class_stats_pcpu_get() |
| 1065 | * Gets one CPU's service class statistics. |
| 1066 | */ |
| 1067 | static inline bool sfe_ipv4_service_class_stats_pcpu_get(struct sfe_ipv4_per_service_class_stats *sc_stats, uint64_t *bytes, uint64_t *packets) |
| 1068 | { |
| 1069 | uint32_t retries = 0; |
| 1070 | uint32_t seq; |
| 1071 | uint64_t bytes_tmp, packets_tmp; |
| 1072 | |
| 1073 | do { |
| 1074 | seq = read_seqcount_begin(&sc_stats->seq); |
| 1075 | bytes_tmp = sc_stats->tx_bytes; |
| 1076 | packets_tmp = sc_stats->tx_packets; |
| 1077 | } while (read_seqcount_retry(&sc_stats->seq, seq) && ++retries < SFE_SERVICE_CLASS_STATS_MAX_RETRY); |
| 1078 | |
| 1079 | *bytes += bytes_tmp; |
| 1080 | *packets += packets_tmp; |
| 1081 | |
| 1082 | return retries < SFE_SERVICE_CLASS_STATS_MAX_RETRY; |
| 1083 | } |
| 1084 | |
| 1085 | /* |
| 1086 | * sfe_ipv4_service_class_stats_get() |
| 1087 | * Copy the ipv4 statistics for the given service class. |
| 1088 | */ |
| 1089 | bool sfe_ipv4_service_class_stats_get(uint8_t sid, uint64_t *bytes, uint64_t *packets) |
| 1090 | { |
| 1091 | struct sfe_ipv4 *si = &__si; |
| 1092 | uint32_t cpu = 0; |
| 1093 | |
| 1094 | for_each_possible_cpu(cpu) { |
| 1095 | struct sfe_ipv4_service_class_stats_db *stats_db = per_cpu_ptr(si->stats_pcpu_psc, cpu); |
| 1096 | struct sfe_ipv4_per_service_class_stats *sc_stats = &stats_db->psc_stats[sid]; |
| 1097 | |
| 1098 | if (!sfe_ipv4_service_class_stats_pcpu_get(sc_stats, bytes, packets)) { |
| 1099 | return false; |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | return true; |
| 1104 | } |
| 1105 | |
| 1106 | /* |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1107 | * sfe_ipv4_create_rule() |
| 1108 | * Create a forwarding rule. |
| 1109 | */ |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1110 | int sfe_ipv4_create_rule(struct sfe_ipv4_rule_create_msg *msg) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1111 | { |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1112 | struct sfe_ipv4 *si = &__si; |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1113 | struct sfe_ipv4_connection *c, *c_old; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1114 | struct sfe_ipv4_connection_match *original_cm; |
| 1115 | struct sfe_ipv4_connection_match *reply_cm; |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1116 | struct net_device *dest_dev; |
| 1117 | struct net_device *src_dev; |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1118 | struct sfe_ipv4_5tuple *tuple = &msg->tuple; |
Suruchi Suman | c1a4a61 | 2021-10-21 14:50:23 +0530 | [diff] [blame] | 1119 | s32 flow_interface_num = msg->conn_rule.flow_top_interface_num; |
| 1120 | s32 return_interface_num = msg->conn_rule.return_top_interface_num; |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 1121 | struct net *net; |
| 1122 | struct sock *sk; |
| 1123 | unsigned int src_if_idx; |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 1124 | u32 flow_sawf_tag; |
| 1125 | u32 return_sawf_tag; |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1126 | |
Suruchi Suman | c1a4a61 | 2021-10-21 14:50:23 +0530 | [diff] [blame] | 1127 | if (msg->rule_flags & SFE_RULE_CREATE_FLAG_USE_FLOW_BOTTOM_INTERFACE) { |
| 1128 | flow_interface_num = msg->conn_rule.flow_interface_num; |
| 1129 | } |
| 1130 | |
| 1131 | if (msg->rule_flags & SFE_RULE_CREATE_FLAG_USE_RETURN_BOTTOM_INTERFACE) { |
| 1132 | return_interface_num = msg->conn_rule.return_interface_num; |
| 1133 | } |
| 1134 | |
| 1135 | src_dev = dev_get_by_index(&init_net, flow_interface_num); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1136 | if (!src_dev) { |
| 1137 | DEBUG_WARN("%px: Unable to find src_dev corresponding to %d\n", msg, |
Suruchi Suman | c1a4a61 | 2021-10-21 14:50:23 +0530 | [diff] [blame] | 1138 | flow_interface_num); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1139 | this_cpu_inc(si->stats_pcpu->connection_create_failures64); |
| 1140 | return -EINVAL; |
| 1141 | } |
| 1142 | |
Suruchi Suman | c1a4a61 | 2021-10-21 14:50:23 +0530 | [diff] [blame] | 1143 | dest_dev = dev_get_by_index(&init_net, return_interface_num); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1144 | if (!dest_dev) { |
| 1145 | DEBUG_WARN("%px: Unable to find dest_dev corresponding to %d\n", msg, |
Suruchi Suman | c1a4a61 | 2021-10-21 14:50:23 +0530 | [diff] [blame] | 1146 | return_interface_num); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1147 | this_cpu_inc(si->stats_pcpu->connection_create_failures64); |
| 1148 | dev_put(src_dev); |
| 1149 | return -EINVAL; |
| 1150 | } |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1151 | |
Matthew McClintock | 389b42a | 2014-09-24 14:05:51 -0500 | [diff] [blame] | 1152 | if (unlikely((dest_dev->reg_state != NETREG_REGISTERED) || |
| 1153 | (src_dev->reg_state != NETREG_REGISTERED))) { |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1154 | dev_put(src_dev); |
| 1155 | dev_put(dest_dev); |
| 1156 | DEBUG_WARN("%px: src_dev=%s and dest_dev=%s are unregistered\n", msg, |
| 1157 | src_dev->name, dest_dev->name); |
| 1158 | this_cpu_inc(si->stats_pcpu->connection_create_failures64); |
Matthew McClintock | 389b42a | 2014-09-24 14:05:51 -0500 | [diff] [blame] | 1159 | return -EINVAL; |
| 1160 | } |
| 1161 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1162 | /* |
| 1163 | * Allocate the various connection tracking objects. |
| 1164 | */ |
| 1165 | c = (struct sfe_ipv4_connection *)kmalloc(sizeof(struct sfe_ipv4_connection), GFP_ATOMIC); |
| 1166 | if (unlikely(!c)) { |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1167 | DEBUG_WARN("%px: memory allocation of connection entry failed\n", msg); |
| 1168 | this_cpu_inc(si->stats_pcpu->connection_create_failures64); |
| 1169 | dev_put(src_dev); |
| 1170 | dev_put(dest_dev); |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1171 | return -ENOMEM; |
| 1172 | } |
| 1173 | |
| 1174 | original_cm = (struct sfe_ipv4_connection_match *)kmalloc(sizeof(struct sfe_ipv4_connection_match), GFP_ATOMIC); |
| 1175 | if (unlikely(!original_cm)) { |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1176 | DEBUG_WARN("%px: memory allocation of connection match entry failed\n", msg); |
| 1177 | this_cpu_inc(si->stats_pcpu->connection_create_failures64); |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1178 | kfree(c); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1179 | dev_put(src_dev); |
| 1180 | dev_put(dest_dev); |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1181 | return -ENOMEM; |
| 1182 | } |
| 1183 | |
| 1184 | reply_cm = (struct sfe_ipv4_connection_match *)kmalloc(sizeof(struct sfe_ipv4_connection_match), GFP_ATOMIC); |
| 1185 | if (unlikely(!reply_cm)) { |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1186 | DEBUG_WARN("%px: memory allocation of connection match entry failed\n", msg); |
| 1187 | this_cpu_inc(si->stats_pcpu->connection_create_failures64); |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1188 | kfree(original_cm); |
| 1189 | kfree(c); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1190 | dev_put(src_dev); |
| 1191 | dev_put(dest_dev); |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1192 | return -ENOMEM; |
| 1193 | } |
| 1194 | |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 1195 | this_cpu_inc(si->stats_pcpu->connection_create_requests64); |
| 1196 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1197 | spin_lock_bh(&si->lock); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1198 | |
| 1199 | /* |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 1200 | * Check to see if there is already a flow that matches the rule we're |
| 1201 | * trying to create. If there is then we can't create a new one. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1202 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 1203 | c_old = sfe_ipv4_find_connection(si, |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1204 | msg->tuple.protocol, |
| 1205 | msg->tuple.flow_ip, |
| 1206 | msg->tuple.flow_ident, |
| 1207 | msg->tuple.return_ip, |
| 1208 | msg->tuple.return_ident); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1209 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1210 | if (c_old != NULL) { |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 1211 | this_cpu_inc(si->stats_pcpu->connection_create_collisions64); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1212 | |
| 1213 | /* |
Nicolas Costa | 436926b | 2014-01-14 10:36:22 -0600 | [diff] [blame] | 1214 | * If we already have the flow then it's likely that this |
| 1215 | * request to create the connection rule contains more |
| 1216 | * up-to-date information. Check and update accordingly. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1217 | */ |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1218 | sfe_ipv4_update_protocol_state(c, msg); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1219 | spin_unlock_bh(&si->lock); |
| 1220 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1221 | kfree(reply_cm); |
| 1222 | kfree(original_cm); |
| 1223 | kfree(c); |
| 1224 | |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1225 | dev_put(src_dev); |
| 1226 | dev_put(dest_dev); |
| 1227 | |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 1228 | DEBUG_TRACE("%px: connection already exists - p:%d\n" |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1229 | " s: %s:%pM:%pI4:%u, d: %s:%pM:%pI4:%u\n", |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 1230 | msg, tuple->protocol, |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1231 | src_dev->name, msg->conn_rule.flow_mac, &tuple->flow_ip, ntohs(tuple->flow_ident), |
| 1232 | dest_dev->name, msg->conn_rule.return_mac, &tuple->return_ip, ntohs(tuple->return_ident)); |
| 1233 | |
Nicolas Costa | 514fde0 | 2014-01-13 15:50:29 -0600 | [diff] [blame] | 1234 | return -EADDRINUSE; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | /* |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1238 | * Fill in the "original" direction connection matching object. |
| 1239 | * Note that the transmit MAC address is "dest_mac_xlate" because |
| 1240 | * we always know both ends of a connection by their translated |
| 1241 | * addresses and not their public addresses. |
| 1242 | */ |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1243 | original_cm->match_dev = src_dev; |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1244 | original_cm->match_protocol = tuple->protocol; |
| 1245 | original_cm->match_src_ip = tuple->flow_ip; |
Suruchi Suman | 66609a7 | 2022-01-20 02:34:25 +0530 | [diff] [blame] | 1246 | original_cm->match_src_port = netif_is_vxlan(src_dev) ? 0 : tuple->flow_ident; |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1247 | original_cm->match_dest_ip = tuple->return_ip; |
| 1248 | original_cm->match_dest_port = tuple->return_ident; |
| 1249 | |
| 1250 | original_cm->xlate_src_ip = msg->conn_rule.flow_ip_xlate; |
| 1251 | original_cm->xlate_src_port = msg->conn_rule.flow_ident_xlate; |
| 1252 | original_cm->xlate_dest_ip = msg->conn_rule.return_ip_xlate; |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 1253 | original_cm->xlate_dest_port = msg->conn_rule.return_ident_xlate; |
| 1254 | |
| 1255 | if (tuple->protocol == IPPROTO_GRE) { |
| 1256 | /* |
| 1257 | * the PPTP is 4 tuple lookup. |
| 1258 | * During th rule lookup destination call id from packet |
| 1259 | * is matched against destination port in cm. |
| 1260 | */ |
| 1261 | original_cm->match_src_port = 0; |
| 1262 | original_cm->xlate_src_port = 0; |
| 1263 | } |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1264 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1265 | atomic_set(&original_cm->rx_packet_count, 0); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1266 | original_cm->rx_packet_count64 = 0; |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1267 | atomic_set(&original_cm->rx_byte_count, 0); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1268 | original_cm->rx_byte_count64 = 0; |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1269 | |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1270 | original_cm->xmit_dev = dest_dev; |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1271 | original_cm->xmit_dev_mtu = msg->conn_rule.return_mtu; |
| 1272 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1273 | original_cm->connection = c; |
| 1274 | original_cm->counter_match = reply_cm; |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1275 | original_cm->l2_hdr_size = 0; |
| 1276 | original_cm->flags = 0; |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1277 | |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 1278 | /* |
| 1279 | * UDP Socket is valid only in decap direction. |
| 1280 | */ |
| 1281 | RCU_INIT_POINTER(original_cm->up, NULL); |
| 1282 | |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 1283 | if (msg->valid_flags & SFE_RULE_CREATE_MARK_VALID) { |
| 1284 | original_cm->mark = msg->mark_rule.flow_mark; |
| 1285 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_MARK; |
| 1286 | } |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1287 | if (msg->valid_flags & SFE_RULE_CREATE_QOS_VALID) { |
| 1288 | original_cm->priority = msg->qos_rule.flow_qos_tag; |
Xiaoping Fan | e1963d4 | 2015-08-25 17:06:19 -0700 | [diff] [blame] | 1289 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_PRIORITY_REMARK; |
| 1290 | } |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1291 | if (msg->valid_flags & SFE_RULE_CREATE_DSCP_MARKING_VALID) { |
| 1292 | original_cm->dscp = msg->dscp_rule.flow_dscp << SFE_IPV4_DSCP_SHIFT; |
Xiaoping Fan | e1963d4 | 2015-08-25 17:06:19 -0700 | [diff] [blame] | 1293 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_DSCP_REMARK; |
| 1294 | } |
Ratheesh Kannoth | 71fc51e | 2022-01-05 10:02:47 +0530 | [diff] [blame] | 1295 | if (msg->rule_flags & SFE_RULE_CREATE_FLAG_BRIDGE_FLOW) { |
| 1296 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_BRIDGE_FLOW; |
| 1297 | } |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 1298 | if (msg->rule_flags & SFE_RULE_CREATE_FLAG_FLOW_TRANSMIT_FAST) { |
| 1299 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_FAST_XMIT_DEV_ADMISSION; |
| 1300 | } |
Ratheesh Kannoth | 71fc51e | 2022-01-05 10:02:47 +0530 | [diff] [blame] | 1301 | |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1302 | /* |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 1303 | * Mark SAWF metadata if the sawf tag is valid and set. |
| 1304 | */ |
| 1305 | original_cm->sawf_valid = false; |
| 1306 | flow_sawf_tag = SFE_GET_SAWF_TAG(msg->sawf_rule.flow_mark); |
| 1307 | if (likely(SFE_SAWF_TAG_IS_VALID(flow_sawf_tag))) { |
| 1308 | original_cm->mark = msg->sawf_rule.flow_mark; |
| 1309 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_MARK; |
| 1310 | original_cm->sawf_valid = true; |
| 1311 | } |
| 1312 | |
| 1313 | /* |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1314 | * Add VLAN rule to original_cm |
| 1315 | */ |
| 1316 | if (msg->valid_flags & SFE_RULE_CREATE_VLAN_VALID) { |
| 1317 | struct sfe_vlan_rule *vlan_primary_rule = &msg->vlan_primary_rule; |
| 1318 | struct sfe_vlan_rule *vlan_secondary_rule = &msg->vlan_secondary_rule; |
| 1319 | sfe_ipv4_match_entry_set_vlan(original_cm, |
| 1320 | vlan_primary_rule->ingress_vlan_tag, |
| 1321 | vlan_primary_rule->egress_vlan_tag, |
| 1322 | vlan_secondary_rule->ingress_vlan_tag, |
| 1323 | vlan_secondary_rule->egress_vlan_tag); |
| 1324 | |
| 1325 | if ((msg->rule_flags & SFE_RULE_CREATE_FLAG_USE_RETURN_BOTTOM_INTERFACE) && |
| 1326 | original_cm->egress_vlan_hdr_cnt > 0) { |
| 1327 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_INSERT_EGRESS_VLAN_TAG; |
| 1328 | original_cm->l2_hdr_size += original_cm->egress_vlan_hdr_cnt * VLAN_HLEN; |
| 1329 | } |
| 1330 | } |
| 1331 | |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 1332 | if ((IPPROTO_GRE == tuple->protocol) && !sfe_ipv4_is_local_ip(si, original_cm->match_dest_ip)) { |
| 1333 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_PASSTHROUGH; |
| 1334 | } |
| 1335 | |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 1336 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 1337 | original_cm->flow_cookie = 0; |
| 1338 | #endif |
Zhi Chen | 8748eb3 | 2015-06-18 12:58:48 -0700 | [diff] [blame] | 1339 | #ifdef CONFIG_XFRM |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1340 | if (msg->valid_flags & SFE_RULE_CREATE_DIRECTION_VALID) { |
| 1341 | original_cm->flow_accel = msg->direction_rule.flow_accel; |
| 1342 | } else { |
| 1343 | original_cm->flow_accel = 1; |
| 1344 | } |
Zhi Chen | 8748eb3 | 2015-06-18 12:58:48 -0700 | [diff] [blame] | 1345 | #endif |
Tian Yang | d98d91b | 2022-03-09 14:50:12 -0800 | [diff] [blame^] | 1346 | |
Ratheesh Kannoth | a3cf0e0 | 2021-12-09 09:44:10 +0530 | [diff] [blame] | 1347 | /* |
| 1348 | * If l2_features are disabled and flow uses l2 features such as macvlan/bridge/pppoe/vlan, |
| 1349 | * bottom interfaces are expected to be disabled in the flow rule and always top interfaces |
| 1350 | * are used. In such cases, do not use HW csum offload. csum offload is used only when we |
| 1351 | * are sending directly to the destination interface that supports it. |
| 1352 | */ |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 1353 | if (likely(dest_dev->features & NETIF_F_HW_CSUM) && sfe_dev_has_hw_csum(dest_dev)) { |
Ratheesh Kannoth | a3cf0e0 | 2021-12-09 09:44:10 +0530 | [diff] [blame] | 1354 | if ((msg->conn_rule.return_top_interface_num == msg->conn_rule.return_interface_num) || |
| 1355 | (msg->rule_flags & SFE_RULE_CREATE_FLAG_USE_RETURN_BOTTOM_INTERFACE)) { |
Ratheesh Kannoth | 4844553 | 2022-02-07 16:19:00 +0530 | [diff] [blame] | 1356 | |
| 1357 | /* |
| 1358 | * Dont enable CSUM offload |
| 1359 | */ |
| 1360 | #if 0 |
Suruchi Suman | f207718 | 2022-01-13 21:35:23 +0530 | [diff] [blame] | 1361 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_CSUM_OFFLOAD; |
Ratheesh Kannoth | 4844553 | 2022-02-07 16:19:00 +0530 | [diff] [blame] | 1362 | #endif |
Ratheesh Kannoth | a3cf0e0 | 2021-12-09 09:44:10 +0530 | [diff] [blame] | 1363 | } |
| 1364 | } |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1365 | |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1366 | reply_cm->l2_hdr_size = 0; |
Ratheesh Kannoth | 5dee377 | 2022-01-18 11:27:14 +0530 | [diff] [blame] | 1367 | if (msg->rule_flags & SFE_RULE_CREATE_FLAG_SRC_INTERFACE_CHECK) { |
| 1368 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_SRC_INTERFACE_CHECK; |
| 1369 | } |
| 1370 | |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 1371 | reply_cm->flags = 0; |
| 1372 | |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1373 | /* |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 1374 | * Adding PPPoE parameters to original and reply entries based on the direction where |
| 1375 | * PPPoE header is valid in ECM rule. |
| 1376 | * |
| 1377 | * If PPPoE is valid in flow direction (from interface is PPPoE), then |
| 1378 | * original cm will have PPPoE at ingress (strip PPPoE header) |
| 1379 | * reply cm will have PPPoE at egress (add PPPoE header) |
| 1380 | * |
| 1381 | * If PPPoE is valid in return direction (to interface is PPPoE), then |
| 1382 | * original cm will have PPPoE at egress (add PPPoE header) |
| 1383 | * reply cm will have PPPoE at ingress (strip PPPoE header) |
| 1384 | */ |
| 1385 | if (msg->valid_flags & SFE_RULE_CREATE_PPPOE_DECAP_VALID) { |
| 1386 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_PPPOE_DECAP; |
| 1387 | original_cm->pppoe_session_id = msg->pppoe_rule.flow_pppoe_session_id; |
| 1388 | ether_addr_copy(original_cm->pppoe_remote_mac, msg->pppoe_rule.flow_pppoe_remote_mac); |
| 1389 | |
| 1390 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_PPPOE_ENCAP; |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1391 | reply_cm->l2_hdr_size += SFE_PPPOE_SESSION_HEADER_SIZE; |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 1392 | reply_cm->pppoe_session_id = msg->pppoe_rule.flow_pppoe_session_id; |
| 1393 | ether_addr_copy(reply_cm->pppoe_remote_mac, msg->pppoe_rule.flow_pppoe_remote_mac); |
| 1394 | } |
| 1395 | |
| 1396 | if (msg->valid_flags & SFE_RULE_CREATE_PPPOE_ENCAP_VALID) { |
| 1397 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_PPPOE_ENCAP; |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1398 | original_cm->l2_hdr_size += SFE_PPPOE_SESSION_HEADER_SIZE; |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 1399 | original_cm->pppoe_session_id = msg->pppoe_rule.return_pppoe_session_id; |
| 1400 | ether_addr_copy(original_cm->pppoe_remote_mac, msg->pppoe_rule.return_pppoe_remote_mac); |
| 1401 | |
| 1402 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_PPPOE_DECAP; |
| 1403 | reply_cm->pppoe_session_id = msg->pppoe_rule.return_pppoe_session_id; |
| 1404 | ether_addr_copy(reply_cm->pppoe_remote_mac, msg->pppoe_rule.return_pppoe_remote_mac); |
| 1405 | } |
| 1406 | |
Ratheesh Kannoth | 5dee377 | 2022-01-18 11:27:14 +0530 | [diff] [blame] | 1407 | if (msg->rule_flags & SFE_RULE_CREATE_FLAG_SRC_INTERFACE_CHECK) { |
| 1408 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_SRC_INTERFACE_CHECK; |
| 1409 | } |
| 1410 | |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 1411 | /* |
Ken Zhu | bbf4965 | 2021-09-12 15:33:09 -0700 | [diff] [blame] | 1412 | * For the non-arp interface, we don't write L2 HDR. |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1413 | */ |
Guduri Prathyusha | 79a5fee | 2021-11-11 17:59:10 +0530 | [diff] [blame] | 1414 | if (sfe_ipv4_xmit_eth_type_check(dest_dev, original_cm->flags)) { |
Ratheesh Kannoth | 29140aa | 2021-10-20 08:25:02 +0530 | [diff] [blame] | 1415 | |
| 1416 | /* |
| 1417 | * Check whether the rule has configured a specific source MAC address to use. |
| 1418 | * This is needed when virtual L3 interfaces such as br-lan, macvlan, vlan are used during egress |
| 1419 | */ |
Ratheesh Kannoth | 71fc51e | 2022-01-05 10:02:47 +0530 | [diff] [blame] | 1420 | |
| 1421 | if (msg->rule_flags & SFE_RULE_CREATE_FLAG_BRIDGE_FLOW) { |
| 1422 | ether_addr_copy((u8 *)original_cm->xmit_src_mac, (u8 *)msg->conn_rule.flow_mac); |
Ratheesh Kannoth | 29140aa | 2021-10-20 08:25:02 +0530 | [diff] [blame] | 1423 | } else { |
Ratheesh Kannoth | 71fc51e | 2022-01-05 10:02:47 +0530 | [diff] [blame] | 1424 | if ((msg->valid_flags & SFE_RULE_CREATE_SRC_MAC_VALID) && |
| 1425 | (msg->src_mac_rule.mac_valid_flags & SFE_SRC_MAC_RETURN_VALID)) { |
| 1426 | ether_addr_copy((u8 *)original_cm->xmit_src_mac, (u8 *)msg->src_mac_rule.return_src_mac); |
| 1427 | } else { |
| 1428 | ether_addr_copy((u8 *)original_cm->xmit_src_mac, (u8 *)dest_dev->dev_addr); |
| 1429 | } |
Ratheesh Kannoth | 29140aa | 2021-10-20 08:25:02 +0530 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | ether_addr_copy((u8 *)original_cm->xmit_dest_mac, (u8 *)msg->conn_rule.return_mac); |
| 1433 | |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1434 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_WRITE_L2_HDR; |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1435 | original_cm->l2_hdr_size += ETH_HLEN; |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1436 | |
| 1437 | /* |
| 1438 | * If our dev writes Ethernet headers then we can write a really fast |
| 1439 | * version. |
| 1440 | */ |
| 1441 | if (dest_dev->header_ops) { |
| 1442 | if (dest_dev->header_ops->create == eth_header) { |
| 1443 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_WRITE_FAST_ETH_HDR; |
| 1444 | } |
| 1445 | } |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | /* |
| 1449 | * Fill in the "reply" direction connection matching object. |
| 1450 | */ |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1451 | reply_cm->match_dev = dest_dev; |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1452 | reply_cm->match_protocol = tuple->protocol; |
| 1453 | reply_cm->match_src_ip = msg->conn_rule.return_ip_xlate; |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 1454 | |
| 1455 | /* |
| 1456 | * Keep source port as 0 for VxLAN tunnels. |
| 1457 | */ |
| 1458 | if (netif_is_vxlan(src_dev) || netif_is_vxlan(dest_dev)) { |
| 1459 | reply_cm->match_src_port = 0; |
| 1460 | } else { |
| 1461 | reply_cm->match_src_port = msg->conn_rule.return_ident_xlate; |
| 1462 | } |
| 1463 | |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1464 | reply_cm->match_dest_ip = msg->conn_rule.flow_ip_xlate; |
| 1465 | reply_cm->match_dest_port = msg->conn_rule.flow_ident_xlate; |
| 1466 | |
| 1467 | reply_cm->xlate_src_ip = tuple->return_ip; |
| 1468 | reply_cm->xlate_src_port = tuple->return_ident; |
| 1469 | reply_cm->xlate_dest_ip = tuple->flow_ip; |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 1470 | reply_cm->xlate_dest_port = tuple->flow_ident; |
| 1471 | |
| 1472 | if (tuple->protocol == IPPROTO_GRE) { |
| 1473 | /* |
| 1474 | * the PPTP is 4 tuple lookup. |
| 1475 | * During th rule lookup destination call id from packet |
| 1476 | * is matched against destination port in cm. |
| 1477 | */ |
| 1478 | reply_cm->match_src_port = 0; |
| 1479 | reply_cm->xlate_src_port = 0; |
| 1480 | } |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1481 | |
| 1482 | atomic_set(&reply_cm->rx_packet_count, 0); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1483 | reply_cm->rx_packet_count64 = 0; |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1484 | atomic_set(&reply_cm->rx_byte_count, 0); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1485 | reply_cm->rx_byte_count64 = 0; |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1486 | |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1487 | reply_cm->xmit_dev = src_dev; |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1488 | reply_cm->xmit_dev_mtu = msg->conn_rule.flow_mtu; |
Ratheesh Kannoth | 29140aa | 2021-10-20 08:25:02 +0530 | [diff] [blame] | 1489 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1490 | reply_cm->connection = c; |
| 1491 | reply_cm->counter_match = original_cm; |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 1492 | |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 1493 | if (msg->valid_flags & SFE_RULE_CREATE_MARK_VALID) { |
| 1494 | reply_cm->mark = msg->mark_rule.return_mark; |
| 1495 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_MARK; |
| 1496 | } |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1497 | if (msg->valid_flags & SFE_RULE_CREATE_QOS_VALID) { |
| 1498 | reply_cm->priority = msg->qos_rule.return_qos_tag; |
Xiaoping Fan | e1963d4 | 2015-08-25 17:06:19 -0700 | [diff] [blame] | 1499 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_PRIORITY_REMARK; |
| 1500 | } |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1501 | |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1502 | if (msg->valid_flags & SFE_RULE_CREATE_DSCP_MARKING_VALID) { |
| 1503 | reply_cm->dscp = msg->dscp_rule.return_dscp << SFE_IPV4_DSCP_SHIFT; |
Xiaoping Fan | e1963d4 | 2015-08-25 17:06:19 -0700 | [diff] [blame] | 1504 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_DSCP_REMARK; |
| 1505 | } |
Ratheesh Kannoth | 71fc51e | 2022-01-05 10:02:47 +0530 | [diff] [blame] | 1506 | if (msg->rule_flags & SFE_RULE_CREATE_FLAG_BRIDGE_FLOW) { |
| 1507 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_BRIDGE_FLOW; |
| 1508 | } |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 1509 | if (msg->rule_flags & SFE_RULE_CREATE_FLAG_RETURN_TRANSMIT_FAST) { |
| 1510 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_FAST_XMIT_DEV_ADMISSION; |
| 1511 | } |
Ratheesh Kannoth | 71fc51e | 2022-01-05 10:02:47 +0530 | [diff] [blame] | 1512 | |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 1513 | if ((IPPROTO_GRE == tuple->protocol) && !sfe_ipv4_is_local_ip(si, reply_cm->match_dest_ip)) { |
| 1514 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_PASSTHROUGH; |
| 1515 | } |
| 1516 | |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 1517 | /* |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 1518 | * Mark SAWF metadata in reply match if the sawf tag is valid. |
| 1519 | */ |
| 1520 | reply_cm->sawf_valid = false; |
| 1521 | return_sawf_tag = SFE_GET_SAWF_TAG(msg->sawf_rule.return_mark); |
| 1522 | if (likely(SFE_SAWF_TAG_IS_VALID(return_sawf_tag))) { |
| 1523 | reply_cm->mark = msg->sawf_rule.return_mark; |
| 1524 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_MARK; |
| 1525 | reply_cm->sawf_valid = true; |
| 1526 | } |
| 1527 | |
| 1528 | /* |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 1529 | * Setup UDP Socket if found to be valid for decap. |
| 1530 | */ |
| 1531 | RCU_INIT_POINTER(reply_cm->up, NULL); |
| 1532 | net = dev_net(reply_cm->match_dev); |
| 1533 | src_if_idx = src_dev->ifindex; |
| 1534 | |
| 1535 | rcu_read_lock(); |
| 1536 | |
| 1537 | /* |
| 1538 | * Look for the associated sock object. |
| 1539 | * __udp4_lib_lookup() holds a reference for this sock object, |
| 1540 | * which will be released in sfe_ipv4_free_connection_rcu() |
| 1541 | */ |
| 1542 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0)) |
| 1543 | sk = __udp4_lib_lookup(net, reply_cm->match_dest_ip, reply_cm->match_dest_port, |
| 1544 | reply_cm->xlate_src_ip, reply_cm->xlate_src_port, src_if_idx, &udp_table); |
| 1545 | #else |
| 1546 | sk = __udp4_lib_lookup(net, reply_cm->match_dest_ip, reply_cm->match_dest_port, |
| 1547 | reply_cm->xlate_src_ip, reply_cm->xlate_src_port, src_if_idx, 0, &udp_table, NULL); |
| 1548 | #endif |
| 1549 | |
| 1550 | rcu_read_unlock(); |
| 1551 | |
| 1552 | /* |
| 1553 | * We set the UDP sock pointer as valid only for decap direction. |
| 1554 | */ |
| 1555 | if (sk && udp_sk(sk)->encap_type) { |
| 1556 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0)) |
| 1557 | if (!atomic_add_unless(&sk->sk_refcnt, 1, 0)) { |
| 1558 | #else |
| 1559 | if (!refcount_inc_not_zero(&sk->sk_refcnt)) { |
| 1560 | #endif |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1561 | spin_unlock_bh(&si->lock); |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 1562 | kfree(reply_cm); |
| 1563 | kfree(original_cm); |
| 1564 | kfree(c); |
| 1565 | |
| 1566 | DEBUG_TRACE("%px: sfe: unable to take reference for socket(%px) p:%d\n" |
| 1567 | " s: %s:%pM:%pI4:%u, d: %s:%pM:%pI4:%u\n", |
| 1568 | msg, sk, tuple->protocol, |
| 1569 | src_dev->name, msg->conn_rule.flow_mac, &tuple->flow_ip, ntohs(tuple->flow_ident), |
| 1570 | dest_dev->name, msg->conn_rule.return_mac, &tuple->return_ip, ntohs(tuple->return_ident)); |
| 1571 | |
| 1572 | dev_put(src_dev); |
| 1573 | dev_put(dest_dev); |
| 1574 | |
| 1575 | return -ESHUTDOWN; |
| 1576 | } |
| 1577 | |
| 1578 | rcu_assign_pointer(reply_cm->up, udp_sk(sk)); |
| 1579 | |
| 1580 | DEBUG_INFO("%px: Sock(%px) lookup success with reply_cm direction\n", msg, sk); |
| 1581 | DEBUG_INFO("%px: SFE connection -\n" |
| 1582 | " s: %s:%pI4(%pI4):%u(%u)\n" |
| 1583 | " d: %s:%pI4(%pI4):%u(%u)\n", |
| 1584 | msg, reply_cm->match_dev->name, &reply_cm->match_src_ip, &reply_cm->xlate_src_ip, |
| 1585 | ntohs(reply_cm->match_src_port), ntohs(reply_cm->xlate_src_port), |
| 1586 | reply_cm->xmit_dev->name, &reply_cm->match_dest_ip, &reply_cm->xlate_dest_ip, |
| 1587 | ntohs(reply_cm->match_dest_port), ntohs(reply_cm->xlate_dest_port)); |
| 1588 | } |
| 1589 | |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1590 | /* |
| 1591 | * Add VLAN rule to reply_cm |
| 1592 | */ |
| 1593 | if (msg->valid_flags & SFE_RULE_CREATE_VLAN_VALID) { |
| 1594 | struct sfe_vlan_rule *vlan_primary_rule = &msg->vlan_primary_rule; |
| 1595 | struct sfe_vlan_rule *vlan_secondary_rule = &msg->vlan_secondary_rule; |
| 1596 | sfe_ipv4_match_entry_set_vlan(reply_cm, |
| 1597 | vlan_primary_rule->egress_vlan_tag, |
| 1598 | vlan_primary_rule->ingress_vlan_tag, |
| 1599 | vlan_secondary_rule->egress_vlan_tag, |
| 1600 | vlan_secondary_rule->ingress_vlan_tag); |
| 1601 | |
| 1602 | if ((msg->rule_flags & SFE_RULE_CREATE_FLAG_USE_FLOW_BOTTOM_INTERFACE) && |
| 1603 | reply_cm->egress_vlan_hdr_cnt > 0) { |
| 1604 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_INSERT_EGRESS_VLAN_TAG; |
| 1605 | reply_cm->l2_hdr_size += reply_cm->egress_vlan_hdr_cnt * VLAN_HLEN; |
| 1606 | } |
| 1607 | } |
| 1608 | |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 1609 | /* |
| 1610 | * the net_protocol handler will be used only in decap path |
| 1611 | * for non passthrough case. |
| 1612 | */ |
| 1613 | original_cm->proto = NULL; |
| 1614 | reply_cm->proto = NULL; |
| 1615 | |
| 1616 | #ifdef SFE_GRE_TUN_ENABLE |
| 1617 | if ((IPPROTO_GRE == tuple->protocol) && !(reply_cm->flags & SFE_IPV4_CONNECTION_MATCH_FLAG_PASSTHROUGH)) { |
| 1618 | rcu_read_lock(); |
| 1619 | reply_cm->proto = rcu_dereference(inet_protos[IPPROTO_GRE]); |
| 1620 | rcu_read_unlock(); |
| 1621 | |
| 1622 | if (unlikely(!reply_cm->proto)) { |
| 1623 | kfree(reply_cm); |
| 1624 | kfree(original_cm); |
| 1625 | kfree(c); |
| 1626 | dev_put(src_dev); |
| 1627 | dev_put(dest_dev); |
| 1628 | DEBUG_WARN("sfe: GRE proto handler is not registered\n"); |
| 1629 | return -EPERM; |
| 1630 | } |
| 1631 | } |
| 1632 | #endif |
| 1633 | |
Tian Yang | d98d91b | 2022-03-09 14:50:12 -0800 | [diff] [blame^] | 1634 | if (IPPROTO_IPV6 == tuple->protocol) { |
| 1635 | original_cm->proto = NULL; |
| 1636 | rcu_read_lock(); |
| 1637 | reply_cm->proto = rcu_dereference(inet_protos[IPPROTO_IPV6]); |
| 1638 | rcu_read_unlock(); |
| 1639 | } |
| 1640 | |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 1641 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 1642 | reply_cm->flow_cookie = 0; |
| 1643 | #endif |
Zhi Chen | 8748eb3 | 2015-06-18 12:58:48 -0700 | [diff] [blame] | 1644 | #ifdef CONFIG_XFRM |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1645 | if (msg->valid_flags & SFE_RULE_CREATE_DIRECTION_VALID) { |
| 1646 | reply_cm->flow_accel = msg->direction_rule.return_accel; |
| 1647 | } else { |
| 1648 | reply_cm->flow_accel = 1; |
| 1649 | } |
| 1650 | |
Zhi Chen | 8748eb3 | 2015-06-18 12:58:48 -0700 | [diff] [blame] | 1651 | #endif |
Ratheesh Kannoth | a3cf0e0 | 2021-12-09 09:44:10 +0530 | [diff] [blame] | 1652 | /* |
| 1653 | * If l2_features are disabled and flow uses l2 features such as macvlan/bridge/pppoe/vlan, |
| 1654 | * bottom interfaces are expected to be disabled in the flow rule and always top interfaces |
| 1655 | * are used. In such cases, do not use HW csum offload. csum offload is used only when we |
| 1656 | * are sending directly to the destination interface that supports it. |
| 1657 | */ |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 1658 | if (likely(src_dev->features & NETIF_F_HW_CSUM) && sfe_dev_has_hw_csum(src_dev)) { |
Ratheesh Kannoth | a3cf0e0 | 2021-12-09 09:44:10 +0530 | [diff] [blame] | 1659 | if ((msg->conn_rule.flow_top_interface_num == msg->conn_rule.flow_interface_num) || |
| 1660 | (msg->rule_flags & SFE_RULE_CREATE_FLAG_USE_FLOW_BOTTOM_INTERFACE)) { |
Ratheesh Kannoth | 4844553 | 2022-02-07 16:19:00 +0530 | [diff] [blame] | 1661 | /* |
| 1662 | * Dont enable CSUM offload |
| 1663 | */ |
| 1664 | #if 0 |
Ratheesh Kannoth | a3cf0e0 | 2021-12-09 09:44:10 +0530 | [diff] [blame] | 1665 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_CSUM_OFFLOAD; |
Ratheesh Kannoth | 4844553 | 2022-02-07 16:19:00 +0530 | [diff] [blame] | 1666 | #endif |
Ratheesh Kannoth | a3cf0e0 | 2021-12-09 09:44:10 +0530 | [diff] [blame] | 1667 | } |
| 1668 | } |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1669 | |
| 1670 | /* |
Ken Zhu | bbf4965 | 2021-09-12 15:33:09 -0700 | [diff] [blame] | 1671 | * For the non-arp interface, we don't write L2 HDR. |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1672 | */ |
Guduri Prathyusha | 79a5fee | 2021-11-11 17:59:10 +0530 | [diff] [blame] | 1673 | if (sfe_ipv4_xmit_eth_type_check(src_dev, reply_cm->flags)) { |
Ratheesh Kannoth | 29140aa | 2021-10-20 08:25:02 +0530 | [diff] [blame] | 1674 | |
| 1675 | /* |
| 1676 | * Check whether the rule has configured a specific source MAC address to use. |
| 1677 | * This is needed when virtual L3 interfaces such as br-lan, macvlan, vlan are used during egress |
| 1678 | */ |
Ratheesh Kannoth | 71fc51e | 2022-01-05 10:02:47 +0530 | [diff] [blame] | 1679 | |
| 1680 | if (msg->rule_flags & SFE_RULE_CREATE_FLAG_BRIDGE_FLOW) { |
| 1681 | ether_addr_copy((u8 *)reply_cm->xmit_src_mac, (u8 *)msg->conn_rule.return_mac); |
Ratheesh Kannoth | 29140aa | 2021-10-20 08:25:02 +0530 | [diff] [blame] | 1682 | } else { |
Ratheesh Kannoth | 71fc51e | 2022-01-05 10:02:47 +0530 | [diff] [blame] | 1683 | if ((msg->valid_flags & SFE_RULE_CREATE_SRC_MAC_VALID) && |
| 1684 | (msg->src_mac_rule.mac_valid_flags & SFE_SRC_MAC_FLOW_VALID)) { |
| 1685 | ether_addr_copy((u8 *)reply_cm->xmit_src_mac, (u8 *)msg->src_mac_rule.flow_src_mac); |
| 1686 | } else { |
| 1687 | ether_addr_copy((u8 *)reply_cm->xmit_src_mac, (u8 *)src_dev->dev_addr); |
| 1688 | } |
Ratheesh Kannoth | 29140aa | 2021-10-20 08:25:02 +0530 | [diff] [blame] | 1689 | } |
Ratheesh Kannoth | 71fc51e | 2022-01-05 10:02:47 +0530 | [diff] [blame] | 1690 | |
Ratheesh Kannoth | 29140aa | 2021-10-20 08:25:02 +0530 | [diff] [blame] | 1691 | ether_addr_copy((u8 *)reply_cm->xmit_dest_mac, (u8 *)msg->conn_rule.flow_mac); |
| 1692 | |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1693 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_WRITE_L2_HDR; |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1694 | reply_cm->l2_hdr_size += ETH_HLEN; |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 1695 | |
| 1696 | /* |
| 1697 | * If our dev writes Ethernet headers then we can write a really fast |
| 1698 | * version. |
| 1699 | */ |
| 1700 | if (src_dev->header_ops) { |
| 1701 | if (src_dev->header_ops->create == eth_header) { |
| 1702 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_WRITE_FAST_ETH_HDR; |
| 1703 | } |
| 1704 | } |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1705 | } |
| 1706 | |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1707 | if ((tuple->return_ip != msg->conn_rule.return_ip_xlate) || |
| 1708 | (tuple->return_ident != msg->conn_rule.return_ident_xlate)) { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1709 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_DEST; |
| 1710 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_SRC; |
| 1711 | } |
| 1712 | |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1713 | if ((tuple->flow_ip != msg->conn_rule.flow_ip_xlate) || |
| 1714 | (tuple->flow_ident != msg->conn_rule.flow_ident_xlate)) { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1715 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_SRC; |
| 1716 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_DEST; |
| 1717 | } |
| 1718 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1719 | /* |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1720 | * Initialize the protocol-specific information that we track. |
| 1721 | */ |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1722 | switch (tuple->protocol) { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1723 | case IPPROTO_TCP: |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1724 | original_cm->protocol_state.tcp.win_scale = msg->tcp_rule.flow_window_scale; |
| 1725 | original_cm->protocol_state.tcp.max_win = msg->tcp_rule.flow_max_window ? msg->tcp_rule.flow_max_window : 1; |
| 1726 | original_cm->protocol_state.tcp.end = msg->tcp_rule.flow_end; |
| 1727 | original_cm->protocol_state.tcp.max_end = msg->tcp_rule.flow_max_end; |
| 1728 | |
| 1729 | reply_cm->protocol_state.tcp.win_scale = msg->tcp_rule.return_window_scale; |
| 1730 | reply_cm->protocol_state.tcp.max_win = msg->tcp_rule.return_max_window ? msg->tcp_rule.return_max_window : 1; |
| 1731 | reply_cm->protocol_state.tcp.end = msg->tcp_rule.return_end; |
| 1732 | reply_cm->protocol_state.tcp.max_end = msg->tcp_rule.return_max_end; |
| 1733 | |
| 1734 | if (msg->rule_flags & SFE_RULE_CREATE_FLAG_NO_SEQ_CHECK) { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1735 | original_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_NO_SEQ_CHECK; |
| 1736 | reply_cm->flags |= SFE_IPV4_CONNECTION_MATCH_FLAG_NO_SEQ_CHECK; |
| 1737 | } |
| 1738 | break; |
| 1739 | } |
| 1740 | |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1741 | /* |
| 1742 | * Fill in the ipv4_connection object. |
| 1743 | */ |
| 1744 | c->protocol = tuple->protocol; |
| 1745 | c->src_ip = tuple->flow_ip; |
| 1746 | c->src_ip_xlate = msg->conn_rule.flow_ip_xlate; |
| 1747 | c->src_port = tuple->flow_ident; |
| 1748 | c->src_port_xlate = msg->conn_rule.flow_ident_xlate; |
| 1749 | c->original_dev = src_dev; |
| 1750 | c->original_match = original_cm; |
| 1751 | c->dest_ip = tuple->return_ip; |
| 1752 | c->dest_ip_xlate = msg->conn_rule.return_ip_xlate; |
| 1753 | c->dest_port = tuple->return_ident; |
| 1754 | c->dest_port_xlate = msg->conn_rule.return_ident_xlate; |
| 1755 | c->reply_dev = dest_dev; |
| 1756 | c->reply_match = reply_cm; |
| 1757 | c->debug_read_seq = 0; |
| 1758 | c->last_sync_jiffies = get_jiffies_64(); |
| 1759 | c->removed = false; |
| 1760 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1761 | sfe_ipv4_connection_match_compute_translations(original_cm); |
| 1762 | sfe_ipv4_connection_match_compute_translations(reply_cm); |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 1763 | sfe_ipv4_insert_connection(si, c); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1764 | |
| 1765 | spin_unlock_bh(&si->lock); |
| 1766 | |
| 1767 | /* |
| 1768 | * We have everything we need! |
| 1769 | */ |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1770 | DEBUG_INFO("NEW connection - p: %d\n" |
| 1771 | "original_cm: match_dev=src_dev: %s %d %pM\n" |
| 1772 | " xmit_dev=dest_dev: %s %d %pM\n" |
| 1773 | " xmit_src_mac: %pM\n" |
| 1774 | " xmit_dest_mac: %pM\n" |
| 1775 | " flags: %x l2_hdr: %u\n" |
| 1776 | "flow_ip: %pI4:%u\n" |
| 1777 | "flow_ip_xlate: %pI4:%u\n" |
| 1778 | "flow_mac: %pM\n" |
| 1779 | "reply_cm: match_dev=dest_dev: %s %d %pM\n" |
| 1780 | " xmit_dev=src_dev: %s %d %pM\n" |
| 1781 | " xmit_src_mac: %pM\n" |
| 1782 | " xmit_dest_mac: %pM\n" |
| 1783 | " flags: %x l2_hdr: %u\n" |
| 1784 | "return_ip: %pI4:%u\n" |
| 1785 | "return_ip_xlate: %pI4:%u\n" |
| 1786 | "return_mac: %pM\n" |
| 1787 | "flags: valid=%x src_mac_valid=%x\n", |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1788 | tuple->protocol, |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 1789 | original_cm->match_dev->name, original_cm->match_dev->ifindex, original_cm->match_dev->dev_addr, |
| 1790 | original_cm->xmit_dev->name, original_cm->xmit_dev->ifindex, original_cm->xmit_dev->dev_addr, |
| 1791 | original_cm->xmit_src_mac, original_cm->xmit_dest_mac, original_cm->flags, original_cm->l2_hdr_size, |
| 1792 | &tuple->flow_ip, ntohs(tuple->flow_ident), |
| 1793 | &msg->conn_rule.flow_ip_xlate, ntohs(msg->conn_rule.flow_ident_xlate), |
| 1794 | msg->conn_rule.flow_mac, |
| 1795 | reply_cm->match_dev->name, reply_cm->match_dev->ifindex, reply_cm->match_dev->dev_addr, |
| 1796 | reply_cm->xmit_dev->name, reply_cm->xmit_dev->ifindex, reply_cm->xmit_dev->dev_addr, |
| 1797 | reply_cm->xmit_src_mac, reply_cm->xmit_dest_mac, reply_cm->flags, reply_cm->l2_hdr_size, |
| 1798 | &tuple->return_ip, ntohs(tuple->return_ident), |
| 1799 | &msg->conn_rule.return_ip_xlate, ntohs(msg->conn_rule.return_ident_xlate), |
| 1800 | msg->conn_rule.return_mac, |
| 1801 | msg->valid_flags, msg->src_mac_rule.mac_valid_flags); |
Nicolas Costa | 514fde0 | 2014-01-13 15:50:29 -0600 | [diff] [blame] | 1802 | |
| 1803 | return 0; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | /* |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1807 | * sfe_ipv4_destroy_rule() |
| 1808 | * Destroy a forwarding rule. |
| 1809 | */ |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1810 | void sfe_ipv4_destroy_rule(struct sfe_ipv4_rule_destroy_msg *msg) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1811 | { |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1812 | struct sfe_ipv4 *si = &__si; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1813 | struct sfe_ipv4_connection *c; |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1814 | bool ret; |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1815 | struct sfe_ipv4_5tuple *tuple = &msg->tuple; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1816 | |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 1817 | this_cpu_inc(si->stats_pcpu->connection_destroy_requests64); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1818 | spin_lock_bh(&si->lock); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1819 | |
| 1820 | /* |
| 1821 | * Check to see if we have a flow that matches the rule we're trying |
| 1822 | * to destroy. If there isn't then we can't destroy it. |
| 1823 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 1824 | c = sfe_ipv4_find_connection(si, tuple->protocol, tuple->flow_ip, tuple->flow_ident, |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1825 | tuple->return_ip, tuple->return_ident); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1826 | if (!c) { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1827 | spin_unlock_bh(&si->lock); |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 1828 | this_cpu_inc(si->stats_pcpu->connection_destroy_misses64); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1829 | |
| 1830 | DEBUG_TRACE("connection does not exist - p: %d, s: %pI4:%u, d: %pI4:%u\n", |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1831 | tuple->protocol, &tuple->flow_ip, ntohs(tuple->flow_ident), |
| 1832 | &tuple->return_ip, ntohs(tuple->return_ident)); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1833 | return; |
| 1834 | } |
| 1835 | |
| 1836 | /* |
| 1837 | * Remove our connection details from the hash tables. |
| 1838 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 1839 | ret = sfe_ipv4_remove_connection(si, c); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1840 | spin_unlock_bh(&si->lock); |
| 1841 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1842 | if (ret) { |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 1843 | sfe_ipv4_flush_connection(si, c, SFE_SYNC_REASON_DESTROY); |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1844 | } |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1845 | |
| 1846 | DEBUG_INFO("connection destroyed - p: %d, s: %pI4:%u, d: %pI4:%u\n", |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 1847 | tuple->protocol, &tuple->flow_ip, ntohs(tuple->flow_ident), |
| 1848 | &tuple->return_ip, ntohs(tuple->return_ident)); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | /* |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 1852 | * sfe_ipv4_sync_invoke() |
| 1853 | * Schedule many sync stats. |
| 1854 | */ |
| 1855 | bool sfe_ipv4_sync_invoke(uint16_t index) |
| 1856 | { |
| 1857 | struct sfe_ipv4 *si = &__si; |
| 1858 | DEBUG_INFO("Request for a sync with index[%d]\n", index); |
| 1859 | return schedule_delayed_work_on(si->work_cpu, &(si->sync_dwork), 0); |
| 1860 | } |
| 1861 | |
| 1862 | /* |
| 1863 | * sfe_ipv4_register_sync_rule_callback() |
| 1864 | * Register a callback for many rule synchronization. |
| 1865 | */ |
| 1866 | void sfe_ipv4_register_many_sync_callback(sfe_ipv4_many_sync_callback_t cb) |
| 1867 | { |
| 1868 | struct sfe_ipv4 *si = &__si; |
| 1869 | |
| 1870 | spin_lock_bh(&si->lock); |
| 1871 | rcu_assign_pointer(si->many_sync_callback, cb); |
| 1872 | spin_unlock_bh(&si->lock); |
| 1873 | } |
| 1874 | |
| 1875 | /* |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1876 | * sfe_ipv4_register_sync_rule_callback() |
| 1877 | * Register a callback for rule synchronization. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1878 | */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 1879 | void sfe_ipv4_register_sync_rule_callback(sfe_sync_rule_callback_t sync_rule_callback) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1880 | { |
| 1881 | struct sfe_ipv4 *si = &__si; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1882 | |
| 1883 | spin_lock_bh(&si->lock); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1884 | rcu_assign_pointer(si->sync_rule_callback, sync_rule_callback); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1885 | spin_unlock_bh(&si->lock); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1886 | } |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1887 | /* |
| 1888 | * sfe_ipv4_get_debug_dev() |
| 1889 | */ |
| 1890 | static ssize_t sfe_ipv4_get_debug_dev(struct device *dev, |
| 1891 | struct device_attribute *attr, |
| 1892 | char *buf) |
| 1893 | { |
| 1894 | struct sfe_ipv4 *si = &__si; |
| 1895 | ssize_t count; |
| 1896 | int num; |
| 1897 | |
| 1898 | spin_lock_bh(&si->lock); |
| 1899 | num = si->debug_dev; |
| 1900 | spin_unlock_bh(&si->lock); |
| 1901 | |
| 1902 | count = snprintf(buf, (ssize_t)PAGE_SIZE, "%d\n", num); |
| 1903 | return count; |
| 1904 | } |
| 1905 | |
| 1906 | /* |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1907 | * sysfs attributes. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1908 | */ |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1909 | static const struct device_attribute sfe_ipv4_debug_dev_attr = |
Xiaoping Fan | e70da41 | 2016-02-26 16:47:57 -0800 | [diff] [blame] | 1910 | __ATTR(debug_dev, S_IWUSR | S_IRUGO, sfe_ipv4_get_debug_dev, NULL); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1911 | |
| 1912 | /* |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1913 | * sfe_ipv4_destroy_all_rules_for_dev() |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1914 | * Destroy all connections that match a particular device. |
| 1915 | * |
| 1916 | * If we pass dev as NULL then this destroys all connections. |
| 1917 | */ |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1918 | void sfe_ipv4_destroy_all_rules_for_dev(struct net_device *dev) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1919 | { |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1920 | struct sfe_ipv4 *si = &__si; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1921 | struct sfe_ipv4_connection *c; |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1922 | bool ret; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1923 | |
Xiaoping Fan | 3458647 | 2015-07-03 02:20:35 -0700 | [diff] [blame] | 1924 | another_round: |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1925 | spin_lock_bh(&si->lock); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1926 | |
Xiaoping Fan | 3458647 | 2015-07-03 02:20:35 -0700 | [diff] [blame] | 1927 | for (c = si->all_connections_head; c; c = c->all_connections_next) { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1928 | /* |
Xiaoping Fan | 3458647 | 2015-07-03 02:20:35 -0700 | [diff] [blame] | 1929 | * Does this connection relate to the device we are destroying? |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1930 | */ |
| 1931 | if (!dev |
| 1932 | || (dev == c->original_dev) |
| 1933 | || (dev == c->reply_dev)) { |
Xiaoping Fan | 3458647 | 2015-07-03 02:20:35 -0700 | [diff] [blame] | 1934 | break; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1935 | } |
Xiaoping Fan | 3458647 | 2015-07-03 02:20:35 -0700 | [diff] [blame] | 1936 | } |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1937 | |
Xiaoping Fan | 3458647 | 2015-07-03 02:20:35 -0700 | [diff] [blame] | 1938 | if (c) { |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 1939 | ret = sfe_ipv4_remove_connection(si, c); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | spin_unlock_bh(&si->lock); |
Xiaoping Fan | 3458647 | 2015-07-03 02:20:35 -0700 | [diff] [blame] | 1943 | |
| 1944 | if (c) { |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1945 | if (ret) { |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 1946 | sfe_ipv4_flush_connection(si, c, SFE_SYNC_REASON_DESTROY); |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 1947 | } |
Xiaoping Fan | 3458647 | 2015-07-03 02:20:35 -0700 | [diff] [blame] | 1948 | goto another_round; |
| 1949 | } |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | /* |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1953 | * sfe_ipv4_periodic_sync() |
| 1954 | */ |
Ken Zhu | 137722d | 2021-09-23 17:57:36 -0700 | [diff] [blame] | 1955 | static void sfe_ipv4_periodic_sync(struct work_struct *work) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1956 | { |
Ken Zhu | 137722d | 2021-09-23 17:57:36 -0700 | [diff] [blame] | 1957 | struct sfe_ipv4 *si = container_of((struct delayed_work *)work, struct sfe_ipv4, sync_dwork); |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 1958 | u64 now_jiffies; |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 1959 | int quota,count; |
| 1960 | sfe_ipv4_many_sync_callback_t sync_rule_callback; |
Ken Zhu | dc42367 | 2021-09-02 18:27:01 -0700 | [diff] [blame] | 1961 | struct sfe_ipv4_connection *c; |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 1962 | struct sfe_ipv4_conn_sync *conn_sync; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1963 | |
| 1964 | now_jiffies = get_jiffies_64(); |
| 1965 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1966 | rcu_read_lock(); |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 1967 | sync_rule_callback = rcu_dereference(si->many_sync_callback); |
| 1968 | rcu_read_unlock(); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1969 | if (!sync_rule_callback) { |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 1970 | return; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1971 | } |
| 1972 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1973 | spin_lock_bh(&si->lock); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1974 | |
| 1975 | /* |
Ken Zhu | dc42367 | 2021-09-02 18:27:01 -0700 | [diff] [blame] | 1976 | * If we have reached the end of the connection list, walk from |
| 1977 | * the connection head. |
| 1978 | */ |
| 1979 | c = si->wc_next; |
| 1980 | if (unlikely(!c)) { |
| 1981 | c = si->all_connections_head; |
| 1982 | } |
| 1983 | |
| 1984 | /* |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 1985 | * Get the max number of connections to be put in this sync msg. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1986 | */ |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 1987 | quota = sfe_ipv4_sync_max_number; |
| 1988 | conn_sync = sfe_ipv4_sync_many_msg->msg.conn_stats_many.conn_sync; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1989 | |
| 1990 | /* |
Ken Zhu | dc42367 | 2021-09-02 18:27:01 -0700 | [diff] [blame] | 1991 | * Walk the "all connection" list and sync the connection state. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1992 | */ |
Ken Zhu | dc42367 | 2021-09-02 18:27:01 -0700 | [diff] [blame] | 1993 | while (likely(c && quota)) { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1994 | struct sfe_ipv4_connection_match *cm; |
| 1995 | struct sfe_ipv4_connection_match *counter_cm; |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 1996 | struct sfe_connection_sync sis; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 1997 | |
Ken Zhu | dc42367 | 2021-09-02 18:27:01 -0700 | [diff] [blame] | 1998 | cm = c->original_match; |
| 1999 | counter_cm = c->reply_match; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2000 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2001 | /* |
Ken Zhu | dc42367 | 2021-09-02 18:27:01 -0700 | [diff] [blame] | 2002 | * Didn't receive packets in the original direction or reply |
| 2003 | * direction, move to the next connection. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2004 | */ |
Ken Zhu | dc42367 | 2021-09-02 18:27:01 -0700 | [diff] [blame] | 2005 | if ((!atomic_read(&cm->rx_packet_count)) && !(atomic_read(&counter_cm->rx_packet_count))) { |
| 2006 | c = c->all_connections_next; |
| 2007 | continue; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2008 | } |
| 2009 | |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 2010 | sfe_ipv4_gen_sync_connection(si, c, &sis, SFE_SYNC_REASON_STATS, now_jiffies); |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 2011 | sfe_ipv4_stats_convert(conn_sync, &sis); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2012 | |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 2013 | quota--; |
| 2014 | conn_sync++; |
| 2015 | c = c->all_connections_next; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2016 | } |
| 2017 | |
Ken Zhu | dc42367 | 2021-09-02 18:27:01 -0700 | [diff] [blame] | 2018 | /* |
| 2019 | * At the end of the sync, put the wc_next to the connection we left. |
| 2020 | */ |
| 2021 | si->wc_next = c; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2022 | spin_unlock_bh(&si->lock); |
| 2023 | |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 2024 | count = sfe_ipv4_sync_max_number - quota; |
| 2025 | /* |
| 2026 | * Tell ecm sync round done if at the end of all connection |
| 2027 | * otherwise tell the number in the msg. |
| 2028 | */ |
| 2029 | if (c == NULL) { |
| 2030 | DEBUG_INFO("Synced all connections.\n"); |
| 2031 | sfe_ipv4_sync_many_msg->msg.conn_stats_many.next = 0; |
| 2032 | } else { |
| 2033 | DEBUG_INFO("Some connections left.\n"); |
| 2034 | sfe_ipv4_sync_many_msg->msg.conn_stats_many.next = count; |
| 2035 | } |
| 2036 | DEBUG_INFO("Sync %d connections\n", count); |
| 2037 | sfe_ipv4_sync_many_msg->msg.conn_stats_many.count = count; |
| 2038 | sfe_ipv4_sync_many_msg->cm.response = SFE_CMN_RESPONSE_ACK; |
| 2039 | |
| 2040 | sync_rule_callback(sfe_ipv4_sync_many_msg); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | #define CHAR_DEV_MSG_SIZE 768 |
| 2044 | |
| 2045 | /* |
| 2046 | * sfe_ipv4_debug_dev_read_start() |
| 2047 | * Generate part of the XML output. |
| 2048 | */ |
| 2049 | static bool sfe_ipv4_debug_dev_read_start(struct sfe_ipv4 *si, char *buffer, char *msg, size_t *length, |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 2050 | int *total_read, struct sfe_ipv4_debug_xml_write_state *ws) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2051 | { |
| 2052 | int bytes_read; |
| 2053 | |
Xiaoping Fan | 3458647 | 2015-07-03 02:20:35 -0700 | [diff] [blame] | 2054 | si->debug_read_seq++; |
| 2055 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2056 | bytes_read = snprintf(msg, CHAR_DEV_MSG_SIZE, "<sfe_ipv4>\n"); |
| 2057 | if (copy_to_user(buffer + *total_read, msg, CHAR_DEV_MSG_SIZE)) { |
| 2058 | return false; |
| 2059 | } |
| 2060 | |
| 2061 | *length -= bytes_read; |
| 2062 | *total_read += bytes_read; |
| 2063 | |
| 2064 | ws->state++; |
| 2065 | return true; |
| 2066 | } |
| 2067 | |
| 2068 | /* |
| 2069 | * sfe_ipv4_debug_dev_read_connections_start() |
| 2070 | * Generate part of the XML output. |
| 2071 | */ |
| 2072 | static bool sfe_ipv4_debug_dev_read_connections_start(struct sfe_ipv4 *si, char *buffer, char *msg, size_t *length, |
| 2073 | int *total_read, struct sfe_ipv4_debug_xml_write_state *ws) |
| 2074 | { |
| 2075 | int bytes_read; |
| 2076 | |
| 2077 | bytes_read = snprintf(msg, CHAR_DEV_MSG_SIZE, "\t<connections>\n"); |
| 2078 | if (copy_to_user(buffer + *total_read, msg, CHAR_DEV_MSG_SIZE)) { |
| 2079 | return false; |
| 2080 | } |
| 2081 | |
| 2082 | *length -= bytes_read; |
| 2083 | *total_read += bytes_read; |
| 2084 | |
| 2085 | ws->state++; |
| 2086 | return true; |
| 2087 | } |
| 2088 | |
| 2089 | /* |
| 2090 | * sfe_ipv4_debug_dev_read_connections_connection() |
| 2091 | * Generate part of the XML output. |
| 2092 | */ |
| 2093 | static bool sfe_ipv4_debug_dev_read_connections_connection(struct sfe_ipv4 *si, char *buffer, char *msg, size_t *length, |
| 2094 | int *total_read, struct sfe_ipv4_debug_xml_write_state *ws) |
| 2095 | { |
| 2096 | struct sfe_ipv4_connection *c; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2097 | struct sfe_ipv4_connection_match *original_cm; |
| 2098 | struct sfe_ipv4_connection_match *reply_cm; |
| 2099 | int bytes_read; |
| 2100 | int protocol; |
| 2101 | struct net_device *src_dev; |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 2102 | __be32 src_ip; |
| 2103 | __be32 src_ip_xlate; |
| 2104 | __be16 src_port; |
| 2105 | __be16 src_port_xlate; |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 2106 | u64 src_rx_packets; |
| 2107 | u64 src_rx_bytes; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2108 | struct net_device *dest_dev; |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 2109 | __be32 dest_ip; |
| 2110 | __be32 dest_ip_xlate; |
| 2111 | __be16 dest_port; |
| 2112 | __be16 dest_port_xlate; |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 2113 | u64 dest_rx_packets; |
| 2114 | u64 dest_rx_bytes; |
| 2115 | u64 last_sync_jiffies; |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 2116 | u32 src_mark, dest_mark, src_priority, dest_priority, src_dscp, dest_dscp; |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2117 | bool original_cm_sawf_valid, reply_cm_sawf_valid; |
| 2118 | u32 flow_service_class, return_service_class; |
| 2119 | u32 flow_msduq, return_msduq; |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 2120 | u32 packet, byte, original_cm_flags; |
| 2121 | u16 pppoe_session_id; |
| 2122 | u8 pppoe_remote_mac[ETH_ALEN]; |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 2123 | u32 original_fast_xmit, reply_fast_xmit; |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 2124 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 2125 | int src_flow_cookie, dst_flow_cookie; |
| 2126 | #endif |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2127 | |
| 2128 | spin_lock_bh(&si->lock); |
Xiaoping Fan | 3458647 | 2015-07-03 02:20:35 -0700 | [diff] [blame] | 2129 | |
| 2130 | for (c = si->all_connections_head; c; c = c->all_connections_next) { |
| 2131 | if (c->debug_read_seq < si->debug_read_seq) { |
| 2132 | c->debug_read_seq = si->debug_read_seq; |
| 2133 | break; |
| 2134 | } |
| 2135 | } |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2136 | |
| 2137 | /* |
Xiaoping Fan | 3458647 | 2015-07-03 02:20:35 -0700 | [diff] [blame] | 2138 | * If there were no connections then move to the next state. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2139 | */ |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 2140 | if (!c || c->removed) { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2141 | spin_unlock_bh(&si->lock); |
Xiaoping Fan | 3458647 | 2015-07-03 02:20:35 -0700 | [diff] [blame] | 2142 | ws->state++; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2143 | return true; |
| 2144 | } |
| 2145 | |
| 2146 | original_cm = c->original_match; |
| 2147 | reply_cm = c->reply_match; |
| 2148 | |
| 2149 | protocol = c->protocol; |
| 2150 | src_dev = c->original_dev; |
| 2151 | src_ip = c->src_ip; |
| 2152 | src_ip_xlate = c->src_ip_xlate; |
| 2153 | src_port = c->src_port; |
| 2154 | src_port_xlate = c->src_port_xlate; |
Xiaoping Fan | e1963d4 | 2015-08-25 17:06:19 -0700 | [diff] [blame] | 2155 | src_priority = original_cm->priority; |
| 2156 | src_dscp = original_cm->dscp >> SFE_IPV4_DSCP_SHIFT; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2157 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 2158 | sfe_ipv4_connection_match_update_summary_stats(original_cm, &packet, &byte); |
| 2159 | sfe_ipv4_connection_match_update_summary_stats(reply_cm, &packet, &byte); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2160 | |
| 2161 | src_rx_packets = original_cm->rx_packet_count64; |
| 2162 | src_rx_bytes = original_cm->rx_byte_count64; |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 2163 | src_mark = original_cm->mark; |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 2164 | original_fast_xmit = (original_cm->flags & SFE_IPV4_CONNECTION_MATCH_FLAG_FAST_XMIT); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2165 | dest_dev = c->reply_dev; |
| 2166 | dest_ip = c->dest_ip; |
| 2167 | dest_ip_xlate = c->dest_ip_xlate; |
| 2168 | dest_port = c->dest_port; |
| 2169 | dest_port_xlate = c->dest_port_xlate; |
Xiaoping Fan | e1963d4 | 2015-08-25 17:06:19 -0700 | [diff] [blame] | 2170 | dest_priority = reply_cm->priority; |
| 2171 | dest_dscp = reply_cm->dscp >> SFE_IPV4_DSCP_SHIFT; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2172 | dest_rx_packets = reply_cm->rx_packet_count64; |
| 2173 | dest_rx_bytes = reply_cm->rx_byte_count64; |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 2174 | dest_mark = reply_cm->mark; |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 2175 | reply_fast_xmit = (reply_cm->flags & SFE_IPV4_CONNECTION_MATCH_FLAG_FAST_XMIT); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2176 | last_sync_jiffies = get_jiffies_64() - c->last_sync_jiffies; |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 2177 | original_cm_flags = original_cm->flags; |
| 2178 | pppoe_session_id = original_cm->pppoe_session_id; |
| 2179 | ether_addr_copy(pppoe_remote_mac, original_cm->pppoe_remote_mac); |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2180 | original_cm_sawf_valid = original_cm->sawf_valid; |
| 2181 | reply_cm_sawf_valid = reply_cm->sawf_valid; |
| 2182 | flow_service_class = SFE_GET_SAWF_SERVICE_CLASS(original_cm->mark); |
| 2183 | flow_msduq = SFE_GET_SAWF_MSDUQ(original_cm->mark); |
| 2184 | return_service_class = SFE_GET_SAWF_SERVICE_CLASS(reply_cm->mark); |
| 2185 | return_msduq = SFE_GET_SAWF_MSDUQ(reply_cm->mark); |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 2186 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 2187 | src_flow_cookie = original_cm->flow_cookie; |
| 2188 | dst_flow_cookie = reply_cm->flow_cookie; |
| 2189 | #endif |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2190 | spin_unlock_bh(&si->lock); |
| 2191 | |
| 2192 | bytes_read = snprintf(msg, CHAR_DEV_MSG_SIZE, "\t\t<connection " |
| 2193 | "protocol=\"%u\" " |
| 2194 | "src_dev=\"%s\" " |
| 2195 | "src_ip=\"%pI4\" src_ip_xlate=\"%pI4\" " |
| 2196 | "src_port=\"%u\" src_port_xlate=\"%u\" " |
Xiaoping Fan | e1963d4 | 2015-08-25 17:06:19 -0700 | [diff] [blame] | 2197 | "src_priority=\"%u\" src_dscp=\"%u\" " |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2198 | "src_rx_pkts=\"%llu\" src_rx_bytes=\"%llu\" " |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 2199 | "src_mark=\"%08x\" " |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 2200 | "src_fast_xmit=\"%s\" " |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2201 | "dest_dev=\"%s\" " |
| 2202 | "dest_ip=\"%pI4\" dest_ip_xlate=\"%pI4\" " |
| 2203 | "dest_port=\"%u\" dest_port_xlate=\"%u\" " |
Xiaoping Fan | e1963d4 | 2015-08-25 17:06:19 -0700 | [diff] [blame] | 2204 | "dest_priority=\"%u\" dest_dscp=\"%u\" " |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2205 | "dest_rx_pkts=\"%llu\" dest_rx_bytes=\"%llu\" " |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 2206 | "dest_mark=\"%08x\" " |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 2207 | "reply_fast_xmit=\"%s\" " |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 2208 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 2209 | "src_flow_cookie=\"%d\" dst_flow_cookie=\"%d\" " |
| 2210 | #endif |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 2211 | "last_sync=\"%llu\" ", |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2212 | protocol, |
| 2213 | src_dev->name, |
| 2214 | &src_ip, &src_ip_xlate, |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 2215 | ntohs(src_port), ntohs(src_port_xlate), |
Xiaoping Fan | e1963d4 | 2015-08-25 17:06:19 -0700 | [diff] [blame] | 2216 | src_priority, src_dscp, |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2217 | src_rx_packets, src_rx_bytes, |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 2218 | src_mark, |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 2219 | original_fast_xmit ? "Yes" : "No", |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2220 | dest_dev->name, |
| 2221 | &dest_ip, &dest_ip_xlate, |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 2222 | ntohs(dest_port), ntohs(dest_port_xlate), |
Xiaoping Fan | e1963d4 | 2015-08-25 17:06:19 -0700 | [diff] [blame] | 2223 | dest_priority, dest_dscp, |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2224 | dest_rx_packets, dest_rx_bytes, |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 2225 | dest_mark, |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 2226 | reply_fast_xmit ? "Yes" : "No", |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 2227 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 2228 | src_flow_cookie, dst_flow_cookie, |
| 2229 | #endif |
Ken Zhu | 37040ea | 2021-09-09 21:11:15 -0700 | [diff] [blame] | 2230 | last_sync_jiffies); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2231 | |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 2232 | if (original_cm_flags &= (SFE_IPV4_CONNECTION_MATCH_FLAG_PPPOE_DECAP | SFE_IPV4_CONNECTION_MATCH_FLAG_PPPOE_ENCAP)) { |
Guduri Prathyusha | 79a5fee | 2021-11-11 17:59:10 +0530 | [diff] [blame] | 2233 | bytes_read += snprintf(msg + bytes_read, CHAR_DEV_MSG_SIZE, "pppoe_session_id=\"%u\" pppoe_server MAC=\"%pM\" ", |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 2234 | pppoe_session_id, pppoe_remote_mac); |
| 2235 | } |
| 2236 | |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2237 | if (original_cm_sawf_valid) { |
Parikshit Gune | fdd9865 | 2022-03-14 17:33:01 +0530 | [diff] [blame] | 2238 | bytes_read += snprintf(msg + bytes_read, CHAR_DEV_MSG_SIZE, "flow_service_class=\"%d\" flow_msduq = \"0x%x\" ", |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2239 | flow_service_class, flow_msduq); |
| 2240 | } |
| 2241 | |
| 2242 | if (reply_cm_sawf_valid) { |
Parikshit Gune | fdd9865 | 2022-03-14 17:33:01 +0530 | [diff] [blame] | 2243 | bytes_read += snprintf(msg + bytes_read, CHAR_DEV_MSG_SIZE, "return_service_class=\"%d\" return_msduq = \"0x%x\" ", |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2244 | return_service_class, return_msduq); |
| 2245 | } |
| 2246 | |
Guduri Prathyusha | eb31c90 | 2021-11-10 20:18:50 +0530 | [diff] [blame] | 2247 | bytes_read += snprintf(msg + bytes_read, CHAR_DEV_MSG_SIZE, "/>\n"); |
| 2248 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2249 | if (copy_to_user(buffer + *total_read, msg, CHAR_DEV_MSG_SIZE)) { |
| 2250 | return false; |
| 2251 | } |
| 2252 | |
| 2253 | *length -= bytes_read; |
| 2254 | *total_read += bytes_read; |
| 2255 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2256 | return true; |
| 2257 | } |
| 2258 | |
| 2259 | /* |
| 2260 | * sfe_ipv4_debug_dev_read_connections_end() |
| 2261 | * Generate part of the XML output. |
| 2262 | */ |
| 2263 | static bool sfe_ipv4_debug_dev_read_connections_end(struct sfe_ipv4 *si, char *buffer, char *msg, size_t *length, |
| 2264 | int *total_read, struct sfe_ipv4_debug_xml_write_state *ws) |
| 2265 | { |
| 2266 | int bytes_read; |
| 2267 | |
| 2268 | bytes_read = snprintf(msg, CHAR_DEV_MSG_SIZE, "\t</connections>\n"); |
| 2269 | if (copy_to_user(buffer + *total_read, msg, CHAR_DEV_MSG_SIZE)) { |
| 2270 | return false; |
| 2271 | } |
| 2272 | |
| 2273 | *length -= bytes_read; |
| 2274 | *total_read += bytes_read; |
| 2275 | |
| 2276 | ws->state++; |
| 2277 | return true; |
| 2278 | } |
| 2279 | |
| 2280 | /* |
| 2281 | * sfe_ipv4_debug_dev_read_exceptions_start() |
| 2282 | * Generate part of the XML output. |
| 2283 | */ |
| 2284 | static bool sfe_ipv4_debug_dev_read_exceptions_start(struct sfe_ipv4 *si, char *buffer, char *msg, size_t *length, |
| 2285 | int *total_read, struct sfe_ipv4_debug_xml_write_state *ws) |
| 2286 | { |
| 2287 | int bytes_read; |
| 2288 | |
| 2289 | bytes_read = snprintf(msg, CHAR_DEV_MSG_SIZE, "\t<exceptions>\n"); |
| 2290 | if (copy_to_user(buffer + *total_read, msg, CHAR_DEV_MSG_SIZE)) { |
| 2291 | return false; |
| 2292 | } |
| 2293 | |
| 2294 | *length -= bytes_read; |
| 2295 | *total_read += bytes_read; |
| 2296 | |
| 2297 | ws->state++; |
| 2298 | return true; |
| 2299 | } |
| 2300 | |
| 2301 | /* |
| 2302 | * sfe_ipv4_debug_dev_read_exceptions_exception() |
| 2303 | * Generate part of the XML output. |
| 2304 | */ |
| 2305 | static bool sfe_ipv4_debug_dev_read_exceptions_exception(struct sfe_ipv4 *si, char *buffer, char *msg, size_t *length, |
| 2306 | int *total_read, struct sfe_ipv4_debug_xml_write_state *ws) |
| 2307 | { |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 2308 | int i; |
| 2309 | u64 val = 0; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2310 | |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 2311 | for_each_possible_cpu(i) { |
| 2312 | const struct sfe_ipv4_stats *s = per_cpu_ptr(si->stats_pcpu, i); |
| 2313 | val += s->exception_events64[ws->iter_exception]; |
| 2314 | } |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2315 | |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 2316 | if (val) { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2317 | int bytes_read; |
| 2318 | |
| 2319 | bytes_read = snprintf(msg, CHAR_DEV_MSG_SIZE, |
| 2320 | "\t\t<exception name=\"%s\" count=\"%llu\" />\n", |
| 2321 | sfe_ipv4_exception_events_string[ws->iter_exception], |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 2322 | val); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2323 | if (copy_to_user(buffer + *total_read, msg, CHAR_DEV_MSG_SIZE)) { |
| 2324 | return false; |
| 2325 | } |
| 2326 | |
| 2327 | *length -= bytes_read; |
| 2328 | *total_read += bytes_read; |
| 2329 | } |
| 2330 | |
| 2331 | ws->iter_exception++; |
| 2332 | if (ws->iter_exception >= SFE_IPV4_EXCEPTION_EVENT_LAST) { |
| 2333 | ws->iter_exception = 0; |
| 2334 | ws->state++; |
| 2335 | } |
| 2336 | |
| 2337 | return true; |
| 2338 | } |
| 2339 | |
| 2340 | /* |
| 2341 | * sfe_ipv4_debug_dev_read_exceptions_end() |
| 2342 | * Generate part of the XML output. |
| 2343 | */ |
| 2344 | static bool sfe_ipv4_debug_dev_read_exceptions_end(struct sfe_ipv4 *si, char *buffer, char *msg, size_t *length, |
| 2345 | int *total_read, struct sfe_ipv4_debug_xml_write_state *ws) |
| 2346 | { |
| 2347 | int bytes_read; |
| 2348 | |
| 2349 | bytes_read = snprintf(msg, CHAR_DEV_MSG_SIZE, "\t</exceptions>\n"); |
| 2350 | if (copy_to_user(buffer + *total_read, msg, CHAR_DEV_MSG_SIZE)) { |
| 2351 | return false; |
| 2352 | } |
| 2353 | |
| 2354 | *length -= bytes_read; |
| 2355 | *total_read += bytes_read; |
| 2356 | |
| 2357 | ws->state++; |
| 2358 | return true; |
| 2359 | } |
| 2360 | |
| 2361 | /* |
| 2362 | * sfe_ipv4_debug_dev_read_stats() |
| 2363 | * Generate part of the XML output. |
| 2364 | */ |
| 2365 | static bool sfe_ipv4_debug_dev_read_stats(struct sfe_ipv4 *si, char *buffer, char *msg, size_t *length, |
| 2366 | int *total_read, struct sfe_ipv4_debug_xml_write_state *ws) |
| 2367 | { |
| 2368 | int bytes_read; |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 2369 | struct sfe_ipv4_stats stats; |
| 2370 | unsigned int num_conn; |
| 2371 | |
| 2372 | sfe_ipv4_update_summary_stats(si, &stats); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2373 | |
| 2374 | spin_lock_bh(&si->lock); |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 2375 | num_conn = si->num_connections; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2376 | spin_unlock_bh(&si->lock); |
| 2377 | |
| 2378 | bytes_read = snprintf(msg, CHAR_DEV_MSG_SIZE, "\t<stats " |
| 2379 | "num_connections=\"%u\" " |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 2380 | "pkts_dropped=\"%llu\" " |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 2381 | "pkts_fast_xmited=\"%llu\" " |
Xiaoping Fan | 5917642 | 2015-05-22 15:58:10 -0700 | [diff] [blame] | 2382 | "pkts_forwarded=\"%llu\" pkts_not_forwarded=\"%llu\" " |
| 2383 | "create_requests=\"%llu\" create_collisions=\"%llu\" " |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 2384 | "create_failures=\"%llu\" " |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2385 | "destroy_requests=\"%llu\" destroy_misses=\"%llu\" " |
| 2386 | "flushes=\"%llu\" " |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 2387 | "hash_hits=\"%llu\" hash_reorders=\"%llu\" " |
| 2388 | "pppoe_encap_pkts_fwded=\"%llu\" " |
Guduri Prathyusha | 034d635 | 2022-01-12 16:49:04 +0530 | [diff] [blame] | 2389 | "pppoe_decap_pkts_fwded=\"%llu\" " |
| 2390 | "pppoe_bridge_pkts_fwded=\"%llu\" />\n", |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 2391 | num_conn, |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 2392 | stats.packets_dropped64, |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 2393 | stats.packets_fast_xmited64, |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 2394 | stats.packets_forwarded64, |
| 2395 | stats.packets_not_forwarded64, |
| 2396 | stats.connection_create_requests64, |
| 2397 | stats.connection_create_collisions64, |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 2398 | stats.connection_create_failures64, |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 2399 | stats.connection_destroy_requests64, |
| 2400 | stats.connection_destroy_misses64, |
| 2401 | stats.connection_flushes64, |
| 2402 | stats.connection_match_hash_hits64, |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 2403 | stats.connection_match_hash_reorders64, |
| 2404 | stats.pppoe_encap_packets_forwarded64, |
Guduri Prathyusha | 034d635 | 2022-01-12 16:49:04 +0530 | [diff] [blame] | 2405 | stats.pppoe_decap_packets_forwarded64, |
| 2406 | stats.pppoe_bridge_packets_forwarded64); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2407 | if (copy_to_user(buffer + *total_read, msg, CHAR_DEV_MSG_SIZE)) { |
| 2408 | return false; |
| 2409 | } |
| 2410 | |
| 2411 | *length -= bytes_read; |
| 2412 | *total_read += bytes_read; |
| 2413 | |
| 2414 | ws->state++; |
| 2415 | return true; |
| 2416 | } |
| 2417 | |
| 2418 | /* |
| 2419 | * sfe_ipv4_debug_dev_read_end() |
| 2420 | * Generate part of the XML output. |
| 2421 | */ |
| 2422 | static bool sfe_ipv4_debug_dev_read_end(struct sfe_ipv4 *si, char *buffer, char *msg, size_t *length, |
| 2423 | int *total_read, struct sfe_ipv4_debug_xml_write_state *ws) |
| 2424 | { |
| 2425 | int bytes_read; |
| 2426 | |
| 2427 | bytes_read = snprintf(msg, CHAR_DEV_MSG_SIZE, "</sfe_ipv4>\n"); |
| 2428 | if (copy_to_user(buffer + *total_read, msg, CHAR_DEV_MSG_SIZE)) { |
| 2429 | return false; |
| 2430 | } |
| 2431 | |
| 2432 | *length -= bytes_read; |
| 2433 | *total_read += bytes_read; |
| 2434 | |
| 2435 | ws->state++; |
| 2436 | return true; |
| 2437 | } |
| 2438 | |
| 2439 | /* |
| 2440 | * Array of write functions that write various XML elements that correspond to |
| 2441 | * our XML output state machine. |
| 2442 | */ |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 2443 | static sfe_ipv4_debug_xml_write_method_t sfe_ipv4_debug_xml_write_methods[SFE_IPV4_DEBUG_XML_STATE_DONE] = { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2444 | sfe_ipv4_debug_dev_read_start, |
| 2445 | sfe_ipv4_debug_dev_read_connections_start, |
| 2446 | sfe_ipv4_debug_dev_read_connections_connection, |
| 2447 | sfe_ipv4_debug_dev_read_connections_end, |
| 2448 | sfe_ipv4_debug_dev_read_exceptions_start, |
| 2449 | sfe_ipv4_debug_dev_read_exceptions_exception, |
| 2450 | sfe_ipv4_debug_dev_read_exceptions_end, |
| 2451 | sfe_ipv4_debug_dev_read_stats, |
| 2452 | sfe_ipv4_debug_dev_read_end, |
| 2453 | }; |
| 2454 | |
| 2455 | /* |
| 2456 | * sfe_ipv4_debug_dev_read() |
| 2457 | * Send info to userspace upon read request from user |
| 2458 | */ |
| 2459 | static ssize_t sfe_ipv4_debug_dev_read(struct file *filp, char *buffer, size_t length, loff_t *offset) |
| 2460 | { |
| 2461 | char msg[CHAR_DEV_MSG_SIZE]; |
| 2462 | int total_read = 0; |
| 2463 | struct sfe_ipv4_debug_xml_write_state *ws; |
| 2464 | struct sfe_ipv4 *si = &__si; |
| 2465 | |
| 2466 | ws = (struct sfe_ipv4_debug_xml_write_state *)filp->private_data; |
| 2467 | while ((ws->state != SFE_IPV4_DEBUG_XML_STATE_DONE) && (length > CHAR_DEV_MSG_SIZE)) { |
| 2468 | if ((sfe_ipv4_debug_xml_write_methods[ws->state])(si, buffer, msg, &length, &total_read, ws)) { |
| 2469 | continue; |
| 2470 | } |
| 2471 | } |
| 2472 | |
| 2473 | return total_read; |
| 2474 | } |
| 2475 | |
| 2476 | /* |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2477 | * sfe_ipv4_debug_dev_open() |
| 2478 | */ |
| 2479 | static int sfe_ipv4_debug_dev_open(struct inode *inode, struct file *file) |
| 2480 | { |
| 2481 | struct sfe_ipv4_debug_xml_write_state *ws; |
| 2482 | |
| 2483 | ws = (struct sfe_ipv4_debug_xml_write_state *)file->private_data; |
| 2484 | if (!ws) { |
| 2485 | ws = kzalloc(sizeof(struct sfe_ipv4_debug_xml_write_state), GFP_KERNEL); |
| 2486 | if (!ws) { |
| 2487 | return -ENOMEM; |
| 2488 | } |
| 2489 | |
| 2490 | ws->state = SFE_IPV4_DEBUG_XML_STATE_START; |
| 2491 | file->private_data = ws; |
| 2492 | } |
| 2493 | |
| 2494 | return 0; |
| 2495 | } |
| 2496 | |
| 2497 | /* |
| 2498 | * sfe_ipv4_debug_dev_release() |
| 2499 | */ |
| 2500 | static int sfe_ipv4_debug_dev_release(struct inode *inode, struct file *file) |
| 2501 | { |
| 2502 | struct sfe_ipv4_debug_xml_write_state *ws; |
| 2503 | |
| 2504 | ws = (struct sfe_ipv4_debug_xml_write_state *)file->private_data; |
| 2505 | if (ws) { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2506 | /* |
| 2507 | * We've finished with our output so free the write state. |
| 2508 | */ |
| 2509 | kfree(ws); |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 2510 | file->private_data = NULL; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | return 0; |
| 2514 | } |
| 2515 | |
| 2516 | /* |
| 2517 | * File operations used in the debug char device |
| 2518 | */ |
| 2519 | static struct file_operations sfe_ipv4_debug_dev_fops = { |
| 2520 | .read = sfe_ipv4_debug_dev_read, |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2521 | .open = sfe_ipv4_debug_dev_open, |
| 2522 | .release = sfe_ipv4_debug_dev_release |
| 2523 | }; |
| 2524 | |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 2525 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 2526 | /* |
| 2527 | * sfe_register_flow_cookie_cb |
| 2528 | * register a function in SFE to let SFE use this function to configure flow cookie for a flow |
| 2529 | * |
| 2530 | * Hardware driver which support flow cookie should register a callback function in SFE. Then SFE |
| 2531 | * can use this function to configure flow cookie for a flow. |
| 2532 | * return: 0, success; !=0, fail |
| 2533 | */ |
| 2534 | int sfe_register_flow_cookie_cb(flow_cookie_set_func_t cb) |
| 2535 | { |
| 2536 | struct sfe_ipv4 *si = &__si; |
| 2537 | |
| 2538 | BUG_ON(!cb); |
| 2539 | |
| 2540 | if (si->flow_cookie_set_func) { |
| 2541 | return -1; |
| 2542 | } |
| 2543 | |
| 2544 | rcu_assign_pointer(si->flow_cookie_set_func, cb); |
| 2545 | return 0; |
| 2546 | } |
| 2547 | |
| 2548 | /* |
| 2549 | * sfe_unregister_flow_cookie_cb |
| 2550 | * unregister function which is used to configure flow cookie for a flow |
| 2551 | * |
| 2552 | * return: 0, success; !=0, fail |
| 2553 | */ |
| 2554 | int sfe_unregister_flow_cookie_cb(flow_cookie_set_func_t cb) |
| 2555 | { |
| 2556 | struct sfe_ipv4 *si = &__si; |
| 2557 | |
| 2558 | RCU_INIT_POINTER(si->flow_cookie_set_func, NULL); |
| 2559 | return 0; |
| 2560 | } |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 2561 | |
| 2562 | /* |
| 2563 | * sfe_ipv4_get_flow_cookie() |
| 2564 | */ |
| 2565 | static ssize_t sfe_ipv4_get_flow_cookie(struct device *dev, |
| 2566 | struct device_attribute *attr, |
| 2567 | char *buf) |
| 2568 | { |
| 2569 | struct sfe_ipv4 *si = &__si; |
Xiaoping Fan | 01c67cc | 2015-11-09 11:31:57 -0800 | [diff] [blame] | 2570 | return snprintf(buf, (ssize_t)PAGE_SIZE, "%d\n", si->flow_cookie_enable); |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | /* |
| 2574 | * sfe_ipv4_set_flow_cookie() |
| 2575 | */ |
| 2576 | static ssize_t sfe_ipv4_set_flow_cookie(struct device *dev, |
| 2577 | struct device_attribute *attr, |
| 2578 | const char *buf, size_t size) |
| 2579 | { |
| 2580 | struct sfe_ipv4 *si = &__si; |
Ken Zhu | 137722d | 2021-09-23 17:57:36 -0700 | [diff] [blame] | 2581 | si->flow_cookie_enable = simple_strtol(buf, NULL, 0); |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 2582 | |
| 2583 | return size; |
| 2584 | } |
| 2585 | |
| 2586 | /* |
| 2587 | * sysfs attributes. |
| 2588 | */ |
| 2589 | static const struct device_attribute sfe_ipv4_flow_cookie_attr = |
Xiaoping Fan | e70da41 | 2016-02-26 16:47:57 -0800 | [diff] [blame] | 2590 | __ATTR(flow_cookie_enable, S_IWUSR | S_IRUGO, sfe_ipv4_get_flow_cookie, sfe_ipv4_set_flow_cookie); |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 2591 | #endif /*CONFIG_NF_FLOW_COOKIE*/ |
| 2592 | |
Ken Zhu | 137722d | 2021-09-23 17:57:36 -0700 | [diff] [blame] | 2593 | /* |
| 2594 | * sfe_ipv4_get_cpu() |
| 2595 | */ |
| 2596 | static ssize_t sfe_ipv4_get_cpu(struct device *dev, |
| 2597 | struct device_attribute *attr, |
| 2598 | char *buf) |
| 2599 | { |
| 2600 | struct sfe_ipv4 *si = &__si; |
| 2601 | return snprintf(buf, (ssize_t)PAGE_SIZE, "%d\n", si->work_cpu); |
| 2602 | } |
| 2603 | |
| 2604 | /* |
| 2605 | * sfe_ipv4_set_cpu() |
| 2606 | */ |
| 2607 | static ssize_t sfe_ipv4_set_cpu(struct device *dev, |
| 2608 | struct device_attribute *attr, |
| 2609 | const char *buf, size_t size) |
| 2610 | { |
| 2611 | struct sfe_ipv4 *si = &__si; |
| 2612 | int work_cpu; |
| 2613 | work_cpu = simple_strtol(buf, NULL, 0); |
| 2614 | if ((work_cpu >= 0) && (work_cpu <= NR_CPUS)) { |
| 2615 | si->work_cpu = work_cpu; |
| 2616 | } else { |
| 2617 | dev_err(dev, "%s is not in valid range[0,%d]", buf, NR_CPUS); |
| 2618 | } |
| 2619 | return size; |
| 2620 | } |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 2621 | |
Ken Zhu | 137722d | 2021-09-23 17:57:36 -0700 | [diff] [blame] | 2622 | /* |
| 2623 | * sysfs attributes. |
| 2624 | */ |
| 2625 | static const struct device_attribute sfe_ipv4_cpu_attr = |
| 2626 | __ATTR(stats_work_cpu, S_IWUSR | S_IRUGO, sfe_ipv4_get_cpu, sfe_ipv4_set_cpu); |
| 2627 | |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 2628 | /* |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 2629 | * sfe_ipv4_conn_match_hash_init() |
| 2630 | * Initialize conn match hash lists |
| 2631 | */ |
| 2632 | static void sfe_ipv4_conn_match_hash_init(struct sfe_ipv4 *si, int len) |
| 2633 | { |
| 2634 | struct hlist_head *hash_list = si->hlist_conn_match_hash_head; |
| 2635 | int i; |
| 2636 | |
| 2637 | for (i = 0; i < len; i++) { |
| 2638 | INIT_HLIST_HEAD(&hash_list[i]); |
| 2639 | } |
| 2640 | } |
| 2641 | |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 2642 | #ifdef SFE_PROCESS_LOCAL_OUT |
| 2643 | /* |
| 2644 | * sfe_ipv4_local_out() |
| 2645 | * Called for packets from ip_local_out() - post encapsulation & other packets |
| 2646 | */ |
| 2647 | static unsigned int sfe_ipv4_local_out(void *priv, struct sk_buff *skb, const struct nf_hook_state *nhs) |
| 2648 | { |
Nitin Shetty | c28f817 | 2022-02-04 16:23:46 +0530 | [diff] [blame] | 2649 | struct sfe_l2_info l2_info = {0}; |
Guduri Prathyusha | 5f27e23 | 2022-01-06 14:39:04 +0530 | [diff] [blame] | 2650 | |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 2651 | DEBUG_TRACE("%px: sfe: sfe_ipv4_local_out hook called.\n", skb); |
| 2652 | |
| 2653 | if (likely(skb->skb_iif)) { |
Guduri Prathyusha | 5f27e23 | 2022-01-06 14:39:04 +0530 | [diff] [blame] | 2654 | return sfe_ipv4_recv(skb->dev, skb, &l2_info, true) ? NF_STOLEN : NF_ACCEPT; |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 2655 | } |
| 2656 | |
| 2657 | return NF_ACCEPT; |
| 2658 | } |
| 2659 | |
| 2660 | /* |
| 2661 | * struct nf_hook_ops sfe_ipv4_ops_local_out[] |
| 2662 | * Hooks into netfilter local out packet monitoring points. |
| 2663 | */ |
| 2664 | static struct nf_hook_ops sfe_ipv4_ops_local_out[] __read_mostly = { |
| 2665 | |
| 2666 | /* |
| 2667 | * Local out routing hook is used to monitor packets. |
| 2668 | */ |
| 2669 | { |
| 2670 | .hook = sfe_ipv4_local_out, |
| 2671 | .pf = PF_INET, |
| 2672 | .hooknum = NF_INET_LOCAL_OUT, |
| 2673 | .priority = NF_IP_PRI_FIRST, |
| 2674 | }, |
| 2675 | }; |
| 2676 | #endif |
| 2677 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2678 | /* |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 2679 | * sfe_ipv4_init() |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2680 | */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 2681 | int sfe_ipv4_init(void) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2682 | { |
| 2683 | struct sfe_ipv4 *si = &__si; |
| 2684 | int result = -1; |
| 2685 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 2686 | DEBUG_INFO("SFE IPv4 init\n"); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2687 | |
Ratheesh Kannoth | 94fc5b8 | 2021-10-20 07:45:06 +0530 | [diff] [blame] | 2688 | sfe_ipv4_conn_match_hash_init(si, ARRAY_SIZE(si->hlist_conn_match_hash_head)); |
| 2689 | |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 2690 | si->stats_pcpu = alloc_percpu_gfp(struct sfe_ipv4_stats, GFP_KERNEL | __GFP_ZERO); |
| 2691 | if (!si->stats_pcpu) { |
| 2692 | DEBUG_ERROR("failed to allocate stats memory for sfe_ipv4\n"); |
| 2693 | goto exit0; |
| 2694 | } |
| 2695 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2696 | /* |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2697 | * Allocate per cpu per service class memory. |
| 2698 | */ |
| 2699 | si->stats_pcpu_psc = alloc_percpu_gfp(struct sfe_ipv4_service_class_stats_db, |
| 2700 | GFP_KERNEL | __GFP_ZERO); |
| 2701 | if (!si->stats_pcpu_psc) { |
| 2702 | DEBUG_ERROR("failed to allocate per cpu per service clas stats memory\n"); |
| 2703 | goto exit1; |
| 2704 | } |
| 2705 | |
| 2706 | /* |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2707 | * Create sys/sfe_ipv4 |
| 2708 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 2709 | si->sys_ipv4 = kobject_create_and_add("sfe_ipv4", NULL); |
| 2710 | if (!si->sys_ipv4) { |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2711 | DEBUG_ERROR("failed to register sfe_ipv4\n"); |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2712 | goto exit2; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | /* |
| 2716 | * Create files, one for each parameter supported by this module. |
| 2717 | */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 2718 | result = sysfs_create_file(si->sys_ipv4, &sfe_ipv4_debug_dev_attr.attr); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2719 | if (result) { |
| 2720 | DEBUG_ERROR("failed to register debug dev file: %d\n", result); |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2721 | goto exit3; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2722 | } |
| 2723 | |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 2724 | result = sysfs_create_file(si->sys_ipv4, &sfe_ipv4_cpu_attr.attr); |
Ken Zhu | 137722d | 2021-09-23 17:57:36 -0700 | [diff] [blame] | 2725 | if (result) { |
| 2726 | DEBUG_ERROR("failed to register debug dev file: %d\n", result); |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2727 | goto exit4; |
Ken Zhu | 137722d | 2021-09-23 17:57:36 -0700 | [diff] [blame] | 2728 | } |
| 2729 | |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 2730 | #ifdef CONFIG_NF_FLOW_COOKIE |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 2731 | result = sysfs_create_file(si->sys_ipv4, &sfe_ipv4_flow_cookie_attr.attr); |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 2732 | if (result) { |
| 2733 | DEBUG_ERROR("failed to register flow cookie enable file: %d\n", result); |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2734 | goto exit5; |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 2735 | } |
| 2736 | #endif /* CONFIG_NF_FLOW_COOKIE */ |
| 2737 | |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 2738 | #ifdef SFE_PROCESS_LOCAL_OUT |
| 2739 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0)) |
| 2740 | result = nf_register_hooks(sfe_ipv4_ops_local_out, ARRAY_SIZE(sfe_ipv4_ops_local_out)); |
| 2741 | #else |
| 2742 | result = nf_register_net_hooks(&init_net, sfe_ipv4_ops_local_out, ARRAY_SIZE(sfe_ipv4_ops_local_out)); |
| 2743 | #endif |
| 2744 | if (result < 0) { |
| 2745 | DEBUG_ERROR("can't register nf local out hook: %d\n", result); |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2746 | goto exit6; |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 2747 | } |
| 2748 | DEBUG_INFO("Register nf local out hook success: %d\n", result); |
| 2749 | #endif |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2750 | /* |
| 2751 | * Register our debug char device. |
| 2752 | */ |
| 2753 | result = register_chrdev(0, "sfe_ipv4", &sfe_ipv4_debug_dev_fops); |
| 2754 | if (result < 0) { |
| 2755 | DEBUG_ERROR("Failed to register chrdev: %d\n", result); |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2756 | goto exit7; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | si->debug_dev = result; |
Ken Zhu | 137722d | 2021-09-23 17:57:36 -0700 | [diff] [blame] | 2760 | si->work_cpu = WORK_CPU_UNBOUND; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2761 | |
| 2762 | /* |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 2763 | * Create a work to handle pull message from ecm. |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2764 | */ |
Ken Zhu | 137722d | 2021-09-23 17:57:36 -0700 | [diff] [blame] | 2765 | INIT_DELAYED_WORK(&(si->sync_dwork), sfe_ipv4_periodic_sync); |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 2766 | /* |
| 2767 | * Allocate a message for stats sync many |
| 2768 | */ |
| 2769 | sfe_ipv4_sync_many_msg = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 2770 | if(!sfe_ipv4_sync_many_msg) { |
| 2771 | goto exit8; |
| 2772 | } |
| 2773 | |
| 2774 | sfe_ipv4_msg_init(sfe_ipv4_sync_many_msg, SFE_SPECIAL_INTERFACE_IPV4, |
| 2775 | SFE_TX_CONN_STATS_SYNC_MANY_MSG, |
| 2776 | sizeof(struct sfe_ipv4_conn_sync_many_msg), |
| 2777 | NULL, |
| 2778 | NULL); |
| 2779 | sfe_ipv4_sync_max_number = (PAGE_SIZE - sizeof(struct sfe_ipv4_msg)) / sizeof(struct sfe_ipv4_conn_sync); |
Ken Zhu | 137722d | 2021-09-23 17:57:36 -0700 | [diff] [blame] | 2780 | |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 2781 | spin_lock_init(&si->lock); |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 2782 | return 0; |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2783 | |
Ken Zhu | 7a43d88 | 2022-01-04 10:51:44 -0800 | [diff] [blame] | 2784 | exit8: |
| 2785 | unregister_chrdev(si->debug_dev, "sfe_ipv4"); |
| 2786 | |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2787 | exit7: |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 2788 | #ifdef SFE_PROCESS_LOCAL_OUT |
| 2789 | DEBUG_TRACE("sfe: Unregister local out hook\n"); |
| 2790 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0)) |
| 2791 | nf_unregister_hooks(sfe_ipv4_ops_local_out, ARRAY_SIZE(sfe_ipv4_ops_local_out)); |
| 2792 | #else |
| 2793 | nf_unregister_net_hooks(&init_net, sfe_ipv4_ops_local_out, ARRAY_SIZE(sfe_ipv4_ops_local_out)); |
| 2794 | #endif |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2795 | exit6: |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 2796 | #endif |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 2797 | #ifdef CONFIG_NF_FLOW_COOKIE |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 2798 | sysfs_remove_file(si->sys_ipv4, &sfe_ipv4_flow_cookie_attr.attr); |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 2799 | |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2800 | exit5: |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 2801 | #endif /* CONFIG_NF_FLOW_COOKIE */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 2802 | sysfs_remove_file(si->sys_ipv4, &sfe_ipv4_cpu_attr.attr); |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2803 | exit4: |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 2804 | sysfs_remove_file(si->sys_ipv4, &sfe_ipv4_debug_dev_attr.attr); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2805 | |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2806 | exit3: |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 2807 | kobject_put(si->sys_ipv4); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2808 | |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2809 | exit2: |
| 2810 | free_percpu(si->stats_pcpu_psc); |
| 2811 | |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2812 | exit1: |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 2813 | free_percpu(si->stats_pcpu); |
| 2814 | |
| 2815 | exit0: |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2816 | return result; |
| 2817 | } |
| 2818 | |
| 2819 | /* |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2820 | * sfe_ipv4_exit() |
| 2821 | */ |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 2822 | void sfe_ipv4_exit(void) |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2823 | { |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 2824 | struct sfe_ipv4 *si = &__si; |
| 2825 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 2826 | DEBUG_INFO("SFE IPv4 exit\n"); |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 2827 | /* |
| 2828 | * Destroy all connections. |
| 2829 | */ |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 2830 | sfe_ipv4_destroy_all_rules_for_dev(NULL); |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 2831 | |
Ken Zhu | 137722d | 2021-09-23 17:57:36 -0700 | [diff] [blame] | 2832 | cancel_delayed_work_sync(&si->sync_dwork); |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 2833 | |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 2834 | unregister_chrdev(si->debug_dev, "sfe_ipv4"); |
| 2835 | |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 2836 | #ifdef SFE_PROCESS_LOCAL_OUT |
| 2837 | DEBUG_TRACE("sfe: Unregister local out hook\n"); |
| 2838 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0)) |
| 2839 | nf_unregister_hooks(sfe_ipv4_ops_local_out, ARRAY_SIZE(sfe_ipv4_ops_local_out)); |
| 2840 | #else |
| 2841 | nf_unregister_net_hooks(&init_net, sfe_ipv4_ops_local_out, ARRAY_SIZE(sfe_ipv4_ops_local_out)); |
| 2842 | #endif |
| 2843 | #endif |
| 2844 | |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 2845 | #ifdef CONFIG_NF_FLOW_COOKIE |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 2846 | sysfs_remove_file(si->sys_ipv4, &sfe_ipv4_flow_cookie_attr.attr); |
Xiaoping Fan | 640faf4 | 2015-08-28 15:50:55 -0700 | [diff] [blame] | 2847 | #endif /* CONFIG_NF_FLOW_COOKIE */ |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 2848 | sysfs_remove_file(si->sys_ipv4, &sfe_ipv4_debug_dev_attr.attr); |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 2849 | |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 2850 | sysfs_remove_file(si->sys_ipv4, &sfe_ipv4_cpu_attr.attr); |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 2851 | |
Ratheesh Kannoth | 6307bec | 2021-11-25 08:26:39 +0530 | [diff] [blame] | 2852 | kobject_put(si->sys_ipv4); |
Dave Hudson | 87973cd | 2013-10-22 16:00:04 +0100 | [diff] [blame] | 2853 | |
Ratheesh Kannoth | 3aeb289 | 2021-10-20 07:57:15 +0530 | [diff] [blame] | 2854 | free_percpu(si->stats_pcpu); |
Parikshit Gune | d31a820 | 2022-01-05 22:15:04 +0530 | [diff] [blame] | 2855 | free_percpu(si->stats_pcpu_psc); |
Dave Hudson | aaf97ca | 2013-06-13 17:52:29 +0100 | [diff] [blame] | 2856 | } |
| 2857 | |
Xiaoping Fan | d1dc7b2 | 2015-01-23 00:43:56 -0800 | [diff] [blame] | 2858 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 2859 | EXPORT_SYMBOL(sfe_register_flow_cookie_cb); |
| 2860 | EXPORT_SYMBOL(sfe_unregister_flow_cookie_cb); |
| 2861 | #endif |