Skip to content

Commit bedd4e0

Browse files
ozhurakijukkar
authored andcommitted
net: tcp2: Add a mutex to TCP connection
The TCP connection might be concurrently modified from the TR/TX threads, so add a mutex to protect from the concurrent modification. Signed-off-by: Oleg Zhurakivskyy <[email protected]>
1 parent d11c92b commit bedd4e0

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

subsys/net/ip/tcp2.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,8 @@ static struct tcp *tcp_conn_alloc(void)
608608

609609
memset(conn, 0, sizeof(*conn));
610610

611+
k_mutex_init(&conn->lock);
612+
611613
conn->state = TCP_LISTEN;
612614

613615
conn->win = tcp_window;
@@ -790,6 +792,8 @@ static void tcp_in(struct tcp *conn, struct net_pkt *pkt)
790792
u8_t next = 0, fl = th ? th->th_flags : 0;
791793
size_t len;
792794

795+
k_mutex_lock(&conn->lock, K_FOREVER);
796+
793797
NET_DBG("%s", log_strdup(tcp_conn_state(conn, pkt)));
794798

795799
if (th && th->th_off < 5) {
@@ -898,6 +902,8 @@ static void tcp_in(struct tcp *conn, struct net_pkt *pkt)
898902
next = 0;
899903
goto next_state;
900904
}
905+
906+
k_mutex_unlock(&conn->lock);
901907
}
902908

903909
/* close() has been called on the socket */

subsys/net/ip/tcp2_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ union tcp_endpoint {
141141
struct tcp { /* TCP connection */
142142
sys_snode_t next;
143143
struct net_context *context;
144+
struct k_mutex lock;
144145
void *recv_user_data;
145146
enum tcp_state state;
146147
u32_t seq;

0 commit comments

Comments
 (0)