summaryrefslogtreecommitdiff
path: root/include/private/ip_reassembly.h
blob: 5248177a292a8d5e137412469c77bf3db7d04d10 (plain)
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
118
119
120
121
122
123
124
125
#ifndef _IP_REASSEMBLY_H_
#define _IP_REASSEMBLY_H_

#include "stream_internal.h" 


#define USE_MESA_STREAM_HASH			(1) 
#if USE_MESA_STREAM_HASH
#include "MESA_htable.h"
#endif

#define IP_FRAG_DEFAULT_BUF_SIZE		(2048) 

#define IP_FRAG_OK					(0x00)	
#define IP_FRAG_INVALID_PACKET			(0x10)	
#define IP_FRAG_DISCARD				(0x08)	
#define IP_FRAG_IGNORE					(0x04)	

#define IP_FRAG_FIRST_IN              		(0x02)	
#define IP_FRAG_LAST_IN               		(0x01)	


struct addr_list{
	struct layer_addr addr;
	struct addr_list *next;
};


struct ip_frags{
	int offset;				
	int end;            	
	struct ip_frags *next;	
	struct ip_frags *prev;	
};


struct frag_ipq{
	int buf_size; 		
	short last_in; 		
	short attack_flag;  
	int tot_len; 		
	int meat;			
	unsigned int hash_index; 	
	int hash_key_size;
	int private_len;	
	int frags_num;		
	time_t create_time; 
	void *new_iph; 		
	struct ip_frags *fragments;			
	struct ip_frags *fragments_tail;	
	int frags_len;
#if USE_MESA_STREAM_HASH
	int thread_num;	
#else
	struct frag_ipq *hash_prev;  		
	struct frag_ipq *hash_next;  		
	struct frag_ipq *lru_prev;  		
	struct frag_ipq *lru_next;  		
#endif	
	void *hash_key; 
	void *private_info; 	
	raw_ipfrag_list_t *ipfrag_list; 
};


struct frag_manage{
	int thread_num;					
	unsigned int total_mem;			
#if USE_MESA_STREAM_HASH
	MESA_htable_handle frag_hash_table;
#else
	unsigned int hash_table_size;	
	int __pad__;
	struct frag_ipq **frag_hash_table;					
	unsigned int (*hash_index)(void *hash_key);			
	int (*hash_cmp)(void *hash_key1, void *hash_key2);	
	struct frag_ipq *lru_head;	
	struct frag_ipq *lru_tail;	
#endif	
	int scratch_frag_cnt;
	int scratch_frag_len;
};

#define JHASH_INITVAL        0xdeadbeef
#define JHASH_INITVAL2       0xfeedcade

#ifdef __cplusplus
extern "C" {
#endif

unsigned int frag_common_hash(unsigned int a, unsigned int b, unsigned int c, unsigned int initval) ;

void *frag_malloc(struct frag_manage *handle, int size);
void frag_free(struct frag_manage *handle, void *free_p, int size);
struct ip_frags* frags_create(struct frag_manage *handle, int offset, int end);
void frags_kill(struct frag_manage *handle, struct frag_ipq *ipq, struct ip_frags *frags_del);
struct frag_ipq* frag_ipq_find(struct frag_manage *handle, void *key, int key_size);
#if USE_MESA_STREAM_HASH
struct frag_ipq* frag_ipq_create(int thread_num);
#else
struct frag_ipq* frag_ipq_create(struct frag_manage *handle, void *key, int key_size, unsigned int hash_index);
#endif
void frag_ipq_kill(struct frag_manage *handle, struct frag_ipq *ipq);
void frag_add_lru_node (struct frag_manage *handle, struct frag_ipq *new_node);
void frag_del_lru_node (struct frag_manage *handle, struct frag_ipq *del_node);
void frag_lru_update(struct frag_manage *handle, struct frag_ipq *ipq);
void frag_add_hash_node (struct frag_manage *handle, struct frag_ipq *new_node);
void frag_del_hash_node (struct frag_manage *handle, struct frag_ipq *del_node);
void *frag_reassemble(struct frag_manage *handle, struct frag_ipq *ipq);

int frags_list_append(struct frag_ipq *ipq, const raw_pkt_t *raw_pkt, int type, int tid);
void raw_frags_list_free_global(int tid, int type);
void raw_frags_list_free_stream(int thread_num, struct streaminfo *stream);
raw_ipfrag_list_t *frags_list_merge(raw_ipfrag_list_t *new_merge_list, raw_ipfrag_list_t *old_list);
void __frags_list_check(raw_ipfrag_list_t *frags_list);
int MESA_stream_list_cmp(struct streaminfo_private *stream1, struct streaminfo_private *stream2);
void MESA_stream_list_free(int mem_used_type, struct streaminfo_private *heap_stream);
struct streaminfo_private *MESA_stream_list_dup(int mem_used_type, struct streaminfo_private *stack_stream, int reverse);

#ifdef __cplusplus
}
#endif


#endif