mapidlib.h 4.16 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

#define MDL_AFTER 1

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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) */
    int color;		 /* colorize the packet for optimizations */

#ifdef PRECLASSIFICATION
    /* hardware preliminary packet classification (e.g. filters field from
     * Type 15-16 DAGDSM ERF), we can select flows to process using this info.
     */
    u_int32_t preclassification;
#endif
} mapid_pkthdr_t;

typedef struct tap
{
	int id;
	char *vo_name;

	unsigned char *packet;
	mapid_pkthdr_t packet_header;

	flist_t *anonfunclist;
	flist_t *anonprocfunclist;
	flist_t *flows;
} mapid_tap;

Arne Øslebø's avatar
Arne Øslebø committed
43
typedef struct mapidlib_instance {
44
  
45
46
47
#ifdef WITH_PRIORITIES
  flist_t **flowlist;
#else
Arne Øslebø's avatar
Arne Øslebø committed
48
  flist_t *flowlist;//=NULL;  //List of flows
49
50
#endif	
//  flist_t *flowlist;//=NULL;  //List of flows
Arne Øslebø's avatar
Arne Øslebø committed
51
  unsigned fcount;	//Number of functions
's avatar
committed
52
  pthread_spinlock_t *shm_spinlock; //Pointer to start of shared memory that contains a spinlock
53
54
55
56
  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];
57

Arne Øslebø's avatar
Arne Øslebø committed
58
59
}mapidlib_instance_t;

60
typedef int (*mapid_add_function)(mapidlib_instance_t *i, int fd, char *funct, ...);
Arne Øslebø's avatar
Arne Øslebø committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

//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
};



//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
82
  unsigned long pkt_drop; // Number of dropped pkts, NOTE: for supported devs.
Arne Øslebø's avatar
Arne Øslebø committed
83
84
85
86
87
  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
88
                 //4 if old-fashioned offline
Arne Øslebø's avatar
Arne Øslebø committed
89
  int devid; //Device ID set by mapid
90
  int devfd;	//file descriptor for hardware device
91
  global_function_list_t *gflist; //Global function list
Arne Øslebø's avatar
Arne Øslebø committed
92
93
94
  void *adapterinfo; //Pointer to adapter specific information
} mapid_hw_info_t;

's avatar
committed
95

96
97
98
#ifdef WITH_AUTHENTICATION
int mapid_init(mapidlib_instance_t *, mapid_hw_info_t *info);
#else
Arne Øslebø's avatar
Arne Øslebø committed
99
int mapid_init(mapidlib_instance_t *i);
100
#endif
Arne Øslebø's avatar
Arne Øslebø committed
101
102
103
104
105
106
107
108
109
110
111
112
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,
113
			  mapiFunctArg *fargs,
114
			  int flags);
Arne Øslebø's avatar
Arne Øslebø committed
115
void mapid_process_pkt(mapidlib_instance_t *i,
's avatar
committed
116
117
		       unsigned char* dev_pkt,
		       unsigned char* link_pkt,
Arne Øslebø's avatar
Arne Øslebø committed
118
119
		       mapid_pkthdr_t* pkt_head);
int mapid_get_errno(mapidlib_instance_t *i,int fid);
120
//void mapid_delete_flows(mapidlib_instance_t *i);
Arne Øslebø's avatar
Arne Øslebø committed
121
122
123
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);
124
125
//void mapid_lock(mapidlib_instance_t *i);
//void mapid_unlock(mapidlib_instance_t *i);
Arne Øslebø's avatar
Arne Øslebø committed
126
127
128
129

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

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

131
//char* mapid_get_lib_name(int libnumber);
's avatar
committed
132

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