Skip to content

Commit

Permalink
Include cause in HTTP response ProblemDetails (open5gs#3051)
Browse files Browse the repository at this point in the history
Cause is set according to particular NF standard.

Additionally:
- OGS_SBI_HTTP_STATUS_MEHTOD_NOT_ALLOWED typo fixed.
- [PCF] Fixed SM Policy establishment error handling
  • Loading branch information
gstaa authored Apr 4, 2024
1 parent 3ee4bb7 commit eb2b19b
Show file tree
Hide file tree
Showing 51 changed files with 573 additions and 392 deletions.
2 changes: 1 addition & 1 deletion lib/sbi/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern "C" {
#define OGS_SBI_HTTP_STATUS_UNAUTHORIZED 401 /* ALL */
#define OGS_SBI_HTTP_STATUS_FORBIDDEN 403 /* ALL */
#define OGS_SBI_HTTP_STATUS_NOT_FOUND 404 /* ALL */
#define OGS_SBI_HTTP_STATUS_MEHTOD_NOT_ALLOWED 405 /* ALL */
#define OGS_SBI_HTTP_STATUS_METHOD_NOT_ALLOWED 405 /* ALL */
#define OGS_SBI_HTTP_STATUS_NOT_ACCEPTABLE 406 /* GET OPTIONS */
#define OGS_SBI_HTTP_STATUS_REQUEST_TIMEOUT 408 /* ALL */
#define OGS_SBI_HTTP_STATUS_CONFLICT 409 /* PATCH POST PUT */
Expand Down
2 changes: 1 addition & 1 deletion lib/sbi/mhd-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ static _MHD_Result access_handler(
ogs_assert(true ==
ogs_sbi_server_send_error((ogs_sbi_stream_t *)sbi_sess,
OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL,
"server callback error", NULL));
"server callback error", NULL, NULL));

return MHD_YES;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/sbi/nghttp2-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ static int on_frame_recv(nghttp2_session *session,
ogs_assert(true ==
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL,
"server callback error", NULL));
"server callback error", NULL, NULL));

return 0;
}
Expand Down
23 changes: 12 additions & 11 deletions lib/sbi/nnrf-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,15 +927,15 @@ bool ogs_nnrf_nfm_handle_nf_status_notify(
ogs_error("No NotificationData");
ogs_assert(true ==
ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
recvmsg, "No NotificationData", NULL));
recvmsg, "No NotificationData", NULL, NULL));
return false;
}

if (!NotificationData->nf_instance_uri) {
ogs_error("No nfInstanceUri");
ogs_assert(true ==
ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
recvmsg, "No nfInstanceUri", NULL));
recvmsg, "No nfInstanceUri", NULL, NULL));
return false;
}

Expand All @@ -947,15 +947,15 @@ bool ogs_nnrf_nfm_handle_nf_status_notify(
ogs_error("Cannot parse nfInstanceUri [%s]", header.uri);
ogs_assert(true ==
ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
recvmsg, "Cannot parse nfInstanceUri", header.uri));
recvmsg, "Cannot parse nfInstanceUri", header.uri, NULL));
return false;
}

