diff options
author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-06-14 14:56:55 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-06-14 14:56:55 +0200 |
commit | 337ab9fe73b86306b72b9eaae3b7be759f7bbd36 (patch) | |
tree | d7b237631ef17df911ec4aef766aba085a63bd30 /src/lib | |
parent | 6019a5b1ee574c8cea485ce5ba68ff77a24b4786 (diff) | |
parent | 6271d09bdd17114c3095b7e819a7bcded14f26a5 (diff) | |
download | ouroboros-337ab9fe73b86306b72b9eaae3b7be759f7bbd36.tar.gz ouroboros-337ab9fe73b86306b72b9eaae3b7be759f7bbd36.zip |
Merge remote-tracking branch 'upstream/be' into be-llc
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/dev.c | 123 | ||||
-rw-r--r-- | src/lib/ipcp.c | 8 | ||||
-rw-r--r-- | src/lib/irm.c | 72 | ||||
-rw-r--r-- | src/lib/irmd_messages.proto | 39 | ||||
-rw-r--r-- | src/lib/utils.c | 18 |
5 files changed, 91 insertions, 169 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index ae6d0f6c..ab4365b8 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -58,6 +58,9 @@ struct ap_data { int ap_init(char * ap_name) { int i = 0; + + ap_name = path_strip(ap_name); + _ap_instance = malloc(sizeof(struct ap_data)); if (_ap_instance == NULL) { return -1; @@ -154,109 +157,7 @@ static int port_id_to_fd(int port_id) } #endif -int ap_reg(char ** difs, - size_t len) -{ - irm_msg_t msg = IRM_MSG__INIT; - irm_msg_t * recv_msg = NULL; - int fd = -1; - - if (difs == NULL || - len == 0 || - difs[0] == NULL) { - return -EINVAL; - } - - rw_lock_rdlock(&_ap_instance->data_lock); - - if (_ap_instance == NULL) { - rw_lock_unlock(&_ap_instance->data_lock); - return -1; /* -ENOTINIT */ - } - - msg.code = IRM_MSG_CODE__IRM_AP_REG; - msg.has_pid = true; - msg.dif_name = difs; - msg.n_dif_name = len; - - msg.pid = _ap_instance->api->id; - msg.ap_name = _ap_instance->api->name; - - recv_msg = send_recv_irm_msg(&msg); - if (recv_msg == NULL) { - rw_lock_unlock(&_ap_instance->data_lock); - return -1; - } - - if (!recv_msg->has_result) { - rw_lock_unlock(&_ap_instance->data_lock); - irm_msg__free_unpacked(recv_msg, NULL); - return -1; - } - - if (recv_msg->result < 0) - fd = -1; - - irm_msg__free_unpacked(recv_msg, NULL); - - rw_lock_wrlock(&_ap_instance->flows_lock); - - fd = bmp_allocate(_ap_instance->fds); - _ap_instance->flows[fd].port_id = -1; - - rw_lock_unlock(&_ap_instance->flows_lock); - rw_lock_unlock(&_ap_instance->data_lock); - - return fd; -} - -int ap_unreg(char ** difs, - size_t len) -{ - irm_msg_t msg = IRM_MSG__INIT; - irm_msg_t * recv_msg = NULL; - int ret = -1; - - if (difs == NULL || - len == 0 || - difs[0] == NULL) { - return -EINVAL; - } - - msg.code = IRM_MSG_CODE__IRM_AP_UNREG; - msg.has_pid = true; - msg.dif_name = difs; - msg.n_dif_name = len; - - rw_lock_rdlock(&_ap_instance->data_lock); - - msg.pid = _ap_instance->api->id; - msg.ap_name = _ap_instance->api->name; - - recv_msg = send_recv_irm_msg(&msg); - if (recv_msg == NULL) { - rw_lock_unlock(&_ap_instance->data_lock); - return -1; - } - - if (!recv_msg->has_result) { - rw_lock_unlock(&_ap_instance->data_lock); - irm_msg__free_unpacked(recv_msg, NULL); - return -1; - } - - ret = recv_msg->result; - - rw_lock_unlock(&_ap_instance->data_lock); - - irm_msg__free_unpacked(recv_msg, NULL); - - return ret; -} - -int flow_accept(int fd, - char ** ap_name, - char ** ae_name) +int flow_accept(char ** ae_name) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -267,6 +168,7 @@ int flow_accept(int fd, rw_lock_rdlock(&_ap_instance->data_lock); + msg.ap_name = _ap_instance->api->name; msg.pid = _ap_instance->api->id; rw_lock_unlock(&_ap_instance->data_lock); @@ -301,23 +203,9 @@ int flow_accept(int fd, return -1; } - if (ap_name != NULL) { - *ap_name = strdup(recv_msg->ap_name); - if (*ap_name == NULL) { - shm_ap_rbuff_close(_ap_instance->flows[cfd].rb); - bmp_release(_ap_instance->fds, cfd); - rw_lock_unlock(&_ap_instance->flows_lock); - rw_lock_unlock(&_ap_instance->data_lock); - irm_msg__free_unpacked(recv_msg, NULL); - return -1; - } - } - if (ae_name != NULL) { *ae_name = strdup(recv_msg->ae_name); if (*ae_name == NULL) { - if (*ap_name != NULL) - free(*ap_name); shm_ap_rbuff_close(_ap_instance->flows[cfd].rb); bmp_release(_ap_instance->fds, cfd); rw_lock_unlock(&_ap_instance->flows_lock); @@ -406,7 +294,6 @@ int flow_alloc(char * dst_name, rw_lock_rdlock(&_ap_instance->data_lock); msg.pid = _ap_instance->api->id; - msg.ap_name = _ap_instance->api->name; rw_lock_unlock(&_ap_instance->data_lock); diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c index 0d75b73e..89756235 100644 --- a/src/lib/ipcp.c +++ b/src/lib/ipcp.c @@ -367,7 +367,6 @@ int ipcp_flow_alloc(pid_t pid, int port_id, pid_t n_pid, char * dst_name, - char * src_ap_name, char * src_ae_name, enum qos_cube qos) { @@ -375,7 +374,7 @@ int ipcp_flow_alloc(pid_t pid, ipcp_msg_t * recv_msg = NULL; int ret = -1; - if (dst_name == NULL || src_ap_name == NULL || src_ae_name == NULL) + if (dst_name == NULL || src_ae_name == NULL) return -EINVAL; msg.code = IPCP_MSG_CODE__IPCP_FLOW_ALLOC; @@ -383,7 +382,6 @@ int ipcp_flow_alloc(pid_t pid, msg.port_id = port_id; msg.has_pid = true; msg.pid = n_pid; - msg.src_ap_name = src_ap_name; msg.src_ae_name = src_ae_name; msg.dst_name = dst_name; msg.has_qos_cube = true; @@ -438,21 +436,19 @@ int ipcp_flow_alloc_resp(pid_t pid, int ipcp_flow_req_arr(pid_t pid, char * dst_name, - char * src_ap_name, char * src_ae_name) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; int port_id = -1; - if (src_ap_name == NULL || src_ae_name == NULL) + if (dst_name == NULL || src_ae_name == NULL) return -EINVAL; msg.code = IRM_MSG_CODE__IPCP_FLOW_REQ_ARR; msg.has_pid = true; msg.pid = pid; msg.dst_name = dst_name; - msg.ap_name = src_ap_name; msg.ae_name = src_ae_name; recv_msg = send_recv_irm_msg(&msg); diff --git a/src/lib/irm.c b/src/lib/irm.c index 6bd16576..ff5c3237 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -202,27 +202,39 @@ int irm_enroll_ipcp(instance_name_t * api, return ret; } -int irm_reg_ipcp(instance_name_t * api, - char ** difs, - size_t difs_size) +int irm_reg(char * name, + instance_name_t * api, + int argc, + char ** argv, + bool autoexec, + char ** difs, + size_t difs_len) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; int ret = -1; - if (api->name == NULL || - difs == NULL || - difs_size == 0 || - difs[0] == NULL) { + if (name == NULL || api->name == NULL) return -EINVAL; - } - msg.code = IRM_MSG_CODE__IRM_REG_IPCP; + msg.code = IRM_MSG_CODE__IRM_AP_REG; + msg.dst_name = name; msg.ap_name = api->name; - msg.has_api_id = true; - msg.api_id = api->id; - msg.dif_name = difs; - msg.n_dif_name = difs_size; + if (difs != NULL) { + msg.dif_name = difs; + msg.n_dif_name = difs_len; + } + + if (argv != NULL) { + msg.n_args = argc; + msg.args = argv; + } else { + msg.has_api_id = true; + msg.api_id = api->id; + } + + msg.has_autoexec = true; + msg.autoexec = autoexec; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) @@ -239,28 +251,36 @@ int irm_reg_ipcp(instance_name_t * api, return ret; } -int irm_unreg_ipcp(const instance_name_t * api, - char ** difs, - size_t difs_size) +int irm_unreg(char * name, + const instance_name_t * api, + char ** difs, + size_t difs_len, + bool hard) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; int ret = -1; - if (api == NULL || - api->name == NULL || - difs == NULL || - difs_size == 0 || - difs[0] == NULL) { + if (name == NULL && api == NULL) + return -EINVAL; + + if (difs == NULL || + difs_len == 0 || + difs[0] == NULL) return -EINVAL; + + msg.code = IRM_MSG_CODE__IRM_AP_UNREG; + if (api != NULL) { + msg.ap_name = api->name; + msg.has_api_id = true; + msg.api_id = api->id; } - msg.code = IRM_MSG_CODE__IRM_UNREG_IPCP; - msg.ap_name = api->name; - msg.has_api_id = true; - msg.api_id = api->id; msg.dif_name = difs; - msg.n_dif_name = difs_size; + msg.n_dif_name = difs_len; + if (name != NULL) + msg.dst_name = name; + msg.hard = hard; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) diff --git a/src/lib/irmd_messages.proto b/src/lib/irmd_messages.proto index 27194ccb..34366975 100644 --- a/src/lib/irmd_messages.proto +++ b/src/lib/irmd_messages.proto @@ -27,19 +27,17 @@ enum irm_msg_code { IRM_DESTROY_IPCP = 2; IRM_BOOTSTRAP_IPCP = 3; IRM_ENROLL_IPCP = 4; - IRM_REG_IPCP = 5; - IRM_UNREG_IPCP = 6; - IRM_AP_REG = 7; - IRM_AP_UNREG = 8; - IRM_FLOW_ACCEPT = 9; - IRM_FLOW_ALLOC_RESP = 10; - IRM_FLOW_ALLOC = 11; - IRM_FLOW_ALLOC_RES = 12; - IRM_FLOW_DEALLOC = 13; - IPCP_FLOW_REQ_ARR = 14; - IPCP_FLOW_ALLOC_REPLY = 15; - IPCP_FLOW_DEALLOC = 16; - IRM_REPLY = 17; + IRM_AP_REG = 5; + IRM_AP_UNREG = 6; + IRM_FLOW_ACCEPT = 7; + IRM_FLOW_ALLOC_RESP = 8; + IRM_FLOW_ALLOC = 9; + IRM_FLOW_ALLOC_RES = 10; + IRM_FLOW_DEALLOC = 11; + IPCP_FLOW_REQ_ARR = 12; + IPCP_FLOW_ALLOC_REPLY = 13; + IPCP_FLOW_DEALLOC = 14; + IRM_REPLY = 15; }; message irm_msg { @@ -49,10 +47,13 @@ message irm_msg { optional uint32 api_id = 3; optional uint32 ipcp_type = 5; repeated string dif_name = 6; - optional sint32 response = 7; - optional string dst_name = 8; - optional sint32 port_id = 9; - optional int32 pid = 10; - optional dif_config_msg conf = 11; - optional sint32 result = 12; + repeated string args = 7; + optional sint32 response = 8; + optional string dst_name = 9; + optional sint32 port_id = 10; + optional int32 pid = 11; + optional dif_config_msg conf = 12; + optional bool autoexec = 13; + optional bool hard = 14; + optional sint32 result = 15; }; diff --git a/src/lib/utils.c b/src/lib/utils.c index 5744fb7c..49065138 100644 --- a/src/lib/utils.c +++ b/src/lib/utils.c @@ -53,3 +53,21 @@ char * strdup(const char * src) return dst; } + +char * path_strip(char * src) +{ + char * dst = NULL; + + if (src == NULL) + return NULL; + + dst = src + strlen(src); + + while (dst > src && *dst != '/') + --dst; + + if (*dst == '/') + ++dst; + + return dst; +} |