diff --git a/src/common/mapiipc.h b/src/common/mapiipc.h index d2d8990bbcfb01a7eea22e29a3f7b38253d90e6a..8b200898cb08d29acbd89933e1cda2696a422a0a 100644 --- a/src/common/mapiipc.h +++ b/src/common/mapiipc.h @@ -197,6 +197,7 @@ struct dmapiipcbuf { typedef struct host_flow { struct host *rhost; char* dev; + char *devtype; int scope_fd; int fd; //fd of flow in the mapid of host int id; diff --git a/src/lib/mapi.c b/src/lib/mapi.c index ca986a7aa6b4a706a6d1afd11a99b0098a5be942..88c4602534e1a3f5683d038d2921779cedb21c03 100644 --- a/src/lib/mapi.c +++ b/src/lib/mapi.c @@ -499,6 +499,7 @@ static void delete_remote_flow(remote_flowdescr_t* rflow) flist_destroy(hflow->functions); free(hflow->functions); free(hflow->dev); + free(hflow->devtype); free(hflow->dbuf); if (hflow->pkt!=NULL) free(hflow->pkt); @@ -545,6 +546,16 @@ static void delete_remote_flow(remote_flowdescr_t* rflow) } #endif +char *mapi_get_devtype_of_flow(int fd) { + flowdescr_t *tmpflow; + char *devtype; + + tmpflow = flist_get(flowlist, fd); + devtype = strdup(tmpflow->devtype); + + return devtype; +} + int mapi_create_flow(const char *dev) //Create new flow //dev=device that should be used @@ -560,7 +571,7 @@ int mapi_create_flow(const char *dev) remote_flowdescr_t *rflow; char *hostname=NULL, *s=NULL, *k=NULL; struct host *h=NULL; - host_flow* hflow; + host_flow* hflow = NULL; char *devp; flist_node_t* fnode; unsigned int idgen=0; @@ -738,6 +749,7 @@ int mapi_create_flow(const char *dev) hflow=(host_flow*)fnode->data; if (hflow->dbuf->cmd == CREATE_FLOW_ACK) { hflow->fd=*((int*)hflow->dbuf->data); + hflow->devtype = strdup((char *)(((char *)hflow->dbuf->data) + sizeof(int))); flist_remove(hflow->rhost->flows, hflow->dbuf->fd); flist_append(hflow->rhost->flows, hflow->fd, hflow); } @@ -1521,8 +1533,7 @@ int mapi_apply_function(int fd, const char* funct, ...) #ifdef DIMAPI } - if (is_remote) fdef=mapilh_get_function_def(funct,"1.3"); - else + if (!is_remote) { #endif //Get information about function @@ -1533,6 +1544,9 @@ int mapi_apply_function(int fd, const char* funct, ...) local_err = MAPI_FUNCTION_NOT_FOUND; return -1; } +#ifdef DIMAPI + } +#endif #ifdef DIMAPI if(is_remote){//flow is remote @@ -1540,6 +1554,14 @@ int mapi_apply_function(int fd, const char* funct, ...) for (fnode=flist_head(rflow->host_flowlist), i=1; fnode!=NULL; fnode=flist_next(fnode), i++) { hflow=(host_flow*)fnode->data; + + fdef=mapilh_get_function_def(funct,hflow->devtype); + if(fdef==NULL) { + printf("ERROR: Could not find/match function %s [%s:%d]\n", funct, __FILE__, __LINE__); + local_err = MAPI_FUNCTION_NOT_FOUND; + return -1; + } + hflow->dbuf->cmd=APPLY_FUNCTION; hflow->dbuf->fd=hflow->fd; memcpy(hflow->dbuf->data, funct, strlen(funct)+1);//put function name in the buffer @@ -4348,8 +4370,7 @@ int mapi_apply_function_array(int fd, const char* funct, char** args, unsigned i #ifdef DIMAPI } - if (is_remote) fdef=mapilh_get_function_def(funct,"1.3"); - else + if (!is_remote) { #endif //Get information about function @@ -4360,12 +4381,24 @@ int mapi_apply_function_array(int fd, const char* funct, char** args, unsigned i local_err = MAPI_FUNCTION_NOT_FOUND; return -1; } +#ifdef DIMAPI + } +#endif #ifdef DIMAPI if(is_remote){//flow is remote for (fnode=flist_head(rflow->host_flowlist), i=1; fnode!=NULL; fnode=flist_next(fnode), i++) { + hflow=(host_flow*)fnode->data; + + fdef=mapilh_get_function_def(funct,hflow->devtype); + if(fdef==NULL) { + printf("ERROR: Could not find/match function %s [%s:%d]\n", funct, __FILE__, __LINE__); + local_err = MAPI_FUNCTION_NOT_FOUND; + return -1; + } + hflow->dbuf->cmd=APPLY_FUNCTION; hflow->dbuf->fd=hflow->fd; memcpy(hflow->dbuf->data, funct, strlen(funct)+1);//put function name in the buffer diff --git a/src/lib/mapi.h b/src/lib/mapi.h index fed02f666a3c1be2d3e048d48b05ee6e1233e8b1..11353d917131354535a1f79be264dca6e5a4cb85 100644 --- a/src/lib/mapi.h +++ b/src/lib/mapi.h @@ -253,4 +253,7 @@ extern int mapi_get_next_function_info(int fd, int fid, mapi_function_info_t *in //mapi stats extern int mapi_stats(const char *dev, struct mapi_stat *stats); +// internal use only (mapi_create_flow does not give devtype directly) +extern char *mapi_get_devtype_of_flow(int id); + #endif diff --git a/src/mapicommd.c b/src/mapicommd.c index ba880cc59a8508e340cbdd3cfe4494c388d6c22f..58d19ea04e1a7052845b27e54eb19129ff60a373 100644 --- a/src/mapicommd.c +++ b/src/mapicommd.c @@ -326,6 +326,7 @@ void *handle_request(void *arg) { mapi_function_info_t funct_info; mapi_flow_info_t flow_info; mapi_device_info_t device_info; + char *devtype = NULL; #ifdef RECONNECT int ignore_flag = 0; #endif @@ -435,12 +436,21 @@ void *handle_request(void *arg) { memcpy(dbuf->data, &errno, sizeof(int)); } else { + devtype = mapi_get_devtype_of_flow(mapid_result); + if(devtype != NULL) { dbuf->cmd = CREATE_FLOW_ACK; memcpy(dbuf->data, &mapid_result, sizeof(int)); + memcpy(((char *)dbuf->data) + sizeof(int), devtype, strlen(devtype)+1); active_flows = realloc(active_flows,(ac_fl_size+1)*sizeof(int)); active_flows[ac_fl_size++] = mapid_result; } - dbuf->length = BASIC_SIZE+sizeof(int); + else { + dbuf->cmd = ERROR_ACK; + mapi_read_error(&errno, errorstr); + memcpy(dbuf->data, &errno, sizeof(int)); + } + } + dbuf->length = BASIC_SIZE+sizeof(int)+strlen(devtype)+1; break; case CLOSE_FLOW: fprintf(stdout,"CLOSE_FLOW (%d)\n",dbuf->fd);