From 7fe5cd2d3080860ff8e934112353062a9df68ba6 Mon Sep 17 00:00:00 2001 From: Alexandre Cassen Date: Thu, 15 Feb 2024 22:48:57 +0100 Subject: [PATCH] fix daemon sub-system destroy order --- src/gtp_data.c | 14 +++++++++++--- src/gtp_pppoe.c | 2 +- src/gtp_pppoe_proto.c | 3 ++- src/gtp_router.c | 20 ++++++++++++++++++-- src/gtp_switch.c | 22 +++++++++++++++++++--- src/include/gtp_conn.h | 3 +-- src/include/gtp_router.h | 1 + src/include/gtp_switch.h | 3 ++- src/main.c | 6 ------ 9 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/gtp_data.c b/src/gtp_data.c index 66b0e4e..d2ce26a 100644 --- a/src/gtp_data.c +++ b/src/gtp_data.c @@ -145,6 +145,7 @@ alloc_daemon_data(void) INIT_LIST_HEAD(&new->gtp_switch_ctx); INIT_LIST_HEAD(&new->gtp_router_ctx); + return new; } @@ -159,12 +160,19 @@ free_daemon_data(void) gtp_xdp_rt_unload(&daemon_data->xdp_gtp_route); if (__test_bit(GTP_FL_PPP_INGRESS_LOADED_BIT, &daemon_data->flags)) gtp_xdp_ppp_unload(&daemon_data->xdp_ppp_ingress); - gtp_mirror_destroy(); - gtp_vrf_destroy(); + gtp_switch_server_destroy(); + gtp_router_server_destroy(); + gtp_request_destroy(); gtp_pppoe_destroy(); - gtp_apn_destroy(); + gtp_sessions_destroy(); + gtp_conn_destroy(); gtp_switch_destroy(); gtp_router_destroy(); + gtp_xdp_destroy(); + gtp_teid_destroy(); + gtp_mirror_destroy(); + gtp_vrf_destroy(); + gtp_apn_destroy(); FREE(daemon_data); } diff --git a/src/gtp_pppoe.c b/src/gtp_pppoe.c index 9fa786c..2459e29 100644 --- a/src/gtp_pppoe.c +++ b/src/gtp_pppoe.c @@ -414,9 +414,9 @@ static int __gtp_pppoe_release(gtp_pppoe_t *pppoe) { __set_bit(PPPOE_FL_STOPPING_BIT, &pppoe->flags); + gtp_pppoe_timer_destroy(pppoe); gtp_pppoe_worker_destroy(pppoe); gtp_ppp_destroy(pppoe); - gtp_pppoe_timer_destroy(pppoe); pthread_join(pppoe->task, NULL); close(pppoe->fd_disc); close(pppoe->fd_session); diff --git a/src/gtp_pppoe_proto.c b/src/gtp_pppoe_proto.c index b17b05d..ccc82b1 100644 --- a/src/gtp_pppoe_proto.c +++ b/src/gtp_pppoe_proto.c @@ -302,7 +302,8 @@ pppoe_timeout(void *arg) PPPDEBUG(("%s: pppoe hunique:0x%.8x failed to send PADR\n", pppoe->ifname, s->unique)); } - retry_wait = PPPOE_DISC_TIMEOUT * (1 + s->padr_retried); + if (!__test_bit(PPPOE_FL_PADI_FAST_RETRY_BIT, &pppoe->flags)) + retry_wait = PPPOE_DISC_TIMEOUT * (1 + s->padi_retried); timer_node_add(&pppoe->session_timer , &s->t_node, retry_wait); break; diff --git a/src/gtp_router.c b/src/gtp_router.c index a9da7bb..45ef27a 100644 --- a/src/gtp_router.c +++ b/src/gtp_router.c @@ -132,18 +132,34 @@ gtp_router_init(const char *name) return new; } +int +gtp_router_ctx_server_destroy(gtp_router_t *ctx) +{ + gtp_server_destroy(&ctx->gtpc); + gtp_server_destroy(&ctx->gtpu); + return 0; +} int gtp_router_ctx_destroy(gtp_router_t *ctx) { gtp_htab_destroy(&ctx->gtpc_teid_tab); gtp_htab_destroy(&ctx->gtpu_teid_tab); - gtp_server_destroy(&ctx->gtpc); - gtp_server_destroy(&ctx->gtpu); list_head_del(&ctx->next); return 0; } +int +gtp_router_server_destroy(void) +{ + gtp_router_t *c; + + list_for_each_entry(c, &daemon_data->gtp_router_ctx, next) + gtp_router_ctx_server_destroy(c); + + return 0; +} + int gtp_router_destroy(void) { diff --git a/src/gtp_switch.c b/src/gtp_switch.c index 3a318ab..11208ca 100644 --- a/src/gtp_switch.c +++ b/src/gtp_switch.c @@ -167,6 +167,14 @@ gtp_switch_init(const char *name) return new; } +int +gtp_switch_ctx_server_destroy(gtp_switch_t *ctx) +{ + gtp_server_destroy(&ctx->gtpc); + gtp_server_destroy(&ctx->gtpu); + gtp_dpd_destroy(&ctx->iptnl); + return 0; +} int gtp_switch_ctx_destroy(gtp_switch_t *ctx) @@ -176,13 +184,21 @@ gtp_switch_ctx_destroy(gtp_switch_t *ctx) gtp_htab_destroy(&ctx->vteid_tab); gtp_htab_destroy(&ctx->vsqn_tab); - gtp_server_destroy(&ctx->gtpc); - gtp_server_destroy(&ctx->gtpu); - gtp_dpd_destroy(&ctx->iptnl); list_head_del(&ctx->next); return 0; } +int +gtp_switch_server_destroy(void) +{ + gtp_switch_t *c; + + list_for_each_entry(c, &daemon_data->gtp_switch_ctx, next) + gtp_switch_ctx_destroy(c); + + return 0; +} + int gtp_switch_destroy(void) { diff --git a/src/include/gtp_conn.h b/src/include/gtp_conn.h index 6ea0f7d..13fcffc 100644 --- a/src/include/gtp_conn.h +++ b/src/include/gtp_conn.h @@ -41,8 +41,7 @@ typedef struct _gtp_conn { /* FIXME: maybe use a global dlock here */ list_head_t gtp_sessions; - pthread_mutex_t gtp_session_mutex; - + pthread_mutex_t gtp_session_mutex; time_t ts; /* hash stuff */ diff --git a/src/include/gtp_router.h b/src/include/gtp_router.h index 636d22f..92ca58e 100644 --- a/src/include/gtp_router.h +++ b/src/include/gtp_router.h @@ -48,6 +48,7 @@ extern int gtp_router_ingress_process(gtp_server_worker_t *, struct sockaddr_sto extern gtp_router_t *gtp_router_get(const char *); extern gtp_router_t *gtp_router_init(const char *); extern int gtp_router_ctx_destroy(gtp_router_t *); +extern int gtp_router_server_destroy(void); extern int gtp_router_destroy(void); extern int gtp_router_vty_init(void); diff --git a/src/include/gtp_switch.h b/src/include/gtp_switch.h index 68b976c..2a4c398 100644 --- a/src/include/gtp_switch.h +++ b/src/include/gtp_switch.h @@ -54,7 +54,8 @@ extern int gtp_switch_ingress_process(gtp_server_worker_t *, struct sockaddr_sto extern gtp_switch_t *gtp_switch_get(const char *); extern gtp_switch_t *gtp_switch_init(const char *); extern int gtp_switch_ctx_destroy(gtp_switch_t *); +extern int gtp_switch_server_destroy(void); extern int gtp_switch_destroy(void); extern int gtp_switch_vty_init(void); -#endif +#endif \ No newline at end of file diff --git a/src/main.c b/src/main.c index e2cd169..0057ead 100644 --- a/src/main.c +++ b/src/main.c @@ -52,12 +52,6 @@ stop_gtp(void) /* Just cleanup memory & exit */ vty_terminate(); cmd_terminate(); - gtp_request_destroy(); - gtp_sessions_destroy(); - gtp_conn_destroy(); - gtp_xdp_destroy(); - gtp_teid_destroy(); - free_daemon_data(); thread_destroy_master(master);