Skip to content

Commit

Permalink
[nrf fromtree] net: zperf: Fix session leak
Browse files Browse the repository at this point in the history
In case zperf session was aborted by the user (by for instance stopping
it from shell), or practically in case of any other
communication-related error, the zperf session could end up in a state
other than NULL or COMPLETED, with no way to recover. This made the
session no longer usable and eventually could lead to zperf being not
able to start a new session anymore.

Fix this by introducing zperf_session_reset() function, which resets the
session state back to defaults. The function is called when the zperf
receiver service is stopped.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
(cherry picked from commit 68bc981)
  • Loading branch information
rlubos authored and krish2718 committed Feb 15, 2024
1 parent 06387e6 commit 61eadca
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
23 changes: 18 additions & 5 deletions subsys/net/lib/zperf/zperf_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,27 @@ void zperf_reset_session_stats(struct session *session)
session->last_transit_time = 0;
}

void zperf_session_init(void)
void zperf_session_reset(enum session_proto proto)
{
int i, j;

if (proto >= SESSION_PROTO_END) {
return;
}

i = (int)proto;

for (j = 0; j < SESSION_MAX; j++) {
sessions[i][j].state = STATE_NULL;
zperf_reset_session_stats(&(sessions[i][j]));
}
}

void zperf_session_init(void)
{
int i;

for (i = 0; i < SESSION_PROTO_END; i++) {
for (j = 0; j < SESSION_MAX; j++) {
sessions[i][j].state = STATE_NULL;
zperf_reset_session_stats(&(sessions[i][j]));
}
zperf_session_reset(i);
}
}
2 changes: 2 additions & 0 deletions subsys/net/lib/zperf/zperf_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ struct session *get_session(const struct sockaddr *addr,
enum session_proto proto);
void zperf_session_init(void);
void zperf_reset_session_stats(struct session *session);
/* Reset all sessions for a given protocol. */
void zperf_session_reset(enum session_proto proto);

#endif /* __ZPERF_SESSION_H */
2 changes: 2 additions & 0 deletions subsys/net/lib/zperf/zperf_tcp_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ static void tcp_receiver_cleanup(void)

tcp_server_running = false;
tcp_session_cb = NULL;

zperf_session_reset(SESSION_TCP);
}

static int tcp_recv_data(struct net_socket_service_event *pev)
Expand Down
2 changes: 2 additions & 0 deletions subsys/net/lib/zperf/zperf_udp_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ static void udp_receiver_cleanup(void)

udp_server_running = false;
udp_session_cb = NULL;

zperf_session_reset(SESSION_UDP);
}

static int udp_recv_data(struct net_socket_service_event *pev)
Expand Down

0 comments on commit 61eadca

Please sign in to comment.