Commit 39d20aac authored by 's avatar
Browse files

Added one more argument to COOKING function. This argument allows the users to...

Added one more argument to COOKING function. This argument allows the users to select SERVER_SIDE, CLIENT_SIDE or BOTH_SIDE traffic.



git-svn-id: file:///home/svn/mapi/trunk@565 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 10dfdcc3
......@@ -1828,7 +1828,14 @@ int mapi_loop(int fd, int fid, int cnt, mapi_handler callback){
struct mapipkt* pkt;
int i = 0;
#ifdef DIMAPI
remote_flowdescr_t* flow;
flist_t *fl = remote_flowlist;
#else
flowdescr_t* flow;
flist_t *fl = flowlist;
#endif
if (!minit) {
DEBUG_CMD(printf("Not initialized! [%s:%d]\n",__FILE__,__LINE__));
......@@ -1841,7 +1848,11 @@ int mapi_loop(int fd, int fid, int cnt, mapi_handler callback){
return -1;
}
if ((flow=flist_get(flowlist,fd))==NULL) {
if ((flow=flist_get(fl,fd))==NULL
#ifdef DIMAPI
&& (flow=flist_get(flowlist,fd))==NULL
#endif
) {
DEBUG_CMD(printf("Invalid flow: %d [%s:%d]\n",fd,__FILE__,__LINE__));
local_err = MAPI_INVALID_FLOW;
return -1;
......
......@@ -44,6 +44,12 @@ enum mapi_read_result_method {
MAPI_REF //Return pointer to result
};
enum cooking_direction {
CLIENT_SIDE=1, //client's only data
SERVER_SIDE, //server's only data
BOTH_SIDE //all data
};
typedef enum mapi_offline_device_status {
DEVICE_ONLINE,
DEVICE_SETUP,
......
......@@ -11,6 +11,7 @@
#include <arpa/inet.h>
#include <assert.h>
#include "mapi.h"
#include "debug.h"
#include "mapid.h"
#include "mapidflib.h"
......@@ -53,6 +54,7 @@ static int cook_init(mapidflib_function_instance_t *instance, int fd)
data->threshold = getargint(&fargs);
data->timeout = getargint(&fargs);
data->ret_once = getargint(&fargs);
data->collect = getargint(&fargs);
//check if uncook is applied
functs = flist_get(instance->hwinfo->gflist->fflist, fd);
......@@ -106,6 +108,10 @@ void create_mod_pkt(unsigned char *link_pkt,struct cooking_data *flow,mapid_pkth
tcp_len = tcp->off * 4;
tcp->seq = 0;
if (flow->client_ready && flow->server_ready && flow->collect != BOTH_SIDE) {
DEBUG_CMD(fprintf(stderr, "client and server are ready but we dont collect both [%s:%d]\n", __FILE__, __LINE__));
}
if (flow->client_ready) {
ret_data = flow->ret_client_data;
ret_size = flow->client_size;
......@@ -145,7 +151,7 @@ void create_mod_pkt(unsigned char *link_pkt,struct cooking_data *flow,mapid_pkth
memcpy(link_pkt, flow->mod_pkt, pkt_head->caplen);
flow->cooked = 1;
//fprintf(stderr, "create_mod_pkt: pkt_head->caplen: %d", pkt_head->caplen);
fprintf(stderr, "create_mod_pkt: pkt_head->caplen: %d\n", pkt_head->caplen);
}
void mapi_tcp_callback(struct tcp_stream *ns, MAPI_UNUSED void **param)
......@@ -154,8 +160,22 @@ void mapi_tcp_callback(struct tcp_stream *ns, MAPI_UNUSED void **param)
if (ns->nids_state == NIDS_JUST_EST) {
//fprintf(stderr, "callback: established\n");
ns->server.collect++;
ns->client.collect++;
switch (flow->collect) {
case SERVER_SIDE:
ns->server.collect++;
ns->client.collect--;
break;
case CLIENT_SIDE:
ns->client.collect++;
ns->server.collect--;
break;
case BOTH_SIDE:
ns->server.collect++;
ns->client.collect++;
break;
default:
;
}
return;
}
......@@ -174,6 +194,8 @@ void mapi_tcp_callback(struct tcp_stream *ns, MAPI_UNUSED void **param)
ret_data = &flow->ret_client_data;
ret_size = &flow->client_size;
ready = &flow->client_ready;
if (flow->collect == SERVER_SIDE)
DEBUG_CMD(fprintf(stderr, "Asked for server data but got client's [%s:%d]\n", __FILE__, __LINE__));
}
else {
hlf = &ns->server;
......@@ -181,6 +203,8 @@ void mapi_tcp_callback(struct tcp_stream *ns, MAPI_UNUSED void **param)
ret_data = &flow->ret_server_data;
ret_size = &flow->server_size;
ready = &flow->server_ready;
if (flow->collect == CLIENT_SIDE)
DEBUG_CMD(fprintf(stderr, "Asked for client data but got server's [%s:%d]\n", __FILE__, __LINE__));
}
if (ns->discard) {
......@@ -214,14 +238,14 @@ void mapi_tcp_callback(struct tcp_stream *ns, MAPI_UNUSED void **param)
server_bytes = ns->server.count - ns->server.offset;
client_bytes = ns->client.count - ns->client.offset;
if (server_bytes > 0 && flow->discard) {
if (server_bytes > 0 && flow->collect != CLIENT_SIDE) {
//flow->ret_server_data = malloc(sizeof(unsigned char) * server_bytes);
memcpy(flow->ret_server_data, ns->server.data, flow->threshold);
flow->server_size = server_bytes;
flow->server_ready = 1;
}
if (client_bytes > 0 && flow->discard) {
if (client_bytes > 0 && flow->collect != SERVER_SIDE) {
//flow->ret_client_data = malloc(sizeof(unsigned char) * client_bytes);
memcpy(flow->ret_client_data, ns->client.data, flow->threshold);
flow->client_size = client_bytes;
......@@ -314,6 +338,11 @@ static int cook_process(mapidflib_function_instance_t *instance,MAPI_UNUSED unsi
else
return 0;
}
//new testing
else {
return 0;
}
//new testing
return 1;
}
......@@ -340,7 +369,7 @@ static mapidflib_function_def_t cooking_finfo =
"", //libname
"COOKING", //name
"Cooking TCP/IP packets", //Description
"iii", //argdescr
"iiii", //argdescr
MAPI_DEVICE_ALL, //Devoid
MAPIRES_NONE,
0, //shm size
......
......@@ -13,7 +13,7 @@ struct cooking_data
int threshold;
int timeout;
int ret_once;
int discard;
enum cooking_direction collect;
// int id;
nids_instance_t *ni;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment