#ifndef _MAPIIPC_H #define _MAPIIPC_H 1 #include "mapi.h" #ifdef DIMAPI #include #include #include #include "flist.h" #ifdef DIMAPISSL #ifdef HAVE_OPENSSL #include #include #else #include #include #endif /* HAVE_OPENSSL */ #endif /* DIMAPISSL */ #endif /* DIMAPI */ #define MAX_SEND_SIZE 8192//1024 #define FUNCTARGS_BUF_SIZE 7168 #define DATA_SIZE 7168 #define DIMAPI_DATA_SIZE 50000 #define FUNCT_NAME_LENGTH 256 #define ARG_LENGTH 32 #define MAPIDSOCKHOME "%s/.mapid.sock" #define MAPIDSOCKGLOBAL "/tmp/mapid.sock" //All IPC code needs to be rewritten and cleand up. //To support dynamic loading of new functions we should have an IPC //system that do not need to be changed for each new function type //that is added. #ifdef DIMAPISSL static SSL_CTX *ctx; struct overload{ SSL * connection; int sock; }; #endif //Messages types that can be sent to/from mapi and mapid typedef enum { CREATE_FLOW, CREATE_FLOW_ACK, APPLY_FUNCTION, APPLY_FUNCTION_ACK, READ_RESULT, READ_RESULT_ACK, CONNECT, CONNECT_ACK, CLOSE_FLOW, CLOSE_FLOW_ACK, READ_ERROR, READ_ERROR_ACK, ERROR_ACK, CREATE_OFFLINE_DEVICE, CREATE_OFFLINE_DEVICE_ACK, START_OFFLINE_DEVICE, START_OFFLINE_DEVICE_ACK, DELETE_OFFLINE_DEVICE, DELETE_OFFLINE_DEVICE_ACK, CREATE_OFFLINE_FLOW, CREATE_OFFLINE_FLOW_ACK, SET_AUTHDATA, SET_AUTHDATA_ACK, AUTHENTICATE, AUTHENTICATE_ACK, LOAD_LIBRARY, LOAD_LIBRARY_ACK, GET_DEVICE_INFO, GET_DEVICE_INFO_ACK, GET_NEXT_DEVICE_INFO, GET_DEVICE_INFO_NACK, GET_LIBRARY_INFO, GET_LIBRARY_INFO_ACK, GET_NEXT_LIBRARY_INFO, GET_LIBRARY_INFO_NACK, GET_FLOW_INFO, GET_FLOW_INFO_ACK, GET_NEXT_FLOW_INFO, GET_FLOW_INFO_NACK, GET_FUNCTION_INFO, GET_FUNCTION_INFO_ACK, GET_NEXT_FUNCTION_INFO, GET_FUNCTION_INFO_NACK, GET_LIBPATH, GET_LIBPATH_ACK, GET_LIBPATH_NACK, GET_LIBS, GET_LIBS_ACK, GET_LIBS_NACK, SEND_FD, GET_NEXT_PKT, GET_NEXT_PKT_ACK } mapiipcMsg; //Buffer that is sent to/from mapi and mapid struct mapiipcbuf { long mtype; mapiipcMsg cmd; int fd; char function[FUNCT_NAME_LENGTH]; int fid; int size; int pid; /* needed to identify target mtype, to send errors when invalid flow-id's are given, when no flow-id is made,... */ //int offset; /* Starting search position from the beginning of packet */ //int depth; /* Maximum search depth from the beginning of search position */ //unsigned long long maxpkts; /* maximum pkt position */ uid_t uid; //UID of the user running the application unsigned char data[DATA_SIZE]; unsigned char argdescr[ARG_LENGTH]; int remote_errorcode; }; //IPC calls //Initialize IPC functions int mapiipc_client_init(void); void mapiipc_daemon_init(void); //Sends an IPC message int mapiipc_write(struct mapiipcbuf *qbuf); //Reads an IPC message. Blocking call. int mapiipc_read(struct mapiipcbuf *qbuf); //Send a file handle int mapiipc_send_fd(int sendfd); //receive a file handle int mapiipc_read_fd(); //Relase socket resources void mapiipc_client_close(void); void mapiipc_daemon_close(void); #ifdef DIMAPI //holds info about a remote mapid struct host { char* hostname; int port; int sockfd; #ifdef DIMAPISSL SSL *con; #endif int num_flows; //to know when to close the socket flist_t *flows; flist_t* functions; pthread_t* comm_thread; //communication thread }; //Buffer that is sent to/from mapi and agent struct dmapiipcbuf { unsigned int length; mapiipcMsg cmd; int fd; int fid; unsigned long long timestamp; char data[DIMAPI_DATA_SIZE]; }; #define BASIC_SIZE (sizeof(struct dmapiipcbuf) - DIMAPI_DATA_SIZE) #define PKT_LENGTH 131072 //pkt info and actual pkt typedef struct host_flow { struct host *rhost; char* dev; int scope_fd; int fd; //fd of flow in the mapid of host int id; struct dmapiipcbuf *dbuf; //buffer for writting results from this host -for this flow- struct mapipkt* pkt; flist_t *functions; //holds all fids for this host_flow } host_flow; typedef struct remote_flowdescr { int fd; // 'scope' fd int scope_size; flist_t* host_flowlist; flist_t* pkt_list; //FIFO list for get_next_pkt sem_t fd_sem; sem_t pkt_sem; //unsigned int pending_msgs; //pthread_mutex_t mutex; //struct mapipkt* pkt; DELETE flist_t* function_res; unsigned char is_connected; // This should be 1 if the flow is connected 0 otherwise /* int error; char errstr[MAPI_ERRORSTR_LENGTH]; */ #ifdef WITH_AUTHENTICATION unsigned char is_authenticated; char *username; char *vo; #endif } remote_flowdescr_t; //dmapi functions and ipcbuffer int mapiipc_remote_init(struct host *h); int mapiipc_remote_write(struct dmapiipcbuf *dbuf, struct host *h); int mapiipc_remote_write_to_all(remote_flowdescr_t* rflow); void mapiipc_remote_close(struct host *h); void *mapiipc_comm_thread(void *host); /* Read "n" bytes from a socket. */ ssize_t readn(int fd, void *vptr, size_t n); #ifdef DIMAPISSL ssize_t SSL_readn(SSL *con, void *vptr, size_t n); #endif #endif//DIMAPI #define INT 1 #define STRING 2 #define UNSIGNED_LONG_LONG 3 extern void addarg(mapiFunctArg **pos, void *arg, int type); extern int getargint(mapiFunctArg **pos); extern char getargchar(mapiFunctArg **pos); extern char * getargstr(mapiFunctArg **pos); extern unsigned long long getargulonglong(mapiFunctArg **pos); #endif//_MAPIIPC_H