mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-upf.git
synced 2025-11-02 21:13:46 +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,
|
bool choose_id_present, uint8_t choose_id,
|
||||||
const char *netinst_name)
|
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);
|
chosen = chosen_f_teid_find(&session->chosen_f_teids, choose_id);
|
||||||
if (chosen) {
|
if (chosen) {
|
||||||
/* Re-use a previous F-TEID */
|
/* Re-use a previous F-TEID */
|
||||||
*dst = chosen->f_teid;
|
*dst = chosen->f_teid;
|
||||||
} else {
|
return OSMO_PFCP_CAUSE_REQUEST_ACCEPTED;
|
||||||
int rc;
|
}
|
||||||
|
/* No previous F-TEID found, allocate a new one below */
|
||||||
|
}
|
||||||
|
|
||||||
*dst = (struct osmo_pfcp_ie_f_teid){
|
*dst = (struct osmo_pfcp_ie_f_teid){
|
||||||
.choose_flag = false,
|
.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,
|
||||||
};
|
};
|
||||||
|
llist_add_tail(&chosen->entry, &session->chosen_f_teids);
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return OSMO_PFCP_CAUSE_REQUEST_ACCEPTED;
|
return OSMO_PFCP_CAUSE_REQUEST_ACCEPTED;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user