diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/dif_config.proto | 25 | ||||
| -rw-r--r-- | src/lib/flow.c | 6 | ||||
| -rw-r--r-- | src/lib/ipcp.c | 142 | ||||
| -rw-r--r-- | src/lib/ipcpd_messages.proto | 20 | ||||
| -rw-r--r-- | src/lib/irm.c | 10 | ||||
| -rw-r--r-- | src/lib/irmd_messages.proto | 27 | ||||
| -rw-r--r-- | src/lib/sockets.c | 7 | ||||
| -rw-r--r-- | src/lib/utils.c | 2 | 
8 files changed, 135 insertions, 104 deletions
| diff --git a/src/lib/dif_config.proto b/src/lib/dif_config.proto index 87cb222f..05b35ea7 100644 --- a/src/lib/dif_config.proto +++ b/src/lib/dif_config.proto @@ -1,16 +1,17 @@  message dif_config_msg { -        required string dif_name = 1; -        required int32 ipcp_type = 2; +        required string dif_name        =  1; +        required int32 ipcp_type        =  2;          // Config for normal IPCP -        optional uint32 addr_size = 3; -        optional uint32 cep_id_size = 4; -        optional uint32 pdu_length_size = 5; -        optional uint32 qos_id_size = 6; -        optional uint32 seqno_size = 7; -        optional uint32 ttl_size = 8; -        optional uint32 chk_size = 9; -        optional uint32 min_pdu_size = 10; -        optional uint32 max_pdu_size = 11; +        optional uint32 addr_size       =  3; +        optional uint32 cep_id_size     =  4; +        optional uint32 pdu_length_size =  5; +        optional uint32 qos_id_size     =  6; +        optional uint32 seqno_size      =  7; +        optional uint32 ttl_size        =  8; +        optional uint32 chk_size        =  9; +        optional uint32 min_pdu_size    = 10; +        optional uint32 max_pdu_size    = 11;          // Config for shim UDP -        optional uint32 ip_addr = 12; +        optional uint32 ip_addr         = 12; +        optional uint32 dns_addr        = 13;  }
\ No newline at end of file diff --git a/src/lib/flow.c b/src/lib/flow.c index 593bef1a..da0ca148 100644 --- a/src/lib/flow.c +++ b/src/lib/flow.c @@ -35,9 +35,11 @@ flow_t * flow_create(int32_t port_id)                  return NULL;          } +        INIT_LIST_HEAD(&flow->list); +          flow->port_id = port_id;          flow->oflags = FLOW_O_DEFAULT; -        flow->state = FLOW_INIT; +        flow->state = FLOW_NULL;          pthread_mutex_init(&flow->lock, NULL); @@ -46,6 +48,8 @@ flow_t * flow_create(int32_t port_id)  void flow_destroy(flow_t * flow)  { +        if (flow == NULL) +                return;          free(flow);  } diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c index a0febe4e..338d8683 100644 --- a/src/lib/ipcp.c +++ b/src/lib/ipcp.c @@ -61,7 +61,7 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t pid,                 return NULL;         } -       buf.data = malloc(buf.size); +       buf.data = malloc(IPCP_MSG_BUF_SIZE);         if (buf.data == NULL) {                 close(sockfd);                 free(sock_path); @@ -103,10 +103,14 @@ pid_t ipcp_create(instance_name_t * api,                    enum ipcp_type    ipcp_type)  {          pid_t pid = 0; +        char irmd_pid[10];          char * api_id = NULL;          size_t len = 0; -        char * ipcp_dir = "bin/ipcpd"; +        char * ipcp_dir = "bin";          char * full_name = NULL; +        char * exec_name = NULL; + +        sprintf (irmd_pid, "%u", getpid());          pid = fork();          if (pid == -1) { @@ -125,10 +129,21 @@ pid_t ipcp_create(instance_name_t * api,          }          sprintf(api_id, "%d", api->id); +        if (ipcp_type == IPCP_NORMAL) +                exec_name = IPCP_NORMAL_EXEC; +        else if (ipcp_type == IPCP_SHIM_UDP) +                exec_name = IPCP_SHIM_UDP_EXEC; +        else { +                free(api_id); +                exit(EXIT_FAILURE); +        } +          len += strlen(INSTALL_DIR);          len += strlen(ipcp_dir); -        len += 2; -        full_name = malloc(len); +        len += strlen(exec_name); +        len += 3; + +        full_name = malloc(len + 1);          if (full_name == NULL) {                  LOG_ERR("Failed to malloc");                  free(api_id); @@ -138,9 +153,16 @@ pid_t ipcp_create(instance_name_t * api,          strcpy(full_name, INSTALL_DIR);          strcat(full_name, "/");          strcat(full_name, ipcp_dir); +        strcat(full_name, "/"); +        strcat(full_name, exec_name); +        full_name[len] = '\0'; + +        LOG_DBG("Full name is %s", full_name);          char * argv[] = {full_name, -                         api->name, api_id, +                         irmd_pid, +                         api->name, +                         api_id,                           0};          char * envp[] = {0}; @@ -172,22 +194,22 @@ int ipcp_destroy(pid_t pid)          return 0;  } -int ipcp_reg(pid_t pid, -             char ** difs, -             size_t difs_size) +int ipcp_reg(pid_t   pid, +             char ** dif_names, +             size_t  len)  {          ipcp_msg_t msg = IPCP_MSG__INIT;          ipcp_msg_t * recv_msg = NULL;          int ret = -1; -        if (difs == NULL || -            difs_size == 0 || -            difs[0] == NULL) +        if (dif_names == NULL || +            len == 0 || +            dif_names[0] == NULL)                  return -EINVAL; -        msg.code = IPCP_MSG_CODE__IPCP_REG; -        msg.dif_name = difs; -        msg.n_dif_name = difs_size; +        msg.code       = IPCP_MSG_CODE__IPCP_REG; +        msg.dif_names  = dif_names; +        msg.len        = len;          recv_msg = send_recv_ipcp_msg(pid, &msg);          if (recv_msg == NULL) @@ -205,21 +227,21 @@ int ipcp_reg(pid_t pid,  }  int ipcp_unreg(pid_t pid, -               char ** difs, -               size_t difs_size) +               char ** dif_names, +               size_t len)  {          ipcp_msg_t msg = IPCP_MSG__INIT;          ipcp_msg_t * recv_msg = NULL;          int ret = -1; -        if (difs == NULL || -            difs_size == 0 || -            difs[0] == NULL) +        if (dif_names == NULL || +            len == 0 || +            dif_names[0] == NULL)                  return -EINVAL; -        msg.code = IPCP_MSG_CODE__IPCP_UNREG; -        msg.dif_name = difs; -        msg.n_dif_name = difs_size; +        msg.code       = IPCP_MSG_CODE__IPCP_UNREG; +        msg.dif_names  = dif_names; +        msg.len        = len;          recv_msg = send_recv_ipcp_msg(pid, &msg);          if (recv_msg == NULL) @@ -276,36 +298,36 @@ int ipcp_enroll(pid_t pid,          if (n_1_dif == 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"); +        msg.code        = IPCP_MSG_CODE__IPCP_ENROLL; +        msg.member_name = malloc(sizeof(*(msg.member_name))); +        if (msg.member_name == NULL) { +                LOG_ERR("Failed to malloc.");                  return -1;          } -        msg.dif_name[0] = n_1_dif; -        msg.ap_name = member_name; +        msg.n_1_dif     = n_1_dif; +        msg.member_name = member_name;          recv_msg = send_recv_ipcp_msg(pid, &msg);          if (recv_msg == NULL) { -                free(msg.dif_name); +                free(msg.member_name);                  return -1;          }          if (recv_msg->has_result == false) {                  ipcp_msg__free_unpacked(recv_msg, NULL); -                free(msg.dif_name); +                free(msg.member_name);                  return -1;          }          ret = recv_msg->result;          ipcp_msg__free_unpacked(recv_msg, NULL); -        free(msg.dif_name); +        free(msg.member_name);          return ret;  }  int ipcp_ap_reg(pid_t    pid, -                uint32_t reg_api_id, +                uint32_t reg_ap_id,                  char *   ap_name)  {          ipcp_msg_t msg = IPCP_MSG__INIT; @@ -315,10 +337,10 @@ int ipcp_ap_reg(pid_t    pid,          if (ap_name == NULL)                  return -1; -        msg.code = IPCP_MSG_CODE__IPCP_AP_REG; -        msg.ap_name = ap_name; -        msg.has_port_id = true; -        msg.port_id = reg_api_id; +        msg.code          = IPCP_MSG_CODE__IPCP_AP_REG; +        msg.ap_name       = ap_name; +        msg.has_reg_ap_id = true; +        msg.reg_ap_id     = reg_ap_id;          recv_msg = send_recv_ipcp_msg(pid, &msg);          if (recv_msg == NULL) @@ -336,15 +358,15 @@ int ipcp_ap_reg(pid_t    pid,  }  int ipcp_ap_unreg(pid_t    pid, -                  uint32_t reg_api_id) +                  uint32_t reg_ap_id)  {          ipcp_msg_t msg = IPCP_MSG__INIT;          ipcp_msg_t * recv_msg = NULL;          int ret = -1; -        msg.code = IPCP_MSG_CODE__IPCP_AP_UNREG; -        msg.has_port_id = true; -        msg.port_id = reg_api_id; +        msg.code          = IPCP_MSG_CODE__IPCP_AP_UNREG; +        msg.has_reg_ap_id = true; +        msg.reg_ap_id     = reg_ap_id;          recv_msg = send_recv_ipcp_msg(pid, &msg);          if (recv_msg == NULL) @@ -375,12 +397,12 @@ int ipcp_flow_alloc(pid_t             pid,          if (dst_ap_name == NULL || src_ap_name == NULL || src_ae_name == NULL)                  return -EINVAL; -        msg.code = IPCP_MSG_CODE__IPCP_FLOW_ALLOC; -        msg.ap_name = src_ap_name; -        msg.ae_name = src_ae_name; +        msg.code        = IPCP_MSG_CODE__IPCP_FLOW_ALLOC; +        msg.ap_name     = src_ap_name; +        msg.ae_name     = src_ae_name;          msg.dst_ap_name = dst_ap_name; +        msg.port_id     = port_id;          msg.has_port_id = true; -        msg.port_id = port_id;          recv_msg = send_recv_ipcp_msg(pid, &msg);          if (recv_msg == NULL) @@ -405,11 +427,11 @@ int ipcp_flow_alloc_resp(pid_t    pid,          ipcp_msg_t * recv_msg = NULL;          int ret = -1; -        msg.code = IPCP_MSG_CODE__IPCP_FLOW_ALLOC_RESP; +        msg.code        = IPCP_MSG_CODE__IPCP_FLOW_ALLOC_RESP;          msg.has_port_id = true; -        msg.port_id = port_id; -        msg.has_result = true; -        msg.result = result; +        msg.port_id     = port_id; +        msg.has_result  = true; +        msg.result      = result;          recv_msg = send_recv_ipcp_msg(pid, &msg);          if (recv_msg == NULL) @@ -427,7 +449,7 @@ int ipcp_flow_alloc_resp(pid_t    pid,  }  int ipcp_flow_req_arr(pid_t    pid, -                      uint32_t reg_api_id, +                      uint32_t reg_ap_id,                        char *   ap_name,                        char *   ae_name)  { @@ -438,13 +460,13 @@ int ipcp_flow_req_arr(pid_t    pid,          if (ap_name == NULL || ae_name == NULL)                  return -EINVAL; -        msg.code = IRM_MSG_CODE__IPCP_FLOW_REQ_ARR; -        msg.ap_name = ap_name; -        msg.ae_name = ae_name; -        msg.port_id = reg_api_id; -        msg.has_port_id = true; -        msg.pid = pid; -        msg.has_pid = true; +        msg.code          = IRM_MSG_CODE__IPCP_FLOW_REQ_ARR; +        msg.ap_name       = ap_name; +        msg.ae_name       = ae_name; +        msg.reg_ap_id     = reg_ap_id; +        msg.has_reg_ap_id = true; +        msg.pid           = pid; +        msg.has_pid       = true;          recv_msg = send_recv_irm_msg(&msg);          if (recv_msg == NULL) @@ -469,11 +491,11 @@ int ipcp_flow_alloc_reply(pid_t    pid,          irm_msg_t * recv_msg = NULL;          int ret = -1; -        msg.code = IRM_MSG_CODE__IPCP_FLOW_ALLOC_REPLY; -        msg.port_id = port_id; +        msg.code        = IRM_MSG_CODE__IPCP_FLOW_ALLOC_REPLY; +        msg.port_id     = port_id;          msg.has_port_id = true; -        msg.result = result; -        msg.has_result = true; +        msg.result      = result; +        msg.has_result  = true;          recv_msg = send_recv_irm_msg(&msg);          if (recv_msg == NULL) diff --git a/src/lib/ipcpd_messages.proto b/src/lib/ipcpd_messages.proto index b83c34c7..796638c7 100644 --- a/src/lib/ipcpd_messages.proto +++ b/src/lib/ipcpd_messages.proto @@ -14,12 +14,16 @@ enum ipcp_msg_code {  };  message ipcp_msg { -        required ipcp_msg_code code = 1; -        optional string ap_name = 2; -        optional dif_config_msg conf = 3; -        repeated string dif_name = 4; -        optional int32 result = 5; -        optional uint32 port_id = 6; -        optional string ae_name = 7; -        optional string dst_ap_name = 8; +        required ipcp_msg_code code  =  1; +        optional string member_name  =  2; +        optional string n_1_dif      =  3; +        repeated string dif_names    =  4; +        optional int32  len          =  5; +        optional string ap_name      =  6; +        optional int32 reg_ap_id     =  7; +        optional int32 port_id       =  8; +        optional string dst_ap_name  =  9; +        optional string ae_name      = 10; +        optional dif_config_msg conf = 11; +        optional int32 result        = 12;  }; diff --git a/src/lib/irm.c b/src/lib/irm.c index 70b7b3a5..b17cb04c 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -44,6 +44,7 @@ int irm_create_ipcp(instance_name_t * api,          msg.ap_name = api->name;          msg.has_api_id = true;          msg.api_id = api->id; +        msg.has_ipcp_type = true;          msg.ipcp_type = ipcp_type;          recv_msg = send_recv_irm_msg(&msg); @@ -101,10 +102,10 @@ int irm_bootstrap_ipcp(instance_name_t   * api,          if (api == NULL || api->name == NULL || conf == NULL)                  return -EINVAL; -        msg.code = IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP; -        msg.ap_name = api->name; +        msg.code       = IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP; +        msg.ap_name    = api->name;          msg.has_api_id = true; -        msg.api_id = api->id; +        msg.api_id     = api->id;          msg.conf = &config;          config.dif_name = conf->dif_name; @@ -134,8 +135,9 @@ int irm_bootstrap_ipcp(instance_name_t   * api,                  break;          case IPCP_SHIM_UDP:                  config.has_ip_addr = true; -                  config.ip_addr = conf->ip_addr; +                config.has_dns_addr = true; +                config.dns_addr = conf->dns_addr;                  break;          default:                  return -1; diff --git a/src/lib/irmd_messages.proto b/src/lib/irmd_messages.proto index 3a2432f3..92ea439e 100644 --- a/src/lib/irmd_messages.proto +++ b/src/lib/irmd_messages.proto @@ -24,17 +24,18 @@ enum irm_msg_code {  };  message irm_msg { -        required irm_msg_code code = 1; -        optional string ap_name = 2; -        optional uint32 api_id = 3; -        optional string ae_name = 4; -        optional uint32 ipcp_type = 5; -        repeated string dif_name = 6; -        optional int32 fd = 7; -        optional int32 result = 8; -        optional int32 oflags = 9; -        optional string dst_ap_name = 10; -        optional uint32 port_id = 11; -        optional int32 pid = 12; -        optional dif_config_msg conf = 13; +        required irm_msg_code code   =  1; +        optional string ap_name      =  2; +        optional uint32 api_id       =  3; +        optional string ae_name      =  4; +        optional uint32 ipcp_type    =  5; +        repeated string dif_name     =  6; +        optional int32 fd            =  7; +        optional int32 result        =  8; +        optional int32 oflags        =  9; +        optional string dst_ap_name  = 10; +        optional uint32 port_id      = 11; +        optional uint32 reg_ap_id    = 12; +        optional int32 pid           = 13; +        optional dif_config_msg conf = 14;  }; diff --git a/src/lib/sockets.c b/src/lib/sockets.c index 805dda39..4f777805 100644 --- a/src/lib/sockets.c +++ b/src/lib/sockets.c @@ -29,7 +29,6 @@  #include <sys/socket.h>  #include <sys/un.h> -#include <sys/stat.h>  #include <string.h>  #include <stdlib.h> @@ -61,9 +60,8 @@ int server_socket_open(char * file_name)  {          int sockfd;          struct sockaddr_un serv_addr; -        struct stat sb; -        if (!stat(file_name, &sb)) { +        if (access(file_name, F_OK) != -1) {                  /* File exists */                  if (unlink(file_name)) {                          LOG_ERR("Failed to unlink filename: %s", @@ -113,8 +111,7 @@ irm_msg_t * send_recv_irm_msg(irm_msg_t * msg)                  return NULL;          } -        LOG_DBG("Size will be %lu", buf.size); -        buf.data = malloc(buf.size); +        buf.data = malloc(IRM_MSG_BUF_SIZE);          if (buf.data == NULL) {                  close(sockfd);                  return NULL; diff --git a/src/lib/utils.c b/src/lib/utils.c index 77a2d44c..5744fb7c 100644 --- a/src/lib/utils.c +++ b/src/lib/utils.c @@ -28,7 +28,7 @@ int n_digits(unsigned i)      int n = 1;      while (i > 9) { -        n++; +        ++n;          i /= 10;      } | 
