diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/lib/dev.c | 46 | ||||
| -rw-r--r-- | src/lib/instance_name.c | 248 | ||||
| -rw-r--r-- | src/lib/ipcp.c | 90 | ||||
| -rw-r--r-- | src/lib/ipcpd_messages.proto | 2 | ||||
| -rw-r--r-- | src/lib/irm.c | 201 | ||||
| -rw-r--r-- | src/lib/irmd_messages.proto | 42 | ||||
| -rw-r--r-- | src/lib/shm_ap_rbuff.c | 14 | ||||
| -rw-r--r-- | src/lib/shm_du_map.c | 10 | ||||
| -rw-r--r-- | src/lib/sockets.c | 18 | 
10 files changed, 243 insertions, 429 deletions
| diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 2a75ef17..410be6fe 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -27,7 +27,6 @@ set(SOURCE_FILES    cdap.c    dev.c    du_buff.c -  instance_name.c    ipcp.c    irm.c    list.c diff --git a/src/lib/dev.c b/src/lib/dev.c index ad311f7f..ac995b2d 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -28,7 +28,6 @@  #include <ouroboros/dev.h>  #include <ouroboros/sockets.h>  #include <ouroboros/bitmap.h> -#include <ouroboros/instance_name.h>  #include <ouroboros/shm_du_map.h>  #include <ouroboros/shm_ap_rbuff.h>  #include <ouroboros/utils.h> @@ -45,7 +44,8 @@ struct flow {  };  struct ap_data { -        instance_name_t *     api; +        char *                ap_name; +        pid_t                 api;          struct shm_du_map *   dum;          struct bmp *          fds;          struct shm_ap_rbuff * rb; @@ -66,30 +66,17 @@ int ap_init(char * ap_name)                  return -ENOMEM;          } -        _ap_instance->api = instance_name_create(); -        if (_ap_instance->api == NULL) { -                free(_ap_instance); -                return -ENOMEM; -        } - -        if (instance_name_init_from(_ap_instance->api, -                                    ap_name, -                                    getpid()) == NULL) { -                instance_name_destroy(_ap_instance->api); -                free(_ap_instance); -                return -ENOMEM; -        } +        _ap_instance->api = getpid(); +        _ap_instance->ap_name = ap_name;          _ap_instance->fds = bmp_create(AP_MAX_FLOWS, 0);          if (_ap_instance->fds == NULL) { -                instance_name_destroy(_ap_instance->api);                  free(_ap_instance);                  return -ENOMEM;          }          _ap_instance->dum = shm_du_map_open();          if (_ap_instance->dum == NULL) { -                instance_name_destroy(_ap_instance->api);                  bmp_destroy(_ap_instance->fds);                  free(_ap_instance);                  return -1; @@ -97,7 +84,6 @@ int ap_init(char * ap_name)          _ap_instance->rb = shm_ap_rbuff_create();          if (_ap_instance->rb == NULL) { -                instance_name_destroy(_ap_instance->api);                  shm_du_map_close(_ap_instance->dum);                  bmp_destroy(_ap_instance->fds);                  free(_ap_instance); @@ -124,8 +110,6 @@ void ap_fini(void)          pthread_rwlock_wrlock(&_ap_instance->data_lock); -        if (_ap_instance->api != NULL) -                instance_name_destroy(_ap_instance->api);          if (_ap_instance->fds != NULL)                  bmp_destroy(_ap_instance->fds);          if (_ap_instance->dum != NULL) @@ -164,12 +148,12 @@ int flow_accept(char ** ae_name)          int cfd = -1;          msg.code    = IRM_MSG_CODE__IRM_FLOW_ACCEPT; -        msg.has_pid = true; +        msg.has_api = true;          pthread_rwlock_rdlock(&_ap_instance->data_lock); -        msg.ap_name = _ap_instance->api->name; -        msg.pid     = _ap_instance->api->id; +        msg.ap_name = _ap_instance->ap_name; +        msg.api     = _ap_instance->api;          pthread_rwlock_unlock(&_ap_instance->data_lock); @@ -178,7 +162,7 @@ int flow_accept(char ** ae_name)                  return -1;          } -        if (!recv_msg->has_pid || !recv_msg->has_port_id) { +        if (!recv_msg->has_api || !recv_msg->has_port_id) {                  irm_msg__free_unpacked(recv_msg, NULL);                  return -1;          } @@ -194,7 +178,7 @@ int flow_accept(char ** ae_name)                  return -1;          } -        _ap_instance->flows[cfd].rb = shm_ap_rbuff_open(recv_msg->pid); +        _ap_instance->flows[cfd].rb = shm_ap_rbuff_open(recv_msg->api);          if (_ap_instance->flows[cfd].rb == NULL) {                  bmp_release(_ap_instance->fds, cfd);                  pthread_rwlock_unlock(&_ap_instance->flows_lock); @@ -237,8 +221,8 @@ int flow_alloc_resp(int fd,                  return -EBADF;          msg.code         = IRM_MSG_CODE__IRM_FLOW_ALLOC_RESP; -        msg.has_pid      = true; -        msg.pid          = _ap_instance->api->id; +        msg.has_api      = true; +        msg.api          = _ap_instance->api;          msg.has_port_id  = true;          pthread_rwlock_rdlock(&_ap_instance->data_lock); @@ -295,11 +279,11 @@ int flow_alloc(char * dst_name,          msg.code        = IRM_MSG_CODE__IRM_FLOW_ALLOC;          msg.dst_name    = dst_name;          msg.ae_name     = src_ae_name; -        msg.has_pid     = true; +        msg.has_api     = true;          pthread_rwlock_rdlock(&_ap_instance->data_lock); -        msg.pid         = _ap_instance->api->id; +        msg.api         = _ap_instance->api;          pthread_rwlock_unlock(&_ap_instance->data_lock); @@ -308,7 +292,7 @@ int flow_alloc(char * dst_name,                  return -1;          } -        if (!recv_msg->has_pid || !recv_msg->has_port_id) { +        if (!recv_msg->has_api || !recv_msg->has_port_id) {                  irm_msg__free_unpacked(recv_msg, NULL);                  return -1;          } @@ -324,7 +308,7 @@ int flow_alloc(char * dst_name,                  return -1;          } -        _ap_instance->flows[fd].rb = shm_ap_rbuff_open(recv_msg->pid); +        _ap_instance->flows[fd].rb = shm_ap_rbuff_open(recv_msg->api);          if (_ap_instance->flows[fd].rb == NULL) {                  bmp_release(_ap_instance->fds, fd);                  pthread_rwlock_unlock(&_ap_instance->flows_lock); diff --git a/src/lib/instance_name.c b/src/lib/instance_name.c deleted file mode 100644 index 844bb924..00000000 --- a/src/lib/instance_name.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - * RINA naming related utilities - * - *    Sander Vrijders       <sander.vrijders@intec.ugent.be> - *    Francesco Salvestrini <f.salvestrini@nextworks.it> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#define OUROBOROS_PREFIX "instance-name" - -#include <ouroboros/logs.h> -#include <ouroboros/common.h> -#include <ouroboros/instance_name.h> -#include <ouroboros/utils.h> - -#include <string.h> -#include <math.h> -#include <stdlib.h> - -instance_name_t * instance_name_create() -{ -        instance_name_t * tmp; - -        tmp = malloc(sizeof *tmp); -        if (tmp == NULL) -                return NULL; - -        tmp->name = NULL; -        tmp->id  = 0; - -        return tmp; -} - -instance_name_t * instance_name_init_from(instance_name_t * dst, -                                          const char *      name, -                                          uint16_t          id) -{ -        if (dst == NULL) -                return NULL; - -        /* Clean up the destination, leftovers might be there ... */ -        instance_name_fini(dst); - -        dst->name = strdup(name); -        dst->id = id; - -        if (dst->name == NULL) { -                instance_name_fini(dst); -                return NULL; -        } - -        return dst; -} - -instance_name_t * instance_name_init_with(instance_name_t * dst, -                                          char *      name, -                                          uint16_t          id) -{ -        if (dst == NULL) -                return NULL; - -        /* Clean up the destination, leftovers might be there ... */ -        instance_name_fini(dst); - -        dst->name = name; -        dst->id  = id; - -        return dst; -} - -void instance_name_fini(instance_name_t * n) -{ -        if (n == NULL || n->name == NULL) -                return; - -        free(n->name); -        n->name = NULL; -} - -void instance_name_destroy(instance_name_t * ptr) -{ -        if (ptr == NULL) -                return; - -        instance_name_fini(ptr); - -        free(ptr); -} - -int instance_name_cpy(instance_name_t *       dst, -                      const instance_name_t * src) -{ -        instance_name_t * res; - -        if (src == NULL || dst == NULL) -                return -EINVAL; - -        res = instance_name_init_from(dst, src->name, src->id); -        if (res == NULL) -                return -ENOMEM; - -        return 0; -} - -instance_name_t * instance_name_dup(const instance_name_t * src) -{ -        instance_name_t * tmp; - -        if (src == NULL) -                return NULL; - -        tmp = instance_name_create(); -        if (tmp == NULL) -                return NULL; - -        if (instance_name_cpy(tmp, src)) { -                instance_name_destroy(tmp); -                return NULL; -        } - -        return tmp; -} - -bool instance_name_is_valid(const instance_name_t * n) -{ -        return (n != NULL && n->name != NULL && strlen(n->name)); -} - -int instance_name_cmp(const instance_name_t * a, -                      const instance_name_t * b) -{ - -        int ret = 0; - -        if (a == NULL || b == NULL) { -                LOG_DBGF("Won't compare NULL."); -                return -2; -        } - -        if (a == b) -                return 0; - -        ret = strcmp(a->name, b->name); - -        if (!ret) { -                if (a->id == b-> id) -                        return 0; -                else -                        return a->id < b->id ? -1 : 1; -        } - -        return ret; -} - - - -#define DELIMITER "/" - -char * instance_name_to_string(const instance_name_t * n) -{ -        char *       tmp; -        size_t       size; -        const char * none     = ""; -        size_t       none_len = strlen(none); - -        if (n == NULL) -                return NULL; - -        size = 0; - -        size += (n->name != NULL ? -                 strlen(n->name) : none_len); -        size += strlen(DELIMITER); - -        size += (n->id == 0 ? -                 1 : n_digits(n->id)); -        size += strlen(DELIMITER); - -        tmp = malloc(size); -        if (!tmp) -                return NULL; - -        if (sprintf(tmp, "%s%s%d", -                    (n->name != NULL ? n->name : none), -                    DELIMITER, n->id) -            != size - 1) { -                free(tmp); -                return NULL; -        } - -        return tmp; -} - -instance_name_t * string_to_instance_name(const char * s) -{ -        instance_name_t * name; - -        char *       tmp1      = NULL; -        char *       tmp_ap    = NULL; -        char *       tmp_s_api = NULL; -        unsigned int tmp_api   = 0; -        char *       tmp2; - -        if (s == NULL) -                return NULL; - -        tmp1 = strdup(s); -        if (tmp1 == NULL) { -                return NULL; -        } - -        tmp_ap = strtok(tmp1, DELIMITER); -        tmp_s_api = strtok(NULL, DELIMITER); -        if (tmp_s_api != NULL) -                tmp_api = (unsigned int) strtol(tmp_s_api, &tmp2, 10); - -        name = instance_name_create(); -        if (name == NULL) { -                if (tmp1 != NULL) -                        free(tmp1); -                return NULL; -        } - -        if (!instance_name_init_from(name, tmp_ap, tmp_api)) { -                instance_name_destroy(name); -                if (tmp1 != NULL) -                        free(tmp1); -                return NULL; -        } - -        if (tmp1 != NULL) -                free(tmp1); - -        return name; -} diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c index 77263bcf..2b6b6825 100644 --- a/src/lib/ipcp.c +++ b/src/lib/ipcp.c @@ -35,7 +35,7 @@  #include <sys/types.h>  #include <sys/wait.h> -static ipcp_msg_t * send_recv_ipcp_msg(pid_t pid, +static ipcp_msg_t * send_recv_ipcp_msg(pid_t api,                                         ipcp_msg_t * msg)  {         int sockfd = 0; @@ -44,7 +44,7 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t pid,         ssize_t count = 0;         ipcp_msg_t * recv_msg = NULL; -       sock_path = ipcp_sock_path(pid); +       sock_path = ipcp_sock_path(api);         if (sock_path == NULL)                 return NULL; @@ -99,26 +99,25 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t pid,         return recv_msg;  } -pid_t ipcp_create(char *         ipcp_name, -                  enum ipcp_type ipcp_type) +pid_t ipcp_create(enum ipcp_type ipcp_type)  { -        pid_t pid = 0; -        char irmd_pid[10]; +        pid_t api = 0; +        char irmd_api[10];          size_t len = 0;          char * ipcp_dir = "/sbin/";          char * full_name = NULL;          char * exec_name = NULL; -        sprintf(irmd_pid, "%u", getpid()); +        sprintf(irmd_api, "%u", getpid()); -        pid = fork(); -        if (pid == -1) { +        api = fork(); +        if (api == -1) {                  LOG_ERR("Failed to fork"); -                return pid; +                return api;          } -        if (pid != 0) { -                return pid; +        if (api != 0) { +                return api;          }          if (ipcp_type == IPCP_NORMAL) @@ -149,8 +148,7 @@ pid_t ipcp_create(char *         ipcp_name,          full_name[len] = '\0';          char * argv[] = {full_name, -                         irmd_pid, -                         ipcp_name, +                         irmd_api,                           0};          char * envp[] = {0}; @@ -164,16 +162,16 @@ pid_t ipcp_create(char *         ipcp_name,          exit(EXIT_FAILURE);  } -int ipcp_destroy(pid_t pid) +int ipcp_destroy(pid_t api)  {          int status; -        if (kill(pid, SIGTERM)) { +        if (kill(api, SIGTERM)) {                  LOG_ERR("Failed to destroy IPCP");                  return -1;          } -        if (waitpid(pid, &status, 0) < 0) { +        if (waitpid(api, &status, 0) < 0) {                  LOG_ERR("Failed to destroy IPCP");                  return -1;          } @@ -181,7 +179,7 @@ int ipcp_destroy(pid_t pid)          return 0;  } -int ipcp_reg(pid_t   pid, +int ipcp_reg(pid_t   api,               char ** dif_names,               size_t  len)  { @@ -198,7 +196,7 @@ int ipcp_reg(pid_t   pid,          msg.dif_names  = dif_names;          msg.len        = len; -        recv_msg = send_recv_ipcp_msg(pid, &msg); +        recv_msg = send_recv_ipcp_msg(api, &msg);          if (recv_msg == NULL)                  return -1; @@ -213,7 +211,7 @@ int ipcp_reg(pid_t   pid,          return ret;  } -int ipcp_unreg(pid_t pid, +int ipcp_unreg(pid_t api,                 char ** dif_names,                 size_t len)  { @@ -230,7 +228,7 @@ int ipcp_unreg(pid_t pid,          msg.dif_names  = dif_names;          msg.len        = len; -        recv_msg = send_recv_ipcp_msg(pid, &msg); +        recv_msg = send_recv_ipcp_msg(api, &msg);          if (recv_msg == NULL)                  return -1; @@ -246,7 +244,7 @@ int ipcp_unreg(pid_t pid,  } -int ipcp_bootstrap(pid_t pid, +int ipcp_bootstrap(pid_t api,                     dif_config_msg_t * conf)  {          ipcp_msg_t msg = IPCP_MSG__INIT; @@ -259,7 +257,7 @@ int ipcp_bootstrap(pid_t pid,          msg.code = IPCP_MSG_CODE__IPCP_BOOTSTRAP;          msg.conf = conf; -        recv_msg = send_recv_ipcp_msg(pid, &msg); +        recv_msg = send_recv_ipcp_msg(api, &msg);          if (recv_msg == NULL)                  return -1; @@ -274,7 +272,7 @@ int ipcp_bootstrap(pid_t pid,          return ret;  } -int ipcp_enroll(pid_t pid, +int ipcp_enroll(pid_t api,                  char * dif_name,                  char * n_1_dif)  { @@ -289,7 +287,7 @@ int ipcp_enroll(pid_t pid,          msg.dif_name = dif_name;          msg.n_1_dif  = n_1_dif; -        recv_msg = send_recv_ipcp_msg(pid, &msg); +        recv_msg = send_recv_ipcp_msg(api, &msg);          if (recv_msg == NULL) {                  return -1;          } @@ -305,7 +303,7 @@ int ipcp_enroll(pid_t pid,          return ret;  } -int ipcp_name_reg(pid_t    pid, +int ipcp_name_reg(pid_t    api,                    char *   name)  {          ipcp_msg_t msg = IPCP_MSG__INIT; @@ -318,7 +316,7 @@ int ipcp_name_reg(pid_t    pid,          msg.code = IPCP_MSG_CODE__IPCP_NAME_REG;          msg.name = name; -        recv_msg = send_recv_ipcp_msg(pid, &msg); +        recv_msg = send_recv_ipcp_msg(api, &msg);          if (recv_msg == NULL)                  return -1; @@ -333,7 +331,7 @@ int ipcp_name_reg(pid_t    pid,          return ret;  } -int ipcp_name_unreg(pid_t  pid, +int ipcp_name_unreg(pid_t  api,                      char * name)  {          ipcp_msg_t msg = IPCP_MSG__INIT; @@ -343,7 +341,7 @@ int ipcp_name_unreg(pid_t  pid,          msg.code = IPCP_MSG_CODE__IPCP_NAME_UNREG;          msg.name = name; -        recv_msg = send_recv_ipcp_msg(pid, &msg); +        recv_msg = send_recv_ipcp_msg(api, &msg);          if (recv_msg == NULL)                  return -1; @@ -358,9 +356,9 @@ int ipcp_name_unreg(pid_t  pid,          return ret;  } -int ipcp_flow_alloc(pid_t         pid, +int ipcp_flow_alloc(pid_t         api,                      int           port_id, -                    pid_t         n_pid, +                    pid_t         n_api,                      char *        dst_name,                      char *        src_ae_name,                      enum qos_cube qos) @@ -375,14 +373,14 @@ int ipcp_flow_alloc(pid_t         pid,          msg.code         = IPCP_MSG_CODE__IPCP_FLOW_ALLOC;          msg.has_port_id  = true;          msg.port_id      = port_id; -        msg.has_pid      = true; -        msg.pid          = n_pid; +        msg.has_api      = true; +        msg.api          = n_api;          msg.src_ae_name  = src_ae_name;          msg.dst_name     = dst_name;          msg.has_qos_cube = true;          msg.qos_cube     = qos; -        recv_msg = send_recv_ipcp_msg(pid, &msg); +        recv_msg = send_recv_ipcp_msg(api, &msg);          if (recv_msg == NULL)                  return -1; @@ -397,9 +395,9 @@ int ipcp_flow_alloc(pid_t         pid,          return ret;  } -int ipcp_flow_alloc_resp(pid_t pid, +int ipcp_flow_alloc_resp(pid_t api,                           int   port_id, -                         pid_t n_pid, +                         pid_t n_api,                           int   response)  {          ipcp_msg_t msg = IPCP_MSG__INIT; @@ -409,12 +407,12 @@ int ipcp_flow_alloc_resp(pid_t pid,          msg.code         = IPCP_MSG_CODE__IPCP_FLOW_ALLOC_RESP;          msg.has_port_id  = true;          msg.port_id      = port_id; -        msg.has_pid      = true; -        msg.pid          = n_pid; +        msg.has_api      = true; +        msg.api          = n_api;          msg.has_response = true;          msg.response     = response; -        recv_msg = send_recv_ipcp_msg(pid, &msg); +        recv_msg = send_recv_ipcp_msg(api, &msg);          if (recv_msg == NULL)                  return -1; @@ -429,7 +427,7 @@ int ipcp_flow_alloc_resp(pid_t pid,          return ret;  } -int ipcp_flow_req_arr(pid_t  pid, +int ipcp_flow_req_arr(pid_t  api,                        char * dst_name,                        char * src_ae_name)  { @@ -441,8 +439,8 @@ int ipcp_flow_req_arr(pid_t  pid,                  return -EINVAL;          msg.code          = IRM_MSG_CODE__IPCP_FLOW_REQ_ARR; -        msg.has_pid       = true; -        msg.pid           = pid; +        msg.has_api       = true; +        msg.api           = api;          msg.dst_name      = dst_name;          msg.ae_name       = src_ae_name; @@ -461,7 +459,7 @@ int ipcp_flow_req_arr(pid_t  pid,          return port_id;  } -int ipcp_flow_alloc_reply(pid_t pid, +int ipcp_flow_alloc_reply(pid_t api,                            int   port_id,                            int   response)  { @@ -491,10 +489,10 @@ int ipcp_flow_alloc_reply(pid_t pid,  } -int ipcp_flow_dealloc(pid_t pid, +int ipcp_flow_dealloc(pid_t api,                        int   port_id)  { -        if (pid != 0) { +        if (api != 0) {                  ipcp_msg_t msg = IPCP_MSG__INIT;                  ipcp_msg_t * recv_msg = NULL;                  int ret = -1; @@ -503,7 +501,7 @@ int ipcp_flow_dealloc(pid_t pid,                  msg.has_port_id = true;                  msg.port_id     = port_id; -                recv_msg = send_recv_ipcp_msg(pid, &msg); +                recv_msg = send_recv_ipcp_msg(api, &msg);                  if (recv_msg == NULL)                          return 0; diff --git a/src/lib/ipcpd_messages.proto b/src/lib/ipcpd_messages.proto index 9eb5707c..f9e0f972 100644 --- a/src/lib/ipcpd_messages.proto +++ b/src/lib/ipcpd_messages.proto @@ -27,7 +27,7 @@ message ipcp_msg {          optional sint32 qos_cube     = 11;          optional dif_config_msg conf = 12;          optional sint32 fd           = 13; -        optional sint32 pid          = 14; +        optional sint32 api          = 14;          optional sint32 response     = 15;          optional sint32 result       = 16;  }; diff --git a/src/lib/irm.c b/src/lib/irm.c index 8fd0a7e7..6b296258 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -27,22 +27,18 @@  #include <ouroboros/common.h>  #include <ouroboros/logs.h>  #include <ouroboros/sockets.h> -#include <ouroboros/instance_name.h>  #include <stdlib.h> -pid_t irm_create_ipcp(char *         ipcp_name, +pid_t irm_create_ipcp(char *         name,                        enum ipcp_type ipcp_type)  {          irm_msg_t msg = IRM_MSG__INIT;          irm_msg_t * recv_msg = NULL;          int ret = -1; -        if (ipcp_name == NULL) -                return -EINVAL; -          msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP; -        msg.ap_name = ipcp_name; +        msg.dst_name = name;          msg.has_ipcp_type = true;          msg.ipcp_type = ipcp_type; @@ -61,19 +57,18 @@ pid_t irm_create_ipcp(char *         ipcp_name,          return ret;  } -int irm_destroy_ipcp(instance_name_t * api) +int irm_destroy_ipcp(pid_t api)  {          irm_msg_t msg = IRM_MSG__INIT;          irm_msg_t * recv_msg = NULL;          int ret = -1; -        if (api == NULL || api->name == NULL) +        if (api == 0)                  return -EINVAL; -        msg.code = IRM_MSG_CODE__IRM_DESTROY_IPCP; -        msg.ap_name = api->name; -        msg.has_api_id = true; -        msg.api_id = api->id; +        msg.code    = IRM_MSG_CODE__IRM_DESTROY_IPCP; +        msg.has_api = true; +        msg.api     = api;          recv_msg = send_recv_irm_msg(&msg);          if (recv_msg == NULL) @@ -90,7 +85,7 @@ int irm_destroy_ipcp(instance_name_t * api)          return ret;  } -int irm_bootstrap_ipcp(instance_name_t   * api, +int irm_bootstrap_ipcp(pid_t               api,                         struct dif_config * conf)  {          irm_msg_t msg = IRM_MSG__INIT; @@ -98,13 +93,12 @@ int irm_bootstrap_ipcp(instance_name_t   * api,          irm_msg_t * recv_msg = NULL;          int ret = -1; -        if (api == NULL || api->name == NULL || conf == NULL) +        if (api == 0 || conf == NULL)                  return -EINVAL; -        msg.code       = IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP; -        msg.ap_name    = api->name; -        msg.has_api_id = true; -        msg.api_id     = api->id; +        msg.code    = IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP; +        msg.has_api = true; +        msg.api     = api;          msg.conf = &config;          config.dif_name = conf->dif_name; @@ -163,20 +157,60 @@ int irm_bootstrap_ipcp(instance_name_t   * api,          return ret;  } -int irm_enroll_ipcp(instance_name_t * api, -                    char *            dif_name) +ssize_t irm_list_ipcps(char *   name, +                       pid_t ** apis) +{ +        irm_msg_t msg = IRM_MSG__INIT; +        irm_msg_t * recv_msg = NULL; +        ssize_t nr = -1; +        int i; + +        if (apis == NULL) +                return -EINVAL; + +        msg.code = IRM_MSG_CODE__IRM_LIST_IPCPS; +        msg.dst_name = name; + +        recv_msg = send_recv_irm_msg(&msg); +        if (recv_msg == NULL) { +                free(msg.dif_name); +                return -1; +        } + +        if (recv_msg->apis == NULL) { +                irm_msg__free_unpacked(recv_msg, NULL); +                return -1; +        } + +        nr = recv_msg->n_apis; +        *apis = malloc(nr * sizeof(pid_t)); +        if (*apis == NULL) { +                irm_msg__free_unpacked(recv_msg, NULL); +                return -ENOMEM; +        } + +        for (i = 0; i < nr; i++) { +                (*apis)[i] = recv_msg->apis[i]; +        } + +        irm_msg__free_unpacked(recv_msg, NULL); + +        return nr; +} + +int irm_enroll_ipcp(pid_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) +        if (api == 0 || dif_name == NULL)                  return -EINVAL;          msg.code = IRM_MSG_CODE__IRM_ENROLL_IPCP; -        msg.ap_name = api->name; -        msg.has_api_id = true; -        msg.api_id = api->id; +        msg.has_api = true; +        msg.api = api;          msg.n_dif_name = 1;          msg.dif_name = malloc(sizeof(*(msg.dif_name)));          if (msg.dif_name == NULL) { @@ -203,39 +237,30 @@ int irm_enroll_ipcp(instance_name_t * api,          return ret;  } -int irm_reg(char *            name, -            instance_name_t * api, -            int               argc, -            char **           argv, -            bool              autoexec, -            char **           difs, -            size_t            difs_len) +int irm_bind(char *   name, +             char *   ap_name, +             uint16_t opts, +             int      argc, +             char **  argv)  {          irm_msg_t msg = IRM_MSG__INIT;          irm_msg_t * recv_msg = NULL;          int ret = -1; -        if (name == NULL || api->name == NULL) +        if (name == NULL || ap_name == NULL)                  return -EINVAL; -        msg.code = IRM_MSG_CODE__IRM_AP_REG; +        msg.code = IRM_MSG_CODE__IRM_BIND;          msg.dst_name = name; -        msg.ap_name = api->name; -        if (difs != NULL) { -                msg.dif_name = difs; -                msg.n_dif_name = difs_len; -        } +        msg.ap_name = ap_name;          if (argv != NULL) {                  msg.n_args = argc;                  msg.args = argv; -        } else { -                msg.has_api_id = true; -                msg.api_id = api->id;          } -        msg.has_autoexec = true; -        msg.autoexec = autoexec; +        msg.has_opts = true; +        msg.opts = opts;          recv_msg = send_recv_irm_msg(&msg);          if (recv_msg == NULL) @@ -252,36 +277,90 @@ int irm_reg(char *            name,          return ret;  } -int irm_unreg(char *                  name, -              const instance_name_t * api, -              char **                 difs, -              size_t                  difs_len, -              bool                    hard) +int irm_unbind(char *   name, +               char *   ap_name, +               uint16_t opts)  {          irm_msg_t msg = IRM_MSG__INIT;          irm_msg_t * recv_msg = NULL;          int ret = -1; -        if (name == NULL && api == NULL) +        if (name == NULL || ap_name == NULL)                  return -EINVAL; -        if (difs == NULL || -            difs_len == 0 || -            difs[0] == NULL) +        msg.code = IRM_MSG_CODE__IRM_UNBIND; + +        msg.dst_name = name; +        msg.ap_name = ap_name; +        msg.has_opts = true; +        msg.opts = opts; + +        recv_msg = send_recv_irm_msg(&msg); +        if (recv_msg == NULL) +                return -1; + +        if (recv_msg->has_result == false) { +                irm_msg__free_unpacked(recv_msg, NULL); +                return -1; +        } + +        ret = recv_msg->result; +        irm_msg__free_unpacked(recv_msg, NULL); + +        return ret; +} + +int irm_reg(char *   name, +            char **  difs, +            size_t   difs_size) +{ +        irm_msg_t msg = IRM_MSG__INIT; +        irm_msg_t * recv_msg = NULL; +        int ret = -1; + +        if (name == NULL || difs == NULL || difs_size == 0)                  return -EINVAL; -        msg.code = IRM_MSG_CODE__IRM_AP_UNREG; -        if (api != NULL) { -                msg.ap_name = api->name; -                msg.has_api_id = true; -                msg.api_id = api->id; +        msg.code = IRM_MSG_CODE__IRM_REG; + +        msg.dst_name = name; + +        msg.dif_name = difs; +        msg.n_dif_name = difs_size; + +        recv_msg = send_recv_irm_msg(&msg); +        if (recv_msg == NULL) +                return -1; + +        if (recv_msg->has_result == false) { +                irm_msg__free_unpacked(recv_msg, NULL); +                return -1;          } +        ret = recv_msg->result; +        irm_msg__free_unpacked(recv_msg, NULL); + +        return ret; +} + + +int irm_unreg(char *   name, +              char **  difs, +              size_t   difs_size) +{ +        irm_msg_t msg = IRM_MSG__INIT; +        irm_msg_t * recv_msg = NULL; +        int ret = -1; + +        if (name == NULL || difs == NULL || difs_size == 0) +                return -EINVAL; + +        msg.code = IRM_MSG_CODE__IRM_UNREG; + +        msg.dst_name = name; +          msg.dif_name = difs; -        msg.n_dif_name = difs_len; -        if (name != NULL) -                msg.dst_name = name; -        msg.hard = hard; +        msg.n_dif_name = difs_size;          recv_msg = send_recv_irm_msg(&msg);          if (recv_msg == NULL) diff --git a/src/lib/irmd_messages.proto b/src/lib/irmd_messages.proto index 34366975..fa2ca258 100644 --- a/src/lib/irmd_messages.proto +++ b/src/lib/irmd_messages.proto @@ -25,35 +25,37 @@ import "dif_config.proto";  enum irm_msg_code {          IRM_CREATE_IPCP       =  1;          IRM_DESTROY_IPCP      =  2; -        IRM_BOOTSTRAP_IPCP    =  3; -        IRM_ENROLL_IPCP       =  4; -        IRM_AP_REG            =  5; -        IRM_AP_UNREG          =  6; -        IRM_FLOW_ACCEPT       =  7; -        IRM_FLOW_ALLOC_RESP   =  8; -        IRM_FLOW_ALLOC        =  9; -        IRM_FLOW_ALLOC_RES    = 10; -        IRM_FLOW_DEALLOC      = 11; -        IPCP_FLOW_REQ_ARR     = 12; -        IPCP_FLOW_ALLOC_REPLY = 13; -        IPCP_FLOW_DEALLOC     = 14; -        IRM_REPLY             = 15; +        IRM_LIST_IPCPS        =  3; +        IRM_BOOTSTRAP_IPCP    =  4; +        IRM_ENROLL_IPCP       =  5; +        IRM_BIND              =  6; +        IRM_UNBIND            =  7; +        IRM_REG               =  8; +        IRM_UNREG             =  9; +        IRM_FLOW_ACCEPT       = 10; +        IRM_FLOW_ALLOC_RESP   = 11; +        IRM_FLOW_ALLOC        = 12; +        IRM_FLOW_ALLOC_RES    = 13; +        IRM_FLOW_DEALLOC      = 14; +        IPCP_FLOW_REQ_ARR     = 15; +        IPCP_FLOW_ALLOC_REPLY = 16; +        IPCP_FLOW_DEALLOC     = 17; +        IRM_REPLY             = 18;  };  message irm_msg {          required irm_msg_code code   =  1;          optional string ap_name      =  2; -        optional string ae_name      =  4; -        optional uint32 api_id       =  3; +        optional string ae_name      =  3; +        optional uint32 api          =  4;          optional uint32 ipcp_type    =  5;          repeated string dif_name     =  6;          repeated string args         =  7;          optional sint32 response     =  8;          optional string dst_name     =  9;          optional sint32 port_id      = 10; -        optional int32 pid           = 11; -        optional dif_config_msg conf = 12; -        optional bool autoexec       = 13; -        optional bool hard           = 14; -        optional sint32 result       = 15; +        optional dif_config_msg conf = 11; +        optional uint32 opts         = 12; +        repeated int32 apis          = 13; +        optional sint32 result       = 14;  }; diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c index 6ee2936c..69e96c40 100644 --- a/src/lib/shm_ap_rbuff.c +++ b/src/lib/shm_ap_rbuff.c @@ -55,7 +55,7 @@ struct shm_ap_rbuff {          size_t *          ptr_tail;    /* start of ringbuffer tail */          pthread_mutex_t * shm_mutex;   /* lock all free space in shm */          pthread_cond_t *  work;        /* threads will wait for a signal */ -        pid_t             pid;         /* pid to which this rb belongs */ +        pid_t             api;         /* api to which this rb belongs */          int               fd;  }; @@ -138,19 +138,19 @@ struct shm_ap_rbuff * shm_ap_rbuff_create()          *rb->ptr_tail = 0;          rb->fd  = shm_fd; -        rb->pid = getpid(); +        rb->api = getpid();          return rb;  } -struct shm_ap_rbuff * shm_ap_rbuff_open(pid_t pid) +struct shm_ap_rbuff * shm_ap_rbuff_open(pid_t api)  {          struct shm_ap_rbuff * rb;          int                   shm_fd;          struct rb_entry *     shm_base;          char                  fn[25]; -        sprintf(fn, SHM_AP_RBUFF_PREFIX "%d", pid); +        sprintf(fn, SHM_AP_RBUFF_PREFIX "%d", api);          rb = malloc(sizeof(*rb));          if (rb == NULL) { @@ -190,7 +190,7 @@ struct shm_ap_rbuff * shm_ap_rbuff_open(pid_t pid)          rb->work      = (pthread_cond_t *) (rb->shm_mutex + 1);          rb->fd = shm_fd; -        rb->pid = pid; +        rb->api = api;          return rb;  } @@ -219,7 +219,7 @@ void shm_ap_rbuff_destroy(struct shm_ap_rbuff * rb)                  return;          } -        if (rb->pid != getpid()) { +        if (rb->api != getpid()) {                  LOG_ERR("Tried to destroy other AP's rbuff.");                  return;          } @@ -227,7 +227,7 @@ void shm_ap_rbuff_destroy(struct shm_ap_rbuff * rb)          if (close(rb->fd) < 0)                  LOG_DBGF("Couldn't close shared memory."); -        sprintf(fn, SHM_AP_RBUFF_PREFIX "%d", rb->pid); +        sprintf(fn, SHM_AP_RBUFF_PREFIX "%d", rb->api);          if (munmap(rb->shm_base, SHM_RBUFF_FILE_SIZE) == -1)                  LOG_DBGF("Couldn't unmap shared memory."); diff --git a/src/lib/shm_du_map.c b/src/lib/shm_du_map.c index f5909e11..2a316265 100644 --- a/src/lib/shm_du_map.c +++ b/src/lib/shm_du_map.c @@ -75,7 +75,7 @@ struct shm_du_map {          size_t *          ptr_tail;    /* start of ringbuffer tail */          pthread_mutex_t * shm_mutex;   /* lock all free space in shm */          pthread_cond_t *  sanitize;    /* run sanitizer when buffer full */ -        pid_t *           pid;         /* pid of the irmd owner */ +        pid_t *           api;         /* api of the irmd owner */          int               fd;  }; @@ -141,7 +141,7 @@ struct shm_du_map * shm_du_map_create()          dum->ptr_tail = dum->ptr_head + 1;          dum->shm_mutex = (pthread_mutex_t *) (dum->ptr_tail + 1);          dum->sanitize = (pthread_cond_t *) (dum->shm_mutex + 1); -        dum->pid = (pid_t *) (dum->sanitize + 1); +        dum->api = (pid_t *) (dum->sanitize + 1);          pthread_mutexattr_init(&mattr);          pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED); @@ -155,7 +155,7 @@ struct shm_du_map * shm_du_map_create()          *dum->ptr_head = 0;          *dum->ptr_tail = 0; -        *dum->pid = getpid(); +        *dum->api = getpid();          dum->fd = shm_fd; @@ -203,7 +203,7 @@ struct shm_du_map * shm_du_map_open()          dum->ptr_tail = dum->ptr_head + 1;          dum->shm_mutex = (pthread_mutex_t *) (dum->ptr_tail + 1);          dum->sanitize = (pthread_cond_t *) (dum->shm_mutex + 1); -        dum->pid = (pid_t *) (dum->sanitize + 1); +        dum->api = (pid_t *) (dum->sanitize + 1);          dum->fd = shm_fd; @@ -212,7 +212,7 @@ struct shm_du_map * shm_du_map_open()  pid_t shm_du_map_owner(struct shm_du_map * dum)  { -        return *dum->pid; +        return *dum->api;  }  void * shm_du_map_sanitize(void * o) diff --git a/src/lib/sockets.c b/src/lib/sockets.c index 403d2833..9bfbad5e 100644 --- a/src/lib/sockets.c +++ b/src/lib/sockets.c @@ -149,19 +149,19 @@ irm_msg_t * send_recv_irm_msg(irm_msg_t * msg)  } -char * ipcp_sock_path(pid_t pid) +char * ipcp_sock_path(pid_t api)  {          char * full_name = NULL; -        char * pid_string = NULL; +        char * api_string = NULL;          size_t len = 0;          char * delim = "_"; -        len = n_digits(pid); -        pid_string = malloc(len + 1); -        if (pid_string == NULL) +        len = n_digits(api); +        api_string = malloc(len + 1); +        if (api_string == NULL)                  return NULL; -        sprintf(pid_string, "%d", pid); +        sprintf(api_string, "%d", api);          len += strlen(IPCP_SOCK_PATH_PREFIX);          len += strlen(delim); @@ -169,16 +169,16 @@ char * ipcp_sock_path(pid_t pid)          full_name = malloc(len + 1);          if (full_name == NULL) { -                free(pid_string); +                free(api_string);                  return NULL;          }          strcpy(full_name, IPCP_SOCK_PATH_PREFIX);          strcat(full_name, delim); -        strcat(full_name, pid_string); +        strcat(full_name, api_string);          strcat(full_name, SOCK_PATH_SUFFIX); -        free(pid_string); +        free(api_string);          return full_name;  } | 
