Skip to content

Commit bd9f707

Browse files
jukkarnashif
authored andcommitted
net: tcp2: Print context state when closing connection
Useful in debugging. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 9cccf0e commit bd9f707

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

subsys/net/ip/net_context.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,22 @@ void net_context_foreach(net_context_cb_t cb, void *user_data)
22122212
k_sem_give(&contexts_lock);
22132213
}
22142214

2215+
const char *net_context_state(struct net_context *context)
2216+
{
2217+
switch (net_context_get_state(context)) {
2218+
case NET_CONTEXT_IDLE:
2219+
return "IDLE";
2220+
case NET_CONTEXT_CONNECTING:
2221+
return "CONNECTING";
2222+
case NET_CONTEXT_CONNECTED:
2223+
return "CONNECTED";
2224+
case NET_CONTEXT_LISTENING:
2225+
return "LISTENING";
2226+
}
2227+
2228+
return NULL;
2229+
}
2230+
22152231
void net_context_init(void)
22162232
{
22172233
k_sem_init(&contexts_lock, 1, UINT_MAX);

subsys/net/ip/net_private.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern void net_if_stats_reset_all(void);
4646

4747
#if defined(CONFIG_NET_NATIVE) || defined(CONFIG_NET_OFFLOAD)
4848
extern void net_context_init(void);
49+
extern const char *net_context_state(struct net_context *context);
4950
extern void net_pkt_init(void);
5051
extern void net_tc_tx_init(void);
5152
extern void net_tc_rx_init(void);
@@ -54,6 +55,11 @@ static inline void net_context_init(void) { }
5455
static inline void net_pkt_init(void) { }
5556
static inline void net_tc_tx_init(void) { }
5657
static inline void net_tc_rx_init(void) { }
58+
static inline const char *net_context_state(context)
59+
{
60+
ARG_UNUSED(context);
61+
return NULL;
62+
}
5763
#endif
5864

5965
#if defined(CONFIG_NET_NATIVE)

subsys/net/ip/tcp2.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,9 @@ int net_tcp_put(struct net_context *context)
13831383
struct tcp *conn = context->tcp;
13841384

13851385
NET_DBG("%s", conn ? log_strdup(tcp_conn_state(conn, NULL)) : "");
1386+
NET_DBG("context %p %s", context,
1387+
log_strdup(({ const char *state = net_context_state(context);
1388+
state ? state : "<unknown>"; })));
13861389

13871390
if (conn && conn->state == TCP_ESTABLISHED) {
13881391
k_mutex_lock(&conn->lock, K_FOREVER);

0 commit comments

Comments
 (0)