summaryrefslogtreecommitdiff
path: root/src/ipcpd
diff options
context:
space:
mode:
Diffstat (limited to 'src/ipcpd')
-rw-r--r--src/ipcpd/ipcp-ops.h8
-rw-r--r--src/ipcpd/ipcp.c342
-rw-r--r--src/ipcpd/ipcp.h2
-rw-r--r--src/ipcpd/normal/fmgr.h12
-rw-r--r--src/ipcpd/normal/frct.c14
-rw-r--r--src/ipcpd/normal/frct.h12
6 files changed, 192 insertions, 198 deletions
diff --git a/src/ipcpd/ipcp-ops.h b/src/ipcpd/ipcp-ops.h
index 9872b00c..d780c6dc 100644
--- a/src/ipcpd/ipcp-ops.h
+++ b/src/ipcpd/ipcp-ops.h
@@ -37,10 +37,10 @@ struct ipcp_ops {
int (* ipcp_name_query)(char * name);
- int (* ipcp_flow_alloc)(int fd,
- char * dst_ap_name,
- char * src_ae_name,
- enum qos_cube qos);
+ int (* ipcp_flow_alloc)(int fd,
+ char * dst_ap_name,
+ char * src_ae_name,
+ qoscube_t qos);
int (* ipcp_flow_alloc_resp)(int fd,
int response);
diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c
index 8bd2ba77..8c0bd0bf 100644
--- a/src/ipcpd/ipcp.c
+++ b/src/ipcpd/ipcp.c
@@ -19,7 +19,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
#define OUROBOROS_PREFIX "ipcpd/ipcp"
#include <ouroboros/config.h>
@@ -37,178 +36,7 @@
#include <sys/socket.h>
#include <stdlib.h>
-int ipcp_init(enum ipcp_type type, struct ipcp_ops * ops)
-{
- pthread_condattr_t cattr;
- int t;
-
- struct timeval tv = {(IPCP_ACCEPT_TIMEOUT / 1000),
- (IPCP_ACCEPT_TIMEOUT % 1000) * 1000};
-
- ipcpi.irmd_fd = -1;
- ipcpi.state = IPCP_INIT;
-
- ipcpi.threadpool = malloc(sizeof(pthread_t) * IPCPD_THREADPOOL_SIZE);
- if (ipcpi.threadpool == NULL) {
- return -ENOMEM;
- }
-
- ipcpi.sock_path = ipcp_sock_path(getpid());
- if (ipcpi.sock_path == NULL) {
- free(ipcpi.threadpool);
- return -1;
- }
-
- ipcpi.sockfd = server_socket_open(ipcpi.sock_path);
- if (ipcpi.sockfd < 0) {
- LOG_ERR("Could not open server socket.");
- free(ipcpi.threadpool);
- free(ipcpi.sock_path);
- return -1;
- }
-
- if (setsockopt(ipcpi.sockfd, SOL_SOCKET, SO_RCVTIMEO,
- (void *) &tv, sizeof(tv)))
- LOG_WARN("Failed to set timeout on socket.");
-
- ipcpi.ops = ops;
-
- ipcpi.data = ipcp_data_create();
- if (ipcpi.data == NULL) {
- free(ipcpi.threadpool);
- free(ipcpi.sock_path);
- return -ENOMEM;
- }
-
- ipcp_data_init(ipcpi.data, type);
-
- pthread_rwlock_init(&ipcpi.state_lock, NULL);
- pthread_mutex_init(&ipcpi.state_mtx, NULL);
- pthread_condattr_init(&cattr);
-#ifndef __APPLE__
- pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK);
-#endif
- pthread_cond_init(&ipcpi.state_cond, &cattr);
-
- for (t = 0; t < IPCPD_THREADPOOL_SIZE; ++t)
- pthread_create(&ipcpi.threadpool[t], NULL,
- ipcp_main_loop, NULL);
-
- return 0;
-}
-
-void ipcp_fini()
-{
- int t;
-
- for (t = 0; t < IPCPD_THREADPOOL_SIZE; ++t)
- pthread_join(ipcpi.threadpool[t], NULL);
-
- close(ipcpi.sockfd);
- if (unlink(ipcpi.sock_path))
- LOG_DBG("Could not unlink %s.", ipcpi.sock_path);
-
- free(ipcpi.sock_path);
- free(ipcpi.threadpool);
-
- ipcp_data_destroy(ipcpi.data);
- pthread_cond_destroy(&ipcpi.state_cond);
- pthread_rwlock_destroy(&ipcpi.state_lock);
-}
-
-void ipcp_set_state(enum ipcp_state state)
-{
- pthread_mutex_lock(&ipcpi.state_mtx);
-
- ipcpi.state = state;
-
- pthread_cond_broadcast(&ipcpi.state_cond);
- pthread_mutex_unlock(&ipcpi.state_mtx);
-}
-
-enum ipcp_state ipcp_get_state()
-{
- enum ipcp_state state;
-
- pthread_mutex_lock(&ipcpi.state_mtx);
-
- state = ipcpi.state;
-
- pthread_mutex_unlock(&ipcpi.state_mtx);
-
- return state;
-}
-
-int ipcp_wait_state(enum ipcp_state state,
- const struct timespec * timeout)
-{
- struct timespec abstime;
-
- clock_gettime(PTHREAD_COND_CLOCK, &abstime);
- ts_add(&abstime, timeout, &abstime);
-
- pthread_mutex_lock(&ipcpi.state_mtx);
-
- while (ipcpi.state != state && ipcpi.state != IPCP_SHUTDOWN) {
- int ret;
- if (timeout == NULL)
- ret = pthread_cond_wait(&ipcpi.state_cond,
- &ipcpi.state_mtx);
- else
- ret = pthread_cond_timedwait(&ipcpi.state_cond,
- &ipcpi.state_mtx,
- &abstime);
- if (ret) {
- pthread_mutex_unlock(&ipcpi.state_mtx);
- return -ret;
- }
- }
-
- pthread_mutex_unlock(&ipcpi.state_mtx);
-
- return 0;
-}
-
-int ipcp_parse_arg(int argc, char * argv[])
-{
- char * log_file;
- size_t len = 0;
-
- if (!(argc == 3 || argc == 2))
- return -1;
-
- /* argument 1: api of irmd */
- if (atoi(argv[1]) == 0)
- return -1;
-
- if (argv[2] == NULL)
- return 0;
-
- len += strlen(INSTALL_PREFIX);
- len += strlen(LOG_DIR);
- len += strlen(argv[2]);
-
- log_file = malloc(len + 1);
- if (log_file == NULL) {
- LOG_ERR("Failed to malloc");
- return -1;
- }
-
- strcpy(log_file, INSTALL_PREFIX);
- strcat(log_file, LOG_DIR);
- strcat(log_file, argv[2]);
- log_file[len] = '\0';
-
- if (set_logfile(log_file))
- LOG_ERR("Cannot open %s, falling back to stdout for logs.",
- log_file);
-
- free(log_file);
-
- return 0;
-}
-
-void * ipcp_main_loop(void * o)
+static void * ipcp_main_loop(void * o)
{
int lsockfd;
uint8_t buf[IPCP_MSG_BUF_SIZE];
@@ -446,3 +274,171 @@ void * ipcp_main_loop(void * o)
return (void *) 0;
}
+
+int ipcp_init(enum ipcp_type type, struct ipcp_ops * ops)
+{
+ pthread_condattr_t cattr;
+ int t;
+
+ struct timeval tv = {(IPCP_ACCEPT_TIMEOUT / 1000),
+ (IPCP_ACCEPT_TIMEOUT % 1000) * 1000};
+
+ ipcpi.irmd_fd = -1;
+ ipcpi.state = IPCP_INIT;
+
+ ipcpi.threadpool = malloc(sizeof(pthread_t) * IPCPD_THREADPOOL_SIZE);
+ if (ipcpi.threadpool == NULL) {
+ return -ENOMEM;
+ }
+
+ ipcpi.sock_path = ipcp_sock_path(getpid());
+ if (ipcpi.sock_path == NULL) {
+ free(ipcpi.threadpool);
+ return -1;
+ }
+
+ ipcpi.sockfd = server_socket_open(ipcpi.sock_path);
+ if (ipcpi.sockfd < 0) {
+ LOG_ERR("Could not open server socket.");
+ free(ipcpi.threadpool);
+ free(ipcpi.sock_path);
+ return -1;
+ }
+
+ if (setsockopt(ipcpi.sockfd, SOL_SOCKET, SO_RCVTIMEO,
+ (void *) &tv, sizeof(tv)))
+ LOG_WARN("Failed to set timeout on socket.");
+
+ ipcpi.ops = ops;
+
+ ipcpi.data = ipcp_data_create();
+ if (ipcpi.data == NULL) {
+ free(ipcpi.threadpool);
+ free(ipcpi.sock_path);
+ return -ENOMEM;
+ }
+
+ ipcp_data_init(ipcpi.data, type);
+
+ pthread_rwlock_init(&ipcpi.state_lock, NULL);
+ pthread_mutex_init(&ipcpi.state_mtx, NULL);
+ pthread_condattr_init(&cattr);
+#ifndef __APPLE__
+ pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK);
+#endif
+ pthread_cond_init(&ipcpi.state_cond, &cattr);
+
+ for (t = 0; t < IPCPD_THREADPOOL_SIZE; ++t)
+ pthread_create(&ipcpi.threadpool[t], NULL,
+ ipcp_main_loop, NULL);
+
+ return 0;
+}
+
+void ipcp_fini()
+{
+ int t;
+
+ for (t = 0; t < IPCPD_THREADPOOL_SIZE; ++t)
+ pthread_join(ipcpi.threadpool[t], NULL);
+
+ close(ipcpi.sockfd);
+ if (unlink(ipcpi.sock_path))
+ LOG_DBG("Could not unlink %s.", ipcpi.sock_path);
+
+ free(ipcpi.sock_path);
+ free(ipcpi.threadpool);
+
+ ipcp_data_destroy(ipcpi.data);
+
+ pthread_cond_destroy(&ipcpi.state_cond);
+ pthread_rwlock_destroy(&ipcpi.state_lock);
+}
+
+void ipcp_set_state(enum ipcp_state state)
+{
+ pthread_mutex_lock(&ipcpi.state_mtx);
+
+ ipcpi.state = state;
+
+ pthread_cond_broadcast(&ipcpi.state_cond);
+ pthread_mutex_unlock(&ipcpi.state_mtx);
+}
+
+enum ipcp_state ipcp_get_state()
+{
+ enum ipcp_state state;
+
+ pthread_mutex_lock(&ipcpi.state_mtx);
+
+ state = ipcpi.state;
+
+ pthread_mutex_unlock(&ipcpi.state_mtx);
+
+ return state;
+}
+
+int ipcp_wait_state(enum ipcp_state state,
+ const struct timespec * timeout)
+{
+ struct timespec abstime;
+ int ret = 0;
+
+ clock_gettime(PTHREAD_COND_CLOCK, &abstime);
+ ts_add(&abstime, timeout, &abstime);
+
+ pthread_mutex_lock(&ipcpi.state_mtx);
+
+ while (ipcpi.state != state && ipcpi.state != IPCP_SHUTDOWN) {
+ if (timeout == NULL)
+ ret = -pthread_cond_wait(&ipcpi.state_cond,
+ &ipcpi.state_mtx);
+ else
+ ret = -pthread_cond_timedwait(&ipcpi.state_cond,
+ &ipcpi.state_mtx,
+ &abstime);
+ }
+
+ pthread_mutex_unlock(&ipcpi.state_mtx);
+
+ return ret;
+}
+
+int ipcp_parse_arg(int argc, char * argv[])
+{
+ char * log_file;
+ size_t len = 0;
+
+ if (!(argc == 3 || argc == 2))
+ return -1;
+
+ /* argument 1: api of irmd */
+ if (atoi(argv[1]) == 0)
+ return -1;
+
+ if (argv[2] == NULL)
+ return 0;
+
+ len += strlen(INSTALL_PREFIX);
+ len += strlen(LOG_DIR);
+ len += strlen(argv[2]);
+
+ log_file = malloc(len + 1);
+ if (log_file == NULL) {
+ LOG_ERR("Failed to malloc");
+ return -1;
+ }
+
+ strcpy(log_file, INSTALL_PREFIX);
+ strcat(log_file, LOG_DIR);
+ strcat(log_file, argv[2]);
+ log_file[len] = '\0';
+
+ if (set_logfile(log_file))
+ LOG_ERR("Cannot open %s, falling back to stdout for logs.",
+ log_file);
+
+ free(log_file);
+
+ return 0;
+}
diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h
index 6cd6f99e..f090f415 100644
--- a/src/ipcpd/ipcp.h
+++ b/src/ipcpd/ipcp.h
@@ -66,8 +66,6 @@ enum ipcp_state ipcp_get_state(void);
int ipcp_wait_state(enum ipcp_state state,
const struct timespec * timeout);
-void * ipcp_main_loop(void * o);
-
int ipcp_parse_arg(int argc,
char * argv[]);
diff --git a/src/ipcpd/normal/fmgr.h b/src/ipcpd/normal/fmgr.h
index 30267666..e17f3f55 100644
--- a/src/ipcpd/normal/fmgr.h
+++ b/src/ipcpd/normal/fmgr.h
@@ -37,10 +37,10 @@ int fmgr_init(void);
int fmgr_fini(void);
-int fmgr_np1_alloc(int fd,
- char * dst_ap_name,
- char * src_ae_name,
- enum qos_cube qos);
+int fmgr_np1_alloc(int fd,
+ char * dst_ap_name,
+ char * src_ae_name,
+ qoscube_t qos);
int fmgr_np1_alloc_resp(int fd,
int response);
@@ -55,8 +55,8 @@ int fmgr_np1_post_sdu(cep_id_t id,
int fmgr_nm1_mgmt_flow(char * dst_name);
-int fmgr_nm1_dt_flow(char * dst_name,
- enum qos_cube qos);
+int fmgr_nm1_dt_flow(char * dst_name,
+ qoscube_t qos);
int fmgr_nm1_write_sdu(struct pci * pci,
struct shm_du_buff * sdb);
diff --git a/src/ipcpd/normal/frct.c b/src/ipcpd/normal/frct.c
index a45e3528..33bd044b 100644
--- a/src/ipcpd/normal/frct.c
+++ b/src/ipcpd/normal/frct.c
@@ -43,7 +43,7 @@ struct frct_i {
uint32_t cep_id;
uint64_t r_address;
uint32_t r_cep_id;
- enum qos_cube cube;
+ qoscube_t cube;
uint64_t seqno;
enum conn_state state;
@@ -217,9 +217,9 @@ static void destroy_frct_i(struct frct_i * instance)
free(instance);
}
-cep_id_t frct_i_create(uint64_t address,
- buffer_t * buf,
- enum qos_cube cube)
+cep_id_t frct_i_create(uint64_t address,
+ buffer_t * buf,
+ qoscube_t cube)
{
struct frct_i * instance;
struct pci pci;
@@ -255,9 +255,9 @@ cep_id_t frct_i_create(uint64_t address,
return id;
}
-int frct_i_accept(cep_id_t id,
- buffer_t * buf,
- enum qos_cube cube)
+int frct_i_accept(cep_id_t id,
+ buffer_t * buf,
+ qoscube_t cube)
{
struct pci pci;
struct frct_i * instance;
diff --git a/src/ipcpd/normal/frct.h b/src/ipcpd/normal/frct.h
index 38dcddf4..39c47cdd 100644
--- a/src/ipcpd/normal/frct.h
+++ b/src/ipcpd/normal/frct.h
@@ -33,13 +33,13 @@ int frct_init(void);
int frct_fini(void);
-cep_id_t frct_i_create(uint64_t address,
- buffer_t * buf,
- enum qos_cube cube);
+cep_id_t frct_i_create(uint64_t address,
+ buffer_t * buf,
+ qoscube_t cube);
-int frct_i_accept(cep_id_t id,
- buffer_t * buf,
- enum qos_cube cube);
+int frct_i_accept(cep_id_t id,
+ buffer_t * buf,
+ qoscube_t cube);
int frct_i_destroy(cep_id_t id,
buffer_t * buf);