diff options
| author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-08-08 14:34:12 +0200 | 
|---|---|---|
| committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-08-08 14:34:12 +0200 | 
| commit | 3220cd99c42f08bbd959cf73b9fc7b3ca8375676 (patch) | |
| tree | ae9898536ee5767080b39e82806804fbf9911605 /src | |
| parent | 3c80fae407f451691a4a4178617986e32d0c8162 (diff) | |
| parent | d13a6dfd0f7a8ebc98cdb59cf0a04a282fa1593d (diff) | |
| download | ouroboros-3220cd99c42f08bbd959cf73b9fc7b3ca8375676.tar.gz ouroboros-3220cd99c42f08bbd959cf73b9fc7b3ca8375676.zip | |
Merged in sandervrijders/ouroboros/be-enroll (pull request #189)
ipcpd: normal: Allow exchange of static DIF information
Diffstat (limited to 'src')
| -rw-r--r-- | src/ipcpd/normal/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/ipcpd/normal/fmgr.c | 4 | ||||
| -rw-r--r-- | src/ipcpd/normal/frct.c | 7 | ||||
| -rw-r--r-- | src/ipcpd/normal/frct.h | 3 | ||||
| -rw-r--r-- | src/ipcpd/normal/main.c | 9 | ||||
| -rw-r--r-- | src/ipcpd/normal/ribmgr.c | 235 | ||||
| -rw-r--r-- | src/ipcpd/normal/static_info.proto | 11 | ||||
| -rw-r--r-- | src/ipcpd/shim-eth-llc/main.c | 1 | ||||
| -rw-r--r-- | src/lib/cdap.c | 181 | ||||
| -rw-r--r-- | src/lib/cdap.proto | 26 | ||||
| -rw-r--r-- | src/lib/dev.c | 3 | 
11 files changed, 325 insertions, 161 deletions
| diff --git a/src/ipcpd/normal/CMakeLists.txt b/src/ipcpd/normal/CMakeLists.txt index 7e6d9266..1e291d30 100644 --- a/src/ipcpd/normal/CMakeLists.txt +++ b/src/ipcpd/normal/CMakeLists.txt @@ -14,6 +14,9 @@ include_directories(${CMAKE_BINARY_DIR}/include)  SET(IPCP_NORMAL_TARGET ipcpd-normal CACHE STRING "IPCP_NORMAL_TARGET") +protobuf_generate_c(STATIC_INFO_SRCS STATIC_INFO_HDRS +  static_info.proto) +  set(SOURCE_FILES          # Add source files here          main.c @@ -22,7 +25,8 @@ set(SOURCE_FILES          ribmgr.c  ) -add_executable (ipcpd-normal ${SOURCE_FILES} ${IPCP_SOURCES}) +add_executable (ipcpd-normal ${SOURCE_FILES} ${IPCP_SOURCES} +  ${STATIC_INFO_SRCS})  target_link_libraries (ipcpd-normal LINK_PUBLIC ouroboros)  include(MacroAddCompileFlags) diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c index a539b289..f9de16c4 100644 --- a/src/ipcpd/normal/fmgr.c +++ b/src/ipcpd/normal/fmgr.c @@ -82,8 +82,8 @@ static void * fmgr_listen(void * o)          /* FIXME: Avoid busy wait and react to pthread_cond_t */          pthread_rwlock_rdlock(&_ipcp->state_lock); -        while (_ipcp->state != IPCP_ENROLLED || -               _ipcp->state != IPCP_SHUTDOWN) { +        while (!(_ipcp->state == IPCP_ENROLLED || +                 _ipcp->state == IPCP_SHUTDOWN)) {                  pthread_rwlock_unlock(&_ipcp->state_lock);                  sched_yield();                  pthread_rwlock_rdlock(&_ipcp->state_lock); diff --git a/src/ipcpd/normal/frct.c b/src/ipcpd/normal/frct.c index ba465540..2de9422d 100644 --- a/src/ipcpd/normal/frct.c +++ b/src/ipcpd/normal/frct.c @@ -33,9 +33,10 @@ struct frct_i {  struct frct {          struct dt_const * dtc; +        uint32_t address;  } * frct = NULL; -int frct_init(struct dt_const * dtc) +int frct_init(struct dt_const * dtc, uint32_t address)  {          if (dtc == NULL)                  return -1; @@ -45,13 +46,15 @@ int frct_init(struct dt_const * dtc)                  return -1;          frct->dtc = dtc; +        frct->address = address;          return 0;  }  int frct_fini()  { -        free(frct); +        if (frct != NULL) +                free(frct);          return 0;  } diff --git a/src/ipcpd/normal/frct.h b/src/ipcpd/normal/frct.h index 515bed3f..2e965d38 100644 --- a/src/ipcpd/normal/frct.h +++ b/src/ipcpd/normal/frct.h @@ -29,7 +29,8 @@  struct frct_i; -int             frct_init(struct dt_const * dtc); +int             frct_init(struct dt_const * dtc, +                          uint32_t address);  int             frct_fini();  struct frct_i * frct_i_create(int port_id, diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c index 57fb72df..2d416942 100644 --- a/src/ipcpd/normal/main.c +++ b/src/ipcpd/normal/main.c @@ -146,7 +146,14 @@ static int normal_ipcp_enroll(char * dif_name)                  return -1;          } -        /* FIXME: Wait until state changed to ENROLLED */ +        /* FIXME: Wait passively until state changed to ENROLLED */ +        pthread_rwlock_rdlock(&_ipcp->state_lock); +        while (_ipcp->state != IPCP_ENROLLED) { +                pthread_rwlock_unlock(&_ipcp->state_lock); +                sched_yield(); +                pthread_rwlock_rdlock(&_ipcp->state_lock); +        } +        pthread_rwlock_unlock(&_ipcp->state_lock);          return 0;  } diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c index 8bb320c0..2a68877a 100644 --- a/src/ipcpd/normal/ribmgr.c +++ b/src/ipcpd/normal/ribmgr.c @@ -36,7 +36,11 @@  #include "frct.h"  #include "ipcp.h" -#define ENROLLMENT "enrollment" +#include "static_info.pb-c.h" +typedef StaticInfoMsg static_info_msg_t; + +#define ENROLLMENT  "enrollment" +#define STATIC_INFO "static DIF information"  extern struct ipcp * _ipcp; @@ -67,6 +71,8 @@ struct mgmt_flow {  struct rib {          struct dt_const  dtc; +        uint32_t         address; +          struct list_head flows;          pthread_rwlock_t flows_lock; @@ -162,17 +168,41 @@ int ribmgr_fini()  int ribmgr_cdap_reply(struct cdap * instance,                        int           invoke_id,                        int           result, -                      buffer_t *    val, +                      uint8_t *     data,                        size_t        len)  { -        LOG_MISSING; +        struct list_head * pos, * n = NULL; -        /* FIXME: Check all cdap_reqs here to see if we expect a reply */ +        pthread_mutex_lock(&rib->cdap_reqs_lock); +        list_for_each_safe(pos, n, &rib->cdap_reqs) { +                struct cdap_request * req = +                        list_entry(pos, struct cdap_request, next); +                if (req->instance == instance && +                    req->invoke_id == invoke_id) { +                        if (result != 0) +                                LOG_ERR("CDAP command with code %d and name %s " +                                        "failed with error %d", +                                        req->code, req->name, result); +                        else +                                LOG_DBG("CDAP command with code %d and name %s " +                                        "executed succesfully", +                                        req->code, req->name); + +                        /* FIXME: In case of a read, update values here */ + +                        free(req->name); +                        list_del(&req->next); +                        free(req); +                        break; +                } +        } +        pthread_mutex_unlock(&rib->cdap_reqs_lock); -        return -1; +        return 0;  }  int ribmgr_cdap_read(struct cdap * instance, +                     int           invoke_id,                       char *        name)  {          LOG_MISSING; @@ -181,19 +211,67 @@ int ribmgr_cdap_read(struct cdap * instance,  }  int ribmgr_cdap_write(struct cdap * instance, +                      int           invoke_id,                        char *        name, -                      buffer_t *    val, +                      uint8_t *     data,                        size_t        len,                        uint32_t      flags)  { -        LOG_MISSING; +        static_info_msg_t * msg; +        int ret = 0; + +        pthread_rwlock_wrlock(&_ipcp->state_lock); +        if (_ipcp->state == IPCP_PENDING_ENROLL && +            strcmp(name, STATIC_INFO) == 0) { +                LOG_DBG("Received static DIF information."); + +                msg = static_info_msg__unpack(NULL, len, data); +                if (msg == NULL) { +                        _ipcp->state = IPCP_INIT; +                        pthread_rwlock_unlock(&_ipcp->state_lock); +                        cdap_send_reply(instance, invoke_id, -1, NULL, 0); +                        LOG_ERR("Failed to unpack static info message."); +                        return -1; +                } -        return -1; +                rib->dtc.addr_size = msg->addr_size; +                rib->dtc.cep_id_size = msg->cep_id_size; +                rib->dtc.pdu_length_size = msg->pdu_length_size; +                rib->dtc.seqno_size = msg->seqno_size; +                rib->dtc.ttl_size = msg->ttl_size; +                rib->dtc.chk_size = msg->chk_size; +                rib->dtc.min_pdu_size = msg->min_pdu_size; +                rib->dtc.max_pdu_size = msg->max_pdu_size; + +                rib->address = msg->address; + +                if (frct_init(&rib->dtc, rib->address)) { +                        _ipcp->state = IPCP_INIT; +                        pthread_rwlock_unlock(&_ipcp->state_lock); +                        cdap_send_reply(instance, invoke_id, -1, NULL, 0); +                        static_info_msg__free_unpacked(msg, NULL); +                        LOG_ERR("Failed to init FRCT"); +                        return -1; +                } + +                static_info_msg__free_unpacked(msg, NULL); +        } else +                ret = -1; +        pthread_rwlock_unlock(&_ipcp->state_lock); + +        if (cdap_send_reply(instance, invoke_id, ret, NULL, 0)) { +                LOG_ERR("Failed to send reply to write request."); +                return -1; +        } + +        return 0;  }  int ribmgr_cdap_create(struct cdap * instance, +                       int           invoke_id,                         char *        name, -                       buffer_t      val) +                       uint8_t *     data, +                       size_t        len)  {          LOG_MISSING; @@ -201,8 +279,10 @@ int ribmgr_cdap_create(struct cdap * instance,  }  int ribmgr_cdap_delete(struct cdap * instance, +                       int           invoke_id,                         char *        name, -                       buffer_t      val) +                       uint8_t *     data, +                       size_t        len)  {          LOG_MISSING; @@ -210,21 +290,135 @@ int ribmgr_cdap_delete(struct cdap * instance,  }  int ribmgr_cdap_start(struct cdap * instance, +                      int           invoke_id,                        char *        name)  { -        LOG_MISSING; +        static_info_msg_t stat_info = STATIC_INFO_MSG__INIT; +        uint8_t * data = NULL; +        size_t len = 0; +        int iid = 0; -        /* FIXME: Handle enrollment request here */ +        pthread_rwlock_rdlock(&_ipcp->state_lock); +        if (_ipcp->state == IPCP_ENROLLED && +            strcmp(name, ENROLLMENT) == 0) { +                LOG_DBG("New enrollment request."); -        return -1; +                if (cdap_send_reply(instance, invoke_id, 0, NULL, 0)) { +                        pthread_rwlock_unlock(&_ipcp->state_lock); +                        LOG_ERR("Failed to send reply to enrollment request."); +                        return -1; +                } + +                stat_info.addr_size = rib->dtc.addr_size; +                stat_info.cep_id_size = rib->dtc.cep_id_size; +                stat_info.pdu_length_size = rib->dtc.pdu_length_size; +                stat_info.seqno_size = rib->dtc.seqno_size; +                stat_info.ttl_size = rib->dtc.ttl_size; +                stat_info.chk_size = rib->dtc.chk_size; +                stat_info.min_pdu_size  = rib->dtc.min_pdu_size; +                stat_info.max_pdu_size = rib->dtc.max_pdu_size; + +                /* FIXME: Hand out an address. */ +                stat_info.address = 0; + +                len = static_info_msg__get_packed_size(&stat_info); +                if (len == 0) { +                        pthread_rwlock_unlock(&_ipcp->state_lock); +                        LOG_ERR("Failed to get size of static information."); +                        return -1; +                } + +                data = malloc(len); +                if (data == NULL) { +                        pthread_rwlock_unlock(&_ipcp->state_lock); +                        LOG_ERR("Failed to allocate memory."); +                        return -1; +                } + +                static_info_msg__pack(&stat_info, data); + +                LOG_DBGF("Sending static info..."); + +                pthread_mutex_lock(&rib->cdap_reqs_lock); + +                iid = cdap_send_write(instance, STATIC_INFO, data, len, 0); +                if (iid < 0) { +                        pthread_mutex_unlock(&rib->cdap_reqs_lock); +                        pthread_rwlock_unlock(&_ipcp->state_lock); +                        free(data); +                        LOG_ERR("Failed to send static information."); +                        return -1; +                } + +                if (cdap_request_add(instance, WRITE, STATIC_INFO, iid)) { +                        pthread_mutex_unlock(&rib->cdap_reqs_lock); +                        pthread_rwlock_unlock(&_ipcp->state_lock); +                        free(data); +                        LOG_ERR("Failed to add CDAP request to list."); +                        return -1; +                } +                pthread_mutex_unlock(&rib->cdap_reqs_lock); + +                /* FIXME: Send neighbors here. */ + +                LOG_DBGF("Sending stop enrollment..."); + +                pthread_mutex_lock(&rib->cdap_reqs_lock); + +                iid = cdap_send_stop(instance, ENROLLMENT); +                if (iid < 0) { +                        pthread_mutex_unlock(&rib->cdap_reqs_lock); +                        pthread_rwlock_unlock(&_ipcp->state_lock); +                        free(data); +                        LOG_ERR("Failed to send stop of enrollment."); +                        return -1; +                } + +                if (cdap_request_add(instance, STOP, ENROLLMENT, iid)) { +                        pthread_mutex_unlock(&rib->cdap_reqs_lock); +                        pthread_rwlock_unlock(&_ipcp->state_lock); +                        free(data); +                        LOG_ERR("Failed to add CDAP request to list."); +                        return -1; +                } +                pthread_mutex_unlock(&rib->cdap_reqs_lock); + +                free(data); +        } else { +                if (cdap_send_reply(instance, invoke_id, -1, NULL, 0)) { +                        pthread_rwlock_unlock(&_ipcp->state_lock); +                        LOG_ERR("Failed to send reply to start request."); +                        return -1; +                } +        } +        pthread_rwlock_unlock(&_ipcp->state_lock); + +        return 0;  }  int ribmgr_cdap_stop(struct cdap * instance, +                     int           invoke_id,                       char *        name)  { -        LOG_MISSING; +        int ret = 0; -        return -1; +        pthread_rwlock_wrlock(&_ipcp->state_lock); +        if (_ipcp->state == IPCP_PENDING_ENROLL && +            strcmp(name, ENROLLMENT) == 0) { +                LOG_DBG("Stop enrollment received."); + +                _ipcp->state = IPCP_ENROLLED; +        } else +                ret = -1; + +        if (cdap_send_reply(instance, invoke_id, ret, NULL, 0)) { +                pthread_rwlock_unlock(&_ipcp->state_lock); +                LOG_ERR("Failed to send reply to stop request."); +                return -1; +        } +        pthread_rwlock_unlock(&_ipcp->state_lock); + +        return 0;  }  static struct cdap_ops ribmgr_ops = { @@ -258,13 +452,11 @@ int ribmgr_add_flow(int fd)          flow->instance = instance;          flow->fd = fd; -        pthread_rwlock_rdlock(&_ipcp->state_lock); +        pthread_rwlock_wrlock(&_ipcp->state_lock);          pthread_rwlock_wrlock(&rib->flows_lock);          if (list_empty(&rib->flows) && -            (_ipcp->state == IPCP_INIT || -             _ipcp->state == IPCP_DISCONNECTED)) { +            _ipcp->state == IPCP_INIT) {                  _ipcp->state = IPCP_PENDING_ENROLL; -                pthread_rwlock_unlock(&_ipcp->state_lock);                  pthread_mutex_lock(&rib->cdap_reqs_lock);                  iid = cdap_send_start(instance, @@ -334,7 +526,10 @@ int ribmgr_bootstrap(struct dif_config * conf)          rib->dtc.min_pdu_size = conf->min_pdu_size;          rib->dtc.max_pdu_size = conf->max_pdu_size; -        if (frct_init(&rib->dtc)) { +        /* FIXME: Set correct address. */ +        rib->address = 0; + +        if (frct_init(&rib->dtc, rib->address)) {                  LOG_ERR("Failed to initialize FRCT.");                  return -1;          } diff --git a/src/ipcpd/normal/static_info.proto b/src/ipcpd/normal/static_info.proto new file mode 100644 index 00000000..24b7994a --- /dev/null +++ b/src/ipcpd/normal/static_info.proto @@ -0,0 +1,11 @@ +message static_info_msg { +        required uint32 addr_size       = 1; +        required uint32 cep_id_size     = 2; +        required uint32 pdu_length_size = 3; +        required uint32 seqno_size      = 4; +        required uint32 ttl_size        = 5; +        required uint32 chk_size        = 6; +        required uint32 min_pdu_size    = 7; +        required uint32 max_pdu_size    = 8; +        required uint32 address         = 9; +}
\ No newline at end of file diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c index 9f6573c9..e2799c19 100644 --- a/src/ipcpd/shim-eth-llc/main.c +++ b/src/ipcpd/shim-eth-llc/main.c @@ -820,6 +820,7 @@ static void * eth_llc_ipcp_sdu_writer(void * o)                  if (len <= 0) {                          pthread_rwlock_unlock(&_ipcp->state_lock);                          free(e); +                        LOG_ERR("Length of du map read was %d.", len);                          continue;                  } diff --git a/src/lib/cdap.c b/src/lib/cdap.c index 0c6140eb..4c70b2e4 100644 --- a/src/lib/cdap.c +++ b/src/lib/cdap.c @@ -23,7 +23,6 @@  #include <ouroboros/config.h>  #include <ouroboros/cdap.h>  #include <ouroboros/bitmap.h> -#include <ouroboros/common.h>  #include <ouroboros/dev.h>  #include <stdlib.h> @@ -44,32 +43,6 @@ struct cdap {          struct cdap_ops * ops;  }; - -static ssize_t cdap_msg_to_buffer(cdap_t * msg, -                                  buffer_t ** val) -{ -        int i; -        size_t len; - -        len = msg->n_value; - -        *val = malloc(len * sizeof(**val)); -        if (*val == NULL) -                return -1; - -        for (i = 0; i < len; i++) { -                if (msg->value[i].data == NULL) { -                        free(*val); -                        return -1; -                } - -                (*val)[i].data = msg->value[i].data; -                (*val)[i].len = msg->value[i].len; -        } - -        return len; -} -  static int next_invoke_id(struct cdap * instance)  {          int ret; @@ -99,8 +72,6 @@ static void * sdu_reader(void * o)          cdap_t * msg;          uint8_t buf[BUF_SIZE];          ssize_t len; -        ssize_t length; -        buffer_t * val;          while (true) {                  len = flow_read(instance->fd, buf, BUF_SIZE); @@ -115,63 +86,59 @@ static void * sdu_reader(void * o)                  case OPCODE__READ:                          if (msg->name != NULL)                                  instance->ops->cdap_read(instance, +                                                         msg->invoke_id,                                                           msg->name);                          break;                  case OPCODE__WRITE: -                        length = cdap_msg_to_buffer(msg, &val);                          if (msg->name != NULL && -                            msg->value != NULL && -                            len > 0) { +                            msg->has_value) {                                  instance->ops->cdap_write(instance, +                                                          msg->invoke_id,                                                            msg->name, -                                                          val, -                                                          length, +                                                          msg->value.data, +                                                          msg->value.len,                                                            msg->flags); -                                free(val);                          }                          break;                  case OPCODE__CREATE: -                        length = cdap_msg_to_buffer(msg, &val);                          if (msg->name != NULL && -                            length == 1) { +                            msg->has_value) {                                  instance->ops->cdap_create(instance, +                                                           msg->invoke_id,                                                             msg->name, -                                                           val[0]); -                                free(val); +                                                           msg->value.data, +                                                           msg->value.len);                          }                          break;                  case OPCODE__DELETE: -                        length = cdap_msg_to_buffer(msg, &val);                          if (msg->name != NULL && -                            length == 1) { +                            msg->has_value) {                                  instance->ops->cdap_create(instance, +                                                           msg->invoke_id,                                                             msg->name, -                                                           val[0]); -                                free(val); +                                                           msg->value.data, +                                                           msg->value.len);                          }                          break;                  case OPCODE__START:                          if (msg->name != NULL)                                  instance->ops->cdap_start(instance, +                                                          msg->invoke_id,                                                            msg->name);                          break;                  case OPCODE__STOP:                          if (msg->name != NULL)                                  instance->ops->cdap_stop(instance, +                                                         msg->invoke_id,                                                           msg->name);                          break;                  case OPCODE__REPLY: -                        length = cdap_msg_to_buffer(msg, &val); -                        if (msg->name != NULL && -                            length > 0) { -                                instance->ops->cdap_reply(instance, -                                                          msg->invoke_id, -                                                          msg->result, -                                                          val, -                                                          length); -                                release_invoke_id(instance, msg->invoke_id); -                                free(val); -                        } +                        instance->ops->cdap_reply(instance, +                                                  msg->invoke_id, +                                                  msg->result, +                                                  msg->value.data, +                                                  msg->value.len); +                        release_invoke_id(instance, msg->invoke_id);                          break;                  default:                          break; @@ -256,50 +223,27 @@ int cdap_destroy(struct cdap * instance)  static int write_msg(struct cdap * instance,                       cdap_t * msg)  { -        buffer_t buf;          int ret; +        uint8_t * data; +        size_t len; -        buf.len = cdap__get_packed_size(msg); -        if (buf.len == 0) +        len = cdap__get_packed_size(msg); +        if (len == 0)                  return -1; -        buf.data = malloc(BUF_SIZE); -        if (buf.data == NULL) +        data = malloc(BUF_SIZE); +        if (data == NULL)                  return -1; -        cdap__pack(msg, buf.data); +        cdap__pack(msg, data); -        ret = flow_write(instance->fd, buf.data, buf.len); +        ret = flow_write(instance->fd, data, len); -        free(buf.data); +        free(data);          return ret;  } -static int buffer_to_cdap_msg(cdap_t * msg, -                              buffer_t * val, -                              size_t len) -{ -        int i; - -        msg->value = malloc(len * sizeof(*msg->value)); -        if (msg->value == NULL) -                return -1; - -        msg->n_value = len; -        for (i = 0; i < len; i++) { -                if (val[i].data == NULL) { -                        free(msg->value); -                        return -1; -                } - -                msg->value[i].data = val[i].data; -                msg->value[i].len = val[i].len; -        } - -        return 0; -} -  static int send_read_or_start_or_stop(struct cdap * instance,                                        char *        name,                                        opcode_t      code) @@ -318,19 +262,22 @@ static int send_read_or_start_or_stop(struct cdap * instance,          msg.invoke_id = id;          msg.name = name; -        return write_msg(instance, &msg); +        if (write_msg(instance, &msg)) +                return -1; + +        return id;  }  static int send_create_or_delete(struct cdap * instance,                                   char *        name, -                                 buffer_t      val, +                                 uint8_t *     data, +                                 size_t        len,                                   opcode_t      code)  {          int id;          cdap_t msg = CDAP__INIT; -        int ret; -        if (instance == NULL || name == NULL) +        if (instance == NULL || name == NULL || data == NULL)                  return -1;          id = next_invoke_id(instance); @@ -340,17 +287,14 @@ static int send_create_or_delete(struct cdap * instance,          msg.opcode = code;          msg.name = name;          msg.invoke_id = id; +        msg.has_value = true; +        msg.value.data = data; +        msg.value.len = len; -        if (buffer_to_cdap_msg(&msg, &val, 1)) { -                release_invoke_id(instance, id); +        if (write_msg(instance, &msg))                  return -1; -        } -        ret = write_msg(instance, &msg); - -        free(msg.value); - -        return ret; +        return id;  }  int cdap_send_read(struct cdap * instance, @@ -361,16 +305,14 @@ int cdap_send_read(struct cdap * instance,  int cdap_send_write(struct cdap * instance,                      char *        name, -                    buffer_t *    val, +                    uint8_t *     data,                      size_t        len,                      uint32_t      flags)  {          int id; -        int ret;          cdap_t msg = CDAP__INIT; -        if (instance == NULL || name == NULL || -            val == NULL || len < 1) +        if (instance == NULL || name == NULL || data == NULL)                  return -1;          id = next_invoke_id(instance); @@ -382,31 +324,30 @@ int cdap_send_write(struct cdap * instance,          msg.has_flags = true;          msg.flags = flags;          msg.invoke_id = id; +        msg.has_value = true; +        msg.value.data = data; +        msg.value.len = len; -        if (buffer_to_cdap_msg(&msg, val, len)) { -                release_invoke_id(instance, id); +        if (write_msg(instance, &msg))                  return -1; -        } - -        ret = write_msg(instance, &msg); -        free(msg.value); - -        return ret; +        return id;  }  int cdap_send_create(struct cdap * instance,                       char *        name, -                     buffer_t      val) +                     uint8_t *     data, +                     size_t        len)  { -        return send_create_or_delete(instance, name, val, OPCODE__CREATE); +        return send_create_or_delete(instance, name, data, len, OPCODE__CREATE);  }  int cdap_send_delete(struct cdap * instance,                       char *        name, -                     buffer_t      val) +                     uint8_t *     data, +                     size_t        len)  { -        return send_create_or_delete(instance, name, val, OPCODE__DELETE); +        return send_create_or_delete(instance, name, data, len, OPCODE__DELETE);  }  int cdap_send_start(struct cdap * instance, @@ -424,20 +365,24 @@ int cdap_send_stop(struct cdap * instance,  int cdap_send_reply(struct cdap * instance,                      int           invoke_id,                      int           result, -                    buffer_t *    val, +                    uint8_t *     data,                      size_t        len)  {          cdap_t msg = CDAP__INIT; -        if (instance == NULL || val == NULL) +        if (instance == NULL)                  return -1; +        msg.opcode = OPCODE__REPLY;          msg.invoke_id = invoke_id;          msg.has_result = true;          msg.result = result; -        if (buffer_to_cdap_msg(&msg, val, len)) -                return -1; +        if (data != NULL) { +                msg.has_value = true; +                msg.value.data = data; +                msg.value.len = len; +        }          return write_msg(instance, &msg);  } diff --git a/src/lib/cdap.proto b/src/lib/cdap.proto index a5e0306d..f641fc65 100644 --- a/src/lib/cdap.proto +++ b/src/lib/cdap.proto @@ -1,18 +1,18 @@  enum opcode { -	CREATE = 1; -	DELETE = 2; -	READ   = 3; -	WRITE  = 4; -	START  = 5; -	STOP   = 6; -	REPLY  = 7; +        CREATE = 1; +        DELETE = 2; +        READ   = 3; +        WRITE  = 4; +        START  = 5; +        STOP   = 6; +        REPLY  = 7;  }  message cdap { -	required opcode opcode    = 1; -	required uint32 invoke_id = 2; -	optional uint32 flags     = 3; -	optional string name      = 4; -	repeated bytes value      = 5; -	optional int32 result     = 6; +        required opcode opcode    = 1; +        required uint32 invoke_id = 2; +        optional uint32 flags     = 3; +        optional string name      = 4; +        optional bytes value      = 5; +        optional int32 result     = 6;  } diff --git a/src/lib/dev.c b/src/lib/dev.c index ce919263..6f0de8c8 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -20,11 +20,8 @@   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   */ -#define OUROBOROS_PREFIX "libouroboros-dev" -  #include <ouroboros/config.h>  #include <ouroboros/errno.h> -#include <ouroboros/logs.h>  #include <ouroboros/dev.h>  #include <ouroboros/sockets.h>  #include <ouroboros/bitmap.h> | 