if (!message.h.resource.component[1]) {
ogs_error("No nfInstanceId [%s]", header.uri);
ogs_assert(true ==
ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
recvmsg, "Cannot parse nfInstanceUri", header.uri));
recvmsg, "Cannot parse nfInstanceUri", header.uri, NULL));
ogs_sbi_header_free(&header);
return false;
}
Expand All @@ -966,7 +966,7 @@ bool ogs_nnrf_nfm_handle_nf_status_notify(
ogs_assert(true ==
ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN,
recvmsg, "The notification is not allowed",
message.h.resource.component[1]));
message.h.resource.component[1], NULL));
ogs_sbi_header_free(&header);
return false;
}
Expand All @@ -982,7 +982,7 @@ bool ogs_nnrf_nfm_handle_nf_status_notify(
ogs_assert(true ==
ogs_sbi_server_send_error(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
recvmsg, "No NFProfile", NULL));
recvmsg, "No NFProfile", NULL, NULL));
ogs_sbi_header_free(&header);
return false;
}
Expand All @@ -992,7 +992,7 @@ bool ogs_nnrf_nfm_handle_nf_status_notify(
ogs_assert(true ==
ogs_sbi_server_send_error(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
recvmsg, "No NFProfile.NFInstanceId", NULL));
recvmsg, "No NFProfile.NFInstanceId", NULL, NULL));
ogs_sbi_header_free(&header);
return false;
}
Expand All @@ -1002,7 +1002,7 @@ bool ogs_nnrf_nfm_handle_nf_status_notify(
ogs_assert(true ==
ogs_sbi_server_send_error(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
recvmsg, "No NFProfile.NFType", NULL));
recvmsg, "No NFProfile.NFType", NULL, NULL));
ogs_sbi_header_free(&header);
return false;
}
Expand All @@ -1012,7 +1012,7 @@ bool ogs_nnrf_nfm_handle_nf_status_notify(
ogs_assert(true ==
ogs_sbi_server_send_error(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
recvmsg, "No NFProfile.NFStatus", NULL));
recvmsg, "No NFProfile.NFStatus", NULL, NULL));
ogs_sbi_header_free(&header);
return false;
}
Expand Down Expand Up @@ -1086,7 +1086,8 @@ bool ogs_nnrf_nfm_handle_nf_status_notify(
ogs_assert(true ==
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_NOT_FOUND,
recvmsg, "Not found", message.h.resource.component[1]));
recvmsg, "Not found", message.h.resource.component[1],
NULL));
ogs_sbi_header_free(&header);
return false;
}
Expand All @@ -1098,7 +1099,7 @@ bool ogs_nnrf_nfm_handle_nf_status_notify(
ogs_assert(true ==
ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
recvmsg, "Not supported event",
eventstr ? eventstr : "Unknown"));
eventstr ? eventstr : "Unknown", NULL));
ogs_sbi_header_free(&header);
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/sbi/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ bool ogs_sbi_server_send_problem(

bool ogs_sbi_server_send_error(ogs_sbi_stream_t *stream,
int status, ogs_sbi_message_t *message,
const char *title, const char *detail)
const char *title, const char *detail, const char *cause)
{
OpenAPI_problem_details_t problem;

Expand All @@ -224,6 +224,7 @@ bool ogs_sbi_server_send_error(ogs_sbi_stream_t *stream,
}
problem.title = (char*)title;
problem.detail = (char*)detail;
problem.cause = (char*)cause;

ogs_sbi_server_send_problem(stream, &problem);

Expand Down
3 changes: 2 additions & 1 deletion lib/sbi/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ bool ogs_sbi_server_send_response(
ogs_sbi_stream_t *stream, ogs_sbi_response_t *response);
bool ogs_sbi_server_send_error(ogs_sbi_stream_t *stream,
int status, ogs_sbi_message_t *message,
const char *title, const char *detail);
const char *title, const char *detail, const char *cause);

bool ogs_sbi_server_send_problem(
ogs_sbi_stream_t *stream, OpenAPI_problem_details_t *problem);

Expand Down
25 changes: 14 additions & 11 deletions src/amf/amf-sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
ogs_assert(true ==
ogs_sbi_server_send_error(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
NULL, "cannot parse HTTP sbi_message", NULL));
NULL, "cannot parse HTTP sbi_message", NULL, NULL));
break;
}

Expand All @@ -117,7 +117,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
ogs_assert(true ==
ogs_sbi_server_send_error(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
&sbi_message, "Not supported version", NULL));
&sbi_message, "Not supported version", NULL, NULL));
ogs_sbi_message_free(&sbi_message);
break;
}
Expand All @@ -137,7 +137,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
ogs_assert(true ==
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_FORBIDDEN, &sbi_message,
"Invalid HTTP method", sbi_message.h.method));
"Invalid HTTP method", sbi_message.h.method, NULL));
END
break;

Expand All @@ -148,7 +148,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message,
"Invalid resource name",
sbi_message.h.resource.component[0]));
sbi_message.h.resource.component[0], NULL));
END
break;

Expand All @@ -166,7 +166,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_BAD_REQUEST,
&sbi_message,
"No N1N2MessageTransferReqData", NULL));
"No N1N2MessageTransferReqData", NULL, NULL));
}
break;

Expand All @@ -176,7 +176,8 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
ogs_assert(true ==
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_FORBIDDEN, &sbi_message,
"Invalid HTTP method", sbi_message.h.method));
"Invalid HTTP method", sbi_message.h.method,
NULL));
END
break;

Expand All @@ -192,7 +193,8 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
ogs_assert(true ==
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_FORBIDDEN, &sbi_message,
"Invalid HTTP method", sbi_message.h.method));
"Invalid HTTP method", sbi_message.h.method,
NULL));
END
break;

Expand All @@ -203,7 +205,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message,
"Invalid resource name",
sbi_message.h.resource.component[2]));
sbi_message.h.resource.component[2], NULL));
END
break;

Expand All @@ -214,7 +216,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message,
"Invalid resource name",
sbi_message.h.resource.component[0]));
sbi_message.h.resource.component[0], NULL));
END
break;

