File size: 5,462 Bytes
258fb37 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
/*
* Copyright (C) 2019,2020 by Sukchan Lee <acetcom@gmail.com>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "sbi-path.h"
#include "npcf-handler.h"
void af_npcf_policyauthorization_handle_create(
af_sess_t *sess, ogs_sbi_message_t *recvmsg)
{
int rv;
ogs_sbi_message_t message;
ogs_sbi_header_t header;
bool rc;
ogs_sbi_client_t *client = NULL;
OpenAPI_uri_scheme_e scheme = OpenAPI_uri_scheme_NULL;
char *fqdn = NULL;
uint16_t fqdn_port = 0;
ogs_sockaddr_t *addr = NULL, *addr6 = NULL;
OpenAPI_app_session_context_t *AppSessionContext = NULL;
OpenAPI_app_session_context_req_data_t *AscReqData = NULL;
uint64_t supported_features = 0;
if (!recvmsg->http.location) {
ogs_error("[%s:%s] No http.location",
sess->ipv4addr ? sess->ipv4addr : "Unknown",
sess->ipv6addr ? sess->ipv6addr : "Unknown");
return;
}
memset(&header, 0, sizeof(header));
header.uri = recvmsg->http.location;
rv = ogs_sbi_parse_header(&message, &header);
if (rv != OGS_OK) {
ogs_error("[%s:%s] Cannot parse http.location [%s]",
sess->ipv4addr ? sess->ipv4addr : "Unknown",
sess->ipv6addr ? sess->ipv6addr : "Unknown",
recvmsg->http.location);
return;
}
if (!message.h.resource.component[1]) {
ogs_error("[%s:%s] No AppSessionId[%s]",
sess->ipv4addr ? sess->ipv4addr : "Unknown",
sess->ipv6addr ? sess->ipv6addr : "Unknown",
recvmsg->http.location);
goto cleanup;
}
AppSessionContext = recvmsg->AppSessionContext;
if (!AppSessionContext) {
ogs_error("[%s:%s] No AppSessionContext",
sess->ipv4addr ? sess->ipv4addr : "Unknown",
sess->ipv6addr ? sess->ipv6addr : "Unknown");
goto cleanup;
}
AscReqData = AppSessionContext->asc_req_data;
if (!AscReqData) {
ogs_error("[%s:%s] No AscReqData",
sess->ipv4addr ? sess->ipv4addr : "Unknown",
sess->ipv6addr ? sess->ipv6addr : "Unknown");
goto cleanup;
}
if (!AscReqData->supp_feat) {
ogs_error("[%s:%s] No AscReqData->suppFeat",
sess->ipv4addr ? sess->ipv4addr : "Unknown",
sess->ipv6addr ? sess->ipv6addr : "Unknown");
goto cleanup;
}
rc = ogs_sbi_getaddr_from_uri(
&scheme, &fqdn, &fqdn_port, &addr, &addr6, header.uri);
if (rc == false || scheme == OpenAPI_uri_scheme_NULL) {
ogs_error("[%s:%s] Invalid URI [%s]",
sess->ipv4addr ? sess->ipv4addr : "Unknown",
sess->ipv6addr ? sess->ipv6addr : "Unknown",
header.uri);
goto cleanup;
}
client = ogs_sbi_client_find(scheme, fqdn, fqdn_port, addr, addr6);
if (!client) {
ogs_debug("[%s:%s] ogs_sbi_client_add()",
sess->ipv4addr ? sess->ipv4addr : "Unknown",
sess->ipv6addr ? sess->ipv6addr : "Unknown");
client = ogs_sbi_client_add(scheme, fqdn, fqdn_port, addr, addr6);
ogs_assert(client);
}
OGS_SBI_SETUP_CLIENT(&sess->app_session.pcf, client);
ogs_free(fqdn);
ogs_freeaddrinfo(addr);
ogs_freeaddrinfo(addr6);
PCF_APP_SESSION_STORE(sess, header.uri, message.h.resource.component[1]);
supported_features = ogs_uint64_from_string(AscReqData->supp_feat);
sess->policyauthorization_features &= supported_features;
cleanup:
ogs_sbi_header_free(&header);
}
void af_npcf_policyauthorization_handle_update(
af_sess_t *sess, ogs_sbi_message_t *recvmsg)
{
OpenAPI_app_session_context_update_data_patch_t
*AppSessionContextUpdateDataPatch = NULL;
OpenAPI_app_session_context_update_data_t *AscUpdateData = NULL;
ogs_assert(sess);
ogs_assert(recvmsg);
if (!recvmsg->h.resource.component[1]) {
ogs_error("[%s:%s] No AppSessionId[%s]",
sess->ipv4addr ? sess->ipv4addr : "Unknown",
sess->ipv6addr ? sess->ipv6addr : "Unknown",
recvmsg->http.location);
return;
}
AppSessionContextUpdateDataPatch =
recvmsg->AppSessionContextUpdateDataPatch;
if (!AppSessionContextUpdateDataPatch) {
ogs_error("[%s:%s] No AppSessionContextUpdateDataPatch",
sess->ipv4addr ? sess->ipv4addr : "Unknown",
sess->ipv6addr ? sess->ipv6addr : "Unknown");
return;
}
AscUpdateData = AppSessionContextUpdateDataPatch->asc_req_data;
if (!AscUpdateData) {
ogs_error("[%s:%s] No AscUpdateData",
sess->ipv4addr ? sess->ipv4addr : "Unknown",
sess->ipv6addr ? sess->ipv6addr : "Unknown");
return;
}
}
|