mapi.h 6.89 KB
Newer Older
Arne Øslebø's avatar
Arne Øslebø committed
1
2
3
4
5
#ifndef _MAPI_H
#define _MAPI_H 1

#include <sys/ipc.h>
#include <time.h>
's avatar
committed
6
#include <syslog.h>
Arne Øslebø's avatar
Arne Øslebø committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#define PAPI 10

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

#define MAPI_STR_LENGTH 256
#define MAPI_ERRORSTR_LENGTH 512

typedef unsigned char mapiFunctArg;

#define INT 1
#define STRING 2
#define UNSIGNED_LONG_LONG 3
#define CHAR 4

27
28
29
30
31
32
33
34
35
#if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
#define MAPI_UNUSED                           \
  __attribute__((__unused__))
#else
#define MAPI_UNUSED
#endif



Arne Øslebø's avatar
Arne Øslebø committed
36
37
38
39
40
41
42
43
44
45
46
enum mapi_file_formats {
  MFF_PCAP,MFF_RAW,MFF_DAG_ERF,MFF_COMBO6
};
#define MFF_PCAP_STR "MFF_PCAP"
#define MFF_DAG_ERF_STR "MFF_DAG_ERF"

enum mapi_read_result_method {
  MAPI_COPY, //Copy result
  MAPI_REF //Return pointer to result
};

47
48
49
50
51
52
enum cooking_direction {
    CLIENT_SIDE=1, //client's only data
    SERVER_SIDE, //server's only data
    BOTH_SIDE //all data
};

's avatar
committed
53
54
55
56
57
58
59
60
typedef enum mapi_offline_device_status {
  DEVICE_ONLINE,
  DEVICE_SETUP,
  DEVICE_READING,
  DEVICE_FINISHED, //Copy result
  DEVICE_DELETED //Return pointer to result
} mapi_offline_device_status_t;

Arne Øslebø's avatar
Arne Øslebø committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
enum mapi_flow_status {
  FLOW_INIT, //Flow is being initialized
  FLOW_ACTIVE, //Flow is active and analyzing packets
  FLOW_FINISHED, //Offline flow is finished analyzing file
  FLOW_CLOSED //Flow is closed
};

typedef struct mapi_flow_info {
  uid_t uid; //UID of user running the flow
  int fd; //Flow descriptor
  char device[MAPI_STR_LENGTH]; //Name of device used by the flow
  unsigned num_functions; //Number of functions applied to the flow
  time_t start; //Start of flow
  time_t end; //End of flow
  enum mapi_flow_status status; //Status of flow
76
77
78
 #ifdef WITH_PRIORITIES
  	int priority;
  #endif
Arne Øslebø's avatar
Arne Øslebø committed
79
80
81
82
83
84
85
86
} mapi_flow_info_t;

typedef struct mapi_stats {
  unsigned flows; //Number of active flows
  unsigned users; //Number of active users
  unsigned functions; //Total number of applied functions  
} mapi_stats_t;

's avatar
committed
87
88
/* It should NOT be confused with mapi_results_t struct that is returned by mapi_read_results.
   It is only for internal use, it may have to be renamed in internal_result_t */
Arne Øslebø's avatar
Arne Øslebø committed
89
90
91
92
93
94
95
96
97
98
99
100
typedef struct mapi_result {
  void *res; //Pointer to function specific result data
  unsigned size; //size of result
} mapi_result_t;

typedef struct mapi_function_info {
  int fid; //Function ID
  char name[MAPI_STR_LENGTH]; //Name of function
  char libname[MAPI_STR_LENGTH]; //Name of library that the function is part of
  char devtype[MAPI_STR_LENGTH]; //Device type the function is compatible with
  unsigned long long pkts; //Number of packets that has been processed
  unsigned long long passed_pkts; //Number of packets that has passed the function
101
  int result_size;		//Size of the function's result
Arne Øslebø's avatar
Arne Øslebø committed
102
103
104
105
106
107
108
109
110
111
112
113
} mapi_function_info_t;

/*Structure that contains device independant information about packets*/
struct mapipkt {
  unsigned long long ts; /* NTP 64-bit timestamp of packet as defined in 
			    RFC 1305*/
  unsigned short ifindex; //Interface index
  unsigned caplen; /* Number of bytes from the packet that were captured*/
  unsigned wlen; /* Wire length. Real lenght of packet as seen on network*/
  unsigned char pkt; /* Pointer to the IP packet */
};

's avatar
committed
114
115
116
117
118
119
120
/*structure returned by mapi_read_results*/
typedef struct mapi_results {
  void* res;			//Pointer to function specific result data
  unsigned long long ts;	//timestamp
  int size;			//size of the result
} mapi_results_t;

's avatar
committed
121
#ifdef DIMAPI
's avatar
Fix    
committed
122
123
#define DEFAULT_DIMAPI_PORT 2233

's avatar
committed
124
125
126
#ifdef WITH_ADMISSION_CONTROL
int agent_send_authdata(void *authdata);
#endif //WITH_ADMISSION_CONTROL
's avatar
committed
127

's avatar
committed
128
#endif //DIMAPI
's avatar
committed
129

130
131
132
133
134
135
136
typedef struct mapi_device_info {
	int id;
  	char device[MAPI_STR_LENGTH];
	char name[MAPI_STR_LENGTH];
	char alias[MAPI_STR_LENGTH];
	char description[1024];
} mapi_device_info_t;
's avatar
committed
137

