forked from acouzens/open5gs
456 lines
15 KiB
C
456 lines
15 KiB
C
/*
|
|
* Copyright (C) 2019 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 "pfcp-path.h"
|
|
#include "gtp-path.h"
|
|
#include "sxa-handler.h"
|
|
|
|
static void setup_gtp_node(ogs_pfcp_far_t *far)
|
|
{
|
|
int rv;
|
|
ogs_ip_t ip;
|
|
ogs_gtp_node_t *gnode = NULL;
|
|
|
|
ogs_assert(far);
|
|
|
|
ogs_pfcp_outer_header_creation_to_ip(&far->outer_header_creation, &ip);
|
|
|
|
/* No Outer Header Creation */
|
|
if (ip.len == 0) return;
|
|
|
|
gnode = ogs_gtp_node_find_by_ip(&sgwu_self()->peer_list, &ip);
|
|
if (!gnode) {
|
|
gnode = ogs_gtp_node_add_by_ip(
|
|
&sgwu_self()->peer_list, &ip, sgwu_self()->gtpu_port,
|
|
ogs_app()->parameter.no_ipv4,
|
|
ogs_app()->parameter.no_ipv6,
|
|
ogs_app()->parameter.prefer_ipv4);
|
|
ogs_assert(gnode);
|
|
|
|
rv = ogs_gtp_connect(
|
|
sgwu_self()->gtpu_sock, sgwu_self()->gtpu_sock6, gnode);
|
|
ogs_assert(rv == OGS_OK);
|
|
}
|
|
|
|
OGS_SETUP_GTP_NODE(far, gnode);
|
|
|
|
ogs_pfcp_far_hash_set(far);
|
|
}
|
|
|
|
void sgwu_sxa_handle_session_establishment_request(
|
|
sgwu_sess_t *sess, ogs_pfcp_xact_t *xact,
|
|
ogs_pfcp_session_establishment_request_t *req)
|
|
{
|
|
ogs_pfcp_pdr_t *pdr = NULL;
|
|
ogs_pfcp_far_t *far = NULL;
|
|
ogs_pfcp_pdr_t *created_pdr[OGS_MAX_NUM_OF_PDR];
|
|
int num_of_created_pdr = 0;
|
|
uint8_t cause_value = 0;
|
|
uint8_t offending_ie_value = 0;
|
|
int i;
|
|
|
|
ogs_assert(xact);
|
|
ogs_assert(req);
|
|
|
|
ogs_debug("Session Establishment Request");
|
|
|
|
cause_value = OGS_PFCP_CAUSE_REQUEST_ACCEPTED;
|
|
|
|
if (!sess) {
|
|
ogs_error("No Context");
|
|
ogs_pfcp_send_error_message(xact, 0,
|
|
OGS_PFCP_SESSION_ESTABLISHMENT_RESPONSE_TYPE,
|
|
OGS_PFCP_CAUSE_MANDATORY_IE_MISSING, 0);
|
|
return;
|
|
}
|
|
|
|
for (i = 0; i < OGS_MAX_NUM_OF_PDR; i++) {
|
|
created_pdr[i] = ogs_pfcp_handle_create_pdr(&sess->pfcp,
|
|
&req->create_pdr[i], &cause_value, &offending_ie_value);
|
|
if (created_pdr[i] == NULL)
|
|
break;
|
|
}
|
|
num_of_created_pdr = i;
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
for (i = 0; i < OGS_MAX_NUM_OF_FAR; i++) {
|
|
if (ogs_pfcp_handle_create_far(&sess->pfcp, &req->create_far[i],
|
|
&cause_value, &offending_ie_value) == NULL)
|
|
break;
|
|
}
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
for (i = 0; i < OGS_MAX_NUM_OF_QER; i++) {
|
|
if (ogs_pfcp_handle_create_qer(&sess->pfcp, &req->create_qer[i],
|
|
&cause_value, &offending_ie_value) == NULL)
|
|
break;
|
|
}
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
ogs_pfcp_handle_create_bar(&sess->pfcp, &req->create_bar,
|
|
&cause_value, &offending_ie_value);
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
/* Setup GTP Node */
|
|
ogs_list_for_each(&sess->pfcp.far_list, far)
|
|
setup_gtp_node(far);
|
|
|
|
/* Setup TEID Hash */
|
|
for (i = 0; i < num_of_created_pdr; i++) {
|
|
pdr = created_pdr[i];
|
|
ogs_assert(pdr);
|
|
|
|
if (pdr->f_teid_len) {
|
|
if (ogs_pfcp_self()->up_function_features.ftup &&
|
|
pdr->f_teid.ch) {
|
|
|
|
ogs_pfcp_pdr_t *choosed_pdr = NULL;
|
|
|
|
if (pdr->f_teid.chid) {
|
|
choosed_pdr = ogs_pfcp_pdr_find_by_choose_id(
|
|
&sess->pfcp, pdr->f_teid.choose_id);
|
|
if (!choosed_pdr) {
|
|
pdr->chid = true;
|
|
pdr->choose_id = pdr->f_teid.choose_id;
|
|
}
|
|
}
|
|
|
|
if (choosed_pdr) {
|
|
pdr->f_teid_len = choosed_pdr->f_teid_len;
|
|
memcpy(&pdr->f_teid, &choosed_pdr->f_teid, pdr->f_teid_len);
|
|
|
|
} else {
|
|
ogs_pfcp_gtpu_resource_t *resource = NULL;
|
|
resource = ogs_pfcp_gtpu_resource_find(
|
|
&ogs_pfcp_self()->gtpu_resource_list,
|
|
pdr->apn, OGS_PFCP_INTERFACE_ACCESS);
|
|
if (resource) {
|
|
ogs_pfcp_user_plane_ip_resource_info_to_f_teid(
|
|
&resource->info, &pdr->f_teid, &pdr->f_teid_len);
|
|
if (resource->info.teidri)
|
|
pdr->f_teid.teid = OGS_PFCP_GTPU_INDEX_TO_TEID(
|
|
pdr->index, resource->info.teidri,
|
|
resource->info.teid_range);
|
|
else
|
|
pdr->f_teid.teid = pdr->index;
|
|
} else {
|
|
ogs_sockaddr_t *addr = NULL, *addr6 = NULL;
|
|
|
|
if (sgwu_self()->gtpu_sock)
|
|
addr = &sgwu_self()->gtpu_sock->local_addr;
|
|
if (sgwu_self()->gtpu_sock6)
|
|
addr6 = &sgwu_self()->gtpu_sock6->local_addr;
|
|
|
|
ogs_assert(addr || addr6);
|
|
ogs_pfcp_sockaddr_to_f_teid(
|
|
addr, addr6, &pdr->f_teid, &pdr->f_teid_len);
|
|
|
|
pdr->f_teid.teid = pdr->index;
|
|
}
|
|
}
|
|
}
|
|
|
|
ogs_pfcp_pdr_hash_set(pdr);
|
|
}
|
|
}
|
|
|
|
/* Send Buffered Packet to gNB */
|
|
ogs_list_for_each(&sess->pfcp.pdr_list, pdr) {
|
|
if (pdr->src_if == OGS_PFCP_INTERFACE_CORE) { /* Downlink */
|
|
ogs_pfcp_send_buffered_packet(pdr);
|
|
}
|
|
}
|
|
|
|
sgwu_pfcp_send_session_establishment_response(
|
|
xact, sess, created_pdr, num_of_created_pdr);
|
|
return;
|
|
|
|
cleanup:
|
|
ogs_pfcp_sess_clear(&sess->pfcp);
|
|
ogs_pfcp_send_error_message(xact, sess ? sess->sgwu_sxa_seid : 0,
|
|
OGS_PFCP_SESSION_ESTABLISHMENT_RESPONSE_TYPE,
|
|
cause_value, offending_ie_value);
|
|
}
|
|
|
|
void sgwu_sxa_handle_session_modification_request(
|
|
sgwu_sess_t *sess, ogs_pfcp_xact_t *xact,
|
|
ogs_pfcp_session_modification_request_t *req)
|
|
{
|
|
ogs_pfcp_pdr_t *pdr = NULL;
|
|
ogs_pfcp_far_t *far = NULL;
|
|
ogs_pfcp_pdr_t *created_pdr[OGS_MAX_NUM_OF_PDR];
|
|
int num_of_created_pdr = 0;
|
|
uint8_t cause_value = 0;
|
|
uint8_t offending_ie_value = 0;
|
|
int i;
|
|
|
|
ogs_assert(xact);
|
|
ogs_assert(req);
|
|
|
|
ogs_debug("Session Modification Request");
|
|
|
|
cause_value = OGS_PFCP_CAUSE_REQUEST_ACCEPTED;
|
|
|
|
if (!sess) {
|
|
ogs_error("No Context");
|
|
ogs_pfcp_send_error_message(xact, 0,
|
|
OGS_PFCP_SESSION_MODIFICATION_RESPONSE_TYPE,
|
|
OGS_PFCP_CAUSE_SESSION_CONTEXT_NOT_FOUND, 0);
|
|
return;
|
|
}
|
|
|
|
for (i = 0; i < OGS_MAX_NUM_OF_PDR; i++) {
|
|
created_pdr[i] = ogs_pfcp_handle_create_pdr(&sess->pfcp,
|
|
&req->create_pdr[i], &cause_value, &offending_ie_value);
|
|
if (created_pdr[i] == NULL)
|
|
break;
|
|
}
|
|
num_of_created_pdr = i;
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
for (i = 0; i < OGS_MAX_NUM_OF_PDR; i++) {
|
|
if (ogs_pfcp_handle_remove_pdr(&sess->pfcp, &req->remove_pdr[i],
|
|
&cause_value, &offending_ie_value) == false)
|
|
break;
|
|
}
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
for (i = 0; i < OGS_MAX_NUM_OF_FAR; i++) {
|
|
if (ogs_pfcp_handle_create_far(&sess->pfcp, &req->create_far[i],
|
|
&cause_value, &offending_ie_value) == NULL)
|
|
break;
|
|
}
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
for (i = 0; i < OGS_MAX_NUM_OF_FAR; i++) {
|
|
if (ogs_pfcp_handle_update_far_flags(&sess->pfcp, &req->update_far[i],
|
|
&cause_value, &offending_ie_value) == NULL)
|
|
break;
|
|
}
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
/* Send End Marker to gNB */
|
|
ogs_list_for_each(&sess->pfcp.pdr_list, pdr) {
|
|
far = pdr->far;
|
|
if (far && far->smreq_flags.send_end_marker_packets)
|
|
ogs_pfcp_send_end_marker(pdr);
|
|
}
|
|
/* Clear PFCPSMReq-Flags */
|
|
ogs_list_for_each(&sess->pfcp.far_list, far)
|
|
far->smreq_flags.value = 0;
|
|
|
|
for (i = 0; i < OGS_MAX_NUM_OF_FAR; i++) {
|
|
if (ogs_pfcp_handle_update_far(&sess->pfcp, &req->update_far[i],
|
|
&cause_value, &offending_ie_value) == NULL)
|
|
break;
|
|
}
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
for (i = 0; i < OGS_MAX_NUM_OF_FAR; i++) {
|
|
if (ogs_pfcp_handle_remove_far(&sess->pfcp, &req->remove_far[i],
|
|
&cause_value, &offending_ie_value) == false)
|
|
break;
|
|
}
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
for (i = 0; i < OGS_MAX_NUM_OF_QER; i++) {
|
|
if (ogs_pfcp_handle_create_qer(&sess->pfcp, &req->create_qer[i],
|
|
&cause_value, &offending_ie_value) == NULL)
|
|
break;
|
|
}
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
for (i = 0; i < OGS_MAX_NUM_OF_QER; i++) {
|
|
if (ogs_pfcp_handle_update_qer(&sess->pfcp, &req->update_qer[i],
|
|
&cause_value, &offending_ie_value) == NULL)
|
|
break;
|
|
}
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
for (i = 0; i < OGS_MAX_NUM_OF_QER; i++) {
|
|
if (ogs_pfcp_handle_remove_qer(&sess->pfcp, &req->remove_qer[i],
|
|
&cause_value, &offending_ie_value) == false)
|
|
break;
|
|
}
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
ogs_pfcp_handle_create_bar(&sess->pfcp, &req->create_bar,
|
|
&cause_value, &offending_ie_value);
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
ogs_pfcp_handle_remove_bar(&sess->pfcp, &req->remove_bar,
|
|
&cause_value, &offending_ie_value);
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED)
|
|
goto cleanup;
|
|
|
|
/* Setup GTP Node */
|
|
ogs_list_for_each(&sess->pfcp.far_list, far)
|
|
setup_gtp_node(far);
|
|
|
|
/* Setup TEID Hash */
|
|
for (i = 0; i < num_of_created_pdr; i++) {
|
|
pdr = created_pdr[i];
|
|
ogs_assert(pdr);
|
|
|
|
if (pdr->f_teid_len) {
|
|
if (ogs_pfcp_self()->up_function_features.ftup &&
|
|
pdr->f_teid.ch) {
|
|
|
|
ogs_pfcp_pdr_t *choosed_pdr = NULL;
|
|
|
|
if (pdr->f_teid.chid) {
|
|
choosed_pdr = ogs_pfcp_pdr_find_by_choose_id(
|
|
&sess->pfcp, pdr->f_teid.choose_id);
|
|
if (!choosed_pdr) {
|
|
pdr->chid = true;
|
|
pdr->choose_id = pdr->f_teid.choose_id;
|
|
}
|
|
}
|
|
|
|
if (choosed_pdr) {
|
|
pdr->f_teid_len = choosed_pdr->f_teid_len;
|
|
memcpy(&pdr->f_teid, &choosed_pdr->f_teid, pdr->f_teid_len);
|
|
|
|
} else {
|
|
ogs_pfcp_gtpu_resource_t *resource = NULL;
|
|
resource = ogs_pfcp_gtpu_resource_find(
|
|
&ogs_pfcp_self()->gtpu_resource_list,
|
|
pdr->apn, OGS_PFCP_INTERFACE_ACCESS);
|
|
if (resource) {
|
|
ogs_pfcp_user_plane_ip_resource_info_to_f_teid(
|
|
&resource->info, &pdr->f_teid, &pdr->f_teid_len);
|
|
if (resource->info.teidri)
|
|
pdr->f_teid.teid = OGS_PFCP_GTPU_INDEX_TO_TEID(
|
|
pdr->index, resource->info.teidri,
|
|
resource->info.teid_range);
|
|
else
|
|
pdr->f_teid.teid = pdr->index;
|
|
} else {
|
|
ogs_sockaddr_t *addr = NULL, *addr6 = NULL;
|
|
|
|
if (sgwu_self()->gtpu_sock)
|
|
addr = &sgwu_self()->gtpu_sock->local_addr;
|
|
if (sgwu_self()->gtpu_sock6)
|
|
addr6 = &sgwu_self()->gtpu_sock6->local_addr;
|
|
|
|
ogs_assert(addr || addr6);
|
|
ogs_pfcp_sockaddr_to_f_teid(
|
|
addr, addr6, &pdr->f_teid, &pdr->f_teid_len);
|
|
|
|
pdr->f_teid.teid = pdr->index;
|
|
}
|
|
}
|
|
}
|
|
|
|
ogs_pfcp_pdr_hash_set(pdr);
|
|
}
|
|
}
|
|
|
|
/* Send Buffered Packet to gNB */
|
|
ogs_list_for_each(&sess->pfcp.pdr_list, pdr) {
|
|
if (pdr->src_if == OGS_PFCP_INTERFACE_CORE) { /* Downlink */
|
|
ogs_pfcp_send_buffered_packet(pdr);
|
|
}
|
|
}
|
|
|
|
sgwu_pfcp_send_session_modification_response(
|
|
xact, sess, created_pdr, num_of_created_pdr);
|
|
return;
|
|
|
|
cleanup:
|
|
ogs_pfcp_sess_clear(&sess->pfcp);
|
|
ogs_pfcp_send_error_message(xact, sess ? sess->sgwu_sxa_seid : 0,
|
|
OGS_PFCP_SESSION_MODIFICATION_RESPONSE_TYPE,
|
|
cause_value, offending_ie_value);
|
|
}
|
|
|
|
void sgwu_sxa_handle_session_deletion_request(
|
|
sgwu_sess_t *sess, ogs_pfcp_xact_t *xact,
|
|
ogs_pfcp_session_deletion_request_t *req)
|
|
{
|
|
ogs_assert(xact);
|
|
ogs_assert(req);
|
|
|
|
ogs_debug("Session Deletion Request");
|
|
|
|
if (!sess) {
|
|
ogs_error("No Context");
|
|
ogs_pfcp_send_error_message(xact, 0,
|
|
OGS_PFCP_SESSION_DELETION_RESPONSE_TYPE,
|
|
OGS_PFCP_CAUSE_SESSION_CONTEXT_NOT_FOUND, 0);
|
|
return;
|
|
}
|
|
|
|
ogs_assert(sess);
|
|
|
|
sgwu_pfcp_send_session_deletion_response(xact, sess);
|
|
|
|
sgwu_sess_remove(sess);
|
|
}
|
|
|
|
void sgwu_sxa_handle_session_report_response(
|
|
sgwu_sess_t *sess, ogs_pfcp_xact_t *xact,
|
|
ogs_pfcp_session_report_response_t *rsp)
|
|
{
|
|
uint8_t cause_value = 0;
|
|
|
|
ogs_assert(xact);
|
|
ogs_assert(rsp);
|
|
|
|
ogs_pfcp_xact_commit(xact);
|
|
|
|
ogs_debug("Session report resopnse");
|
|
|
|
cause_value = OGS_PFCP_CAUSE_REQUEST_ACCEPTED;
|
|
|
|
if (!sess) {
|
|
ogs_warn("No Context");
|
|
cause_value = OGS_PFCP_CAUSE_SESSION_CONTEXT_NOT_FOUND;
|
|
}
|
|
|
|
if (rsp->cause.presence) {
|
|
if (rsp->cause.u8 != OGS_PFCP_CAUSE_REQUEST_ACCEPTED) {
|
|
ogs_error("PFCP Cause[%d] : Not Accepted", rsp->cause.u8);
|
|
cause_value = rsp->cause.u8;
|
|
}
|
|
} else {
|
|
ogs_error("No Cause");
|
|
cause_value = OGS_PFCP_CAUSE_MANDATORY_IE_MISSING;
|
|
}
|
|
|
|
if (cause_value != OGS_PFCP_CAUSE_REQUEST_ACCEPTED) {
|
|
ogs_error("Cause request not accepted[%d]", cause_value);
|
|
return;
|
|
}
|
|
}
|