diff options
author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2020-09-26 16:30:37 +0200 |
---|---|---|
committer | Sander Vrijders <sander@ouroboros.rocks> | 2020-09-26 16:32:26 +0200 |
commit | 74c4155dc472651be9c40528657bdf35bfffd87c (patch) | |
tree | 8ddead3927c96bc5e53098e113db4d7f66670652 /src/ipcpd/udp | |
parent | 59f2230689a3c07cfee0578b491660c1fc471390 (diff) | |
download | ouroboros-74c4155dc472651be9c40528657bdf35bfffd87c.tar.gz ouroboros-74c4155dc472651be9c40528657bdf35bfffd87c.zip |
ipcpd: Improve locking np1_flow_set in eth and udp
A flow_set is thread-safe and doesn't need to be protected by a lock.
Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/ipcpd/udp')
-rw-r--r-- | src/ipcpd/udp/main.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/ipcpd/udp/main.c b/src/ipcpd/udp/main.c index c59ea36d..9e1900ef 100644 --- a/src/ipcpd/udp/main.c +++ b/src/ipcpd/udp/main.c @@ -1069,10 +1069,10 @@ static int ipcp_udp_flow_alloc(int fd, udp_data.fd_to_uf[fd].d_eid = -1; udp_data.fd_to_uf[fd].skfd = skfd; - fset_add(udp_data.np1_flows, fd); - pthread_rwlock_unlock(&udp_data.flows_lock); + fset_add(udp_data.np1_flows, fd); + log_dbg("Flow pending on fd %d, UDP src port %d, dst port %d.", fd, ntohs(c_saddr.sin_port), ntohs(r_saddr.sin_port)); @@ -1118,18 +1118,15 @@ static int ipcp_udp_flow_alloc_resp(int fd, skfd = udp_data.fd_to_uf[fd].skfd; d_eid = udp_data.fd_to_uf[fd].d_eid; - fset_add(udp_data.np1_flows, fd); - pthread_rwlock_unlock(&udp_data.flows_lock); if (ipcp_udp_port_alloc_resp(skfd, d_eid, fd, resp, data, len) < 0) { - pthread_rwlock_rdlock(&udp_data.flows_lock); - fset_del(udp_data.np1_flows, fd); - pthread_rwlock_unlock(&udp_data.flows_lock); log_err("Failed to respond to flow request."); return -1; } + fset_add(udp_data.np1_flows, fd); + log_dbg("Accepted flow, fd %d on eid %d.", fd, d_eid); @@ -1142,19 +1139,19 @@ static int ipcp_udp_flow_dealloc(int fd) ipcp_flow_fini(fd); - pthread_rwlock_wrlock(&udp_data.flows_lock); - fset_del(udp_data.np1_flows, fd); + pthread_rwlock_wrlock(&udp_data.flows_lock); + skfd = udp_data.fd_to_uf[fd].skfd; udp_data.fd_to_uf[fd].d_eid = -1; udp_data.fd_to_uf[fd].skfd = -1; - close(skfd); - pthread_rwlock_unlock(&udp_data.flows_lock); + close(skfd); + flow_dealloc(fd); log_dbg("Flow with fd %d deallocated.", fd); |