pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-upf/+/39450?usp=email )

Change subject: Simplify up_session_choose_f_teid() with early returns
......................................................................

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(-)

Approvals:
  Jenkins Builder: Verified
  fixeria: Looks good to me, but someone else must approve
  laforge: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved




diff --git a/src/osmo-upf/up_session.c b/src/osmo-upf/up_session.c
index 928db0b..198bf88 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 https://gerrit.osmocom.org/c/osmo-upf/+/39450?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: osmo-upf
Gerrit-Branch: master
Gerrit-Change-Id: I6e8c64d093588157c86bb3acaaeed458ff73132d
Gerrit-Change-Number: 39450
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>

Reply via email to