summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ipcpd/ipcp.c12
-rw-r--r--src/ipcpd/ipcp.h3
-rw-r--r--src/ipcpd/normal/main.c29
-rw-r--r--src/irmd/ipcp.c26
-rw-r--r--src/irmd/ipcp.h7
-rw-r--r--src/irmd/main.c64
-rw-r--r--src/lib/dev.c140
-rw-r--r--src/lib/ipcpd_messages.proto6
8 files changed, 99 insertions, 188 deletions
diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c
index d682309d..7f3ebc73 100644
--- a/src/ipcpd/ipcp.c
+++ b/src/ipcpd/ipcp.c
@@ -143,9 +143,10 @@ static void * ipcp_main_loop(void * o)
ipcp_config_msg_t * conf_msg;
struct ipcp_config conf;
+ struct dif_info info;
struct timeval ltv = {(SOCKET_TIMEOUT / 1000),
- (SOCKET_TIMEOUT % 1000) * 1000};
+ (SOCKET_TIMEOUT % 1000) * 1000};
ssize_t id = (ssize_t) o;
@@ -259,7 +260,14 @@ static void * ipcp_main_loop(void * o)
break;
}
- ret_msg.result = ipcpi.ops->ipcp_enroll(msg->dst_name);
+ ret_msg.result = ipcpi.ops->ipcp_enroll(msg->dst_name,
+ &info);
+
+ if (ret_msg.result == 0) {
+ ret_msg.has_dir_hash_algo = true;
+ ret_msg.dir_hash_algo = info.algo;
+ ret_msg.dif_name = info.dif_name;
+ }
break;
case IPCP_MSG_CODE__IPCP_REG:
ret_msg.has_result = true;
diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h
index c78aa5a6..3f5e1bd6 100644
--- a/src/ipcpd/ipcp.h
+++ b/src/ipcpd/ipcp.h
@@ -43,7 +43,8 @@ enum ipcp_state {
struct ipcp_ops {
int (* ipcp_bootstrap)(const struct ipcp_config * conf);
- int (* ipcp_enroll)(const char * dst);
+ int (* ipcp_enroll)(const char * dst,
+ struct dif_info * info);
int (* ipcp_reg)(const uint8_t * hash);
diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c
index 74406d54..42516efd 100644
--- a/src/ipcpd/normal/main.c
+++ b/src/ipcpd/normal/main.c
@@ -116,21 +116,21 @@ static int boot_components(void)
log_dbg("Starting ribmgr.");
- if (ribmgr_init()) {
- log_err("Failed to initialize RIB manager.");
+ if (dir_init()) {
+ log_err("Failed to initialize directory.");
goto fail_addr_auth;
}
- if (dir_init()) {
- log_err("Failed to initialize directory.");
- goto fail_ribmgr;
+ if (ribmgr_init()) {
+ log_err("Failed to initialize RIB manager.");
+ goto fail_dir;
}
log_dbg("Ribmgr started.");
if (frct_init()) {
log_err("Failed to initialize FRCT.");
- goto fail_dir;
+ goto fail_ribmgr;
}
if (fa_init()) {
@@ -180,10 +180,10 @@ static int boot_components(void)
fa_fini();
fail_frct:
frct_fini();
- fail_dir:
- dir_fini();
fail_ribmgr:
ribmgr_fini();
+ fail_dir:
+ dir_fini();
fail_addr_auth:
addr_auth_fini();
fail_name:
@@ -208,16 +208,17 @@ void shutdown_components(void)
frct_fini();
- dir_fini();
-
ribmgr_fini();
+ dir_fini();
+
addr_auth_fini();
free(ipcpi.dif_name);
}
-static int normal_ipcp_enroll(const char * dst)
+static int normal_ipcp_enroll(const char * dst,
+ struct dif_info * info)
{
if (rib_add(RIB_ROOT, MEMBERS_NAME)) {
log_err("Failed to create members.");
@@ -237,7 +238,11 @@ static int normal_ipcp_enroll(const char * dst)
log_dbg("Enrolled with " HASH_FMT, HASH_VAL(dst));
- return ipcpi.dir_hash_algo;
+ info->algo = ipcpi.dir_hash_algo;
+
+ strcpy(info->dif_name, ipcpi.dif_name);
+
+ return 0;
}
const struct ros {
diff --git a/src/irmd/ipcp.c b/src/irmd/ipcp.c
index 7a32dd88..182970b1 100644
--- a/src/irmd/ipcp.c
+++ b/src/irmd/ipcp.c
@@ -212,13 +212,13 @@ int ipcp_bootstrap(pid_t api,
return ret;
}
-/* return the hash algorithm */
-int ipcp_enroll(pid_t api,
- const char * dst)
+int ipcp_enroll(pid_t api,
+ const char * dst,
+ struct dif_info * info)
{
- ipcp_msg_t msg = IPCP_MSG__INIT;
+ ipcp_msg_t msg = IPCP_MSG__INIT;
ipcp_msg_t * recv_msg = NULL;
- int ret = -1;
+ int ret = -1;
if (dst == NULL)
return -EINVAL;
@@ -236,9 +236,23 @@ int ipcp_enroll(pid_t api,
}
ret = recv_msg->result;
+ if (ret != 0) {
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+ return ret;
+ }
+
+ if (!recv_msg->has_dir_hash_algo || recv_msg->dif_name == NULL) {
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+ return -EIPCP;
+ }
+
+ info->algo = recv_msg->dir_hash_algo;
+
+ strcpy(info->dif_name, recv_msg->dif_name);
+
ipcp_msg__free_unpacked(recv_msg, NULL);
- return ret;
+ return 0;
}
int ipcp_reg(pid_t api,
diff --git a/src/irmd/ipcp.h b/src/irmd/ipcp.h
index 11adad7d..74175f97 100644
--- a/src/irmd/ipcp.h
+++ b/src/irmd/ipcp.h
@@ -34,10 +34,11 @@ pid_t ipcp_create(const char * name,
int ipcp_destroy(pid_t api);
-int ipcp_enroll(pid_t api,
- const char * dst);
+int ipcp_enroll(pid_t api,
+ const char * dst,
+ struct dif_info * info);
-int ipcp_bootstrap(pid_t api,
+int ipcp_bootstrap(pid_t api,
ipcp_config_msg_t * conf);
int ipcp_reg(pid_t api,
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 45a348ae..67c2ad60 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -56,7 +56,7 @@
#define IRMD_CLEANUP_TIMER ((IRMD_FLOW_TIMEOUT / 20) * MILLION) /* ns */
#define SHM_SAN_HOLDOFF 1000 /* ms */
-#define IPCP_HASH_LEN(e) (hash_len(e->dir_hash_algo))
+#define IPCP_HASH_LEN(e) hash_len(e->dir_hash_algo)
struct ipcp_entry {
struct list_head next;
@@ -226,27 +226,26 @@ static struct ipcp_entry * get_ipcp_entry_by_name(const char * name)
return NULL;
}
-/*
- * Check if the hash is reachable anywhere in a DIF.
- * FIXME: specify algorithm used
- */
static struct ipcp_entry * get_ipcp_by_dst_name(const char * name)
{
struct list_head * p = NULL;
uint8_t * hash;
list_for_each(p, &irmd.ipcps) {
- struct ipcp_entry * e =
- list_entry(p, struct ipcp_entry, next);
- if (e->dir_hash_algo < 0)
+ struct ipcp_entry * e = list_entry(p, struct ipcp_entry, next);
+ if (e->dif_name == NULL)
continue;
+
+ log_dbg("IPCP %s found for name %s with hash enum %d.",
+ e->dif_name, name, e->dir_hash_algo);
+
hash = malloc(IPCP_HASH_LEN(e));
if (hash == NULL)
return NULL;
str_hash(e->dir_hash_algo, hash, name);
- if (ipcp_query(e->api, hash, hash_len(e->dir_hash_algo)) == 0) {
+ if (ipcp_query(e->api, hash, IPCP_HASH_LEN(e)) == 0) {
free(hash);
return e;
}
@@ -319,10 +318,10 @@ static pid_t create_ipcp(char * name,
list_add(&api->next, &irmd.spawned_apis);
- pthread_mutex_lock(&tmp->init_lock);
-
pthread_rwlock_unlock(&irmd.reg_lock);
+ pthread_mutex_lock(&tmp->init_lock);
+
while (tmp->init == false)
pthread_cond_wait(&tmp->init_cond, &tmp->init_lock);
@@ -401,7 +400,7 @@ static int destroy_ipcp(pid_t api)
return 0;
}
-static int bootstrap_ipcp(pid_t api,
+static int bootstrap_ipcp(pid_t api,
ipcp_config_msg_t * conf)
{
struct ipcp_entry * entry = NULL;
@@ -445,9 +444,10 @@ static int bootstrap_ipcp(pid_t api,
}
static int enroll_ipcp(pid_t api,
- char * dif_name)
+ char * dst_name)
{
struct ipcp_entry * entry = NULL;
+ struct dif_info info;
pthread_rwlock_wrlock(&irmd.reg_lock);
@@ -464,27 +464,35 @@ static int enroll_ipcp(pid_t api,
return -1;
}
- entry->dif_name = strdup(dif_name);
- if (entry->dif_name == NULL) {
- pthread_rwlock_unlock(&irmd.reg_lock);
- log_err("Failed to strdup.");
+ pthread_rwlock_unlock(&irmd.reg_lock);
+
+ if (ipcp_enroll(api, dst_name, &info) < 0) {
+ log_err("Could not enroll IPCP.");
return -1;
}
- pthread_rwlock_unlock(&irmd.reg_lock);
+ pthread_rwlock_wrlock(&irmd.reg_lock);
- entry->dir_hash_algo = ipcp_enroll(api, dif_name);
- if (entry->dir_hash_algo < 0) {
- pthread_rwlock_wrlock(&irmd.reg_lock);
- free(entry->dif_name);
- entry->dif_name = NULL;
+ entry = get_ipcp_entry_by_api(api);
+ if (entry == NULL) {
pthread_rwlock_unlock(&irmd.reg_lock);
- log_err("Could not enroll IPCP.");
+ log_err("No such IPCP.");
return -1;
}
+ entry->dif_name = strdup(info.dif_name);
+ if (entry->dif_name == NULL) {
+ pthread_rwlock_unlock(&irmd.reg_lock);
+ log_err("Failed to strdup dif_name.");
+ return -ENOMEM;
+ }
+
+ entry->dir_hash_algo = info.algo;
+
+ pthread_rwlock_unlock(&irmd.reg_lock);
+
log_info("Enrolled IPCP %d in DIF %s.",
- api, dif_name);
+ api, info.dif_name);
return 0;
}
@@ -769,6 +777,9 @@ static int name_reg(const char * name,
if (wildcard_match(difs[i], e->dif_name))
continue;
+ log_dbg("gonna register %s in dif %s.",
+ name, e->dif_name);
+
hash = malloc(IPCP_HASH_LEN(e));
if (hash == NULL)
break;
@@ -1101,10 +1112,9 @@ static int flow_alloc(pid_t api,
assert(irm_flow_get_state(f) == FLOW_ALLOC_PENDING);
hash = malloc(IPCP_HASH_LEN(ipcp));
- if (hash == NULL) {
+ if (hash == NULL)
/* sanitizer cleans this */
return -ENOMEM;
- }
str_hash(ipcp->dir_hash_algo, hash, dst);
diff --git a/src/lib/dev.c b/src/lib/dev.c
index c46cd407..f5315cf5 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -156,7 +156,6 @@ struct {
struct shm_rdrbuff * rdrb;
struct shm_flow_set * fqset;
- pthread_rwlock_t data_lock;
struct bmp * fds;
struct bmp * fqueues;
@@ -193,13 +192,9 @@ static int api_announce(char * ap_name)
msg.code = IRM_MSG_CODE__IRM_API_ANNOUNCE;
msg.has_api = true;
- pthread_rwlock_rdlock(&ai.data_lock);
-
msg.api = ai.api;
msg.ap_name = ap_name;
- pthread_rwlock_unlock(&ai.data_lock);
-
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL) {
return -EIRMD;
@@ -330,7 +325,6 @@ int ouroboros_init(const char * ap_name)
}
pthread_rwlock_init(&ai.flows_lock, NULL);
- pthread_rwlock_init(&ai.data_lock, NULL);
return 0;
}
@@ -339,8 +333,6 @@ void ouroboros_fini()
{
int i = 0;
- pthread_rwlock_wrlock(&ai.data_lock);
-
bmp_destroy(ai.fds);
bmp_destroy(ai.fqueues);
@@ -375,10 +367,8 @@ void ouroboros_fini()
free(ai.ports);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
pthread_rwlock_destroy(&ai.flows_lock);
- pthread_rwlock_destroy(&ai.data_lock);
}
int flow_accept(qosspec_t * qs,
@@ -398,12 +388,8 @@ int flow_accept(qosspec_t * qs,
msg.timeo_nsec = timeo->tv_nsec;
}
- pthread_rwlock_rdlock(&ai.data_lock);
-
msg.api = ai.api;
- pthread_rwlock_unlock(&ai.data_lock);
-
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
return -EIRMD;
@@ -424,13 +410,11 @@ int flow_accept(qosspec_t * qs,
return -EIRMD;
}
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_wrlock(&ai.flows_lock);
fd = bmp_allocate(ai.fds);
if (!bmp_is_id_valid(ai.fds, fd)) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
return -EBADF;
}
@@ -439,7 +423,6 @@ int flow_accept(qosspec_t * qs,
if (ai.flows[fd].rx_rb == NULL) {
bmp_release(ai.fds, fd);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
return -ENOMEM;
}
@@ -449,7 +432,6 @@ int flow_accept(qosspec_t * qs,
reset_flow(fd);
bmp_release(ai.fds, fd);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
return -ENOMEM;
}
@@ -459,7 +441,6 @@ int flow_accept(qosspec_t * qs,
reset_flow(fd);
bmp_release(ai.fds, fd);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
return -ENOMEM;
}
@@ -478,7 +459,6 @@ int flow_accept(qosspec_t * qs,
ai.ports[recv_msg->port_id].state = PORT_ID_ASSIGNED;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
@@ -499,6 +479,7 @@ int flow_alloc(const char * dst_name,
msg.has_api = true;
msg.has_qoscube = true;
msg.qoscube = spec_to_cube(qs);
+ msg.api = ai.api;
if (timeo != NULL) {
msg.has_timeo_sec = true;
@@ -507,11 +488,6 @@ int flow_alloc(const char * dst_name,
msg.timeo_nsec = timeo->tv_nsec;
}
- pthread_rwlock_rdlock(&ai.data_lock);
-
- msg.api = ai.api;
-
- pthread_rwlock_unlock(&ai.data_lock);
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -533,13 +509,11 @@ int flow_alloc(const char * dst_name,
return -EIRMD;
}
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_wrlock(&ai.flows_lock);
fd = bmp_allocate(ai.fds);
if (!bmp_is_id_valid(ai.fds, fd)) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
return -EBADF;
}
@@ -548,7 +522,6 @@ int flow_alloc(const char * dst_name,
if (ai.flows[fd].rx_rb == NULL) {
bmp_release(ai.fds, fd);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
return -ENOMEM;
}
@@ -558,7 +531,6 @@ int flow_alloc(const char * dst_name,
reset_flow(fd);
bmp_release(ai.fds, fd);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
return -ENOMEM;
}
@@ -568,7 +540,6 @@ int flow_alloc(const char * dst_name,
reset_flow(fd);
bmp_release(ai.fds, fd);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
return -ENOMEM;
}
@@ -584,7 +555,6 @@ int flow_alloc(const char * dst_name,
ai.ports[recv_msg->port_id].state = PORT_ID_ASSIGNED;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
@@ -604,20 +574,17 @@ int flow_dealloc(int fd)
msg.has_api = true;
msg.api = ai.api;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_wrlock(&ai.flows_lock);
if (ai.flows[fd].port_id < 0) {
bmp_release(ai.fds, fd);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return 0;
}
msg.port_id = ai.flows[fd].port_id;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -631,14 +598,12 @@ int flow_dealloc(int fd)
irm_msg__free_unpacked(recv_msg, NULL);
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_wrlock(&ai.flows_lock);
reset_flow(fd);
bmp_release(ai.fds, fd);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return 0;
}
@@ -651,12 +616,10 @@ int flow_set_flags(int fd,
if (fd < 0 || fd >= AP_MAX_FLOWS)
return -EBADF;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_wrlock(&ai.flows_lock);
if (ai.flows[fd].port_id < 0) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -ENOTALLOC;
}
@@ -667,8 +630,8 @@ int flow_set_flags(int fd,
shm_rbuff_block(ai.flows[fd].rx_rb);
if (flags & FLOW_O_RDWR)
shm_rbuff_unblock(ai.flows[fd].rx_rb);
+
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return old;
}
@@ -680,19 +643,16 @@ int flow_get_flags(int fd)
if (fd < 0 || fd >= AP_MAX_FLOWS)
return -EBADF;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_wrlock(&ai.flows_lock);
if (ai.flows[fd].port_id < 0) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -ENOTALLOC;
}
old = ai.flows[fd].oflags;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return old;
}
@@ -705,12 +665,10 @@ int flow_get_timeout(int fd,
if (fd < 0 || fd >= AP_MAX_FLOWS || timeo == NULL)
return -EINVAL;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_wrlock(&ai.flows_lock);
if (ai.flows[fd].port_id < 0) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -ENOTALLOC;
}
@@ -720,7 +678,6 @@ int flow_get_timeout(int fd,
ret = -EPERM;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return ret;
}
@@ -731,12 +688,10 @@ int flow_set_timeout(int fd,
if (fd < 0 || fd >= AP_MAX_FLOWS)
return -EINVAL;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_wrlock(&ai.flows_lock);
if (ai.flows[fd].port_id < 0) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -ENOTALLOC;
}
@@ -748,7 +703,6 @@ int flow_set_timeout(int fd,
}
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return 0;
}
@@ -759,19 +713,16 @@ int flow_get_qosspec(int fd,
if (fd < 0 || fd >= AP_MAX_FLOWS || qs == NULL)
return -EINVAL;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_wrlock(&ai.flows_lock);
if (ai.flows[fd].port_id < 0) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -ENOTALLOC;
}
fill_qosspec(qs, ai.flows[fd].cube);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return 0;
}
@@ -788,18 +739,15 @@ ssize_t flow_write(int fd,
if (fd < 0 || fd >= AP_MAX_FLOWS)
return -EBADF;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
if (ai.flows[fd].port_id < 0) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -ENOTALLOC;
}
if ((ai.flows[fd].oflags & FLOW_O_ACCMODE) == FLOW_O_RDONLY) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -EPERM;
}
@@ -811,14 +759,12 @@ ssize_t flow_write(int fd,
count);
if (idx < 0) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return idx;
}
if (shm_rbuff_write(ai.flows[fd].tx_rb, idx) < 0) {
shm_rdrbuff_remove(ai.rdrb, idx);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -ENOTALLOC;
}
} else { /* blocking */
@@ -826,7 +772,6 @@ ssize_t flow_write(int fd,
struct shm_rbuff * tx_rb = ai.flows[fd].tx_rb;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
assert(tx_rb);
@@ -841,14 +786,12 @@ ssize_t flow_write(int fd,
return -ENOTALLOC;
}
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
}
shm_flow_set_notify(ai.flows[fd].set, ai.flows[fd].port_id);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return 0;
}
@@ -864,12 +807,10 @@ ssize_t flow_read(int fd,
if (fd < 0 || fd >= AP_MAX_FLOWS)
return -EBADF;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
if (ai.flows[fd].port_id < 0) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -ENOTALLOC;
}
@@ -882,34 +823,26 @@ ssize_t flow_read(int fd,
struct timespec timeout = ai.flows[fd].rcv_timeo;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
if (timeo)
idx = shm_rbuff_read_b(rb, &timeout);
else
idx = shm_rbuff_read_b(rb, NULL);
-
- pthread_rwlock_rdlock(&ai.data_lock);
}
if (idx < 0) {
assert(idx == -EAGAIN || idx == -ETIMEDOUT);
- pthread_rwlock_unlock(&ai.data_lock);
return idx;
}
n = shm_rdrbuff_read(&sdu, ai.rdrb, idx);
- if (n < 0) {
- pthread_rwlock_unlock(&ai.data_lock);
+ if (n < 0)
return -1;
- }
memcpy(buf, sdu, MIN((size_t) n, count));
shm_rdrbuff_remove(ai.rdrb, idx);
- pthread_rwlock_unlock(&ai.data_lock);
-
return n;
}
@@ -968,11 +901,7 @@ void flow_set_zero(struct flow_set * set)
if (set == NULL)
return;
- pthread_rwlock_rdlock(&ai.data_lock);
-
shm_flow_set_zero(ai.fqset, set->idx);
-
- pthread_rwlock_unlock(&ai.data_lock);
}
int flow_set_add(struct flow_set * set,
@@ -985,7 +914,6 @@ int flow_set_add(struct flow_set * set,
if (set == NULL)
return -EINVAL;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
ret = shm_flow_set_add(ai.fqset, set->idx, ai.flows[fd].port_id);
@@ -995,7 +923,6 @@ int flow_set_add(struct flow_set * set,
shm_flow_set_notify(ai.fqset, ai.flows[fd].port_id);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return ret;
}
@@ -1006,14 +933,12 @@ void flow_set_del(struct flow_set * set,
if (set == NULL)
return;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
if (ai.flows[fd].port_id >= 0)
shm_flow_set_del(ai.fqset, set->idx, ai.flows[fd].port_id);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
}
bool flow_set_has(const struct flow_set * set,
@@ -1024,19 +949,16 @@ bool flow_set_has(const struct flow_set * set,
if (set == NULL || fd < 0)
return false;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
if (ai.flows[fd].port_id < 0) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return false;
}
ret = (shm_flow_set_has(ai.fqset, set->idx, ai.flows[fd].port_id) == 1);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return ret;
}
@@ -1051,13 +973,11 @@ int fqueue_next(struct fqueue * fq)
if (fq->fqsize == 0)
return -EPERM;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
fd = ai.ports[fq->fqueue[fq->next++]].fd;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
if (fq->next == fq->fqsize) {
fq->fqsize = 0;
@@ -1101,13 +1021,11 @@ int np1_flow_alloc(pid_t n_api,
{
int fd;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_wrlock(&ai.flows_lock);
fd = bmp_allocate(ai.fds);
if (!bmp_is_id_valid(ai.fds, fd)) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -1;
}
@@ -1115,7 +1033,6 @@ int np1_flow_alloc(pid_t n_api,
if (ai.flows[fd].rx_rb == NULL) {
reset_flow(fd);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -1;
}
@@ -1123,7 +1040,6 @@ int np1_flow_alloc(pid_t n_api,
if (ai.flows[fd].tx_rb == NULL) {
reset_flow(fd);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -1;
}
@@ -1131,7 +1047,6 @@ int np1_flow_alloc(pid_t n_api,
if (ai.flows[fd].set == NULL) {
reset_flow(fd);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -1;
}
@@ -1143,7 +1058,6 @@ int np1_flow_alloc(pid_t n_api,
ai.ports[port_id].state = PORT_ID_ASSIGNED;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return fd;
}
@@ -1152,13 +1066,11 @@ int np1_flow_dealloc(int port_id)
{
int fd;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
fd = ai.ports[port_id].fd;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return fd;
}
@@ -1170,13 +1082,11 @@ int np1_flow_resp(int port_id)
if (port_wait_assign(&ai.ports[port_id]) != PORT_ID_ASSIGNED)
return -1;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
fd = ai.ports[port_id].fd;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return fd;
}
@@ -1231,35 +1141,29 @@ int ipcp_flow_req_arr(pid_t api,
msg.has_qoscube = true;
msg.qoscube = cube;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_wrlock(&ai.flows_lock);
fd = bmp_allocate(ai.fds);
if (!bmp_is_id_valid(ai.fds, fd)) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -1; /* -ENOMOREFDS */
}
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
recv_msg = send_recv_irm_msg(&msg);
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_wrlock(&ai.flows_lock);
if (recv_msg == NULL) {
ai.ports[fd].state = PORT_INIT;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -EIRMD;
}
if (!recv_msg->has_port_id || !recv_msg->has_api) {
ai.ports[fd].state = PORT_INIT;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
@@ -1267,7 +1171,6 @@ int ipcp_flow_req_arr(pid_t api,
if (recv_msg->has_result && recv_msg->result) {
ai.ports[fd].state = PORT_INIT;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
@@ -1276,7 +1179,6 @@ int ipcp_flow_req_arr(pid_t api,
if (port_id < 0) {
ai.ports[fd].state = PORT_INIT;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
@@ -1285,7 +1187,6 @@ int ipcp_flow_req_arr(pid_t api,
if (ai.flows[fd].rx_rb == NULL) {
reset_flow(fd);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
@@ -1294,7 +1195,6 @@ int ipcp_flow_req_arr(pid_t api,
if (ai.flows[fd].tx_rb == NULL) {
reset_flow(fd);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
@@ -1303,7 +1203,6 @@ int ipcp_flow_req_arr(pid_t api,
if (ai.flows[fd].set == NULL) {
reset_flow(fd);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
@@ -1315,7 +1214,6 @@ int ipcp_flow_req_arr(pid_t api,
port_set_state(&ai.ports[port_id], PORT_ID_ASSIGNED);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
irm_msg__free_unpacked(recv_msg, NULL);
@@ -1332,11 +1230,11 @@ int ipcp_flow_alloc_reply(int fd,
msg.code = IRM_MSG_CODE__IPCP_FLOW_ALLOC_REPLY;
msg.has_port_id = true;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
+
msg.port_id = ai.flows[fd].port_id;
+
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
msg.has_response = true;
msg.response = response;
@@ -1367,30 +1265,23 @@ int ipcp_flow_read(int fd,
assert(fd >=0);
assert(sdb);
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
if ((port_id = ai.flows[fd].port_id) < 0) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -ENOTALLOC;
}
rb = ai.flows[fd].rx_rb;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
idx = shm_rbuff_read(rb);
if (idx < 0)
return idx;
- pthread_rwlock_rdlock(&ai.data_lock);
-
*sdb = shm_rdrbuff_get(ai.rdrb, idx);
- pthread_rwlock_unlock(&ai.data_lock);
-
return 0;
}
@@ -1402,18 +1293,15 @@ int ipcp_flow_write(int fd,
if (sdb == NULL)
return -EINVAL;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
if (ai.flows[fd].port_id < 0) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -ENOTALLOC;
}
if ((ai.flows[fd].oflags & FLOW_O_ACCMODE) == FLOW_O_RDONLY) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -EPERM;
}
@@ -1425,7 +1313,6 @@ int ipcp_flow_write(int fd,
shm_flow_set_notify(ai.flows[fd].set, ai.flows[fd].port_id);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return 0;
}
@@ -1436,12 +1323,8 @@ int ipcp_sdb_reserve(struct shm_du_buff ** sdb,
struct shm_rdrbuff * rdrb;
ssize_t idx;
- pthread_rwlock_rdlock(&ai.data_lock);
-
rdrb = ai.rdrb;
- pthread_rwlock_unlock(&ai.data_lock);
-
idx = shm_rdrbuff_write_b(rdrb,
DU_BUFF_HEADSPACE,
DU_BUFF_TAILSPACE,
@@ -1462,13 +1345,11 @@ int ipcp_flow_fini(int fd)
flow_set_flags(fd, FLOW_O_WRONLY);
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
rx_rb = ai.flows[fd].rx_rb;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
shm_rbuff_fini(rx_rb);
@@ -1481,19 +1362,16 @@ int ipcp_flow_get_qoscube(int fd,
if (fd < 0 || fd >= AP_MAX_FLOWS || cube == NULL)
return -EINVAL;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_wrlock(&ai.flows_lock);
if (ai.flows[fd].port_id < 0) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -ENOTALLOC;
}
*cube = ai.flows[fd].cube;
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return 0;
}
@@ -1504,13 +1382,11 @@ ssize_t local_flow_read(int fd)
assert(fd >= 0);
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
ret = shm_rbuff_read(ai.flows[fd].rx_rb);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return ret;
}
@@ -1521,12 +1397,10 @@ int local_flow_write(int fd,
if (fd < 0)
return -EINVAL;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
if (ai.flows[fd].port_id < 0) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -ENOTALLOC;
}
@@ -1535,7 +1409,6 @@ int local_flow_write(int fd,
shm_flow_set_notify(ai.flows[fd].set, ai.flows[fd].port_id);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return 0;
}
@@ -1545,7 +1418,6 @@ int ipcp_read_shim(int fd,
{
ssize_t idx;
- pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
assert(ai.flows[fd].rx_rb);
@@ -1553,14 +1425,12 @@ int ipcp_read_shim(int fd,
idx = shm_rbuff_read(ai.flows[fd].rx_rb);
if (idx < 0) {
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return -EAGAIN;
}
*sdb = shm_rdrbuff_get(ai.rdrb, idx);
pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
return 0;
}
diff --git a/src/lib/ipcpd_messages.proto b/src/lib/ipcpd_messages.proto
index bd71d3f3..9299afcd 100644
--- a/src/lib/ipcpd_messages.proto
+++ b/src/lib/ipcpd_messages.proto
@@ -46,6 +46,8 @@ message ipcp_msg {
optional uint32 qoscube = 6;
optional ipcp_config_msg conf = 7;
optional int32 api = 8;
- optional int32 response = 9;
- optional int32 result = 10;
+ optional int32 dir_hash_algo = 9;
+ optional string dif_name = 10;
+ optional int32 response = 11;
+ optional int32 result = 12;
};