diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/dev.c | 72 | ||||
-rw-r--r-- | src/lib/ipcp.c | 4 | ||||
-rw-r--r-- | src/lib/irm.c | 85 | ||||
-rw-r--r-- | src/lib/irmd_messages.proto | 55 |
4 files changed, 135 insertions, 81 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index f27ef0fe..3a5fc8e0 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -54,6 +54,37 @@ struct ap_data { pthread_rwlock_t flows_lock; } * _ap_instance; +static int api_announce(char * ap_name) +{ + irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; + int ret = -1; + + msg.code = IRM_MSG_CODE__IRM_API_ANNOUNCE; + msg.has_api = true; + + pthread_rwlock_rdlock(&_ap_instance->data_lock); + + msg.api = _ap_instance->api; + msg.ap_name = ap_name; + + pthread_rwlock_unlock(&_ap_instance->data_lock); + + recv_msg = send_recv_irm_msg(&msg); + if (recv_msg == NULL) { + return -1; + } + + if (!recv_msg->has_result || (ret = recv_msg->result)) { + irm_msg__free_unpacked(recv_msg, NULL); + return ret; + } + + irm_msg__free_unpacked(recv_msg, NULL); + + return ret; +} + int ap_init(char * ap_name) { int i = 0; @@ -100,6 +131,9 @@ int ap_init(char * ap_name) pthread_rwlock_init(&_ap_instance->flows_lock, NULL); pthread_rwlock_init(&_ap_instance->data_lock, NULL); + if (ap_name != NULL) + return api_announce(ap_name); + return 0; } @@ -134,42 +168,6 @@ void ap_fini(void) free(_ap_instance); } -int api_bind(char * ap_subset) -{ - irm_msg_t msg = IRM_MSG__INIT; - irm_msg_t * recv_msg = NULL; - int ret = -1; - - msg.code = IRM_MSG_CODE__IRM_API_BIND; - msg.has_api = true; - - if (_ap_instance->ap_name == NULL) - return -EPERM; /* call init first */ - - pthread_rwlock_rdlock(&_ap_instance->data_lock); - - msg.api = _ap_instance->api; - msg.ap_name = _ap_instance->ap_name; - - pthread_rwlock_unlock(&_ap_instance->data_lock); - - msg.ap_subset = ap_subset; - - recv_msg = send_recv_irm_msg(&msg); - if (recv_msg == NULL) { - return -1; - } - - if (!recv_msg->has_result || (ret = recv_msg->result)) { - irm_msg__free_unpacked(recv_msg, NULL); - return ret; - } - - irm_msg__free_unpacked(recv_msg, NULL); - - return ret; -} - static int port_id_to_fd(int port_id) { int i; @@ -417,6 +415,8 @@ int flow_dealloc(int fd) msg.code = IRM_MSG_CODE__IRM_FLOW_DEALLOC; msg.has_port_id = true; + msg.has_api = true; + msg.api = getpid(); pthread_rwlock_rdlock(&_ap_instance->data_lock); pthread_rwlock_wrlock(&_ap_instance->flows_lock); diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c index bdc980f9..e8e31e46 100644 --- a/src/lib/ipcp.c +++ b/src/lib/ipcp.c @@ -53,6 +53,7 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t api, char * sock_path = NULL; ssize_t count = 0; ipcp_msg_t * recv_msg = NULL; + struct timeval tv = {(SOCKET_TIMEOUT / 1000), (SOCKET_TIMEOUT % 1000) * 1000}; @@ -260,9 +261,8 @@ int ipcp_enroll(pid_t api, msg.dif_name = dif_name; recv_msg = send_recv_ipcp_msg(api, &msg); - if (recv_msg == NULL) { + if (recv_msg == NULL) return -1; - } if (recv_msg->has_result == false) { ipcp_msg__free_unpacked(recv_msg, NULL); diff --git a/src/lib/irm.c b/src/lib/irm.c index 4c71817d..64a4fa0f 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -321,21 +321,21 @@ static int check_ap_path(char ** ap_name) return -ENOENT; } -int irm_bind(char * name, - char * ap_name, - uint16_t opts, - int argc, - char ** argv) +int irm_bind_ap(char * ap, + char * name, + uint16_t opts, + int argc, + char ** argv) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; int ret = -1; char * full_ap_name; - if (name == NULL || ap_name == NULL) + if (ap == NULL || name == NULL) return -EINVAL; - full_ap_name = strdup(ap_name); + full_ap_name = strdup(ap); if (full_ap_name == NULL) return -ENOMEM; @@ -344,7 +344,7 @@ int irm_bind(char * name, return ret; } - msg.code = IRM_MSG_CODE__IRM_BIND; + msg.code = IRM_MSG_CODE__IRM_BIND_AP; msg.dst_name = name; msg.ap_name = full_ap_name; @@ -372,23 +372,76 @@ int irm_bind(char * name, return ret; } -int irm_unbind(char * name, - char * ap_name, - uint16_t opts) +int irm_bind_api(pid_t api, char * name) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; int ret = -1; - if (name == NULL || ap_name == NULL) + if (name == NULL) return -EINVAL; - msg.code = IRM_MSG_CODE__IRM_UNBIND; + msg.code = IRM_MSG_CODE__IRM_BIND_API; + msg.has_api = true; + msg.api = api; + msg.dst_name = name; + + recv_msg = send_recv_irm_msg(&msg); + if (recv_msg == NULL) + return -1; + + if (recv_msg->has_result == false) { + irm_msg__free_unpacked(recv_msg, NULL); + return -1; + } + + ret = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + return ret; +} + +int irm_unbind_ap(char * ap, char * name) +{ + irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; + int ret = -1; + + if (name == NULL) + return -EINVAL; + + msg.code = IRM_MSG_CODE__IRM_UNBIND_AP; + msg.ap_name = ap; + msg.dst_name = name; + + recv_msg = send_recv_irm_msg(&msg); + if (recv_msg == NULL) + return -1; + + if (recv_msg->has_result == false) { + irm_msg__free_unpacked(recv_msg, NULL); + return -1; + } + + ret = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + + return ret; +} + +int irm_unbind_api(pid_t api, char * name) +{ + irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; + int ret = -1; + + if (name == NULL) + return -EINVAL; + + msg.code = IRM_MSG_CODE__IRM_UNBIND_API; + msg.has_api = true; + msg.api = api; msg.dst_name = name; - msg.ap_name = ap_name; - msg.has_opts = true; - msg.opts = opts; 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 5c320a17..7a634201 100644 --- a/src/lib/irmd_messages.proto +++ b/src/lib/irmd_messages.proto @@ -29,36 +29,37 @@ enum irm_msg_code { IRM_LIST_IPCPS = 4; IRM_BOOTSTRAP_IPCP = 5; IRM_ENROLL_IPCP = 6; - IRM_BIND = 7; - IRM_UNBIND = 8; - IRM_API_BIND = 9; - IRM_REG = 10; - IRM_UNREG = 11; - IRM_FLOW_ACCEPT = 12; - IRM_FLOW_ALLOC_RESP = 13; - IRM_FLOW_ALLOC = 14; - IRM_FLOW_ALLOC_RES = 15; - IRM_FLOW_DEALLOC = 16; - IPCP_FLOW_REQ_ARR = 17; - IPCP_FLOW_ALLOC_REPLY = 18; - IPCP_FLOW_DEALLOC = 19; - IRM_REPLY = 20; + IRM_BIND_AP = 7; + IRM_UNBIND_AP = 8; + IRM_API_ANNOUNCE = 9; + IRM_BIND_API = 10; + IRM_UNBIND_API = 11; + IRM_REG = 12; + IRM_UNREG = 13; + IRM_FLOW_ACCEPT = 14; + IRM_FLOW_ALLOC_RESP = 15; + IRM_FLOW_ALLOC = 16; + IRM_FLOW_ALLOC_RES = 17; + IRM_FLOW_DEALLOC = 18; + IPCP_FLOW_REQ_ARR = 19; + IPCP_FLOW_ALLOC_REPLY = 20; + IPCP_FLOW_DEALLOC = 21; + IRM_REPLY = 22; }; message irm_msg { required irm_msg_code code = 1; optional string ap_name = 2; - optional string ap_subset = 3; - optional string ae_name = 4; - optional sint32 api = 5; - optional uint32 ipcp_type = 6; - repeated string dif_name = 7; - repeated string args = 8; - optional sint32 response = 9; - optional string dst_name = 10; - optional sint32 port_id = 11; - optional dif_config_msg conf = 12; - optional uint32 opts = 13; - repeated sint32 apis = 14; - optional sint32 result = 15; + optional string ae_name = 3; + optional sint32 api = 4; + optional uint32 ipcp_type = 5; + repeated string dif_name = 6; + repeated string args = 7; + optional sint32 response = 8; + optional string dst_name = 9; + optional sint32 port_id = 10; + optional dif_config_msg conf = 11; + optional uint32 opts = 12; + repeated sint32 apis = 13; + optional sint32 result = 14; }; |