cooking.c 2.91 KB
Newer Older
Arne Øslebø's avatar
Arne Øslebø committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <pcap.h>
#include <sys/shm.h>
#include <netinet/in.h>

#include "mapid.h"
#include "mapidflib.h"
#include "mapidlib.h"
#include "mapidevices.h"
#include "fhelp.h"
#include "cooking.h"
#include "list.h"
's avatar
committed
17
18
19
20
#include "pcapio.h"
#include "libnids/nids.h"

#define int_ntoa(x) inet_ntoa(*((struct in_addr *)&x))
Arne Øslebø's avatar
Arne Øslebø committed
21
22
23
24
25
26

#define COOKING "COOKING"
#define SERVER 0
#define CLIENT 1
#define FRAG_BUF_SIZE 16*1024

's avatar
committed
27
28
#define CHECKED 15
#define NON_CHECKED 16
Arne Øslebø's avatar
Arne Øslebø committed
29

's avatar
committed
30
31
32
static int threshold = 0;
static unsigned int timeout = 0;
unsigned int client_size = 0,server_size=0;
Arne Øslebø's avatar
Arne Øslebø committed
33

's avatar
committed
34
struct mapidlibflow *mod_flow = NULL;
Arne Øslebø's avatar
Arne Øslebø committed
35

's avatar
committed
36
37
38
39
char* ret_client_data = NULL;
char* ret_server_data = NULL;
char* to_free = NULL;
char* to_free2 = NULL;
Arne Øslebø's avatar
Arne Øslebø committed
40

's avatar
committed
41
42
flist_t *ret_client_headers = NULL;
flist_t *ret_server_headers = NULL;
Arne Øslebø's avatar
Arne Øslebø committed
43

's avatar
committed
44
45
46
struct headers_data *headers = NULL;
char *precooked_data = NULL;
extern struct pcap_pkthdr *nids_last_pcap_header;
Arne Øslebø's avatar
Arne Øslebø committed
47

's avatar
committed
48
mapid_pkthdr_t *last_mapid_header;
Arne Øslebø's avatar
Arne Øslebø committed
49

's avatar
committed
50
int status;
Arne Øslebø's avatar
Arne Øslebø committed
51

's avatar
committed
52
53
int cooked_pkts = 0;
int un_cooked_pkts = 0;
Arne Øslebø's avatar
Arne Øslebø committed
54

's avatar
committed
55
static int cook_instance(mapidflib_function_instance_t* instance, flist_t *flist, mapidflib_flow_mod_t *flow_mod,function_manipulation_t* manip)
Arne Øslebø's avatar
Arne Øslebø committed
56
57
58
59
{
	return 0;
}

's avatar
committed
60
void tcp_callback(struct tcp_stream *ns, void **param)
Arne Øslebø's avatar
Arne Øslebø committed
61
62
63
{
}

's avatar
committed
64
65
static int cook_init(mapidflib_function_instance_t *instance,
		     flist_t *flist)
Arne Øslebø's avatar
Arne Øslebø committed
66
{
's avatar
committed
67
68
69
	struct cooking_data* data = (struct cooking_data*)malloc(sizeof(struct cooking_data));
	mapiFunctArg* fargs;
	struct pcap desc;
Arne Øslebø's avatar
Arne Øslebø committed
70

's avatar
committed
71
72
73
74
75
76
77
	fargs=instance->args;
	data->threshold=getargint(&fargs);
	data->timeout=getargint(&fargs);
	
	desc.fd = 1;
	desc.linktype = instance->hwinfo->link_type;
	desc.bufsize = instance->hwinfo->cap_length;
Arne Øslebø's avatar
Arne Øslebø committed
78

's avatar
committed
79
	nids_mapi_init(&desc, instance->hwinfo->link_type);
Arne Øslebø's avatar
Arne Øslebø committed
80

's avatar
committed
81
	nids_register_tcp(tcp_callback);
Arne Øslebø's avatar
Arne Øslebø committed
82

's avatar
committed
83
	if(data->threshold <= 0)
Arne Øslebø's avatar
Arne Øslebø committed
84
	{
's avatar
committed
85
		data->threshold = -1;
Arne Øslebø's avatar
Arne Øslebø committed
86
87
	}

's avatar
committed
88
89
	instance->internal_data=(void *)data;
	
Arne Øslebø's avatar
Arne Øslebø committed
90
91
92
93
94
	return 0;
}

//////////////////////////////////////////////

's avatar
committed
95
96
// return 1 in order for processing to continue in other functions
// return 0 not to
Arne Øslebø's avatar
Arne Øslebø committed
97

's avatar
committed
98
static int cook_process(mapidflib_function_instance_t *instance,unsigned char* dev_pkt, unsigned char* link_pkt, mapid_pkthdr_t* pkt_head)
Arne Øslebø's avatar
Arne Øslebø committed
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
126
127
128
129
130
131
132
133
134
135
136
137
138
{

}

//////////////////////////////////////////////

static int cook_cleanup(mapidflib_function_instance_t *instance)
{
}

//////////////////////////////////////////////

static mapidflib_function_def_t finfo =
{
	"", //libname
	COOKING, //name
	"Cooking TCP/IP packets\nParameters:\n\tthreshold : int\n\ttimeout : int\n", //Description
	"ii", //argdescr
	MAPI_DEVICE_ALL, //Devoid
	MAPIRES_NONE,
	0, //shm size
	1, //modifies_pkts
	cook_instance, //instance
	cook_init, //init
	cook_process, //process
	NULL, //get_result,
	NULL, //change_args
	NULL, //reset
	cook_cleanup, //cleanup
	NULL, //client_init
	NULL, //client_read_result
	NULL  //client_cleanup
};

mapidflib_function_def_t* cooking_get_funct_info();

mapidflib_function_def_t* cooking_get_funct_info()
{
	return &finfo;
};