From a14d696bdbc72754e8019fa9579d5a338cc85a05 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Mon, 28 Mar 2016 14:43:16 +0200 Subject: lib: Update irm.h API Removes rina_name_t from that API. Passing ap_name and api_id as params instead. The IRM tool has been updated accordingly. Some errors in the build related to protobuf-c have also been resolved. --- src/lib/sockets.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/lib/sockets.c') diff --git a/src/lib/sockets.c b/src/lib/sockets.c index b157b628..b98f6bbc 100644 --- a/src/lib/sockets.c +++ b/src/lib/sockets.c @@ -166,6 +166,13 @@ struct irm_msg * send_recv_irmd_msg(struct irm_msg * msg) return recv_msg; } + +int send_irm_msg(irm_msg_t * msg) +{ + + return -1; +} + char * ipcp_sock_path(pid_t pid) { char * full_name = NULL; -- cgit v1.2.3 From b144406dbb9cbdf83354590746097a93d6e88bc4 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Mon, 28 Mar 2016 16:04:34 +0200 Subject: lib, irmd: Use GPB for dev.c and IRMd IRMd and dev.c now also use GPB instead of our own ser/des. irm_msg struct has been dropped as well as the methods associated with it. --- include/ouroboros/sockets.h | 49 +---- src/irmd/main.c | 72 +++---- src/lib/dev.c | 125 ++++++------ src/lib/sockets.c | 469 ++++++-------------------------------------- 4 files changed, 155 insertions(+), 560 deletions(-) (limited to 'src/lib/sockets.c') diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h index 69d86cd0..0974ada0 100644 --- a/include/ouroboros/sockets.h +++ b/include/ouroboros/sockets.h @@ -37,47 +37,6 @@ typedef IrmMsg irm_msg_t; #define IPCP_SOCK_PATH_PREFIX "/tmp/ipcp_sock" #define IPCP_MSG_BUFS_SIZE IRM_MSG_BUF_SIZE -enum irm_msg_code { - IRM_CREATE_IPCP, - IRM_DESTROY_IPCP, - IRM_BOOTSTRAP_IPCP, - IRM_ENROLL_IPCP, - IRM_REG_IPCP, - IRM_UNREG_IPCP, - IRM_AP_REG, - IRM_AP_REG_R, - IRM_AP_UNREG, - IRM_FLOW_ACCEPT, - IRM_FLOW_ACCEPT_R, - IRM_FLOW_ALLOC_RESP, - IRM_FLOW_ALLOC, - IRM_FLOW_ALLOC_R, - IRM_FLOW_ALLOC_RES, - IRM_FLOW_ALLOC_RES_R, - IRM_FLOW_DEALLOC, - IRM_FLOW_CONTROL, - IRM_FLOW_WRITE, - IRM_FLOW_READ -}; - -struct irm_msg { - enum irm_msg_code code; - rina_name_t * name; - char * ipcp_type; - struct dif_config * conf; - char * dif_name; - char ** difs; - size_t difs_size; - char * ap_name; - char * ae_name; - int fd; - int result; - struct qos_spec * qos; - int oflags; - char * dst_ap_name; - ssize_t count; -}; - enum ipcp_msg_code { IPCP_BOOTSTRAP, IPCP_ENROLL, @@ -100,16 +59,12 @@ char * ipcp_sock_path(pid_t pid); int server_socket_open(char * file_name); int client_socket_open(char * file_name); -int send_irmd_msg(struct irm_msg * msg); -struct irm_msg * send_recv_irmd_msg(struct irm_msg * msg); - -int send_irm_msg(irm_msg_t * msg); +int send_irm_msg(irm_msg_t * msg); +irm_msg_t * send_recv_irm_msg(irm_msg_t * msg); /* Caller has to free the buffer */ -buffer_t * serialize_irm_msg(struct irm_msg * msg); buffer_t * serialize_ipcp_msg(struct ipcp_msg * msg); /* Caller has to free all the allocated fields in the message */ -struct irm_msg * deserialize_irm_msg(buffer_t * data); struct ipcp_msg * deserialize_ipcp_msg(buffer_t * data); #endif diff --git a/src/irmd/main.c b/src/irmd/main.c index 622b367d..d5e1fcd8 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -124,7 +124,7 @@ static void destroy_ipcp(struct irm * instance, static void bootstrap_ipcp(struct irm * instance, rina_name_t name, - struct dif_config conf) + struct dif_config * conf) { pid_t pid = 0; @@ -134,7 +134,7 @@ static void bootstrap_ipcp(struct irm * instance, return; } - if (ipcp_bootstrap(pid, conf)) + if (ipcp_bootstrap(pid, *conf)) LOG_ERR("Could not bootstrap IPCP"); } @@ -219,10 +219,9 @@ int main() while (true) { int cli_sockfd; - struct irm_msg * msg; + irm_msg_t * msg; ssize_t count; - buffer_t buffer; - int i; + rina_name_t name; cli_sockfd = accept(sockfd, 0, 0); if (cli_sockfd < 0) { @@ -232,59 +231,44 @@ int main() count = read(cli_sockfd, buf, IRM_MSG_BUF_SIZE); if (count > 0) { - buffer.size = count; - buffer.data = buf; - msg = deserialize_irm_msg(&buffer); + msg = irm_msg__unpack(NULL, count, buf); if (msg == NULL) continue; + name.ap_name = msg->ap_name; + name.api_id = msg->api_id; + switch (msg->code) { - case IRM_CREATE_IPCP: - create_ipcp(instance, - *(msg->name), - msg->ipcp_type); - free(msg->ipcp_type); + case IRM_MSG_CODE__IRM_CREATE_IPCP: + create_ipcp(instance, name, msg->ipcp_type); break; - case IRM_DESTROY_IPCP: - destroy_ipcp(instance, - *(msg->name)); + case IRM_MSG_CODE__IRM_DESTROY_IPCP: + destroy_ipcp(instance, name); break; - case IRM_BOOTSTRAP_IPCP: - bootstrap_ipcp(instance, - *(msg->name), - *(msg->conf)); - free(msg->conf); + case IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP: + bootstrap_ipcp(instance, name, NULL); break; - case IRM_ENROLL_IPCP: - enroll_ipcp(instance, - *(msg->name), - msg->dif_name); - free(msg->dif_name); + case IRM_MSG_CODE__IRM_ENROLL_IPCP: + if (msg->n_dif_name != 1) + continue; + enroll_ipcp(instance, name, msg->dif_name[0]); break; - case IRM_REG_IPCP: - reg_ipcp(instance, - *(msg->name), - msg->difs, - msg->difs_size); - for (i = 0; i < msg->difs_size; i++) - free(msg->difs[i]); - free(msg->difs); + case IRM_MSG_CODE__IRM_REG_IPCP: + reg_ipcp(instance, name, + msg->dif_name, + msg->n_dif_name); break; - case IRM_UNREG_IPCP: - unreg_ipcp(instance, - *(msg->name), - msg->difs, - msg->difs_size); - for (i = 0; i < msg->difs_size; i++) - free(msg->difs[i]); - free(msg->difs); + case IRM_MSG_CODE__IRM_UNREG_IPCP: + unreg_ipcp(instance, name, + msg->dif_name, + msg->n_dif_name); break; default: LOG_ERR("Don't know that message code"); break; } - name_destroy(msg->name); - free(msg); + + irm_msg__free_unpacked(msg, NULL); } close(cli_sockfd); diff --git a/src/lib/dev.c b/src/lib/dev.c index 7c0c8a15..5c11d8bf 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -32,30 +32,29 @@ int ap_reg(char * ap_name, char ** difs, size_t difs_size) { - struct irm_msg msg; - struct irm_msg * recv_msg = NULL; + irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; int fd = 0; if (ap_name == NULL || difs == NULL || - difs_size == 0) { - LOG_ERR("Invalid arguments"); - return -1; + difs_size == 0 || + difs[0] == NULL) { + return -EINVAL; } - msg.code = IRM_AP_REG; + msg.code = IRM_MSG_CODE__IRM_AP_REG; msg.ap_name = ap_name; - msg.difs = difs; - msg.difs_size = difs_size; + msg.dif_name = difs; + msg.n_dif_name = difs_size; - recv_msg = send_recv_irmd_msg(&msg); + recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { - LOG_ERR("Failed to send and receive message"); return -1; } fd = recv_msg->fd; - free(recv_msg); + irm_msg__free_unpacked(recv_msg, NULL); return fd; } @@ -64,21 +63,21 @@ int ap_unreg(char * ap_name, char ** difs, size_t difs_size) { - struct irm_msg msg; + irm_msg_t msg = IRM_MSG__INIT; if (ap_name == NULL || difs == NULL || - difs_size == 0) { - LOG_ERR("Invalid arguments"); - return -1; + difs_size == 0 || + difs[0] == NULL) { + return -EINVAL; } - msg.code = IRM_AP_UNREG; + msg.code = IRM_MSG_CODE__IRM_AP_UNREG; msg.ap_name = ap_name; - msg.difs = difs; - msg.difs_size = difs_size; + msg.dif_name = difs; + msg.n_dif_name = difs_size; - if (send_irmd_msg(&msg)) { + if (send_irm_msg(&msg)) { LOG_ERR("Failed to send message to daemon"); return -1; } @@ -90,45 +89,47 @@ int flow_accept(int fd, char * ap_name, char * ae_name) { - struct irm_msg msg; - struct irm_msg * recv_msg = NULL; + irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; int cli_fd = 0; if (ap_name == NULL) { - LOG_ERR("Invalid arguments"); - return -1; + return -EINVAL; } - msg.code = IRM_FLOW_ACCEPT; + msg.code = IRM_MSG_CODE__IRM_FLOW_ACCEPT; + msg.has_fd = true; msg.fd = fd; - recv_msg = send_recv_irmd_msg(&msg); + recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { - LOG_ERR("Failed to send and receive message"); return -1; } + if (recv_msg->has_fd == false) { + irm_msg__free_unpacked(recv_msg, NULL); + return -1; + } cli_fd = recv_msg->fd; ap_name = recv_msg->ap_name; - if (ae_name == NULL) - ae_name = ""; - else - ae_name = recv_msg->ae_name; - free(recv_msg); + ae_name = recv_msg->ae_name; + irm_msg__free_unpacked(recv_msg, NULL); return cli_fd; } int flow_alloc_resp(int fd, int result) { - struct irm_msg msg; + irm_msg_t msg = IRM_MSG__INIT; - msg.code = IRM_FLOW_ALLOC_RESP; + msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC_RESP; + msg.has_fd = true; msg.fd = fd; + msg.has_result = true; msg.result = result; - if (send_irmd_msg(&msg)) { + if (send_irm_msg(&msg)) { LOG_ERR("Failed to send message to daemon"); return -1; } @@ -142,67 +143,74 @@ int flow_alloc(char * dst_ap_name, struct qos_spec * qos, int oflags) { - struct irm_msg msg; - struct irm_msg * recv_msg = NULL; + irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; int fd = 0; if (dst_ap_name == NULL || - src_ap_name == NULL) { + src_ap_name == NULL || + qos == NULL) { LOG_ERR("Invalid arguments"); return -1; } - msg.code = IRM_FLOW_ALLOC; + msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC; msg.dst_ap_name = dst_ap_name; msg.ap_name = src_ap_name; - if (src_ae_name == NULL) - msg.ae_name = ""; - else - msg.ae_name = src_ae_name; - msg.qos = qos; + msg.ae_name = src_ae_name; + msg.has_oflags = true; msg.oflags = oflags; - recv_msg = send_recv_irmd_msg(&msg); + recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { - LOG_ERR("Failed to send and receive message"); return -1; } - fd = recv_msg->fd; - free(recv_msg); + if (recv_msg->has_fd == false) { + irm_msg__free_unpacked(recv_msg, NULL); + return -1; + } + fd = recv_msg->fd; + irm_msg__free_unpacked(recv_msg, NULL); return fd; } int flow_alloc_res(int fd) { - struct irm_msg msg; - struct irm_msg * recv_msg = NULL; + irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; int result = 0; - msg.code = IRM_FLOW_ALLOC_RES; + msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC_RES; + msg.has_fd = true; msg.fd = fd; - recv_msg = send_recv_irmd_msg(&msg); + recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { - LOG_ERR("Failed to send and receive message"); + return -1; + } + + if (recv_msg->has_result == false) { + irm_msg__free_unpacked(recv_msg, NULL); return -1; } result = recv_msg->result; - free(recv_msg); + irm_msg__free_unpacked(recv_msg, NULL); return result; } int flow_dealloc(int fd) { - struct irm_msg msg; + irm_msg_t msg = IRM_MSG__INIT; - msg.code = IRM_FLOW_DEALLOC; + msg.code = IRM_MSG_CODE__IRM_FLOW_DEALLOC; + msg.has_fd = true; msg.fd = fd; - if (send_irmd_msg(&msg)) { + if (send_irm_msg(&msg)) { LOG_ERR("Failed to send message to daemon"); return -1; } @@ -212,12 +220,13 @@ int flow_dealloc(int fd) int flow_cntl(int fd, int oflags) { - struct irm_msg msg; + irm_msg_t msg = IRM_MSG__INIT; + msg.has_fd = true; msg.fd = fd; msg.oflags = oflags; - if (send_irmd_msg(&msg)) { + if (send_irm_msg(&msg)) { LOG_ERR("Failed to send message to daemon"); return -1; } diff --git a/src/lib/sockets.c b/src/lib/sockets.c index b98f6bbc..fcd5d55a 100644 --- a/src/lib/sockets.c +++ b/src/lib/sockets.c @@ -96,83 +96,94 @@ int server_socket_open(char * file_name) return sockfd; } -int send_irmd_msg(struct irm_msg * msg) +int send_irm_msg(irm_msg_t * msg) { - int sockfd; - buffer_t * buf; - - sockfd = client_socket_open(IRM_SOCK_PATH); - if (sockfd < 0) - return -1; - - buf = serialize_irm_msg(msg); - if (buf == NULL) { - close(sockfd); - return -1; - } - - if (write(sockfd, buf->data, buf->size) == -1) { - free(buf->data); - free(buf); - close(sockfd); - return -1; - } - - free(buf->data); - free(buf); - - close(sockfd); - return 0; + int sockfd; + buffer_t buf; + + sockfd = client_socket_open(IRM_SOCK_PATH); + if (sockfd < 0) + return -1; + + buf.size = irm_msg__get_packed_size(msg); + if (buf.size == 0) { + close(sockfd); + return -1; + } + + LOG_DBG("Size will be %lu", buf.size); + buf.data = malloc(buf.size); + if (buf.data == NULL) { + close(sockfd); + return -ENOMEM; + } + + irm_msg__pack(msg, buf.data); + + if (write(sockfd, buf.data, buf.size) == -1) { + free(buf.data); + close(sockfd); + return -1; + } + + free(buf.data); + + close(sockfd); + return 0; } -struct irm_msg * send_recv_irmd_msg(struct irm_msg * msg) +irm_msg_t * send_recv_irm_msg(irm_msg_t * msg) { int sockfd; - buffer_t * buf; + buffer_t buf; ssize_t count = 0; - struct irm_msg * recv_msg = NULL; + irm_msg_t * recv_msg = NULL; sockfd = client_socket_open(IRM_SOCK_PATH); if (sockfd < 0) return NULL; - buf = serialize_irm_msg(msg); - if (buf == NULL) { + buf.size = irm_msg__get_packed_size(msg); + if (buf.size == 0) { close(sockfd); return NULL; } - if (write(sockfd, buf->data, buf->size) == -1) { - free(buf->data); - free(buf); + LOG_DBG("Size will be %lu", buf.size); + buf.data = malloc(buf.size); + if (buf.data == NULL) { close(sockfd); return NULL; } - count = read(sockfd, buf->data, IRM_MSG_BUF_SIZE); - if (count <= 0) { - free(buf->data); - free(buf); + irm_msg__pack(msg, buf.data); + + if (write(sockfd, buf.data, buf.size) == -1) { + free(buf.data); close(sockfd); return NULL; } - recv_msg = deserialize_irm_msg(buf); + count = read(sockfd, buf.data, IRM_MSG_BUF_SIZE); + if (count <= 0) { + free(buf.data); + close(sockfd); + return NULL; + } - free(buf->data); - free(buf); + recv_msg = irm_msg__unpack(NULL, count, buf.data); + if (recv_msg == NULL) { + free(buf.data); + close(sockfd); + return NULL; + } + free(buf.data); close(sockfd); return recv_msg; } -int send_irm_msg(irm_msg_t * msg) -{ - - return -1; -} - char * ipcp_sock_path(pid_t pid) { char * full_name = NULL; @@ -223,16 +234,6 @@ static void ser_copy_value(size_t flen, *offset += flen; } -static void ser_copy_name(rina_name_t * name, - uint8_t * data, - int * offset) -{ - ser_copy_value(strlen(name->ap_name) + 1, - data, name->ap_name, offset); - ser_copy_value(sizeof(int), data, - &name->api_id, offset); -} - static void deser_copy_value(size_t flen, void * dst, void * src, @@ -256,14 +257,6 @@ static int deser_copy_string(uint8_t * data, return 0; } -static void deser_copy_int(uint8_t * data, - unsigned int * dst, - int * offset) -{ - *dst = 0; - deser_copy_value(sizeof(int), dst, data, offset); -} - static void deser_copy_size_t(uint8_t * data, size_t * dst, int * offset) @@ -272,28 +265,6 @@ static void deser_copy_size_t(uint8_t * data, deser_copy_value(sizeof(size_t), dst, data, offset); } -static rina_name_t * deser_copy_name(uint8_t * data, - int * offset) -{ - rina_name_t * name; - - name = name_create(); - if (name == NULL) { - LOG_ERR("Failed to alloc memory"); - return NULL; - } - - if (deser_copy_string(data, &name->ap_name, offset)) { - name_destroy(name); - return NULL; - } - - deser_copy_int(data, &name->api_id, offset); - - return name; -} - - /* Move these to a separate file? */ static buffer_t * buffer_create() { @@ -321,330 +292,6 @@ static void buffer_destroy(buffer_t * buf) free(buf); } -buffer_t * serialize_irm_msg(struct irm_msg * msg) -{ - buffer_t * buf; - uint8_t * data; - int offset = 0; - int i; - char ** pos; - - if (msg == NULL) - return NULL; - - buf = buffer_create(); - if (buf == NULL) - return NULL; - - data = buf->data; - - ser_copy_value(sizeof(enum irm_msg_code), data, &msg->code, &offset); - - ser_copy_name(msg->name, data, &offset); - - switch (msg->code) { - case IRM_CREATE_IPCP: - if (msg->ipcp_type == NULL || - !name_is_ok(msg->name)) { - LOG_ERR("Null pointer passed"); - buffer_destroy(buf); - return NULL; - } - ser_copy_name(msg->name, data, &offset); - ser_copy_value(strlen(msg->ipcp_type) + 1, data, - msg->ipcp_type, &offset); - break; - case IRM_DESTROY_IPCP: - if (!name_is_ok(msg->name)) { - LOG_ERR("Null pointer passed"); - buffer_destroy(buf); - return NULL; - } - ser_copy_name(msg->name, data, &offset); - break; - case IRM_BOOTSTRAP_IPCP: - if (!name_is_ok(msg->name)) { - LOG_ERR("Null pointer passed"); - buffer_destroy(buf); - return NULL; - } - ser_copy_name(msg->name, data, &offset); - /* FIXME: Fields missing, need to define dif_conf properly */ - break; - case IRM_ENROLL_IPCP: - if (msg->dif_name == NULL || - !name_is_ok(msg->name)) { - buffer_destroy(buf); - return NULL; - } - - ser_copy_name(msg->name, data, &offset); - ser_copy_value(strlen(msg->dif_name) + 1, data, - msg->dif_name, &offset); - - break; - case IRM_REG_IPCP: - case IRM_UNREG_IPCP: - if (msg->difs == NULL || - msg->difs[0] == NULL || - !name_is_ok(msg->name)) { - buffer_destroy(buf); - return NULL; - } - - ser_copy_name(msg->name, data, &offset); - - ser_copy_value(sizeof(size_t), data, &msg->difs_size, &offset); - - pos = msg->difs; - for (i = 0; i < msg->difs_size; i++) { - ser_copy_value(strlen(*pos) + 1, data, *pos, &offset); - pos++; - } - - break; - case IRM_AP_REG: - case IRM_AP_UNREG: - if (msg->ap_name == NULL || - msg->difs == NULL || - msg->difs[0] == NULL) { - LOG_ERR("Invalid arguments"); - buffer_destroy(buf); - return NULL; - } - - ser_copy_value(strlen(msg->ap_name) + 1, - data, msg->ap_name, &offset); - - ser_copy_value(sizeof(size_t), data, &msg->difs_size, &offset); - - pos = msg->difs; - for (i = 0; i < msg->difs_size; i++) { - ser_copy_value(strlen(*pos) + 1, data, *pos, &offset); - pos++; - } - - break; - case IRM_FLOW_ACCEPT: - if (msg->ap_name == NULL || - msg->ae_name == NULL) { - LOG_ERR("Invalid arguments"); - buffer_destroy(buf); - return NULL; - } - - ser_copy_value(sizeof(int), data, &msg->fd, &offset); - - ser_copy_value(strlen(msg->ap_name) + 1, - data, msg->ap_name, &offset); - - ser_copy_value(strlen(msg->ae_name) + 1, - data, msg->ae_name, &offset); - - break; - case IRM_FLOW_ALLOC_RESP: - ser_copy_value(sizeof(int), data, &msg->fd, &offset); - - ser_copy_value(sizeof(int), data, &msg->result, &offset); - - break; - case IRM_FLOW_ALLOC: - if (msg->ap_name == NULL || - msg->ae_name == NULL || - msg->dst_ap_name == NULL || - msg->qos == NULL) { - LOG_ERR("Invalid arguments"); - buffer_destroy(buf); - return NULL; - } - - ser_copy_value(strlen(msg->dst_ap_name) + 1, - data, msg->dst_ap_name, &offset); - - ser_copy_value(strlen(msg->ap_name) + 1, - data, msg->ap_name, &offset); - - ser_copy_value(strlen(msg->ae_name) + 1, - data, msg->ae_name, &offset); - - /* FIXME: Serialize qos spec here */ - - ser_copy_value(sizeof(int), data, &msg->oflags, &offset); - - break; - case IRM_FLOW_ALLOC_RES: - case IRM_FLOW_DEALLOC: - ser_copy_value(sizeof(int), data, &msg->fd, &offset); - break; - case IRM_FLOW_CONTROL: - ser_copy_value(sizeof(int), data, &msg->fd, &offset); - ser_copy_value(sizeof(int), data, &msg->oflags, &offset); - break; - case IRM_FLOW_WRITE: - LOG_MISSING; - break; - case IRM_FLOW_READ: - LOG_MISSING; - break; - case IRM_AP_REG_R: - case IRM_FLOW_ALLOC_R: - ser_copy_value(sizeof(int), data, &msg->fd, &offset); - break; - case IRM_FLOW_ACCEPT_R: - ser_copy_value(sizeof(int), data, &msg->fd, &offset); - - ser_copy_value(strlen(msg->ap_name) + 1, - data, msg->ap_name, &offset); - - ser_copy_value(strlen(msg->ae_name) + 1, - data, msg->ae_name, &offset); - break; - case IRM_FLOW_ALLOC_RES_R: - ser_copy_value(sizeof(int), data, &msg->result, &offset); - break; - default: - LOG_ERR("Don't know that code"); - buffer_destroy(buf); - return NULL; - } - - buf->size = offset; - - return buf; -} - -struct irm_msg * deserialize_irm_msg(buffer_t * data) -{ - struct irm_msg * msg; - int i, j; - int offset = 0; - size_t difs_size; - - if (data == NULL || data->data == NULL) { - LOG_ERR("Got a null pointer"); - return NULL; - } - - msg = malloc(sizeof(*msg)); - if (msg == NULL) { - LOG_ERR("Failed to allocate memory"); - return NULL; - } - - deser_copy_value(sizeof(enum irm_msg_code), - &msg->code, data->data, &offset); - - switch (msg->code) { - case IRM_CREATE_IPCP: - msg->name = deser_copy_name(data->data, &offset); - if (msg->name == NULL) { - LOG_ERR("Failed to reconstruct name"); - free(msg); - return NULL; - } - - if (deser_copy_string(data->data, - &msg->ipcp_type, - &offset)) { - name_destroy(msg->name); - free(msg); - return NULL; - } - - break; - case IRM_DESTROY_IPCP: - msg->name = deser_copy_name(data->data, &offset); - if (msg->name == NULL) { - LOG_ERR("Failed to reconstruct name"); - free(msg); - return NULL; - } - - break; - case IRM_BOOTSTRAP_IPCP: - msg->name = deser_copy_name(data->data, &offset); - if (msg->name == NULL) { - LOG_ERR("Failed to reconstruct name"); - free(msg); - return NULL; - } - - break; - case IRM_ENROLL_IPCP: - msg->name = deser_copy_name(data->data, &offset); - if (msg->name == NULL) { - LOG_ERR("Failed to reconstruct name"); - free(msg); - return NULL; - } - - if (deser_copy_string(data->data, - &msg->dif_name, - &offset)) { - name_destroy(msg->name); - free(msg); - return NULL; - } - - break; - case IRM_REG_IPCP: - case IRM_UNREG_IPCP: - msg->name = deser_copy_name(data->data, &offset); - if (msg->name == NULL) { - LOG_ERR("Failed to reconstruct name"); - free(msg); - return NULL; - } - - deser_copy_size_t(data->data, &difs_size, &offset); - msg->difs_size = difs_size; - - msg->difs = malloc(sizeof(*(msg->difs)) * difs_size); - if (msg->difs == NULL) { - name_destroy(msg->name); - free(msg); - return NULL; - } - - for (i = 0; i < difs_size; i++) { - if (deser_copy_string(data->data, - &msg->difs[i], - &offset)) { - for (j = 0; j < i; j++) - free(msg->difs[j]); - free(msg->difs); - name_destroy(msg->name); - free(msg); - return NULL; - } - } - - break; - case IRM_AP_REG: - case IRM_AP_REG_R: - case IRM_AP_UNREG: - case IRM_FLOW_ACCEPT: - case IRM_FLOW_ACCEPT_R: - case IRM_FLOW_ALLOC_RESP: - case IRM_FLOW_ALLOC: - case IRM_FLOW_ALLOC_R: - case IRM_FLOW_ALLOC_RES: - case IRM_FLOW_ALLOC_RES_R: - case IRM_FLOW_DEALLOC: - case IRM_FLOW_CONTROL: - case IRM_FLOW_WRITE: - case IRM_FLOW_READ: - LOG_MISSING; - break; - default: - LOG_ERR("Don't know that code"); - free(msg); - return NULL; - } - - return msg; -} - buffer_t * serialize_ipcp_msg(struct ipcp_msg * msg) { buffer_t * buf = NULL; -- cgit v1.2.3 From c45be0dcbd123881cc33ce61571578dcb22c3b54 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Mon, 28 Mar 2016 16:35:40 +0200 Subject: lib: Add ipcp_messages proto file This removes the custom ser/des methods for communicating with the IPCP daemon and also uses GPB instead. --- include/ouroboros/ipcp.h | 20 ++-- include/ouroboros/sockets.h | 34 ++---- src/irmd/main.c | 2 +- src/lib/CMakeLists.txt | 52 ++++----- src/lib/ipcp.c | 94 ++++++++++------- src/lib/ipcpd_messages.proto | 14 +++ src/lib/sockets.c | 245 ------------------------------------------- 7 files changed, 115 insertions(+), 346 deletions(-) create mode 100644 src/lib/ipcpd_messages.proto (limited to 'src/lib/sockets.c') diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h index b8775fc0..cd4a3f51 100644 --- a/include/ouroboros/ipcp.h +++ b/include/ouroboros/ipcp.h @@ -32,21 +32,21 @@ struct ipcp; /* Returns the process id */ pid_t ipcp_create(rina_name_t name, - char * ipcp_type); + char * ipcp_type); int ipcp_destroy(pid_t pid); -int ipcp_reg(pid_t pid, +int ipcp_reg(pid_t pid, char ** difs, - size_t difs_size); -int ipcp_unreg(pid_t pid, + size_t difs_size); +int ipcp_unreg(pid_t pid, char ** difs, - size_t difs_size); + size_t difs_size); -int ipcp_bootstrap(pid_t pid, - struct dif_config conf); -int ipcp_enroll(pid_t pid, - char * dif_name, - char * member_name, +int ipcp_bootstrap(pid_t pid, + struct dif_config * conf); +int ipcp_enroll(pid_t pid, + char * dif_name, + char * member_name, char ** n_1_difs, ssize_t n_1_difs_size); diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h index 0974ada0..bb8e6d84 100644 --- a/include/ouroboros/sockets.h +++ b/include/ouroboros/sockets.h @@ -31,40 +31,22 @@ #include "irmd_messages.pb-c.h" typedef IrmMsg irm_msg_t; +#include "ipcpd_messages.pb-c.h" +typedef IpcpMsg ipcp_msg_t; + #define IRM_SOCK_PATH "/tmp/irm_sock" #define IRM_MSG_BUF_SIZE 256 #define IPCP_SOCK_PATH_PREFIX "/tmp/ipcp_sock" #define IPCP_MSG_BUFS_SIZE IRM_MSG_BUF_SIZE -enum ipcp_msg_code { - IPCP_BOOTSTRAP, - IPCP_ENROLL, - IPCP_REG, - IPCP_UNREG -}; - -struct ipcp_msg { - enum ipcp_msg_code code; - struct dif_config * conf; - char * dif_name; - char * ap_name; - char ** difs; - size_t difs_size; -}; - /* Returns the full socket path of an IPCP */ -char * ipcp_sock_path(pid_t pid); - -int server_socket_open(char * file_name); -int client_socket_open(char * file_name); +char * ipcp_sock_path(pid_t pid); -int send_irm_msg(irm_msg_t * msg); -irm_msg_t * send_recv_irm_msg(irm_msg_t * msg); +int server_socket_open(char * file_name); +int client_socket_open(char * file_name); -/* Caller has to free the buffer */ -buffer_t * serialize_ipcp_msg(struct ipcp_msg * msg); -/* Caller has to free all the allocated fields in the message */ -struct ipcp_msg * deserialize_ipcp_msg(buffer_t * data); +int send_irm_msg(irm_msg_t * msg); +irm_msg_t * send_recv_irm_msg(irm_msg_t * msg); #endif diff --git a/src/irmd/main.c b/src/irmd/main.c index d5e1fcd8..e4b6cebd 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -134,7 +134,7 @@ static void bootstrap_ipcp(struct irm * instance, return; } - if (ipcp_bootstrap(pid, *conf)) + if (ipcp_bootstrap(pid, conf)) LOG_ERR("Could not bootstrap IPCP"); } diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 0427e236..52061645 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -3,48 +3,48 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_BINARY_DIR}/include) -find_package(ProtobufC REQUIRED) +find_package(ProtobufC REQUIRED) include_directories(${PROTOBUF_INCLUDE_DIRS}) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -protobuf_generate_c(PROTO_SRCS PROTO_HDRS irmd_messages.proto) +protobuf_generate_c(IRM_PROTO_SRCS IRM_PROTO_HDRS irmd_messages.proto) +protobuf_generate_c(IPCP_PROTO_SRCS IPCP_PROTO_HDRS ipcpd_messages.proto) find_library(LIBRT_LIBRARIES rt) if(NOT LIBRT_LIBRARIES) - message(FATAL_ERROR "librt not found") + message(FATAL_ERROR "librt not found") endif() find_library(LIBPTHREAD_LIBRARIES pthread) if(NOT LIBPTHREAD_LIBRARIES) - message(FATAL_ERROR "libpthread not found") + message(FATAL_ERROR "libpthread not found") endif() set(SOURCE_FILES - # Add source files here - bitmap.c - cdap.c - da.c - dev.c - du_buff.c - ipcp.c - irm.c - list.c - rina_name.c - shm_du_map.c - sockets.c - utils.c - ) - -install(FILES ${PROTO_HDRS} - DESTINATION include/ouroboros) - -add_library(ouroboros SHARED ${SOURCE_FILES} ${PROTO_SRCS}) + # Add source files here + bitmap.c + cdap.c + da.c + dev.c + du_buff.c + ipcp.c + irm.c + list.c + rina_name.c + shm_du_map.c + sockets.c + utils.c + ) + +install(FILES ${IRM_PROTO_HDRS} ${IPCP_PROTO_HDRS} + DESTINATION include/ouroboros) + +add_library(ouroboros SHARED ${SOURCE_FILES} + ${IRM_PROTO_SRCS} ${IPCP_PROTO_SRCS}) target_link_libraries(ouroboros rt pthread ${PROTOBUF_C_LIBRARY}) include(MacroAddCompileFlags) if (CMAKE_BUILD_TYPE MATCHES Debug) - MACRO_ADD_COMPILE_FLAGS(ouroboros -DCONFIG_OUROBOROS_DEBUG) + MACRO_ADD_COMPILE_FLAGS(ouroboros -DCONFIG_OUROBOROS_DEBUG) endif (CMAKE_BUILD_TYPE MATCHES Debug) install(TARGETS ouroboros LIBRARY DESTINATION lib) diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c index 53d717ba..445160f0 100644 --- a/src/lib/ipcp.c +++ b/src/lib/ipcp.c @@ -40,10 +40,10 @@ #include static int send_ipcp_msg(pid_t pid, - struct ipcp_msg * msg) + ipcp_msg_t * msg) { int sockfd = 0; - buffer_t * buf = NULL; + buffer_t buf; char * sock_path; sock_path = ipcp_sock_path(pid); @@ -56,24 +56,31 @@ static int send_ipcp_msg(pid_t pid, return -1; } - buf = serialize_ipcp_msg(msg); - if (buf == NULL) { - free(sock_path); + buf.size = ipcp_msg__get_packed_size(msg); + if (buf.size == 0) { close(sockfd); + free(sock_path); return -1; } - if (write(sockfd, buf->data, buf->size) == -1) { + buf.data = malloc(buf.size); + if (buf.data == NULL) { + close(sockfd); + free(sock_path); + return -ENOMEM; + } + + ipcp_msg__pack(msg, buf.data); + + if (write(sockfd, buf.data, buf.size) == -1) { free(sock_path); - free(buf->data); - free(buf); + free(buf.data); close(sockfd); return -1; } - free(buf->data); - free(buf); - + free(buf.data); + free(sock_path); close(sockfd); return 0; } @@ -158,14 +165,16 @@ int ipcp_reg(pid_t pid, char ** difs, size_t difs_size) { - struct ipcp_msg msg; + ipcp_msg_t msg = IPCP_MSG__INIT; - if (difs == NULL) - return -1; + if (difs == NULL || + difs_size == 0 || + difs[0] == NULL) + return -EINVAL; - msg.code = IPCP_REG; - msg.difs = difs; - msg.difs_size = difs_size; + msg.code = IPCP_MSG_CODE__IPCP_REG; + msg.dif_name = difs; + msg.n_dif_name = difs_size; if (send_ipcp_msg(pid, &msg)) { LOG_ERR("Failed to send message to daemon"); @@ -179,14 +188,16 @@ int ipcp_unreg(pid_t pid, char ** difs, size_t difs_size) { - struct ipcp_msg msg; + ipcp_msg_t msg = IPCP_MSG__INIT; - if (difs == NULL) - return -1; + if (difs == NULL || + difs_size == 0 || + difs[0] == NULL) + return -EINVAL; - msg.code = IPCP_UNREG; - msg.difs = difs; - msg.difs_size = difs_size; + msg.code = IPCP_MSG_CODE__IPCP_UNREG; + msg.dif_name = difs; + msg.n_dif_name = difs_size; if (send_ipcp_msg(pid, &msg)) { LOG_ERR("Failed to send message to daemon"); @@ -197,12 +208,11 @@ int ipcp_unreg(pid_t pid, } int ipcp_bootstrap(pid_t pid, - struct dif_config conf) + struct dif_config * conf) { - struct ipcp_msg msg; + ipcp_msg_t msg = IPCP_MSG__INIT; - msg.code = IPCP_BOOTSTRAP; - msg.conf = &conf; + msg.code = IPCP_MSG_CODE__IPCP_BOOTSTRAP; if (send_ipcp_msg(pid, &msg)) { LOG_ERR("Failed to send message to daemon"); @@ -218,24 +228,32 @@ int ipcp_enroll(pid_t pid, char ** n_1_difs, ssize_t n_1_difs_size) { - struct ipcp_msg msg; - - if (n_1_difs == NULL) - return -1; - - if (dif_name == NULL) + ipcp_msg_t msg = IPCP_MSG__INIT; + + if (n_1_difs == NULL || + n_1_difs_size == 0 || + n_1_difs[0] == NULL || + dif_name == NULL || + member_name == NULL) + return -EINVAL; + + msg.code = IPCP_MSG_CODE__IPCP_ENROLL; + msg.dif_name = malloc(sizeof(*(msg.dif_name))); + if (msg.dif_name == NULL) { + LOG_ERR("Failed to malloc"); return -1; - - msg.code = IPCP_ENROLL; - msg.dif_name = dif_name; + } + msg.dif_name[0] = dif_name; msg.ap_name = member_name; - msg.difs = n_1_difs; - msg.difs_size = n_1_difs_size; + msg.n_1_dif_name = n_1_difs; + msg.n_n_1_dif_name = n_1_difs_size; if (send_ipcp_msg(pid, &msg)) { LOG_ERR("Failed to send message to daemon"); + free(msg.dif_name); return -1; } + free(msg.dif_name); return 0; } diff --git a/src/lib/ipcpd_messages.proto b/src/lib/ipcpd_messages.proto new file mode 100644 index 00000000..0715fbe0 --- /dev/null +++ b/src/lib/ipcpd_messages.proto @@ -0,0 +1,14 @@ +enum ipcp_msg_code { + IPCP_BOOTSTRAP = 1; + IPCP_ENROLL = 2; + IPCP_REG = 3; + IPCP_UNREG = 4; +}; + +message ipcp_msg { + required ipcp_msg_code code = 1; + optional string ap_name = 2; + // Missing dif_config field here + repeated string dif_name = 4; + repeated string n_1_dif_name = 5; +}; diff --git a/src/lib/sockets.c b/src/lib/sockets.c index fcd5d55a..a699206d 100644 --- a/src/lib/sockets.c +++ b/src/lib/sockets.c @@ -111,7 +111,6 @@ int send_irm_msg(irm_msg_t * msg) return -1; } - LOG_DBG("Size will be %lu", buf.size); buf.data = malloc(buf.size); if (buf.data == NULL) { close(sockfd); @@ -214,247 +213,3 @@ char * ipcp_sock_path(pid_t pid) return full_name; } - -static int serialized_string_len(uint8_t * data) -{ - uint8_t * seek = data; - - while (*seek != '\0') - seek++; - - return (seek - data) + 1; -} - -static void ser_copy_value(size_t flen, - void * dst, - void * src, - int * offset) -{ - memcpy(dst + *offset, src, flen); - *offset += flen; -} - -static void deser_copy_value(size_t flen, - void * dst, - void * src, - int * offset) -{ - memcpy(dst, src + *offset, flen); - *offset += flen; -} - -static int deser_copy_string(uint8_t * data, - char ** dst, - int * offset) -{ - size_t flen; - - flen = serialized_string_len(data + *offset); - *dst = malloc(sizeof(**dst) * (flen + 1)); - if (*dst == NULL) - return -1; - deser_copy_value(flen, *dst, data, offset); - return 0; -} - -static void deser_copy_size_t(uint8_t * data, - size_t * dst, - int * offset) -{ - *dst = 0; - deser_copy_value(sizeof(size_t), dst, data, offset); -} - -/* Move these to a separate file? */ -static buffer_t * buffer_create() -{ - buffer_t * buf; - - buf = malloc(sizeof(*buf)); - if (buf == NULL) - return NULL; - - buf->data = malloc(IRM_MSG_BUF_SIZE); - if (buf->data == NULL) { - free(buf); - return NULL; - } - - return buf; -} - -static void buffer_destroy(buffer_t * buf) -{ - if (buf->data != NULL) - free(buf->data); - - if (buf != NULL) - free(buf); -} - -buffer_t * serialize_ipcp_msg(struct ipcp_msg * msg) -{ - buffer_t * buf = NULL; - uint8_t * data = NULL; - int offset = 0; - char ** pos = NULL; - int i = 0; - - if (msg == NULL) - return NULL; - - buf = buffer_create(); - if (buf == NULL) - return NULL; - - data = buf->data; - - ser_copy_value(sizeof(enum ipcp_msg_code), - data, &msg->code, &offset); - - switch (msg->code) { - case IPCP_BOOTSTRAP: - break; - case IPCP_ENROLL: - if (msg->dif_name == NULL) { - buffer_destroy(buf); - return NULL; - } - - ser_copy_value(strlen(msg->dif_name) + 1, data, - msg->dif_name, &offset); - - if (msg->ap_name == NULL) { - LOG_ERR("Null pointer passed"); - buffer_destroy(buf); - return NULL; - } - ser_copy_value(strlen(msg->ap_name) + 1, data, - msg->ap_name, &offset); - - /* All these operations end with a list of DIFs */ - case IPCP_REG: - case IPCP_UNREG: - if (msg->difs == NULL || msg->difs[0] == NULL) { - buffer_destroy(buf); - return NULL; - } - - ser_copy_value(sizeof(size_t), data, &msg->difs_size, &offset); - - pos = msg->difs; - for (i = 0; i < msg->difs_size; i++) { - ser_copy_value(strlen(*pos) + 1, data, *pos, &offset); - pos++; - } - break; - default: - LOG_ERR("Don't know that code"); - buffer_destroy(buf); - return NULL; - } - - buf->size = offset; - - return buf; -} - -struct ipcp_msg * deserialize_ipcp_msg(buffer_t * data) -{ - struct ipcp_msg * msg; - int i, j; - int offset = 0; - size_t difs_size; - - if (data == NULL || data->data == NULL) { - LOG_ERR("Got a null pointer"); - return NULL; - } - - msg = malloc(sizeof(*msg)); - if (msg == NULL) { - LOG_ERR("Failed to allocate memory"); - return NULL; - } - - deser_copy_value(sizeof(enum ipcp_msg_code), - &msg->code, data->data, &offset); - - switch (msg->code) { - case IPCP_BOOTSTRAP: - break; - case IPCP_ENROLL: - if (deser_copy_string(data->data, - &msg->dif_name, - &offset)) { - free(msg); - return NULL; - } - - deser_copy_string(data->data, - &msg->ap_name, - &offset); - if (msg->ap_name == NULL) { - LOG_ERR("Failed to reconstruct name"); - free(msg->dif_name); - free(msg); - return NULL; - } - - deser_copy_size_t(data->data, &difs_size, &offset); - msg->difs_size = difs_size; - - msg->difs = malloc(sizeof(*(msg->difs)) * difs_size); - if (msg->difs == NULL) { - free(msg->ap_name); - free(msg->dif_name); - free(msg); - return NULL; - } - - for (i = 0; i < difs_size; i++) { - if (deser_copy_string(data->data, - &msg->difs[i], - &offset)) { - for (j = 0; j < i; j++) - free(msg->difs[j]); - free(msg->dif_name); - free(msg->difs); - free(msg->ap_name); - free(msg); - return NULL; - } - } - break; - case IPCP_REG: - case IPCP_UNREG: - deser_copy_size_t(data->data, &difs_size, &offset); - msg->difs_size = difs_size; - - msg->difs = malloc(sizeof(*(msg->difs)) * difs_size); - if (msg->difs == NULL) { - free(msg); - return NULL; - } - - for (i = 0; i < difs_size; i++) { - if (deser_copy_string(data->data, - &msg->difs[i], - &offset)) { - for (j = 0; j < i; j++) - free(msg->difs[j]); - free(msg->difs); - free(msg); - return NULL; - } - } - - break; - default: - LOG_ERR("Don't know that code"); - free(msg); - return NULL; - } - - return msg; -} -- cgit v1.2.3 From 08941177f030b77fb44238a7e589322d2e0fcaa2 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Wed, 30 Mar 2016 17:25:30 +0200 Subject: lib, irmd: Update communication with IRMd All messages sent to the IRMd now also get a reply back with the result of the operation. --- include/ouroboros/config.h.in | 9 +- include/ouroboros/shm_du_map.h | 4 - include/ouroboros/sockets.h | 1 - src/irmd/main.c | 311 +++++++++++++++++++++++++++++----------- src/lib/dev.c | 78 +++++++--- src/lib/ipcp.c | 8 +- src/lib/irm.c | 92 +++++++++--- src/lib/irmd_messages.proto | 23 ++- src/lib/sockets.c | 35 ----- src/lib/tests/shm_du_map_test.c | 1 + 10 files changed, 379 insertions(+), 183 deletions(-) (limited to 'src/lib/sockets.c') diff --git a/include/ouroboros/config.h.in b/include/ouroboros/config.h.in index 0f5c2131..01d7888e 100644 --- a/include/ouroboros/config.h.in +++ b/include/ouroboros/config.h.in @@ -23,9 +23,10 @@ #ifndef OUROBOROS_CONFIG #define OUROBOROS_CONFIG -#define PROJECT_NAME "@CMAKE_PROJECT_NAME@" -#define PROJECT_VERSION "@PACKAGE_VERSION@" -#define INSTALL_DIR "@CMAKE_INSTALL_PREFIX@" -#define BUILD_TYPE "@CMAKE_BUILD_TYPE@" +#define PROJECT_NAME "@CMAKE_PROJECT_NAME@" +#define PROJECT_VERSION "@PACKAGE_VERSION@" +#define INSTALL_DIR "@CMAKE_INSTALL_PREFIX@" +#define BUILD_TYPE "@CMAKE_BUILD_TYPE@" +#define _POSIX_C_SOURCE 199506L #endif diff --git a/include/ouroboros/shm_du_map.h b/include/ouroboros/shm_du_map.h index 68492a91..fb51768d 100644 --- a/include/ouroboros/shm_du_map.h +++ b/include/ouroboros/shm_du_map.h @@ -24,10 +24,6 @@ #ifndef OUROBOROS_SHM_DU_MAP_H #define OUROBOROS_SHM_DU_MAP_H -#ifndef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 199506L -#endif - #ifndef SHM_DU_BUFF_BLOCK_SIZE #define SHM_DU_BUFF_BLOCK_SIZE sysconf(_SC_PAGESIZE) #endif diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h index 4c736de2..9904eecd 100644 --- a/include/ouroboros/sockets.h +++ b/include/ouroboros/sockets.h @@ -45,7 +45,6 @@ char * ipcp_sock_path(pid_t pid); int server_socket_open(char * file_name); int client_socket_open(char * file_name); -int send_irm_msg(irm_msg_t * msg); irm_msg_t * send_recv_irm_msg(irm_msg_t * msg); #endif diff --git a/src/irmd/main.c b/src/irmd/main.c index 547286e8..af0f85e2 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -46,8 +46,9 @@ struct irm { struct list_head name_to_pid; }; -static pid_t find_pid_by_name(struct irm * instance, - instance_name_t * api) +struct irm * instance = NULL; + +static pid_t find_pid_by_name(instance_name_t * api) { struct list_head * pos; @@ -64,9 +65,8 @@ static pid_t find_pid_by_name(struct irm * instance, return 0; } -static void create_ipcp(struct irm * instance, - instance_name_t * api, - char * ipcp_type) +static int create_ipcp(instance_name_t * api, + char * ipcp_type) { pid_t pid; struct name_to_pid_entry * tmp; @@ -74,12 +74,12 @@ static void create_ipcp(struct irm * instance, pid = ipcp_create(api, ipcp_type); if (pid == -1) { LOG_ERR("Failed to create IPCP"); - return; + return -1; } tmp = malloc(sizeof(*tmp)); if (tmp == NULL) - return; + return -1; INIT_LIST_HEAD(&tmp->next); @@ -87,25 +87,25 @@ static void create_ipcp(struct irm * instance, tmp->api = instance_name_dup(api); if (tmp->api == NULL) { free(tmp); - return; + return -1; } LOG_DBG("Created IPC process with pid %d", pid); list_add(&tmp->next, &instance->name_to_pid); + return 0; } -static void destroy_ipcp(struct irm * instance, - instance_name_t * api) +static int destroy_ipcp(instance_name_t * api) { pid_t pid = 0; struct list_head * pos; struct list_head * n; - pid = find_pid_by_name(instance, api); + pid = find_pid_by_name(api); if (pid == 0) { LOG_ERR("No such IPCP"); - return; + return -1; } LOG_DBG("Destroying ipcp with pid %d", pid); @@ -120,92 +120,159 @@ static void destroy_ipcp(struct irm * instance, if (instance_name_cmp(api, tmp->api) == 0) list_del(&tmp->next); } + + return 0; } -static void bootstrap_ipcp(struct irm * instance, - instance_name_t * api, - struct dif_config * conf) +static int bootstrap_ipcp(instance_name_t * api, + struct dif_config * conf) { pid_t pid = 0; - pid = find_pid_by_name(instance, api); + pid = find_pid_by_name(api); if (pid == 0) { LOG_ERR("No such IPCP"); - return; + return -1; } - if (ipcp_bootstrap(pid, conf)) + if (ipcp_bootstrap(pid, conf)) { LOG_ERR("Could not bootstrap IPCP"); + return -1; + } + + return 0; } -static void enroll_ipcp(struct irm * instance, - instance_name_t * api, - char * dif_name) +static int enroll_ipcp(instance_name_t * api, + char * dif_name) { pid_t pid = 0; char * member; char ** n_1_difs = NULL; ssize_t n_1_difs_size = 0; - pid = find_pid_by_name(instance, api); + pid = find_pid_by_name(api); if (pid == 0) { LOG_ERR("No such IPCP"); - return; + return -1; } member = da_resolve_daf(dif_name); if (member == NULL) { LOG_ERR("Could not find a member of that DIF"); - return; + return -1; } n_1_difs_size = da_resolve_dap(member, n_1_difs); if (n_1_difs_size != 0) if (ipcp_enroll(pid, dif_name, member, - n_1_difs, n_1_difs_size)) + n_1_difs, n_1_difs_size)) { LOG_ERR("Could not enroll IPCP"); + return -1; + } + + return 0; } -static void reg_ipcp(struct irm * instance, - instance_name_t * api, - char ** difs, - size_t difs_size) +static int reg_ipcp(instance_name_t * api, + char ** difs, + size_t difs_size) { pid_t pid = 0; - pid = find_pid_by_name(instance, api); + pid = find_pid_by_name(api); if (pid == 0) { LOG_ERR("No such IPCP"); - return; + return -1; } - if (ipcp_reg(pid, difs, difs_size)) + if (ipcp_reg(pid, difs, difs_size)) { LOG_ERR("Could not register IPCP to N-1 DIF(s)"); + return -1; + } + + return 0; } -static void unreg_ipcp(struct irm * instance, - instance_name_t * api, - char ** difs, - size_t difs_size) +static int unreg_ipcp(instance_name_t * api, + char ** difs, + size_t difs_size) { pid_t pid = 0; - pid = find_pid_by_name(instance, api); + pid = find_pid_by_name(api); if (pid == 0) { LOG_ERR("No such IPCP"); - return; + return -1; } - if (ipcp_unreg(pid, difs, difs_size)) + if (ipcp_unreg(pid, difs, difs_size)) { LOG_ERR("Could not unregister IPCP from N-1 DIF(s)"); + return -1; + } + + return 0; +} + +static int ap_reg(char * ap_name, + char ** difs, + size_t difs_size) +{ + return -1; +} + +static int ap_unreg(char * ap_name, + char ** difs, + size_t difs_size) +{ + return -1; +} + +static int flow_accept(int fd, + char * ap_name, + char * ae_name) +{ + return -1; +} + +static int flow_alloc_resp(int fd, + int result) +{ + + return -1; +} + +static int flow_alloc(char * dst_ap_name, + char * src_ap_name, + char * src_ae_name, + struct qos_spec * qos, + int oflags) +{ + return -1; +} + +static int flow_alloc_res(int fd) +{ + + return -1; +} + +static int flow_dealloc(int fd) +{ + return -1; +} + +static int flow_cntl(int fd, + int oflags) +{ + return -1; } /* FIXME: Close sockfd on closing and release irm */ int main() { - struct irm * instance = NULL; - int sockfd; - uint8_t buf[IRM_MSG_BUF_SIZE]; + int sockfd; + uint8_t buf[IRM_MSG_BUF_SIZE]; instance = malloc(sizeof(*instance)); if (instance == NULL) @@ -222,6 +289,10 @@ int main() irm_msg_t * msg; ssize_t count; instance_name_t api; + buffer_t buffer; + irm_msg_t ret_msg = IRM_MSG__INIT; + + ret_msg.code = IRM_MSG_CODE__IRM_REPLY; cli_sockfd = accept(sockfd, 0, 0); if (cli_sockfd < 0) { @@ -230,47 +301,125 @@ int main() } count = read(cli_sockfd, buf, IRM_MSG_BUF_SIZE); - if (count > 0) { - msg = irm_msg__unpack(NULL, count, buf); - if (msg == NULL) - continue; - - api.name = msg->ap_name; - api.id = msg->api_id; - - switch (msg->code) { - case IRM_MSG_CODE__IRM_CREATE_IPCP: - create_ipcp(instance, &api, msg->ipcp_type); - break; - case IRM_MSG_CODE__IRM_DESTROY_IPCP: - destroy_ipcp(instance, &api); - break; - case IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP: - bootstrap_ipcp(instance, &api, NULL); - break; - case IRM_MSG_CODE__IRM_ENROLL_IPCP: - if (msg->n_dif_name != 1) - continue; - enroll_ipcp(instance, &api, msg->dif_name[0]); - break; - case IRM_MSG_CODE__IRM_REG_IPCP: - reg_ipcp(instance, &api, - msg->dif_name, - msg->n_dif_name); - break; - case IRM_MSG_CODE__IRM_UNREG_IPCP: - unreg_ipcp(instance, &api, - msg->dif_name, - msg->n_dif_name); - break; - default: - LOG_ERR("Don't know that message code"); - break; - } - - irm_msg__free_unpacked(msg, NULL); + if (count <= 0) { + LOG_ERR("Failed to read from socket"); + close(cli_sockfd); + continue; + } + + msg = irm_msg__unpack(NULL, count, buf); + if (msg == NULL) { + close(cli_sockfd); + continue; + } + + api.name = msg->ap_name; + api.id = msg->api_id; + + switch (msg->code) { + case IRM_MSG_CODE__IRM_CREATE_IPCP: + ret_msg.has_result = true; + ret_msg.result = create_ipcp(&api, + msg->ipcp_type); + break; + case IRM_MSG_CODE__IRM_DESTROY_IPCP: + ret_msg.has_result = true; + ret_msg.result = destroy_ipcp(&api); + break; + case IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP: + ret_msg.has_result = true; + ret_msg.result = bootstrap_ipcp(&api, NULL); + break; + case IRM_MSG_CODE__IRM_ENROLL_IPCP: + ret_msg.has_result = true; + ret_msg.result = enroll_ipcp(&api, + msg->dif_name[0]); + break; + case IRM_MSG_CODE__IRM_REG_IPCP: + ret_msg.has_result = true; + ret_msg.result = reg_ipcp(&api, + msg->dif_name, + msg->n_dif_name); + break; + case IRM_MSG_CODE__IRM_UNREG_IPCP: + ret_msg.has_result = true; + ret_msg.result = unreg_ipcp(&api, + msg->dif_name, + msg->n_dif_name); + break; + case IRM_MSG_CODE__IRM_AP_REG: + ret_msg.has_fd = true; + ret_msg.fd = ap_reg(msg->ap_name, + msg->dif_name, + msg->n_dif_name); + break; + case IRM_MSG_CODE__IRM_AP_UNREG: + ret_msg.has_result = true; + ret_msg.result = ap_unreg(msg->ap_name, + msg->dif_name, + msg->n_dif_name); + break; + case IRM_MSG_CODE__IRM_FLOW_ACCEPT: + ret_msg.has_fd = true; + ret_msg.fd = flow_accept(msg->fd, + ret_msg.ap_name, + ret_msg.ae_name); + break; + case IRM_MSG_CODE__IRM_FLOW_ALLOC_RESP: + ret_msg.has_result = true; + ret_msg.result = flow_alloc_resp(msg->fd, + msg->result); + break; + case IRM_MSG_CODE__IRM_FLOW_ALLOC: + ret_msg.has_fd = true; + ret_msg.fd = flow_alloc(msg->dst_ap_name, + msg->ap_name, + msg->ae_name, + NULL, + msg->oflags); + break; + case IRM_MSG_CODE__IRM_FLOW_ALLOC_RES: + ret_msg.has_result = true; + ret_msg.result = flow_alloc_res(msg->fd); + break; + case IRM_MSG_CODE__IRM_FLOW_DEALLOC: + ret_msg.has_result = true; + ret_msg.result = flow_dealloc(msg->fd); + break; + case IRM_MSG_CODE__IRM_FLOW_CONTROL: + ret_msg.has_result = true; + ret_msg.result = flow_cntl(msg->fd, + msg->oflags); + break; + default: + LOG_ERR("Don't know that message code"); + break; + } + + irm_msg__free_unpacked(msg, NULL); + + buffer.size = irm_msg__get_packed_size(&ret_msg); + if (buffer.size == 0) { + LOG_ERR("Failed to send reply message"); + close(cli_sockfd); + continue; + } + + buffer.data = malloc(buffer.size); + if (buffer.data == NULL) { + close(cli_sockfd); + continue; + } + + irm_msg__pack(&ret_msg, buffer.data); + + if (write(cli_sockfd, buffer.data, buffer.size) == -1) { + free(buffer.data); + close(cli_sockfd); + continue; } + free(buffer.data); close(cli_sockfd); } diff --git a/src/lib/dev.c b/src/lib/dev.c index 5c11d8bf..c138b009 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -49,7 +49,11 @@ int ap_reg(char * ap_name, msg.n_dif_name = difs_size; recv_msg = send_recv_irm_msg(&msg); - if (recv_msg == NULL) { + if (recv_msg == NULL) + return -1; + + if (recv_msg->has_fd == false) { + irm_msg__free_unpacked(recv_msg, NULL); return -1; } @@ -64,6 +68,8 @@ int ap_unreg(char * ap_name, size_t difs_size) { irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; + int ret = -1; if (ap_name == NULL || difs == NULL || @@ -77,12 +83,19 @@ int ap_unreg(char * ap_name, msg.dif_name = difs; msg.n_dif_name = difs_size; - if (send_irm_msg(&msg)) { - LOG_ERR("Failed to send message to daemon"); + 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; } - return 0; + ret = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + + return ret; } int flow_accept(int fd, @@ -102,9 +115,8 @@ int flow_accept(int fd, msg.fd = fd; recv_msg = send_recv_irm_msg(&msg); - if (recv_msg == NULL) { + if (recv_msg == NULL) return -1; - } if (recv_msg->has_fd == false) { irm_msg__free_unpacked(recv_msg, NULL); @@ -122,6 +134,8 @@ int flow_alloc_resp(int fd, int result) { irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; + int ret = -1; msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC_RESP; msg.has_fd = true; @@ -129,12 +143,19 @@ int flow_alloc_resp(int fd, msg.has_result = true; msg.result = result; - if (send_irm_msg(&msg)) { - LOG_ERR("Failed to send message to daemon"); + 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; } - return 0; + ret = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + + return ret; } int flow_alloc(char * dst_ap_name, @@ -150,8 +171,7 @@ int flow_alloc(char * dst_ap_name, if (dst_ap_name == NULL || src_ap_name == NULL || qos == NULL) { - LOG_ERR("Invalid arguments"); - return -1; + return -EINVAL; } msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC; @@ -162,9 +182,8 @@ int flow_alloc(char * dst_ap_name, msg.oflags = oflags; recv_msg = send_recv_irm_msg(&msg); - if (recv_msg == NULL) { + if (recv_msg == NULL) return -1; - } if (recv_msg->has_fd == false) { irm_msg__free_unpacked(recv_msg, NULL); @@ -187,9 +206,8 @@ int flow_alloc_res(int fd) msg.fd = fd; recv_msg = send_recv_irm_msg(&msg); - if (recv_msg == NULL) { + if (recv_msg == NULL) return -1; - } if (recv_msg->has_result == false) { irm_msg__free_unpacked(recv_msg, NULL); @@ -205,33 +223,51 @@ int flow_alloc_res(int fd) int flow_dealloc(int fd) { irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; + int ret = -1; msg.code = IRM_MSG_CODE__IRM_FLOW_DEALLOC; msg.has_fd = true; msg.fd = fd; - if (send_irm_msg(&msg)) { - LOG_ERR("Failed to send message to daemon"); + 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; } - return 0; + ret = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + + return ret; } int flow_cntl(int fd, int oflags) { irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; + int ret = -1; msg.has_fd = true; msg.fd = fd; msg.oflags = oflags; - if (send_irm_msg(&msg)) { - LOG_ERR("Failed to send message to daemon"); + 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; } - return 0; + ret = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + + return ret; } ssize_t flow_write(int fd, diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c index 60d5879e..2caeaad3 100644 --- a/src/lib/ipcp.c +++ b/src/lib/ipcp.c @@ -22,14 +22,10 @@ #define OUROBOROS_PREFIX "lib-ipcp" -#ifndef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 199506L -#endif - +#include #include #include #include -#include #include #include @@ -97,6 +93,8 @@ pid_t ipcp_create(instance_name_t * api, if (ipcp_type == NULL) return -1; + LOG_DBG("%lu", _POSIX_C_SOURCE); + pid = fork(); if (pid == -1) { LOG_ERR("Failed to fork"); diff --git a/src/lib/irm.c b/src/lib/irm.c index 644e1113..7c187be1 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -34,6 +34,8 @@ int irm_create_ipcp(instance_name_t * api, char * ipcp_type) { irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; + int ret = -1; if (api == NULL || ipcp_type == NULL || api->name == NULL) return -EINVAL; @@ -44,17 +46,26 @@ int irm_create_ipcp(instance_name_t * api, msg.api_id = api->id; msg.ipcp_type = ipcp_type; - if (send_irm_msg(&msg)) { - LOG_ERR("Failed to send message to daemon"); + 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; } - return 0; + ret = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + + return ret; } int irm_destroy_ipcp(instance_name_t * api) { irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; + int ret = -1; if (api == NULL || api->name == NULL) return -EINVAL; @@ -64,18 +75,27 @@ int irm_destroy_ipcp(instance_name_t * api) msg.has_api_id = true; msg.api_id = api->id; - if (send_irm_msg(&msg)) { - LOG_ERR("Failed to send message to daemon"); + 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; } - return 0; + ret = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + + return ret; } int irm_bootstrap_ipcp(instance_name_t * api, struct dif_config * conf) { irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; + int ret = -1; if (api == NULL || api->name == NULL || conf == NULL) return -EINVAL; @@ -85,18 +105,27 @@ int irm_bootstrap_ipcp(instance_name_t * api, msg.has_api_id = true; msg.api_id = api->id; - if (send_irm_msg(&msg)) { - LOG_ERR("Failed to send message to daemon"); + 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; } - return 0; + ret = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + + return ret; } int irm_enroll_ipcp(instance_name_t * api, char * dif_name) { irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; + int ret = -1; if (api == NULL || api->name == NULL || dif_name == NULL) return -EINVAL; @@ -113,15 +142,22 @@ int irm_enroll_ipcp(instance_name_t * api, } msg.dif_name[0] = dif_name; - if (send_irm_msg(&msg)) { - LOG_ERR("Failed to send message to daemon"); + recv_msg = send_recv_irm_msg(&msg); + if (recv_msg == NULL) { free(msg.dif_name); return -1; } - free(msg.dif_name); + 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 0; + free(msg.dif_name); + return ret; } int irm_reg_ipcp(instance_name_t * api, @@ -129,6 +165,8 @@ int irm_reg_ipcp(instance_name_t * api, size_t difs_size) { irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; + int ret = -1; if (api->name == NULL || difs == NULL || @@ -144,12 +182,19 @@ int irm_reg_ipcp(instance_name_t * api, msg.dif_name = difs; msg.n_dif_name = difs_size; - if (send_irm_msg(&msg)) { - LOG_ERR("Failed to send message to daemon"); + 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; } - return 0; + ret = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + + return ret; } int irm_unreg_ipcp(const instance_name_t * api, @@ -157,6 +202,8 @@ int irm_unreg_ipcp(const instance_name_t * api, size_t difs_size) { irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; + int ret = -1; if (api == NULL || api->name == NULL || @@ -173,10 +220,17 @@ int irm_unreg_ipcp(const instance_name_t * api, msg.dif_name = difs; msg.n_dif_name = difs_size; - if (send_irm_msg(&msg)) { - LOG_ERR("Failed to send message to daemon"); + 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; } - return 0; + ret = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + + return ret; } diff --git a/src/lib/irmd_messages.proto b/src/lib/irmd_messages.proto index c61d1b6d..a524a7fb 100644 --- a/src/lib/irmd_messages.proto +++ b/src/lib/irmd_messages.proto @@ -6,19 +6,16 @@ enum irm_msg_code { IRM_REG_IPCP = 5; IRM_UNREG_IPCP = 6; IRM_AP_REG = 7; - IRM_AP_REG_R = 8; - IRM_AP_UNREG = 9; - IRM_FLOW_ACCEPT = 10; - IRM_FLOW_ACCEPT_R = 11; - IRM_FLOW_ALLOC_RESP = 12; - IRM_FLOW_ALLOC = 13; - IRM_FLOW_ALLOC_R = 14; - IRM_FLOW_ALLOC_RES = 15; - IRM_FLOW_ALLOC_RES_R = 16; - IRM_FLOW_DEALLOC = 17; - IRM_FLOW_CONTROL = 18; - IRM_FLOW_WRITE = 19; - IRM_FLOW_READ = 20; + 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; + IRM_FLOW_CONTROL = 14; + IRM_FLOW_WRITE = 15; + IRM_FLOW_READ = 16; + IRM_REPLY = 17; }; message irm_msg { diff --git a/src/lib/sockets.c b/src/lib/sockets.c index a699206d..f9024f70 100644 --- a/src/lib/sockets.c +++ b/src/lib/sockets.c @@ -96,41 +96,6 @@ int server_socket_open(char * file_name) return sockfd; } -int send_irm_msg(irm_msg_t * msg) -{ - int sockfd; - buffer_t buf; - - sockfd = client_socket_open(IRM_SOCK_PATH); - if (sockfd < 0) - return -1; - - buf.size = irm_msg__get_packed_size(msg); - if (buf.size == 0) { - close(sockfd); - return -1; - } - - buf.data = malloc(buf.size); - if (buf.data == NULL) { - close(sockfd); - return -ENOMEM; - } - - irm_msg__pack(msg, buf.data); - - if (write(sockfd, buf.data, buf.size) == -1) { - free(buf.data); - close(sockfd); - return -1; - } - - free(buf.data); - - close(sockfd); - return 0; -} - irm_msg_t * send_recv_irm_msg(irm_msg_t * msg) { int sockfd; diff --git a/src/lib/tests/shm_du_map_test.c b/src/lib/tests/shm_du_map_test.c index f636c941..85a82e4d 100644 --- a/src/lib/tests/shm_du_map_test.c +++ b/src/lib/tests/shm_du_map_test.c @@ -20,6 +20,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include #include #include -- cgit v1.2.3