Expand Down Expand Up @@ -245,7 +247,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message,
"Invalid resource name",
sbi_message.h.resource.component[1]));
sbi_message.h.resource.component[1], NULL));
END
break;

Expand All @@ -254,7 +256,8 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
ogs_assert(true ==
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message,
"Invalid API name", sbi_message.h.resource.component[0]));
"Invalid API name", sbi_message.h.resource.component[0],
NULL));
END

/* In lib/sbi/server.c, notify_completed() releases 'request' buffer. */
Expand Down
2 changes: 1 addition & 1 deletion src/amf/namf-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ int amf_namf_comm_handle_ue_context_transfer_request(
ogs_error("%s", strerror);

ogs_assert(true ==
ogs_sbi_server_send_error(stream, status, NULL, strerror, NULL));
ogs_sbi_server_send_error(stream, status, NULL, strerror, NULL, NULL));
ogs_free(strerror);

return OGS_ERROR;
Expand Down
16 changes: 9 additions & 7 deletions src/ausf/ausf-sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e)
ogs_assert(true ==
ogs_sbi_server_send_error(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
NULL, "cannot parse HTTP message", NULL));
NULL, "cannot parse HTTP message", NULL, NULL));
break;
}

Expand All @@ -82,7 +82,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e)
ogs_assert(true ==
ogs_sbi_server_send_error(
stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
&message, "Not supported version", NULL));
&message, "Not supported version", NULL, NULL));
ogs_sbi_message_free(&message);
break;
}
Expand All @@ -104,7 +104,8 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e)
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_FORBIDDEN,
&message,
"Invalid HTTP method", message.h.method));
"Invalid HTTP method", message.h.method,
NULL));
END
break;

Expand All @@ -115,7 +116,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e)
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message,
"Unknown resource name",
message.h.resource.component[0]));
message.h.resource.component[0], NULL));
END
break;

Expand Down Expand Up @@ -147,7 +148,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e)
ogs_assert(true ==
ogs_sbi_server_send_error(
stream, OGS_SBI_HTTP_STATUS_NOT_FOUND,
&message, "Not found", message.h.method));
&message, "Not found", message.h.method, NULL));
break;
}

Expand All @@ -167,7 +168,8 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e)
ogs_assert(true ==
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message,
"Invalid API name", message.h.resource.component[0]));
"Invalid API name", message.h.resource.component[0],
NULL));
END

/* In lib/sbi/server.c, notify_completed() releases 'request' buffer. */
Expand Down Expand Up @@ -428,7 +430,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e)
ogs_assert(true ==
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL,
"Cannot receive SBI message", NULL));
"Cannot receive SBI message", NULL, NULL));
break;
default:
ogs_error("Unknown timer[%s:%d]",
Expand Down
8 changes: 4 additions & 4 deletions src/ausf/nausf-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool ausf_nausf_auth_handle_authenticate(ausf_ue_t *ausf_ue,
ogs_error("[%s] No AuthenticationInfo", ausf_ue->suci);
ogs_assert(true ==
ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
recvmsg, "No AuthenticationInfo", ausf_ue->suci));
recvmsg, "No AuthenticationInfo", ausf_ue->suci, NULL));
return false;
}

Expand All @@ -46,7 +46,7 @@ bool ausf_nausf_auth_handle_authenticate(ausf_ue_t *ausf_ue,
ogs_error("[%s] No servingNetworkName", ausf_ue->suci);
ogs_assert(true ==
ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
recvmsg, "No servingNetworkName", ausf_ue->suci));
recvmsg, "No servingNetworkName", ausf_ue->suci, NULL));
return false;
}

Expand Down Expand Up @@ -82,7 +82,7 @@ bool ausf_nausf_auth_handle_authenticate_confirmation(ausf_ue_t *ausf_ue,
ogs_error("[%s] No ConfirmationData", ausf_ue->suci);
ogs_assert(true ==
ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
recvmsg, "No ConfirmationData", ausf_ue->suci));
recvmsg, "No ConfirmationData", ausf_ue->suci, NULL));
return false;
}

Expand All @@ -91,7 +91,7 @@ bool ausf_nausf_auth_handle_authenticate_confirmation(ausf_ue_t *ausf_ue,
ogs_error("[%s] No ConfirmationData.resStar", ausf_ue->suci);
ogs_assert(true ==
ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST,
recvmsg, "No ConfirmationData.resStar", ausf_ue->suci));
recvmsg, "No ConfirmationData.resStar", ausf_ue->suci, NULL));
return false;
}

Expand Down
Loading

0 comments on commit eb2b19b

Please sign in to comment.