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