Commit b3abd25d authored by Arne Øslebø's avatar Arne Øslebø
Browse files

started adding doxygen documentation

git-svn-id: file:///home/svn/mapi/trunk@330 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent db931ce6
......@@ -70,7 +70,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 slist.o parseconf.o mapipktdecoder.o priorities.o
mapi.so: mapi.o mapiipc.o mapilibhandler.o fhelp.o flist.o parseconf.o mapipktdecoder.o priorities.o
$(CC) -shared -o $@ $^ -ldl $(KEYNOTE_LDADD) -lpthread
mapierror.o: mapierror.c mapi.h mapi_errors.h
......@@ -79,13 +79,13 @@ mapierror.o: mapierror.c mapi.h mapi_errors.h
mapilibhandler.o: mapilibhandler.c mapilibhandler.h
$(CC) $(CFLAGS) -c $<
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 priorities.o
mapidlib.o: mapidlib.c flist.h mapidlib.h mapid.h mapidrv.h mapi.h mapi_errors.h mstring.h mapilibhandler.h mapidflib.h priorities.o
$(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 slist.o flist.o parseconf.o priorities.o $(ADMCTRLCL_OBJS) $(RESCTRL_OBJS)
mapid: mapid.o mapiipc.o mapierror.o mstring.o flist.o parseconf.o priorities.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 mapid.c
......@@ -130,9 +130,6 @@ cbuf.o: cbuf.c cbuf.h
fifo.o: fifo.c fifo.h
$(CC) $(CFLAGS) -c $<
slist.o: slist.c slist.h xalloc.h
$(CC) $(CFLAGS) -c $<
resctrl_cl.o: resctrl_cl.c resctrl_cl.h
$(CC) $(CFLAGS) $(RESCTRL_CFLAGS) -c $<
......@@ -172,6 +169,9 @@ build_dimapi_tests:
build_agent:
cd agent && make
docs:
doxygen doxygen.cfg
clean:
@/bin/rm -f mapidtmp.* *.o *.so *~ $(TARGETS) \
mapi_erorrs.dat mapi_errors.h \
......
......@@ -24,7 +24,7 @@ all: $(BINS)
$(CC) $(CFLAGS) $(INCLUDE) -c $<
agent: agent.o
$(CC) $(CFLAGS) ../mapi.o ../mapiipc.o ../mapilibhandler.o ../fhelp.o ../flist.o ../slist.o ../parseconf.o ../mapipktdecoder.o $^ -ldl $(KEYNOTE_LDADD) -lpthread -o $@ $(LDLIBS)
$(CC) $(CFLAGS) ../mapi.o ../mapiipc.o ../mapilibhandler.o ../fhelp.o ../flist.o ../parseconf.o ../mapipktdecoder.o $^ -ldl $(KEYNOTE_LDADD) -lpthread -o $@ $(LDLIBS)
clean:
$(RM) *.o $(BINS)
This diff is collapsed.
/** \file flist.c
Implementation of a simple single linked list for flows or functions.
Based on slist in adm_ctrl
*/
#include "stdlib.h"
#include "flist.h"
/** \brief Append data to list
\param list a pointer to a list
\param data the data to place in the list
\return 0 on success, or -1 on failure
*/
int
flist_append(flist_t *list,int id,void *data)
{
......@@ -34,60 +24,6 @@ flist_append(flist_t *list,int id,void *data)
return 0;
}
int flist_insert_before(flist_t *list, int before, int id, void *data)
{
flist_node_t *newnode,*node,*prev=NULL;
if ( (newnode = malloc(sizeof(flist_node_t))) == NULL )
return -1;
newnode->id=id;
newnode->data = data;
newnode->next = NULL;
//Find before node
node=flist_head(list);
if ( node == NULL )
{
flist_append(list,id,data);
free(newnode);
}
else
{
while(node!=NULL)
{
if(node->id!=before)
{
prev=node;
node=flist_next(node);
}
else
break;
}
if(prev==NULL) {
free(newnode);
flist_prepend(list,id,data);
}
else {
prev->next=newnode;
newnode->next=node;
if(node==NULL)
flist_tail(list)=newnode;
++flist_size(list);
}
}
return 0;
}
/** \brief Prepend data to list
\param list a pointer to list
\param data the data to place in the list
\return 0 on success, or -1 on failure
*/
int
flist_prepend(flist_t *list,int id,void *data)
{
......@@ -108,10 +44,6 @@ flist_prepend(flist_t *list,int id,void *data)
return 0;
}
/** \brief Pop the first element in the list
\param list a pointer to a list
\return a pointer to the element, or NULL if the list is empty
*/
void *
flist_pop_first(flist_t *list)
{
......@@ -129,9 +61,7 @@ flist_pop_first(flist_t *list)
return d;
}
/** \ brief Initialize a single linked list
\param list the list to initialize
*/
void
flist_init(flist_t *list)
{
......@@ -139,10 +69,6 @@ flist_init(flist_t *list)
flist_size(list) = 0;
}
/** \brief Destroy and de-allocate the memory hold by a list
\param list a pointer to an existing list
\param dealloc flag that indicates whether stored data should also be de-allocated
*/
void
flist_destroy(flist_t *list,flist_destroy_t dealloc)
{
......@@ -194,7 +120,7 @@ int flist_get_next_id(flist_t *list, int id)
void flist_move_before(flist_t *list,int before,int id) {
void *data=flist_remove(list,id,FLIST_LEAVE_DATA);
flist_insert_before(list,before,id,data);
flist_insert(list,id,data,before);
}
void* flist_remove(flist_t *list,int id,flist_destroy_t dealloc)
......
/**
* \file flist.h
* \brief Library for handling linked lists where each node is identified by an integer ID
*/
#ifndef _FLIST_H
#define _FLIST_H 1
//Flow/function linked list
//Based on slist in adm_ctrl
/**
* \struct flist_node flist.h
* \brief Structure containing the data for one single node in an flist
*/
typedef struct flist_node
{
int id;
void *data;
struct flist_node* next;
int id; //!< ID of the node
void *data; //!< Pointer to the data stored in the node
struct flist_node* next; //!< Pointer to the next node. NULL if no other nodes exits
} flist_node_t;
/**
* \struct flist flist.h
* \brief Structure containing control information about an flist
*/
typedef struct flist
{
flist_node_t *head; //Pointer to head of list
flist_node_t *tail; //Pointer to tail of list
unsigned size; //Number of elements in the list
flist_node_t *head; //!< Pointer to head of list
flist_node_t *tail; //!< Pointer to tail of list
unsigned size; //!< Number of elements in the list
} flist_t;
//! Macro to get the head node of a list l
......@@ -24,25 +35,87 @@ typedef struct flist
#define flist_tail(l) (l)->tail
//! Macro to get the size of a list l
#define flist_size(l) (l)->size
//! Macro to get the next node of l
//! Macro to get the next node after n
#define flist_next(n) (n)->next
//! Macro to get the data of node l
//! Macro to get the data of node n
#define flist_data(n) (n)->data
/// Macro to get the ID of node n
#define flist_id(n) (n)->id
typedef enum { FLIST_LEAVE_DATA = 0, FLIST_FREE_DATA } flist_destroy_t;
void flist_init(flist_t *);
void flist_destroy(flist_t *,flist_destroy_t);
void* flist_remove(flist_t *,int,flist_destroy_t);
int flist_insert(flist_t *, int id, void*, int index);
void flist_reverse(flist_t*);
void flist_move_before(flist_t *,int before,int id);
/**
* \brief Initialise an flist
* \param list the list to initialize
*/
void flist_init(flist_t *list);
/** \brief Destroy and de-allocate the memory hold by a list
* \param list a pointer to an existing list
* \param dealloc flag that indicates whether stored data should also be de-allocated
*/
void flist_destroy(flist_t *list,flist_destroy_t dealloc);
/** \brief Remove a node from the list
* \param list a pointer to an existing list
* \param dealloc flag that indicates whether stored data should also be de-allocated
*/
void* flist_remove(flist_t *list,int,flist_destroy_t dealloc);
/** \brief Insert a new node into the list
* \param list a pointer to an existing list
* \param id ID of the new node
* \param data data to be stored in the node
* \param index specifies the exact index of the list where the node should be inserted
* \return 0 on success, or -1 on failure
*/
int flist_insert(flist_t *list, int id, void *data, int index);
/** \brief Reverse the order of the list
* \param list a pointer to an existing list
*/
void flist_reverse(flist_t *list);
/** \brief Moves one node before another one in the list
* \param list a pointer to an existing list
* \param before ID of the node that the other node should be moved before
* \param id ID of the node that should be moved
*/
void flist_move_before(flist_t *list,int before,int id);
/** \brief Pop the first element in the list
* \param list a pointer to a list
* \return a pointer to the element, or NULL if the list is empty
*/
extern inline void *flist_pop_first(flist_t *);
extern inline int flist_append(flist_t *,int id,void *);
extern inline int flist_insert_before(flist_t *,int before,int id,void *);
extern inline int flist_prepend(flist_t *,int id,void *);
extern inline void* flist_get(flist_t *,int id);
extern inline int flist_get_next_id(flist_t *,int id);
/** \brief Append data to list
* \param list a pointer to a list
* \param data the data to place in the list
* \return 0 on success, or -1 on failure
*/
extern inline int flist_append(flist_t *list,int id,void *data);
/** \brief Prepend data to list
* \param list a pointer to list
* \param data the data to place in the list
* \return 0 on success, or -1 on failure
*/
extern inline int flist_prepend(flist_t *list,int id,void *data);
/** \brief Get the data of a node from the list
* \param list a pointer to list
* \param id ID of the node to get
* \return pointer to the data of the node. 0 if the node do not exist
*/
extern inline void* flist_get(flist_t *list,int id);
/** \brief Get the data of the next node in the list
* \param list a pointer to list
* \param id ID of the previous node
* \return pointer to the data of the node. 0 if the node do not exist
*/
extern inline int flist_get_next_id(flist_t *list,int id);
#endif
......@@ -23,7 +23,6 @@
#include "flist.h"
#include "parseconf.h"
#include "debug.h"
#include "slist.h"
#ifdef WITH_ADMISSION_CONTROL
#include "config.h"
......
......@@ -5,40 +5,117 @@
#include "mapidlib.h"
#include "flist.h"
/**
* \file mapidflib.h
* \brief Defines all structures related to MAPI functions
*/
/**
* \struct mapidflib_flow_mod mapidflib.h
* \brief Structure used for modifying the list of functions applied to a MAPI flow
*/
typedef struct mapidflib_flow_mod {
int reorder; //Used for reordering the execution order of functions
//A function can set this to indicate that this function
//should be processed before the function with fid=reorder.
int identical; //Set this variable to the fid of an existing function that
//is identical with this one.
int *delete; //Pointer to an array of FIDs of functions that can be deleted from the flow. This is usefull in case a hardware function can replace multiple software functions.
int delete_size; //Size of the delete array.
mapid_add_function add_funct; //Used for adding extra MAPI functions
mapidlib_instance_t *mi; //needed as parameter for mapid_add_function
/**
* \brief Used for reordering the execution order of functions.
*
* A function can set this to indicate that this function
* should be processed before the function with function ID equel to the value of reorder.
*/
int reorder;
/**
* \brief Used for manual global optimization.
*
* A function can search through already
* active function applied to other functions and if it nd a function that is
* identical it can set the value of identical so that it points to the ID of
* the identical function. Should be set to 0 if there are no identical
* functions.
*/
int identical;
/**
* \brief Used for deleting functions from the flow
*
* Pointer to an array of functions IDs that can be deleted from the flow.
* This is usefull in case a hardware function can replace multiple
* software functions.
*/
int *delete;
int delete_size; ///< Size of the delete array.
/**
* \brief Used for adding new MAPI functions to the flow
*
* Pointer to a function that can be used for adding new functions to the current flow.
* It is used in the same way as mapi_apply_function.
*/
mapid_add_function add_funct;
/**
* \brief Argument for mapid_add_function
*
* Pointer to an instance of mapidlib. This is needed as an argument for mapid_add_function.
* As it is subject to change without notice it should NEVER be used directly by a MAPI function
*/
mapidlib_instance_t *mi;
} mapidflib_flow_mod_t;
/**
* \brief Structure for storing results for MAPI functions
*
* This structure contains the actual results from a MAPI function as well as information needed by the application
* to get hold of the results
*/
typedef struct mapidflib_result {
mapid_result_t info; //Information about results that is sent back to the client
void* data; //Pointer to memory that contains the result data
unsigned long data_size; //Size of data that contains the result
mapid_result_t info; ///< Information about results that is sent back to the client
void* data; ///< Pointer to memory that contains the result data
unsigned long data_size; ///< Size of data that contains the result
} mapidflib_result_t;
typedef enum { MAPIFUNC_UNINIT, MAPIFUNC_INIT } mapidflib_status_t;
typedef enum { MAPIOPT_NONE, MAPIOPT_AUTO, MAPIOPT_MANUAL } mapidflib_optimize_t;
/**
* \brief Enum showing if a MAPI function is initialized
*/
typedef enum { MAPIFUNC_UNINIT, ///< Enum value indicating that the function is uninitialized
MAPIFUNC_INIT ///< Enum value indicating that the function is initialized
} mapidflib_status_t;
/**
* \brief Enum used for deciding how global anonymization should be handled for a function
*/
typedef enum { MAPIOPT_NONE, ///< Enum value indicating that no global optimization should be used
MAPIOPT_AUTO, ///< Enum value indicating that automatic global optimization should be used
MAPIOPT_MANUAL ///< Enum value indicating that manual global optimization should be used. Function using this method should use the identical field in the mapiflib_flow_mod structure for global optimization
} mapidflib_optimize_t;
/**
* \brief Structure containing information related to the actual instance of a MAPI function
*/
typedef struct mapidflib_function_instance {
mapidflib_status_t status; //status of initialization
mapiFunctArg args[FUNCTARGS_BUF_SIZE]; //Arguments
mapidflib_result_t result; //Results returned by the function
void* internal_data; //Data used internally by the function
mapid_hw_info_t *hwinfo;
unsigned long long pkts; //Number of packets that has been processed
unsigned long long processed_pkts; //Number of packets that has been processed by the function and passd through it.
struct mapidflib_function_def* def;
int ret; //Return value 0 or 1
int refcount; //Number of flows that references this function
mapidflib_status_t status; ///< status of initialization
/**
* Arguments passed to the function.
*
* All arguments passed to the function is serialized into this string. The functions getargin, getargchar, getargulongulong and getargstr defined in mapiipc.h can be used for retrieving the arguments.
*/
mapiFunctArg args[FUNCTARGS_BUF_SIZE];
mapidflib_result_t result; ///< Results returned by the function
void* internal_data; ///< Data used internally by the function
mapid_hw_info_t *hwinfo; ///< Pointer to information about the adapter the flow is running on
unsigned long long pkts; ///< Number of packets that has been processed by the function
unsigned long long processed_pkts; ///< Number of packets that has been processed by the function and passd through it.
struct mapidflib_function_def* def; ///< Pointer to the function definition structure
int ret; ///< The return value of the last time the function processed a packet
int refcount; ///< Number of flows that references this function
} mapidflib_function_instance_t;
/**
* \brief Structur containing information about an applied MAPI function
*/
typedef struct mapidflib_function {
int fd; //Flow descriptor
int fid; //Function id
......@@ -47,9 +124,6 @@ typedef struct mapidflib_function {
} mapidflib_function_t;
typedef enum { MAPIRES_NONE,MAPIRES_IPC, MAPIRES_SHM, MAPIRES_FUNCT } mapi_result_method_t;
typedef struct mapidflib_function_def {
......
......@@ -420,7 +420,7 @@ free_functionlist (struct mapidlibflow *fl)
fn=flist_data(cur);
if(fn->instance->def->cleanup!=NULL && fn->instance->status==MAPIFUNC_INIT)
fn->instance->def->cleanup(fn);
fn->instance->def->cleanup(fn->instance);
free(fn->instance->def);
// if(fn->internal_data!=NULL)
......@@ -957,12 +957,13 @@ void mapid_process_pkt(mapidlib_instance_t *i,
#endif
funct->instance->ret=ret;
}
n2 = flist_next(n2);
n2 = flist_next(n2);
}
} else if(flow->delete==1)
n = flist_next(n);
} else if(flow->delete==1) {
n = flist_next(n);
delete_flow(i,flow);
n = flist_next(n);
}
}
#ifdef WITH_PRIORITIES
}
......
......@@ -202,7 +202,7 @@ mapidrv_offline_proc_loop(int devid)
c=read(i->file,&head,sizeof(struct pcap_file_header));
c=read(i->file,b,BUFSIZE);
while(c>0) {
while(c>0) {
left=process_pkts(buf,c+left,i,devid,c);
//Copy last bytes to beginning of buffer
memcpy(buf,b+c-left,left);
......@@ -236,8 +236,7 @@ mapidrv_proc_loop (int devid)
while (1)
{
while( (packet = pcap_next(i->pcap,&phdr)) == NULL )
;
while( (packet = pcap_next(i->pcap,&phdr)) == NULL );
// Transform header
// This is only for backward compatibility
......
/** \file slist.c
Implementation of a very simple single linked list.
Works both in user and kernel space.
It is not safe for concurrent access.
\todo Use compare & swap to try and make it safe!
*/
#include "xalloc.h"
#include "slist.h"
/** \brief Append data to list
\param list a pointer to a list
\param data the data to place in the list
\return 0 on success, or -1 on failure
*/
int
slist_append(slist_t *list,void *data)
{
slist_node_t *node;
if ( (node = xalloc(sizeof(slist_node_t))) == NULL )
return -1;
node->data = data;
node->next = NULL;
if ( slist_head(list) == NULL )
slist_head(list) = node;
else
slist_next(slist_tail(list)) = node;
slist_tail(list) = node;
++slist_size(list);
return 0;
}
/** \brief Prepend data to list
\param list a pointer to list
\param data the data to place in the list
\return 0 on success, or -1 on failure
*/
int
slist_prepend(slist_t *list,void *data)
{
slist_node_t *node;
if ( (node = xalloc(sizeof(slist_node_t))) == NULL )
return -1;
slist_data(node) = data;
slist_next(node) = slist_head(list);
slist_head(list) = node;
if ( slist_tail(list) == NULL )
slist_tail(list) = node;
++slist_size(list);
return 0;
}
/** \brief Pop the first element in the list
\param list a pointer to a list
\return a pointer to the element, or NULL if the list is empty
*/
void *
slist_pop_first(slist_t *list)
{
void *d;
slist_node_t *node;
if ( slist_head(list) == NULL )
return NULL;
d = slist_data((node = slist_head(list)));
slist_head(list) = slist_next(node);
xfree(node);
if ( --slist_size(list) == 0 )
slist_tail(list) = NULL;
return d;
}
/** \brief Searches for a mathcing node and returns it
Returns only the first matching node.
\param list a pointer to an existing list
\param comp function reference to be used for comparison of nodes
\param cdata 2nd argument to be passed to comparison function
\return Reference to the matching node's data, or NULL if no node
was matched
*/
void *
slist_search(slist_t *list,slist_comp_t comp,void *cdata)
{
slist_node_t *n;
for(n = slist_head(list) ; n != NULL ; n = slist_next(n))
if ( comp(slist_data(n),cdata) == 0 )
return slist_data(n);
return NULL;
}
/** \brief Searches for matching objects and deletes them
\param list a pointer to an existing list
\param comp function reference to be used for comparison
\param cdata 2nd argument to be passed to comparison function
\return the number of removed nodes
*/
int
slist_search_and_delete(slist_t *list,slist_comp_t comp,void *cdata,slist_destroy_t dealloc)
{
slist_node_t *n,*d,*prev;
int ret = 0;
for(n = slist_head(