From b99490e2955f967f2780d2726b1e8f33b9f41f23 Mon Sep 17 00:00:00 2001 From: Christian Giese Date: Thu, 21 Apr 2022 16:58:28 +0200 Subject: [PATCH] enhance session-start command #78 --- code/bngblaster/src/bbl_ctrl.c | 19 ++++++++++++++++--- code/bngblaster/src/bbl_session.c | 2 +- code/bngblaster/src/bbl_session.h | 3 +++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/code/bngblaster/src/bbl_ctrl.c b/code/bngblaster/src/bbl_ctrl.c index 0d1b3eed..559274df 100644 --- a/code/bngblaster/src/bbl_ctrl.c +++ b/code/bngblaster/src/bbl_ctrl.c @@ -421,7 +421,7 @@ bbl_ctrl_session_info(int fd, bbl_ctx_s *ctx, uint32_t session_id, json_t* argum if(session) { session_json = bbl_session_json(session); if(!session_json) { - bbl_ctrl_status(fd, "error", 500, "internal error"); + return bbl_ctrl_status(fd, "error", 500, "internal error"); } root = json_pack("{ss si so*}", @@ -446,14 +446,27 @@ ssize_t bbl_ctrl_session_start(int fd, bbl_ctx_s *ctx, uint32_t session_id, json_t* arguments __attribute__((unused))) { bbl_session_s *session; + if(g_teardown) { + return bbl_ctrl_status(fd, "error", 405, "teardown"); + } + if(session_id == 0) { /* session-id is mandatory */ - return bbl_ctrl_status(fd, "error", 405, "missing session-id"); + return bbl_ctrl_status(fd, "error", 400, "missing session-id"); } session = bbl_session_get(ctx, session_id); if(session) { - if(session->session_state != BBL_IDLE || + if(session->session_state == BBL_TERMINATED && + session->reconnect_delay == 0) { + ctx->sessions_flapped++; + session->stats.flapped++; + session->session_state = BBL_IDLE; + bbl_session_reset(session); + if(ctx->sessions_terminated) { + ctx->sessions_terminated--; + } + } else if(session->session_state != BBL_IDLE || CIRCLEQ_NEXT(session, session_idle_qnode) || CIRCLEQ_PREV(session, session_idle_qnode)) { return bbl_ctrl_status(fd, "error", 405, "wrong session state"); diff --git a/code/bngblaster/src/bbl_session.c b/code/bngblaster/src/bbl_session.c index a4817ce7..c03bb456 100644 --- a/code/bngblaster/src/bbl_session.c +++ b/code/bngblaster/src/bbl_session.c @@ -128,7 +128,7 @@ bbl_session_get(bbl_ctx_s *ctx, uint32_t session_id) return ctx->session_list[session_id-1]; } -static void +void bbl_session_reset(bbl_session_s *session) { /* Reset session for reconnect */ memset(&session->server_mac, 0xff, ETH_ADDR_LEN); /* init with broadcast MAC */ diff --git a/code/bngblaster/src/bbl_session.h b/code/bngblaster/src/bbl_session.h index 8730f7a9..c777cc4e 100644 --- a/code/bngblaster/src/bbl_session.h +++ b/code/bngblaster/src/bbl_session.h @@ -418,6 +418,9 @@ session_state_string(uint32_t state); bbl_session_s * bbl_session_get(bbl_ctx_s *ctx, uint32_t session_id); +void +bbl_session_reset(bbl_session_s *session); + void bbl_session_update_state(bbl_ctx_s *ctx, bbl_session_s *session, session_state_t state);