mapidlib.h 3.57 KB
Newer Older
Arne Øslebø's avatar
Arne Øslebø committed
1
2
3
4
5
6
7
#ifndef _MAPIDLIB_H
#define _MAPIDLIB_H 1

#include <pthread.h>
#include <sys/types.h>

#include "flist.h"
8
#ifdef WITH_PRIORITIES
9
#include "priorities.h"
10
#endif
11
#include "mapid.h"
Arne Øslebø's avatar
Arne Øslebø committed
12
13
14
15

#define MDL_AFTER 1

typedef struct mapidlib_instance {
16
  
17
18
19
#ifdef WITH_PRIORITIES
  flist_t **flowlist;
#else
Arne Øslebø's avatar
Arne Øslebø committed
20
  flist_t *flowlist;//=NULL;  //List of flows
21
22
#endif	
//  flist_t *flowlist;//=NULL;  //List of flows
Arne Øslebø's avatar
Arne Øslebø committed
23
  unsigned fcount;	//Number of functions
24
  pthread_mutex_t *shm_spinlock; //Pointer to start of shared memory that contains a spinlock
25
26
27
28
29
  unsigned long long shm_spinlock_size; //Size of shared memory
  key_t shm_spinlock_key;
  int shm_spinlock_id;
  char shm_spinlock_fname[MAPI_STR_LENGTH];
  
Arne Øslebø's avatar
Arne Øslebø committed
30
31
}mapidlib_instance_t;

32
typedef int (*mapid_add_function)(mapidlib_instance_t *i, int fd, char *funct, ...);
Arne Øslebø's avatar
Arne Øslebø committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

//Structure used by the to_buffer function
struct mapid_to_buffer {
  key_t buf_key; //Shared memory key for the buffer
  unsigned long read_ptr; //Pointer to the next packet that can be read
  unsigned long write_ptr; //Pointer to where the next packet can be written
  char* buf; //Pointer to buffer
  int cap_length; //Maximum size of a captured packet
  unsigned bufsize;  //Size of buffer
  key_t sem_key; //key of the semaphore used for blocking the clients app.
  int semaphore; //the semaphore ID
};

typedef struct mapid_pkthdr {
    unsigned long long ts; /* 64-bit timestamp of packet*/
    unsigned short ifindex; //Interface index
    unsigned caplen;     /* length of portion present */
    unsigned wlen;        /* length this packet (off wire) */
51
	int color;			/* colorize the packet for optimizations */
Arne Øslebø's avatar
Arne Øslebø committed
52
53
54
55
56
57
58
59
60
} mapid_pkthdr_t;


//General information about the hardware adapter that is being used
//and that various functions might find useful
typedef struct mapid_hw_info {
  unsigned int link_type; // Data-link level type as defined in bpf.h
  unsigned int cap_length; // Maximum packet capture length  
  unsigned long long pkts; //Number of packets read by the device
61
  unsigned long pkt_drop; // Number of dropped pkts, NOTE: for supported devs.
Arne Øslebø's avatar
Arne Øslebø committed
62
63
64
65
66
  char* devtype; //Device type
  short offline; //0 Proper device
                 //1 active offline flow
                 //2 active full speed offline flow
                 //3 finished offline flow
's avatar
committed
67
                 //4 if old-fashioned offline
Arne Øslebø's avatar
Arne Øslebø committed
68
  int devid; //Device ID set by mapid
69
  global_function_list_t *gflist; //Global function list
Arne Øslebø's avatar
Arne Øslebø committed
70
71
72
  void *adapterinfo; //Pointer to adapter specific information
} mapid_hw_info_t;

's avatar
committed
73
74
75



Arne Øslebø's avatar
Arne Øslebø committed
76
77
78
79
80
81
82
83
84
85
86
87
88
int mapid_init(mapidlib_instance_t *i);
void mapid_destroy(mapidlib_instance_t *i);
int mapid_connect(mapidlib_instance_t *i,int fd);
int mapid_add_flow(mapidlib_instance_t *i,int fd,mapid_hw_info_t* hwinfo,void *info);
int mapid_close_flow(mapidlib_instance_t *i,int fd);

int mapid_read_results(mapidlib_instance_t *i,
		       int fd,
		       int fid,
		       mapid_result_t **result);
int  mapid_apply_function(mapidlib_instance_t *i,
			  int fd,
			  char* function,
89
90
			  mapiFunctArg *fargs,
			  unsigned char internal);
Arne Øslebø's avatar
Arne Øslebø committed
91
void mapid_process_pkt(mapidlib_instance_t *i,
's avatar
committed
92
93
		       unsigned char* dev_pkt,
		       unsigned char* link_pkt,
Arne Øslebø's avatar
Arne Øslebø committed
94
95
96
97
98
		       mapid_pkthdr_t* pkt_head);
int mapid_get_errno(mapidlib_instance_t *i,int fid);
int mapid_get_devid(mapidlib_instance_t *i,int fd);
int mapid_load_library(char *lib);
int mapid_get_flow_info(mapidlib_instance_t *i,int fd,mapi_flow_info_t *info);
99
100
//void mapid_lock(mapidlib_instance_t *i);
//void mapid_unlock(mapidlib_instance_t *i);
Arne Øslebø's avatar
Arne Øslebø committed
101
102
103
104

mapid_funct_info_t* mapid_get_flow_functions(mapidlib_instance_t *i,int fd);

int mapid_finished(mapidlib_instance_t *i);
's avatar
committed
105

106
//char* mapid_get_lib_name(int libnumber);
's avatar
committed
107

Arne Øslebø's avatar
Arne Øslebø committed
108
#endif