1/*
2 **************************************************************************
3 * Copyright (c) 2014-2015, The Linux Foundation.  All rights reserved.
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all copies.
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
13 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 **************************************************************************
15 */
16
17struct ecm_tracker_tcp_instance;
18
19#ifdef ECM_TRACKER_DPI_SUPPORT_ENABLE
20typedef uint32_t (*ecm_tracker_tcp_bytes_avail_get_method_t)(struct ecm_tracker_tcp_instance *tti, ecm_tracker_sender_type_t sender);
21									/* Return number of bytes available to read */
22typedef int (*ecm_tracker_tcp_bytes_read_method_t)(struct ecm_tracker_tcp_instance *tti, ecm_tracker_sender_type_t sender, uint32_t offset, uint32_t size, void *buffer);
23									/* Read a number of bytes */
24typedef void (*ecm_tracker_tcp_bytes_discard_method_t)(struct ecm_tracker_tcp_instance *tti, ecm_tracker_sender_type_t sender, uint32_t n);
25									/* Discard n bytes from the available stream bytes */
26typedef bool (*ecm_tracker_tcp_mss_get_method_t)(struct ecm_tracker_tcp_instance *tti, ecm_tracker_sender_type_t sender, uint16_t *mss);
27									/* Get the MSS as sent BY the given target i.e. the MSS the other party is allowed to send */
28typedef bool (*ecm_tracker_tcp_segment_add_method_t)(struct ecm_tracker_tcp_instance *tti, ecm_tracker_sender_type_t sender,
29								struct ecm_tracker_ip_header *ip_hdr, struct ecm_tracker_ip_protocol_header *ecm_tcp_header, struct tcphdr *tcp_hdr, struct sk_buff *skb);
30									/* Add a pre-checked segment */
31#endif
32
33struct ecm_tracker_tcp_instance {
34	struct ecm_tracker_instance base;				/* MUST BE FIRST FIELD */
35
36#ifdef ECM_TRACKER_DPI_SUPPORT_ENABLE
37	ecm_tracker_tcp_bytes_avail_get_method_t bytes_avail_get;	/* Return number of bytes available to read */
38	ecm_tracker_tcp_bytes_read_method_t bytes_read;			/* Read a number of bytes */
39	ecm_tracker_tcp_bytes_discard_method_t bytes_discard;		/* Discard n number of bytes from the beginning of the stream */
40	ecm_tracker_tcp_mss_get_method_t mss_get;			/* Get the MSS as sent BY the given target i.e. the maximum number of */
41	ecm_tracker_tcp_segment_add_method_t segment_add;		/* Add a prechecked MSS segment */
42#endif
43};
44
45/*
46 * TCP tracker
47 *	Records the two streams of bytes sent in either direction over a TCP connection
48 */
49struct tcphdr *ecm_tracker_tcp_check_header_and_read(struct sk_buff *skb, struct ecm_tracker_ip_header *ip_hdr, struct tcphdr *port_buffer);
50void ecm_tracker_tcp_init(struct ecm_tracker_tcp_instance *tti, int32_t data_limit, uint16_t src_mss_default, uint16_t dest_mss_default);
51struct ecm_tracker_tcp_instance *ecm_tracker_tcp_alloc(void);
52
53#ifdef ECM_TRACKER_DPI_SUPPORT_ENABLE
54/*
55 * TCP Reader
56 *	Faster reading of a stream of bytes.
57 * The stream MUST NOT BE EMPTY and the stream MUST NOT have any data discarded from it for the duration of the reader.
58 * It is fine for additional data to be added to the stream during reader use.
59 * You must operate the reader within the byte space you know to be available for reading.
60 *
61 * When reading blocks of data it is better to use the tracker bytes_read() method instead.
62 */
63struct ecm_tracker_tcp_reader_instance;
64void ecm_tracker_tcp_reader_discard_preceding(struct ecm_tracker_tcp_reader_instance *tri);
65void ecm_tracker_tcp_reader_advance(struct ecm_tracker_tcp_reader_instance *tri, uint32_t advancement);
66void ecm_tracker_tcp_reader_position_set(struct ecm_tracker_tcp_reader_instance *tri, uint32_t offset);
67void ecm_tracker_tcp_reader_init(struct ecm_tracker_tcp_reader_instance *tri, struct ecm_tracker_tcp_instance *tti, ecm_tracker_sender_type_t sender);
68uint8_t ecm_tracker_tcp_reader_fwd_read_u8(struct ecm_tracker_tcp_reader_instance *tri);
69void ecm_tracker_tcp_reader_ref(struct ecm_tracker_tcp_reader_instance *tri);
70int ecm_tracker_tcp_reader_deref(struct ecm_tracker_tcp_reader_instance *tri);
71struct ecm_tracker_tcp_reader_instance *ecm_tracker_tcp_reader_alloc(void);
72uint32_t ecm_tracker_tcp_reader_remain_get(struct ecm_tracker_tcp_reader_instance *tri);
73uint32_t ecm_tracker_tcp_reader_position_get(struct ecm_tracker_tcp_reader_instance *tri);
74void ecm_tracker_tcp_reader_retreat(struct ecm_tracker_tcp_reader_instance *tri, uint32_t retreatment);
75#endif
76
77