Commit efe517aa authored by 's avatar
Browse files

Debuging in cooking function


git-svn-id: file:///home/svn/mapi/trunk@355 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent a47272c4
...@@ -15,6 +15,42 @@ ...@@ -15,6 +15,42 @@
#include "mapidevices.h" #include "mapidevices.h"
#include "debug.h" #include "debug.h"
//Stores information about flows in mapidlib
typedef struct mapidlibflow {
int fd;
// short active;
enum mapi_flow_status status;
short delete;
flist_t *functionlist;
flist_t *procfunctionlist;
mapid_funct_info_t *funct_info_list;
mapid_hw_info_t *hwinfo; //Information about hardware using mapidlib
char devtype[MAPI_STR_LENGTH];
void* adapterinfo; //Pointer to adapter specific information
char *shm; //Pointer to start of shared memory
unsigned long long shm_size; //Size of shared memory
key_t shm_key;
int shm_id;
char shm_fname[MAPI_STR_LENGTH];
time_t start;
time_t end;
int err_no;
#ifdef WITH_MODIFY_PKTS
short modifies; //1 if a function in the flow modifies packets
unsigned char *mod_pkt; //Modified packet
mapid_pkthdr_t mod_pkt_head;
short mod_pkt_init; // 1 if allocated space for current modpkt
#endif
#ifdef WITH_PRIORITIES
int priority;
#endif
} mapidlibflow_t;
#ifdef WITH_MODIFY_PKTS
#define NIC_PKTCAP_LEN 1514
unsigned char modified_packet_buf[NIC_PKTCAP_LEN];
#endif
short libs_loaded=0; //1 if function libraries are loaded short libs_loaded=0; //1 if function libraries are loaded
char *libpath; char *libpath;
...@@ -223,7 +259,12 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) { ...@@ -223,7 +259,12 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) {
//Check to see if other functions references this function //Check to see if other functions references this function
fix_funct_ref(flow->hwinfo->gflist,funct); fix_funct_ref(flow->hwinfo->gflist,funct);
} }
#ifdef WITH_MODIFY_PKTS
if(flow->mod_pkt != NULL && flow->mod_pkt != (unsigned char *)&modified_packet_buf[0]) {
// free(flow->mod_pkt);
}
#endif
lock=&flow->hwinfo->gflist->lock; lock=&flow->hwinfo->gflist->lock;
pthread_spin_lock(lock); pthread_spin_lock(lock);
...@@ -633,7 +674,7 @@ mapid_funct_info_t* mapid_get_flow_functions(mapidlib_instance_t *i,int fd) ...@@ -633,7 +674,7 @@ mapid_funct_info_t* mapid_get_flow_functions(mapidlib_instance_t *i,int fd)
//Finds and identical function that can be used for global optimization //Finds and identical function that can be used for global optimization
static mapidflib_function_instance_t *find_identical_function(mapidlib_instance_t *i,global_function_list_t *gflist, int fd, char *name, char *args, int devid) { static mapidflib_function_instance_t *find_identical_function(MAPI_UNUSED mapidlib_instance_t *i,global_function_list_t *gflist, int fd, char *name, char *args, int devid) {
flist_node_t *flow; flist_node_t *flow;
flist_node_t *fnode,*fnode2; flist_node_t *fnode,*fnode2;
mapidflib_function_t *funct,*funct2; mapidflib_function_t *funct,*funct2;
...@@ -932,15 +973,11 @@ mapid_get_lib_name(int libnumber) ...@@ -932,15 +973,11 @@ mapid_get_lib_name(int libnumber)
return mapidflib_get_lib_name(libnumber); return mapidflib_get_lib_name(libnumber);
} }
#ifdef WITH_MODIFY_PKTS
#define NIC_PKTCAP_LEN 1514
unsigned char modified_packet_buf[NIC_PKTCAP_LEN];
#endif
void mapid_process_pkt(mapidlib_instance_t *i, void mapid_process_pkt(mapidlib_instance_t *i,
const unsigned char* dev_pkt, unsigned char* dev_pkt,
const unsigned char* link_pkt, unsigned char* link_pkt,
mapid_pkthdr_t* pkt_head) mapid_pkthdr_t* pkt_head)
//Process a single packet by applying functions to it //Process a single packet by applying functions to it
//pkt = pointer to packet //pkt = pointer to packet
...@@ -968,24 +1005,22 @@ void mapid_process_pkt(mapidlib_instance_t *i, ...@@ -968,24 +1005,22 @@ void mapid_process_pkt(mapidlib_instance_t *i,
if(flow->status==FLOW_ACTIVE) { if(flow->status==FLOW_ACTIVE) {
#ifdef WITH_MODIFY_PKTS #ifdef WITH_MODIFY_PKTS
flow->decoded_packet=NULL;
flow->client_headers=NULL;
flow->server_headers=NULL;
if(flow->modifies==1) { if(flow->modifies==1) {
if(flow->mod_pkt!=(unsigned char *)(&modified_packet_buf[0])) { if(flow->mod_pkt_init == 0) {
free(flow->mod_pkt); if(flow->mod_pkt != NULL){
flow->mod_pkt=&modified_packet_buf[0]; free(flow->mod_pkt);
flow->mod_pkt = NULL;
}
flow->mod_pkt = malloc(sizeof(char) * flow->hwinfo->cap_length);
flow->mod_pkt_init = 1;
} }
memcpy(modified_packet_buf,link_pkt,pkt_head->caplen);
memcpy(flow->mod_pkt, link_pkt, pkt_head->caplen);
memcpy(&flow->mod_pkt_head,pkt_head,sizeof(mapid_pkthdr_t)); memcpy(&flow->mod_pkt_head,pkt_head,sizeof(mapid_pkthdr_t));
flow->mod_pkt =&modified_packet_buf[0];
if(flow->server_mod_pkt) {
free(flow->server_mod_pkt);
flow->server_mod_pkt=NULL;
}
} }
#endif #endif
n2=flist_head(flow->procfunctionlist); n2=flist_head(flow->procfunctionlist);
ret=1; ret=1;
......
...@@ -84,8 +84,8 @@ int mapid_apply_function(mapidlib_instance_t *i, ...@@ -84,8 +84,8 @@ int mapid_apply_function(mapidlib_instance_t *i,
char* function, char* function,
mapiFunctArg *fargs); mapiFunctArg *fargs);
void mapid_process_pkt(mapidlib_instance_t *i, void mapid_process_pkt(mapidlib_instance_t *i,
const unsigned char* dev_pkt, unsigned char* dev_pkt,
const unsigned char* link_pkt, unsigned char* link_pkt,
mapid_pkthdr_t* pkt_head); mapid_pkthdr_t* pkt_head);
int mapid_get_errno(mapidlib_instance_t *i,int fid); int mapid_get_errno(mapidlib_instance_t *i,int fid);
int mapid_get_devid(mapidlib_instance_t *i,int fd); int mapid_get_devid(mapidlib_instance_t *i,int fd);
...@@ -102,49 +102,4 @@ mapi_function_def_mini_t* mapid_get_function_info(int libnumber,int functionnumb ...@@ -102,49 +102,4 @@ mapi_function_def_mini_t* mapid_get_function_info(int libnumber,int functionnumb
char* mapid_get_lib_name(int libnumber); char* mapid_get_lib_name(int libnumber);
//Stores information about flows in mapidlib
typedef struct mapidlibflow {
int fd;
// short active;
enum mapi_flow_status status;
short delete;
flist_t *functionlist;
flist_t *procfunctionlist;
mapid_funct_info_t *funct_info_list;
mapid_hw_info_t *hwinfo; //Information about hardware using mapidlib
char devtype[MAPI_STR_LENGTH];
void* adapterinfo; //Pointer to adapter specific information
char *shm; //Pointer to start of shared memory
unsigned long long shm_size; //Size of shared memory
key_t shm_key;
int shm_id;
char shm_fname[MAPI_STR_LENGTH];
time_t start;
time_t end;
int err_no;
#ifdef WITH_MODIFY_PKTS
short modifies; //1 if a function in the flow modifies packets
unsigned char *mod_pkt; //Modified packet
unsigned char *server_mod_pkt;
mapid_pkthdr_t mod_pkt_head;
mapid_pkthdr_t server_mod_pkt_head;
flist_t *client_headers;
flist_t *server_headers;
unsigned int client_size;
unsigned int server_size;
flist_t *ret_client_headers;
flist_t *ret_server_headers;
unsigned char* ret_client_data;
unsigned char* ret_server_data;
char uncook_ready;
void *decoded_packet;
#endif
#ifdef WITH_PRIORITIES
int priority;
#endif
} mapidlibflow_t;
#endif #endif
...@@ -141,7 +141,7 @@ process_pkts(void *buf,unsigned len, nic_instance_t *i,MAPI_UNUSED int devid, in ...@@ -141,7 +141,7 @@ process_pkts(void *buf,unsigned len, nic_instance_t *i,MAPI_UNUSED int devid, in
unsigned c = 0; unsigned c = 0;
int rlen = 0; int rlen = 0;
struct pcap_pkthdr *rec; struct pcap_pkthdr *rec;
const unsigned char *packet; unsigned char *packet;
mapid_pkthdr_t mhdr; mapid_pkthdr_t mhdr;
rec = (struct pcap_pkthdr *) buf; rec = (struct pcap_pkthdr *) buf;
...@@ -221,7 +221,7 @@ mapidrv_offline_proc_loop(int devid) ...@@ -221,7 +221,7 @@ mapidrv_offline_proc_loop(int devid)
static void static void
mapidrv_proc_loop (int devid) mapidrv_proc_loop (int devid)
{ {
const u_char *packet; u_char *packet;
struct pcap_pkthdr phdr; struct pcap_pkthdr phdr;
mapid_pkthdr_t mhdr; mapid_pkthdr_t mhdr;
nic_instance_t *i=flist_get(devlist,devid); nic_instance_t *i=flist_get(devlist,devid);
...@@ -239,7 +239,7 @@ mapidrv_proc_loop (int devid) ...@@ -239,7 +239,7 @@ mapidrv_proc_loop (int devid)
while (1) while (1)
{ {
while( (packet = pcap_next(i->pcap,&phdr)) == NULL ); while( (packet = (u_char *)pcap_next(i->pcap,&phdr)) == NULL );
// Transform header // Transform header
// This is only for backward compatibility // This is only for backward compatibility
......
...@@ -32,8 +32,8 @@ static int binop_init(mapidflib_function_instance_t *instance, ...@@ -32,8 +32,8 @@ static int binop_init(mapidflib_function_instance_t *instance,
} }
static int binop_process_add(mapidflib_function_instance_t *instance, static int binop_process_add(mapidflib_function_instance_t *instance,
MAPI_UNUSED const unsigned char* dev_pkt, MAPI_UNUSED unsigned char* dev_pkt,
MAPI_UNUSED const unsigned char* link_pkt, MAPI_UNUSED unsigned char* link_pkt,
MAPI_UNUSED mapid_pkthdr_t* pkt_head) MAPI_UNUSED mapid_pkthdr_t* pkt_head)
{ {
unsigned long long *res,*left,*right; unsigned long long *res,*left,*right;
...@@ -49,8 +49,8 @@ static int binop_process_add(mapidflib_function_instance_t *instance, ...@@ -49,8 +49,8 @@ static int binop_process_add(mapidflib_function_instance_t *instance,
} }
static int binop_process_sub(mapidflib_function_instance_t *instance, static int binop_process_sub(mapidflib_function_instance_t *instance,
MAPI_UNUSED const unsigned char* dev_pkt, MAPI_UNUSED unsigned char* dev_pkt,
MAPI_UNUSED const unsigned char* link_pkt, MAPI_UNUSED unsigned char* link_pkt,
MAPI_UNUSED mapid_pkthdr_t* pkt_head) MAPI_UNUSED mapid_pkthdr_t* pkt_head)
{ {
unsigned long long *res,*left,*right; unsigned long long *res,*left,*right;
......
...@@ -62,8 +62,8 @@ static int bpf_init(mapidflib_function_instance_t *instance, ...@@ -62,8 +62,8 @@ static int bpf_init(mapidflib_function_instance_t *instance,
} }
static int bpf_process(mapidflib_function_instance_t *instance, static int bpf_process(mapidflib_function_instance_t *instance,
MAPI_UNUSED const unsigned char* dev_pkt, MAPI_UNUSED unsigned char* dev_pkt,
const unsigned char* link_pkt, unsigned char* link_pkt,
mapid_pkthdr_t* pkt_head) mapid_pkthdr_t* pkt_head)
{ {
return bpf_filter(((struct bpf_program)((struct bpf_filter*)instance->internal_data)->compiled).bf_insns, (unsigned char *)link_pkt,pkt_head->caplen,pkt_head->wlen); return bpf_filter(((struct bpf_program)((struct bpf_filter*)instance->internal_data)->compiled).bf_insns, (unsigned char *)link_pkt,pkt_head->caplen,pkt_head->wlen);
......
...@@ -93,8 +93,8 @@ static int bucket_init(mapidflib_function_instance_t *instance, ...@@ -93,8 +93,8 @@ static int bucket_init(mapidflib_function_instance_t *instance,
} }
static int bucket_process(mapidflib_function_instance_t *instance, static int bucket_process(mapidflib_function_instance_t *instance,
MAPI_UNUSED const unsigned char* dev_pkt, MAPI_UNUSED unsigned char* dev_pkt,
MAPI_UNUSED const unsigned char* link_pkt, MAPI_UNUSED unsigned char* link_pkt,
mapid_pkthdr_t* pkt_head) mapid_pkthdr_t* pkt_head)
{ {
struct bucket_function_data* fdata; struct bucket_function_data* fdata;
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "fhelp.h" #include "fhelp.h"
static int bytec_process(mapidflib_function_instance_t *instance, static int bytec_process(mapidflib_function_instance_t *instance,
MAPI_UNUSED const unsigned char* dev_pkt, MAPI_UNUSED unsigned char* dev_pkt,
MAPI_UNUSED const unsigned char* link_pkt, MAPI_UNUSED unsigned char* link_pkt,
mapid_pkthdr_t* pkt_head) mapid_pkthdr_t* pkt_head)
{ {
unsigned long long *counter; unsigned long long *counter;
......
...@@ -41,47 +41,29 @@ unsigned char *last_dev_pkt; ...@@ -41,47 +41,29 @@ unsigned char *last_dev_pkt;
static int cooking_id=0; static int cooking_id=0;
extern struct tcp_stream *find_stream(struct tcphdr * this_tcphdr, struct ip * this_iphdr,int *from_client,int id); extern struct tcp_stream *find_stream(struct tcphdr * this_tcphdr, struct ip * this_iphdr,int *from_client,int id);
void create_mod_pkt(unsigned char *dev_pkt,struct mapidlibflow *flow,mapid_pkthdr_t *pkt_head); void create_mod_pkt(unsigned char *dev_pkt,struct cooking_data *flow,mapid_pkthdr_t *pkt_head);
//void process_flushed_data(struct mapidlibflow *flow); //void process_flushed_data(struct mapidlibflow *flow);
void tcp_callback(struct tcp_stream *ns, void **param); void tcp_callback(struct tcp_stream *ns, void **param);
static int cook_instance(mapidflib_function_instance_t* instance,MAPI_UNUSED int fd, mapidflib_flow_mod_t *flow_mod) static int cook_instance(mapidflib_function_instance_t* instance,MAPI_UNUSED int fd, MAPI_UNUSED mapidflib_flow_mod_t *flow_mod)
{ {
flist_node_t *n; struct cooking_data* data = NULL;
struct mapidlibflow *flow=NULL;
mapidlib_instance_t *i;
struct cooking_data* data;
/*
i = flow_mod->mi;
n = flist_head(i->flowlist);
while(n)
{
flow = flist_data(n);
if(flow->fd == instance->fd)
{
break;
}
n = flist_next(n);
} */
data= (struct cooking_data*)malloc(sizeof(struct cooking_data)); data = (struct cooking_data*)malloc(sizeof(struct cooking_data));
data->flow=flow; memset(data, 0, sizeof(struct cooking_data));
instance->internal_data=data; instance->internal_data=data;
return 0; return 0;
} }
void create_mod_pkt(unsigned char *dev_pkt,struct mapidlibflow *flow,mapid_pkthdr_t *pkt_head) { void create_mod_pkt(unsigned char *dev_pkt,struct cooking_data *flow,mapid_pkthdr_t *pkt_head) {
ether_header* eth = NULL; ether_header* eth = NULL;
ip_header* ip = NULL; ip_header* ip = NULL;
tcp_header* tcp = NULL; tcp_header* tcp = NULL;
int ether_len = 0, ip_len = 0, tcp_len = 0; int ether_len = 0, ip_len = 0, tcp_len = 0;
eth = (ether_header*)dev_pkt; eth = (ether_header*)dev_pkt;
ether_len = sizeof(ether_header); ether_len = sizeof(ether_header);
ip = (ip_header*)(dev_pkt + ether_len); ip = (ip_header*)(dev_pkt + ether_len);
...@@ -92,8 +74,17 @@ void create_mod_pkt(unsigned char *dev_pkt,struct mapidlibflow *flow,mapid_pkthd ...@@ -92,8 +74,17 @@ void create_mod_pkt(unsigned char *dev_pkt,struct mapidlibflow *flow,mapid_pkthd
tcp->seq = 0; tcp->seq = 0;
ip->tlen = ntohs(flow->client_size + ip_len + tcp_len); ip->tlen = ntohs(flow->client_size + ip_len + tcp_len);
flow->mod_pkt = malloc(sizeof(char) * (flow->client_size + ether_len + ip_len + tcp_len)); printf("flow->mod_pkt_size %d addition %d\n", flow->mod_pkt_size , (sizeof(char) * (flow->client_size +ether_len + ip_len + tcp_len)));
if(flow->mod_pkt == NULL) {
flow->mod_pkt = malloc(sizeof(char) * (flow->client_size + ether_len + ip_len + tcp_len));
flow->mod_pkt_size = (sizeof(char) * (flow->client_size + ether_len + ip_len + tcp_len));
}
else if(flow->mod_pkt_size < (sizeof(char)*(flow->client_size + ether_len + ip_len + tcp_len))) {
flow->mod_pkt = realloc(flow->mod_pkt,(sizeof(char)*(flow->client_size + ether_len + ip_len + tcp_len)));
flow->mod_pkt_size = (sizeof(char) * (flow->client_size + ether_len + ip_len + tcp_len));
}
memset(flow->mod_pkt, 0, (sizeof(char) * (flow->client_size + ether_len + ip_len + tcp_len)));
assert(flow->mod_pkt!=NULL); assert(flow->mod_pkt!=NULL);
memcpy(flow->mod_pkt, eth, ether_len); memcpy(flow->mod_pkt, eth, ether_len);
memcpy(&flow->mod_pkt[ether_len], ip, ip_len); memcpy(&flow->mod_pkt[ether_len], ip, ip_len);
...@@ -122,7 +113,7 @@ void create_mod_pkt(unsigned char *dev_pkt,struct mapidlibflow *flow,mapid_pkthd ...@@ -122,7 +113,7 @@ void create_mod_pkt(unsigned char *dev_pkt,struct mapidlibflow *flow,mapid_pkthd
void tcp_callback(struct tcp_stream *ns, MAPI_UNUSED void **param) void tcp_callback(struct tcp_stream *ns, MAPI_UNUSED void **param)
{ {
struct mapidlibflow *flow; struct cooking_data *flow;
flow=ns->flow; flow=ns->flow;
...@@ -177,8 +168,8 @@ void tcp_callback(struct tcp_stream *ns, MAPI_UNUSED void **param) ...@@ -177,8 +168,8 @@ void tcp_callback(struct tcp_stream *ns, MAPI_UNUSED void **param)
flow->ret_client_headers = ns->client.headers; flow->ret_client_headers = ns->client.headers;
flow->ret_server_headers = ns->server.headers; flow->ret_server_headers = ns->server.headers;
flow=(struct mapidlibflow *)(ns->flow); flow=(struct cooking_data *)(ns->flow);
create_mod_pkt(last_dev_pkt,flow,&flow->mod_pkt_head); create_mod_pkt(last_dev_pkt,flow,flow->mod_pkt_head);
//process_flushed_data(flow); //process_flushed_data(flow);
return; return;
} }
...@@ -353,6 +344,8 @@ static int cook_init(mapidflib_function_instance_t *instance,MAPI_UNUSED int fd) ...@@ -353,6 +344,8 @@ static int cook_init(mapidflib_function_instance_t *instance,MAPI_UNUSED int fd)
data->timeout=getargint(&fargs); data->timeout=getargint(&fargs);
data->id=cooking_id; data->id=cooking_id;
cooking_id++; cooking_id++;
instance->hwinfo->cap_length = data->threshold + 1000; // adding 1000 in order to avoid overflowing the buffer
desc.fd = 1; desc.fd = 1;
desc.linktype = instance->hwinfo->link_type; desc.linktype = instance->hwinfo->link_type;
...@@ -376,22 +369,20 @@ static int cook_init(mapidflib_function_instance_t *instance,MAPI_UNUSED int fd) ...@@ -376,22 +369,20 @@ static int cook_init(mapidflib_function_instance_t *instance,MAPI_UNUSED int fd)
// return 1 in order for processing to continue in other functions // return 1 in order for processing to continue in other functions
// return 0 not to // return 0 not to
static int cook_process(mapidflib_function_instance_t *instance,MAPI_UNUSED const unsigned char* dev_pkt,const unsigned char* link_pkt, mapid_pkthdr_t* pkt_head) static int cook_process(mapidflib_function_instance_t *instance,MAPI_UNUSED unsigned char* dev_pkt,unsigned char* link_pkt, mapid_pkthdr_t* pkt_head)
{ {
struct pcap_pkthdr h; struct pcap_pkthdr h;
ether_header* eth = NULL; ether_header* eth = NULL;
struct ip *iph; struct ip *iph = NULL;
struct tcphdr *tcph; struct tcphdr *tcph = NULL;
int ether_len = 0, ip_len = 0; int ether_len = 0, ip_len = 0;
struct mapidlibflow *flow; struct cooking_data* flow=NULL;
struct cooking_data* data; struct headers_data *headers = NULL;
struct headers_data *headers;
data= (struct cooking_data*)(instance->internal_data); flow = (struct cooking_data*)(instance->internal_data);
threshold = data->threshold; threshold = flow->threshold;
timeout = data->timeout; timeout = flow->timeout;
flow=data->flow;
//fprintf(stderr,"I am COOKING\n"); //fprintf(stderr,"I am COOKING\n");
...@@ -408,6 +399,7 @@ static int cook_process(mapidflib_function_instance_t *instance,MAPI_UNUSED cons ...@@ -408,6 +399,7 @@ static int cook_process(mapidflib_function_instance_t *instance,MAPI_UNUSED cons
flow->ret_client_data = NULL; flow->ret_client_data = NULL;
flow->ret_server_data = NULL; flow->ret_server_data = NULL;
flow->client_size=flow->server_size=0; flow->client_size=flow->server_size=0;
flow->decoded_packet = NULL;
eth = (ether_header*)link_pkt; eth = (ether_header*)link_pkt;
ether_len = sizeof(ether_header); ether_len = sizeof(ether_header);
...@@ -417,19 +409,19 @@ static int cook_process(mapidflib_function_instance_t *instance,MAPI_UNUSED cons ...@@ -417,19 +409,19 @@ static int cook_process(mapidflib_function_instance_t *instance,MAPI_UNUSED cons
return 1; return 1;
//printf("i got a packet %d\n",data->id); //printf("i got a packet %d\n",data->id);
nids_mapi_next(&h, (unsigned char *)link_pkt,data->id); nids_mapi_next(&h, (unsigned char *)link_pkt,flow->id);
if(status == NON_CHECKED) if(status == NON_CHECKED)
{ {
//fprintf(stderr,"\tnon check report\n"); fprintf(stderr,"\tnon check report\n");
struct tcp_stream *stream; struct tcp_stream *stream;
int from_client; int from_client;
tcph = (struct tcphdr *)(link_pkt + ether_len + ip_len); tcph = (struct tcphdr *)(link_pkt + ether_len + ip_len);
stream= find_stream(tcph,iph,&from_client,data->id); stream= find_stream(tcph,iph,&from_client,flow->id);
if(stream) { if(stream) {
//fprintf(stderr,"\tStream found\n"); fprintf(stderr,"\tStream found\n");
headers = malloc(sizeof(struct headers_data)); headers = malloc(sizeof(struct headers_data));
headers->header = malloc(pkt_head->caplen); //added 100 more bytes headers->header = malloc(pkt_head->caplen); //added 100 more bytes
memcpy(headers->header,link_pkt,pkt_head->caplen); memcpy(headers->header,link_pkt,pkt_head->caplen);
...@@ -454,19 +446,29 @@ static int cook_process(mapidflib_function_instance_t *instance,MAPI_UNUSED cons ...@@ -454,19 +446,29 @@ static int cook_process(mapidflib_function_instance_t *instance,MAPI_UNUSED cons
stream->flow=(void *)flow; stream->flow=(void *)flow;
} }
else { //unsolicited data else { // unsolicited data
//fprintf(stderr,"Stream not found\n"); fprintf(stderr,"Stream not found\n");
return 1; return 1;
} }
printf("here come a packet 1\n");
return 0; return 0;
} }
else { else {
struct tcp_stream *stream; struct tcp_stream *stream;
int from_client; int from_client;
//fprintf(stderr,"\tcheck report %d\n",flow->client_size); fprintf(stderr,"\tcheck report %d caplen %d\n",flow->client_size, pkt_head->caplen);
tcph = (struct tcphdr *)(link_pkt + ether_len + ip_len); tcph = (struct tcphdr *)(link_pkt + ether_len + ip_len);
if(headers != NULL) {
if(headers->header != NULL) {
free(headers->header);
headers->header = NULL;
}
free(headers);
headers = NULL;
}
headers = malloc(sizeof(struct headers_data)); headers = malloc(sizeof(struct headers_data));
headers->header = malloc(pkt_head->caplen); headers->header = malloc(pkt_head->caplen);
memcpy(headers->header, link_pkt,pkt_head->caplen); memcpy(headers->header, link_pkt,pkt_head->caplen);
...@@ -475,11 +477,12 @@ static int cook_process(mapidflib_function_instance_t *instance,MAPI_UNUSED cons ...@@ -475,11 +477,12 @@ static int cook_process(mapidflib_function_instance_t *instance,MAPI_UNUSED cons
headers->ts.tv_sec = pkt_head->ts; //XXX headers->ts.tv_sec = pkt_head->ts; //XXX
headers->ts.tv_usec = pkt_head->ts; headers->ts.tv_usec = pkt_head->ts;
stream= find_stream(tcph,iph,&from_client,data->id); stream= find_stream(tcph,iph,&from_client,flow->id);
if(stream==NULL) { if(stream==NULL) {
//fprintf(stderr,"\tNULL stream %d %d\n",headers->ts.tv_sec,headers->ts.tv_usec);