-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtcp_session.h
115 lines (95 loc) · 3.95 KB
/
tcp_session.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/***********************************************************
Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
University
We are making the OpenFlow specification and associated documentation
(Software) available for public use and benefit with the expectation
that others will use, modify and enhance the Software and contribute
those enhancements back to the community. However, since we would
like to make the Software available for broadest use, with as few
restrictions as possible permission is hereby granted, free of charge,
to any person obtaining a copy of this Software to deal in the Software
under the copyrights without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The name and trademarks of copyright holder(s) may NOT be used in
advertising or publicity pertaining to the Software or any derivatives
without specific, written prior permission.
*****************************************************************/
#ifndef TCP_SESSION_H
#define TCP_SESSION_H
#define OFTRACE_DELETE_FLOW -1
#define OFTRACE_OK 0
#define OFTRACE_SKIP_LIMIT 100
#define OFTRACE_QUEUE_LIMIT 200
// hack to get uint32_t etc..
#include "oftrace.h"
typedef struct tcp_frag {
uint32_t start_seq;
uint16_t len;
char data[BUFLEN];
struct tcp_frag * next;
} tcp_frag;
typedef struct tcp_session {
uint32_t sip;
uint32_t dip;
uint16_t sport; // stored in network byte order!
uint16_t dport; // stored in network byte order!
uint32_t seqno; // stored in HOST byte order
uint32_t isn; // stored in HOST byte order (initial seqno)
int n_segs;
int skipped_count;
int close_on_empty;
tcp_frag * next;
} tcp_session;
tcp_session * tcp_session_new(struct oft_iphdr * ip, struct oft_tcphdr * tcp);
/***************************
* find the session matching the passes parameters
* return NULL if not found
*/
tcp_session * tcp_session_find(tcp_session ** sessions, int n_sessions,struct oft_iphdr * ip, struct oft_tcphdr * tcp);
/***************************
* remove the session from the lists of sessions
* and free it's contents
* throw an assert if not found
*/
int tcp_session_delete(tcp_session ** sessions, int * n_sessions, tcp_session * ts);
/****************************
* does this session have at least len contiguous bytes queued?
* if yes, copy them to data, but don't dequeue, return 1
* else return 0
*/
int tcp_session_peek(tcp_session * ts, char * data, int len);
/****************************
* add this fragment to this session
*/
int tcp_session_add_frag(tcp_session * ts, uint32_t seqno, char * data, int cap_len, int full_len);
/****************************
* remove/dequeue len bytes from this session
* return 0 if len continuguous bytes not available
* don't bother copying it, b/c the tcp_session_peek pretty
* much already does that
*/
int tcp_session_pull(tcp_session * ts, int len);
/*************************
* count the number of stored fragments
*/
int tcp_session_count_frags(tcp_session *ts);
/************************
* set close_on_empty flag
*/
int tcp_session_close(tcp_session ** sessions, int * n_sessions,tcp_session *ts);
/*************************
* expose hooks for unittesting
*/
int unittest_do_tcp_session_delete(void);
#endif