From 794f555f63cc662c73e9113fd1eff2ebba4e50ff Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Mon, 8 May 2023 18:57:32 +0200 Subject: [PATCH] BGP: fix listen socket cleanup --- proto/bgp/bgp.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index e2a0d7df..c98f84ab 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -197,13 +197,20 @@ bgp_close(struct bgp_proto *p) struct bgp_listen_request *req = &p->listen; struct bgp_socket *bs = req->sock; - if (bs) + if (enlisted(&req->n)) { - req->sock = NULL; + /* Remove listen request from listen socket or pending list */ rem_node(&req->n); - if (bs && EMPTY_LIST(bs->requests)) - ev_send(&global_event_list, &bgp_listen_event); + if (bs) + { + /* Already had a socket. */ + req->sock = NULL; + + /* Request listen socket cleanup */ + if (bs && EMPTY_LIST(bs->requests)) + ev_send(&global_event_list, &bgp_listen_event); + } } UNLOCK_DOMAIN(rtable, bgp_listen_domain);