mapi.h 7.82 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
#define PAPI 10

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

17 18
typedef int boolean_t;

Arne Øslebø's avatar
Arne Øslebø committed
19 20 21 22 23 24 25 26 27 28
#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

29 30 31 32 33 34 35 36 37
#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
38 39 40 41 42 43 44 45 46 47 48
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
};

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

55 56 57 58 59
enum toba_flg {
  WAIT = 0,
  NOWAIT
};

's avatar
committed
60 61 62 63 64 65 66 67
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
68 69 70 71 72 73 74 75 76 77
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
78
  int devid; // ID of the device used by the flow
Arne Øslebø's avatar
Arne Øslebø committed
79 80 81 82 83
  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
84 85 86
 #ifdef WITH_PRIORITIES
  	int priority;
  #endif
Arne Øslebø's avatar
Arne Øslebø committed
87 88 89 90 91 92 93 94
} 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
95 96
/* 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
97 98 99 100 101 102 103 104 105 106 107 108
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
109
  int result_size;		//Size of the function's result
Arne Øslebø's avatar
Arne Øslebø committed
110 111 112 113 114 115 116 117 118 119 120 121
} 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
122 123 124 125 126 127 128
/*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
129
#ifdef DIMAPI
's avatar
Fix  
committed
130 131
#define DEFAULT_DIMAPI_PORT 2233

's avatar
committed
132 133 134
#ifdef WITH_ADMISSION_CONTROL
int agent_send_authdata(void *authdata);
#endif //WITH_ADMISSION_CONTROL
's avatar
committed
135

's avatar
committed
136
#endif //DIMAPI
's avatar
committed
137

138 139 140 141 142 143
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];
144
	int link_speed;
145
	int mpls;
's avatar
committed
146
	int vlan;
147
} mapi_device_info_t;
's avatar
committed
148

149 150 151 152 153 154 155 156
typedef struct mapi_libfunct_info {
    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 {
157
  int id; //Library ID
158 159 160
  char libname[MAPI_STR_LENGTH]; //Name of library
  unsigned int functs; //Number of functions in the library
} mapi_lib_info_t;
's avatar
committed
161

162 163 164 165 166 167 168
/*
 * As returned by mapi_stats()
 */
struct mapi_stat {
	unsigned int ps_recv;		/* number of packets received */
	unsigned int ps_drop;		/* number of packets dropped */
	unsigned int ps_ifdrop;	/* drops by interface */
's avatar
committed
169 170
	char hostname[MAPI_STR_LENGTH];
	char dev[MAPI_STR_LENGTH];
171
};
's avatar
committed
172

Arne Øslebø's avatar
Arne Øslebø committed
173 174 175 176
//Prototype of the mapi_loop callback function
typedef void (*mapi_handler)(const struct mapipkt*);

//Create new mapi flow
's avatar
 
committed
177
extern int mapi_create_flow(const char *dev);
Arne Øslebø's avatar
Arne Øslebø committed
178 179

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

's avatar
committed
182
//Create new mapi flow based on a trace file
's avatar
 
committed
183
extern char* mapi_create_offline_device(const char *path,int format);
's avatar
committed
184 185

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

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

Arne Øslebø's avatar
Arne Øslebø committed
191
//Apply function to a flow
's avatar
 
committed
192
extern int mapi_apply_function(int fd, const char* funct, ...);
193
extern int mapi_apply_function_array(int fd, const char* funct, char** args, unsigned int argn);
Arne Øslebø's avatar
Arne Øslebø committed
194 195

//Connect to a mapi flow
's avatar
 
committed
196
extern int mapi_connect(int fd);
Arne Øslebø's avatar
Arne Øslebø committed
197 198

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

201 202 203
//Get the next packet from a to_buffer function, using asynchronous mechanism - PUSH MODEL (only for DiMAPI)
extern struct mapipkt *mapi_asynchronous_get_next_pkt(int fd, int fid);

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

//Read result from a function
's avatar
committed
208
extern mapi_results_t* mapi_read_results(int fd, int fid);
Arne Øslebø's avatar
Arne Øslebø committed
209 210

//Close a mapi flow
's avatar
 
committed
211
extern int mapi_close_flow(int fd);
Arne Øslebø's avatar
Arne Øslebø committed
212 213 214 215

//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
216
extern int mapi_read_error(int* err_no, char* errorstr);
Arne Øslebø's avatar
Arne Øslebø committed
217

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

220
#ifdef WITH_AUTHENTICATION
's avatar
 
committed
221 222
extern int mapi_authenticate(int, const char *, const char *, const char *);
extern int agent_authenticate(void *);
223 224
#endif

225
//int mapi_load_library(char* library);
Arne Øslebø's avatar
Arne Øslebø committed
226 227

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

's avatar
committed
230
//Get information on hardware-devices
's avatar
 
committed
231 232
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
233 234

//Get information on loaded libraries
's avatar
 
committed
235 236
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);
237 238
extern int mapi_get_libfunct_info(int libnum, int fnum, mapi_libfunct_info_t *info);
extern int mapi_get_next_libfunct_info(int libnum, int fnum, mapi_libfunct_info_t *info);
239

Arne Øslebø's avatar
Arne Øslebø committed
240
//Get information about a flow
's avatar
 
committed
241
extern int mapi_get_flow_info(int fd, mapi_flow_info_t *info);
Arne Øslebø's avatar
Arne Øslebø committed
242
//Get information about next flow with flow descriptor>fd
's avatar
 
committed
243
extern int mapi_get_next_flow_info(int fd, mapi_flow_info_t *info);
Arne Øslebø's avatar
Arne Øslebø committed
244

's avatar
committed
245
extern int mapi_get_scope_size(int fd);
's avatar
committed
246
extern int mapi_is_remote(int fd);
247
extern int mapi_is_sensor_down(int fd);
Arne Øslebø's avatar
Arne Øslebø committed
248

249
//Get information about a function applied to a flow
's avatar
 
committed
250
extern int mapi_get_function_info(int fd, int fid, mapi_function_info_t *info);
251
//Get information about a function applied to a flow
's avatar
 
committed
252
extern int mapi_get_next_function_info(int fd, int fid, mapi_function_info_t *info);
253 254
//mapi stats
extern int mapi_stats(const char *dev, struct mapi_stat *stats);
Arne Øslebø's avatar
Arne Øslebø committed
255

256 257 258
// internal use only (mapi_create_flow does not give devtype directly)
extern char *mapi_get_devtype_of_flow(int id);

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