Skip to content

Commit

Permalink
fix daemon sub-system destroy order
Browse files Browse the repository at this point in the history
  • Loading branch information
acassen committed Feb 15, 2024
1 parent 1b620ba commit 7fe5cd2
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 19 deletions.
14 changes: 11 additions & 3 deletions src/gtp_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ alloc_daemon_data(void)
INIT_LIST_HEAD(&new->gtp_switch_ctx);
INIT_LIST_HEAD(&new->gtp_router_ctx);


return new;
}

Expand All @@ -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);
}

2 changes: 1 addition & 1 deletion src/gtp_pppoe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/gtp_pppoe_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 18 additions & 2 deletions src/gtp_router.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
22 changes: 19 additions & 3 deletions src/gtp_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down
3 changes: 1 addition & 2 deletions src/include/gtp_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions src/include/gtp_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/include/gtp_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 7fe5cd2

Please sign in to comment.