summaryrefslogtreecommitdiff
path: root/src/ipcpd/shim-eth-llc
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2017-04-05 14:28:24 +0200
committerSander Vrijders <sander.vrijders@ugent.be>2017-04-05 14:28:24 +0200
commitc5b092665c219c679ede91b3dc816c61f2f9dabe (patch)
treee60083545da6ce0dc5fdacd06610d907b90c5aee /src/ipcpd/shim-eth-llc
parentfa1590539e66c17902bb4f09221e6447b3233bfb (diff)
downloadouroboros-c5b092665c219c679ede91b3dc816c61f2f9dabe.tar.gz
ouroboros-c5b092665c219c679ede91b3dc816c61f2f9dabe.zip
ipcpd: Add lock for allocation requests
This adds a lock to prevent a race condition between flow_req_arr and flow_alloc_resp.
Diffstat (limited to 'src/ipcpd/shim-eth-llc')
-rw-r--r--src/ipcpd/shim-eth-llc/main.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c
index d42e6fff..142ca680 100644
--- a/src/ipcpd/shim-eth-llc/main.c
+++ b/src/ipcpd/shim-eth-llc/main.c
@@ -347,19 +347,23 @@ static int eth_llc_ipcp_sap_req(uint8_t r_sap,
{
int fd;
- pthread_rwlock_wrlock(&eth_llc_data.flows_lock);
+ pthread_mutex_lock(&ipcpi.alloc_lock);
/* reply to IRM, called under lock to prevent race */
fd = ipcp_flow_req_arr(getpid(), dst_name, cube);
if (fd < 0) {
+ pthread_mutex_unlock(&ipcpi.alloc_lock);
log_err("Could not get new flow from IRMd.");
return -1;
}
+ pthread_rwlock_wrlock(&eth_llc_data.flows_lock);
+
eth_llc_data.fd_to_ef[fd].r_sap = r_sap;
memcpy(eth_llc_data.fd_to_ef[fd].r_addr, r_addr, MAC_SIZE);
pthread_rwlock_unlock(&eth_llc_data.flows_lock);
+ pthread_mutex_unlock(&ipcpi.alloc_lock);
log_dbg("New flow request, fd %d, remote SAP %d.", fd, r_sap);