diff --git a/lib/sbi/client.c b/lib/sbi/client.c index a22ee5baf7..eccd6a292d 100644 --- a/lib/sbi/client.c +++ b/lib/sbi/client.c @@ -103,17 +103,20 @@ ogs_sbi_client_t *ogs_sbi_client_add( { ogs_sbi_client_t *client = NULL; CURLM *multi = NULL; + char buf[OGS_ADDRSTRLEN]; ogs_assert(scheme); ogs_assert(addr); ogs_pool_alloc(&client_pool, &client); - ogs_assert(client); + if (!client) { + ogs_error("No memory in client_pool"); + return NULL; + } memset(client, 0, sizeof(ogs_sbi_client_t)); client->scheme = scheme; - ogs_debug("ogs_sbi_client_add[%s]", OpenAPI_uri_scheme_ToString(scheme)); OGS_OBJECT_REF(client); ogs_assert(OGS_OK == ogs_copyaddrinfo(&client->node.addr, addr)); @@ -141,6 +144,9 @@ ogs_sbi_client_t *ogs_sbi_client_add( ogs_list_add(&ogs_sbi_self()->client_list, client); + ogs_debug("[%d] CLEINT added with Ref [%s:%d]", + client->reference_count, OGS_ADDR(addr, buf), OGS_PORT(addr)); + return client; } @@ -153,8 +159,8 @@ void ogs_sbi_client_remove(ogs_sbi_client_t *client) addr = client->node.addr; ogs_assert(addr); - ogs_debug("ogs_sbi_client_remove() [%s:%d]", - OGS_ADDR(addr, buf), OGS_PORT(addr)); + ogs_debug("[%d] CLEINT UnRef [%s:%d]", + client->reference_count, OGS_ADDR(addr, buf), OGS_PORT(addr)); /* ogs_sbi_client_t is always created with reference context */ if (OGS_OBJECT_IS_REF(client)) { @@ -162,6 +168,9 @@ void ogs_sbi_client_remove(ogs_sbi_client_t *client) return; } + ogs_debug("[%d] CLEINT removed [%s:%d]", + client->reference_count, OGS_ADDR(addr, buf), OGS_PORT(addr)); + ogs_list_remove(&ogs_sbi_self()->client_list, client); connection_remove_all(client); diff --git a/lib/sbi/client.h b/lib/sbi/client.h index c5ccaa8ba0..c1b84acdd3 100644 --- a/lib/sbi/client.h +++ b/lib/sbi/client.h @@ -30,13 +30,13 @@ extern "C" { #define OGS_SBI_SETUP_CLIENT(__cTX, __pClient) \ do { \ + char buf[OGS_ADDRSTRLEN]; \ ogs_assert((__cTX)); \ ogs_assert((__pClient)); \ \ if ((__cTX)->client) { \ ogs_sbi_client_t *client = NULL; \ ogs_sockaddr_t *addr = NULL; \ - char buf[OGS_ADDRSTRLEN]; \ \ client = ((__cTX)->client); \ ogs_assert(client); \ @@ -49,6 +49,10 @@ extern "C" { \ OGS_OBJECT_REF(__pClient); \ ((__cTX)->client) = (__pClient); \ + ogs_debug("[%d] CLIENT Ref [%s:%d]", \ + (__pClient)->reference_count, \ + OGS_ADDR((__pClient)->node.addr, buf), \ + OGS_PORT((__pClient)->node.addr)); \ } while(0) typedef int (*ogs_sbi_client_cb_f)( diff --git a/lib/sbi/context.c b/lib/sbi/context.c index c1bcb46708..42da88069b 100644 --- a/lib/sbi/context.c +++ b/lib/sbi/context.c @@ -580,6 +580,7 @@ int ogs_sbi_context_parse_config( if (addr == NULL) continue; + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add( ogs_sbi_client_default_scheme(), addr); ogs_assert(client); @@ -683,6 +684,7 @@ int ogs_sbi_context_parse_config( if (addr == NULL) continue; + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add( ogs_sbi_client_default_scheme(), addr); ogs_assert(client); @@ -805,8 +807,6 @@ ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_add(void) ogs_assert(nf_instance); memset(nf_instance, 0, sizeof(ogs_sbi_nf_instance_t)); - ogs_debug("ogs_sbi_nf_instance_add()"); - OGS_OBJECT_REF(nf_instance); nf_instance->time.heartbeat_interval = @@ -818,6 +818,9 @@ ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_add(void) ogs_list_add(&ogs_sbi_self()->nf_instance_list, nf_instance); + ogs_debug("[%s:%d] NFInstance added with Ref", + nf_instance->id, nf_instance->reference_count); + return nf_instance; } @@ -913,13 +916,17 @@ void ogs_sbi_nf_instance_remove(ogs_sbi_nf_instance_t *nf_instance) { ogs_assert(nf_instance); - ogs_debug("ogs_sbi_nf_instance_remove()"); + ogs_debug("[%s:%d] NFInstance UnRef", + nf_instance->id, nf_instance->reference_count); if (OGS_OBJECT_IS_REF(nf_instance)) { OGS_OBJECT_UNREF(nf_instance); return; } + ogs_debug("[%s:%d] NFInstance removed", + nf_instance->id, nf_instance->reference_count); + ogs_list_remove(&ogs_sbi_self()->nf_instance_list, nf_instance); ogs_sbi_nf_info_remove_all(&nf_instance->nf_info_list); @@ -1519,8 +1526,15 @@ static ogs_sbi_client_t *find_client_by_fqdn( client = ogs_sbi_client_find(scheme, addr); if (!client) { + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add(scheme, addr); - ogs_assert(client); + if (!client) { + char buf[OGS_ADDRSTRLEN]; + ogs_error("%s: ogs_sbi_client_add() failed [%s]:%d", + OGS_FUNC, OGS_ADDR(addr, buf), OGS_PORT(addr)); + ogs_freeaddrinfo(addr); + return NULL; + } } ogs_freeaddrinfo(addr); @@ -1548,8 +1562,14 @@ static ogs_sbi_client_t *nf_instance_find_client( if (addr) { client = ogs_sbi_client_find(scheme, addr); if (!client) { + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add(scheme, addr); - ogs_assert(client); + if (!client) { + char buf[OGS_ADDRSTRLEN]; + ogs_error("%s: ogs_sbi_client_add() failed [%s]:%d", + OGS_FUNC, OGS_ADDR(addr, buf), OGS_PORT(addr)); + return NULL; + } } } } @@ -1578,12 +1598,19 @@ static void nf_service_associate_client(ogs_sbi_nf_service_t *nf_service) if (addr) { client = ogs_sbi_client_find(nf_service->scheme, addr); if (!client) { + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add(nf_service->scheme, addr); - ogs_assert(client); + if (!client) { + char buf[OGS_ADDRSTRLEN]; + ogs_error("%s: ogs_sbi_client_add() failed [%s]:%d", + OGS_FUNC, OGS_ADDR(addr, buf), OGS_PORT(addr)); + } } } } + ogs_debug("[%s] NFService associated [%s]", + nf_service->name, nf_service->id); if (client) OGS_SBI_SETUP_CLIENT(nf_service, client); } diff --git a/lib/sbi/nnrf-handler.c b/lib/sbi/nnrf-handler.c index 000fd0104e..8bdffe1fdd 100644 --- a/lib/sbi/nnrf-handler.c +++ b/lib/sbi/nnrf-handler.c @@ -747,7 +747,7 @@ bool ogs_nnrf_nfm_handle_nf_status_notify( ogs_sbi_nf_fsm_tran( nf_instance, ogs_sbi_nf_state_de_registered); } else { - ogs_info("[%s:%d] NF removed", + ogs_info("[%s:%d] (NRF-notify) NF_DEREGISTERED event", nf_instance->id, nf_instance->reference_count); ogs_sbi_nf_fsm_fini((nf_instance)); ogs_sbi_nf_instance_remove(nf_instance); diff --git a/src/amf/namf-handler.c b/src/amf/namf-handler.c index 7eb3bda75e..7594d874bc 100644 --- a/src/amf/namf-handler.c +++ b/src/amf/namf-handler.c @@ -248,8 +248,15 @@ int amf_namf_comm_handle_n1_n2_message_transfer( client = ogs_sbi_client_find(scheme, addr); if (!client) { + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add(scheme, addr); - ogs_assert(client); + if (!client) { + char buf[OGS_ADDRSTRLEN]; + ogs_error("%s: ogs_sbi_client_add() failed [%s]:%d", + OGS_FUNC, OGS_ADDR(addr, buf), OGS_PORT(addr)); + ogs_freeaddrinfo(addr); + return OGS_ERROR; + } } OGS_SBI_SETUP_CLIENT(&sess->paging, client); ogs_freeaddrinfo(addr); diff --git a/src/amf/nnssf-handler.c b/src/amf/nnssf-handler.c index a1d33811f9..10de73c0fb 100644 --- a/src/amf/nnssf-handler.c +++ b/src/amf/nnssf-handler.c @@ -126,13 +126,23 @@ int amf_nnssf_nsselection_handle_get( ogs_sbi_discovery_option_free(discovery_option); - return OGS_ERROR;; + return OGS_ERROR; } client = ogs_sbi_client_find(scheme, addr); if (!client) { + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add(scheme, addr); - ogs_assert(client); + if (!client) { + char buf[OGS_ADDRSTRLEN]; + ogs_error("%s: ogs_sbi_client_add() failed [%s]:%d", + OGS_FUNC, OGS_ADDR(addr, buf), OGS_PORT(addr)); + + ogs_sbi_discovery_option_free(discovery_option); + ogs_freeaddrinfo(addr); + + return OGS_ERROR; + } } OGS_SBI_SETUP_CLIENT(&sess->nssf.nrf, client); diff --git a/src/nrf/nnrf-handler.c b/src/nrf/nnrf-handler.c index 987e16de44..166ce17b11 100644 --- a/src/nrf/nnrf-handler.c +++ b/src/nrf/nnrf-handler.c @@ -344,6 +344,7 @@ bool nrf_nnrf_handle_nf_status_subscribe( client = ogs_sbi_client_find(scheme, addr); if (!client) { + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add(scheme, addr); ogs_assert(client); } diff --git a/src/nrf/nrf-sm.c b/src/nrf/nrf-sm.c index 0b1e4b55d5..21b49b708c 100644 --- a/src/nrf/nrf-sm.c +++ b/src/nrf/nrf-sm.c @@ -158,6 +158,9 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) ogs_fsm_dispatch(&nf_instance->sm, e); if (OGS_FSM_CHECK(&nf_instance->sm, nrf_nf_state_de_registered)) { + ogs_info("[%s:%d] NF de-registered", + nf_instance->id, + nf_instance->reference_count); nrf_nf_fsm_fini(nf_instance); ogs_sbi_nf_instance_remove(nf_instance); } else if (OGS_FSM_CHECK(&nf_instance->sm, diff --git a/src/pcf/npcf-handler.c b/src/pcf/npcf-handler.c index c7e518d68f..581a5531ab 100644 --- a/src/pcf/npcf-handler.c +++ b/src/pcf/npcf-handler.c @@ -93,8 +93,15 @@ bool pcf_npcf_am_policy_contrtol_handle_create(pcf_ue_t *pcf_ue, client = ogs_sbi_client_find(scheme, addr); if (!client) { + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add(scheme, addr); - ogs_assert(client); + if (!client) { + char buf[OGS_ADDRSTRLEN]; + ogs_error("%s: ogs_sbi_client_add() failed [%s]:%d", + OGS_FUNC, OGS_ADDR(addr, buf), OGS_PORT(addr)); + ogs_freeaddrinfo(addr); + return false; + } } OGS_SBI_SETUP_CLIENT(&pcf_ue->namf, client); ogs_freeaddrinfo(addr); @@ -276,8 +283,16 @@ bool pcf_npcf_smpolicycontrol_handle_create(pcf_sess_t *sess, client = ogs_sbi_client_find(scheme, addr); if (!client) { + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add(scheme, addr); - ogs_assert(client); + if (!client) { + char buf[OGS_ADDRSTRLEN]; + strerror = ogs_msprintf("%s: ogs_sbi_client_add() failed [%s]:%d", + OGS_FUNC, OGS_ADDR(addr, buf), OGS_PORT(addr)); + status = OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR; + ogs_freeaddrinfo(addr); + goto cleanup; + } } OGS_SBI_SETUP_CLIENT(&sess->nsmf, client); ogs_freeaddrinfo(addr); @@ -599,8 +614,16 @@ bool pcf_npcf_policyauthorization_handle_create(pcf_sess_t *sess, client = ogs_sbi_client_find(scheme, addr); if (!client) { + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add(scheme, addr); - ogs_assert(client); + if (!client) { + char buf[OGS_ADDRSTRLEN]; + strerror = ogs_msprintf("%s: ogs_sbi_client_add() failed [%s]:%d", + OGS_FUNC, OGS_ADDR(addr, buf), OGS_PORT(addr)); + status = OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR; + ogs_freeaddrinfo(addr); + goto cleanup; + } } OGS_SBI_SETUP_CLIENT(&app_session->naf, client); ogs_freeaddrinfo(addr); diff --git a/src/scp/sbi-path.c b/src/scp/sbi-path.c index 55ad68e070..0ef585a334 100644 --- a/src/scp/sbi-path.c +++ b/src/scp/sbi-path.c @@ -309,8 +309,19 @@ static int request_handler(ogs_sbi_request_t *request, void *data) client = ogs_sbi_client_find(scheme, addr); if (!client) { + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add(scheme, addr); - ogs_assert(client); + if (!client) { + char buf[OGS_ADDRSTRLEN]; + ogs_error("ogs_sbi_client_add() failed [%s]:%d", + OGS_ADDR(addr, buf), OGS_PORT(addr)); + + ogs_freeaddrinfo(addr); + ogs_sbi_discovery_option_free(discovery_option); + scp_assoc_remove(assoc); + + return OGS_ERROR; + } } OGS_SBI_SETUP_CLIENT(assoc, client); ogs_freeaddrinfo(addr); @@ -443,8 +454,19 @@ static int request_handler(ogs_sbi_request_t *request, void *data) nrf_client = ogs_sbi_client_find(scheme, addr); if (!nrf_client) { + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); nrf_client = ogs_sbi_client_add(scheme, addr); - ogs_assert(nrf_client); + if (!nrf_client) { + char buf[OGS_ADDRSTRLEN]; + ogs_error("ogs_sbi_client_add() failed [%s]:%d", + OGS_ADDR(addr, buf), OGS_PORT(addr)); + + ogs_freeaddrinfo(addr); + ogs_sbi_discovery_option_free(discovery_option); + scp_assoc_remove(assoc); + + return OGS_ERROR; + } } OGS_SBI_SETUP_CLIENT(assoc, nrf_client); ogs_freeaddrinfo(addr); diff --git a/src/smf/nsmf-handler.c b/src/smf/nsmf-handler.c index f9f9903b1b..8901fce22c 100644 --- a/src/smf/nsmf-handler.c +++ b/src/smf/nsmf-handler.c @@ -250,8 +250,15 @@ bool smf_nsmf_handle_create_sm_context( client = ogs_sbi_client_find(scheme, addr); if (!client) { + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add(scheme, addr); - ogs_assert(client); + if (!client) { + char buf[OGS_ADDRSTRLEN]; + ogs_error("%s: ogs_sbi_client_add() failed [%s]:%d", + OGS_FUNC, OGS_ADDR(addr, buf), OGS_PORT(addr)); + ogs_freeaddrinfo(addr); + return false; + } } OGS_SBI_SETUP_CLIENT(&sess->namf, client); ogs_freeaddrinfo(addr); diff --git a/tests/af/context.c b/tests/af/context.c index 14fe786e39..48a59d922e 100644 --- a/tests/af/context.c +++ b/tests/af/context.c @@ -289,8 +289,15 @@ static ogs_sbi_client_t *find_client_by_fqdn( client = ogs_sbi_client_find(scheme, addr); if (!client) { + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add(scheme, addr); - ogs_assert(client); + if (!client) { + char buf[OGS_ADDRSTRLEN]; + ogs_error("%s: ogs_sbi_client_add() failed [%s]:%d", + OGS_FUNC, OGS_ADDR(addr, buf), OGS_PORT(addr)); + ogs_freeaddrinfo(addr); + return NULL; + } } ogs_freeaddrinfo(addr); @@ -323,8 +330,13 @@ void af_sess_associate_pcf_client(af_sess_t *sess) if (addr) { client = ogs_sbi_client_find(scheme, addr); if (!client) { + ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC); client = ogs_sbi_client_add(scheme, addr); - ogs_assert(client); + if (!client) { + char buf[OGS_ADDRSTRLEN]; + ogs_error("%s: ogs_sbi_client_add() failed [%s]:%d", + OGS_FUNC, OGS_ADDR(addr, buf), OGS_PORT(addr)); + } } } }