pespin has uploaded this change for review.

View Change

Simplify up_session_choose_f_teid() with early returns

Change-Id: I6e8c64d093588157c86bb3acaaeed458ff73132d
---
M src/osmo-upf/up_session.c
1 file changed, 36 insertions(+), 33 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/50/39450/1
diff --git a/src/osmo-upf/up_session.c b/src/osmo-upf/up_session.c
index 928db0b..c870358 100644
--- a/src/osmo-upf/up_session.c
+++ b/src/osmo-upf/up_session.c
@@ -185,43 +185,46 @@
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;
}

To view, visit change 39450. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: osmo-upf
Gerrit-Branch: master
Gerrit-Change-Id: I6e8c64d093588157c86bb3acaaeed458ff73132d
Gerrit-Change-Number: 39450
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>