mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-upf.git
synced 2025-10-23 08:12:03 +00:00
Simplify up_session_choose_f_teid() with early returns
Change-Id: I6e8c64d093588157c86bb3acaaeed458ff73132d
This commit is contained in:
@@ -185,43 +185,46 @@ static enum osmo_pfcp_cause up_session_choose_f_teid(struct up_session *session,
|
||||
bool choose_id_present, uint8_t choose_id,
|
||||
const char *netinst_name)
|
||||
{
|
||||
struct chosen_f_teid *chosen = NULL;
|
||||
struct chosen_f_teid *chosen;
|
||||
int rc;
|
||||
|
||||
if (choose_id_present)
|
||||
if (choose_id_present) {
|
||||
chosen = chosen_f_teid_find(&session->chosen_f_teids, choose_id);
|
||||
if (chosen) {
|
||||
/* Re-use a previous F-TEID */
|
||||
*dst = chosen->f_teid;
|
||||
} else {
|
||||
int rc;
|
||||
if (chosen) {
|
||||
/* Re-use a previous F-TEID */
|
||||
*dst = chosen->f_teid;
|
||||
return OSMO_PFCP_CAUSE_REQUEST_ACCEPTED;
|
||||
}
|
||||
/* No previous F-TEID found, allocate a new one below */
|
||||
}
|
||||
|
||||
*dst = (struct osmo_pfcp_ie_f_teid){
|
||||
.choose_flag = false,
|
||||
*dst = (struct osmo_pfcp_ie_f_teid){
|
||||
.choose_flag = false,
|
||||
};
|
||||
|
||||
/* Determine local IP address from Network Instance value received in PFCP request */
|
||||
rc = up_session_choose_local_ip(session, &dst->fixed.ip_addr, netinst_name);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
/* Choose a new TEID */
|
||||
dst->fixed.teid = upf_next_local_teid();
|
||||
if (dst->fixed.teid == 0) {
|
||||
LOGPFSML(session->fi, LOGL_ERROR, "Failed to allocate an unused TEID\n");
|
||||
return OSMO_PFCP_CAUSE_PFCP_ENTITY_IN_CONGESTION;
|
||||
}
|
||||
|
||||
LOGPFSML(session->fi, LOGL_INFO, "Allocated new local F-TEID %s\n",
|
||||
osmo_pfcp_ie_f_teid_to_str_c(OTC_SELECT, dst));
|
||||
|
||||
/* Save this choice */
|
||||
if (choose_id_present) {
|
||||
chosen = talloc(session, struct chosen_f_teid);
|
||||
*chosen = (struct chosen_f_teid){
|
||||
.f_teid = *dst,
|
||||
.choose_id = choose_id,
|
||||
};
|
||||
|
||||
/* Determine local IP address from Network Instance value received in PFCP request */
|
||||
rc = up_session_choose_local_ip(session, &dst->fixed.ip_addr, netinst_name);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
/* Choose a new TEID */
|
||||
dst->fixed.teid = upf_next_local_teid();
|
||||
if (dst->fixed.teid == 0) {
|
||||
LOGPFSML(session->fi, LOGL_ERROR, "Failed to allocate an unused TEID\n");
|
||||
return OSMO_PFCP_CAUSE_PFCP_ENTITY_IN_CONGESTION;
|
||||
}
|
||||
LOGPFSML(session->fi, LOGL_INFO, "Allocated new local F-TEID %s\n",
|
||||
osmo_pfcp_ie_f_teid_to_str_c(OTC_SELECT, dst));
|
||||
|
||||
/* Save this choice */
|
||||
if (choose_id_present) {
|
||||
chosen = talloc(session, struct chosen_f_teid);
|
||||
*chosen = (struct chosen_f_teid){
|
||||
.f_teid = *dst,
|
||||
.choose_id = choose_id,
|
||||
};
|
||||
llist_add_tail(&chosen->entry, &session->chosen_f_teids);
|
||||
}
|
||||
llist_add_tail(&chosen->entry, &session->chosen_f_teids);
|
||||
}
|
||||
return OSMO_PFCP_CAUSE_REQUEST_ACCEPTED;
|
||||
}
|
||||
|
Reference in New Issue
Block a user