blob: 22effa42ce583930e7555d4738ef5b0c46c5a42d [file] [log] [blame]
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +05301/*
2 * sfe_ipv4.h
3 * Shortcut forwarding engine header file for IPv4.
4 *
5 * Copyright (c) 2013-2016, 2019-2020, The Linux Foundation. All rights reserved.
Guduri Prathyusha5f27e232022-01-06 14:39:04 +05306 * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +05307 *
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
Wayne Tanbb7f1782021-12-13 11:16:04 -080021#ifndef __SFE_IPV4_H
22#define __SFE_IPV4_H
23
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +053024#define SFE_IPV4_DSCP_MASK 0x3
25#define SFE_IPV4_DSCP_SHIFT 2
Tian Yangd98d91b2022-03-09 14:50:12 -080026#include <linux/version.h>
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +053027
28/*
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +053029 * Specifies the lower bound on ACK numbers carried in the TCP header
30 */
31#define SFE_IPV4_TCP_MAX_ACK_WINDOW 65520
32
33/*
34 * IPv4 TCP connection match additional data.
35 */
36struct sfe_ipv4_tcp_connection_match {
37 u8 win_scale; /* Window scale */
38 u32 max_win; /* Maximum window size seen */
39 u32 end; /* Sequence number of the next byte to send (seq + segment length) */
40 u32 max_end; /* Sequence number of the last byte to ack */
41};
42
43/*
44 * Bit flags for IPv4 connection matching entry.
45 */
46#define SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_SRC (1<<0)
47 /* Perform source translation */
48#define SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_DEST (1<<1)
49 /* Perform destination translation */
50#define SFE_IPV4_CONNECTION_MATCH_FLAG_NO_SEQ_CHECK (1<<2)
51 /* Ignore TCP sequence numbers */
52#define SFE_IPV4_CONNECTION_MATCH_FLAG_WRITE_FAST_ETH_HDR (1<<3)
53 /* Fast Ethernet header write */
54#define SFE_IPV4_CONNECTION_MATCH_FLAG_WRITE_L2_HDR (1<<4)
55 /* Fast Ethernet header write */
56#define SFE_IPV4_CONNECTION_MATCH_FLAG_PRIORITY_REMARK (1<<5)
57 /* remark priority of SKB */
58#define SFE_IPV4_CONNECTION_MATCH_FLAG_DSCP_REMARK (1<<6)
59 /* remark DSCP of packet */
Ratheesh Kannotha3cf0e02021-12-09 09:44:10 +053060#define SFE_IPV4_CONNECTION_MATCH_FLAG_CSUM_OFFLOAD (1<<7)
61 /* checksum offload.*/
Guduri Prathyushaeb31c902021-11-10 20:18:50 +053062#define SFE_IPV4_CONNECTION_MATCH_FLAG_PPPOE_DECAP (1<<8)
63 /* Indicates that PPPoE should be decapsulated */
64#define SFE_IPV4_CONNECTION_MATCH_FLAG_PPPOE_ENCAP (1<<9)
65 /* Indicates that PPPoE should be encapsulated */
Ratheesh Kannoth71fc51e2022-01-05 10:02:47 +053066#define SFE_IPV4_CONNECTION_MATCH_FLAG_BRIDGE_FLOW (1<<10)
67 /* Bridge flow */
Ken Zhu37040ea2021-09-09 21:11:15 -070068#define SFE_IPV4_CONNECTION_MATCH_FLAG_MARK (1<<11)
69 /* skb mark of the packet */
Wayne Tanbb7f1782021-12-13 11:16:04 -080070#define SFE_IPV4_CONNECTION_MATCH_FLAG_INSERT_EGRESS_VLAN_TAG (1<<12)
71 /* Insert VLAN tag */
Ratheesh Kannoth5dee3772022-01-18 11:27:14 +053072#define SFE_IPV4_CONNECTION_MATCH_FLAG_SRC_INTERFACE_CHECK (1<<13)
Murat Sezgin9c538972022-05-17 13:33:17 -070073 /* Source interface check */
Nitin Shettye6ed5b52021-12-27 14:50:11 +053074#define SFE_IPV4_CONNECTION_MATCH_FLAG_PASSTHROUGH (1<<14)
75 /* passthrough flow: encap/decap to be skipped for this flow */
Ken Zhu7e38d1a2021-11-30 17:31:46 -080076#define SFE_IPV4_CONNECTION_MATCH_FLAG_FAST_XMIT (1<<15)
77 /* skb go fast xmit */
78#define SFE_IPV4_CONNECTION_MATCH_FLAG_FAST_XMIT_FLOW_CHECKED (1<<16)
79 /* Fast xmit flow checked or not */
80#define SFE_IPV4_CONNECTION_MATCH_FLAG_FAST_XMIT_DEV_ADMISSION (1<<17)
81 /* Fast xmit may be possible for this flow, if SFE check passes */
Murat Sezgin9c538972022-05-17 13:33:17 -070082#define SFE_IPV4_CONNECTION_MATCH_FLAG_SRC_INTERFACE_CHECK_NO_FLUSH (1<<18)
83 /* Source interface check but do not flush the connection */
Wayne Tanbb7f1782021-12-13 11:16:04 -080084
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +053085/*
86 * IPv4 connection matching structure.
87 */
88struct sfe_ipv4_connection_match {
89 /*
90 * References to other objects.
91 */
Ratheesh Kannoth94fc5b82021-10-20 07:45:06 +053092 struct hlist_node hnode;
93
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +053094 /*
95 * Characteristics that identify flows that match this rule.
96 */
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +053097 __be32 match_src_ip; /* Source IP address */
98 __be32 match_dest_ip; /* Destination IP address */
99 __be16 match_src_port; /* Source port/connection ident */
100 __be16 match_dest_port; /* Destination port/connection ident */
Sourav Poddar345e26a2022-07-26 17:53:08 +0530101 u8 match_protocol; /* Protocol */
102 u32 flags; /* Bit flags */
103 u16 xmit_dest_mac[ETH_ALEN / 2];
104 /* Destination MAC address to use when forwarding */
105 u16 xmit_src_mac[ETH_ALEN / 2];
106 /* Source MAC address to use when forwarding */
107 struct net_device *xmit_dev; /* Network device on which to transmit */
108 /*
109 * xmit device's feature
110 */
111 netdev_features_t features;
112 /*
113 * Packet transmit information.
114 */
115 unsigned short int xmit_dev_mtu;
116 /* Interface MTU */
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530117
Sourav Poddar345e26a2022-07-26 17:53:08 +0530118 /*
119 * Size of all needed L2 headers
120 */
121 u16 l2_hdr_size;
122
123 /*
124 * Stats recorded in a sync period. These stats will be added to
125 * rx_packet_count64/rx_byte_count64 after a sync period.
126 */
127 atomic_t rx_packet_count;
128 atomic_t rx_byte_count;
129
130 struct net_device *match_dev; /* Network device */
Amitesh Anand63be37d2021-12-24 20:51:48 +0530131
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530132 /*
133 * Control the operations of the match.
134 */
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530135#ifdef CONFIG_NF_FLOW_COOKIE
136 u32 flow_cookie; /* used flow cookie, for debug */
137#endif
138#ifdef CONFIG_XFRM
139 u32 flow_accel; /* The flow accelerated or not */
140#endif
141
Sourav Poddar345e26a2022-07-26 17:53:08 +0530142 struct sfe_ipv4_connection *connection;
143 struct sfe_ipv4_connection_match *counter_match;
144 /* Matches the flow in the opposite direction as the one in *connection */
145
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530146 /*
147 * Connection state that we track once we match.
148 */
149 union { /* Protocol-specific state */
150 struct sfe_ipv4_tcp_connection_match tcp;
151 } protocol_state;
Wayne Tanbb7f1782021-12-13 11:16:04 -0800152
Sourav Poddar345e26a2022-07-26 17:53:08 +0530153 struct udp_sock *up; /* Stores UDP sock information; valid only in decap path */
154
155#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0))
156 const struct net_protocol *proto; /* stores protocol handler; valid only in decap path */
157#else
158 struct net_protocol *proto; /* stores protocol handler; valid only in decap path */
159#endif
160
Wayne Tanbb7f1782021-12-13 11:16:04 -0800161 /*
162 * VLAN headers
163 */
164 struct sfe_vlan_hdr ingress_vlan_hdr[SFE_MAX_VLAN_DEPTH];
165 struct sfe_vlan_hdr egress_vlan_hdr[SFE_MAX_VLAN_DEPTH];
166
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530167 /*
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530168 * Packet translation information.
169 */
170 __be32 xlate_src_ip; /* Address after source translation */
171 __be16 xlate_src_port; /* Port/connection ident after source translation */
172 u16 xlate_src_csum_adjustment;
173 /* Transport layer checksum adjustment after source translation */
174 u16 xlate_src_partial_csum_adjustment;
175 /* Transport layer pseudo header checksum adjustment after source translation */
176
177 __be32 xlate_dest_ip; /* Address after destination translation */
178 __be16 xlate_dest_port; /* Port/connection ident after destination translation */
179 u16 xlate_dest_csum_adjustment;
180 /* Transport layer checksum adjustment after destination translation */
181 u16 xlate_dest_partial_csum_adjustment;
182 /* Transport layer pseudo header checksum adjustment after destination translation */
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530183 /*
184 * QoS information
185 */
186 u32 priority;
187 u32 dscp;
Ken Zhu37040ea2021-09-09 21:11:15 -0700188 u32 mark; /* mark for outgoing packet */
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530189
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530190
Wayne Tanbb7f1782021-12-13 11:16:04 -0800191 u8 ingress_vlan_hdr_cnt; /* Ingress active vlan headers count */
192 u8 egress_vlan_hdr_cnt; /* Egress active vlan headers count */
193
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530194 /*
195 * Summary stats.
196 */
197 u64 rx_packet_count64;
198 u64 rx_byte_count64;
Guduri Prathyushaeb31c902021-11-10 20:18:50 +0530199
200 /*
201 * PPPoE information
202 */
203 u16 pppoe_session_id;
204 u8 pppoe_remote_mac[ETH_ALEN];
Wayne Tanbb7f1782021-12-13 11:16:04 -0800205
Tian Yang46d6eb02022-03-31 10:26:16 -0700206 struct net_device *top_interface_dev; /* Used by tun6rd to store decap VLAN netdevice.*/
207
Parikshit Guned31a8202022-01-05 22:15:04 +0530208 bool sawf_valid; /* Indicates mark has valid SAWF information */
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530209};
210
211/*
212 * Per-connection data structure.
213 */
214struct sfe_ipv4_connection {
215 struct sfe_ipv4_connection *next;
216 /* Pointer to the next entry in a hash chain */
217 struct sfe_ipv4_connection *prev;
218 /* Pointer to the previous entry in a hash chain */
219 int protocol; /* IP protocol number */
220 __be32 src_ip; /* Src IP addr pre-translation */
221 __be32 src_ip_xlate; /* Src IP addr post-translation */
222 __be32 dest_ip; /* Dest IP addr pre-translation */
223 __be32 dest_ip_xlate; /* Dest IP addr post-translation */
224 __be16 src_port; /* Src port pre-translation */
225 __be16 src_port_xlate; /* Src port post-translation */
226 __be16 dest_port; /* Dest port pre-translation */
227 __be16 dest_port_xlate; /* Dest port post-translation */
228 struct sfe_ipv4_connection_match *original_match;
229 /* Original direction matching structure */
230 struct net_device *original_dev;
231 /* Original direction source device */
232 struct sfe_ipv4_connection_match *reply_match;
233 /* Reply direction matching structure */
234 struct net_device *reply_dev; /* Reply direction source device */
235 u64 last_sync_jiffies; /* Jiffies count for the last sync */
236 struct sfe_ipv4_connection *all_connections_next;
237 /* Pointer to the next entry in the list of all connections */
238 struct sfe_ipv4_connection *all_connections_prev;
239 /* Pointer to the previous entry in the list of all connections */
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530240 u32 debug_read_seq; /* sequence number for debug dump */
Ratheesh Kannoth94fc5b82021-10-20 07:45:06 +0530241 bool removed; /* Indicates the connection is removed */
242 struct rcu_head rcu; /* delay rcu free */
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530243};
244
245/*
246 * IPv4 connections and hash table size information.
247 */
248#define SFE_IPV4_CONNECTION_HASH_SHIFT 12
249#define SFE_IPV4_CONNECTION_HASH_SIZE (1 << SFE_IPV4_CONNECTION_HASH_SHIFT)
250#define SFE_IPV4_CONNECTION_HASH_MASK (SFE_IPV4_CONNECTION_HASH_SIZE - 1)
251
252enum sfe_ipv4_exception_events {
253 SFE_IPV4_EXCEPTION_EVENT_UDP_HEADER_INCOMPLETE,
254 SFE_IPV4_EXCEPTION_EVENT_UDP_NO_CONNECTION,
255 SFE_IPV4_EXCEPTION_EVENT_UDP_IP_OPTIONS_OR_INITIAL_FRAGMENT,
256 SFE_IPV4_EXCEPTION_EVENT_UDP_SMALL_TTL,
257 SFE_IPV4_EXCEPTION_EVENT_UDP_NEEDS_FRAGMENTATION,
258 SFE_IPV4_EXCEPTION_EVENT_TCP_HEADER_INCOMPLETE,
259 SFE_IPV4_EXCEPTION_EVENT_TCP_NO_CONNECTION_SLOW_FLAGS,
260 SFE_IPV4_EXCEPTION_EVENT_TCP_NO_CONNECTION_FAST_FLAGS,
261 SFE_IPV4_EXCEPTION_EVENT_TCP_IP_OPTIONS_OR_INITIAL_FRAGMENT,
262 SFE_IPV4_EXCEPTION_EVENT_TCP_SMALL_TTL,
263 SFE_IPV4_EXCEPTION_EVENT_TCP_NEEDS_FRAGMENTATION,
264 SFE_IPV4_EXCEPTION_EVENT_TCP_FLAGS,
265 SFE_IPV4_EXCEPTION_EVENT_TCP_SEQ_EXCEEDS_RIGHT_EDGE,
266 SFE_IPV4_EXCEPTION_EVENT_TCP_SMALL_DATA_OFFS,
267 SFE_IPV4_EXCEPTION_EVENT_TCP_BAD_SACK,
268 SFE_IPV4_EXCEPTION_EVENT_TCP_BIG_DATA_OFFS,
269 SFE_IPV4_EXCEPTION_EVENT_TCP_SEQ_BEFORE_LEFT_EDGE,
270 SFE_IPV4_EXCEPTION_EVENT_TCP_ACK_EXCEEDS_RIGHT_EDGE,
271 SFE_IPV4_EXCEPTION_EVENT_TCP_ACK_BEFORE_LEFT_EDGE,
272 SFE_IPV4_EXCEPTION_EVENT_ICMP_HEADER_INCOMPLETE,
273 SFE_IPV4_EXCEPTION_EVENT_ICMP_UNHANDLED_TYPE,
274 SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_HEADER_INCOMPLETE,
275 SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_NON_V4,
276 SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_IP_OPTIONS_INCOMPLETE,
277 SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_UDP_HEADER_INCOMPLETE,
278 SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_TCP_HEADER_INCOMPLETE,
279 SFE_IPV4_EXCEPTION_EVENT_ICMP_IPV4_UNHANDLED_PROTOCOL,
280 SFE_IPV4_EXCEPTION_EVENT_ICMP_NO_CONNECTION,
281 SFE_IPV4_EXCEPTION_EVENT_ICMP_FLUSHED_CONNECTION,
282 SFE_IPV4_EXCEPTION_EVENT_HEADER_INCOMPLETE,
Ratheesh Kannoth43d64f82021-10-20 08:23:29 +0530283 SFE_IPV4_EXCEPTION_EVENT_HEADER_CSUM_BAD,
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530284 SFE_IPV4_EXCEPTION_EVENT_BAD_TOTAL_LENGTH,
285 SFE_IPV4_EXCEPTION_EVENT_NON_V4,
286 SFE_IPV4_EXCEPTION_EVENT_NON_INITIAL_FRAGMENT,
287 SFE_IPV4_EXCEPTION_EVENT_DATAGRAM_INCOMPLETE,
288 SFE_IPV4_EXCEPTION_EVENT_IP_OPTIONS_INCOMPLETE,
289 SFE_IPV4_EXCEPTION_EVENT_UNHANDLED_PROTOCOL,
Guduri Prathyusha5f27e232022-01-06 14:39:04 +0530290 SFE_IPV4_EXCEPTION_EVENT_NO_HEADROOM,
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530291 SFE_IPV4_EXCEPTION_EVENT_INVALID_PPPOE_SESSION,
292 SFE_IPV4_EXCEPTION_EVENT_INCORRECT_PPPOE_PARSING,
293 SFE_IPV4_EXCEPTION_EVENT_PPPOE_NOT_SET_IN_CME,
Wayne Tan1cabbf12022-05-01 13:01:45 -0700294 SFE_IPV4_EXCEPTION_EVENT_PPPOE_BR_NOT_IN_CME,
Wayne Tanbb7f1782021-12-13 11:16:04 -0800295 SFE_IPV4_EXCEPTION_EVENT_INGRESS_VLAN_TAG_MISMATCH,
Ratheesh Kannoth5dee3772022-01-18 11:27:14 +0530296 SFE_IPV4_EXCEPTION_EVENT_INVALID_SRC_IFACE,
Tian Yangd98d91b2022-03-09 14:50:12 -0800297 SFE_IPV4_EXCEPTION_EVENT_TUN6RD_NO_CONNECTION,
298 SFE_IPV4_EXCEPTION_EVENT_TUN6RD_NEEDS_FRAGMENTATION,
299 SFE_IPV4_EXCEPTION_EVENT_TUN6RD_SYNC_ON_FIND,
Nitin Shettye6ed5b52021-12-27 14:50:11 +0530300 SFE_IPV4_EXCEPTION_EVENT_GRE_HEADER_INCOMPLETE,
301 SFE_IPV4_EXCEPTION_EVENT_GRE_NO_CONNECTION,
302 SFE_IPV4_EXCEPTION_EVENT_GRE_IP_OPTIONS_OR_INITIAL_FRAGMENT,
303 SFE_IPV4_EXCEPTION_EVENT_GRE_SMALL_TTL,
304 SFE_IPV4_EXCEPTION_EVENT_GRE_NEEDS_FRAGMENTATION,
Suhas N Bhargav592e64c2021-11-12 16:53:08 +0530305 SFE_IPV4_EXCEPTION_EVENT_ESP_NO_CONNECTION,
306 SFE_IPV4_EXCEPTION_EVENT_ESP_IP_OPTIONS_OR_INITIAL_FRAGMENT,
307 SFE_IPV4_EXCEPTION_EVENT_ESP_NEEDS_FRAGMENTATION,
308 SFE_IPV4_EXCEPTION_EVENT_ESP_SMALL_TTL,
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530309 SFE_IPV4_EXCEPTION_EVENT_LAST
310};
311
312/*
Ratheesh Kannoth3aeb2892021-10-20 07:57:15 +0530313 * per CPU stats
314 */
315struct sfe_ipv4_stats {
316 /*
317 * Stats recorded in a sync period. These stats will be added to
318 * connection_xxx64 after a sync period.
319 */
320 u64 connection_create_requests64;
321 /* Number of IPv4 connection create requests */
322 u64 connection_create_collisions64;
323 /* Number of IPv4 connection create requests that collided with existing hash table entries */
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530324 u64 connection_create_failures64;
325 /* Number of IPv4 connection create requests that failed */
Ratheesh Kannoth3aeb2892021-10-20 07:57:15 +0530326 u64 connection_destroy_requests64;
327 /* Number of IPv4 connection destroy requests */
328 u64 connection_destroy_misses64;
329 /* Number of IPv4 connection destroy requests that missed our hash table */
330 u64 connection_match_hash_hits64;
331 /* Number of IPv4 connection match hash hits */
332 u64 connection_match_hash_reorders64;
333 /* Number of IPv4 connection match hash reorders */
334 u64 connection_flushes64; /* Number of IPv4 connection flushes */
Amitesh Anand63be37d2021-12-24 20:51:48 +0530335 u64 packets_dropped64; /* Number of IPv4 packets dropped */
Ratheesh Kannoth3aeb2892021-10-20 07:57:15 +0530336 u64 packets_forwarded64; /* Number of IPv4 packets forwarded */
Ken Zhu7e38d1a2021-11-30 17:31:46 -0800337 u64 packets_fast_xmited64; /* Number of IPv4 packets fast transmited */
Ratheesh Kannoth3aeb2892021-10-20 07:57:15 +0530338 u64 packets_not_forwarded64; /* Number of IPv4 packets not forwarded */
339 u64 exception_events64[SFE_IPV4_EXCEPTION_EVENT_LAST];
Guduri Prathyusha034d6352022-01-12 16:49:04 +0530340 u64 pppoe_encap_packets_forwarded64; /* Number of IPv4 PPPoE encap packets forwarded */
341 u64 pppoe_decap_packets_forwarded64; /* Number of IPv4 PPPoE decap packets forwarded */
342 u64 pppoe_bridge_packets_forwarded64; /* Number of IPv4 PPPoE bridge packets forwarded */
Wayne Tan1cabbf12022-05-01 13:01:45 -0700343 u64 pppoe_bridge_packets_3tuple_forwarded64; /* Number of IPv4 PPPoE bridge packets forwarded based on 3-tuple info */
Ratheesh Kannoth3aeb2892021-10-20 07:57:15 +0530344};
345
346/*
Parikshit Guned31a8202022-01-05 22:15:04 +0530347 * sfe_ipv4_per_service_class_stats
348 * Per service class stats
349 */
350struct sfe_ipv4_per_service_class_stats {
351 u64 tx_bytes; /* Byte count */
352 u64 tx_packets; /* Packet count */
353 seqcount_t seq; /* seq lock for read/write protection */
354 /*
355 * TODO : add entries to be collected later.
356 */
357};
358
359/*
360 * sfe_ipv4_service_class_stats_db
361 * stat entries for each service class.
362 */
363struct sfe_ipv4_service_class_stats_db {
364 struct sfe_ipv4_per_service_class_stats psc_stats[SFE_MAX_SERVICE_CLASS_ID];
365 /* Per service class stats */
366};
367
368/*
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530369 * Per-module structure.
370 */
371struct sfe_ipv4 {
372 spinlock_t lock; /* Lock for SMP correctness */
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530373 struct sfe_ipv4_connection *all_connections_head;
374 /* Head of the list of all connections */
375 struct sfe_ipv4_connection *all_connections_tail;
376 /* Tail of the list of all connections */
377 unsigned int num_connections; /* Number of connections */
Ken Zhu137722d2021-09-23 17:57:36 -0700378 struct delayed_work sync_dwork; /* Work to sync the statistics */
379 unsigned int work_cpu; /* The core to run stats sync on */
380
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530381 sfe_sync_rule_callback_t __rcu sync_rule_callback;
Ken Zhu7a43d882022-01-04 10:51:44 -0800382 sfe_ipv4_many_sync_callback_t __rcu many_sync_callback;
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530383 /* Callback function registered by a connection manager for stats syncing */
384 struct sfe_ipv4_connection *conn_hash[SFE_IPV4_CONNECTION_HASH_SIZE];
385 /* Connection hash table */
Ratheesh Kannoth94fc5b82021-10-20 07:45:06 +0530386
387 struct hlist_head hlist_conn_match_hash_head[SFE_IPV4_CONNECTION_HASH_SIZE];
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530388 /* Connection match hash table */
Ratheesh Kannoth94fc5b82021-10-20 07:45:06 +0530389
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530390#ifdef CONFIG_NF_FLOW_COOKIE
391 struct sfe_flow_cookie_entry sfe_flow_cookie_table[SFE_FLOW_COOKIE_SIZE];
392 /* flow cookie table*/
393 flow_cookie_set_func_t flow_cookie_set_func;
394 /* function used to configure flow cookie in hardware*/
395 int flow_cookie_enable;
396 /* Enable/disable flow cookie at runtime */
397#endif
Parikshit Guned31a8202022-01-05 22:15:04 +0530398 struct sfe_ipv4_service_class_stats_db __percpu *stats_pcpu_psc;
399 /* Database to maintain per cpu per service class statistics */
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530400
Ratheesh Kannoth3aeb2892021-10-20 07:57:15 +0530401 struct sfe_ipv4_stats __percpu *stats_pcpu;
402 /* Per CPU statistics. */
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530403
Ken Zhudc423672021-09-02 18:27:01 -0700404 struct sfe_ipv4_connection *wc_next; /* Connection list walk pointer for stats sync */
405
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530406 /*
407 * Control state.
408 */
Ratheesh Kannoth6307bec2021-11-25 08:26:39 +0530409 struct kobject *sys_ipv4; /* sysfs linkage */
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530410 int debug_dev; /* Major number of the debug char device */
411 u32 debug_read_seq; /* sequence number for debug dump */
412};
413
414/*
415 * Enumeration of the XML output.
416 */
417enum sfe_ipv4_debug_xml_states {
418 SFE_IPV4_DEBUG_XML_STATE_START,
419 SFE_IPV4_DEBUG_XML_STATE_CONNECTIONS_START,
420 SFE_IPV4_DEBUG_XML_STATE_CONNECTIONS_CONNECTION,
421 SFE_IPV4_DEBUG_XML_STATE_CONNECTIONS_END,
422 SFE_IPV4_DEBUG_XML_STATE_EXCEPTIONS_START,
423 SFE_IPV4_DEBUG_XML_STATE_EXCEPTIONS_EXCEPTION,
424 SFE_IPV4_DEBUG_XML_STATE_EXCEPTIONS_END,
425 SFE_IPV4_DEBUG_XML_STATE_STATS,
426 SFE_IPV4_DEBUG_XML_STATE_END,
427 SFE_IPV4_DEBUG_XML_STATE_DONE
428};
429
430/*
431 * XML write state.
432 */
433struct sfe_ipv4_debug_xml_write_state {
434 enum sfe_ipv4_debug_xml_states state;
435 /* XML output file state machine state */
436 int iter_exception; /* Next exception iterator */
437};
438
439typedef bool (*sfe_ipv4_debug_xml_write_method_t)(struct sfe_ipv4 *si, char *buffer, char *msg, size_t *length,
440 int *total_read, struct sfe_ipv4_debug_xml_write_state *ws);
441
Ratheesh Kannoth6307bec2021-11-25 08:26:39 +0530442u16 sfe_ipv4_gen_ip_csum(struct iphdr *iph);
Jackson Bockus3fafbf32022-02-13 17:15:26 -0800443bool sfe_ipv4_service_class_stats_get(uint8_t sid, uint64_t *bytes, uint64_t *packets);
Parikshit Guned31a8202022-01-05 22:15:04 +0530444void sfe_ipv4_service_class_stats_inc(struct sfe_ipv4 *si, uint8_t sid, uint64_t bytes);
Ratheesh Kannoth6307bec2021-11-25 08:26:39 +0530445void sfe_ipv4_exception_stats_inc(struct sfe_ipv4 *si, enum sfe_ipv4_exception_events reason);
446bool sfe_ipv4_remove_connection(struct sfe_ipv4 *si, struct sfe_ipv4_connection *c);
447void sfe_ipv4_flush_connection(struct sfe_ipv4 *si, struct sfe_ipv4_connection *c, sfe_sync_reason_t reason);
Ken Zhu88c58152021-12-09 15:12:06 -0800448void sfe_ipv4_sync_status(struct sfe_ipv4 *si, struct sfe_ipv4_connection *c, sfe_sync_reason_t reason);
Ratheesh Kannoth6307bec2021-11-25 08:26:39 +0530449
450struct sfe_ipv4_connection_match *
451sfe_ipv4_find_connection_match_rcu(struct sfe_ipv4 *si, struct net_device *dev, u8 protocol,
452 __be32 src_ip, __be16 src_port,
453 __be32 dest_ip, __be16 dest_port);
454
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530455void sfe_ipv4_exit(void);
456int sfe_ipv4_init(void);
Wayne Tanbb7f1782021-12-13 11:16:04 -0800457
458#endif /* __SFE_IPV4_H */