diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2017-02-09 16:49:56 +0100 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2017-02-09 18:11:48 +0100 |
commit | 6785ca65ab48f1a29914c1784a24009964ec4720 (patch) | |
tree | 31828a5eb1a646883c3f582795c8ffc7c990b35b /src/lib | |
parent | 275dc65b22e39654e4dfc9cbd13277e490c8dccd (diff) | |
download | ouroboros-6785ca65ab48f1a29914c1784a24009964ec4720.tar.gz ouroboros-6785ca65ab48f1a29914c1784a24009964ec4720.zip |
ipcpd, lib: Report IPCP creation failure
The IPCP will now respond with an ipcp_create_r message when it fails,
informing the IRMd.
Also adds some const qualifiers in the public headers and fixes
some formatting in dev.c.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/dev.c | 115 | ||||
-rw-r--r-- | src/lib/irm.c | 81 | ||||
-rw-r--r-- | src/lib/shm_rdrbuff.c | 4 |
3 files changed, 127 insertions, 73 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index eefb9b18..38f7cddf 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -87,7 +87,8 @@ static void port_destroy(struct port * p) pthread_mutex_unlock(&p->state_lock); } -static void port_set_state(struct port * p, enum port_state state) +static void port_set_state(struct port * p, + enum port_state state) { pthread_mutex_lock(&p->state_lock); @@ -169,7 +170,8 @@ static qoscube_t spec_to_cube(qosspec_t * spec) } /* FIXME: fill real spec */ -static void fill_qosspec(qosspec_t * spec, qoscube_t cube) +static void fill_qosspec(qosspec_t * spec, + qoscube_t cube) { assert(spec); @@ -235,14 +237,13 @@ static void reset_flow(int fd) ai.flows[fd].cube = QOS_CUBE_BE; } -int ap_init(char * ap_name) +int ap_init(const char * ap_name) { int i = 0; - ap_name = path_strip(ap_name); + assert(ai.ap_name == NULL); ai.api = getpid(); - ai.ap_name = ap_name; ai.daf_name = NULL; ai.fds = bmp_create(AP_MAX_FLOWS, 0); @@ -300,6 +301,28 @@ int ap_init(char * ap_name) return -1; } + if (ap_name != NULL) { + ai.ap_name = strdup(path_strip((char *) ap_name)); + if (ai.ap_name == NULL) { + free(ai.flows); + shm_rdrbuff_close(ai.rdrb); + shm_flow_set_destroy(ai.fqset); + bmp_destroy(ai.fqueues); + bmp_destroy(ai.fds); + return -ENOMEM; + } + + if (api_announce((char *) ai.ap_name)) { + free(ai.ap_name); + free(ai.flows); + shm_rdrbuff_close(ai.rdrb); + shm_flow_set_destroy(ai.fqset); + bmp_destroy(ai.fqueues); + bmp_destroy(ai.fds); + return -1; + } + } + for (i = 0; i < IRMD_MAX_FLOWS; ++i) { ai.ports[i].state = PORT_ID_PENDING; pthread_mutex_init(&ai.ports[i].state_lock, NULL); @@ -309,9 +332,6 @@ int ap_init(char * ap_name) pthread_rwlock_init(&ai.flows_lock, NULL); pthread_rwlock_init(&ai.data_lock, NULL); - if (ap_name != NULL) - return api_announce(ap_name); - return 0; } @@ -323,11 +343,15 @@ void ap_fini() bmp_destroy(ai.fds); bmp_destroy(ai.fqueues); + shm_flow_set_destroy(ai.fqset); if (ai.daf_name != NULL) free(ai.daf_name); + if (ai.ap_name != NULL) + free(ai.ap_name); + pthread_rwlock_rdlock(&ai.flows_lock); for (i = 0; i < AP_MAX_FLOWS; ++i) { @@ -358,7 +382,8 @@ void ap_fini() pthread_rwlock_destroy(&ai.data_lock); } -int flow_accept(char ** ae_name, qosspec_t * spec) +int flow_accept(char ** ae_name, + qosspec_t * spec) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -452,7 +477,8 @@ int flow_accept(char ** ae_name, qosspec_t * spec) return fd; } -int flow_alloc_resp(int fd, int response) +int flow_alloc_resp(int fd, + int response) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -499,7 +525,9 @@ int flow_alloc_resp(int fd, int response) return ret; } -int flow_alloc(char * dst_name, char * src_ae_name, qosspec_t * spec) +int flow_alloc(const char * dst_name, + const char * src_ae_name, + qosspec_t * spec) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -512,8 +540,8 @@ int flow_alloc(char * dst_name, char * src_ae_name, qosspec_t * spec) src_ae_name = UNKNOWN_AE; msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC; - msg.dst_name = dst_name; - msg.ae_name = src_ae_name; + msg.dst_name = (char *) dst_name; + msg.ae_name = (char *) src_ae_name; msg.has_api = true; msg.has_qoscube = true; msg.qoscube = spec_to_cube(spec); @@ -678,7 +706,8 @@ int flow_dealloc(int fd) return 0; } -int flow_set_flags(int fd, int flags) +int flow_set_flags(int fd, + int flags) { int old; @@ -731,7 +760,8 @@ int flow_get_flags(int fd) return old; } -int flow_get_timeout(int fd, struct timespec * timeo) +int flow_get_timeout(int fd, + struct timespec * timeo) { int ret = 0; @@ -758,7 +788,8 @@ int flow_get_timeout(int fd, struct timespec * timeo) return ret; } -int flow_set_timeout(int fd, struct timespec * timeo) +int flow_set_timeout(int fd, + const struct timespec * timeo) { if (fd < 0 || fd >= AP_MAX_FLOWS) return -EINVAL; @@ -785,7 +816,8 @@ int flow_set_timeout(int fd, struct timespec * timeo) return 0; } -int flow_get_qosspec(int fd, qosspec_t * spec) +int flow_get_qosspec(int fd, + qosspec_t * spec) { if (fd < 0 || fd >= AP_MAX_FLOWS || spec == NULL) return -EINVAL; @@ -807,7 +839,9 @@ int flow_get_qosspec(int fd, qosspec_t * spec) return 0; } -ssize_t flow_write(int fd, void * buf, size_t count) +ssize_t flow_write(int fd, + const void * buf, + size_t count) { ssize_t idx; @@ -882,7 +916,9 @@ ssize_t flow_write(int fd, void * buf, size_t count) return 0; } -ssize_t flow_read(int fd, void * buf, size_t count) +ssize_t flow_read(int fd, + void * buf, + size_t count) { ssize_t idx = -1; ssize_t n; @@ -1002,7 +1038,8 @@ void flow_set_zero(struct flow_set * set) pthread_rwlock_unlock(&ai.data_lock); } -int flow_set_add(struct flow_set * set, int fd) +int flow_set_add(struct flow_set * set, + int fd) { int ret; @@ -1020,7 +1057,8 @@ int flow_set_add(struct flow_set * set, int fd) return ret; } -void flow_set_del(struct flow_set * set, int fd) +void flow_set_del(struct flow_set * set, + int fd) { if (set == NULL) return; @@ -1035,7 +1073,8 @@ void flow_set_del(struct flow_set * set, int fd) pthread_rwlock_unlock(&ai.data_lock); } -bool flow_set_has(struct flow_set * set, int fd) +bool flow_set_has(const struct flow_set * set, + int fd) { bool ret = false; @@ -1112,7 +1151,8 @@ int flow_event_wait(struct flow_set * set, /* ipcp-dev functions */ -int np1_flow_alloc(pid_t n_api, int port_id) +int np1_flow_alloc(pid_t n_api, + int port_id) { int fd; @@ -1195,15 +1235,18 @@ int np1_flow_resp(int port_id) return fd; } -int ipcp_create_r(pid_t api) +int ipcp_create_r(pid_t api, + int result) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; int ret = -1; - msg.code = IRM_MSG_CODE__IPCP_CREATE_R; - msg.has_api = true; - msg.api = api; + msg.code = IRM_MSG_CODE__IPCP_CREATE_R; + msg.has_api = true; + msg.api = api; + msg.has_result = true; + msg.result = result; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) @@ -1320,7 +1363,8 @@ int ipcp_flow_req_arr(pid_t api, return fd; } -int ipcp_flow_alloc_reply(int fd, int response) +int ipcp_flow_alloc_reply(int fd, + int response) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -1354,7 +1398,8 @@ int ipcp_flow_alloc_reply(int fd, int response) return ret; } -int ipcp_flow_read(int fd, struct shm_du_buff ** sdb) +int ipcp_flow_read(int fd, + struct shm_du_buff ** sdb) { ssize_t idx = -1; int port_id = -1; @@ -1389,7 +1434,8 @@ int ipcp_flow_read(int fd, struct shm_du_buff ** sdb) return 0; } -int ipcp_flow_write(int fd, struct shm_du_buff * sdb) +int ipcp_flow_write(int fd, + struct shm_du_buff * sdb) { size_t idx; @@ -1442,7 +1488,8 @@ int ipcp_flow_fini(int fd) return 0; } -int ipcp_flow_get_qoscube(int fd, qoscube_t * cube) +int ipcp_flow_get_qoscube(int fd, + qoscube_t * cube) { if (fd < 0 || fd >= AP_MAX_FLOWS || cube == NULL) return -EINVAL; @@ -1479,7 +1526,8 @@ ssize_t local_flow_read(int fd) return ret; } -int local_flow_write(int fd, size_t idx) +int local_flow_write(int fd, + size_t idx) { if (fd < 0) return -EINVAL; @@ -1503,7 +1551,8 @@ int local_flow_write(int fd, size_t idx) return 0; } -int ipcp_read_shim(int fd, struct shm_du_buff ** sdb) +int ipcp_read_shim(int fd, + struct shm_du_buff ** sdb) { ssize_t idx; diff --git a/src/lib/irm.c b/src/lib/irm.c index 477547a2..b610a59e 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -31,7 +31,7 @@ #include <stdlib.h> #include <sys/stat.h> -pid_t irm_create_ipcp(char * name, +pid_t irm_create_ipcp(const char * name, enum ipcp_type ipcp_type) { irm_msg_t msg = IRM_MSG__INIT; @@ -39,7 +39,7 @@ pid_t irm_create_ipcp(char * name, int ret = -1; msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP; - msg.dst_name = name; + msg.dst_name = (char *) name; msg.has_ipcp_type = true; msg.ipcp_type = ipcp_type; @@ -86,8 +86,8 @@ int irm_destroy_ipcp(pid_t api) return ret; } -int irm_bootstrap_ipcp(pid_t api, - struct dif_config * conf) +int irm_bootstrap_ipcp(pid_t api, + const struct dif_config * conf) { irm_msg_t msg = IRM_MSG__INIT; dif_config_msg_t config = DIF_CONFIG_MSG__INIT; @@ -161,8 +161,8 @@ int irm_bootstrap_ipcp(pid_t api, return ret; } -ssize_t irm_list_ipcps(char * name, - pid_t ** apis) +ssize_t irm_list_ipcps(const char * name, + pid_t ** apis) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -173,7 +173,7 @@ ssize_t irm_list_ipcps(char * name, return -EINVAL; msg.code = IRM_MSG_CODE__IRM_LIST_IPCPS; - msg.dst_name = name; + msg.dst_name = (char *) name; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { @@ -202,8 +202,8 @@ ssize_t irm_list_ipcps(char * name, return nr; } -int irm_enroll_ipcp(pid_t api, - char * dif_name) +int irm_enroll_ipcp(pid_t api, + const char * dif_name) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -220,7 +220,7 @@ int irm_enroll_ipcp(pid_t api, if (msg.dif_name == NULL) return -ENOMEM; - msg.dif_name[0] = dif_name; + msg.dif_name[0] = (char *) dif_name; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { @@ -240,7 +240,7 @@ int irm_enroll_ipcp(pid_t api, return ret; } -static int check_ap(char * ap_name) +static int check_ap(const char * ap_name) { struct stat s; @@ -265,6 +265,8 @@ static int check_ap_path(char ** ap_name) bool perm = true; int ret = 0; + assert(ap_name); + if (*ap_name == NULL || path == NULL) return -EINVAL; @@ -320,11 +322,11 @@ static int check_ap_path(char ** ap_name) return -ENOENT; } -int irm_bind_ap(char * ap, - char * name, - uint16_t opts, - int argc, - char ** argv) +int irm_bind_ap(const char * ap, + const char * name, + uint16_t opts, + int argc, + char ** argv) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -344,12 +346,12 @@ int irm_bind_ap(char * ap, } msg.code = IRM_MSG_CODE__IRM_BIND_AP; - msg.dst_name = name; + msg.dst_name = (char *) name; msg.ap_name = full_ap_name; if (argv != NULL) { msg.n_args = argc; - msg.args = argv; + msg.args = (char **) argv; } msg.has_opts = true; @@ -373,7 +375,8 @@ int irm_bind_ap(char * ap, return ret; } -int irm_bind_api(pid_t api, char * name) +int irm_bind_api(pid_t api, + const char * name) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -385,7 +388,7 @@ int irm_bind_api(pid_t api, char * name) msg.code = IRM_MSG_CODE__IRM_BIND_API; msg.has_api = true; msg.api = api; - msg.dst_name = name; + msg.dst_name = (char *) name; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) @@ -402,7 +405,8 @@ int irm_bind_api(pid_t api, char * name) return ret; } -int irm_unbind_ap(char * ap, char * name) +int irm_unbind_ap(const char * ap, + const char * name) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -412,8 +416,8 @@ int irm_unbind_ap(char * ap, char * name) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_UNBIND_AP; - msg.ap_name = ap; - msg.dst_name = name; + msg.ap_name = (char *) ap; + msg.dst_name = (char *) name; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) @@ -430,7 +434,8 @@ int irm_unbind_ap(char * ap, char * name) return ret; } -int irm_unbind_api(pid_t api, char * name) +int irm_unbind_api(pid_t api, + const char * name) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -442,7 +447,7 @@ int irm_unbind_api(pid_t api, char * name) msg.code = IRM_MSG_CODE__IRM_UNBIND_API; msg.has_api = true; msg.api = api; - msg.dst_name = name; + msg.dst_name = (char *) name; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) @@ -459,23 +464,23 @@ int irm_unbind_api(pid_t api, char * name) return ret; } -int irm_reg(char * name, - char ** difs, - size_t difs_size) +int irm_reg(const char * name, + char ** difs, + size_t len) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; int ret = -1; - if (name == NULL || difs == NULL || difs_size == 0) + if (name == NULL || difs == NULL || len == 0) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_REG; - msg.dst_name = name; + msg.dst_name = (char *) name; msg.dif_name = difs; - msg.n_dif_name = difs_size; + msg.n_dif_name = len; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) @@ -493,23 +498,23 @@ int irm_reg(char * name, } -int irm_unreg(char * name, - char ** difs, - size_t difs_size) +int irm_unreg(const char * name, + char ** difs, + size_t len) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; int ret = -1; - if (name == NULL || difs == NULL || difs_size == 0) + if (name == NULL || difs == NULL || len == 0) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_UNREG; - msg.dst_name = name; + msg.dst_name = (char *) name; - msg.dif_name = difs; - msg.n_dif_name = difs_size; + msg.dif_name = (char **) difs; + msg.n_dif_name = len; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c index 55047aa5..eb51a278 100644 --- a/src/lib/shm_rdrbuff.c +++ b/src/lib/shm_rdrbuff.c @@ -321,7 +321,7 @@ void shm_rdrbuff_destroy(struct shm_rdrbuff * rdrb) ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb, size_t headspace, size_t tailspace, - uint8_t * data, + const uint8_t * data, size_t len) { struct shm_du_buff * sdb; @@ -400,7 +400,7 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb, ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb, size_t headspace, size_t tailspace, - uint8_t * data, + const uint8_t * data, size_t len) { struct shm_du_buff * sdb; |