summaryrefslogtreecommitdiff
path: root/src/ipcpd
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-06-20 23:49:35 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-06-21 00:14:14 +0200
commita46114ec01e8d174a41744f4f1b49905613847dc (patch)
tree9a76d884afc10c276c0b4e3af989d68a9556551b /src/ipcpd
parent34f96731f5fb8ab8a1f7018366fc28fd041d73e2 (diff)
downloadouroboros-a46114ec01e8d174a41744f4f1b49905613847dc.tar.gz
ouroboros-a46114ec01e8d174a41744f4f1b49905613847dc.zip
lib, irmd, ipcp: robust mutexes
Update to POSIX 200112L to allow use of robust mutexes in the shm_du_map. Removed the implementation of the rw_lock in favor of pthread_rwlock_t. Placeholder for the shm_du_map_sanitize function.
Diffstat (limited to 'src/ipcpd')
-rw-r--r--src/ipcpd/ipcp.c2
-rw-r--r--src/ipcpd/ipcp.h5
-rw-r--r--src/ipcpd/local/main.c121
-rw-r--r--src/ipcpd/shim-eth-llc/main.c187
-rw-r--r--src/ipcpd/shim-udp/main.c219
5 files changed, 267 insertions, 267 deletions
diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c
index 5a621391..901abae6 100644
--- a/src/ipcpd/ipcp.c
+++ b/src/ipcpd/ipcp.c
@@ -40,7 +40,7 @@ struct ipcp * ipcp_instance_create()
i->irmd_fd = -1;
i->state = IPCP_INIT;
- rw_lock_init(&i->state_lock);
+ pthread_rwlock_init(&i->state_lock, NULL);
return i;
}
diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h
index 63f9677a..1e9e9763 100644
--- a/src/ipcpd/ipcp.h
+++ b/src/ipcpd/ipcp.h
@@ -23,7 +23,8 @@
#ifndef IPCPD_IPCP_H
#define IPCPD_IPCP_H
-#include <ouroboros/rw_lock.h>
+#include <ouroboros/config.h>
+#include <pthread.h>
#include "ipcp-ops.h"
#include "ipcp-data.h"
@@ -41,7 +42,7 @@ struct ipcp {
int irmd_fd;
enum ipcp_state state;
- rw_lock_t state_lock;
+ pthread_rwlock_t state_lock;
};
struct ipcp * ipcp_instance_create();
diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c
index 43ca14da..1e033a21 100644
--- a/src/ipcpd/local/main.c
+++ b/src/ipcpd/local/main.c
@@ -33,7 +33,6 @@
#include <ouroboros/bitmap.h>
#include <ouroboros/flow.h>
#include <ouroboros/dev.h>
-#include <ouroboros/rw_lock.h>
#define OUROBOROS_PREFIX "ipcpd/local"
@@ -76,7 +75,7 @@ struct shim_ap_data {
int in_out[AP_MAX_FLOWS];
struct flow flows[AP_MAX_FLOWS];
- rw_lock_t flows_lock;
+ pthread_rwlock_t flows_lock;
pthread_t mainloop;
pthread_t sduloop;
@@ -137,7 +136,7 @@ static int shim_ap_init(char * ap_name)
_ap_instance->in_out[i] = -1;
}
- rw_lock_init(&_ap_instance->flows_lock);
+ pthread_rwlock_init(&_ap_instance->flows_lock, NULL);
return 0;
}
@@ -149,7 +148,7 @@ void shim_ap_fini()
if (_ap_instance == NULL)
return;
- rw_lock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_SHUTDOWN)
LOG_WARN("Cleaning up AP while not in shutdown.");
@@ -163,14 +162,14 @@ void shim_ap_fini()
if (_ap_instance->rb != NULL)
shm_ap_rbuff_destroy(_ap_instance->rb);
- rw_lock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
for (i = 0; i < AP_MAX_FLOWS; i ++)
if (_ap_instance->flows[i].rb != NULL)
shm_ap_rbuff_close(_ap_instance->flows[i].rb);
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
free(_ap_instance);
}
@@ -206,18 +205,18 @@ static void * ipcp_local_sdu_loop(void * o)
continue;
}
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_ENROLLED) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return (void *) 1; /* -ENOTENROLLED */
}
- rw_lock_rdlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ap_instance->flows_lock);
fd = _ap_instance->in_out[port_id_to_fd(e->port_id)];
if (fd == -1) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
free(e);
continue;
}
@@ -226,8 +225,8 @@ static void * ipcp_local_sdu_loop(void * o)
while (shm_ap_rbuff_write(_ap_instance->flows[fd].rb, e) < 0)
;
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
}
return (void *) 1;
@@ -249,14 +248,14 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c)
LOG_DBG("Terminating by order of %d. Bye.",
info->si_pid);
- rw_lock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
if (_ipcp->state == IPCP_ENROLLED)
clean_threads = true;
_ipcp->state = IPCP_SHUTDOWN;
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
if (clean_threads) {
pthread_cancel(_ap_instance->sduloop);
@@ -278,12 +277,12 @@ static int ipcp_local_bootstrap(struct dif_config * conf)
}
if (_ipcp->state != IPCP_INIT) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_ERR("IPCP in wrong state.");
return -1;
}
- rw_lock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
_ipcp->state = IPCP_ENROLLED;
@@ -292,7 +291,7 @@ static int ipcp_local_bootstrap(struct dif_config * conf)
ipcp_local_sdu_loop,
NULL);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBG("Bootstrapped local IPCP with pid %d.",
getpid());
@@ -302,25 +301,25 @@ static int ipcp_local_bootstrap(struct dif_config * conf)
static int ipcp_local_name_reg(char * name)
{
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_ENROLLED) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Won't register with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
}
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (ipcp_data_add_reg_entry(_ipcp->data, name)) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Failed to add %s to local registry.", name);
return -1;
}
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBG("Registered %s.", name);
@@ -329,11 +328,11 @@ static int ipcp_local_name_reg(char * name)
static int ipcp_local_name_unreg(char * name)
{
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
ipcp_data_del_reg_entry(_ipcp->data, name);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return 0;
}
@@ -356,26 +355,26 @@ static int ipcp_local_flow_alloc(pid_t n_pid,
/* This ipcpd has all QoS */
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_ENROLLED) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Won't allocate flow with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
}
rb = shm_ap_rbuff_open(n_pid);
if (rb == NULL) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return -1; /* -ENORBUFF */
}
- rw_lock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
in_fd = bmp_allocate(_ap_instance->fds);
if (!bmp_is_id_valid(_ap_instance->fds, in_fd)) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return -EMFILE;
}
@@ -391,8 +390,8 @@ static int ipcp_local_flow_alloc(pid_t n_pid,
src_ae_name);
if (port_id < 0) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_ERR("Could not get port id from IRMd");
/* shm_ap_rbuff_close(n_pid); */
return -1;
@@ -401,8 +400,8 @@ static int ipcp_local_flow_alloc(pid_t n_pid,
out_fd = bmp_allocate(_ap_instance->fds);
if (!bmp_is_id_valid(_ap_instance->fds, out_fd)) {
/* shm_ap_rbuff_close(n_pid); */
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return -1; /* -ENOMOREFDS */
}
@@ -413,8 +412,8 @@ static int ipcp_local_flow_alloc(pid_t n_pid,
_ap_instance->in_out[in_fd] = out_fd;
_ap_instance->in_out[out_fd] = in_fd;
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Pending local allocation request, port_id %d.", port_id);
@@ -433,23 +432,23 @@ static int ipcp_local_flow_alloc_resp(pid_t n_pid,
if (response)
return 0;
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
/* awaken pending flow */
- rw_lock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
in_fd = port_id_to_fd(port_id);
if (in_fd < 0) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Could not find flow with port_id %d.", port_id);
return -1;
}
if (_ap_instance->flows[in_fd].state != FLOW_PENDING) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Flow was not pending.");
return -1;
}
@@ -460,8 +459,8 @@ static int ipcp_local_flow_alloc_resp(pid_t n_pid,
_ap_instance->flows[in_fd].state = FLOW_NULL;
_ap_instance->flows[in_fd].port_id = -1;
_ap_instance->in_out[in_fd] = -1;
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return -1;
}
@@ -472,24 +471,24 @@ static int ipcp_local_flow_alloc_resp(pid_t n_pid,
out_fd = _ap_instance->in_out[in_fd];
if (out_fd < 0) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("No pending local flow with port_id %d.", port_id);
return -1;
}
if (_ap_instance->flows[out_fd].state != FLOW_PENDING) {
/* FIXME: clean up other end */
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Flow was not pending.");
return -1;
}
_ap_instance->flows[out_fd].state = FLOW_ALLOCATED;
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
if ((ret = ipcp_flow_alloc_reply(getpid(),
_ap_instance->flows[out_fd].port_id,
@@ -509,13 +508,13 @@ static int ipcp_local_flow_dealloc(int port_id)
int fd = -1;
struct shm_ap_rbuff * rb;
- rw_lock_rdlock(&_ipcp->state_lock);
- rw_lock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
fd = port_id_to_fd(port_id);
if (fd < 0) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Could not find flow with port_id %d.", port_id);
return 0;
}
@@ -532,12 +531,12 @@ static int ipcp_local_flow_dealloc(int port_id)
rb = _ap_instance->flows[fd].rb;
_ap_instance->flows[fd].rb = NULL;
- rw_lock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
if (rb != NULL)
shm_ap_rbuff_close(rb);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Flow with port_id %d deallocated.", port_id);
@@ -632,7 +631,7 @@ int main (int argc, char * argv[])
exit(1);
}
- rw_lock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
@@ -640,7 +639,7 @@ int main (int argc, char * argv[])
pthread_sigmask(SIG_UNBLOCK, &sigset, NULL);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
pthread_join(_ap_instance->mainloop, NULL);
diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c
index 7ff59cde..9bd6920b 100644
--- a/src/ipcpd/shim-eth-llc/main.c
+++ b/src/ipcpd/shim-eth-llc/main.c
@@ -36,7 +36,6 @@
#include <ouroboros/bitmap.h>
#include <ouroboros/flow.h>
#include <ouroboros/dev.h>
-#include <ouroboros/rw_lock.h>
#define OUROBOROS_PREFIX "ipcpd/shim-eth-llc"
@@ -104,7 +103,7 @@ struct eth_llc_ipcp_data {
int tx_offset;
struct eth_llc_flow flows[AP_MAX_FLOWS];
- rw_lock_t flows_lock;
+ pthread_rwlock_t flows_lock;
pthread_t mainloop;
pthread_t sdu_writer;
@@ -159,7 +158,7 @@ struct eth_llc_ipcp_data * eth_llc_ipcp_data_create()
return NULL;
}
- rw_lock_init(&eth_llc_data->flows_lock);
+ pthread_rwlock_init(&eth_llc_data->flows_lock, NULL);
return eth_llc_data;
}
@@ -171,7 +170,7 @@ void eth_llc_ipcp_data_destroy()
if (_ipcp == NULL)
return;
- rw_lock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_SHUTDOWN)
LOG_WARN("Cleaning up while not in shutdown.");
@@ -185,14 +184,14 @@ void eth_llc_ipcp_data_destroy()
if (shim_data(_ipcp)->saps != NULL)
bmp_destroy(shim_data(_ipcp)->saps);
- rw_lock_wrlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_wrlock(&shim_data(_ipcp)->flows_lock);
for (i = 0; i < AP_MAX_FLOWS; i ++)
if (ipcp_flow(i)->rb != NULL)
shm_ap_rbuff_close(ipcp_flow(i)->rb);
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
free(_ipcp->data);
}
@@ -440,13 +439,13 @@ static int eth_llc_ipcp_port_req(uint8_t r_sap,
ssize_t index = 0;
int i;
- rw_lock_wrlock(&_ipcp->state_lock);
- rw_lock_wrlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&shim_data(_ipcp)->flows_lock);
index = bmp_allocate(shim_data(_ipcp)->indices);
if (index < 0) {
- rw_lock_unlock(&_ipcp->state_lock);
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
LOG_ERR("Out of free indices.");
return -1;
}
@@ -458,8 +457,8 @@ static int eth_llc_ipcp_port_req(uint8_t r_sap,
if (port_id < 0) {
bmp_release(shim_data(_ipcp)->indices, index);
- rw_lock_unlock(&_ipcp->state_lock);
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
LOG_ERR("Could not get port id from IRMd.");
return -1;
}
@@ -472,8 +471,8 @@ static int eth_llc_ipcp_port_req(uint8_t r_sap,
shim_data(_ipcp)->flows[index].r_addr[i] = r_addr[i];
}
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBG("New flow request, port_id %d, remote SAP %d.", port_id, r_sap);
@@ -490,20 +489,20 @@ static int eth_llc_ipcp_port_alloc_reply(uint8_t ssap,
int port_id = -1;
int i;
- rw_lock_rdlock(&_ipcp->state_lock);
- rw_lock_rdlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&shim_data(_ipcp)->flows_lock);
index = sap_to_index(ssap);
if (index < 0) {
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_ERR("No flow found with that SAP.");
return -1; /* -EFLOWNOTFOUND */
}
if (ipcp_flow(index)->state != FLOW_PENDING) {
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return -1; /* -EFLOWNOTPENDING */
}
@@ -519,8 +518,8 @@ static int eth_llc_ipcp_port_alloc_reply(uint8_t ssap,
}
}
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBG("Flow reply, port_id %d, remote SAP %d.", port_id, dsap);
@@ -540,13 +539,13 @@ static int eth_llc_ipcp_flow_dealloc_req(uint8_t ssap,
int port_id = -1;
int i = 0;
- rw_lock_rdlock(&_ipcp->state_lock);
- rw_lock_wrlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&shim_data(_ipcp)->flows_lock);
i = sap_to_index(ssap);
if (i < 0) {
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_ERR("No flow found for remote deallocation request.");
return 0;
}
@@ -554,8 +553,8 @@ static int eth_llc_ipcp_flow_dealloc_req(uint8_t ssap,
port_id = ipcp_flow(i)->port_id;
destroy_ipcp_flow(i);
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
ipcp_flow_dealloc(0, port_id);
@@ -633,14 +632,14 @@ static void * eth_llc_ipcp_sdu_reader(void * o)
memset(br_addr, 0xff, MAC_SIZE * sizeof(uint8_t));
while (true) {
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_ENROLLED) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return (void *) 1; /* -ENOTENROLLED */
}
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
#if defined(PACKET_RX_RING) && defined(PACKET_TX_RING)
header = (void *) shim_data(_ipcp)->rx_ring +
@@ -709,13 +708,13 @@ static void * eth_llc_ipcp_sdu_reader(void * o)
eth_llc_ipcp_mgmt_frame((uint8_t *) (buf + i),
frame_len, src_mac);
} else {
- rw_lock_rdlock(&_ipcp->state_lock);
- rw_lock_rdlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&shim_data(_ipcp)->flows_lock);
j = addr_and_saps_to_index(src_mac, ssap, dsap);
if (j < 0) {
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBG("Received data for unknown flow.");
#if defined(PACKET_RX_RING) && defined(PACKET_TX_RING)
offset = (offset + 1)
@@ -738,8 +737,8 @@ static void * eth_llc_ipcp_sdu_reader(void * o)
while (shm_ap_rbuff_write(ipcp_flow(j)->rb, &e) < 0)
;
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
}
#if defined(PACKET_RX_RING) && defined(PACKET_TX_RING)
offset = (offset + 1) & (SHM_BLOCKS_IN_MAP -1);
@@ -765,10 +764,10 @@ static void * eth_llc_ipcp_sdu_writer(void * o)
continue;
}
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_ENROLLED) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return (void *) 1; /* -ENOTENROLLED */
}
@@ -776,18 +775,18 @@ static void * eth_llc_ipcp_sdu_writer(void * o)
shim_data(_ipcp)->dum,
e->index);
if (len <= 0) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
free(e);
continue;
}
- rw_lock_rdlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_rdlock(&shim_data(_ipcp)->flows_lock);
i = port_id_to_index(e->port_id);
if (i < 0) {
free(e);
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
continue;
}
@@ -798,12 +797,12 @@ static void * eth_llc_ipcp_sdu_writer(void * o)
dsap, ssap, buf, len))
LOG_ERR("Failed to send SDU.");
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
if (shim_data(_ipcp)->dum != NULL)
shm_release_du_buff(shim_data(_ipcp)->dum, e->index);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
}
return (void *) 1;
@@ -824,14 +823,14 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c)
LOG_DBG("Terminating by order of %d. Bye.",
info->si_pid);
- rw_lock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
if (_ipcp->state == IPCP_ENROLLED)
clean_threads = true;
_ipcp->state = IPCP_SHUTDOWN;
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
if (clean_threads) {
pthread_cancel(shim_data(_ipcp)->sdu_reader);
@@ -964,10 +963,10 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
#endif
- rw_lock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_INIT) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_ERR("IPCP in wrong state.");
close(fd);
return -1;
@@ -989,7 +988,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
eth_llc_ipcp_sdu_writer,
NULL);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBG("Bootstrapped shim IPCP over Ethernet with LLC with pid %d.",
getpid());
@@ -999,21 +998,21 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
static int eth_llc_ipcp_name_reg(char * name)
{
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_ENROLLED) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Won't register with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
}
if (ipcp_data_add_reg_entry(_ipcp->data, name)) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_ERR("Failed to add %s to local registry.", name);
return -1;
}
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBG("Registered %s.", name);
@@ -1022,11 +1021,11 @@ static int eth_llc_ipcp_name_reg(char * name)
static int eth_llc_ipcp_name_unreg(char * name)
{
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
ipcp_data_del_reg_entry(_ipcp->data, name);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return 0;
}
@@ -1054,11 +1053,11 @@ static int eth_llc_ipcp_flow_alloc(pid_t n_pid,
if (rb == NULL)
return -1; /* -ENORBUFF */
- rw_lock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_ENROLLED) {
shm_ap_rbuff_close(rb);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Won't allocate flow with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
}
@@ -1066,18 +1065,18 @@ static int eth_llc_ipcp_flow_alloc(pid_t n_pid,
index = bmp_allocate(shim_data(_ipcp)->indices);
if (index < 0) {
shm_ap_rbuff_close(rb);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return -1;
}
- rw_lock_wrlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_wrlock(&shim_data(_ipcp)->flows_lock);
ssap = bmp_allocate(shim_data(_ipcp)->saps);
if (ssap < 0) {
shm_ap_rbuff_close(rb);
bmp_release(shim_data(_ipcp)->indices, index);
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return -1;
}
@@ -1086,8 +1085,8 @@ static int eth_llc_ipcp_flow_alloc(pid_t n_pid,
ipcp_flow(index)->rb = rb;
shim_data(_ipcp)->flows[index].sap = ssap;
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
memset(r_addr, 0xff, MAC_SIZE * sizeof(uint8_t));
@@ -1095,11 +1094,11 @@ static int eth_llc_ipcp_flow_alloc(pid_t n_pid,
dst_name,
src_ae_name) < 0) {
LOG_DBGF("Port alloc returned -1.");
- rw_lock_wrlock(&_ipcp->state_lock);
- rw_lock_wrlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&shim_data(_ipcp)->flows_lock);
destroy_ipcp_flow(index);
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return -1;
}
@@ -1117,20 +1116,20 @@ static int eth_llc_ipcp_flow_alloc_resp(pid_t n_pid,
int index = -1;
uint8_t ssap = 0;
- rw_lock_wrlock(&_ipcp->state_lock);
- rw_lock_wrlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&shim_data(_ipcp)->flows_lock);
index = port_id_to_index(port_id);
if (index < 0) {
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Could not find flow with port_id %d.", port_id);
return -1;
}
if (ipcp_flow(index)->state != FLOW_PENDING) {
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Flow was not pending.");
return -1;
}
@@ -1141,8 +1140,8 @@ static int eth_llc_ipcp_flow_alloc_resp(pid_t n_pid,
ipcp_flow(index)->state = FLOW_NULL;
ipcp_flow(index)->port_id = -1;
bmp_release(shim_data(_ipcp)->indices, index);
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return -1;
}
@@ -1152,8 +1151,8 @@ static int eth_llc_ipcp_flow_alloc_resp(pid_t n_pid,
ipcp_flow(index)->port_id = -1;
shm_ap_rbuff_close(ipcp_flow(index)->rb);
bmp_release(shim_data(_ipcp)->indices, index);
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return -1;
}
@@ -1161,18 +1160,18 @@ static int eth_llc_ipcp_flow_alloc_resp(pid_t n_pid,
ipcp_flow(index)->rb = rb;
shim_data(_ipcp)->flows[index].sap = ssap;
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
if (eth_llc_ipcp_port_alloc_resp(shim_data(_ipcp)->flows[index].r_addr,
shim_data(_ipcp)->flows[index].r_sap,
ssap,
response) < 0) {
- rw_lock_rdlock(&_ipcp->state_lock);
- rw_lock_wrlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&shim_data(_ipcp)->flows_lock);
destroy_ipcp_flow(index);
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Could not send response.");
return -1;
@@ -1191,13 +1190,13 @@ static int eth_llc_ipcp_flow_dealloc(int port_id)
int i;
int ret;
- rw_lock_rdlock(&_ipcp->state_lock);
- rw_lock_wrlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&shim_data(_ipcp)->flows_lock);
index = port_id_to_index(port_id);
if (index < 0) {
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return 0;
}
@@ -1208,10 +1207,12 @@ static int eth_llc_ipcp_flow_dealloc(int port_id)
destroy_ipcp_flow(index);
- rw_lock_unlock(&shim_data(_ipcp)->flows_lock);
+ pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock);
ret = eth_llc_ipcp_port_dealloc(addr, sap);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
+ if (eth_llc_ipcp_port_dealloc(addr, sap) < 0)
+ LOG_DBGF("Could not notify remote.");
if (ret < 0)
LOG_DBGF("Could not notify remote.");
@@ -1289,7 +1290,7 @@ int main(int argc, char * argv[])
_ipcp->ops = &eth_llc_ops;
_ipcp->state = IPCP_INIT;
- rw_lock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
@@ -1298,7 +1299,7 @@ int main(int argc, char * argv[])
pthread_sigmask(SIG_UNBLOCK, &sigset, NULL);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
pthread_join(shim_data(_ipcp)->mainloop, NULL);
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c
index ccd8530b..5a51433e 100644
--- a/src/ipcpd/shim-udp/main.c
+++ b/src/ipcpd/shim-udp/main.c
@@ -34,7 +34,6 @@
#include <ouroboros/bitmap.h>
#include <ouroboros/flow.h>
#include <ouroboros/dev.h>
-#include <ouroboros/rw_lock.h>
#define OUROBOROS_PREFIX "ipcpd/shim-udp"
@@ -93,7 +92,7 @@ struct shim_ap_data {
struct shm_ap_rbuff * rb;
struct flow flows[AP_MAX_FLOWS];
- rw_lock_t flows_lock;
+ pthread_rwlock_t flows_lock;
pthread_t mainloop;
pthread_t sduloop;
@@ -157,7 +156,7 @@ static int shim_ap_init(char * ap_name)
_ap_instance->flows[i].state = FLOW_NULL;
}
- rw_lock_init(&_ap_instance->flows_lock);
+ pthread_rwlock_init(&_ap_instance->flows_lock, NULL);
pthread_mutex_init(&_ap_instance->fd_set_lock, NULL);
return 0;
@@ -170,7 +169,7 @@ void shim_ap_fini()
if (_ap_instance == NULL)
return;
- rw_lock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_SHUTDOWN)
LOG_WARN("Cleaning up AP while not in shutdown.");
@@ -184,14 +183,14 @@ void shim_ap_fini()
if (_ap_instance->rb != NULL)
shm_ap_rbuff_destroy(_ap_instance->rb);
- rw_lock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
for (i = 0; i < AP_MAX_FLOWS; i ++)
if (_ap_instance->flows[i].rb != NULL)
shm_ap_rbuff_close(_ap_instance->flows[i].rb);
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
free(_ap_instance);
}
@@ -215,14 +214,14 @@ static ssize_t ipcp_udp_flow_write(int fd, void * buf, size_t count)
ssize_t index;
struct rb_entry e;
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_ENROLLED) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return -1; /* -ENOTENROLLED */
}
- rw_lock_rdlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ap_instance->flows_lock);
while ((index = shm_create_du_buff(_ap_instance->dum,
count + DU_BUFF_HEADSPACE +
@@ -238,8 +237,8 @@ static ssize_t ipcp_udp_flow_write(int fd, void * buf, size_t count)
while (shm_ap_rbuff_write(_ap_instance->flows[fd].rb, &e) < 0)
;
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return 0;
}
@@ -477,8 +476,8 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr,
}
- rw_lock_rdlock(&_ipcp->state_lock);
- rw_lock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
/* reply to IRM */
port_id = ipcp_flow_req_arr(getpid(),
@@ -486,8 +485,8 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr,
src_ae_name);
if (port_id < 0) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_ERR("Could not get port id from IRMd");
close(fd);
return -1;
@@ -497,8 +496,8 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr,
_ap_instance->flows[fd].rb = NULL;
_ap_instance->flows[fd].state = FLOW_PENDING;
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Pending allocation request, port_id %d, UDP port (%d, %d).",
port_id, ntohs(f_saddr.sin_port), ntohs(c_saddr->sin_port));
@@ -520,20 +519,20 @@ static int ipcp_udp_port_alloc_reply(int src_udp_port,
LOG_DBGF("Received reply for flow on udp port %d.",
ntohs(dst_udp_port));
- rw_lock_rdlock(&_ipcp->state_lock);
- rw_lock_rdlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ap_instance->flows_lock);
fd = udp_port_to_fd(dst_udp_port);
if (fd == -1) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Unknown flow on UDP port %d.", dst_udp_port);
return -1; /* -EUNKNOWNFLOW */
}
if (_ap_instance->flows[fd].state != FLOW_PENDING) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Flow on UDP port %d not pending.", dst_udp_port);
return -1; /* -EFLOWNOTPENDING */
}
@@ -550,8 +549,8 @@ static int ipcp_udp_port_alloc_reply(int src_udp_port,
if (getpeername(fd,
(struct sockaddr *) &t_saddr,
&t_saddr_len) < 0) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Flow with port_id %d has no peer.", port_id);
return -1;
}
@@ -562,8 +561,8 @@ static int ipcp_udp_port_alloc_reply(int src_udp_port,
if (connect(fd,
(struct sockaddr *) &t_saddr,
sizeof(t_saddr)) < 0) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
close(fd);
return -1;
}
@@ -571,8 +570,8 @@ static int ipcp_udp_port_alloc_reply(int src_udp_port,
_ap_instance->flows[fd].state = FLOW_ALLOCATED;
}
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
if ((ret = ipcp_flow_alloc_reply(getpid(),
@@ -595,13 +594,13 @@ static int ipcp_udp_flow_dealloc_req(int udp_port)
struct shm_ap_rbuff * rb;
- rw_lock_rdlock(&_ipcp->state_lock);
- rw_lock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
fd = udp_port_to_fd(udp_port);
if (fd < 0) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Could not find flow on UDP port %d.",
ntohs(udp_port));
return 0;
@@ -615,12 +614,12 @@ static int ipcp_udp_flow_dealloc_req(int udp_port)
rb = _ap_instance->flows[fd].rb;
_ap_instance->flows[fd].rb = NULL;
- rw_lock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
if (rb != NULL)
shm_ap_rbuff_close(rb);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
ipcp_flow_dealloc(0, port_id);
@@ -642,16 +641,16 @@ static void * ipcp_udp_listener()
int sfd = 0;
shim_udp_msg_t * msg = NULL;
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_ENROLLED) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return (void *) 1; /* -ENOTENROLLED */
}
sfd = shim_data(_ipcp)->s_fd;
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
memset(&buf, 0, SHIM_UDP_MSG_SIZE);
n = sizeof(c_saddr);
@@ -715,14 +714,14 @@ static void * ipcp_udp_sdu_reader()
while (true) {
struct timeval tv = {0, FD_UPDATE_TIMEOUT};
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_ENROLLED) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return (void *) 1; /* -ENOTENROLLED */
}
- rw_lock_rdlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ap_instance->flows_lock);
pthread_mutex_lock(&_ap_instance->fd_set_lock);
@@ -731,8 +730,8 @@ static void * ipcp_udp_sdu_reader()
pthread_mutex_unlock(&_ap_instance->fd_set_lock);
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
if (select(FD_SETSIZE, &read_fds, NULL, NULL, &tv) <= 0) {
continue;
@@ -776,10 +775,10 @@ static void * ipcp_udp_sdu_loop(void * o)
continue;
}
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_ENROLLED) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return (void *) 1; /* -ENOTENROLLED */
}
@@ -787,17 +786,17 @@ static void * ipcp_udp_sdu_loop(void * o)
_ap_instance->dum,
e->index);
if (len <= 0) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
free(e);
continue;
}
- rw_lock_rdlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ap_instance->flows_lock);
fd = port_id_to_fd(e->port_id);
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
if (fd == -1) {
free(e);
@@ -807,12 +806,12 @@ static void * ipcp_udp_sdu_loop(void * o)
if (send(fd, buf, len, 0) < 0)
LOG_ERR("Failed to send SDU.");
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (_ap_instance->dum != NULL)
shm_release_du_buff(_ap_instance->dum, e->index);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
}
return (void *) 1;
@@ -833,14 +832,14 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c)
LOG_DBG("Terminating by order of %d. Bye.",
info->si_pid);
- rw_lock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
if (_ipcp->state == IPCP_ENROLLED)
clean_threads = true;
_ipcp->state = IPCP_SHUTDOWN;
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
if (clean_threads) {
pthread_cancel(_ap_instance->handler);
@@ -925,10 +924,10 @@ static int ipcp_udp_bootstrap(struct dif_config * conf)
return -1;
}
- rw_lock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_INIT) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_ERR("IPCP in wrong state.");
close(fd);
return -1;
@@ -956,7 +955,7 @@ static int ipcp_udp_bootstrap(struct dif_config * conf)
ipcp_udp_sdu_loop,
NULL);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBG("Bootstrapped shim IPCP over UDP with pid %d.",
getpid());
@@ -1107,16 +1106,16 @@ static int ipcp_udp_name_reg(char * name)
return -1;
}
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_ENROLLED) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Won't register with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
}
if (ipcp_data_add_reg_entry(_ipcp->data, name)) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_ERR("Failed to add %s to local registry.", name);
return -1;
}
@@ -1126,7 +1125,7 @@ static int ipcp_udp_name_reg(char * name)
dns_addr = shim_data(_ipcp)->dns_addr;
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
if (dns_addr != 0) {
ip_addr = shim_data(_ipcp)->ip_addr;
@@ -1145,14 +1144,14 @@ static int ipcp_udp_name_reg(char * name)
dnsstr, name, DNS_TTL, ipstr);
if (ddns_send(cmd)) {
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
ipcp_data_del_reg_entry(_ipcp->data, name);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return -1;
}
}
#else
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
#endif
LOG_DBG("Registered %s.", name);
@@ -1176,17 +1175,17 @@ static int ipcp_udp_name_unreg(char * name)
#ifdef CONFIG_OUROBOROS_ENABLE_DNS
/* unregister application with DNS server */
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_ENROLLED) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("IPCP is not enrolled");
return -1; /* -ENOTENROLLED */
}
dns_addr = shim_data(_ipcp)->dns_addr;
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
if (dns_addr != 0) {
if (inet_ntop(AF_INET, &dns_addr, dnsstr, INET_ADDRSTRLEN)
@@ -1200,11 +1199,11 @@ static int ipcp_udp_name_unreg(char * name)
}
#endif
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
ipcp_data_del_reg_entry(_ipcp->data, name);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return 0;
}
@@ -1262,10 +1261,10 @@ static int ipcp_udp_flow_alloc(pid_t n_pid,
return -1;
}
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
if (_ipcp->state != IPCP_ENROLLED) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Won't allocate flow with non-enrolled IPCP.");
close(fd);
return -1; /* -ENOTENROLLED */
@@ -1274,7 +1273,7 @@ static int ipcp_udp_flow_alloc(pid_t n_pid,
#ifdef CONFIG_OUROBOROS_ENABLE_DNS
dns_addr = shim_data(_ipcp)->dns_addr;
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
if (dns_addr != 0) {
ip_addr = ddns_resolve(dst_name, dns_addr);
@@ -1308,13 +1307,13 @@ static int ipcp_udp_flow_alloc(pid_t n_pid,
return -1;
}
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Pending flow with port_id %d on UDP port %d.",
port_id, ntohs(f_saddr.sin_port));
- rw_lock_rdlock(&_ipcp->state_lock);
- rw_lock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
set_fd(fd);
@@ -1322,16 +1321,16 @@ static int ipcp_udp_flow_alloc(pid_t n_pid,
_ap_instance->flows[fd].state = FLOW_PENDING;
_ap_instance->flows[fd].rb = rb;
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
if (ipcp_udp_port_alloc(ip_addr,
f_saddr.sin_port,
dst_name,
src_ae_name) < 0) {
LOG_DBGF("Port alloc returned -1.");
- rw_lock_rdlock(&_ipcp->state_lock);
- rw_lock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
clr_fd(fd);
@@ -1340,8 +1339,8 @@ static int ipcp_udp_flow_alloc(pid_t n_pid,
shm_ap_rbuff_close(_ap_instance->flows[fd].rb);
_ap_instance->flows[fd].rb = NULL;
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
close(fd);
return -1;
}
@@ -1362,23 +1361,23 @@ static int ipcp_udp_flow_alloc_resp(pid_t n_pid,
if (response)
return 0;
- rw_lock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
/* awaken pending flow */
- rw_lock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
fd = port_id_to_fd(port_id);
if (fd < 0) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Could not find flow with port_id %d.", port_id);
return -1;
}
if (_ap_instance->flows[fd].state != FLOW_PENDING) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Flow was not pending.");
return -1;
}
@@ -1388,13 +1387,13 @@ static int ipcp_udp_flow_alloc_resp(pid_t n_pid,
LOG_ERR("Could not open N + 1 ringbuffer.");
_ap_instance->flows[fd].state = FLOW_NULL;
_ap_instance->flows[fd].port_id = -1;
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
return -1;
}
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
if (getsockname(fd, (struct sockaddr *) &f_saddr, &len) < 0) {
LOG_DBGF("Flow with port_id %d has no socket.", port_id);
@@ -1406,23 +1405,23 @@ static int ipcp_udp_flow_alloc_resp(pid_t n_pid,
return -1;
}
- rw_lock_rdlock(&_ipcp->state_lock);
- rw_lock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
_ap_instance->flows[fd].state = FLOW_ALLOCATED;
_ap_instance->flows[fd].rb = rb;
set_fd(fd);
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
if (ipcp_udp_port_alloc_resp(r_saddr.sin_addr.s_addr,
f_saddr.sin_port,
r_saddr.sin_port,
response) < 0) {
- rw_lock_rdlock(&_ipcp->state_lock);
- rw_lock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
_ap_instance->flows[fd].state = FLOW_NULL;
shm_ap_rbuff_close(_ap_instance->flows[fd].rb);
@@ -1430,8 +1429,8 @@ static int ipcp_udp_flow_alloc_resp(pid_t n_pid,
clr_fd(fd);
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Could not send response.");
return -1;
@@ -1450,13 +1449,13 @@ static int ipcp_udp_flow_dealloc(int port_id)
struct sockaddr_in r_saddr;
socklen_t r_saddr_len = sizeof(r_saddr);
- rw_lock_rdlock(&_ipcp->state_lock);
- rw_lock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
fd = port_id_to_fd(port_id);
if (fd < 0) {
- rw_lock_unlock(&_ap_instance->flows_lock);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Could not find flow with port_id %d.", port_id);
return 0;
}
@@ -1468,13 +1467,13 @@ static int ipcp_udp_flow_dealloc(int port_id)
clr_fd(fd);
- rw_lock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
if (rb != NULL)
shm_ap_rbuff_close(rb);
if (getpeername(fd, (struct sockaddr *) &r_saddr, &r_saddr_len) < 0) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
LOG_DBGF("Flow with port_id %d has no peer.", port_id);
close(fd);
return 0;
@@ -1484,7 +1483,7 @@ static int ipcp_udp_flow_dealloc(int port_id)
r_saddr.sin_port = LISTEN_PORT;
if (connect(fd, (struct sockaddr *) &r_saddr, sizeof(r_saddr)) < 0) {
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
close(fd);
return 0 ;
}
@@ -1492,12 +1491,12 @@ static int ipcp_udp_flow_dealloc(int port_id)
if (ipcp_udp_port_dealloc(r_saddr.sin_addr.s_addr,
remote_udp) < 0) {
LOG_DBGF("Could not notify remote.");
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
close(fd);
return 0;
}
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
close(fd);
@@ -1590,7 +1589,7 @@ int main (int argc, char * argv[])
exit(1);
}
- rw_lock_wrlock(&_ipcp->state_lock);
+ pthread_rwlock_wrlock(&_ipcp->state_lock);
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
@@ -1598,7 +1597,7 @@ int main (int argc, char * argv[])
pthread_sigmask(SIG_UNBLOCK, &sigset, NULL);
- rw_lock_unlock(&_ipcp->state_lock);
+ pthread_rwlock_unlock(&_ipcp->state_lock);
pthread_join(_ap_instance->mainloop, NULL);