138
139
140
141
142
143
144
145
146
147
148
149
typedef struct mapi_libfunct_info {
	char libname[MAPI_STR_LENGTH]; //Name of library
    char name[MAPI_STR_LENGTH]; //Name of function
    char descr[1024]; //Description of function
    char argdescr[MAPI_STR_LENGTH]; //Description of function arguments
    char devtype[MAPI_STR_LENGTH];
} mapi_libfunct_info_t;

typedef struct mapi_lib_info {
  char libname[MAPI_STR_LENGTH]; //Name of library
  unsigned int functs; //Number of functions in the library
} mapi_lib_info_t;
's avatar
committed
150
151


Arne Øslebø's avatar
Arne Øslebø committed
152
153
154
155
//Prototype of the mapi_loop callback function
typedef void (*mapi_handler)(const struct mapipkt*);

//Create new mapi flow
's avatar
   
committed
156
extern int mapi_create_flow(const char *dev);
Arne Øslebø's avatar
Arne Øslebø committed
157
158

//Create new mapi flow based on a trace file
's avatar
   
committed
159
extern int mapi_create_offline_flow(const char *path,int format);
Arne Øslebø's avatar
Arne Øslebø committed
160

's avatar
committed
161
//Create new mapi flow based on a trace file
's avatar
   
committed
162
extern char* mapi_create_offline_device(const char *path,int format);
's avatar
committed
163
164

//Create new mapi flow based on a trace file
's avatar
   
committed
165
extern int mapi_start_offline_device(const char *dev);
's avatar
committed
166
167

//Create new mapi flow based on a trace file
's avatar
   
committed
168
extern int mapi_delete_offline_device(char *dev);
's avatar
committed
169

Arne Øslebø's avatar
Arne Øslebø committed
170
//Apply function to a flow
's avatar
   
committed
171
extern int mapi_apply_function(int fd, const char* funct, ...);
Arne Øslebø's avatar
Arne Øslebø committed
172
173

//Connect to a mapi flow
's avatar
   
committed
174
extern int mapi_connect(int fd);
Arne Øslebø's avatar
Arne Øslebø committed
175
176

//Get the next packet from a to_buffer function
's avatar
   
committed
177
extern struct mapipkt *mapi_get_next_pkt(int fd,int fid);
Arne Øslebø's avatar
Arne Øslebø committed
178
179

//Apply a callback function to all packets in to_buffer (mapi_loop is blocking!!!)
's avatar
   
committed
180
extern int mapi_loop(int fd, int fid, int cnt, mapi_handler);
Arne Øslebø's avatar
Arne Øslebø committed
181
182
183

//Read result from a function
//This should be changed to:
's avatar
committed
184
extern mapi_results_t* mapi_read_results(int fd, int fid);
Arne Øslebø's avatar
Arne Øslebø committed
185
186

//Close a mapi flow
's avatar
   
committed
187
extern int mapi_close_flow(int fd);
Arne Øslebø's avatar
Arne Øslebø committed
188
189
190
191

//Read the last error-code set by mapid or mapi-api
//err_no and errorstr should be allocated, the function won't allocate memory
//errorstr is always < 512 bytes
's avatar
   
committed
192
extern int mapi_read_error(int fd, int* err_no, char* errorstr);
Arne Øslebø's avatar
Arne Øslebø committed
193

's avatar
   
committed
194
extern int mapi_set_authdata(int fd,const char *pub,const char *priv,const char *creds);
Arne Øslebø's avatar
Arne Øslebø committed
195

196
#ifdef WITH_AUTHENTICATION
's avatar
   
committed
197
198
extern int mapi_authenticate(int, const char *, const char *, const char *);
extern int agent_authenticate(void *);
199
200
#endif

201
//int mapi_load_library(char* library);
Arne Øslebø's avatar
Arne Øslebø committed
202
203

//Unload library
204
//int mapi_unload_library(char* library);
Arne Øslebø's avatar
Arne Øslebø committed
205

's avatar
committed
206
//Get information on hardware-devices
's avatar
   
committed
207
208
extern int mapi_get_device_info(int devicenumber, mapi_device_info_t* info);
extern int mapi_get_next_device_info(int devicenumber, mapi_device_info_t* info);
's avatar
committed
209
210

//Get information on loaded libraries
's avatar
   
committed
211
212
213
214
extern int mapi_get_library_info(int libnum, mapi_lib_info_t *info);
extern int mapi_get_next_library_info(int libnum, mapi_lib_info_t* info);
extern int mapi_get_libfunct_info(int libnum, mapi_libfunct_info_t *info);
extern int mapi_get_libfunct_next_info(int libnum, mapi_libfunct_info_t *info);
215

Arne Øslebø's avatar
Arne Øslebø committed
216
//Get information about a flow
's avatar
   
committed
217
extern int mapi_get_flow_info(int fd, mapi_flow_info_t *info);
Arne Øslebø's avatar
Arne Øslebø committed
218
//Get information about next flow with flow descriptor>fd
's avatar
   
committed
219
extern int mapi_get_next_flow_info(int fd, mapi_flow_info_t *info);
Arne Øslebø's avatar
Arne Øslebø committed
220

's avatar
committed
221
extern int mapi_get_scope_size(int fd);
Arne Øslebø's avatar
Arne Øslebø committed
222

223
//Get information about a function applied to a flow
's avatar
   
committed
224
extern int mapi_get_function_info(int fd, int fid, mapi_function_info_t *info);
225
//Get information about a function applied to a flow
's avatar
   
committed
226
extern int mapi_get_next_function_info(int fd, int fid, mapi_function_info_t *info);
Arne Øslebø's avatar
Arne Øslebø committed
227
228

#endif