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
116
117
|
#ifndef __LTSM_H_
#define __LTSM_H_
#ifdef __cplusplus
extern "C"
{
#endif
/*
LTSM : Light TCP State Machine.
Version : 2018-01-16
*/
/* RFC��TCPЭ��ջ״̬������ */
enum full_tcp_state{
FTSM_VOID, /* ���һ�����ĵ�һ��������SYN��, ���ش�ֵ */
FTSM_SYN_SENT,
FTSM_SYN_RCVD,
FTSM_ESTABLISHED,
FTSM_FIN_WAIT,
FTSM_CLOSE_WAIT,
FTSM_LAST_ACK,
FTSM_TIME_WAIT,
FTSM_CLOSED,
FTSM_LISTEN,
__FTSM_MAX,
};
/*
����TCP״̬������,
ʵ��ֻ������״̬:�½�����, ��������, ��������,
ÿ�����ض�����1��START��1��CLOSE״̬, ���ܰ���0�����ɸ�DATA״̬.
VOID״̬���ڵ����߿����ж��Ƿ���Ҫ��������.
*/
enum light_tcp_state{
LTSM_VOID, /* ���һ�����ĵ�һ��������SYN��, ���ش�ֵ */
LTSM_START,
LTSM_DATA,
LTSM_CLOSE,
};
struct ltsm_iphdr
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int ip_hl:4; /* header length */
unsigned int ip_v:4; /* version */
#endif
#if __BYTE_ORDER == __BIG_ENDIAN
unsigned int ip_v:4; /* version */
unsigned int ip_hl:4; /* header length */
#endif
u_int8_t ip_tos; /* type of service */
u_short ip_len; /* total length */
u_short ip_id; /* identification */
u_short ip_off; /* fragment offset field */
#define IP_RF 0x8000 /* reserved fragment flag */
#define IP_DF 0x4000 /* dont fragment flag */
#define IP_MF 0x2000 /* more fragments flag */
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
u_int8_t ip_ttl; /* time to live */
u_int8_t ip_p; /* protocol */
u_short ip_sum; /* checksum */
struct in_addr ip_src, ip_dst; /* source and dest address */
};
struct ltsm_tcphdr
{
u_int16_t th_sport; /* source port */
u_int16_t th_dport; /* destination port */
u_int32_t th_seq; /* sequence number */
u_int32_t th_ack; /* acknowledgement number */
# if __BYTE_ORDER == __LITTLE_ENDIAN
u_int8_t th_x2:4; /* (unused) */
u_int8_t th_off:4; /* data offset */
# endif
# if __BYTE_ORDER == __BIG_ENDIAN
u_int8_t th_off:4; /* data offset */
u_int8_t th_x2:4; /* (unused) */
# endif
u_int8_t th_flags;
# define TH_FIN 0x01
# define TH_SYN 0x02
# define TH_RST 0x04
# define TH_PUSH 0x08
# define TH_ACK 0x10
# define TH_URG 0x20
u_int16_t th_win; /* window */
u_int16_t th_sum; /* checksum */
u_int16_t th_urp; /* urgent pointer */
};
struct ltsm_result{
enum full_tcp_state fstate;
enum light_tcp_state lstate;
};
typedef void * ltsm_stream_handle;
ltsm_stream_handle ltsm_create_handle(void);
#define LTSM_DIR_C2S 0
#define LTSM_DIR_S2C 1
struct ltsm_result ltsm_get_current_state(ltsm_stream_handle pltsm, uint8_t tcp_flags, uint8_t dir);
const char *ltsm_fstate_ntop(enum full_tcp_state fstate);
const char *ltsm_lstate_ntop(enum light_tcp_state lstate);
void ltsm_destroy_handle(ltsm_stream_handle pltsm);
#ifdef __cplusplus
}
#endif
#endif
|