[NRF] Don't abort if there are too many registered NF instances (#1579)

Reply with an error instead.
This commit is contained in:
mitmitmitm 2022-06-06 13:54:59 +02:00 committed by GitHub
parent 7dd5d27a71
commit a6abe1fffb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 0 deletions

View File

@ -494,6 +494,11 @@ int ogs_sbi_context_parse_config(const char *local, const char *remote)
return OGS_OK;
}
bool ogs_sbi_nf_instance_maximum_number_is_reached()
{
return nf_instance_pool.avail <= 0;
}
ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_add(char *id)
{
ogs_sbi_nf_instance_t *nf_instance = NULL;

View File

@ -246,6 +246,7 @@ void ogs_sbi_context_final(void);
ogs_sbi_context_t *ogs_sbi_self(void);
int ogs_sbi_context_parse_config(const char *local, const char *remote);
bool ogs_sbi_nf_instance_maximum_number_is_reached(void);
ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_add(char *id);
void ogs_sbi_nf_instance_add_allowed_nf_type(
ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_type_e allowed_nf_type);

View File

@ -105,6 +105,19 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e)
if (!nf_instance) {
SWITCH(message.h.method)
CASE(OGS_SBI_HTTP_METHOD_PUT)
if (ogs_sbi_nf_instance_maximum_number_is_reached()) {
ogs_warn("Can't add instance [%s] "
"due to insufficient space",
message.h.resource.component[1]);
ogs_assert(
true ==
ogs_sbi_server_send_error(
stream,
OGS_SBI_HTTP_STATUS_PAYLOAD_TOO_LARGE,
&message, "Insufficient space",
message.h.resource.component[1]));
break;
}
nf_instance = ogs_sbi_nf_instance_add(
message.h.resource.component[1]);
ogs_assert(nf_instance);