Commit f571ea21 authored by 's avatar
Browse files

Veien mot 1.0


git-svn-id: file:///home/svn/mapi/trunk@62 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 2e80909b
......@@ -49,7 +49,7 @@ mapi_errors.h: errors.mapi
cat errors.mapi|grep -v "#" > mapi_errors.dat
cat errors.mapi|grep "#" > mapi_errors.h
mapi.so: mapi.o mapiipc.o mapilibhandler.o fhelp.o flist.o parseconf.o mapipktdecoder.o
mapi.so: mapi.o mapiipc.o mapilibhandler.o fhelp.o flist.o slist.o parseconf.o mapipktdecoder.o
$(CC) -shared -o $@ $^ -ldl $(KEYNOTE_LDADD) -lpthread
mapierror.o: mapierror.c mapi.h mapi_errors.h
......@@ -58,16 +58,16 @@ mapierror.o: mapierror.c mapi.h mapi_errors.h
mapilibhandler.o: mapilibhandler.c mapilibhandler.h
$(CC) $(CFLAGS) -c $<
mapidlib.o: mapidlib.c flist.h mapidlib.h mapid.h mapidrv.h mapi.h mapi_errors.h mstring.h mapilibhandler.h mapidflib.h
mapidlib.o: mapidlib.c slist.h flist.h mapidlib.h mapid.h mapidrv.h mapi.h mapi_errors.h mstring.h mapilibhandler.h mapidflib.h
$(CC) $(CFLAGS) -fPIC -c $<
mapid.o: mapid.c mapid.h mapiipc.h mapi.h mapi_errors.h $(ADMCTRLCL_HEADERS) $(RESCTRL_HEADERS)
$(CC) $(CFLAGS) $(ADMCTRLCL_CFLAGS) $(RESCTRL_CFLAGS) -c $<
mapid: mapid.o mapiipc.o mapierror.o mstring.o flist.o parseconf.o $(ADMCTRLCL_OBJS) $(RESCTRL_OBJS)
mapid: mapid.o mapiipc.o mapierror.o mstring.o slist.o flist.o parseconf.o $(ADMCTRLCL_OBJS) $(RESCTRL_OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LIB_DIR) -lpcap -lpthread -ldl $(ADMCTRLCL_LDFLAGS) $(ADMCTRLCL_LDADD) $(RESCTRL_LDFLAGS) $(RESCTRL_LDADD)
fhelp.o: fhelp.c mapi.h fhelp.h
fhelp.o: fhelp.c mapi.h fhelp.h mapid.c
$(CC) $(CFLAGS) -c $<
flist.o: flist.c flist.h
......@@ -153,7 +153,6 @@ install: all
$(INSTALL) mapid $(INSTALL_BINDIR)
sh ./gen-mapi-conf -c $(WITH_COMBO6) -d $(WITH_DAG) -i $(WITH_IPFIX) \
-e $(WITH_ETHEREAL) -l $(INSTALL_LIBDIR) mapi.conf.in mapi.conf
$(INSTALL) mapi.conf /etc
./$(MKINSTALLDIRS) $(INSTALL_INCDIR)
$(INSTALL) mapi.h $(INSTALL_INCDIR)
$(INSTALL) mapi_errors.h $(INSTALL_INCDIR)
......
......@@ -72,6 +72,8 @@ endif
INSTALL=install
MKINSTALLDIRS=mkinstalldirs
# -Wno-pointer-sign shuts up "pointer targets differ in signedness", which gcc-4.0 produces
# en masse
C_WARNINGS=-Wall -Wsign-compare -Wpointer-arith -Wnested-externs \
-Wmissing-declarations -Wcast-align -Wchar-subscripts
C_FEATURES=-D_GNU_SOURCE -D_THREAD_SAFE
......
......@@ -10,13 +10,13 @@
#include "mapid.h"
#include "fhelp.h"
typedef struct interface_instance {
typedef struct interface_instance_type {
int ifindex;
} interface_instance_t;
static int interface_instance(mapidflib_function_instance_t *instance,
flist_t *flist,
mapidflib_flow_mod_t *flow_mod)
mapidflib_flow_mod_t *flow_mod, function_manipulation_t* manip)
{
mapiFunctArg* a=instance->args;
int ifindex = getargint(&a);
......
......@@ -25,7 +25,7 @@ typedef struct erf_instance {
static int to_erf_instance(mapidflib_function_instance_t *instance,
flist_t *flist,
mapidflib_flow_mod_t *flow_mod)
mapidflib_flow_mod_t *flow_mod, function_manipulation_t* manip)
{
mapiFunctArg* a=instance->args;
int type = getargint(&a);
......@@ -72,7 +72,7 @@ static int to_erf_process(mapidflib_function_instance_t *instance,
int *res=instance->result.data;
dag_record_t *rec=(dag_record_t*)dev_pkt;
if(i->pkts>i->maxpkts && i->maxpkts!=0) {
if(i->pkts >= i->maxpkts && i->maxpkts!=0) {
*res=0;
return 1;
}
......
......@@ -47,7 +47,9 @@
#define MAPID_NO_DRIVER 3200
3200 = "No driver found for this device"
#define MAPID_NO_FD 3201
3200 = "Could not receive file descriptor"
3201 = "Could not receive file descriptor"
#define MAPID_NO_DEVICE 3202
3202 = "No such device"
#define MDLIB_ETH_DLINK_ERR 3500
3500 = "Error Loading lib_ethereal shared library"
#define MDLIB_ETH_SYM_NOT_FOUND 3501
......@@ -108,6 +110,8 @@
7008 = "Semaphore error"
#define MFUNCT_NOT_SUPPORTED 7009
7009 = "Not supported"
#define MFUNCT_INVALID_ARGUMENT_DESCRIPTOR 7010
7010 = "Invalid argument descriptor"
#define ADMCTRL_MEM_ERROR 8000
8000 = "Admission control memory allocation error"
#define ADMCTRL_NO_AUTHDATA 8001
......
......@@ -17,7 +17,7 @@
static int ethereal_instance(mapidflib_function_instance_t *instance,
flist_t *flist,
mapidflib_flow_mod_t *flow_mod)
mapidflib_flow_mod_t *flow_mod, function_manipulation_t* manip)
{
//TODO: verify arguments
return 0;
......@@ -91,6 +91,7 @@ static int ethereal_process(mapidflib_function_instance_t *instance,
ethereal_check=dlsym(mbuf->dll,"ethereal_check");
res = ethereal_check(&(mbuf->session),phdr,pkt);
free(phdr);
if(res==1) /* packet passed filter */
{
return 1; //ok
......
......@@ -17,7 +17,7 @@
static int ethereal_reti_instance(mapidflib_function_instance_t *instance,
flist_t *flist,
mapidflib_flow_mod_t *flow_mod)
mapidflib_flow_mod_t *flow_mod, function_manipulation_t* manip)
{
//TODO: verify arguments
return 0;
......@@ -94,8 +94,8 @@ static int ethereal_reti_process(mapidflib_function_instance_t *instance,
res = ethereal_reti_check(&(mbuf->session),phdr,pkt);
//printf("CP20\n");
mbuf->result=res;
if(res!=NULL) /* packet passed filter */
free(phdr);
if((void*)res!=NULL) /* packet passed filter */
{
return 1; //ok
}
......
......@@ -17,7 +17,7 @@
static int ethereal_rets_instance(mapidflib_function_instance_t *instance,
flist_t *flist,
mapidflib_flow_mod_t *flow_mod)
mapidflib_flow_mod_t *flow_mod, function_manipulation_t* manip)
{
//TODO: verify arguments
return 0;
......@@ -79,9 +79,8 @@ static int ethereal_rets_process(mapidflib_function_instance_t *instance,
//printf("\nProcessing\n");
char* res;
struct ethereal_rets_data* mbuf=instance->result.data;
int (*ethereal_rets_check)(struct ethereal_rets_ses* session, const struct pcap_pkthdr *phdr, const char *pd);
char* (*ethereal_rets_check)(struct ethereal_rets_ses* session, const struct pcap_pkthdr *phdr, const char *pd);
struct pcap_pkthdr *phdr;
int trunk = 0;
/* recreate pcap header */
phdr=malloc(sizeof(struct pcap_pkthdr));
phdr->caplen=pkt_head->caplen;
......@@ -92,7 +91,7 @@ static int ethereal_rets_process(mapidflib_function_instance_t *instance,
if(pkt==NULL) return 0; /* invalid packet */
ethereal_rets_check=dlsym(mbuf->dll,"ethereal_rets_check");
//printf("CP10\n");
res = ethereal_rets_check(&(mbuf->session),phdr,pkt);
res = ethereal_rets_check(&(mbuf->session),phdr,pkt);
if(res!=NULL)
{
if(strlen(res)>511)
......@@ -107,8 +106,9 @@ static int ethereal_rets_process(mapidflib_function_instance_t *instance,
else
mbuf->result[0]='\0';
//printf("rett fr CP20 sitter vi med %s\n",mbuf->result);
//printf("rett f?r CP20 sitter vi med %s\n",mbuf->result);
//printf("CP20\n");
free(phdr);
if(res!=NULL) /* packet passed filter */
{
......@@ -127,7 +127,7 @@ static mapidflib_function_def_t finfo={
"",
"ETHEREAL_RETS",
"Ethereal filter return function\nUSE WITH CARE\nReturns a string based on return-clause\nParameters:\n\tfilter : char*",
"s",
"qs",
MAPI_DEVICE_ALL,
MAPIRES_SHM,
sizeof(struct ethereal_rets_data), //shm size
......
......@@ -18,6 +18,14 @@
#define TIME_MS 4294967
#define TIME_US 4294
function_manipulation_t* manipulation;
void fhlp_init_manipulation(function_manipulation_t* manip)
{
manipulation = manip;
}
int fhlp_check_funct(flist_t *flist, char *fname)
//return fid of first function with the name fname
{
......@@ -55,6 +63,11 @@ int fhlp_check_software_funct(flist_t *flist, mapidflib_function_instance_t *fro
return 0;
}
void* fhlp_get_function_instance(int fd, int fid, int pid)
{
return manipulation->get_function(fd,fid,pid);
}
int fhlp_create_semaphore(fhlp_sem_t *sem, int num)
//Creates a new semaphore
//Returns 0 if successfull
......@@ -123,6 +136,24 @@ mapidflib_result_t* fhlp_get_res(mapidflib_function_instance_t *instance)
}
}
mapidflib_result_t* fhlp_new_get_res(int fd, int fid, int pid)
{
mapidflib_result_t **res = NULL;
mapidflib_function_instance_t *instance = manipulation->get_function(fd, fid, pid);
if(instance==NULL)
return NULL;
if(instance->def->get_result==NULL)
return &instance->result;
else {
instance->def->get_result(instance,res);
return *res;
}
}
unsigned long long fhlp_str2ull(char *str)
//Converts a string to an unsigned long long value
{
......
......@@ -18,11 +18,15 @@ typedef struct fhlp_sem {
char fname[MAPI_STR_LENGTH];
} fhlp_sem_t;
void fhelp_init_manipulation(function_manipulation_t*);
int fhlp_check_software_funct(flist_t *flist,mapidflib_function_instance_t *from);
int fhlp_check_funct(flist_t *flist, char *fname);
int fhlp_create_semaphore(fhlp_sem_t *sem,int num);
void fhlp_free_semaphore(fhlp_sem_t *sem);
extern inline mapidflib_result_t* fhlp_get_res(mapidflib_function_instance_t *instance);
void* fhlp_get_function_instance(int fd, int fid, int pid);
void fhlp_init_manipulation(function_manipulation_t* manip);
mapidflib_result_t* fhlp_new_get_res(int fd, int fid, int pid);
//Convert a string to an unsigned long long value
unsigned long long fhlp_str2ull(char *str);
......
......@@ -199,16 +199,17 @@ void* flist_remove(flist_t *list,int id,flist_destroy_t dealloc)
--flist_size(list);
data=node->data;
if(p==NULL)
flist_head(list)=node->next;
flist_head(list)=node->next;
else
p->next=node->next;
p->next=node->next;
if(flist_tail(list)==node)
flist_tail(list)=p;
flist_tail(list)=p;
if(dealloc==FLIST_FREE_DATA)
free(flist_data(node));
free(flist_data(node));
free(node);
return data;
} else {
}
else {
p=node;
node=flist_next(node);
}
......
......@@ -53,7 +53,7 @@ static struct {
static int
ifp_instance(mapidflib_function_instance_t *instance,
flist_t *flist,
mapidflib_flow_mod_t *flow_mod)
mapidflib_flow_mod_t *flow_mod, function_manipulation_t* manip)
{
//TODO: Verify arguments
return 0;
......
......@@ -45,6 +45,15 @@ static int totalflows=0; // number of flows so far (including closed flows)
static char libpath[256];
static int offline_devices;
static int availible_device_number;
static int availible_offline_device_number;
static int availible_library_number;
static int availible_function_number;
/*
//Structure used as a linked list to store information about
//registered functions
......@@ -63,6 +72,11 @@ static char libpath[256];
static struct functiondescr *functions=NULL;
*/
typedef struct libinfo {
char* name;
} libinfo_t;
typedef struct flowdescr {
int fd;
int file; //File descriptor for offline flows
......@@ -112,6 +126,8 @@ static void mapi_init()
mapiipc_client_init();
pthread_spin_init(&mapi_lock, PTHREAD_PROCESS_PRIVATE);
offline_devices = 0;
flowlist=malloc(sizeof(flist_t));
flist_init(flowlist);
......@@ -220,9 +236,9 @@ int mapi_create_flow(char *dev)
pthread_spin_lock(&mapi_lock);
if ((numflows == 0) && (totalflows > 0) && minit) { // socket has been closed, re-create it
pthread_spin_lock(&mapi_lock);
// pthread_spin_lock(&mapi_lock);
mapiipc_client_init();
pthread_spin_unlock(&mapi_lock);
// pthread_spin_unlock(&mapi_lock);
}
pthread_spin_unlock(&mapi_lock);
......@@ -239,11 +255,12 @@ int mapi_create_flow(char *dev)
{
case CREATE_FLOW_ACK:
tmpflow=flist_get(flowlist,qbuf.fd);
if (tmpflow!=NULL) {
ERROR_CMD(fprintf(stderr,"mapid gave us a fd which already exist in our lists (%d), exiting [%s:%d]\n",
qbuf.fd,__FILE__,__LINE__));
exit(EXIT_FAILURE);
}
if (tmpflow!=NULL)
{
ERROR_CMD(fprintf(stderr,"mapid gave us a fd which already exist in our lists (%d), exiting [%s:%d]\n",
qbuf.fd,__FILE__,__LINE__));
exit(EXIT_FAILURE);
}
flow=malloc(sizeof(flowdescr_t));
flow->fd=qbuf.fd;
flow->devtype=malloc(strlen(qbuf.data)+1);
......@@ -342,6 +359,153 @@ int mapi_create_offline_flow(char *dev, int format)
}
}
char* mapi_create_offline_device(char *path, int format)
//Create new flow
//dev=device that should be used
{
struct mapiipcbuf qbuf;
int file;
pthread_once(&mapi_is_initialized, (void*)mapi_init);
//Check to see if file can be opened
if ((file=open(path,O_LARGEFILE))==-1) {
local_err=MAPI_ERROR_FILE;
return NULL;
}
pthread_spin_lock(&mapi_lock);
if ((numflows == 0) && (totalflows > 0) && minit) { // socket has been closed, re-create it
// pthread_spin_lock(&mapi_lock);
mapiipc_client_init();
// pthread_spin_unlock(&mapi_lock);
}
pthread_spin_unlock(&mapi_lock);
qbuf.mtype=1;
qbuf.cmd=CREATE_OFFLINE_DEVICE;
qbuf.fd=getpid();
qbuf.pid=getpid();
qbuf.fid=format;
strncpy(qbuf.data,path,DATA_SIZE);
pthread_spin_lock(&mapi_lock);
mapiipc_write((struct mapiipcbuf*)&qbuf);
mapiipc_read((struct mapiipcbuf*)&qbuf,getpid());
if(qbuf.cmd==SEND_FD) {
if(mapiipc_send_fd(file)==-1) {
local_err=MAPI_ERROR_SEND_FD;
return NULL;
}
} else {
local_err=MAPI_ERROR_SEND_FD;
return NULL;
}
mapiipc_read((struct mapiipcbuf*)&qbuf,getpid());
pthread_spin_unlock(&mapi_lock);
switch(qbuf.cmd)
{
case CREATE_OFFLINE_DEVICE_ACK:
printf("Vi fikk strengen %s\n",qbuf.data);
offline_devices++;
return strdup(qbuf.data);
case ERROR_ACK:
local_err=MCOM_ERROR_ACK;
return NULL;
default:
local_err=MCOM_UNKNOWN_ERROR;
return NULL;
}
}
int mapi_start_offline_device(char *dev)
//Create new flow
//dev=device that should be used
{
struct mapiipcbuf qbuf;
pthread_once(&mapi_is_initialized, (void*)mapi_init);
pthread_spin_lock(&mapi_lock);
if ((numflows == 0) && (totalflows > 0) && minit) { // socket has been closed, re-create it
pthread_spin_lock(&mapi_lock);
mapiipc_client_init();
pthread_spin_unlock(&mapi_lock);
}
pthread_spin_unlock(&mapi_lock);
qbuf.mtype=1;
qbuf.cmd=START_OFFLINE_DEVICE;
qbuf.fd=getpid();
qbuf.pid=getpid();
strncpy(qbuf.data,dev,DATA_SIZE);
qbuf.fid=0;
pthread_spin_lock(&mapi_lock);
mapiipc_write((struct mapiipcbuf*)&qbuf);
mapiipc_read((struct mapiipcbuf*)&qbuf,getpid());
pthread_spin_unlock(&mapi_lock);
switch(qbuf.cmd)
{
case START_OFFLINE_DEVICE_ACK:
return 0;
case ERROR_ACK:
local_err=MCOM_ERROR_ACK;
return -1;
default:
local_err=MCOM_UNKNOWN_ERROR;
return -1;
}
}
int mapi_delete_offline_device(char *dev)
//Create new flow
//dev=device that should be used
{
struct mapiipcbuf qbuf;
printf("closing down...\n");
pthread_once(&mapi_is_initialized, (void*)mapi_init);
/* socet is not closed
pthread_spin_lock(&mapi_lock);
if ((numflows == 0) && (totalflows > 0) && minit) { // socket has been closed, re-create it
mapiipc_client_init();
}
pthread_spin_unlock(&mapi_lock);
*/
qbuf.mtype=1;
qbuf.cmd=DELETE_OFFLINE_DEVICE;
qbuf.fd=getpid();
qbuf.pid=getpid();
strncpy(qbuf.data,dev,DATA_SIZE);
qbuf.fid=0;
printf("Sender\n");
pthread_spin_lock(&mapi_lock);
mapiipc_write((struct mapiipcbuf*)&qbuf);
mapiipc_read((struct mapiipcbuf*)&qbuf,getpid());
pthread_spin_unlock(&mapi_lock);
switch(qbuf.cmd)
{
case DELETE_OFFLINE_DEVICE_ACK:
pthread_spin_lock(&mapi_lock);
if((numflows == 0) && --offline_devices == 0)
mapiipc_client_close();
pthread_spin_unlock(&mapi_lock);
return 0;
case ERROR_ACK:
local_err=MCOM_ERROR_ACK;
printf("Die\n");
return -1;
default:
local_err=MCOM_UNKNOWN_ERROR;
printf("Die2\n");
return -1;
}
}
int mapi_close_flow(int fd)
{
struct mapiipcbuf qbuf;
......@@ -406,7 +570,7 @@ int mapi_close_flow(int fd)
* flows...
*/
pthread_spin_lock(&mapi_lock);
if(--numflows == 0)
if((--numflows == 0) && offline_devices == 0)
mapiipc_client_close();
pthread_spin_unlock(&mapi_lock);
......@@ -540,7 +704,9 @@ int mapi_apply_function(int fd, char* funct, ...)
break;
default:
break;
local_err=MFUNCT_INVALID_ARGUMENT_DESCRIPTOR;
printf("Illegal argument descriptor %c\n",*argdescr_ptr);
exit(EXIT_FAILURE);
}
argdescr_ptr++; // move to the next arg
}
......@@ -1112,6 +1278,217 @@ mapi_unload_library(char* library)
return 0;
}
int mapi_get_availible_offline_devices(int devicenumber,device_info_t* ret)
{
struct mapiipcbuf qbuf;
if (!minit) {
DEBUG_CMD(printf("Not initialized! [%s:%d]\n",__FILE__,__LINE__));
return -1;
}
availible_offline_device_number = devicenumber;
qbuf.mtype=1;
qbuf.cmd=GET_AVAILIBLE_OFFLINE_DEVICES;
qbuf.fd = devicenumber;
pthread_spin_lock(&mapi_lock);
mapiipc_write(&qbuf);
mapiipc_read(&qbuf,getpid());
pthread_spin_unlock(&mapi_lock);
if(qbuf.cmd==GET_AVAILIBLE_OFFLINE_DEVICES_ACK) {
memcpy(ret,&qbuf.data,sizeof(device_info_t));
return 0;
} else
return -10;
}
int mapi_get_next_availible_offline_device(device_info_t* ret )
{
return mapi_get_availible_offline_devices(++availible_offline_device_number,ret);
}
int mapi_get_availible_devices(int devicenumber,device_info_t* ret)
{
struct mapiipcbuf qbuf;
if (!minit) {
DEBUG_CMD(printf("Not initialized! [%s:%d]\n",__FILE__,__LINE__));
return -1;
}
availible_device_number = devicenumber;
qbuf.mtype=1;
qbuf.cmd=GET_AVAILIBLE_DEVICES;
qbuf.fd = devicenumber;
pthread_spin_lock(&mapi_lock);
mapiipc_write(&qbuf);
mapiipc_read(&qbuf,getpid());
pthread_spin_unlock(&mapi_lock);
if(qbuf.cmd==GET_AVAILIBLE_DEVICES_ACK) {
memcpy(ret,&qbuf.data,sizeof(device_info_t));
return 0;
} else
return -1;
}
int mapi_get_next_availible_device(device_info_t* ret)
{
return mapi_get_availible_devices(++availible_device_number,ret);
}
int mapi_get_availible_libraries(int libnumber,char* ret)
{
struct mapiipcbuf qbuf;
if (!minit) {
DEBUG_CMD(printf("Not initialized! [%s:%d]\n",__FILE__,__LINE__));
return -1;
}
availible_library_number = libnumber;